示例#1
0
 function CreateTableHeader($order = '', $elemID = null)
 {
     $this->headerOutputDone = true;
     $res = '';
     // Check for javascript output
     if (str_replace('.', '', R3SIMPLETABLE_VERSION_SUPPORT) > 112 && !$this->jsOutputDone) {
         $res .= $this->getJSHeader();
     }
     if ($order == '' && isset($_REQUEST[$this->orderparam])) {
         $order = $_REQUEST[$this->orderparam];
     }
     $this->ExtractOrderParam($order, $OrderBy, $OrderType);
     if ($elemID === null && strlen($this->name) > 0) {
         $elemID = $this->name;
     }
     if ($elemID !== null) {
         $res .= "<table id=\"{$elemID}\" class=\"{$this->baseclass}\" width=\"{$this->width}\">\n";
     } else {
         $res .= "<table class=\"{$this->baseclass}\" width=\"{$this->width}\">\n";
     }
     // Create col proportion
     foreach ($this->fields as $field) {
         if ($field['width'] < 0) {
             $field['width'] = "";
         }
         if ($field['width'] == '') {
             $res .= "<col>\n";
         } else {
             $res .= "<col width=\"" . $field['width'] . "\">\n";
         }
     }
     // Create table header
     $res .= "<tr>\n";
     $cont = 0;
     foreach ($this->fields as $field) {
         if ($field['visible']) {
             $label = $field['label'];
             $width = $field['width'];
             if ($width > 0) {
                 $w = "width=\"{$width}\"";
             } else {
                 $w = '';
             }
             if ($field['hint'] !== false) {
                 $title = 'title="' . str_replace('"', '&quot;', strip_tags($field['hint'])) . '"';
             } else {
                 if ($label != '') {
                     $title = 'title="' . trim(str_replace('&nbsp;', ' ', $label)) . '"';
                 } else {
                     $title = '';
                 }
             }
             // Checkbox for header
             if (isset($field['header_checkbox']) && $field['header_checkbox'] == true) {
                 if (!isset($_SESSION[$this->name][$field['field'] . '_off'])) {
                     $_SESSION[$this->name][$field['field'] . '_off'] = array();
                 }
                 if (is_array($_SESSION[$this->name][$field['field'] . '_off']) && count($_SESSION[$this->name][$field['field'] . '_off']) > 0) {
                     $className = "class=\"header_checkbox_intermediate\"";
                 } else {
                     $className = "";
                 }
                 if (isset($_SESSION[$this->name][$field['field'] . '_header']) && $_SESSION[$this->name][$field['field'] . '_header'] == 'T') {
                     $label = "<input type=\"checkbox\" name=\"" . $field['field'] . "_header\" value=\"T\" onclick=\"simpletable_onHeaderCheckboxClick(this)\" {$className} checked>" . $label;
                 } else {
                     $label = "<input type=\"checkbox\" name=\"" . $field['field'] . "_header\" value=\"T\" onclick=\"simpletable_onHeaderCheckboxClick(this)\" {$className}>" . $label;
                 }
                 unset($field['sortable']);
             }
             if (isset($field['sortable']) && $field['sortable']) {
                 $class = $this->baseclass . "_header_sort";
                 //if ($_REQUEST[$this->orderparam] == ($cont + 1) && $OrderType == 'asc')
                 if ($order == $cont + 1 && $OrderType == 'asc') {
                     $url = AddURLParam($this->baseurl, $this->orderparam, $this->CreateOrderParam($cont + 1));
                 } else {
                     $url = AddURLParam($this->baseurl, $this->orderparam, $this->CreateOrderParam($cont + 1, 'desc'));
                 }
                 //  echo $url;
                 // TODO: find solution for label as text
                 if ($order == $cont + 1) {
                     if ($OrderType == 'asc') {
                         $label = "{$label}<img class=\"ui-icon ui-icon-triangle-1-n\" src=\"" . R3_APP_URL . "images/ico_spacer.gif\" />";
                     } else {
                         $label = "{$label}<img class=\"ui-icon ui-icon-triangle-1-s\" src=\"" . R3_APP_URL . "images/ico_spacer.gif\" />";
                     }
                 }
                 if (str_replace('.', '', R3SIMPLETABLE_VERSION_SUPPORT) > 112) {
                     $res .= "  <th class=\"{$class}\" {$w} onclick=\"" . $this->jsEvents['onChangeOrder'] . "(this, '{$url}'); \" {$title}>{$label}</th>\n";
                 } else {
                     $res .= "  <th class=\"{$class}\" {$w} onclick=\"document.location='{$url}'\" {$title}>{$label}</th>\n";
                 }
             } else {
                 $class = $this->baseclass . "_header";
                 $res .= "  <th class=\"{$class}\" {$w} {$title}>{$label}</th>\n";
             }
         }
         $cont++;
     }
     $res .= "</tr>\n";
     return $res;
 }
 function ShowTemplate($s_name, $a_specs)
 {
     global $TEMPLATEURL, $TEMPLATEDIR, $bIsUserError, $bAlerted, $aGetVars;
     global $php_errormsg;
     if (empty($TEMPLATEDIR) && empty($TEMPLATEURL)) {
         ReportError("neither TEMPLATEDIR nor TEMPLATEURL is set");
         return false;
     }
     if (!empty($TEMPLATEDIR)) {
         $s_name = "{$TEMPLATEDIR}/" . basename($s_name);
         @($fp = fopen($s_name, "r"));
         if ($fp === false) {
             ReportError("Cannot open template '{$s_name}': {$php_errormsg}");
             return false;
         }
         //
         // load the whole template into a string
         //
         $s_buf = fread($fp, filesize($s_name));
         fclose($fp);
     } else {
         $s_name = AddUserAgent("{$TEMPLATEURL}/" . basename($s_name));
         if (session_id() !== "") {
             $s_name = AddURLParam($s_name, "sessid=" . urlencode(session_id()));
         }
         if (defined("SID")) {
             $s_name = AddURLParam($s_name, SID);
         }
         @($fp = fopen($s_name, "r"));
         if ($fp === false) {
             ReportError("Cannot open template '{$s_name}': {$php_errormsg}");
             return false;
         }
         //
         // load the whole template into a string
         //
         $s_buf = "";
         while (!feof($fp)) {
             $s_buf .= fread($fp, 4096);
         }
         fclose($fp);
     }
     //
     // now look for the tags to replace
     //
     foreach ($a_specs as $s_tag => $s_value) {
         //
         // search for
         //		<tagname/>
         // with optional whitespace
         //
         $s_buf = preg_replace('/<\\s*' . preg_quote($s_tag, "/") . '\\s*\\/\\s*>/ims', nl2br($s_value), $s_buf);
     }
     if ($bIsUserError) {
         //
         // put the form link just before the </body> end tag or replace
         // a <return_link/> tag
         //
         $s_link = GetFormLink($s_url);
         if (!empty($s_link)) {
             //
             // Replace any "$return_link" strings with the
             // return link URL.
             //
             if (preg_match('/\\$return_link\\b/ms', $s_buf) > 0) {
                 $s_buf = preg_replace('/\\$return_link\\b/ms', "{$s_url}", $s_buf);
             } else {
                 //
                 // Look for a "<return_link/>" tag and replace that.
                 // If it doesn't exist, put the return link before
                 // the body end tag.
                 //
                 if (preg_match('/<\\s*return_link\\s*\\/\\s*>/ims', $s_buf) > 0) {
                     $s_buf = preg_replace('/<\\s*return_link\\s*\\/\\s*>/ims', "{$s_link}\n", $s_buf);
                 } else {
                     $s_buf = preg_replace('/<\\s*\\/\\s*body\\s*>/ims', "{$s_link}\n" . '$0', $s_buf);
                 }
             }
         }
         // strip any <fmusererror> and </fmusererror> tags
         //
         // You can show information that's specific to user
         // errors between these special tags.
         //
         $s_buf = preg_replace('/<\\s*\\/?\\s*fmusererror\\s*>/ims', '', $s_buf);
         //
         // since this isn't a system error, strip anything between
         // <fmsyserror> and </fmsyserror>
         //
         $s_buf = preg_replace('/<\\s*fmsyserror\\s*>.*<\\s*\\/\\s*fmsyserror\\s*>/ims', '', $s_buf);
     } else {
         // strip any <fmsyserror> and </fmsyserror> tags
         //
         // You can show information that's specific to system
         // errors between these special tags.
         //
         $s_buf = preg_replace('/<\\s*\\/?\\s*fmsyserror\\s*>/ims', '', $s_buf);
         //
         // since this isn't a user error, strip anything between
         // <fmusererror> and </fmusererror>
         //
         $s_buf = preg_replace('/<\\s*fmusererror\\s*>.*<\\s*\\/\\s*fmusererror\\s*>/ims', '', $s_buf);
     }
     //
     // output the modified page
     //
     echo $s_buf;
     return true;
 }