/** * 使用array建立form * * @param mix $data * @param string $action = "" * @param string $method = "post" * @param boolean $enable = true * @param boolean $show = true * @return string HTML */ public static function buildFormWithDbData($data, $action = "", $method = "post", $enable = true, $show = true, $dataDesc = array()) { //忽略列表应可动态增加 $formId = mt_rand(100, 999); $out = "<div><form id='form" . $formId . "' action=\"{$action}\" method=\"" . $method . "\" onsubmit=\"\$('{$formId}_submit_area').hide();\$('{$formId}_submit_area_mask').show();if(Tpm.Validator.checkForm(this)){return true;}else{ \$('{$formId}_submit_area_mask').hide();\$('{$formId}_submit_area').show();return false; }\">\n"; $out .= '<table class="formtable">'; if (is_array($data)) { $i = 0; foreach ($data as $key => $val) { if (self::_isIgnoreField($key)) { continue; } if ($i == 0) { $out .= "<tr>"; } elseif ($i % 2 == 0) { $out .= "</tr>\n<tr>"; } $i++; $out .= "<th class=GridTH>" . Watt_I18n::trans($key) . "</th>"; $out .= "<td>"; if ($enable) { if (strlen($val) > self::$_bigTextLen) { $out .= "<textarea cols=" . self::$_bigTextLen . " id=\"{$key}\" name=\"{$key}\" rule=\"\" ruletip=\"\">" . htmlspecialchars($val) . "</textarea>"; } else { $out .= Watt_View_Helper::buildElmentByVartype("", $key, $val, array('rule' => '', 'ruletip' => '')); //$out .= "<input type=\"text\" name=\"$key\" value=\"" // . htmlspecialchars($val) ."\" />"; } } else { $out .= htmlspecialchars($val); } $out .= "</td>"; if (key_exists($key, $dataDesc)) { $out .= "<td class=\"formdesc\">"; $out .= htmlspecialchars($dataDesc[$key]); $out .= "</td>"; } //$out .= "</tr>\n" ; } if ($i > 0) { $out .= "</tr>\n"; } if ($enable) { //$out .= "<tr><td colspan=99 align=center><input type='submit' class='btn'/> <input type='reset' class='btn'/></td></tr>\n"; $out .= "\n<tr><td colspan=99 align=center class='bottom'>\n\t<div align=\"center\" id=\"{$formId}_submit_area\">\n\t\t<input type='submit' name='Submit' value=\"" . Watt_I18n::trans('SUBMIT') . "\" class='btn'/> \n\t\t<input type='reset' value=\"" . Watt_I18n::trans('RESET') . "\" class='btn'/>\n\t\t<input type='button' class='btn' onclick=\"history.back()\" value=\"" . Watt_I18n::trans('GOBACK') . "\"/>\n\t</div>\n\t<div align='center' id='{$formId}_submit_area_mask' style='display:none' ondblclick=\"\$('{$formId}_submit_area_mask').hide();\$('{$formId}_submit_area').show();\">\n\t\t" . Watt_I18n::trans('数据提交中,请稍候...') . "\n\t</div>\n</td></tr>"; } } else { } $out .= "</table><input type='hidden' id='{$formId}_op' name='op' value='1'></form></div>\n"; if ($show) { echo $out; } return $out; }
/** * 以html的形式进行显示 * 接收的数组的定义是这样的 * * $rev[Watt_Util_Pager::PAGER_VAR_TOTAL] = $this->getTotal(); * $rev[Watt_Util_Pager::PAGER_VAR_PAGE_NUM] = $this->getPageNum(); * $rev[Watt_Util_Pager::PAGER_VAR_PAGE_COUNT] = $this->getPageCount(); * $rev[Watt_Util_Pager::PAGER_VAR_PAGE_START] = $this->getPageStart(); * $rev[Watt_Util_Pager::PAGER_VAR_PAGE_END] = $this->getPageEnd(); * $rev[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE] = $this->getPageSize(); * * * * @param array $pageInfo Watt_Util_Pager toArray 出的 Array */ public static function toHtml($pageInfo, $pageEvalString = "") { //去掉 uri中原有的 pagenum信息 // $query_string = $_SERVER['QUERY_STRING']; // $url = $_SERVER['PHP_SELF']; // $query_string = preg_replace( $match, "", $query_string ); // $uri = $url."?".urlencode( $query_string ); if ($pageEvalString == "") { $match = "/[&]?" . Watt_Util_Pager::PAGER_VAR_PAGE_NUM . "=[+-]?[0-9]*/"; $uri = preg_replace($match, "", $_SERVER['REQUEST_URI']); $pageEvalString = '"' . $uri . '&' . Watt_Util_Pager::PAGER_VAR_PAGE_NUM . '=".$pg'; } //href="javascript:gotoPage($pg)" //"javascript:setPagesize($pz)" $html = '<div class="pageinfo">'; //提供下拉列表选择 jute 20080416 $pagesize = array('5' => 5, '10' => 10, '15' => 15, '20' => 20, '50' => 50, '100' => 100, 'All' => 2147483647); //$pagesizestr = $pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE]; if (in_array($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE], $pagesize)) { } else { $pagesize[$pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE]] = $pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE]; } $pagesizestr = '<select class="search_input" name="pagesizeslect" id="pagesizeslect" onchange="if(this.options[this.selectedIndex].value == 2147483647 ){if(confirm(\'' . Watt_I18n::trans('JT_MSG_SHUJUTAIDUOSHISHUJUTAIMANYAOQUEDINGMA') . '\')){document.getElementById(\'searchFormPageSize\').value=this.options[this.selectedIndex].value;document.getElementById(\'searchform\').submit();}else{ for(var i=0;i<this.options.length;i++){if(this.options[i].value==' . $pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE] . '){this.options[i].selected=true;}};return false;}}else{document.getElementById(\'searchFormPageSize\').value=this.options[this.selectedIndex].value;document.getElementById(\'searchform\').submit();}">'; foreach ($pagesize as $key => $val) { $check_str = ""; if ($val == $pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_SIZE]) { $check_str = "selected"; } $pagesizestr .= '<option value="' . $val . '" ' . $check_str . ' >' . $key . '</option>'; } $pagesizestr .= '</select>'; $html .= "" . Watt_I18n::trans('PAGE') . " {$pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_NUM]}/{$pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_COUNT]} | " . "{$pagesizestr}/" . Watt_I18n::trans('PAGE') . " | {$pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_START]} " . "- {$pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_END]} " . Watt_I18n::trans('PAGE_OF') . " {$pageInfo[Watt_Util_Pager::PAGER_VAR_TOTAL]}"; if ($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_COUNT] > 1) { $pagerString = self::_getUrlInfo(1, $pageEvalString); $html .= " <a class=\"pagenavigator\" href=\"{$pagerString}\">|<</a>"; $pagerString = self::_getUrlInfo($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_NUM] - 1, $pageEvalString); $html .= " <a class=\"pagenavigator\" href=\"{$pagerString}\"><</a>"; $pagerString = self::_getUrlInfo($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_NUM] + 1, $pageEvalString); $html .= " <a class=\"pagenavigator\" href=\"{$pagerString}\">></a>"; $pagerString = self::_getUrlInfo($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_COUNT], $pageEvalString); $html .= " <a class=\"pagenavigator\" href=\"{$pagerString}\">>|</a>"; $pagerString = self::_getUrlInfo("\$('" . Watt_Util_Pager::PAGER_VAR_PAGE_GOTONUM . "').value", $pageEvalString); $html .= " <input id=\"" . Watt_Util_Pager::PAGER_VAR_PAGE_GOTONUM . "\" size=\"1\">"; $html .= " <a class=\"pagenavigator\" href=\"{$pagerString}\">" . Watt_I18n::trans('PAGE_GOTO') . "</a>"; } // $html .= "<a class=\"pagenavigator\" href=\"{$uri}&".Watt_Util_Pager::PAGER_VAR_PAGE_NUM."=1\">first</a>"; // $html .= " <a class=\"pagenavigator\" href=\"{$uri}&".Watt_Util_Pager::PAGER_VAR_PAGE_NUM."=".($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_NUM]-1)."\"\">prev</a>"; // $html .= " <a class=\"pagenavigator\" href=\"{$uri}&".Watt_Util_Pager::PAGER_VAR_PAGE_NUM."=".($pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_NUM]+1)."\"\">next</a>"; // $html .= " <a class=\"pagenavigator\" href=\"{$uri}&".Watt_Util_Pager::PAGER_VAR_PAGE_NUM."=".$pageInfo[Watt_Util_Pager::PAGER_VAR_PAGE_COUNT]."\"\">last</a>"; $html .= "</div>"; return $html; }
/** * 说明 * 语种 */ private function language_type() { $this->z_language = array('高级检索' => Watt_I18n::trans('DBGRID_GAOJIJIANSUO'), '首页' => Watt_I18n::trans('DBGRID_SHOUYE'), '上一页' => Watt_I18n::trans('DBGRID_SHANGYIYE'), '下一页' => Watt_I18n::trans('DBGRID_XIAYIYE'), '尾页' => Watt_I18n::trans('DBGRID_WEIYE'), '页' => Watt_I18n::trans('DBGRID_YE'), '共' => Watt_I18n::trans('DBGRID_GONG'), '项' => Watt_I18n::trans('DBGRID_XIANG'), '跳转到' => Watt_I18n::trans('DBGRID_TIAOZHUANDAO'), '每页' => Watt_I18n::trans('DBGRID_MEIYE'), '返回初始状态' => Watt_I18n::trans('DBGRID_CHUSHI'), '隐藏检索' => Watt_I18n::trans('DBGRID_YCJIANSUO'), '精确查询' => Watt_I18n::trans('DBGRID_JQCHAXUN'), '关联查询' => Watt_I18n::trans('DBGRID_GLCHAXUN'), '检索时间格式' => Watt_I18n::trans('DBGRID_JSSHIJIANGESHI'), '检索' => Watt_I18n::trans('DBGRID_JIANSUO'), '从' => Watt_I18n::trans('DBGRID_CONG'), '到' => Watt_I18n::trans('DBGRID_DAO'), '小计' => Watt_I18n::trans('小计'), '合计' => Watt_I18n::trans('合计')); /*$this -> z_language = array( '高级检索' => '高级检索', '首页' => '首页', '上一页' => '上一页', '下一页' => '下一页', '尾页' => '尾页', '页' => '页', '共' => '共', '项' => '项', '跳转到' => '跳转到', '每页' => '每页', '返回初始状态' => '返回初始状态', '隐藏检索' => '隐藏检索', '精确查询' => '精确查询', '关联查询' => '关联查询', '检索时间格式' => '检索时间格式', '检索' => '检索', '从' => '从', '到' => '到' );*/ /*$this -> z_language = array( '高级检索' => '高级检索', '首页' => 'first', '上一页' => 'pre', '下一页' => 'next', '尾页' => 'last', '页' => 'page', '共' => 'together', '项' => 'item', '跳转到' => 'jump', '每页' => 'page', '返回初始状态' => '返回初始状态', '隐藏检索' => '隐藏检索', '精确查询' => '精确查询', '关联查询' => '关联查询', '检索时间格式' => '检索时间格式', '检索' => '检索', '从' => '从', '到' => '到' );*/ }
public function notice($alertType, $msg) { $msg .= ' ' . date('Y-m-d H:i:s'); $recerverlist = $this->getReceiverList($alertType); if (is_array($recerverlist)) { foreach ($recerverlist as $type => $recerver) { switch ($type) { case self::NOTICE_TYPE_MAIL: $rev = Watt_Util_Msg_Mail::sendMail($recerver, Watt_I18n::trans("JT_OTHER_TONGBUJIANKONGFAXIAOXI"), $msg); Watt_Log::addLog("Notice [{$msg}] to [{$recerver}] and rev [{$rev}]"); break; case self::MOTICE_TYPE_SMS: $rev = Watt_Util_Msg_Sms::sendSms($recerver, $msg); Watt_Log::addLog("Notice [{$msg}] to [{$recerver}] and rev [{$rev}]"); break; } } } else { Watt_Log::addLog("Notice [{$msg}] to Nobody!"); } }
public static final function factory($controllerAndActionName) { //$toFile = Watt_Config::getAppPath() . $controllerAndActionName . ".php"; $toFile = Watt_Config::getAbsPathFilename("PATH_APP", $controllerAndActionName . ".php"); $arrTmp = array_map("ucfirst", explode(DIRECTORY_SEPARATOR, $controllerAndActionName)); $className = ucfirst(implode("", $arrTmp)) . "Controller"; /* 这里要适应变化 通过上面的代码改成一个controller多个action的形式 //这种形式要求 conntroller $toFile = PATH_APP . $controllerAndActionName . DIRECTORY_SEPARATOR . $actionName . ".php"; $arrTmp = array_map("ucfirst", explode( DIRECTORY_SEPARATOR, $controllerAndActionName) ); $className = ucfirst(implode("",$arrTmp)).ucfirst($actionName)."Controller"; */ if (DEBUG) { include_once $toFile; } else { @(include_once $toFile); } //Watt::loadFile( $toFile ); if (class_exists($className)) { $class = new $className(); $class->setScriptFile($toFile); //$class->_autoGetControllerName(); $class->setControllerName(str_replace(DIRECTORY_SEPARATOR, "_", $controllerAndActionName)); //自动获取名称不够准确,只能继续使用第二种方法 by terry at Mon Jul 13 11:03:22 CST 2009 $class->setControllerPrivilegeMaps(); return $class; } else { throw new Exception(Watt_I18n::trans("ERR_APP_LOST_CONTROLLER") . "[ " . $className . " ]"); //return null; } }
/** * 功能:计算周期 * 传入两个时间,计算周期 * Tony---Fri Mar 16 16:29:09 CST 2007----16:29:09 * $bs为真时不返回字体设置,导出报表时用 jute 20080416 */ public static function getTimeZhouqi($min_time, $max_time, $bs = false) { $error = $min_time ? '' : self::ZHQ_START_TIME; $error .= $max_time ? '' : self::ZHQ_END_TIME; if (!$error) { $day = ($max_time - $min_time) / 86400; if (abs($day) > 1) { $ret = round($day) . Watt_I18n::trans('TY_TIAN'); } elseif (abs(($max_time - $min_time) / 3600) > 1) { $ret = round(($max_time - $min_time) / 3600) . Watt_I18n::trans('TY_XIAOSHI'); } else { $ret = ($max_time - $min_time > 0 ? '' : '-') . '0.1' . Watt_I18n::trans('TY_XIAOSHI'); } } else { $ret = $error; } if ($max_time < $min_time && !$bs) { $ret = '<font color="red">' . $ret . '</font>'; } return $ret; }
/** * 根据符合Watt:Data里的 Grid 的Schema 的数据创建一个HTML的 Grid显示 * * @param unknown_type $gridData */ public static function buildGrid($grid, $show = true) { //这里判断数据是否符合规则 //将来要根据 Shema 判断 if (!is_array($grid)) { $e = new Watt_Exception(Watt_I18n::trans("ERR_INVALID_DATATYPE")); throw $e; } if (isset($grid[Watt_Util_Grid::GRID_SCHEMA_COLS]) && count($grid[Watt_Util_Grid::GRID_SCHEMA_COLS]) > 0) { $isDefCols = true; $cols = $grid[Watt_Util_Grid::GRID_SCHEMA_COLS]; } else { $isDefCols = false; } $datas = $grid[Watt_Util_Grid::GRID_SCHEMA_DATAS]; $out = '<table border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">'; if ($isDefCols) { $out .= "<tr>"; foreach ($cols as $col) { $out .= "<th class=GridTH>" . $col["title"] . "</th>"; } $out .= "</tr>\n"; } foreach ($datas as $row) { $out .= "<tr>"; if ($isDefCols) { reset($cols); foreach ($cols as $col) { if (isset($col["isext"]) && $col["isext"]) { if (isset($col["render"]) && trim($col["render"]) != "") { //每个row都分析了一次render,这里要优化!! preg_match_all("/\\{([\\w]+)\\}/i", $col["render"], $matchs); if (is_array($matchs[1])) { $tmpLink = $col["render"]; foreach ($matchs[1] as $tmpColName) { $tmpLink = str_replace("{" . $tmpColName . "}", $row[$tmpColName], $tmpLink); } $showText = $tmpLink; } } } else { $orignText = $row[$col["colname"]]; $showText = $orignText; if (trim($orignText) != "") { //只有 $colContent 有值才处理 //处理回调函数 if (isset($col["callback"]) && trim($col["callback"]) != "") { $callBack = str_replace("{me}", $orignText, $col["callback"]); eval("\$showText={$callBack};"); } if (isset($col["render"]) && trim($col["render"]) != "") { //每个row都分析了一次render,这里要优化!! preg_match_all("/\\{([\\w]+)\\}/i", $col["render"], $matchs); if (is_array($matchs[1])) { $tmpLink = $col["render"]; foreach ($matchs[1] as $tmpColName) { $tmpLink = str_replace("{" . $tmpColName . "}", $row[$tmpColName], $tmpLink); } $showText = $tmpLink; } } elseif (isset($col["linkto"]) && trim($col["linkto"]) != "") { //有了render,就不用linkto了.. //处理链接 //此处与HTML联系,现在也想不清楚了,将来再改进吧.. //echo __FILE__.__LINE__.$col["linkto"]; preg_match_all("/\\{([\\w]+)\\}/i", $col["linkto"], $matchs); if (is_array($matchs[1])) { $tmpLink = $col["linkto"]; foreach ($matchs[1] as $tmpColName) { $tmpLink = str_replace("{" . $tmpColName . "}", $row[$tmpColName], $tmpLink); } $showText = "<a href=\"{$tmpLink}\">" . $showText . "</a>"; } } } } $out .= "<td>" . $showText . "</td>"; } } else { foreach ($row as $col) { $out .= "<td>" . $col . "</td>"; } } $out .= "</tr>\n"; } $out .= "</table>\n"; if ($show) { echo $out; } return $out; }
function setAlias($alias) { if (!$alias) { //因为数据库字段的 语言键值是小写的,所以用 strtolower转化一下 $alias = strtolower(preg_replace("/^[\\w]+\\./", "", $this->_dbColName)); $alias = Watt_I18n::trans($alias); } $this->_alias = $alias; }
/** * __get * * @param string $nm * @return mix */ function __get($nm) { if (isset($this->_data[$nm])) { $r = $this->_data[$nm]; return $r; } else { $e = new Watt_Exception(Watt_I18n::trans("ERR_VIEW_NODATA")); throw $e; return ""; } }
<td>产品图片</td> <td><div id="imgDiv"></div></td> <td><span id="pImg"></span></td> </tr> <tr> <td>产品说明</td> <td><textarea id="p_info" name="p_info" rows="2" cols="30"></textarea></td> <td><span id="pInfo"></span></td> </tr> <tr> <td colspan="3" align="center"> <div id="ajaxProductDiv" style="display:none"></div> <input type="submit" style="display:none" id="Submit"> <input type="hidden" name="op" value="1"> <input type="button" id="s_Submit" value="<?php echo Watt_I18n::trans("保存"); ?> "> </td> </tr> </table> </form> </div> </div> </div> </td> <td width="30%" height="400px" valign="top" class="_grid _td"> <div class="pDiv"> <div id="pFenlei"> <div> 产品分类
/** * tabs扩展 * 增加了 回复删除 * john 2007-2-12 */ public static function buildplus($tabs_arr, $show = true) { $out = ""; $out .= "<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>"; $out .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>"; foreach ($tabs_arr as $tabs_info => $tabs_keys) { //默认选中 $tabs_keys_arr = parse_url($tabs_keys); if (isset($tabs_keys_arr['query'])) { $path_arr = explode("&", $tabs_keys_arr['query']); $do_arr = explode("=", $path_arr[0]); } // if( $tabs_info == $_GET['tabs_name']) // { // $tabs_css="tabs_down"; // $onmouseout_css="tabs_down"; // $onmouseover_css="tabs_down"; // } // else if (isset($do_arr[1]) && $do_arr[1] == $_GET['do']) { $tabs_css = "tabs_down"; $onmouseout_css = "tabs_down"; $onmouseover_css = "tabs_down"; } else { $tabs_css = "tabs"; $onmouseout_css = "tabs"; $onmouseover_css = "tabs_hover"; } $out .= "<td nowrap=\"nowrap\" class=\"" . $tabs_css . "\" onclick=\"javascript:location.href='" . $tabs_keys . "'\" onmouseover=\"this.className='" . $onmouseover_css . "'\" onmouseout=\"this.className='" . $onmouseout_css . "'\" onmousedown=\"this.className='tabs'\">" . $tabs_info . "</td>"; } $out .= "</tr></table>"; $out .= "</td><td align='right' style='cursor:pointer'><span onclick='huifushanchu();'>" . Watt_I18n::trans('RES_ZIYUAN_HUIFUJINYONG') . "</span></td></tr></table>"; if ($show) { echo $out; } return $out; }
/** * 检查 某个 会话是否具有访问某个 controller 的 某个 action 的权限 * 如果没有权限,则抛出一个异常 * * @param WATT_SESSION $session * @param Watt_Controller_Action $ctrlObj * @param string $actionName * @return boolean|TpmQuanxian */ public static function checkActionPrivilege(WATT_SESSION $session, Watt_Controller_Action $ctrlObj, $actionName) { /** * 危险的东西 * 免登陆 * @author terry */ /** * 注释掉了 * @author terry * @version 0.1.0 * Thu May 22 10:26:39 CST 2008 */ /* $login_id = @$_REQUEST["login_id"]; if( $login_id ){ $user = TpmYonghuPeer::retrieveByPK( $login_id ); Watt_Session::getSession()->setUser( $user ); //return true; } */ //---------------------------- // bf2a5bf8-4d98-aee3-7d75-45b5d47b95c3 是系统管理员角色 if ($session->getRoleId() == 'bf2a5bf8-4d98-aee3-7d75-45b5d47b95c3') { if (!defined('ADMIN')) { define('ADMIN', true); } } //如果return true,则拥有所有权限 //return true; /** * 暂时取消权限验证 2007-1-16 */ $rev = false; if ($ctrlObj->isPublic()) { $rev = true; } elseif ($ctrlObj->isActionPublic($actionName)) { $rev = true; } elseif ($session->getUserId()) { //echo $ctrlObj->getActionLevel( $actionName); if (self::LEVEL_LOGIN == $ctrlObj->getActionLevel($actionName)) { $rev = true; } else { //这里进行针对 action 的权限校验 //$privilege_do = $ctrlObj->getControllerName()."_".$actionName; $privilege_do = $ctrlObj->getMappingedPrivilegeByAction($actionName); //$rev = TpmQuanxianPeer::jianchaYonghuQuanxian($session->getUserId(), $privilege_do); $rev = TpmQuanxianPeer::jianchaJueseQuanxian($session->getRoleId(), $privilege_do); /** * 全注释是不检验action权限,也就是最高登录权限 * @todo 外部配置检验级别 * @author terry * @version 0.1.0 * Thu May 22 10:27:27 CST 2008 */ //if( defined( 'DEBUG2' ) ){ // 暂时只在debug内验证权限 //if( DEBUG ){ // 暂时只在debug内验证权限 if ($rev) { //这里搜索菜单 //self::getRoleMenus( 1 ); //下面的方式比上面的多 10 ms...研究 //TpmMenuPeer::getRoleMenus( 1 ); } else { $rev = false; throw new Watt_Exception(Watt_I18n::trans("EXCEPTION_NO_PRIVILEGE"), Watt_Exception::EXCEPTION_NO_PRIVILEGE); } //} } } else { Watt_Session::getSession()->recordCurrentVisitPage(); $rev = false; throw new Watt_Exception(Watt_I18n::trans("EXCEPTION_NEED_LOGIN"), Watt_Exception::EXCEPTION_NEED_LOGIN); } return $rev; }
/** * 根据 GridData render一下 * */ private static function _getRenderedDataByGridData($datas, $cols = null) { $output_arr = array(); if (is_array($datas)) { $showText = ""; if ($cols) { foreach ($datas as $rowKey => $row) { $row_arr = array(); if (!is_array($row)) { continue; } reset($cols); $colNum = 0; foreach ($cols as $colKey => $col) { /** * 增加对合计的处理 * @author terry * @version 0.1.0 * Wed Oct 10 19:11:55 CST 2007 */ if ($rowKey === Watt_Util_Grid_Searchs::DEF_SUM || $rowKey === Watt_Util_Grid_Searchs::DEF_TOTAL) { //注意,这里要用 === ,否则第一行会出错 if ($colNum == 0) { $showText = '<b>' . Watt_I18n::trans($rowKey) . '</b>'; } else { if (@$row[$col["colname"]] && isset($col["render"]) && $col["render"] != "") { //有值才显示 $showText = ""; eval('$showText = ' . $col["render"] . ';'); } else { $showText = '<b>' . htmlspecialchars(@$row[$col["colname"]]) . '</b>'; } } } else { if (isset($col["render"]) && $col["render"] != "") { $showText = ""; eval('$showText = ' . $col["render"] . ';'); if (@$_REQUEST['debug_z']) { print "<pre>"; print_r($showText); print "</pre>"; } } else { if (isset($col["colname"])) { $showText = htmlspecialchars(@$row[$col["colname"]]); } else { $showText = ""; } } } $row_arr[] = $showText; $colNum++; } $output_arr[] = $row_arr; } } else { $output_arr = $datas; } } return $output_arr; }
/** * 处理 do * 有可能会返回 goToDo * * 只有一个单词的do,对应的action是 index * * * @param string $do * @return string $goToDo */ protected function processDo($do, $defaultView = "Html") { if ($do == "") { $e = new Watt_Exception(Watt_I18n::trans("ERR_DISPATCH_NODO")); throw $e; } $goToDo = ""; $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do); $controller = $arrCtrlAndAction[0]; $action = $arrCtrlAndAction[1]; $doFile = $arrCtrlAndAction[2]; $doAction = $arrCtrlAndAction[3]; //exit( $doFile . "|" . $doAction ); //使用 ob_start 是为了Controller里的 redirect 可以正常使用 if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) { /** * 为了不让服务器过长等待时间,改为不启用Ctrl Buffer * @author terry * @version 0.1.0 * Mon Jan 14 14:41:39 CST 2008 */ ob_start(); } /** * 增加了对页面缓存的支持 */ $cache = null; Watt_Debug::addInfoToDefault('Begin create action [' . $controller . '] [' . $action . ']'); $theCtrl = Watt_Controller_Action::factory($controller, $action); Watt_Debug::addInfoToDefault('After create action'); $viewMenu = isset($_REQUEST["view_menu"]) ? trim($_REQUEST["view_menu"]) == '0' ? false : true : true; $theCtrl->setNeedMenu($viewMenu); $actionCacheTime = $theCtrl->getActionCacheTime($action); if ($actionCacheTime > 0) { $cache = new Watt_Cache($actionCacheTime); if ($cache->cacheCheck()) { //如果符合缓存条件,则会读取缓存文件,并 exit. /** * 改为退出处理,为了记录页面执行时间。 * 这里一定不能 return true. * @author terry * @version 0.1.0 * Mon Jan 14 14:30:43 CST 2008 */ return ''; } } /** * 检查 会话的权限。 * 如果没有权限,抛出一个异常 * 此处别扭 */ $rbac = new Watt_Rbac(); //$rbac->checkSession(Watt_Session::getSession(), $do); $privilege = $rbac->checkActionPrivilege(Watt_Session::getSession(), $theCtrl, $action); if (is_object($privilege) && $privilege instanceof TpmYonghuzhaoquanxian) { if (!$theCtrl->getTitle()) { $theCtrl->setTitle(Watt_I18n::trans($privilege->getQxMingcheng())); } } Watt_Debug::addInfoToDefault('', 'Pre do action..'); if (method_exists($theCtrl, $doAction)) { //执行controller中的action $theCtrl->{$doAction}(); } else { throw new Exception(Watt_I18n::trans("ERR_APP_LOST_ACTION")); } Watt_Debug::addInfoToDefault('', 'After do action..'); $goToDo = $theCtrl->getGoToDo(); $data = $theCtrl->getData(); /** * 改为对 Ctrl 不进行 Buffer 的处理 * @author terry * @version 0.1.0 * Mon Jan 14 15:05:28 CST 2008 */ if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) { if (defined("DEBUG") && DEBUG) { //调试阶段才显示Controller里输出的信息 echo ob_get_clean(); } else { //用户使用阶段不允许 action 里输出显示数据 ob_clean(); } } if ($theCtrl->isNeedView()) { Watt_Debug::addInfoToDefault('', 'Pre load view..'); if ($theCtrl->getViewType()) { $defaultView = $theCtrl->getViewType(); } /** * 创建一个View。将来可以用不同的View代替此View */ //$view = Watt_View::factory( "Html", Watt_Config::getViewPath() ); $view = Watt_View::factory($defaultView, Watt_Config::getViewPath()); $view->setHeader($theCtrl->getHeader()); Watt_Debug::addInfoToDefault('', 'After view factory..'); /** * 读取菜单应该由View来判断 * @author terry * Thu Jul 22 10:46:07 CST 2010 */ if ($theCtrl->isNeedMenu() && strtolower($defaultView) == 'html') { //$theCtrl->isNeedCaidan(); /** * 如果用户已登录,读取菜单信息 * @todo 未登录可能也可以有菜单 */ if ($user_id = Watt_Session::getSession()->getUserId()) { $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Watt_Session::getSession()->getRoleId()); if (count($tpmCaidans)) { $view->setHeader($tpmCaidans, "menu"); } } //读取菜单完 } //$view->renderModel($theCtrl); $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true); } /** * 与开始的Cache对应 */ if ($actionCacheTime > 0 && $cache instanceof Watt_Cache) { $cache->caching(); } return $goToDo; }
public static function buildMenuEx($data, $show = true) { //没调好 先藏掉 //Terry //return ""; $xhtml = ""; if (is_array($data)) { $menu_arr = self::sortMenu($data); $roleId = Watt_Session::getSession()->getRoleId(); $crSessionRoleId = array('6b32ff50-df19-4e07-d50c-45b6b62bc171' => 'CR', '2798de2b-30bf-9dcb-22cd-45b6b68b315e' => 'TR', '4ade1c61-fac6-8f11-4200-466fa0a2c627' => 'CR', '61c705eb-0cde-4867-3211-45b6b6753d4d' => 'PR'); // if( key_exists( $roleId, $crSessionRoleId ) ){ // $xhtml .= "<link rel=\"stylesheet\" href=\"{$this->_menu_lib_path}xqtrmenu.css\">"; // }else{ // $xhtml .= "<link rel=\"stylesheet\" href=\"{$this->_menu_lib_path}xqmenu.css\">"; // } $xhtml = '<div id="mainmenu" style="" onmouseout="this.style.left=\'-118px\'" onmouseover="$(\'mainmenu\').style.left=\'0px\'">' . "\n"; // $xhtml .= '<ul>'; // foreach ( $data as $key=>$val) // { // $xhtml .= '<li><a href="'.$val[1].'">'.$val[0].'</a></li>'."\n"; // } // $xhtml .= '</ul>'; // 结束 if (Watt_Session::getSession()->getSession()->getRoleShortname() == 'CR') { $xhtml .= "<div class='quick_order'>"; if (Watt_Session::getSession()->isTq()) { $xhtml .= "<a TQCmd='CmdType=CallOrder' id='TQCmdTag_CallOrder' style='cursor:hand;' TQFileType=\"" . Watt_I18n::trans("EC_PUBLIC_FILETYPES_LIST") . "\">" . Watt_I18n::trans('快速下单') . "</a>"; } else { //$xhtml .= "<a id='TQCmdTag_CallOrder' style='cursor:hand;' href='?do=ec_dingdan_add'\">".Watt_I18n::trans('快速下单')."</a>"; $xhtml .= "<a id='TQCmdTag_CallOrder' style='cursor:hand;' href='?do=twftpm_start_startNewFlowAndExecute&lclx_id=16'\">" . Watt_I18n::trans('快速下单') . "</a>"; } $xhtml .= '</div>'; } $xhtml .= '<div class="cls"></div>' . "\n"; $xhtml .= '<div style="float:left;width:117px;background-color:#FFF;">' . "\n"; $xhtml .= self::_buildMenuArr($menu_arr, 'menulist'); $xhtml .= '</div>' . "\n"; $xhtml .= '<div class="cls"></div>' . "\n"; $xhtml .= '</div>'; // echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Thu Jul 17 11:48:15 CST 2008] :\n "; // var_dump( $menu_arr ); // echo "</pre>"; // exit(); } if ($show) { echo $xhtml; } return $xhtml; }