⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forms.php

📁 基于PHP的一套网络管理系统代码,对接口流量等可以进行详细的统计分析,很不错.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	
	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function ProcessLinks($link) {
		return CryptLink($link);
	}
	
	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Validate($form  , $input) {

		$form = $this->Process($form);


		if (is_array($form)) {

			foreach ($form["fields"] as $key => $val)
	
				if ($val["validate"] && $val["required"] && !$val["hidden"])
					$_valid_temp[] = strtoupper($val["name"] ? $val["name"] : $key) . ":" . $val["validate"];

			$validate = @implode("," , $_valid_temp);
			
		}				
		
		//validate the input fields
		$result = ValidateVars($input ,$validate);
		$vars = array();

		if (is_array($result)) {
		
			foreach ($result as $key => $val)
				$fields["errors"][strtolower($val)] = 1;

			$fields["error"] = _MSG_FORMS_UNCOMPLETE;
			$fields["values"] = $input;

		} else {

			//proceed to complex validation for unique fields 
			if (is_array($form)) {
				
				foreach ($form["fields"] as $key => $val) {
		
					if ($val["unique"] == "true") {

						//check if this is an adding processor or editing one
						if ($input[$form["table_uid"]]) {
							$old_record = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $form["table_uid"] . "`='" . $input[$form["table_uid"]] . "'" );
						}

						$name = $val["name"] ? $val["name"] : $key ;
						$data = $this->db->QFetchArray("SELECT `$name` FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $name . "` = '" . $input[$name] . "'");

						if (((is_array($data) && is_array($old_record)) && ($data[$name] != $old_record[$name])) || (is_array($data) && !is_array($old_record))) {

							//preparing the message
							$fields["error"] = $val["unique_err"] ? $val["unique_err"] : $val["title"] . _MSG_FORMS_UNIQUE;
							$fields["errors"][$name] = 1;
							$fields["values"] = $input;

						}
					}

					// search to see if is a vvalid file path
					if ($val["fileexists"] == "true") {
						$name = $val["name"] ? $val["name"] : $key ;

						if (!is_file($input[$name])) {
							//preparing the message
							$fields["error"] = $val["fileexists_err"] ? $val["fileexists_err"] : $val["title"] . ": \"$input[$name]\"" . _MSG_FORMS_FILEEXISTS;
							$fields["errors"][$name] = 1;
							$fields["values"] = $input;
						}
						
					}

					// search to see if is a vvalid file path
					if (($val["type"] == "password") && !strstr($key , "_confirm")) {
						$name = $val["name"] ? $val["name"] : $key ;

						if ($input[$name] != $input[$name . "_confirm"]) {
							//preparing the message
							$fields["error"] = "Password and confirmation does not match.";
							$fields["errors"][$name] = 1;
							$fields["errors"][$name . "_confirm"] = 1;
							$fields["values"] = $input;
						}
						
					}

				}
					
			}
			
		}

		return is_array($fields) ? $fields : true;

	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function SimpleList($form , $items = "", $count = "", $extra = null , $search = false , $returnArray  = false) {
		global $_CONF , $form_errors;

		if (is_array($form["vars"])) {
			foreach ($form["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("\$tpl_vars[\"$key\"] = " . $val["import"] . ";");
					break;
					case "complex_eval":
						eval($val["import"]);
					break;

					case "var":
						$tpl_vars[$key] = $val["import"];
					break;
				}													
			}
		}

		//add an extra element to vars
		$tpl_vars["current_page"] = urlencode(urlencode($_SERVER["REQUEST_URI"]));
		//check to see where is the returnurl

		if ($_GET["returnurl"])
			$private_return = $_GET["returnurl"];
		if ($_GET["returnURL"])
			$private_return = $_GET["returnURL"];
		if ($_POST["returnurl"])
			$private_return = $_POST["returnurl"];
		
		$tpl_vars["private.form_previous_page"] = $private_return ? urldecode($private_return) : $form_errors["NO_BACK_LINK"] ;
		$tpl_vars["private.form_previous_page_enc"] = $private_return ? urlencode($private_return) : $form_errors["NO_BACK_LINK"] ;

		//add the other vars from the get
		$tpl_vars["private.get_mod"] = $_GET["mod"];
		$tpl_vars["private.get_sub"] = $_GET["sub"];
		$tpl_vars["private.get_action"] = $_GET["action"];
		$tpl_vars["private.table_uid"] = $form["table_uid"];
		$tpl_vars["private.value_uid"] = '{' . strtoupper($form["table_uid"]) . "}";


		if (!is_array($items)) {

			if (is_array($form["sql"])) {

				if (is_array($form["sql"]["vars"])) {

					foreach ($form["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("\$sql_vars[\"$key\"] = " . $val["import"] . ";");
							break;

							case "complex_eval":
								eval($val["import"]);
							break;

							case "var":
								$sql_vars[$key] = $val["import"];
							break;

							case "page":
								$sql_vars[$key] = ($_GET[($val["code"] ? $val["code"] : 'page')] -1 )* $form['items'];
							break;

							case "form":
								eval("\$sql_vars[\"$key\"] = " . $form[$val["var"]] . ";");
							break;
						}													
					}

					foreach ($sql_vars as $key => $val) {							
						$this->templates->blocks["Temp"]->input = $val;							
						$sql_vars[$key] = $this->templates->blocks["Temp"]->Replace($sql_vars);
						$sql_vars[$key] = str_replace("]" , ">" , str_replace("[" , "<" , $sql_vars[$key]));
					}	
					
					//doing a double replace, in case there are unreplaced variable sfom "vars" type
					$this->templates->blocks["Temp"]->input = $form["sql"]["query"];
					$sql = $this->templates->blocks["Temp"]->Replace($sql_vars);

					//do a precheck for [] elements to be replaced with <>
					$sql = str_replace("]" , ">" , str_replace("[" , "<" , $sql));

					$items = $this->db->QFetchRowArray($sql);
					//$items = $this->Query						

					//processing the counting query
					if (is_array($form["sql"]["count"])) {

						//if no table is set then i use the default table'
						$form["sql"]["count"]["table"] = $form["sql"]["count"]["table"] ? $form["sql"]["count"]["table"] : $form["table"];

						foreach ($form["sql"]["count"] as $key => $val) {
							$this->templates->blocks["Temp"]->input = $val;							
							$form["sql"]["count"][$key] = $this->templates->blocks["Temp"]->Replace($sql_vars);
						}						

						$count = $this->db->RowCount($form["sql"]["count"]["table"] , $form["sql"]["count"]["condition"] , $form["sql"]["count"]["select"] , $form["sql"]["count"]["fields"] );
					}					
				}

				
			} else {				
				if (!is_array($items)) {	
					$items = $this->db->QuerySelectLimit($this->tables[$form["table"]],"*","",(int) $_GET["page"],$form["items"]);
					$count = $this->db->RowCount($this->tables[$form["table"]]);
				}
			}
		}

		if ($returnArray == true) {
			return array(
						"items" => $items,
						"count" => $count
						);
		}
		
		$_GET["page"] = $_GET["page"] ? $_GET["page"] : 1;
		//auto index the element
		$start = $form["items"] * ($_GET["page"] ? $_GET["page"] - 1 : 0);

		$_old_count = $start + 1;

		if (is_array($items)) {
			foreach ($items as $key => $val) {
				$items[$key]["_count"] = ++$start;
				$items[$key]["original_count"] = $items[$key]["_count"] ;
			}			
		}		

		$_new_count = $start;

		$html = new CHtml();

		$form = $this->Process($form);

		$template = &$this->templates;

		//this sux, building the template
		if (is_array($form["fields"])) {
			$tmp_count = 0;
			foreach ($form["fields"] as $key => $val) {
				$tmp_count ++;
				$data .= $template->blocks["ListCell"]->Replace (
							array (
								"width" => $val["width"],
								"align" => $val["align"],
								"value" => "{" . strtoupper($key) . "}",
								"valign" => $val["valign"] ? $val["valign"] : "middle",
								"final" => !is_array($form["buttons"]) && ($tmp_count == count($form["fields"])) ? "Final" : ""
							)
						  );

				if ($val["type"] == "multiple")
					$val["header"] = $template->blocks["SimpleListMultipleHeader"]->Replace(array(
										"name" => $form["name"],
										"start" => $_old_count,
										"end" => $_new_count
									));

				//buildint the title header
				$titles .= $template->blocks["ListTitle"]->Replace ( array(
																		"title" => ($val["header"] ?  $val["header"]  : "&nbsp"),
																		"width" => $val["width"]

																	));
			}

			//adding one more title col in titles ( the one for buttons )
			if (is_array($form["buttons"])) {
				$titles .= $template->blocks["ListTitle"]->Replace ( array("title" => "&nbsp" ));
				$row = $data . $template->blocks["ButtonsCell"]->output;
			} else
				$row = $data;
			

			

			$template->blocks["ListElement"]->input = $template->blocks["ListRow"]->Replace(array("ROW"=> $row ));			
			$titles = $template->blocks["ListRow"]->Replace(array("ROW"=> $titles ));

			//  i know this is stupid, but now i dont have other idees
			//if i see a variable <no heade> then i clear the template
			if ($form["header"]["titles"] == "false") {
				$titles = "";
			}
			
		}
		
		//bulding the header buttons and search box
		if (is_array($form["header"]["buttons"])) {
			foreach ($form["header"]["buttons"] as $key => $val) {
				$val = array_merge($_GET , $val);

				$this->templates->blocks["Temp"]->input = $val["location"];
				$val["location"] = $this->templates->blocks["Temp"]->Replace($val);
				$val["location"] = CryptLink($val["location"]);
				$val["title"] = $val["title"];
				$val["onmouseout"] = $val["onmouseout"];
				$val["onmouseover"] = $val["onmouseover"];
				$val["onclick"] = $val["onclick"];

				$header["buttons"] .= $template->blocks["Button"]->Replace($val);
			}					
		}

		//  the search options, this is kinda buggy for this version, will be fixed in other
		if (is_array($form["header"]["search"])) {
			$form_search = $form["header"]["search"];

			//bulding the droplist options
			if (is_array($form_search["options"])) {

				foreach ($form_search["options"] as $key => $val) {
					$search_form[$key]["label"] = $val;
					$search_form[$key]["checked"] = $_GET[$form_search["variable"]] == $key ? " selected " : "";
				}
				
				
				$search["droplist"] = $html->FormSelect(
											"what" , 
											$search_form ,
											$template,
											"Select" ,
											$_GET["what"],
											$search_form ,
											array(	
												"width" => "" ,
												"onchange" => ""
											)
									);				

				//building the form and the buttons
				//reading all varibals from $_GET excepting the $_GET["page"], and transform them in hidden fields
				if (is_array($_GET)) {
					$temp = $_GET;

					//force the action variable
					$temp[$this->forms["uridata"]["action"]] = $this->forms["uridata"]["search"];

					foreach ($temp as $key => $val) {
						if (!in_array($key , array( "page" , "what" , "search")))  {
							
							$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"];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -