Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
ajax_sort_sections.php
Go to the documentation of this file.
1 <?php
3 
4  function handle(&$params){
6  $query =& $app->getQuery();
7  $tablename = $query['-table'];
8  $record =& $app->getRecord();
9 
10  //print_r($_POST);
11  $section_keys = array('--dataface-sections-left', '--dataface-sections-main');
12  foreach ($section_keys as $section_key){
13 
14  if ( !isset($_POST[$section_key]) ) continue;
15 
16  $sections = explode(',',$_POST[$section_key]);
17 
18  import('Dataface/PreferencesTool.php');
20 
21  $prefs =& $pt->getPreferences($record->getId());
22 
23  $sectionOrders = array();
24  $lastOrder = 0;
25  foreach ( $sections as $section){
26  if ( isset($prefs['tables.'.$tablename.'.sections.'.$section.'.order']) ){
27  $order = intval($prefs['tables.'.$tablename.'.sections.'.$section.'.order']);
28  $lastOrder = $order;
29  } else {
30  $order = ++$lastOrder;
31  }
32  $sectionOrders[$section] = $order;
33  }
34 
35  $orderVals = array_values($sectionOrders);
36  sort($orderVals);
37 
38  $i=0;
39  foreach ( array_keys($sectionOrders) as $section ){
40  $sectionOrders[$section] = $orderVals[$i++];
41  }
42 
43 
44 
45  $record_id = $record->getId();
46  $last_order=0;
47  foreach ($sectionOrders as $section=>$order){
48  $order = max($last_order+1, $order);
49  $pt->savePreference('*', 'tables.'.$tablename.'.sections.'.$section.'.order', $order);
50  $last_order=$order;
51  }
52  }
53 
54 
55 
56  //$pt->savePreference($record->getId(), 'foo','bar','user1');
57  //print_r($_SESSION['dataface__preferences']);
58  //echo "here";
59  /*
60  if ( $record->checkPermission('manage_sort_sections') ){
61  $prefUser = null;
62  } else if ( class_exists('Dataface_AuthenticationTool') ){
63  $auth =& Dataface_AuthenticationTool::getInstance();
64  if ( $auth->isLoggedIn() ){
65  $prefUser = $auth->getLoggedInUsername();
66  } else {
67  $prefUser = null;
68  }
69  } else {
70  $prefUser = null;
71  }
72 
73 
74  $configFile = 'tables/'.$tablename.'/fields.ini';
75 
76 
77  $sections = $_POST['--left-sections'];
78 
79  $ct =& Dataface_ConfigTool::getInstance();
80  for ( $i=0; $i<count($sections); $i++){
81  $ct->setConfigParams($configFile, 'section:'.$sections[$i], 'order', $i, $prefUser);
82  }
83 
84  echo "Sections sorted";*/
85  }
86 }