/** * @param $tablename The name of the table upon which this form is based. - or a Dataface_Record object to edit. * @type string | Dataface_Record * * @param $db DB handle for the current database connection. * @type resource * * @param $query Associative array of query parameters to dictate which record is loaded for editing. * @type array([String]->[String]) * * @param $new Flag to indicate whether this form is creating a new record or editing an existing one. * @type boolean * * @param $fieldnames An optional array of field names to include in the form. * @type array(string) * */ function Dataface_QuickForm($tablename, $db = '', $query = '', $formname = '', $new = false, $fieldnames = null, $lang = null) { $app =& Dataface_Application::getInstance(); $this->app =& $app; $appQuery =& $app->getQuery(); if (!isset($lang) && !isset($this->_lang)) { $this->_lang = $app->_conf['lang']; } else { if (isset($lang)) { $this->_lang = $lang; } } if (is_a($tablename, 'Dataface_Record')) { if (!$this->formSubmitted()) { $this->_record =& $tablename; $this->tablename = $this->_record->_table->tablename; $this->_table =& $this->_record->_table; unset($tablename); $tablename = $this->tablename; } else { $this->_record =& Dataface_QuickForm::getRecord(); $this->tablename = $tablename; $this->_table =& Dataface_Table::loadTable($this->tablename); } } else { if (!$new) { if ($tablename == $appQuery['-table']) { $this->_record =& Dataface_QuickForm::getRecord(); } else { if ($query) { $this->_record =& df_get_record($tablename, $query); } } if (!$this->_record) { $this->_record = new Dataface_Record($tablename, array()); } $this->tablename = $tablename; $this->_table =& Dataface_Table::loadTable($this->tablename); //$tablename = $this->tablename; } else { $this->tablename = $tablename; $this->_table =& Dataface_Table::loadTable($this->tablename, $this->db); $this->_record = new Dataface_Record($this->tablename, array()); } } $this->_new = $new; if (!$formname) { if ($new) { $formname = "new_" . $tablename . "_record_form"; } else { $formname = "existing_" . $tablename . "_record_form"; } } if (!$db) { $db = $app->db(); } $this->db = $db; $this->_query = is_array($query) ? $query : array(); // The cursor tells us which record in the dataset we will be editing. if (!isset($this->_query['-cursor'])) { $this->_query['-cursor'] = 0; } // Load the results of the query. $this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $this->_query); parent::HTML_QuickForm($formname, 'post', df_absolute_url($_SERVER['PHP_SELF']), '', array('accept-charset' => $app->_conf['ie']), self::$TRACK_SUBMIT); $this->setJsWarnings(df_translate('quickform.warning.prefix', $this->_jsPrefix), df_translate('quickform.warning.postfix', $this->_jsPostfix)); //$this->_fields =& $this->_table->fields(false,false,true); $this->_fields =& $this->_table->formFields(false, true); if (@$appQuery['-xf-hide-fields']) { $hiddenFields = explode(' ', $appQuery['-xf-hide-fields']); $css = array(); foreach ($hiddenFields as $f) { if (isset($this->_fields[$f])) { $css[] = "#{$f}_form_row { display:none;}"; // $this->_fields[$f]['widget']['type'] = 'hidden'; // $fieldDef =& Dataface_Table::loadTable($this->_fields[$f]['tablename'])->getField($f); // $fieldDef['widget']['type'] = 'hidden'; // unset($fieldDef); // //$field =& } } if ($css) { $app->addHeadContent('<style type="text/css">' . implode('', $css) . '</style>'); } } //$this->_record = new Dataface_Record($this->_table->tablename, array()); $this->_renderer = new HTML_QuickForm_Renderer_Dataface($this); //$this->defaultRenderer(); $this->_renderer->setFormTemplate($this->getFormTemplate()); $this->_requiredNote = ''; if (is_array($fieldnames)) { /* * $fieldnames were specified in the parameters. We will use the provided * field names but we must make sure that the fields exist. */ $this->_fieldnames = array(); foreach ($fieldnames as $fieldname) { if (isset($this->_fields[$fieldname])) { $this->_fieldnames[] = $fieldname; } } } //$this->_build(); }
/** * @param $tablename The name of the table upon which this form is based. - or a Dataface_Record object to edit. * @type string | Dataface_Record * * @param $db DB handle for the current database connection. * @type resource * * @param $query Associative array of query parameters to dictate which record is loaded for editing. * @type array([String]->[String]) * * @param $new Flag to indicate whether this form is creating a new record or editing an existing one. * @type boolean * * @param $fieldnames An optional array of field names to include in the form. * @type array(string) * */ function Dataface_QuickForm($tablename, $db = '', $query = '', $formname = '', $new = false, $fieldnames = null, $lang = null) { $app =& Dataface_Application::getInstance(); $this->app =& $app; $appQuery =& $app->getQuery(); if (!isset($lang) && !isset($this->_lang)) { $this->_lang = $app->_conf['lang']; } else { if (isset($lang)) { $this->_lang = $lang; } } if (is_a($tablename, 'Dataface_Record')) { if (!$this->formSubmitted()) { $this->_record =& $tablename; $this->tablename = $this->_record->_table->tablename; $this->_table =& $this->_record->_table; unset($tablename); $tablename = $this->tablename; } else { $this->_record =& Dataface_QuickForm::getRecord(); $this->tablename = $tablename; $this->_table =& Dataface_Table::loadTable($this->tablename); } } else { if (!$new) { if ($tablename == $appQuery['-table']) { $this->_record =& Dataface_QuickForm::getRecord(); } else { if ($query) { $this->_record =& df_get_record($tablename, $query); } } if (!$this->_record) { $this->_record = new Dataface_Record($tablename, array()); } $this->tablename = $tablename; $this->_table =& Dataface_Table::loadTable($this->tablename); //$tablename = $this->tablename; } else { $this->tablename = $tablename; $this->_table =& Dataface_Table::loadTable($this->tablename, $this->db); $this->_record = new Dataface_Record($this->tablename, array()); } } $this->_new = $new; if (!$formname) { if ($new) { $formname = "new_" . $tablename . "_record_form"; } else { $formname = "existing_" . $tablename . "_record_form"; } } if (!$db and defined('DATAFACE_DB_HANDLE')) { $db = DATAFACE_DB_HANDLE; } else { $db = $app->_db; } $this->db = $db; $this->_query = is_array($query) ? $query : array(); // The cursor tells us which record in the dataset we will be editing. if (!isset($this->_query['-cursor'])) { $this->_query['-cursor'] = 0; } // Load the results of the query. $this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $this->_query); parent::HTML_QuickForm($formname, 'post', df_absolute_url($_SERVER['PHP_SELF']), '', array('accept-charset' => $app->_conf['ie']), true); //$this->_fields =& $this->_table->fields(false,false,true); $this->_fields =& $this->_table->formFields(false, true); //$this->_record = new Dataface_Record($this->_table->tablename, array()); $this->_renderer = new HTML_QuickForm_Renderer_Dataface($this); //$this->defaultRenderer(); $this->_renderer->setFormTemplate($this->getFormTemplate()); $this->_requiredNote = ''; if (is_array($fieldnames)) { /* * $fieldnames were specified in the parameters. We will use the provided * field names but we must make sure that the fields exist. */ $this->_fieldnames = array(); foreach ($fieldnames as $fieldname) { if (isset($this->_fields[$fieldname])) { $this->_fieldnames[] = $fieldname; } } } //$this->_build(); }