diff --git a/main/newscorm/learnpath_functions.inc.php b/main/newscorm/learnpath_functions.inc.php index c13c2ce14e..582e332702 100755 --- a/main/newscorm/learnpath_functions.inc.php +++ b/main/newscorm/learnpath_functions.inc.php @@ -1,59 +1,58 @@ , main author -* @author Roan Embrechts, some code cleaning -* @author Yannick Warnier , multi-level learnpath behaviour + new SCORM tool -* @access public -* @package chamilo.learnpath -* @todo rename functions to coding conventions: not deleteitem but delete_item, etc -* @todo rewrite functions to comply with phpDocumentor -* @todo remove code duplication -*/ + * This is a function library for the learning path. + * + * Due to the face that the learning path has been built upon the resoucelinker, + * naming conventions have changed at least 2 times. You can see here in order the : + * 1. name used in the first version of the resourcelinker + * 2. name used in the first version of the LP + * 3. name used in the second (current) version of the LP + * + * 1. 2. 3. + * Category = Chapter = Module + * Item (?) = Item = Step + * + * @author Denes Nagy , main author + * @author Roan Embrechts, some code cleaning + * @author Yannick Warnier , multi-level learnpath behaviour + new SCORM tool + * @access public + * @package chamilo.learnpath + * @todo rename functions to coding conventions: not deleteitem but delete_item, etc + * @todo rewrite functions to comply with phpDocumentor + * @todo remove code duplication + */ + /** * This function deletes an item * @param integer $id: the item we want to delete * @return boolean True if item was deleted, false if not found or error - **/ -function deleteitem($id) -{ + */ +function deleteitem($id) { $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); - //get the display order for this item before it is deleted + // Get the display order for this item before it is deleted. $sql = "SELECT display_order, parent_item_id FROM $tbl_lp_item WHERE id=$id"; $result = Database::query($sql); - if (Database::num_rows($result) == 0) - { + if (Database::num_rows($result) == 0) { return false; } $row = Database::fetch_row($result); $display_order = $row[0]; $parent_item_id = $row[1]; - // delete the item + // Delete the item. $sql = "DELETE FROM $tbl_learnpath_item WHERE id='$id'"; $result = Database::query($sql); - if ($result === false) - { + if ($result === false) { return false; } - // update the other items and chapters + // Update the other items and chapters. $sql = "UPDATE $tbl_learnpath_item SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_item_id"; $result = Database::query($sql); $sql = "UPDATE $tbl_learnpath_chapter SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_item_id"; $result = Database::query($sql); - //return + return true; } @@ -62,33 +61,28 @@ function deleteitem($id) * * @param integer id of the chapter we want to delete * @return boolean True on success and false if not found or error - **/ -function deletemodule($parent_item_id) -{ + */ +function deletemodule($parent_item_id) { global $learnpath_id; $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); - //Added for multi-level behaviour - slightly recursive + // Added for multi-level behaviour - slightly recursive. $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$learnpath_id"; $result = Database::query($sql); - while ($row = Database::fetch_array($result)) - { - if ($row['parent_item_id'] == $parent_item_id) - { - //delete every subchapter - if (deletemodule($row['id']) === false) - { + while ($row = Database::fetch_array($result)) { + if ($row['parent_item_id'] == $parent_item_id) { + // Delete every subchapter. + if (deletemodule($row['id']) === false) { return false; } } } - //get this chapter's display order + // Get this chapter's display order. $sql = "SELECT display_order, parent_item_id FROM $tbl_learnpath_chapter WHERE id=$parent_item_id and lp_id=$learnpath_id"; $result = Database::query($sql); - if (Database::num_rows($result) == 0) - { + if (Database::num_rows($result) == 0) { return false; } $row = Database::fetch_row($result); @@ -96,14 +90,14 @@ function deletemodule($parent_item_id) $display_order = $row[0]; $parent_id = $row[1]; - //delete the chapter itself + // Delete the chapter itself. $sql = "DELETE FROM $tbl_learnpath_chapter WHERE (id=$parent_item_id and lp_id=$learnpath_id)"; $result = Database::query($sql); - //delete items from that chapter + // Delete items from that chapter. $sql2 = "DELETE FROM $tbl_learnpath_item WHERE parent_item_id=$parent_item_id"; $result = Database::query($sql2); - //update all other chapters accordingly + // Update all other chapters accordingly. $sql = "UPDATE $tbl_learnpath_item SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_id"; $result = Database::query($sql); $sql = "UPDATE $tbl_learnpath_chapter SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_id"; @@ -117,9 +111,8 @@ function deletemodule($parent_item_id) * * @param integer $id: the path we want to delete * @return void - **/ -function deletepath($path_id) -{ + */ +function deletepath($path_id) { $tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); @@ -131,8 +124,7 @@ function deletepath($path_id) //also delete all elements inside that path $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$path_id"; $result = Database::query($sql); - while ($row = Database::fetch_array($result)) - { + while ($row = Database::fetch_array($result)) { deletemodule($row['id']); } } @@ -145,9 +137,8 @@ function deletepath($path_id) * @param integer $moduleid: the id of the chapter the element resides in * @return boolean Returns false on error * @note With this new version, the moveitem deals with items AND directories (not the base-level modules). This is a lot more complicated but is a temporary step towards new database structure as 'everything is an item' - **/ -function moveitem($direction, $id, $moduleid, $type = 'item') -{ + */ +function moveitem($direction, $id, $moduleid, $type = 'item') { global $learnpath_id; $tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER); @@ -156,11 +147,9 @@ function moveitem($direction, $id, $moduleid, $type = 'item') $orig_order = 0; $orig_type = ''; $orig_id = $id; - foreach ($tree[$moduleid] as $row) - { - //if this is the element we want (be it a chapter or an item), get its data - if (($row['id'] == $id) && ($row['type'] == $type)) - { + foreach ($tree[$moduleid] as $row) { + // If this is the element we want (be it a chapter or an item), get its data. + if (($row['id'] == $id) && ($row['type'] == $type)) { $orig_order = $row['display_order']; $orig_type = $row['type']; break; @@ -170,59 +159,40 @@ function moveitem($direction, $id, $moduleid, $type = 'item') $dest_order = 0; $dest_type = ''; $dest_id = 0; - if ($direction == "up") - { - if (!empty ($tree[$moduleid][$orig_order -1])) - { - $dest_order = $orig_order -1; - $dest_type = $tree[$moduleid][$orig_order -1]['type']; - $dest_id = $tree[$moduleid][$orig_order -1]['id']; - } - else - { + if ($direction == 'up') { + if (!empty ($tree[$moduleid][$orig_order - 1])) { + $dest_order = $orig_order - 1; + $dest_type = $tree[$moduleid][$orig_order - 1]['type']; + $dest_id = $tree[$moduleid][$orig_order - 1]['id']; + } else { return false; } - } - else - { - //move down - if (!empty ($tree[$moduleid][$orig_order +1])) - { - $dest_order = $orig_order +1; - $dest_type = $tree[$moduleid][$orig_order +1]['type']; - $dest_id = $tree[$moduleid][$orig_order +1]['id']; - } - else - { + } else { + // Move down. + if (!empty ($tree[$moduleid][$orig_order + 1])) { + $dest_order = $orig_order + 1; + $dest_type = $tree[$moduleid][$orig_order + 1]['type']; + $dest_id = $tree[$moduleid][$orig_order + 1]['id']; + } else { return false; } } $sql1 = ''; $sql2 = ''; - if ($orig_type == 'chapter') - { + if ($orig_type == 'chapter') { $sql1 = "UPDATE $tbl_learnpath_chapter SET display_order = ".$dest_order." WHERE (id=$orig_id and parent_item_id=$moduleid)"; - } - elseif ($orig_type == 'item') - { + } elseif ($orig_type == 'item') { $sql1 = "UPDATE $tbl_learnpath_item SET display_order = ".$dest_order." WHERE (id=$orig_id and parent_item_id=$moduleid)"; - } - else - { + } else { return false; } - if ($dest_type == 'chapter') - { + if ($dest_type == 'chapter') { $sql2 = "UPDATE $tbl_learnpath_chapter SET display_order = ".$orig_order." WHERE (id='$dest_id' and parent_item_id=$moduleid)"; - } - elseif ($dest_type == 'item') - { + } elseif ($dest_type == 'item') { $sql2 = "UPDATE $tbl_learnpath_item SET display_order = ".$orig_order." WHERE (id='$dest_id' and parent_item_id=$moduleid)"; - } - else - { + } else { return false; } Database::query($sql1); @@ -235,35 +205,29 @@ function moveitem($direction, $id, $moduleid, $type = 'item') * @param string $direction: move the given chapter up or down * @param integer $id: the id of the chapter we want to move * @return void - **/ -function movemodule($direction, $id) -{ + */ +function movemodule($direction, $id) { global $learnpath_id; $tbl_learnpath_chapter = Database :: get_course_learnpath_chapter_table(); - if ($direction == "up") - { - $sortDirection = "DESC"; - } - else - { - $sortDirection = "ASC"; + if ($direction == 'up') { + $sortDirection = 'DESC'; + } else { + $sortDirection = 'ASC'; } - // Select all chapters of first level (parent_item_id = 0) + // Select all chapters of first level (parent_item_id = 0). $sql = "SELECT * FROM $tbl_learnpath_chapter where (lp_id=$learnpath_id AND parent_item_id = 0) ORDER BY display_order $sortDirection"; $result = Database::query($sql); - $previousrow = ""; + $previousrow = ''; - // see similar comment in moveitem() function + // See similar comment in moveitem() function. // @TODO: this only works for chapters in multi-level mode. Why not gather // this function and moveitem to keep only one multi-uses function? - while ($row = Database::fetch_array($result)) - { - // step 2: performing the move (only happens when passed trhough step 1 at least once) - if (!empty ($this_cat_order)) - { - $next_cat_order = $row["display_order"]; - $next_cat_id = $row["id"]; + while ($row = Database::fetch_array($result)) { + // Step 2: Performing the move (only happens when passed trhough step 1 at least once). + if (!empty ($this_cat_order)) { + $next_cat_order = $row['display_order']; + $next_cat_id = $row['id']; $sql1 = "UPDATE $tbl_learnpath_chapter SET display_order = '$next_cat_order' WHERE (id='$this_cat_id' and lp_id=$learnpath_id)"; $sql2 = "UPDATE $tbl_learnpath_chapter SET display_order = '$this_cat_order' WHERE (id='$next_cat_id' and lp_id=$learnpath_id)"; @@ -276,14 +240,12 @@ function movemodule($direction, $id) break; } - // step 1: looking for the order of the row we want to move - if ($row["id"] == $id) - { - $this_cat_order = $row["display_order"]; + // Step 1: Looking for the order of the row we want to move. + if ($row['id'] == $id) { + $this_cat_order = $row['display_order']; $this_cat_id = $id; } } - } /** @@ -298,31 +260,29 @@ function movemodule($direction, $id) * @TODO Finish this function before it is used. Currently only chapters can be added using it. * @note This function is currently never used! */ -function insert_item($type = 'item', $name, $chapter_description = '', $parent_id = 0, $learnpath_id = 0, $params = null) -{ +function insert_item($type = 'item', $name, $chapter_description = '', $parent_id = 0, $learnpath_id = 0, $params = null) { $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); - // getting the last order number from the chapters table, in this learnpath, for the parent chapter given + // Getting the last order number from the chapters table, in this learnpath, for the parent chapter given. $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$learnpath_id AND parent_item_id = $parent_id ORDER BY display_order DESC"; $result = Database::query($sql); $row = Database::fetch_array($result); - $last_chapter_order = $row["display_order"]; + $last_chapter_order = $row['display_order']; - // getting the last order number of the items + // Getting the last order number of the items. $sql = "SELECT * FROM $tbl_learnpath_item AND parent_item_id = $parent_id ORDER BY display_order DESC"; $result = Database::query($sql); $row = Database::fetch_array($result); - $last_item_order = $row["display_order"]; + $last_item_order = $row['display_order']; $new_order = max($last_chapter_order, $last_item_order) + 1; - if ($type === 'chapter') - { + if ($type === 'chapter') { $sql = "INSERT INTO $tbl_learnpath_chapter (lp_id, chapter_name, chapter_description, display_order) VALUES ('".domesticate($learnpath_id)."', @@ -330,14 +290,11 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i '".domesticate(htmlspecialchars($chapter_description))."', $new_order )"; $result = Database::query($sql); - if ($result === false) - { + if ($result === false) { return false; } $id = Database :: insert_id(); - } - elseif ($type === 'item') - { + } elseif ($type === 'item') { $sql = "INSERT INTO $tbl_learnpath_item (parent_item_id, item_type, item_id, display_order) VALUES ('".domesticate($parent_id)."', @@ -345,8 +302,7 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i '".domesticate(htmlspecialchars($item_id))."', $new_order )"; $result = Database::query($sql); - if ($result === false) - { + if ($result === false) { return false; } $id = Database :: insert_id(); @@ -357,21 +313,19 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i /** * This function returns an array with all the learnpath categories/chapters * @return array List of learnpath chapter titles - **/ -function array_learnpath_categories() -{ - #global $tbl_learnpath_chapter; + */ +function array_learnpath_categories() { + //global $tbl_learnpath_chapter; global $learnpath_id; $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id) ORDER BY display_order ASC"; $result = Database::query($sql); - while ($row = Database::fetch_array($result)) - { - $array_learnpath_categories[] = array ($row["id"], $row["chapter_name"]); + while ($row = Database::fetch_array($result)) { + $array_learnpath_categories[] = array($row['id'], $row['chapter_name']); } - //$array_learnpath_categories=array($array_learnpath_categories_name,$array_learnpath_categories_id); + //$array_learnpath_categories = array($array_learnpath_categories_name, $array_learnpath_categories_id); return $array_learnpath_categories; } @@ -385,15 +339,13 @@ function array_learnpath_categories() * @author Roan Embrechts * @author Yannick Warnier - complete redesign for multi-level learnpath chapters */ -function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $level = 0) -{ - //error_log('New LP - In learnpath_functions::display_learnpath_chapters',0); +function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $level = 0) { + //error_log('New LP - In learnpath_functions::display_learnpath_chapters', 0); global $color2; global $xml_output; global $learnpath_id; $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); - // @todo: coding standards: Language variables are CaMMelCaSe, all other variables should use the underscoring method. $lang_move_down = get_lang('_move_down'); $lang_move_up = get_lang('lang_move_up'); @@ -410,28 +362,23 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve $lang_add_title_and_desc = get_lang('lang_add_title_and_desc'); $lang_delete = get_lang('Delete'); - if ($parent_item_id === 0) - { - // this is the first time we use the function, define the tree and display learnpath name + if ($parent_item_id === 0) { + // This is the first time we use the function, define the tree and display learnpath name. $tree = get_learnpath_tree($learnpath_id); $num_modules = count($tree); - //$num_modules=Database::num_rows($result); - if ($num_modules == 0) - { + //$num_modules = Database::num_rows($result); + if ($num_modules == 0) { // do not diplay useless information //echo " $lang_nochapters"; - } - else - { + } else { echo " \n"."  $lang_title_and_desc \n"."  $lang_add_item \n"; - if (is_prereq($learnpath_id)) - { + if (is_prereq($learnpath_id)) { echo "  $lang_prerequisites_limit \n"; - } - else + } else { echo "  $lang_prerequisites \n"; + } echo "  $lang_change_order  $lang_add_prereqi \n"."  $lang_add_title_and_desc  $lang_delete \n"." \n"; } @@ -441,67 +388,52 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve $counter = 0; $num_modules = count($tree[$parent_item_id]); - //while ($row=Database::fetch_array($result)) - if (isset ($tree[$parent_item_id])) - { - foreach ($tree[$parent_item_id] as $row) - { - if ($row['item_type'] === 'dokeos_chapter') - { + //while ($row = Database::fetch_array($result)) + if (isset ($tree[$parent_item_id])) { + foreach ($tree[$parent_item_id] as $row) { + if ($row['item_type'] === 'dokeos_chapter') { $xml_output .= ""; - $xml_output .= "".$row["title"].""; - $xml_output .= "".$row["description"].""; + $xml_output .= "".$row['title'].""; + $xml_output .= "".$row['description'].""; $counter ++; - if (($counter % 2) == 0) - { - $oddclass = "row_odd"; - } - else - { - $oddclass = "row_even"; + if (($counter % 2) == 0) { + $oddclass = 'row_odd'; + } else { + $oddclass = 'row_even'; } //echo ''."\n".' '.str_repeat(" >", $level)."folder ".$row['title'].""."
 ".str_repeat("   ", $level)."\n".' \n"." '."\n".' '.str_repeat(" >", $level)."folder ".$row['title'].""."
 ".str_repeat("   ", $level)."\n".' \n"." ".$row['prerequisite']."\n"; - // showing the edit, delete and move icons - if (is_allowed_to_edit()) - { + // Showing the edit, delete and move icons. + if (is_allowed_to_edit()) { $myaction = 'move_item'; - if ($i < $num_modules) - { - - // if we are still under the number of chapters in this section, show "move down" - //echo " "."".""."\n"; - echo " "."".""."\n"; - } - else - { + if ($i < $num_modules) { + // If we are still under the number of chapters in this section, show "move down". + //echo " "."".""."\n"; + echo " "."".""."\n"; + } else { echo '  '."\n"; } - if ($i > 1) - { - //echo ' '.""."".""."\n"; - echo ' '.""."".""."\n"; - } - else - { + if ($i > 1) { + //echo ' '.""."".""."\n"; + echo ' '.""."".""."\n"; + } else { echo '  '."\n"; } echo "  \n"; - //echo " ".""."".""."\n"; - echo " ".""."".""."\n"; + //echo " ".""."".""."\n"; + echo " ".""."".""."\n"; - //echo " ".""."".""."\n"; - echo " ".""."".""."\n"; + //echo " ".""."".""."\n"; + echo " ".""."".""."\n"; } echo "\n"; @@ -509,69 +441,57 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve $xml_output .= ""; - #display_learnpath_items($row["id"]); - display_learnpath_chapters($row['id'], $tree, $level +1); + //display_learnpath_items($row['id']); + display_learnpath_chapters($row['id'], $tree, $level + 1); $xml_output .= ""; $xml_output .= ""; - } - else //if //($row['item_type'] === 'item') + } else //if //($row['item_type'] === 'item') { $row_items = $row; echo "\n "; //require 'resourcelinker.inc.php'; - display_addedresource_link_in_learnpath($row_items["item_type"], $row_items["ref"], '', $row_items["id"], 'builder', 'icon', $level); + display_addedresource_link_in_learnpath($row_items['item_type'], $row_items['ref'], '', $row_items['id'], 'builder', 'icon', $level); - if ($row_items["description"]) - { + if ($row_items['description']) { echo "
   {$row_items['description']}"; } echo ""; - if (is_prereq($learnpath_id)) - { + if (is_prereq($learnpath_id)) { echo ''; - } - else - { + } else { echo ""; } - if (is_allowed_to_edit()) - { + if (is_allowed_to_edit()) { - if ($row_items["prerequisite"] <> '') - { - $prereq = $row_items["prerequisite"]; + if ($row_items['prerequisite'] != '') { + $prereq = $row_items['prerequisite']; - //if ($row_items["prereq_type"] == 'i') - //{ - //item - $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq'"; //check if prereq has been deleted + //if ($row_items['prereq_type'] == 'i') { + // item + $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq'"; // Check if prereq has been deleted. $result_items2 = Database::query($sql_items2); $number_items2 = Database::num_rows($result_items2); - if ($number_items2 == 0) - { + if ($number_items2 == 0) { echo get_lang('prereq_deleted_error'); } $row_items2 = Database::fetch_array($result_items2); - display_addedresource_link_in_learnpath($row_items2["item_type"], $row_items2["ref"], '', $row_items2["id"], 'builder', '', 0); - if ((($row_items2["item_type"] == TOOL_QUIZ) or ($row_items2["item_type"] == 'HotPotatoes')) and ($row_items['prerequisite'])) - { + display_addedresource_link_in_learnpath($row_items2['item_type'], $row_items2['ref'], '', $row_items2['id'], 'builder', '', 0); + if ((($row_items2['item_type'] == TOOL_QUIZ) or ($row_items2['item_type'] == 'HotPotatoes')) and ($row_items['prerequisite'])) { //echo " ({$row_items2['title']})"; } //} /* - if ($row_items["prereq_type"] == 'c') - { - //chapter - $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq' AND item_type='dokeos_chapter'"; //check if prereq has been deleted + if ($row_items['prereq_type'] == 'c') { + // chapter + $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq' AND item_type='dokeos_chapter'"; // Check if prereq has been deleted. $result_items2 = Database::query($sql_items2); $number_items2 = Database::num_rows($result_items2); - if ($number_items2 == 0) - { + if ($number_items2 == 0) { echo "$lang_prereq_deleted_error"; } $row_items2 = Database::fetch_array($result_items2); @@ -579,41 +499,34 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve }*/ } echo ""; - $xml_output .= "".$row_items["item_type"].""; - $xml_output .= "".$row_items["item_id"].""; + $xml_output .= "".$row_items['item_type'].""; + $xml_output .= "".$row_items['item_id'].""; - // move - if ($i < $num_modules) - { - echo ""."".""."".""; - } - else - { + // Move + if ($i < $num_modules) { + echo ""."".""."".""; + } else { echo " "; } - if ($i > 1) - { - echo "".""."".""; - } - else - { + if ($i > 1) { + echo "".""."".""; + } else { echo " "; } echo "".""; - // edit prereq - echo "".""."".""; + // Edit prereq + echo "".""."".""; - // edit - echo ""."".""."".""; + // Edit + echo ""."".""."".""; - // delete - echo "".""."".""; + // Delete + echo "".""."".""; } $i ++; echo ""; - } } } @@ -624,8 +537,7 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve * @return void * @todo eliminate all global $lang declarations, use get_lang, improve structure. */ -function display_all_learnpath() -{ +function display_all_learnpath() { global $tbl_tool, $color2; global $xml_output, $lang_edit_learnpath, $lang_delete_learnpath, $lang_publish, $lang_no_publish, $lang_add_learnpath_chapter_to_path; $tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN); @@ -635,20 +547,18 @@ function display_all_learnpath() $i = 1; $num_modules = Database::num_rows($result); - while ($row = Database::fetch_array($result)) - { - //other grey color : #E6E6E6 + while ($row = Database::fetch_array($result)) { + // Other grey color : #E6E6E6 echo " "; echo "{$row['learnpath_name']}"; echo "
{$row['learnpath_description']}
"; - // showing the edit, delete and publish icons - if (is_allowed_to_edit()) - { + // Showing the edit, delete and publish icons. + if (is_allowed_to_edit()) { echo ""; - echo ""; - echo ""; - $id = $row["lp_id"]; + echo ""; + echo ""; + $id = $row['lp_id']; $sql2 = "SELECT * FROM $tbl_learnpath_main where lp_id=$id"; $result2 = Database::query($sql2); $row2 = Database::fetch_array($result2); @@ -656,13 +566,10 @@ function display_all_learnpath() $sql3 = "SELECT * FROM $tbl_tool where (name=\"$name\" and image='scormbuilder.gif')"; $result3 = Database::query($sql3); $row3 = Database::fetch_array($result3); - if (($row3["visibility"]) == '1') - { - echo ""; - } - else - { - echo ""; + if (($row3['visibility']) == '1') { + echo ""; + } else { + echo ""; } } $i ++; @@ -676,8 +583,7 @@ function display_all_learnpath() * @return void * @todo eliminate all global $lang declarations, use get_lang, improve structure. */ -function display_learnpath_items($categoryid) -{ +function display_learnpath_items($categoryid) { global $xml_output; global $lang_prerequisites, $lang_move_down, $lang_move_up, $lang_edit_learnpath_item, $lang_delete_learnpath_item, $learnpath_id, $lang_add_prereq, $lang_prereq_deleted_error, $lang_pre_short, $langThisItem; $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); @@ -686,60 +592,48 @@ function display_learnpath_items($categoryid) $result_items = Database::query($sql_items); $number_items = Database::num_rows($result_items); $i = 1; - error_log('Selected item under '.$categoryid,0); + error_log('Selected item under '.$categoryid, 0); - while ($row_items = Database::fetch_array($result_items)) - { + while ($row_items = Database::fetch_array($result_items)) { echo ""; - display_addedresource_link_in_learnpath($row_items["item_type"], $row_items["ref"], '', $row_items["id"], 'builder', 'icon'); - if ($row_items["description"]) - { + display_addedresource_link_in_learnpath($row_items['item_type'], $row_items['ref'], '', $row_items['id'], 'builder', 'icon'); + if ($row_items['description']) { echo "
   {$row_items['description']}"; } echo ""; - if (is_prereq($learnpath_id)) - { + if (is_prereq($learnpath_id)) { echo ''; - } - else - { + } else { echo ""; } - if (is_allowed_to_edit()) - { - error_log('Is allowed to edit item'.$row_items['id'],0); - //TODO: fix by adding true prerequisites parsing (and cycle through) - //Over simplification here, we transform prereq_id field into prerequisite field - if ($row_items["prerequisite"] <> '') - { - $prereq = $row_items["prerequisite"]; + if (is_allowed_to_edit()) { + error_log('Is allowed to edit item'.$row_items['id'], 0); + // TODO: Fix by adding true prerequisites parsing (and cycle through). + // Over simplification here, we transform prereq_id field into prerequisite field. + if ($row_items['prerequisite'] != '') { + $prereq = $row_items['prerequisite']; - //if ($row_items["prereq_type"] == 'i') - //{ - //item - $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq'"; //check if prereq has been deleted + //if ($row_items['prereq_type'] == 'i') { + // item + $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq'"; // Check if prereq has been deleted. $result_items2 = Database::query($sql_items2); $number_items2 = Database::num_rows($result_items2); - if ($number_items2 == 0) - { + if ($number_items2 == 0) { echo "$lang_prereq_deleted_error"; } $row_items2 = Database::fetch_array($result_items2); - display_addedresource_link_in_learnpath($row_items2["item_type"], $row_items2["ref"], '', $row_items2["id"], 'builder', ''); - if ((($row_items2["item_type"] == 'Exercise') or ($row_items2["item_type"] == 'HotPotatoes')) and ($row_items['prerequisites'])) - { + display_addedresource_link_in_learnpath($row_items2['item_type'], $row_items2['ref'], '', $row_items2['id'], 'builder', ''); + if ((($row_items2['item_type'] == 'Exercise') or ($row_items2['item_type'] == 'HotPotatoes')) and ($row_items['prerequisites'])) { echo " ({$row_items2['title']})"; } //} - /*if ($row_items["prereq_type"] == 'c') - { - //chapter + /*if ($row_items['prereq_type'] == 'c') { + // chapter $sql_items2 = "SELECT * FROM $tbl_learnpath_chapter WHERE id='$prereq'"; //check if prereq has been deleted $result_items2 = Database::query($sql_items2); $number_items2 = Database::num_rows($result_items2); - if ($number_items2 == 0) - { + if ($number_items2 == 0) { echo "$lang_prereq_deleted_error"; } $row_items2 = Database::fetch_array($result_items2); @@ -747,38 +641,32 @@ function display_learnpath_items($categoryid) }*/ } echo ""; - $xml_output .= "".$row_items["item_type"].""; - $xml_output .= "".$row_items["id"].""; + $xml_output .= "".$row_items['item_type'].""; + $xml_output .= "".$row_items['id'].""; - // move - if ($i < $number_items) - { - echo ""; - } - else - { + // Move + if ($i < $number_items) { + echo ""; + } else { echo " "; } - if ($i > 1) - { - echo ""; - } - else - { + if ($i > 1) { + echo ""; + } else { echo " "; } echo ""; - // edit prereq - echo ""; + // Edit prereq + echo ""; - // edit - echo ""; + // Edit + echo ""; - // delete + // Delete echo ""; - echo ""; + echo ""; } $i ++; echo ""; @@ -790,26 +678,23 @@ function display_learnpath_items($categoryid) * @param integer Item id * @return array Table containing the items */ -function learnpath_items($itemid) -{ +function learnpath_items($itemid) { global $xml_output; $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $sql_items = "SELECT parent_item_id FROM $tbl_lp_item WHERE id='$itemid'"; $moduleid_sql = Database::query($sql_items); - $moduleid_array = Database::fetch_array($moduleid_sql); //first row of the results - $moduleid = $moduleid_array["parent_item_id"]; + $moduleid_array = Database::fetch_array($moduleid_sql); // First row of the results. + $moduleid = $moduleid_array['parent_item_id']; $sql_items = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$moduleid' ORDER BY display_order ASC"; $result_items = Database::query($sql_items); $ar = Database::fetch_array($result_items); - while ($ar != '') - { + while ($ar != '') { $result[] = $ar; $ar = Database::fetch_array($result_items); } return $result; - } /** @@ -817,24 +702,20 @@ function learnpath_items($itemid) * @param integer Learnpath id * @return array Table containing the chapters */ -function learnpath_chapters($learnpath_id) -{ +function learnpath_chapters($learnpath_id) { global $xml_output, $learnpath_id; //$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); - $sql_items = "SELECT * FROM $tbl_lp_item WHERE lp_id='$learnpath_id' AND item_type='dokeos_chapter' ORDER BY display_order ASC"; //$sql_items = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id='$learnpath_id' ORDER BY display_order ASC"; $result_items = Database::query($sql_items); $ar = Database::fetch_array($result_items); - while ($ar != '') - { + while ($ar != '') { $result[] = $ar; $ar = Database::fetch_array($result_items); } return $result; - } /** @@ -842,8 +723,7 @@ function learnpath_chapters($learnpath_id) * @param integer Learnpath id * @return boolean True if this learnpath contains an item which is a prerequisite to something */ -function is_prereq($learnpath_id) -{ +function is_prereq($learnpath_id) { global $xml_output; $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); @@ -851,15 +731,12 @@ function is_prereq($learnpath_id) $sql_items = "SELECT * FROM $tbl_lp_item WHERE lp_id='$learnpath_id' AND parent_item_id=0 ORDER BY display_order ASC"; $result_items = Database::query($sql_items); - while ($ar = Database::fetch_array($result_items)) - { + while ($ar = Database::fetch_array($result_items)) { $c = $ar['id']; $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE lp_id = $learnpath_id AND parent_item_id='$c' ORDER BY display_order ASC"; $result_items2 = Database::query($sql_items2); - while ($ar2 = Database::fetch_array($result_items2)) - { - if ($ar2['prerequisite'] != '') - { + while ($ar2 = Database::fetch_array($result_items2)) { + if ($ar2['prerequisite'] != '') { $prereq = true; } } @@ -872,141 +749,114 @@ function is_prereq($learnpath_id) * @param integer Item ID * @return string Prerequisite warning text */ -function prereqcheck($id_in_path) -{ - //1 Initialise and import working vars +function prereqcheck($id_in_path) { + // 1. Initialise and import working vars. global $learnpath_id, $_user; global $langPrereqToEnter, $langPrereqTestLimit1, $langPrereqTestLimit2, $langPrereqTestLimitNow, $langPrereqFirstNeedTo, $langPrereqModuleMinimum1, $langPrereqModuleMinimum2; $tbl_learnpath_user = Database :: get_course_table(TABLE_LEARNPATH_USER); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); - //2 Initialise return value + // 2. Initialise return value. $prereq = false; - //3 Get item data from the database + // 3. Get item data from the database. $sql_items = "SELECT * FROM $tbl_learnpath_item WHERE id='$id_in_path'"; $result_items = Database::query($sql_items); $row = Database::fetch_array($result_items); - //4 Check prerequisite's type - if ($row['prereq_type'] == 'i') - { - //4.a If prerequisite is of type 'i' (item) - //4.a.1 Get data ready for use + // 4. Check prerequisite's type. + if ($row['prereq_type'] == 'i') { + // 4.a If prerequisite is of type 'i' (item): + // 4.a.1 Get data ready for use. $id_in_path3 = $row['prereq_id']; $prereq_limit = $row['prereq_completion_limit']; - //4.a.2 Get data from the user-item relation - if ($_user['user_id'] == '') - { + // 4.a.2 Get data from the user-item relation. + if ($_user['user_id'] == '') { $user_id = '0'; - } - else - { + } else { $user_id = $_user['user_id']; } $sql_items3 = "SELECT * FROM $tbl_learnpath_user WHERE (learnpath_item_id='$id_in_path3' and user_id=$user_id)"; $result_items3 = Database::query($sql_items3); $row3 = Database::fetch_array($result_items3); - //4.a.3 Get the link that needs to be shown for the current item (not the prereq) + // 4.a.3 Get the link that needs to be shown for the current item (not the prereq) $stepname = display_addedresource_link_in_learnpath($row['item_type'], $row['ref'], '', $id_in_path, 'builder', 'nolink'); - //this is the step we want to open - $stepname = trim($stepname); //to remove occasional line breaks and white spaces + // This is the step we want to open. + $stepname = trim($stepname); // Removing occasional line breaks and white spaces - //4.a.4 Get the prerequisite item + // 4.a.4 Get the prerequisite item. $sql6 = "SELECT * FROM $tbl_learnpath_item WHERE (id='$id_in_path3')"; $result6 = Database::query($sql6); $row6 = Database::fetch_array($result6); - //4.a.5 Get a link to the prerequisite item + // 4.a.5 Get a link to the prerequisite item. $prereqname = display_addedresource_link_in_learnpath($row6['item_type'], $row6['ref'], '', $id_in_path3, 'builder', 'nolink'); //this is the prereq of the step we want to open - //4.a.5 Initialise limit value + // 4.a.5 Initialise limit value. $limitok = true; - //4.a.6 Get prerequisite limit - if ($prereq_limit) - { - //4.a.6.a If the completion limit exists - if ($row3['score'] < $prereq_limit) - { - //4.a.6.a.a If the completion limit hasn't been reached, then display the corresponding message + // 4.a.6 Get prerequisite limit. + if ($prereq_limit) { + // 4.a.6.a If the completion limit exists. + if ($row3['score'] < $prereq_limit) { + // 4.a.6.a.a If the completion limit hasn't been reached, then display the corresponding message. $prereq = $langPrereqToEnter.$stepname.$langPrereqTestLimit1."$prereq_limit".$langPrereqTestLimit2.$prereqname.". (".$langPrereqTestLimitNow.$row3['score'].")"; - } - else - { - //4.a.6.a.b The completion limit has been reached. Prepare to return false (no prereq hanging) + } else { + // 4.a.6.a.b The completion limit has been reached. Prepare to return false (no prereq hanging). $prereq = false; } - } - else - { - //4.a.6.b If the completion limit doesn't exist - if ($row3['status'] == "completed" or $row3['status'] == 'passed') - { - //4.a.6.b.a If the prerequisite status is 'completed' + } else { + // 4.a.6.b If the completion limit doesn't exist. + if ($row3['status'] == 'completed' or $row3['status'] == 'passed') { + // 4.a.6.b.a If the prerequisite status is 'completed'. $prereq = false; - } - else - { - //4.a.6.b.b The prerequisite status is not 'completed', return corresponding message + } else { + // 4.a.6.b.b The prerequisite status is not 'completed', return corresponding message. $prereq = $langPrereqToEnter.$stepname.$langPrereqFirstNeedTo.$prereqname.'.'; } } - - } - elseif ($row['prereq_type'] == 'c') - { - //4.b If prerequisite is of type 'c' (chapter) - //4.b.1 Get data ready to use + } elseif ($row['prereq_type'] == 'c') { + // 4.b If prerequisite is of type 'c' (chapter). + // 4.b.1 Get data ready to use. $id_in_path2 = $row['prereq_id']; - //4.b.2 Get all items in the prerequisite chapter + // 4.b.2 Get all items in the prerequisite chapter. $sql_items3 = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$id_in_path2'"; $result_items3 = Database::query($sql_items3); $allcompleted = true; - while ($row3 = Database::fetch_array($result_items3)) - { - //4.b.3 Cycle through items in the prerequisite chapter - //4.b.3.1 Get data ready to use + while ($row3 = Database::fetch_array($result_items3)) { + // 4.b.3 Cycle through items in the prerequisite chapter. + // 4.b.3.1 Get data ready to use. $id_in_path4 = $row3['id']; - if ($_user['user_id'] == '') - { + if ($_user['user_id'] == '') { $user_id = '0'; - } - else - { + } else { $user_id = $_user['user_id']; } - //4.b.3.2 Get user-item relation + // 4.b.3.2 Get user-item relation. $sql_items4 = "SELECT * FROM $tbl_learnpath_user WHERE (learnpath_item_id='$id_in_path4' and user_id=$user_id)"; $result_items4 = Database::query($sql_items4); $row4 = Database::fetch_array($result_items4); - //4.b.3.3 If any of these elements is not 'completed', the overall completion status is false - if ($row4['status'] != "completed" and $row4['status'] != 'passed') - { + // 4.b.3.3 If any of these elements is not 'completed', the overall completion status is false. + if ($row4['status'] != 'completed' and $row4['status'] != 'passed') { $allcompleted = false; } } - if ($allcompleted) - { - //4.b.4.a All items were completed, prepare to return that there is no prerequisite blocking the way + if ($allcompleted) { + // 4.b.4.a All items were completed, prepare to return that there is no prerequisite blocking the way. $prereq = false; - } - else - { - //4.b.4.b Something was not completed. Return corresponding message + } else { + // 4.b.4.b Something was not completed. Return corresponding message. $sql5 = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id='$learnpath_id' and id='$id_in_path2')"; $result5 = Database::query($sql5); $row5 = Database::fetch_array($result5); $prereqmodulename = trim($row5['chapter_name']); $prereq = $langPrereqModuleMinimum1.$prereqmodulename.$langPrereqModuleMinimum2; } - } - else - { - //5 If prerequisite type undefined, no prereq + } else { + // 5. If prerequisite type undefined, no prereq. $prereq = false; } - //6 Return the message (or false if no prerequisite waiting) + // 6. Return the message (or false if no prerequisite waiting). return ($prereq); } @@ -1017,35 +867,32 @@ function prereqcheck($id_in_path) * @author Yannick Warnier * @comment This is a temporary function, which exists while the chapters and items * are still in separate tables in the database. This function gathers the data in a unique tree. - **/ -function get_learnpath_tree($learnpath_id) -{ - //error_log('New LP - In learnpath_functions::get_learnpath_tree',0); - //init elems - #global $tbl_learnpath_item, $tbl_learnpath_chapter; + */ +function get_learnpath_tree($learnpath_id) { + //error_log('New LP - In learnpath_functions::get_learnpath_tree', 0); + // Init elems + //global $tbl_learnpath_item, $tbl_learnpath_chapter; /* $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); */ $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); - $tree = array (); - $chapters = array (); + $tree = array(); + $chapters = array(); //$chapters = array(); //$chapters_by_parent = array(); //$items = array(); //$items_by_chapter = array(); - $all_items_by_chapter = array (); + $all_items_by_chapter = array(); $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = ".$learnpath_id." AND item_type='dokeos_chapter' ORDER BY display_order"; //error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql,0); $res = Database::query($sql); - // format the $chapters_by_parent array so we have a suitable structure to work with - while ($row = Database::fetch_array($res)) - { + // Format the $chapters_by_parent array so we have a suitable structure to work with. + while ($row = Database::fetch_array($res)) { $chapters[] = $row; - //shouldn't be necessary (check no null value) - if (empty ($row['parent_item_id'])) - { + // Shouldn't be necessary (check no null value). + if (empty ($row['parent_item_id'])) { $row['parent_item_id'] = 0; } //$chapters_by_parent[$row['parent_item_id']][$row['previous_item_id']] = $row; @@ -1053,16 +900,14 @@ function get_learnpath_tree($learnpath_id) $all_items_by_chapter[$row['parent_item_id']][$row['display_order']]['type'] = 'dokeos_chapter'; } - // now for every item in each chapter, get a suitable structure too - foreach ($chapters as $row) - { - // select items from this chapter + // Now for every item in each chapter, get a suitable structure too. + foreach ($chapters as $row) { + // Select items from this chapter. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $learnpath_id AND parent_item_id = ".$row['id']." ORDER BY display_order"; - //error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql,0); + //error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql, 0); $res = Database::query($sql); - //error_log('New LP - learnpath_functions - get_learnpath_tree: Found '.Database::num_rows($res).' results',0); - while ($myrow = Database::fetch_array($res, 'ASSOC')) - { + //error_log('New LP - learnpath_functions - get_learnpath_tree: Found '.Database::num_rows($res).' results', 0); + while ($myrow = Database::fetch_array($res, 'ASSOC')) { //$items[] = $myrow; //$items_by_chapter[$myrow['parent_item_id']][$myrow['display_order']] = $myrow; $all_items_by_chapter[$row['id']][$myrow['display_order']] = $myrow; @@ -1070,13 +915,12 @@ function get_learnpath_tree($learnpath_id) } } //array_multisort($all_items_by_chapter[0], SORT_ASC, SORT_NUMERIC); - foreach ($all_items_by_chapter as $key => $subrow) - { + foreach ($all_items_by_chapter as $key => $subrow) { ksort($all_items_by_chapter[$key]); } //all items should now be well-ordered - //error_log('New LP - In get_learnpath_tree, returning '.print_r($all_items_by_chapter,true),0); + //error_log('New LP - In get_learnpath_tree, returning '.print_r($all_items_by_chapter,true), 0); return $all_items_by_chapter; } @@ -1087,26 +931,19 @@ function get_learnpath_tree($learnpath_id) * @param boolean Whether to include chapters or not * @return array List of elements in the first to last order * @author Yannick Warnier - **/ -function get_ordered_items_list($tree, $chapter = 0, $include_chapters = false) -{ + */ +function get_ordered_items_list($tree, $chapter = 0, $include_chapters = false) { $list = array (); - foreach ($tree[$chapter] as $order => $elem) - { - if ($elem['type'] == 'chapter') - { - if ($include_chapters === true) - { + foreach ($tree[$chapter] as $order => $elem) { + if ($elem['type'] == 'chapter') { + if ($include_chapters === true) { $list[] = array ('id' => $elem['id'], 'type' => $elem['type']); } $res = get_ordered_items_list($tree, $elem['id'], $include_chapters); - foreach ($res as $elem) - { + foreach ($res as $elem) { $list[] = $elem; } - } - elseif ($elem['type'] == 'item') - { + } elseif ($elem['type'] == 'item') { $list[] = array ('id' => $elem['id'], 'type' => $elem['type'], 'item_type' => $elem['item_type'], 'parent_item_id' => $elem['parent_item_id'], 'item_id' => $elem['item_id']); } } @@ -1123,94 +960,70 @@ function get_ordered_items_list($tree, $chapter = 0, $include_chapters = false) * @param integer Level reached so far in the tree depth (enables recursive behaviour) * @return array Number of items, Number of items completed * @author Many changes by Yannick Warnier - **/ -function display_toc_chapter_contents($tree, $parent_item_id = 0, $learnpath_id, $uid, $wrap, $level = 0) -{ - #global $tbl_learnpath_user; + */ +function display_toc_chapter_contents($tree, $parent_item_id = 0, $learnpath_id, $uid, $wrap, $level = 0) { + //global $tbl_learnpath_user; $tbl_learnpath_user = Database :: get_course_table(TABLE_LEARNPATH_USER); $num = 0; $num_completed = 0; - foreach ($tree[$parent_item_id] as $order => $elem) - { + foreach ($tree[$parent_item_id] as $order => $elem) { $bold = false; - if (!empty ($_SESSION['cur_open']) && ($elem['id'] == $_SESSION['cur_open'])) - { + if (!empty ($_SESSION['cur_open']) && ($elem['id'] == $_SESSION['cur_open'])) { $bold = true; } - if ($elem['type'] === 'chapter') - { - if ($wrap) - { + if ($elem['type'] === 'chapter') { + if ($wrap) { echo str_repeat("  ", $level).shorten(strip_tags($elem['chapter_name']), (35 - 3 * $level))."
\n"; - } - else - { + } else { echo "".str_repeat("  ", $level).shorten($elem['chapter_name'], (35 - 3 * $level))."\n"; } - if ($wrap) - { - if ($elem['chapter_description'] != '') - { + if ($wrap) { + if ($elem['chapter_description'] != '') { echo "
".str_repeat("  ", $level)." ".shorten($elem['chapter_description'], (35 - 3 * $level))."
\n"; } - } - else - { - if ($elem['chapter_description'] != '') - { + } else { + if ($elem['chapter_description'] != '') { echo "
".str_repeat("  ", $level)." ".shorten($elem['chapter_description'], (35 - 3 * $level))."
\n"; } } - list ($a, $b) = display_toc_chapter_contents($tree, $elem['id'], $learnpath_id, $uid, $wrap, $level +1); + list ($a, $b) = display_toc_chapter_contents($tree, $elem['id'], $learnpath_id, $uid, $wrap, $level + 1); $num += $a; $num_completed += $b; - } - elseif ($elem['type'] === 'item') - { - // If this element is an item (understand: not a directory/module) + } elseif ($elem['type'] === 'item') { + // If this element is an item (understand: not a directory/module). $sql0 = "SELECT * FROM $tbl_learnpath_user WHERE (user_id='".$uid."' and learnpath_item_id='".$elem['id']."' and lp_id='".$learnpath_id."')"; $result0 = Database::query($sql0); $row0 = Database::fetch_array($result0); $completed = ''; - if (($row0['status'] == 'completed') or ($row0['status'] == 'passed')) - { + if (($row0['status'] == 'completed') or ($row0['status'] == 'passed')) { $completed = 'completed'; $num_completed ++; } - if ($wrap) - { + if ($wrap) { echo str_repeat("  ", $level)."\n"; - } - else - { + } else { echo "".str_repeat("  ", $level-1)."\n"; } - if ($wrap) - { + if ($wrap) { $icon = 'wrap'; } - if ($bold) - { + if ($bold) { echo ""; } display_addedresource_link_in_learnpath($elem['item_type'], $elem['ref'], $completed, $elem['id'], 'player', $icon); - if ($bold) - { + if ($bold) { echo ""; } - if ($wrap) - { + if ($wrap) { echo "
\n"; - } - else - { + } else { echo "\n"; } @@ -1230,57 +1043,44 @@ function display_toc_chapter_contents($tree, $parent_item_id = 0, $learnpath_id, * @param integer Counter of elements already displayed * @author Yannick Warnier * @note : forced display because of display_addedresource_link_in_learnpath behaviour (outputing a string would be better) - **/ -function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree = false, $level = 0, $counter = 0) -{ + */ +function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree = false, $level = 0, $counter = 0) { $tbl_learnpath_chapter = Database :: get_course_learnpath_chapter_table(); $tbl_learnpath_item = Database :: get_course_learnpath_item_table(); $tbl_learnpath_user = Database :: get_course_learnpath_user_table(); //$mytable = ''; $include_chapters = true; - if (!is_array($tree)) - { - //get a tree of the current learnpath elements + if (!is_array($tree)) { + // Get a tree of the current learnpath elements. $tree = get_learnpath_tree($learnpath_id); } - foreach ($tree[$parent_item_id] as $order => $elem) - { - if (($counter % 2) == 0) - { + foreach ($tree[$parent_item_id] as $order => $elem) { + if (($counter % 2) == 0) { $oddclass = 'row_odd'; - } - else - { + } else { $oddclass = 'row_even'; } - if ($elem['type'] == 'chapter') - { - if ($include_chapters === true) - { + if ($elem['type'] == 'chapter') { + if ($include_chapters === true) { //$mytable .= "".str_repeat(' ',$level*2+2).$elem['chapter_name']."\n"; echo "".str_repeat(' ', $level * 2 + 2).$elem['chapter_name']."\n"; } $counter ++; //$mytable .= get_tracking_table($learnpath_id, $user_id, $elem['id'], $tree, $level + 1, $counter ); - get_tracking_table($learnpath_id, $user_id, $elem['id'], $tree, $level +1, $counter); + get_tracking_table($learnpath_id, $user_id, $elem['id'], $tree, $level + 1, $counter); - } - elseif ($elem['type'] == 'item') - { + } elseif ($elem['type'] == 'item') { $sql = "SELECT * FROM $tbl_learnpath_user "."WHERE user_id = $user_id "."AND lp_id = $learnpath_id "."AND learnpath_item_id = ".$elem['id']; $res = Database::query($sql); $myrow = Database::fetch_array($res); - if (($myrow['status'] == 'completed') || ($myrow['status'] == 'passed')) - { + if (($myrow['status'] == 'completed') || ($myrow['status'] == 'passed')) { $color = 'blue'; $statusmessage = get_lang('Complete'); - } - else - { + } else { $color = 'black'; $statusmessage = get_lang('Incomplete'); } @@ -1306,8 +1106,7 @@ function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree * @param Learnpath ID * @return boolean True if nothing was found, false otherwise */ -function is_empty($id) -{ +function is_empty($id) { $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); @@ -1316,26 +1115,21 @@ function is_empty($id) $num_modules = Database::num_rows($result); $empty = true; - if ($num_modules != 0) - { - while ($row = Database::fetch_array($result)) - { + if ($num_modules != 0) { + while ($row = Database::fetch_array($result)) { $num_items = 0; $parent_item_id = $row['id']; $sql2 = "SELECT * FROM $tbl_learnpath_item WHERE (parent_item_id=$parent_item_id) ORDER BY display_order ASC"; $result2 = Database::query($sql2); $num_items = Database::num_rows($result2); - if ($num_items > 0) - { + if ($num_items > 0) { $empty = false; } - } } return ($empty); - } /** @@ -1346,19 +1140,16 @@ function is_empty($id) * @param string Content to write * @return void */ -function exporttofile($filename, $LPname, $LPid, $content) -{ +function exporttofile($filename, $LPname, $LPid, $content) { - global $circle1_files; //this keeps all the files which are exported [0]:filename [1]:LP name - //the $circle1_files variable is going to be used to a deep extent in the imsmanifest.xml + global $circle1_files; // This keeps all the files which are exported [0]:filename [1]:LP name. + // The $circle1_files variable is going to be used to a deep extent in the imsmanifest.xml. global $expdir; - if (!$handle = fopen($expdir.'/'.$filename, 'w')) - { + if (!$handle = fopen($expdir.'/'.$filename, 'w')) { echo "Cannot open file ($filename)"; } - if (fwrite($handle, $content) === FALSE) - { + if (fwrite($handle, $content) === false) { echo "Cannot write to file ($filename)"; exit; } @@ -1367,7 +1158,6 @@ function exporttofile($filename, $LPname, $LPid, $content) $circle1_files[0][] = $filename; $circle1_files[1][] = $LPname; $circle1_files[2][] = $LPid; - } /** @@ -1375,8 +1165,7 @@ function exporttofile($filename, $LPname, $LPid, $content) * @param integer Test ID * @return string The test itself as an HTML string */ -function export_exercise($item_id) -{ +function export_exercise($item_id) { global $expdir, $_course, $_configuration, $_SESSION, $_SERVER, $language_interface, $langExerciseNotFound, $langQuestion, $langOk; @@ -1387,7 +1176,7 @@ function export_exercise($item_id) require_once '../exercice/answer.class.php'; require_once '../exercice/exercise.lib.php'; - // answer types + // Answer types define('UNIQUE_ANSWER', 1); define('MULTIPLE_ANSWER', 2); define('FILL_IN_BLANKS', 3); @@ -1396,49 +1185,40 @@ function export_exercise($item_id) $TBL_EXERCISES = Database :: get_course_table(TABLE_QUIZ_TEST); - /*******************************/ /* Clears the exercise session */ - /*******************************/ - if (isset ($_SESSION['objExercise'])) - { + if (isset ($_SESSION['objExercise'])) { api_session_unregister('objExercise'); unset ($objExercise); } - if (isset ($_SESSION['objQuestion'])) - { + if (isset ($_SESSION['objQuestion'])) { api_session_unregister('objQuestion'); unset ($objQuestion); } - if (isset ($_SESSION['objAnswer'])) - { + if (isset ($_SESSION['objAnswer'])) { api_session_unregister('objAnswer'); unset ($objAnswer); } - if (isset ($_SESSION['questionList'])) - { + if (isset ($_SESSION['questionList'])) { api_session_unregister('questionList'); unset ($questionList); } - if (isset ($_SESSION['exerciseResult'])) - { + if (isset ($_SESSION['exerciseResult'])) { api_session_unregister('exerciseResult'); unset ($exerciseResult); } - // if the object is not in the session - if (!isset ($_SESSION['objExercise'])) - { - // construction of Exercise + // If the object is not in the session: + if (!isset ($_SESSION['objExercise'])) { + // Construction of Exercise. $objExercise = new Exercise(); $sql = "SELECT title,description,sound,type,random,active FROM $TBL_EXERCISES WHERE id='$exerciseId'"; - // if the specified exercise doesn't exist or is disabled - if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) - { + // If the specified exercise doesn't exist or is disabled: + if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) { die($langExerciseNotFound); } - // saves the object into the session + // Saves the object into the session. api_session_register('objExercise'); } @@ -1448,27 +1228,22 @@ function export_exercise($item_id) $randomQuestions = $objExercise->isRandom(); $exerciseType = $objExercise->selectType(); - if (!isset ($_SESSION['questionList'])) - { - // selects the list of question ID + if (!isset ($_SESSION['questionList'])) { + // Selects the list of question ID. $questionList = $randomQuestions ? $objExercise->selectRandomList() : $objExercise->selectQuestionList(); - // saves the question list into the session + // Saves the question list into the session. api_session_register('questionList'); } $nbrQuestions = sizeof($questionList); - // if questionNum comes from POST and not from GET - if (!$questionNum || $_POST['questionNum']) - { - // only used for sequential exercises (see $exerciseType) - if (!$questionNum) - { + // If questionNum comes from POST and not from GET: + if (!$questionNum || $_POST['questionNum']) { + // Only used for sequential exercises (see $exerciseType). + if (!$questionNum) { $questionNum = 1; - } - else - { + } else { $questionNum ++; } } @@ -1477,14 +1252,13 @@ function export_exercise($item_id) $test .= "

".$exerciseTitle."

"; - if (!empty ($exerciseSound)) - { + if (!empty ($exerciseSound)) { $test .= "
.get_lang("; } $exerciseDescription = text_filter($exerciseDescription); - // --------- writing the .js file with to check the correct answers begin ----------------------- + // Writing the .js file with to check the correct answers begin. $scriptfilename = "Exercice".$item_id.".js"; $s = ""; $test .= $s; @@ -1494,18 +1268,16 @@ function export_exercise($item_id) } "; - if (!$handle = fopen($expdir.'/js/'.$scriptfilename, 'w')) - { + if (!$handle = fopen($expdir.'/js/'.$scriptfilename, 'w')) { echo "Cannot open file ($scriptfilename)"; } - if (fwrite($handle, $content) === FALSE) - { + if (fwrite($handle, $content) === false) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); - // --------- writing the .js file with to check the correct answers end ----------------------- + // Writing the .js file with to check the correct answers end. $s = "

$exerciseDescription

@@ -1518,7 +1290,7 @@ function export_exercise($item_id)
"; - $exerciseType = 1; //so to list all questions in one page + $exerciseType = 1; // So to list all questions in one page. $test .= $s; $i = 0; @@ -1526,27 +1298,26 @@ function export_exercise($item_id) foreach ($questionList as $questionId) { $i ++; - // for sequential exercises + // For sequential exercises. if ($exerciseType == 2) { - // if it is not the right question, goes to the next loop iteration - if ($questionNum != $i) - { + // If it is not the right question, goes to the next loop iteration. + if ($questionNum != $i) { continue; } else { - // if the user has already answered this question + // if the user has already answered this question: if (isset ($exerciseResult[$questionId])) { - // construction of the Question object + // Construction of the Question object. $objQuestionTmp = new Question(); - // reads question informations + // Reads question informations. $objQuestionTmp->read($questionId); $questionName = $objQuestionTmp->selectTitle(); - // destruction of the Question object + // Destruction of the Question object. unset ($objQuestionTmp); - $test .= ''; + $test .= ''; break; } @@ -1554,12 +1325,12 @@ function export_exercise($item_id) } echo $s = "
'.get_lang("AlreadyAnswered").' "'.$questionName.'"
'.get_lang('AlreadyAnswered').' "'.$questionName.'"
".get_lang('Question')." "; - //Call the showQuestion() function from exercise.lib.php. This basically displays the question in a table + // Call the showQuestion() function from exercise.lib.php. This basically displays the question in a table. $test .= showQuestion($questionId, false, 'export', $i, $nbrQuestions); } // end foreach() - $s = "

"; + $s = "

"; $s .= ""; $s .= ""; $b = 2; @@ -1577,13 +1348,12 @@ function export_exercise($item_id) * @todo Try using the SCORM communications addition (adding a button and several javascript calls to the SCORM API) elsewhere than just in the export feature, so it doesn't look like an incoherent feature */ -function exportitem($id, $item_id, $item_type, $add_scorm_communications = false) -{ +function exportitem($id, $item_id, $item_type, $add_scorm_communications = false) { global $circle1_files, $expdir, $_course, $_SESSION, $GLOBALS; global $timeNoSecFormat, $dateFormatLong, $language_interface, $langPubl, $langDone, $langThisCourseDescriptionIsEmpty, $lang_course_description, $lang_introduction_text, $_cid, $langHotPotatoesFinished, $lang_author, $lang_date, $lang_groups, $lang_users, $lang_ass, $lang_dropbox, $test, $langQuestion; - // $_course=$_SESSION['course']; + //$_course = $_SESSION['course']; require_once api_get_path(LIBRARY_PATH).'database.lib.php'; //$tbl_learnpath_item = Database::get_course_learnpath_item_table(); @@ -1616,7 +1386,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false --> "; - //files needed for communicating with the scos + // Files needed for communicating with the scos. $scocomfiles = "".""; $expcontent .= ''.$scocomfiles.''; @@ -1635,13 +1405,13 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
- +
"; /** - * switch between the different element types, namely: + * Switch between the different element types, namely: * - Agenda * - Ad_Valvas * - Course_description @@ -1650,231 +1420,215 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false * - HotPotatoes * - Exercise * - Post - * - Forum ] - * - Thread ] - * - Dropbox ] - * - Assignments ] Theses elements are all replaced by a simple message in the exported document - * - Groups ] - * - Users ] + * - Forum ] + * - Thread ] + * - Dropbox ] + * - Assignments ] These elements are all replaced by a simple message in the exported document. + * - Groups ] + * - Users ] * - Link _self * - Link _blank */ - switch ($item_type) - { + switch ($item_type) { - //------------------------AGENDA BEGIN------------------- - case "Agenda" : - //1 Get agenda event data from the database table + // AGENDA BEGIN + case 'Agenda': + // 1. Get agenda event data from the database table. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); $sql = "SELECT * FROM ".$TABLEAGENDA." where (id=$item_id)"; $result = Database::query($sql); - //2 Prepare table output + // 2. Prepare table output. $expcontent .= ""; - $barreMois = ""; + $barreMois = ''; - //3 For each event corresponding to this agenda, do the following: - while ($myrow = Database::fetch_array($result)) - { - $start_date_local = api_get_local_time($myrow["start_date"], null, date_default_timezone_get()); + // 3. For each event corresponding to this agenda, do the following: + while ($myrow = Database::fetch_array($result)) { + $start_date_local = api_get_local_time($myrow['start_date'], null, date_default_timezone_get()); //3.1 Make the blue month bar appear only once. - if ($barreMois != api_format_date($start_date_local, "%m")) - { - //3.1.1 Update the check value for the month bar + if ($barreMois != api_format_date($start_date_local, "%m")) { + // 3.1.1 Update the check value for the month bar. $barreMois = api_format_date($start_date_local, "%m"); - //3.1.2 Display the month bar + // 3.1.2 Display the month bar. $expcontent .= ""; } - //3.2 Display the agenda items (of this month): the date, hour and title + // 3.2 Display the agenda items (of this month): the date, hour and title. $db_date = (int) api_format_date($start_date_local, "%d"); - if ($_GET["day"] <> $db_date) - { //3.2.1.a If the day given in the URL (might not be set) is different from this element's day, use style 'data' + if ($_GET['day'] != $db_date) { + // 3.2.1.a If the day given in the URL (might not be set) is different from this element's day, use style 'data'. $expcontent .= ""; - //3.2.6 Prepare the content of the agenda item - $content = $myrow["content"]; - //3.2.7 Make clickable??? + // 3.2.6 Prepare the content of the agenda item. + $content = $myrow['content']; + // 3.2.7 Make clickable??? $content = make_clickable($content); $content = text_filter($content); - //3.2.8 Write the prepared content to the export string + // 3.2.8 Write the prepared content to the export string. $expcontent .= ""; - // displaying the agenda item of this month: the added resources - // this part is not included into LP export - /*if (check_added_resources("Agenda", $myrow["id"])) - { - $content.= ""; + // Displaying the agenda item of this month: the added resources. + // This part is not included into LP export. + /*if (check_added_resources("Agenda", $myrow['id'])) { + $content.= ""; }*/ } - //4 Finish the export string + // 4. Finish the export string. $expcontent .= "
".api_format_date($start_date_local, "%B %Y")."
"; - } - else - { //3.2.1.b Else (same day) use style 'datanow' + } else { + // 3.2.1.b Else (same day) use style 'datanow'. $expcontent .= "
"; } - //3.2.2 Mark an anchor for this date + // 3.2.2 Mark an anchor for this date. $expcontent .= ""; // anchoring - //3.2.3 Write the date and time of this event to the export string + // 3.2.3 Write the date and time of this event to the export string. $expcontent .= api_format_date($start_date_local); - //3.2.4 If a duration is set, write it, otherwise ignore - if ($myrow["duration"] == "") - { + // 3.2.4 If a duration is set, write it, otherwise ignore. + if ($myrow['duration'] == '') { $expcontent .= "
"; + } else { + $expcontent .= " / ".$lang_lasting." ".$myrow['duration']."
"; } - else - { - $expcontent .= " / ".$lang_lasting." ".$myrow["duration"]."
"; - } - //3.2.5 Write the title - $expcontent .= $myrow["title"]; + // 3.2.5 Write the title. + $expcontent .= $myrow['title']; $expcontent .= "
"; $expcontent .= $content; $expcontent .= "
"; - $content.= "".get_lang('AddedResources')."
"; - display_added_resources("Agenda", $myrow["id"]); - $content.= "
"; + $content.= "".get_lang('AddedResources')."
"; + display_added_resources("Agenda", $myrow['id']); + $content.= "
"; break; - //------------------------ANNOUNCEMENT BEGIN------------------- - case "Ad_Valvas" : - //1 Get the announcement data from the database + + // ANNOUNCEMENT BEGIN + case 'Ad_Valvas': + // 1. Get the announcement data from the database $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $sql = "SELECT * FROM $tbl_announcement where id='$item_id'"; $result = Database::query($sql); - //2 Initialise export string + // 2. Initialise export string $expcontent .= ""; - //3 For each announcement matching the query - while ($myrow = Database::fetch_array($result)) - { - //3.1 Get the __ field data + // 3. For each announcement matching the query + while ($myrow = Database::fetch_array($result)) { + // 3.1 Get the __ field data. $content = $myrow[1]; //$content = nl2br($content); - //3.2 Prepare the data for export + // 3.2 Prepare the data for export. $content = make_clickable($content); $content = text_filter($content); - //3.3 Get a UNIX(?<-mktime) Timestamp of the end_date for this announcement + // 3.3 Get a UNIX(?<-mktime) Timestamp of the end_date for this announcement. $last_post_datetime = $myrow['end_date']; // post time format datetime de mysql - list ($last_post_date, $last_post_time) = split(" ", $last_post_datetime); - list ($year, $month, $day) = explode("-", $last_post_date); - list ($hour, $min) = explode(":", $last_post_time); + list ($last_post_date, $last_post_time) = split(' ', $last_post_datetime); + list ($year, $month, $day) = explode('-', $last_post_date); + list ($hour, $min) = explode(':', $last_post_time); $announceDate = mktime($hour, $min, 0, $month, $day, $year); - //3.4 Compare the end date to the last login date of the user (mark it in red if he has not already read it) - if ($announceDate > $_SESSION['user_last_login_datetime']) - { + // 3.4 Compare the end date to the last login date of the user (mark it in red if he has not already read it). + if ($announceDate > $_SESSION['user_last_login_datetime']) { $colorBecauseNew = " color=\"red\" "; - } - else - { - $colorBecauseNew = " "; + } else { + $colorBecauseNew = ' '; } - //3.5 Write this content to the export string (formatted HTML array) + // 3.5 Write this content to the export string (formatted HTML array). $expcontent .= "\n"."\n"."\n"."\n"."\n"."\n"; } // while loop - //4 Finish the export string + // 4 Finish the export string. $expcontent .= "
\n"."".$langPubl." : ".api_convert_and_format_date($last_post_datetime, null, date_default_timezone_get())."\n"."
\n".$content."
"; break; - //------------------------Course_description BEGIN------------------- - case "Course_description" : - //1 Get course description data from database + + // Course_description BEGIN + case 'Course_description': + // 1. Get course description data from database. $tbl_course_description = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); $result = Database::query("SELECT id, title, content FROM ".$tbl_course_description." ORDER BY id"); - //2 Check this element - if (Database::num_rows($result)) - { - //2.a This course has one (or more) description in the database + // 2. Check this element. + if (Database::num_rows($result)) { + // 2.a This course has one (or more) description in the database. $expcontent .= "
"; - //2.a.1 For each description available for this course - while ($row = Database::fetch_array($result)) - { - //2.a.1.1 Write title to export string + // 2.a.1 For each description available for this course. + while ($row = Database::fetch_array($result)) { + // 2.a.1.1 Write title to export string. $expcontent .= "

".$row['title']."

"; - //2.a.1.2 Prepare content + // 2.a.1.2 Prepare content. $content = make_clickable(nl2br($row['content'])); $content = text_filter($content); - //2.a.1.3 Write content to the export string + // 2.a.1.3 Write content to the export string. $expcontent .= $content; } - } - else - { - //2.b This course has no description available + } else { + // 2.b This course has no description available. $expcontent .= "

$langThisCourseDescriptionIsEmpty

"; } break; - //------------------------DOCUMENT BEGIN------------------- - case "Document" : - //1 Get the document data from the database + + // DOCUMENT BEGIN + case 'Document': + // 1. Get the document data from the database. $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $sql_query = "SELECT * FROM $tbl_document WHERE id=$item_id"; $sql_result = Database::query($sql_query); $myrow = Database::fetch_array($sql_result); - //2 Get the origin path of the document to treat it internally - $orig = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$myrow["path"]; - //3 Make some kind of strange transformation to get the destination filepath ??? - $pathname = explode("/", $myrow["path"]); + // 2. Get the origin path of the document to treat it internally. + $orig = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$myrow['path']; + // 3. Make some kind of strange transformation to get the destination filepath ??? + $pathname = explode('/', $myrow['path']); $last = count($pathname) - 1; $filename = 'data/'.$filename.$pathname[$last]; $copyneeded = true; - //htm files do not need to be copied as the ok button is inserted into them, - //so don't copy directly - $extension = explode(".", $pathname[$last]); - //This old condition was WRONG for names like design.html.old. Instead, we now get the extension - // by using preg_match to match case-insensitive (probably faster than 4 conditions) + // Html files do not need to be copied as the ok button is inserted into them, + // so don't copy directly. + $extension = explode('.', $pathname[$last]); + // This old condition was WRONG for names like design.html.old. Instead, we now get the extension + // by using preg_match to match case-insensitive (probably faster than 4 conditions). //if (($extension[1]=='htm') or ($extension[1]=='html') or ($extension[1]=='HTM') or ($extension[1]=='HTML')) { - //4 Check the file extension - if (preg_match('/.*(\.htm(l)?)$/i', $pathname[$last])) - { - //4.a If this file ends with ".htm(l)", we consider it's an HTML file - //src tag check begin - //we now check if there is any src attribute in htm(l) files, if yes, we have to also export - //the target file (swf, mp3, video,...) of that src tag - //In case of absolute links (http://) this is not neccessary, but makes no error. - //however still missing : relative links case with subdirs -> the necessary dirs are not created in the exported package - - //4.a.1 Get the file contents into $file + // 4. Check the file extension. + if (preg_match('/.*(\.htm(l)?)$/i', $pathname[$last])) { + // 4.a If this file ends with ".htm(l)", we consider it's an HTML file. + // src tag check begin + // We now check if there is any src attribute in htm(l) files, if yes, we have to also export + // the target file (swf, mp3, video,...) of that src tag. + // In case of absolute links (http://) this is not neccessary, but makes no error. + // However still missing : relative links case with subdirs -> the necessary dirs are not created in the exported package. + + // 4.a.1 Get the file contents into $file. $file = file_get_contents($orig); - //4.a.2 Get all the src links in this file + // 4.a.2 Get all the src links in this file. //preg_match_all("|((?i)src=\".*\" )|U",$file,$match); $match = GetSRCTags($orig); - //4.a.3 For each src tag found, do the following: - for ($i = 0; $i < count($match); $i ++) - { - //4.a.3.1 Get the tag (split from the key) + // 4.a.3 For each src tag found, do the following: + for ($i = 0; $i < count($match); $i ++) { + // 4.a.3.1 Get the tag (split from the key). list ($key, $srctag) = each($match); $src = $srctag; - //4.a.3.2 Check the link kind (web or absolute/relative) - if (stristr($src, "http") === false) - { - //4.a.3.2.a Do something only if relative (otherwise the user will be able to see it too anyway) - //4.a.3.2.a.1 Get a proper URL and remove all './' + // 4.a.3.2 Check the link kind (web or absolute/relative). + if (stristr($src, 'http') === false) { + // 4.a.3.2.a Do something only if relative (otherwise the user will be able to see it too anyway). + // 4.a.3.2.a.1 Get a proper URL and remove all './' $src = urldecode($src); //mp3 //$src=str_replace('./','',$src); $src = preg_replace('/^\.\//', '', $src); - //4.a.3.2.a.2 Remove the player link from the URL (only use the mp3 file) + // 4.a.3.2.a.2 Remove the player link from the URL (only use the mp3 file). $src = str_replace('mp3player.swf?son=', '', $src); //mp3 - //4.a.3.2.a.3 Remove funny link parts + // 4.a.3.2.a.3 Remove funny link parts. $src = str_replace('?0', '', $src); //mp3 - //the previous lines are used when creating docs with Dokeos Document tool's htmlarea - //rows marked by 'mp3' are needed because the mp3 plugin inserts the swf-mp3 links in a very strange way - //and we can decode them with those 3 lines, hoping this will not cause errors in case of other htmls, - //created by any other software - //4.a.3.2.a.4 Prepare source and destination paths + // The previous lines are used when creating docs with Chamilo Document tool's htmlarea + // Rows marked by 'mp3' are needed because the mp3 plugin inserts the swf-mp3 links in a very strange way + // and we can decode them with those 3 lines, hoping this will not cause errors in case of other htmls, + // created by any other software. + // 4.a.3.2.a.4 Prepare source and destination paths. $source = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.dirname($myrow['path']).'/'.$src; $dest = $expdir.'/data/'.$src; //CopyNCreate($source,$dest); @@ -1882,42 +1636,35 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false } //else...? } - //src tag check end + // src tag check end - //sco communication insertion begin - //4.a.4 If we want to add SCORM actions and a "Done" button, do the following: - if ($add_scorm_communications === true) - { - if ($bodyclose = strpos($file, '')) - { + // sco communication insertion begin + // 4.a.4 If we want to add SCORM actions and a "Done" button, do the following: + if ($add_scorm_communications === true) { + if ($bodyclose = strpos($file, '')) { $file = substr_replace($file, $scocomfiles.$donebutton, $bodyclose, 7); - } - elseif ($htmlclose = strpos($file, '')) - { + } elseif ($htmlclose = strpos($file, '')) { $file = substr_replace($file, $scocomfiles.$donebutton, $htmlclose, 7); $file .= ''; - } - else - { + } else { $file .= $scocomfiles.$donebutton; } } //sco communication insertion end - //4.a.5 Replace the file's name by adding the element's ID before htm + // 4.a.5 Replace the file's name by adding the element's ID before htm. // This will not work with uppercase HTML though. Maybe use the preg_replace syntax proposed... $filename = str_replace('.htm', $id.'.htm', $filename); //$filename=preg_replace('/.*(\.htm(l)?)$/i',$id.$1,$filename); - //4.a.6 Export these contents to a file and set the circle1_files array for later reuse + // 4.a.6 Export these contents to a file and set the circle1_files array for later reuse. exporttofile($filename, $LPname, $id, $file); - //The file has been copied, so ask not to copy it again + // The file has been copied, so ask not to copy it again. $copyneeded = false; } //if (htm(l) files) end - //5 If we still need to copy the file (e.g. it was not an HTML file), then copy and set circle1_files for later reuse - if ($copyneeded) - { + // 5. If we still need to copy the file (e.g. it was not an HTML file), then copy and set circle1_files for later reuse. + if ($copyneeded) { copy($orig, $expdir.'/'.$filename); $circle1_files[0][] = $filename; $circle1_files[1][] = $LPname; @@ -1927,57 +1674,55 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false //echo $orig; return; - //------------------------Introduction_text BEGIN------------------- - case "Introduction_text" : - //1 Get the introduction text data from the database + // Introduction_text BEGIN + case 'Introduction_text': + // 1 Get the introduction text data from the database. $TBL_INTRO = Database :: get_course_tool_intro_table(); // Modified by Ivan Tcholakov, 15-SEP-2008. //$result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE id=1"); $result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE id='course_homepage'"); // $myrow = Database::fetch_array($result); - $intro = $myrow["intro_text"]; - //2 Write introduction text to the export string - $expcontent .= "
".$intro; + $intro = $myrow['intro_text']; + // 2 Write introduction text to the export string. + $expcontent .= '
'.$intro; break; - //------------------------HotPotatoes BEGIN------------------- - case "HotPotatoes" : - //1 Get HotPotatoes data from the document table + // HotPotatoes BEGIN + case 'HotPotatoes': + // 1. Get HotPotatoes data from the document table. $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $result = Database::query("SELECT * FROM $tbl_document WHERE id=$item_id"); $myrow = Database::fetch_array($result); - //2 Get the document path + // 2. Get the document path. $testfile = api_get_path(SYS_COURSE_PATH).$_course['path']."/document".urldecode($myrow['path']); - //3 Get the document contents into a string + // 3. Get the document contents into a string. $content = file_get_contents($testfile); - //4 Get the document filename (just the file, no path) - would probably be better to use PHP native function - $pathname = explode("/", $myrow["path"]); + // 4. Get the document filename (just the file, no path) - would probably be better to use PHP native function. + $pathname = explode('/', $myrow['path']); $last = count($pathname) - 1; $filename = 'data/'.$filename.$pathname[$last]; - //4beta - get all linked files and copy them (procedure copied from documents type) - //Get all the src links in this file + // 4beta - get all linked files and copy them (procedure copied from documents type). + // Get all the src links in this file. $match = GetSRCTags($testfile); - //For each src tag found, do the following: - foreach ($match as $src) - { + // For each src tag found, do the following: + foreach ($match as $src) { //Check the link kind (web or absolute/relative) - if (stristr($src, "http") === false) - { - //Do something only if relative (otherwise the user will be able to see it too anyway) - //Get a proper URL and remove all './' + if (stristr($src, 'http') === false) { + // Do something only if relative (otherwise the user will be able to see it too anyway). + // Get a proper URL and remove all './' $src = urldecode($src); //mp3 $src = str_replace('./', '', $src); - //Remove the player link from the URL (only use the mp3 file) + // Remove the player link from the URL (only use the mp3 file). $src = str_replace('mp3player.swf?son=', '', $src); //mp3 - //Remove funny link parts + // Remove funny link parts. $src = str_replace('?0', '', $src); //mp3 - //The previous lines are used when creating docs with Dokeos Document tool's htmlarea - //rows marked by 'mp3' are needed because the mp3 plugin inserts the swf-mp3 links in a very strange way - //and we can decode them with those 3 lines, hoping this will not cause errors in case of other htmls, - //created by any other software - //Prepare source and destination paths + // The previous lines are used when creating docs with Dokeos Document tool's htmlarea. + // Rows marked by 'mp3' are needed because the mp3 plugin inserts the swf-mp3 links in a very strange way + // and we can decode them with those 3 lines, hoping this will not cause errors in case of other htmls, + // created by any other software. + // Prepare source and destination paths. $source = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.dirname($myrow['path']).'/'.$src; $dest = $expdir.'/data/'.$src; //CopyNCreate($source,$dest); @@ -1985,15 +1730,15 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false } //else...? } - //5 Prepare the special "close window" for this test + // 5. Prepare the special "close window" for this test. $closewindow = ""."
$langHotPotatoesFinished
"; - //Finish is the function of HP to save scores, we insert our scorm function calls to its beginning - //'Score' is the variable that tracks the score in HP tests - //6 + // Finish is the function of HP to save scores, we insert our scorm function calls to its beginning + // 'Score' is the variable that tracks the score in HP tests. + // 6. $mit = "function Finish(){"; - $js_content = "var SaveScoreVariable = 0; // This variable is included by Dokeos LP export\n"."function mySaveScore() // This function is included by Dokeos LP export\n"."{\n"." if (SaveScoreVariable==0)\n"." {\n"." SaveScoreVariable = 1;\n". + $js_content = "var SaveScoreVariable = 0; // This variable is included by Chamilo LP export\n"."function mySaveScore() // This function is included by Chamilo LP export\n"."{\n"." if (SaveScoreVariable==0)\n"." {\n"." SaveScoreVariable = 1;\n". //the following function are implemented in SCOFunctions.js " exitPageStatus = true;\n"." computeTime();\n"." doLMSSetValue( 'cmi.core.score.raw', Score );\n"." doLMSSetValue( 'cmi.core.lesson_status', 'completed' );\n"." doLMSCommit();\n"." doLMSFinish();\n". // " document.write('".$closewindow."');\n". @@ -2001,32 +1746,33 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false " }\n"."}\n"."function Finish(){\n"." mySaveScore();"; $start = ""; - //7 Replace the current MIT function call by our set of functions. In clear, transform HP to SCORM + // 7. Replace the current MIT function call by our set of functions. In clear, transform HP to SCORM. $content = str_replace($mit, $js_content, $content); - //8 Finally, add the API loading calls (although that might have been done first) + // 8. Finally, add the API loading calls (although that might have been done first). $content = str_replace("", "".$scocomfiles.$start, $content); - //9 Change the filename to add the database ID and export to a new file, - // setting the circle1_files array for later reuse + // 9. Change the filename to add the database ID and export to a new file, + // setting the circle1_files array for later reuse. $filename = str_replace('.htm', $id.'.htm', $filename); exporttofile($filename, $LPname, $id, $content); return; - //------------------------Dokeos test BEGIN------------------- - case "Exercise" : + // Chamilo test BEGIN + case 'Exercise': //1 Use the export_exercise() function to do the job of constructing the question's HTML table $expcontent .= export_exercise($item_id); break; - //------------------------POST BEGIN--------------------------------------- - case "Post" : - //1 Get the forum post data from the database + + // POST BEGIN + case 'Post': + // 1. Get the forum post data from the database. $tbl_posts =Database::get_course_table(TABLE_FORUM_POST); $tbl_posts_text =Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE); $result = Database::query("SELECT * FROM $tbl_posts where post_id=$item_id"); $myrow = Database::fetch_array($result); - // grabbing the title of the post - $sql_titel = "SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow["post_id"]; + // Grabbing the title of the post. + $sql_titel = "SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow['post_id']; $result_titel = Database::query($sql_titel); $myrow_titel = Database::fetch_array($result_titel); @@ -2052,55 +1798,55 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false "; break; - //------------------------NOT IMPLEMENTED ITEMS BEGIN------------------- - case "Forum" : - case "Thread" : - case "Dropbox" : - case "Assignments" : - case "Groups" : - case "Users" : - //1 Instead of building something, put an info message + + // NOT IMPLEMENTED ITEMS BEGIN + case 'Forum': + case 'Thread': + case 'Dropbox': + case 'Assignments': + case 'Groups': + case 'Users': + // 1. Instead of building something, put an info message. $langItemMissing1 = "There was a "; - $langItemMissing2 = "page (step) here in the original Dokeos Learning Path."; + $langItemMissing2 = "page (step) here in the original Chamilo Learning Path."; $expcontent .= "
$langItemMissing1 $item_type $langItemMissing2
"; break; - //------------------------Link BEGIN------------------------------------- - case "Link _self" : - case "Link _blank" : - //1 Get the link data from the database + + // Link BEGIN + case 'Link _self': + case 'Link _blank': + // 1. Get the link data from the database. $TABLETOOLLINK = Database :: get_course_link_table(); $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$item_id"); $myrow = Database::fetch_array($result); - $thelink = $myrow["url"]; - //2 Check the link type (open in blank page or in current page) - if ($item_type == "Link _blank") + $thelink = $myrow['url']; + // 2. Check the link type (open in blank page or in current page). + if ($item_type == 'Link _blank') { - $target = "_blank"; + $target = '_blank'; } - //3 Write the link to the export string + // 3. Write the link to the export string. $expcontent .= "$LPname"; - //4 Change the element type for later changes (this is lost, however, so useless here) - $item_type = "Link"; //to put this to the filename + // 4. Change the element type for later changes (this is lost, however, so useless here). + $item_type = 'Link'; // To put this to the filename. //$LPname="$LPname"; - //i am still not sure about Link export : to export them as files or they can appear in the TOC at once ? - //to enable the second possibility, unrem the row $LPname=... + // I am still not sure about Link export : to export them as files or they can appear in the TOC at once ? + // To enable the second possibility, unrem the row $LPname=... break; } - //now we add the Done button and the initialize function : loadpage() - //not in the case of Documents, HotP - if ($item_type != 'Exercise' and ($add_scorm_communications === true)) - { + // Now we add the Done button and the initialize function : loadpage() + // not in the case of Documents, HotP + if ($item_type != 'Exercise' and ($add_scorm_communications === true)) { $expcontent .= $donebutton; } - //End the export string with valid HTML tags + // End the export string with valid HTML tags. $expcontent .= ""; - //Prepare new file name + // Prepare new file name. $filename = $item_type.$id.".htm"; - //Write the export content to the new file + // Write the export content to the new file. exporttofile('data/'.$filename, $LPname, $id, $expcontent); - } /** @@ -2110,12 +1856,9 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false * @param string Description * @return void */ -function exportdescription($id, $item_type, $description) -{ - +function exportdescription($id, $item_type, $description) { global $expdir; - - $filename = $item_type.$id.".desc"; + $filename = $item_type.$id.'.desc'; $expcontent = $description; exporttofile($expdir.$filename, 'description_of_'.$item_type.$id, 'description_of_item_'.$id, $expcontent); } @@ -2125,20 +1868,14 @@ function exportdescription($id, $item_type, $description) * @param string The directory path * @return boolean True on success, false on failure */ -function deldir($dir) -{ +function deldir($dir) { $dh = opendir($dir); - while ($file = readdir($dh)) - { - if ($file != "." && $file != "..") - { - $fullpath = $dir."/".$file; - if (!is_dir($fullpath)) - { + while ($file = readdir($dh)) { + if ($file != '.' && $file != '..') { + $fullpath = $dir.'/'.$file; + if (!is_dir($fullpath)) { unlink($fullpath); - } - else - { + } else { deldir($fullpath); } } @@ -2146,14 +1883,10 @@ function deldir($dir) closedir($dh); - if (rmdir($dir)) - { + if (rmdir($dir)) { return true; } - else - { - return false; - } + return false; } /** @@ -2161,19 +1894,18 @@ function deldir($dir) * @param integer The path id * @return resource A zip file, containing a hopefully Scorm compliant course made from the LP. This might happen when we don't actually exit the function first :-) */ -function exportpath($learnpath_id) -{ - //1 Initialise variables +function exportpath($learnpath_id) { + // 1. Initialise variables. global $_course, $circle1_files, $LPnamesafe, $LPname, $expdir; //$tbl_learnpath_main, $tbl_learnpath_chapter, $tbl_learnpath_item, $tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); - //where applicable, add a scorm "Done" button at the end of all contents + // Where applicable, add a scorm "Done" button at the end of all contents. $add_scorm_button = true; - //2 Get the name of the LP + // 2. Get the name of the LP. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; $sql = "SELECT * FROM $tbl_learnpath_main WHERE (lp_id=$learnpath_id)"; $result = Database::query($sql); @@ -2181,11 +1913,11 @@ function exportpath($learnpath_id) $LPname = $row['learnpath_name']; $LPnamesafe = replace_dangerous_char($LPname, 'strict'); - //3 Get a temporary dir for creating the zip file + // 3. Get a temporary dir for creating the zip file. $expdir = api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe; $fromdir = '../scorm/export/'; //this dir contains some standard files - deldir($expdir); //make sure the temp dir is cleared + deldir($expdir); // Make sure the temp dir is cleared. mkdir($expdir, api_get_permissions_for_new_directories()); mkdir($expdir.'/css', api_get_permissions_for_new_directories()); mkdir($expdir.'/data', api_get_permissions_for_new_directories()); @@ -2194,53 +1926,48 @@ function exportpath($learnpath_id) mkdir($expdir.'/data/audio', api_get_permissions_for_new_directories()); mkdir($expdir.'/data/videos', api_get_permissions_for_new_directories()); - $circle1 = array (//this array contains the types of elements we want to export - 'Chapter', 'Agenda', 'Ad_Valvas', 'Course_description', 'Document', 'Introduction_text', 'Link _self', 'Link _blank', 'Forum', 'Thread', 'Post', 'Exercise', 'HotPotatoes', 'Assignments', 'Dropbox', 'Users', 'Groups'); - //$circle2=array(''); + $circle1 = array( // This array contains the types of elements we want to export. + 'Chapter', 'Agenda', 'Ad_Valvas', 'Course_description', 'Document', 'Introduction_text', 'Link _self', 'Link _blank', 'Forum', 'Thread', 'Post', 'Exercise', 'HotPotatoes', 'Assignments', 'Dropbox', 'Users', 'Groups'); + //$circle2 = array(''); - //4 Get the first level chapters - YW added parent_item_id condition for multi-level paths + // 4. Get the first level chapters - YW added parent_item_id condition for multi-level paths. $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id and parent_item_id=0) ORDER BY display_order ASC"; - //to get all the elements, we should use the function that builds the table of content get_learnpath_tree + // To get all the elements, we should use the function that builds the table of content get_learnpath_tree. //WHERE (lp_id=$learnpath_id) //ORDER BY parent_item_id, display_order ASC"; $result = Database::query($sql); - //5 export the items listed in Circle I one by one - while ($row = Database::fetch_array($result)) - { - //5.1 Get items data from the database for this chapter + // 5. export the items listed in Circle I one by one. + while ($row = Database::fetch_array($result)) { + // 5.1. Get items data from the database for this chapter. $parent_item_id = $row['id']; - //$sql2a="SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id and parent_item_id=$parent_item_id) ORDER BY display_order ASC"; - //$result2a=Database::query($sql); + //$sql2a = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id and parent_item_id=$parent_item_id) ORDER BY display_order ASC"; + //$result2a = Database::query($sql); $sql2b = "SELECT * FROM $tbl_learnpath_item WHERE (parent_item_id=$parent_item_id) ORDER BY display_order ASC"; $result2b = Database::query($sql2b); - while ($row2 = Database::fetch_array($result2b)) - { - //5.1.1 Check if the element is in the circle1 array + while ($row2 = Database::fetch_array($result2b)) { + // 5.1.1 Check if the element is in the circle1 array. $tobeexported = false; - for ($i = 0; $i < count($circle1) && !$tobeexported; $i ++) - { - //if the type is found in the circle1 array, ask for export - if ($circle1[$i] == $row2['item_type']) - { + for ($i = 0; $i < count($circle1) && !$tobeexported; $i ++) { + // If the type is found in the circle1 array, ask for export. + if ($circle1[$i] == $row2['item_type']) { $tobeexported = true; } } - //5.1.2 If applicable, export the item to an HTML file (see exportitem function for more details) - if ($tobeexported) - { + // 5.1.2 If applicable, export the item to an HTML file (see exportitem function for more details). + if ($tobeexported) { exportitem($row2['id'], $row2['item_id'], $row2['item_type'], $add_scorm_button); - /*if ($row2['description']) { //put the description of items to a separate file (.desc) - exportdescription($row2['id'],$row2['item_type'],$row2['description']); + /*if ($row2['description']) { // Put the description of items to a separate file (.desc). + exportdescription($row2['id'], $row2['item_type'], $row2['description']); }*/ } } //end of items loop } //end of first-level chapters loop - //6 export the other necceassary files + // 6. Export the other necceassary files. $filename = 'default.css'; copy('../css/'.$filename, $expdir.'/css/'.$filename); $filename = 'ims_xml.xsd'; @@ -2254,20 +1981,20 @@ function exportpath($learnpath_id) $filename = 'SCOFunctions.js'; copy($fromdir.$filename, $expdir.'/js/'.$filename); - //in case circle1_files is not defined, build it + // In case circle1_files is not defined, build it //$circle1_files - //7 create imsmanifest.xml + // 7. Create imsmanifest.xml. createimsmanifest($circle1_files, $learnpath_id); - //8 put the files in the exportdir into a zip and force download + // 8. Put the files in the exportdir into a zip and force download. include_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; - //create zipfile of given directory + // Create zipfile of given directory. $zip_folder = new PclZip(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe.".zip"); $zip_folder->create(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe."/", PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/"); //api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe); // whitout folder - // modified by imandak80 + // Modified by imandak80 /* copy(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe.".zip", api_get_path(SYS_COURSE_PATH).$_course['path']."/document/".$LPnamesafe.".zip"); @@ -2277,7 +2004,7 @@ function exportpath($learnpath_id) $zipfilename = $zipfoldername.".zip"; DocumentManager :: file_send_for_download($zipfilename, false, basename($LPnamesafe.".zip")); - //9 Delete the temporary zip file and directory + // 9. Delete the temporary zip file and directory. include_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; // in fileManage.lib.php my_delete($zipfilename); @@ -2285,7 +2012,7 @@ function exportpath($learnpath_id) //exit; - //0 Return the circle_files hash (array) + // 10. Return the circle_files hash (array). return ($circle1_files); //has been used before... } @@ -2299,30 +2026,28 @@ function exportpath($learnpath_id) * @return void * @author imandak80 */ -function exportSCORM($scormname, $course) -{ +function exportSCORM($scormname, $course) { global $_course; - //initialize - $tmpname = api_get_path(SYS_COURSE_PATH).$_course['path']."/scorm"; + // Initialize. + $tmpname = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm'; $zipfoldername = $tmpname.$scormname; - $zipfilename = $zipfoldername.".zip"; + $zipfilename = $zipfoldername.'.zip'; - //create zipfile of given directory + // Create zipfile of given directory. include_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; $zip_folder = new PclZip($zipfilename); $list = 1; - //$list = $zip_folder->create($zipfoldername."/",PCLZIP_OPT_REMOVE_PATH,$tmpname.$scormname."/"); // whitout folder - $list = $zip_folder->create($zipfoldername."/", PCLZIP_OPT_REMOVE_PATH, $tmpname); - if ($list == 0) - { - // echo "Error : ".$zip_folder->errorInfo(true); + //$list = $zip_folder->create($zipfoldername.'/',PCLZIP_OPT_REMOVE_PATH,$tmpname.$scormname."/"); // whitout folder + $list = $zip_folder->create($zipfoldername.'/', PCLZIP_OPT_REMOVE_PATH, $tmpname); + if ($list == 0) { + //echo "Error : ".$zip_folder->errorInfo(true); } - //send to client - DocumentManager :: file_send_for_download($zipfilename, false, basename($scormname.".zip")); + // Send to client. + DocumentManager :: file_send_for_download($zipfilename, false, basename($scormname.'.zip')); - //clear + // Clear. include_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; my_delete($zipfilename); } @@ -2337,40 +2062,33 @@ function exportSCORM($scormname, $course) * @param string * @return string */ -function xmltagwrite($tagname, $which, $data, $linebreak = "yes") -{ - switch ($which) - { - case "open" : - $tag = "<".$tagname; +function xmltagwrite($tagname, $which, $data, $linebreak = 'yes') { + switch ($which) { + case 'open': + $tag = '<'.$tagname; $i = 0; - while ($data[0][$i]) - { - $tag .= " ".$data[0][$i]."=\"".$data[1][$i]."\""; + while ($data[0][$i]) { + $tag .= ' '.$data[0][$i]."=\"".$data[1][$i]."\""; $i ++; } - if ($tagname == 'file') - { + if ($tagname == 'file') { $closing = '/'; } - $tag .= $closing.">"; - if ($linebreak != 'no_linebreak') - { + $tag .= $closing.'>'; + if ($linebreak != 'no_linebreak') { $tag .= "\n"; } break; - case "close" : - $tag = ""; - if ($linebreak != 'no_linebreak') - { + case 'close': + $tag = ''; + if ($linebreak != 'no_linebreak') { $tag .= "\n"; } break; - case "full" : - $tag = "<".$tagname; - $tag .= ">".$data.""; - if ($linebreak != 'no_linebreak') - { + case 'full': + $tag = '<'.$tagname; + $tag .= '>'.$data.''; + if ($linebreak != 'no_linebreak') { $tag .= "\n"; } break; @@ -2384,8 +2102,7 @@ function xmltagwrite($tagname, $which, $data, $linebreak = "yes") * @param integer Learnpath_id * @return void */ -function createimsmanifest($circle1_files, $learnpath_id) -{ +function createimsmanifest($circle1_files, $learnpath_id) { global $_course, $LPname, $expdir, $LPnamesafe; //$tbl_learnpath_main, $tbl_learnpath_chapter, $tbl_learnpath_item, $tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN); @@ -2394,19 +2111,19 @@ function createimsmanifest($circle1_files, $learnpath_id) include_once '../metadata/md_funcs.php'; // RH: export metadata - //1.1 header + // 1.1 Header /* $header=''."\n"; */ - //1.2 - //charset should be dependent on content + // 1.2 + // Charset should be dependent on content. $mycharset = api_get_system_encoding(); $header = ''."\n\n"; $org .= xmltagwrite('metadata', 'open'); - $org .= " ".xmltagwrite('schema', 'full', 'ADL SCORM'); - $org .= " ".xmltagwrite('schemaversion', 'full', '1.2'); + $org .= ' '.xmltagwrite('schema', 'full', 'ADL SCORM'); + $org .= ' '.xmltagwrite('schemaversion', 'full', '1.2'); $org .= xmltagwrite('metadata', 'close'); $defaultorgname = 'default_org'; @@ -2417,26 +2134,24 @@ function createimsmanifest($circle1_files, $learnpath_id) $attributes[0][0] = 'identifier'; $attributes[1][0] = $defaultorgname; - $org .= " ".xmltagwrite('organization', 'open', $attributes); + $org .= ' '.xmltagwrite('organization', 'open', $attributes); - $org .= " ".xmltagwrite('title', 'full', $LPname); + $org .= ' '.xmltagwrite('title', 'full', $LPname); - //items list + // Items list. $i = 0; $previous_item_id = '00'; - while ($circle1_files[0][$i]) - { - //check whether we are in the border of two chapters - //if (!$desc=strpos($circle1_files[2][$i],'scription')) { //this is is needed if the descriptions are exported to file + while ($circle1_files[0][$i]) { + // Check whether we are in the border of two chapters. + //if (!$desc=strpos($circle1_files[2][$i],'scription')) { // This is needed if the descriptions are exported to file. $sql = "SELECT * FROM $tbl_learnpath_item WHERE (id=".$circle1_files[2][$i].")"; $result = Database::query($sql); $row = Database::fetch_array($result); $parent_item_id = $row['parent_item_id']; - if ($parent_item_id != $previous_item_id) - { - //we create the item tag for the chapter (without indifierref) + if ($parent_item_id != $previous_item_id) { + // We create the item tag for the chapter (without indifierref). $sql2 = "SELECT * FROM $tbl_learnpath_chapter WHERE (id=".$parent_item_id.")"; $result2 = Database::query($sql2); $row2 = Database::fetch_array($result2); @@ -2447,91 +2162,84 @@ function createimsmanifest($circle1_files, $learnpath_id) $attributes[1][] = 'chapter_'.$row2['id']; $attributes[0][] = 'isvisible'; $attributes[1][] = '1'; - if ($previous_item_id != '00') - { - $org .= " ".xmltagwrite('item', 'close'); + if ($previous_item_id != '00') { + $org .= ' '.xmltagwrite('item', 'close'); } - $org .= " ".xmltagwrite('item', 'open', $attributes); - $org .= " ".xmltagwrite('title', 'full', $chapter_name); + $org .= ' '.xmltagwrite('item', 'open', $attributes); + $org .= ' '.xmltagwrite('title', 'full', $chapter_name); - if ($row2['chapter_description'] != '') - { - //chapter description + if ($row2['chapter_description'] != '') { + // Chapter description. $attributes = ''; $attributes[0][] = 'identifier'; $attributes[1][] = 'chapter_'.$row2['id'].'_desc'; $attributes[0][] = 'isvisible'; $attributes[1][] = '1'; - $org .= " ".xmltagwrite('item', 'open', $attributes); - $org .= " ".xmltagwrite('title', 'full', ' '.$row2['chapter_description']); - $org .= " ".xmltagwrite('item', 'close'); + $org .= ' '.xmltagwrite('item', 'open', $attributes); + $org .= ' '.xmltagwrite('title', 'full', ' '.$row2['chapter_description']); + $org .= ' '.xmltagwrite('item', 'close'); } } $previous_item_id = $parent_item_id; //} - $attributes = ''; //item output + $attributes = ''; // Item output. $attributes[0][] = 'identifier'; $attributes[1][] = 'item_'.$circle1_files[2][$i]; $attributes[0][] = 'identifierref'; $attributes[1][] = 'item_ref_'.$circle1_files[2][$i]; $attributes[0][] = 'isvisible'; $attributes[1][] = '1'; - $org .= " ".xmltagwrite('item', 'open', $attributes); - $org .= " ".xmltagwrite('title', 'full', $circle1_files[1][$i]); + $org .= ' '.xmltagwrite('item', 'open', $attributes); + $org .= ' '.xmltagwrite('title', 'full', $circle1_files[1][$i]); - if ($row['prereq_id'] != '') - { //item prerequisites + if ($row['prereq_id'] != '') { + // Item prerequisites. $attributes = ''; $attributes[0][] = 'type'; $attributes[1][] = 'aicc_script'; - $org .= " ".xmltagwrite('adlcp:prerequisites', 'open', $attributes, "no_linebreak"); - if ($row['prereq_type'] == 'i') - { + $org .= ' '.xmltagwrite('adlcp:prerequisites', 'open', $attributes, 'no_linebreak'); + if ($row['prereq_type'] == 'i') { $org .= 'item_'.$row['prereq_id']; } - if ($row['prereq_type'] == 'c') - { + if ($row['prereq_type'] == 'c') { $org .= 'chapter_'.$row['prereq_id']; } $org .= xmltagwrite('adlcp:prerequisites', 'close', $attributes); } - if ($row['description'] != '') - { - //item description + if ($row['description'] != '') { + // Item description. $attributes = ''; $attributes[0][] = 'identifier'; $attributes[1][] = 'item_'.$circle1_files[2][$i].'_desc'; $attributes[0][] = 'isvisible'; $attributes[1][] = '1'; - $org .= " ".xmltagwrite('item', 'open', $attributes); - $org .= " ".xmltagwrite('title', 'full', ' '.$row['description']); - $org .= " ".xmltagwrite('item', 'close'); + $org .= ' '.xmltagwrite('item', 'open', $attributes); + $org .= ' '.xmltagwrite('title', 'full', ' '.$row['description']); + $org .= ' '.xmltagwrite('item', 'close'); } - $mds = new mdstore(TRUE); // RH: export metadata; if no table, create it + $mds = new mdstore(true); // RH: export metadata; if no table, create it if (($mdt = $mds->mds_get($row['item_type'].'.'.$row['item_id']))) if (($mdo = api_strpos($mdt, '')) && ($mdc = api_strpos($mdt, ''))) - $org .= " ".api_substr($mdt, $mdo, $mdc - $mdo +11)."\n"; + $org .= ' '.api_substr($mdt, $mdo, $mdc - $mdo + 11)."\n"; - $org .= " ".xmltagwrite('item', 'close'); + $org .= ' '.xmltagwrite('item', 'close'); $i ++; } - if ($circle1_files) - { - $org .= " ".xmltagwrite('item', 'close'); - } //not needed in case of a blank path - $org .= " ".xmltagwrite('organization', 'close'); + if ($circle1_files) { + $org .= ' '.xmltagwrite('item', 'close'); + } // Not needed in case of a blank path. + $org .= ' '.xmltagwrite('organization', 'close'); $org .= xmltagwrite('organizations', 'close'); $org .= xmltagwrite('resources', 'open'); - //resources list + // Resources list. $i = 0; - while ($circle1_files[0][$i]) - { + while ($circle1_files[0][$i]) { $attributes = ''; $attributes[0][] = 'identifier'; $attributes[1][] = 'item_ref_'.$circle1_files[2][$i]; @@ -2541,19 +2249,19 @@ function createimsmanifest($circle1_files, $learnpath_id) $attributes[1][] = 'sco'; $attributes[0][] = 'href'; $attributes[1][] = $circle1_files[0][$i]; - $org .= " ".xmltagwrite('resource', 'open', $attributes); + $org .= ' '.xmltagwrite('resource', 'open', $attributes); - $org .= " ".xmltagwrite('metadata', 'open'); - $org .= " ".xmltagwrite('schema', 'full', 'ADL SCORM'); - $org .= " ".xmltagwrite('schemaversion', 'full', '1.2'); - $org .= " ".xmltagwrite('metadata', 'close'); + $org .= ' '.xmltagwrite('metadata', 'open'); + $org .= ' '.xmltagwrite('schema', 'full', 'ADL SCORM'); + $org .= ' '.xmltagwrite('schemaversion', 'full', '1.2'); + $org .= ' '.xmltagwrite('metadata', 'close'); $attributes = ''; $attributes[0][] = 'href'; $attributes[1][] = $circle1_files[0][$i]; - $org .= " ".xmltagwrite('file', 'open', $attributes); + $org .= ' '.xmltagwrite('file', 'open', $attributes); - $org .= " ".xmltagwrite('resource', 'close'); + $org .= ' '.xmltagwrite('resource', 'close'); $i ++; } @@ -2565,39 +2273,34 @@ function createimsmanifest($circle1_files, $learnpath_id) } /** - * Gets the tags of the file given as parameter - * - * if $filename is not found, GetSRCTags(filename) will return FALSE - * @param string file path - * @return mixed array of strings on success, false on failure - * @author unknown - * @author included by imandak80 - */ -function GetSRCTags($fileName) -{ - if (!($fp = fopen($fileName, "r"))) - { - //if file can't be opened, return false + * Gets the tags of the file given as parameter + * + * if $filename is not found, GetSRCTags(filename) will return FALSE + * @param string File path + * @return mixed Array of strings on success, false on failure + * @author unknown + * @author Included by imandak80 + */ +function GetSRCTags($fileName) { + if (!($fp = fopen($fileName, 'r'))) { + // Iif file can't be opened, return false. return false; } - //read file contents + // Read file contents. $contents = fread($fp, filesize($fileName)); fclose($fp); - $matches = array (); - $srcList = array (); - //get all src tags contents in this file. Use multi-line search. - preg_match_all('/src(\s)*=(\s)*[\'"]([^\'"]*)[\'"]/mi', $contents, $matches); //get the img src as contained between " or ' + $matches = array(); + $srcList = array(); + // Get all src tags contents in this file. Use multi-line search. + preg_match_all('/src(\s)*=(\s)*[\'"]([^\'"]*)[\'"]/mi', $contents, $matches); // Get the img src as contained between " or ' - foreach ($matches[3] as $match) - { - if (!in_array($match, $srcList)) - { + foreach ($matches[3] as $match) { + if (!in_array($match, $srcList)) { $srcList[] = $match; } } - if (count($srcList) == 0) - { + if (count($srcList) == 0) { return false; } return $srcList; @@ -2610,16 +2313,14 @@ function GetSRCTags($fileName) * @param string $dest Destination path * @return boolean true on success, false on failure */ -function CopyNCreate($source, $dest) -{ +function CopyNCreate($source, $dest) { if (strcmp($source, $dest) == 0) return false; - $dir = ""; + $dir = ''; $tdest = explode('/', $dest); - for ($i = 0; $i < sizeof($tdest) - 1; $i ++) - { - $dir = $dir.$tdest[$i]."/"; + for ($i = 0; $i < sizeof($tdest) - 1; $i ++) { + $dir = $dir.$tdest[$i].'/'; if (!is_dir($dir)) if (!mkdir($dir, api_get_permissions_for_new_directories())) return false; @@ -2631,75 +2332,54 @@ function CopyNCreate($source, $dest) return true; } -function rcopy($source, $dest) -{ - //error_log($source." -> ".$dest,0); - if (!file_exists($source)) - { - //error_log($source." does not exist",0); +function rcopy($source, $dest) { + //error_log($source." -> ".$dest, 0); + if (!file_exists($source)) { + //error_log($source." does not exist", 0); return false; } - if (is_dir($source)) - { - //error_log($source." is a dir",0); - //this is a directory - //remove trailing '/' - if (strrpos($source, '/') == sizeof($source) - 1) - { + if (is_dir($source)) { + //error_log($source." is a dir", 0); + // This is a directory. + // Remove trailing '/' + if (strrpos($source, '/') == sizeof($source) - 1) { $source = substr($source, 0, size_of($source) - 1); } - if (strrpos($dest, '/') == sizeof($dest) - 1) - { + if (strrpos($dest, '/') == sizeof($dest) - 1) { $dest = substr($dest, 0, size_of($dest) - 1); } - if (!is_dir($dest)) - { + if (!is_dir($dest)) { $res = @mkdir($dest, api_get_permissions_for_new_directories()); - if ($res !== false) - { + if ($res !== false) { return true; - } - else - { - //remove latest part of path and try creating that - if (rcopy(substr($source, 0, strrpos($source, '/')), substr($dest, 0, strrpos($dest, '/')))) - { + } else { + // Remove latest part of path and try creating that. + if (rcopy(substr($source, 0, strrpos($source, '/')), substr($dest, 0, strrpos($dest, '/')))) { return @mkdir($dest, api_get_permissions_for_new_directories()); - } - else - { + } else { return false; } } } return true; - } - else - { - //this is presumably a file - //error_log($source." is a file",0); - if (!@ copy($source, $dest)) - { - //error_log("Could not simple-copy $source",0); + } else { + // This is presumably a file. + //error_log($source." is a file", 0); + if (!@ copy($source, $dest)) { + //error_log("Could not simple-copy $source", 0); $res = rcopy(dirname($source), dirname($dest)); - if ($res === true) - { - //error_log("Welcome dir created",0); + if ($res === true) { + //error_log("Welcome dir created", 0); return @ copy($source, $dest); - } - else - { + } else { return false; - //error_log("Error creating path",0); + //error_log("Error creating path", 0); } - } - else - { - //error_log("Could well simple-copy $source",0); + } else { + //error_log("Could well simple-copy $source", 0); return true; } } } -?>