소스 검색

Merge with 1.10.x

jmontoyaa 9 년 전
부모
커밋
b024e8dd8d

+ 2 - 2
main/admin/user_list.php

@@ -688,8 +688,8 @@ if (!empty($action)) {
 					$number_of_deleted_users = 0;
 					if (is_array($_POST['id'])) {
 						foreach ($_POST['id'] as $index => $user_id) {
-							if($user_id != $_user['user_id']) {
-								if(UserManager :: delete_user($user_id)) {
+							if ($user_id != $_user['user_id']) {
+								if (UserManager::delete_user($user_id)) {
 									$number_of_deleted_users++;
 								}
 							}

+ 1 - 1
main/course_info/infocours.php

@@ -606,7 +606,7 @@ if ($form->validate() && is_settings_editable()) {
         'activate_legal'
     );
 
-    $activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : '';
+    $activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : 0;
     $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
 
     $params = [

+ 12 - 9
main/dropbox/dropbox_class.inc.php

@@ -68,7 +68,7 @@ class Dropbox_Work
      * @param unknown_type $arg6
      * @return Dropbox_Work
      */
-    public function Dropbox_Work($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null)
+    public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null)
     {
         if (func_num_args() > 1) {
             $this->_createNewWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
@@ -148,9 +148,10 @@ class Dropbox_Work
                 'upload_date' => $this->upload_date,
                 'last_upload_date' => $this->last_upload_date,
                 'session_id' => api_get_session_id(),
+                'cat_id' => 0
 			];
-			$this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
 
+			$this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
 			if ($this->id) {
 				$sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
 				Database::query($sql);
@@ -248,7 +249,7 @@ class Dropbox_SentWork extends Dropbox_Work
 	 * @param unknown_type $arg7
 	 * @return Dropbox_SentWork
 	 */
-	function Dropbox_SentWork($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
+	public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
     {
 		if (func_num_args() > 1) {
 		    $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
@@ -274,7 +275,7 @@ class Dropbox_SentWork extends Dropbox_Work
         $_course = api_get_course_info();
 
 		// Call constructor of Dropbox_Work object
-        $this->Dropbox_Work(
+        parent::__construct(
             $uploader_id,
             $title,
             $description,
@@ -314,12 +315,14 @@ class Dropbox_SentWork extends Dropbox_Work
         $session_id = api_get_session_id();
         $uploader_id = $this->uploader_id;
         $user  = api_get_user_id();
+        $now = api_get_utc_datetime();
+
 		// Insert data in dropbox_post and dropbox_person table for each recipient
 		foreach ($this->recipients as $rec) {
             $file_id = (int)$this->id;
             $user_id = (int)$rec['id'];
-			$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id)
-                    VALUES ($course_id, $file_id, $user_id, $session_id)";
+			$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
+                    VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)";
 	        Database::query($sql);
             // If work already exists no error is generated
 
@@ -361,7 +364,7 @@ class Dropbox_SentWork extends Dropbox_Work
 	 *
 	 * @param unknown_type $id
 	 */
-	function _createExistingSentWork($id)
+	public function _createExistingSentWork($id)
     {
         $dropbox_cnf = getDropboxConf();
         $id = intval($id);
@@ -369,7 +372,7 @@ class Dropbox_SentWork extends Dropbox_Work
 		$course_id = api_get_course_int_id();
 
 		// Call constructor of Dropbox_Work object
-		$this->Dropbox_Work($id);
+		parent::__construct($id);
 
 		// Fill in recipients array
 		$this->recipients = array();
@@ -417,7 +420,7 @@ class Dropbox_Person
 	 * @param bool $isCourseTutor
 	 * @return Dropbox_Person
 	 */
-	function Dropbox_Person($userId, $isCourseAdmin, $isCourseTutor)
+	public function __construct($userId, $isCourseAdmin, $isCourseTutor)
     {
 	    $course_id = api_get_course_int_id();
 

+ 6 - 4
main/exercice/answer.class.php

@@ -275,7 +275,7 @@ class Answer
 	 */
     public function selectAutoId($id)
     {
-		return isset($this->autoId[$id]) ? $this->autoId[$id] : null;
+		return isset($this->autoId[$id]) ? $this->autoId[$id] : 0;
 	}
 
 	/**
@@ -572,12 +572,13 @@ class Answer
         $params = [
             'answer' => $answer,
             'comment' => $comment,
-            'correct' => $correct,
+            'correct' => intval($correct),
             'ponderation' => $weighting,
             'position' => $position,
             'destination' => $destination,
             'hotspot_coordinates' => $hotspot_coordinates,
-            'hotspot_type' => $hotspot_type,
+            'hotspot_type' => $hotspot_type
+
         ];
 
         Database::update($answerTable, $params, ['id_auto = ?' => $autoId]);
@@ -610,10 +611,11 @@ class Answer
 
             if (!isset($this->position[$i])) {
                 $params = [
+                    'id_auto' => $autoId,
                     'c_id' => $c_id,
                     'question_id' => $questionId,
                     'answer' => $answer,
-                    'correct' => $correct,
+                    'correct' => intval($correct),
                     'comment' => $comment,
                     'ponderation' => $weighting,
                     'position' => $position,

+ 5 - 1
main/forum/forumfunction.inc.php

@@ -601,6 +601,7 @@ function store_forumcategory($values, $courseInfo = array(), $showMessage = true
  */
 function store_forum($values, $courseInfo = array(), $returnId = false)
 {
+    $now = api_get_utc_datetime();
     $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
     $course_id = $courseInfo['real_id'];
     $session_id = api_get_session_id();
@@ -739,7 +740,9 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
             'moderated'=> isset($values['moderated']['moderated']) ? 1 : 0,
             'forum_order'=> isset($new_max) ? $new_max : null,
             'session_id'=> $session_id,
-            'lp_id' => isset($values['lp_id']) ? intval($values['lp_id']) : 0
+            'lp_id' => isset($values['lp_id']) ? intval($values['lp_id']) : 0,
+            'locked' => 0,
+            'forum_id' => 0
         ];
         $last_id = Database::insert($table_forums, $params);
         if ($last_id > 0) {
@@ -3290,6 +3293,7 @@ function store_reply($current_forum, $values)
                 'thread_id' => $values['thread_id'],
                 'forum_id' => $values['forum_id'],
                 'poster_id' => api_get_user_id(),
+                'post_id' => 0,
                 'post_date' => $post_date,
                 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : null,
                 'post_parent_id' => isset($values['post_parent_id']) ? $values['post_parent_id'] : null,

+ 2 - 1
main/gradebook/lib/GradebookUtils.php

@@ -701,10 +701,11 @@ class GradebookUtils
         $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document';
         $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
         $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
+        $print = '';
 
         //add print header
         if ($hide_print_button == false) {
-            $print = '<style media="print" type="text/css">#print_div {visibility:hidden;}</style>';
+            $print .= '<style media="print" type="text/css">#print_div {visibility:hidden;}</style>';
             $print .= '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div">';
             $print .= Display::return_icon('printmgr.gif', get_lang('Print'));
             $print .= '</a>';

+ 8 - 9
main/gradebook/lib/be/category.class.php

@@ -1895,6 +1895,7 @@ class Category implements GradebookItem
     }
 
     /**
+     * Generates a certificate for this user if everything matches
      * @param int $category_id
      * @param int $user_id
      * @return bool|string
@@ -1952,15 +1953,13 @@ class Category implements GradebookItem
         $userHasSkills = false;
 
         if ($skillToolEnabled) {
-            if ($category->getGenerateCertificates()) {
-                $skill = new Skill();
-                $skill->add_skill_to_user(
-                    $user_id,
-                    $category_id,
-                    $courseId,
-                    $sessionId
-                );
-            }
+            $skill = new Skill();
+            $skill->add_skill_to_user(
+                $user_id,
+                $category_id,
+                $courseId,
+                $sessionId
+            );
 
             $objSkillRelUser = new SkillRelUser();
             $userSkills = $objSkillRelUser->get_user_skills($user_id, $courseId, $sessionId);

+ 1 - 1
main/gradebook/lib/be/learnpathlink.class.php

@@ -120,7 +120,7 @@ class LearnpathLink extends AbstractLink
 		$scores = Database::query($sql);
 		// for 1 student
 		if (isset($stud_id)) {
-			if ($data = Database::fetch_array($scores)) {
+			if ($data = Database::fetch_assoc($scores)) {
 				return array ($data['progress'], 100);
 			} else
 				return null;

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

@@ -1584,7 +1584,8 @@ class Attendance
 			$params = array(
 				'c_id' =>  $course_id,
 				'date_time' => $this->date_time,
-				'attendance_id' => $attendance_id
+				'attendance_id' => $attendance_id,
+                'done_attendance' => 0
 			);
 			$id = Database::insert($tbl_attendance_calendar, $params);
 

+ 2 - 2
main/inc/lib/blog.lib.php

@@ -167,8 +167,8 @@ class Blog
             }
 
 			// Put it on course homepage
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id)
-					VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id')";
+			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target)
+					VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')";
 			Database::query($sql);
 
             $toolId = Database::insert_id();

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

@@ -5080,7 +5080,7 @@ class CourseManager
             // Create
             Database::insert(
                 $courseSettingTable,
-                array('value' => $value, 'c_id' => $courseId, 'variable' => $variable)
+                ['title' => $variable, 'value' => $value, 'c_id' => $courseId, 'variable' => $variable]
             );
         }
         return true;

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

@@ -287,7 +287,7 @@ function get_total_folder_size($path, $can_see_invisible = false)
     $visibility_rule = ' props.visibility ' . ($can_see_invisible ? '<> 2' : '= 1');
 
     $sql = "SELECT SUM(table1.size) FROM (
-                SELECT size
+                SELECT props.ref, size
                 FROM $table_itemproperty AS props, $table_document AS docs
                 WHERE
                     docs.c_id 	= $course_id AND

+ 6 - 6
main/inc/lib/pear/HTML/Table/Storage.php

@@ -137,7 +137,7 @@ class HTML_Table_Storage extends HTML_Common
      * @param   boolean   $useTGroups
      * @access  public
      */
-    function setUseTGroups($useTGroups)
+    public function setUseTGroups($useTGroups)
     {
         $this->_useTGroups = $useTGroups;
     }
@@ -147,7 +147,7 @@ class HTML_Table_Storage extends HTML_Common
      * @access   public
      * @return   boolean
      */
-    function getUseTGroups()
+    public function getUseTGroups()
     {
         return $this->_useTGroups;
     }
@@ -157,7 +157,7 @@ class HTML_Table_Storage extends HTML_Common
      * @param   mixed   $fill
      * @access  public
      */
-    function setAutoFill($fill)
+    public function setAutoFill($fill)
     {
         $this->_autoFill = $fill;
     }
@@ -167,7 +167,7 @@ class HTML_Table_Storage extends HTML_Common
      * @access   public
      * @return   mixed
      */
-    function getAutoFill()
+    public function getAutoFill()
     {
         return $this->_autoFill;
     }
@@ -177,7 +177,7 @@ class HTML_Table_Storage extends HTML_Common
      * @param    bool   $fill
      * @access   public
      */
-    function setAutoGrow($grow)
+    public function setAutoGrow($grow)
     {
         $this->_autoGrow = $grow;
     }
@@ -187,7 +187,7 @@ class HTML_Table_Storage extends HTML_Common
      * @access   public
      * @return   mixed
      */
-    function getAutoGrow()
+    public function getAutoGrow()
     {
         return $this->_autoGrow;
     }

+ 26 - 15
main/inc/lib/usermanager.lib.php

@@ -465,6 +465,7 @@ class UserManager
             ));
             $hook->notifyCreateUser(HOOK_EVENT_TYPE_POST);
         }
+
         return $return;
     }
 
@@ -655,9 +656,6 @@ class UserManager
                 WHERE lastedit_user_id = '".$user_id."'";
         Database::query($sql);
 
-
-
-
         // Delete user from database
         $sql = "DELETE FROM $table_user WHERE id = '".$user_id."'";
         Database::query($sql);
@@ -696,7 +694,7 @@ class UserManager
      * @assert (-1) === false
      * @assert (array(-1)) === false
      */
-    static function delete_users($ids = array())
+    public static function delete_users($ids = array())
     {
         $result = false;
         $ids = is_array($ids) ? $ids : func_get_args();
@@ -721,7 +719,7 @@ class UserManager
      * @assert (null) === false
      * @assert (array(-1)) === false
      */
-    static function deactivate_users($ids = array())
+    public static function deactivate_users($ids = array())
     {
         if (empty($ids)) {
             return false;
@@ -751,7 +749,7 @@ class UserManager
      * @assert (null) === false
      * @assert (array(-1)) === false
      */
-    static function activate_users($ids = array())
+    public static function activate_users($ids = array())
     {
         if (empty($ids)) {
             return false;
@@ -1277,6 +1275,7 @@ class UserManager
         while ($row = Database::fetch_array($rs)) {
             $result[] = $row;
         }
+
         return $result;
     }
 
@@ -1288,8 +1287,12 @@ class UserManager
      * @todo optional course code parameter, optional sorting parameters...
      * @todo security filter order by
      */
-    public static function get_user_list($conditions = array(), $order_by = array(), $limit_from = false, $limit_to = false)
-    {
+    public static function get_user_list(
+        $conditions = array(),
+        $order_by = array(),
+        $limit_from = false,
+        $limit_to = false
+    ) {
         $user_table = Database :: get_main_table(TABLE_MAIN_USER);
         $return_array = array();
         $sql_query = "SELECT * FROM $user_table";
@@ -1326,8 +1329,12 @@ class UserManager
      * @todo optional course code parameter, optional sorting parameters...
      * @todo security filter order_by
      */
-    public static function get_user_list_like($conditions = array(), $order_by = array(), $simple_like = false, $condition = 'AND')
-    {
+    public static function get_user_list_like(
+        $conditions = array(),
+        $order_by = array(),
+        $simple_like = false,
+        $condition = 'AND'
+    ) {
         $user_table = Database :: get_main_table(TABLE_MAIN_USER);
         $return_array = array();
         $sql_query = "SELECT * FROM $user_table";
@@ -1455,7 +1462,7 @@ class UserManager
                 try {
                     mkdir($rootPath, $perm);
                 } catch (Exception $e) {
-                    //
+                    error_log($e->getMessage());
                 }
             }
         }
@@ -1812,8 +1819,8 @@ class UserManager
     /**
      * Remove a user production.
      *
-     * @param   int $user_id        User id
-     * @param   string $production    The production to remove
+     * @param int $user_id        User id
+     * @param string $production    The production to remove
      */
     public static function remove_user_production($user_id, $production)
     {
@@ -2061,6 +2068,7 @@ class UserManager
     {
         $extraField = new ExtraField('user');
         $data = $extraField->get_handler_field_info_by_field_variable($variable);
+
         return empty($data) ? true : false;
     }
 
@@ -2728,7 +2736,8 @@ class UserManager
 
         $sql = "SELECT DISTINCT
                     c.visibility,
-                    c.id as real_id
+                    c.id as real_id,                    
+                    sc.position
                 FROM $tbl_session_course_user as scu
                 INNER JOIN $tbl_session_course sc
                 ON (scu.session_id = sc.session_id AND scu.c_id = sc.c_id)
@@ -2755,7 +2764,9 @@ class UserManager
 
         if (api_is_allowed_to_create_course()) {
             $sql = "SELECT DISTINCT
-                        c.visibility, c.id as real_id
+                        c.visibility, 
+                        c.id as real_id,
+                        sc.position
                     FROM $tbl_session_course_user as scu
                     INNER JOIN $tbl_session as s
                     ON (scu.session_id = s.id)

+ 8 - 6
main/newscorm/learnpath.class.php

@@ -4079,7 +4079,7 @@ class learnpath
 
     /**
      * Check that all prerequisites are fulfilled. Returns true and an
-     * empty string on succes, returns false
+     * empty string on success, returns false
      * and the prerequisite string on error.
      * This function is based on the rules for aicc_script language as
      * described in the SCORM 1.2 CAM documentation page 108.
@@ -8480,12 +8480,14 @@ class learnpath
         $i = 0;
 
         while ($row_zero = Database :: fetch_array($res_zero)) {
-            if ($row_zero['item_type'] == TOOL_QUIZ) {
-                $row_zero['title'] = Exercise::get_formated_title_variable($row_zero['title']);
+            if ($row_zero['item_type'] !== TOOL_LP_FINAL_ITEM) {
+                if ($row_zero['item_type'] == TOOL_QUIZ) {
+                    $row_zero['title'] = Exercise::get_formated_title_variable($row_zero['title']);
+                }
+                $js_var = json_encode(get_lang('After').' '.$row_zero['title']);
+                $return .= 'child_name[0][' . $i . '] = '.$js_var.' ;' . "\n";
+                $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
             }
-            $js_var = json_encode(get_lang('After').' '.$row_zero['title']);
-            $return .= 'child_name[0][' . $i . '] = '.$js_var.' ;' . "\n";
-            $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
         }
         $return .= "\n";
         $sql = "SELECT * FROM " . $tbl_lp_item . "

+ 180 - 96
main/newscorm/lp_final_item.php

@@ -1,123 +1,104 @@
 <?php
-
+/* For licensing terms, see /license.txt */
+/**
+ * Print a learning path finish page with details
+ * @author Jose Loguercio <jose.loguercio@beeznest.com>
+ * @package chamilo.learnpath
+ */
+// Initialize context
 $_in_course = true;
-require_once '../inc/global.inc.php';
+require_once __DIR__.'/../inc/global.inc.php';
 $current_course_tool  = TOOL_GRADEBOOK;
 
+// Make sure no anonymous user gets here without permission
 api_protect_course_script(true);
 
+// Get environment variables
 $courseCode = api_get_course_id();
 $userId = api_get_user_id();
 $sessionId = api_get_session_id();
 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
 $lpId = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : 0;
 
+// This page can only be shown from inside a learning path
 if (!$id && !$lpId) {
     Display::display_warning_message(get_lang('FileNotFound'));
     exit;
 }
 
-$catLoad = Category::load(null, null, $courseCode, null, null, $sessionId, 'ORDER By id');
-
-if (!$catLoad) {
-    Display::display_warning_message(get_lang('FileNotFound'));
-    exit;
-}
-
-$categoryId = $catLoad[0]->get_id();
-$link = LinkFactory::load(null, null, $lpId, null, $courseCode, $categoryId);
+// Initialize variables required for the template
 $downloadCertificateLink = '';
 $viewCertificateLink = '';
 $badgeLink = '';
-
-if ($link) {
-    $cat = new Category();
-    $catCourseCode     = CourseManager::get_course_by_category($categoryId);
-    $show_message  = $cat->show_message_resource_delete($catCourseCode);
-
-    if ($show_message == '') {
-        if (!api_is_allowed_to_edit() && !api_is_excluded_user_type()) {
-            $certificate = Category::register_user_certificate(
-                $categoryId,
-                $userId
-            );
-            if (isset($certificate['pdf_url']) && isset($certificate['certificate_link']) && isset($certificate['badge_link'])) {
-                $downloadCertificateLink .= Display::url(Display::returnFontAwesomeIcon('file-pdf-o') .
-                    get_lang('DownloadCertificatePdf'),
-                    $certificate['pdf_url'],
-                    ['class' => 'btn btn-default']
-                );
-                $viewCertificateLink .= $certificate['certificate_link'];
-                $downloadCertificateLink = "
-                    <div class='panel panel-default'>
-                        <div class='panel-body'>
-                            <h3 class='text-center'>".get_lang('NowDownloadYourCertificateClickHere')."</h3>
-                            <div class='text-center'>$downloadCertificateLink $viewCertificateLink</div>
-                        </div>
-                    </div>
-                ";
-
-                $skillRelUser = new SkillRelUser();
-                $courseId = api_get_course_int_id();
-                $userSkills = $skillRelUser->get_user_skills($userId, $courseId, $sessionId);
-                $skillList = '';
-
-                if ($userSkills) {
-                    $skill = new Skill();
-                    foreach ($userSkills as $userSkill) {
-                        $oneSkill = $skill->get($userSkill['skill_id']);
-                        $skillList .= "
-                            <div class='row'>
-                                <div class='col-md-2 col-xs-6'>
-                                    <div class='thumbnail'>
-                                      <img class='skill-badge-img' src='".$oneSkill['web_icon_path']."' >
-                                    </div>
-                                </div>
-                                <div class='col-md-8 col-xs-6'>
-                                    <h5><b>".$oneSkill['name']."</b></h5>
-                                    ".$oneSkill['description']."
-                                </div>
-                                <div class='col-md-2 col-xs-12'>
-                                    <h5><b>".get_lang('ShareWithYourFriends')."</b></h5>
-                                    <a href='http://www.facebook.com/sharer.php?u=".api_get_path(WEB_PATH)."badge/".$oneSkill['id']."/user/".$userId."' target='_new'>
-                                        <em class='fa fa-facebook-square fa-3x text-info' aria-hidden='true'></em>
-                                    </a>
-                                    <a href='https://twitter.com/home?status=".api_get_path(WEB_PATH)."badge/".$oneSkill['id']."/user/".$userId."' target='_new'>
-                                        <em class='fa fa-twitter-square fa-3x text-light' aria-hidden='true'></em>
-                                    </a>
-                                </div>
-                            </div>
-                        ";
+$finalItemTemplate = '';
+
+// Check prerequisites and total completion of the learning path
+$lp = new Learnpath($courseCode, $lpId, $userId);
+$count = $lp->get_total_items_count_without_chapters();
+$completed = $lp->get_complete_items_count();
+$currentItemId = $lp->get_current_item_id();
+$currentItem = $lp->items[$currentItemId];
+$currentItemStatus = $currentItem->get_status();
+$accessGranted = false;
+if (($count - $completed == 0) or (($count - $completed == 1 && ($currentItemStatus == 'incomplete') or ($currentItemStatus == 'not attempted') ))) {
+    if ($lp->prerequisites_match($currentItemId)) {
+        $accessGranted = true;
+    }
+}
+// Update the progress in DB from the items completed
+$lp->save_last();
+
+// unset the (heavy) lp object to free memory - we don't need it anymore
+unset($lp);
+unset($currentItem);
+
+// If for some reason we consider the requirements haven't been completed yet,
+// show a prerequisites warning
+if ($accessGranted == false) {
+    Display::display_warning_message(get_lang('LearnpathPrereqNotCompleted'));
+    $finalItemTemplate = '';
+} else {
+    $catLoad = Category::load(null, null, $courseCode, null, null, $sessionId, 'ORDER By id');
+    // If not gradebook has been defined
+    if (empty($catLoad)) {
+
+        $finalItemTemplate = generateLPFinalItemTemplate($id, $courseCode, $sessionId, $downloadCertificateLink,
+            $badgeLink);
+        // TODO: Missing validation of learning path completion
+
+    } else {
+        // A gradebook was found, proceed...
+        $categoryId = $catLoad[0]->get_id();
+        $link = LinkFactory::load(null, null, $lpId, null, $courseCode, $categoryId);
+
+        if ($link) {
+            $cat = new Category();
+            $catCourseCode = CourseManager::get_course_by_category($categoryId);
+            $show_message = $cat->show_message_resource_delete($catCourseCode);
+
+            if ($show_message == '') {
+                if (!api_is_allowed_to_edit() && !api_is_excluded_user_type()) {
+                    $certificate = Category::register_user_certificate(
+                        $categoryId,
+                        $userId
+                    );
+                    if (!empty($certificate['pdf_url']) || !empty($certificate['badge_link'])) {
+                        if (is_array($certificate) && isset($certificate['pdf_url'])) {
+                            $downloadCertificateLink = generateLPFinalItemTemplateCertificateLinks($certificate);
+                        }
+
+                        if (is_array($certificate) && isset($certificate['badge_link'])) {
+                            $courseId = api_get_course_int_id();
+                            $badgeLink = generateLPFinalItemTemplateBadgeLinks($userId, $courseId, $sessionId);
+                        }
                     }
-                    $badgeLink .= "
-                        <div class='panel panel-default'>
-                            <div class='panel-body'>
-                                <h3 class='text-center'>".get_lang('AdditionallyYouHaveObtainedTheFollowingSkills')."</h3>
-                                $skillList
-                            </div>
-                        </div>
-                    ";
+                    $currentScore = Category::getCurrentScore($userId, $categoryId, $courseCode, $sessionId, true);
+                    Category::registerCurrentScore($currentScore, $userId, $categoryId);
                 }
-
-                $documentInfo = DocumentManager::get_document_data_by_id(
-                    $id,
-                    $courseCode,
-                    true,
-                    $sessionId
-                );
-
-                $finalItemTemplate = file_get_contents($documentInfo['absolute_path']);
-
-                $finalItemTemplate = str_replace('((certificate))', $downloadCertificateLink, $finalItemTemplate);
-                $finalItemTemplate = str_replace('((skill))', $badgeLink, $finalItemTemplate);
-            } else {
-                Display::display_warning_message(get_lang('LearnpathPrereqNotCompleted'));
-                $finalItemTemplate = '';
             }
-
-            $currentScore = Category::getCurrentScore($userId, $categoryId, $courseCode, $sessionId, true);
-            Category::registerCurrentScore($currentScore, $userId, $categoryId);
         }
+        $finalItemTemplate = generateLPFinalItemTemplate($id, $courseCode, $sessionId, $downloadCertificateLink,
+            $badgeLink);
     }
 }
 
@@ -126,3 +107,106 @@ $tpl = new Template(null, false, false);
 $tpl->assign('content', $finalItemTemplate);
 $tpl->display_one_col_template();
 
+// A few functions used only here...
+
+/**
+ * Return a HTML string to show as final document in learning path
+ * @param int $lpItemId
+ * @param string $courseCode
+ * @param int $sessionId
+ * @param string $downloadCertificateLink
+ * @param string $badgeLink
+ * @return mixed|string
+ */
+function generateLPFinalItemTemplate($lpItemId, $courseCode, $sessionId=0, $downloadCertificateLink='', $badgeLink='')
+{
+    $documentInfo = DocumentManager::get_document_data_by_id(
+        $lpItemId,
+        $courseCode,
+        true,
+        $sessionId
+    );
+
+    $finalItemTemplate = file_get_contents($documentInfo['absolute_path']);
+
+    $finalItemTemplate = str_replace('((certificate))', $downloadCertificateLink, $finalItemTemplate);
+    $finalItemTemplate = str_replace('((skill))', $badgeLink, $finalItemTemplate);
+    return $finalItemTemplate;
+}
+
+/**
+ * Return HTML string with badges list
+ * @param int $userId
+ * @param int $courseId
+ * @param int $sessionId
+ * @return string HTML string for badges
+ */
+function generateLPFinalItemTemplateBadgeLinks($userId, $courseId, $sessionId=0)
+{
+    $skillRelUser = new SkillRelUser();
+    $userSkills = $skillRelUser->get_user_skills($userId, $courseId, $sessionId);
+    $skillList = '';
+    $badgeLink = '';
+
+    if ($userSkills) {
+        $skill = new Skill();
+        foreach ($userSkills as $userSkill) {
+            $oneSkill = $skill->get($userSkill['skill_id']);
+            $skillList .= "
+                                    <div class='row'>
+                                        <div class='col-md-2 col-xs-6'>
+                                            <div class='thumbnail'>
+                                              <img class='skill-badge-img' src='" . $oneSkill['web_icon_path'] . "' >
+                                            </div>
+                                        </div>
+                                        <div class='col-md-8 col-xs-6'>
+                                            <h5><b>" . $oneSkill['name'] . "</b></h5>
+                                            " . $oneSkill['description'] . "
+                                        </div>
+                                        <div class='col-md-2 col-xs-12'>
+                                            <h5><b>" . get_lang('ShareWithYourFriends') . "</b></h5>
+                                            <a href='http://www.facebook.com/sharer.php?u=" . api_get_path(WEB_PATH) . "badge/" . $oneSkill['id'] . "/user/" . $userId . "' target='_new'>
+                                                <em class='fa fa-facebook-square fa-3x text-info' aria-hidden='true'></em>
+                                            </a>
+                                            <a href='https://twitter.com/home?status=" . api_get_path(WEB_PATH) . "badge/" . $oneSkill['id'] . "/user/" . $userId . "' target='_new'>
+                                                <em class='fa fa-twitter-square fa-3x text-light' aria-hidden='true'></em>
+                                            </a>
+                                        </div>
+                                    </div>
+                                ";
+        }
+        $badgeLink .= "
+                                <div class='panel panel-default'>
+                                    <div class='panel-body'>
+                                        <h3 class='text-center'>" . get_lang('AdditionallyYouHaveObtainedTheFollowingSkills') . "</h3>
+                                        $skillList
+                                    </div>
+                                </div>
+                            ";
+    }
+    return $badgeLink;
+}
+
+/**
+ * Return HTML string with certificate links
+ * @param array $certificate
+ * @return string HTML string for certificates
+ */
+function generateLPFinalItemTemplateCertificateLinks($certificate)
+{
+    $downloadCertificateLink = Display::url(Display::returnFontAwesomeIcon('file-pdf-o') .
+        get_lang('DownloadCertificatePdf'),
+        $certificate['pdf_url'],
+        ['class' => 'btn btn-default']
+    );
+    $viewCertificateLink = $certificate['certificate_link'];
+    $downloadCertificateLink = "
+                            <div class='panel panel-default'>
+                                <div class='panel-body'>
+                                    <h3 class='text-center'>" . get_lang('NowDownloadYourCertificateClickHere') . "</h3>
+                                    <div class='text-center'>$downloadCertificateLink $viewCertificateLink</div>
+                                </div>
+                            </div>
+                        ";
+    return $downloadCertificateLink;
+}

+ 1 - 1
main/newscorm/resourcelinker.inc.php

@@ -1725,7 +1725,7 @@ function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_pa
             Session::write('officedoc',$officedoc);
             break;
         case TOOL_LP_FINAL_ITEM:
-            $link .= api_get_path(WEB_CODE_PATH).'newscorm/lp_final_item.php?id='.$id.'&lp_id='.$learnpath_id;
+            $link .= api_get_path(WEB_CODE_PATH).'newscorm/lp_final_item.php?'.api_get_cidreq().'&id='.$id.'&lp_id='.$learnpath_id;
             break;
         case 'assignments':
             $link .= $main_dir_path.'work/work.php?origin='.$origin;

+ 10 - 8
main/wiki/wiki.inc.php

@@ -280,8 +280,8 @@ class Wiki
             'fprogress1' => '',
             'fprogress2' => '',
             'fprogress3' => '',
-            'max_text' => '',
-            'max_version' => '',
+            'max_text' => 0,
+            'max_version' => 0,
             'delayedsubmit' => '',
             'assignment' => 0
         );
@@ -360,7 +360,9 @@ class Wiki
             'session_id' => $session_id,
             'page_id' => $values['page_id'],
             'editlock' => 0,
-            'is_editing' => 0
+            'is_editing' => 0,
+            'time_edit' => $time,
+            'tag' => ''
         ];
 
         $id = Database::insert($tbl_wiki, $params);
@@ -398,8 +400,8 @@ class Wiki
                 'fprogress1' => $_clean['fprogress1'],
                 'fprogress2' => $_clean['fprogress2'],
                 'fprogress3' => $_clean['fprogress3'],
-                'max_text' => $_clean['max_text'],
-                'max_version' => $_clean['max_version'],
+                'max_text' => intval($_clean['max_text']),
+                'max_version' => intval($_clean['max_version']),
                 'startdate_assig' => $_clean['startdate_assig'],
                 'enddate_assig' => $_clean['enddate_assig'],
                 'delayedsubmit' => $_clean['delayedsubmit']
@@ -415,8 +417,8 @@ class Wiki
                 'fprogress1' => $_clean['fprogress1'],
                 'fprogress2' => $_clean['fprogress2'],
                 'fprogress3' => $_clean['fprogress3'],
-                'max_text' => $_clean['max_text'],
-                'max_version' => $_clean['max_version'],
+                'max_text' => intval($_clean['max_text']),
+                'max_version' => intval($_clean['max_version']),
                 'startdate_assig' => $_clean['startdate_assig'],
                 'enddate_assig' => $_clean['enddate_assig'],
                 'delayedsubmit' => $_clean['delayedsubmit']
@@ -4950,7 +4952,7 @@ class Wiki
                         }
                     }
 
-                    if (!empty($row['max_text']) && $row['max_text']<=self::word_count($row['content'])) {
+                    if (!empty($row['max_text']) && $row['max_text'] <= self::word_count($row['content'])) {
                         $message = get_lang('HasReachedMaxNumWords');
                         Display::addFlash(
                             Display::return_message(