📄 forms.php
字号:
$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);
//! TEST
if (is_array($tpl_vars)) {
$template->blocks["ListElement"]->input = $template->blocks["ListElement"]->Replace($tpl_vars);
$template->blocks["Button"]->input = $template->blocks["Button"]->Replace($tpl_vars);
}
//! E:TEST
//prereplace the pagination template
if (is_array($_GET)) {
foreach ($_GET as $key => $val) {
if ($key != "page") {
if ($key == "returnurl") {
$url[] = $key . "=" . urlencode($val);
} else {
$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":
//save the value
$items[$key]["original_" . $k] = $items[$key][$k];
if (isset($val[$k . "_day" ]) && isset($val[$k . "_month" ]) && isset($val[$k . "_year" ])) {
$items[$key][$k] =
( $val[$k . "_month" ] ? sprintf("%02d" ,$val[$k . "_month" ]) : "--" ). "." .
( $val[$k . "_day" ] ? sprintf("%02d" ,$val[$k . "_day" ]) : "--" ) . "." .
( $val[$k . "_year" ] ? $val[$k . "_year" ] : "----" ) ;
} else
//$field["value"] = $field["value"] > 0 ? @date($field["params"] , $field["value"]) : "not available";
$items[$key][$k] = $items[$key][$k] > 0 ? @date($v["params"] , ($v["now"] == "true" ? time() : $items[$key][$k])) : "N/A";
// $items[$key][$k] = $items[$key][$k] > 0 ? @date($v["params"] , ($v["now"] == "true" ? time() : $items[$key][$k])) : "N/A";
break;
case "price":
$items[$key]["original_" . $k] = $items[$key][$k];
$items[$key][$k] = number_format($items[$key][$k],2);
break;
case "int":
$items[$key][$k] = (int)$items[$key][$k];
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
$items[$key]["original_" . $k] = $items[$key][$k];
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 );
//build the label for multiple fields
if (is_array($v["relation"]["text"])) {
$_tmp_text = "";
foreach ($v["relation"]["text"] as $kkey => $vval)
if (is_array($vval))
$_tmp_text[] = $vval["preffix"] . $record[$vval["field"]] . $vval["suffix"];
else
$_tmp_text[] = $record[$vval];
$items[$key][$k] = implode($v["relation"]["separator"] ? $v["relation"]["separator"] : " " , $_tmp_text);
} else
//else return the single field
$items[$key][$k] = $record[$v["relation"]["text"]];
}
break;
case "sql":
if (is_array($v["sql"])) {
$form_sql_vars = array();
if (is_array($v["sql"]["vars"])) {
foreach ($v["sql"]["vars"] as $_key => $_val) {
//echeking if the default must be evaluated
if ($_val["action"] == "eval") {
eval("\$_val[\"import\"] = " . $_val["default"] .";");
}
switch ($_val["type"]) {
case "eval":
eval("\$form_sql_vars[\"$_key\"] = " . $_val["import"] . ";");
break;
case "var":
$form_sql_vars[$_key] = $_val["import"];
break;
case "page":
$form_sql_vars[$_key] = ($_GET[($_val["code"] ? $_val["code"] : 'page')] -1 )* $form['items'];
break;
case "form":
eval("\$form_sql_vars[\"$_key\"] = " . $form[$_val["var"]] . ";");
break;
case "field":
$form_sql_vars[$_key] = $items[$key][$_val["import"]];
break;
}
}
foreach ($form_sql_vars as $_key => $_val) {
$this->templates->blocks["Temp"]->input = $_val;
$form_sql_vars[$_key] = $this->templates->blocks["Temp"]->Replace($form_sql_vars);
}
//doing a double replace, in case there are unreplaced variable sfom "vars" type
$this->templates->blocks["Temp"]->input = $v["sql"]["query"];
$sql = $this->templates->blocks["Temp"]->Replace($form_sql_vars);
//do a precheck for [] elements to be replaced with <>
$sql = str_replace("]" , ">" , str_replace("[" , "<" , $sql));
$record = $this->db->QFetchArray($sql);
$items[$key][$k] = $record[$v["sql"]["field"]];
}
}
break;
case "button":
//check to see if this button isnt a protected one
if ($v["protected"] && $items[$key][$v["protected"]]) {
$items[$key][$k] = " ";
} else {
//replace the location and the button in the template
$tmp = $v;
//chec for variables which might not be defined
$tmp["onmouseout"] = $tmp["onmouseout"] ? $tmp["onmouseout"] : "";
$tmp["onmouseover"] = $tmp["onmouseover"] ? $tmp["onmouseover"] : "";
$tmp["onclick"] = $tmp["onclick"] ? $tmp["onclick"] : "";
$tmp["title"] = $tmp["title"] ? $tmp["title"] : "";
$button = new CTemplate($template->blocks["SimpleButton"]->Replace($tmp),"string");
$button->input = $button->Replace($tpl_vars);
$items[$key][$k] = $button->Replace($items[$key]);
}
break;
case "multiple":
$items[$key]["original_" . $k] = $items[$key][$k];
// a control variable to know to add the data to end
$found_multiple = true;
$items[$key][$k] = $template->blocks["SimpleListMultiple"]->Replace(array("value" => $items[$key][$v["value"]] , "field" => $v["field"] , "_count" => $items[$key]["original_count"]));
break;
default:
if ($v["html"] != "true")
$items[$key][$k] = htmlentities($items[$key][$k]);
$items[$key][$k] = $items[$key][$k] ? $items[$key][$k] : " ";
break;
}
$items[$key][$k] = $v["preffix"] . ( strtoupper($v["allownl"]) == "TRUE" ? nl2br($items[$key][$k]) : $items[$key][$k] ). $v["suffix"];
if ($v["html"] != "true") {
$items[$key][$k] = eregi_replace("([_a-z0-9\-\.]+)@([a-z0-9\-\.]+)\." . "(net|com|gov|mil|org|edu|int|biz|info|name|pro|[A-Z]{2})". "($|[^a-z]{1})", "<a title=\"Click to open the mail client.\" href=\"mailto:\\1@\\2.\\3\">\\1@\\2.\\3</a>\\4", $items[$key][$k]);
$items[$key][$k] = eregi_replace("(http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href=\"\\1://\\2\" title=\"Click to open in new window.\" target=\"_blank\">\\2</a>", $items[$key][$k]);
}
}
}
//adding the ing buttons
if (is_array($form["buttons"])) {
foreach ($form["buttons"] as $key2 => $val2) {
if ($key2 != "set") {
if ($val2["protected"] && $items[$key][$val2["protected"]]) {
} else {
//do a replace with the values from the item
$this->templates->blocks["Temp"]->input = $val2["location"];
$this->templates->blocks["Temp"]->input = $this->templates->blocks["Temp"]->Replace($tpl_vars);
$val2["location"] = $this->ProcessLinks($this->templates->blocks["Temp"]->Replace(array_merge($items[$key],$tpl_vars)));
//do an extra replacement for space with %20
$val2["location"] = str_replace(" ","%20" , $val2["location"]);
$val2["title"] = $val2["title"];
$val2["onmouseout"] = $val2["onmouseout"];
$val2["onmouseover"] = $val2["onmouseover"];
$val2["onclick"] = $val2["onclick"];
$items[$key]["buttons"] .=
($form["buttons"]["set"]["buttonsvert"] == "true" ? "<tr><td height=3></td></tr><tr>" : "" ).
$template->blocks["Button"]->Replace($val2) .
($form["buttons"]["set"]["buttonsvert"] == "true" ? "</tr>" : "" );
}
}
}
//do a check for the cases when all buttons were protected
if ( $items[$key]["buttons"] == "") {
$items[$key]["buttons"] = " ";
}
} 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);
}
// , 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;
// do a check for the cases when is required a form
if ($form["formtag"] == "true") {
$form["id"] = $form["id"] ? " id=\"" . $form["id"] . "\" " : "";
$form["encoding"] = $form["encoding"] ? $form["encoding"] : "";
$form["method"] = $form["method"] ? $form["method"] : "post";
$form["_template_data"] = $this->templates->blocks["Temp"]->input;
$this->templates->blocks["Temp"]->input = $this->templates->blocks["Action"]->Replace( $form );
}
$this->templates->blocks["Temp"]->input = $this->templates->blocks["Temp"]->Replace($tpl_vars);
return $this->templates->blocks["Temp"]->input;
}
/**
* 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 drWING A PRIVATE TREE ELEMENT, LIKE A MULTIPLE CHECKBOX.
*
* @param
*
* @return
*
* @access
*/
function privateDrawTree($field , $cats , $values , $parent = 0 , $level = 0, $sep = '') {
$return = "";
//if i found categories then return the list of it
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -