34 import(
'Dataface/FormTool.php');
35 import(
'Dataface/QuickForm.php');
39 $query =&
$app->getQuery();
40 $resultSet =&
$app->getResultSet();
42 $currentRecord =&
$app->getRecord();
44 if ( !isset($query[
'--tab']) and count($currentTable->tabs($currentRecord)) > 1 ){
45 list($query[
'--tab']) = array_keys($currentTable->tabs($currentRecord));
46 }
else if ( count($currentTable->tabs($currentRecord)) <= 1 ){
47 unset($query[
'--tab']);
61 if ( $resultSet->found()> @$query[
'-cursor']){
62 $form = $formTool->createRecordForm($currentRecord,
false, @$query[
'--tab'], $query);
68 $res = $form->_build();
70 error_log($res->toString().implode(
"\n", $res->getBacktrace()));
71 throw new Exception(
"An error occurred while building the edit form. See error log for details.", E_USER_ERROR);
75 $formTool->decorateRecordForm($currentRecord, $form,
false, @$query[
'--tab']);
84 foreach ( $query as $key=>$value){
85 if ( strpos($key,
'-')===0 ){
86 $form->addElement(
'hidden', $key);
87 $form->setDefaults( array( $key=>$value) );
96 $form->addElement(
'hidden',
'-query');
97 $form->setDefaults( array(
'-action'=>$query[
'-action'],
'-query'=>
$_SERVER[
'QUERY_STRING']) );
111 if ( $formTool->validateRecordForm($currentRecord, $form,
false, @$query[
'--tab']) ){
117 $app->clearMessages();
118 $formTool->handleTabSubmit($currentRecord, $form, @$query[
'--tab']);
119 if ( !isset($query[
'--tab']) ){
123 $result = $form->process( array( &$form,
'save') );
128 $result = $formTool->saveSession($currentRecord);
135 throw new Exception(
"An error occurred while attempting to save the record. See error log for details.", E_USER_ERROR);
143 error_log(
$result->toString(). implode(
"\n",
$result->getBacktrace()));
144 throw new Exception(
"An error occurred while attempting to save the record. See error log for details.", E_USER_ERROR);
157 if (@$query[
'-response'] ==
'json' ){
159 $rvals = $currentRecord->strvals();
160 $rvals[
'__title__'] = $currentRecord->getTitle();
161 $rvals[
'__id__'] = $currentRecord->getId();
162 echo htmlspecialchars(json_encode(array(
'response_code'=>200,
'record_data'=> $rvals,
'response_message'=>df_translate(
'Record Successfully Saved',
'Record Successfully Saved'))));
166 import(
'Dataface/Utilities.php');
174 $vals = $form->exportValues();
175 $vals[
'-query'] = preg_replace(
'/[&\?]-new=[^&]+/i',
'', $vals[
'-query']);
177 $_SESSION[
'--last_modified_record_url'] = $form->_record->getURL();
178 $_SESSION[
'--last_modified_record_title'] = $form->_record->getTitle();
180 $msg = implode(
"\n",
$app->getMessages());
185 'Record successfully saved',
187 "Record successfully saved.<br>"
191 if ( preg_match(
'/[&\?]-action=edit&/', $vals[
'-query']) and !$form->_record->checkPermission(
'edit') ){
192 $vals[
'-query'] = preg_replace(
'/([&\?])-action=edit&/',
'$1-action=view&', $vals[
'-query']);
193 }
else if ( preg_match(
'/[&\?]-action=edit$/', $vals[
'-query']) and !$form->_record->checkPermission(
'edit') ){
194 $vals[
'-query'] = preg_replace(
'/([&\?])-action=edit$/',
'$1-action=view', $vals[
'-query']);
196 $vals[
'-query'] = preg_replace(
'/&?--msg=[^&]*/',
'', $vals[
'-query']);
198 $link =
$_SERVER[
'HOST_URI'].DATAFACE_SITE_HREF.
'?'.$vals[
'-query'].
'&--msg='.$msg;
206 $app->redirect(
"$link");
212 $out = ob_get_contents();
215 if ( count($form->_errors) > 0 ){
216 $app->clearMessages();
217 $app->addError(
PEAR::raiseError(
"Some errors occurred while processing this form: <ul><li>".implode(
'</li><li>', $form->_errors).
"</li></ul>"));
219 $context = array(
'form'=>
$out);
223 $context[
'tabs'] = $formTool->createHTMLTabs($currentRecord, $form, @$query[
'--tab']);
228 $context = array(
'form'=>
'');
230 if ( isset($_SESSION[
'--last_modified_record_url']) ){
231 $lastModifiedURL = $_SESSION[
'--last_modified_record_url'];
232 $lastModifiedTitle = $_SESSION[
'--last_modified_record_title'];
233 unset($_SESSION[
'--last_modified_record_title']);
234 unset($_SESSION[
'--last_modified_record_url']);
237 'Return to last modified record',
238 'No records matched your request. Click <a href="'.$lastModifiedURL.
'">here</a> to return to <em>'.htmlspecialchars($lastModifiedTitle).
'</em>.',
239 array(
'lastModifiedURL'=>$lastModifiedURL,
240 'lastModifiedTitle'=>$lastModifiedTitle
247 'No records matched request',
248 'No records matched your request'
253 $query[
'-template'] =
'Dataface_Main_Template.html';
257 if ( isset($query[
'-template']) ) $template = $query[
'-template'];
258 else if ( isset( $params[
'action'][
'template']) ) $template = $params[
'action'][
'template'];
259 else $template =
'Dataface_Edit_Record.html';
262 df_display($context, $template,
true);