Selaa lähdekoodia

Adding new admin exercise report see BT#6646

Julio Montoya 11 vuotta sitten
vanhempi
commit
d4b48e826b

+ 281 - 0
main/admin/exercise_report.php

@@ -0,0 +1,281 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Exercise list: This script shows the list of exercises for administrators and students.
+ * @package chamilo.exercise
+ * @author Julio Montoya <gugli100@gmail.com> jqgrid integration
+ *   Modified by hubert.borderiou (question category)
+ *
+ * @todo fix excel export
+ *
+ */
+/**
+ * Code
+ */
+// name of the language file that needs to be included
+$language_file = array('exercice');
+
+api_protect_global_admin_script();
+
+$urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
+
+// Setting the tabs
+$this_section = SECTION_COURSES;
+
+$htmlHeadXtra[] = api_get_jqgrid_js();
+
+// including additional libraries
+require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
+require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
+require_once api_get_path(SYS_CODE_PATH).'exercice/answer.class.php';
+
+// need functions of statsutils lib to display previous exercices scores
+require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
+
+// document path
+$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
+
+/*	Constants and variables */
+$is_tutor = api_is_allowed_to_edit(true);
+
+$TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
+$TBL_TRACK_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+$TBL_TRACK_ATTEMPT = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
+$TBL_TRACK_ATTEMPT_RECORDING = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
+$TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
+$course_id = api_get_course_int_id();
+
+if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
+
+    $load_extra_data = false;
+    if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
+        $load_extra_data = true;
+    }
+    require_once 'exercise_result.class.php';
+    switch ($_GET['export_format']) {
+        case 'xls':
+            $export = new ExerciseResult();
+            $export->exportCompleteReportXLS(
+                $documentPath,
+                null,
+                $load_extra_data,
+                null,
+                $_GET['exerciseId'],
+                $_GET['hotpotato_name']
+            );
+            exit;
+            break;
+        case 'csv':
+        default:
+            $export = new ExerciseResult();
+            $export->exportCompleteReportCSV(
+                $documentPath,
+                null,
+                $load_extra_data,
+                null,
+                $_GET['exerciseId'],
+                $_GET['hotpotato_name']
+            );
+            exit;
+            break;
+    }
+
+}
+
+$nameTools = get_lang('StudentScore');
+
+$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array("url" => "", "name" => get_lang('ExercicesReport'));
+
+Display :: display_header($nameTools);
+
+$extra = '<script>
+    $(document).ready(function() {
+
+        $( "#dialog:ui-dialog" ).dialog( "destroy" );
+
+        $( "#dialog-confirm" ).dialog({
+                autoOpen: false,
+                show: "blind",
+                resizable: false,
+                height:300,
+                modal: true
+         });
+
+        $("#export_opener").click(function() {
+            var targetUrl = $(this).attr("href");
+            $( "#dialog-confirm" ).dialog({
+                width:400,
+                height:300,
+                buttons: {
+                    "'.addslashes(get_lang('Download')).'": function() {
+                        var export_format = $("input[name=export_format]:checked").val();
+                        var extra_data  = $("input[name=load_extra_data]:checked").val();
+                        location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
+                        $( this ).dialog( "close" );
+                    },
+                }
+            });
+            $( "#dialog-confirm" ).dialog("open");
+            return false;
+        });
+    });
+    </script>';
+
+$extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
+$form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
+$form->addElement(
+    'radio',
+    'export_format',
+    null,
+    get_lang('ExportAsCSV'),
+    'csv',
+    array('id' => 'export_format_csv_label')
+);
+$form->addElement(
+    'radio',
+    'export_format',
+    null,
+    get_lang('ExportAsXLS'),
+    'xls',
+    array('id' => 'export_format_xls_label')
+);
+$form->addElement(
+    'checkbox',
+    'load_extra_data',
+    null,
+    get_lang('LoadExtraData'),
+    '0',
+    array('id' => 'export_format_xls_label')
+);
+$form->setDefaults(array('export_format' => 'csv'));
+$extra .= $form->return_form();
+$extra .= '</div>';
+
+echo $extra;
+
+$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_admin_exercise_results';
+
+$action_links = '';
+
+//The order is important you need to check the the $column variable in the model.ajax.php file
+$columns = array(
+    get_lang('LoginName'),
+    get_lang('FirstName'),
+    get_lang('LastName'),
+    get_lang('Score'),
+    get_lang('Link'),
+    get_lang('Session')
+  //  get_lang('Actions')
+);
+
+//Column config
+$column_model = array(
+    array(
+        'name' => 'login',
+        'index' => 'username',
+        'width' => '40',
+        'align' => 'left',
+        'search' => 'true'
+    ),
+    array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'),
+    array(
+        'name' => 'lastname',
+        'index' => 'lastname',
+        'width' => '50',
+        'align' => 'left',
+        //'formatter' => 'action_formatter',
+        'search' => 'true'
+    ),
+    array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'true'),
+    array('name' => 'link', 'index' => 'link', 'width' => '50', 'align' => 'left', 'search' => 'false'),
+    array('name' => 'session', 'index' => 'session_id', 'width' => '50', 'align' => 'left', 'search' => 'true'),
+);
+
+//Autowidth
+$extra_params['autowidth'] = 'true';
+
+//height auto
+$extra_params['height'] = 'auto';
+
+?>
+<script>
+
+    function setSearchSelect(columnName) {
+        $("#results").jqGrid('setColProp', columnName, {
+            searchoptions:{
+                dataInit:function (el) {
+                    $("option[value='1']", el).attr("selected", "selected");
+                    setTimeout(function () {
+                        $(el).trigger('change');
+                    }, 1000);
+                }
+            }
+        });
+    }
+
+    function exportExcel() {
+        var mya = new Array();
+        mya = $("#results").getDataIDs();  // Get All IDs
+        var data = $("#results").getRowData(mya[0]);     // Get First row to get the labels
+        var colNames = new Array();
+        var ii = 0;
+        for (var i in data) {
+            colNames[ii++] = i;
+        }    // capture col names
+        var html = "";
+
+        for (i = 0; i < mya.length; i++) {
+            data = $("#results").getRowData(mya[i]); // get each row
+            for (j = 0; j < colNames.length; j++) {
+                html = html + data[colNames[j]] + ","; // output each column as tab delimited
+            }
+            html = html + "\n";  // output each row with end of line
+        }
+        html = html + "\n";  // end of line at the end
+
+        var form = $("#export_report_form");
+
+        $("#csvBuffer").attr('value', html);
+        form.target = '_blank';
+        form.submit();
+    }
+
+    $(function () {
+    <?php
+        echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
+    ?>
+        //setSearchSelect("status");
+        //
+        //view:true, del:false, add:false, edit:false, excel:true}
+        $("#results").jqGrid(
+            'navGrid',
+            '#results_pager',
+            { view:true, edit:false, add:false, del:false, excel:false },
+            { height:280, reloadAfterSubmit:false }, // view options
+            { height:280, reloadAfterSubmit:false }, // edit options
+            { height:280, reloadAfterSubmit:false }, // add options
+            { reloadAfterSubmit : false }, // del options
+            { width:500 } // search options
+        );
+        //Adding search options
+        var options = {
+            'stringResult': true,
+            'autosearch' : true,
+            'searchOnEnter':false
+        }
+        jQuery("#results").jqGrid('filterToolbar', options);
+        var sgrid = $("#results")[0];
+        sgrid.triggerToolbar();
+
+    });
+</script>
+<form id="export_report_form" method="post" action="exercise_report.php">
+    <input type="hidden" name="csvBuffer" id="csvBuffer" value=""/>
+    <input type="hidden" name="export_report" id="export_report" value="1"/>
+</form>
+<?php
+
+echo Display::grid_html('results');
+
+Display :: display_footer();

+ 1 - 3
main/admin/index.php

@@ -198,9 +198,7 @@ if (api_is_platform_admin()) {
 }
 
 $items[] = array('url'=>'usergroups.php', 	'label' => get_lang('Classes'));
-
-
-
+$items[] = array('url'=> 'exercise_report.php', 	'label' => get_lang('ExerciseReport'));
 $items[] = array('url'=>'extra_fields.php?type=session', 	'label' => get_lang('ManageSessionFields'));
 
 $blocks['sessions']['items'] = $items;

+ 10 - 29
main/exercice/exercise_report.php

@@ -243,7 +243,7 @@ if ($is_allowedToEdit) {
 
 echo $actions;
 
-$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user;
+$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user.'&'.api_get_cidreq();
 
 $action_links = '';
 
@@ -404,35 +404,16 @@ $extra_params['height'] = 'auto';
 
     if ($is_allowedToEdit || $is_tutor) {
         ?>
-        //setSearchSelect("status");
-        //
-        //view:true, del:false, add:false, edit:false, excel:true}
-        $("#results").jqGrid('navGrid', '#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
-                {height:280, reloadAfterSubmit:false}, // view options
-                {height:280, reloadAfterSubmit:false}, // edit options
-                {height:280, reloadAfterSubmit:false}, // add options
-                {reloadAfterSubmit:false}, // del options
-                {width:500} // search options
+        $("#results").jqGrid(
+            'navGrid',
+            '#results_pager',
+            { view:true, edit:false, add:false, del:false, excel:false },
+            { height:280, reloadAfterSubmit:false }, // view options
+            { height:280, reloadAfterSubmit:false }, // edit options
+            { height:280, reloadAfterSubmit:false }, // add options
+            { reloadAfterSubmit:false }, // del options
+            { width:500 } // search options
         );
-        /*
-// add custom button to export the data to excel
-jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
-  caption:"",
-  onClickButton : function () {
-       //exportExcel();
-  }
-});*/
-
-        /*
-        jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
-        {
-            try {
-                jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
-            } catch (e) {
-                window.location= 'grid.php?oper=csv';
-            }
-        },buttonicon:'ui-icon-document'})
-        */
 
         //Adding search options
         var options = {

+ 53 - 59
main/inc/ajax/model.ajax.php

@@ -83,7 +83,8 @@ $ops = array(
  * @param $val
  * @return string
  */
-function get_where_clause($col, $oper, $val) {
+function get_where_clause($col, $oper, $val)
+{
     global $ops;
     if (empty($col)) {
         return '';
@@ -233,10 +234,13 @@ switch ($action) {
         }
         $count = ExerciseLib::get_count_exam_results($exercise_id, $where_condition);
         break;
+    case 'get_admin_exercise_results':
+        $count = ExerciseLib::get_admin_count_exam_results($where_condition);
+        break;
     case 'get_hotpotatoes_exercise_results':
         $hotpot_path = $_REQUEST['path'];
-		$count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
-		break;
+        $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
+        break;
     case 'get_sessions':
         $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
         if ($list_type == 'simple') {
@@ -344,7 +348,6 @@ switch ($action) {
                 }
             }
             $columns[] = 'actions';
-
             $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition, $extraFields);
         }
         break;
@@ -380,22 +383,22 @@ switch ($action) {
         $column_names = array(get_lang('Course'), get_lang('User'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance'));
         $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
         if (!empty($extra_fields)) {
-            foreach($extra_fields as $extra) {
+            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);
         break;
-	case 'get_user_skill_ranking':
+    case 'get_user_skill_ranking':
         $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
-	    $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
+        $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
         $result = ArrayClass::msort($result, 'skills_acquired', 'asc');
 
         $skills_in_course = array();
-	    if (!empty($result)) {
-    	    //$counter = 1;
-	        foreach ($result as &$item) {
+        if (!empty($result)) {
+            //$counter = 1;
+            foreach ($result as &$item) {
                 $user_info = api_get_user_info($item['user_id']);
                 $personal_course_list = UserManager::get_personal_session_course_list($item['user_id']);
                 $count_skill_by_course = array();
@@ -407,11 +410,11 @@ switch ($action) {
                         $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
                     }
                 }
-	            $item['photo'] = Display::img($user_info['avatar_small']);
-	            $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
-	        }
-	    }
-    	break;
+                $item['photo'] = Display::img($user_info['avatar_small']);
+                $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
+            }
+        }
+        break;
     case 'get_work_user_list_all':
         if (isset($_GET['type'])  && $_GET['type'] == 'simple') {
             //$columns = array('type', 'firstname', 'lastname',  'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
@@ -432,7 +435,7 @@ switch ($action) {
         }
         $where_condition .= " AND u.user_id <> ".api_get_user_id();
         $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
-    	break;
+        break;
     case 'get_work_user_list':
         if (isset($_GET['type'])  && $_GET['type'] == 'simple') {
             //$columns = array('type', 'firstname', 'lastname',  'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
@@ -444,24 +447,26 @@ switch ($action) {
         $where_condition .= " AND u.user_id = ".api_get_user_id();
         $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
         break;
-	case 'get_exercise_results':
-		$course                     = api_get_course_info();
+    case 'get_exercise_results':
+        $course                     = api_get_course_info();
         //used inside get_exam_results_data()
-		$documentPath				= api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
-		if ($is_allowedToEdit) {
-			$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
-		} else {
-			//$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions');
-		}
+        $documentPath				= api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
+        if ($is_allowedToEdit) {
+            $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
+        }
 		$result = ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
 		break;
-	case 'get_hotpotatoes_exercise_results':
-		$course = api_get_course_info();
+    case 'get_admin_exercise_results':
+        $columns = array('username', 'firstname', 'lastname', 'score', 'link', 'session');
+        $result = ExerciseLib::get_admin_exam_results_data($start, $limit, $sidx, $sord, $where_condition);
+        break;
+    case 'get_hotpotatoes_exercise_results':
+        $course = api_get_course_info();
         //used inside get_exam_results_data()
-		$documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
-		$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date',  'score', 'actions');
-		$result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
-		break;
+        $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
+        $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date',  'score', 'actions');
+        $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
+        break;
     case 'get_sessions':
         $session_columns = SessionManager::get_session_columns($list_type);
         $columns = $session_columns['simple_column_name'];
@@ -474,9 +479,8 @@ switch ($action) {
         break;
      case 'get_timelines':
         $columns = array('headline', 'actions');
-        //$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id');
 
-        if(!in_array($sidx, $columns)) {
+        if (!in_array($sidx, $columns)) {
         	$sidx = 'headline';
         }
         $course_id = api_get_course_int_id();
@@ -502,7 +506,7 @@ switch ($action) {
         }
         $result     = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
         $new_result = array();
-        foreach($result as $item) {
+        foreach ($result as $item) {
             if ($item['parent_id'] != 0) {
                 continue;
             }
@@ -525,7 +529,7 @@ switch ($action) {
                 $item['has_certificates'] = '0';
             }
             if (!empty($skills)) {
-                foreach($skills as $skill) {
+                foreach ($skills as $skill) {
                     $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
                 }
             }
@@ -536,7 +540,7 @@ switch ($action) {
     case 'get_event_email_template':
         $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
         if(!in_array($sidx, $columns)) {
-        	$sidx = 'subject';
+            $sidx = 'subject';
         }
         $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
         $new_result = array();
@@ -555,7 +559,7 @@ switch ($action) {
         break;
     case 'get_careers':
         $columns = array('name', 'description', 'actions');
-        if(!in_array($sidx, $columns)) {
+        if (!in_array($sidx, $columns)) {
         	$sidx = 'name';
         }
         $result     = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
@@ -570,7 +574,7 @@ switch ($action) {
         break;
     case 'get_promotions':
         $columns = array('name', 'career', 'description', 'actions');
-        if(!in_array($sidx, $columns)) {
+        if (!in_array($sidx, $columns)) {
             $sidx = 'name';
         }
         $result     = Database::select('p.id,p.name, p.description, c.name as career, p.status', "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c  ON c.id = p.career_id ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
@@ -588,7 +592,7 @@ switch ($action) {
         if (!in_array($sidx, $columns)) {
             $sidx = 'name';
         }
-        $result     = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
+        $result = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
         $new_result = array();
         foreach($result as $item) {
             $new_result[] = $item;
@@ -608,7 +612,7 @@ switch ($action) {
                     case '0':
                         $group['group_type'] = Display::label(get_lang('Class'), 'info');
                         break;
-                    case '1' :
+                    case '1':
                         $group['group_type'] = Display::label(get_lang('Social'), 'success');
                         break;
                 }
@@ -617,7 +621,7 @@ switch ($action) {
             $result = $new_result;
         }
         $columns = array('name', 'users', 'courses','sessions', 'group_type');
-        if(!in_array($sidx, $columns)) {
+        if (!in_array($sidx, $columns)) {
             $sidx = 'name';
         }
         //Multidimensional sort
@@ -643,31 +647,20 @@ switch ($action) {
         $obj = new ExtraFieldOption($type);
         $columns = array('option_display_text', 'option_value', 'option_order');
         $result  = Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id),'order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
-        /*$new_result = array();
-        if (!empty($result)) {
-            foreach ($result as $item) {
-                $item['field_type']         = $obj->get_field_type_by_id($item['field_type']);
-                $item['field_changeable']   = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
-                $item['field_visible']      = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
-                $item['field_filter']       = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
-                $new_result[]        = $item;
-            }
-            $result = $new_result;
-        }*/
         break;
     case 'get_usergroups_teacher':
         $columns = array('name', 'users', 'actions');
         $options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
         $options['course_id'] = $course_id;
         switch ($type) {
-        case 'not_registered':
-            $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
-            $result = $obj->get_usergroup_not_in_course($options);
-            break;
-        case 'registered':
-            $options['where'] = array(" usergroup.course_id = ? " =>  $course_id);
-            $result = $obj->get_usergroup_in_course($options);
-            break;
+            case 'not_registered':
+                $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
+                $result = $obj->get_usergroup_not_in_course($options);
+                break;
+            case 'registered':
+                $options['where'] = array(" usergroup.course_id = ? " =>  $course_id);
+                $result = $obj->get_usergroup_in_course($options);
+                break;
         }
         $new_result = array();
 
@@ -706,6 +699,7 @@ $allowed_actions = array(
     'get_gradebooks',
     'get_sessions',
     'get_exercise_results',
+    'get_admin_exercise_results',
     'get_hotpotatoes_exercise_results',
     'get_work_user_list',
     'get_work_user_list_others',

+ 131 - 3
main/inc/lib/exercise.lib.php

@@ -119,6 +119,134 @@ class ExerciseLib
         return $count;
     }
 
+    /**
+     * Gets count of exam results
+     * @todo this public static function should be moved in a library  + no global calls
+     */
+    public static function get_admin_count_exam_results($extra_where_conditions)
+    {
+        $count = self::get_admin_exam_results_data(null, null, null, null, $extra_where_conditions, true);
+        return $count;
+    }
+
+    /**
+     * Gets the exam'data results
+     * @todo this function should be moved in a library  + no global calls
+     */
+    public static function get_admin_exam_results_data($from, $number_of_items, $column, $direction, $extra_where_conditions = null, $get_count = false)
+    {
+
+        if (empty($extra_where_conditions)) {
+            $extra_where_conditions = "1 = 1 ";
+        }
+
+        $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER);
+        $tableCourse = Database :: get_main_table(TABLE_MAIN_COURSE);
+        $tableSession = Database :: get_main_table(TABLE_MAIN_SESSION);
+        $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
+
+        $TBL_TRACK_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+        $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
+
+        // sql for chamilo-type tests for teacher / tutor view
+        $sql_inner_join_tbl_track_exercices = " (
+            SELECT DISTINCT ttte.*
+            FROM $TBL_TRACK_EXERCICES ttte LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr
+            ON (ttte.exe_id = tr.exe_id)
+        )";
+
+        $first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname";
+
+        if ($get_count) {
+            $sql_select = "SELECT count(te.exe_id) ";
+        } else {
+            $sql_select = "SELECT DISTINCT
+                    user_id,
+                    $first_and_last_name,
+                    ce.title,
+                    username,
+                    session.name as session,
+                    te.exe_result,
+                    te.exe_weighting,
+                    te.exe_date,
+                    te.exe_id,
+                    email as exemail,
+                    te.start_date,
+                    steps_counter,
+                    exe_user_id,
+                    te.exe_duration,
+                    propagate_neg,
+                    te.c_id,
+                    te.session_id,
+                    course.code,
+                    orig_lp_id";
+        }
+
+        $sql = " $sql_select
+                FROM $TBL_EXERCICES AS ce
+                INNER JOIN $sql_inner_join_tbl_track_exercices AS te ON (te.exe_exo_id = ce.iid)
+                INNER JOIN $TBL_USER  AS user ON (user.user_id = exe_user_id)
+                INNER JOIN $tableCourse AS course ON (course.id = te.c_id)
+                INNER JOIN $tableSession AS session ON (session.id = te.session_id)
+
+                WHERE $extra_where_conditions AND
+                    te.status != 'incomplete' AND
+                    ce.active <>-1
+                ";
+
+        $column = !empty($column) ? Database::escape_string($column) : null;
+        $from = intval($from);
+        $number_of_items = intval($number_of_items);
+
+        // just count how many answers
+        if ($get_count) {
+            $res = Database::query($sql);
+            return Database::num_rows($res);
+        }
+
+        if (!empty($column)) {
+            $sql .= " ORDER BY $column $direction ";
+        }
+        if ($get_count == false) {
+            $sql .= " LIMIT $from, $number_of_items";
+        }
+
+        $results = array();
+        $resx = Database::query($sql);
+        while ($rowx = Database::fetch_array($resx, 'ASSOC')) {
+            $results[] = $rowx;
+        }
+
+        $list_info = array();
+
+        if (is_array($results)) {
+            // Looping results.
+            foreach ($results as $result) {
+
+                $id = $result['exe_id'];
+                $my_res = $result['exe_result'];
+                $my_total = $result['exe_weighting'];
+
+                if (!$result['propagate_neg'] && $my_res < 0) {
+                    $my_res = 0;
+                }
+
+                $score = self::show_score($my_res, $my_total);
+
+                $courseLink = 'cidReq='.$result['code'].'&id_session='.$result['session_id'];
+
+                $url = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.$courseLink.'&action=edit&id='.$id;
+                $link = Display::url('exercise', $url);
+                $result['link'] = $link;
+                $result['score'] = $score;
+
+                $list_info[] = $result;
+            }
+        }
+
+        return $list_info;
+    }
+
     public static function get_count_exam_hotpotatoes_results($in_hotpot_path)
     {
         return self::get_exam_results_hotpotatoes_data(0, 0, '', '', $in_hotpot_path, true, '');
@@ -191,7 +319,6 @@ class ExerciseLib
         $TBL_TRACK_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
         $TBL_TRACK_HOTPOTATOES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
         $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
-
         $session_id_and = ' AND te.session_id = '.api_get_session_id().' ';
 
         $exercise_id = intval($exercise_id);
@@ -223,7 +350,7 @@ class ExerciseLib
             }
 
             $sqlFromOption = "";
-            $sqlWhereOption = "";           // for hpsql
+            $sqlWhereOption = "";
             //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
             //Hack in order to filter groups
             $sql_inner_join_tbl_user = '';
@@ -359,7 +486,7 @@ class ExerciseLib
             $teacher_id_list[] = $teacher['user_id'];
         }
 
-        //Simple exercises
+        // Simple exercises.
         if (empty($hotpotatoe_where)) {
             $column = !empty($column) ? Database::escape_string($column) : null;
             $from = intval($from);
@@ -371,6 +498,7 @@ class ExerciseLib
             $sql .= " LIMIT $from, $number_of_items";
 
             $results = array();
+
             $resx = Database::query($sql);
             while ($rowx = Database::fetch_array($resx, 'ASSOC')) {
                 $results[] = $rowx;