Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
import.php
Go to the documentation of this file.
1 <?php
2 import('Dataface/QueryTool.php');
8  function handle($params){
9  ini_set('memory_limit', '256M');
10  set_time_limit(99999);
11  import( 'Dataface/ImportForm.php');
13  $app->startSession();
14  $query =& $app->getQuery();
15 
16  $form = new Dataface_ImportForm($query['-table']);
17  $record =& $form->_record;
18 
19  if ( is_object($record) ){
20  if ( !$record->checkPermission('import') ){
21 
23  }
24  } else {
25  if ( !Dataface_PermissionsTool::checkPermission('import',Dataface_Table::loadTable($query['-table']) ) ){
27  }
28  }
29  $form->_build();
30 
31 
32  if ( $form->validate() ){
33  //echo "validated";
34  $querystr = $form->exportValue('-query');
35  $returnPage = $form->exportValue('--redirect');
36 
37  if ( intval($form->_step) === 1 ){
38 
39  if ( preg_match('/--step=1/',$querystr) ){
40  $querystr = preg_replace('/--step=1/', '--step=2', $querystr);
41  } else {
42  $querystr .= '&--step=2';
43  }
44  $importTablename = $form->process(array(&$form, 'import'));
45  $app->redirect($_SERVER['PHP_SELF'].'?'.$querystr.'&--importTablename='.$importTablename.'&--redirect='.urlencode($returnPage));
46  } else {
47  $records = $form->process(array(&$form, 'import'));
48 
49  $returnPage = $form->exportValue('--redirect');
50  //$keys = $form->exportValue('__keys__');
51  //$keys['-action'] = 'browse';
52  //$keys['-step'] = null;
53  //$keys['-query'] = null;
54 
55  //$link = Dataface_LinkTool::buildLink($keys);
56  $link = $returnPage;
57  $response =& Dataface_Application::getResponse();
58  $msg = urlencode(trim("Records imported successfully.\n".@$response['--msg']));
59  if ( strpos($link,'?') === false ) $link .= '?';
60  $app->redirect($link.'&--msg='.$msg);
61 
62 
63 
64  }
65 
66 
67 
68 
69  }
70 
71  ob_start();
72  $form->display();
73  $out = ob_get_contents();
74  ob_end_clean();
75  $context['form'] = $out;
76  $context['filters'] = $form->_filterNames;
77  $context['step'] = $form->_step;
78 
79  if ( isset($query['-template']) ) $template = $query['-template'];
80  else if ( isset( $params['action']['template']) ) $template = $params['action']['template'];
81  else {
82  if ( isset( $query['-relationship'] ) ){
83  $template = 'Dataface_Import_RelatedRecords.html';
84 
85  } else {
86  $template = 'Dataface_Import_RelatedRecords.html';
87  }
88 
89  }
90 
91  df_display($context, $template, true);
92 
93  }
94 }
95 
96 
97 ?>