* @package common * @version $Id$ * @link http://www.zentao.net */ class common extends control { /** * The construc method, to do some auto things. * * @access public * @return void */ public function __construct() { parent::__construct(); $this->common->startSession(); $this->common->sendHeader(); $this->common->setCompany(); $this->common->setUser(); } /** * Check the user has permission to access this method, if not, locate to the login page or deny page. * * @access public * @return void */ public function checkPriv() { $module = $this->app->getModuleName(); $method = $this->app->getMethodName(); if($this->common->isOpenMethod($module, $method)) return true; if(isset($this->app->user) and $this->app->user->account == 'guest' and $this->server->php_auth_user) $this->common->identifyPhpAuth(); if(isset($this->app->user)) { if(!common::hasPriv($module, $method)) $this->common->deny($module, $method); } else { $referer = helper::safe64Encode($this->app->getURI(true)); $this->locate($this->createLink('user', 'login', "referer=$referer")); } } /** * Check the user has permisson of one method of one module. * * @param string $module * @param string $method * @static * @access public * @return bool */ public static function hasPriv($module, $method) { global $app; /* Check is the super admin or not. */ $account = ',' . $app->user->account . ','; if(strpos($app->company->admins, $account) !== false) return true; /* If not super admin, check the rights. */ $rights = $app->user->rights; if(isset($rights[strtolower($module)][strtolower($method)])) return true; return false; } /** * Replace the %s of one key of a menu by $params. * * All the menus are defined in the common's language file. But there're many dynamic params, so in the defination, * we used %s as placeholder. These %s should be setted in one module. * * The items of one module's menu may be an string or array. For example, please see module/common/lang. * * @param string $object the menus of one module * @param string $key the menu item to be replaced * @param string $params the params passed to the menu item * @access public * @return void */ public function setMenuVars($menu, $key, $params) { if(is_array($params)) { if(is_array($menu->$key)) { $menu->$key = (object)$menu->$key; $menu->$key->link = vsprintf($menu->$key->link, $params); $menu->$key = (array)$menu->$key; } else { $menu->$key = vsprintf($menu->$key, $params); } } else { if(is_array($menu->$key)) { $menu->$key = (object)$menu->$key; $menu->$key->link = sprintf($menu->$key->link, $params); $menu->$key = (array)$menu->$key; } else { $menu->$key = sprintf($menu->$key, $params); } } } /** * Print the link contains orderBy field. * * This method will auto set the orderby param according the params. Fox example, if the order by is desc, * will be changed to asc. * * @param string $fieldName the field name to sort by * @param string $orderBy the order by string * @param string $vars the vars to be passed * @param string $label the label of the link * @param string $module the module name * @param string $method the method name * @static * @access public * @return void */ public static function printOrderLink($fieldName, $orderBy, $vars, $label, $module = '', $method = '') { global $lang, $app; if(empty($module)) $module= $app->getModuleName(); if(empty($method)) $method= $app->getMethodName(); if(strpos($orderBy, $fieldName) !== false) { if(stripos($orderBy, 'desc') !== false) { $orderBy = str_ireplace('desc', 'asc', $orderBy); $className = 'headerSortUp'; } elseif(stripos($orderBy, 'asc') !== false) { $orderBy = str_ireplace('asc', 'desc', $orderBy); $className = 'headerSortDown'; } } else { $orderBy = $fieldName . '_' . 'asc'; $className = 'header'; } $link = helper::createLink($module, $method, sprintf($vars, $orderBy)); echo "