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

📄 forms.php

📁 基于PHP的一套网络管理系统代码,对接口流量等可以进行详细的统计分析,很不错.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		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,$form_US_states,$form_countries , $_VARS , $_USER , $base;

		//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' , 'separator' , 'link'"
			);

		$field = $form["fields"][$_field];
		
		$field["_end_char"] = $field["title"] ? ":" : "";

		//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 (!isset($values["values"][$field["name"]])) {		
			switch ($field["action"]) {
				case "eval":
					if (isset($field["default"]))
						eval("\$field[\"value\"] = " . $field["default"] . ";");
				break;

				default:
					$field["value"]	= $field["default"];
				break;
			}
		} else {
			
			$field["value"] = $values["values"][$field["name"]];
		}
		
		//somtimes i may want to force a specific value nomatter of what is already set
		if (isset($field["forcevalue"])) {
			switch ($field["action"]) {
				case "eval":
//					echo $field["forcevalue"];
					eval("\$field[\"value\"] = " . $field["forcevalue"] . ";");
				break;

				default:
					$field["value"] = $field["forcevalue"];
				break;
			}

		}

		//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"])) {
			$field["value"] = GetFileContents($_CONF["path"] . $_CONF["upload"] . $field["file"]["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"]);
		}		

		//strip the slashes from the value
//		$field["value"] = stripslashes($field["value"]);
			
		//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;
				}

				//okay so ...
				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"] = 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 {

						//else the size field is the size of textbox
						$field["_size"] = $field["size"];
						$field["_maxlength"] = $_textboxMaxLength;
					}

				} else {

					//check if there is defined any withd value
					if ($field["width"]) {
					} else {
						//get the default values

						$field["_size"] = $_textboxSize;
						$field["_maxlength"] = $_textboxMaxLength;
					}

					
				}

				if (!isset($values["values"][$field["name"] . "_confirm"]))				
					$values["values"][$field["name"] . "_confirm"] = $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 "sql":
				if (is_array($field["sql"])) {
					$form_sql_vars = array();

					if (is_array($field["sql"]["vars"])) {
						foreach ($field["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 = $field["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);								

						$field["value"] = $record[$field["sql"]["field"]];
					}							
				}
			case "text":

				$field["value"] = $field["html"] == "true" ? $field["value"] : nl2br(htmlentities($field["value"]));

				$field["action"] = $field["subtype"] ? $field["subtype"] : $field["action"];

				switch ($field["action"]) {
					case "date":
						if (isset($values["values"][$field["name"] . "_day" ]) && isset($values["values"][$field["name"] . "_month" ]) && isset($values["values"][$field["name"] . "_year" ])) 
							$field["value"] = 
												( $values["values"][$field["name"] . "_month" ] ? sprintf("%02d" ,$values["values"][$field["name"] . "_month" ])  : "--" ). "." . 
												( $values["values"][$field["name"] . "_day" ] ? sprintf("%02d" ,$values["values"][$field["name"] . "_day" ]) : "--" ) . "." .  
												( $values["values"][$field["name"] . "_year" ] ? $values["values"][$field["name"] . "_year" ] : "----" ) ;
						else						
							$field["value"] = $field["value"] > 0 ? @date($field["params"] , $field["value"]) : "not available";
					break;

					case "price":
						$field["value"] = number_format($field["value"] , 2);
					break;
				}

//WARNING THIS IS IN TESTING MODE SO IF ANYTHING WILL GO WRONG IT WILL DISPEAR				
				//do some special tricks, to transform the links and the email addresses in urls
//				if ($field["linkstransform"] == "true") {
				//check if there is any html content around
				if ($field["html"] != "true") {
					$field["value"] = 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", $field["value"]);
					$field["value"] = eregi_replace("(http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href=\"\\1://\\2\" title=\"Click to open in new window.\" target=\"_blank\">\\2</a>", $field["value"]);
				}

//				}

				//format the text
				switch ($field["font"]) {

					case "normal":
					break;

					default:
						$field["value"] = "<b>" . $field["value"] . "</b>";
					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["valign"] ? $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";
/*
				//  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;
					}
				}								
*/				
				$current_field = $this->templates->blocks["hidden"]->Replace($field , false);
				//$current_field = $this->templates->blocks["hidden"]->EmptyVars();	
				$current_field_extra = "";
			break;

			case "button":			
				$current_field = $this->templates->blocks["button"]->Replace($field , false);
				//$this->templates->blocks["button"]->EmptyVars();							

				//if the field hs description then i add the valign code
				$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : ""; 
			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 "USstates":								

⌨️ 快捷键说明

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