Esempio n. 1
0
	public function getScaffoldingEditRow($attName,$options=array())
	{
		$row=$this->getScaffoldingFileRow($attName,$options);
		if ($row!==false)
			return $row;

		$link="";
		if (isset($this->dataStructure['fields'][$attName]['link_class'])) {
			$class=$this->dataStructure['fields'][$attName]['link_class'];
			if (
				$this->id &&
				$this->getAttr($attName)
			) {
				$obj=$this->getObject($attName);
				$name=$obj->getNameH();
				if ($name)
					$name=" (".$name.")";
				$link=$name." <a href='objectEdit.php?c=".rawurlencode($class)."&amp;id=".rawurlencode($this->getAttr($attName))."'>"._LS('scaffoldingEditLink',htmlspecialchars($class),$this->getAttrH($attName))."</a>";
			}
			$link.=" <a href='#' onClick='return LPC_scaffolding_pickObject(\"".addslashes($class)."\",$(this).prevAll(\"input\").get(0))'>☞</a>";
		}
		if (!$this->id)
			$this->setAttr($attName,$this->getScaffoldingDefault($attName));
		$type="";
		if (isset($this->dataStructure['fields'][$attName]['type']))
			$type=$this->dataStructure['fields'][$attName]['type'];
		switch($type) {
			case 'integer':
				$input="<input type='text' name='attr[$attName]' size='6' value=\"".$this->getAttrH($attName)."\">".$link;
				break;
			case 'date':
				if ($val=$this->getAttr($attName))
					$val=date('Y-m-d',$val);
			case 'datetime':
				if (!isset($val) && ($val=$this->getAttr($attName)))
					$val=date('Y-m-d H:i',$val);
				$input=
					"<input type='text' name='attr[$attName]' value=\"".$val."\" class='input-date' id='attr_$attName'>".
					"<input type='button' value=\"".addslashes(_LS('scaffoldingSetDateNow'))."\" onClick=\"$('#attr_$attName').val('+0 minutes')\">";
				break;
			case 'longtext':
			case 'html':
				// HTML + longtext
				$input = new LPC_HTML_node('textarea');
				$input->setAttrs(array(
					'name' => "attr[$attName]",
					'style' => 'width: 100%; height: 150px',
				));
				$input->a($this->getAttrH($attName));
				if ('longtext' == $type)
					break;

				// HTML only
				$input->setAttr('style', $input->getAttr('style')."; min-width: 600px; height: 250px");
				$input = new LPC_HTML_html_editor($input, true);

				break;
			case 'boolean':
				if ($this->getAttr($attName)) {
					$checked_yes=" checked";
					$checked_no="";
				} else {
					$checked_yes="";
					$checked_no=" checked";
				}
				$input=
					"<input type='radio' name='attr[$attName]' value='1'$checked_yes id='{$attName}_yes'> <label for='{$attName}_yes'>"._LH('scaffoldingBooleanYes')."</label><br>".
					"<input type='radio' name='attr[$attName]' value='0'$checked_no id='{$attName}_no'> <label for='{$attName}_no'>"._LH('scaffoldingBooleanNo')."</label>";
				break;
			case 'enum':
			case 'set':
				if (!isset($this->dataStructure['fields'][$attName]['options']))
					throw new RuntimeException("You need to define the options explicitly for enum and set fields (key 'options' in the data structure).");
				$input=new LPC_HTML_node('div');

				$inputS=new LPC_HTML_select("attr[$attName]");
				$input->a($inputS);
				if ($type=='set') {
					// Allow for an empty set by providing an empty option which will be processed on POST
					$input->a("<input type='hidden' name=\"attr[$attName][]\" value='NULL'>");

					$inputS->setAttr('name',"attr[$attName][]");
					$inputS->setAttr('multiple','multiple');
					$inputS->setAttr('size',min(5,count($this->dataStructure['fields'][$attName]['options'])));
				}
				$values=explode(",",$this->getAttr($attName));
				foreach($this->dataStructure['fields'][$attName]['options'] as $option) {
					$optionH=new LPC_HTML_node('option');
					$optionH->compact=true;
					if (in_array($option,$values))
						$optionH->setAttr('selected',1);
					$optionH->setAttr('value',addslashes($option));
					$optionH->a(htmlspecialchars($option));
					$inputS->a($optionH);
				}
				break;
			default:
				$input="<input type='text' name='attr[$attName]' oninput=\"LPC_scaffolding_onTextInput(this)\" value=\"".$this->getAttrH($attName)."\" style='width:90%;'>".$link;
		}
		if (isset($this::$scaffoldingDesc[$attName]))
			$attDesc=_LS($this::$scaffoldingDesc[$attName]['name']);
		else
			$attDesc=$attName;
		if (empty($options['NO_SQL_DESC'])) {
			$rs=$this->query("DESCRIBE ".$this->getTableName()." ".$this->getFieldName($attName,true));
			$attDesc = "<span title=\"".htmlspecialchars($rs->fields['Type'])."\">".$attDesc."</span>";
		}
		if (isset($this::$scaffoldingDesc[$attName]['desc']) && empty($options['NO_LPC_DESC']))
			$attDesc.="<div style='font-weight:normal; font-size:80%'>"._LS($this::$scaffoldingDesc[$attName]['desc'])."</div>";

		$row=new LPC_HTML_form_row(array(
			'label'=>$attDesc,
			'input'=>$input,
		));
		$row->compact=true;
		return $row;
	}