_id: holds the primary key of the entry in the table (-1 = no entry in table i.e. create not update) * o _tn: holds the tablename for which the primary key is valid * o _type: holds the type of entry (text/boolean/list) - for parsing purposes * * The actual value is held in a form field name * * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa * @date 25 January 2003 * @todo - add client side validation stuff * @package lib.visualpatterns */ class PatternEditableTableSqlQuery { /** query to execute*/ var $sQuery; /** table to perform insert/update on */ var $sTableName; /** columns names in $sQuery to display */ var $aDisplayColumnNames; /** column names in $sQuery that will be stored/updated */ var $aStoreColumnNames; /** Array of boolean values dictating column editability */ var $aColumnsEditable; /** columns visible or not (store columns) */ var $aColumnsVisible; /** column types: 1 = text, 2 = boolean, 3 = drop down list */ var $aColumnTypes; /** Unique name */ var $sUniqueName; function PatternEditableTableSqlQuery($sTmpQuery, $sTmpTableName, $aTmpDisplayColumnNames, $aTmpStoreColumnNames, $aTmpColumnsEditable, $aTmpColumnsVisible, $sTmpUniqueName) { $this->sQuery = $sTmpQuery; $this->sTableName = $sTmpTableName; $this->aDisplayColumnNames = $aTmpDisplayColumnNames; $this->aStoreColumnNames = $aTmpStoreColumnNames; $this->aColumnsEditable = $aTmpColumnsEditable; $this->sUniqueName = $sTmpUniqueName; $this->aColumnsVisible = $aTmpColumnsVisible; } function setDisplayColumnHeadings($bNewValue) { $this->bDisplayColumnHeadings = $bNewValue; } function setTableCaption($sNewValue) { $this->sTableCaption = $sNewValue; } function setColumnHeaderNames($aNewValue) { $this->aColumnHeaderNames = $aNewValue; } function getRequiredVariableNames() { return $this->aRequiredVariableNames; } function & render() { //$sToRender = "sWidth>\n"; $sToRender = "
\n"; if (isset($this->sTableCaption)) { $sToRender .= "\n"; } if ($this->bDisplayColumnHeadings) { for ($i = 0; $i < count($this->aColumnHeaderNames); $i++) { $sToRender .= "\n"; } } $sql = new Owl_DB(); $sql->query($this->sQuery); if ($sql->num_rows() == 0) { $sToRender .= "\n"; $sToRender .= "\n"; $sToRender .= "\n"; } else { $iRowCount = 0; while ($sql->next_record()) { $sToRender .= "\n"; $sToRender .= "sUniqueName . "_" . $iRowCount . "\" value=\"" . $sql->f("id") . "\" />\n"; $sToRender .= "sUniqueName . "_" . $iRowCount . "_tc\" value=\"" . $this->sTableName . "\" />\n"; for ($i = 0; $i < count($this->aStoreColumnNames); $i++) { //generate the right kind of editable field $sToRender .= "\t\n"; } $sToRender .= "\n"; $iRowCount++; } } $sToRender .= "
$this->sTableCaption
" . $this->aColumnHeaderNames[$i] . "
No " . (isset($this->sTableCaption) ? $this->sTableCaption : "") . " data
\n"; if ($this->aColumnsVisible[$i]) { if ($this->aColumnsEditable[$i]) { $sToRender .= "\tsUniqueName . "_" . $iRowCount . "_value\" value=\"" . $sql->f($this->aStoreColumnNames[$i]) . "\" />\n"; } else { $sToRender .= "\tsUniqueName . "_" . $iRowCount . "_value\" value=\"" . $sql->f($this->aStoreColumnNames[$i]) . "\" />".$sql->f($this->aDisplayColumnNames[$i])."\n"; } } else { $sToRender .= "\tsUniqueName . "_" . $iRowCount . "_value\" value=\"" . $sql->f($this->aStoreColumnNames[$i]) . "\" />"; } $sToRender .= "\tsUniqueName . "_" . $iRowCount . "_tc\" value=\"" . $this->aStoreColumnNames[$i] . "\" />\n"; $sToRender .= "\t
"; return $sToRender; } } /* case 1: $sToRender .= "\t\n"; if ($this->aColumnsVisible[$i]) { $sToRender .= "\t\tsUniqueName . "_" . $this->iVariableCount . "\" value=\"" . $sql->f($this->aDisplayColumns[$i]) . "\" />\n"; $sToRender .= "\t\tsUniqueName . "_" . $this->iVariableCount . "_row\" value=\"" . $iRowCount . "\" />\n"; $sToRender .= "\t\tsUniqueName . "_" . $this->iVariableCount . "_id\" value=\"" . $sql->f($this->aPrimaryKey[$i]) . "\" />\n"; $sToRender .= "\t\tsUniqueName . "_" . $this->iVariableCount . "_tn\" value=\"" . $this->sTableName . "\" />\n"; $sToRender .= "\t\tsUniqueName . "_" . $this->iVariableCount . "_tc\" value=\"" . $this->aTableColumns[$i] . "\" />\n"; $sToRender .= "\t\tsUniqueName . "_" . $this->iVariableCount . "_type\" value=\"text\" />\n"; if ($this->aColumnsRequired[$i]) { $this->aRequiredFormVariableNames[count($this->aRequiredFormVariableNames)] = "unique_" .$this->sUniqueName . "_" . $this->iVariableCount; } $this->iVariableCount++; } else { $sToRender .= "\t\t" . $sql->f($this->aColumnsSql[$i]) . "\n"; } $sToRender .= "\t\n"; break; case 2: //todo - implement checkbox functionality break; case 3: //todo - implement drop down list functionality break; default: break; */ ?>