_row_added(tableId, rowNr) _field_changed(tableId, rowNr, fieldId, field) */ private $tablename = ""; private $fields = array(); public $editmode = false; public $fields_details = null; public $keyfield = ""; public function HaproxyHtmlList($tablename, $fields) { $this->tablename = $tablename; $this->fields = $fields; } public function Draw($data) { $this->haproxy_htmllist($data, $this->fields, $this->editmode, $this->fields_details); } public function outputjavascript() { $table_def = array(); $table_def['keyfield'] = $this->keyfield; phparray_to_javascriptarray($table_def, "tabledefinition_".$this->tablename,Array('/*','/*/*')); phparray_to_javascriptarray($this->fields, "fields_".$this->tablename,Array('/*','/*/name','/*/type','/*/text','/*/size','/*/items','/*/items/*','/*/items/*/*','/*/items/*/*/name')); if (count($this->fields_details) != 0) { phparray_to_javascriptarray($this->fields_details,"fields_details_".$this->tablename,Array('/*','/*/name','/*/columnheader','/*/description','/*/type','/*/text','/*/size','/*/items','/*/items/*','/*/items/*/*','/*/items/*/*/name','/*/items/*/*/name')); } } // function retrieves all posted values and returns an array public function haproxy_htmllist_get_values() { $values = array(); for($x = 0; $x < 99; $x ++) { $value = array(); $add_item = false; if (is_array($this->fields_details)) { $fields = array_merge($this->fields, $this->fields_details); } else { $fields = $this->fields; } foreach($fields as $item) { $itemname = $item['name']; $value[$itemname] = $_POST[$this->tablename.$itemname.$x]; if ($item['type'] == 'textarea') { $value[$itemname] = base64_encode($value[$itemname]); } $add_item |= isset($_POST[$this->tablename.$itemname.$x]); } if ($add_item) { if ($this->keyfield != "") { if (isset($_POST[$this->tablename."_key".$x])) { $key = $_POST[$this->tablename."_key".$x]; } else { $key = $_POST[$this->tablename.$this->keyfield.$x]; } } else { $key = ""; } $index = $_POST[$this->tablename."_rowindex".$x]; $value['_index'] = $index; if (isset($values[$key])) { $values[] = $value; } else { $values[$key] = $value; } } } usort($values, 'sort_index'); return $values; } function haproxy_htmllist_drawcell($item, $itemvalue, $editable, $itemname, $counter) { $itemnamenr = $this->tablename . $itemname . $counter; $itemtype = $item['type']; if ($editable) { $itemtype = $item['type']; if ($itemtype == "select") { echo_html_select($itemnamenr, $item['items'], $itemvalue,"-none available-","html_listitem_change(\"{$this->tablename}\",\"{$itemname}\",\"{$counter}\",this);", "width:{$item['size']}"); } elseif ($itemtype == "checkbox") { $checked = $itemvalue=='yes' ? " checked" : ""; echo ""; } elseif ($itemtype == "textarea") { echo ""; } elseif ($itemtype == "fixedtext") { echo $item['text']; } else { echo ""; } } else { if ($itemtype == "select") { echo $item['items'][$itemvalue]['name']; } elseif ($itemtype == "checkbox") { echo $itemvalue=='yes' ? gettext('yes') : gettext('no'); } elseif ($itemtype == "textarea") { echo "
"; echo str_replace(" "," ", str_replace("\n","
", htmlspecialchars(base64_decode($itemvalue)))); echo '
'; } elseif ($itemtype == "fixedtext") { echo $item['text']; } else { echo htmlspecialchars($itemvalue); } } } function haproxy_htmllist($rowvalues,$items,$editstate=false,$itemdetails=null){ $tablename = $this->tablename; global $g, $counter; echo ""; foreach($items as $item){ echo ""; } echo ""; if (is_array($rowvalues)) { foreach($rowvalues as $keyid => $value) { if (!empty($this->keyfield)) { if (preg_match("/[^0-9]/", $keyid)) { $itemvalue = $keyid; } else { $itemvalue = $value[$this->keyfield]; } $key = ""; } else { $key = ""; } if (!$editstate) { echo ""; $leftitem = true; foreach($items as $item) { $tdclass = $leftitem ? "vtable listlr" : "vtable listr"; echo ""; $leftitem = false; } echo " "; echo ""; } $displaystyle = $editstate ? "" : "display: none;"; echo ""; foreach($items as $item){ $itemname = $item['name']; $itemvalue = $value[$itemname]; echo ""; $key = ""; } echo " "; echo ""; if (isset($itemdetails)) { $colspan = count($items)-1; echo ""; ?> "; $itemnr = 0; echo "
"; $itemcount = count($itemdetails); $leftitem = true; foreach($itemdetails as $item) { $itemname = $item['name']; $itemvalue = $value[$itemname]; //TODO don't filter empty items, filter context un-related items through customizable function.. if (empty($itemvalue)) { continue; } echo "
"; $tdclass = ""; if (!$leftitem) { echo ", "; } $leftitem = false; echo $item['columnheader'] . ": "; if (isset($item['customdrawcell'])) { $item['customdrawcell']($this, $item, $itemvalue, false, $itemname, $counter); } else { $this->haproxy_htmllist_drawcell($item, $itemvalue, false, $itemname, $counter); } $itemnr++; echo "
"; } echo "
"; echo "
{$item['columnheader']}
"; $itemname = $item['name']; $itemvalue = $value[$itemname]; if (isset($item['customdrawcell'])) { $item['customdrawcell']($this, $item, $itemvalue, false, $itemname, $counter); } else { $this->haproxy_htmllist_drawcell($item, $itemvalue, false, $itemname, $counter); } echo " "; if (empty($this->noindex)) { echo ""; } echo "
".$key; if (isset($item['customdrawcell'])) { $item['customdrawcell']($this, $item, $itemvalue, true, $itemname, $counter); } else { $this->haproxy_htmllist_drawcell($item, $itemvalue, true, $itemname, $counter); } echo " "; if (empty($this->noindex)) { echo ""; } echo "
"; foreach($itemdetails as $item) { $itemname = $item['name']; echo ""; echo ""; echo ""; echo ""; } echo "
"; echo "{$item['columnheader']}: "; echo ""; $itemvalue = $value[$itemname]; if (!empty($item['description'])) { echo "{$item['description']}
"; } if (isset($item['customdrawcell'])) { $item['customdrawcell']($this, $item, $itemvalue, true, $itemname, $counter); } else { $this->haproxy_htmllist_drawcell($item, $itemvalue, true, $itemname, $counter); } echo "
"; echo ""; echo ""; echo ""; } $counter++; } } echo " "; } } function sort_index(&$a, &$b) { // sort callback function, cannot be inside the object. if ($a['_index'] != $b['_index']) { return $a['_index'] > $b['_index'] ? 1 : -1; } return 0; } function haproxy_htmllist($tablename,$rowvalues,$items,$editstate=false,$itemdetails=null){ $list = new HaproxyHtmlList($tablename, $items); $list->haproxy_htmllist($rowvalues, $items, $editstate, $itemdetails); } function haproxy_htmllist_get_values($tablename, $html_list){ $list = new HaproxyHtmlList($tablename, $html_list); return $list->haproxy_htmllist_get_values(); } function haproxy_htmllist_js(){ global $g; ?>