コード例 #1
0
 /**
  * Sorts 2-dimensional table. It is possile changing the columns that will be shown and the way that the columns are to be sorted.
  * @param array $data The data to be sorted.
  * @param int $column The column on which the data should be sorted (default = 0)
  * @param string $direction The direction to sort (SORT_ASC (default) orSORT_DESC)
  * @param array $column_show The columns that we will show in the table i.e: $column_show = array('1','0','1') we will show the 1st and the 3th column.
  * @param array $column_order Changes how the columns will be sorted ie. $column_order = array('0','3','2','3') The column [1] will be sorted like the column [3]
  * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_DATE, SORT_IMAGE)
  * @return array The sorted dataset
  * @author bart.mollet@hogent.be
  */
 public static function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show = null, $column_order = null, $type = SORT_REGULAR, $doc_filter = false)
 {
     if (!is_array($data) || empty($data)) {
         return array();
     }
     if ($column != strval(intval($column))) {
         // Probably an attack
         return $data;
     }
     if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
         // Probably an attack
         return $data;
     }
     // Change columns sort
     // Here we say that the real way of how the columns are going to be order is manage by the $column_order array
     if (is_array($column_order)) {
         $column = isset($column_order[$column]) ? $column_order[$column] : $column;
     }
     if ($type == SORT_REGULAR) {
         if (TableSort::is_image_column($data, $column)) {
             $type = SORT_IMAGE;
         } elseif (TableSort::is_date_column($data, $column)) {
             $type = SORT_DATE;
         } elseif (TableSort::is_numeric_column($data, $column)) {
             $type = SORT_NUMERIC;
         } else {
             $type = SORT_STRING;
         }
     }
     //This fixs only works in the document tool when ordering by name
     if ($doc_filter && in_array($type, array(SORT_STRING))) {
         $data_to_sort = $folder_to_sort = array();
         $new_data = array();
         if (!empty($data)) {
             foreach ($data as $document) {
                 if ($document['type'] == 'folder') {
                     $docs_to_sort[$document['id']] = api_strtolower($document['name']);
                 } else {
                     $folder_to_sort[$document['id']] = api_strtolower($document['name']);
                 }
                 $new_data[$document['id']] = $document;
             }
             if ($direction == SORT_ASC) {
                 if (!empty($docs_to_sort)) {
                     api_natrsort($docs_to_sort);
                 }
                 if (!empty($folder_to_sort)) {
                     api_natrsort($folder_to_sort);
                 }
             } else {
                 if (!empty($docs_to_sort)) {
                     api_natsort($docs_to_sort);
                 }
                 if (!empty($folder_to_sort)) {
                     api_natsort($folder_to_sort);
                 }
             }
             $new_data_order = array();
             if (!empty($docs_to_sort)) {
                 foreach ($docs_to_sort as $id => $document) {
                     $new_data_order[] = $new_data[$id];
                 }
             }
             if (!empty($folder_to_sort)) {
                 foreach ($folder_to_sort as $id => $document) {
                     $new_data_order[] = $new_data[$id];
                 }
             }
             $data = $new_data_order;
         }
     } else {
         $compare_operator = $direction == SORT_ASC ? '>' : '<=';
         switch ($type) {
             case SORT_NUMERIC:
                 $compare_function = 'return strip_tags($a[' . $column . ']) ' . $compare_operator . ' strip_tags($b[' . $column . ']);';
                 break;
             case SORT_IMAGE:
                 $compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a[' . $column . '], "<img>")), api_strtolower(strip_tags($b[' . $column . '], "<img>"))) ' . $compare_operator . ' 0;';
                 break;
             case SORT_DATE:
                 $compare_function = 'return strtotime(strip_tags($a[' . $column . '])) ' . $compare_operator . ' strtotime(strip_tags($b[' . $column . ']));';
                 break;
             case SORT_STRING:
             default:
                 $compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a[' . $column . '])), api_strtolower(strip_tags($b[' . $column . ']))) ' . $compare_operator . ' 0;';
                 break;
         }
         // Sort the content
         usort($data, create_function('$a, $b', $compare_function));
     }
     if (is_array($column_show)) {
         // We show only the columns data that were set up on the $column_show array
         $new_order_data = array();
         $count_data = count($data);
         $count_column_show = count($column_show);
         for ($j = 0; $j < $count_data; $j++) {
             $k = 0;
             for ($i = 0; $i < $count_column_show; $i++) {
                 if ($column_show[$i]) {
                     $new_order_data[$j][$k] = $data[$j][$i];
                 }
                 $k++;
             }
         }
         // Replace the multi-arrays
         $data = $new_order_data;
     }
     return $data;
 }
コード例 #2
0
ファイル: user_add.php プロジェクト: annickvdp/Chamilo1.9.10
	$where = 'WHERE session_admin_id='.intval(api_get_user_id());
	$where .= ' AND ( (session.date_start <= "'.$now.'" AND session.date_end >= "'.$now.'") OR session.date_start="0000-00-00" ) ';
	$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
	$sql="SELECT id,name,nbr_courses,date_start,date_end FROM $tbl_session $where ORDER BY name";
	$result = Database::query($sql);
	$a_sessions = Database::store_result($result);
	$session_list = array();
	$session_list[0] = get_lang('SelectSession');
	if (is_array($a_sessions)) {
		foreach ($a_sessions as $session) {
			$session_list[$session['id']]=$session['name'];
		}
	}
	//asort($session_list);
	//api_asort($session_list, SORT_STRING);
	api_natsort($session_list);
	$form->addElement('select', 'session_id', get_lang('Session'), $session_list);
}

UserManager::set_extra_fields_in_form($form, null, 'registration');

// Set default values
$defaults['admin']['platform_admin'] = 0;
$defaults['mail']['send_mail'] = 0;
$defaults['password']['password_auto'] = 1;
$defaults['active'] = 1;
$defaults['expiration_date'] = array();
$days = api_get_setting('account_valid_duration');
$time = strtotime('+'.$days.' day');
$defaults['expiration_date']['d'] = date('d', $time);
$defaults['expiration_date']['F'] = date('m', $time);