Location: PHPKode > projects > CenterFlow > app/controllers/people_controller.php
<?

class PeopleController extends AppController
{
	var $name = 'People';
	var $scaffold;
	var $helpers = array('Html','Text','Javascript','Cache','Time');
	var $uses = array('Person','Project');
	var $cacheAction = array(//'/userlist'	=>'1 day',
	'/statusfilter'=>'1 day');
	var $layout = 'app';

	function userlist($selected = NULL)
	{
		$this->checkSession();
		$this->set('userlist',$this->Person->getUsers());
		if(empty($selected))
		{
			$selected = 'Anybody';
		}
		$this->set('selected',$selected);
		$this->render('userlist','ajax');
	}
	
	function feedback()
	{
		list($error,$accepted) = array('','');
		if(!empty($this->data))
		{
			extract($this->data);
			if(!in_array($type,array('Bug','Feature Request','Question')))
			{
				$type = 'Question';
			}
			$subject = "Centerflow Feedback: $type";
			$extra   = "From: $email";
			$body	 = strip_tags($body);
			if(empty($body))
			{
				$error .= 'You must fill out the feedback message<br/>';
			}
			if(!preg_match(VALID_EMAIL,$email))
			{
				$error .= 'You must fill out a valid email';
			}
			if(empty($error))
			{
				mail('hide@address.com',$subject,$body,$extra);	
				$accepted = 'Your feedback has been accepted. Thank you';
			}
		}
		$this->set('accepted',$accepted);
		$this->set('error',$error);
		$this->layout = 'default';
	}

	function statusfilter($selected = 'All')
	{
		$this->checkSession();
		$this->set('selected',$selected);
		$this->set('userlist',$this->Person->getUsers());
		$this->set('status_array', array('new','in progress','completed','on hold'));
		$this->layout = 'ajax';
	}

	function beforeRender()
	{
		if($this->layout != 'ajax')
		{
			//$this->set('project_listing',$this->Project->generateList('parentid = 0', null, null, '{n}.Project.id', '{n}.Project.name'));
			$this->set('project_listing',$this->Project->generateTree());
		}
		if(!$this->pageTitle || empty($this->pageTitle))
		{
			$this->pageTitle = ucwords($this->name.' :: '.$this->action);
		}
		$this->set('cfroot',CF_ROOT);
		$this->pageTitle = '[centerFLOW] '.$this->pageTitle;
	}

	function login($ref = null)
	{
		$this->layout = 'default';
		
		//Don't show the error message if no data has been submitted.
		$this->set('error', false);
		$this->set('ref',$ref);
		// If a Person has submitted form data:
		if (!empty($this->data))
		{
			// First, let's see if there are any Persons in the database
			// with the name supplied by the Person using the form:

			$someone = $this->Person->findByUsername($this->data['Person']['username']);

			// At this point, $someone is full of Person data, or its empty.
			// Let's compare the form-submitted password with the one in
			// the database.

			if(!empty($someone['Person']['password']) && $someone['Person']['password'] == md5($this->data['Person']['password']))
			{
				// Note: hopefully your password in the DB is hashed,
				// so your comparison might look more like:
				// md5($this->data['Person']['password']) == ...

				// This means they were the same. We can now build some basic
				// session information to remember this Person as 'logged-in'.

				$this->Session->write('Person', $someone['Person']);

				// Now that we have them stored in a session, forward them on
				// to a landing page for the application.

				if(!empty($this->params['form']['ref']))
				{
					$redirect_to = base64_decode($this->params['form']['ref']);
				}
				else
				{
					$person_id = $someone['Person']['id'];
					$redirect_to = CF_ROOT."/people/home/$person_id";
				}
				//$this->redirect($redirect_to);
				header("Location: $redirect_to");
				exit();
			}
			// Else, they supplied incorrect data:
			else
			{
				// Remember the $error var in the view? Let's set that to true:
				$this->set('error', true);
			}
		}
	}

	function logout()
	{
		// Redirect Persons to this action if they click on a Logout button.
		// All we need to do here is trash the session information:

		$this->Session->delete('Person');

		// And we should probably forward them somewhere, too...

		$this->redirect(CF_ROOT);
	}
	
	function index()
	{
		$this->checkSession();
		$this->set('data',$this->Person->getUserIndex());
	}

	function home($id = null)
	{
		$this->checkSession();
		if($id == NULL)
		{
			$id = $this->Session->read('Person.id');
		}
		$data = $this->Person->getTasks($id);
		$this->set('data',$data);
		$this->set('my_person_id',$id);
		$this->set('projects',$this->Project->generateList(null, null, null, '{n}.Project.id', '{n}.Project.name'));
		$this->pageTitle = $data['Person']['name']."'s Home";
	}

	function edit($id)
	{
		$this->checkSession();
		if (!empty($this->data))
		{
			if ($this->Person->save($this->data))
			{
				//$this->flash('Your post has been updated.','/people');
				$this->set('data',$this->data);
				$this->set('notice','Data saved');
			}
			else
			{
				$this->validateErrors();
				$this->set('data',$this->data);
				$this->set('error','Data was not saved');

			}
		}
		else
		{
			$this->Person->unbindModel(array('hasMany'=>array('Tasks')));
			$data = $this->Person->findById($id);
			$data['Person']['password'] = '';
			$this->set('data',$data);
		}
	}
}
?>
Return current item: CenterFlow