<?php
/**
 * pph_is_goal_editor.php - Unit module pre-process handle for determine is current user the goal editor.
 * 								 This one includes goal team members. This means team members has edit access too.
 *
 * @author $Author: dtong $
 * @version $Id: pph_is_goal_editor.php,v 1.6 2011/05/10 16:11:55 dtong Exp $
 * @copyright Copyright (c) 2010, Tiller Software Co., Ltd.
*/
require_once('pph_base.php');

class pph_is_goal_editor extends pph_base {

	function process(&$stage, $stagenum, $meta_flag, $params) {
		if ($this->is_edit_goal($params->unitid) || $this->access_readonly())
			return TRUE;
		else
			return FALSE;
	}
	private function is_edit_goal($goalid){
		if ( !is_numeric($goalid) )
			return FALSE;
		$this->CI->load->model('goal/goal_model');
		if ($this->CI->goal_model->is_edit_goal($goalid) || $this->CI->goal_model->is_goal_member($goalid))
			return TRUE;
		return FALSE;
	}
	private function access_readonly(){
		return $this->CI->access_model->checkaccess_any('admin_goal_readonly',FALSE,FALSE,FALSE);
	}

}