forms.php
来自「基于PHP和MYSQL的计算机辅助设备维修管理系统」· PHP 代码 · 共 1,637 行 · 第 1/4 页
PHP
1,637 行
//else the size field is the size of textbox
$field["_size"] = $field["size"];
$field["_maxlength"] = $_textboxMaxLength;
}
} else {
//get the default values
$field["_size"] = $_textboxSize;
$field["_maxlength"] = $_textboxMaxLength;
}
$field["value"] = $values["values"][$field["name"]] ? $values["values"][$field["name"]] : $field["default"];
$field["value"] = stripslashes(htmlentities($field["value"]));
$current_field = $this->templates->blocks[$field["type"]]->Replace($field);
//$current_field = $this->templates->blocks[$field["type"]]->EmptyVars();
//if the field hs description then i add the valign code
$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "text":
$field["value"] = $values["values"][$field["name"]] ? $values["values"][$field["name"]] : $field["default"];
$field["value"] = $field["html"] == "true" ? $field["value"] : nl2br(stripslashes(htmlentities($field["value"])));
switch ($field["action"]) {
case "date":
$field["value"] = $field["value"] > 0 ? @date($field["params"] , $field["value"]) : "not available";
break;
case "price":
$field["value"] = number_format($field["value"] , 2);
break;
}
$current_field = $this->templates->blocks["text"]->Replace($field , false);
//$current_field = $this->templates->blocks["text"]->EmptyVars();
//if the field hs description then i add the valign code
$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "hidden":
//fix a small bug, if the hidden!= true then the elemet is drow like normal element.
$field["hidden"] = "true";
//crap some evals here too :)
if ($values["values"][$field["name"]]) {
$field["value"] = $values["values"][$field["name"]];
} else {
switch ($field["action"]) {
case "eval":
eval("\$field[\"value\"] = " . $field["default"] . ";");
break;
default:
$field["value"] = $field["default"];
break;
}
}
$this->templates->blocks["hidden"]->Replace($field , false);
$current_field = $this->templates->blocks["hidden"]->EmptyVars();
$current_field_extra = "";
break;
case "checkbox":
$field["checked"] = $values["values"][$field["name"]] ? " checked=\"checked\" " : "";
$this->templates->blocks["checkbox"]->Replace($field , false);
$current_field = $this->templates->blocks["checkbox"]->EmptyVars();
//if the field hs description then i add the valign code
$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "relation":
$field["editable"] = "false";
case "droplist":
//clearign vals
$temp_options = "";
//check if the options are generated dinamic
if (is_array($field["dynamic"])) {
for ($i = $field["dynamic"]["from"]; $i<=$field["dynamic"]["to"]; $i++ ) {
$field["options"][$i] = $field["dynamic"]["width"] ? sprintf("%0" . $field["dynamic"]["width"] . "d", $i) : $i;
}
}
if (is_array($field["options"])) {
//add the enpty option
if ($field["empty"] == "true") {
$temp_options = $this->templates->blocks["SelectOption"]->Replace(array(
"LABEL" => $field["empty_text"] ? $field["empty_text"] : "[ select ]",
"VALUE" => "",
"DISABLED" => "",
"CHECKED" => "" ));
}
//building the select from options
foreach ($field["options"] as $key => $val) {
//hm ... support for noeditable fields, will apear as text
if ($field["editable"] == "false") {
foreach ($field["options"] as $key => $val) {
if ($key == $values["values"][$field["name"]]) {
$field["value"] = $val;
$this->templates->blocks["text"]->Replace($field , false);
$current_field = $this->templates->blocks["text"]->EmptyVars();
}
}
} else {
//checking if is a complex option or a simple one
if (is_array($val)) {
$label = $val["value"];
$disabled = $val["disabled"] == "true" ? " disabled " : "";
} else {
$label = $val;
$disabled = "";
}
$temp_options .= $this->templates->blocks["SelectOption"]->Replace(
array(
"value" => $key,
"label" => $label,
"checked" => ($key == $values["values"][$field["name"]] ? " selected=\"selected\" " : ""),
"disabled" => $disabled
)
);
}
}
} else
if (is_array($field["relation"])) {
//reading from database
//check to eval the condition if requred
if (is_array($field["relation"]["condition"]) && ($field["relation"]["condition"]["eval"] == "true")) {
echo "\$field[\"relation\"][\"condition\"] = " . $field["relation"]["condition"]["import"];
eval("\$field[\"relation\"][\"condition\"] = " . $field["relation"]["condition"]["import"]);
}
$sql = "SELECT * FROM `" . $this->tables[$field["relation"]["table"]] . "`" .
($field["relation"]["condition"] ? " WHERE (" . $field["relation"]["condition"] . ") " : "" ) .
($field["relation"]["order"] ? " ORDER BY `" . $field["relation"]["order"] . "` " .
($field["relation"]["ordermode"] ? $field["relation"]["ordermode"] : "") : "" );
$records =$this->db->QFetchRowArray( $sql );
//ckech and replace the label field with multi fields array
if (is_array($tmp_fields = @explode($field["tree"]["db_separator"] , $values["values"][$field["name"]]))) {
foreach ($tmp_fields as $_val) {
$_tmp_fields[$_val] = $_val;
}
}
if (is_array($records)) {
if ($field["subtype"] == "multiple") {
foreach ($records as $_k => $_v) {
if ($_tmp_fields[$_v[$field["tree"]["id"]]] == $_v[$field["tree"]["id"]])
$values["values"][$field["name"]."_option_" . $_v[$field["tree"]["id"]]] = true;
}
$temp_options = $this->privateDrawTree($field, $records , $values);
//check if the overflow div settings are enabled
if (is_array($field["tree"]["div"])) {
$temp_options = $this->templates->blocks["SelectDiv"]->Replace(array(
"WIDTH" => $field["tree"]["div"]["width"],
"HEIGHT" => $field["tree"]["div"]["height"],
"SELECT_DATA" =>$temp_options
));
}
} else {
//add the enpty option
if ($field["empty"] == "true") {
$temp_options = $this->templates->blocks["SelectOption"]->Replace(array(
"LABEL" => $field["empty_text"] ? $field["empty_text"] : "[ select ]",
"VALUE" => "",
"DISABLED" => "",
"CHECKED" => ""
));
}
//echo "`" . $field["relation"]["id"] . "`" ;
foreach ($records as $key => $val) {
//preparing the data to send to template
$send = array();
$_tmp_text = "";
$send["value"] = $val[$field["relation"]["id"]];
$send["checked"] = $val[$field["relation"]["id"]] == $field["value"] ? " selected=\"selected\" " : "";
$send["disabled"] = "";
//build the label for multiple fields
if (is_array($field["relation"]["text"])) {
foreach ($field["relation"]["text"] as $kkey => $vval)
$_tmp_text[] = $val[$vval];
$send["label"] = implode($field["relation"]["separator"] ? $field["relation"]["separator"] : " " , $_tmp_text);
} else
//else return the single field
$send["label"] = $val[$field["relation"]["text"]];
// if the type is relation of editable false, then search for the selected element.
if (($val[$field["relation"]["id"]] == $field["value"]) && ($field["editable"] == "false")) {
$field["value"] = $send["label"];
$this->templates->blocks["text"]->Replace($field , false);
$current_field = $this->templates->blocks["text"]->EmptyVars();
//quit the for
break;
}
$temp_options .= $this->templates->blocks["SelectOption"]->Replace($send);
}
}
}
}
if ($field["editable"] != "false") {
if ($temp_options != "") {
if ($field["subtype"] == "multiple") {
$current_field = $temp_options;
} else {
//if there are options, build the select
$current_field = $this->templates->blocks["Select"]->Replace(array(
"name" => $field["name"] ,
"options" => $temp_options ,
"width" => $field["width"],
"onchange" => $field["onchange"]
));
}
} else
//else return a message, customizable from xml
$current_field = $field["empty"] ? $field["empty"] : $this->templates->blocks["selectempty"]->output;
} else {
if ($temp_options != "") {
if ($field["subtype"] == "multiple") {
$current_field = $temp_options;
}
}
}
//if the field hs description then i add the valign code
$current_field_extra = $field["description"] || $field["subtype"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "upload":
$file = true;
case "image":
if ($field["editable"] != "false") {
//adding the editable area to form
$field["web_checked"] = $values["values"][$field["name"] . "_radio_type"] ? "checked" : "";
$field["client_checked"] = $values["values"][$field["name"] . "_radio_type"] ? "" : "checked";
$field["web_link"] = $values["values"][$field["name"] . "_upload_web"] ? $values["values"][$field["name"] . "_upload_web"] : "http://";
$field["file_name"] = $values["values"][$field["name"] . "_file"];
$field["rem_disabled"] = $values["values"][$field["name"] . "_temp"] || $values["values"][$field["name"] . "_temp"] || $values["values"][$field["name"]] ? "" : "disabled";
$image["editable"] = $this->templates->blocks[$file ? "uploadedit" : "imageedit"]->Replace($field);
}
if ($file) {
if (is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"])) {
//show the ing image
$image["preview"] = $this->templates->blocks["fileshow"]->Replace(
array(
"name" => $_CONF["url"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_file"],
"src" => $_CONF["url"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"]
)
);
} else {
$file_name = $_CONF["path"] . $_CONF["upload"] . ($field["path"] ? $field["path"] : $field["file"]["path"]) . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"];
$file_url = $_CONF["url"] . $_CONF["upload"] . ($field["path"] ? $field["path"] : $field["file"]["path"]) . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"];
if (/*$values["values"][$field["name"]] && */file_exists($file_name)) {
$image["preview"] = $this->templates->blocks["fileshow"]->Replace(
array(
"name" => $values["values"][$field["name"] . "_file"] ? $values["values"][$field["name"] . "_file"] : $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"],
"src" => $file_url
)
);
} else
$image["preview"] = $field["error"] ? $field["error"] : "No file uploaded.";
}
} else {
if (is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"])) {
//show the ing image
$image["preview"] = $this->templates->blocks["imageshow"]->Replace(
array(
"width" => $field["adminwidth"],
"height" => $field["adminheight"],
"src" => $_CONF["url"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"]
)
);
} else {
//hm ... making a small trick to keep the image even if that was an failed adding,
//this sux becouse if the add process is not completed then i get crap in the temp folder.
if ($values["values"][$field["name"]] && file_exists($_CONF["path"] . $_CONF["upload"] . $field["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"])) {
$image["preview"] = $this->templates->blocks["imageshow"]->Replace(
array(
"width" => $field["adminwidth"],
"height" => $field["adminheight"],
"src" => $_CONF["url"] . $_CONF["upload"] . $field["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"]
)
);
} else {
//checking if there exists a default image
if ($field["default"]) {
$image["preview"] = $this->templates->blocks["imageshownolink"]->Replace(
array(
"width" => $field["adminwidth"],
"height" => $field["adminheight"],
"src" => $_CONF["url"] . $_CONF["upload"] . $field["path"] . $field["default"]
)
);
} else
//return an error from xml
$image["preview"] = $field["error"] ? $field["error"] : "No image curently available.";
}
}
}
$image["temp"] = $values["values"][$field["name"] . "_temp"];
$this->templates->blocks["image"]->Replace($image , false);
$current_field = $this->templates->blocks["image"]->EmptyVars();
//if the field hs description then i add the valign code
$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "comment":
if ($field["subtype"] == "extern") {
$field["description"] = GetFileContents(dirname($form["xmlfile"]) . "/" . $field["file"]);
} else {
$field["description"] = preg_replace(
array( '(\[)' , '(\])' ),
array( "<" , ">" ),
$field["description"]
);
}
//save the input
$old = $this->templates->blocks["Comment"]->input ;
//do the replaces
$this->templates->blocks["Comment"]->input = $this->templates->blocks["Comment"]->Replace(array(
"COMMENT" => $field["description"],
"PADDING" => $field["padding"] ? $field["padding"] : "0"
));
$this->templates->blocks["Comment"]->input = $this->templates->blocks["Comment"]->Replace($values["values"]);
$this->templates->blocks["Comment"]->input = $this->templates->blocks["Comment"]->Replace($_GET);
$current_field = $this->templates->blocks["Comment"]->Replace($_POST);
//restore the template
$this->templates->blocks["Comment"]->input = $old;
//do a few other replaces
//if the field hs description then i add the valign code
// $current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : "";
break;
case "date":
if (is_array($field["fields"])) {
$html = new CHtml;
$date_vals = &$values["values"][$field["name"]];
if ($date_vals) {
//setting the previous values
$year_selected = $values["values"][$field["name"] ."_year"] ? $values["values"][$field["name"] ."_year"] : @date("Y" , $date_vals );
$month_selected = $values["values"][$field["name"] ."_month"] ? $values["values"][$field["name"] ."_month"] : @date("n" , $date_vals );
$day_selected = $values["values"][$field["name"] ."_day"] ? $values["values"][$field["name"] ."_day"] : @date("j" , $date_vals );
//crap, adding the time values too
$hour_selected = $values["values"][$field["name"] ."_hour"] ? $values["values"][$field["name"] ."_hour"] : @date("G" , $date_vals );
$minute_selected = $values["values"][$field["name"] ."_minute"] ? $values["values"][$field["name"] ."_minute"] : @date("i" , $date_vals );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?