<?php
Class ManageUser extends Management {
private $user;
private $group;
public function __construct(){
parent::__construct();
$this->user = new User();
$this->group = new Group();
}
public function show(){
parent::show();
}
public function remove(){
parent::remove();
}
public function removeItem(){
$this->user->remove($_POST['id']);
}
public function changepass(){
if(isset($_POST['pass'])){
//this magic number is MD5 for an empty string
if($_POST['pass']=='d41d8cd98f00b204e9800998ecf8427e'){
die('ERROR: Password should not be empty');
}
$array = array('password'=>$_POST['pass']);
if($this->user->update($array,$_POST['id'])==true){
$this->xml->addRedir($this->getName().'/show');
$this->xml->addText(null,'panel',0);
$this->xml->addText('updating password for User ID '.$_POST['id'],'note',0);
}
else{
$this->xml->addText('IGNORE: item no longer exists','note',0);
$this->xml->addRedirPOST($this->getName().'/show','ofs='.$_POST['ofs']);
}
}
else{
$this->xml->addForm('changepass','panel',0);
$this->xml->addSelect('Username',$this->user->selectCouple('username','username'),'','id');
$this->xml->addTextField('New Password','','pass','password');
$this->xml->addSubmitBtn('submitForm(\''.$this->getName().'/changepass\')','Submit');
$this->xml->addText('Change Password','headbox',1);
}
$this->xml->flush();
}
public function populateShowContent(){
$array_column = array("Username","Group","Real Name","Email","Handset");
$this->xml->addTable($this->user->select($this->offset,$this->pglimit),
$array_column,'Table Users',$this->navigator->getAccess($this),$this->offset,'rightcontent',0);
}
public function populateAddForm(){
$this->xml->addTextField('Username',null,'username','text');
$this->xml->addTextField('Password',null,'pass','password');
$this->xml->addTextField('Real Name',null,'realname','text');
$this->xml->addSelect('Group',$this->group->selectCouple('id','name'),'','group');
$this->xml->addTextField('Email',null,'email','text');
$this->xml->addTextField('Handset',null,'handset','text');
}
public function populateEditForm(){
$this->user->selectByID($_POST['id']);
$this->xml->addTextField('Real Name',$this->user->getRealname(),'realname','text');
$this->xml->addSelect('Group',$this->group->selectCouple('id','name'),$this->user->getGroup(),'group');
$this->xml->addTextField('Email',$this->user->getEmail(),'email','text');
$this->xml->addTextField('Handset',$this->user->getHandset(),'handset','text');
}
public function setEditCaption(){
$this->xml->addText('Edit Profile '.$_POST['id'],'headbox',1);
}
//return string to set the title
public function getTitle(){
return SITENAME.' -user';
}
public function getFormPlace(){
return 'panel';
}
public function editItem(){
$array = array('realname'=>$_POST['realname'],
'group'=>$_POST['group'],'email'=>$_POST['email'],'handset'=>$_POST['handset']);
return $this->user->update($array,$_POST['id']);
}
public function getKeyVar(){
return 'group';
}
public function getTotal(){
return $this->user->getTotal();
}
public function addItem(){
$array = array($_POST['username'],$_POST['pass'],$_POST['group'],$_POST['realname'],$_POST['email'],$_POST['handset']);
$this->user->add($array);
}
public function checkAdd(){
if($_POST['username']==''){
die('Username should not be empty');
}
if($_POST['pass']=='d41d8cd98f00b204e9800998ecf8427e'){
die('Password just too weak. Please don\'t leave it blank');
}
if($this->user->isExist($_POST['username'])){
die('Please choose different username.\''.$_POST['username'].'\' is owned by someone else');
}
}
public function checkEdit(){
}
}
?>