Location: PHPKode > projects > Monyet > controllers/manageprivileges.php
<?php

Class ManagePrivileges extends Management {

	private $privileges;
	private $group;

	public function __construct(){
		parent::__construct();
		$this->privileges = new Privileges();
		$this->group = new Group();
	}
	public function show(){
		parent::show();
	}

	public function remove(){
		parent::remove();
	}

	public function removeItem(){
		$this->privileges->remove($_POST['id']);
	}

	public function populateShowContent(){
		//to make sure the menu panel is updated when privileges is being edited	  
		$this->xml->buildMenu($this->navigator->getMenu(2));
		$this->xml->buildSubMenu($this->navigator->getSubMenu($this));
		
		$array_column = array("Group Name","Allowed Access","Permission");	 
		$this->xml->addText('NOTE: Super Admin and Guest is only logical consideration. you still need to redefine all privileges','rightcontent',0);
		$this->xml->addBreak('rightcontent',2);
		$this->xml->addTable($this->privileges->select($this->offset,$this->pglimit),$array_column,'Table Group Privileges',
				  $this->navigator->getAccess($this),$this->offset,'rightcontent',1);
	}

	public function populateAddForm(){
	 	$this->xml->addSelectAction('Group Name',$this->group->selectCouple('id','name'),'',
				  'group_id',$this->getName().'/addSelect');
		$this->xml->addSelect('Allowed Access',$this->privileges->selectRemaining($this->group->getHead('id')),'','access');
		$arraypermission = array('Read'=>'Read','Write'=>'Write');
		$this->xml->addSelect('Permission',$arraypermission,'','permission');
	}
	public function populateEditForm(){
		$this->privileges->selectByID($_POST['id']);
		$arraypermission = array('Read'=>'Read','Write'=>'Write');
		$this->xml->addSelect('Permission',$arraypermission,$this->privileges->getPermission(),'permission');
	}
	
	//return string to set the title
	public function getTitle(){
		return SITENAME.' -group-privileges';
	}

	public function getFormPlace(){
		return 'panel';
	}

	public function editItem(){
		$array = array('permission'=>$_POST['permission']);
		return $this->privileges->update($array,$_POST['id']);	  
	}

	public function getKeyVar(){
		return 'permission';
	}

	public function getTotal(){
		return $this->privileges->getTotal();
	}

	public function addItem(){
		$array = array('',$_POST['group_id'],$_POST['access'],$_POST['permission']);
		$this->privileges->add($array);
	}

	public function checkAdd(){
		if($_POST['access']==''){
			die('No access definition left for the group');	  
		}
	}
	//not implemented
	public function checkEdit(){}

	//redefine post add action 
	public function postAddAction(){
		$this->xml->addText('Adding new access','note',0);
		$this->xml->addRedirPOST($this->getName().'/addSelect','group_id='.$_POST['group_id']);
	}
	public function setEditCaption(){
		$this->xml->addText('Edit Access No. '.$_POST['itemnumber'],'headbox',1);
	}

	//spesific method
	public function addSelect(){
		if(isset($_POST['group_id'])){
			$this->xml->addSingleSelect($this->privileges->selectRemaining($_POST['group_id']),'','access','divselectaccess');
		}
		$this->xml->flush();
	}
	
}
?>
Return current item: Monyet