Browse Source

Minor - format code

jmontoyaa 6 years ago
parent
commit
89694ece65
3 changed files with 349 additions and 615 deletions
  1. 120 291
      main/extra/userInfo.php
  2. 208 289
      main/extra/userInfoLib.php
  3. 21 35
      main/survey/fillsurvey.php

+ 120 - 291
main/extra/userInfo.php

@@ -1,41 +1,21 @@
 <?php
-/* For licensing terms, see /license.txt	*/
-
-/**
- *	This script displays info about one specific user, specified through
- *	a GET parameter, e.g. uInfo=2
- *
- *	@todo clean up script in clean sections:
- *	(1) gather information
- *	(2) tool logic
- *	(3) display
- *	@author original author (unknown, probably thomas,hugues,moosh)
- *	@author Roan Embrechts, minor modification: virtual courses support
- *	@author Julio Montoya Armas Several fixes
- *  @todo clean this code
- *	@package chamilo.user
- */
-
-// name of the language file that needs to be included
-$language_file = array ('registration', 'userInfo');
+/* For licensing terms, see /license.txt */
 
 require_once '../inc/global.inc.php';
+require_once 'userInfoLib.php';
 
 $allow = api_get_configuration_value('extra');
 if (empty($allow)) {
     exit;
 }
 
-require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
 $TABLECALHORAIRE  = Database :: get_course_table(cal_horaire);
-
-$htmlHeadXtra[] = '<script type="text/javascript">
+$htmlHeadXtra[] = '<script>
 function show_image(image,width,height) {
 	width = parseInt(width) + 20;
 	height = parseInt(height) + 20;
 	window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
 }
-
 </script>';
 
 $editMainUserInfo = Security::remove_XSS($_REQUEST['editMainUserInfo']);
@@ -51,8 +31,8 @@ if (api_is_anonymous()) {
 }
 
 //prepare variables used in userInfoLib.php functions
-$TBL_USERINFO_DEF 		= Database :: get_course_table(userinfo_def);
-$TBL_USERINFO_CONTENT 	= Database :: get_course_table(userinfo_content);
+$TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
+$TBL_USERINFO_CONTENT = Database:: get_course_table(userinfo_content);
 
 if ($tool_info['visibility'] == 1 ) {
     $interbreadcrumb[] = array ('url' => 'user.php', 'name' => get_lang('Users'));
@@ -67,8 +47,6 @@ if ($origin != 'learnpath') { //so we are not in learnpath tool
 
 $currentCourse = api_get_course_id();
 $current_session_id = api_get_session_id();
-// api_display_tool_title(get_lang("Users"));
-
 /*
  * data  found  in settings  are :
  *	$uid
@@ -78,9 +56,6 @@ $current_session_id = api_get_session_id();
  *	$currentCourseID
  */
 
-//$userIdViewed = $uInfo; // Id of the user we want to view coming from the user.php
-
-//get information about one user
 $userIdViewed = Security::remove_XSS($_REQUEST['uInfo']);
 
 /**
@@ -90,21 +65,9 @@ $userIdViewed = Security::remove_XSS($_REQUEST['uInfo']);
 $courseCode = api_get_course_id();
 $tbl_coursUser = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 $userIdViewer = api_get_user_id(); // id fo the user currently online
-//$userIdViewed = $_GET['userIdViewed']; // Id of the user we want to view
-
 $allowedToEditContent = ($userIdViewer == $userIdViewed) || $is_platformAdmin;
 $allowedToEditDef = api_is_allowed_to_edit(null, true);
 $is_allowedToTrack = api_is_allowed_to_edit(null, true);
-
-// Library connection
-require_once "userInfoLib.php";
-
-/**
- *  FUNCTIONS
- */
-
-/* 	   COMMANDS SECTION */
-
 $displayMode = "viewContentList";
 $removeDef = Security::remove_XSS($_GET['removeDef']);
 $editDef = Security::remove_XSS($_GET['editDef']);
@@ -124,7 +87,7 @@ if ($allowedToEditDef) {
         $displayMode = "viewDefList";
     } elseif (!empty($_GET['editDef'])) {
         $displayMode = "viewDefEdit";
-    } elseif (!empty ($_POST['addDef'])) {
+    } elseif (!empty($_POST['addDef'])) {
         $displayMode = "viewDefEdit";
     } elseif (!empty($_GET['moveUpDef'])) {
         move_cat_rank($_GET['moveUpDef'], "up");
@@ -138,83 +101,35 @@ if ($allowedToEditDef) {
         $userIdViewed = strval(intval($_GET['editMainUserInfo']));
         $displayMode = "viewMainInfoEdit";
     } elseif (!empty($_REQUEST['submitMainUserInfo'])) {
-        /*
-        if (isset ($_REQUEST['submitMainUserInfo']))
-        {
-        */
         $userIdViewed = strval(intval($_REQUEST['submitMainUserInfo']));
-
-        /*
-        //is teacher
-        $promoteCourseAdmin=$_REQUEST['promoteCourseAdmin'];
-        $userProperties['status'] = 5;
-        if ($promoteCourseAdmin)
-        {
-            $userProperties['status'] = 1;
-        }
-
-        // deprecated feature
-
-        // is coach
-        if (isset ($_REQUEST['promoteTutor']))
-        {
-            $promoteTutor=$_REQUEST['promoteTutor'];
-            $userProperties['tutor'] = 0;
-            if ($promoteTutor)
-            {
-                $userProperties['tutor'] = 1;
-            }
-        }
-//        role is a string
-        if (isset ($_REQUEST['role']))
-        {
-            $role=$_REQUEST['role'];
-            $userProperties['role'] = $role;
-        }
-
-        //get information about one user - task #3009
-*/
-
         if ($current_session_id) {
-
-//            $nocoach = isset($_POST['promoteTutor'])?false:true;
-//            $res = SessionManager::set_coach_to_course_session($userIdViewed, $current_session_id, $courseCode, $nocoach);
-
         } else {
-            if (!empty($_POST['promoteCourseAdmin']) && $_POST['promoteCourseAdmin']){
+            if (!empty($_POST['promoteCourseAdmin']) && $_POST['promoteCourseAdmin']) {
                 $userProperties['status'] = 1;
-            } else{
+            } else {
                 $userProperties['status'] = 5;
             }
-            if (!empty($_POST['promoteTutor']) && $_POST['promoteTutor']){
+            if (!empty($_POST['promoteTutor']) && $_POST['promoteTutor']) {
                 $userProperties['tutor'] = 1;
-            } else{
+            } else {
                 $userProperties['tutor'] = 0;
             }
-
-                            //$userProperties['role'] = $_POST['role'];
-                           	$userhoraire_name = $_POST['hor_name'];
-                           	 $course_id = $_course['real_id'];
-                            update_user_course_properties($userIdViewed, $courseCode, $userProperties,$userhoraire_name, $course_id);
-
-                        }
-
+            $userhoraire_name = $_POST['hor_name'];
+            $course_id = $_course['real_id'];
+            update_user_course_properties($userIdViewed, $courseCode, $userProperties, $userhoraire_name, $course_id);
+        }
         $displayMode = "viewContentList";
     }
 }
 
-// COMMON COMMANDS
-
 if ($allowedToEditContent) {
     if (isset($_POST['submitContent'])) {
         if ($_POST['cntId']) {
             // submit a content change
             edit_cat_content($_POST['catId'], $userIdViewed, $_POST['content'], $_SERVER['REMOTE_ADDR']);
-
-        } else  {
+        } else {
             // submit a totally new content
             fill_new_cat_content($_POST['catId'], $userIdViewed, $_POST['content'], $_SERVER['REMOTE_ADDR']);
-
         }
         $displayMode = "viewContentList";
     } elseif (!empty($_GET['editContent'])) {
@@ -222,38 +137,55 @@ if ($allowedToEditContent) {
         $userIdViewed = $userIdViewed;
     }
 }
-
-/*	   DISPLAY MODES	*/
-// Back button for each display mode (Top)
-
 if (api_is_allowed_to_edit(null, true)) {
-	echo '<div class="actions">';
-	if($origin=='users'){
-		echo '<a href="user.php?'.api_get_cidreq().'&amp;origin='.$origin.'">'.Display::return_icon('back.png',get_lang('BackUser'),'',ICON_SIZE_MEDIUM).'</a>';
-	}
-	else{
-		echo '<a href="javascript:history.back(1)">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
-	}
-
-	if (!is_numeric($_GET['editMainUserInfo'])) {
-		if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
-                    echo '<a href="userInfo.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;editMainUserInfo='.$userIdViewed.'">'.Display::return_icon('edit.png',get_lang('EditUser'),'',ICON_SIZE_MEDIUM).get_lang('EditUser').'</a>';
-                }
-	} else {
-                if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
-                    echo '<a href="userInfo.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;uInfo='.$userIdViewed.'">'.Display::return_icon('user.png',get_lang('ViewUser'),'',ICON_SIZE_MEDIUM).get_lang('ViewUser').'</a>';
-                }
-	}
-	echo '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&amp;origin=user_course&amp;student='.$userIdViewed.'&amp;details=true&amp;course='.$_course['id'].'">'.Display::return_icon('stats.png',get_lang('UserStatistics'),'',ICON_SIZE_MEDIUM).get_lang('UserStatistics').'</a>';
+    echo '<div class="actions">';
+    if ($origin == 'users') {
+        echo '<a href="user.php?'.api_get_cidreq().'&origin='.$origin.'">'.
+            Display::return_icon('back.png', get_lang('BackUser'), '', ICON_SIZE_MEDIUM).'</a>';
+    } else {
+        echo '<a href="javascript:history.back(1)">'.
+            Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
+    }
+
+    if (!is_numeric($_GET['editMainUserInfo'])) {
+        if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
+            echo '<a href="userInfo.php?'.api_get_cidreq(
+                ).'&origin='.$origin.'&editMainUserInfo='.$userIdViewed.'">'.
+                Display::return_icon('edit.png', get_lang('EditUser'), '', ICON_SIZE_MEDIUM).get_lang(
+                    'EditUser'
+                ).'</a>';
+        }
+    } else {
+        if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
+            echo '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&uInfo='.$userIdViewed.'">'.
+                Display::return_icon(
+                    'user.png',
+                    get_lang('ViewUser'),
+                    '',
+                    ICON_SIZE_MEDIUM
+                ).get_lang('ViewUser').'</a>';
+        }
+    }
+	echo '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&origin=user_course&student='.$userIdViewed.'&details=true&course='.$_course['id'].'">'.Display::return_icon('stats.png',get_lang('UserStatistics'),'',ICON_SIZE_MEDIUM).get_lang('UserStatistics').'</a>';
 	echo '</div>';
 } else {
-    if ($tool_info['visibility'] == 1 ) {
+    if ($tool_info['visibility'] == 1) {
         echo '<div class="actions">';
-        if($origin=='users'){
-            echo '<a href="user.php?'.api_get_cidreq().'&amp;origin='.$origin.'">'.Display::return_icon('back.png',get_lang('BackUser'),'',ICON_SIZE_MEDIUM).'</a>';
-        }
-        else{
-            echo '<a href="javascript:history.back(1)">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
+        if ($origin == 'users') {
+            echo '<a href="user.php?'.api_get_cidreq().'&origin='.$origin.'">'.
+                Display::return_icon(
+                    'back.png',
+                    get_lang('BackUser'),
+                    '',
+                    ICON_SIZE_MEDIUM
+                ).'</a>';
+        } else {
+            echo '<a href="javascript:history.back(1)">'.Display::return_icon(
+                    'back.png',
+                    get_lang('Back'),
+                    '',
+                    ICON_SIZE_MEDIUM
+                ).'</a>';
         }
         echo '</div>';
     }
@@ -261,16 +193,19 @@ if (api_is_allowed_to_edit(null, true)) {
 
 // get information about user id viewed
 $user_info_viewed = api_get_user_info($userIdViewed);
-$is_session_course_coach = UserManager::is_session_course_coach($userIdViewed, $_course['sysCode'], $current_session_id);
+$is_session_course_coach = UserManager::is_session_course_coach(
+    $userIdViewed,
+    $_course['sysCode'],
+    $current_session_id
+);
 
 if ($displayMode == "viewDefEdit") {
     /* CATEGORIES DEFINITIONS : EDIT */
-
     $catToEdit = get_cat_def($_GET['editDef']);
     $edit_heading_form = new FormValidator('edit_heading_form');
     $edit_heading_form->addElement('hidden', 'id');
     $edit_heading_form->add_textfield('title', get_lang('Title'));
-    $edit_heading_form->addElement('textarea', 'comment', get_lang('Comment'), array ('cols' => 60, 'rows' => 4));
+    $edit_heading_form->addElement('textarea', 'comment', get_lang('Comment'), array('cols' => 60, 'rows' => 4));
     $possible_line_nrs[1] = '1 '.get_lang('Line');
     $possible_line_nrs[3] = '3 '.get_lang('Lines');
     $possible_line_nrs[5] = '5 '.get_lang('Lines');
@@ -282,23 +217,17 @@ if ($displayMode == "viewDefEdit") {
     $edit_heading_form->display();
 
 } elseif ($displayMode == "viewDefList") {
-    /*CATEGORIES DEFINITIONS : LIST */
-
     $catList = get_cat_def_list();
-
     if ($catList) {
         foreach ($catList as $thisCat) {
             // displays Title and comments
             echo "<p>", "<b>".htmlize($thisCat['title'])."</b><br>\n", "<i>".htmlize($thisCat['comment'])."</i>\n", "</p>";
-
             // displays lines
             echo "<blockquote>\n", "<font color=\"gray\">\n";
-
             for ($i = 1; $i <= $thisCat['nbline']; $i ++) {
                 echo "<br>__________________________________________\n";
             }
             echo "</font>\n", "</blockquote>\n";
-
             // displays commands
             echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&removeDef=", $thisCat['catId'], "\">", "<img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang('Remove')."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\">", "</a>", "<a href=\"".api_get_self()."?".api_get_cidreq()."&editDef=", $thisCat['catId'], "\">", "<img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang('Edit')."\" />", "</a>", "<a href=\"".api_get_self()."?".api_get_cidreq()."&moveUpDef=", $thisCat['catId'], "\">", "<img src=\"../img/up.gif\" border=\"0\" alt=\"".get_lang('MoveUp')."\">", "</a>", "<a href=\"".api_get_self()."?".api_get_cidreq()."&moveDownDef=", $thisCat['catId'], "\">", "<img src=\"../img/down.gif\" border=\"0\" alt=\"".get_lang('MoveDown')."\">", "</a>\n";
         } // end for each
@@ -309,10 +238,8 @@ if ($displayMode == "viewDefEdit") {
         "<input type=\"submit\" name=\"addDef\" class=\"plus\" value=\"".get_lang('AddNewHeading')."\" />",
     "</form>\n",
     "<center>\n";
-}
-elseif ($displayMode == "viewContentEdit") {
+} elseif ($displayMode == 'viewContentEdit') {
     /* CATEGORIES CONTENTS : EDIT */
-
     $catToEdit = get_cat_content($userIdViewed, $_GET['editContent']);
     $content_heading_form = new FormValidator('content_heading_form');
     $content_heading_form->addElement('hidden', 'cntId');
@@ -322,7 +249,12 @@ elseif ($displayMode == "viewContentEdit") {
     if ($catToEdit['nbline'] == 1) {
         $content_heading_form->addElement('text', 'content', null, array ('size' => 80));
     } else {
-        $content_heading_form->addElement('textarea', 'content', null, array ('cols' => 60, 'rows' => $catToEdit['nbline']));
+        $content_heading_form->addElement(
+            'textarea',
+            'content',
+            null,
+            array('cols' => 60, 'rows' => $catToEdit['nbline'])
+        );
     }
     $content_heading_form->addElement('submit', 'submitContent', get_lang('Ok'));
     $defaults = $catToEdit;
@@ -331,21 +263,10 @@ elseif ($displayMode == "viewContentEdit") {
     $content_heading_form->setDefaults($defaults);
     $content_heading_form->display();
 } elseif ($displayMode == "viewMainInfoEdit") {
-
-    /* CATEGORIES MAIN INFO : EDIT */
-
-//    $mainUserInfo = get_main_user_info($userIdViewed, $courseCode);
-	$mainUserInfo = api_get_user_info($userIdViewed);
+    $mainUserInfo = api_get_user_info($userIdViewed);
     if ($mainUserInfo) {
         ($mainUserInfo['status'] == COURSEMANAGER) ? $courseAdminChecked = "checked" : $courseAdminChecked = "";
-
-        if ($current_session_id) {
-//            ($is_session_course_coach)? $tutorChecked = "checked" : $tutorChecked = "";
-        } else {
-//            ($mainUserInfo['tutor_id'] == 1) ? $tutorChecked = "checked" : $tutorChecked = "";
-        }
-
-        $image_array=UserManager::get_user_picture_path_by_id($userIdViewed,'web',false,true);
+        $image_array = UserManager::get_user_picture_path_by_id($userIdViewed, 'web', false, true);
         // get the path,width and height from original picture
         $big_image = $image_array['dir'].'big_'.$image_array['file'];
         $big_image_size = api_getimagesize($big_image);
@@ -365,69 +286,35 @@ elseif ($displayMode == "viewContentEdit") {
 			"<tr align=\"center\" bgcolor=\"#E6E6E6\">\n",
 			"<td align=\"left\">", get_lang('Name'), "</td>\n",
 			"<td width=\"100px\" align=\"left\">", get_lang('Horaire'), "</td>\n";
-			if ($current_session_id) {
-			if ($user_info_viewed['status'] == COURSEMANAGER) {
-			//echo "<td>", get_lang('Tutor'), "</td>\n";
-			}
-			} else {
-			if ($user_info_viewed['status'] == STUDENT) {
-			//echo "<td>", get_lang('CourseAssistant'), "</td>\n";
-			} else {
-			//echo "<td>", get_lang('CourseManager'), "</td>\n";
-			}
-			}
 			echo "</tr>\n",
 			"<tr align=\"center\">",
 			"<td align=\"left\"><b>", htmlize(api_get_person_name($mainUserInfo['firstName'], $mainUserInfo['lastName'])), "</b></td>\n",
-			//"<td align=\"left\"><input type=\"text\" name =\"role\" value=\"", $mainUserInfo['role'], "\" maxlength=\"40\" /></td>",
-
          "<td align=\"left\"><b>", $mainUserInfo['official_code'], "</td>" ;
-$course_id = $_course['real_id'];
-//$course_id = $c_id;
-//récupérer horaire de l'élève
-            ?>
-
-  <SELECT NAME='hor_name'>
+        $course_id = $_course['real_id'];
+        //récupérer horaire de l'élève
+        ?>
+        <SELECT NAME='hor_name'>
             <OPTION VALUE='<?php echo $mainUserInfo['official_code'] ?>'><?php echo get_lang('select_calendar_student'); ?></OPTION>
             <?php
             $sql = "SELECT distinct name FROM $TABLECALHORAIRE
-           where c_id = $course_id ";
-        $result2 = api_sql_query($sql);// OR die(mysql_error());
-             while ( $row = Database::fetch_array( $result2)) {
-                    $horaire_name = $row["name"];
-                                                            ?>
-            <OPTION VALUE='<?php echo $horaire_name; ?>'><?php echo "$horaire_name "; ?></OPTION>
+            where c_id = $course_id ";
+            $result2 = Database::query($sql);
+            while ($row = Database::fetch_array( $result2)) {
+                    $horaire_name = $row["name"]; ?>
+                    <OPTION VALUE='<?php echo $horaire_name; ?>'><?php echo "$horaire_name "; ?></OPTION>
             <?php
-                  }
-                  ?>
-           </SELECT>
-
-             <?php
-              echo'<p></p>  ';
-
-        if (!($is_courseAdmin && $_user['user_id'] == $userIdViewed)) {
-           if ($current_session_id) {
-                if ($user_info_viewed['status'] == COURSEMANAGER) {
-               //     echo "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteTutor\" value=\"1\" ", $tutorChecked, " /></td>";
-                }
-            } else {
-                if ($user_info_viewed['status'] == STUDENT) {
-                //    echo "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteTutor\" value=\"1\" ", $tutorChecked, " />" . ' ' . Display::return_icon('synthese_view.gif',get_lang('TheTutorOnlyCanKeepTrackOfStudentsRegisteredInTheCourse')),$checked,"</td>";
-                } else {
-                //    echo "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteCourseAdmin\" value=\"1\"", $courseAdminChecked, " />" . ' ' . Display::return_icon('synthese_view.gif',get_lang('TheTeacherCanQualifyEvaluateAndKeepTrackOfAllStudentsEnrolledInTheCourse')),$checked,"</td>\n";
-                }
             }
+              ?>
+        </SELECT>
+         <?php
+         echo'<p></p>  ';
+        if (!($is_courseAdmin && $_user['user_id'] == $userIdViewed)) {
         } else {
             echo "<td>", get_lang('CourseManager'), "</td>\n";
-
-
         }
-
-
         echo "<td><button class=\"save\" type=\"submit\" name=\"submit\">".get_lang('SaveChanges')."</button></td>\n", "</tr>", "</table>", "</form>\n";
-
         if (api_get_setting('show_email_addresses') == 'true') {
-            echo "<p>".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."</p>";
+            echo "<p>".Display:: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."</p>";
         }
 
         if (api_get_setting('extended_profile') == 'true') {
@@ -450,14 +337,11 @@ $course_id = $_course['real_id'];
     $virtual_course_code = $_GET["virtual_course"];
     if (isset ($virtual_course_code)) {
         $courseCode = $virtual_course_code;
-        //not supported yet: editing users of virtual courses
         $allowedToEditDef = false;
     }
-
-//    $mainUserInfo = get_main_user_info($userIdViewed, $courseCode);
 	$mainUserInfo = api_get_user_info($userIdViewed);
     if ($mainUserInfo) {
-        $image_array=UserManager::get_user_picture_path_by_id($userIdViewed,'web',false,true);
+        $image_array = UserManager::get_user_picture_path_by_id($userIdViewed, 'web', false, true);
         // get the path,width and height from original picture
         $big_image = $image_array['dir'].'big_'.$image_array['file'];
         $big_image_size = api_getimagesize($big_image);
@@ -474,80 +358,41 @@ $course_id = $_course['real_id'];
         // is the user online?
         $online ='';
         if (user_is_online($userIdViewed)) {
-            $online = Display::return_icon('online.gif', get_lang('OnLine'),array('style'=>'with="8"; height="8"'));
+            $online = Display::return_icon('online.gif', get_lang('OnLine'), array('style' => 'with="8"; height="8"'));
         }
 
-        //DISPLAY TABLE HEADING
-        if ($origin == 'learnpath') { $allowedToEditDef=false; $is_allowedToTrack=false; }
-
-        //"<td>",get_lang('Tutor'),"</td>\n",
-        echo	"<table width=\"80%\" border=\"0\">",
+        // DISPLAY TABLE HEADING
+        if ($origin == 'learnpath') {
+            $allowedToEditDef = false;
+            $is_allowedToTrack = false;
+        }
 
+        echo "<table width=\"80%\" border=\"0\">",
         "<tr align=\"center\" bgcolor=\"#E6E6E6\">\n",
             "<td align=\"left\">".get_lang('Name')."</td>\n",
 				"<td width=\"20%\" align=\"left\">".get_lang('Description')."</td>\n",
          "<td width=\"100px\" align=\"left\">", get_lang('OfficialCode'), "</td>\n";
 
-        if ($current_session_id) {
-            if ($user_info_viewed['status'] == COURSEMANAGER) {
-              //  echo "<td>".get_lang('Tutor')."</td>\n";
-            }
-        } else {
-            if ($user_info_viewed['status'] == STUDENT) {
-               // echo "<td>".get_lang('Tutor')."</td>\n";
-            } else {
-              //  echo "<td>".get_lang('CourseManager')."</td>\n";
-            }
-        }
-        //echo ($allowedToEditDef && api_get_setting('allow_user_course_subscription_by_course_admin') == 'true'?"<td>".get_lang('Edit')."</td>\n":"");
-        //echo ($is_allowedToTrack?"<td>".get_lang('Tracking')."</td>\n":"");
-
-        echo    "</tr>\n",
+        echo "</tr>\n",
         "<tr align=\"center\">\n",
-
             "<td  align=\"left\"><b>".$online.' '.htmlize(api_get_person_name($mainUserInfo['firstName'], $mainUserInfo['lastName']))."</b></td>\n",
-				//	"<td  align=\"left\">".htmlize($mainUserInfo['role'])."</td>",
         "<td align=\"left\"><b>", $mainUserInfo['official_code'], "</td>";
-        //DISPLAY TABLE CONTENT
-
+        // DISPLAY TABLE CONTENT
         if ($current_session_id) {
             if ($user_info_viewed['status'] == COURSEMANAGER) {
-//                if ($is_session_course_coach) {
-//                    echo "<td>",get_lang('Tutor'),"</td>\n";
-//                } else {
-                    echo "<td> - </td>\n";
-//                }
+                echo "<td> - </td>\n";
             }
         } else {
             if ($user_info_viewed['status'] == STUDENT) {
-  //              if ($mainUserInfo['tutor_id'] == 1) {
-  //                  echo "<td>",get_lang('Tutor'),"</td>\n";
-  //              } else {
-                    echo "<td> - </td>\n";
-  //              }
+                echo "<td> - </td>\n";
             } else {
- //               if ($mainUserInfo['status'] == 1) {
- //                   echo "<td>",get_lang('CourseManager'),"</td>";
- //               } else {
-                    echo "<td> - </td>\n";
- //               }
+                echo "<td> - </td>\n";
             }
         }
 
-        if ($allowedToEditDef && api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
-            //echo	"<td>";
-            //echo	"<a href=\"".api_get_self()."?".api_get_cidreq()."&editMainUserInfo=$userIdViewed\"><img border=\"0\" alt=\"\" src=\"../img/edit.gif\" /></a>";
-            //echo	"</td>";
-        }
-        if ($is_allowedToTrack) {
-            //echo "<td>";
-            //echo "<a href=\"../mySpace/myStudents.php?".api_get_cidreq()."&origin=user_course&student=$userIdViewed&details=true&course=".$_course['id']."\"><img border=\"0\" alt=\"".get_lang('Tracking')." : $userIdViewed\" src=\"../img/statistics.gif\" /></a>";
-            //echo "</td>";
-        }
         echo "</tr></table>";
-
         if (api_get_setting("show_email_addresses") == "true") {
-            echo "<p>". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "</p>";
+            echo "<p>".Display::encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."</p>";
         }
 
         if (api_get_setting('extended_profile') == 'true') {
@@ -563,12 +408,12 @@ $course_id = $_course['real_id'];
                 echo '<div style="margin-top:10px;" class="actions-message"><strong>'.get_lang('MyProductions').'</strong></div><div>'.UserManager::build_production_list($mainUserInfo['user_id']).'</div>';
         }
     } else {
-        Display :: display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession'));
+        Display::display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession'));
     }
 
-    if (api_get_setting('allow_user_headings') == 'true' && $allowedToEditDef) // only course administrators see this line
-    {
-        echo	"<div align=right>",
+    if (api_get_setting('allow_user_headings') == 'true' && $allowedToEditDef) {
+        // only course administrators see this line
+        echo "<div align=right>",
             "<form method=\"post\" action=\"".api_get_self()."\">",
         get_lang('CourseAdministratorOnly')," : ",
             "<input type=\"submit\" class=\"save\" name=\"viewDefList\" value=\"".get_lang('DefineHeadings')."\" />",
@@ -578,44 +423,28 @@ $course_id = $_course['real_id'];
     }
 
     $catList = get_course_user_info($userIdViewed);
-
-    if ($catList)
-    {
-        foreach ($catList as $thisCat)
-        {
+    if ($catList) {
+        foreach ($catList as $thisCat) {
             // Category title
-
-            echo	"<p><b>",$thisCat['title'],"</b></p>\n";
-
+            echo "<p><b>", $thisCat['title'], "</b></p>\n";
             // Category content
-
-            echo	"<blockquote>\n";
-
-            if ($thisCat['content'])
-            {
+            echo "<blockquote>\n";
+            if ($thisCat['content']) {
                 echo htmlize($thisCat['content'])."\n";
-            }
-            else
-            {
+            } else {
                 echo "....";
             }
-
             // Edit command
-
-            if ($allowedToEditContent)
-            {
-                echo	"<br><br>\n",
-                    "<a href=\"".api_get_self()."?".api_get_cidreq()."&editContent=",$thisCat['catId'],"&uInfo=",$userIdViewed,"\">",
+            if ($allowedToEditContent) {
+                echo "<br><br>\n",
+                    "<a href=\"".api_get_self()."?".api_get_cidreq(
+                    )."&editContent=", $thisCat['catId'], "&uInfo=", $userIdViewed, "\">",
                 "<img src=\"../img/edit.gif\" border=\"0\" alt=\"edit\">",
                 "</a>\n";
             }
-
-            echo	"</blockquote>\n";
+            echo "</blockquote>\n";
         }
     }
 }
 
-// Back button for each display mode (bottom)
-//echo "<div class=\"actions\"><a href=\"user.php?".api_get_cidreq()."&amp;origin=".$origin."\">".get_lang('BackUser')."</a></div>\n";
-/*		FOOTER	*/
-Display :: display_footer();
+Display::display_footer();

+ 208 - 289
main/extra/userInfoLib.php

@@ -1,22 +1,19 @@
 <?php
 /* For licensing terms, see /license.txt*/
-/**
-*   @package chamilo.user
-*/
 
-/*     CATEGORIES DEFINITION TREATMENT */
 /**
  * create a new category definition for the user information
  *
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesch� <gesche@ipm.ucl.ac.be>
- * @param  - string $title - category title
- * @param  - string $comment - title comment
- * @param  - int$nbline - lines number for the field the user will fill.
- * @return - bollean true if succeed, else bolean false
+ *
+ * @param  string $title   - category title
+ * @param  string $comment - title comment
+ * @param  int    $nbline  - lines number for the field the user will fill.
+ *
+ * @return boolean true if succeed, else bolean false
  */
-
-function create_cat_def($title="", $comment="", $nbline="5")
+function create_cat_def($title = "", $comment = "", $nbline = "5")
 {
     global $TBL_USERINFO_DEF; //taken from userInfo.php
 
@@ -24,17 +21,17 @@ function create_cat_def($title="", $comment="", $nbline="5")
     $comment = Database::escape_string(trim($comment));
     $nbline = strval(intval($nbline));
 
-    if ( 0 == (int) $nbline || empty($title))
-    {
+    if (0 == (int)$nbline || empty($title)) {
         return false;
     }
 
     $sql = "SELECT MAX(rank) as maxRank FROM ".$TBL_USERINFO_DEF;
     $result = Database::query($sql);
-    if ($result) $maxRank = Database::fetch_array($result);
+    if ($result) {
+        $maxRank = Database::fetch_array($result);
+    }
 
     $maxRank = $maxRank['maxRank'];
-
     $thisRank = $maxRank + 1;
 
     $sql = "INSERT INTO $TBL_USERINFO_DEF SET
@@ -53,10 +50,12 @@ function create_cat_def($title="", $comment="", $nbline="5")
  *
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesch� <gesche@ipm.ucl.ac.be>
- * @param  - int $id - id of the category
- * @param  - string $title - category title
- * @param  - string $comment - title comment
- * @param  - int$nbline - lines number for the field the user will fill.
+ *
+ * @param  int    $id      - id of the category
+ * @param  string $title   - category title
+ * @param  string $comment - title comment
+ * @param  int    $nbline  - lines number for the field the user will fill.
+ *
  * @return - boolean true if succeed, else otherwise
  */
 
@@ -64,12 +63,11 @@ function edit_cat_def($id, $title, $comment, $nbline)
 {
     global $TBL_USERINFO_DEF;
 
-    if ( 0 == $nbline || 0 == $id )
-    {
+    if (0 == $nbline || 0 == $id) {
         return false;
     }
     $id = strval(intval($id)); //make sure id is integer
-    $title   = Database::escape_string(trim($title));
+    $title = Database::escape_string(trim($title));
     $comment = Database::escape_string(trim($comment));
     $nbline = strval(intval($nbline));
 
@@ -89,34 +87,32 @@ function edit_cat_def($id, $title, $comment, $nbline)
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
  *
- * @param  - int $id - id of the category
- *              or "ALL" for all category
- * @param  - boolean $force - FALSE (default) : prevents removal if users have
+ * @param  int     $id        - id of the category
+ *                            or "ALL" for all category
+ * @param  boolean $force     - FALSE (default) : prevents removal if users have
  *                            already fill this category
  *                            TRUE : bypass user content existence check
- * @param  - int $nbline - lines number for the field the user will fill.
- * @return - bollean  - TRUE if succeed, ELSE otherwise
+ * @param  int     $nbline    - lines number for the field the user will fill.
+ *
+ * @return boolean  - TRUE if succeed, ELSE otherwise
  */
 
 function remove_cat_def($id, $force = false)
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
-    $TBL_USERINFO_CONTENT   = Database :: get_course_table(userinfo_content);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
+    $TBL_USERINFO_CONTENT = Database:: get_course_table(userinfo_content);
 
     $id = strval(intval($id));
 
-    if ( (0 == (int) $id || $id == "ALL") || ! is_bool($force))
-    {
+    if ((0 == (int)$id || $id == "ALL") || !is_bool($force)) {
         return false;
     }
     $sqlCondition = " WHERE id = '$id'";
-    if (!$force)
-    {
+    if (!$force) {
         $sql = "SELECT * FROM $TBL_USERINFO_CONTENT $sqlCondition";
         $result = Database::query($sql);
 
-        if ( Database::num_rows($result) > 0)
-        {
+        if (Database::num_rows($result) > 0) {
             return false;
         }
     }
@@ -130,29 +126,26 @@ function remove_cat_def($id, $force = false)
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesch� <gesche@ipm.ucl.ac.be>
  *
- * @param  - int $id - id of the category
- * @param  - direction "up" or "down" :
- *                  "up"    decrease the rank of gived $id by switching rank with the just lower
- *                  "down"  increase the rank of gived $id by switching rank with the just upper
+ * @param  int    $id         - id of the category
+ * @param  string $direction  "up" or "down" :
+ *                            "up"    decrease the rank of gived $id by switching rank with the just lower
+ *                            "down"  increase the rank of gived $id by switching rank with the just upper
  *
- * @return - boolean true if succeed, else bolean false
+ * @return boolean true if succeed, else boolean false
  */
-
 function move_cat_rank($id, $direction) // up & down.
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
     $id = strval(intval($id));
 
-    if ( 0 == (int) $id || ! ($direction == "up" || $direction == "down") )
-    {
+    if (0 == (int)$id || !($direction == "up" || $direction == "down")) {
         return false;
     }
 
     $sql = "SELECT rank FROM $TBL_USERINFO_DEF WHERE id = '$id'";
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) < 1)
-    {
+    if (Database::num_rows($result) < 1) {
         return false;
     }
 
@@ -167,42 +160,39 @@ function move_cat_rank($id, $direction) // up & down.
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
  *
- * @param  - int $rank - actual rank of the category
- * @param  - direction "up" or "down" :
- *                  "up"    decrease the rank of gived $rank by switching rank with the just lower
- *                  "down"  increase the rank of gived $rank by switching rank with the just upper
+ * @param  int    $rank      - actual rank of the category
+ * @param  string $direction "up" or "down" :
+ *                           "up"    decrease the rank of gived $rank by switching rank with the just lower
+ *                           "down"  increase the rank of gived $rank by switching rank with the just upper
  *
- * @return - boolean true if succeed, else bolean false
+ * @return boolean true if succeed, else boolean false
  */
-
 function move_cat_rank_by_rank($rank, $direction) // up & down.
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
 
-    if ( 0 == (int) $rank || ! ($direction == "up" || $direction == "down") )
-    {
+    if (0 == (int)$rank || !($direction == "up" || $direction == "down")) {
         return false;
     }
 
-    if ($direction == "down") // thus increase rank ...
-    {
+    if ($direction == "down") {
+        // thus increase rank ...
         $sort = "ASC";
         $compOp = ">=";
-    }
-    else     // thus decrease rank ...
-    {
+    } else {
+        // thus decrease rank ...
         $sort = "DESC";
         $compOp = "<=";
     }
 
     // this request find the 2 line to be switched (on rank value)
-    $sql = "SELECT id, rank FROM ".$TBL_USERINFO_DEF." WHERE rank $compOp $rank
-    ORDER BY rank $sort LIMIT 2";
+    $sql = "SELECT id, rank FROM ".$TBL_USERINFO_DEF." 
+            WHERE rank $compOp $rank
+            ORDER BY rank $sort LIMIT 2";
 
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) < 2)
-    {
+    if (Database::num_rows($result) < 2) {
         return false;
     }
 
@@ -210,9 +200,9 @@ function move_cat_rank_by_rank($rank, $direction) // up & down.
     $nextCat = Database::fetch_array($result);
 
     $sql1 = "UPDATE ".$TBL_USERINFO_DEF." SET rank ='".$nextCat['rank'].
-            "' WHERE id = '".$thisCat['id']."'";
+        "' WHERE id = '".$thisCat['id']."'";
     $sql2 = "UPDATE ".$TBL_USERINFO_DEF." SET rank ='".$thisCat['rank'].
-            "' WHERE id = '".$nextCat['id']."'";
+        "' WHERE id = '".$nextCat['id']."'";
 
     Database::query($sql1);
     Database::query($sql2);
@@ -220,185 +210,131 @@ function move_cat_rank_by_rank($rank, $direction) // up & down.
     return true;
 }
 
-
 /**
  * @author Hugues Peeters - peeters@ipm.ucl.ac.be
- * @param  int     $user_id
- * @param  string  $course_code
- * @param  array   $properties - should contain 'role', 'status', 'tutor_id'
+ *
+ * @param  int    $user_id
+ * @param  string $course_code
+ * @param  array  $properties - should contain 'role', 'status', 'tutor_id'
+ *
  * @return boolean true if succeed false otherwise
  */
-
 function update_user_course_properties($user_id, $course_code, $properties, $horaire_name, $course_id)
 {
     global $tbl_coursUser,$_user;
     $sqlChangeStatus = "";
     $user_id = strval(intval($user_id));//filter integer
     $course_code = Database::escape_string($course_code);
-    if ($user_id != $_user['user_id'])
-    {
+    if ($user_id != $_user['user_id']) {
         $sqlChangeStatus = "status     = '".Database::escape_string($properties['status'])."',";
     }
 
-        //feature deprecated   tutor_id         = '".Database::escape_string($properties['tutor'])."'
-        $sql = "UPDATE $tbl_coursUser
-                        SET     ".$sqlChangeStatus."
+    $sql = "UPDATE $tbl_coursUser
+            SET     ".$sqlChangeStatus."
                 is_tutor        = '".Database::escape_string($properties['tutor'])."'
-                        WHERE   user_id         = '".$user_id."'
-                        AND     c_id     = '".$course_id."'";
-    $result = Database::query($sql);
-            //update official-code: Horaire
+            WHERE   
+                user_id         = '".$user_id."' AND     
+                c_id     = '".$course_id."'";
+    Database::query($sql);
+    //update official-code: Horaire
     $table_user = Database::get_main_table(TABLE_MAIN_USER);
-       $sql2 = "UPDATE $table_user
-                        SET official_code   = '".$horaire_name."'
-                WHERE   user_id         = '".$user_id."'
-               ";
-                  
-    $result2 = api_sql_query($sql2,__FILE__,__LINE__);
- 
-//on récupère l'horaire
-
-$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA);
-$TABLECALDATES = Database :: get_course_table(cal_dates);
-$jour= 0 ;
-        $sql3 = "SELECT date FROM $TABLECALDATES 
-                  WHERE horaire_name = '".$horaire_name."' AND status = 'C'
-                  AND    c_id = '".$course_id."' 
-                  ORDER BY date 
-                  ";
-   
-     $result3 = api_sql_query($sql3,__FILE__,__LINE__);
+    $sql2 = "UPDATE $table_user
+             SET official_code   = '".$horaire_name."'
+             WHERE   user_id         = '".$user_id."'";
+    Database::query($sql2);
+    //on récupère l'horaire
+    $tbl_personal_agenda = Database:: get_main_table(TABLE_PERSONAL_AGENDA);
+    $TABLECALDATES = Database:: get_course_table(cal_dates);
+    $jour = 0;
+    $sql3 = "SELECT date FROM $TABLECALDATES 
+             WHERE 
+                horaire_name = '".$horaire_name."' AND 
+                status = 'C' AND    
+                c_id = '".$course_id."' 
+             ORDER BY date ";
+    $result3 = Database::query($sql3);
+
+    if (Database::num_rows($result3) == '0') {
+        return false;
+    }
 
-  if (Database::num_rows($result3) == '0')
-    {
-            return false;
-    }  
      //on efface ce qui est déjà inscrit
- 
-$sql4 = "DELETE FROM ".$tbl_personal_agenda."
+    $sql4 = "DELETE FROM ".$tbl_personal_agenda."
          WHERE user = '".$user_id."' 
-         AND text = 'Pour le calendrier, ne pas effacer'
-         
- ";
-api_sql_query($sql4,__FILE__,__LINE__);
-
-$sql = "DELETE FROM ".$tbl_personal_agenda."
-         WHERE user = '".$user_id."' AND title = 'Examen*' 
- ";
-api_sql_query($sql,__FILE__,__LINE__);
-    //à chaque date dans l'horaire 
-     while($res3  = Database::fetch_array($result3)) {
-                   $date=$res3['date'];
-  
-//on incrémente les jours de cours
-$date = api_get_utc_datetime($date); 
- 
-$jour= $jour+1;
-//on réinsère le nouvel horaire 
-$sql = "INSERT ".$tbl_personal_agenda." (user,title,text,date)
-      VALUES  ('".$user_id."','".$jour."','Pour le calendrier, ne pas effacer','".$date."')
-        ";
-    api_sql_query($sql,__FILE__,__LINE__);
-    
-    // pour les inscrire examens dans agenda
-    
-           $sql5 = "SELECT date FROM $TABLECALDATES 
+         AND text = 'Pour le calendrier, ne pas effacer'";
+    Database::query($sql4);
+
+    $sql = "DELETE FROM ".$tbl_personal_agenda."
+         WHERE user = '".$user_id."' AND title = 'Examen*'";
+    Database::query($sql);
+    //à chaque date dans l'horaire
+    while ($res3 = Database::fetch_array($result3)) {
+        $date = $res3['date'];
+        //on incrémente les jours de cours
+        $date = api_get_utc_datetime($date);
+        $jour = $jour + 1;
+        //on réinsère le nouvel horaire
+        $sql = "INSERT ".$tbl_personal_agenda." (user,title,text,date) 
+                VALUES ('".$user_id."','".$jour."','Pour le calendrier, ne pas effacer','".$date."')";
+        Database::query($sql);
+        // pour les inscrire examens dans agenda
+        $sql5 = "SELECT date FROM $TABLECALDATES 
                   WHERE horaire_name = '".$horaire_name."' AND status = 'E'
                   AND    c_id = '".$course_id."' 
                   ORDER BY date 
                   ";
-    
-     $result5 = api_sql_query($sql5,__FILE__,__LINE__);
-   
-    } 
-  
-//à chaque date dans l'horaire 
-     while($res5  = Database::fetch_array($result5)) {
-                   $date=$res5['date'];
-$date = api_get_utc_datetime($date);  
- 
-//on réinsère le nouvel horaire  
-$sql7 = "INSERT ".$tbl_personal_agenda." (user,title,date) 
-      VALUES  ('".$user_id."','Examen*','".$date."')
-        ";
-    api_sql_query($sql7,__FILE__,__LINE__);
-    }   
-
-// fin horaire
-
- ///// Francois Belisle Kezber
- //    The only calling location does not process a result, so there is no need to return a value
- //    Moreover, the Database:affectedrows() needs a parameter to work properly.
- //    The code used to crash here because of the Database::affected_rows() call
-
- /*
-    if (Database::affected_rows() > 0)
-    {
-       die('TRUE');
-        return true;
+        $result5 = Database::query($sql5);
     }
-    else
-    {
-       die('FALSE');
-        return false;
-    }*/
 
+    //à chaque date dans l'horaire
+    while ($res5 = Database::fetch_array($result5)) {
+        $date = $res5['date'];
+        $date = api_get_utc_datetime($date);
+        //on réinsère le nouvel horaire
+        $sql7 = "INSERT ".$tbl_personal_agenda." (user,title,date) VALUES  ('".$user_id."','Examen*','".$date."')";
+        Database::query($sql7);
+    }
 }
 
-
-
-
-
-/*----------------------------------------
-     CATEGORIES CONTENT TREATMENT
- --------------------------------------*/
-
-
-
-
-
 /**
  * fill a bloc for information category
  *
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @param  - $definition_id,
- * @param  - $user_id,
- * @param  - $user_ip,
- * @param  - $content
- * @return - boolean true if succeed, else bolean false
+ *
+ * @param   $definition_id
+ * @param   $user_id
+ * @param   $user_ip
+ * @param   $content
+ *
+ * @return  boolean true if succeed, else boolean false
  */
-
-function fill_new_cat_content($definition_id, $user_id, $content="", $user_ip="")
+function fill_new_cat_content($definition_id, $user_id, $content = "", $user_ip = "")
 {
     global $TBL_USERINFO_CONTENT;
 
-    if (empty($user_ip))
-    {
+    if (empty($user_ip)) {
         $user_ip = $_SERVER['REMOTE_ADDR'];
     }
-    $definition_id  = strval(intval($definition_id));
-    $user_id        = strval(intval($user_id));
-    $content        = Database::escape_string(trim($content));
-    $user_ip        = Database::escape_string(trim($user_ip));
+    $definition_id = strval(intval($definition_id));
+    $user_id = strval(intval($user_id));
+    $content = Database::escape_string(trim($content));
+    $user_ip = Database::escape_string(trim($user_ip));
 
-    if ( 0 == $definition_id || 0 == $user_id || $content == "")
-    {
+    if (0 == $definition_id || 0 == $user_id || $content == "") {
         // Here we should introduce an error handling system...
 
         return false;
     }
 
     // Do not create if already exist
-
     $sql = "SELECT id FROM ".$TBL_USERINFO_CONTENT."
             WHERE   definition_id   = '$definition_id'
             AND     user_id         = '$user_id'";
 
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) > 0)
-    {
+    if (Database::num_rows($result) > 0) {
         return false;
     }
 
@@ -418,36 +354,34 @@ function fill_new_cat_content($definition_id, $user_id, $content="", $user_ip=""
  *
  * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @param  - $definition_id,
- * @param  - $user_id,
- * @param  - $user_ip, DEFAULT $REMOTE_ADDR
- * @param  - $content ; if empty call delete the bloc
- * @return - boolean true if succeed, else bolean false
+ *
+ * @param   $definition_id
+ * @param   $user_id
+ * @param   $user_ip        DEFAULT $REMOTE_ADDR
+ * @param   $content        if empty call delete the bloc
+ *
+ * @return  boolean true if succeed, else boolean false
  */
-function edit_cat_content($definition_id, $user_id, $content ="", $user_ip="")
+function edit_cat_content($definition_id, $user_id, $content = "", $user_ip = "")
 {
     global $TBL_USERINFO_CONTENT;
-    $definition_id  = strval(intval($definition_id));
-    $user_id        = strval(intval($user_id));
-    $content        = Database::escape_string(trim($content));
-    if (empty($user_ip))
-    {
+    $definition_id = strval(intval($definition_id));
+    $user_id = strval(intval($user_id));
+    $content = Database::escape_string(trim($content));
+    if (empty($user_ip)) {
         $user_ip = $_SERVER['REMOTE_ADDR'];
     }
     $user_ip = Database::escape_string($user_ip);
 
-    if (0 == $user_id || 0 == $definition_id)
-    {
+    if (0 == $user_id || 0 == $definition_id) {
         return false;
     }
 
-    if ( $content == "")
-    {
+    if ($content == "") {
         return cleanout_cat_content($user_id, $definition_id);
     }
 
-
-    $sql= "UPDATE ".$TBL_USERINFO_CONTENT." SET
+    $sql = "UPDATE ".$TBL_USERINFO_CONTENT." SET
             content         = '$content',
             editor_ip       = '$user_ip',
             edition_time    = now()
@@ -461,21 +395,21 @@ function edit_cat_content($definition_id, $user_id, $content ="", $user_ip="")
 /**
  * clean the content of a bloc for information category
  *
- * @author - Hugues peeters <peeters@ipm.ucl.ac.be>
- * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @param  - $definition_id,
- * @param  - $user_id
- * @return - boolean true if succeed, else bolean false
+ * @author Hugues peeters <peeters@ipm.ucl.ac.be>
+ * @author Christophe Gesche <gesche@ipm.ucl.ac.be>
+ *
+ * @param   $definition_id
+ * @param   $user_id
+ *
+ * @return boolean true if succeed, else boolean false
  */
-
 function cleanout_cat_content($user_id, $definition_id)
 {
     global $TBL_USERINFO_CONTENT;
-    $user_id        = strval(intval($user_id));
-    $definition_id  = strval(intval($definition_id));
+    $user_id = strval(intval($user_id));
+    $definition_id = strval(intval($definition_id));
 
-    if (0 == $user_id || 0 == $definition_id)
-    {
+    if (0 == $user_id || 0 == $definition_id) {
         return false;
     }
 
@@ -487,26 +421,20 @@ function cleanout_cat_content($user_id, $definition_id)
     return true;
 }
 
-
-
-/*----------------------------------------
-     SHOW USER INFORMATION TREATMENT
- --------------------------------------*/
-
 /**
  * get the user info from the user id
  * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @param - int $user_id user id as stored in the Dokeos main db
- * @return - array containg user info sort by categories rank
+ *
+ * @param  int $user_id user id as stored in the Dokeos main db
+ *
+ * @return array containg user info sort by categories rank
  *           each rank contains 'title', 'comment', 'content', 'cat_id'
  */
-
-
 function get_course_user_info($user_id)
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
-    $TBL_USERINFO_CONTENT   = Database :: get_course_table(userinfo_content);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
+    $TBL_USERINFO_CONTENT = Database:: get_course_table(userinfo_content);
 
     $sql = "SELECT  cat.id catId,   cat.title,
                     cat.comment ,   content.content
@@ -516,11 +444,9 @@ function get_course_user_info($user_id)
 
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) > 0)
-    {
-        while ($userInfo = Database::fetch_array($result, 'ASSOC'))
-        {
-            $userInfos[]=$userInfo;
+    if (Database::num_rows($result) > 0) {
+        while ($userInfo = Database::fetch_array($result, 'ASSOC')) {
+            $userInfos[] = $userInfo;
         }
 
         return $userInfos;
@@ -529,27 +455,23 @@ function get_course_user_info($user_id)
     return false;
 }
 
-
-
 /**
  * get the main user information
  * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @param -  int $user_id user id as stored in the Dokeos main db
- * @return - array containing user info as 'lastName', 'firstName'
- *           'email', 'role'
+ *
+ * @param  int $user_id user id as stored in the Dokeos main db
+ *
+ * @return array containing user info as 'lastName', 'firstName', 'email', 'role'
  */
-
 function get_main_user_info($user_id, $courseCode)
 {
-    $user_id    = strval(intval($user_id));
+    $user_id = strval(intval($user_id));
     $courseCode = Database::escape_string($courseCode);
-    if (0 == $user_id)
-    {
+    if (0 == $user_id) {
         return false;
     }
 
-
     $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $table_user = Database::get_main_table(TABLE_MAIN_USER);
     $sql = "SELECT  u.*, u.lastname lastName, u.firstname firstName,
@@ -562,36 +484,33 @@ function get_main_user_info($user_id, $courseCode)
 
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) > 0)
-    {
+    if (Database::num_rows($result) > 0) {
         $userInfo = Database::fetch_array($result, 'ASSOC');
-        $userInfo['password']='';
+        $userInfo['password'] = '';
+
         return $userInfo;
     }
 
     return false;
 }
 
-
-
-
 /**
  * get the user content of a categories plus the categories definition
  * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @param  - int $userId - id of the user
- * @param  - int $catId - id of the categories
- * @return - array containing 'catId', 'title', 'comment',
- *           'nbline', 'contentId' and 'content'
+ *
+ * @param int $userId id of the user
+ * @param int $catId  id of the categories
+ *
+ * @return array containing 'catId', 'title', 'comment', 'nbline', 'contentId' and 'content'
  */
-
 function get_cat_content($userId, $catId)
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
-    $TBL_USERINFO_CONTENT   = Database :: get_course_table(userinfo_content);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
+    $TBL_USERINFO_CONTENT = Database:: get_course_table(userinfo_content);
 
     $userId = strval(intval($userId));
-    $catId  = strval(intval($catId));
+    $catId = strval(intval($catId));
     $sql = "SELECT  cat.id catId,   cat.title,
                     cat.comment ,   cat.line_count,
                     content.id contentId,   content.content
@@ -601,57 +520,57 @@ function get_cat_content($userId, $catId)
             WHERE cat.id = '$catId' ";
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) > 0)
-    {
+    if (Database::num_rows($result) > 0) {
         $catContent = Database::fetch_array($result, 'ASSOC');
         $catContent['nbline'] = $catContent['line_count'];
+
         return $catContent;
     }
 
     return false;
 }
 
-
 /**
  * get the definition of a category
  *
- * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
- * @param  - int $catId - id of the categories
- * @return - array containing 'id', 'title', 'comment', and 'nbline',
+ * @author Christophe Gesche <gesche@ipm.ucl.ac.be>
+ * @author Hugues Peeters <peeters@ipm.ucl.ac.be>
+ *
+ * @param  int $catId - id of the categories
+ *
+ * @return array containing 'id', 'title', 'comment', and 'nbline',
  */
 function get_cat_def($catId)
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
 
     $catId = strval(intval($catId));
     $sql = "SELECT id, title, comment, line_count, rank FROM ".$TBL_USERINFO_DEF." WHERE id = '$catId'";
 
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) > 0)
-    {
+    if (Database::num_rows($result) > 0) {
         $catDef = Database::fetch_array($result, 'ASSOC');
         $catDef['nbline'] = $catDef['line_count'];
+
         return $catDef;
     }
 
     return false;
 }
 
-
 /**
  * get list of all this course categories
  *
- * @author - Christophe Gesche <gesche@ipm.ucl.ac.be>
- * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
- * @return - array containing a list of arrays.
+ * @author Christophe Gesche <gesche@ipm.ucl.ac.be>
+ * @author Hugues Peeters <peeters@ipm.ucl.ac.be>
+ * @return array containing a list of arrays.
  *           And each of these arrays contains
  *           'catId', 'title', 'comment', and 'nbline',
  */
 function get_cat_def_list()
 {
-    $TBL_USERINFO_DEF       = Database :: get_course_table(userinfo_def);
+    $TBL_USERINFO_DEF = Database:: get_course_table(userinfo_def);
 
     $sql = "SELECT  id catId,   title,  comment , line_count
             FROM  ".$TBL_USERINFO_DEF."
@@ -659,11 +578,9 @@ function get_cat_def_list()
 
     $result = Database::query($sql);
 
-    if (Database::num_rows($result) > 0)
-    {
-        while ($cat_def = Database::fetch_array($result, 'ASSOC'))
-        {
-            $cat_def_list[]=$cat_def;
+    if (Database::num_rows($result) > 0) {
+        while ($cat_def = Database::fetch_array($result, 'ASSOC')) {
+            $cat_def_list[] = $cat_def;
         }
 
         return $cat_def_list;
@@ -674,13 +591,15 @@ function get_cat_def_list()
 
 /**
  * transform content in a html display
- * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
- * @param  - string $string string to htmlize
- * @ return  - string htmlized
+ * @author Hugues Peeters <peeters@ipm.ucl.ac.be>
+ *
+ * @param string $string string to htmlize
+ *
+ * @return string htmlized
  */
-
-function htmlize($phrase)
+function htmlize($string)
 {
     global $charset;
-    return nl2br(htmlspecialchars($phrase,ENT_QUOTES,$charset));
-}
+
+    return nl2br(htmlspecialchars($string, ENT_QUOTES, $charset));
+}

+ 21 - 35
main/survey/fillsurvey.php

@@ -504,7 +504,8 @@ if ($survey_data['form_fields'] != '' &&
     $returnParams = $extraField->addElements($form, api_get_user_id());
     $jquery_ready_content = $returnParams['jquery_ready_content'];
 
-    // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
+    // the $jquery_ready_content variable collects all functions
+    // that will be load in the $(document).ready javascript function
     $htmlHeadXtra[] = '<script>
     $(document).ready(function(){
         '.$jquery_ready_content.'
@@ -691,10 +692,10 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                             survey_question_option.sort as option_sort
                         FROM $table_survey_question survey_question
                         LEFT JOIN $table_survey_question_option survey_question_option
-                            ON survey_question.question_id = survey_question_option.question_id AND
-                            survey_question_option.c_id = $course_id
+                        ON survey_question.question_id = survey_question_option.question_id AND
+                        survey_question_option.c_id = $course_id
                         WHERE
-                            survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
+                            survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
                             survey_question.question_id NOT IN (
                                 SELECT sa.question_id
                                 FROM ".$table_survey_answer." sa
@@ -764,9 +765,7 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
             } else {
                 $order = $shuffle;
             }
-
             $answer_list = [];
-
             // Get current user results
             $results = [];
             $sql = "SELECT survey_group_pri, user, SUM(value) as value
@@ -809,7 +808,6 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                             survey_group_sec2='0'
                         GROUP BY survey_group_pri, survey_question.question_id
                     ) as temp
-
                     GROUP BY temp.survey_group_pri
                     ORDER BY temp.survey_group_pri";
 
@@ -869,7 +867,6 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
              */
 
             // i.e 70% - 70% -70% 70%  $equal_count =3
-
             $i = 0;
             $group_cant = 0;
             $equal_count = 0;
@@ -898,18 +895,19 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                         ($result[2]['value'] == $result[3]['value'])
                     ) {
                         $group_cant = 1;
-                    }
-                    // i.e 70% - 70% -0% - 0%     -    $equal_count = 0 we only get the first 2 options
-                    /* elseif (($result[0]['value'] == $result[1]['value']) && ($result[1]['value'] != $result[2]['value'])) {
-                      $group_cant = 0;
-                      } */
-                    /*
-                      // i.e 70% - 70% -60% - 60%  $equal_count = 0 we only get the first 2 options
-                      elseif (($result[0]['value'] == $result[1]['value'])  &&  ($result[2]['value'] == $result[3]['value'])) {
-                      $group_cant = 0;
-                      } */
-                    // i.e. 80% - 70% - 70% - 70%
-                    elseif (($result[0]['value'] != $result[1]['value']) && ($result[1]['value'] == $result[2]['value']) && ($result[2]['value'] == $result[3]['value'])) {
+                    } elseif (($result[0]['value'] != $result[1]['value']) &&
+                        ($result[1]['value'] == $result[2]['value']) && ($result[2]['value'] == $result[3]['value'])
+                    ) {
+                        // i.e 70% - 70% -0% - 0%     -    $equal_count = 0 we only get the first 2 options
+                        /* elseif (($result[0]['value'] == $result[1]['value']) && ($result[1]['value'] != $result[2]['value'])) {
+                          $group_cant = 0;
+                          } */
+                        /*
+                          // i.e 70% - 70% -60% - 60%  $equal_count = 0 we only get the first 2 options
+                          elseif (($result[0]['value'] == $result[1]['value'])  &&  ($result[2]['value'] == $result[3]['value'])) {
+                          $group_cant = 0;
+                          } */
+                        // i.e. 80% - 70% - 70% - 70%
                         $group_cant = 0;
                     } else {
                         // i.e. 80% - 70% - 70% - 50
@@ -986,12 +984,7 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                     if ($shuffle == '') {
                         $shuffle = ' BY survey_question.sort, survey_question_option.sort ASC ';
                     }
-
-                    //$val = 0;
-                    //if ($survey_data['one_question_per_page'] == 0) {
                     $val = (int) $_POST['personality'];
-                    //}
-                    //echo '<pre>'; print_r($paged_questions_sec); echo '</pre>';
                     if (is_array($paged_questions_sec)) {
                         $sql = "SELECT
                                     survey_question.survey_group_sec1,
@@ -1095,15 +1088,10 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
             if ($shuffle == '') {
                 $order_sql = ' BY survey_question.sort, survey_question_option.sort ASC ';
             }
-
-            //$val = 0;
-            //if ($survey_data['one_question_per_page'] == 0) {
             $val = $_GET['show'];
-            //}
-
             $result = null;
             if ($val != '') {
-                $imploded = implode(',', $paged_questions[$val]);
+                $imploded = Database::escape_string(implode(',', $paged_questions[$val]));
                 if ($imploded != '') {
                     // The answers are always in the same order NO shuffle
                     $order_sql = ' BY survey_question.sort, survey_question_option.sort ASC ';
@@ -1135,6 +1123,7 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                     $question_counter_max = Database :: num_rows($result);
                 }
             }
+
             if (!is_null($result)) {
                 $counter = 0;
                 $limit = 0;
@@ -1172,11 +1161,10 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
 $sql = "SELECT * FROM $table_survey_question
         WHERE
             c_id = $course_id AND
-            type='".Database::escape_string('pagebreak')."' AND
+            type = '".Database::escape_string('pagebreak')."' AND
             survey_id='".intval($survey_invitation['survey_id'])."'";
 $result = Database::query($sql);
 $numberofpages = Database::num_rows($result) + 1;
-
 // Displaying the form with the questions
 if (isset($_GET['show'])) {
     $show = (int) $_GET['show'] + 1;
@@ -1196,9 +1184,7 @@ $g_c = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : '';
 $g_ic = isset($_GET['invitationcode']) ? Security::remove_XSS($_GET['invitationcode']) : '';
 $g_cr = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
 $p_l = isset($_POST['language']) ? Security::remove_XSS($_POST['language']) : '';
-
 $add_parameters = isset($_GET['user_id']) ? '&user_id='.intval($_GET['user_id']) : '';
-
 $url = api_get_self().'?cidReq='.$courseInfo['code'].
     '&id_session='.$sessionId.
     $add_parameters.