Browse Source

Adding excel support + fixing col names see BT#5476

Julio Montoya 12 years ago
parent
commit
343ca5e9ec
3 changed files with 25 additions and 14 deletions
  1. 21 4
      main/inc/ajax/model.ajax.php
  2. 2 2
      main/inc/lib/course.lib.php
  3. 2 8
      main/mySpace/company_reports.php

+ 21 - 4
main/inc/ajax/model.ajax.php

@@ -78,6 +78,7 @@ function get_where_clause($col, $oper, $val) {
 $where_condition = ""; //if there is no search request sent by jqgrid, $where should be empty
 
 $operation    = isset($_REQUEST['oper'])  ? $_REQUEST['oper']  : false;
+$export_format    = isset($_REQUEST['export_format'])  ? $_REQUEST['export_format']  : 'csv';
 
 $search_field    = isset($_REQUEST['searchField'])  ? $_REQUEST['searchField']  : false;
 $search_oper     = isset($_REQUEST['searchOper'])   ? $_REQUEST['searchOper']   : false;
@@ -222,11 +223,13 @@ $columns = array();
 
 switch ($action) {
     case 'get_user_course_report':
-        $columns = array('course', 'user', 'time', 'status', 'score');
+        $columns = array('course', 'user', 'time', 'certificate', 'score');
+        $column_names = array(get_lang('Course'), get_lang('User'), get_lang('TotalTime'), get_lang('Certificate'), get_lang('Score'));
         $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
         if (!empty($extra_fields)) {
             foreach($extra_fields as $extra) {
                 $columns[] = $extra['1'];
+                $column_names[] = $extra['3'];
             }
         }
         $result = CourseManager::get_user_list_from_course_code(null, null, "LIMIT $start, $limit", " $sidx $sord", null, null, true);
@@ -483,7 +486,7 @@ $allowed_actions = array('get_careers',
                          'get_grade_models',
                          'get_event_email_template',
                          'get_user_skill_ranking',
-                          'get_user_course_report'
+                         'get_user_course_report'
 );
 
 //5. Creating an obj to return a json
@@ -496,8 +499,14 @@ if (in_array($action, $allowed_actions)) {
     if ($operation && $operation == 'excel') {
         $j = 1;
         require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
+
         $array = array();
-        foreach ($columns as $col) {
+        if (empty($column_names)) {
+            $column_names = $columns;
+        }
+
+        //Headers
+        foreach ($column_names as $col) {
             $array[0][] = $col;
         }
         foreach ($result as $row) {
@@ -506,7 +515,15 @@ if (in_array($action, $allowed_actions)) {
             }
             $j++;
         }
-        Export :: export_table_csv($array, 'company_report');
+        switch ($export_format) {
+            case 'xls':
+                Export::export_table_xls($array, 'company_report');
+                break;
+            case 'csv':
+            default:
+                Export::export_table_csv($array, 'company_report');
+                break;
+        }
         exit;
     }
 

+ 2 - 2
main/inc/lib/course.lib.php

@@ -1232,9 +1232,9 @@ class CourseManager {
 
 
                     $category = Category :: load (null, null, $course_code);
-                    $report_info['status'] = Display::label(get_lang('No'));
+                    $report_info['certificate'] = Display::label(get_lang('No'));
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
-                        $report_info['status'] = Display::label(get_lang('Yes'));
+                        $report_info['certificate'] = Display::label(get_lang('Yes'));
                     }
                     $report_info['score'] = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), 0);
 

+ 2 - 8
main/mySpace/company_reports.php

@@ -28,7 +28,7 @@ $column_model   = array(
                         array('name'=>'course',     'index'=>'title',   'width'=>'120', 'align'=>'left'),
                         array('name'=>'user',       'index'=>'user',    'width'=>'120', 'align'=>'left','sortable'=>'false'),
                         array('name'=>'time',       'index'=>'time',    'width'=>'50',  'align'=>'left','sortable'=>'false'),
-                        array('name'=>'status',     'index'=>'status',  'width'=>'50',  'align'=>'left','sortable'=>'false'),
+                        array('name'=>'certificate',     'index'=>'certificate',  'width'=>'50',  'align'=>'left','sortable'=>'false'),
                         array('name'=>'score',      'index'=>'score',   'width'=>'50',  'align'=>'left','sortable'=>'false'),
 );
 
@@ -68,20 +68,14 @@ $(function() {
     jQuery("#user_course_report").jqGrid("navButtonAdd","#user_course_report_pager",{
            caption:"",
            onClickButton : function () {
-               jQuery("#user_course_report").jqGrid("excelExport",{"url":"'.$url.'"});
+               jQuery("#user_course_report").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
            }
     });
-
 });
-
-
-
-
 </script>';
 $content = Display::grid_html('user_course_report');
 
 $tpl = new Template($tool_name);
-//$tpl->assign('actions', $actions);
 $tpl->assign('message', $message);
 $tpl->assign('content', $content);
 $tpl->display_one_col_template();