private function _getCommonHtml() { $out = ""; if (!self::$_isBuildedCommonJs) { self::$_isBuildedCommonJs = true; $out = '<link rel="stylesheet" type="text/css" media="all" href="' . $this->_calendar_lib_path . $this->_calendar_theme_file . '.css" />'; $out .= '<script type="text/javascript" src="' . $this->_calendar_lib_path . 'calendar.js"></script>'; $out .= '<script type="text/javascript" src="' . $this->_calendar_lib_path . 'lang/calendar-en.js"></script>'; $out .= '<script type="text/javascript" src="' . $this->_calendar_lib_path . 'calendar-setup.js"></script>'; /* if (Watt_Session::getSession()->getlanguage() == 'en') { $out .= '<script type="text/javascript" src="'.$this->_calendar_lib_path_new.'lang/calendar-en.js"></script>'; }else{ $out .= '<script type="text/javascript" src="'.$this->_calendar_lib_path_new.'lang/calendar-cn.js"></script>'; } $out .= '<script type="text/javascript" src="'.$this->_calendar_lib_path_new.'calendar.js"></script>'; */ } return $out; }
/** * buildGridToOutArray副本 * * @param unknown_type $grid * @param unknown_type $params * @param unknown_type $searchCols * @return unknown */ public static function buildGridToOutArrayBack($grid, $params = "", $searchCols = 4) { /** * 这里判断数据是否符合规则 * 应该根据 Shema 判断 */ if (!is_array($grid)) { $e = new Watt_Exception(Watt_I18n::trans("ERR_INVALID_DATATYPE")); throw $e; } if (is_array($params)) { $gridId = @$params['id']; $formAttribs = @$params['formAttribs']; } else { $formAttribs = $params; $gridId = null; } //随机生成一个 search form 的id //$specSearchFormId = mt_rand( 10000, 99999 ); /** * 用来记录orderby了的字段和orderbyorder */ $orderByCols = array(); 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; $cols = null; } $datas = $grid[Watt_Util_Grid::GRID_SCHEMA_DATAS]; $output_searchs = ""; /** * 开始输出查询信息 */ $output_searchs .= '<form method="get" action="' . $_SERVER['PHP_SELF'] . '" id="searchform" ' . $formAttribs . ' onsubmit="if($(\'searchFormPageTotal\')){$(\'searchFormPageTotal\').value=\'\';}">'; //初始化参数 $initParams = $grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS][Watt_Util_Grid_Searchs::DEF_INITPARAMS]; foreach ($initParams as $initKey => $initValue) { $output_searchs .= '<input type="hidden" name="' . $initKey . '" value="' . h($initValue) . '">'; $output_searchs .= '<input type="hidden" name="' . Watt_Util_Grid_Searchs::INIT_PARAM_NAME . '[]" value="' . h($initKey) . '">'; } if (isset($grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS]) && is_array($grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS]) || isset($grid[Watt_Util_Grid::GRID_SCHEMA_PAGER]) && is_array($grid[Watt_Util_Grid::GRID_SCHEMA_PAGER]) || isset($grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS]) && is_array($grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS])) { $output_searchs .= '<div class="search_container">' . "\n"; //$output_searchs .= '<div class="search"><form method="post" id="searchform" '.$formAttribs.'>'; /* 070322 暂时给演示注销*/ $output_searchs .= '<div class="search">'; /* $output_searchs .= '<input type="hidden" name="do" value="'.$_REQUEST['do'].'">'; */ //var_dump( $grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS] ); $SCHEMA_SEARCHS = $grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS]; $output_searchs .= '<div class="grid">'; //$output_searchs .= '<div style="float:left;width:33%">'; //高级搜索 //if( isset( $grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS][Watt_Util_Grid_Searchs::SEARCH_ADV_SIGN] ) ){ if (key_exists(Watt_Util_Grid_Searchs::SEARCH_ADV_SIGN, $SCHEMA_SEARCHS)) { $advSign = $SCHEMA_SEARCHS[Watt_Util_Grid_Searchs::SEARCH_ADV_SIGN]; $output_searchs .= '<input name="' . Watt_Util_Grid_Searchs::SEARCH_ADV_SIGN . '" id="' . Watt_Util_Grid_Searchs::SEARCH_ADV_SIGN . '" value="' . h($advSign) . '">'; } $searchs = $grid[Watt_Util_Grid::GRID_SCHEMA_SEARCHS][Watt_Util_Grid_Searchs::DEF_SEARCHS]; //$output_searchs .= '高级</div>'; $output_searchs .= '</div>'; $searchsCounter = 0; $output_searchs .= '<div id="search_searchs" style="clear:both">'; $output_searchs .= '<table><tr>'; foreach ($searchs as $search) { $opration = $search[Watt_Util_Grid_Search::DEF_OPERATION]; if ($opration == Watt_Util_Grid_Searchs::LIKE) { $oprationTip = i18ntrans('#模糊匹配'); } elseif ($opration == Watt_Util_Grid_Searchs::EQUAL || $opration == Watt_Util_Grid_Searchs::IN) { $oprationTip = i18ntrans('#精确匹配'); } else { $oprationTip = sprintf(i18ntrans('#规则为(%s)'), $opration); } //$output_searchs .= '<div style="float:left;width:200px;text-align:right;">'; $output_searchs .= '<td class="search_name">'; $output_searchs .= '<span class="search_name" title="' . $oprationTip . '">' . $search[Watt_Util_Grid_Search::DEF_TITLE] . ': </span>'; $output_searchs .= '</td><td style="text-align:left">'; if (is_array($search[Watt_Util_Grid_Search::DEF_REFERENCE])) { //这里用下拉列表显示 $output_searchs .= '<select class="search_input" name="' . $search[Watt_Util_Grid_Search::DEF_COLNAME] . '" id="' . $search[Watt_Util_Grid_Search::DEF_COLNAME] . '">'; $output_searchs .= '<option> </option>'; foreach ($search[Watt_Util_Grid_Search::DEF_REFERENCE] as $key => $value) { $selSign = $key == $search[Watt_Util_Grid_Search::DEF_VALUE] && $search[Watt_Util_Grid_Search::DEF_VALUE] !== '' && !is_null($search[Watt_Util_Grid_Search::DEF_VALUE]) ? "selected" : ""; $output_searchs .= '<option value="' . htmlspecialchars($key) . '" ' . $selSign . '>' . htmlspecialchars($value) . '</option>'; } $output_searchs .= ''; $output_searchs .= '</select>'; } else { switch ($search[Watt_Util_Grid_Search::DEF_SHOWTYPE]) { case Watt_Util_Grid_Search::SHOW_TYPE_DATE: $dateselector = new Watt_View_Helper_DateSelector(); $output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME], $search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'dateselector')); break; case Watt_Util_Grid_Search::SHOW_TYPE_TIMESTAMP: $dateselector = new Watt_View_Helper_DateSelector(); $dateselector->setShowTimes(true); $output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME], $search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'dateselector')); break; case Watt_Util_Grid_Search::SHOW_TYPE_TIMESEC: $dateselector = new Watt_View_Helper_DateSelector(); $dateselector->setShowTimeSecs(true); $output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME], $search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'dateselector')); break; case Watt_Util_Grid_Search::SHOW_TYPE_SELECTOR_PERSON: $dateselector = new Watt_View_Helper_PersonSelector(); $output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME], $search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'personselector')); break; case Watt_Util_Grid_Search::SHOW_TYPE_SELECTOR_DINGDAN: $dateselector = new Watt_View_Helper_DingdanSelector(); $output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME], $search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'dingdanselector')); break; case Watt_Util_Grid_Search::SHOW_TYPE_SEARCHTIP: //此功能尚未完善,暂时屏蔽 //$dateselector = new Watt_View_Helper_SearchTip(); //$output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME],$search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'search_input'),null,$search[Watt_Util_Grid_Search::DEF_EXTEND]); //break; //此功能尚未完善,暂时屏蔽 //$dateselector = new Watt_View_Helper_SearchTip(); //$output_searchs .= $dateselector->build($search[Watt_Util_Grid_Search::DEF_COLNAME],$search[Watt_Util_Grid_Search::DEF_VALUE], array('class' => 'search_input'),null,$search[Watt_Util_Grid_Search::DEF_EXTEND]); //break; default: $output_searchs .= '<input class="search_input" name="' . $search[Watt_Util_Grid_Search::DEF_COLNAME] . '" id="' . $search[Watt_Util_Grid_Search::DEF_COLNAME] . '" value="' . h($search[Watt_Util_Grid_Search::DEF_VALUE]) . '">' . "\n"; } } $output_searchs .= '</td>'; //$output_searchs .= '</div>'; $searchsCounter++; if ($searchsCounter > 0 && $searchsCounter % $searchCols == 0) { $output_searchs .= '</tr><tr>'; } } if (count($searchs)) { //如果没有修改搜索条件,不会影响总记录的条数 $output_searchs .= '<td colspan="' . ($searchCols - $searchsCounter % $searchCols) * 2 . '"> <div style="clear:both;text-align:center"> <input type="submit" id="searchFormSubmit" value="' . Watt_I18n::trans("SEARCH") . '" class="btn"> </div> </td>' . "\n"; } $output_searchs .= '</tr></table>'; //$output_searchs .= '<div style="clear:both"> </div>'; $output_searchs .= '</div>'; /** * 如果有排序定义,输出排序表单域 */ if (is_array($grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS]) && count($grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS][Watt_Util_Grid_Searchs::DEF_ORDERBYS])) { $output_searchs .= '<input type="hidden" name="' . Watt_Util_Grid_Searchs::DEF_ORDERBYS . '" id="searchFormOrderBy" value="' . $grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS][Watt_Util_Grid_Searchs::DEF_ORDERBYS][0] . '">'; $output_searchs .= '<input type="hidden" name="' . Watt_Util_Grid_Searchs::DEF_ORDERBYORDERS . '" id="searchFormOrderByOrder" value="' . $grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS][Watt_Util_Grid_Searchs::DEF_ORDERBYORDERS][0] . '">'; $orderByCols[$grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS][Watt_Util_Grid_Searchs::DEF_ORDERBYS][0]] = $grid[Watt_Util_Grid::GRID_SCHEMA_ORDERBYS][Watt_Util_Grid_Searchs::DEF_ORDERBYORDERS][0] == Watt_Util_Grid_Searchs::DESC ? "↓" : "↑"; } else { $output_searchs .= '<input type="hidden" name="' . Watt_Util_Grid_Searchs::DEF_ORDERBYS . '" id="searchFormOrderBy" value="">' . "\n"; $output_searchs .= '<input type="hidden" name="' . Watt_Util_Grid_Searchs::DEF_ORDERBYORDERS . '" id="searchFormOrderByOrder" value="">' . "\n"; } /** * 这是order by 的js脚本 * //已写到 common.js 里了 */ // $descSign = Watt_Util_Grid_Searchs::DESC; // $ascSign = Watt_Util_Grid_Searchs::ASC; // $output_searchs .= <<<EOT //<script> //function orderby{$specSearchFormId}(colName){document.getElementById("searchFormOrderBy").value=colName;if(document.getElementById("searchFormOrderByOrder").value=="{$ascSign}"){document.getElementById("searchFormOrderByOrder").value="{$descSign}"}else{document.getElementById("searchFormOrderByOrder").value="{$ascSign}"}document.getElementById("searchform").submit();} //</script> //EOT; /** * 如果有页码定义,输出页码表单域 */ if (is_array($grid[Watt_Util_Grid::GRID_SCHEMA_PAGER])) { //这是翻页的js脚本 //已写到 common.js 里了 // $output_searchs .= <<<EOT // <script>function gotoPage(pn){document.getElementById("searchFormPageNum").value=pn;document.getElementById("searchform").submit();}</script> //EOT; //这里不显示 PAGER_VAR_PAGE_NUM 是为了 按 search 后进入到第1页 $output_searchs .= '<input type="hidden" name="' . Watt_Util_Pager::PAGER_VAR_PAGE_NUM . '" id="searchFormPageNum" value="">'; $output_searchs .= '<input type="hidden" name="' . Watt_Util_Pager::PAGER_VAR_PAGE_SIZE . '" id="searchFormPageSize" value="' . $grid[Watt_Util_Grid::GRID_SCHEMA_PAGER][Watt_Util_Pager::PAGER_VAR_PAGE_SIZE] . '">'; $output_searchs .= '<input type="hidden" name="' . Watt_Util_Pager::PAGER_VAR_TOTAL . '" id="searchFormPageTotal" value="' . $grid[Watt_Util_Grid::GRID_SCHEMA_PAGER][Watt_Util_Pager::PAGER_VAR_TOTAL] . '">'; //var_dump( $output_searchs ); } $output_searchs .= "</div>\n"; $output_searchs .= "</div>\n"; } $output_searchs .= '</form>'; /** * 这里开始输出数据信息 */ $output_body = ""; $output_body .= '<div class="grid">' . "\n"; $output_body .= '<table class="grid" cellspacing="1" ' . ($gridId ? 'id="' . $gridId . '"' : '') . ' >' . "\n"; /** * 输出 header col 头信息 */ $output_body .= "<thead>\n"; if ($isDefCols) { $output_body .= "<tr>"; foreach ($cols as $col) { $col_title = is_null($col["title"]) ? Watt_I18n::trans($col["colname"]) : $col["title"]; if (trim($col[Watt_Util_Grid::COL_COLNAME]) != "" && $col["sortable"]) { $orderBySign = key_exists($col[Watt_Util_Grid::COL_COLNAME], $orderByCols) ? $orderByCols[$col[Watt_Util_Grid::COL_COLNAME]] : ""; if ($output_searchs) { //如果在 $col["sortable"] 中不是 boolean,那么就是填写的 order by 的值 if (is_bool($col["sortable"])) { $orderByColname = $col["colname"]; } else { $orderByColname = $col["sortable"]; } //如果有search信息,则输出order by $output_body .= "<th nowrap=\"true\"><a href=\"javascript:orderby('" . addslashes($orderByColname) . "')\">" . $col_title . "</a>" . $orderBySign . $col["colext"] . "</th>"; } else { //否则不输出order by脚本 $output_body .= "<th nowrap=\"true\">" . $col_title . "</th>"; } } else { $output_body .= "<th nowrap=\"true\">" . $col_title . $col["colext"] . "</th>"; } } $output_body .= "</tr>\n"; } else { if (count($datas)) { $row = current($datas); if (is_array($row)) { $output_body .= "<tr>"; foreach ($row as $key => $col) { $output_body .= "<th>" . Watt_I18n::trans($key) . "</th>"; } $output_body .= "</tr>\n"; } } } $output_body .= "</thead>\n"; /** * Body 信息 */ $output_body .= "<tbody>\n"; if (is_array($datas) && count($datas)) { $output_arr = self::_getRenderedDataByGridData($datas, $cols); foreach ($output_arr as $row) { if (!is_array($row)) { continue; } $output_body .= "<tr>"; if ($isDefCols) { reset($cols); foreach ($cols as $col) { $output_body .= "<td {$col["coltags"]}>" . current($row) . "</td>"; next($row); } } else { foreach ($row as $col) { $output_body .= "<td>" . $col . "</td>"; } } $output_body .= "</tr>\n"; } // $showText = ""; // foreach ( $datas as $row ) // { // if( !is_array( $row ) )continue; // $output_body .= "<tr>"; // if( $isDefCols ) // { // reset( $cols ); // foreach ( $cols as $col ) // { // if( isset($col["render"]) && $col["render"] != "" ) // { // $showText = ""; // @eval('$showText = '.$col["render"].';'); // } // else // { // if( isset($col["colname"]) ){ // $showText = @$row[$col["colname"]]; // }else{ // $showText = ""; // } // } // $output_body .= "<td {$col["coltags"]}>".$showText."</td>"; // } // } // else // { // foreach ( $row as $col ) // { // $output_body .= "<td>". $col ."</td>"; // } // } // $output_body .= "</tr>\n"; // } } //end if( is_array $output_body .= "</tbody>\n"; $output_body .= "</table>\n"; $output_body .= "</div>\n"; $output_page = ""; //if( is_array( $grid[Watt_Util_Grid::GRID_SCHEMA_PAGER] ) && $grid[Watt_Util_Grid::GRID_SCHEMA_PAGER][Watt_Util_Pager::PAGER_VAR_PAGE_COUNT] > 1 ){ if (is_array($grid[Watt_Util_Grid::GRID_SCHEMA_PAGER]) && $grid[Watt_Util_Grid::GRID_SCHEMA_PAGER][Watt_Util_Pager::PAGER_VAR_PAGE_COUNT] > 0) { // 只要存在数据就显示 GRID FOOTER,具体显示哪些元素由 toHtml 函数内判断 //bobit Tue Dec 11 10:13:54 CST 200710:13:54 $output_page = '<div class="search_container">' . "\n"; $output_page .= Watt_View_Helper_Pager::toHtml($grid[Watt_Util_Grid::GRID_SCHEMA_PAGER], '"javascript:gotoPage($pg)"'); $output_page .= '</div>' . "\n"; } $rev[Watt_Util_Grid::GRID_SCHEMA_SEARCHS] = $output_searchs; $rev[Watt_Util_Grid::GRID_SCHEMA_DATAS] = $output_body; $rev[Watt_Util_Grid::GRID_SCHEMA_PAGER] = $output_page; return $rev; }