function Dataface_ShortRelatedRecordForm(&$record, $relationshipName, $db = '', $fieldNames = null) { $app =& Dataface_Application::getInstance(); if (is_a($record, 'Dataface_Record')) { /* * A Record has been passed as a parameter. */ $this->_record =& $record; } else { /* * A null record was passed as a parameter so we will load the correct record ourselves. */ $this->_record =& Dataface_ShortRelatedRecordForm::getRecord(); $record =& $this->_record; } $tableName = $record->_table->tablename; $this->_relatedRecord = new Dataface_RelatedRecord($record, $relationshipName); $this->_db = $db; $this->_relationshipName = $relationshipName; $this->_parentTable =& Dataface_Table::loadTable($tableName, $db); $this->_relationship =& $this->_parentTable->getRelationship($relationshipName); $this->_quickForms = array(); // Don't need this anymore because we load necessary quickforms at build time. $this->_built = false; $this->HTML_QuickForm($tableName . '_' . $relationshipName, 'post', '', '', array('accept-charset' => $app->_conf['ie']), true); $this->setJsWarnings(df_translate('quickform.warning.prefix', $this->_jsPrefix), df_translate('quickform.warning.postfix', $this->_jsPostfix)); $this->_renderer = new HTML_QuickForm_Renderer_Dataface($this); //$this->defaultRenderer(); $this->_renderer->setFormTemplate($this->getFormTemplate()); $this->_requiredNote = ''; if ($fieldNames === null) { //$this->_fieldNames =& $this->_relationship->_schema['columns']; $this->_fieldNames = $this->_relationship->fields(true, true); } else { $this->_fieldNames =& $fieldNames; } }
/** * Loads the parent record for this form. This may be called in static context. * This method is called in the constructor if no valid record is supplied. */ function &getRecord() { if (Dataface_ShortRelatedRecordForm::formSubmitted()) { $record = new Dataface_Record($_POST['-table'], array()); $io = new Dataface_IO($_POST['-table']); $query = $_POST['__keys__']; if (is_array($query)) { foreach (array_keys($query) as $postKey) { if ($query[$postKey][0] != '=') { $query[$postKey] = '=' . $query[$postKey]; } } } $io->read($query, $record); return $record; } else { $app =& Dataface_Application::getInstance(); $qt =& Dataface_QueryTool::loadResult($app->_currentTable); return $qt->loadCurrent(); } }
/** * Handles initialization and control for the new related record form. */ function _new_related_record_init() { import('Dataface/ShortRelatedRecordForm.php'); if (!isset($this->_params['relationship'])) { $this->_vars['error'] = "<div class=\"error\">Error. No relationship was specified.<!-- At line " . __LINE__ . " of file " . __FILE__ . " --></div>"; return; } $record = null; // we let the Form automatically handle loading of record. $form = new Dataface_ShortRelatedRecordForm($record, $this->_params['relationship']); $form->_build(); $this->_vars['form'] =& $form; if (!Dataface_PermissionsTool::edit($form->_record)) { $this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line " . __LINE__ . " of file " . __FILE__ . " --></div>"; return; } if ($form->validate()) { $vals = $form->exportValues(); $res = $form->process(array(&$form, 'save'), true); $response =& Dataface_Application::getResponse(); if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) { $this->_vars['error'] = "<div class=\"error\">Error. " . $res->toString() . "<!-- At line " . __LINE__ . " of file " . __FILE__ . " --></div>"; return; } else { if (Dataface_Error::isNotice($res)) { $success = false; $response['--msg'] = @$response['--msg'] . "\n" . $res->getMessage(); } else { $success = true; } } $query = array('-action' => 'browse'); $msg = urlencode(trim(($success ? "Record successfully added to " . $this->_params['relationship'] . " relationship.\n" : '') . @$response['--msg'])); foreach ($vals['__keys__'] as $key => $value) { $query[$key] = "=" . $value; } $link = Dataface_LinkTool::buildLink($query); header("Location: {$link}" . "&--msg=" . $msg); exit; } }
function handle(&$params) { //global $myctr; $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $resultSet =& $app->getResultSet(); //$record =& $app->getRecord(); // loads the current record import('Dataface/ShortRelatedRecordForm.php'); if (!isset($query['-relationship'])) { return PEAR::raiseError(Dataface_LanguageTool::translate('No relationship specified in new related record', 'No relationship was specified while trying to create new related record. Please specify a relationship.'), DATAFACE_E_ERROR); } $record = null; // we let the Form automatically handle loading of record. $form = new Dataface_ShortRelatedRecordForm($record, $query['-relationship']); $form->_build(); /* * * We need to add the current GET parameter flags (the GET vars starting with '-') so * that the controller knows to pass control to this method again upon form submission. * */ //$myctr = 0; foreach ($query as $key => $value) { //echo "doing $key"; if (strpos($key, '-') === 0) { $form->addElement('hidden', $key); $form->setDefaults(array($key => $value)); //if ( $myctr == 2 ) exit; } //$myctr++; } /* * Store the current query string (the portion after the '?') in the form, so we * can retrieve it after and redirect back to our original location. */ $form->addElement('hidden', '-query'); $form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING'])); if (!Dataface_PermissionsTool::checkPermission('add new related record', $form->_record, array('relationship' => $query['-relationship']))) { return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate('Permission denied while trying to add new related record', 'Permission Denied: You do not have permission to add related records to the current record.')); //$this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>"; //return; } if ($form->validate()) { $vals = $form->exportValues(); $res = $form->process(array(&$form, 'save'), true); $response =& Dataface_Application::getResponse(); if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) { return $res; //$this->_vars['error'] = "<div class=\"error\">Error. ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>"; //return; } else { if (Dataface_Error::isNotice($res)) { $success = false; $app->addError($res); //$response['--msg'] = @$response['--msg'] . "\n".$res->getMessage(); } else { $success = true; } } if ($success) { import('Dataface/Utilities.php'); Dataface_Utilities::fireEvent('after_action_new_related_record'); $fquery = array('-action' => 'browse'); $table = Dataface_Table::loadTable($query['-table']); $rel = $table->getRelationship($query['-relationship']); $msg = urlencode(trim(Dataface_LanguageTool::translate("Record successfully added to relationship", "Record successfully added to " . $rel->getLabel() . " relationship.\n", array('relationship' => $rel->getLabel())) . (isset($response['--msg']) ? $response['--msg'] : ''))); foreach ($vals['__keys__'] as $key => $value) { $fquery[$key] = "=" . $value; } $fquery['-relationship'] = $query['-relationship']; $fquery['-action'] = 'related_records_list'; $link = Dataface_LinkTool::buildLink($fquery); $app->redirect("{$link}" . "&--msg=" . $msg); } } ob_start(); $gdefs = array(); foreach ($_GET as $gkey => $gval) { if (substr($gkey, 0, 4) == '--q:') { $gdefs[substr($gkey, 4)] = $gval; } } if (count($gdefs) > 0) { $form->setDefaults($gdefs); } $form->display(); $out = ob_get_contents(); ob_end_clean(); $context = array('form' => $out); if (isset($query['-template'])) { $template = $query['-template']; } else { if (isset($params['action']['template'])) { $template = $params['action']['template']; } else { $template = 'Dataface_Add_New_Related_Record.html'; } } df_display($context, $template, true); }