Browse Source

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

aragonc 9 years ago
parent
commit
86d6839d47
66 changed files with 831 additions and 2092 deletions
  1. 35 0
      CONTRIBUTING.md
  2. 132 0
      documentation/installation_guide_es_ES.html
  3. 2 2
      main/admin/user_edit.php
  4. 2 2
      main/admin/user_information.php
  5. 3 3
      main/auth/profile.php
  6. 24 27
      main/chat/chat_functions.lib.php
  7. 2 1
      main/chat/chat_hidden.php
  8. 22 23
      main/chat/chat_whoisonline.php
  9. 2 2
      main/course_description/add.php
  10. 39 16
      main/course_description/course_description_controller.php
  11. 13 0
      main/course_description/edit.php
  12. 10 12
      main/course_description/listing.php
  13. 8 8
      main/course_info/delete_course.php
  14. 20 1
      main/cron/document/index_all_docs.php
  15. 1 1
      main/document/create_document.php
  16. 4 1
      main/document/document.php
  17. 0 62
      main/exercice/GC.php
  18. 37 29
      main/exercice/answer.class.php
  19. 16 162
      main/exercice/exercise.class.php
  20. 7 8
      main/exercice/exercise_show.php
  21. 29 10
      main/exercice/hotpotatoes.php
  22. 8 2
      main/exercice/hotspot_save.inc.php
  23. 18 20
      main/exercice/multiple_answer_true_false.class.php
  24. 59 59
      main/exercice/question_admin.inc.php
  25. 4 4
      main/exercice/unique_answer.class.php
  26. 0 6
      main/forum/index.php
  27. 0 7
      main/forum/viewforumcategory.php
  28. 0 1264
      main/inc/lib/SequenceManager.php
  29. 4 3
      main/inc/lib/SequenceResourceManager.php
  30. 1 1
      main/inc/lib/access_url_edit_users_to_url_functions.lib.php
  31. 10 11
      main/inc/lib/course_description.lib.php
  32. 2 1
      main/inc/lib/events.lib.php
  33. 3 3
      main/inc/lib/exercise.lib.php
  34. 4 2
      main/inc/lib/fileManage.lib.php
  35. 2 2
      main/inc/lib/hook/README.md
  36. 1 1
      main/inc/lib/jpegcam/webcam_receiver.php
  37. 20 27
      main/inc/lib/search/search_widget.php
  38. 1 0
      main/inc/lib/skill.lib.php
  39. 3 8
      main/inc/lib/skill.visualizer.lib.php
  40. 28 19
      main/inc/lib/svg-edit/extensions/imagelib/groups.php
  41. 1 1
      main/inc/lib/template.lib.php
  42. 2 2
      main/install/install.lib.php
  43. 5 5
      main/newscorm/learnpath.class.php
  44. 3 2
      main/permissions/group_permissions.inc.php
  45. 0 3
      main/social/group_view.php
  46. 1 1
      main/social/groups.php
  47. 12 23
      main/social/my_skills_report.php
  48. 1 2
      main/social/myfiles.php
  49. 24 12
      main/social/profile.php
  50. 10 1
      main/social/skills_ranking.php
  51. 4 4
      main/social/skills_tree.php
  52. 2 2
      main/template/default/course_description/edit.tpl
  53. 20 33
      main/upload/upload.document.php
  54. 1 5
      main/upload/upload.php
  55. 1 3
      main/upload/upload.scorm.php
  56. 1 4
      main/upload/upload_ppt.php
  57. 1 5
      main/upload/upload_word.php
  58. 64 65
      main/user/add_users_to_session.php
  59. 0 2
      main/user/class.php
  60. 16 16
      main/user/classes.php
  61. 32 38
      main/user/resume_session.php
  62. 1 8
      main/user/session_list.php
  63. 16 17
      main/user/subscribe_class.php
  64. 23 13
      main/user/subscribe_user.php
  65. 1 2
      main/user/user_import.php
  66. 13 13
      main/wiki/wiki.inc.php

+ 35 - 0
CONTRIBUTING.md

@@ -60,6 +60,41 @@ modify or create an entity, but you will still need to follow these two steps:
 1. Modify the main/install/data.sql file (at the end, add a new section before the chamilo_database_version update
 2. Create a new Migration in src/Chamilo/CoreBundle/Migrations/Schema/V110/ (see above section for details)
 
+# Testing through Docker
+
+We are working on an official (production) image of Chamilo LMS for Docker.
+In the meantime, you can test development versions following more or less this procedure:
+```
+host$ composer run -it ubuntu:14.04.2
+root@docker$ apt-get update
+root@docker$ apt-get install -y git vim libapache2-mod-php5 php5-mysql php5-gd php5-intl php5-curl curl mysql-server mysql-client
+```
+Pick a password for the MySQL server and enter it twice, when prompted.
+```
+root@docker$ cd /var/www
+root@docker$ rm -rf html
+root@docker$ git clone --single-branch -b 1.10.0-beta https://github.com/chamilo/chamilo-lms.git html
+root@docker$ chmod -R 0777 app/ vendor/ main/lang/ main/default_course_document/images/ web/
+root@docker$ vim /etc/php5/apache2/php.ini
+```
+Look for timezone and modify it to the best timezone that suits you:
+```
+[Date]
+; Defines the default timezone used by the date functions
+; http://php.net/date.timezone
+;date.timezone =
+date.timezone = Europe/Brussels
+```
+Save and exit.
+```
+root@docker$ service apache2 reload
+root@docker$ service mysql start
+root@docker$ ifconfig | grep inet
+```
+Now you should be able to load Chamilo in your host machine's browser by loading the IP address showing on the first
+line of this command's results (and proceed with the installation on the MySQL server you configured above).
+
+
 
 
 [1]: https://support.chamilo.org/projects/chamilo-18/wiki/Coding_conventions

+ 132 - 0
documentation/installation_guide_es_ES.html

@@ -73,6 +73,7 @@
   <li><a href="#11._rapid">Chamilo Rapid - sistema conversion PPT</a></li>
   <li><a href="#12._cron">Configuración de tareas programadas</a></li>
   <li><a href="#13._name_order">Cambiando el orden del nombre/apellido en el idioma</a></li>
+  <li><a href="#14._alter_conf">Configuraciones opcionales para Apache y Nginx</a></li>
 </ol>
 
 
@@ -780,6 +781,137 @@ Siéntase libre de cambiar esto a
 </pre>
 por ejemplo. El efecto debería ser inmediato.
 </p>
+
+<hr style="width: 100%; height: 2px;" />
+<h2><a name="14._alter_conf"></a>14. Configuraciones opcionales para Apache y Nginx</h2>
+<p><p>
+    Dadas las nuevas actualizaciones de servidores web y la fragilidad en cuanto a seguridad de archivos facilmente
+    localizables por atacantes como los htaccess, se aconseja restringir las configuraciones a un solo archivo.
+    A continuación se presentan dos ejemplos de configuración de modo que no se dependa de los archivos .htaccess.
+</p>
+<p>
+    Nginx: La configuración para nuestro sitio de ejemplo my.chamilo10.net (en el cual los archivos se han almacenado
+    en /var/www/my.chamilo10.net/www) sería la siguiente, tomando como supuesto el uso de php5-fpm a través de sockets:
+<pre>
+server {
+  listen 80;
+  server_name my.chamilo10.net;
+  rewrite_log off;
+  access_log /var/log/nginx/my.chamilo10.net-access.log;
+  error_log /var/log/nginx/my.chamilo10.net-error.log debug;
+  root /var/www/my.chamilo10.net/www;
+  index index.php;
+  port_in_redirect off;
+
+  location / {
+    #client_max_body_size 20M;
+    #try_files $uri /index.php$is_args$args;
+    #rewrite ^/courses/([^/]+)/$ /main/course_home/course_home.php?cDir=$1 last;
+    #rewrite ^/courses/([^/]+)/index.php$ main/course_home/course_home.php?cDir=$1 last;
+  }
+  location ~ ^/(app_dev|config)\.php(/|$) {
+    fastcgi_pass unix:/var/run/php5-fpm.sock;
+    fastcgi_split_path_info ^(.+\.php)(/.*)$;
+    include fastcgi_params;
+    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+    fastcgi_param HTTPS off;
+  }
+  location ~ ^/app\.php(/|$) {
+    fastcgi_pass unix:/var/run/php5-fpm.sock;
+    fastcgi_split_path_info ^(.+\.php)(/.*)$;
+    include fastcgi_params;
+    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+    fastcgi_param HTTPS off;
+    # Prevents URIs that include the front controller. This will 404:
+    # http://domain.tld/app.php/some-path
+    # Remove the internal directive to allow URIs like this
+    #internal;
+  }
+
+  location ~ \.php$ {
+    client_max_body_size 20M;
+    try_files $uri /index.php$is_args$args;
+
+    rewrite ^/certificates/$ /certificates/index.php?id=%1  last;
+    rewrite ^/courses/([^/]+)/$ /main/course_home/course_home.php?cDir=$1 last;
+    rewrite ^/courses/([^/]+)/index.php$ /main/course_home/course_home.php?cDir=$1 last;
+    rewrite ^/courses/([^/]+)/scorm/(.*)$ /main/document/download_scorm.php?doc_url=/$2&cDir=$1 last;
+    rewrite ^/courses/([^/]+)/document/(.*)$ /main/document/download.php?doc_url=/$2&cDir=$1 last;
+    rewrite ^/courses/([^/]+)/work/(.*)$ /main/work/download.php?file=work/$2&cDir=$1 last;
+    rewrite ^/courses/([^/]+)/upload/(.*)$ /app/courses/$1/upload/$2 last;
+    rewrite ^/courses/([^/]+)/course-pic85x85.png$ /app/courses/$1/course-pic85x85.png last;
+    rewrite ^/courses/([^/]+)/course-pic.png$ /app/courses/$1/course-pic.png last;
+    rewrite ^/session/([^/]+)/about/?$ /main/session/about.php?session_id=$1 last;
+
+    fastcgi_pass unix:/var/run/php5-fpm.sock;
+    fastcgi_split_path_info ^(.+\.php)(/.*)$;
+    include fastcgi_params;
+    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+    fastcgi_param HTTPS off;
+  }
+  location ~ ~\.(ht|git){
+    deny all;
+  }
+  location ^~ /tests/ {
+    deny all;
+  }
+}
+</pre>
+
+Apache2: La configuración para nuestro sitio de ejemplo my.chamilo10.net sería la siguiente:
+
+<pre>
+&lt;VirtualHost *:80&gt;
+  ServerAdmin root@localhost
+  DocumentRoot /var/www/my.chamilo10.net/www
+  ServerName my.chamilo10.net
+  ErrorLog  /var/log/apache2/my.chamilo10.net-error.log
+  CustomLog /var/log/apache2/my.chamilo10.net-access.log combined
+
+  ErrorDocument 401 /public/error-401.html
+  DirectoryIndex index.php index.html
+  Options Indexes FollowSymLinks
+
+  &lt;LocationMatch "/.git*"&gt;
+	order deny,allow
+	deny from all
+  &lt;/LocationMatch&gt;
+
+  &lt;Directory ~/.&gt;
+    AllowOverride None
+	Options -Indexes
+  &lt;/Directory&gt;
+
+  &lt;Directory "/var/www/my.chamilo10.net/www"&gt;
+	RewriteEngine On
+	RewriteCond %{QUERY_STRING} ^id=(.*)$
+	RewriteRule ^([^/.]+)/?$ user.php?$1 [L]
+	RewriteRule ^certificates/$ certificates/index.php?id=%1 [L]
+	RewriteRule ^courses/([^/]+)/$ app/course_home/course_home.php?cDir=$1 [QSA,L]
+	RewriteRule ^courses/([^/]+)/index.php$ main/course_home/course_home.php?cDir=$1 [QSA,L]
+	RewriteRule ^courses/([^/]+)/document/(.*)$ main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L]
+	RewriteRule ^courses/([^/]+)/work/(.*)$ main/work/download.php?file=work/$2&cDir=$1 [QSA,L]
+	RewriteRule ^courses/([^/]+)/upload/(.*)$ main/courses/$1/upload/$2 [QSA,L]
+	RewriteRule ^courses/([^/]+)/course-pic85x85.png$ main/courses/$1/course-pic85x85.png [QSA,L]
+	RewriteRule ^courses/([^/]+)/course-pic.png$ app/courses/$1/course-pic.png [QSA,L]
+	RewriteRule ^session/(\d{1,})/about/?$ main/session/about.php?session_id=$1 [L]
+  &lt;/Directory&gt;
+
+  php_value display_errors Off
+  php_value log_errors On
+  php_value display_startup_errors Off
+  php_value post_max_size 300M
+  php_value upload_max_filesize 300M
+  # E_ALL:  php_admin_value error_reporting 6143
+  # E_ALL & ^E_NOTICE:
+  php_admin_value error_reporting 6135
+  #php_admin_value session.save_path /var/www/my.chamilo10.net/sessions/
+  php_admin_value short_open_tag Off
+  php_value session.cookie_httponly 1
+
+&lt;/VirtualHost&gt;
+</pre></p>
+
 <hr style="width: 100%; height: 2px;" />
 <p>
   <br />

+ 2 - 2
main/admin/user_edit.php

@@ -417,8 +417,8 @@ if ($error_drh) {
 
 $content = null;
 
-$bigImage = Usermanager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_BIG);
-$normalImage = Usermanager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
+$bigImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_BIG);
+$normalImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
 $content .= '<a class="expand-image" href="'.$bigImage.'" /><img src="'.$normalImage.'"></a>';
 
 // Display form

+ 2 - 2
main/admin/user_information.php

@@ -410,12 +410,12 @@ echo '<div class="actions">
 echo Display::page_header($tool_name);
 
 
-$fullUrlBig = Usermanager::getUserPicture(
+$fullUrlBig = UserManager::getUserPicture(
     $user['user_id'],
     USER_IMAGE_SIZE_BIG
 );
 
-$fullUrl = Usermanager::getUserPicture(
+$fullUrl = UserManager::getUserPicture(
     $user['user_id'],
     USER_IMAGE_SIZE_ORIGINAL
 );

+ 3 - 3
main/auth/profile.php

@@ -431,7 +431,7 @@ if ($form->validate()) {
     $wrong_current_password = false;
     $user_data = $form->getSubmitValues(1);
 
-    $user = Usermanager::getRepository()->find(api_get_user_id());
+    $user = UserManager::getRepository()->find(api_get_user_id());
 
     // set password if a new one was provided
     $validPassword = false;
@@ -752,8 +752,8 @@ if (api_get_setting('allow_social_tool') == 'true') {
     $social_layout = $tpl->get_template('social/edit_profile.tpl');
     $tpl->display($social_layout);
 } else {
-    $bigImage = Usermanager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_BIG);
-    $normalImage = Usermanager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
+    $bigImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_BIG);
+    $normalImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
 
     $imageToShow = '<div id="image-message-container">';
     $imageToShow .= '<a class="expand-image" href="'.$bigImage.'" /><img src="'.$normalImage.'"></a>';

+ 24 - 27
main/chat/chat_functions.lib.php

@@ -50,11 +50,11 @@ function exit_of_chat($user_id)
 
     foreach ($list_course as $course) {
         $response = user_connected_in_chat($user_id);
-        //if ($response === true) {
-            $sql = 'DELETE FROM '.$tbl_chat_connected.'
-                    WHERE c_id = '.$course['real_id'].' AND user_id = '.$user_id;
-            Database::query($sql);
-        //}
+
+        $sql = 'DELETE FROM '.$tbl_chat_connected.'
+                WHERE c_id = '.$course['real_id'].' AND user_id = '.$user_id;
+        Database::query($sql);
+
     }
 }
 
@@ -73,27 +73,27 @@ function disconnect_user_of_chat()
     $cdate_s = date('s', $now);
 	$cd_count_time_seconds = $cdate_h*3600 + $cdate_m*60 + $cdate_s;
 
-	if (is_array($list_info_user_in_chat) && count($list_info_user_in_chat) > 0) {
-		foreach ($list_info_user_in_chat as $list_info_user) {
-			$date_db_date = date('Y-m-d', api_strtotime($list_info_user['last_connection'], 'UTC'));
-			$date_db_h  = date('H', api_strtotime($list_info_user['last_connection'], 'UTC'));
-			$date_db_m  = date('i', api_strtotime($list_info_user['last_connection'], 'UTC'));
-			$date_db_s  = date('s', api_strtotime($list_info_user['last_connection'], 'UTC'));
+    if (is_array($list_info_user_in_chat) && count($list_info_user_in_chat) > 0) {
+        foreach ($list_info_user_in_chat as $list_info_user) {
+            $date_db_date = date('Y-m-d', api_strtotime($list_info_user['last_connection'], 'UTC'));
+            $date_db_h  = date('H', api_strtotime($list_info_user['last_connection'], 'UTC'));
+            $date_db_m  = date('i', api_strtotime($list_info_user['last_connection'], 'UTC'));
+            $date_db_s  = date('s', api_strtotime($list_info_user['last_connection'], 'UTC'));
             $date_count_time_seconds = $date_db_h * 3600 + $date_db_m * 60 + $date_db_s;
-			if ($cd_date == $date_db_date) {
-				if (($cd_count_time_seconds - $date_count_time_seconds) > 5) {
+            if ($cd_date == $date_db_date) {
+                if (($cd_count_time_seconds - $date_count_time_seconds) > 5) {
                     $tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED);
-			 		$sql = 'DELETE FROM '.$tbl_chat_connected.'
-			 		        WHERE
-			 		            c_id = '.$course_id.' AND
-			 		            user_id = '.$list_info_user['user_id'].' AND
-			 		            to_group_id = '.$groupId.'
+                    $sql = 'DELETE FROM '.$tbl_chat_connected.'
+                            WHERE
+                                c_id = '.$course_id.' AND
+                                user_id = '.$list_info_user['user_id'].' AND
+                                to_group_id = '.$groupId.'
                             ';
-			 		Database::query($sql);
-				}
-			}
-		}
-	}
+                    Database::query($sql);
+                }
+            }
+        }
+    }
 }
 
 /**
@@ -224,11 +224,8 @@ function saveMessage($message, $userId, $_course, $session_id, $group_id, $previ
             }
 
             $fp = fopen($chat_path.$basename_chat.'.log.html', 'a');
-
-            $userPhoto = Usermanager::getUserPicture($userId, USER_IMAGE_SIZE_MEDIUM);
-
+            $userPhoto = UserManager::getUserPicture($userId, USER_IMAGE_SIZE_MEDIUM);
             $filePhoto = '<img class="chat-image" src="'.$userPhoto.'"/>';
-
             if ($isMaster) {
                 fputs($fp, '<div class="message-teacher"><div class="content-message"><div class="chat-message-block-name">'.$fullName.'</div><div class="chat-message-block-content">'.$message.'</div><div class="message-date">'.$timeNow.'</div></div><div class="icon-message"></div>'.$filePhoto.'</div>'."\n");
             } else {

+ 2 - 1
main/chat/chat_hidden.php

@@ -87,7 +87,8 @@ if (Database::num_rows($result) == 0) {
         Database::query($sql);
     }
 } else {
-	$query = "UPDATE $tbl_chat_connected SET last_connection='".$current_time."'
+	$query = "UPDATE $tbl_chat_connected SET
+	          last_connection='".$current_time."'
 	          WHERE c_id = $course_id AND user_id='".$userId."' AND session_id='$session_id' AND to_group_id='$group_id'";
     Database::query($query);
 }

+ 22 - 23
main/chat/chat_whoisonline.php

@@ -16,14 +16,11 @@ $courseInfo = api_get_course_info();
 $group_id = api_get_group_id();
 $session_id = api_get_session_id();
 $user_id = api_get_user_id();
-$session_condition = api_get_session_condition($session_id);
 $group_condition = " AND to_group_id = '$group_id'";
 
 $extra_condition = '';
 if (!empty($group_id)) {
     $extra_condition = $group_condition;
-} else {
-    $extra_condition = $session_condition;
 }
 
 if (!empty($course)) {
@@ -42,7 +39,6 @@ if (!empty($course)) {
 
 	$isAllowed = !(empty($pseudo_user) || !$_cid);
 	$isMaster = api_is_course_admin();
-
     $date_inter = api_get_utc_datetime(time() - 120);
 
     $users = array();
@@ -70,6 +66,7 @@ if (!empty($course)) {
         $result = Database::query($sql);
         $users = Database::store_result($result);
 	} else {
+        $session_condition = api_get_session_condition($session_id, true, false, 't3.session_id');
 		// select learners
 		$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email
                   FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_session_course_user t3
@@ -77,8 +74,8 @@ if (!empty($course)) {
 		          t2.c_id = $course_id AND
 		          t1.user_id=t2.user_id AND t3.user_id=t2.user_id AND
 		          t3.session_id = '".$session_id."' AND
-		          t3.c_id = '".$_course['real_id']."' AND
-		          t2.last_connection>'".$date_inter."' $extra_condition
+		          t3.c_id = '".$courseInfo['real_id']."' AND
+		          t2.last_connection>'".$date_inter."' $session_condition
 		          ORDER BY username";
 		$result = Database::query($query);
 		while ($learner = Database::fetch_array($result)) {
@@ -129,33 +126,35 @@ if (!empty($course)) {
 		<div class="viewport"><div id="hidden" class="overview">
 		<ul class="profile list-group">
 			<?php
-				foreach ($users as & $user) {
-					if (empty($session_id)) {
-						$status = $user['status'];
-					} else {
-						$status = CourseManager::is_course_teacher($user['user_id'], $_SESSION['_course']['id']) ? 1 : 5;
-					}
-					$fileUrl = Usermanager::getUserPicture($user['user_id'], USER_IMAGE_SIZE_MEDIUM);
-				    $url_user_profile=api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user['user_id'].'&';
+            foreach ($users as & $user) {
+                if (empty($session_id)) {
+                    $status = $user['status'];
+                } else {
+                    $status = CourseManager::is_course_teacher($user['user_id'], api_get_course_id()) ? 1 : 5;
+                }
+                $fileUrl = UserManager::getUserPicture($user['user_id'], USER_IMAGE_SIZE_MEDIUM);
+                $url_user_profile=api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user['user_id'].'&';
 			?>
 			<li class="list-group-item">
 				<img src="<?php echo $fileUrl;?>" border="0" width="50" alt="" class="user-image-chat" />
 				<div class="user-name">
-					<a href="<?php echo $url_user_profile; ?>" target="_blank"><?php echo api_get_person_name($user['firstname'], $user['lastname']); ?></a>
+					<a href="<?php echo $url_user_profile; ?>" target="_blank">
+                        <?php echo api_get_person_name($user['firstname'], $user['lastname']); ?>
+                    </a>
 					<?php
-						if ($status == 1) {
-							echo Display::return_icon('teachers.gif', get_lang('Teacher'), array('height' => '18'));
-						}else{
-							echo Display::return_icon('students.gif', get_lang('Student'), array('height' => '18'));
-						}
+                        if ($status == 1) {
+                            echo Display::return_icon('teachers.gif', get_lang('Teacher'), array('height' => '18'));
+                        } else {
+                            echo Display::return_icon('students.gif', get_lang('Student'), array('height' => '18'));
+                        }
 					?>
 				</div>
 				<div class="user-email"><?php echo $user['username']; ?></div>
 			</li>
 			<?php
-                }
-                unset($users);
-            ?>
+            }
+            unset($users);
+        ?>
 		</ul>
 	</div></div></div></div>
 	<?php

+ 2 - 2
main/course_description/add.php

@@ -58,8 +58,8 @@ $form = new FormValidator(
     'index.php?action=add&'.api_get_cidreq()
 );
 $form->addElement('header', '', $header);
-$form->addElement('hidden', 'description_type',$description_type);
-$form->addElement('hidden', 'sec_token',$token);
+$form->addElement('hidden', 'description_type', $description_type);
+$form->addElement('hidden', 'sec_token', $token);
 $form->addText('title', get_lang('Title'), true, array('size'=>'width: 350px;'));
 $form->applyFilter('title','html_filter');
 $form->addHtmlEditor(

+ 39 - 16
main/course_description/course_description_controller.php

@@ -65,7 +65,8 @@ class CourseDescriptionController
     /**
      * It's used for editing a course description,
      * render to listing or edit view
-     * @param int description type
+     * @param int $id description item id
+     * @param int $description_type description type id
      */
     public function edit($id, $description_type)
     {
@@ -84,6 +85,16 @@ class CourseDescriptionController
                     $content = $_POST['contentDescription'];
                     $description_type = $_POST['description_type'];
                     $id = $_POST['id'];
+                    if (empty($id)) {
+                        // If the ID was not provided, find the first matching description item given the item type
+                        $description = $course_description->get_data_by_description_type(
+                            $description_type
+                        );
+                        if (count($description) > 0) {
+                            $id = $description['id'];
+                        }
+                        // If no corresponding description is found, edit a new one
+                    }
                     $progress = isset($_POST['progress']) ? $_POST['progress'] : '';
                     $course_description->set_description_type($description_type);
                     $course_description->set_title($title);
@@ -98,12 +109,14 @@ class CourseDescriptionController
                         $affected_rows = $course_description->insert();
                     }
                     Security::clear_token();
-                }
 
-                if ($affected_rows) {
-                    $message['edit'] = true;
+                    Display::addFlash(
+                        Display::return_message(
+                            get_lang('CourseDescriptionUpdated')
+                        )
+                    );
                 }
-                $this->listing(false, $message);
+                $this->listing(false);
             } else {
                 $data['error'] = 1;
                 $data['default_description_titles'] = $course_description->get_default_description_title();
@@ -131,7 +144,14 @@ class CourseDescriptionController
             $data['information'] = $course_description->get_default_information();
 
             $data['description_type'] = $description_type;
-
+            if (empty($id)) {
+                // If the ID was not provided, find the first matching description item given the item type
+                $description = $course_description->get_data_by_description_type($description_type);
+                if (count($description) > 0) {
+                    $id = $description['id'];
+                }
+                // If no corresponding description is found, edit a new one
+            }
             if (!empty($id)) {
                 if (isset($_GET['id_session'])) {
                     $session_id = intval($_GET['id_session']);
@@ -186,11 +206,14 @@ class CourseDescriptionController
                         $affected_rows = $course_description->insert(api_get_course_int_id());
                     }
                     Security::clear_token();
+
+                    Display::addFlash(
+                        Display::return_message(
+                            get_lang('CourseDescriptionUpdated')
+                        )
+                    );
                 }
-                if ($affected_rows) {
-                    $message['add'] = true;
-                }
-                $this->listing(false, $message);
+                $this->listing(false);
             } else {
                 $data['error'] = 1;
                 $data['default_description_titles'] = $course_description->get_default_description_title();
@@ -224,7 +247,7 @@ class CourseDescriptionController
     /**
      * It's used for destroy a course description,
      * render to listing view
-     * @param int description type
+     * @param int $id description type
      */
     public function destroy($id)
     {
@@ -233,11 +256,11 @@ class CourseDescriptionController
         $course_description->set_session_id($session_id);
         if (!empty($id)) {
             $course_description->set_id($id);
-            $affected_rows = $course_description->delete();
-        }
-        if ($affected_rows) {
-            $message['destroy'] = true;
+            $course_description->delete();
+            Display::addFlash(
+                Display::return_message(get_lang('CourseDescriptionDeleted'))
+            );
         }
-        $this->listing(false, $message);
+        $this->listing(false);
     }
 }

+ 13 - 0
main/course_description/edit.php

@@ -9,6 +9,19 @@
 
 // protect a course script
 api_protect_course_script(true);
+if (empty($id)) {
+	$id = intval($_REQUEST['id']);
+	if (empty($id)) {
+		// If the ID was not provided, find the first matching description item given the item type
+		$course_description = new CourseDescription();
+		$description = $course_description->get_data_by_description_type($description_type);
+		if (count($description) > 0) {
+			$id = $description['id'];
+		}
+		unset ($course_description);
+		// If no corresponding description is found, edit a new one
+	}
+}
 $original_id = $id;
 
 if (empty($error)) {

+ 10 - 12
main/course_description/listing.php

@@ -10,15 +10,6 @@
 // protect a course script
 api_protect_course_script(true);
 
-// display messages
-if ((isset($messages['edit']) && $messages['edit']) ||
-    (isset($messages['add']) && $messages['add'])
-) {
-	Display :: display_confirmation_message(get_lang('CourseDescriptionUpdated'));
-} else if (isset($messages['destroy']) && $messages['destroy']) {
-	Display :: display_confirmation_message(get_lang('CourseDescriptionDeleted'));
-}
-
 // display actions menu
 if (api_is_allowed_to_edit(null,true)) {
     $categories = array();
@@ -32,10 +23,12 @@ if (api_is_allowed_to_edit(null,true)) {
 	ksort($categories);
 	foreach ($categories as $id => $title) {
 		if ($i==ADD_BLOCK) {
-			echo '<a href="index.php?'.api_get_cidreq().'&action=add">'.Display::return_icon($default_description_icon[$id], $title,'',ICON_SIZE_MEDIUM).'</a>';
+			echo '<a href="index.php?'.api_get_cidreq().'&action=add">'.
+                Display::return_icon($default_description_icon[$id], $title,'',ICON_SIZE_MEDIUM).'</a>';
 			break;
 		} else {
-			echo '<a href="index.php?action=edit&'.api_get_cidreq().'&description_type='.$id.'">'.Display::return_icon($default_description_icon[$id], $title,'',ICON_SIZE_MEDIUM).'</a>';
+			echo '<a href="index.php?action=edit&'.api_get_cidreq().'&description_type='.$id.'">'.
+                Display::return_icon($default_description_icon[$id], $title,'',ICON_SIZE_MEDIUM).'</a>';
 			$i++;
 		}
 	}
@@ -45,7 +38,12 @@ $history = isset($history) ? $history : null;
 
 // display course description list
 if ($history) {
-	echo '<div><table width="100%"><tr><td><h3>'.get_lang('ThematicAdvanceHistory').'</h3></td><td align="right"><a href="index.php?action=listing">'.Display::return_icon('info.png',get_lang('BackToCourseDesriptionList'),array('style'=>'vertical-align:middle;'),ICON_SIZE_SMALL).' '.get_lang('BackToCourseDesriptionList').'</a></td></tr></table></div>';
+	echo '<div>
+        <table width="100%">
+            <tr>
+                <td><h3>'.get_lang('ThematicAdvanceHistory').'</h3></td>
+                <td align="right"><a href="index.php?action=listing">'.
+                Display::return_icon('info.png',get_lang('BackToCourseDesriptionList'), array('style'=>'vertical-align:middle;'),ICON_SIZE_SMALL).' '.get_lang('BackToCourseDesriptionList').'</a></td></tr></table></div>';
 }
 
 $user_info = api_get_user_info();

+ 8 - 8
main/course_info/delete_course.php

@@ -26,18 +26,18 @@ if (!api_is_allowed_to_edit()) {
 
 $tool_name = get_lang('DelCourse');
 
-if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
-	CourseManager::delete_course($_course['sysCode']);
-	$obj_cat = new Category();
-	$obj_cat->update_category_delete($_course['sysCode']);
+    if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
+    CourseManager::delete_course($_course['sysCode']);
+    $obj_cat = new Category();
+    $obj_cat->update_category_delete($_course['sysCode']);
 
-	// DELETE CONFIRMATION MESSAGE
+    // DELETE CONFIRMATION MESSAGE
     Session::erase('_cid');
     Session::erase('_real_cid');
-	$noPHP_SELF = true;
-	$message = '<h2>'.get_lang('Course').' : '.$current_course_name.' ('.$current_course_code.') </h2>';
+    $noPHP_SELF = true;
+    $message = '<h2>'.get_lang('Course').' : '.$current_course_name.' ('.$current_course_code.') </h2>';
     $message .=get_lang('HasDel');
-	$message .= '<br /><br /><a href="../../index.php">'.get_lang('BackHome').' '.api_get_setting('siteName').'</a>';
+    $message .= '<br /><br /><a href="../../index.php">'.get_lang('BackHome').' '.api_get_setting('siteName').'</a>';
 
 } else {
     $message = '<h3>'.get_lang('Course').' : '.$current_course_name.' ('.$current_course_code.') </h3>';

+ 20 - 1
main/cron/document/index_all_docs.php

@@ -13,7 +13,26 @@ if (empty($_GET['doc'])) {
   echo "Received param ".$_GET['doc']."<br />\n";
 }
 $allowed_mime_types = DocumentManager::file_get_mime_type(true);
-$allowed_extensions = array('doc', 'docx', 'ppt', 'pptx', 'pps', 'ppsx', 'xls', 'xlsx', 'odt', 'odp', 'ods', 'pdf', 'txt', 'rtf', 'msg', 'csv', 'html', 'htm');
+$allowed_extensions = array(
+    'doc',
+    'docx',
+    'ppt',
+    'pptx',
+    'pps',
+    'ppsx',
+    'xls',
+    'xlsx',
+    'odt',
+    'odp',
+    'ods',
+    'pdf',
+    'txt',
+    'rtf',
+    'msg',
+    'csv',
+    'html',
+    'htm',
+);
 $courses_list =  CourseManager::get_courses_list();
 
 // Simulating empty specific fields (this is necessary for indexing)

+ 1 - 1
main/document/create_document.php

@@ -274,7 +274,7 @@ if ($is_certificate_mode) {
 }
 
 // Show read-only box only in groups
-if (!empty($_SESSION['_gid'])) {
+if (!empty($groupId)) {
 	$group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
 }
 $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');

+ 4 - 1
main/document/document.php

@@ -879,7 +879,10 @@ if (!empty($documentAndFolders)) {
     foreach ($documentAndFolders as $file) {
         if ($file['filetype'] == 'file') {
             $path_info = pathinfo($file['path']);
-            $extension = strtolower($path_info['extension']);
+            $extension = '';
+            if (!empty($path_info['extension'])) {
+                $extension = strtolower($path_info['extension']);
+            }
 
             //@todo use a js loop to auto generate this code
             if (in_array($extension, array('ogg', 'mp3', 'wav'))) {

+ 0 - 62
main/exercice/GC.php

@@ -1,62 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- *	Code library for HotPotatoes integration.
- *	@package chamilo.exercise
- * 	@author Istvan Mandak
- * 	@version $Id: GC.php 20451 2009-05-10 12:02:22Z ivantcholakov $
- */
-/**
- * Code
- */
-// usage:  HotPotGC($_configuration['root_sys'],$flag);
-// working recursively, flag[0,1] print or delete the HotPotatoes temp files (.t.html)
-
-echo "Garbage Collector<BR>";
-HotPotGC($_configuration['root_sys'],1,1);
-/**
- * Garbage collector caller function
- */
-function HotPotGC($root_sys,$flag,$userID) {
-	// flag[0,1] - print or delete the HotPotatoes temp files (.t.html)
-	$documentPath = $root_sys."courses";
-	HotPotGCt($documentPath,$flag,$userID);
-}
-/**
- * Garbage collector
- */
-function HotPotGCt($folder,$flag,$userID) { // Garbage Collector
-	$filelist = array();
-	    if ($dir = @opendir($folder)) {
-        while (($file = readdir($dir)) !== false) {
-            if ( $file != ".") {
-            	if ($file != "..")
-      		{
-            	 $full_name = $folder."/".$file;
-        	  if (is_dir($full_name))
-							{
-								HotPotGCt($folder."/".$file,$flag);
-							}
-						else
-						 {
-                $filelist[] = $file;
-                 }
-               }
-            }
-        }
-      	closedir($dir);
-    	}
-	while (list ($key, $val) = each ($filelist))
-	{
-		 if (stristr($val,$userID.".t.html"))
-		 { if ($flag == 1)
-		 		{
-						my_delete($folder."/".$val);
-				}
-			 else
-			  {
-			  	echo $folder."/".$val."<br />";
-			  }
-		 }
-	}
-}

+ 37 - 29
main/exercice/answer.class.php

@@ -115,22 +115,22 @@ class Answer
         $result = Database::query($sql);
         $i=1;
 
-		// while a record is found
-		while ($object = Database::fetch_object($result)) {
-			$this->id[$i] = $object->id;
-			$this->answer[$i] = $object->answer;
-			$this->correct[$i] = $object->correct;
-			$this->comment[$i] = $object->comment;
-			$this->weighting[$i] = $object->ponderation;
-			$this->position[$i] = $object->position;
-			$this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
-			$this->hotspot_type[$i] = $object->hotspot_type;
-			$this->destination[$i] = $object->destination;
-			$this->autoId[$i] = $object->id_auto;
-			$i++;
-		}
-		$this->nbrAnswers = $i-1;
-	}
+        // while a record is found
+        while ($object = Database::fetch_object($result)) {
+            $this->id[$i] = $object->id;
+            $this->answer[$i] = $object->answer;
+            $this->correct[$i] = $object->correct;
+            $this->comment[$i] = $object->comment;
+            $this->weighting[$i] = $object->ponderation;
+            $this->position[$i] = $object->position;
+            $this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
+            $this->hotspot_type[$i] = $object->hotspot_type;
+            $this->destination[$i] = $object->destination;
+            $this->autoId[$i] = $object->id_auto;
+            $i++;
+        }
+        $this->nbrAnswers = $i-1;
+    }
 
      /**
      * returns all answer ids from this question Id
@@ -178,9 +178,10 @@ class Answer
 
 		$TBL_ANSWER   = Database::get_course_table(TABLE_QUIZ_ANSWER);
 		$TBL_QUIZ     = Database::get_course_table(TABLE_QUIZ_QUESTION);
-		$questionId=intval($this->questionId);
+		$questionId = intval($this->questionId);
 
-		$sql = "SELECT type FROM $TBL_QUIZ WHERE c_id = {$this->course_id} AND id = $questionId";
+		$sql = "SELECT type FROM $TBL_QUIZ
+		        WHERE c_id = {$this->course_id} AND id = $questionId";
 		$result_question = Database::query($sql);
 		$question_type = Database::fetch_array($result_question);
 
@@ -532,6 +533,7 @@ class Answer
             'hotspot_coordinates' => $hotspot_coordinates,
             'hotspot_type' => $hotspot_type,
         ];
+
         Database::update($answerTable, $params, ['id_auto = ?' => $autoId]);
 	}
 
@@ -582,6 +584,7 @@ class Answer
                 // https://support.chamilo.org/issues/6558
                 // function updateAnswers already escape_string, error if we do it twice.
                 // Feed function updateAnswers with none escaped strings
+
                 $this->updateAnswers(
                     $autoId,
                     $this->new_answer[$i],
@@ -596,26 +599,31 @@ class Answer
             }
 
             $answerList[$i] = $autoId;
+
             if ($correct) {
-                $correctList[$autoId] = array('id' => $i, 'correct' => $correct);
+                $correctList[$autoId] = true;
             }
         }
 
-        if (!empty($correctList)) {
-            foreach ($correctList as $autoId => $data) {
-                $correct = $data['correct'];
+        $questionType = self::getQuestionType();
 
-                if (isset($answerList[$correct])) {
-                    $correct = $answerList[$correct];
-                }
+        if ($questionType == MATCHING) {
 
-                $sql = "UPDATE $answerTable
-                        SET correct = $correct
+            if (!empty($correctList)) {
+                foreach ($correctList as $autoId => $status) {
+                    /*$correct = $data['correct'];
+
+                    if (isset($answerList[$correct])) {
+                        $correct = $answerList[$correct];
+                    }*/
+
+                    $sql = "UPDATE $answerTable
+                        SET correct = $autoId
                         WHERE
                             id_auto = $autoId
                         ";
-                Database::query($sql);
-
+                    Database::query($sql);
+                }
             }
         }
 

+ 16 - 162
main/exercice/exercise.class.php

@@ -2283,9 +2283,9 @@ class Exercise
         $user_answer = '';
 
         // Get answer list for matching
-        $sql_answer = 'SELECT id_auto, id, answer FROM '.$table_ans.'
-                       WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'"';
-        $res_answer = Database::query($sql_answer);
+        $sql = "SELECT id_auto, id, answer FROM $table_ans
+                WHERE c_id = $course_id AND question_id = $questionId";
+        $res_answer = Database::query($sql);
 
         $answerMatching = array();
         while ($real_answer = Database::fetch_array($res_answer)) {
@@ -2440,15 +2440,17 @@ class Exercise
                     break;
                 case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
                     if ($from_database) {
-                        $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
-                                     WHERE exe_id = ".$exeId." AND question_id= ".$questionId;
-                        $resultans = Database::query($queryans);
+                        $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
+                                WHERE exe_id = $exeId AND question_id= ".$questionId;
+                        $resultans = Database::query($sql);
                         while ($row = Database::fetch_array($resultans)) {
                             $ind = $row['answer'];
                             $result = explode(':',$ind);
-                            $my_answer_id = $result[0];
-                            $option       = $result[1];
-                            $choice[$my_answer_id] = $option;
+                            if (isset($result[0])) {
+                                $my_answer_id = $result[0];
+                                $option = $result[1];
+                                $choice[$my_answer_id] = $option;
+                            }
                         }
                         $studentChoice = $choice[$answerAutoId];
 
@@ -2472,16 +2474,17 @@ class Exercise
                     break;
                 case MULTIPLE_ANSWER_COMBINATION:
                     if ($from_database) {
-                        $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
-                                     WHERE exe_id = '".$exeId."' and question_id= '".$questionId."'";
-                        $resultans = Database::query($queryans);
+                        $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
+                                WHERE exe_id = $exeId AND question_id= $questionId";
+                        $resultans = Database::query($sql);
                         while ($row = Database::fetch_array($resultans)) {
                             $ind = $row['answer'];
                             $choice[$ind] = 1;
                         }
+
                         $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
 
-                        if ($answerCorrect == 1) {
+                        if ($answerCorrect == $answerAutoId) {
                             if ($studentChoice) {
                                 $real_answers[$answerId] = true;
                             } else {
@@ -2591,155 +2594,6 @@ class Exercise
                     }
 
                     $answer = FillBlanks::getAnswerInStudentAttempt($listCorrectAnswers);
-
-                    // the question is encoded like this
-                    // [A] B [C] D [E] F::10,10,10@1
-                    // number 1 before the "@" means that is a switchable fill in blank question
-                    // [A] B [C] D [E] F::10,10,10@ or  [A] B [C] D [E] F::10,10,10
-                    // means that is a normal fill blank question
-                    // first we explode the "::"
-                    /*
-                    $pre_array = explode('::', $answer);
-                    // is switchable fill blank or not
-                    $last = count($pre_array) - 1;
-                    $is_set_switchable = explode('@', $pre_array[$last]);
-                    $switchable_answer_set = false;
-                    if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
-                        $switchable_answer_set = true;
-                    }
-                    $answer = '';
-                    for ($k = 0; $k < $last; $k++) {
-                        $answer .= $pre_array[$k];
-                    }
-
-                    // splits weightings that are joined with a comma
-                    $answerWeighting = explode(',', $is_set_switchable[0]);
-
-                    // we save the answer because it will be modified
-                    $temp = $answer;
-
-                    $answer = '';
-                    $j = 0;
-                    //initialise answer tags
-                    $user_tags = $correct_tags = $real_text = array();
-
-                    // the loop will stop at the end of the text
-                    while (1) {
-                        // quits the loop if there are no more blanks (detect '[')
-                        if (($pos = api_strpos($temp, '[')) === false) {
-                            // adds the end of the text
-                            $answer = $temp;
-                            $real_text[] = $answer;
-                            break; //no more "blanks", quit the loop
-                        }
-
-                        // adds the piece of text that is before the blank
-                        // and ends with '[' into a general storage array
-                        $real_text[] = api_substr($temp, 0, $pos +1);
-                        $answer .= api_substr($temp, 0, $pos +1);
-
-                        //take the string remaining (after the last "[" we found)
-                        $temp = api_substr($temp, $pos +1);
-
-                        // quit the loop if there are no more blanks, and update $pos to the position of next ']'
-                        if (($pos = api_strpos($temp, ']')) === false) {
-                            // adds the end of the text
-                            $answer .= $temp;
-                            break;
-                        }
-                        if ($from_database) {
-                            $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
-                                          WHERE
-                                            exe_id = '".$exeId."' AND
-                                            question_id= ".intval($questionId)."";
-                            $resfill = Database::query($queryfill);
-                            $str = Database::result($resfill, 0, 'answer');
-
-
-                            api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
-                            $str = str_replace('\r\n', '', $str);
-
-                            $choice = $arr[1];
-
-
-                            if (isset($choice[$j])) {
-                                $tmp = api_strrpos($choice[$j], ' / ');
-                                $choice[$j] = api_substr($choice[$j], 0, $tmp);
-                                $choice[$j] = trim($choice[$j]);
-
-                                // Needed to let characters ' and " to work as part of an answer
-                                $choice[$j] = stripslashes($choice[$j]);
-                            } else {
-                                $choice[$j] = null;
-                            }
-
-                        } else {
-							// This value is the user input, not escaped while correct answer is escaped by fckeditor
-							// Works with cyrillic alphabet and when using ">" chars
-                            $choice[$j] = htmlentities(api_utf8_encode(trim($choice[$j])));
-                        }
-
-                        $user_tags[] = $choice[$j];
-
-                        //put the contents of the [] answer tag into correct_tags[]
-                        $correct_tags[] = api_substr($temp, 0, $pos);
-                        $j++;
-                        $temp = api_substr($temp, $pos +1);
-                    }
-
-                    $answer = '';
-                    $real_correct_tags = $correct_tags;
-                    $chosen_list = array();
-
-                    for ($i = 0; $i < count($real_correct_tags); $i++) {
-                        if ($i == 0) {
-                            $answer .= $real_text[0];
-                        }
-                        if (!$switchable_answer_set) {
-                            // Needed to parse ' and " characters
-                            $user_tags[$i] = stripslashes($user_tags[$i]);
-                            if ($correct_tags[$i] == $user_tags[$i]) {
-                                // gives the related weighting to the student
-                                $questionScore += $answerWeighting[$i];
-                                // increments total score
-                                $totalScore += $answerWeighting[$i];
-                                // adds the word in green at the end of the string
-                                $answer .= $correct_tags[$i];
-                            } elseif (!empty($user_tags[$i])) {
-                                // else if the word entered by the student IS NOT the same as the one defined by the professor
-                                // adds the word in red at the end of the string, and strikes it
-                                $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
-                            } else {
-                                // adds a tabulation if no word has been typed by the student
-                                $answer .= ''; // remove &nbsp; that causes issue
-                            }
-                        } else {
-                            // switchable fill in the blanks
-                            if (in_array($user_tags[$i], $correct_tags)) {
-                                $chosen_list[] = $user_tags[$i];
-                                $correct_tags = array_diff($correct_tags, $chosen_list);
-
-                                // gives the related weighting to the student
-                                $questionScore += $answerWeighting[$i];
-                                // increments total score
-                                $totalScore += $answerWeighting[$i];
-                                // adds the word in green at the end of the string
-                                $answer .= $user_tags[$i];
-                            } elseif (!empty ($user_tags[$i])) {
-                                // else if the word entered by the student IS NOT the same as the one defined by the professor
-                                // adds the word in red at the end of the string, and strikes it
-                                $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
-                            } else {
-                                // adds a tabulation if no word has been typed by the student
-                                $answer .= '';  // remove &nbsp; that causes issue
-                            }
-                        }
-                        // adds the correct word, followed by ] to close the blank
-                        $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
-                        if (isset($real_text[$i +1])) {
-                            $answer .= $real_text[$i + 1];
-                        }
-                    }*/
                     break;
                 // for calculated answer
                 case CALCULATED_ANSWER:

+ 7 - 8
main/exercice/exercise_show.php

@@ -12,8 +12,6 @@
  *
  */
 
-// name of the language file that needs to be included
-
 use ChamiloSession as Session;
 
 require_once '../inc/global.inc.php';
@@ -166,8 +164,8 @@ function getFCK(vals,marksid) {
 }
 </script>
 <?php
-$show_results           = true;
-$show_only_total_score  = false;
+$show_results = true;
+$show_only_total_score = false;
 
 // Avoiding the "Score 0/0" message  when the exe_id is not set
 if (!empty($track_exercise_info)) {
@@ -232,10 +230,10 @@ $arrans  = array();
 
 $user_restriction = $is_allowedToEdit ? '' :  "AND user_id=".intval($student_id)." ";
 $sql = "SELECT attempts.question_id, answer
-        FROM ".$TBL_TRACK_ATTEMPT." as attempts
+        FROM $TBL_TRACK_ATTEMPT as attempts
         INNER JOIN ".$TBL_TRACK_EXERCISES." AS stats_exercises
         ON stats_exercises.exe_id=attempts.exe_id
-        INNER JOIN ".$TBL_EXERCISE_QUESTION." AS quizz_rel_questions
+        INNER JOIN $TBL_EXERCISE_QUESTION AS quizz_rel_questions
         ON
             quizz_rel_questions.exercice_id=stats_exercises.exe_exo_id AND
             quizz_rel_questions.question_id = attempts.question_id AND
@@ -244,7 +242,8 @@ $sql = "SELECT attempts.question_id, answer
         ON
             questions.id=quizz_rel_questions.question_id AND
             questions.c_id = ".api_get_course_int_id()."
-        WHERE attempts.exe_id = ".intval($id)." $user_restriction
+        WHERE
+            attempts.exe_id = ".intval($id)." $user_restriction
 		GROUP BY quizz_rel_questions.question_order, attempts.question_id";
 
 $result = Database::query($sql);
@@ -284,7 +283,7 @@ if (!empty($end_of_message) && ($origin == 'learnpath')) {
 $total_weighting = 0;
 foreach ($questionList as $questionId) {
     $objQuestionTmp = Question::read($questionId);
-    $total_weighting  +=$objQuestionTmp->selectWeighting();
+    $total_weighting +=$objQuestionTmp->selectWeighting();
 }
 
 $counter = 1;

+ 29 - 10
main/exercice/hotpotatoes.php

@@ -42,9 +42,9 @@ $course_id = api_get_course_int_id();
 // Setting some variables.
 $document_sys_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 $uploadPath = '/HotPotatoes_files';
-$finish         = (!empty($_POST['finish']) ? $_POST['finish'] : 0);
-$imgcount       = (!empty($_POST['imgcount']) ? $_POST['imgcount'] : null);
-$fld            = (!empty($_POST['fld']) ? $_POST['fld'] : null);
+$finish = (!empty($_POST['finish']) ? $_POST['finish'] : 0);
+$imgcount = (!empty($_POST['imgcount']) ? $_POST['imgcount'] : null);
+$fld = (!empty($_POST['fld']) ? $_POST['fld'] : null);
 $imgparams = [];
 $dialogBox = '';
 
@@ -56,9 +56,21 @@ if ($finish == 2 && isset($_POST['imgparams'])) {
 if (api_is_allowed_to_edit(null, true)) {
     if (hotpotatoes_init($document_sys_path.$uploadPath)) {
         // If the directory doesn't exist, create the "HotPotatoes" directory.
-        $doc_id = add_document($_course, '/HotPotatoes_files', 'folder', 0, get_lang('HotPotatoesFiles'));
+        $doc_id = add_document(
+            $_course,
+            '/HotPotatoes_files',
+            'folder',
+            0,
+            get_lang('HotPotatoesFiles')
+        );
         // Update properties in dbase (in any case).
-        api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
+        api_item_property_update(
+            $_course,
+            TOOL_DOCUMENT,
+            $doc_id,
+            'FolderCreated',
+            api_get_user_id()
+        );
         // Make invisible (in any case) - why?
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id());
     }
@@ -67,7 +79,13 @@ if (api_is_allowed_to_edit(null, true)) {
 /** Display */
 $nameTools = get_lang('HotPotatoesTests');
 
-$form = new FormValidator('hotpotatoes', 'post', api_get_self()."?".api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
+$form = new FormValidator(
+    'hotpotatoes',
+    'post',
+    api_get_self()."?".api_get_cidreq(),
+    null,
+    array('enctype' => 'multipart/form-data')
+);
 $form->addElement('header', $nameTools);
 $form->addElement('hidden', 'uploadPath');
 $form->addElement('hidden', 'fld', $fld);
@@ -119,7 +137,6 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
                 $filename = $_FILES['userFile']['name'];
             }
 
-            /*if (treat_uploaded_file($_FILES['userFile'], $document_sys_path, $uploadPath."/".$fld, $max_filled_space, $unzip))*/
             $allow_output_on_success = false;
             if (handle_uploaded_document(
                 $_course,
@@ -163,8 +180,9 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
                 }
 
                 $title = @htmlspecialchars(GetQuizName($filename, $document_sys_path.$uploadPath.'/'.$fld.'/'), ENT_COMPAT, api_get_system_encoding());
-                $query = "UPDATE $dbTable SET comment='".Database::escape_string($title)."'
-                         WHERE c_id = $course_id AND path=\"".$uploadPath."/".$fld."/".$filename."\"";
+                $query = "UPDATE $dbTable
+                          SET comment='".Database::escape_string($title)."'
+                          WHERE c_id = $course_id AND path=\"".$uploadPath."/".$fld."/".$filename."\"";
                 Database::query($query);
                 api_item_property_update($_course, TOOL_QUIZ, $id, 'QuizAdded', api_get_user_id());
 
@@ -196,7 +214,8 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
         '</a>';
     echo '</div>';
 
-    if ($finish == 2) { // If we are in the img upload process.
+    if ($finish == 2) {
+        // If we are in the img upload process.
         $dialogBox .= get_lang('ImgNote_st').$imgcount.get_lang('ImgNote_en').'<br />';
         while (list($key, $string) = each($imgparams)) {
             $dialogBox .= $string.'; ';

+ 8 - 2
main/exercice/hotspot_save.inc.php

@@ -35,7 +35,13 @@ if ($_GET['type'] == "poly" || $_GET['type'] == "delineation" || $_GET['type'] =
 	$hotspot_coordinates = api_substr($hotspot_coordinates,0,-2);
 }
 $course_id = api_get_course_int_id();
-$sql = "UPDATE $TBL_ANSWER SET hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',hotspot_type = '".Database::escape_string($hotspot_type)."'
-        WHERE c_id = $course_id AND id = ".intval($answerId)." AND question_id = ".intval($questionId)." LIMIT 1 ;";
+$sql = "UPDATE $TBL_ANSWER SET
+            hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',
+            hotspot_type = '".Database::escape_string($hotspot_type)."'
+        WHERE
+            c_id = $course_id AND
+            id = ".intval($answerId)." AND
+            question_id = ".intval($questionId)."
+        LIMIT 1 ";
 $result = Database::query($sql);
 echo "done=done";

+ 18 - 20
main/exercice/multiple_answer_true_false.class.php

@@ -82,7 +82,7 @@ class MultipleAnswerTrueFalse extends Question
         }
 
         // Can be more options
-        $option_data = Question::readQuestionOption($this->id, $course_id);
+        $optionData = Question::readQuestionOption($this->id, $course_id);
 
         for ($i = 1; $i <= $nb_answers; ++$i) {
             $form->addHtml('<tr>');
@@ -120,8 +120,8 @@ class MultipleAnswerTrueFalse extends Question
                 $defaults['correct[' . $i . ']'] = $correct;
 
                 $j = 1;
-                if (!empty($option_data)) {
-                    foreach ($option_data as $id => $data) {
+                if (!empty($optionData)) {
+                    foreach ($optionData as $id => $data) {
                         $form->addElement('radio', 'correct[' . $i . ']', null, null, $id);
                         $j++;
                         if ($j == 3) {
@@ -212,7 +212,6 @@ class MultipleAnswerTrueFalse extends Question
         if (!empty($this->extra)) {
             $scores = explode(':', $this->extra);
 
-
             if (!empty($scores)) {
                 for ($i = 1; $i <= 3; $i++) {
                     $defaults['option[' . $i . ']'] = $scores[$i - 1];
@@ -231,8 +230,6 @@ class MultipleAnswerTrueFalse extends Question
             $form->addGroup($buttonGroup);
         }
 
-        $defaults['correct'] = $correct;
-
         if (!empty($this->id)) {
             $form->setDefaults($defaults);
         } else {
@@ -250,19 +247,19 @@ class MultipleAnswerTrueFalse extends Question
     public function processAnswersCreation($form)
     {
 		$questionWeighting = $nbrGoodAnswers = 0;
-		$objAnswer        = new Answer($this->id);
-		$nb_answers       = $form->getSubmitValue('nb_answers');
-        $options_count    = $form->getSubmitValue('options_count');
-        $course_id        = api_get_course_int_id();
+		$objAnswer = new Answer($this->id);
+        $nb_answers = $form->getSubmitValue('nb_answers');
+        //$options_count    = $form->getSubmitValue('options_count');
+        $course_id = api_get_course_int_id();
 
         $correct = array();
         $options = Question::readQuestionOption($this->id, $course_id);
 
         if (!empty($options)) {
-            foreach ($options as $option_data) {
-                $id = $option_data['id'];
-                unset($option_data['id']);
-                Question::updateQuestionOption($id, $option_data, $course_id);
+            foreach ($options as $optionData) {
+                $id = $optionData['id'];
+                unset($optionData['id']);
+                Question::updateQuestionOption($id, $optionData, $course_id);
             }
         } else {
             for ($i=1 ; $i <= 3 ; $i++) {
@@ -282,7 +279,7 @@ class MultipleAnswerTrueFalse extends Question
         $new_options = Question::readQuestionOption($this->id, $course_id);
 
         $sorted_by_position = array();
-        foreach($new_options as $item) {
+        foreach ($new_options as $item) {
         	$sorted_by_position[$item['position']] = $item;
         }
 
@@ -294,18 +291,19 @@ class MultipleAnswerTrueFalse extends Question
             $score = trim($form -> getSubmitValue('option['.$i.']'));
             $extra_values[]= $score;
         }
-        $this->setExtra(implode(':',$extra_values));
+        $this->setExtra(implode(':', $extra_values));
 
-		for ($i=1 ; $i <= $nb_answers ; $i++) {
-        	$answer     = trim($form -> getSubmitValue('answer['.$i.']'));
-            $comment    = trim($form -> getSubmitValue('comment['.$i.']'));
-            $goodAnswer = trim($form -> getSubmitValue('correct['.$i.']'));
+		for ($i = 1; $i <= $nb_answers; $i++) {
+            $answer = trim($form->getSubmitValue('answer['.$i.']'));
+            $comment = trim($form->getSubmitValue('comment['.$i.']'));
+            $goodAnswer = trim($form->getSubmitValue('correct['.$i.']'));
             if (empty($options)) {
                 //If this is the first time that the question is created when
                 // change the default values from the form 1 and 2 by the correct "option id" registered
                 $goodAnswer = $sorted_by_position[$goodAnswer]['id'];
             }
     	    $questionWeighting += $extra_values[0]; //By default 0 has the correct answers
+
         	$objAnswer->createAnswer($answer, $goodAnswer, $comment,'',$i);
         }
 

+ 59 - 59
main/exercice/question_admin.inc.php

@@ -11,77 +11,77 @@
  */
 
 if (isset($_GET['editQuestion'])) {
-	$objQuestion = Question::read ($_GET['editQuestion']);
-	$action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
+    $objQuestion = Question::read ($_GET['editQuestion']);
+    $action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
 } else {
-	$objQuestion = Question :: getInstance($_REQUEST['answerType']);
-	$action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
+    $objQuestion = Question :: getInstance($_REQUEST['answerType']);
+    $action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
 }
 
 if (is_object($objQuestion)) {
-	// FORM CREATION
-	$form = new FormValidator('question_admin_form','post', $action);
-	if (isset($_GET['editQuestion'])) {
-		$class = "btn btn-default";
-		$text = get_lang('ModifyQuestion');
-		$type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null;
-	} else {
-		$class = "btn btn-default";
-		$text = get_lang('AddQuestionToExercise');
-		$type = $_REQUEST['answerType'];
-	}
+    // FORM CREATION
+    $form = new FormValidator('question_admin_form','post', $action);
+    if (isset($_GET['editQuestion'])) {
+        $class = "btn btn-default";
+        $text = get_lang('ModifyQuestion');
+        $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null;
+    } else {
+        $class = "btn btn-default";
+        $text = get_lang('AddQuestionToExercise');
+        $type = $_REQUEST['answerType'];
+    }
 
-	$typesInformation = Question::get_question_type_list();
-	$form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null;
+    $typesInformation = Question::get_question_type_list();
+    $form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null;
 
-	// form title
-	$form->addElement('header', $text.': '.$form_title_extra);
+    // form title
+    $form->addElement('header', $text.': '.$form_title_extra);
 
-	// question form elements
-	$objQuestion->createForm($form);
+    // question form elements
+    $objQuestion->createForm($form);
 
-	// answer form elements
-	$objQuestion->createAnswersForm($form);
+    // answer form elements
+    $objQuestion->createAnswersForm($form);
 
-	// this variable  $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
-	if ($objExercise->edit_exercise_in_lp == false) {
-		$form->freeze();
-	}
+    // this variable  $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
+    if ($objExercise->edit_exercise_in_lp == false) {
+        $form->freeze();
+    }
 
-	// FORM VALIDATION
-	if (isset($_POST['submitQuestion']) && $form->validate()) {
+    // FORM VALIDATION
+    if (isset($_POST['submitQuestion']) && $form->validate()) {
 
-		// question
-		$objQuestion->processCreation($form, $objExercise);
+        // question
+        $objQuestion->processCreation($form, $objExercise);
 
-		// answers
-		$nb_answers = isset($nb_answers) ? $nb_answers : 0;
-		$objQuestion->processAnswersCreation($form, $nb_answers);
+        // answers
+        $nb_answers = isset($nb_answers) ? $nb_answers : 0;
+        $objQuestion->processAnswersCreation($form, $nb_answers);
 
-		// TODO: maybe here is the better place to index this tool, including answers text
+        // TODO: maybe here is the better place to index this tool, including answers text
 
-		// redirect
-		if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
-			if(isset($_GET['editQuestion'])) {
-				echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemUpdated"</script>';
-			} else {
-				//New question
-				echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemAdded"</script>';
-			}
-		} else {
-			echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'&'.api_get_cidreq().'"</script>';
-		}
-	} else {
-		if (isset($questionName)) {
-			echo '<h3>'.$questionName.'</h3>';
-		}
-		if (!empty($pictureName)) {
-			echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
-		}
-		if(!empty($msgErr)) {
-			Display::display_normal_message($msgErr); //main API
-		}
-		// display the form
-		$form->display();
-	}
+        // redirect
+        if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
+            if(isset($_GET['editQuestion'])) {
+                echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemUpdated"</script>';
+            } else {
+                //New question
+                echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemAdded"</script>';
+            }
+        } else {
+            echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'&'.api_get_cidreq().'"</script>';
+        }
+    } else {
+        if (isset($questionName)) {
+            echo '<h3>'.$questionName.'</h3>';
+        }
+        if (!empty($pictureName)) {
+            echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
+        }
+        if (!empty($msgErr)) {
+            Display::display_normal_message($msgErr);
+        }
+        // display the form
+        $form->display();
+    }
 }

+ 4 - 4
main/exercice/unique_answer.class.php

@@ -143,10 +143,10 @@ class UniqueAnswer extends Question
 
                 $item_list = explode('@@', $answer->destination[$i]);
 
-                $try = $item_list[0];
-                $lp = $item_list[1];
-                $list_dest = $item_list[2];
-                $url = $item_list[3];
+                $try = isset($item_list[0]) ? $item_list[0] : '';
+                $lp = isset($item_list[1]) ? $item_list[1] : '';
+                $list_dest = isset($item_list[2]) ? $item_list[2] : '';
+                $url = isset($item_list[3]) ? $item_list[3] : '';
 
                 if ($try == 0) {
                     $try_result = 0;

+ 0 - 6
main/forum/index.php

@@ -174,12 +174,6 @@ if (!api_is_anonymous()) {
     }
 }
 
-/* CLEAN GROUP ID FOR AJAXFILEMANAGER */
-
-if (isset($_SESSION['_gid'])) {
-    unset($_SESSION['_gid']);
-}
-
 /* ACTION LINKS */
 
 echo '<div class="actions">';

+ 0 - 7
main/forum/viewforumcategory.php

@@ -168,14 +168,7 @@ if ($action_forums != 'add') {
         }
     }
 
-    /* CLEAN GROUP ID FOR AJAXFILEMANAGER */
-
-    if (isset($_SESSION['_gid'])) {
-        unset($_SESSION['_gid']);
-    }
-
     /* Display Forum Categories and the Forums in it */
-
     $html = '';
     $html .= '<div class="category-forum">';
 

+ 0 - 1264
main/inc/lib/SequenceManager.php

@@ -6,1269 +6,5 @@
  */
 class SequenceManager
 {
-    const _debug = false;
 
-    /**
-     * @param $row_entity_id
-     * @return array|bool
-     */
-    public static function get_pre_req_id_by_row_entity_id($row_entity_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = intval($row_entity_id);
-        if ($row_entity_id > 0) {
-            $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-            $sql = "SELECT sequence_row_entity_id FROM $seq_table
-                    WHERE sequence_row_entity_id_next = $row_entity_id";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_pre_req = Database::fetch_array($result, 'ASSOC')){
-                    $pre_req[] = intval($temp_pre_req['sequence_row_entity_id']);
-                }
-
-                return $pre_req;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $entity_id
-     * @param int $row_entity_id
-     * @param int $course_id
-     * @return array|bool
-     */
-    public static function get_next_by_row_id($entity_id, $row_entity_id, $course_id = null)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = Database::escape_string($row_entity_id);
-        $entity_id = Database::escape_string($entity_id);
-        $course_id = Database::escape_string($course_id);
-
-        if (is_numeric($row_entity_id) && is_numeric($entity_id)) {
-            $row_entity_id = intval($row_entity_id);
-            $entity_id = intval($entity_id);
-            $course_id = is_numeric($course_id) ? intval($course_id) : api_get_course_int_id();
-
-            $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-            $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
-            $sql = "SELECT row.id FROM $row_table row
-                    WHERE
-                        row.sequence_type_entity_id = $entity_id AND
-                         row.row_id = $row_entity_id AND
-                         row.c_id = $course_id LIMIT 0, 1";
-            $sql = "SELECT main.sequence_row_entity_id_next
-                    FROM $seq_table main WHERE main.sequence_row_entity_id_next IN ($sql)";
-            $sql = "SELECT * FROM $row_table res
-                    WHERE res.id IN ($sql)";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_next = Database::fetch_array($result, 'ASSOC')){
-                    $next[] = $temp_next;
-                }
-
-                return $next;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $entity_id
-     * @return array|bool
-     */
-    public static function get_entity_by_id($entity_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $entity_id = intval($entity_id);
-        if (is_numeric($entity_id)) {
-            $entity_id = intval($entity_id);
-            $ety_table = Database::get_main_table(TABLE_SEQUENCE_TYPE_ENTITY);
-            $sql = "SELECT * FROM $ety_table WHERE id = $entity_id LIMIT 0, 1";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_entity = Database::fetch_array($result, 'ASSOC')){
-                    $entity[] = $temp_entity;
-                }
-
-                return $entity;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $row_entity_id
-     * @param int $user_id
-     * @param int $session_id
-     * @param int $rule_id
-     *
-     * @return bool
-     */
-    public static function validate_rule_by_row_id(
-        $row_entity_id,
-        $user_id = null,
-        $session_id,
-        $rule_id = 1
-    ) {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $condition = self::get_condition_by_rule_id($rule_id);
-        if ($condition !== false) {
-            $con = $condition[0];
-            while(isset($con)) {
-                $var = self::get_variable_by_condition_id($con['id']);
-                $val = self::get_value_by_user_id($row_entity_id, $user_id, $session_id, 1);
-                $statement = 'return ('.floatval($val[0][$var[0]["name"]]).' '.$con["mat_op"].' '.$con["param"].');';
-                if (eval($statement)) {
-                    $go = (!isset($con['act_true']))? -1 : intval($con['act_true']);
-                } else {
-                    $go = (!isset($con['act_false']))? -1 : intval($con['act_false']);
-                }
-                if ($go === 0) {
-                    return true;
-                } else {
-                    --$go;
-                    $con = isset($condition[$go]) ? $condition[$go] : null;
-                }
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $rule_id
-     * @return array|bool
-     */
-    public static function get_condition_by_rule_id($rule_id = 1)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $rule_id = intval($rule_id);
-        if (is_numeric($rule_id)) {
-            $rule_id = intval($rule_id);
-            $con_table = Database::get_main_table(TABLE_SEQUENCE_CONDITION);
-            $rul_con_table = Database::get_main_table(TABLE_SEQUENCE_RULE_CONDITION);
-            $sql = "SELECT rc.sequence_condition_id FROM $rul_con_table rc
-                    WHERE rc.sequence_rule_id = $rule_id";
-            $sql = "SELECT * FROM $con_table co WHERE co.id IN ($sql)";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_condition = Database::fetch_array($result, 'ASSOC')) {
-                    $condition[] = $temp_condition;
-                }
-
-                return $condition;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $rule_id
-     *
-     * @return array|bool
-     */
-    public static function get_method_by_rule_id($rule_id = 1)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $rule_id = intval($rule_id);
-        if (is_numeric($rule_id)) {
-            $rule_id = intval($rule_id);
-            $met_table = Database::get_main_table(TABLE_SEQUENCE_METHOD);
-            $rul_met_table = Database::get_main_table(TABLE_SEQUENCE_RULE_METHOD);
-            $sql = "SELECT rm.sequence_method_id
-                    FROM $rul_met_table rm
-                    WHERE rc.sequence_rule_id = $rule_id";
-            $sql = "SELECT * FROM $met_table co
-                    WHERE co.id IN ($sql)";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_method = Database::fetch_array($result, 'ASSOC')){
-                    $method[] = $temp_method;
-                }
-
-                return $method;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $row_entity_id
-     *
-     * @return array|bool
-     */
-    public static function get_value_by_row_entity_id($row_entity_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = intval($row_entity_id);
-        if ($row_entity_id > 0) {
-            $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-            $sql = "SELECT * FROM $val_table val
-                    WHERE val.sequence_row_entity_id = $row_entity_id";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_value = Database::fetch_array($result, 'ASSOC')){
-                    $value[] = $temp_value;
-                }
-
-                return $value;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $condition_id
-     * @return array|bool
-     */
-    public static function get_variable_by_condition_id($condition_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $condition_id = intval($condition_id);
-        if (is_numeric($condition_id)) {
-            $condition_id = intval($condition_id);
-            $var_table = Database::get_main_table(TABLE_SEQUENCE_VARIABLE);
-            $vld_table = Database::get_main_table(TABLE_SEQUENCE_VALID);
-            $sql = "SELECT DISTINCT vld.sequence_variable_id
-                    FROM $vld_table vld
-                    WHERE vld.sequence_condition_id = $condition_id";
-            $sql = "SELECT * FROM $var_table var WHERE var.id IN ($sql)";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_variable = Database::fetch_array($result, 'ASSOC')) {
-                    $variable[] = $temp_variable;
-                }
-                return $variable;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * @param int $row_entity_id
-     * @param int $user_id
-     * @param $session_id
-     * @param string $met_type
-     * @param int $available
-     * @param int $complete_items
-     * @param int $total_items
-     * @param null $available_end_date
-     * @return bool
-     */
-    public static function execute_formulas_by_user_id(
-        $row_entity_id = null,
-        $user_id = null,
-        $session_id,
-        $met_type = '',
-        $available = 1,
-        $complete_items = 1,
-        $total_items = 1,
-        $available_end_date = null
-    ) {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $value = self::get_value_by_user_id($row_entity_id, $user_id, $session_id, $available);
-        $met_type = Database::escape_string($met_type);
-        if ($value !== false) {
-            if (empty($met_type)) {
-                $met_filter = " AND met.met_type NOT IN ('success', 'pre', 'update') ";
-            } else {
-                $met_filter = " AND met.met_type = '$met_type' ";
-            }
-            $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-            $rul_table = Database::get_main_table(TABLE_SEQUENCE_RULE);
-            $rul_met_table = Database::get_main_table(TABLE_SEQUENCE_RULE_METHOD);
-            $met_table = Database::get_main_table(TABLE_SEQUENCE_METHOD);
-            $var_table = Database::get_main_table(TABLE_SEQUENCE_VARIABLE);
-            $sql = "SELECT var.id, var.name FROM $var_table var";
-            $result = Database::query($sql);
-            $variable = [];
-            while ($temp_var = Database::fetch_row($result)) {
-                $variable[$temp_var['0']] = $temp_var['1'];
-            }
-            $sql = "SELECT rul.id FROM $rul_table rul";
-            $sql = "SELECT met.formula, met.assign assign
-                    FROM $met_table met, $rul_met_table rm
-                    WHERE
-                        met.id = rm.sequence_method_id $met_filter
-                    ORDER BY rm.method_order";
-            $result = Database::query($sql);
-            while ($temp_fml = Database::fetch_array($result, 'ASSOC')) {
-                $formula[] = $temp_fml;
-            }
-            $pat = "/v#(\d+)/";
-            if (isset($formula) && isset($variable)) {
-                if (is_array($value[0])) {
-                    $rep = '$val[$variable[$1]]';
-                    foreach ($value as $val) {
-                        $sql_array = array(
-                            'UPDATE' => " $val_table SET "
-                        );
-                        foreach ($formula as $fml) {
-                            $assign_key = $variable[$fml['assign']];
-                            $assign_val = &$val[$variable[$fml['assign']]];
-                            $fml_exe = preg_replace($pat, $rep, $fml['formula']);
-                            $fml_exe = 'return '.$fml_exe;
-                            $assign_val = eval($fml_exe);
-                            $sql_array[$assign_key] = " = '$assign_val', ";
-                        }
-                        $sql_array['WHERE'] = ' id = '.$val['id'];
-                        $sql = '';
-                        foreach ($sql_array as $sql_key => $sql_val) {
-                            $sql .= $sql_key;
-                            $sql .= $sql_val;
-                        }
-                        $sql = preg_replace('/, WHERE/', ' WHERE', $sql);
-                        $result = Database::query($sql);
-                    }
-                }
-
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $row_entity_id
-     * @param int $user_id
-     * @param int $session_id
-     * @param int $available
-     * @param int $success
-     * @return array|bool
-     */
-    public static function get_value_by_user_id(
-        $row_entity_id = null,
-        $user_id = null,
-        $session_id = null,
-        $available = -1,
-        $success = -1
-    ) {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $user_id = (isset($user_id))? intval($user_id) : api_get_user_id();
-        if ($user_id > 0) {
-            $available = Database::escape_string($available);
-            $available = (is_numeric($available))? intval($available) : -1;
-            if ($available < 0) {
-                $available_filter = '';
-            } else {
-                $available_filter = " AND available = $available ";
-            }
-            $success = Database::escape_string($success);
-            $success = (is_numeric($success))? intval($success) : -1;
-            if ($success < 0) {
-                $success_filter = '';
-            } else {
-                $success_filter = " AND success = $success ";
-            }
-            $row_entity_id = Database::escape_string($row_entity_id);
-            $row_entity_id = (is_numeric($row_entity_id))? intval($row_entity_id) : 0;
-            if ($row_entity_id !== 0) {
-                $row_entity_filter = " AND sequence_row_entity_id = $row_entity_id ";
-            } else {
-                $row_entity_filter = '';
-            }
-            $session_id = Database::escape_string($session_id);
-            $session_id = (is_numeric($session_id))? intval($session_id) : -1;
-            if ($session_id < 0) {
-                $session_filter = '';
-            } else {
-                $session_filter = " AND session_id = $session_id ";
-            }
-            $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-            $sql = "SELECT * FROM $val_table
-                    WHERE
-                        user_id = $user_id
-                        $available_filter
-                        $success_filter
-                        $row_entity_filter
-                        $session_filter
-                    ";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while($temp_value = Database::fetch_array($result,'ASSOC')) {
-                    $value[] = $temp_value;
-                }
-
-                return $value;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param $formula
-     * @return array|bool
-     */
-    public static function find_variables_in_formula($formula)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $formula = Database::escape_string($formula);
-        if (isset($formula)) {
-            $pat = "/v#(\d+)/";
-            preg_match_all($pat, $formula, $v_array);
-            if (isset($v_array)){
-                $var_array = array_unique($v_array[1]);
-                sort($var_array);
-                return $var_array;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $row_entity_id
-     * @return array|bool
-     */
-    public static function get_user_id_by_row_entity_id($row_entity_id = 0)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = intval($row_entity_id);
-        if ($row_entity_id > 0) {
-            $row_entity_filter = "WHERE sequence_row_entity_id = $row_entity_id";
-        } else {
-            $row_entity_filter = '';
-        }
-        $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-        $sql = "SELECT DISTINCT user_id, session_id
-                FROM $val_table $row_entity_filter";
-        $result = Database::query($sql);
-        if (Database::num_rows($result) > 0) {
-            while ($temp_user = Database::fetch_array($result, 'ASSOC')) {
-                $user[] = $temp_user;
-            }
-            return $user;
-        }
-        return false;
-    }
-
-    /**
-     * @param $row_entity_id
-     * @param $user_id
-     * @param $session_id
-     * @param null $available_end_date
-     * @return bool
-     */
-    public static function action_pre_init(
-        $row_entity_id,
-        $user_id,
-        $session_id,
-        $available_end_date = null
-    ) {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $user_id = intval($user_id);
-        $session_id = intval($session_id);
-        $row_entity_id = intval($row_entity_id);
-        $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-        $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-        $sql = "SELECT DISTINCT seq.sequence_row_entity_id, val.user_id
-                FROM $seq_table seq, $val_table val
-                WHERE
-                    seq.is_part != 1
-                    AND val.success = 0
-                    AND val.user_id = $user_id
-                    AND val.session_id = $session_id
-                    AND val.sequence_row_entity_id = seq.sequence_row_entity_id
-                    AND seq.sequence_row_entity_id_next = $row_entity_id";
-        $result = Database::query($sql);
-        while ($temp = Database::fetch_array($result, 'ASSOC')){
-            $pre_req[$temp['user_id']] = $temp['sequence_row_entity_id'];
-        }
-        if (empty($pre_req)) {
-            if (self::get_value_by_user_id($row_entity_id, $user_id, $session_id) === false) {
-                self::temp_hack_4_insert(1, $row_entity_id, $user_id, 0, $session_id);
-            }
-            self::execute_formulas_by_user_id(
-                $row_entity_id,
-                $user_id,
-                $session_id,
-                'pre',
-                0,
-                null,
-                null,
-                $available_end_date
-            );
-            return true;
-        } else {
-            self::temp_hack_4_set_aval($row_entity_id, $user_id, $session_id, 0);
-        }
-
-        return false;
-    }
-
-    /**
-     * @param int $row_entity_id
-     * @param int $user_id
-     * @param $session_id
-     * @param null $available_end_date
-     */
-    public static function action_post_success_by_user_id($row_entity_id, $user_id, $session_id, $available_end_date = null)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        if (self::execute_formulas_by_user_id(
-            $row_entity_id,
-            $user_id,
-            $session_id,
-            'success',
-            1,
-            null,
-            null,
-            null
-        )
-        ) {
-            $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-            $value = self::get_value_by_user_id($row_entity_id, $user_id, $session_id, 1, 1);
-            //$check_array = []; Update later
-            foreach ($value as $val) {
-                $row_entity_id_prev = $val['sequence_row_entity_id'];
-                $sql = "SELECT seq.sequence_row_entity_id_next
-                        FROM $seq_table seq
-                        WHERE seq.sequence_row_entity_id = $row_entity_id_prev";
-                $result = Database::query($sql);
-                while ($temp_next = Database::fetch_array($result, 'ASSOC')) {
-                    $next[] = $temp_next['sequence_row_entity_id_next'];
-                }
-                foreach ($next as $nx) {
-                    self::action_pre_init(
-                        $nx,
-                        $user_id,
-                        $session_id,
-                        $available_end_date
-                    );
-                }
-            }
-        }
-    }
-
-    /**
-     * @param int $entity_id
-     * @param int $row_id
-     * @param int $c_id
-     */
-    public static function getAllRowEntityIdByRowId($entity_id, $row_id, $c_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_id = intval($row_id);
-        $entity_id = intval($entity_id);
-        $c_id = intval($c_id);
-
-        $row_entity_id_prev = self::get_row_entity_id_by_row_id($entity_id, $row_id, $c_id);
-
-        if ($row_id > 0 && $entity_id > 0 && $c_id > 0) {
-            $table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-            $tableRow = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
-            $sql = "SELECT DISTINCT r.* FROM $table s
-                    INNER JOIN $tableRow r
-                    ON (r.id = s.sequence_row_entity_id)
-                    WHERE sequence_row_entity_id_next = $row_entity_id_prev";
-
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                $row_entity = array();
-                while ($temp_row_entity = Database::fetch_array($result, 'ASSOC')) {
-                    $row_entity[] = $temp_row_entity;
-                }
-                return $row_entity;
-            }
-        }
-
-        return array();
-    }
-
-    /**
-     * @param int $entity_id
-     * @param int $row_id
-     * @param int $c_id
-     * @return array
-     */
-    public static function getRowEntityByRowId($entity_id, $row_id, $c_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_id = intval($row_id);
-        $entity_id = intval($entity_id);
-        $c_id = intval($c_id);
-        if ($row_id > 0 && $entity_id > 0 && $c_id > 0) {
-            $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
-            $sql = "SELECT row.*
-                    FROM $row_table row
-                    WHERE
-                        row.sequence_type_entity_id = $entity_id AND
-                        row.row_id = $row_id AND
-                        row.c_id = $c_id
-                    LIMIT 0, 1";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-
-                return Database::fetch_array($result, 'ASSOC');
-            }
-        }
-
-        return array();
-    }
-
-    /**
-     * @param int $row_entity_id
-     * @param int $user_id
-     * @param int $session_id
-     * @return mixed
-     */
-    public static function getValIdByRowEntityId($row_entity_id, $user_id, $session_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = intval($row_entity_id);
-        $user_id = intval($user_id);
-        $session_id = intval($session_id);
-
-        if ($row_entity_id > 0 && $user_id > 0 && $session_id >= 0) {
-            $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-            $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-
-            //check if exists value row
-            $sql = "SELECT val.id FROM $val_table val
-                    WHERE
-                        val.sequence_row_entity_id = $row_entity_id
-                        AND val.user_id = $user_id
-                        AND val.session_id = $session_id
-                    LIMIT 0, 1";
-
-            $result = Database::query($sql);
-
-            if (Database::num_rows($result) > 0) {
-                $temp_row_entity = Database::fetch_array($result, 'ASSOC');
-                return $temp_row_entity['id'];
-            } else {
-                $sql = "SELECT sequence_row_entity_id FROM $seq_table
-                        WHERE sequence_row_entity_id_next = $row_entity_id";
-                $result = Database::query($sql);
-                $available = 0;
-                if (Database::num_rows($result)) {
-                    while ($temp_row_entity = Database::fetch_row($result)) {
-                        if ($temp_row_entity[0] == 0) {
-                            $available = 1;
-                            break;
-                        }
-                    }
-                    // Val row starts not available
-                } else {
-                    // Val row starts available
-                    $available = 1;
-                }
-                return self::temp_hack_4_insert(1, $row_entity_id, $user_id, $available, $session_id);
-            }
-        }
-        return 0;
-    }
-
-    /**
-     * @param int $entity_id
-     * @param int $row_id
-     * @param int $c_id
-     * @param string $name
-     * @return int
-     */
-    public static function get_row_entity_id_by_row_id($entity_id, $row_id, $c_id, $name = '')
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-            error_log('......................................');
-            error_log('entity_id: '.$entity_id.'.............');
-            error_log('row_id: '.$row_id.'...................');
-            error_log('c_id: '.$c_id.'.......................');
-        }
-        $row_id = intval($row_id);
-        $entity_id = intval($entity_id);
-        $c_id = intval($c_id);
-        $name = Database::escape_string($name);
-        if ($row_id > 0 && $entity_id > 0 && $c_id > 0) {
-            $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
-            $clp_table = Database::get_course_table(TABLE_LP_MAIN);
-            $sql = "SELECT row.id
-                    FROM $row_table row
-                    WHERE
-                        row.sequence_type_entity_id = $entity_id AND
-                        row.row_id = $row_id AND
-                        row.c_id = $c_id
-                    LIMIT 0, 1";
-            $result = Database::query($sql);
-            if (Database::num_rows($result) > 0) {
-                while ($temp_row_entity = Database::fetch_array($result, 'ASSOC')) {
-                    $row_entity[] = $temp_row_entity;
-                }
-                if (self::_debug) {
-                    error_log('Return in '.__FUNCTION__.' in '.__FILE__);
-                    error_log('...............................'.$row_entity[0]['id']);
-                }
-                return $row_entity[0]['id'];
-            } elseif ($entity_id == 1) {
-                $sql = "SELECT name, prerequisite FROM $clp_table
-                        WHERE c_id = $c_id
-                        AND id = $row_id
-                        LIMIT 0, 1";
-                $result = Database::query($sql);
-                if (Database::num_rows($result) > 0) {
-                    $temp_arr = Database::fetch_array($result, 'ASSOC');
-                    $name = $temp_arr['name'];
-                    $name = Database::escape_string($name);
-                    $pre = ($temp_arr['prerequisite'] > 0)? self::get_row_entity_id_by_row_id($entity_id, $temp_arr['prerequisite'], $c_id) : 0 ;
-                    $sql = "INSERT INTO $row_table (sequence_type_entity_id, c_id, row_id, name)
-                            VALUES ($entity_id, $c_id, $row_id, '$name')";
-                    Database::query($sql);
-                    $id = Database::insert_id();
-                    if ($id != 0) {
-                        $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-                        $sql = "INSERT INTO $seq_table (sequence_row_entity_id, sequence_row_entity_id_next, is_part) VALUES
-                        ($pre, $id, 0)";
-                        Database::query($sql);
-                        if (self::_debug) {
-                            error_log('Return in '.__FUNCTION__.' in '.__FILE__);
-                            error_log('................................'.$id);
-                        }
-                        return $id;
-                    } else {
-                        if (self::_debug) {
-                            error_log('Fail and Return in '.__FUNCTION__.' in '.__FILE__);
-                            error_log('................................');
-                            error_log($sql);
-                            error_log('................................');
-                            error_log('......................................0');
-                        }
-                    }
-                } else {
-                    if (self::_debug) {
-                        error_log('No result for query in '.__FUNCTION__.' in '.__FILE__);
-                        error_log('................................');
-                        error_log($sql);
-                    }
-                }
-            } else {
-                if (self::_debug) {
-                    error_log('Fail and Return in '.__FUNCTION__.' in '.__FILE__);
-                    error_log('................................');
-                    error_log($sql);
-                    error_log('................................');
-                    error_log('......................................0');
-                }
-            }
-        }
-        if (self::_debug) {
-            error_log('Fail and Return in '.__FUNCTION__.' in '.__FILE__);
-            error_log('......................................');
-            error_log('entity_id: '.$entity_id.'.............');
-            error_log('row_id: '.$row_id.'...................');
-            error_log('c_id: '.$c_id.'.......................');
-            error_log('......................................0');
-        }
-        return 0;
-    }
-
-    /**
-     * @param $entity_id
-     * @param $row_id
-     * @param $c_id
-     * @param $session_id
-     * @param $user_id
-     * @param $rule_id
-     * @param int $items_completed
-     * @param int $total_items
-     * @param null $available_end_date
-     */
-    public static function temp_hack_4_update($entity_id, $row_id, $c_id, $session_id, $user_id, $rule_id, $items_completed = 1, $total_items = 1, $available_end_date =null )
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = self::get_row_entity_id_by_row_id($entity_id, $row_id, $c_id);
-        if (!empty($row_entity_id)) {
-            self::execute_formulas_by_user_id($row_entity_id, $user_id, $session_id, 'update', 1, $items_completed, $total_items);
-            if (self::validate_rule_by_row_id($row_entity_id, $user_id, $session_id, $rule_id) && (self::get_value_by_user_id($row_entity_id, $user_id, $session_id, 1, 1) === false)) {
-                self::action_post_success_by_user_id($row_entity_id, $user_id, $session_id, $available_end_date);
-            }
-        }
-    }
-
-    /**
-     * @param $entity_name
-     * @return bool
-     */
-    public static function get_table_by_entity_name($entity_name)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $entity_name = Database::escape_string($entity_name);
-        $ety_table = Database::get_main_table(TABLE_SEQUENCE_TYPE_ENTITY);
-        $sql = "SELECT ety.ent_table
-                FROM $ety_table ety
-                WHERE ety.name = $entity_name
-                LIMIT 0, 1";
-        $result = Database::query($sql);
-        if (Database::num_rows($result) > 0) {
-            while ($temp_entity = Database::fetch_array($result, 'ASSOC')) {
-                $entity[] = $temp_entity;
-            }
-            return $entity[0]['ent_table'];
-        }
-
-        return false;
-    }
-
-    /**
-     * @param $entity_name
-     * @return array|bool
-     */
-    public static function get_entity_by_entity_name($entity_name)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $entity_name = Database::escape_string($entity_name);
-        $ety_table = Database::get_main_table(TABLE_SEQUENCE_TYPE_ENTITY);
-        $sql = "SELECT ety.* FROM $ety_table ety WHERE ety.name = $entity_name LIMIT 0, 1";
-        $result = Database::query($sql);
-        if (Database::num_rows($result) > 0) {
-            while ($temp_entity = Database::fetch_array($result,'ASSOC')) {
-                $entity[] = $temp_entity;
-            }
-            return $entity;
-        }
-        return false;
-    }
-
-    /**
-     * @param $entity_id
-     * @param $row_id
-     * @param $c_id
-     * @param string $name
-     * @return bool|string
-     */
-    public static function temp_hack_2_insert($entity_id, $row_id, $c_id, $name = '')
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_id = intval(Database::escape_string($row_id));
-        $c_id = intval(Database::escape_string($c_id));
-        $entity_id = intval(Database::escape_string($entity_id));
-        $name = Database::escape_string($name);
-
-        if ($entity_id > 0 && $row_id > 0 && $c_id >0) {
-            $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
-            $sql = "INSERT INTO $row_table (sequence_type_entity_id, c_id, row_id, name) VALUES
-            ($entity_id, $c_id, $row_id, '$name')";
-            Database::query($sql);
-            if (Database::affected_rows() > 0) {
-                return Database::insert_id();
-            }
-        }
-        return false;
-    }
-
-    /**
-     * @param $entity_id_prev
-     * @param $entity_id_next
-     * @param int $row_id_prev
-     * @param int $row_id_next
-     * @param int $c_id
-     * @param int $is_part
-     * @return bool|string
-     */
-    public static function temp_hack_3_insert($entity_id_prev, $entity_id_next, $row_id_prev = 0, $row_id_next = 0, $c_id = 1, $is_part = 0)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $is_part = intval($is_part);
-        $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-        $prev = self::get_row_entity_id_by_row_id($entity_id_prev, $row_id_prev, $c_id);
-        $next = self::get_row_entity_id_by_row_id($entity_id_next, $row_id_next, $c_id);
-        if ($prev != 0 || $next != 0) {
-            $sql = "INSERT INTO  $seq_table (sequence_row_entity_id, sequence_row_entity_id_next, is_part) VALUES
-            ($prev, $next, $is_part)";
-            Database::query($sql);
-            if (Database::affected_rows() > 0) {
-                return Database::insert_id();
-            }
-        }
-        return false;
-    }
-
-    /**
-     * @param $total_items
-     * @param $row_entity_id
-     * @param int $user_id
-     * @param int $available
-     * @param $session_id
-     * @return string
-     */
-    public static function temp_hack_4_insert($total_items, $row_entity_id, $user_id = 0, $available = -1, $session_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $user_id = intval($user_id);
-        $session_id = intval($session_id);
-        $total_items = intval($total_items);
-        $available = intval($available);
-
-        if ($available === -1) {
-            $pre_req = self::get_pre_req_id_by_row_entity_id($row_entity_id);
-            foreach ($pre_req as $pr) {
-                if($pr === 0) {
-                    $available = 1;
-                    break;
-                }
-            }
-        }
-
-        if (self::get_value_by_user_id($row_entity_id, $user_id, $session_id) === false) {
-            $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-            $sql = "INSERT INTO $val_table (user_id, sequence_row_entity_id, total_items, available, session_id)
-                    VALUES ($user_id, $row_entity_id, $total_items, $available, $session_id)";
-            Database::query($sql);
-
-            return Database::insert_id();
-        }
-    }
-
-    /**
-     * Cleans the sequence table by sequence_row_entity_id_next
-     * @param int $id
-     * @param int $c_id
-     */
-
-    public function cleanPrerequisites($id, $c_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-        $row_entity_id_next = self::get_row_entity_id_by_row_id(1, $id, $c_id);
-        $sql = "DELETE FROM $table
-                WHERE sequence_row_entity_id_next = $row_entity_id_next";
-        Database::query($sql);
-    }
-
-    /**
-     * @param $entity_id_prev
-     * @param $entity_id_next
-     * @param int $row_id_prev
-     * @param int $row_id_next
-     * @param int $c_id
-     * @param int $user_id
-     */
-    public static function temp_hack_3_update(
-        $entity_id_prev,
-        $entity_id_next,
-        $row_id_prev = 0,
-        $row_id_next = 0,
-        $c_id = 0,
-        $user_id = 0
-    ) {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $user_id = intval($user_id);
-
-        $row_entity_id_prev = self::get_row_entity_id_by_row_id($entity_id_prev, $row_id_prev, $c_id);
-        $row_entity_id_next = self::get_row_entity_id_by_row_id($entity_id_next, $row_id_next, $c_id);
-
-        if ($row_entity_id_prev !== 0 || $row_entity_id_next !== 0) {
-            $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-
-            // Check if exists.
-            $sql = "SELECT count(*) as count FROM $seq_table
-                    WHERE sequence_row_entity_id = $row_entity_id_prev AND sequence_row_entity_id_next = $row_entity_id_next";
-            $result = Database::query($sql);
-            $countRow = Database::fetch_array($result);
-            $count = $countRow['count'];
-
-            if (empty($count)) {
-                // Insert
-                $sql = "INSERT INTO $seq_table SET sequence_row_entity_id = $row_entity_id_prev, sequence_row_entity_id_next = $row_entity_id_next";
-                Database::query($sql);
-            } else {
-                // Update.
-                $data = self::getRowEntityByRowId($entity_id_next, $row_id_next, $c_id);
-                $sql = "UPDATE $seq_table SET sequence_row_entity_id = $row_entity_id_prev
-                       WHERE sequence_row_entity_id_next = $row_entity_id_next AND id = {$data['id']}";
-                Database::query($sql);
-            }
-
-            if ($row_entity_id_prev === 0) {
-                if ($user_id === 0) {
-                    $user_id = self::get_user_id_by_row_entity_id($row_entity_id_next);
-                    foreach ($user_id as $us_id) {
-                        self::action_pre_init($row_entity_id_next, $us_id['user_id'], $us_id['session_id']);
-                    }
-                } else {
-                    $sessions = self::get_sessions_by_user_id($user_id,$row_entity_id_next);
-                    foreach ($sessions as $session) {
-                        self::action_pre_init($row_entity_id_next, $user_id, $session);
-                    }
-                }
-            } else {
-                if ($user_id === 0) {
-                    $user_id = self::get_user_id_by_row_entity_id($row_entity_id_prev);
-                    foreach ($user_id as $us_id) {
-                        self::action_pre_init($row_entity_id_next, $us_id['user_id'], $us_id['session_id'], 0);
-                    }
-                } else {
-                    $sessions = self::get_sessions_by_user_id($user_id,$row_entity_id_next);
-                    foreach ($sessions as $session) {
-                        self::action_pre_init($row_entity_id_next, $user_id, $session['session_id']);
-                    }
-                }
-            }
-        }
-    }
-
-    public static function get_sessions_by_user_id($user_id, $row_entity_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-
-        $row_entity_id = intval($row_entity_id);
-
-        $sessions = [];
-        $sql = "SELECT session_id FROM $val_table
-            WHERE user_id = $user_id
-            AND row_entity_id = $row_entity_id";
-        $res = Database::query($sql);
-        while ($temp_array = Database::fetch_array($res, 'ASSOC')) {
-            $sessions[] = $temp_array;
-        }
-        return $sessions;
-    }
-
-    public static function temp_hack_4_delete($entity_id, $row_id, $c_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = self::get_row_entity_id_by_row_id($entity_id, $row_id, $c_id);
-        if ($row_entity_id !== false) {
-            $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-            $sql = "DELETE FROM $val_table WHERE sequence_row_entity_id = $row_entity_id";
-            $result = Database::query($sql);
-            if (Database::affected_rows() > 0) {
-                return Database::affected_rows();
-            }
-        }
-        return false;
-    }
-    public static function temp_hack_3_delete($entity_id, $row_id, $c_id, $rule_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = self::get_row_entity_id_by_row_id($entity_id, $row_id, $c_id);
-        $seq_array = array();
-        if ($row_entity_id !== false) {
-            $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
-            $sql = "SELECT * FROM $seq_table WHERE sequence_row_entity_id = $row_entity_id";
-            $result = Database::query($sql);
-            while ($temp_seq_array = Database::fetch_array($result, 'ASSOC')){
-                $seq_array[] = $temp_seq_array;
-            }
-            if (is_array($seq_array)) {
-                foreach ($seq_array as $seq) {
-                    $sql = "SELECT id FROM $seq_table
-                            WHERE sequence_row_entity_id_next = ".$seq['sequence_row_entity_id_next'];
-                    $result = Database::query($sql);
-                    if (Database::num_rows($result) > 1){
-                        $value = self::get_value_by_row_entity_id($seq['sequence_row_entity_id_next']);
-                        foreach ($value as $val) {
-                            if ($seq['is_part'] === 1) {
-                                self::execute_formulas_by_user_id($seq['sequence_row_entity_id_next'], $val['user_id'], $val['session_id'], '', 1, 0, -1, null);
-                            }
-                            if (self::validate_rule_by_row_id($seq['sequence_row_entity_id_next'], $val['user_id'], $val['session_id'], $rule_id) && $val['success'] !== 1) {
-                                self::action_post_success_by_user_id($seq['sequence_row_entity_id_next'], $val['user_id'], $val['session_id'], null);
-                            }
-                        }
-                    } else {
-                        $sql = "UPDATE $seq_table SET sequence_row_entity_id = 0 WHERE sequence_row_entity_id_next = ".$seq['sequence_row_entity_id_next'];
-                        Database::query($sql);
-                        $user = self::get_user_id_by_row_entity_id($seq['sequence_row_entity_id_next']);
-                        foreach ($user as $us) {
-                            self::temp_hack_4_set_aval($seq['sequence_row_entity_id_next'], $us['user_id'], $us['session_id'], 1);
-                        }
-                    }
-                }
-            }
-            $sql = "DELETE FROM $seq_table
-                    WHERE
-                        (sequence_row_entity_id = $row_entity_id AND sequence_row_entity_id_next = 0 ) OR
-                        (sequence_row_entity_id_next = $row_entity_id)";
-            Database::query($sql);
-            if (Database::affected_rows() > 0) {
-                return (!empty($seq_array))? $seq_array : true;
-            }
-        }
-        return false;
-    }
-
-    public static function temp_hack_2_delete($entity_id, $row_id, $c_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = self::get_row_entity_id_by_row_id($entity_id, $row_id, $c_id);
-        if ($row_entity_id !== false) {
-            $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
-            $sql = "DELETE FROM $row_table WHERE id = $row_entity_id";
-            $result = Database::query($sql);
-            if (Database::affected_rows() > 0) {
-                return Database::affected_rows();
-            }
-        }
-        return false;
-    }
-
-    public static function temp_hack_5($entity_id, $row_id, $c_id, $rule_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        if (self::temp_hack_3_delete($entity_id, $row_id, $c_id, $rule_id)) {
-            if (self::temp_hack_4_delete($entity_id, $row_id, $c_id)) {
-                if (self::temp_hack_2_delete($entity_id, $row_id, $c_id)) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    public static function temp_hack_4_set_aval($row_entity_id, $user_id, $session_id, $available, $available_end_date = null)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $available_end_date = Database::escape_string($available_end_date);
-        $available = intval(Database::escape_string($available));
-        $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-        if ($available == 1) {
-            $available_date = api_get_utc_datetime();
-            $available_date = ", available_start_date = '$available_date'";
-            if (!empty($available_end_date)) {
-                $available_end_date = api_get_utc_datetime($available_end_date);
-                $available_date .= "available_end_date = '$available_end_date'";
-            }
-        } else {
-            $available_date = '';
-        }
-        $sql = "UPDATE $val_table SET available = $available
-                $available_date
-                WHERE sequence_row_entity_id = $row_entity_id
-                AND user_id = $user_id
-                AND session_id = $session_id";
-        Database::query($sql);
-    }
-
-    /**
-     * @param $user_id
-     * @return array|bool
-     */
-    public static function get_row_entity_id_by_user_id($user_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $user_id = intval($user_id);
-        if ($user_id > 0) {
-            $user_filter = "WHERE user_id = $user_id";
-        } else {
-            $user_filter = '';
-        }
-        $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-        $sql = "SELECT sequence_row_entity_id FROM $val_table $user_filter";
-        $result = Database::query($sql);
-        if (Database::num_rows($result) > 0) {
-            while ($temp = Database::fetch_array($result, 'ASSOC')) {
-                $row_entity[] = $temp;
-            }
-            return $row_entity;
-        }
-        return false;
-    }
-
-    /**
-     * Bool Available for LP
-     */
-    public static function get_state_lp_by_row_entity_id($row_entity_id, $user_id, $session_id)
-    {
-        if (self::_debug) {
-            error_log('Entering '.__FUNCTION__.' in '.__FILE__);
-        }
-        $row_entity_id = intval($row_entity_id);
-        $user_id = intval($user_id);
-        $session_id = intval($session_id);
-
-        $val_table = Database::get_main_table(TABLE_SEQUENCE_VALUE);
-
-        if ($row_entity_id > 0 && $user_id > 0 && $session_id >= 0) {
-
-            $val_id = self::getValIdByRowEntityId($row_entity_id, $user_id, $session_id);
-            $sql_seq = "SELECT val.available, val.success FROM $val_table val
-            WHERE val.id = $val_id
-            LIMIT 0, 1";
-            $result_seq = Database::query($sql_seq);
-            $arr_seq = Database::fetch_array($result_seq, 'ASSOC');
-            if (intval($arr_seq['available']) === 1) {
-                if (intval($arr_seq['success']) === 1) {
-                    return "completed";
-                } else {
-                    return "process";
-                }
-            } else {
-                return "closed";
-            }
-        }
-        return false;
-    }
 }

+ 4 - 3
main/inc/lib/SequenceResourceManager.php

@@ -16,6 +16,7 @@ class SequenceResourceManager
      * @param array $sequences The sequences
      * @param int $type The type of sequence resource
      * @param int $userId Optional. The user ID
+     *
      * @return array
      */
     public static function checkRequirementsForUser(array $sequences, $type, $userId = 0)
@@ -35,6 +36,7 @@ class SequenceResourceManager
      * Check if the ser has completed the requirements for the session sequences
      * @param array $sequences The sequences
      * @param int $userId Optional. The user ID
+     *
      * @return array
      */
     private static function checkSessionRequirementsForUser(array $sequences, $userId = 0)
@@ -99,16 +101,15 @@ class SequenceResourceManager
     /**
      * Check if at least one sequence are completed
      * @param array $sequences The sequences
-     * @param int $type The type of sequence resource
      *
      * @return boolean
      */
     public static function checkSequenceAreCompleted(array $sequences)
     {
-        foreach ($sequences as $secuence) {
+        foreach ($sequences as $sequence) {
             $status = true;
 
-            foreach ($secuence['requirements'] as $item) {
+            foreach ($sequence['requirements'] as $item) {
                 $status = $status && $item['status'];
             }
 

+ 1 - 1
main/inc/lib/access_url_edit_users_to_url_functions.lib.php

@@ -28,7 +28,7 @@ class Accessurledituserstourl
      */
     function search_users($needle, $id)
     {
-        global $tbl_user, $tbl_access_url_rel_user;
+        global $tbl_user;
         $xajax_response = new xajaxResponse();
         $return = '';
 

+ 10 - 11
main/inc/lib/course_description.lib.php

@@ -93,36 +93,35 @@ class CourseDescription
     /**
      * Get all data by description and session id,
      * first you must set session_id property with the object CourseDescription
-     * @param    int        description type
-     * @param   string  course code (optional)
-     * @param    int        session id (optional)
-     * @return array
+     * @param    int  $description_type Description type
+     * @param   string $course_code Course code (optional)
+     * @param    int $session_id Session id (optional)
+     * @return array    List of fields from the descriptions found of the given type
      */
     public function get_data_by_description_type(
         $description_type,
-        $course_code = '',
+        $courseId = null,
         $session_id = null
     ) {
         $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
-        $course_id = api_get_course_int_id();
+        if (empty($courseId)) {
+            $courseId = api_get_course_int_id();
+        }
 
         if (!isset($session_id)) {
             $session_id = $this->session_id;
         }
         $condition_session = api_get_session_condition($session_id);
-        if (!empty($course_code)) {
-            $course_info = api_get_course_info($course_code);
-            $course_id = $course_info['real_id'];
-        }
         $description_type = intval($description_type);
         $sql = "SELECT * FROM $tbl_course_description
-		        WHERE c_id = $course_id AND description_type='$description_type' $condition_session ";
+		        WHERE c_id = $courseId AND description_type='$description_type' $condition_session ";
         $rs = Database::query($sql);
         $data = array();
         if ($description = Database::fetch_array($rs)) {
             $data['description_title'] = $description['title'];
             $data['description_content'] = $description['content'];
             $data['progress'] = $description['progress'];
+            $data['id'] = $description['id'];
         }
 
         return $data;

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

@@ -800,7 +800,8 @@ class Event
         Database::query($sql);
 
         foreach ($users as $user) {
-            $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' (user_id,event_type_name) VALUES('.intval($user).',"'.$event_name.'")';
+            $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' (user_id,event_type_name)
+                    VALUES('.intval($user).',"'.$event_name.'")';
             Database::query($sql);
         }
         $language_id = api_get_language_id($event_message_language);

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

@@ -324,7 +324,6 @@ HTML;
 
                     if ($answerType == UNIQUE_ANSWER_IMAGE) {
                         $attributes['style'] = 'display: none;';
-
                         $answer = '<div class="thumbnail">' . $answer . '</div>';
                     }
 
@@ -506,7 +505,9 @@ HTML;
                     if (!empty($user_choice_array)) {
                         foreach ($user_choice_array as $item) {
                             $item = explode(':', $item);
-                            $my_choice[$item[0]] = $item[1];
+                            if (isset($item[1]) && isset($item[0])) {
+                                $my_choice[$item[0]] = $item[1];
+                            }
                         }
                     }
                     $answer = Security::remove_XSS($answer, STUDENT);
@@ -3479,7 +3480,6 @@ HTML;
 
         $counter = 1;
         $total_score = $total_weight = 0;
-
         $exercise_content = null;
 
         // Hide results

+ 4 - 2
main/inc/lib/fileManage.lib.php

@@ -468,10 +468,12 @@ class FileManager
 		// Determine which query to execute
 		if ($result['number_existing'] > 0) {
 			// Entry exists, update
-			$query = "UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype' WHERE path='$full_file_name'";
+			$query = "UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype'
+			          WHERE path='$full_file_name'";
 		} else {
 			// No entry exists, create new one
-			$query = "INSERT INTO $glued_table (path,visibility,filetype) VALUES('$full_file_name','$default_visibility','$filetype')";
+			$query = "INSERT INTO $glued_table (path,visibility,filetype)
+			          VALUES ('$full_file_name','$default_visibility','$filetype')";
 		}
 		Database::query($query);
 	}

+ 2 - 2
main/inc/lib/hook/README.md

@@ -18,8 +18,8 @@ From version 1.10.x, the following Hooks (or more) exist:
 
 |Number| Directory                         | EventClass     | ObserverInterface               | Reference                 |
 |------|-----------------------------------|----------------|---------------------------------|---------------------------|
-|     1| /main/inc/lib/usermanager.lib.php | HookCreateUser | HookCreateUserObserverInterface | Usermanager::createUser() |
-|     2| /main/inc/lib/usermanager.lib.php | HookUpdateUser | HookUpdateUserObserverInterface | Usermanager::updateUser() |
+|     1| /main/inc/lib/usermanager.lib.php | HookCreateUser | HookCreateUserObserverInterface | UserManager::createUser() |
+|     2| /main/inc/lib/usermanager.lib.php | HookUpdateUser | HookUpdateUserObserverInterface | UserManager::updateUser() |
 |     3| /main/admin/index.php             | HookAdminBlock | HookAdminBlockObserverInterface | ADMIN BLOCK               |
 
 # What do I need to use Hooks?

+ 1 - 1
main/inc/lib/jpegcam/webcam_receiver.php

@@ -48,7 +48,7 @@ if($ext!= 'jpg'){
 $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 $saveDir=$dirBaseDocuments.$webcamdir;
 $current_session_id = api_get_session_id();
-$groupId=$_SESSION['_gid'];
+$groupId = api_get_group_id();
 
 //avoid duplicates
 $webcamname_to_save=$webcamname;

+ 20 - 27
main/inc/lib/search/search_widget.php

@@ -19,7 +19,7 @@ require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  * @param   array $htmlHeadXtra     A reference to the doc $htmlHeadXtra
  */
 function search_widget_prepare(&$htmlHeadXtra) {
-    $htmlHeadXtra[] = '    
+    $htmlHeadXtra[] = '
     <script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.autocomplete.js"></script>
     <script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'search/search_widget.js"></script>
     <link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.autocomplete.css" />
@@ -31,7 +31,7 @@ function search_widget_prepare(&$htmlHeadXtra) {
  */
 function format_one_specific_field_select($prefix, $sf_term_array, $op, $extra_select_attr='size="7" class="sf-select-multiple"') {
 	global $charset;
-    $multiple_select .= '<select '. $extra_select_attr .' title="'. $prefix .'" id="sf-'. $prefix .'" name="sf_'. $prefix .'[]">';
+    $multiple_select = '<select '. $extra_select_attr .' title="'. $prefix .'" id="sf-'. $prefix .'" name="sf_'. $prefix .'[]">';
 
     $all_selected = '';
     if (!empty($_REQUEST['sf_'. $prefix]) ) {
@@ -123,7 +123,7 @@ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) {
 		$action='index.php';
 	}
 	$navigator_info = api_get_navigator();
-	
+
 	if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
 		$submit_button1	= '<input type="submit" id="submit" value="'. get_lang('Search') .'" />';
 		$submit_button2 = '<input class="lower-submit" type="submit" value="'. get_lang('Search') .'" />';
@@ -142,8 +142,8 @@ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) {
           	'.$submit_button1.'
             <br /><br />';
     $list = get_specific_field_list();
-    
-    if(!empty($list)) {         
+
+    if(!empty($list)) {
         $form .= '<span class="search-links-box">'. $advanced_options .'&nbsp;</span>
             <div id="tags" class="tags" style="display:'. $display_thesaurus .';">
                 <div class="search-help-box">'. $help .'</div>
@@ -200,7 +200,7 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
 	if (isset($_GET['action']) && strcmp(trim($_GET['action']),'search')===0) {
 		$action='index.php';
 	}
-	
+
     $form = '
         <form id="chamilo_search" action="'. $action .'" method="GET">
             <input type="text" id="query" name="query" size="40" />
@@ -226,26 +226,26 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
                 unset($sf_term_array);
                 natcasesort($temp);
                 $sf_term_array = $temp;
-        
+
                 // get specific field name
                 $sf_value = get_specific_field_list(array( 'code' => "'$prefilter_prefix'" ));
                 $sf_value = array_shift($sf_value);
                 $form .= '<label class="sf-select-multiple-title" for="sf_'. $prefix .'[]">'.$icons_for_search_terms[$prefix].' '.$sf_value['name'].'</label><br />';
-        
+
                 $form .= format_one_specific_field_select($prefilter_prefix, $sf_term_array, $op, 'id="prefilter"');
                 $form .= format_specific_fields_selects($sf_terms, $op, $prefilter_prefix);
             } else {
                 $form .= format_specific_fields_selects($sf_terms, $op);
             }
-            
-            
+
+
             $or_checked = '';
             $and_checked = '';
             if ($op == 'or') {
                 $or_checked = 'checked="checked"';
             } else if ($op == 'and') {
                 $and_checked = 'checked="checked"';
-            }    
+            }
             $form .= '
                         </tr>
                         <tr>
@@ -263,11 +263,11 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
                         </tr>
                         </table>
                     </div>';
-        }    
+        }
        $form .= '
         </form>
         <br style="clear: both;"/>';
-    
+
     return $form;
 }
 
@@ -276,7 +276,7 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
  */
 function display_search_form($action, $show_thesaurus, $sf_terms, $op) {
     $type = (!empty($_REQUEST['type'])? htmlentities($_REQUEST['type']): 'normal');
-    
+
     switch ($type) {
         case 'prefilter':
             $prefilter_prefix = api_get_setting('search_prefilter_prefix');
@@ -302,17 +302,17 @@ function display_search_form($action, $show_thesaurus, $sf_terms, $op) {
  * @param   string $action     Just in case your action is not
  * index.php
  */
-function search_widget_show($action='index.php') {
-    global $charset;
+function search_widget_show($action='index.php')
+{
     require_once api_get_path(LIBRARY_PATH).'search/ChamiloQuery.php';
     // TODO: load images dinamically when they're avalaible from specific field ui to add
-    $icons_for_search_terms = array();
+    $groupId = api_get_group_id();
 
     $sf_terms = array();
     $specific_fields = get_specific_field_list();
     $url_params = array();
 
-    if ( ($cid=api_get_course_id()) != -1 ) { // with cid
+    if (($cid = api_get_course_id()) != -1) { // with cid
 
         // get search engine terms
         $course_filter = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid);
@@ -330,31 +330,25 @@ function search_widget_show($action='index.php') {
             $url_params[] = 'sf_'.$specific_field['code'];
             unset($temp);
         }
-
     } else { // without cid
-
         // prepare specific fields names (and also get possible URL param names)
         foreach ($specific_fields as $specific_field) {
             //get Xapian terms for a specific term prefix, in ISO, apparently
             $sf_terms[$specific_field['code']] = xapian_get_all_terms(1000, $specific_field['code']);
             $url_params[] = 'sf_'.$specific_field['code'];
         }
-
     }
-
     echo '<h2>'.get_lang('Search').'</h2>';
 
-
 	// Tool introduction
     // TODO: Settings for the online editor to be checked (insert an image for example). Probably this is a special case here.
     if (api_get_course_id() !== -1)
-    if (!empty($_SESSION['_gid'])) {
-        Display::display_introduction_section(TOOL_SEARCH.$_SESSION['_gid']);
+    if (!empty($groupId)) {
+        Display::display_introduction_section(TOOL_SEARCH.$groupId);
     } else {
         Display::display_introduction_section(TOOL_SEARCH);
     }
 
-
     $op = 'or';
     if (!empty($_REQUEST['operator']) && in_array($op,array('or','and'))) {
         $op = $_REQUEST['operator'];
@@ -379,5 +373,4 @@ function search_widget_show($action='index.php') {
     // create the form
     // TODO: use FormValidator
     display_search_form($action, $show_thesaurus, $sf_terms, $op);
-
 }

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

@@ -1372,6 +1372,7 @@ class Skill extends Model
     /**
      * Get the users list who achieved a skill
      * @param int $skillId The skill id
+     *
      * @return array The users list
      */
     public function listUsersWhoAchieved($skillId)

+ 3 - 8
main/inc/lib/skill.visualizer.lib.php

@@ -40,13 +40,7 @@ class SkillVisualizer
         }
 
         $this->html .= '<div id="block_'.$block_id.'" class = "open_block window '.$extra_class.'  '.$class.'" style = "top:' . $position['y'] . 'px; left:' . $position['x'] . 'px;">';
-        /*$gradebook_string = '';
-        if (!empty($skill['gradebooks'])) {
-            foreach ($skill['gradebooks'] as $gradebook) {
-                //uncomment this to show the gradebook tags
-                $gradebook_string .= Display::span($gradebook['name'], array('class'=>'label_tag gradebook','style'=>'width:50px')).'<br />';
-            }
-        } */
+
         $content =  $skill['name'];
         $content .= '<div class="btn-group">';
         $content .= Display::url(get_lang('Edit'), '#', array('id'=>'edit_block_'.$block_id, 'class'=>'edit_block btn'));
@@ -69,7 +63,8 @@ class SkillVisualizer
     /**
      * Adds a node using jplumb
      */
-    private function add_item($skill, $position) {
+    private function add_item($skill, $position)
+    {
         $block_id = $skill['id'];
         $end_point = 'readEndpoint';
         $class = 'default_window';

+ 28 - 19
main/inc/lib/svg-edit/extensions/imagelib/groups.php

@@ -13,15 +13,22 @@ api_block_anonymous_users();
 $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
 
 $course_info = api_get_course_info();
+$groupId = api_get_group_id();
 
-
-$group_properties 	= GroupManager::get_group_properties(api_get_group_id());
-$groupdirpath 		= $group_properties['directory'];
-$group_disk_path 	= api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
-$group_web_path  	= api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
+$group_properties = GroupManager::get_group_properties($groupId);
+$groupdirpath = $group_properties['directory'];
+$group_disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
+$group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
 
 //get all group files and folders
-$docs_and_folders = DocumentManager::get_all_document_data($course_info, $groupdirpath, api_get_group_id(), null, $is_allowed_to_edit, false);
+$docs_and_folders = DocumentManager::get_all_document_data(
+    $course_info,
+    $groupdirpath,
+    api_get_group_id(),
+    null,
+    $is_allowed_to_edit,
+    false
+);
 
 //get all group filenames
 $array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array();
@@ -36,13 +43,13 @@ if (count($array_to_search) > 0) {
 $accepted_extensions = array('.svg', '.png');
 
 if (is_array($all_files) && count($all_files) > 0) {
-	foreach ($all_files as & $file) {
-		$slideshow_extension = strrchr($file, '.');
-		$slideshow_extension = strtolower($slideshow_extension);
-		if (in_array($slideshow_extension, $accepted_extensions)) {
-			$png_svg_files[] =$file;
-		}
-	}
+    foreach ($all_files as & $file) {
+        $slideshow_extension = strrchr($file, '.');
+        $slideshow_extension = strtolower($slideshow_extension);
+        if (in_array($slideshow_extension, $accepted_extensions)) {
+            $png_svg_files[] =$file;
+        }
+    }
 }
 
 $style = '<style>';
@@ -58,7 +65,10 @@ $style .='</style>';
 <?php
 echo '<h2>'.get_lang('GroupSingle').': '.$group_properties['name'].'</h2>';
 
-if (($group_properties['doc_state'] == 2 && ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid']))) || $group_properties['doc_state'] == 1){
+if ((
+        $group_properties['doc_state'] == 2 &&
+        ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $groupId))) || $group_properties['doc_state'] == 1
+){
 
 	if (!empty($png_svg_files)) {
 		echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
@@ -69,13 +79,12 @@ if (($group_properties['doc_state'] == 2 && ($is_allowed_to_edit || GroupManager
 			if (strpos($filename, "svg")){
 				$new_sizes['width'] = 60;
 				$new_sizes['height'] = 60;
-			}
-			else {
+			} else {
 				$new_sizes = api_resize_image($image, 60, 60);
 			}
-				echo '<li style="display:inline; padding:8px;">';
-				echo '<a href = "'.$group_web_path.$filename.'" alt="'.$filename.'" title="'.$filename.'">';
-				echo '<img src = "'.$group_web_path.$filename.'" width = "'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
+            echo '<li style="display:inline; padding:8px;">';
+            echo '<a href = "'.$group_web_path.$filename.'" alt="'.$filename.'" title="'.$filename.'">';
+            echo '<img src = "'.$group_web_path.$filename.'" width = "'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
 		}
 		echo '</ul>';
 	}

+ 1 - 1
main/inc/lib/template.lib.php

@@ -643,7 +643,7 @@ class Template
             $js_files[] = 'fontresize.js';
         }
 
-        $js_files[] = 'tag/jquery.fcbkcomplete.js';
+        $js_files[] = 'tag/jquery.fcbkcomplete.min.js';
 
         $js_file_to_string = null;
         $isoCode = api_get_language_isocode();

+ 2 - 2
main/install/install.lib.php

@@ -1536,7 +1536,7 @@ function display_configuration_settings_form(
     echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
     echo '</div>';
 
-    echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>main/inc/conf/configuration.php</strong></p>';
+    echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>app/config/configuration.php</strong></p>';
 
     // Parameter 1: administrator's login
     
@@ -1696,7 +1696,7 @@ function display_after_install_message($installType)
     echo '<div class="alert alert-warning">';
     echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
     echo ': ';
-    printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'main/inc/conf/', 'main/install/');
+    printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'app/config/', 'main/install/');
     echo '</div>';
     ?></form>
     <br />

+ 5 - 5
main/newscorm/learnpath.class.php

@@ -5391,9 +5391,10 @@ class learnpath
 
                     $prerequisiteMinScore = isset($array[$i]['prerequisite_min_score']) ? $array[$i]['prerequisite_min_score'] : null;
                     $prerequisiteMaxScore = isset($array[$i]['prerequisite_max_score']) ? $array[$i]['prerequisite_max_score'] : null;
-
+                    $ref = isset($array[$i]['ref']) ? $array[$i]['ref'] : '';
                     $this->arrMenu[] = array(
                         'id' => $array[$i]['id'],
+                        'ref' => $ref,
                         'item_type' => $array[$i]['item_type'],
                         'title' => $array[$i]['title'],
                         'path' => $path,
@@ -6535,7 +6536,6 @@ class learnpath
     public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
     {
         $course_id = api_get_course_int_id();
-        global $charset;
         $uploadPath = DIR_HOTPOTATOES; //defined in main_api
         $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
 
@@ -8319,8 +8319,8 @@ class learnpath
         $return .= '<label for="idNone">' . get_lang('None') . '</label>';
         $return .= '</tr>';
 
-        $sql 	= "SELECT * FROM $tbl_lp_item
-                   WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
+        $sql = "SELECT * FROM $tbl_lp_item
+                WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
         $result = Database::query($sql);
         $arrLP = array();
 
@@ -8415,7 +8415,7 @@ class learnpath
         $return .= '</tr>';
         $return .= '</table>';
         $return .= '<div style="padding-top:3px;">';
-        $return .= '<button class="btn btn-default" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . '</button>';
+        $return .= '<button class="btn btn-primary" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . '</button>';
         $return .= '</form>';
 
         return $return;

+ 3 - 2
main/permissions/group_permissions.inc.php

@@ -2,12 +2,13 @@
 /**
  * @package chamilo.permissions
  */
-/** 
+/**
  * Code
  */
 include_once('permissions_functions.inc.php');
 include_once('all_permissions.inc.php');
-$group_id=$_SESSION['_gid'];
+$group_id = api_get_group_id();
+
 echo $group_id;
 // ---------------------------------------------------
 // 			ACTIONS

+ 0 - 3
main/social/group_view.php

@@ -279,13 +279,10 @@ $tpl = new Template(null);
 SocialManager::setSocialUserBlock($tpl, $user_id, 'groups', $group_id);
 //Block Social Menu
 $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
-
 $tpl->setHelp('Groups');
-
 $tpl->assign('create_link', $create_thread_link);
 $tpl->assign('is_group_member', $is_group_member);
 $tpl->assign('group_info', $group_info);
-
 $tpl->assign('social_menu_block', $social_menu_block);
 $tpl->assign('social_right_content', $social_right_content);
 $social_layout = $tpl->get_template('social/group_view.tpl');

+ 1 - 1
main/social/groups.php

@@ -20,7 +20,7 @@ $this_section = SECTION_SOCIAL;
 $allowed_views = array('mygroups','newest','pop');
 $content = null;
 
-if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
+if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
     if ($_GET['view'] == 'mygroups') {
         $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
         $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));

+ 12 - 23
main/social/my_skills_report.php

@@ -13,7 +13,7 @@ $isDRH = api_is_drh();
 
 if (!$isStudent && !$isStudentBosss && !$isDRH) {
     header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/skills_wheel.php');
-    die;
+    exit;
 }
 
 $userId = api_get_user_id();
@@ -31,11 +31,11 @@ $tpl->assign('allowSkillsTool', api_get_setting('allow_skills_tool') == 'true');
 $tpl->assign('allowDrhSkillsManagement', api_get_setting('allow_hr_skills_management') == 'true');
 
 if ($isStudent) {
-    $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory "
-        . "FROM $skillTable s "
-        . "INNER JOIN $skillRelUserTable sru ON s.id = sru.skill_id "
-        . "INNER JOIN $courseTable c ON sru.course_id = c.id "
-        . "WHERE sru.user_id = $userId";
+    $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
+            FROM $skillTable s
+            INNER JOIN $skillRelUserTable sru ON s.id = sru.skill_id
+            INNER JOIN $courseTable c ON sru.course_id = c.id
+            WHERE sru.user_id = $userId";
 
     $result = Database::query($sql);
 
@@ -78,11 +78,12 @@ if ($isStudent) {
     }
 
     if ($selectedStudent > 0) {
-        $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory "
-            . "FROM $skillTable s "
-            . "INNER JOIN $skillRelUserTable sru ON s.id = sru.skill_id "
-            . "INNER JOIN $courseTable c ON sru.course_id = c.id "
-            . "WHERE sru.user_id = $selectedStudent";
+        $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
+                FROM $skillTable s
+                INNER JOIN $skillRelUserTable sru ON s.id = sru.skill_id
+                INNER JOIN $courseTable c ON sru.course_id = c.id
+                WHERE sru.user_id = $selectedStudent
+                ";
 
         $result = Database::query($sql);
 
@@ -106,16 +107,13 @@ if ($isStudent) {
                     $courseImageThumb->resize(32, 32, 0);
                     $courseImageThumb->send_image($thumbSysPath);
                 }
-
                 $tableRow['courseImage'] = $thumbWebPath;
             }
-
             $tableRows[] = $tableRow;
         }
     }
 
     $tplPath = 'skill/student_boss_report.tpl';
-
     $tpl->assign('followedStudents', $followedStudents);
     $tpl->assign('selectedStudent', $selectedStudent);
 } else if ($isDRH) {
@@ -141,28 +139,22 @@ if ($isStudent) {
     switch ($action) {
         case 'filterByCourse':
             $course = api_get_course_info_by_id($selectedCourse);
-
             $reportTitle = sprintf(get_lang('AchievedSkillInCourseX'), $course['name']);
-
             $tableRows = $objSkill->listAchievedByCourse($selectedCourse);
             break;
         case 'filterBySkill':
             $skill = $objSkill->get($selectedSkill);
-
             $reportTitle = sprintf(get_lang('StudentsWhoAchievedTheSkillX'), $skill['name']);
-
             $students = UserManager::getUsersFollowedByUser(
                 $userId, STUDENT, false, false, false, null, null, null, null, null, null, DRH
             );
 
             $coursesFilter = array();
-
             foreach ($courses as $course) {
                 $coursesFilter[] = $course['id'];
             }
 
             $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
-
             break;
     }
 
@@ -190,13 +182,10 @@ if ($isStudent) {
     $tplPath = 'skill/drh_report.tpl';
 
     $tpl->assign('action', $action);
-
     $tpl->assign('courses', $courses);
     $tpl->assign('skills', $skills);
-
     $tpl->assign('selectedCourse', $selectedCourse);
     $tpl->assign('selectedSkill', $selectedSkill);
-
     $tpl->assign('reportTitle', $reportTitle);
 }
 

+ 1 - 2
main/social/myfiles.php

@@ -4,6 +4,7 @@
  * @author Juan Carlos Trabado herodoto@telefonica.net
  * @package chamilo.social
  */
+
 $cidReset = true;
 require_once '../inc/global.inc.php';
 
@@ -75,7 +76,6 @@ $(document).on("ready", function () {
 
 </script>';
 
-$show_message = null;
 // Social Menu Block
 $social_menu_block = SocialManager::show_social_menu('myfiles');
 $actions = null;
@@ -106,7 +106,6 @@ $editor = $tpl->fetch('default/'.$editor->getEditorStandAloneTemplate());
 $tpl->assign('social_right_content', $editor);
 $tpl->assign('social_menu_block', $social_menu_block);
 $tpl->assign('actions', $actions);
-$tpl->assign('message', $show_message);
 
 $social_layout = $tpl->get_template('social/myfiles.tpl');
 $tpl->display($social_layout);

+ 24 - 12
main/social/profile.php

@@ -59,7 +59,7 @@ if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp
     header('Location: ' . $url);
     exit;
 
-} else if (!empty($_POST['social_wall_new_msg'])  && !empty($_POST['messageId'])) {
+} else if (!empty($_POST['social_wall_new_msg']) && !empty($_POST['messageId'])) {
     $messageId = intval($_POST['messageId']);
     $res = SocialManager::sendWallMessage(
         api_get_user_id(),
@@ -201,18 +201,22 @@ if (isset($_GET['shared'])) {
     $my_link = '../social/profile.php';
     $link_shared = '';
 }
-$interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('SocialNetwork') );
+$interbreadcrumb[] = array(
+    'url' => 'home.php',
+    'name' => get_lang('SocialNetwork'),
+);
 
 if (isset($_GET['u']) && is_numeric($_GET['u']) && $_GET['u'] != api_get_user_id()) {
     $info_user =   api_get_user_info($_GET['u']);
-    $interbreadcrumb[]= array (
+    $interbreadcrumb[]= array(
         'url' => '#',
-        'name' => api_get_person_name($info_user['firstName'], $info_user['lastName']));
+        'name' => $info_user['complete_name']
+    );
     $nametool = '';
 }
 if (isset($_GET['u'])) {
-    $param_user='u='.Security::remove_XSS($_GET['u']);
-}else {
+    $param_user = 'u='.Security::remove_XSS($_GET['u']);
+} else {
     $info_user = api_get_user_info(api_get_user_id());
     $param_user = '';
 }
@@ -230,7 +234,7 @@ if (is_array($personal_course_list)) {
     foreach ($personal_course_list as $my_course) {
         if ($i<=10) {
             $list[] = SocialManager::get_logged_user_course_html($my_course, $i);
-            $course_list_code[] = array('code'=> $my_course['code']);
+            $course_list_code[] = array('code' => $my_course['code']);
         } else {
             break;
         }
@@ -241,11 +245,19 @@ if (is_array($personal_course_list)) {
 }
 
 //Social Block Menu
-$social_menu_block = SocialManager::show_social_menu('shared_profile', null, $user_id, $show_full_profile);
+$social_menu_block = SocialManager::show_social_menu(
+    'shared_profile',
+    null,
+    $user_id,
+    $show_full_profile
+);
 
 //Setting some session info
 $user_info = api_get_user_info($my_user_id);
-$sessionList = SessionManager::getSessionsFollowedByUser($my_user_id, $user_info['status']);
+$sessionList = SessionManager::getSessionsFollowedByUser(
+    $my_user_id,
+    $user_info['status']
+);
 
 // My friends
 $friend_html = SocialManager::listMyFriendsBlock(
@@ -296,7 +308,7 @@ if ($show_full_profile) {
                 continue;
             }
             // get display text, visibility and type from user_field table
-            $field_variable = str_replace('extra_','',$key);
+            $field_variable = str_replace('extra_', '', $key);
 
             $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(
                 $field_variable
@@ -471,7 +483,7 @@ if ($show_full_profile) {
         // Courses without sessions
         $my_course = '';
         $i = 1;
-       
+
         foreach ($list as $key => $value) {
             if ( empty($value[2]) ) { //if out of any session
                 $my_courses .=  $value[1];
@@ -488,7 +500,7 @@ if ($show_full_profile) {
         //$social_session_block = $htmlSessionList;
         $social_session_block = $sessionList;
     }
-    
+
     // Block Social User Feeds
     $user_feeds = SocialManager::get_user_feeds($user_id);
 

+ 10 - 1
main/social/skills_ranking.php

@@ -45,7 +45,16 @@ $extra_params['height'] = 'auto';
 
 //$extra_params['rowList'] = array(10, 20 ,30);
 
-$jqgrid = Display::grid_js('skill_ranking', $url,$columns,$column_model,$extra_params, array(), null, true);
+$jqgrid = Display::grid_js(
+    'skill_ranking',
+    $url,
+    $columns,
+    $column_model,
+    $extra_params,
+    array(),
+    null,
+    true
+);
 $content = Display::grid_html('skill_ranking');
 
 $tpl = new Template(get_lang('Ranking'));

+ 4 - 4
main/social/skills_tree.php

@@ -21,12 +21,12 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
 $htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');
 $htmlHeadXtra[] = api_get_js('skills.js');
 
-$skill  = new Skill();
-$type   = 'read'; //edit
+$skill = new Skill();
+$type = 'read'; //edit
 
-$tree   = $skill->get_skills_tree(api_get_user_id(), null, true);
+$tree = $skill->get_skills_tree(api_get_user_id(), null, true);
 $skill_visualizer = new SkillVisualizer($tree, $type);
-$url  = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?1=1';
+$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?1=1';
 $tpl = new Template(null, false, false);
 
 $tpl->assign('url', $url);

+ 2 - 2
main/template/default/course_description/edit.tpl

@@ -22,9 +22,9 @@
 {% endif %}
 
 
-{% if type.question %}	
+{% if type.question %}
     <div class="normal-message">
-        <div>            
+        <div>
             <strong>{{'QuestionPlan'|get_lang}}</strong>
         </div>
         {{type.question}}

+ 20 - 33
main/upload/upload.document.php

@@ -8,19 +8,6 @@
  * @package chamilo.upload
  * @author Yannick Warnier <ywarnier@beeznest.org>
  */
-/**
- * Process the document and return to the document tool
- */
-
-/*
-	Libraries
-*/
-
-//many useful functions in main_api.lib.php, by default included
-if (!function_exists('api_get_path')) {
-    header('location: upload.php');
-    die;
-}
 
 $courseDir = $_course['path'] . "/document";
 $sys_course_path = api_get_path(SYS_COURSE_PATH);
@@ -59,7 +46,6 @@ api_display_tool_title($nameTools . $add_group_to_title);
 /**
  * Process
  */
-
 //user has submitted a file
 if (isset($_FILES['user_upload'])) {
 	$upload_ok = process_uploaded_file($_FILES['user_upload']);
@@ -87,10 +73,10 @@ if (isset($_FILES['user_upload'])) {
         	if ($new_title)   $ct .= ", title='$new_title'";
         	Database::query("UPDATE $table_document SET" . substr($ct, 1) ." WHERE id = '$docid'");
     	}
-		//check for missing images in html files
-		$missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
-		if ($missing_files)  {
-			//show a form to upload the missing files
+        //check for missing images in html files
+        $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
+        if ($missing_files)  {
+            //show a form to upload the missing files
             Display::display_normal_message(
                 build_missing_files_form(
                     $missing_files,
@@ -98,17 +84,17 @@ if (isset($_FILES['user_upload'])) {
                     $_FILES['user_upload']['name']
                 )
             );
-		}
-	}
+        }
+    }
 }
 //missing images are submitted
 if (isset($_POST['submit_image'])) {
-	$number_of_uploaded_images = count($_FILES['img_file']['name']);
-	//if images are uploaded
-	if ($number_of_uploaded_images > 0) {
-		//we could also create a function for this, I'm not sure...
-		//create a directory for the missing files
-		$img_directory = str_replace('.','_',$_POST['related_file']."_files");
+    $number_of_uploaded_images = count($_FILES['img_file']['name']);
+    //if images are uploaded
+    if ($number_of_uploaded_images > 0) {
+        //we could also create a function for this, I'm not sure...
+        //create a directory for the missing files
+        $img_directory = str_replace('.','_',$_POST['related_file']."_files");
         $folderData = create_unexisting_directory(
             $_course,
             $_user['user_id'],
@@ -119,7 +105,7 @@ if (isset($_POST['submit_image'])) {
             $img_directory
         );
         $missing_files_dir = $folderData['path'];
-		//put the uploaded files in the new directory and get the paths
+        //put the uploaded files in the new directory and get the paths
         $paths_to_replace_in_file = move_uploaded_file_collection_into_directory(
             $_course,
             $_FILES['img_file'],
@@ -130,15 +116,15 @@ if (isset($_POST['submit_image'])) {
             $to_user_id,
             $max_filled_space
         );
-		//open the html file and replace the paths
+        //open the html file and replace the paths
         replace_img_path_in_html_file(
             $_POST['img_file_path'],
             $paths_to_replace_in_file,
             $base_work_dir . $_POST['related_file']
         );
-		//update parent folders
-		item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']);
-	}
+        //update parent folders
+        item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']);
+    }
 }
 //they want to create a directory
 if (isset($_POST['create_dir']) && $_POST['dirname']!='') {
@@ -174,7 +160,9 @@ if (isset($_GET['createdir'])) {
 	Display::display_normal_message($new_folder_text);
 } else {	//give them a link to create a directory
 ?>
-	<p><a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" />
+	<p>
+        <a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1">
+            <img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" />
             <?php echo(get_lang('CreateDir'));?>
         </a>
     </p>
@@ -184,7 +172,6 @@ if (isset($_GET['createdir'])) {
 
 <div id="folderselector">
 </div>
-
 <!-- start upload form -->
 <form action="<?php echo api_get_self(); ?>" method="POST" name="upload" enctype="multipart/form-data">
 <!-- <input type="hidden" name="MAX_FILE_SIZE" value="5400"> -->

+ 1 - 5
main/upload/upload.php

@@ -6,11 +6,7 @@
  * @package chamilo.upload
  * @author Yannick Warnier <ywarnier@beeznest.org>
  */
-/**
- * First, initialise the script
- */
-// global settings initialisation
-// also provides access to main api (inc/lib/main_api.lib.php)
+
 require_once '../inc/global.inc.php';
 
 // return to index if no tool is set

+ 1 - 3
main/upload/upload.scorm.php

@@ -7,9 +7,7 @@
  * @package chamilo.upload
  * @author Yannick Warnier <ywarnier@beeznest.org>
  */
-/**
- * Process the SCORM package and return to the SCORM tool
- */
+
 $cwdir = getcwd();
 require_once '../newscorm/lp_upload.php';
 

+ 1 - 4
main/upload/upload_ppt.php

@@ -6,9 +6,7 @@
  * @package chamilo.upload
  * @author Yannick Warnier <ywarnier@beeznest.org>
  */
-/**
- * First, initialise the script
- */
+
 require_once '../inc/global.inc.php';
 
 $htmlHeadXtra[] = '<script language="javascript" src="../inc/lib/javascript/upload.js" type="text/javascript"></script>';
@@ -91,7 +89,6 @@ if (api_get_setting('search_enabled') == 'true') {
 
 $form->addButtonUpload(get_lang('ConvertToLP'), 'convert');
 $form->addElement('hidden', 'ppt2lp', 'true');
-
 $form->add_real_progress_bar(md5(rand(0, 10000)), 'user_file', 1, true);
 $defaults = array('take_slide_name'=>'checked="checked"','index_document'=>'checked="checked"');
 $form->setDefaults($defaults);

+ 1 - 5
main/upload/upload_word.php

@@ -7,11 +7,7 @@
  * @package chamilo.upload
  * @author Yannick Warnier <ywarnier@beeznest.org>
  */
-/**
- * First, initialise the script
- */
-// global settings initialisation
-// also provides access to main api (inc/lib/main_api.lib.php)
+
 include '../inc/global.inc.php';
 
 $form_style= '<style>

+ 64 - 65
main/user/add_users_to_session.php

@@ -3,15 +3,15 @@
 /**
 *	@package chamilo.admin
 */
-// resetting the course id
+
 $cidReset = true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
 require_once '../inc/lib/xajax/xajax.inc.php';
-$xajax = new xajax();
 
-$xajax -> registerFunction ('search_users');
+$xajax = new xajax();
+$xajax->registerFunction('search_users');
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;
@@ -29,31 +29,33 @@ if (api_is_platform_admin()) {
 $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session');
 if($allowTutors == 'true') {
     // Database Table Definitions
-    $tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
-    $tbl_course							= Database::get_main_table(TABLE_MAIN_COURSE);
-    $tbl_user							= Database::get_main_table(TABLE_MAIN_USER);
-    $tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
+    $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+    $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
+    $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+    $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
 
     // setting the name of the tool
     $tool_name = get_lang('SubscribeUsersToSession');
-
     $add_type = 'unique';
 
     if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
-    	$add_type = Security::remove_XSS($_REQUEST['add_type']);
+        $add_type = Security::remove_XSS($_REQUEST['add_type']);
     }
 
     $page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
 
-    //checking for extra field with filter on
-
+    // Checking for extra field with filter on
     $extra_field_list= UserManager::get_extra_fields();
     $new_field_list = array();
     if (is_array($extra_field_list)) {
     	foreach ($extra_field_list as $extra_field) {
     		//if is enabled to filter and is a "<select>" field type
     		if ($extra_field[8]==1 && $extra_field[2]==4 ) {
-    			$new_field_list[] = array('name'=> $extra_field[3], 'variable'=>$extra_field[1], 'data'=> $extra_field[9]);
+                $new_field_list[] = array(
+                    'name' => $extra_field[3],
+                    'variable' => $extra_field[1],
+                    'data' => $extra_field[9],
+                );
     		}
     	}
     }
@@ -103,14 +105,16 @@ if($allowTutors == 'true') {
             switch ($type) {
                 case 'single':
                     // search users where username or firstname or lastname begins likes $needle
-                    $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
+                    $sql = 'SELECT user.user_id, username, lastname, firstname
+                            FROM '.$tbl_user.' user
                             WHERE (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%"
                                 OR lastname LIKE "'.$needle.'%") AND user.status<>6 AND user.status<>'.DRH.''.
                                 $order_clause.
                                 ' LIMIT 11';
                     break;
                 case 'multiple':
-                    $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
+                    $sql = 'SELECT user.user_id, username, lastname, firstname
+                            FROM '.$tbl_user.' user
                             WHERE '.(api_sort_by_first_name() ? 'firstname' : 'lastname').'
                             LIKE "'.$needle.'%" AND
                             user.status<>'.DRH.' AND
@@ -134,26 +138,34 @@ if($allowTutors == 'true') {
     			if ($access_url_id != -1) {
                     switch ($type) {
                         case 'single':
-                            $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-                            INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
-                            WHERE access_url_id = '.$access_url_id.'  AND (username LIKE "'.$needle.'%"
-                            OR firstname LIKE "'.$needle.'%"
-                            OR lastname LIKE "'.$needle.'%") AND user.status<>6 AND user.status<>'.DRH.' '.
-                            $order_clause.
-                            ' LIMIT 11';
+                            $sql = 'SELECT user.user_id, username, lastname, firstname
+                                    FROM '.$tbl_user.' user
+                                    INNER JOIN '.$tbl_user_rel_access_url.' url_user
+                                    ON (url_user.user_id=user.user_id)
+                                    WHERE
+                                        access_url_id = '.$access_url_id.' AND
+                                        (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%" OR lastname LIKE "'.$needle.'%") AND
+                                        user.status<>6 AND
+                                        user.status<>'.DRH.' '.
+                                    $order_clause.
+                                    ' LIMIT 11';
                             break;
                         case 'multiple':
-                            $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-                            INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
-                            WHERE access_url_id = '.$access_url_id.' AND
+                            $sql = 'SELECT user.user_id, username, lastname, firstname
+                                    FROM '.$tbl_user.' user
+                                    INNER JOIN '.$tbl_user_rel_access_url.' url_user
+                                    ON (url_user.user_id=user.user_id)
+                                    WHERE access_url_id = '.$access_url_id.' AND
                                     '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user.status<>'.DRH.' AND user.status<>6 '.$cond_user_id.
-                            $order_clause;
+                                    $order_clause;
                             break;
                         case 'any_session' :
                             $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname
-                                    FROM '.$tbl_user.' user LEFT OUTER JOIN '.$tbl_session_rel_user.' s
+                                    FROM '.$tbl_user.' user
+                                    LEFT OUTER JOIN '.$tbl_session_rel_user.' s
                                     ON (s.user_id = user.user_id)
-                                    INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
+                                    INNER JOIN '.$tbl_user_rel_access_url.' url_user
+                                    ON (url_user.user_id=user.user_id)
                                     WHERE
                                         access_url_id = '.$access_url_id.' AND
                                         s.user_id IS null AND
@@ -243,7 +255,6 @@ if($allowTutors == 'true') {
 
     </script>';
 
-
     $form_sent = 0;
     $errorMsg = $firstLetterUser = $firstLetterSession='';
     $UserList = $SessionList = array();
@@ -251,10 +262,10 @@ if($allowTutors == 'true') {
     $noPHP_SELF = true;
 
     if (isset($_POST['form_sent']) && $_POST['form_sent']) {
-        $form_sent             = $_POST['form_sent'];
-        $firstLetterUser       = $_POST['firstLetterUser'];
-        $firstLetterSession    = $_POST['firstLetterSession'];
-        $UserList              = $_POST['sessionUsersList'];
+        $form_sent = $_POST['form_sent'];
+        $firstLetterUser = $_POST['firstLetterUser'];
+        $firstLetterSession = $_POST['firstLetterSession'];
+        $UserList = $_POST['sessionUsersList'];
 
         if (!is_array($UserList)) {
             $UserList=array();
@@ -280,7 +291,7 @@ if($allowTutors == 'true') {
         $sql = "SELECT u.user_id, lastname, firstname, username, session_id
                 FROM $tbl_user u
                 INNER JOIN $tbl_session_rel_user
-                    ON $tbl_session_rel_user.user_id = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
+                ON $tbl_session_rel_user.user_id = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
                     AND $tbl_session_rel_user.session_id = ".intval($id_session)."
                 WHERE u.status<>".DRH." AND u.status<>6 $order_clause";
 
@@ -288,13 +299,13 @@ if($allowTutors == 'true') {
             $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1) {
-                $sql="SELECT u.user_id, lastname, firstname, username, session_id
-                FROM $tbl_user u
-                INNER JOIN $tbl_session_rel_user
-                    ON $tbl_session_rel_user.user_id = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                    AND $tbl_session_rel_user.session_id = ".intval($id_session)."
-                    INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
-                    WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
+                $sql = "SELECT u.user_id, lastname, firstname, username, session_id
+                        FROM $tbl_user u
+                        INNER JOIN $tbl_session_rel_user
+                        ON $tbl_session_rel_user.user_id = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
+                        AND $tbl_session_rel_user.session_id = ".intval($id_session)."
+                        INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
+                        WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
                     $order_clause";
             }
         }
@@ -315,7 +326,10 @@ if($allowTutors == 'true') {
                     if (UserManager::is_extra_field_available($new_field['variable'])) {
                         if (isset($_POST[$varname]) && $_POST[$varname]!='0') {
                             $use_extra_fields = true;
-                            $extra_field_result[]= UserManager::get_extra_user_data_by_value($new_field['variable'], $_POST[$varname]);
+                            $extra_field_result[] = UserManager::get_extra_user_data_by_value(
+                                $new_field['variable'],
+                                $_POST[$varname]
+                            );
                         }
                     }
                 }
@@ -327,7 +341,10 @@ if($allowTutors == 'true') {
            	if (count($extra_field_result)>1) {
     	    for($i=0;$i<count($extra_field_result)-1;$i++) {
                     if (is_array($extra_field_result[$i+1])) {
-                        $final_result  = array_intersect($extra_field_result[$i],$extra_field_result[$i+1]);
+                        $final_result = array_intersect(
+                            $extra_field_result[$i],
+                            $extra_field_result[$i + 1]
+                        );
                     }
                 }
             } else {
@@ -354,7 +371,7 @@ if($allowTutors == 'true') {
 
         if ($use_extra_fields) {
             $sql = "SELECT  u.user_id, lastname, firstname, username, session_id
-                   FROM $tbl_user u
+                    FROM $tbl_user u
                     LEFT JOIN $tbl_session_rel_user
                     ON $tbl_session_rel_user.user_id = u.user_id AND
                     $tbl_session_rel_user.session_id = '$id_session' AND
@@ -389,8 +406,8 @@ if($allowTutors == 'true') {
             }
         }
 
-        $result   = Database::query($sql);
-        $users    = Database::store_result($result,'ASSOC');
+        $result = Database::query($sql);
+        $users = Database::store_result($result,'ASSOC');
 
         foreach ($users as $uid => $user) {
             if ($user['session_id'] != $id_session) {
@@ -555,9 +572,8 @@ if($allowTutors == 'true') {
                     <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
                         <i class="fa fa-arrow-left"></i>
                     </button>
-
                   <?php
-                }
+            }
             ?>
             </div>
             <br />
@@ -568,11 +584,9 @@ if($allowTutors == 'true') {
             } else {
                 //@todo see that the call to "valide()" doesn't duplicate the onsubmit of the form (necessary to avoid delete on "enter" key pressed)
     			echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToSession').'</button>';
-
             }
     		?>
         </div>
-
         <div class="span5">
             <div class="multiple_select_header">
                 <b><?php echo get_lang('UserListInSession') ?> :</b>
@@ -592,9 +606,7 @@ if($allowTutors == 'true') {
     </form>
     <script>
     <!--
-    function moveItem(origin , destination)
-    {
-
+    function moveItem(origin , destination) {
     	for (var i = 0 ; i<origin.options.length ; i++) {
     		if (origin.options[i].selected) {
     			destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
@@ -604,12 +616,10 @@ if($allowTutors == 'true') {
     	}
     	destination.selectedIndex = -1;
     	sortOptions(destination.options);
-
     }
 
     function sortOptions(options)
     {
-
     	newOptions = new Array();
     	for (i = 0 ; i<options.length ; i++)
     		newOptions[i] = options[i];
@@ -618,7 +628,6 @@ if($allowTutors == 'true') {
     	options.length = 0;
     	for (i = 0 ; i < newOptions.length ; i++)
     		options[i] = newOptions[i];
-
     }
 
     function mysort(a, b)
@@ -643,9 +652,7 @@ if($allowTutors == 'true') {
 
     function loadUsersInSelect(select)
     {
-
     	var xhr_object = null;
-
     	if(window.XMLHttpRequest) // Firefox
     		xhr_object = new XMLHttpRequest();
     	else if(window.ActiveXObject) // Internet Explorer
@@ -655,16 +662,12 @@ if($allowTutors == 'true') {
 
     	//xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
     	xhr_object.open("POST", "loadUsersInSelect.ajax.php");
-
     	xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
-
     	nosessionUsers = makepost(document.getElementById('origin_users'));
     	sessionUsers = makepost(document.getElementById('destination_users'));
     	nosessionClasses = makepost(document.getElementById('origin_classes'));
     	sessionClasses = makepost(document.getElementById('destination_classes'));
     	xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
-
     	xhr_object.onreadystatechange = function() {
     		if (xhr_object.readyState == 4) {
     			document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
@@ -675,14 +678,11 @@ if($allowTutors == 'true') {
 
     function makepost(select)
     {
-
     	var options = select.options;
     	var ret = "";
     	for (i = 0 ; i<options.length ; i++)
     		ret = ret + options[i].value +'::'+options[i].text+";;";
-
     	return ret;
-
     }
     -->
     </script>
@@ -690,5 +690,4 @@ if($allowTutors == 'true') {
 } else {
     api_not_allowed();
 }
-/*		FOOTER */
 Display::display_footer();

+ 0 - 2
main/user/class.php

@@ -37,9 +37,7 @@ $(document).ready( function() {
 ';
 
 Display :: display_header($tool_name, "User");
-
 $usergroup = new UserGroup();
-
 if (api_is_allowed_to_edit()) {
     echo '<div class="actions">';
     if ($type == 'registered') {

+ 16 - 16
main/user/classes.php

@@ -4,13 +4,9 @@
  * @package chamilo.classes
  * @author Julio Montoya <gugli100@gmail.com>
  */
-/**
- * Init
- */
-$cidReset=true;
-require_once '../inc/global.inc.php';
 
-require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
+$cidReset = true;
+require_once '../inc/global.inc.php';
 
 api_block_anonymous_users();
 
@@ -21,25 +17,29 @@ if (isset($_GET['id'])) {
     $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Groups'));
 }
 
-if (api_get_setting('show_groups_to_users') == 'false') {
-
-}
-
 Display :: display_header($tool_name, 'Classes');
 
 $usergroup = new UserGroup();
 $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
 if (!empty($usergroup_list)) {
-    echo Display::tag('h1',get_lang('MyClasses'));
-    foreach($usergroup_list as $group_id) {
-        if (isset($_GET['id']) && $_GET['id'] != $group_id) continue;
-    	$data = $usergroup->get($group_id);
-        echo Display::tag('h2',$data['name']);
+    echo Display::tag('h1', get_lang('MyClasses'));
+    foreach ($usergroup_list as $group_id) {
+        if (isset($_GET['id']) && $_GET['id'] != $group_id) {
+            continue;
+        }
+        $data = $usergroup->get($group_id);
+        echo Display::tag('h2', $data['name']);
         echo Display::div($data['description']);
     }
 } else {
     if (api_is_platform_admin()) {
-        Display::display_normal_message(Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'), false);
+        Display::display_normal_message(
+            Display::url(
+                get_lang('AddClasses'),
+                api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'
+            ),
+            false
+        );
     }
 }
 

+ 32 - 38
main/user/resume_session.php

@@ -4,33 +4,29 @@
 *	@author Bart Mollet, Julio Montoya lot of fixes
 *	@package chamilo.admin
 */
-/*		INIT SECTION */
+
 $cidReset = true;
 require_once '../inc/global.inc.php';
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;
-
 $id_session = (int)$_GET['id_session'];
-
 SessionManager::protect_teacher_session_edit($id_session);
 
-
 $tool_name = get_lang('SessionOverview');
 
 $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session');
 if($allowTutors == 'true') {
     // Database Table Definitions
-    $tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
-    $tbl_session_rel_class				= Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
-    $tbl_session_rel_course				= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-    $tbl_course							= Database::get_main_table(TABLE_MAIN_COURSE);
-    $tbl_user							= Database::get_main_table(TABLE_MAIN_USER);
-    $tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-    $tbl_session_rel_course_rel_user	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-    $tbl_session_category				= Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
-
-    $table_access_url_user              = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
+    $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+    $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
+    $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+    $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
+    $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+    $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
+    $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+    $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
+    $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
 
     $sql = 'SELECT
               name,
@@ -47,10 +43,12 @@ if($allowTutors == 'true') {
               coach_access_end_date,
               session_category_id,
               visibility
-            FROM '.$tbl_session.' LEFT JOIN '.$tbl_user.' ON id_coach = user_id
+            FROM '.$tbl_session.'
+            LEFT JOIN '.$tbl_user.'
+            ON id_coach = user_id
             WHERE '.$tbl_session.'.id='.$id_session;
 
-    $rs      = Database::query($sql);
+    $rs = Database::query($sql);
     $session = Database::store_result($rs);
     $session = $session[0];
 
@@ -109,7 +107,6 @@ if($allowTutors == 'true') {
             if (!empty($_GET['user'])) {
                 $result = Database::query("DELETE FROM $tbl_session_rel_user WHERE relation_type<>".SESSION_RELATION_TYPE_RRHH." AND session_id ='$id_session' AND user_id=".intval($_GET['user']));
                 $nbr_affected_rows = Database::affected_rows($result);
-
                 Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'");
 
                 $result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id ='$id_session' AND user_id=".intval($_GET['user']));
@@ -130,8 +127,6 @@ if($allowTutors == 'true') {
     }
 
     echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']);
-
-
     echo Display::page_subheader(get_lang('GeneralProperties').$url);
 
     ?>
@@ -196,11 +191,9 @@ if($allowTutors == 'true') {
     		<?php if ($session['visibility']==1) echo get_lang('ReadOnly'); elseif($session['visibility']==2) echo get_lang('Visible');elseif($session['visibility']==3) echo api_ucfirst(get_lang('Invisible'))  ?>
     	</td>
     </tr>
-
     <?php
 
     $multiple_url_is_on = api_get_multiple_access_url();
-
     if ($multiple_url_is_on) {
         echo '<tr><td>';
         echo 'URL';
@@ -215,13 +208,9 @@ if($allowTutors == 'true') {
     ?>
     </table>
     <br />
-
     <?php
-
     echo Display::page_subheader(get_lang('CourseList').$url);
-
     ?>
-
     <!--List of courses -->
     <table class="data_table">
     <tr>
@@ -230,7 +219,7 @@ if($allowTutors == 'true') {
       <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
     </tr>
     <?php
-    if ($session['nbr_courses'] == 0){
+    if ($session['nbr_courses'] == 0) {
     	echo '<tr>
     			<td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
     		</tr>';
@@ -246,9 +235,13 @@ if($allowTutors == 'true') {
     	foreach ($courses as $course) {
     		//select the number of users
 
-    		$sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
-    				WHERE srcru.user_id = sru.user_id AND srcru.session_id = sru.session_id AND srcru.c_id = '".Database::escape_string($course['id'])."'
-    				AND sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND srcru.session_id = '".intval($id_session)."'";
+    		$sql = "SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
+                    WHERE
+                        srcru.user_id = sru.user_id AND
+                        srcru.session_id = sru.session_id AND
+                        srcru.c_id = '".Database::escape_string($course['id'])."'AND
+                        sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
+                        srcru.session_id = '".intval($id_session)."'";
 
     		$rs = Database::query($sql);
     		$course['nbr_users'] = Database::result($rs,0,0);
@@ -260,13 +253,17 @@ if($allowTutors == 'true') {
     				WHERE
     				    session_rcru.user_id = user.user_id AND
     				    session_rcru.session_id = '".intval($id_session)."' AND
-    				    session_rcru.c_id ='".Database::escape_string($course['id'])."' AND session_rcru.status=2";
+    				    session_rcru.c_id ='".Database::escape_string($course['id'])."' AND
+    				    session_rcru.status=2";
     		$rs = Database::query($sql);
 
     		$coachs = array();
     		if (Database::num_rows($rs) > 0) {
-    			while($info_coach = Database::fetch_array($rs)) {
-    				$coachs[] = api_get_person_name($info_coach['firstname'], $info_coach['lastname']).' ('.$info_coach['username'].')';
+    			while ($info_coach = Database::fetch_array($rs)) {
+                    $coachs[] = api_get_person_name(
+                            $info_coach['firstname'],
+                            $info_coach['lastname']
+                        ).' ('.$info_coach['username'].')';
     			}
     		} else {
     			$coach = get_lang('None');
@@ -292,15 +289,11 @@ if($allowTutors == 'true') {
     ?>
     </table>
     <br />
-
     <?php
-
     echo Display::page_subheader(get_lang('UserList').$url);
-
     ?>
 
     <!--List of users -->
-
     <table class="data_table">
         <tr>
             <th>
@@ -338,10 +331,11 @@ if($allowTutors == 'true') {
     	$result = Database::query($sql);
     	$users  = Database::store_result($result);
     	$orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
-    	foreach ($users as $user){
+    	foreach ($users as $user) {
             $user_link = '';
             if (!empty($user['user_id'])) {
-                $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']),ENT_QUOTES,$charset).' ('.$user['username'].')</a>';
+                $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.
+                    api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']),ENT_QUOTES,$charset).' ('.$user['username'].')</a>';
             }
 
             $link_to_add_user_in_url = '';

+ 1 - 8
main/user/session_list.php

@@ -4,9 +4,7 @@
  * List sessions in an efficient and usable way
  * @package chamilo.admin
  */
-/**
- * Code
- */
+
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
@@ -81,7 +79,6 @@ if($allowTutors == 'true') {
     }';
     ?>
     <script>
-
         function setSearchSelect(columnName) {
         $("#sessions").jqGrid('setColProp', columnName,
         {
@@ -96,14 +93,12 @@ if($allowTutors == 'true') {
         });
     }
 
-
     $(function() {
         <?php
             echo Display::grid_js('sessions', $url,$columns,$column_model,$extra_params, array(), $action_links,true);
         ?>
 
         setSearchSelect("status");
-
         $("#sessions").jqGrid('navGrid','#sessions_pager', {edit:false,add:false,del:false},
             {height:280,reloadAfterSubmit:false}, // edit options
             {height:280,reloadAfterSubmit:false}, // add options
@@ -128,8 +123,6 @@ if($allowTutors == 'true') {
             }
         },buttonicon:'ui-icon-document'})
         */
-
-
         //Adding search options
         var options = {
             'stringResult': true,

+ 16 - 17
main/user/subscribe_class.php

@@ -4,27 +4,20 @@
 /**
  * 	@package chamilo.user
  */
-/**
- * Code
- */
+
 include ('../inc/global.inc.php');
 $this_section = SECTION_COURSES;
 
-
 if (!api_is_allowed_to_edit()) {
     api_not_allowed();
     exit;
 }
 
-/*
-  MAIN CODE
- */
 $tool_name = get_lang("AddClassesToACourse");
 //extra entries in breadcrumb
 $interbreadcrumb[] = array("url" => "user.php", "name" => get_lang("ToolUser"));
 $interbreadcrumb[] = array("url" => "class.php", "name" => get_lang("Classes"));
 Display :: display_header($tool_name, "User");
-
 echo Display::page_header($tool_name);
 
 if (isset($_GET['register'])) {
@@ -51,10 +44,14 @@ if (isset($_POST['action'])) {
 /**
  *  * Get the number of classes to display on the current page.
  */
-function get_number_of_classes() {
+function get_number_of_classes()
+{
     $class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
     $course_class_table = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
-    $sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $_SESSION['_course']['id'] . "'";
+    $courseCode = api_get_course_id();
+
+    $sql = "SELECT * FROM $course_class_table
+            WHERE course_code = '" . $courseCode. "'";
     $res = Database::query($sql);
     $subscribed_classes = array();
     while ($obj = Database::fetch_object($res)) {
@@ -70,6 +67,7 @@ function get_number_of_classes() {
     }
     $res = Database::query($sql);
     $result = Database::num_rows($res);
+
     return $result;
 }
 
@@ -80,19 +78,20 @@ function get_class_data($from, $number_of_items, $column, $direction) {
     $class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
     $course_class_table = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
     $class_user_table = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
-    $sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $_SESSION['_course']['id'] . "'";
+    $courseCode = api_get_course_id();
+
+    $sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $courseCode . "'";
     $res = Database::query($sql);
     $subscribed_classes = array();
     while ($obj = Database::fetch_object($res)) {
         $subscribed_classes[] = $obj->class_id;
     }
     $sql = "SELECT
-							c.id AS col0,
-							c.name   AS col1,
-							COUNT(cu.user_id) AS col2,
-							c.id AS col3
-						FROM $class_table c
-						";
+                c.id AS col0,
+                c.name   AS col1,
+                COUNT(cu.user_id) AS col2,
+                c.id AS col3
+            FROM $class_table c ";
     $sql .= " LEFT JOIN $class_user_table cu ON cu.class_id = c.id";
     $sql .= " WHERE 1 = 1";
     if (isset($_GET['keyword'])) {

+ 23 - 13
main/user/subscribe_user.php

@@ -104,7 +104,7 @@ if (isset($_POST['action'])) {
         case 'subscribe':
             if (is_array($_POST['user'])) {
                 foreach ($_POST['user'] as $index => $user_id) {
-                    $user_id=intval($user_id);
+                    $user_id = intval($user_id);
                     if ($type == COURSEMANAGER) {
                         if (!empty($current_session_id)) {
                             $is_suscribe[] = SessionManager::set_coach_to_course_session(
@@ -139,16 +139,16 @@ if (isset($_POST['action'])) {
 
 			$list_register_user='';
 
-            for ($i=0; $i<$is_suscribe_counter;$i++) {
-                for ($j=0; $j<count($user_id_temp);$j++) {
-                    if ($is_suscribe_user_id[$i]==$user_id_temp[$j]) {
-                            if ($is_suscribe[$i]) {
-                                $list_register_user.=" - ".$user_name_temp[$j].'<br/>';
-                                $temp_unique_user=$user_name_temp[$j];
-                                $counter++;
-                            } else {
-                                $list_not_register_user.=" - ".$user_name_temp[$j].'<br/>';
-                            }
+            for ($i = 0; $i < $is_suscribe_counter; $i++) {
+                for ($j = 0; $j < count($user_id_temp); $j++) {
+                    if ($is_suscribe_user_id[$i] == $user_id_temp[$j]) {
+                        if ($is_suscribe[$i]) {
+                            $list_register_user .= " - ".$user_name_temp[$j].'<br/>';
+                            $temp_unique_user = $user_name_temp[$j];
+                            $counter++;
+                        } else {
+                            $list_not_register_user .= " - ".$user_name_temp[$j].'<br/>';
+                        }
                     }
                 }
             }
@@ -282,6 +282,9 @@ function get_number_of_users()
 	$tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 	$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
 
+    $courseCode = api_get_course_id();
+    $sessionId = api_get_session_id();
+
 	if (isset($_REQUEST['type']) && $_REQUEST['type']=='teacher') {
 
 		if (api_get_session_id() != 0) {
@@ -429,9 +432,15 @@ function get_number_of_users()
 
 		// getting all the users of the course (to make sure that we do not display users that are already in the course)
 		if (!empty($_SESSION["id_session"])) {
-			$a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], $_SESSION['id_session']);
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
+                $courseCode,
+                $sessionId
+            );
 		} else {
-			$a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], 0);
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
+                $courseCode,
+                0
+            );
 	    }
 		foreach ($a_course_users as $user_id=>$course_user) {
 			$users_of_course[] = $course_user['user_id'];
@@ -445,6 +454,7 @@ function get_number_of_users()
 	   $row = Database::fetch_row($res);
 	   $count_user = $row[0];
 	}
+
 	return $count_user;
 }
 /**

+ 1 - 2
main/user/user_import.php

@@ -1,8 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
 
+require_once '../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 
 // notice for unauthorized people.

+ 13 - 13
main/wiki/wiki.inc.php

@@ -553,7 +553,7 @@ class Wiki
         $_clean = array();
 
         // cleaning the variables
-        $_clean['assignment'] = null;
+        $_clean['assignment'] = '';
         if (isset($values['assignment'])) {
             $_clean['assignment'] = $values['assignment'];
         }
@@ -562,7 +562,7 @@ class Wiki
         $session_id = api_get_session_id();
         // Unlike ordinary pages of pages of assignments.
         // Allow create a ordinary page although there is a assignment with the same name
-        if ($_clean['assignment']==2 || $_clean['assignment']==1) {
+        if ($_clean['assignment'] == 2 || $_clean['assignment'] == 1) {
             $page = str_replace(' ','_',$values['title']."_uass".$assig_user_id);
         } else {
             $page = str_replace(' ','_',$values['title']);
@@ -604,13 +604,13 @@ class Wiki
         $_clean['linksto'] = self::links_to($_clean['content']);	//check wikilinks
 
         // cleaning config variables
-        $_clean['task'] = $values['task'];
-        $_clean['feedback1'] = $values['feedback1'];
-        $_clean['feedback2'] = $values['feedback2'];
-        $_clean['feedback3'] = $values['feedback3'];
-        $_clean['fprogress1'] = $values['fprogress1'];
-        $_clean['fprogress2'] = $values['fprogress2'];
-        $_clean['fprogress3'] = $values['fprogress3'];
+        $_clean['task'] = isset($values['task']) ? $values['task'] : '';
+        $_clean['feedback1'] = isset($values['feedback1']) ? $values['feedback1'] : '';
+        $_clean['feedback2'] = isset($values['feedback2']) ? $values['feedback2'] : '';
+        $_clean['feedback3'] = isset($values['feedback3']) ? $values['feedback3'] : '';
+        $_clean['fprogress1'] = isset($values['fprogress1']) ? $values['fprogress1'] : '';
+        $_clean['fprogress2'] = isset($values['fprogress2']) ? $values['fprogress2'] : '';
+        $_clean['fprogress3'] = isset($values['fprogress3']) ? $values['fprogress3'] : '';
 
         if (isset($values['initstartdate']) && $values['initstartdate'] == 1) {
             $_clean['startdate_assig'] = $values['startdate_assig'];
@@ -624,9 +624,9 @@ class Wiki
             $_clean['enddate_assig'] = '0000-00-00 00:00:00';
         }
 
-        $_clean['delayedsubmit'] = $values['delayedsubmit'];
-        $_clean['max_text'] = $values['max_text'];
-        $_clean['max_version'] = $values['max_version'];
+        $_clean['delayedsubmit'] = isset($values['delayedsubmit']) ? $values['delayedsubmit'] : '';
+        $_clean['max_text'] = isset($values['max_text']) ? $values['max_text'] : '';
+        $_clean['max_version'] = isset($values['max_version']) ? $values['max_version'] : '';
 
         $course_id = api_get_course_int_id();
 
@@ -826,7 +826,7 @@ class Wiki
                 //double post
 
             } else {
-                if ($values['assignment'] == 1) {
+                if (isset($values['assignment']) && $values['assignment'] == 1) {
                     self::auto_add_page_users($values);
                 }