Xataface 2.0
Xataface Application Framework
actions/new_related_record.php
Go to the documentation of this file.
00001 <?php
00002 class dataface_actions_new_related_record {
00003         
00004         function handle(&$params){
00005                 //global $myctr;
00006                 $app =& Dataface_Application::getInstance();
00007                 $query =& $app->getQuery();
00008                 $resultSet =& $app->getResultSet();
00009                 
00010                 //$record =& $app->getRecord(); // loads the current record 
00011                 
00012                 import( 'Dataface/ShortRelatedRecordForm.php');
00013                 if ( !isset( $query['-relationship'])){
00014                         return PEAR::raiseError(Dataface_LanguageTool::translate(
00015                                 'No relationship specified in new related record',
00016                                 'No relationship was specified while trying to create new related record.  Please specify a relationship.'
00017                                 ), DATAFACE_E_ERROR
00018                         );
00019                 }
00020 
00021 
00022                 $record = null; // we let the Form automatically handle loading of record.
00023                 $form = new Dataface_ShortRelatedRecordForm($record, $query['-relationship']);
00024 
00025                 $form->_build();
00026                 
00027                 /*
00028                  *
00029                  * We need to add the current GET parameter flags (the GET vars starting with '-') so
00030                  * that the controller knows to pass control to this method again upon form submission.
00031                  *
00032                  */
00033                 //$myctr = 0;
00034                 foreach ( $query as $key=>$value){
00035                         //echo "doing $key";
00036                         
00037                         if ( strpos($key,'-')===0 ){
00038                                 $form->addElement('hidden', $key);
00039                                 
00040                                 
00041                                 $form->setDefaults( array( $key=>$value) );
00042                                 //if ( $myctr == 2 ) exit;
00043                                 
00044                                 
00045                                 
00046                         }
00047                         //$myctr++;
00048                 }
00049                 
00050                 /*
00051                  * Store the current query string (the portion after the '?') in the form, so we 
00052                  * can retrieve it after and redirect back to our original location.
00053                  */
00054                 $form->addElement('hidden', '-query');
00055                 $form->setDefaults( array( '-action'=>$query['-action'],'-query'=>$_SERVER['QUERY_STRING']) );
00056                 
00057                 
00058                 if ( !Dataface_PermissionsTool::checkPermission('add new related record',$form->_record, array('relationship'=>$query['-relationship']))){
00059                         return Dataface_Error::permissionDenied(
00060                                 Dataface_LanguageTool::translate(
00061                                         'Permission denied while trying to add new related record',
00062                                         'Permission Denied: You do not have permission to add related records to the current record.'
00063                                 )
00064                         );
00065                         //$this->_vars['error'] =  "<div class=\"error\">Error.  Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
00066                         //return;
00067                 }
00068                 
00069                 if ( $form->validate() ){
00070                         $vals = $form->exportValues();
00071                                 
00072                         $res = $form->process(array(&$form, 'save'), true);
00073 
00074                         $response =& Dataface_Application::getResponse();
00075                         
00076                         if ( PEAR::isError($res) && !Dataface_Error::isNotice($res) ){
00077                                 return $res;
00078                                 //$this->_vars['error'] = "<div class=\"error\">Error.  ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
00079                                 //return;
00080                         } else if ( Dataface_Error::isNotice($res) ){
00081                                 $success = false;
00082                                 $app->addError($res);
00083                                 //$response['--msg'] = @$response['--msg'] . "\n".$res->getMessage();
00084                         } else {
00085                                 $success = true;
00086                         }
00087                                 
00088                         if ( $success ){
00089                                 import('Dataface/Utilities.php');
00090                                 Dataface_Utilities::fireEvent('after_action_new_related_record');
00091                                 $fquery = array('-action'=>'browse');
00092                                 $msg = urlencode(
00093                                         trim(
00094                                                 Dataface_LanguageTool::translate(
00095                                                         "Record successfully added to relationship",
00096                                                         "Record successfully added to ".$query['-relationship']." relationship.\n",
00097                                                         array('relationship'=>$query['-relationship'])
00098                                                 ).
00099                                                 (isset($response['--msg']) ? $response['--msg'] : '')
00100                                         )
00101                                 );
00102 
00103                         
00104                                 foreach ($vals['__keys__'] as $key=>$value){
00105                                         $fquery[$key] = "=".$value;
00106                                 }
00107                                 $fquery['-relationship'] = $query['-relationship'];
00108                                 $fquery['-action'] = 'related_records_list';
00109                                 $link = Dataface_LinkTool::buildLink($fquery);
00110                                 $app->redirect("$link"."&--msg=".$msg);
00111 
00112                         }
00113                  }
00114                  
00115                 ob_start();
00116                 $gdefs = array();
00117                 foreach ( $_GET as $gkey=>$gval ){
00118                         if ( substr($gkey,0, 4) == '--q:' ){
00119                                 $gdefs[substr($gkey, 4)] = $gval;
00120                         }
00121                 }
00122                 if ( count($gdefs) > 0 ){
00123                         $form->setDefaults($gdefs);
00124                 }
00125                 
00126                 
00127                 
00128                 
00129                 $form->display();
00130                 $out = ob_get_contents();
00131                 ob_end_clean();
00132                 
00133                 
00134                 $context = array('form'=>$out);
00135                 if ( isset($query['-template']) ) $template = $query['-template'];
00136                 else if ( isset( $params['action']['template']) ) $template = $params['action']['template'];
00137                 else $template = 'Dataface_Add_New_Related_Record.html';
00138                 df_display($context, $template, true);
00139                 
00140         }
00141 }
00142 
00143 
00144 
00145 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations