Julio Montoya 13 years ago
parent
commit
637440283b

+ 2 - 1
main/exercice/exercice.php

@@ -409,10 +409,11 @@ if ($total > $limit) {
  
     $i =1;
     $lis = '';
-$exercise_list = array();
+
 $online_icon  = Display::return_icon('online.png', get_lang('Visible'),array('width'=>'12px'));
 $offline_icon = Display::return_icon('offline.png',get_lang('Invisible'),array('width'=>'12px'));
 
+$exercise_list = array();
 while ($row = Database :: fetch_array($result,'ASSOC')) {
     $exercise_list[] = $row;
 } 

+ 3 - 2
main/exercice/exercise.class.php

@@ -3310,15 +3310,16 @@ class Exercise {
 		
 		if ($limit_time_exists) {
 			$time_now 				= time();
+            //Do not add the UTC parameter in the api_strtotime because the $this->start_time was converted in the read() function
 		
 			if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') {				
-				$permission_to_start = (($time_now - api_strtotime($this->start_time, 'UTC')) > 0) ? true : false;
+				$permission_to_start = (($time_now - api_strtotime($this->start_time)) > 0) ? true : false;
 			} else {
 				$permission_to_start = true;
 			}
 			
 			if ($this->end_time != '0000-00-00 00:00:00') {
-				$exercise_timeover = (($time_now - api_strtotime($this->end_time, 'UTC')) > 0) ? true : false;
+				$exercise_timeover = (($time_now - api_strtotime($this->end_time)) > 0) ? true : false;
 			} else {
 				$exercise_timeover = false;
 			}

+ 6 - 4
main/exercice/exercise.lib.php

@@ -1232,10 +1232,12 @@ function get_all_exercises($course_info = null, $session_id = 0, $check_publicat
     
     $now = api_get_utc_datetime();
     $time_conditions = '';
-    if ($check_publication_dates) {
-        $time_conditions = " AND ((start_time <> '0000-00-00 00:00:00' AND start_time < '$now'  AND end_time <> '0000-00-00 00:00:00'  AND end_time > '$now' )  OR 
-                            (start_time <> '0000-00-00 00:00:00'  AND start_time < '$now'  AND end_time = '0000-00-00 00:00:00') OR
-                            (start_time = '0000-00-00 00:00:00'   AND end_time <> '0000-00-00 00:00:00'  AND end_time > '$now')) ";
+    
+    if ($check_publication_dates) {        
+        $time_conditions = " AND ((start_time <> '0000-00-00 00:00:00' AND start_time < '$now'  AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now' )  OR "; //start and end are set
+        $time_conditions .= " (start_time <> '0000-00-00 00:00:00' AND start_time < '$now'  AND end_time = '0000-00-00 00:00:00') OR "; // only start is set
+        $time_conditions .= " (start_time = '0000-00-00 00:00:00'   AND end_time <> '0000-00-00 00:00:00'  AND end_time > '$now') OR   "; // only end is set
+        $time_conditions .= " (start_time = '0000-00-00 00:00:00'   AND end_time =  '0000-00-00 00:00:00'))  "; // nothing is set                           
     }
     
     if ($session_id == 0) {       

+ 13 - 9
main/inc/lib/main_api.lib.php

@@ -1731,12 +1731,13 @@ function api_get_session_visibility($session_id) {
                 $visibility = SESSION_AVAILABLE;    
             } else {
                 $time = time();
-                
+                     
                 //If datestart is set
                 if (!empty($row['date_start']) && $row['date_start'] != '0000-00-00') {
                     $row['date_start'] = $row['date_start'].' 00:00:00';   
-                    if ($time > api_strtotime($row['date_start'], 'UTC')) {
-                        $visibility = SESSION_AVAILABLE;
+                  
+                    if ($time > api_strtotime($row['date_start'], 'UTC')) {                          
+                        $visibility = SESSION_AVAILABLE;                        
                     } else {
                         $visibility = SESSION_INVISIBLE;
                     }
@@ -1746,14 +1747,17 @@ function api_get_session_visibility($session_id) {
                 if (!empty($row['date_end']) && $row['date_end'] != '0000-00-00') {                    
                     $row['date_end'] = $row['date_end'].' 00:00:00';
                     //only if date_start said that it was ok
+                    
                     if ($visibility == SESSION_AVAILABLE) {
                         $visibility = $row['visibility'];
-                        /*
+                        
                         if ($time < api_strtotime($row['date_end'], 'UTC')) {
-                            $visibility = $row['visibility'];
+                            //date still available
+                            $visibility = SESSION_AVAILABLE;
                         } else {
+                            //session ends
                             $visibility = $row['visibility'];
-                        }*/                 
+                        }
                     }
                 }                
             }
@@ -2374,9 +2378,9 @@ function api_is_allowed_to_session_edit($tutor = false, $coach = false) {
             // Get the session visibility
             $session_visibility = api_get_session_visibility($session_id);  // if 5 the session is still available.
             
-                //@todo We could load the session_rel_course_rel_user permission to increase the level of detail.
-                //echo api_get_user_id();
-                //echo api_get_course_id();
+            //@todo We could load the session_rel_course_rel_user permission to increase the level of detail.
+            //echo api_get_user_id();
+            //echo api_get_course_id();
 
             switch ($session_visibility) {
                 case SESSION_VISIBLE_READ_ONLY: // 1

+ 40 - 50
main/inc/lib/tracking.lib.php

@@ -2179,7 +2179,8 @@ class Tracking {
 				}
 				$course_in_session[$my_session_id]['course_list'] = $final_course_data;
 				$course_in_session[$my_session_id]['name'] = $session_name;
-			}			
+			}		
+            
 			 
 			$html = '';
 
@@ -2187,7 +2188,7 @@ class Tracking {
 			
 			if ($show_courses) {
 				if (!empty($courses)) {
-					$html .= Display::tag('h1', Display::return_icon('course.png', get_lang('MyCourses'), array(), 22).' '.get_lang('MyCourses'));
+					$html .= Display::tag('h2', Display::return_icon('course.png', get_lang('MyCourses'), array(), 22).' '.get_lang('MyCourses'));
 					$html .= '<table class="data_table" width="100%">';
 					$html .= '<tr>
                               '.Display::tag('th', get_lang('Course'),          		array('width'=>'300px')).'
@@ -2335,7 +2336,7 @@ class Tracking {
 				}
 				
 				
-				$html .= Display::tag('h1',Display::return_icon('session.png', get_lang('Sessions'), array(), 22).' '.get_lang('Sessions'));
+				$html .= Display::tag('h2',Display::return_icon('session.png', get_lang('Sessions'), array(), 22).' '.get_lang('Sessions'));
 				
 				$html .= '<table class="data_table" width="100%">';
 				//'.Display::tag('th', get_lang('DoneExercises'),            array('class'=>'head')).'
@@ -2432,7 +2433,7 @@ class Tracking {
 					$session_data 	= $course_in_session[$session_id_from_get];
 					$course_list 	= $session_data['course_list'];
 					
-					$html .= Display::tag('h2',$session_data['name'].' - '.get_lang('CourseList'));
+					$html .= Display::tag('h3',$session_data['name'].' - '.get_lang('CourseList'));
 
 					$html .= '<table class="data_table" width="100%">';
 					//'.Display::tag('th', get_lang('DoneExercises'),         array('class'=>'head')).'
@@ -2563,34 +2564,22 @@ class Tracking {
 			$html = '';
 			if (isset($course_code)) {
 				require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
+                require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
+                require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
+                
 
 				$user_id                    = intval($user_id);
 				$session_id                 = intval($session_id);
 				$course                     = Database::escape_string($course_code);
 				$course_info                = CourseManager::get_course_information($course);
                 
-                $course_id                  = $course_info['real_id'];
-
-				$tbl_user                   = Database :: get_main_table(TABLE_MAIN_USER);
-				$tbl_session                = Database :: get_main_table(TABLE_MAIN_SESSION);
-				$tbl_session_course         = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
-				$tbl_session_course_user    = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+                $course_id                  = $course_info['real_id'];              				
+				$session_name               = api_get_session_name($session_id);
                 
-				$tbl_course_lp              = Database :: get_course_table(TABLE_LP_MAIN);				
-				$tbl_course_quiz            = Database :: get_course_table(TABLE_QUIZ_TEST);
-				
-				$session_name = api_get_session_name($session_id);
 				$html .= Display::tag('h2', $course_info['title']);
 				
 				$html .= '<table class="data_table" width="100%">';
-				
-				// This code was commented on purpose see BT#924
-				
-				/*$sql = 'SELECT visibility FROM '.$course_info['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
-				 $result_visibility_tests = Database::query($sql);
-				
-				if (Database::result($result_visibility_tests, 0, 'visibility') == 1) {*/
-				
+						
 				//Course details
 				$html .= '<tr>
 				                <th class="head" style="color:#000">'.get_lang('Exercices').'</th>
@@ -2600,27 +2589,31 @@ class Tracking {
 				                <th class="head" style="color:#000">'.get_lang('BestResultInCourse').'</th>
 				                <th class="head" style="color:#000">'.get_lang('Statistics').' '.Display :: return_icon('info3.gif', get_lang('OnlyBestResultsPerStudent'), array('align' => 'absmiddle', 'hspace' => '3px')).'</th>                                        
 				                </tr>';
-				
-				if (empty($session_id)) {
-					$sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE c_id = $course_id AND active='1' AND session_id = 0";
-				} else {
-					$sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE c_id = $course_id AND active='1'";
-				}
-				$result_exercices = Database::query($sql_exercices);
-				$to_graph_exercise_result = array();
-                
                 
                 if (empty($session_id)) {
                     $user_list  = UserManager::get_user_list();
                 } else {        
                     $user_list  = SessionManager::get_users_by_session($session_id);        
-                }                                
+                }
+                
+                $exercise_list = get_all_exercises($course_info, $session_id, true);
+                
+                $to_graph_exercise_result = array();                
                                 
-				if (Database::num_rows($result_exercices) > 0) {
+				if (!empty($exercise_list)) {
 					$score = $weighting = $exe_id = 0;
-					while ($exercices = Database::fetch_array($result_exercices)) {
-						//if ($exercices['id'] != 3) continue;
+					foreach ($exercise_list as $exercices) {
+                        
+                        $exercise_obj = new Exercise($course_info['real_id']);
+                        $exercise_obj->read($exercices['id']);
+                        
+                        //just in case
+                        if (!$exercise_obj->is_visible()) {
+                            continue;
+                        }
+                        						
 						$score = $weighting = $attempts = 0;
+                        
 						//Getting count of attempts by user
 						$attempts      = count_exercise_attempts_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id);
 						//For graphics
@@ -2706,19 +2699,16 @@ class Tracking {
 				$html .= Display::tag('th', get_lang('LastConnexion'), array('class'=>'head', 'style'=>'color:#000'));
 				$html .= '</tr>';
 
-				if (empty($session_id)) {
-					$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp  WHERE c_id = $course_id AND session_id = 0 ORDER BY lp.display_order";
-				} else {
-					$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp WHERE c_id = $course_id ORDER BY lp.display_order";
-				}
-
-				$result_learnpath = Database::query($sql_learnpath);
-				if (Database::num_rows($result_learnpath) > 0) {
-					while($learnpath = Database::fetch_array($result_learnpath)) {
-						$progress               = Tracking::get_avg_student_progress($user_id, $course, array($learnpath['id']), $session_id);
-						$last_connection_in_lp  = Tracking::get_last_connection_time_in_lp($user_id, $course, $learnpath['id'], $session_id);
-						$time_spent_in_lp       = Tracking::get_time_spent_in_lp($user_id, $course, array($learnpath['id']), $session_id);
-						$percentage_score 		= Tracking::get_avg_student_score($user_id, $course, array($learnpath['id']), $session_id);
+                $list = new LearnpathList(api_get_user_id(), $course_info['code'], $session_id, 'publicated_on ASC', true);  
+                $lp_list        = $list->get_flat_list();
+                
+				if (!empty($lp_list) > 0) {
+					foreach($lp_list as $lp_id => $learnpath) {
+                        
+						$progress               = Tracking::get_avg_student_progress($user_id, $course, array($lp_id), $session_id);
+						$last_connection_in_lp  = Tracking::get_last_connection_time_in_lp($user_id, $course, $lp_id, $session_id);
+						$time_spent_in_lp       = Tracking::get_time_spent_in_lp($user_id, $course, array($lp_id), $session_id);
+						$percentage_score 		= Tracking::get_avg_student_score($user_id, $course, array($lp_id), $session_id);
 						if (is_numeric($percentage_score)) {
 							$percentage_score = $percentage_score.'%';
 						} else {
@@ -2728,8 +2718,8 @@ class Tracking {
 						$time_spent_in_lp       = api_time_to_hms($time_spent_in_lp);
 
 						$html .= '<tr class="row_even">';
-						$url = api_get_path(WEB_CODE_PATH)."newscorm/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id={$learnpath['id']}&action=view";						
-						$html .= Display::tag('td', Display::url($learnpath['name'], $url, array('target'=>SESSION_LINK_TARGET)));
+						$url = api_get_path(WEB_CODE_PATH)."newscorm/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id=$lp_id&action=view";						
+						$html .= Display::tag('td', Display::url($learnpath['lp_name'], $url, array('target'=>SESSION_LINK_TARGET)));
 						$html .= Display::tag('td', $time_spent_in_lp, array('align'=>'center'));
 						if (is_numeric($progress)) {
 							$progress = $progress.'%';

+ 3 - 1
main/newscorm/learnpathList.class.php

@@ -57,7 +57,9 @@ class learnpathList {
         if ($check_publication_dates) {
             $time_conditions = " AND ( (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now'  AND expired_on <> '0000-00-00 00:00:00'  AND expired_on > '$now' )  OR 
                         (publicated_on <> '0000-00-00 00:00:00'  AND publicated_on < '$now'  AND expired_on = '0000-00-00 00:00:00') OR
-                        (publicated_on = '0000-00-00 00:00:00'   AND expired_on <> '0000-00-00 00:00:00'  AND expired_on > '$now')) ";
+                        (publicated_on = '0000-00-00 00:00:00'   AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR                        
+                        (publicated_on = '0000-00-00 00:00:00'   AND expired_on = '0000-00-00 00:00:00' )) 
+            ";
         }
         
         $sql = "SELECT * FROM $lp_table WHERE c_id = $course_id $time_conditions $condition_session $order";

+ 68 - 16
main/session/index.php

@@ -45,6 +45,50 @@ foreach($new_session_list as $session_item) {
 $my_session_list = array();
 $final_array     = array();
 
+if (!empty($new_session_list)) {
+    foreach($new_session_list as $item) {
+        $my_session_id = isset($item['id_session']) ? $item['id_session'] : null;    
+        if (isset($my_session_id) && !in_array($my_session_id, $my_session_list) && $session_id == $my_session_id) {
+        	$final_array[$my_session_id]['name'] = $item['session_name'];
+            
+            //Get all courses by session where I'm subscribed
+            $my_course_list = UserManager::get_courses_list_by_session(api_get_user_id(), $my_session_id);            
+                   
+            foreach ($my_course_list as $my_course) {
+                $course = array();
+            
+                $course_info   = api_get_course_info($my_course['code']);
+                //Getting all exercises from the current course            
+                $exercise_list = get_all_exercises($course_info, $my_session_id, true);
+                           
+                //Exercises we skip
+                /*if (empty($exercise_list)) {
+                    continue;
+                } */   
+                //$exercise_course_list = array();
+                $course['name'] = $course_info['name'];
+                $course['id']   = $course_info['real_id'];
+                if (!empty($exercise_list)) {        
+                    foreach($exercise_list as $exercise_item) {
+                        //Loading the exercise                
+                        $exercise = new Exercise($course_info['real_id']);
+                        $exercise->read($exercise_item['id']);       
+                        if ($exercise->is_visible()) {                             
+                            //$exercise_course_list[$exercise_item['id']] = $exercise;
+                            //Reading all Exercise results by user, exercise_id, code, and session
+                            $user_results = get_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id);
+                            $course['exercises'][$exercise_item['id']]['data']['exercise_data'] =  $exercise;                            
+                            $course['exercises'][$exercise_item['id']]['data']['results']       =  $user_results;
+                        }
+                    }
+                    $final_array[$my_session_id]['data'][$my_course['code']] = $course;        
+                }   
+            }            
+        }
+        $my_session_list[] =  $my_session_id;      
+    }
+}
+
 if (!empty($course_list)) {
     foreach($course_list as $course_data) {
         if (in_array($course_data['code'], $user_course_list)) {
@@ -96,11 +140,9 @@ if (!empty($course_list)) {
     }
 }
 
-
-//echo '<pre>';print_r($final_array);
 //If the requested session does not exist in my list we stop the script
 if (!api_is_platform_admin()) {
-	if (!in_array($session_id, $my_session_list)) {
+	if (!in_array($session_id, $my_session_list)) {       
 		api_not_allowed();
 	}
 }
@@ -250,31 +292,41 @@ echo $dates.'<br />';
 
 $columns_courses        = array(get_lang('Title'), get_lang('NumberOfPublishedExercises'), get_lang('NumberOfPublishedLps'));
 $column_model_courses   = array(
-    array('name'=>'title',              'index'=>'title',               'width'=>'120px',  'align'=>'left',  'sortable'=>'true'),
+    array('name'=>'title',              'index'=>'title',               'width'=>'400px',  'align'=>'left',  'sortable'=>'true'),
     //array('name'=>'recent_lps',         'index'=>'recent_lps',          'width'=>'10px',  'align'=>'left',  'sortable'=>'false'),
 //    array('name'=>'max_mutation_date',  'index'=>'max_mutation_date',   'width'=>'120px',  'align'=>'left',  'sortable'=>'true'),
-    array('name'=>'exercise_count',     'index'=>'exercise_count',      'width'=>'50px',  'align'=>'left',  'sortable'=>'true'),
-    array('name'=>'lp_count',           'index'=>'lp_count',            'width'=>'50px',  'align'=>'left',  'sortable'=>'true')
+    array('name'=>'exercise_count',     'index'=>'exercise_count',      'width'=>'180px',  'align'=>'left',  'sortable'=>'true'),
+    array('name'=>'lp_count',           'index'=>'lp_count',            'width'=>'180px',  'align'=>'left',  'sortable'=>'true')
 );
 
-$extra_params_courses   = array();
-$extra_params_courses['gridview'] = "false";
-$extra_params_courses['rowNum'] = 9000;
-//$extra_params_courses['scroll'] = 1;
+//$extra_params_courses['gridview'] = "false";
+/*$extra_params_courses['rowNum'] = 9000;
+
 $extra_params_courses['height'] = "100%";
 $extra_params_courses['autowidth'] = 'false'; //use the width of the parent                             
 $extra_params_courses['recordtext'] = '';
 $extra_params_courses['pgtext'] = '';
-$extra_params_courses['pgbuttons'] = false;
-$extra_params_courses['width'] = '90%';
-$extra_params_courses['autowidth'] = 'true';                     
+$extra_params_courses['pgbuttons'] = false;*/
+//$extra_params_courses['width'] = '50%';
+//$extra_params_courses['autowidth'] = 'true'; 
                         
 $url            = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id.'&course_id='.$course_id;
 $columns        = array(get_lang('PublicationDate'),get_lang('Course'), get_lang('LearningPaths'));
 $column_model   = array(array('name'=>'date',   'index'=>'date',   'width'=>'120', 'align'=>'left', 'sortable'=>'true'),
                         array('name'=>'course', 'index'=>'course', 'width'=>'300', 'align'=>'left', 'sortable'=>'true'),
                         array('name'=>'lp',     'index'=>'lp',     'width'=>'440', 'align'=>'left', 'sortable'=>'true'));
-$extra_params = array();                        
+$extra_params = array();   
+/*
+$extra_params['sortname'] = 'date';
+$extra_params['sortorder'] = 'asc';
+$extra_params['pgbuttons'] = false;
+$extra_params['recordtext'] = '';
+$extra_params['pgtext'] = '';
+$extra_params['height'] = "100%";
+*/
+//$extra_params['autowidth'] = 'true'; //use the width of the parent
+//$extra_params['width'] = '90%';    
+
 //$extra_params['autowidth'] = 'true'; //use the width of the parent
 //$extra_params['forceFit'] = 'true'; //use the width of the parent
 //$extra_params['altRows'] = 'true'; //zebra style
@@ -377,9 +429,9 @@ $(function() {
 </script>
 
 <?php 
-$my_reporting   = Tracking::show_user_progress(api_get_user_id(), $session_id, '&session_id='.$session_id.'#tabs-4', false);
+$my_reporting   = Tracking::show_user_progress(api_get_user_id(), $session_id, '#tabs-4', false);
 if (!empty($my_reporting))  {
-    $my_reporting  .= '<br />'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $_GET['session_id']);
+    $my_reporting  .= '<br />'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $session_id);
 }
 if (empty($my_reporting)) {
     $my_reporting  = Display::return_message(get_lang('NoDataAvailable'), 'warning');