Xataface 2.0
Xataface Application Framework
actions/remove_related_record.php
Go to the documentation of this file.
00001 <?php
00011 class dataface_actions_remove_related_record {
00012         function handle(&$params){
00013                 import( 'Dataface/RemoveRelatedRecordForm.php');
00014                 $app =& Dataface_Application::getInstance();
00015                 $query =& $app->getQuery();
00016                 
00017                 $record = null; //& new Dataface_Record($this->_tablename, $_REQUEST['--__keys__']);
00018                         // let the form handle the loading of the record
00019                 
00020                 
00021                 $form = new Dataface_RemoveRelatedRecordForm($record, $query['-relationship']);
00022                 
00023         
00024                 if ( !$form->_record ){
00025                         // the record could not be loaded
00026                         return PEAR::raiseError(
00027                                 Dataface_LanguageTool::translate(
00028                                         'Specified record could not be loaded',
00029                                         'The specified record could not be loaded'
00030                                         ),
00031                                         DATAFACE_E_NOTICE
00032                                 );
00033                 }
00034                 
00035                 unset($app->currentRecord);
00036                 $app->currentRecord =& $form->_record;
00037                 
00038                 if ( !Dataface_PermissionsTool::checkPermission('remove related record', $form->_record, array('relationship'=>$query['-relationship']) ) ) {
00039                         return Dataface_Error::permissionDenied(
00040                                 Dataface_LanguageTool::translate(
00041                                         'Insufficient permissions to delete record',
00042                                         'Permission Denied.  You do not have permissions to remove related records from the relationship "'.
00043                                         $query['-relationship'].
00044                                         '" for this record.  
00045                                         Requires permission "remove related record" but you only have the following permissions: "'.
00046                                         df_permission_names_as_string(
00047                                                 $form->_record->getPermissions(
00048                                                         array('relationship'=>$query['-relationship'])
00049                                                         )
00050                                                 ).
00051                                         '"',
00052                                         array('relationship'=>$query['-relationship'],
00053                                                 'required_permission'=>'remove related record',
00054                                                 'granted_permissions'=>df_permission_names_as_string($form->_record->getPermissions(array('relationship'=>$query['-relationship'])))
00055                                                 )
00056                                         )
00057                                 );
00058                         //$this->_vars['error'] =  "<div class=\"error\">Error.  Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
00059                         //return;
00060                 }
00061                 if ( @$_POST['-confirm_delete_hidden'] and $form->validate() ){
00062                 
00063                         $res = $form->process(array(&$form, 'delete'), true);
00064                         $response =& Dataface_Application::getResponse();
00065                         
00066                         if ( PEAR::isError($res) && !Dataface_Error::isNotice($res) ){
00067                                 return $res;
00068                                 //$this->_vars['error'] = "<div class=\"error\">Error.  ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
00069                                 //return;
00070                         } else if ( count($res['warnings']) > 0 ){ //Dataface_Error::isNotice($res) ){
00071                                 foreach ($res['warnings'] as $warning){
00072                                         $app->addError($warning);
00073                                         $response['--msg'] = 'Errors occurred trying to remove records';
00074                                 }
00075                                 
00076                         } else {
00077                                 $response['--msg'] = df_translate(
00078                                         'Records successfully deleted from relationship',
00079                                         ' Records successfully removed from relationship'
00080                                         )."<br>".@$response['--msg'];
00081                         }
00082                         
00083                         if ( count($res['warnings'])>0){
00084                                 foreach (array_merge($res['confirmations'], $res['warnings']) as $confirmation){
00085                                         $response['--msg'] .= "<br>".$confirmation;
00086                                 }
00087                         }
00088                         
00089                         $msg = urlencode(trim(@$response['--msg']));
00090                         $app->redirect($form->_record->getURL(array('-action'=>'related_records_list', '-relationship'=>$query['-relationship']) ).'&--msg='.$msg);
00091                         //header("Location: ".$_SERVER['HOST_URI'].$_SERVER['PHP_SELF'].'?'.$_COOKIE['dataface_lastpage'].'&--msg='.$msg);
00092                         
00093                                 
00094                         
00095                 }
00096                 
00097                 
00098                 
00099                 ob_start();
00100                 $form->display();
00101                 $out = ob_get_contents();
00102                 ob_end_clean();
00103                 
00104                 
00105                 $context = array('form'=>$out);
00106                 if ( isset($query['-template']) ) $template = $query['-template'];
00107                 else if ( isset( $params['action']['template']) ) $template = $params['action']['template'];
00108                 else $template = 'Dataface_Remove_Related_Record.html';
00109                 df_display($context, $template, true);
00110         }
00111 }
00112 
00113 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations