Julio Montoya před 12 roky
rodič
revize
5cb93f229e

+ 55 - 85
main/admin/usergroup_user_import.php

@@ -1,69 +1,69 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-*	@package chamilo.admin
-*/
+ * 	@package chamilo.admin
+ */
 /**
  * Code
-* This tool allows platform admins to update class-user relations by uploading
-* a CSVfile
-*/
+ * This tool allows platform admins to update class-user relations by uploading
+ * a CSVfile
+ */
 
 /**
  * Validates imported data.
  */
 function validate_data($user_classes) {
     global $purification_option_for_usernames;
-    $errors = array ();
-    $classcodes = array ();
-    
-    /*if (!isset($_POST['subscribe']) && !isset($_POST['subscribe']))  {
-          $user_class['error'] = get_lang('SelectAnAction');
-          $errors[] = $user_class;
-          return $errors;
-    }*/
-    
+    $errors = array();
+    $classcodes = array();
+
+    /* if (!isset($_POST['subscribe']) && !isset($_POST['subscribe']))  {
+      $user_class['error'] = get_lang('SelectAnAction');
+      $errors[] = $user_class;
+      return $errors;
+      } */
+
     $usergroup = new UserGroup();
-    
+
     foreach ($user_classes as $index => $user_class) {
         $user_class['line'] = $index + 1;
         // 1. Check whether mandatory fields are set.
-        $mandatory_fields = array ('UserName', 'ClassName');
-        
-        foreach ($mandatory_fields as $key => $field) {            
-            if (!isset ($user_class[$field]) || strlen($user_class[$field]) == 0) {                
-                $user_class['error'] = get_lang($field.'Mandatory');
+        $mandatory_fields = array('UserName', 'ClassName');
+
+        foreach ($mandatory_fields as $key => $field) {
+            if (!isset($user_class[$field]) || strlen($user_class[$field]) == 0) {
+                $user_class['error'] = get_lang($field . 'Mandatory');
                 $errors[] = $user_class;
             }
         }
-        
+
         // 2. Check whether classcode exists.
-        if (isset ($user_class['ClassName']) && strlen($user_class['ClassName']) != 0) {
+        if (isset($user_class['ClassName']) && strlen($user_class['ClassName']) != 0) {
             // 2.1 Check whether code has been allready used in this CVS-file.
-            if (!isset ($classcodes[$user_class['ClassName']])) {
+            if (!isset($classcodes[$user_class['ClassName']])) {
                 // 2.1.1 Check whether code exists in DB
-                $exists = $usergroup->usergroup_exists($user_class['ClassName']);                
+                $exists = $usergroup->usergroup_exists($user_class['ClassName']);
                 if (!$exists) {
-                    $user_class['error'] = get_lang('CodeDoesNotExists').': '.$user_class['ClassName'];
+                    $user_class['error'] = get_lang('CodeDoesNotExists') . ': ' . $user_class['ClassName'];
                     $errors[] = $user_class;
                 } else {
                     $classcodes[$user_class['CourseCode']] = 1;
                 }
             }
         }
-        
+
         // 3. Check username, first, check whether it is empty.
         if (!UserManager::is_username_empty($user_class['UserName'])) {
             // 3.1. Check whether username is too long.
             if (UserManager::is_username_too_long($user_class['UserName'])) {
-                $user_class['error'] = get_lang('UserNameTooLong').': '.$user_class['UserName'];
+                $user_class['error'] = get_lang('UserNameTooLong') . ': ' . $user_class['UserName'];
                 $errors[] = $user_class;
             }
-            
-            $username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames);            
+
+            $username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames);
             // 3.2. Check whether username exists.
             if (UserManager::is_username_available($username)) {
-                $user_class['error'] = get_lang('UnknownUser').': '.$username;
+                $user_class['error'] = get_lang('UnknownUser') . ': ' . $username;
                 $errors[] = $user_class;
             }
         }
@@ -79,21 +79,22 @@ function save_data($users_classes) {
     global $purification_option_for_usernames;
 
     // Table definitions.
-    $user_table 		= Database :: get_main_table(TABLE_MAIN_USER);
-    
+    $user_table = Database :: get_main_table(TABLE_MAIN_USER);
+
     $usergroup = new UserGroup();
-    
+
     // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
-    $csv_data = array ();
+    $csv_data = array();
     if (!empty($users_classes)) {
+        
         foreach ($users_classes as $user_class) {
-            $sql1 = "SELECT user_id FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'";
+            $sql1 = "SELECT user_id FROM $user_table WHERE username = '" . Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames)) . "'";
             $res1 = Database::query($sql1);
             $obj1 = Database::fetch_object($res1);
 
             $usergroup = new UserGroup();
-            $id = $usergroup->get_id_by_name($user_class['ClassName']);   
-            
+            $id = $usergroup->get_id_by_name($user_class['ClassName']);
+
             if ($obj1 && $id) {
                 $csv_data[$id]['user_list'][] = $obj1->user_id;
                 $csv_data[$id]['user_list_name'][] = $user_class['UserName'];
@@ -101,51 +102,20 @@ function save_data($users_classes) {
             }
         }
     }
-    
+
     // Logic for processing the request (data + UI options).
-        
-    if (!empty($csv_data)) {
+    $message = null;
+    if (!empty($csv_data)) {        
         foreach ($csv_data as $class_id => $user_data) {
             $user_list = $user_data['user_list'];
-            
             $class_name = $user_data['class_name'];
             $user_list_name = $user_data['user_list_name'];
-            
             $usergroup->subscribe_users_to_usergroup($class_id, $user_list);
-
-            /*
-            $sql = "SELECT class_id FROM $class_user_table cu WHERE cu.user_id = $user_id";
-            $res = Database::query($sql);
-            while ($obj = Database::fetch_object($res)) {
-                $db_subscriptions[$obj->class_id] = 1;
-            }
-            $to_subscribe   = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
-            $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
-
-            // Subscriptions for new classes.
-            if ($_POST['subscribe']) {
-                foreach ($to_subscribe as $class_id) {
-                    ClassManager::add_user($user_id, $class_id);
-                }
-            }
-            // Unsubscription from previous classes.
-            if ($_POST['unsubscribe']) {
-                foreach ($to_unsubscribe as $class_id) {
-                    ClassManager::unsubscribe_user($user_id, $class_id);
-                }
-            }*/
-            $message = Display::return_message(get_lang('Class').': '.$class_name.'<br />', 'normal', false);
-            $message .= Display::return_message(get_lang('Users').': '.implode(', ', $user_list_name));
-            
-            return $message;
-
+            $message .= Display::return_message(get_lang('Class') . ': ' . $class_name . '<br />', 'normal', false);
+            $message .= Display::return_message(get_lang('Users') . ': ' . implode(', ', $user_list_name));
         }
-    }
-    
-   
-    
-    
-    
+    }    
+    return $message;
 }
 
 /**
@@ -166,13 +136,13 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
+require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
+require_once api_get_path(LIBRARY_PATH) . 'import.lib.php';
 
-$tool_name = get_lang('AddUsersToAClass').' CSV';
+$tool_name = get_lang('AddUsersToAClass') . ' CSV';
 
-$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
-$interbreadcrumb[] = array ('url' => 'usergroups.php', 'name' => get_lang('Classes'));
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array('url' => 'usergroups.php', 'name' => get_lang('Classes'));
 
 // Set this option to true to enforce strict purification for usenames.
 $purification_option_for_usernames = false;
@@ -188,9 +158,9 @@ $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="s
 
 if ($form->validate()) {
     $users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
-    $errors = validate_data($users_classes);    
-    if (count($errors) == 0) {        
-        $return = save_data($users_classes);        
+    $errors = validate_data($users_classes);
+    if (count($errors) == 0) {
+        $return = save_data($users_classes);
     }
 }
 
@@ -203,7 +173,7 @@ if (isset($return) && $return) {
 if (count($errors) != 0) {
     $error_message = "\n";
     foreach ($errors as $index => $error_class_user) {
-        $error_message .= get_lang('Line').' '.$error_class_user['line'].': '.$error_class_user['error'].'</b>';
+        $error_message .= get_lang('Line') . ' ' . $error_class_user['line'] . ': ' . $error_class_user['error'] . '</b>';
         $error_message .= "<br />";
     }
     $error_message .= "\n";
@@ -211,7 +181,7 @@ if (count($errors) != 0) {
 }
 $form->display();
 ?>
-<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
+<p><?php echo get_lang('CSVMustLookLike') . ' (' . get_lang('MandatoryFields') . ')'; ?> :</p>
 <pre>
 <b>UserName</b>;<b>ClassName</b>
 jdoe;class01

+ 1 - 2
main/course_progress/thematic_controller.php

@@ -180,8 +180,7 @@ class ThematicController {
                         $advance_html = null;
                         if (!empty($data)) {
                             foreach ($data as $advance) {                                
-                                //DATE_TIME_FORMAT_LONG
-                                $advance_html .= api_convert_and_format_date($advance['start_date'], DATE_FORMAT_ONLY_DAYNAME) . ' ('.$advance['duration'].' '.get_lang('HourShort').')<br />'.$advance['content'].'<br />';
+                                $advance_html .= api_convert_and_format_date($advance['start_date'], DATE_FORMAT_LONG) . ' ('.$advance['duration'].' '.get_lang('HourShort').')<br />'.$advance['content'].'<br />';
                             }
                         }
                         $table[] = array($theme['title'], $plan_html, $advance_html);

+ 10 - 9
main/exercice/exercise.lib.php

@@ -46,7 +46,6 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
 	$answerType    = $objQuestionTmp->selectType();
 	$pictureName   = $objQuestionTmp->selectPicture();
 	
-	$html = '';
 	if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
 		// Question is not a hotspot
         
@@ -388,11 +387,11 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                 }			
             	$s.='</tr>';
 				
-			} elseif ($answerType == FILL_IN_BLANKS) {                
+			} elseif ($answerType == FILL_IN_BLANKS) {               
 				list($answer) = explode('::', $answer);
 				
-				api_preg_match_all('/\[[^]]+\]/', $answer, $teacher_answer_list);				
-				
+				api_preg_match_all('/\[[^]]+\]/', $answer, $teacher_answer_list);
+                
 				if (isset($user_choice[0]['answer'])) {
 					api_preg_match_all('/\[[^]]+\]/', $user_choice[0]['answer'], $student_answer_list);
 					$student_answer_list = $student_answer_list[0];
@@ -409,20 +408,22 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
 				        $value = null;
 				        if (isset($student_answer_list[$i]) && !empty($student_answer_list[$i])) {
 				        	//Cleaning student answer list
-				            $value = strip_tags($student_answer_list[$i]);				            				            
-				            $value = api_substr($value,1, api_strlen($value)-2);
+				            $value = strip_tags($student_answer_list[$i]);                            
+				            $value = api_substr($value, 1, api_strlen($value)-2);                            
 				            $value = explode('/', $value);
+                            
 				            if (!empty($value[0])) {
 				            	$value = trim($value[0]);
 				            	$value = str_replace('&nbsp;', '',  $value);
-				            }
-				            $answer = api_preg_replace('/\['.$teacher_item.'+\]/', Display::input('text', "choice[$questionId][]", $value), $answer);				            
+				            }                            
+                            $teacher_item = api_preg_replace('-', '\-', $teacher_item);
+				            $answer = api_preg_replace('/\['.$teacher_item.'+\]/', Display::input('text', "choice[$questionId][]", $value), $answer);	
 				        }				        				        
 				        $i++;				        
 				    }
 				} else {
 					$answer = api_preg_replace('/\[[^]]+\]/', Display::input('text', "choice[$questionId][]", '', $attributes), $answer);
-				}				
+				}
 				$s .= '<tr><td>'.$answer.'</td></tr>';
             } elseif ($answerType == MATCHING) {
 				// matching type, showing suggestions and answers

+ 3 - 5
main/inc/lib/thematic.lib.php

@@ -479,7 +479,7 @@ class Thematic
 					}
 				}
                 //DATE_TIME_FORMAT_LONG
-				$thematic_advance_item  = '<div><strong>'.api_convert_and_format_date($thematic_advance['start_date'], DATE_FORMAT_ONLY_DAYNAME).$session_star.'</strong></div>';
+				$thematic_advance_item  = '<div><strong>'.api_convert_and_format_date($thematic_advance['start_date'], DATE_FORMAT_LONG).$session_star.'</strong></div>';
 //				$thematic_advance_item .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance['duration'].'</div>';
 				$thematic_advance_item .= '<div>'.$thematic_advance['duration'].' '.get_lang('HourShort').'</div>';
 				$thematic_advance_item .= '<div>'.Security::remove_XSS($thematic_advance['content'], STUDENT).'</div>';
@@ -743,10 +743,8 @@ class Thematic
 						$data[] = $row;
 					}	
 				}
-			}
-		
-		}
-			
+			}		
+		}			
 		return $data;
 	}
 

+ 30 - 12
main/inc/lib/tracking.lib.php

@@ -731,8 +731,8 @@ class Tracking {
 								//Getting lp_items done by the user
 								$sql = "SELECT DISTINCT lp_item_id 
                                         FROM $lp_item_view_table
-										WHERE   c_id = $course_id AND 
-                                                lp_view_id = $lp_view_id 
+										WHERE c_id = $course_id AND 
+                                              lp_view_id = $lp_view_id 
                                         ORDER BY lp_item_id";
 								$res_lp_item = Database::query($sql);
 
@@ -740,11 +740,20 @@ class Tracking {
 									$my_lp_item_id = $row_lp_item['lp_item_id'];
 
 									//Getting the most recent attempt
-									$sql = "SELECT lp_iv.id as lp_item_view_id, lp_iv.score as score,lp_i.max_score, lp_iv.max_score as max_score_item_view, lp_i.path, lp_i.item_type, lp_i.id as iid
-                                            FROM $lp_item_view_table as lp_iv INNER JOIN $lp_item_table as lp_i ON lp_i.id = lp_iv.lp_item_id AND (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') 
-                                            WHERE 	lp_iv.c_id = $course_id AND 
-                                            		lp_i.c_id  = $course_id AND
-													lp_item_id = $my_lp_item_id AND 
+									$sql = "SELECT  lp_iv.id as lp_item_view_id, 
+                                                    lp_iv.score as score,
+                                                    lp_i.max_score, 
+                                                    lp_iv.max_score as max_score_item_view, 
+                                                    lp_i.path, 
+                                                    lp_i.item_type, 
+                                                    lp_i.id as iid
+                                            FROM $lp_item_view_table as lp_iv 
+                                                INNER JOIN $lp_item_table as lp_i 
+                                                ON  lp_i.id = lp_iv.lp_item_id AND 
+                                                    lp_iv.c_id = $course_id AND 
+                                                    lp_i.c_id  = $course_id AND 
+                                                    (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') 
+                                            WHERE 	lp_item_id = $my_lp_item_id AND 
 													lp_view_id = $lp_view_id 
 											ORDER BY view_count DESC 
 											LIMIT 1";
@@ -756,11 +765,20 @@ class Tracking {
 							} else {
 								// For the currently analysed view, get the score and
 								// max_score of each item if it is a sco or a TOOL_QUIZ
-								$sql_max_score = "SELECT lp_iv.id as lp_item_view_id, lp_iv.score as score,lp_i.max_score, lp_iv.max_score as max_score_item_view, lp_i.path, lp_i.item_type, lp_i.id as iid
-                                                  FROM $lp_item_view_table as lp_iv INNER JOIN $lp_item_table as lp_i ON lp_i.id = lp_iv.lp_item_id AND (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') 
-                                                  WHERE lp_iv.c_id = $course_id AND 
-                                            			lp_i.c_id  = $course_id AND
-														lp_view_id = $lp_view_id ";
+								$sql_max_score = "SELECT lp_iv.id as lp_item_view_id, 
+                                                         lp_iv.score as score,
+                                                         lp_i.max_score, 
+                                                         lp_iv.max_score as max_score_item_view, 
+                                                         lp_i.path, 
+                                                         lp_i.item_type, 
+                                                         lp_i.id as iid
+                                                  FROM $lp_item_view_table as lp_iv 
+                                                      INNER JOIN $lp_item_table as lp_i 
+                                                      ON lp_i.id = lp_iv.lp_item_id AND
+                                                         lp_iv.c_id = $course_id AND
+                                                         lp_i.c_id  = $course_id AND
+                                                         (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."')
+                                                  WHERE lp_view_id = $lp_view_id ";
 								if ($debug) echo $sql_max_score.'<br />';
 
 								$res_max_score = Database::query($sql_max_score);

+ 2 - 3
main/inc/lib/usergroup.lib.php

@@ -30,7 +30,7 @@ class UserGroup extends Model {
     }
     
     public function get_id_by_name($name) {
-        $row = Database::select('id', $this->table, array('where' => array('name = ?', $name)),'first');
+        $row = Database::select('id', $this->table, array('where' => array('name = ?' => $name)),'first');
         return $row['id'];
     }
 
@@ -266,8 +266,7 @@ class UserGroup extends Model {
                 }
                 Database::delete($this->usergroup_rel_course_table, array('usergroup_id = ? AND course_id = ?'=>array($usergroup_id, $course_id)));
             }
-        }
-        
+        }        
     }
 
      /**

+ 5 - 3
main/user/user.php

@@ -379,9 +379,7 @@ if ($origin != 'learnpath') {
     Display::display_reduced_header();
 }
 
-if (isset($message)) {
-	Display::display_confirmation_message($message);
-}
+
 
 /*		MAIN CODE*/
 
@@ -429,6 +427,10 @@ if ( api_is_allowed_to_edit(null, true)) {
 	echo '</div>';
 }
 
+if (isset($message)) {
+	Display::display_confirmation_message($message);
+}
+
 /* 		DISPLAY LIST OF USERS */
 /**
  *  * Get the users to display on the current page.