📄 forms.php
字号:
$search["fields"] .= $template->blocks["SearchField"]->Replace(array("name" => $key , "value" => $val));
}
}
}
//preparing the action, post the requests to the same file as curernt
$search["action"] = $_SERVER["PHP_SELF"];
$search["value"] = $_GET["search"];
$header["search"] = $template->blocks["SearchForm"]->Replace($search);
}
}
//checking if header exists, then add the template
if (is_array($header) || $form["subtitle"] || $form["header"]["titles"]) {
//cleanup the variables
$header["buttons"] = $header["buttons"] ? $header["buttons"] : "";
$header["search"] = $header["search"] ? $header["search"] : "";
$header["subtitle"] = $form["subtitle"];
//building the template
$header = $template->blocks["ListHeader"]->Replace($header);
$template->blocks["ListGroup"]->input = $template->blocks["ListGroup"]->Replace(array(
"_HEADER" => $header ,
"_TITLES" => $titles ,
//adding the extra html
"_HTML_PRE" => (is_array($form["html"]["pre"]) && ($form["html"]["pre"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["pre"]["file"]) : html_entity_decode($form["html"]["pre"]),
"_HTML_MIDDLE" => (is_array($form["html"]["middle"]) && ($form["html"]["middle"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["middle"]["file"]) : html_entity_decode($form["html"]["middle"]),
"_HTML_AFTER" => (is_array($form["html"]["after"]) && ($form["html"]["after"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["after"]["file"]) : html_entity_decode($form["html"]["after"]),
"PRE" => $extra["pre"],
"AFTER" => $extra["after"]
));
} else {
//cleanup the vars
$form["_HEADER"] = "";
$form["_TITLES"] = "";
$form["_HTML_PRE"] = "";
$form["_HTML_AFTER"] = "";
$form["pre"] = $form["after"] = "";
}
//prereplace the vars main template
$template->blocks["ListGroup"]->input = $template->blocks["ListGroup"]->Replace($form);
//prereplace the pagination template
if (is_array($_GET)) {
foreach ($_GET as $key => $val) {
if ($key != "page")
$url[] = "$key=$val";
}
$url = $_SERVER["SCRIPT_NAME"] . "?" . implode("&" , $url) . "&";
}
$template->blocks["Page"]->input = $template->blocks["Page"]->Replace(array("BASE" => $url));
$_GET["page"] = ($_GET["page"] ? $_GET["page"] : "1");
//preprocessing the items
if (is_array($items)) {
foreach ($items as $key => $val) {
if (is_array($form["fields"])) {
foreach ($form["fields"] as $k => $v) {
switch ($v["type"]) {
case "date":
$items[$key][$k] = $items[$key][$k] > 0 ? @date($v["params"] , ($v["now"] == "true" ? time() : $items[$key][$k])) : "N/A";
break;
case "price":
$items[$key][$k] = number_format($items[$key][$k],2);
break;
case "image":
if ($items[$key][$k]) {
// if is the image then show it
$items[$key][$k] = $template->blocks["imageshow"]->Replace(
array(
"width" => $v["width"],
"height" => $v["height"],
"src" => $_CONF["url"] . $_CONF["upload"] . $v["path"] . $v["file"]["default"] . $items[$key][$v["file"]["field"]] . $v["file"]["ext"]
)
);
} else {
//else check if the default image exists
if ($v["default"]) {
$items[$key][$k] = $template->blocks["imageshownolink"]->Replace(
array(
"width" => $v["width"],
"height" => $v["height"],
"src" => $_CONF["url"] . $_CONF["upload"] . $v["path"] . $v["default"]
)
);
} else
//if not simply return a space
$items[$key][$k] = " ";
}
break;
case "relation":
//cheking if there are static relations or dinamic relations
if (is_array($v["options"])) {
//ok, i have the static ones
$items[$key][$k] = $v["options"][$items[$key][$k]] ? $v["options"][$items[$key][$k]] : " ";
}
if (is_array($v["relation"])) {
//reading from database
$sql = "SELECT * FROM `" . $this->tables[$v["relation"]["table"]] . "` WHERE `" . $v["relation"]["id"] . "`='" . $items[$key][$k] . "'";
$record =$this->db->QFetchArray( $sql );
$items[$key][$k] = $record[$v["relation"]["text"]];
}
break;
default:
$items[$key][$k] = $items[$key][$k] ? htmlentities($items[$key][$k]) : " ";
break;
}
$items[$key][$k] = $v["preffix"] . $items[$key][$k] . $v["suffix"];
}
}
//adding the ing buttons
if (is_array($form["buttons"])) {
foreach ($form["buttons"] as $key2 => $val2) {
//do a replace with the values from the item
$this->templates->blocks["Temp"]->input = $val2["location"];
$val2["location"] = $this->ProcessLinks($this->templates->blocks["Temp"]->Replace(array_merge($items[$key],$tpl_vars)));
$items[$key]["buttons"] .= $template->blocks["Button"]->Replace($val2);
}
} else {
$items[$key]["buttons"] = "";
}
}
}
if ($form["items"]) {
$return = $html->Table( $template , "List" , $items , true , $count , $form["items"] , $_GET["page"] , $template );
} else {
$return = $html->Table( $template , "List" , $items);
}
//crap, append some extra elements to this form, in case, , i dont know how to handle if there will be 2 pagging functions.
if (is_array($this->functions["list"]["after"]))
call_user_func($this->functions["list"]["after"],&$append);
//clearing the extra value
if (!$append) {
$append = "";
}
//adding the border
//doing a small trick before adding the border
if ($form["border"] != "true") {
//overwrite the border template with the content one
$template->blocks["Border"]->input = $return;
//empty the return variable
$return = "";
}
$return = $template->blocks["Border"]->Replace(
array(
"_TEMPLATE_DATA" => $return ,
"WIDTH" => $form["width"],
"TITLE" => $form["title"] ,
"EXTRA" => $append
));
$this->templates->blocks["Temp"]->input = $return;
return $this->templates->blocks["Temp"]->Replace($tpl_vars);
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function InsertField( $params ) {
//for the momment it dont support complex fields like referers, and multiple
//preparing the input vars
$form["fields"]["temp"] = $params;
$values["values"][$params["name"]] = $params["value"] ;
//draw the element
return $this->DrawElement ( $form , "temp" , $values );
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function privateDrawTree($field , $cats , $values , $parent = 0 , $level = 0, $sep = '') {
$return = "";
//if i found categories then return the list of it
if (is_array($cats)) {
$sep = preg_replace(
array( '(\[)' , '(\])' ),
array( "<" , ">" ),
$field["tree"]["separator"]
);
//prepare the values
//do a small check to see if there are values set in separed values
//preparing the separator
if ($level > 0 ) {
$separator = "";
for ($i = 0; $i< $level; $i++) {
$separator .= $sep;
}
}
foreach ($cats as $key => $val) {
if ($val[$field["tree"]["parent"]] == $parent) {
$return .= $this->templates->blocks["SelectTree" . ($field["editable"] == "false" ? "Disabled" : "" )]->Replace(
array (
"LABEL" => $val[$field["tree"]["text"]],
"ID" => $val[$field["tree"]["id"]],
"NAME" => $field["name"],
"CHECKED" => $values["values"][$field["name"] . "_option_" . $val[$field["tree"]["id"]]] ? ' checked="checked" ' : "",
"X" => $values["values"][$field["name"] . "_option_" . $val[$field["tree"]["id"]]] ? 'x' : " ",
"SEPARATOR" => $separator,
"PARENT" => $val[$field["tree"]["parent"]]
)
);
$return .= $this->privateDrawTree($field , $cats , $values , $val[$field["tree"]["id"]], $level + 1 , $sep);
}
}
return $return;
} else {
return "";
}
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function DrawElement( $form , $_field , $values , $draw_referer = 0 ) {
global $_CONF;
//some default settings
$_textareaCols = 30;
$_textareaRows = 4;
$_textboxSize = 20;
$_textboxMaxLength = "";
$_textareaButtons = array (
"1" => "'cut' , 'copy' , 'paste' , 'separator' , 'undo' , 'redo' , 'separator' , 'removeformat' , 'toolbar' , 'bold' , 'italic' , 'underline' , 'strike' , 'superscript' , 'subscript' , 'insertorderedlist' , 'insertunorderedlist' , 'indent' , 'outdent' , 'inserthr'",
"2" => "'font-family' , 'font-size' , 'justifyleft' , 'justifycenter' , 'justifyright' , 'justifyfull'"
);
$field = $form["fields"][$_field];
//doing a precheck in case there are referers or multiples to elements which arent in xml
if (!is_array($field))
return "";
if (!$field["type"]) {
return "";
}
//a temporary solution for name loosing
$field["name"] = $_field;
if (!$values["values"][$field["name"]]) {
switch ($field["action"]) {
case "eval":
eval("\$field[\"value\"] = " . $field["default"] . ";");
break;
default:
$field["value"] = $field["default"];
break;
}
} else {
$field["value"] = $values["values"][$field["name"]];
}
//load data from external files
if ((($field["type"] != "image")&&($field["type"] != "upload")) && is_array($field["file"]) && !($values["values"][$field["name"]]) && file_exists($_CONF["path"] . $_CONF["upload"] . $field["file"]["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"])) {
$values["values"][$field["name"]] = GetFileContents($_CONF["path"] . $_CONF["upload"] . $field["file"]["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"]);
}
//checking if this file is a referer, and if i have to show the referers at this point
if (! $draw_referer && (($field["referer"] == "true") || ($field["multiple"] == "true")))
return "";
//drawing the form elements
switch ($field["type"]) {
case "textarea":
if (is_array($temp = @explode(":" , $field["size"]))) {
//size from xml
$field["_cols"] = $temp["0"];
$field["_rows"] = $temp["1"];
} else {
//preset size
$field["_cols"] = $_textareaCols;
$field["_rows"] = $_textareaRows;
}
$field["value"] = $values["values"][$field["name"]] ? $values["values"][$field["name"]] : $field["default"];
if ($field["html"] == "true") {
//checking if the editor.js was loaded until now
if ($_GLOBALS["cform_editor_loaded"] != true) {
$current_field = $this->templates->blocks["htmlareainit"]->output;
$_GLOBALS["cform_editor_loaded"] = true;
}
//checking if the buttons exists, else add the buttons from default
if (!is_array($field["buttons"])) {
$field["buttons"] = $_textareaButtons;
}
if (is_array($field["buttons"])) {
$buttons = $field["buttons"];
//clear the buttons from field, it will be rplaced with the template
$field["buttons"] = "";
foreach ($buttons as $k => $v) {
$field["buttons"] .= $this->templates->blocks["htmlareabutton"]->Replace(
array(
"NAME" => $field["name"],
"BUTTONS" => is_array($v) ? "" : $v
)
);
}
} else
$field["buttons"] = "";
$current_field .= $this->templates->blocks["htmlarea"]->Replace($field);
} else {
$field["value"] = stripslashes(htmlentities($field["value"]));
$current_field = $this->templates->blocks["textarea"]->Replace($field);
//$current_field = $this->templates->blocks["textarea"]->EmptyVars();
}
//valign for forms which has more then one field
$current_field_extra = $this->templates->blocks["TopAlign"]->output;
break;
case "file":
$field["file"] = $values["values"][$field["name"]];
$this->templates->blocks["file"]->Replace($field , false);
$current_field = $this->templates->blocks["file"]->EmptyVars();
//if the field hs description then i add the valign code
$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "password":
case "textbox":
//check if the size for textbox is defined
if ($field["size"]) {
//autodetect if the size value contaigns the maxlength too
if (is_array($temp = @explode(":" , $field["size"]))) {
$field["_size"] = $temp["0"];
$field["_maxlength"] = $temp["1"];
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -