Location: PHPKode > projects > AModules3 > amodules-3.0.1/mini-apps/03-DocAssistant/main.php
<?php
/*
 * Created on 21.03.2006 by *Camper*
 */
include "amodules3/loader.php";
class Documenter extends ApiAdmin{
	private $auth;
	public $logger;
	
    public $apinfo=array(
            'version'=>'0.1',
            'name'=>'Documentation assistant'
            );

	function init(){
		$this->readConfig('config.php');
		parent::init();
		$this->logger=$this->add('Logger');
		$this->dbConnect();
		$this->template->trySet('page_title', $this->apinfo['name']);
		$this->api->debug = defined('DEBUG');

		$this->template->del('Content');
		$this->template->del('Locator');
		$this->template->del('msgbox');
		$this->template->del('RightSidebar');
		$this->template->del('InfoWindow');
		//user authentication
		if($this->recall('editable', 0)==1){
			//TODO add a login validation
			if(isset($_REQUEST['register']))$this->api->redirect('Register');
			elseif(strtolower($this->page)!='register'){
				$this->auth = $this->api->add('Auth')->setSource('user', 'name', 'password');
				$this->auth->dq->field(array('level'));
				$this->auth
					->addRegisterLink()
					->addLostPassword()
				;
			}
		}
	}
	function initLayout(){
		$this
			->addLayout('Content')
			->addLayout('Menu')
		;
	}
	function layout_Menu(){
		$menu = $this->add('Menu', null, 'Menu')
			->addMenuItem('Projects');
		//if($this->auth->auth_data['level'] == 'admin')$menu->addMenuItem('User Management');
		$menu->addMenuItem('About');
		if($this->recall('editable', 0)==1&&$this->isAuthenticated()){
			$menu->addMenuItem('Logout');
		}else{
			$menu->addMenuItem('Login');
		}
	}
	function page_Login($p){
		$this->memorize('editable', 1);
		$this->redirect('Index');
	}
	function page_Index($p){
		if($this->isAuthenticated()||!$this->recall('editable'))$this->redirect('Projects');
	}
	function page_Logout(){
		$this->forget('auth_data');
		$this->forget('editable');
		$this->auth->logout();
		$this->api->redirect('Index');
	}
	function page_delete_project(){
		$this->db->query("delete from member where project_id = ".$_REQUEST['id']);
		$this->db->query("delete from version where project_id = ".$_REQUEST['id']);
		$this->db->query("delete from project where id = ".$_REQUEST['id']);
		$this->redirect('Projects');
	}
	function getProjectName($prj_id){
		return $this->db->getOne("select name from project where id = $prj_id");
	}
	function getProjectPath($prj_id){
		return $this->db->getOne("select local_path from project where id = $prj_id");
	}
	/**
	 * returns a last version for project
	 */
	function getProjectVersion($prj_id){
		$result = $this->db->getOne("select max(id) from version where project_id = $prj_id");
		return $result == ''?0:$result;
	}
	function isAuthenticated(){
		return $this->auth&&$this->auth->auth_data['authenticated'];
	}
	function getUserId(){
		return $this->auth?$this->auth->auth_data['id']:0;
	}
	function getMemberName($member_id){
		if(is_null($member_id))return "";
		return $this->api->db->getOne("select name from member where id = $member_id");
	}
	function getItem($id){
		return $this->db->getHash("select * from member where id = $id");
	}
	function getMemberLink($name, $id, $for_class=false){
    	$caption=$name;
    	$page=$for_class?'ClassDetail':'MemberDetail';
    	$div_id=$for_class?'class_details':'member_details';
    	$onclick="aasn('$div_id','".
					$this->api->getDestinationURL($page, array(
						'id'=>$id,
	                    'member_id'=>$id,
	                    'cut_object'=>$page
				))."')";
		//$onclick="alert('1')";
    	$caption="<a href=#$div_id onclick=\"".$onclick.
				"\">".
    		$caption."</a>";
    	return $caption;
	}
}
$doc = new Documenter("DocHelper");
$doc->main();
Return current item: AModules3