Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Angel Fernando Quiroz Campos 8 years ago
parent
commit
ba7c15758b

+ 42 - 0
app/Migrations/Schema/V111/Version20160929120000.php

@@ -0,0 +1,42 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+namespace Application\Migrations\Schema\V111;
+
+use Application\Migrations\AbstractMigrationChamilo;
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Types\Type;
+
+/**
+ * Class Version20160929120000
+ * Change tables engine to InnoDB
+ * @package Application\Migrations\Schema\V111
+ */
+class Version20160929120000 extends AbstractMigrationChamilo
+{
+    /**
+     * @param Schema $schema
+     * @throws \Doctrine\DBAL\DBALException
+     * @throws \Doctrine\DBAL\Schema\SchemaException
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql("ALTER TABLE c_tool ADD INDEX idx_ctool_name (name(20))");
+    }
+
+    /**
+     * @param Schema $schema
+     * @throws \Doctrine\DBAL\DBALException
+     * @throws \Doctrine\DBAL\Schema\SchemaException
+     */
+    public function down(Schema $schema)
+    {
+        foreach ($this->names as $name) {
+            if (!$schema->hasTable($name)) {
+                continue;
+            }
+
+            $this->addSql("ALTER TABLE c_tool DROP INDEX idx_ctool_name");
+        }
+    }
+}

+ 5 - 2
main/announcements/download.php

@@ -62,14 +62,17 @@ $doc_url = Database::escape_string($doc_url);
 $sql = "SELECT filename FROM $tbl_announcement_attachment
   	  	WHERE c_id = $course_id AND path LIKE BINARY '$doc_url'";
 
-$result= Database::query($sql);
+$result = Database::query($sql);
 if (Database::num_rows($result) > 0) {
     $row= Database::fetch_array($result);
     $title = str_replace(' ','_', $row['filename']);
     if (Security::check_abs_path($full_file_name,
         api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/announcements/')
     ) {
-        DocumentManager::file_send_for_download($full_file_name, true, $title);
+        $result = DocumentManager::file_send_for_download($full_file_name, true, $title);
+        if ($result === false) {
+            api_not_allowed(true);
+        }
     }
 }
 exit;

+ 1 - 1
main/auth/external_login/ldap.inc.php

@@ -182,7 +182,7 @@ function extldap_get_chamilo_user($ldap_user, $cor = null)
                 if (isset($ldap_user[$ldap_field][0])) {
                     $chamilo_user[$chamilo_field] = extldap_purify_string($ldap_user[$ldap_field][0]);
                 } else {
-                    error_log('EXTLDAP WARNING : '.$ldap_field.'[0] field is not set in ldap array');
+                    //error_log('EXTLDAP WARNING : '.$ldap_field.'[0] field is not set in ldap array');
                 }
                 break;
         }

+ 15 - 7
main/auth/external_login/login.ldap.php

@@ -1,5 +1,7 @@
 <?php
 
+use ChamiloSession as Session;
+
 // External login module : LDAP
 /**
  *
@@ -38,24 +40,30 @@
  *
  * */
 
-use ChamiloSession as Session;
-
 require_once dirname(__FILE__) . '/ldap.inc.php';
 require_once dirname(__FILE__) . '/functions.inc.php';
-error_log('Entering login.ldap.php');
+$debug = false;
+if ($debug) {
+    error_log('Entering login.ldap.php');
+}
 $ldap_user = extldap_authenticate($login, $password);
 if ($ldap_user !== false) {
-    error_log('extldap_authenticate works');
+    if ($debug) {
+        error_log('extldap_authenticate works');
+    }
     $chamilo_user = extldap_get_chamilo_user($ldap_user);
     //userid is not on the ldap, we have to use $uData variable from local.inc.php
     $chamilo_user['user_id'] = $uData['user_id'];
-
-    error_log("chamilo_user found user_id: {$uData['user_id']}");
+    if ($debug) {
+        error_log("chamilo_user found user_id: {$uData['user_id']}");
+    }
 
     //Update user info
     if (isset($extldap_config['update_userinfo']) && $extldap_config['update_userinfo']) {
         external_update_user($chamilo_user);
-        error_log("Calling external_update_user");
+        if ($debug) {
+            error_log("Calling external_update_user");
+        }
     }
 
     $loginFailed = false;

+ 9 - 2
main/blog/download.php

@@ -58,12 +58,19 @@ $sql = 'SELECT filename FROM '.$tbl_blogs_attachment.'
 $result = Database::query($sql);
 if (Database::num_rows($result) > 0) {
     $row = Database::fetch_array($result);
-    if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/')) {
-        DocumentManager::file_send_for_download(
+    if (Security::check_abs_path(
+        $full_file_name,
+        api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/')
+    ) {
+        $result = DocumentManager::file_send_for_download(
             $full_file_name,
             true,
             $row['filename']
         );
+
+        if ($result === false) {
+            api_not_allowed(true);
+        }
     }
 }
 exit;

+ 4 - 1
main/calendar/download.php

@@ -82,7 +82,10 @@ if (Database::num_rows($result)) {
         $full_file_name,
         api_get_path(SYS_COURSE_PATH).$course_info['path'].'/upload/calendar/'
     )) {
-        DocumentManager::file_send_for_download($full_file_name, true, $title);
+        $result = DocumentManager::file_send_for_download($full_file_name, true, $title);
+        if ($result === false) {
+            api_not_allowed(true);
+        }
     }
 }
 

+ 6 - 0
main/cron/import_csv.php

@@ -872,6 +872,7 @@ class ImportCsv
                         $this->extraFieldIdNameList['calendar_event'] => $row['external_calendar_itemID'],
                     );
                 }
+                $errorFound = false;
             }
 
             if (empty($eventsToCreate)) {
@@ -2006,6 +2007,11 @@ class ImportCsv
             Database::query($sql);
             echo $sql.PHP_EOL;
         }
+
+        $table = Database::get_course_table(TABLE_ITEM_PROPERTY);
+        $sql = "DELETE FROM $table WHERE tool = 'calendar_event'";
+        Database::query($sql);
+        echo $sql.PHP_EOL;
     }
 
     /**

+ 4 - 1
main/document/document.php

@@ -315,7 +315,10 @@ switch ($action) {
         }
         $full_file_name = $base_work_dir.$document_data['path'];
         if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) {
-            DocumentManager::file_send_for_download($full_file_name, true);
+            $result = DocumentManager::file_send_for_download($full_file_name, true);
+            if ($result === false) {
+                api_not_allowed(true);
+            }
         }
         exit;
         break;

+ 4 - 1
main/document/download.php

@@ -101,6 +101,9 @@ if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
     // Launch event
     Event::event_download($doc_url);
     $download = (!empty($_GET['dl']) ? true : false);
-    DocumentManager::file_send_for_download($full_file_name, $download);
+    $result = DocumentManager::file_send_for_download($full_file_name, $download);
+    if ($result === false) {
+        api_not_allowed(true);
+    }
 }
 exit;

+ 4 - 1
main/document/download_scorm.php

@@ -55,6 +55,9 @@ if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
     Event::event_download($doc_url);
 
     $fixLinks = api_get_configuration_value('lp_replace_http_to_https');
-    DocumentManager::file_send_for_download($full_file_name, false, '', $fixLinks);
+    $result = DocumentManager::file_send_for_download($full_file_name, false, '', $fixLinks);
+    if ($result === false) {
+        api_not_allowed(true);
+    }
 }
 exit;

+ 3 - 0
main/document/downloadfolder.inc.php

@@ -314,6 +314,9 @@ $name = ($path == '/') ? 'documents.zip' : $documentInfo['title'].'.zip';
 
 if (Security::check_abs_path($tempZipFile, api_get_path(SYS_ARCHIVE_PATH))) {
     $result = DocumentManager::file_send_for_download($tempZipFile, true, $name);
+    if ($result === false) {
+        api_not_allowed(true);
+    }
     @unlink($tempZipFile);
     exit;
 } else {

+ 4 - 1
main/dropbox/dropbox_download.php

@@ -100,7 +100,10 @@ if (!$allowed_to_download) {
         exit;
     }
     $file = $work->title;
-    DocumentManager::file_send_for_download($path, true, $file);
+    $result = DocumentManager::file_send_for_download($path, true, $file);
+    if ($result === false) {
+        api_not_allowed(true);
+    }
     exit;
 }
 //@todo clean this file the code below is useless there are 2 exits in previous conditions ... maybe a bad copy/paste/merge?

+ 4 - 1
main/dropbox/dropbox_functions.inc.php

@@ -1189,7 +1189,10 @@ function zip_download($fileList)
     }
     Session::erase('dropbox_files_to_download');
     $name = 'dropbox-'.api_get_utc_datetime().'.zip';
-    DocumentManager::file_send_for_download($temp_zip_file, true, $name);
+    $result = DocumentManager::file_send_for_download($temp_zip_file, true, $name);
+    if ($result === false) {
+        api_not_allowed(true);
+    }
     @unlink($temp_zip_file);
     exit;
 }

+ 21 - 12
main/exercise/exercise.class.php

@@ -3244,11 +3244,7 @@ class Exercise
 
         $organs_at_risk_hit = 0;
         $questionScore = 0;
-
-        if ($debug) error_log('Start answer loop ');
-
         $answer_correct_array = array();
-
         $orderedHotspots = [];
 
         if ($answerType == HOT_SPOT) {
@@ -3263,6 +3259,8 @@ class Exercise
                 );
         }
 
+        if ($debug) error_log('Start answer loop ');
+
         for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
             $answer = $objAnswerTmp->selectAnswer($answerId);
             $answerComment = $objAnswerTmp->selectComment($answerId);
@@ -3861,18 +3859,22 @@ class Exercise
                     break;
                 case ORAL_EXPRESSION:
                     if ($from_database) {
-                        $query  = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT."
-                                   WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
-                        $resq   = Database::query($query);
+                        $query = "SELECT answer, marks 
+                                  FROM $TBL_TRACK_ATTEMPT
+                                  WHERE 
+                                        exe_id = $exeId AND 
+                                        question_id = $questionId
+                                 ";
+                        $resq = Database::query($query);
                         $row = Database::fetch_assoc($resq);
                         $choice = $row['answer'];
                         $choice = str_replace('\r\n', '', $choice);
                         $choice = stripslashes($choice);
                         $questionScore = $row['marks'];
-                        if ($questionScore==-1) {
-                            $totalScore+=0;
+                        if ($questionScore == -1) {
+                            $totalScore += 0;
                         } else {
-                            $totalScore+=$questionScore;
+                            $totalScore += $questionScore;
                         }
                         $arrques = $questionName;
                         $arrans  = $choice;
@@ -4215,12 +4217,13 @@ class Exercise
                             );
                         } elseif ($answerType == ORAL_EXPRESSION) {
                             // to store the details of open questions in an array to be used in mail
+                            /** @var OralExpression $objQuestionTmp */
                             ExerciseShowFunctions::display_oral_expression_answer(
                                 $feedback_type,
                                 $choice,
                                 0,
                                 0,
-                                $nano,
+                                $objQuestionTmp->getFileUrl(true),
                                 $results_disabled
                             );
                         } elseif ($answerType == HOT_SPOT) {
@@ -6986,7 +6989,13 @@ class Exercise
                     $s .= $objQuestionTmp->returnRecorder();
                 }
 
-                $form->addElement('html_editor', "choice[".$questionId."]", null, array('id' => "choice[".$questionId."]"), array('ToolbarSet' => 'TestFreeAnswer'));
+                $form->addElement(
+                    'html_editor',
+                    "choice[".$questionId."]",
+                    null,
+                    array('id' => "choice[".$questionId."]"),
+                    array('ToolbarSet' => 'TestFreeAnswer')
+                );
                 //$form->setDefaults(array("choice[".$questionId."]" => $content));
                 $s .= $form->return_form();
             }

+ 3 - 1
main/exercise/exercise_submit.php

@@ -532,7 +532,9 @@ if ($formSent && isset($_POST)) {
                     $choice = $exerciseResult[$questionId];
                     if (isset($exe_id)) {
                     	// Manage the question and answer attempts
-                        if ($debug) { error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1)); }
+                        if ($debug) {
+                            error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1));
+                        }
                         $objExercise->manage_answer(
                             $exe_id,
                             $questionId,

+ 42 - 31
main/exercise/oral_expression.class.php

@@ -28,8 +28,8 @@ class OralExpression extends Question
     public function __construct()
     {
         parent::__construct();
-        $this -> type = ORAL_EXPRESSION;
-        $this -> isContent = $this-> getIsContent();
+        $this->type = ORAL_EXPRESSION;
+        $this->isContent = $this->getIsContent();
     }
 
     /**
@@ -38,7 +38,6 @@ class OralExpression extends Question
      */
     function createAnswersForm($form)
     {
-
         $form -> addElement('text','weighting', get_lang('Weighting'), array('class' => 'span1'));
         global $text, $class;
         // setting the save button here and not in the question class.php
@@ -58,7 +57,7 @@ class OralExpression extends Question
      */
     function processAnswersCreation($form)
     {
-        $this->weighting = $form ->getSubmitValue('weighting');
+        $this->weighting = $form->getSubmitValue('weighting');
         $this->save();
     }
 
@@ -96,15 +95,11 @@ class OralExpression extends Question
     {
         $this->sessionId = intval($sessionId);
         $this->userId = intval($userId);
-
         $this->exerciseId = 0;
-
+        $this->exeId = intval($exeId);
         if (!empty($exerciseId)) {
             $this->exerciseId = intval($exerciseId);
         }
-
-        $this->exeId = intval($exeId);
-
         $this->storePath = $this->generateDirectory();
         $this->fileName = $this->generateFileName();
         $this->filePath = $this->storePath . $this->fileName;
@@ -138,15 +133,16 @@ class OralExpression extends Question
             mkdir($this->storePath . $this->sessionId . '/' . $this->exerciseId . '/' . $this->id . '/' . $this->userId);
         }
 
-        return $this->storePath .= implode(
-                '/',
-                array(
-                    $this->sessionId,
-                    $this->exerciseId,
-                    $this->id,
-                    $this->userId
-                )
-            ) . '/';
+        $params = [
+            $this->sessionId,
+            $this->exerciseId,
+            $this->id,
+            $this->userId,
+        ];
+
+        $this->storePath .= implode('/', $params).'/';
+
+        return $this->storePath;
     }
 
     /**
@@ -157,14 +153,14 @@ class OralExpression extends Question
     {
         return implode(
             '-',
-            array(
+            [
                 $this->course['real_id'],
                 $this->sessionId,
                 $this->userId,
                 $this->exerciseId,
                 $this->id,
                 $this->exeId
-            )
+            ]
         );
     }
 
@@ -174,10 +170,17 @@ class OralExpression extends Question
      */
     private function generateRelativeDirectory()
     {
-        return '/exercises/' . implode(
-            '/',
-            [$this->sessionId, $this->exerciseId, $this->id, $this->userId]
-        ) . '/';
+        $params = [
+            $this->sessionId,
+            $this->exerciseId,
+            $this->id,
+            $this->userId,
+        ];
+
+        $path = implode('/', $params);
+        $directory = '/exercises/'.$path.'/';
+
+        return $directory;
     }
 
     /**
@@ -187,7 +190,6 @@ class OralExpression extends Question
     public function returnRecorder()
     {
         $directory = '/..' . $this->generateRelativeDirectory();
-
         $recordAudioView = new Template('', false, false,false, false, false, false);
         $recordAudioView->assign('directory', $directory);
         $recordAudioView->assign('user_id', $this->userId);
@@ -222,7 +224,13 @@ class OralExpression extends Question
                     ]);
 
                 if (!$result) {
-                    return null;
+                    return '';
+                }
+
+                $fileName = $result->getFilename();
+
+                if (empty($fileName)) {
+                    return '';
                 }
 
                 return $this->storePath . $result->getFilename();
@@ -230,23 +238,26 @@ class OralExpression extends Question
         }
 
         foreach ($this->available_extensions as $extension) {
-            if (!is_file($this->storePath . $fileName . ".$extension.$extension")) {
+            $file = "{$this->storePath}$fileName.$extension";
+            if (!is_file($file)) {
                 continue;
             }
 
-            return "{$this->storePath}$fileName.$extension.$extension";
+            return $file;
         }
 
-        return null;
+        return '';
     }
 
     /**
      * Get the URL for the audio file. Return null if the file doesn't exists
+     * @param bool $loadFromDatabase
+     *
      * @return string
      */
-    public function getFileUrl()
+    public function getFileUrl($loadFromDatabase = false)
     {
-        $filePath = $this->getAbsoluteFilePath();
+        $filePath = $this->getAbsoluteFilePath($loadFromDatabase);
 
         if (empty($filePath)) {
             return null;

+ 2 - 2
main/inc/ajax/exercise.ajax.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-use \ChamiloSession as Session;
+use ChamiloSession as Session;
 
 /**
  * Responses to AJAX calls
@@ -326,7 +326,7 @@ switch ($action) {
                 exit;
             }
 
-            $_SESSION['exe_id'] = $exe_id;
+            Session::write('exe_id', $exe_id);
 
             // Getting the total weight if the request is simple
             $total_weight = 0;

+ 1 - 1
main/inc/ajax/record_audio_rtc.ajax.php

@@ -15,7 +15,7 @@ if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
     api_not_allowed();
 }
 
-$file = $_FILES["audio_blob"];
+$file = $_FILES['audio_blob'];
 $audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
 $userId = api_get_user_id();
 

+ 7 - 27
main/inc/lib/api.lib.php

@@ -2635,7 +2635,7 @@ function api_is_coach($session_id = 0, $courseId = null, $check_student_view = t
     if (!empty($session_id)) {
         $sql = "SELECT DISTINCT id, name, access_start_date, access_end_date
                 FROM $session_table
-                WHERE session.id_coach =  '".$userId."' AND id = '$session_id'
+                WHERE session.id_coach = $userId AND id = $session_id
                 ORDER BY access_start_date, access_end_date, name";
         $result = Database::query($sql);
         if (!empty($sessionIsCoach)) {
@@ -3015,7 +3015,6 @@ function api_is_coach_of_course_in_session($sessionId)
     return false;
 }
 
-
 /**
 * Checks if a student can edit contents in a session depending
 * on the session visibility
@@ -3054,7 +3053,6 @@ function api_is_allowed_to_session_edit($tutor = false, $coach = false)
                 case SESSION_AVAILABLE:         //5
                     return true;
             }
-
         }
     }
 }
@@ -3348,7 +3346,7 @@ function api_not_allowed($print_headers = false, $message = null)
             $msg .= "<div style='display:none;'>";
         }
         $msg .= '<div class="well">';
-        $msg .= $form->return_form();
+        $msg .= $form->returnForm();
         $msg .='</div>';
         if ($casEnabled) {
             $msg .= "</div>";
@@ -3936,6 +3934,7 @@ function api_get_item_property_id($course_code, $tool, $ref, $sessionId = 0)
     // Definition of tables.
     $tableItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $course_id = $course_info['real_id'];
+    $sessionId = (int) $sessionId;
     $sessionCondition = " AND session_id = $sessionId ";
     if (empty($sessionId)) {
         $sessionCondition = " AND (session_id = 0 OR session_id IS NULL) ";
@@ -4072,7 +4071,6 @@ function api_get_item_property_info($course_id, $tool, $ref, $session_id = 0, $g
  * (in some cases, like the indexing language picker, it can alter the presentation)
  * @return string
  */
-
 function api_get_languages_combo($name = 'language')
 {
     $ret = '';
@@ -4433,23 +4431,6 @@ function api_max_sort_value($user_course_category, $user_id)
     return 0;
 }
 
-/**
- * This function converts the string "true" or "false" to a boolean true or false.
- * This function is in the first place written for the Chamilo Config Settings (also named AWACS)
- * @param string "true" or "false"
- * @return boolean true or false
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
-function api_string_2_boolean($string) {
-    if ($string == 'true') {
-        return true;
-    }
-    if ($string == 'false') {
-        return false;
-    }
-    return false;
-}
-
 /**
  * Determines the number of plugins installed for a given location
  */
@@ -4895,9 +4876,9 @@ function parse_info_file($filename) {
  * Gets Chamilo version from the configuration files
  * @return string   A string of type "1.8.4", or an empty string if the version could not be found
  */
-function api_get_version() {
-    global $_configuration;
-    return (string)$_configuration['system_version'];
+function api_get_version()
+{
+    return (string) api_get_configuration_value('system_version');
 }
 
 /**
@@ -8078,7 +8059,7 @@ function api_is_date_in_date_range($startDate, $endDate, $currentDate = null)
     $endDate = strtotime(api_get_local_time($endDate));
     $currentDate = strtotime(api_get_local_time($currentDate));
 
-    if (($currentDate >= $startDate) && ($currentDate <= $endDate)) {
+    if ($currentDate >= $startDate && $currentDate <= $endDate) {
         return true;
     }
 
@@ -8175,4 +8156,3 @@ function api_remove_uploaded_file($type, $file)
         unlink($path);
     }
 }
-

+ 0 - 1
main/inc/lib/events.lib.php

@@ -498,7 +498,6 @@ class Event
             );
 
             // Check if attempt exists.
-
             $sql = "SELECT exe_id FROM $TBL_TRACK_ATTEMPT
                     WHERE
                         c_id = $course_id AND

+ 18 - 17
main/inc/lib/usermanager.lib.php

@@ -2613,7 +2613,7 @@ class UserManager
                 case SESSION_AVAILABLE:
                     break;
                 case SESSION_INVISIBLE:
-                    if ($ignore_visibility_for_admins == false) {
+                    if ($ignore_visibility_for_admins === false) {
                         continue 2;
                     }
             }
@@ -2635,6 +2635,7 @@ class UserManager
     /**
      * Gives a list of [session_id-course_code] => [status] for the current user.
      * @param integer $user_id
+     * @param int $sessionLimit
      * @return array  list of statuses (session_id-course_code => status)
      */
     public static function get_personal_session_course_list($user_id, $sessionLimit = null)
@@ -2775,7 +2776,7 @@ class UserManager
 
                 // This query is horribly slow when more than a few thousand
                 // users and just a few sessions to which they are subscribed
-                $personal_course_list_sql = "SELECT DISTINCT
+                $sql = "SELECT DISTINCT
                         course.code code,
                         course.title i,
                         ".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." t,
@@ -2799,8 +2800,7 @@ class UserManager
                             OR session.id_coach = $user_id
                         )
                     ORDER BY i";
-                $course_list_sql_result = Database::query($personal_course_list_sql);
-
+                $course_list_sql_result = Database::query($sql);
                 while ($result_row = Database::fetch_array($course_list_sql_result, 'ASSOC')) {
                     $result_row['course_info'] = api_get_course_info($result_row['code']);
                     $key = $result_row['session_id'].' - '.$result_row['code'];
@@ -2818,7 +2818,7 @@ class UserManager
 
             /* This query is very similar to the above query,
                but it will check the session_rel_course_user table if there are courses registered to our user or not */
-            $personal_course_list_sql = "SELECT DISTINCT
+            $sql = "SELECT DISTINCT
                 course.code code,
                 course.title i, CONCAT(user.lastname,' ',user.firstname) t,
                 email,
@@ -2839,8 +2839,7 @@ class UserManager
             WHERE session_course_user.user_id = $user_id
             ORDER BY i";
 
-            $course_list_sql_result = Database::query($personal_course_list_sql);
-
+            $course_list_sql_result = Database::query($sql);
             while ($result_row = Database::fetch_array($course_list_sql_result, 'ASSOC')) {
                 $result_row['course_info'] = api_get_course_info($result_row['code']);
                 $key = $result_row['session_id'].' - '.$result_row['code'];
@@ -2881,9 +2880,6 @@ class UserManager
             }
         }
 
-        $personal_course_list = array();
-        $courses = array();
-
         /* This query is very similar to the query below, but it will check the
         session_rel_course_user table if there are courses registered
         to our user or not */
@@ -2904,8 +2900,10 @@ class UserManager
                     $where_access_url
                 ORDER BY sc.position ASC";
 
-        $result = Database::query($sql);
+        $personal_course_list = array();
+        $courses = array();
 
+        $result = Database::query($sql);
         if (Database::num_rows($result) > 0) {
             while ($result_row = Database::fetch_array($result, 'ASSOC')) {
                 $result_row['status'] = 5;
@@ -2932,7 +2930,7 @@ class UserManager
                     WHERE
                       s.id = $session_id AND
                       (
-                        (scu.user_id=$user_id AND scu.status=2) OR
+                        (scu.user_id = $user_id AND scu.status=2) OR
                         s.id_coach = $user_id
                       )
                     $where_access_url
@@ -2963,8 +2961,8 @@ class UserManager
             }
         } else {
             //check if user is general coach for this session
-            $s = api_get_session_info($session_id);
-            if ($s['id_coach'] == $user_id) {
+            $sessionInfo = api_get_session_info($session_id);
+            if ($sessionInfo['id_coach'] == $user_id) {
                 $course_list = SessionManager::get_course_list_by_session_id($session_id);
 
                 if (!empty($course_list)) {
@@ -3036,15 +3034,18 @@ class UserManager
                     $return = "<h4>$course</h4>";
                     $return .= '<ul class="thumbnails">';
                 }
+                $extensionList = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif'];
                 foreach ($file_list as $file) {
                     if ($resourcetype == "all") {
                         $return .= '<li><a href="'.$web_path.urlencode($file).'" target="_blank">'.htmlentities($file).'</a></li>';
                     } elseif ($resourcetype == "images") {
                         //get extension
                         $ext = explode('.', $file);
-                        if ($ext[1] == 'jpg' || $ext[1] == 'jpeg' || $ext[1] == 'png' || $ext[1] == 'gif' || $ext[1] == 'bmp' || $ext[1] == 'tif') {
-                            $return .= '<li class="span2"><a class="thumbnail" href="'.$web_path.urlencode($file).'" target="_blank">
-                                            <img src="'.$web_path.urlencode($file).'" ></a>
+                        if (isset($ext[1]) && in_array($ext[1], $extensionList)) {
+                            $return .= '<li class="span2">
+                                            <a class="thumbnail" href="'.$web_path.urlencode($file).'" target="_blank">
+                                                <img src="'.$web_path.urlencode($file).'" >
+                                            </a>
                                         </li>';
                         }
                     }

+ 3 - 13
main/inc/lib/userportal.lib.php

@@ -1088,13 +1088,12 @@ class IndexManager
      */
     public function returnCoursesAndSessions($user_id)
     {
-        global $_configuration;
-
         $gamificationModeIsActive = api_get_setting('gamification_mode');
         $listCourse = '';
         $specialCourseList = '';
         $load_history = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
         $viewGridCourses = api_get_configuration_value('view_grid_courses');
+        $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
 
         $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
         $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
@@ -1102,12 +1101,10 @@ class IndexManager
         if ($load_history) {
             // Load sessions in category in *history*
             $session_categories = UserManager::get_sessions_by_category($user_id, true);
-
         } else {
             // Load sessions in category
             $session_categories = UserManager::get_sessions_by_category($user_id, false);
         }
-
         $html = '';
         // Showing history title
         if ($load_history) {
@@ -1286,12 +1283,8 @@ class IndexManager
                             $params['num_users'] = $session_box['num_users'];
                             $params['num_courses'] = $session_box['num_courses'];
                             $params['courses'] = $html_courses_session;
-                            //$params['extra_fields'] = $session_box['extra_fields'];
 
-                            if (
-                                isset($_configuration['show_simple_session_info']) &&
-                                $_configuration['show_simple_session_info']
-                            ) {
+                            if ($showSimpleSessionInfo) {
                                 $params['show_simple_session_info'] = true;
                             }
 
@@ -1381,10 +1374,7 @@ class IndexManager
                                 $sessionParams[0]['courses'] = $html_courses_session;
                                 $sessionParams[0]['show_simple_session_info'] = false;
 
-                                if (
-                                    isset($_configuration['show_simple_session_info']) &&
-                                    $_configuration['show_simple_session_info']
-                                ) {
+                                if ($showSimpleSessionInfo) {
                                     $sessionParams[0]['show_simple_session_info'] = true;
                                 }
 

+ 5 - 2
main/lp/learnpath.class.php

@@ -10699,8 +10699,11 @@ EOD;
                     continue;
                 }
 
-                $exerciseResult = $exerciseResultInfo['exe_result'] * 100 / $exerciseResultInfo['exe_weighting'];
-
+                if (!empty($exerciseResultInfo['exe_weighting'])) {
+                    $exerciseResult = $exerciseResultInfo['exe_result'] * 100 / $exerciseResultInfo['exe_weighting'];
+                } else {
+                    $exerciseResult = 0;
+                }
                 $totalResult += $exerciseResult;
             }
 

+ 12 - 2
main/lp/learnpathItem.class.php

@@ -4157,6 +4157,16 @@ class learnpathItem
                                         )
                                     ";
                         $iva_res = Database::query($iva_sql);
+
+                        $interaction[0] = isset($interaction[0]) ? $interaction[0] : '';
+                        $interaction[1] = isset($interaction[1]) ? $interaction[1] : '';
+                        $interaction[2] = isset($interaction[2]) ? $interaction[2] : '';
+                        $interaction[3] = isset($interaction[3]) ? $interaction[3] : '';
+                        $interaction[4] = isset($interaction[4]) ? $interaction[4] : '';
+                        $interaction[5] = isset($interaction[5]) ? $interaction[5] : '';
+                        $interaction[6] = isset($interaction[6]) ? $interaction[6] : '';
+                        $interaction[7] = isset($interaction[7]) ? $interaction[7] : '';
+
                         // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7)
                         if (Database::num_rows($iva_res) > 0) {
                             // Update (or don't).
@@ -4169,7 +4179,7 @@ class learnpathItem
                                 'weighting' => $interaction[3],
                                 'completion_time' => $interaction[2],
                                 'correct_responses' => $correct_resp,
-                                'student_response' => isset($interaction[5]) ? $interaction[5] : '',
+                                'student_response' => $interaction[5],
                                 'result' => $interaction[6],
                                 'latency' => $interaction[7]
                             );
@@ -4194,7 +4204,7 @@ class learnpathItem
                                 'weighting' => $interaction[3],
                                 'completion_time' => $interaction[2],
                                 'correct_responses' => $correct_resp,
-                                'student_response' => isset($interaction[5]) ? $interaction[5] : '',
+                                'student_response' => $interaction[5],
                                 'result' => $interaction[6],
                                 'latency' => $interaction[7]
                             );

+ 112 - 112
main/template/default/exercise/oral_expression.tpl

@@ -30,133 +30,133 @@
 </div>
 
 <script>
-    $(document).on('ready', function () {
-        function useRecordRTC() {
-            $('#record-audio-recordrtc').show();
-            var mediaConstraints = {audio: true},
-                    recordRTC = null,
-                    btnStart = $('#btn-start-record'),
-                    btnStop = $('#btn-stop-record'),
-                    btnSave = $('#btn-save-record'),
-                    tagAudio = $('#record-preview');
-
-            btnStart.on('click', function () {
-                navigator.getUserMedia = navigator.getUserMedia ||
-                        navigator.mozGetUserMedia ||
-                        navigator.webkitGetUserMedia;
-
-                if (navigator.getUserMedia) {
-                    navigator.getUserMedia(mediaConstraints, successCallback, errorCallback);
-                } else if (navigator.mediaDevices.getUserMedia) {
-                    navigator.mediaDevices.getUserMedia(mediaConstraints)
-                            .then(successCallback).error(errorCallback);
-                }
-
-                function successCallback(stream) {
-                    recordRTC = RecordRTC(stream, {
-                        numberOfAudioChannels: 1,
-                        type: 'audio'
-                    });
-                    recordRTC.startRecording();
-
-                    btnSave.prop('disabled', true);
-                    btnStop.prop('disabled', false);
-                    btnStart.prop('disabled', true);
-                    tagAudio.removeClass('show').addClass('hidden');
-                }
-
-                function errorCallback(error) {
-                    alert(error.message);
-                }
-            });
-
-            btnStop.on('click', function () {
-                if (!recordRTC) {
-                    return;
-                }
-
-                recordRTC.stopRecording(function (audioURL) {
-                    btnStart.prop('disabled', false);
-                    btnStop.prop('disabled', true);
-                    btnSave.prop('disabled', false);
+$(document).on('ready', function () {
+    function useRecordRTC() {
+        $('#record-audio-recordrtc').show();
+        var mediaConstraints = {audio: true},
+                recordRTC = null,
+                btnStart = $('#btn-start-record'),
+                btnStop = $('#btn-stop-record'),
+                btnSave = $('#btn-save-record'),
+                tagAudio = $('#record-preview');
+
+        btnStart.on('click', function () {
+            navigator.getUserMedia = navigator.getUserMedia ||
+                    navigator.mozGetUserMedia ||
+                    navigator.webkitGetUserMedia;
+
+            if (navigator.getUserMedia) {
+                navigator.getUserMedia(mediaConstraints, successCallback, errorCallback);
+            } else if (navigator.mediaDevices.getUserMedia) {
+                navigator.mediaDevices.getUserMedia(mediaConstraints)
+                        .then(successCallback).error(errorCallback);
+            }
 
-                    tagAudio
-                            .removeClass('hidden')
-                            .addClass('show')
-                            .prop('src', audioURL);
+            function successCallback(stream) {
+                recordRTC = RecordRTC(stream, {
+                    numberOfAudioChannels: 1,
+                    type: 'audio'
                 });
-            });
+                recordRTC.startRecording();
 
-            btnSave.on('click', function () {
-                if (!recordRTC) {
-                    return;
-                }
+                btnSave.prop('disabled', true);
+                btnStop.prop('disabled', false);
+                btnStart.prop('disabled', true);
+                tagAudio.removeClass('show').addClass('hidden');
+            }
 
-                var recordedBlob = recordRTC.getBlob();
+            function errorCallback(error) {
+                alert(error.message);
+            }
+        });
 
-                if (!recordedBlob) {
-                    return;
-                }
+        btnStop.on('click', function () {
+            if (!recordRTC) {
+                return;
+            }
 
-                var fileName = '{{ file_name }}',
-                        fileExtension = '.' + recordedBlob.type.split('/')[1];
-
-                var formData = new FormData();
-                formData.append('audio_blob', recordedBlob, fileName + fileExtension);
-                formData.append('audio_dir', '{{ directory }}');
-
-                $.ajax({
-                    url: '{{ _p.web_ajax }}record_audio_rtc.ajax.php',
-                    data: formData,
-                    processData: false,
-                    contentType: false,
-                    type: 'POST'
-                }).then(function () {
-                    btnSave.prop('disabled', true);
-                    btnStop.prop('disabled', true);
-                    btnStart.prop('disabled', false);
-                });
+            recordRTC.stopRecording(function (audioURL) {
+                btnStart.prop('disabled', false);
+                btnStop.prop('disabled', true);
+                btnSave.prop('disabled', false);
+
+                tagAudio
+                        .removeClass('hidden')
+                        .addClass('show')
+                        .prop('src', audioURL);
             });
-        }
+        });
 
-        function useWami() {
-            $('#record-audio-wami').show();
+        // Download button
+        btnSave.on('click', function () {
+            if (!recordRTC) {
+                return;
+            }
+
+            var recordedBlob = recordRTC.getBlob();
+            if (!recordedBlob) {
+                return;
+            }
 
-            Wami.setup({
-                id: "record-audio-wami-container",
-                onReady: setupGUI,
-                swfUrl: '{{ _p.web_lib }}wami-recorder/Wami.swf'
+            var fileName = '{{ file_name }}',
+                    fileExtension = '.' + recordedBlob.type.split('/')[1];
+
+            var formData = new FormData();
+            formData.append('audio_blob', recordedBlob, fileName + fileExtension);
+            formData.append('audio_dir', '{{ directory }}');
+
+            $.ajax({
+                url: '{{ _p.web_ajax }}record_audio_rtc.ajax.php',
+                data: formData,
+                processData: false,
+                contentType: false,
+                type: 'POST'
+            }).then(function () {
+                btnSave.prop('disabled', true);
+                btnStop.prop('disabled', true);
+                btnStart.prop('disabled', false);
             });
+        });
+    }
+
+    function useWami() {
+        $('#record-audio-wami').show();
+
+        Wami.setup({
+            id: "record-audio-wami-container",
+            onReady: setupGUI,
+            swfUrl: '{{ _p.web_lib }}wami-recorder/Wami.swf'
+        });
+
+        function setupGUI() {
+            var gui = new Wami.GUI({
+                    id: 'record-audio-wami-container',
+                    singleButton: true,
+                    recordUrl: '{{ _p.web_ajax }}record_audio_wami.ajax.php?' + $.param({
+                        waminame: '{{ file_name }}.wav',
+                        wamidir: '{{ directory }}',
+                        wamiuserid: {{ user_id }}
+                    }),
+                    buttonUrl: '{{ _p.web_lib }}wami-recorder/buttons.png',
+                    buttonNoUrl: '{{ _p.web_img }}blank.gif'
+                }
+            );
 
-            function setupGUI() {
-                var gui = new Wami.GUI({
-                        id: 'record-audio-wami-container',
-                        singleButton: true,
-                        recordUrl: '{{ _p.web_ajax }}record_audio_wami.ajax.php?' + $.param({
-                            waminame: '{{ file_name }}.wav',
-                            wamidir: '{{ directory }}',
-                            wamiuserid: {{ user_id }}
-                        }),
-                        buttonUrl: '{{ _p.web_lib }}wami-recorder/buttons.png',
-                        buttonNoUrl: '{{ _p.web_img }}blank.gif'
-                    }
-                );
-
-                gui.setPlayEnabled(false);
-            }
+            gui.setPlayEnabled(false);
         }
+    }
 
-        $('#record-audio-recordrtc, #record-audio-wami').hide();
+    $('#record-audio-recordrtc, #record-audio-wami').hide();
 
-        var webRTCIsEnabled = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia ||
-                navigator.mediaDevices.getUserMedia;
+    var webRTCIsEnabled = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia ||
+            navigator.mediaDevices.getUserMedia;
 
-        if (webRTCIsEnabled) {
-            useRecordRTC();
+    if (webRTCIsEnabled) {
+        useRecordRTC();
 
-            return;
-        }
+        return;
+    }
 
-        useWami();
-    });
+    useWami();
+});
 </script>

+ 26 - 0
main/template/default/social/whoisonline.tpl

@@ -18,4 +18,30 @@
             </div>
         </div>
     </div>
+    <script>
+        $(document).ready(function() {
+            $("#link_load_more_items").click(function() {
+                page = $("#link_load_more_items").attr("data_link");
+                $.ajax({
+                    beforeSend: function(objeto) {
+                        $("#display_response_id").html("'.addslashes(get_lang('Loading')).'");
+                    },
+                    type: "GET",
+                    url: "main/inc/ajax/online.ajax.php?a=load_online_user",
+                    data: "online_page_nr="+page,
+                    success: function(data) {
+                        $("#display_response_id").html("");
+                        if (data != "end") {
+                            $("#link_load_more_items").remove();
+                            var last = $("#online_grid_container li:last");
+                            last.after(data);
+                        } else {
+                            $("#link_load_more_items").remove();
+                        }
+                    }
+                });
+            });
+        });
+    </script>
 {% endblock %}
+

+ 76 - 72
main/user/subscribe_user.php

@@ -231,7 +231,7 @@ function get_number_of_users()
 
 	if (isset($_REQUEST['type']) && $_REQUEST['type'] === 'teacher') {
 		if (api_get_session_id() != 0) {
-			$sql = "SELECT COUNT(u.user_id)
+			$sql = "SELECT COUNT(u.id)
 					FROM $user_table u
 					LEFT JOIN $tbl_session_rel_course_user cu
 					ON
@@ -243,68 +243,68 @@ function get_number_of_users()
 						u.status = 1 AND
 						(u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
 
-			if (api_is_multiple_url_enabled()) {
-				$url_access_id = api_get_current_access_url_id();
-				if ($url_access_id !=-1) {
-					$tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-					$sql = "SELECT COUNT(u.user_id)
-							FROM $user_table u
-							LEFT JOIN $tbl_session_rel_course_user cu
-							ON
-							    u.user_id = cu.user_id and cu.c_id = '".api_get_course_int_id()."' AND
-							    session_id ='".$sessionId."'
-							INNER JOIN  $tbl_url_rel_user as url_rel_user
-							ON (url_rel_user.user_id = u.user_id)
-							WHERE
-								cu.user_id IS NULL AND
-								access_url_id= $url_access_id AND
-								u.status = 1 AND
-								(u.official_code <> 'ADMIN' OR u.official_code IS NULL)
-							";
-				}
-			}
-		} else {
-			$sql = "SELECT COUNT(u.user_id)
-					FROM $user_table u
-					LEFT JOIN $course_user_table cu
-					ON u.user_id = cu.user_id and c_id='".api_get_course_int_id()."'
-				    WHERE cu.user_id IS NULL AND u.status<>".DRH." ";
+            if (api_is_multiple_url_enabled()) {
+                $url_access_id = api_get_current_access_url_id();
+                if ($url_access_id !=-1) {
+                    $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
+                    $sql = "SELECT COUNT(u.id)
+                            FROM $user_table u
+                            LEFT JOIN $tbl_session_rel_course_user cu
+                            ON
+                                u.user_id = cu.user_id AND cu.c_id = '".api_get_course_int_id()."' AND
+                                session_id ='".$sessionId."'
+                            INNER JOIN  $tbl_url_rel_user as url_rel_user
+                            ON (url_rel_user.user_id = u.user_id)
+                            WHERE
+                                cu.user_id IS NULL AND
+                                access_url_id= $url_access_id AND
+                                u.status = 1 AND
+                                (u.official_code <> 'ADMIN' OR u.official_code IS NULL)
+                            ";
+                }
+            }
+        } else {
+            $sql = "SELECT COUNT(u.id)
+                    FROM $user_table u
+                    LEFT JOIN $course_user_table cu
+                    ON u.user_id = cu.user_id and c_id='".api_get_course_int_id()."'
+                    WHERE cu.user_id IS NULL AND u.status<>".DRH." ";
 
-			if (api_is_multiple_url_enabled()) {
-				$url_access_id = api_get_current_access_url_id();
-				if ($url_access_id !=-1) {
-					$tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
+            if (api_is_multiple_url_enabled()) {
+                $url_access_id = api_get_current_access_url_id();
+                if ($url_access_id !=-1) {
+                    $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
 
-					$sql = "SELECT COUNT(u.user_id)
-						FROM $user_table u
-						LEFT JOIN $course_user_table cu
-						ON u.user_id = cu.user_id AND c_id='".api_get_course_int_id()."'
-						INNER JOIN  $tbl_url_rel_user as url_rel_user
-						ON (url_rel_user.user_id = u.user_id)
-						WHERE cu.user_id IS NULL AND u.status<>".DRH." AND access_url_id= $url_access_id ";
-				}
-			}
-		}
-	} else {
-		// students
-		if ($sessionId != 0) {
-			$sql = "SELECT COUNT(u.user_id)
-					FROM $user_table u
-					LEFT JOIN $tbl_session_rel_course_user cu
-					ON
-						u.user_id = cu.user_id AND
-						c_id='".api_get_course_int_id()."' AND
-						session_id ='".$sessionId."'
-					WHERE
-						cu.user_id IS NULL AND
-						u.status<>".DRH." AND
-						(u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
+                    $sql = "SELECT COUNT(u.id)
+                        FROM $user_table u
+                        LEFT JOIN $course_user_table cu
+                        ON u.user_id = cu.user_id AND c_id='".api_get_course_int_id()."'
+                        INNER JOIN  $tbl_url_rel_user as url_rel_user
+                        ON (url_rel_user.user_id = u.user_id)
+                        WHERE cu.user_id IS NULL AND u.status<>".DRH." AND access_url_id= $url_access_id ";
+                }
+            }
+        }
+    } else {
+        // students
+        if ($sessionId != 0) {
+            $sql = "SELECT COUNT(u.id)
+                    FROM $user_table u
+                    LEFT JOIN $tbl_session_rel_course_user cu
+                    ON
+                        u.user_id = cu.user_id AND
+                        c_id='".api_get_course_int_id()."' AND
+                        session_id ='".$sessionId."'
+                    WHERE
+                        cu.user_id IS NULL AND
+                        u.status<>".DRH." AND
+                        (u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
 
             if (api_is_multiple_url_enabled()) {
                 $url_access_id = api_get_current_access_url_id();
                 if ($url_access_id !=-1) {
                     $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-                    $sql = "SELECT COUNT(u.user_id)
+                    $sql = "SELECT COUNT(u.id)
                             FROM $user_table u
                             LEFT JOIN $tbl_session_rel_course_user cu
                             ON
@@ -312,7 +312,7 @@ function get_number_of_users()
                                 c_id='".api_get_course_int_id()."' AND
                                 session_id ='".$sessionId."'
                             INNER JOIN $tbl_url_rel_user as url_rel_user
-                            ON (url_rel_user.user_id = u.user_id)
+                            ON (url_rel_user.user_id = u.id)
                             WHERE
                                 cu.user_id IS NULL AND
                                 u.status<>".DRH." AND
@@ -321,7 +321,7 @@ function get_number_of_users()
                 }
             }
         } else {
-            $sql = "SELECT COUNT(u.user_id)
+            $sql = "SELECT COUNT(u.id)
                     FROM $user_table u
                     LEFT JOIN $course_user_table cu
                     ON u.user_id = cu.user_id AND c_id='".api_get_course_int_id()."'";
@@ -350,16 +350,17 @@ function get_number_of_users()
 
                 if ($url_access_id !=-1) {
                     $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-                    $sql = "SELECT COUNT(u.user_id)
+                    $sql = "SELECT COUNT(u.id)
                             FROM $user_table u
-                            LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and c_id='".api_get_course_int_id()."'
+                            LEFT JOIN $course_user_table cu 
+                            ON u.user_id = cu.user_id AND c_id='".api_get_course_int_id()."'
                             INNER JOIN $tbl_url_rel_user as url_rel_user
-                            ON (url_rel_user.user_id = u.user_id)
+                            ON (url_rel_user.user_id = u.id)
                             WHERE cu.user_id IS NULL AND access_url_id= $url_access_id AND u.status <> ".DRH." ";
                 }
             }
-		}
-	}
+        }
+    }
 
     // when there is a keyword then we are searching and we have to change the SQL statement
     if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
@@ -425,7 +426,7 @@ function get_user_data($from, $number_of_items, $column, $direction)
 	$is_western_name_order = api_is_western_name_order();
 
     if (api_get_setting('show_email_addresses') === 'true') {
-        $select_fields = "u.user_id              AS col0,
+        $select_fields = "u.id              AS col0,
                 u.official_code        AS col1,
                 ".($is_western_name_order
                 ? "u.firstname         AS col2,
@@ -474,12 +475,11 @@ function get_user_data($from, $number_of_items, $column, $direction)
 						(u.official_code <> 'ADMIN' OR u.official_code IS NULL) AND
 						field_values.field_id = '".intval($field_identification[0])."' AND
 						field_values.value = '".Database::escape_string($field_identification[1])."'";
-			} else {
-				$sql .=	"WHERE cu.user_id IS NULL AND u.status=1 AND (u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
-			}
-
-            $sql .=	" AND access_url_id= $url_access_id";
+            } else {
+                $sql .=	"WHERE cu.user_id IS NULL AND u.status=1 AND (u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
+            }
 
+            $sql .=	" AND access_url_id = $url_access_id";
 		} else {
 		     // adding a teacher NOT through a session
 			$sql = "SELECT $select_fields
@@ -664,7 +664,9 @@ function get_user_data($from, $number_of_items, $column, $direction)
 
 	// Sorting and pagination (used by the sortable table)
 	$sql .= " ORDER BY col$column $direction ";
-	$sql .= " LIMIT $from,$number_of_items";
+    $from = (int) $from;
+    $number_of_items = (int) $number_of_items;
+	$sql .= " LIMIT $from, $number_of_items";
 
 	$res = Database::query($sql);
 	$users = array ();
@@ -695,6 +697,8 @@ function reg_filter($user_id)
     } else {
         $type = STUDENT;
     }
+    $user_id = (int) $user_id;
+
 	$result = '<a class="btn btn-small btn-primary" href="'.api_get_self().'?register=yes&type='.$type.'&user_id='.$user_id.'">'.
         get_lang("reg").'</a>';
 
@@ -710,7 +714,6 @@ function reg_filter($user_id)
  * @param string $url_params
  * @return string Some HTML-code with the lock/unlock button
  */
-
 function active_filter($active, $url_params, $row)
 {
 	$_user = api_get_user_info();
@@ -723,7 +726,7 @@ function active_filter($active, $url_params, $row)
         $action = 'AccountInactive';
         $image = 'error';
 	}
-    $result = null;
+    $result = '';
     if ($row['0'] <> $_user['user_id']) {
 	// you cannot lock yourself out otherwise you could disable all the accounts
 	// including your own => everybody is locked out and nobody can change it anymore.
@@ -754,6 +757,7 @@ function search_additional_profile_fields($keyword)
     $tableExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
 	$table_user = Database::get_main_table(TABLE_MAIN_USER);
 
+    $keyword = Database::escape_string($keyword);
 	// getting the field option text that match this keyword (for radio buttons and checkboxes)
 	$sql = "SELECT * FROM $table_user_field_options
 	        WHERE display_text LIKE '%".$keyword."%'";

+ 0 - 6
tests/main/inc/lib/main_api.lib.test.php

@@ -454,12 +454,6 @@ class TestMainApi extends UnitTestCase {
 		//var_dump($res);
 	}
 
-	function testString2Boolean(){
-		global $string;
-		$res=api_string_2_boolean($string);
-		$this->assertFalse($res);
-	}
-
 	function testApiNumberOfPlugins(){
 		global $_plugins;
 		$location=2;