Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
remove_related_record.php
Go to the documentation of this file.
1 <?php
12  function handle(&$params){
13  import( 'Dataface/RemoveRelatedRecordForm.php');
15  $query =& $app->getQuery();
16 
17  $record = null; //& new Dataface_Record($this->_tablename, $_REQUEST['--__keys__']);
18  // let the form handle the loading of the record
19 
20 
21  $form = new Dataface_RemoveRelatedRecordForm($record, $query['-relationship']);
22 
23 
24  if ( !$form->_record ){
25  // the record could not be loaded
26  return PEAR::raiseError(
28  'Specified record could not be loaded',
29  'The specified record could not be loaded'
30  ),
32  );
33  }
34 
35  unset($app->currentRecord);
36  $app->currentRecord =& $form->_record;
37 
38  if ( !Dataface_PermissionsTool::checkPermission('remove related record', $form->_record, array('relationship'=>$query['-relationship']) ) ) {
41  'Insufficient permissions to delete record',
42  'Permission Denied. You do not have permissions to remove related records from the relationship "'.
43  $query['-relationship'].
44  '" for this record.
45  Requires permission "remove related record" but you only have the following permissions: "'.
46  df_permission_names_as_string(
47  $form->_record->getPermissions(
48  array('relationship'=>$query['-relationship'])
49  )
50  ).
51  '"',
52  array('relationship'=>$query['-relationship'],
53  'required_permission'=>'remove related record',
54  'granted_permissions'=>df_permission_names_as_string($form->_record->getPermissions(array('relationship'=>$query['-relationship'])))
55  )
56  )
57  );
58  //$this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
59  //return;
60  }
61  if ( @$_POST['-confirm_delete_hidden'] and $form->validate() ){
62 
63  $res = $form->process(array(&$form, 'delete'), true);
64  $response =& Dataface_Application::getResponse();
65 
66  if ( PEAR::isError($res) && !Dataface_Error::isNotice($res) ){
67  return $res;
68  //$this->_vars['error'] = "<div class=\"error\">Error. ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
69  //return;
70  } else if ( count($res['warnings']) > 0 ){ //Dataface_Error::isNotice($res) ){
71  foreach ($res['warnings'] as $warning){
72  $app->addError($warning);
73  $response['--msg'] = 'Errors occurred trying to remove records';
74  }
75 
76  } else {
77  $response['--msg'] = df_translate(
78  'Records successfully deleted from relationship',
79  ' Records successfully removed from relationship'
80  )."<br>".@$response['--msg'];
81  }
82 
83  if ( count($res['warnings'])>0){
84  foreach (array_merge($res['confirmations'], $res['warnings']) as $confirmation){
85  $response['--msg'] .= "<br>".$confirmation;
86  }
87  }
88 
89  $msg = urlencode(trim(@$response['--msg']));
90  $app->redirect($form->_record->getURL(array('-action'=>'related_records_list', '-relationship'=>$query['-relationship']) ).'&--msg='.$msg);
91  //header("Location: ".$_SERVER['HOST_URI'].$_SERVER['PHP_SELF'].'?'.$_COOKIE['dataface_lastpage'].'&--msg='.$msg);
92 
93 
94 
95  }
96 
97 
98 
99  ob_start();
100  $form->display();
101  $out = ob_get_contents();
102  ob_end_clean();
103 
104 
105  $context = array('form'=>$out);
106  if ( isset($query['-template']) ) $template = $query['-template'];
107  else if ( isset( $params['action']['template']) ) $template = $params['action']['template'];
108  else $template = 'Dataface_Remove_Related_Record.html';
109  df_display($context, $template, true);
110  }
111 }
112 
113 ?>