Example #1
0
 function get_temp_csvs()
 {
     $this->_secure(50);
     $grid_method = get_grid_method_from_page();
     $result = array();
     $user = $this->session->all_userdata();
     $this->load->model('model_temp_csvs');
     $post_data = $_POST;
     $filters = array();
     $filters['client_id'] = $user['client_id'];
     $filters['processed_flag'] = '0';
     $temp_csvs = $this->model_temp_csvs->get_records($filters);
     $temp_csv_data = array();
     if (!empty($temp_csvs)) {
         foreach ($temp_csvs as $temp_csv) {
             $actions = '';
             if ($grid_method == 'jqgrid' || $grid_method == 'slick') {
                 $classes = 'tooltip fg-button ui-state-default fg-button-icon-solo ui-corner-all';
                 $status = '';
                 if ($temp_csv['processed_flag'] == '0') {
                     $status = 'Unprocessed';
                     $title = 'Process CSV';
                     $actions .= '<a href="javascript: void(0);" title="' . $title . '" class="' . $classes . ' process" id="' . $temp_csv['temp_csv_id'] . '">' . '<span class="ui-icon ui-icon-transferthick-e-w"></span> </a>';
                 } else {
                     $status = 'Processed';
                 }
                 $actions .= '<a href="javascript: void(0);" title="Delete CSV" class="' . $classes . ' delete" id="' . $temp_csv['temp_csv_id'] . '">' . '<span class="ui-icon ui-icon-close"></span> </a>';
                 $temp_csv_data[$temp_csv['temp_csv_id']] = array($actions, $temp_csv['filename'], date('d/m/Y H:i', $temp_csv['uploaded_date']), $temp_csv['line_count'], $status);
             } else {
                 $status = '';
                 if ($temp_csv['processed_flag'] == '0') {
                     $status = 'Unprocessed';
                     $actions .= '<a class="btn small theme left process" href="javascript:process_csv(' . $temp_csv['temp_csv_id'] . ');">Process</a>';
                 } else {
                     $status = 'Processed';
                 }
                 $actions .= '<a class="btn small theme left delete" href="javascript:delete_temp_csv(' . $temp_csv['temp_csv_id'] . ');">Delete</a>';
                 $this_temp_csv = array();
                 $this_temp_csv[] = '<span>' . $temp_csv['filename'] . '</span>';
                 $this_temp_csv[] = '<span>' . date('d/m/Y H:i', $temp_csv['uploaded_date']) . '</span>';
                 $this_temp_csv[] = '<span>' . $temp_csv['line_count'] . '</span>';
                 $this_temp_csv[] = '<span>' . $status . '</span>';
                 $this_temp_csv[] = $actions;
                 $temp_csv_data[] = $this_temp_csv;
             }
         }
     }
     if (!empty($temp_csv_data) && isset($post_data['sSearch']) && !empty($post_data['sSearch'])) {
         $new_temp_csv_data = array();
         for ($i = 0; $i < sizeof($temp_csv_data); $i++) {
             $matched = false;
             for ($j = 0; $j < $post_data['iColumns']; $j++) {
                 if ($post_data['bSearchable_' . $j] == 'true') {
                     if (stristr(strip_tags($temp_csv_data[$i][$j]), $post_data['sSearch'])) {
                         $matched = true;
                         break;
                     }
                 }
             }
             if ($matched) {
                 $new_temp_csv_data[] = $temp_csv_data[$i];
             }
         }
         $temp_csv_data = $new_temp_csv_data;
     } elseif (!empty($temp_csv_data) && isset($post_data['search']) && !empty($post_data['search'])) {
         $new_temp_csv_data = array();
         $columns = array('actions', 'filename', 'uploaded_date', 'line_count', 'temp_csv_status');
         $search_columns = array('filename', 'temp_csv_status');
         foreach ($temp_csv_data as $temp_csv_id => $values) {
             $matched = false;
             for ($i = 0; $i < sizeof($columns); $i++) {
                 if (in_array($columns[$i], $search_columns)) {
                     if (stristr(strip_tags($values[$i]), $post_data['search'])) {
                         $matched = true;
                         break;
                     }
                 }
             }
             if ($matched) {
                 $new_temp_csv_data[$temp_csv_id] = $values;
             }
         }
         $temp_csv_data = $new_temp_csv_data;
     }
     if (!empty($temp_csv_data) && isset($post_data['iSortingCols']) && !empty($post_data['iSortingCols'])) {
         $column_sorts = array();
         $column_sort_index = 0;
         $column_sort_directions = array();
         for ($i = 0; $i < $post_data['iSortingCols']; $i++) {
             if (isset($post_data['iSortCol_' . $i])) {
                 $column_sorts[$column_sort_index] = array();
                 for ($j = 0; $j < sizeof($temp_csv_data); $j++) {
                     $column_sorts[$column_sort_index][] = strtolower(strip_tags($temp_csv_data[$j][$post_data['iSortCol_' . $i]]));
                 }
                 $column_sort_directions[$column_sort_index] = 'SORT_' . strtoupper($post_data['sSortDir_' . $i]);
                 $column_sort_index++;
             }
         }
         if (!empty($column_sorts)) {
             $eval = 'array_multisort(';
             for ($i = 0; $i < sizeof($column_sorts); $i++) {
                 $eval .= ($i > 0 ? ',' : '') . '$column_sorts[' . $i . '],' . $column_sort_directions[$i] . ',SORT_REGULAR';
             }
             $eval .= ',$temp_csv_data);';
             eval($eval);
         }
     } elseif (!empty($temp_csv_data) && isset($post_data['sidx']) && !empty($post_data['sidx']) && isset($post_data['sord']) && !empty($post_data['sord'])) {
         $columns = array('actions', 'filename', 'uploaded_date', 'line_count', 'temp_csv_status');
         $column_sort = array();
         $column_sort_index = -1;
         $column_sort_direction = null;
         for ($i = 0; $i < sizeof($columns); $i++) {
             if ($columns[$i] == $post_data['sidx']) {
                 $column_sort_index = $i;
                 break;
             }
         }
         if ($column_sort_index != -1) {
             foreach ($temp_csv_data as $temp_csv_id => $values) {
                 $column_value = trim(strip_tags($values[$column_sort_index]));
                 if (is_date($column_value)) {
                     $column_sort[] = to_unixtime($column_value);
                 } else {
                     $column_sort[] = strtolower($column_value);
                 }
                 if ($post_data['sord'] == 'asc') {
                     $column_sort_direction = SORT_ASC;
                 } else {
                     $column_sort_direction = SORT_DESC;
                 }
             }
         }
         if (!empty($column_sort)) {
             array_multisort($column_sort, $column_sort_direction, SORT_REGULAR, $temp_csv_data);
         }
     }
     if ($grid_method == 'jqgrid' || $grid_method == 'slick') {
         if (!empty($temp_csv_data)) {
             $new_temp_csv_data = array();
             foreach ($temp_csv_data as $temp_csv_id => $values) {
                 $new_temp_csv_data[] = array('id' => $temp_csv_id, 'cell' => $values);
             }
             $temp_csv_data = $new_temp_csv_data;
         }
         $result['total'] = 1;
         $result['page'] = 1;
         $result['records'] = sizeof($temp_csv_data);
         $result['temp_csvs'] = $temp_csv_data;
     } else {
         $result['sEcho'] = $post_data['sEcho'];
         $result['iTotalRecords'] = sizeof($temp_csv_data);
         $result['iTotalDisplayRecords'] = sizeof($temp_csv_data);
         if (!empty($temp_csv_data) && isset($post_data['iDisplayStart']) && isset($post_data['iDisplayLength'])) {
             if ($post_data['iDisplayLength'] == -1) {
                 $result['aaData'] = array_slice($temp_csv_data, $post_data['iDisplayStart']);
             } else {
                 $result['aaData'] = array_slice($temp_csv_data, $post_data['iDisplayStart'], $post_data['iDisplayLength']);
             }
         } else {
             $result['aaData'] = $temp_csv_data;
         }
     }
     $data = array();
     $data['any'] = json_encode($result);
     $data['action_view'] = 'misc/any';
     $this->load->view('layouts/blank', $data);
 }
Example #2
0
function to_datetime($tim = 0, $fmt = null)
{
    isset($fmt) || ($fmt = 'Y-m-d H:i:s');
    return date($fmt, to_unixtime($tim));
}