2 import(
'Dataface/LinkTool.php');
5 import(
'Dataface/ExistingRelatedRecordForm.php');
8 $query =&
$app->getQuery();
9 $resultSet =&
$app->getResultSet();
13 if ( !isset( $query[
'-relationship'] ) ){
16 'Error: No relationship specified',
17 'Error. No relationship was specified when trying to add existing related record.'
25 $res = $form->_build();
34 foreach ( $query as $key=>$value){
35 if ( strpos($key,
'-')===0 ){
36 $form->addElement(
'hidden', $key);
37 $form->setDefaults( array( $key=>$value) );
46 $form->addElement(
'hidden',
'-query');
47 $form->setDefaults( array(
'-action'=>$query[
'-action'],
'-query'=>
$_SERVER[
'QUERY_STRING']) );
50 if ( !$form->_record || !is_a($form->_record,
'Dataface_Record') ){
61 if ( !$form->_record->checkPermission(
'add existing related record', array(
'relationship'=>$query[
'-relationship']))){
65 'Error: Permission denied adding existing related record',
66 'Permission Denied. You do not have sufficient permissions to add an existing related record. Required permission: "add existing related record", but you have only been granted permissions: "'.implode(
',',$form->_record->getPermissions()).
'".',
67 array(
'required_permission'=>
'add existing related record',
'granted_permissions'=>implode(
',', $form->_record->getPermissions()) )
73 if ( $form->validate() ){
74 $res = $form->process(array(&$form,
'save'),
true);
83 'Failed to add record because of errors',
84 'Failed to add record to relationship because of the following errors:'
94 import(
'Dataface/Utilities.php');
96 $fquery = array(
'-action'=>
'browse');
98 'Record successfully added to relationship',
99 "The record has been successfully added to the ".$query[
'-relationship'].
" relationship.\n" ,
100 array(
'relationship'=>$query[
'-relationship'])
102 $msg = urlencode(trim(($success ? $msg :
'').@$response[
'--msg']));
105 $vals = $form->exportValues();
106 if ( isset($vals[
'--redirect']) ){
107 $qmark = (strpos($vals[
'--redirect'],
'?') !==
false) ?
'&':
'?';
108 $app->redirect($vals[
'--redirect'].$qmark.
'--msg='.$msg);
110 foreach ($vals[
'__keys__'] as $key=>$value){
111 $fquery[$key] =
"=".$value;
114 $app->redirect(
"$link".
"&--msg=".$msg);
122 $out = ob_get_contents();
126 $context = array(
'form'=>
$out);
127 if ( isset($query[
'-template']) ) $template = $query[
'-template'];
128 else if ( isset( $params[
'action'][
'template']) ) $template = $params[
'action'][
'template'];
129 else $template =
'Dataface_Add_Existing_Related_Record.html';
130 df_display($context, $template,
true);