34 import(
'Dataface/FormTool.php');
35 import(
'Dataface/QuickForm.php');
37 $query =&
$app->getQuery();
43 if ( !isset($query[
'--tab']) and count($currentTable->tabs($currentRecord)) > 1 ){
44 list($query[
'--tab']) = array_keys($currentTable->tabs($currentRecord));
45 }
else if ( count($currentTable->tabs($currentRecord)) <= 1 ){
46 unset($query[
'--tab']);
49 $form = $formTool->createRecordForm($currentRecord,
true, @$query[
'--tab'], $query);
53 $res = $form->_build();
55 error_log($res->toString().Dataface_Error::printStackTrace());
56 throw new Exception(
"Error occurred while building the new record form. See error log for details.", E_USER_ERROR);
60 $formTool->decorateRecordForm($currentRecord, $form,
true, @$query[
'--tab']);
67 foreach ( $query as $key=>$value){
68 if ( strpos($key,
'-')===0 ){
69 $form->addElement(
'hidden', $key);
70 $form->setDefaults( array( $key=>$value) );
79 $form->addElement(
'hidden',
'-query');
80 $form->setDefaults( array(
'-action'=>$query[
'-action'],
'-query'=>
$_SERVER[
'QUERY_STRING']) );
94 if ( $formTool->validateRecordForm($currentRecord, $form,
true, @$query[
'--tab']) ){
101 $formTool->handleTabSubmit($currentRecord, $form, @$query[
'--tab']);
102 if ( !isset($query[
'--tab']) ){
105 $result = $form->process( array( &$form,
'save') );
109 $result = $formTool->saveSession($currentRecord,
true);
116 throw new Exception(
"Error occurred in save: ".mysql_error(
$app->db()), E_USER_ERROR);
121 $form->_errors[] =
$result->getMessage();
125 error_log(
$result->toString().
"\n".implode(
"\n",
$result->getBacktrace()));
126 throw new Exception(
"An error occurred while attempting to save the record. See server error log for details.", E_USER_ERROR);
137 if (@$query[
'-response'] ==
'json' ){
139 $rvals = $currentRecord->strvals();
140 $rvals[
'__title__'] = $currentRecord->getTitle();
141 $rvals[
'__id__'] = $currentRecord->getId();
142 echo json_encode(array(
'response_code'=>200,
'record_data'=> $rvals,
'response_message'=>df_translate(
'Record Successfully Saved',
'Record Successfully Saved')));
145 import(
'Dataface/Utilities.php');
158 $currentRecord->secureDisplay =
false;
159 if ( $currentRecord->checkPermission(
'edit') ){
160 $nextAction =
'edit';
162 $nextAction =
'view';
164 $url = $currentRecord->getURL(array(
'-action'=>$nextAction));
167 $msg = implode(
"\n",
$app->getMessages());
168 $msg = urlencode(trim(
171 "Record successfully saved",
173 "Record successfully saved."
175 if ( strpos($url,
'?') ===
false ) $url .=
'?';
176 $link = $url.
'&--msg='.$msg;
177 $app->redirect(
"$link");
184 $form->setDefaults($_GET);
186 $out = ob_get_contents();
189 if ( count($form->_errors) > 0 ){
194 $context = array(
'form'=>&
$out);
195 $context[
'tabs'] = $formTool->createHTMLTabs($currentRecord, $form, @$query[
'--tab']);
197 df_display($context,
'Dataface_New_Record.html',
true);