![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 class dataface_actions_ajax_sort_sections { 00003 00004 function handle(&$params){ 00005 $app =& Dataface_Application::getInstance(); 00006 $query =& $app->getQuery(); 00007 $tablename = $query['-table']; 00008 $record =& $app->getRecord(); 00009 00010 //print_r($_POST); 00011 $section_keys = array('--dataface-sections-left', '--dataface-sections-main'); 00012 foreach ($section_keys as $section_key){ 00013 00014 if ( !isset($_POST[$section_key]) ) continue; 00015 00016 $sections = explode(',',$_POST[$section_key]); 00017 00018 import('Dataface/PreferencesTool.php'); 00019 $pt =& Dataface_PreferencesTool::getInstance(); 00020 00021 $prefs =& $pt->getPreferences($record->getId()); 00022 00023 $sectionOrders = array(); 00024 $lastOrder = 0; 00025 foreach ( $sections as $section){ 00026 if ( isset($prefs['tables.'.$tablename.'.sections.'.$section.'.order']) ){ 00027 $order = intval($prefs['tables.'.$tablename.'.sections.'.$section.'.order']); 00028 $lastOrder = $order; 00029 } else { 00030 $order = ++$lastOrder; 00031 } 00032 $sectionOrders[$section] = $order; 00033 } 00034 00035 $orderVals = array_values($sectionOrders); 00036 sort($orderVals); 00037 00038 $i=0; 00039 foreach ( array_keys($sectionOrders) as $section ){ 00040 $sectionOrders[$section] = $orderVals[$i++]; 00041 } 00042 00043 00044 00045 $record_id = $record->getId(); 00046 $last_order=0; 00047 foreach ($sectionOrders as $section=>$order){ 00048 $order = max($last_order+1, $order); 00049 $pt->savePreference('*', 'tables.'.$tablename.'.sections.'.$section.'.order', $order); 00050 $last_order=$order; 00051 } 00052 } 00053 00054 00055 00056 //$pt->savePreference($record->getId(), 'foo','bar','user1'); 00057 //print_r($_SESSION['dataface__preferences']); 00058 //echo "here"; 00059 /* 00060 if ( $record->checkPermission('manage_sort_sections') ){ 00061 $prefUser = null; 00062 } else if ( class_exists('Dataface_AuthenticationTool') ){ 00063 $auth =& Dataface_AuthenticationTool::getInstance(); 00064 if ( $auth->isLoggedIn() ){ 00065 $prefUser = $auth->getLoggedInUsername(); 00066 } else { 00067 $prefUser = null; 00068 } 00069 } else { 00070 $prefUser = null; 00071 } 00072 00073 00074 $configFile = 'tables/'.$tablename.'/fields.ini'; 00075 00076 00077 $sections = $_POST['--left-sections']; 00078 00079 $ct =& Dataface_ConfigTool::getInstance(); 00080 for ( $i=0; $i<count($sections); $i++){ 00081 $ct->setConfigParams($configFile, 'section:'.$sections[$i], 'order', $i, $prefUser); 00082 } 00083 00084 echo "Sections sorted";*/ 00085 } 00086 }