From 1150048a4bae115b9c58395c5426838f899f7e36 Mon Sep 17 00:00:00 2001 From: Patrick Cool Date: Sat, 25 Nov 2006 16:26:00 +0100 Subject: [PATCH] [svn r10195] third run of cleanup of the table names http://www.dokeos.com/forum/viewtopic.php?t=7982 --- main/admin/configure_extensions.php | 2 +- main/admin/course_information.php | 12 +- main/announcements/announcements.php | 8 +- main/calendar/agenda.inc.php | 22 +- main/calendar/agenda.php | 8 +- main/calendar/myagenda.php | 16 +- main/calendar/print.php | 6 +- main/course_description/index.php | 4 +- main/course_home/2column.php | 6 +- main/course_home/3column.php | 2 +- main/course_home/activity.php | 6 +- main/course_home/btf_functions.php | 8 +- main/course_home/course_home.php | 4 +- main/course_info/infocours.php | 20 +- .../classes/CourseBuilder.class.php | 32 +- .../classes/CourseRecycler.class.php | 20 +- .../classes/CourseRestorer.class.php | 22 +- main/document/create_document.php | 4 +- main/document/document.inc.php | 4 +- main/document/document.php | 4 +- main/document/downloadfolder.inc.php | 6 +- main/document/edit_document.php | 4 +- main/document/slideshow.php | 4 +- main/document/upload.php | 4 +- main/exercice/adminhp.php | 4 +- main/exercice/exercice.php | 4 +- main/exercice/exercise.class.php | 6 +- main/exercice/hotpotatoes.lib.php | 2 +- main/exercice/hotpotatoes.php | 2 +- main/external_module/external_module.php | 2 +- main/forum/forumconfig.inc.php | 2 +- main/group/group.php | 2 +- main/inc/introductionSection.inc.php | 2 +- main/inc/lib/add_course.lib.inc.php | 2 +- main/inc/lib/blog.lib.php | 8 +- main/inc/lib/course.lib.php | 2 +- main/inc/lib/database.lib.php | 32 +- main/inc/lib/document.lib.php | 17 +- .../plugins/Attachment/fck_Attachment.php | 2 +- main/inc/lib/fileDisplay.lib.php | 4 +- main/inc/lib/fileUpload.lib.php | 10 +- main/inc/lib/groupmanager.lib.php | 30 +- main/inc/lib/main_api.lib.php | 2 +- main/inc/local.inc.php | 2 +- main/inc/tool_navigation_menu.inc.php | 4 +- main/link/link.php | 4 +- main/link/linkfunctions.php | 28 +- main/metadata/importlinks.php | 6 +- main/metadata/importmanifest.php | 2 +- main/metadata/md_document.php | 4 +- main/metadata/md_link.php | 6 +- main/metadata/md_mix.php | 6 +- main/metadata/md_scorm.php | 2 +- main/mySpace/myStudents.php | 2 +- main/newscorm/document.php | 2 +- main/newscorm/learnpath.class.php | 12712 ++++++++-------- main/newscorm/learnpathList.class.php | 200 +- main/newscorm/learnpath_functions.inc.php | 10 +- main/newscorm/resourcelinker.inc.php | 4126 ++--- main/newscorm/resourcelinker.php | 24 +- main/newscorm/scorm_migrate_db.php | 12 +- main/newscorm/scorm_migrate_db_one_course.php | 8 +- main/newscorm/scorm_migrate_hometools.php | 2 +- .../scorm_migrate_hometools_reverse.php | 2 +- main/permissions/blog_permissions.inc.php | 2 +- main/resourcelinker/resourcelinker.inc.php | 8 +- main/resourcelinker/resourcelinker.php | 18 +- main/tracking/courseLog.php | 2 +- main/tracking/userLog.php | 6 +- main/upload/upload.document.php | 466 +- main/user/user.php | 4 +- main/work/work.lib.php | 6 +- main/work/work.php | 4 +- myStudents.php | 2 +- user_portal.php | 14 +- 75 files changed, 9028 insertions(+), 9031 deletions(-) diff --git a/main/admin/configure_extensions.php b/main/admin/configure_extensions.php index d0d25d357f..f51a11025e 100644 --- a/main/admin/configure_extensions.php +++ b/main/admin/configure_extensions.php @@ -63,7 +63,7 @@ if(isset($_POST['activeExtension'])){ $rs = api_sql_query($sql); while($row = mysql_fetch_array($rs)){ - $sql = 'INSERT INTO '.$row['db_name'].'.'.TOOL_LIST_TABLE.' SET + $sql = 'INSERT INTO '.$row['db_name'].'.'.TABLE_TOOL_LIST.' SET name="visio", link="conf/", image="visio.gif", diff --git a/main/admin/course_information.php b/main/admin/course_information.php index 5a1cfbe380..7233f006cc 100644 --- a/main/admin/course_information.php +++ b/main/admin/course_information.php @@ -1,5 +1,5 @@ db_name); $usage[] = array (get_lang(TOOL_QUIZ), Database::count_rows($table)); // Documents - $table = Database :: get_course_table(DOCUMENT_TABLE, $course->db_name); + $table = Database :: get_course_table(TABLE_DOCUMENT, $course->db_name); $usage[] = array (get_lang(TOOL_DOCUMENT), Database::count_rows($table)); // Groups - $table = Database :: get_course_table(GROUP_TABLE, $course->db_name); + $table = Database :: get_course_table(TABLE_GROUP, $course->db_name); $usage[] = array (get_lang(TOOL_GROUP), Database::count_rows($table)); // Calendar - $table = Database :: get_course_table(AGENDA_TABLE, $course->db_name); + $table = Database :: get_course_table(TABLE_AGENDA, $course->db_name); $usage[] = array (get_lang(TOOL_CALENDAR_EVENT), Database::count_rows($table)); // Link - $table = Database::get_course_table(LINK_TABLE, $course->db_name); + $table = Database::get_course_table(TABLE_LINK, $course->db_name); $usage[] = array(get_lang(TOOL_LINK), Database::count_rows($table)); // Announcements - $table = Database::get_course_table(ANNOUNCEMENT_TABLE, $course->db_name); + $table = Database::get_course_table(TABLE_ANNOUNCEMENT, $course->db_name); $usage[] = array(get_lang(TOOL_ANNOUNCEMENT), Database::count_rows($table)); return $usage; } diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index c1cdd89966..3f8cec2c2d 100644 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -1,4 +1,4 @@ -0) @@ -761,7 +761,7 @@ return $send_to; function sent_to($tool, $id) { global $_course; -$TABLE_ITEM_PROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); +$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'"; $result=api_sql_query($sql,__FILE__,__LINE__); @@ -967,7 +967,7 @@ function show_user_group_filter_form() function load_edit_users($tool, $id) { global $_course; -$TABLE_ITEM_PROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); +$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='$tool' AND ref='$id'"; $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error()); @@ -1001,7 +1001,7 @@ return $to; function change_visibility($tool,$id) { global $_course; - $TABLE_ITEM_PROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); + $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".TOOL_CALENDAR_EVENT."' AND ref='$id'"; $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error()); @@ -1111,7 +1111,7 @@ function store_edited_agenda_item() global $_user; // database definitions - $TABLE_ITEM_PROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); + $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); // STEP 1: editing the calendar_event table // 1.a. some filtering of the input data @@ -1173,7 +1173,7 @@ function store_edited_agenda_item() */ function save_edit_agenda_item($id,$title,$content,$start_date,$end_date) { - $TABLEAGENDA = Database::get_course_table(AGENDA_TABLE); + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); // store the modifications in the table calendar_event $sql = "UPDATE ".$TABLEAGENDA." diff --git a/main/calendar/agenda.php b/main/calendar/agenda.php index 5c64ef9dd3..bdca50056f 100644 --- a/main/calendar/agenda.php +++ b/main/calendar/agenda.php @@ -1,4 +1,4 @@ - $array_course_info) { //databases of the courses - $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $array_course_info["db"]); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); // if the user is administrator of that course we show all the agenda items @@ -709,8 +709,8 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) foreach ($courses_dbs as $key => $array_course_info) { //databases of the courses - $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $array_course_info["db"]); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); // getting all the groups of the user for the current course $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); @@ -857,8 +857,8 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') foreach ($courses_dbs as $key => $array_course_info) { //databases of the courses - $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $array_course_info["db"]); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); // getting all the groups of the user for the current course $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); diff --git a/main/calendar/print.php b/main/calendar/print.php index 8c1425ff47..e2cae3f557 100644 --- a/main/calendar/print.php +++ b/main/calendar/print.php @@ -20,7 +20,7 @@ include('../inc/global.inc.php'); -$TABLEAGENDA = Database::get_course_table(AGENDA_TABLE); +$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); $sql = "SELECT * FROM $TABLEAGENDA WHERE id IN($id) ORDER BY start_date DESC"; $result = api_sql_query($sql,__FILE__,__LINE__); @@ -38,7 +38,7 @@ $result = api_sql_query($sql,__FILE__,__LINE__);
- +


@@ -75,7 +75,7 @@ while($row=mysql_fetch_array($result))

- +
diff --git a/main/course_description/index.php b/main/course_description/index.php index c7da3b95d8..79242ba246 100644 --- a/main/course_description/index.php +++ b/main/course_description/index.php @@ -1,4 +1,4 @@ - "index.php", "name" => get_lang('CourseProgram')); -$tbl_course_description = Database::get_course_table(COURSE_DESCRIPTION_TABLE); +$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION); $show_description_list = true; $show_peda_suggest = true; define('ADD_BLOCK', 0); diff --git a/main/course_home/2column.php b/main/course_home/2column.php index 9d9363e6a6..fd44146cce 100644 --- a/main/course_home/2column.php +++ b/main/course_home/2column.php @@ -53,7 +53,7 @@ function show_tools($course_tool_category) { $web_code_path = api_get_path(WEB_CODE_PATH); - $course_tool_table = Database::get_course_table(TOOL_LIST_TABLE); + $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); switch ($course_tool_category) { @@ -94,8 +94,8 @@ function show_tools($course_tool_category) } // grabbing all the links that have the property on_homepage set to 1 - $course_link_table = Database::get_course_table(LINK_TABLE); - $course_item_property_table = Database::get_course_table(ITEM_PROPERTY_TABLE); + $course_link_table = Database::get_course_table(TABLE_LINK); + $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); switch ($course_tool_category) { case TOOL_PUBLIC: diff --git a/main/course_home/3column.php b/main/course_home/3column.php index ffb584274f..933d055e75 100644 --- a/main/course_home/3column.php +++ b/main/course_home/3column.php @@ -47,7 +47,7 @@ $is_AllowedToEdit = is_allowed_to_edit(); // RH: Allowed is not allowed... $TABLE_TOOLS = Database::get_main_table(TABLE_MAIN_COURSE_MODULE); -$TBL_ACCUEIL = Database::get_course_table(TOOL_LIST_TABLE); +$TBL_ACCUEIL = Database::get_course_table(TABLE_TOOL_LIST); // WORK with data post askable by admin of course if (is_allowed_to_edit()) diff --git a/main/course_home/activity.php b/main/course_home/activity.php index 89d480f287..2645eeb83c 100644 --- a/main/course_home/activity.php +++ b/main/course_home/activity.php @@ -55,7 +55,7 @@ function show_tools_category($course_tool_category) { $web_code_path = api_get_path(WEB_CODE_PATH); - $course_tool_table = Database::get_course_table(TOOL_LIST_TABLE); + $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); switch ($course_tool_category) { @@ -100,8 +100,8 @@ function show_tools_category($course_tool_category) $i=0; // grabbing all the links that have the property on_homepage set to 1 - $course_link_table = Database::get_course_table(LINK_TABLE); - $course_item_property_table = Database::get_course_table(ITEM_PROPERTY_TABLE); + $course_link_table = Database::get_course_table(TABLE_LINK); + $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); diff --git a/main/course_home/btf_functions.php b/main/course_home/btf_functions.php index 408a570549..26eccdfb9a 100644 --- a/main/course_home/btf_functions.php +++ b/main/course_home/btf_functions.php @@ -1,5 +1,5 @@ course->resources as $type => $resources) { foreach ($resources as $id => $resource) @@ -121,8 +121,8 @@ class CourseBuilder */ function build_documents() { - $table_doc = Database :: get_course_table(DOCUMENT_TABLE); - $table_prop = Database :: get_course_table(ITEM_PROPERTY_TABLE); + $table_doc = Database :: get_course_table(TABLE_DOCUMENT); + $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY); $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 ORDER BY path'; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -196,8 +196,8 @@ class CourseBuilder */ function build_links() { - $table = Database :: get_course_table(LINK_TABLE); - $table_prop = Database :: get_course_table(ITEM_PROPERTY_TABLE); + $table = Database :: get_course_table(TABLE_LINK); + $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY); $sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 ORDER BY l.display_order"; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -212,7 +212,7 @@ class CourseBuilder */ function build_tool_intro() { - $table = Database :: get_course_table(TOOL_INTRO_TABLE); + $table = Database :: get_course_table(TABLE_TOOL_INTRO); $sql = 'SELECT * FROM '.$table; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -226,7 +226,7 @@ class CourseBuilder */ function build_link_category($id) { - $link_cat_table = Database :: get_course_table(LINK_CATEGORY_TABLE); + $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY); $sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -242,7 +242,7 @@ class CourseBuilder { $table_qui = Database :: get_course_table(QUIZ_TEST_TABLE); $table_rel = Database :: get_course_table(QUIZ_TEST_QUESTION_TABLE); - $table_doc = Database :: get_course_table(DOCUMENT_TABLE); + $table_doc = Database :: get_course_table(TABLE_DOCUMENT); $sql = 'SELECT * FROM '.$table_qui; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -289,7 +289,7 @@ class CourseBuilder */ function build_announcements() { - $table = Database :: get_course_table(ANNOUNCEMENT_TABLE); + $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); $sql = 'SELECT * FROM '.$table; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -303,7 +303,7 @@ class CourseBuilder */ function build_events() { - $table = Database :: get_course_table(AGENDA_TABLE); + $table = Database :: get_course_table(TABLE_AGENDA); $sql = 'SELECT * FROM '.$table; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -317,7 +317,7 @@ class CourseBuilder */ function build_course_descriptions() { - $table = Database :: get_course_table(COURSE_DESCRIPTION_TABLE); + $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); $sql = 'SELECT * FROM '.$table; $db_result = api_sql_query($sql, __FILE__, __LINE__); while ($obj = mysql_fetch_object($db_result)) @@ -331,10 +331,10 @@ class CourseBuilder */ function build_learnpaths() { - $table_main = Database :: get_course_table(LEARNPATH_MAIN_TABLE); - $table_chapter = Database :: get_course_table(LEARNPATH_CHAPTER_TABLE); - $table_item = Database :: get_course_table(LEARNPATH_ITEM_TABLE); - $table_tool = Database::get_course_table(TOOL_LIST_TABLE); + $table_main = Database :: get_course_table(LEARNPATH_MAIN_TABLE); + $table_chapter = Database :: get_course_table(LEARNPATH_CHAPTER_TABLE); + $table_item = Database :: get_course_table(LEARNPATH_ITEM_TABLE); + $table_tool = Database::get_course_table(TABLE_TOOL_LIST); $sql = 'SELECT * FROM '.$table_main; $db_result = api_sql_query($sql, __FILE__, __LINE__); diff --git a/main/coursecopy/classes/CourseRecycler.class.php b/main/coursecopy/classes/CourseRecycler.class.php index 5f38040b88..73bde491bd 100644 --- a/main/coursecopy/classes/CourseRecycler.class.php +++ b/main/coursecopy/classes/CourseRecycler.class.php @@ -1,5 +1,5 @@ course->destination_db); - $table_item_properties = Database::get_course_table(ITEM_PROPERTY_TABLE); + $table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY); foreach ($this->course->resources as $type => $resources) { foreach ($resources as $id => $resource) @@ -82,7 +82,7 @@ class CourseRecycler { if ($this->course->has_resources(RESOURCE_DOCUMENT)) { - $table = Database :: get_course_table(DOCUMENT_TABLE); + $table = Database :: get_course_table(TABLE_DOCUMENT); foreach ($this->course->resources[RESOURCE_DOCUMENT] as $id => $document) { rmdirr($this->course->backup_path.'/'.$document->path); @@ -99,7 +99,7 @@ class CourseRecycler { if ($this->course->has_resources(RESOURCE_LINK)) { - $table = Database :: get_course_table(LINK_TABLE); + $table = Database :: get_course_table(TABLE_LINK); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_LINK]))); $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; api_sql_query($sql,__FILE__,__LINE__); @@ -157,8 +157,8 @@ class CourseRecycler */ function recycle_link_categories() { - $link_cat_table = Database :: get_course_table(LINK_CATEGORY_TABLE); - $link_table = Database :: get_course_table(LINK_TABLE); + $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY); + $link_table = Database :: get_course_table(TABLE_LINK); $sql = "SELECT lc.id FROM ".$link_cat_table." lc LEFT JOIN ".$link_table." l ON lc.id=l.category_id WHERE l.id IS NULL"; $res = api_sql_query($sql,__FILE__,__LINE__); while ($obj = mysql_fetch_object($res)) @@ -174,7 +174,7 @@ class CourseRecycler { if ($this->course->has_resources(RESOURCE_EVENT)) { - $table = Database :: get_course_table(AGENDA_TABLE); + $table = Database :: get_course_table(TABLE_AGENDA); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_EVENT]))); $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; api_sql_query($sql,__FILE__,__LINE__); @@ -187,7 +187,7 @@ class CourseRecycler { if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { - $table = Database :: get_course_table(ANNOUNCEMENT_TABLE); + $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_ANNOUNCEMENT]))); $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; api_sql_query($sql,__FILE__,__LINE__); @@ -219,7 +219,7 @@ class CourseRecycler $table_main = Database :: get_course_table(LEARNPATH_MAIN_TABLE); $table_chapter = Database :: get_course_table(LEARNPATH_CHAPTER_TABLE); $table_item = Database :: get_course_table(LEARNPATH_ITEM_TABLE); - $table_tool = Database::get_course_table(TOOL_LIST_TABLE); + $table_tool = Database::get_course_table(TABLE_TOOL_LIST); foreach($this->course->resources[RESOURCE_LEARNPATH] as $id => $learnpath) { $sql = "DELETE FROM $table_tool WHERE link='".mysql_real_escape_string('learnpath/learnpath_handler.php?learnpath_id='.$id)."'"; @@ -252,7 +252,7 @@ class CourseRecycler { if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { - $table = Database :: get_course_table(COURSE_DESCRIPTION_TABLE); + $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_COURSEDESCRIPTION]))); $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; api_sql_query($sql,__FILE__,__LINE__); diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index afbca1ab49..a11199b19d 100644 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -1,7 +1,7 @@ restore_quizzes(); // after restore_documents! (for correct import of sound/video) $this->restore_learnpaths(); // Restore the item properties - $table = Database :: get_course_table(ITEM_PROPERTY_TABLE, $this->course->destination_db); + $table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db); foreach ($this->course->resources as $type => $resources) { foreach ($resources as $id => $resource) @@ -161,7 +161,7 @@ class CourseRestorer { if ($this->course->has_resources(RESOURCE_DOCUMENT)) { - $table = Database :: get_course_table(DOCUMENT_TABLE, $this->course->destination_db); + $table = Database :: get_course_table(TABLE_DOCUMENT, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { @@ -427,7 +427,7 @@ class CourseRestorer { if ($this->course->has_resources(RESOURCE_LINK)) { - $link_table = Database :: get_course_table(LINK_TABLE, $this->course->destination_db); + $link_table = Database :: get_course_table(TABLE_LINK, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_LINK] as $id => $link) { @@ -448,7 +448,7 @@ class CourseRestorer { if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) { - $tool_intro_table = Database :: get_course_table(TOOL_INTRO_TABLE, $this->course->destination_db); + $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) { @@ -469,7 +469,7 @@ class CourseRestorer { if ($id == 0) return 0; - $link_cat_table = Database :: get_course_table(LINK_CATEGORY_TABLE, $this->course->destination_db); + $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY, $this->course->destination_db); $resources = $this->course->resources; $link_cat = $resources[RESOURCE_LINKCATEGORY][$id]; if (!$link_cat->is_restored()) @@ -493,7 +493,7 @@ class CourseRestorer { if ($this->course->has_resources(RESOURCE_EVENT)) { - $table = Database :: get_course_table(AGENDA_TABLE, $this->course->destination_db); + $table = Database :: get_course_table(TABLE_AGENDA, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_EVENT] as $id => $event) { @@ -510,7 +510,7 @@ class CourseRestorer { if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { - $table = Database :: get_course_table(COURSE_DESCRIPTION_TABLE, $this->course->destination_db); + $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) { @@ -527,7 +527,7 @@ class CourseRestorer { if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { - $table = Database :: get_course_table(ANNOUNCEMENT_TABLE, $this->course->destination_db); + $table = Database :: get_course_table(TABLE_ANNOUNCEMENT, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { @@ -546,7 +546,7 @@ class CourseRestorer { $table_qui = Database :: get_course_table(QUIZ_TEST_TABLE, $this->course->destination_db); $table_rel = Database :: get_course_table(QUIZ_TEST_QUESTION_TABLE, $this->course->destination_db); - $table_doc = Database :: get_course_table(DOCUMENT_TABLE, $this->course->destination_db); + $table_doc = Database :: get_course_table(TABLE_DOCUMENT, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { @@ -615,7 +615,7 @@ class CourseRestorer $table_main = Database :: get_course_table(LEARNPATH_MAIN_TABLE, $this->course->destination_db); $table_chapter = Database :: get_course_table(LEARNPATH_CHAPTER_TABLE, $this->course->destination_db); $table_item = Database :: get_course_table(LEARNPATH_ITEM_TABLE, $this->course->destination_db); - $table_tool = Database::get_course_table(TOOL_LIST_TABLE, $this->course->destination_db); + $table_tool = Database::get_course_table(TABLE_TOOL_LIST, $this->course->destination_db); $resources = $this->course->resources; $prereq_old = array (); diff --git a/main/document/create_document.php b/main/document/create_document.php index 29f992118a..3e50c26f67 100644 --- a/main/document/create_document.php +++ b/main/document/create_document.php @@ -1,5 +1,5 @@ validate()) $new_title = isset ($_POST['title']) ? trim($_POST['title']) : ''; if ($new_comment || $new_title) { - $TABLE_DOCUMENT = Database::get_course_table(DOCUMENT_TABLE); + $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $ct = ''; if ($new_comment) $ct .= ", comment='$new_comment'"; diff --git a/main/document/document.inc.php b/main/document/document.inc.php index 95c8f36d1f..9de1253134 100644 --- a/main/document/document.inc.php +++ b/main/document/document.inc.php @@ -1,4 +1,4 @@ -"./exercice.php", "name"=> get_lang('Exercices $is_allowedToEdit=(!empty($is_courseAdmin)?$is_courseAdmin:false); //$dbTable = '`'.$_course['dbNameGlu']."document`"; -$dbTable = Database::get_course_table(DOCUMENT_TABLE); +$dbTable = Database::get_course_table(TABLE_DOCUMENT); $baseServDir = $_configuration['root_sys']; $baseServUrl = $_configuration['url_append']."/"; $document_sys_path = api_get_path(SYS_COURSE_PATH).$_course['path']."/document"; diff --git a/main/external_module/external_module.php b/main/external_module/external_module.php index 194f73b955..65c2656838 100644 --- a/main/external_module/external_module.php +++ b/main/external_module/external_module.php @@ -43,7 +43,7 @@ $iconForInactiveImportedTools='external_inactive.gif'; include('../inc/global.inc.php'); -$tbl_courseHome = Database::get_course_table(TOOL_LIST_TABLE); +$tbl_courseHome = Database::get_course_table(TABLE_TOOL_LIST); $toolid = $_GET['id']; // RH: all lines with $toolid added/changed by me if($toolid) diff --git a/main/forum/forumconfig.inc.php b/main/forum/forumconfig.inc.php index 666a7a3a4d..3125d5de1f 100644 --- a/main/forum/forumconfig.inc.php +++ b/main/forum/forumconfig.inc.php @@ -20,7 +20,7 @@ $table_threads = "`".$_course["dbNameGlu"]."forum_thread"."`"; $table_posts = "`".$_course["dbNameGlu"]."forum_post"."`"; $table_mailcue = "`".$_course["dbNameGlu"]."forum_mailcue"."`"; -$table_item_property = Database :: get_course_table(LAST_TOOL_EDIT_TABLE); +$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $table_users = Database :: get_main_table(TABLE_MAIN_USER); /* diff --git a/main/group/group.php b/main/group/group.php index 452a806524..feddc8be0a 100644 --- a/main/group/group.php +++ b/main/group/group.php @@ -194,7 +194,7 @@ if (api_is_allowed_to_edit()) { echo '
  • '.get_lang('PropModify').'
  • '; } - if( Database::count_rows(Database::get_course_table(GROUP_TABLE)) > 0) + if( Database::count_rows(Database::get_course_table(TABLE_GROUP)) > 0) { echo '
  • '.get_lang('GroupOverview').'
  • '; } diff --git a/main/inc/introductionSection.inc.php b/main/inc/introductionSection.inc.php index b2c8bbcd84..07ec1c46a3 100644 --- a/main/inc/introductionSection.inc.php +++ b/main/inc/introductionSection.inc.php @@ -53,7 +53,7 @@ include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php') Constants and variables ----------------------------------------------------------- */ -$TBL_INTRODUCTION = Database::get_course_table(TOOL_INTRO_TABLE); +$TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO); $intro_editAllowed = $is_allowed_to_edit; $intro_cmdEdit = $_GET['intro_cmdEdit']; diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 04a52df829..f1f5213d1e 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -1629,7 +1629,7 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $ $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); #$TABLEANNOUNCEMENTS=$_configuration['table_prefix'].$courseDbName.$_configuration['db_glue'].$TABLEANNOUNCEMENTS; - $TABLEANNOUNCEMENTS = Database :: get_course_table(ANNOUNCEMENT_TABLE,$courseDbName); + $TABLEANNOUNCEMENTS = Database :: get_course_table(TABLE_ANNOUNCEMENT,$courseDbName); $okForRegisterCourse = true; diff --git a/main/inc/lib/blog.lib.php b/main/inc/lib/blog.lib.php index 21fc911798..0aa210b4bb 100644 --- a/main/inc/lib/blog.lib.php +++ b/main/inc/lib/blog.lib.php @@ -139,7 +139,7 @@ class Blog // Tabel definitions $tbl_blogs = Database::get_course_table(BLOGS_TABLE); - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $tbl_blogs_posts = Database::get_course_table(BLOGS_POSTS_TABLE); $tbl_blogs_tasks = Database::get_course_table(BLOGS_TASKS); @@ -178,7 +178,7 @@ class Blog // Table definitions $tbl_blogs = Database::get_course_table(BLOGS_TABLE); - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); // Update the blog $sql = "UPDATE $tbl_blogs SET blog_name = '$title', blog_subtitle = '$subtitle' WHERE blog_id =$blog_id LIMIT 1"; @@ -206,7 +206,7 @@ class Blog $tbl_blogs = Database::get_course_table(BLOGS_TABLE); $tbl_blogs_posts = Database::get_course_table(BLOGS_POSTS_TABLE); $tbl_blogs_tasks = Database::get_course_table(BLOGS_TASKS); - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $tbl_blogs_rating = Database::get_course_table(BLOGS_RATING); // Delete posts @@ -626,7 +626,7 @@ class Blog { // Init $tbl_blogs = Database::get_course_table(BLOGS_TABLE); - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); // Get blog properties $sql = "SELECT blog_name, visibility FROM $tbl_blogs WHERE blog_id=$blog_id"; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 58b84332dc..17a23d4c16 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1083,7 +1083,7 @@ class CourseManager { $course_info = Database :: get_course_info($course_code); $database_name = $course_info['db_name']; - $group_table = Database :: get_course_table(GROUP_TABLE, $database_name); + $group_table = Database :: get_course_table(TABLE_GROUP, $database_name); $group_user_table = Database :: get_course_table(GROUP_USER_TABLE, $database_name); $sql = "SELECT g.id, g.name, COUNT(gu.id) userNb diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 770908d474..dc885beca0 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -73,25 +73,25 @@ define('STATISTIC_TRACK_E_COURSE_ACCESS_TABLE', 'track_e_course_access'); define('SCORM_MAIN_TABLE', 'scorm_main'); define('SCORM_SCO_DATA_TABLE', 'scorm_sco_data'); //course tables -define('AGENDA_TABLE', 'calendar_event'); -define('ANNOUNCEMENT_TABLE', 'announcement'); -define('CHAT_CONNECTED_TABLE', 'chat_connected'); -define('COURSE_DESCRIPTION_TABLE', 'course_description'); -define('DOCUMENT_TABLE', 'document'); -define('LAST_TOOL_EDIT_TABLE', 'item_property'); -define('LINK_TABLE', 'link'); -define('LINK_CATEGORY_TABLE', 'link_category'); -define('TOOL_LIST_TABLE', 'tool'); -define('TOOL_INTRO_TABLE', 'tool_intro'); -define('SCORMDOC_TABLE', 'scormdocument'); -define('STUDENT_PUBLICATION_TABLE', 'student_publication'); +define('TABLE_AGENDA', 'calendar_event'); +define('TABLE_ANNOUNCEMENT', 'announcement'); +define('TABLE_CHAT_CONNECTED', 'chat_connected'); // @todo: probably no longer in use !!! +define('TABLE_COURSE_DESCRIPTION', 'course_description'); +define('TABLE_DOCUMENT', 'document'); +define('TABLE_ITEM_PROPERTY', 'item_property'); +define('TABLE_LINK', 'link'); +define('TABLE_LINK_CATEGORY', 'link_category'); +define('TABLE_TOOL_LIST', 'tool'); +define('TABLE_TOOL_INTRO', 'tool_intro'); +define('TABLE_SCORMDOC', 'scormdocument'); +define('TABLE_STUDENT_PUBLICATION', 'student_publication'); //course forum tables define('TABLE_FORUM_CATEGORY','forum_category'); define('TABLE_FORUM','forum_forum'); define('TABLE_FORUM_THREAD','forum_thread'); define('TABLE_FORUM_POST','forum_post'); //course group tables -define('GROUP_TABLE', 'group_info'); +define('TABLE_GROUP', 'group_info'); define('GROUP_USER_TABLE', 'group_rel_user'); define('GROUP_TUTOR_TABLE', 'group_rel_tutor'); define('GROUP_CATEGORY_TABLE', 'group_category'); @@ -130,8 +130,6 @@ define('BLOGS_TASKS_PERMISSIONS', 'permission_task'); // user information tables define('USER_INFO_TABLE', 'userinfo_def'); define('USER_INFO_CONTENT_TABLE', 'userinfo_content'); -// item property table -define('ITEM_PROPERTY_TABLE', 'item_property'); // course settings table define('COURSE_SETTING_TABLE', 'course_setting'); // course online tables @@ -254,7 +252,7 @@ class Database so the queries can look cleaner. Example: - $table = Database::get_course_document_table(); + $table = Database::get_course_table(TABLE_DOCUMENT); $sql_query = "SELECT * FROM $table WHERE $condition"; $sql_result = api_sql_query($sql_query,__FILE__,__LINE__); $result = mysql_fetch_array($sql_result); @@ -603,7 +601,7 @@ class Database { $database_name_with_glue = Database::fix_database_parameter($database_name); - return Database::format_glued_course_table_name($database_name_with_glue, TOOL_LIST_TABLE); + return Database::format_glued_course_table_name($database_name_with_glue, TABLE_TOOL_LIST); } } //end class Database diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 65d1b462d8..28e40bb615 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -314,8 +314,7 @@ class DocumentManager } else { - //$document_table = Database::get_course_document_table(); - $tbl_document = $this_course.'document'; + $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_item_property = $this_course.'item_property'; //$doc_url = addslashes($doc_url); $query = "SELECT 1 FROM `$tbl_document` AS docs,`$tbl_item_property` AS props WHERE props.tool = 'document' AND docs.id=props.ref AND props.visibility <> '1' AND docs.path = '$doc_url'"; @@ -408,8 +407,8 @@ class DocumentManager */ function get_all_document_data($_course, $path = '/', $to_group_id = 0, $to_user_id = NULL, $can_see_invisible = false) { - $TABLE_ITEMPROPERTY = Database :: get_course_table(ITEM_PROPERTY_TABLE, $_course['dbName']); - $TABLE_DOCUMENT = Database :: get_course_table(DOCUMENT_TABLE, $_course['dbName']); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']); + $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $_course['dbName']); //if to_user_id = NULL -> change query (IS NULL) //$to_user_id = (is_null($to_user_id))?'IS NULL':'= '.$to_user_id; @@ -479,8 +478,8 @@ class DocumentManager */ function get_all_document_folders($_course, $to_group_id = '0', $can_see_invisible = false) { - $TABLE_ITEMPROPERTY = Database :: get_course_table(ITEM_PROPERTY_TABLE, $_course['dbName']); - $TABLE_DOCUMENT = Database :: get_course_table(DOCUMENT_TABLE, $_course['dbName']); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']); + $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $_course['dbName']); if(empty($to_group_id)){$to_group_id = '0';} //avoid empty strings in $to_group_id if ($can_see_invisible) { @@ -587,8 +586,8 @@ class DocumentManager */ function delete_document($_course, $path, $base_work_dir) { - $TABLE_DOCUMENT = Database :: get_course_table(DOCUMENT_TABLE); - $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE); + $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); //first, delete the actual document... $document_id = DocumentManager :: get_document_id($_course, $path); @@ -688,7 +687,7 @@ class DocumentManager */ function get_document_id($_course, $path) { - $TABLE_DOCUMENT = Database :: get_course_table(DOCUMENT_TABLE, $_course['dbName']); + $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $_course['dbName']); $sql = "SELECT id FROM $TABLE_DOCUMENT WHERE path = '$path'"; diff --git a/main/inc/lib/fckeditor/editor/plugins/Attachment/fck_Attachment.php b/main/inc/lib/fckeditor/editor/plugins/Attachment/fck_Attachment.php index ec73b8e60d..8d10cbb8fb 100644 --- a/main/inc/lib/fckeditor/editor/plugins/Attachment/fck_Attachment.php +++ b/main/inc/lib/fckeditor/editor/plugins/Attachment/fck_Attachment.php @@ -80,7 +80,7 @@ if($_POST['fileupload']=="Attach File"){ if ($new_path && ($new_comment || $new_title)) if (($docid = DocumentManager::get_document_id($_course, $new_path))) { - $table_document = Database::get_course_table(DOCUMENT_TABLE); + $table_document = Database::get_course_table(TABLE_DOCUMENT); $ct = ''; if ($new_comment) $ct .= ", comment='$new_comment'"; if ($new_title) $ct .= ", title='$new_title'"; diff --git a/main/inc/lib/fileDisplay.lib.php b/main/inc/lib/fileDisplay.lib.php index 7906ccb636..5f66bebd70 100644 --- a/main/inc/lib/fileDisplay.lib.php +++ b/main/inc/lib/fileDisplay.lib.php @@ -260,8 +260,8 @@ function folder_size($dir_name) */ function get_total_folder_size($path, $can_see_invisible = false) { - $table_itemproperty = Database::get_course_table(LAST_TOOL_EDIT_TABLE); - $table_document = Database::get_course_table(DOCUMENT_TABLE); + $table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY); + $table_document = Database::get_course_table(TABLE_DOCUMENT); $tool_document = TOOL_DOCUMENT; $visibility_rule = 'props.visibility ' . ($can_see_invisible ? '<> 2' : '= 1'); diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 48d53ff3b4..fce6b64c06 100644 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -572,8 +572,8 @@ function dir_total_space($dirPath) function documents_total_space($to_group_id='0') { - $TABLE_ITEMPROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); - $TABLE_DOCUMENT = Database::get_course_table(DOCUMENT_TABLE); + $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); + $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $sql = "SELECT SUM(size) FROM ".$TABLE_ITEMPROPERTY." AS props, ".$TABLE_DOCUMENT." AS docs @@ -1075,7 +1075,7 @@ function clean_up_path(&$path) */ function add_document($_course,$path,$filetype,$filesize,$title,$comment=NULL) { - $table_document = Database::get_course_table(DOCUMENT_TABLE,$_course['dbName']); + $table_document = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']); $sql="INSERT INTO $table_document (`path`,`filetype`,`size`,`title`, `comment`) VALUES ('$path','$filetype','$filesize','$title', '$comment')"; @@ -1110,7 +1110,7 @@ function get_document_id() moved to document.lib.php */ function update_existing_document($_course,$document_id,$filesize) { - $document_table = Database::get_course_table(DOCUMENT_TABLE,$_course['dbName']); + $document_table = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']); $sql="UPDATE $document_table SET `size`='$filesize' WHERE id='$document_id'"; if(api_sql_query($sql,__FILE__,__LINE__)) { @@ -1141,7 +1141,7 @@ function item_property_update_on_folder($_course,$path,$user_id) $endchar=substr($path,strlen($path)-1,1); if($endchar=='/') $path=substr($path,0,strlen($path)-1); - $TABLE_ITEMPROPERTY = Database::get_course_table(ITEM_PROPERTY_TABLE,$_course['dbName']); + $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']); //get the time $time = date("Y-m-d H:i:s", time()); diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index b5bde1ac8c..47c95ad5fc 100644 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -100,7 +100,7 @@ class GroupManager $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } - $table_group = Database :: get_course_table(GROUP_TABLE, $course_db); + $table_group = Database :: get_course_table(TABLE_GROUP, $course_db); $table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); $table_group_user = Database :: get_course_table(GROUP_USER_TABLE, $course_db); @@ -147,7 +147,7 @@ class GroupManager global $_course,$_user; $currentCourseRepository = $_course['path']; - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $table_forum = Database :: get_course_table(TABLE_FORUM); $category = GroupManager :: get_category($category_id); if( strlen($places) == 0) @@ -181,7 +181,7 @@ class GroupManager */ function create_subgroups($group_id, $number_of_groups) { - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $category_id = GroupManager :: create_category('Subgroups', '', TOOL_PRIVATE, TOOL_PRIVATE, 0, 0, 1, 1); $users = GroupManager :: get_users($group_id); $group_ids = array (); @@ -285,7 +285,7 @@ class GroupManager } // Database table definitions - $group_table = Database :: get_course_table(GROUP_TABLE, $course_db); + $group_table = Database :: get_course_table(TABLE_GROUP, $course_db); $group_user_table = Database :: get_course_table(GROUP_USER_TABLE, $course_db); $forum_table = Database :: get_course_table(TABLE_FORUM, $course_db); $forum_post_table = Database :: get_course_table(TABLE_FORUM_POST, $course_db); @@ -329,7 +329,7 @@ class GroupManager if (empty($group_id) or !is_integer(intval($group_id)) ) { return null; } - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $sql = 'SELECT * FROM '.$table_group.' WHERE id = '.$group_id; $db_result = api_sql_query($sql,__FILE__,__LINE__); $db_object = mysql_fetch_object($db_result); @@ -361,7 +361,7 @@ class GroupManager */ function set_group_properties($group_id, $name, $description, $maximum_number_of_students, $doc_state, $work_state, $calendar_state, $announcements_state, $self_registration_allowed, $self_unregistration_allowed) { - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); //$table_forum = Database :: get_course_table(TABLE_FORUM); $sql = "UPDATE ".$table_group." SET name='".trim($name)."', @@ -385,7 +385,7 @@ class GroupManager */ function get_number_of_groups() { - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $res = api_sql_query('SELECT COUNT(id) AS number_of_groups FROM '.$table_group); $obj = mysql_fetch_object($res); return $obj->number_of_groups; @@ -450,7 +450,7 @@ class GroupManager $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } - $table_group = Database :: get_course_table(GROUP_TABLE, $course_db); + $table_group = Database :: get_course_table(TABLE_GROUP, $course_db); $table_group_cat = Database :: get_course_table(GROUP_CATEGORY_TABLE, $course_db); $sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g WHERE gc.id = g.category_id AND g.id=$group_id"; $res = api_sql_query($sql,__FILE__,__LINE__); @@ -471,7 +471,7 @@ class GroupManager $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } - $table_group = Database :: get_course_table(GROUP_TABLE, $course_db); + $table_group = Database :: get_course_table(TABLE_GROUP, $course_db); $table_group_cat = Database :: get_course_table(GROUP_CATEGORY_TABLE, $course_db); $sql = "SELECT id FROM $table_group WHERE category_id='".$cat_id."'"; $res = api_sql_query($sql,__FILE__,__LINE__); @@ -560,7 +560,7 @@ class GroupManager $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } - $group_table = Database :: get_course_table(GROUP_TABLE, $course_db); + $group_table = Database :: get_course_table(TABLE_GROUP, $course_db); $group_user_table = Database :: get_course_table(GROUP_USER_TABLE, $course_db); $sql = 'SELECT COUNT(gu.group_id) AS current_max FROM '.$group_user_table.' gu, '.$group_table.' g WHERE gu.group_id = g.id '; if ($category_id != null) @@ -642,7 +642,7 @@ class GroupManager $category = GroupManager :: get_category_from_group($group_ids[0]); $groups_per_user = $category['groups_per_user']; $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $group_table = Database :: get_course_table(GROUP_TABLE); + $group_table = Database :: get_course_table(TABLE_GROUP); $group_user_table = Database :: get_course_table(GROUP_USER_TABLE); $complete_user_list = CourseManager :: get_real_and_linked_user_list($_course['sysCode']); $number_groups_per_user = ($groups_per_user == GROUP_PER_MEMBER_NO_LIMIT ? INFINITE : $groups_per_user); @@ -747,7 +747,7 @@ class GroupManager */ function maximum_number_of_students($group_id) { - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $db_result = api_sql_query('SELECT max_student FROM '.$table_group.' WHERE id = '.$group_id); $db_object = mysql_fetch_object($db_result); if ($db_object->max_student == 0) @@ -764,7 +764,7 @@ class GroupManager function user_in_number_of_groups($user_id, $cat_id) { $table_group_user = Database :: get_course_table(GROUP_USER_TABLE); - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $sql = 'SELECT COUNT(*) AS number_of_groups FROM '.$table_group_user.' gu, '.$table_group.' g WHERE gu.user_id = \''.$user_id.'\' AND g.id = gu.group_id AND g.category_id= \''.$cat_id.'\''; $db_result = api_sql_query($sql,__FILE__,__LINE__); $db_object = mysql_fetch_object($db_result); @@ -780,7 +780,7 @@ class GroupManager { if (!$user_id > 0) return false; - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $sql = 'SELECT self_registration_allowed FROM '.$table_group.' WHERE id = '.$group_id; $db_result = api_sql_query($sql,__FILE__,__LINE__); $db_object = mysql_fetch_object($db_result); @@ -796,7 +796,7 @@ class GroupManager { if (!$user_id > 0) return false; - $table_group = Database :: get_course_table(GROUP_TABLE); + $table_group = Database :: get_course_table(TABLE_GROUP); $db_result = api_sql_query('SELECT self_unregistration_allowed FROM '.$table_group.' WHERE id = '.$group_id); $db_object = mysql_fetch_object($db_result); return $db_object->self_unregistration_allowed == 1 && GroupManager :: can_user_unsubscribe($user_id, $group_id); diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 7f681e0dd5..69d4ec1d33 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -1380,7 +1380,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us { $time = time(); $time = date("Y-m-d H:i:s", $time); - $TABLE_ITEMPROPERTY = Database :: get_course_table(ITEM_PROPERTY_TABLE); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); if ($to_user_id <= 0) $to_user_id = NULL; //no to_user_id set $start_visible = ($start_visible == 0) ? "0000-00-00 00:00:00" : $start_visible; diff --git a/main/inc/local.inc.php b/main/inc/local.inc.php index 3c5e08cece..5e7a94de8e 100644 --- a/main/inc/local.inc.php +++ b/main/inc/local.inc.php @@ -745,7 +745,7 @@ if ((isset($gidReset) && $gidReset) || (isset($cidReset) && $cidReset)) // sessi { if ($gidReq && $_cid ) // have keys to search data { - $group_table = Database::get_course_table(GROUP_TABLE); + $group_table = Database::get_course_table(TABLE_GROUP); $sql = "SELECT * FROM $group_table WHERE `id` = '$gidReq'"; $result = api_sql_query($sql,__FILE__,__LINE__); if (mysql_num_rows($result) > 0) // This group has recorded status related to this course diff --git a/main/inc/tool_navigation_menu.inc.php b/main/inc/tool_navigation_menu.inc.php index 14d3f19356..0e87a5ea10 100644 --- a/main/inc/tool_navigation_menu.inc.php +++ b/main/inc/tool_navigation_menu.inc.php @@ -1,5 +1,5 @@ = 1 && ($row = mysql_fetch_array($result))) @@ -111,7 +111,7 @@ if (isset($lcn)) // category_title if (($lci = get_cat($lcn)) !== FALSE) { - $link_table = Database::get_course_table(LINK_TABLE); + $link_table = Database::get_course_table(TABLE_LINK); $result = api_sql_query("SELECT id FROM $link_table WHERE category_id=" . $lci, __FILE__, __LINE__); while ($row = mysql_fetch_array($result)) @@ -304,7 +304,7 @@ echo '', "\n"; if (count($perCat)) foreach ($perCat as $cat => $number) $perCat[$cat] = '(' . htmlspecialchars($cat) . ')'; -$linkcat_table = Database::get_course_table(LINK_CATEGORY_TABLE); +$linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY); $result = api_sql_query("SELECT category_title FROM $linkcat_table", __FILE__, __LINE__); while ($row = mysql_fetch_array($result)) diff --git a/main/metadata/importmanifest.php b/main/metadata/importmanifest.php index 1663a85b15..d7f9df9f72 100644 --- a/main/metadata/importmanifest.php +++ b/main/metadata/importmanifest.php @@ -60,7 +60,7 @@ require('md_phpdig.php'); if (isset($workWith)) // explicit in URL, or selected at bottom of screen { - $scormdocument = Database::get_course_table(SCORMDOC_TABLE); + $scormdocument = Database::get_course_table(TABLE_SCORMDOC); $result = api_sql_query("SELECT id FROM $scormdocument WHERE path='" . addslashes($workWith) . "'", __FILE__, __LINE__); diff --git a/main/metadata/md_document.php b/main/metadata/md_document.php index 1a71d615e8..5960d563b2 100644 --- a/main/metadata/md_document.php +++ b/main/metadata/md_document.php @@ -163,7 +163,7 @@ function mdobject($_course, $id) $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v; - $document_table = Database::get_course_table(DOCUMENT_TABLE); + $document_table = Database::get_course_table(TABLE_DOCUMENT); if (($docinfo = @mysql_fetch_array(api_sql_query( "SELECT path,title,comment,filetype FROM $document_table WHERE id='" . addslashes($id) . "'", __FILE__, __LINE__)))) @@ -174,7 +174,7 @@ function mdobject($_course, $id) $this->mdo_filetype = $docinfo['filetype']; $this->mdo_group = ''; // 2005-05-30: find group_id, if any - $group_info = Database::get_course_table(GROUP_TABLE); + $group_info = Database::get_course_table(TABLE_GROUP); if (($result = api_sql_query( "SELECT id,secret_directory FROM $group_info", __FILE__, __LINE__))) while (($row = mysql_fetch_array($result))) diff --git a/main/metadata/md_link.php b/main/metadata/md_link.php index 0e2827c9a1..5adcba4034 100644 --- a/main/metadata/md_link.php +++ b/main/metadata/md_link.php @@ -169,7 +169,7 @@ function mdo_storeback(&$xmlDoc) // by ref! // do not store back a modified coverage as category... - $link_table = Database::get_course_table(LINK_TABLE); + $link_table = Database::get_course_table(TABLE_LINK); if ($u) api_sql_query("UPDATE $link_table SET " . substr($u, 2) . " WHERE id='" . addslashes($this->mdo_id) . "'", __FILE__, __LINE__); } @@ -198,7 +198,7 @@ function mdobject($_course, $id) $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v; - $link_table = Database::get_course_table(LINK_TABLE); + $link_table = Database::get_course_table(TABLE_LINK); if (($linkinfo = @mysql_fetch_array(api_sql_query( "SELECT url,title,description,category_id FROM $link_table WHERE id='" . addslashes($id) . "'", __FILE__, __LINE__)))) @@ -208,7 +208,7 @@ function mdobject($_course, $id) $this->mdo_description = $linkinfo['description']; $this->mdo_category = ($lci = $linkinfo['category_id']); - $linkcat_table = Database::get_course_table(LINK_CATEGORY_TABLE); + $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY); if (($catinfo = @mysql_fetch_array(api_sql_query( "SELECT category_title FROM $linkcat_table WHERE id='" . addslashes($lci) . "'", __FILE__, __LINE__)))) diff --git a/main/metadata/md_mix.php b/main/metadata/md_mix.php index c0bb1b0c7a..9f18f83ce0 100644 --- a/main/metadata/md_mix.php +++ b/main/metadata/md_mix.php @@ -40,8 +40,8 @@ function mdobject($_course, $eid) if ($type == 'Document' || $type == 'Scorm') { $table = $type == 'Scorm' ? - Database::get_course_table(SCORMDOC_TABLE) : - Database::get_course_table(DOCUMENT_TABLE); + Database::get_course_table(TABLE_SCORMDOC) : + Database::get_course_table(TABLE_DOCUMENT); if (($dotpos = strpos($id, '.'))) { @@ -75,7 +75,7 @@ function mdobject($_course, $eid) } elseif ($type == 'Link') { - $link_table = Database::get_course_table(LINK_TABLE); + $link_table = Database::get_course_table(TABLE_LINK); if (($linkinfo = @mysql_fetch_array(api_sql_query( "SELECT url,title,description,category_id FROM $link_table WHERE id='" . addslashes($id) . diff --git a/main/metadata/md_scorm.php b/main/metadata/md_scorm.php index 5bf104c735..7bd68c106e 100644 --- a/main/metadata/md_scorm.php +++ b/main/metadata/md_scorm.php @@ -78,7 +78,7 @@ function mdobject($_course, $id) { global $ieee_dcmap_e, $ieee_dcmap_v; // md_funcs - $scormdocument = Database::get_course_table(SCORMDOC_TABLE); + $scormdocument = Database::get_course_table(TABLE_SCORMDOC); $this->mdo_course = $_course; $this->mdo_type = 'Scorm'; $this->mdo_id = $id; $this->mdo_eid = $this->mdo_type . '.' . $id; diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index e70fcb42e5..ddb8c156dc 100644 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -165,7 +165,7 @@ $tbl_course_quiz = 'quiz'; $course_quiz_question = 'quiz_question'; $course_quiz_rel_question = 'quiz_rel_question'; $course_quiz_answer = 'quiz_answer'; -$course_student_publication = Database::get_course_table(STUDENT_PUBLICATION_TABLE); +$course_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION); api_display_tool_title($nameTools); diff --git a/main/newscorm/document.php b/main/newscorm/document.php index 41744091a2..b9176dbe56 100644 --- a/main/newscorm/document.php +++ b/main/newscorm/document.php @@ -49,7 +49,7 @@ require_once('learnpath.class.php'); require_once('learnpathItem.class.php'); // storing the tables names in variables. -$tbl_document = Database::get_course_table(SCORMDOC_TABLE); +$tbl_document = Database::get_course_table(TABLE_SCORMDOC); $tbl_learnpath_main = Database::get_course_learnpath_main_table(); $tbl_tool = Database::get_course_tool_list_table(); diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 27838c443d..0d9ff632a9 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -1,6357 +1,6357 @@ - - * @license GNU/GPL - See Dokeos license directory for details - */ -/** - * Defines the learnpath parent class - * @package dokeos.learnpath - */ -class learnpath { - - var $attempt = 0; //the number for the current ID view - var $cc; //course (code) this learnpath is located in - var $current; //id of the current item the user is viewing - var $current_score; //the score of the current item - var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet) - var $current_time_stop; //the time the user closed this resource - var $default_status = 'not attempted'; - var $encoding = 'ISO-8859-1'; - var $error = ''; - var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath - var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue() - var $index; //the index of the active learnpath_item in $ordered_items array - var $items = array(); - var $last; //item_id of last item viewed in the learning path - var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized - var $license; //which license this course has been given - not used yet on 20060522 - var $lp_id; //DB ID for this learnpath - var $lp_view_id; //DB ID for lp_view - var $log_file; //file where to log learnpath API msg - var $maker; //which maker has conceived the content (ENI, Articulate, ...) - var $message = ''; - var $mode='embedded'; //holds the video display mode (fullscreen or embedded) - var $name; //learnpath name (they generally have one) - var $ordered_items = array(); //list of the learnpath items in the order they are to be read - var $path = ''; //path inside the scorm directory (if scorm) - - // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1) - var $prevent_reinit = 1; - - // Describes the mode of progress bar display - var $progress_bar_mode = '%'; - - // Percentage progress as saved in the db - var $progress_db = '0'; - var $proximity; //wether the content is distant or local or unknown - var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match. - //!!!This array (refs_list) is built differently depending on the nature of the LP. - //If SCORM, uses ref, if Dokeos, uses id to keep a unique value - var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ... - //TODO check if this type variable is useful here (instead of just in the controller script) - var $user_id; //ID of the user that is viewing/using the course - var $update_queue = array(); - var $scorm_debug = 0; - - var $arrMenu = array(); //array for the menu items - - var $debug = 0; //logging level - - - - /** - * Class constructor. Needs a database handler, a course code and a learnpath id from the database. - * Also builds the list of items into $this->items. - * @param string Course code - * @param integer Learnpath ID - * @param integer User ID - * @return boolean True on success, false on error - */ - function learnpath($course, $lp_id, $user_id) { - //check params - //check course code - if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);} - if(empty($course)){ - $this->error = 'Course code is empty'; - return false; - } - else - { - $main_table = Database::get_main_table(TABLE_MAIN_COURSE); - //$course = Database::escape_string($course); - $course = $this->escape_string($course); - $sql = "SELECT * FROM $main_table WHERE code = '$course'"; - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);} - //$res = Database::query($sql); - $res = api_sql_query($sql); - if(Database::num_rows($res)>0) - { - $this->cc = $course; - } - else - { - $this->error = 'Course code does not exist in database ('.$sql.')'; - return false; - } - } - //check learnpath ID - if(empty($lp_id)) - { - $this->error = 'Learnpath ID is empty'; - return false; - } - else - { - //TODO make it flexible to use any course_code (still using env course code here) - //$lp_table = Database::get_course_table(LEARNPATH_TABLE); - $lp_db = Database::get_current_course_database(); - $lp_pref = Database::get_course_table_prefix(); - $lp_table = $lp_db.'.'.$lp_pref.'lp'; - - //$id = Database::escape_integer($id); - $lp_id = $this->escape_string($lp_id); - $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'"; - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);} - //$res = Database::query($sql); - $res = api_sql_query($sql); - if(Database::num_rows($res)>0) - { - $this->lp_id = $lp_id; - $row = Database::fetch_array($res); - $this->type = $row['lp_type']; - $this->name = stripslashes($row['name']); - $this->encoding = $row['default_encoding']; - $this->proximity = $row['content_local']; - $this->maker = $row['content_maker']; - $this->prevent_reinit = $row['prevent_reinit']; - $this->license = $row['content_license']; - $this->scorm_debug = $row['debug']; - $this->js_lib = $row['js_lib']; - $this->path = $row['path']; - if($this->type == 2){ - if($row['force_commit'] == 1){ - $this->force_commit = true; - } - } - $this->mode = $row['default_view_mod']; - } - else - { - $this->error = 'Learnpath ID does not exist in database ('.$sql.')'; - return false; - } - } - //check user ID - if(empty($user_id)){ - $this->error = 'User ID is empty'; - return false; - } - else - { - //$main_table = Database::get_main_user_table(); - $main_table = Database::get_main_table(TABLE_MAIN_USER); - //$user_id = Database::escape_integer($user_id); - $user_id = $this->escape_string($user_id); - $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'"; - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);} - //$res = Database::query($sql); - $res = api_sql_query($sql); - if(Database::num_rows($res)>0) - { - $this->user_id = $user_id; - } - else - { - $this->error = 'User ID does not exist in database ('.$sql.')'; - return false; - } - } - //end of variables checking - - //now get the latest attempt from this user on this LP, if available, otherwise create a new one - //$lp_table = Database::get_course_table(LEARNPATH_VIEW_TABLE); - $lp_db = Database::get_current_course_database(); - $lp_pref = Database::get_course_table_prefix(); - $lp_table = $lp_db.'.'.$lp_pref.'lp_view'; - //selecting by view_count descending allows to get the highest view_count first - $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC"; - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);} - //$res = Database::query($sql); - $res = api_sql_query($sql); - $view_id = 0; //used later to query lp_item_view - if(Database::num_rows($res)>0) - { - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);} - $row = Database::fetch_array($res); - $this->attempt = $row['view_count']; - $this->lp_view_id = $row['id']; - $this->last_item_seen = $row['last_item']; - $this->progress_db = $row['progress']; - } - else - { - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);} - $this->attempt = 1; - $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)"; - $res_ins = api_sql_query($sql_ins); - $this->lp_view_id = Database::get_last_insert_id(); - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);} - } - - //initialise items - $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item'; - $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order"; - $res = api_sql_query($sql); - - while($row = Database::fetch_array($res)) - { - $oItem = ''; - //$this->ordered_items[] = $row['id']; - switch($this->type){ - - case 3: //aicc - $oItem = new aiccItem('db',$row['id']); - if(is_object($oItem)){ - $oItem->set_lp_view($this->lp_view_id); - $oItem->set_prevent_reinit($this->prevent_reinit); - $id = $oItem->get_id(); - // Don't use reference here as the next loop will make the pointed object change - $this->items[$id] = $oItem; - $this->refs_list[$oItem->ref]=$id; - if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$id.' set in items[]',0);} - } - break; - case 2: - - require_once('scorm.class.php'); - require_once('scormItem.class.php'); - $oItem = new scormItem('db',$row['id']); - if(is_object($oItem)){ - $oItem->set_lp_view($this->lp_view_id); - $oItem->set_prevent_reinit($this->prevent_reinit); - // Don't use reference here as the next loop will make the pointed object change - $this->items[$oItem->get_id()] = $oItem; - $this->refs_list[$oItem->ref]=$oItem->get_id(); - if($this->debug>2){error_log('New LP - object with id '.$oItem->get_id().' set in items[]',0);} - } - break; - - case 1: - - default: - require_once('learnpathItem.class.php'); - $oItem = new learnpathItem($row['id'],$user_id); - if(is_object($oItem)){ - //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists - $oItem->set_prevent_reinit($this->prevent_reinit); - // Don't use reference here as the next loop will make the pointed object change - $this->items[$oItem->get_id()] = $oItem; - $this->refs_list[$oItem->get_id()]=$oItem->get_id(); - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$oItem->get_id().' set in items[]',0);} - } - break; - } - - //items is a list of pointers to all items, classified by DB ID, not SCO id - if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){ - $this->items[$row['id']]->set_level(0); - }else{ - $level = $this->items[$row['parent_item_id']]->get_level()+1; - $this->items[$row['id']]->set_level($level); - if(is_object($this->items[$row['parent_item_id']])){ - //items is a list of pointers from item DB ids to item objects - $this->items[$row['parent_item_id']]->add_child($row['id']); - }else{ - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - The parent item ('.$row['parent_item_id'].') of item '.$row['id'].' could not be found',0);} - } - } - - //get last viewing vars - //$learnpath_items_view_table = Database::get_course_table(LEARNPATH_ITEM_VIEW_TABLE); - $lp_item_view_table = $lp_db.'.'.$lp_pref.'lp_item_view'; - //this query should only return one or zero result - $sql = "SELECT * " . - "FROM $lp_item_view_table " . - "WHERE lp_view_id = ".$this->lp_view_id." " . - "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC "; - if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);} - //get the item status - $res2 = api_sql_query($sql); - if(Database::num_rows($res2)>0) - { - //if this learnpath has already been used by this user, get his last attempt count and - //the last item seen back into this object - //$max = 0; - $row2 = Database::fetch_array($res2); - if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);} - $this->items[$row['id']]->set_status($row2['status']); - if(empty($row2['status'])){ - $this->items[$row['id']]->set_status($this->default_status); - } - //$this->attempt = $row['view_count']; - //$this->last_item = $row['id']; - } - else //no item found in lp_item_view for this view - { - //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available) - //TODO if the learnpath has not got attempts activated, always use attempt '1' - //$this->attempt = 1; - //$this->last_item = 0; - $this->items[$row['id']]->set_status($this->default_status); - //Add that row to the lp_item_view table so that we have something to show in the stats page - $sql_ins = "INSERT INTO $lp_item_view_table " . - "(lp_item_id, lp_view_id, view_count, status) VALUES " . - "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')"; - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);} - $res_ins = api_sql_query($sql_ins); - } - //setting the view in the item object - $this->items[$row['id']]->set_lp_view($this->lp_view_id); - } - $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0); - $this->max_ordered_items = 0; - foreach($this->ordered_items as $index=>$dummy){ - if($index > $this->max_ordered_items AND !empty($dummy)){ - $this->max_ordered_items = $index; - } - } - //TODO define the current item better - $this->first(); - if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);} - } - - /** - * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and - * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description. - * - * @param int $parent - * @param int $previous - * @param string $type - * @param int $id - * @param string $title - * @param string $description - * @return int - */ - function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description) - { - if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);} - - $tbl_lp_item = Database::get_course_table('lp_item'); - $parent = (int) $parent; - - $sql_count = " - SELECT COUNT(id) AS num - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->get_id() . " AND - parent_item_id = " . $parent; - - $res_count = api_sql_query($sql_count, __FILE__, __LINE__); - $row = Database::fetch_array($res_count); - - $num = $row['num']; - - if($num > 0) - { - if($previous == 0) - { - $sql = " - SELECT - id, - next_item_id, - display_order - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->get_id() . " AND - parent_item_id = " . $parent . " AND - previous_item_id = 0"; - - $result = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $tmp_previous = 0; - $next = $row['id']; - $display_order = 0; - } - else - { - $previous = (int) $previous; - - $sql = " - SELECT - id, - previous_item_id, - next_item_id, - display_order - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->get_id() . " AND - id = " . $previous; - - $result = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $tmp_previous = $row['id']; - $next = $row['next_item_id']; - - $display_order = $row['display_order']; - } - } - else - { - $tmp_previous = 0; - $next = 0; - $display_order = 0; - } - - $new_item_id = -1; - $id = $this->escape_string($id); - - //insert new item - $sql_ins = " - INSERT INTO " . $tbl_lp_item . " ( - lp_id, - item_type, - ref, - title, - description, - path, - parent_item_id, - previous_item_id, - next_item_id, - display_order - ) VALUES ( - " . $this->get_id() . ", - '" . $type . "', - '', - '" . $this->escape_string(htmlentities($title)) . "', - '" . $this->escape_string(htmlentities($description)) . "', - '" . $id . "', - " . $parent . ", - " . $previous . ", - " . $next . ", - " . ($display_order + 1) . " - )"; - - //echo $sql_ins; // for debug - - if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);} - - $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__); - - if($res_ins > 0) - { - $new_item_id = Database::get_last_insert_id($res_ins); - - //update the item that should come after the new item - $sql_update_next = " - UPDATE " . $tbl_lp_item . " - SET previous_item_id = " . $new_item_id . " - WHERE id = " . $next; - - $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__); - - //update the item that should be before the new item - $sql_update_previous = " - UPDATE " . $tbl_lp_item . " - SET next_item_id = " . $new_item_id . " - WHERE id = " . $tmp_previous; - - $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__); - - //update all the items after the new item - $sql_update_order = " - UPDATE " . $tbl_lp_item . " - SET display_order = display_order + 1 - WHERE - lp_id = " . $this->get_id() . " AND - id <> " . $new_item_id . " AND - parent_item_id = " . $parent . " AND - display_order > " . $display_order; - - $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__); - } - - return $new_item_id; - } - - - /** - * Adds an item to the current learnpath - * @param integer Parent ID - * @param integer Previous elem ID (0 if first) - * @param string Resource type to add ('file','dokeos_item') - * @param string Resource ID or path if 'file' or name if 'dokeos_chapter' - * @return integer New element ID - */ - function old_add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title) - { - //TODO - if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);} - - $tbl_lp_item = Database::get_course_table('lp_item'); - $parent = (int) $parent; - $display_order = 1; - - if($previous == -1){ - //insert in latest position available - $sql_check = "SELECT MAX(previous_item_id) as prev, id FROM $tbl_lp_item WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent; - - if($this->debug>1){error_log('New LP - checking for latest item at this level: '.$sql_check,0);} - - $res = mysql_query($sql_check) or die(mysql_error()); - - $res_check = api_sql_query($sql_check, __FILE__, __LINE__); - $num = Database::num_rows($res_check); - - if($num>0){ - $row = Database::fetch_array($res_check); - $previous = $row['id']; - }else{ - $previous = 0; - } - }else{ - $previous = (int) $previous; - } - - $new_item_id = -1; - //check type - switch ($type){ - case 'dokeos_step': - $id = $this->escape_string($id); - //check the next item - $sql_check = "SELECT * FROM $tbl_lp_item " . - "WHERE lp_id = ".$this->get_id()." " . - "AND previous_item_id = $previous " . - "AND parent_item_id = $parent"; - if($this->debug>2){error_log('New LP - Getting info from the next element: '.$sql_check,0);} - $res_check = api_sql_query($sql_check); - if(Database::num_rows($res_check)){ - $row = Database::fetch_array($res_check); - $next = $row['id']; - //TODO check display_order - $display_order = $row['display_order']+1; - }else{ - $next = 0; - $display_order = 1; - } - - //insert new item - $sql_ins = "INSERT INTO $tbl_lp_item " . - "(lp_id,item_type,ref,title," . - "path,parent_item_id," . - "previous_item_id,next_item_id,display_order)" . - "VALUES" . - "(".$this->get_id().",'$type','','$title','$id'," . - "$parent," . - "$previous,$next,$display_order)"; - if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);} - $res_ins = api_sql_query($sql_ins); - if($res_ins>0){ - $new_item_id = Database::get_last_insert_id($res_ins); - //now update previous item - $sql_upd = "UPDATE $tbl_lp_item " . - "SET next_item_id = $new_item_id " . - "WHERE lp_id = ".$this->get_id()." " . - "AND id = $previous AND parent_item_id = $parent"; - - if($this->debug>2){error_log('New LP - Updating previous item: '.$sql_upd,0);} - - $res_upd = api_sql_query($sql_upd); - - //now update next item - - $sql_upd = "UPDATE $tbl_lp_item " . - - "SET previous_item_id = $new_item_id " . - - "WHERE lp_id = ".$this->get_id()." " . - - "AND id = $next AND parent_item_id = $parent"; - - if($this->debug>2){error_log('New LP - Updating next item: '.$sql_upd,0);} - - $res_upd = api_sql_query($sql_upd); - - } - - break; - - default: - - break; - - } - - return $new_item_id; - - } - - /** - - * Static admin function allowing addition of a learnpath to a course. - - * @param string Course code - - * @param string Learnpath name - - * @param string Learnpath description string, if provided - - * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) - - * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) - - * @param string Zip file containing the learnpath or directory containing the learnpath - - * @return integer The new learnpath ID on success, 0 on failure - - */ - - function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='') - - { - - //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);} - - //TODO - - $tbl_lp = Database::get_course_table('lp'); - - //check course code exists - - //check lp_name doesn't exist, otherwise append something - - $i = 0; - - $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities() - - $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'"; - - //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);} - - $res_name = api_sql_query($check_name); - - while(Database::num_rows($res_name)){ - - //there is already one such name, update the current one a bit - - $i++; - - $name = $name.' - '.$i; - - $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'"; - - //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);} - - $res_name = api_sql_query($check_name); - - } - - //new name does not exist yet; keep it - - //escape description - - $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities() - - $type = 1; - - switch($learnpath){ - - case 'guess': - - break; - - case 'dokeos': - - $type = 1; - - break; - - case 'aicc': - - break; - - } - - switch($origin){ - - case 'zip': - - //check zipname string. If empty, we are currently creating a new Dokeos learnpath - - break; - - case 'manual': - - $get_max = "SELECT MAX(display_order) FROM $tbl_lp"; - - $res_max = api_sql_query($get_max); - - if(Database::num_rows($res_max)<1){ - - $dsp = 1; - - }else{ - - $row = Database::fetch_array($res_max); - - $dsp = $row[0]+1; - - } - - $sql_insert = "INSERT INTO $tbl_lp " . - - "(lp_type,name,description,path,default_view_mod," . - - "default_encoding,display_order,content_maker," . - - "content_local,js_lib) " . - - "VALUES ($type,'$name','$description','','embedded'," . - - "'ISO-8859-1','$dsp','Dokeos'," . - - "'local','')"; - - //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);} - - $res_insert = api_sql_query($sql_insert); - - $id = Database::get_last_insert_id(); - - if($id>0){ - - return $id; - - } - - break; - - } - - } - - /** - - * Appends a message to the message attribute - - * @param string Message to append. - - */ - - function append_message($string) - - { - - if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);} - - $this->message .= $string; - - } - - /** - - * Autocompletes the parents of an item in case it's been completed or passed - - * @param integer Optional ID of the item from which to look for parents - - */ - - function autocomplete_parents($item) - - { - - if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);} - - if(empty($item)){ - - $item = $this->current; - - } - - $parent_id = $this->items[$item]->get_parent(); - - if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);} - - if(is_object($this->items[$item]) and !empty($parent_id)) - - {//if $item points to an object and there is a parent - - if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);} - - $current_item =& $this->items[$item]; - - $parent =& $this->items[$parent_id]; //get the parent - - //new experiment including failed and browsed in completed status - $current_status = $current_item->get_status(); - if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed'){ - - //if the current item is completed or passes or succeeded - - $completed = true; - - if($this->debug>2){error_log('New LP - Status of current item is alright',0);} - - foreach($parent->get_children() as $child){ - - //check all his brothers (his parent's children) for completion status - - if($child!= $item){ - - if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);} - - //if($this->items[$child]->status_is(array('completed','passed','succeeded'))) - //Trying completing parents of failed and browsed items as well - if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed'))) - { - - //keep completion status to true - - }else{ - - if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);} - - $completed = false; - - } - - } - - } - - if($completed == true){ //if all the children were completed - - $parent->set_status('completed'); - - $parent->save(false); - - $this->update_queue[$parent->get_id()] = $parent->get_status(); - - if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);} - - $this->autocomplete_parents($parent->get_id()); //recursive call - - } - - }else{ - - //error_log('New LP - status of current item is not enough to get bothered',0); - - } - - } - - } - - /** - - * Autosaves the current results into the database for the whole learnpath - - */ - - function autosave() - - { - - if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);} - - //TODO add aditionnal save operations for the learnpath itself - - } - - /** - - * Clears the message attribute - - */ - - function clear_message() - - { - - if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);} - - $this->message = ''; - - } - - /** - - * Closes the current resource - - * - - * Stops the timer - - * Saves into the database if required - - * Clears the current resource data from this object - - * @return boolean True on success, false on failure - - */ - - function close() - - { - - if($this->debug>0){error_log('New LP - In learnpath::close()',0);} - - if(empty($this->lp_id)) - - { - - $this->error = 'Trying to close this learnpath but no ID is set'; - - return false; - - } - - $this->current_time_stop = time(); - - if($this->save) - - { - - $learnpath_view_table = Database::get_course_table(LEARNPATH_VIEW_TABLE); - - /* - - $sql = "UPDATE $learnpath_view_table " . - - "SET " . - - "stop_time = ".$this->current_time_stop.", " . - - "score = ".$this->current_score.", ". - - "WHERE learnpath_id = '".$this->lp_id."'"; - - //$res = Database::query($sql); - - $res = api_sql_query($res); - - if(mysql_affected_rows($res)<1) - - { - - $this->error = 'Could not update learnpath_view table while closing learnpath'; - - return false; - - } - - */ - - } - - $this->ordered_items = array(); - - $this->index=0; - - unset($this->lp_id); - - //unset other stuff - - return true; - - } - - /** - - * Static admin function allowing removal of a learnpath - - * @param string Course code - - * @param integer Learnpath ID - - * @param string Whether to delete data or keep it (default: 'keep', others: 'remove') - - * @return boolean True on success, false on failure (might change that to return number of elements deleted) - - */ - - function delete($course=null,$id=null,$delete='keep') - - { - - //TODO implement a way of getting this to work when the current object is not set - - //In clear: implement this in the item class as well (abstract class) and use the given ID in queries - - //if(empty($course)){$course = api_get_course_id();} - - //if(empty($id)){$id = $this->get_id();} - - - - //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);} - - foreach($this->items as $id => $dummy) - - { - - $this->items[$id]->delete(); - - } - - $lp = Database::get_course_table('lp'); - - $lp_view = Database::get_course_table('lp_view'); - - $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id; - - //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);} - - $res_del_view = api_sql_query($sql_del_view); - - //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);} - - if($this->type == 2 OR $this->type==3){ - //this is a scorm learning path, delete the files as well - $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id; - $res = api_sql_query($sql); - if(Database::num_rows($res)>0){ - $row = Database::fetch_array($res); - $path = $row['path']; - $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id; - $res = api_sql_query($sql); - if(Database::num_rows($res)>0) - { //another learning path uses this directory, so don't delete it - if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);} - }else{ - //no other LP uses that directory, delete it - $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses - $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course - if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){ - if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);} - exec('rm -rf '.$course_scorm_dir.$path); - } - } - } - } - $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id; - //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);} - $res_del_lp = api_sql_query($sql_del_lp); - //TODO: also delete items and item-views - } - - /** - - * Removes all the children of one item - dangerous! - - * @param integer Element ID of which children have to be removed - - * @return integer Total number of children removed - - */ - - function delete_children_items($id){ - - if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);} - - $num = 0; - - if(empty($id) || $id != strval(intval($id))){return false;} - - $lp_item = Database::get_course_table('lp_item'); - - $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id"; - - $res = api_sql_query($sql); - - while($row = Database::fetch_array($res)){ - - $num += $this->delete_children_items($row['id']); - - $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id']; - - $res_del = api_sql_query($sql_del); - - $num++; - - } - - return $num; - - } - - /** - - * Removes an item from the current learnpath - - * @param integer Elem ID (0 if first) - - * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove') - - * @return integer Number of elements moved - - * @todo implement resource removal - - */ - - function delete_item($id, $remove='keep') - - { - - if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);} - - //TODO - implement the resource removal - - if(empty($id) || $id != strval(intval($id))){return false;} - - //first select item to get previous, next, and display order - - $lp_item = Database::get_course_table('lp_item'); - - $sql_sel = "SELECT * FROM $lp_item WHERE id = $id"; - - $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__); - - if(Database::num_rows($res_sel)<1){return false;} - - $row = Database::fetch_array($res_sel); - - $previous = $row['previous_item_id']; - - $next = $row['next_item_id']; - - $display = $row['display_order']; - - $parent = $row['parent_item_id']; - - $lp = $row['lp_id']; - - //delete children items - - $num = $this->delete_children_items($id); - - if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);} - - //now delete the item - - $sql_del = "DELETE FROM $lp_item WHERE id = $id"; - - if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);} - - $res_del = api_sql_query($sql_del,__FILE__,__LINE__); - - //now update surrounding items - - $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous"; - - $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__); - - $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next"; - - $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__); - - //now update all following items with new display order - - $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display"; - - $res_all = api_sql_query($sql_all,__FILE__,__LINE__); - - } - - /** - - * Updates an item's content in place - - * @param integer Element ID - - * @param string New content - - * @return boolean True on success, false on error - - */ - - function old_edit_item($id,$content) - - { - - if($this->debug>0){error_log('New LP - In learnpath::edit_item()',0);} - - if(empty($id) or ($id != strval(intval($id))) or empty($content)){ return false; } - - $content = $this->escape_string($content); - - $lp_item = Database::get_course_table('lp_item'); - - $sql_upd = "UPDATE $lp_item SET title = '$content' WHERE id = $id"; - - $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__); - - //TODO update the item object (can be ignored for now because refreshed) - - return true; - - } - - function edit_item($id, $parent, $previous, $title, $description) - { - if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);} - - if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; } - - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql_select = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE id = " . $id; - $res_select = api_sql_query($sql_select, __FILE__, __LINE__); - $row_select = Database::fetch_array($res_select); - - $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false; - $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false; - - if($same_parent && $same_previous) - { - //only update title and description - $sql_update = " - UPDATE " . $tbl_lp_item . " - SET - title = '" . $this->escape_string(htmlentities($title)) . "', - description = '" . $this->escape_string(htmlentities($description)) . "' - WHERE id = " . $id; - $res_update = api_sql_query($sql_update, __FILE__, __LINE__); - } - else - { - $old_parent = $row_select['parent_item_id']; - $old_previous = $row_select['previous_item_id']; - $old_next = $row_select['next_item_id']; - $old_order = $row_select['display_order']; - - /* BEGIN -- virtually remove the current item id */ - /* for the next and previous item it is like the current item doesn't exist anymore */ - - if($old_previous != 0) - { - $sql_update_next = " - UPDATE " . $tbl_lp_item . " - SET next_item_id = " . $old_next . " - WHERE id = " . $old_previous; - $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__); - - //echo '

    ' . $sql_update_next . '

    '; - } - - if($old_next != 0) - { - $sql_update_previous = " - UPDATE " . $tbl_lp_item . " - SET previous_item_id = " . $old_previous . " - WHERE id = " . $old_next; - $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__); - - //echo '

    ' . $sql_update_previous . '

    '; - } - - //display_order - 1 for every item with a display_order bigger then the display_order of the current item - $sql_update_order = " - UPDATE " . $tbl_lp_item . " - SET display_order = display_order - 1 - WHERE - display_order > " . $old_order . " AND - parent_item_id = " . $old_parent; - $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__); - - //echo '

    ' . $sql_update_order . '

    '; - - /* END -- virtually remove the current item id */ - - /* BEGIN -- update the current item id to his new location */ - - if($previous == 0) - { - //select the data of the item that should come after the current item - $sql_select_old = " - SELECT - id, - display_order - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id . " AND - parent_item_id = " . $parent . " AND - previous_item_id = " . $previous; - $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__); - $row_select_old = Database::fetch_array($res_select_old); - - //echo '

    ' . $sql_select_old . '

    '; - - //if the new parent doesn't had children before - if(Database::num_rows($res_select_old) == 0) - { - $new_next = 0; - $new_order = 1; - } - else - { - $new_next = $row_select_old['id']; - $new_order = $row_select_old['display_order']; - } - - //echo 'New next_item_id of current item: ' . $new_next . '
    '; - //echo 'New previous_item_id of current item: ' . $previous . '
    '; - //echo 'New display_order of current item: ' . $new_order . '
    '; - - - } - else - { - //select the data of the item that should come before the current item - $sql_select_old = " - SELECT - next_item_id, - display_order - FROM " . $tbl_lp_item . " - WHERE id = " . $previous; - $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__); - $row_select_old = Database::fetch_array($res_select_old); - - //echo '

    ' . $sql_select_old . '

    '; - - //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '
    '; - //echo 'New previous_item_id of current item: ' . $previous . '
    '; - //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '
    '; - - $new_next = $row_select_old['next_item_id']; - $new_order = $row_select_old['display_order'] + 1; - } - - //update the current item with the new data - $sql_update = " - UPDATE " . $tbl_lp_item . " - SET - title = '" . $this->escape_string(htmlentities($title)) . "', - description = '" . $this->escape_string(htmlentities($description)) . "', - parent_item_id = " . $parent . ", - previous_item_id = " . $previous . ", - next_item_id = " . $new_next . ", - display_order = " . $new_order . " - WHERE id = " . $id; - $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__); - //echo '

    ' . $sql_update . '

    '; - - if($previous != 0) - { - //update the previous item his next_item_id - $sql_update_previous = " - UPDATE " . $tbl_lp_item . " - SET next_item_id = " . $id . " - WHERE id = " . $previous; - $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__); - //echo '

    ' . $sql_update_previous . '

    '; - } - - if($new_next != 0) - { - //update the next item his previous_item_id - $sql_update_next = " - UPDATE " . $tbl_lp_item . " - SET previous_item_id = " . $id . " - WHERE id = " . $new_next; - $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__); - //echo '

    ' . $sql_update_next . '

    '; - } - - //update all the items with the same or a bigger display_order then the current item - $sql_update_order = " - UPDATE " . $tbl_lp_item . " - SET display_order = display_order + 1 - WHERE - lp_id = " . $this->get_id() . " AND - id <> " . $id . " AND - parent_item_id = " . $parent . " AND - display_order >= " . $new_order; - - $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__); - //echo '

    ' . $sql_update_order . '

    '; - - /* END -- update the current item id to his new location */ - } - } - - /** - - * Updates an item's prereq in place - - * @param integer Element ID - - * @param string Prerequisite Element ID - * - * @param string Prerequisite item type - * - * @param string Prerequisite min score - * - * @param string Prerequisite max score - - * @return boolean True on success, false on error - - */ - - function edit_item_prereq($id, $prerequisite_id, $min_score = 0, $max_score = 100) - - { - - if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq()',0);} - - if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; } - - $prerequisite_id = $this->escape_string($prerequisite_id); - - $tbl_lp_item = Database::get_course_table('lp_item'); - - if(!is_numeric($min_score) || $min_score < 0 || $min_score > 100) - $min_score = 0; - - if(!is_numeric($max_score) || $max_score < 0 || $max_score > 100) - $max_score = 100; - - if($min_score > $max_score) - $max_score = $min_score; - - if(!is_numeric($prerequisite_id)) - $prerequisite_id = 'NULL'; - - $sql_upd = " - UPDATE " . $tbl_lp_item . " - SET - min_score = " . $min_score . ", - max_score = " . $max_score . ", - prerequisite = " . $prerequisite_id . " - WHERE id = " . $id; - - $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__); - - //TODO update the item object (can be ignored for now because refreshed) - - return true; - - } - - /** - - * Escapes a string with the available database escape function - - * @param string String to escape - - * @return string String escaped - - */ - - function escape_string($string){ - - //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);} - - return mysql_real_escape_string($string); - - } - - /** - - * Static admin function exporting a learnpath into a zip file - - * @param string Export type (scorm, zip, cd) - - * @param string Course code - - * @param integer Learnpath ID - - * @param string Zip file name - - * @return string Zip file path (or false on error) - - */ - - function export_lp($type, $course, $id, $zipname) - - { - - //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);} - - //TODO - - if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;} - - $url = ''; - - switch($type){ - - case 'scorm': - - break; - - case 'zip': - - break; - - case 'cdrom': - - break; - - } - - return $url; - - } - - /** - - * Gets all the chapters belonging to the same parent as the item/chapter given - - * Can also be called as abstract method - - * @param integer Item ID - - * @return array A list of all the "brother items" (or an empty array on failure) - - */ - - function get_brother_chapters($id){ - - if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);} - - if(empty($id) OR $id != strval(intval($id))){ return array();} - - $lp_item = Database::get_course_table('lp_item'); - - $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'"; - - $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__); - - if(Database::num_rows($res_parent)>0){ - - $row_parent = Database::fetch_array($res_parent); - - $parent = $row_parent['parent_item_id']; - - $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order"; - - $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__); - - $list = array(); - - while ($row_bro = Database::fetch_array($res_bros)){ - - $list[] = $row_bro; - - } - - return $list; - - } - - return array(); - - } - - /** - - * Gets all the items belonging to the same parent as the item given - - * Can also be called as abstract method - - * @param integer Item ID - - * @return array A list of all the "brother items" (or an empty array on failure) - - */ - - function get_brother_items($id){ - - if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);} - - if(empty($id) OR $id != strval(intval($id))){ return array();} - - $lp_item = Database::get_course_table('lp_item'); - - $sql_parent = "SELECT * FROM $lp_item WHERE id = $id"; - - $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__); - - if(Database::num_rows($res_parent)>0){ - - $row_parent = Database::fetch_array($res_parent); - - $parent = $row_parent['parent_item_id']; - - $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order"; - - $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__); - - $list = array(); - - while ($row_bro = Database::fetch_array($res_bros)){ - - $list[] = $row_bro; - - } - - return $list; - - } - - return array(); - - } - - /** - - * Gets the number of items currently completed - - * @return integer The number of items currently completed - - */ - - function get_complete_items_count() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);} - - $i = 0; - - foreach($this->items as $id => $dummy){ - - //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){ - //Trying failed and browsed considered "progressed" as well - if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))){ - - $i++; - - } - - } - - return $i; - - } - - /** - * Gets the current item ID - * @return integer The current learnpath item id - */ - function get_current_item_id() - { - $current = 0; - if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);} - if(!empty($this->current)) - { - $current = $this->current; - } - if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);} - return $current; - } - /** - * Gets the total number of items available for viewing in this SCORM - * @return integer The total number of items - */ - function get_total_items_count() - { - if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);} - return count($this->items); - } - /** - * Gets the first element URL. - * @return string URL to load into the viewer - */ - function first() - { - if($this->debug>0){error_log('New LP - In learnpath::first()',0);} - //test if the last_item_seen exists and is not a dir - if(!empty($this->last_item_seen) - && !empty($this->items[$this->last_item_seen]) - && $this->items[$this->last_item_seen]->get_type() != 'dir' - && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' - && $this->items[$this->last_item_seen]->is_done() != true - ){ - if($this->debug>2){error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(),0);} - $index = -1; - foreach($this->ordered_items as $myindex => $item_id){ - if($item_id == $this->last_item_seen){ - $index = $myindex; - break; - } - } - if($index==-1){ - //index hasn't changed, so item not found - panic (this shouldn't happen) - if($this->debug>2){error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!',0);} - return false; - }else{ - $this->last = $this->last_item_seen; - $this->current = $this->last_item_seen; - $this->index = $index; - } - }else{ - if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);} - $index = 0; - while (!empty($this->ordered_items[$index]) - AND - ( - $this->items[$this->ordered_items[$index]]->get_type() == 'dir' - OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' - OR $this->items[$this->ordered_items[$index]]->is_done() === true - ) - AND $index < $this->max_ordered_items) - { - $index ++; - } - $this->last = $this->current; - //current is - $this->current = $this->ordered_items[$index]; - $this->index = $index; - if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);} - } - if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());} - } - - /** - - * Gets the information about an item in a format usable as JavaScript to update - - * the JS API by just printing this content into the section of the message frame - - * @param integer Item ID - - * @return string - - */ - - function get_js_info($item_id=''){ - - if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);} - - $info = ''; - - $item_id = $this->escape_string($item_id); - - if(!empty($item_id) && is_object($this->items[$item_id])){ - - //if item is defined, return values from DB - - $oItem = $this->items[$item_id]; - - $info .= ''; - - if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);} - - return $info; - - }else{ - - //if item_id is empty, just update to default SCORM data - - $info .= ''; - - if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);} - - return $info; - - } - - } - /** - * Gets the js library from the database - * @return string The name of the javascript library to be used - */ - function get_js_lib(){ - $lib = ''; - if(!empty($this->js_lib)){ - $lib = $this->js_lib; - } - return $lib; - } - /** - - * Gets the learnpath database ID - - * @return integer Learnpath ID in the lp table - - */ - - function get_id() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);} - - if(!empty($this->lp_id)) - - { - - return $this->lp_id; - - }else{ - - return 0; - - } - - } - - /** - - * Gets the last element URL. - - * @return string URL to load into the viewer - - */ - - function get_last() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);} - - $this->index = count($this->ordered_items)-1; - - return $this->ordered_items[$this->index]; - - } - - /** - - * Gets the navigation bar for the learnpath display screen - - * @return string The HTML string to use as a navigation bar - - */ - - function get_navigation_bar() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);} - - //TODO find a good value for the following variables - - $file = ''; - - $openDir = ''; - - $edoceo = ''; - - $time = 0; - - $navbar = ''; - - $RequestUri = ''; - - $mycurrentitemid = $this->get_current_item_id(); - - if($this->mode == 'fullscreen'){ - - $navbar = ''."\n". - - ' '."\n" . - - ' '."\n" . - - ' '."\n" . - - '
    '."\n" . - - '
    '."\n" . - - '  '."\n" . - - '  '."\n" . - - ' '."\n" . - - ' '."\n" . - - '
    '."\n" . - - '
    '."\n" ; - - - - }else{ - - $navbar = ''."\n". - - ' '."\n" . - - ' '."\n" . - - ' '."\n" . - - '
    '."\n" . - - '
    '."\n" . - - '  '."\n" . - - '  '."\n" . - - '  '."\n" . - - ' '."\n" . - - '
    '."\n" . - - '
    '."\n" ; - - } - - return $navbar; - - } - - /** - - * Gets the next resource in queue (url). - - * @return string URL to load into the viewer - - */ - - function get_next_index() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);} - - //TODO - - $index = $this->index; - - $index ++; - - if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]['type'],0);} - - while(!empty($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir' AND $index < $this->max_ordered_items) - - { - - $index ++; - - if($index == $this->max_ordered_items) - - { - - return $this->index; - - } - - } - - if(empty($this->ordered_items[$index])){ - - return $this->index; - - } - - if($this->debug>2){error_log('New LP - index is now '.$index,0);} - - return $index; - - } - - /** - - * Gets item_id for the next element - - * @return integer Next item (DB) ID - - */ - - function get_next_item_id() - - { - - $new_index = $this->get_next_index(); - - return $this->ordered_items[$new_index]; - - } - /** - * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...) - * - * Generally, the package provided is in the form of a zip file, so the function - * has been written to test a zip file. If not a zip, the function will return the - * default return value: '' - * @param string the path to the file - * @param string the original name of the file - * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized - */ - function get_package_type($file_path,$file_name){ - //error_log('In learnpath::get_package_type("'.$file_path.'","'.$file_name.'")',0); - - //get name of the zip file without the extension - $file_info = pathinfo($file_name); - $filename = $file_info['basename'];//name including extension - $extension = $file_info['extension'];//extension only - - if(in_array($extension,array('ppt','odp'))) - { - return 'ppt'; - } - - $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension - - $zipFile = new pclZip($file_path); - // Check the zip content (real size and file extension) - $zipContentArray = $zipFile->listContent(); - $package_type=''; - $at_root = false; - $manifest = ''; - - //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?) - foreach($zipContentArray as $thisContent) - { - if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) ) - { - return ''; - } - elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE) - { - $manifest = $thisContent['filename']; //just the relative directory inside scorm/ - $package_type = 'scorm'; - break;//exit the foreach loop - } - elseif(stristr($thisContent['filename'],'AICC')!==FALSE) - { - $package_type='aicc'; - break;//exit the foreach loop - } - else - { - $package_type = ''; - } - } - return $package_type; - } - /** - - * Gets the previous resource in queue (url). Also initialises time values for this viewing - - * @return string URL to load into the viewer - - */ - - function get_previous_index() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);} - - $index = $this->index; - - if(isset($this->ordered_items[$index-1])){ - - $index --; - - while(isset($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir') - - { - - $index --; - - if($index < 0){ - - return $this->index; - - } - - } - - }else{ - - if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);} - - //no previous item - - } - - return $index; - - } - - /** - - * Gets item_id for the next element - - * @return integer Previous item (DB) ID - - */ - - function get_previous_item_id() - - { - - $new_index = $this->get_previous_index(); - - return $this->ordered_items[$new_index]; - - } - - /** - - * Gets the progress value from the progress_db attribute - - * @return integer Current progress value - - */ - - function get_progress(){ - - if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);} - - if(!empty($this->progress_db)){ - - return $this->progress_db; - - } - - return 0; - - } - /** - * Gets the progress value from the progress field in the database (allows use as abstract method) - * @param integer Learnpath ID - * @param integer User ID - * @param string Mode of display ('%','abs' or 'both') - * @return integer Current progress value as found in the database - */ - function get_db_progress($lp_id,$user_id,$mode='%'){ - //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);} - $table = Database::get_course_table('lp_view'); - $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id"; - $res = api_sql_query($sql,__FILE__,__LINE__); - $view_id = 0; - if(Database::num_rows($res)>0){ - $row = Database::fetch_array($res); - $progress = $row['progress']; - $view_id = $row['id']; - } - if(!$progress){ - $progress = '0'; - } - if($mode == '%'){ - return $progress.'%'; - }else{ - //get the number of items completed and the number of items total - $tbl = Database::get_course_table('lp_item'); - $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id; - $res = api_sql_query($sql); - $row = Database::fetch_array($res); - $total = $row[0]; - $tbl = Database::get_course_table('lp_item_view'); - //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')"; - //trying as also counting browsed and failed items - $sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded','browsed','failed')"; - $res = api_sql_query($sql); - $row = Database::fetch_array($res); - $completed = $row[0]; - if($mode == 'abs'){ - return $completed.'/'.$total; - } - elseif($mode == 'both') - { - if($progress<($completed/($total?$total:1))){ - $progress = number_format(($completed/($total?$total:1))*100,0); - } - return $progress.'% ('.$completed.'/'.$total.')'; - } - } - return $progress; - } - - /** - - * Gets a progress bar for the learnpath by counting the number of items in it and the number of items - - * completed so far. - - * @param string Mode in which we want the values - - * @param integer Progress value to display (optional but mandatory if used in abstract context) - - * @param string Text to display near the progress value (optional but mandatory in abstract context) - - * @return string HTML string containing the progress bar - - */ - - function get_progress_bar($mode='',$percentage=-1,$text_add='') - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);} - - if($percentage=='-1' OR $text_add==''){ - - list ($percentage, $text_add) = $this->get_progress_bar_text($mode); - - } - - $text = $percentage.$text_add; - - $output = '' - - //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."
    " - - .'
    ' - - .'' - - .'' - - .''; - - if($percentage <= 98){ - - $output .= ''; - - }else{ - - $output .= ''; - - } - - $output .= '
    ' - - .'
    '.$text.'
    '; - - return $output; - - } - - /** - - * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php - - * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements - - * //@param integer Additional steps to fake as completed - - * @return list Percentage or number and symbol (% or /xx) - - */ - - function get_progress_bar_text($mode='',$add=0) - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);} - - if(empty($mode)){$mode = $this->progress_bar_mode;} - - $total_items = $this->get_total_items_count(); - - if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);} - - $i = $this->get_complete_items_count(); - - if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);} - - if($add != 0){ - - $i += $add; - - if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);} - - } - - $text = ''; - - if($i>$total_items){ - - $i = $total_items; - - } - - if($mode == '%'){ - - $percentage = ((float)$i/(float)$total_items)*100; - - $percentage = number_format($percentage,0); - - $text = '%'; - - }elseif($mode == 'abs'){ - - $percentage = $i; - - $text = '/'.$total_items; - - } - - return array($percentage,$text); - - } - - /** - - * Gets the progress bar mode - - * @return string The progress bar mode attribute - - */ - - function get_progress_bar_mode() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);} - - if(!empty($this->progress_bar_mode)) - - { - - return $this->progress_bar_mode; - - }else{ - - return '%'; - - } - - } - - - - /** - - * Returns a usable array of stats related to the current learnpath and user - - * @return array Well-formatted array containing status for the current learnpath - - */ - - function get_stats() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);} - - //TODO - - } - - /** - - * Static method. Can be re-implemented by children. Gives an array of statistics for - - * the given course (for all learnpaths and all users) - - * @param string Course code - - * @return array Well-formatted array containing status for the course's learnpaths - - */ - - function get_stats_course($course) - - { - - //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);} - - //TODO - - } - - /** - - * Static method. Can be re-implemented by children. Gives an array of statistics for - - * the given course and learnpath (for all users) - - * @param string Course code - - * @param integer Learnpath ID - - * @return array Well-formatted array containing status for the specified learnpath - - */ - - function get_stats_lp($course,$lp) - - { - - //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);} - - //TODO - - } - - /** - - * Static method. Can be re-implemented by children. Gives an array of statistics for - - * the given course, learnpath and user. - - * @param string Course code - - * @param integer Learnpath ID - - * @param integer User ID - - * @return array Well-formatted array containing status for the specified learnpath and user - - */ - - function get_stats_lp_user($course,$lp,$user) - - { - - //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);} - - //TODO - - } - - /** - - * Static method. Can be re-implemented by children. Gives an array of statistics for - - * the given course and learnpath (for all users) - - * @param string Course code - - * @param integer User ID - - * @return array Well-formatted array containing status for the user's learnpaths - - */ - - function get_stats_user($course,$user) - - { - - //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);} - - //TODO - - } - - /** - - * Gets the status list for all LP's items - - * @return array Array of [index] => [item ID => current status] - - */ - - function get_items_status_list(){ - - if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);} - - $list = array(); - - foreach($this->ordered_items as $item_id) - - { - - $list[]= array($item_id => $this->items[$item_id]->get_status()); - - } - - return $list; - - } - /** - * Generate and return the table of contents for this learnpath. The (flat) table returned can be - * used by get_html_toc() to be ready to display - * @return array TOC as a table with 4 elements per row: title, link, status and level - */ - function get_toc() - { - if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);} - $toc = array(); - //echo "
    ".print_r($this->items,true)."
    "; - foreach($this->ordered_items as $item_id) - { - if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);} - //TODO change this link generation and use new function instead - $toc[] = array( - 'id'=>$item_id, - 'title'=>$this->items[$item_id]->get_title(), - //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1), - 'status'=>$this->items[$item_id]->get_status(), - 'level'=>$this->items[$item_id]->get_level(), - 'type' =>$this->items[$item_id]->get_type(), - ); - } - if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);} - return $toc; - } - /** - * Gets the learning path type - * @param boolean Return the name? If false, return the ID. Default is false. - * @return mixed Type ID or name, depending on the parameter - */ - function get_type($get_name = false) - { - $res = false; - if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);} - if(!empty($this->type)) - { - if($get_name) - { - //get it from the lp_type table in main db - }else{ - $res = $this->type; - } - } - if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);} - return $res; - } - - /** - * Gets a flat list of item IDs ordered for display (level by level ordered by order_display) - * This method can be used as abstract and is recursive - * @param integer Learnpath ID - * @param integer Parent ID of the items to look for - * @return mixed Ordered list of item IDs or false on error - */ - function get_flat_ordered_items_list($lp,$parent=0){ - if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);} - $list = array(); - if(empty($lp)){return false;} - $tbl_lp_item = Database::get_course_table('lp_item'); - $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order"; - $res = api_sql_query($sql,__FILE__,__LINE__); - while($row = Database::fetch_array($res)){ - $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']); - $list[] = $row['id']; - foreach($sublist as $item){ - $list[] = $item; - } - } - return $list; - } - /** - * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display - * @return string HTML TOC ready to display - */ - function get_html_toc() - { - if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);} - $list = $this->get_toc(); - //echo $this->current; - //$parent = $this->items[$this->current]->get_parent(); - //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];} - $html = '
    '."\n" ; - // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n"; - require_once('resourcelinker.inc.php'); - - //temp variables - $mycurrentitemid = $this->get_current_item_id(); - - foreach($list as $item) - { - if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);} - //TODO complete this - $icon_name = array('not attempted' => 'notattempted.png', - 'incomplete' => 'incomplete.png', - 'failed' => 'failed.png', - 'completed' => 'completed.png', - 'passed' => 'passed.png', - 'succeeded' => 'succeeded.png', - 'browsed' => 'completed.png'); - - $style = 'scorm_item'; - if($item['id'] == $this->current){ - $style = 'scorm_item_highlight'; - } - //the anchor will let us center the TOC on the currently viewed item &^D - $html .= '\n"; - } - $html .= "
    \n"; - return $html; - } - /** - * Gets the user-friendly message stored in $this->message - * @return string Message - */ - function get_message(){ - - if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);} - return $this->message; - } - /** - * Gets the learnpath name/title - * @return string Learnpath name/title - */ - function get_name() - { - if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);} - if(!empty($this->name)){return $this->name;}else{return 'N/A';} - } - /** - * Gets a link to the resource from the present location, depending on item ID. - * @param string Type of link expected - * @param integer Learnpath item ID - * @return string Link to the lp_item resource - */ - function get_link($type='http',$item_id=null) - { - if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);} - if(empty($item_id)) - { - if($this->debug>2){error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: '.$this->get_current_item_id(),0);} - $item_id = $this->get_current_item_id(); - } - - if(empty($item_id)){ - if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);} - //still empty, this means there was no item_id given and we are not in an object context or - //the object property is empty, return empty link - $item_id = $this->first(); - return ''; - } - - $file = ''; - $lp_db = Database::get_current_course_database(); - $lp_pref = Database::get_course_table_prefix(); - $lp_table = $lp_db.'.'.$lp_pref.'lp'; - $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item'; - $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath " . - "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id"; - if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);} - $res = api_sql_query($sel); - if(Database::num_rows($res)>0) - { - $row = Database::fetch_array($res); - //var_dump($row); - $lp_type = $row['ltype']; - $lp_path = $row['lpath']; - $lp_item_type = $row['litype']; - $lp_item_path = $row['lipath']; - if($type == 'http'){ - $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path - }else{ - $course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); //system path - } - //now go through the specific cases to get the end of the path - switch($lp_type){ - case 1: - if($lp_item_type == 'dokeos_chapter'){ - $file = 'lp_content.php?type=dir'; - }else{ - require_once('resourcelinker.inc.php'); - $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id); - } - break; - case 2: - if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);} - if($lp_item_type!='dir'){ - //Quite complex here: - //we want to make sure 'http://' (and similar) links can - //be loaded as is (withouth the Dokeos path in front) but - //some contents use this form: resource.htm?resource=http://blablabla - //which means we have to find a protocol at the path's start, otherwise - //it should not be considered as an external URL - - //if($this->prerequisites_match($item_id)){ - if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){ - if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);} - //distant url, return as is - $file = $lp_item_path; - }else{ - if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);} - //prevent getting untranslatable urls - $lp_item_path = preg_replace('/%2F/','/',$lp_item_path); - $lp_item_path = preg_replace('/%3A/',':',$lp_item_path); - //prepare the path - $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; - //TODO fix this for urls with protocol header - $file = str_replace('//','/',$file); - $file = str_replace(':/','://',$file); - } - //}else{ - //prerequisites did not match - //$file = 'blank.php'; - //} - }else{ - $file = 'lp_content.php?type=dir'; - } - break; - case 3: - if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);} - //formatting AICC HACP append URL - $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&'; - if($lp_item_type!='dir'){ - //Quite complex here: - //we want to make sure 'http://' (and similar) links can - //be loaded as is (withouth the Dokeos path in front) but - //some contents use this form: resource.htm?resource=http://blablabla - //which means we have to find a protocol at the path's start, otherwise - //it should not be considered as an external URL - - if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){ - if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);} - //distant url, return as is - $file = $lp_item_path; - /* - if(stristr($file,'')!==false){ - $file = str_replace('',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path); - } - */ - $file .= $aicc_append; - }else{ - if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);} - //prevent getting untranslatable urls - $lp_item_path = preg_replace('/%2F/','/',$lp_item_path); - $lp_item_path = preg_replace('/%3A/',':',$lp_item_path); - //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name - $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; - //TODO fix this for urls with protocol header - $file = str_replace('//','/',$file); - $file = str_replace(':/','://',$file); - $file .= $aicc_append; - } - }else{ - $file = 'lp_content.php?type=dir'; - } - - break; - - case 4: - - break; - - default: - - break; - - } - - } - - if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);} - - return $file; - - } - - /** - - * Gets the latest usable view or generate a new one - - * @param integer Optional attempt number. If none given, takes the highest from the lp_view table - - * @return integer DB lp_view id - - */ - - function get_view($attempt_num=0) - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);} - - $search = ''; - - //use $attempt_num to enable multi-views management (disabled so far) - - if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) - - { - - $search = 'AND view_count = '.$attempt_num; - - } - - //when missing $attempt_num, search for a unique lp_view record for this lp and user - - $lp_view_table = Database::get_course_table('lp_view'); - - $sql = "SELECT id, view_count FROM $lp_view_table " . - - "WHERE lp_id = ".$this->get_id()." " . - - "AND user_id = ".$this->get_user_id()." " . - - $search . - - " ORDER BY view_count DESC"; - - $res = api_sql_query($sql); - - if(Database::num_rows($res)>0) - - { - - $row = Database::fetch_array($res); - - $this->lp_view_id = $row['id']; - - }else{ - - //no database record, create one - - $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" . - - "VALUES (".$this->get_id().",".$this->get_user_id().",1)"; - - $res = api_sql_query($sql); - - $id = Database::get_last_insert_id(); - - $this->lp_view_id = $id; - - } - - } - - /** - - * Gets the current view id - - * @return integer View ID (from lp_view) - - */ - - function get_view_id() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);} - - if(!empty($this->lp_view_id)) - - { - - return $this->lp_view_id; - - }else{ - - return 0; - - } - - } - - /** - - * Gets the update queue - - * @return array Array containing IDs of items to be updated by JavaScript - - */ - - function get_update_queue() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);} - - return $this->update_queue; - - } - - /** - - * Gets the user ID - - * @return integer User ID - - */ - - function get_user_id() - - { - - if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);} - - if(!empty($this->user_id)) - - { - - return $this->user_id; - - }else{ - - return false; - - } - - } - - /** - - * Logs a message into a file - - * @param string Message to log - - * @return boolean True on success, false on error or if msg empty - - */ - - function log($msg) - - { - - if($this->debug>0){error_log('New LP - In learnpath::log()',0);} - - //TODO - - $this->error .= $msg."\n"; - - return true; - - } - - /** - - * Moves an item up and down at its level - - * @param integer Item to move up and down - - * @param string Direction 'up' or 'down' - - * @return integer New display order, or false on error - - */ - - function move_item($id, $direction){ - - if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);} - - if(empty($id) or empty($direction)){return false;} - - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql_sel = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE id = " . $id; - $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__); - - //check if elem exists - - if(Database::num_rows($res_sel)<1){return false;} - - //gather data - - $row = Database::fetch_array($res_sel); - - $previous = $row['previous_item_id']; - - $next = $row['next_item_id']; - - $display = $row['display_order']; - - $parent = $row['parent_item_id']; - - $lp = $row['lp_id']; - - //update the item (switch with previous/next one) - - switch($direction) - { - case 'up': - if($this->debug>2){error_log('Movement up detected',0);} - - if($display <= 1){/*do nothing*/} - - else{ - - $sql_sel2 = "SELECT * - FROM $tbl_lp_item - WHERE id = $previous"; - - if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);} - - $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__); - - if(Database::num_rows($res_sel2)<1){$previous_previous = 0;} - - //gather data - - $row2 = Database::fetch_array($res_sel2); - - $previous_previous = $row2['previous_item_id']; - - //update previous_previous item (switch "next" with current) - - if($previous_previous != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_$previous"; - - if($this->debug>2){error_log($sql_upd2,0);} - - $res_upd2 = api_sql_query($sql_upd2); - - } - - //update previous item (switch with current) - - if($previous != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous"; - - if($this->debug>2){error_log($sql_upd2,0);} - - $res_upd2 = api_sql_query($sql_upd2); - - } - - //update current item (switch with previous) - - if($id != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id"; - - if($this->debug>2){error_log($sql_upd2,0);} - - $res_upd2 = api_sql_query($sql_upd2); - - } - - //update next item (new previous item) - - if($next != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next"; - - if($this->debug>2){error_log($sql_upd2,0);} - - $res_upd2 = api_sql_query($sql_upd2); - - } - - $display = $display-1; - - } - - break; - - case 'down': - - if($this->debug>2){error_log('Movement down detected',0);} - - if($next == 0){/*do nothing*/} - - else{ - - $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next"; - - if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);} - - $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__); - - if(Database::num_rows($res_sel2)<1){$next_next = 0;} - - //gather data - - $row2 = Database::fetch_array($res_sel2); - - $next_next = $row2['next_item_id']; - - //update previous item (switch with current) - - if($previous != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous"; - - $res_upd2 = api_sql_query($sql_upd2); - - } - - //update current item (switch with previous) - - if($id != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id"; - - $res_upd2 = api_sql_query($sql_upd2); - - } - - //update next item (new previous item) - - if($next != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next"; - - $res_upd2 = api_sql_query($sql_upd2); - - } - - //update next_next item (switch "previous" with current) - - if($next_next != 0){ - - $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next"; - - $res_upd2 = api_sql_query($sql_upd2); - - } - - $display = $display+1; - - } - - break; - - default: - - return false; - - } - - return $display; - - } - - /** - - * Updates learnpath attributes to point to the next element - - * The last part is similar to set_current_item but processing the other way around - - */ - - function next(){ - - if($this->debug>0){error_log('New LP - In learnpath::next()',0);} - - $this->last = $this->get_current_item_id(); - - $this->items[$this->last]->save(false); - - $this->autocomplete_parents($this->last); - - $new_index = $this->get_next_index(); - - if($this->debug>2){error_log('New LP - New index: '.$new_index,0);} - - $this->index = $new_index; - - if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);} - - $this->current = $this->ordered_items[$new_index]; - - if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);} - - } - - /** - - * Open a resource = initialise all local variables relative to this resource. Depending on the child - - * class, this might be redefined to allow several behaviours depending on the document type. - - * @param integer Resource ID - - * @return boolean True on success, false otherwise - - */ - - function open($id) - - { - - if($this->debug>0){error_log('New LP - In learnpath::open()',0);} - - //TODO - - //set the current resource attribute to this resource - - //switch on element type (redefine in child class?) - - //set status for this item to "opened" - - //start timer - - //initialise score - - $this->index = 0; //or = the last item seen (see $this->last) - - } - - /** - - * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false - - * and the prerequisite string on error. - - * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108. - - * @param integer Optional item ID. If none given, uses the current open item. - - * @return boolean True if prerequisites are matched, false otherwise - - * @return string Empty string if true returned, prerequisites string otherwise. - - */ - - function prerequisites_match($item = null){ - - if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);} - - if(empty($item)){$item = $this->current;} - - if(is_object($this->items[$item])){ - - $prereq_string = $this->items[$item]->get_prereq_string(); - - if(empty($prereq_string)){return true;} - - //clean spaces - - $prereq_string = str_replace(' ','',$prereq_string); - - if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);} - - //now send to the parse_prereq() function that will check this component's prerequisites - - $result = $this->items[$item]->parse_prereq($prereq_string,$this); - - if($result === false){ - - $this->set_error_msg($this->items[$item]->prereq_alert); - - } - - }else{ - - $result = true; - - if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);} - - } - - if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);} - - return $result; - - } - - /** - - * Updates learnpath attributes to point to the previous element - - * The last part is similar to set_current_item but processing the other way around - - */ - - function previous(){ - - if($this->debug>0){error_log('New LP - In learnpath::previous()',0);} - - $this->last = $this->get_current_item_id(); - - $this->items[$this->last]->save(false); - - $this->autocomplete_parents($this->last); - - $new_index = $this->get_previous_index(); - - $this->index = $new_index; - - $this->current = $this->ordered_items[$new_index]; - - } - - /** - - * Publishes a learnpath. This basically means show or hide the learnpath - - * to normal users. - - * Can be used as abstract - - * @param integer Learnpath ID - - * @param string New visibility - - */ - - function toggle_visibility($lp_id,$set_visibility='v') - - { - - //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);} - - $tbl_lp = Database::get_course_table('lp'); - - $sql="SELECT * FROM $tbl_lp where id=$lp_id"; - - $result=api_sql_query($sql,__FILE__,__LINE__); - - $row=Database::fetch_array($result); - - $name=domesticate($row['name']); - - if($set_visibility == 'i') { - - $s=$name." ".get_lang('_no_published'); - - $dialogBox=$s; - - $v=0; - - } - - if($set_visibility == 'v') { - - $s=$name." ".get_lang('_published'); - - $dialogBox=$s; - - $v=1; - - } - - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE); - - $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id; - - $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'"; - - $result=api_sql_query($sql,__FILE__,__LINE__); - - $num=Database::num_rows($result); - - $row2=Database::fetch_array($result); - - //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);} - - if(($set_visibility == 'i') && ($num>0)) - - { - - //it is visible or hidden but once was published - - if(($row2['visibility'])==1) - - { - - $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')"; - - } - - else - - { - - $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')"; - - } - - } - - elseif(($set_visibility == 'v') && ($num==0)) - - { - - $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)"; - - } - - else - - { - - //parameter and database incompatible, do nothing - - } - - $result=api_sql_query($sql,__FILE__,__LINE__); - - //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);} - - } - /** - * Restart the whole learnpath. Return the URL of the first element. - * Make sure the results are saved with anoter method. This method should probably be - * redefined in children classes. - * @return string URL to load in the viewer - */ - function restart() - { - if($this->debug>0){error_log('New LP - In learnpath::restart()',0);} - //TODO - //call autosave method to save the current progress - //$this->index = 0; - $lp_view_table = Database::get_course_table('lp_view'); - $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " . - "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")"; - if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);} - $res = api_sql_query($sql); - if($view_id = Database::get_last_insert_id($res)) - { - $this->lp_view_id = $view_id; - $this->attempt = $this->attempt+1; - }else{ - $this->error = 'Could not insert into item_view table...'; - return false; - } - $this->autocomplete_parents($this->current); - foreach($this->items as $index=>$dummy){ - $this->items[$index]->restart(); - $this->items[$index]->set_lp_view($this->lp_view_id); - } - $this->first(); - return true; - } - /** - * Saves the current item - * @return boolean - */ - function save_current(){ - if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);} - //TODO do a better check on the index pointing to the right item (it is supposed to be working - // on $ordered_items[] but not sure it's always safe to use with $items[]) - if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);} - if($this->debug>2){error_log(''.print_r($this->items,true),0);} - if(is_object($this->items[$this->current])){ - $res = $this->items[$this->current]->save(false); - $this->autocomplete_parents($this->current); - $status = $this->items[$this->current]->get_status(); - $this->append_message('new_item_status: '.$status); - $this->update_queue[$this->current] = $status; - return $res; - } - return false; - } - /** - * Saves the given item - * @param integer Item ID. Optional (will take from $_REQUEST if null) - * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true - * @return boolean - */ - function save_item($item_id=null,$from_outside=true){ - if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);} - //TODO do a better check on the index pointing to the right item (it is supposed to be working - // on $ordered_items[] but not sure it's always safe to use with $items[]) - if(empty($item_id)){ - $item_id = $this->escape_string($_REQUEST['id']); - } - if(empty($item_id)) - { - $item_id = $this->get_current_item_id(); - } - if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);} - if(is_object($this->items[$item_id])){ - $res = $this->items[$item_id]->save($from_outside); - $this->autocomplete_parents($item_id); - $status = $this->items[$item_id]->get_status(); - $this->append_message('new_item_status: '.$status); - $this->update_queue[$item_id] = $status; - return $res; - } - return false; - } - /** - * Saves the last item seen's ID only in case - */ - function save_last(){ - - if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);} - - $table = Database::get_course_table('lp_view'); - - if(isset($this->current)){ - - if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);} - - $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " . - - "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id(); - - if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);} - - $res = api_sql_query($sql,__FILE__,__LINE__); - - } - - //save progress - - list($progress,$text) = $this->get_progress_bar_text('%'); - - if($progress>=0 AND $progress<=100){ - - $progress= (int)$progress; - - $sql = "UPDATE $table SET progress = $progress " . - - "WHERE lp_id = ".$this->get_id()." AND " . - - "user_id = ".$this->get_user_id(); - - $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet - - $this->progress_db = $progress; - - } - - } - /** - * Sets the current item ID (checks if valid and authorized first) - * @param integer New item ID. If not given or not authorized, defaults to current - */ - function set_current_item($item_id=null) - { - if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);} - if(empty($item_id)){ - if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);} - //do nothing - }else{ - if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);} - $item_id = $this->escape_string($item_id); - //TODO check in database here - $this->last = $this->current; - $this->current = $item_id; - //TODO update $this->index as well - foreach($this->ordered_items as $index => $item) - { - if($item == $this->current) - { - $this->index = $index; - break; - } - } - if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);} - } - } - /** - * Sets the encoding - * @param string New encoding - */ - function set_encoding($enc='ISO-8859-1'){ - if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);} - $enc = strtoupper($enc); - $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS'); - if(in_array($enc,$encodings)){ - $lp = $this->get_id(); - if($lp!=0){ - $tbl_lp = Database::get_course_table('lp'); - $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp; - $res = api_sql_query($sql); - return $res; - } - } - return false; - } - /** - * Sets the JS lib setting in the database directly. - * This is the JavaScript library file this lp needs to load on startup - * @param string Proximity setting - */ - function set_jslib($lib=''){ - if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);} - $lp = $this->get_id(); - if($lp!=0){ - $tbl_lp = Database::get_course_table('lp'); - $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp; - $res = api_sql_query($sql); - return $res; - }else{ - return false; - } - } - /** - * Sets the name of the LP maker (publisher) (and save) - * @param string Optional string giving the new content_maker of this learnpath - */ - function set_maker($name=''){ - - if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);} - - if(empty($name))return false; - - - - $this->maker = $this->escape_string($name); - - $lp_table = Database::get_course_table('lp'); - - $lp_id = $this->get_id(); - - $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'"; - - if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);} - - //$res = Database::query($sql); - - $res = api_sql_query($sql); - - return true; - - } - - /** - - * Sets the name of the current learnpath (and save) - - * @param string Optional string giving the new name of this learnpath - - */ - - function set_name($name=''){ - - if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);} - - if(empty($name))return false; - - - - $this->name = $this->escape_string($name); - - $lp_table = Database::get_course_table('lp'); - - $lp_id = $this->get_id(); - - $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'"; - - if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);} - - //$res = Database::query($sql); - - $res = api_sql_query($sql); - - return true; - - } - - /** - * Sets the location/proximity of the LP (local/remote) (and save) - * @param string Optional string giving the new location of this learnpath - */ - function set_proximity($name=''){ - if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);} - if(empty($name))return false; - - $this->proximity = $this->escape_string($name); - $lp_table = Database::get_course_table('lp'); - $lp_id = $this->get_id(); - $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'"; - if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);} - //$res = Database::query($sql); - $res = api_sql_query($sql); - return true; - } - /** - * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item - * @param integer DB ID of the item - */ - function set_previous_item($id) - { - if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);} - $this->last = $id; - } - /** - * Sets the object's error message - * @param string Error message. If empty, reinits the error string - * @return void - */ - function set_error_msg($error='') - { - if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);} - if(empty($error)){ - $this->error = ''; - }else{ - $this->error .= $error; - } - } - /** - * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB) - * - */ - function start_current_item(){ - if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);} - if($this->current != 0 AND - is_object($this->items[$this->current])) - { - $type = $this->get_type(); - if( - ($type == 2 && $this->items[$this->current]->get_type()!='sco') - OR - ($type == 3 && $this->items[$this->current]->get_type()!='au') - OR - ($type==1) - ) - { - $this->items[$this->current]->open(); - $this->items[$this->current]->save(false); - $this->autocomplete_parents($this->current); - $this->prerequisites_match(); //launch the prerequisites check and set error if needed - //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); - }else{ - //if sco, then it is supposed to have been updated by some other call - } - } - return true; - } - - /** - - * Stops the processing and counters for the old item (as held in $this->last) - - * @param - - */ - - function stop_previous_item(){ - - if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);} - - if($this->last != 0 AND is_object($this->items[$this->last])) - { - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);} - switch($this->get_type()){ - case '3': - if($this->items[$this->last]->get_type()!='au') - { - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);} - $this->items[$this->last]->close(); - //$this->autocomplete_parents($this->last); - //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); - }else{ - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);} - } - case '2': - if($this->items[$this->last]->get_type()!='sco') - { - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);} - $this->items[$this->last]->close(); - //$this->autocomplete_parents($this->last); - //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); - }else{ - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);} - } - break; - case '1': - default: - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);} - $this->items[$this->last]->close(); - break; - } - }else{ - if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);} - return false; - } - return true; - } - - /** - - * Updates the default view mode from fullscreen to embedded and inversely - - * @return string The current default view mode ('fullscreen' or 'embedded') - - */ - - function update_default_view_mode() - - { - - if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);} - - $lp_table = Database::get_course_table('lp'); - - $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql); - - if(Database::num_rows($res)>0){ - - $row = Database::fetch_array($res); - - $view_mode = $row['default_view_mod']; - - if($view_mode == 'fullscreen'){ - - $view_mode = 'embedded'; - - }elseif($view_mode == 'embedded'){ - - $view_mode = 'fullscreen'; - - } - - $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql); - - $this->mode = $view_mode; - - return $view_mode; - - }else{ - - if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);} - - } - - return -1; - - } - - /** - - * Updates the default behaviour about auto-commiting SCORM updates - - * @return boolean True if auto-commit has been set to 'on', false otherwise - - */ - - function update_default_scorm_commit(){ - - if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);} - - $lp_table = Database::get_course_table('lp'); - - $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql); - - if(Database::num_rows($res)>0){ - - $row = Database::fetch_array($res); - - $force = $row['force_commit']; - - if($force == 1){ - - $force = 0; - - $force_return = false; - - }elseif($force == 0){ - - $force = 1; - - $force_return = true; - - } - - $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql); - - $this->force_commit = $force_return; - - return $force_return; - - }else{ - - if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);} - - } - - return -1; - - } - - /** - - * Updates the "prevent_reinit" value that enables control on reinitialising items on second view - - * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case) - - */ - - function update_reinit(){ - - if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);} - - $lp_table = Database::get_course_table('lp'); - - $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql); - - if(Database::num_rows($res)>0){ - - $row = Database::fetch_array($res); - - $force = $row['prevent_reinit']; - - if($force == 1){ - - $force = 0; - - }elseif($force == 0){ - - $force = 1; - - } - - $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql,__FILE__,__LINE__); - - $this->prevent_reinit = $force; - - return $force; - - }else{ - - if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);} - - } - - return -1; - - } - - /** - - * Updates the "scorm_debug" value that shows or hide the debug window - - * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case) - - */ - - function update_scorm_debug(){ - - if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);} - - $lp_table = Database::get_course_table('lp'); - - $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql); - - if(Database::num_rows($res)>0){ - - $row = Database::fetch_array($res); - - $force = $row['debug']; - - if($force == 1){ - - $force = 0; - - }elseif($force == 0){ - - $force = 1; - - } - - $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id(); - - $res = api_sql_query($sql,__FILE__,__LINE__); - - $this->scorm_debug = $force; - - return $force; - - }else{ - - if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);} - - } - - return -1; - - } - - /** - * Function that makes a call to the function sort_tree_array and create_tree_array - * - * @author Kevin Van Den Haute - * - * @param unknown_type $array - */ - function tree_array($array) - { - $array = $this->sort_tree_array($array); - $this->create_tree_array($array); - } - - /** - * Creates an array with the elements of the learning path tree in it - * - * @author Kevin Van Den Haute - * - * @param array $array - * @param int $parent - * @param int $depth - * @param array $tmp - */ - function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array()) - { - if(is_array($array)) - { - for($i = 0; $i < count($array); $i++) - { - if($array[$i]['parent_item_id'] == $parent) - { - if(!in_array($array[$i]['parent_item_id'], $tmp)) - { - $tmp[] = $array[$i]['parent_item_id']; - $depth++; - } - - $this->arrMenu[] = array( - 'id' => $array[$i]['id'], - 'item_type' => $array[$i]['item_type'], - 'title' => $array[$i]['title'], - 'path' => $array[$i]['path'], - 'description' => $array[$i]['description'], - 'parent_item_id' => $array[$i]['parent_item_id'], - 'previous_item_id' => $array[$i]['previous_item_id'], - 'next_item_id' => $array[$i]['next_item_id'], - 'display_order' => $array[$i]['display_order'], - 'depth' => $depth - ); - - $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp); - } - } - } - } - - /** - * Sorts a multi dimensional array by parent id and display order - * @author Kevin Van Den Haute - * - * @param array $array (array with al the learning path items in it) - * - * @return array - */ - function sort_tree_array($array) - { - foreach($array as $key => $row) - { - $parent[$key] = $row['parent_item_id']; - $position[$key] = $row['display_order']; - } - - if(count($array) > 0) - array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array); - - return $array; - } - - - - /** - * Function that creates a table structure with a learning path his modules, chapters and documents. - * Also the actions for the modules, chapters and documents are in this table. - * - * @author Kevin Van Den Haute - * - * @param int $lp_id - * - * @return string - */ - function overview() - { - $return = ''; - - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - if(api_is_allowed_to_edit()) - $return .= '

    Advanced

    '; - - $return .= '' . "\n"; - - $return .= "\t" . '' . "\n"; - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= "\t" . '' . "\n"; - - for($i = 0; $i < count($arrLP); $i++) - { - if($arrLP[$i]['description'] == '') - $arrLP[$i]['description'] = ' '; - - $return .= "\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - $return .= "\t\t" . '' . "\n"; - - if(api_is_allowed_to_edit()) - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t" . '' . "\n"; - } - - if(count($arrLP) == 0) - { - $return .= "\t" . '' . "\n"; - $return .= "\t\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - } - - $return .= '
    TitleDescriptionMoveActions
    ' . stripslashes($arrLP[$i]['title']) . '' . stripslashes($arrLP[$i]['description']) . '' . "\n"; - - if($arrLP[$i]['previous_item_id'] != 0) - { - $return .= "\t\t\t" . ''; - $return .= ''; - $return .= '' . "\n"; - } - else - $return .= "\t\t\t" . '' . "\n"; - - if($arrLP[$i]['next_item_id'] != 0) - { - $return .= "\t\t\t" . ''; - $return .= ''; - $return .= '' . "\n"; - } - else - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') - { - $return .= "\t\t\t" . ''; - $return .= ''; - $return .= '' . "\n"; - } - else - { - $return .= "\t\t\t" . ''; - $return .= ''; - $return .= '' . "\n"; - } - - $return .= "\t\t\t" . ''; - $return .= ''; - $return .= '' . "\n"; - - $return .= "\t\t" . '
    There are no items in the learning path for this moment. Click on "Advanced" for creating your learning path items.
    ' . "\n"; - - return $return; - } - - /** - * This functions builds the LP tree based on data from the database. - * - * @return string - * @uses dtree.js :: necessary javascript for building this tree - */ - function build_tree() - { - $return = "\n"; - - return $return; - } - - /** - * Create a new document //still needs some finetuning - * - * @param array $_course - * @return string - */ - function create_document($_course) - { - $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting - - if(strstr($dir, '..')) - $dir = '/'; - - if($dir[0] == '.') - $dir = substr($dir, 1); - - if($dir[0] != '/') - $dir = '/'.$dir; - - if($dir[strlen($dir) - 1] != '/') - $dir .= '/'; - - $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir; - - if(!is_dir($filepath)) - { - $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/'; - - $dir = '/'; - } - - $title = replace_dangerous_char($_POST['title']); - $filename = $title; - $content = $_POST['content']; - - $tmp_filename = $filename; - - while(file_exists($filepath . $tmp_filename . '.html')) - $tmp_filename = $filename . '_' . ++$i; - - $filename = $tmp_filename . '.html'; - - $content = stripslashes(text_filter($content)); - - $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir; - $content = str_replace($path_to_remove, './', $content); - - if(!file_exists($filepath . $filename)) - { - if($fp = @fopen($filepath . $filename, 'w')) - { - fputs($fp, $content); - fclose($fp); - - $file_size = filesize($filepath . $filename); - $save_file_path = $dir . $filename; - - $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html'); - - if($document_id) - { - api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id); - - //update parent folders - //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']); - - $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : ''; - $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : ''; - - if($new_comment || $new_title) - { - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE); - $ct = ''; - - if($new_comment) - $ct .= ", comment='" . $new_comment . "'"; - - if($new_title) - $ct .= ", title='" . $new_title . ".html '"; - - $sql_update = " - UPDATE " . $tbl_doc . " - SET " . substr($ct, 1) . " - WHERE id = " . $document_id; - api_sql_query($sql_update, __FILE__, __LINE__); - } - } - - return $document_id; - } - } - } - - /** - * Enter description here... - * - * @param array $_course - */ - function edit_document($_course) - { - $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting - - if(strstr($dir, '..')) - $dir = '/'; - - if($dir[0] == '.') - $dir = substr($dir, 1); - - if($dir[0] != '/') - $dir = '/'.$dir; - - if($dir[strlen($dir) - 1] != '/') - $dir .= '/'; - - $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir; - - if(!is_dir($filepath)) - { - $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/'; - - $dir = '/'; - } - - $table_doc = Database::get_course_table(DOCUMENT_TABLE); - - $sql = " - SELECT path - FROM " . $table_doc . " - WHERE id = " . $_POST['path']; - $res = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($res); - - $content = stripslashes($_POST['content']); - $file = $filepath . $row['path']; - - - if($fp = @fopen($file, 'w')) - { - $content = text_filter($content); - $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir; - $content = str_replace($path_to_remove, './', $content); - - fputs($fp, $content); - fclose($fp); - } - } - - /** - * Displays the selected item, with a panel for manipulating the item - * - * @param int $item_id - * @param string $msg - * @return string - */ - function display_item($item_id, $iframe = true, $msg = '') - { - global $_course; //will disappear - - $return = ''; - - if(is_numeric($item_id)) - { - $tbl_lp_item = Database::get_course_table('lp_item'); - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE); - - $sql = " - SELECT - lp.* - FROM " . $tbl_lp_item . " as lp - WHERE - lp.id = " . $item_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - while($row = Database::fetch_array($result)) - { - $return .= $this->display_manipulate($item_id, $row['item_type']); - - $return .= '
    '; - - if($msg != '') - $return .= $msg; - - $return .= '

    ' . stripslashes($row['title']) . '

    '; - $return .= '

    ' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '

    '; - - $return .= '
    '; - - if($row['item_type'] == TOOL_DOCUMENT) - $return .= $this->display_document($row['path'], true, true); - - $return .= '
    '; - } - } - - return $return; - } - - /** - * Shows the needed forms for editing a specific item - * - * @param int $item_id - * @return string - */ - function display_edit_item($item_id) - { - global $_course; //will disappear - - $return = ''; - - if(is_numeric($item_id)) - { - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE id = " . $item_id; - - $res = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($res); - - switch($row['item_type']) - { - case 'dokeos_chapter': - - if(isset($_GET['view']) && $_GET['view'] == 'build') - { - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_item_form($row['item_type'], 'Edit the current chapter:', 'edit', $item_id, $row); - } - else - { - $return .= $this->display_item_small_form($row['item_type'], 'Edit the current chapter:', $row); - } - - break; - - case TOOL_DOCUMENT: - - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE); - - $sql_step = " - SELECT - lp.*, - doc.path as dir - FROM " . $tbl_lp_item . " as lp - LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path - WHERE - lp.id = " . $item_id; - $res_step = api_sql_query($sql_step, __FILE__, __LINE__); - $row_step = Database::fetch_array($res_step); - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_document_form('edit', $item_id, $row_step); - - break; - - case TOOL_LINK: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_link_form('edit', $item_id, $row); - - break; - - case 'dokeos_module': - - if(isset($_GET['view']) && $_GET['view'] == 'build') - { - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_item_form($row['item_type'], 'Edit the current module:', 'edit', $item_id, $row); - } - else - { - $return .= $this->display_item_small_form($row['item_type'], 'Edit the current module:', $row); - } - - break; - - case TOOL_QUIZ: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_quiz_form('edit', $item_id, $row); - - break; - - case TOOL_STUDENTPUBLICATION: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_student_publication_form('edit', $item_id, $row); - - break; - } - } - - return $return; - } - - /** - * Function that displays a list with al the resources that could be added to the learning path - * - * @return string - */ - function display_resources() - { - global $_course; //TODO: don't use globals - - $return = '
    ' . "\n"; - - $return .= '

    Create a new step:

    '; - - $return .= '
    New document
    '; - - $return .= '

    Or use an existing resource:

    '; - - /* get al the docs */ - $return .= $this->get_documents(); - - /* get al the exercises */ - $return .= $this->get_exercises(); - - /* get al links */ - $return .= $this->get_links(); - - /* get al the student publications */ - $return .= $this->get_student_publications(); - - $return .= '
    ' . "\n"; - - return $return; - } - - /** - * Returns the extension of a document - * - * @param unknown_type $filename - * @return unknown - */ - function get_extension($filename) - { - $explode = explode('.', $filename); - - return $explode[count($explode) - 1]; - } - - /** - * Displays a document by id - * - * @param unknown_type $id - * @return unknown - */ - function display_document($id, $show_title = false, $iframe = true, $edit_link = false) - { - global $_course; //temporary - - $return = ''; - - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE); - - $sql_doc = " - SELECT * - FROM " . $tbl_doc . " - WHERE id = " . $id; - $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__); - $row_doc = Database::fetch_array($res_doc); - - if($show_title) - $return .= '

    ' . $row_doc['title'] . ($edit_link ? ' [ Edit this document ]' : '') . '

    '; - - //TODO: add a path filter - if($iframe) - $return .= ''; - else - $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']); - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $action - * @param unknown_type $id - * @param unknown_type $extra_info - * @return unknown - */ - function display_quiz_form($action = 'add', $id = 0, $extra_info = '') - { - $tbl_lp_item = Database::get_course_table('lp_item'); - $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE); - - if($id != 0 && is_array($extra_info)) - { - $item_title = stripslashes($extra_info['title']); - $item_description = stripslashes($extra_info['description']); - } - elseif(is_numeric($extra_info)) - { - $sql_quiz = " - SELECT - title, - description - FROM " . $tbl_quiz . " - WHERE id = " . $extra_info; - - $result = api_sql_query($sql_quiz, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $item_title = $row['title']; - $item_description = $row['description']; - } - else - { - $item_title = ''; - $item_description = ''; - } - - $return = '
    '; - - if($id != 0 && is_array($extra_info)) - $parent = $extra_info['parent_item_id']; - else - $parent = 0; - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'path' => $row['path'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - if($action == 'add') - $return .= '

    Create the exercise:

    ' . "\n"; - elseif($action == 'move') - $return .= '

    Move the current exercise:

    ' . "\n"; - else - $return .= '

    Edit the current exercise:

    ' . "\n"; - - if(isset($_GET['edit']) && $_GET['edit'] == 'true') - { - $return .= '
    '; - - $return .= '

    Warning !

    '; - $return .= 'When you edit an existing document in the Learning Path, the new version of the document will not overwrite the old version but will be saved as a new document. If you want to edit a document definitively, you can do that with the document tool.'; - - $return .= '
    '; - } - - $return .= '
    ' . "\n"; - - $return .= "\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if($action != 'move') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - if($action == 'move') - { - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - } - - if(is_numeric($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - elseif(is_array($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= '
    ' . "\n"; - - $return .= '
    ' . "\n"; - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $item_type - * @param unknown_type $title - * @param unknown_type $action - * @param unknown_type $id - * @param unknown_type $extra_info - * @return unknown - */ - function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') - { - $tbl_lp_item = Database::get_course_table('lp_item'); - - if($id != 0 && is_array($extra_info)) - { - $item_title = stripslashes($extra_info['title']); - $item_description = stripslashes($extra_info['description']); - } - else - { - $item_title = ''; - $item_description = ''; - } - - $return = '
    '; - - if($id != 0 && is_array($extra_info)) - $parent = $extra_info['parent_item_id']; - else - $parent = 0; - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - if($item_type == 'module') - $sql .= " AND parent_item_id = 0"; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'path' => $row['path'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - $return .= '

    ' . $title . '

    ' . "\n"; - - $return .= '
    ' . "\n"; - - $return .= "\t" . '' . "\n"; - - if($item_type != 'module' && $item_type != 'dokeos_module') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if($action != 'move') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - if($item_type == 'module' || $item_type == 'dokeos_module') - $return .= "\t" . '' . "\n"; - - if($action == 'move') - { - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - } - /*if($id != 0 && is_array($extra_info)) - { - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - }*/ - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= '
    ' . "\n"; - $return .= '
    ' . "\n"; - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $action - * @param unknown_type $id - * @param unknown_type $extra_info - * @return unknown - */ - function display_document_form($action = 'add', $id = 0, $extra_info = 'new') - { - $tbl_lp_item = Database::get_course_table('lp_item'); - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE); - - if($id != 0 && is_array($extra_info)) - { - $item_title = stripslashes($extra_info['title']); - $item_description = stripslashes($extra_info['description']); - } - elseif(is_numeric($extra_info)) - { - $sql_doc = " - SELECT title - FROM " . $tbl_doc . " - WHERE id = " . $extra_info; - - $result = api_sql_query($sql_doc, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $explode = explode('.', $row['title']); - - for($i = 0; $i < count($explode) - 1; $i++) - $item_title .= $explode[$i]; - - $item_title = str_replace('_', ' ', $item_title); - } - else - { - $item_title = ''; - $item_description = ''; - } - - $return = '
    '; - - if($id != 0 && is_array($extra_info)) - $parent = $extra_info['parent_item_id']; - else - $parent = 0; - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'path' => $row['path'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - if($action == 'add') - $return .= '

    Create the document:

    ' . "\n"; - elseif($action == 'move') - $return .= '

    Move the current document:

    ' . "\n"; - else - $return .= '

    Edit the current document:

    ' . "\n"; - - if(isset($_GET['edit']) && $_GET['edit'] == 'true') - { - $return .= '
    '; - - $return .= '

    Warning !

    '; - $return .= 'When you edit an existing document in the Learning Path, the new version of the document will not overwrite the old version but will be saved as a new document. If you want to edit a document definitively, you can do that with the document tool.'; - - $return .= '
    '; - } - - $return .= '
    ' . "\n"; - - $return .= "\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if($action != 'move') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) - { - if($action == 'add' || $_GET['edit'] == 'true') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - elseif(is_numeric($extra_info)) - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    '; - - $sql_doc = " - SELECT * - FROM " . $tbl_doc . " - WHERE - filetype = 'folder' - ORDER BY path ASC"; - - $result = api_sql_query($sql_doc, __FILE__, __LINE__); - - $return .= "\t\t\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '
    ' . "\n"; - - if(isset($_POST['content'])) - $content = stripslashes($_POST['content']); - elseif(is_array($extra_info)) - $content = $this->display_document($extra_info['path'], false, false); - elseif(is_numeric($extra_info)) - $content = $this->display_document($extra_info, false, false); - else - $content = ''; - - $oFCKeditor = new FCKeditor('content_lp') ; - $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ; - $oFCKeditor->Height = '400'; - $oFCKeditor->Width = '100%'; - $oFCKeditor->Value = $content; - - $return .= $oFCKeditor->CreateHtml(); - - $return .= "\t\t\t" . '
    ' . "\n"; - - $return .= $this->display_document($extra_info, true, true, true); - - $return .= "\t\t\t" . '
    ' . "\n"; - - if($action == 'move') - { - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - } - - if(is_numeric($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - elseif(is_array($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= '
    ' . "\n"; - $return .= '
    ' . "\n"; - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $action - * @param unknown_type $id - * @param unknown_type $extra_info - */ - function display_link_form($action = 'add', $id = 0, $extra_info = '') - { - $tbl_lp_item = Database::get_course_table('lp_item'); - $tbl_link = Database::get_course_table(LINK_TABLE); - - if($id != 0 && is_array($extra_info)) - { - $item_title = stripslashes($extra_info['title']); - $item_description = stripslashes($extra_info['description']); - } - elseif(is_numeric($extra_info)) - { - $sql_link = " - SELECT - title, - description, - url - FROM " . $tbl_link . " - WHERE id = " . $extra_info; - - $result = api_sql_query($sql_link, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $item_title = $row['title']; - $item_description = $row['description']; - $item_url = $row['url']; - } - else - { - $item_title = ''; - $item_description = ''; - } - - $return = '
    '; - - if($id != 0 && is_array($extra_info)) - $parent = $extra_info['parent_item_id']; - else - $parent = 0; - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'path' => $row['path'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - if($action == 'add') - $return .= '

    Create the link:

    ' . "\n"; - elseif($action == 'move') - $return .= '

    Move the current link:

    ' . "\n"; - else - $return .= '

    Edit the current link:

    ' . "\n"; - - $return .= '
    ' . "\n"; - - $return .= "\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if($action != 'move') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - if($action == 'move') - { - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - } - - if(is_numeric($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - elseif(is_array($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= '
    ' . "\n"; - - $return .= '
    ' . "\n"; - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $action - * @param unknown_type $id - * @param unknown_type $extra_info - * @return unknown - */ - function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') - { - $tbl_lp_item = Database::get_course_table('lp_item'); - $tbl_publication = Database::get_course_table(STUDENT_PUBLICATION_TABLE); - - if($id != 0 && is_array($extra_info)) - { - $item_title = stripslashes($extra_info['title']); - $item_description = stripslashes($extra_info['description']); - } - elseif(is_numeric($extra_info)) - { - $sql_publication = " - SELECT - title, - description - FROM " . $tbl_publication . " - WHERE id = " . $extra_info; - - $result = api_sql_query($sql_publication, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $item_title = $row['title']; - $item_description = $row['description']; - } - else - { - $item_title = ''; - $item_description = ''; - } - - $return = '
    '; - - if($id != 0 && is_array($extra_info)) - $parent = $extra_info['parent_item_id']; - else - $parent = 0; - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'path' => $row['path'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - if($action == 'add') - $return .= '

    Create the student publication:

    ' . "\n"; - elseif($action == 'move') - $return .= '

    Move the current student publication:

    ' . "\n"; - else - $return .= '

    Edit the current student publication:

    ' . "\n"; - - $return .= '
    ' . "\n"; - - $return .= "\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - if($action != 'move') - { - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - } - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - $return .= "\t\t\t\t" . ''; - - $return .= "\t\t\t" . '
    ' . "\n"; - - if($action == 'move') - { - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - } - - if(is_numeric($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - elseif(is_array($extra_info)) - { - $return .= "\t" . '' . "\n"; - } - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= '
    ' . "\n"; - - $return .= '
    ' . "\n"; - - return $return; - } - - /** - * Displays the menu for manipulating a step - * - * @return unknown - */ - function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) - { - $return = '
    '; - - switch($item_type) - { - case 'dokeos_chapter': - case 'chapter': - - $lang = get_lang('TitleManipulateChapter'); - /* temp */ $lang = 'Manipulate the current chapter'; - break; - - case 'dokeos_module': - case 'module': - - $lang = get_lang('TitleManipulateModule'); - /* temp */ $lang = 'Manipulate the current module'; - - break; - - case TOOL_DOCUMENT: - - $lang = get_lang('TitleManipulateDocument'); - /* temp */ $lang = 'Manipulate the current document'; - - break; - - case TOOL_LINK: - case 'link': - - $lang = get_lang('TitleManipulateLink'); - /* temp */ $lang = 'Manipulate the current link'; - - break; - - case TOOL_QUIZ: - - $lang = get_lang('TitleManipulateQuiz'); - /* temp */ $lang = 'Manipulate the current exercise'; - - break; - - case TOOL_STUDENTPUBLICATION: - - $lang = get_lang('TitleManipulateStudentPublication'); - /* temp */ $lang = 'Manipulate the current student publication'; - - break; - } - - $return .= '

    ' . $lang . '

    '; - - $return .= 'Edit the current item Edit'; - $return .= 'Move the current item Move'; - - if($item_type != 'chapter' && $item_type != 'dokeos_chapter' && $item_type != 'module' && $item_type != 'dokeos_module') - $return .= 'Edit the prerequisites of the current item Prerequisites'; - - $return .= 'Delete the current item Delete'; - - $return .= '
    '; - - return $return; - } - - /** - * Creates the javascript needed for filling up the checkboxes without page reload - * - * @return string - */ - function create_js() - { - $return = '' . "\n"; - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $item_id - * @return unknown - */ - function display_move_item($item_id) - { - global $_course; //will disappear - - $return = ''; - - if(is_numeric($item_id)) - { - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE id = " . $item_id; - - $res = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($res); - - switch($row['item_type']) - { - case 'dokeos_chapter': - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_item_form($row['item_type'], 'Move the current chapter:', 'move', $item_id, $row); - - break; - - case 'dokeos_module': - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row); - - break; - - case TOOL_DOCUMENT: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_document_form('move', $item_id, $row); - - break; - - case TOOL_LINK: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_link_form('move', $item_id, $row); - - break; - - case TOOL_QUIZ: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_quiz_form('move', $item_id, $row); - - break; - - case TOOL_STUDENTPUBLICATION: - - $return .= $this->display_manipulate($item_id, $row['item_type']); - $return .= $this->display_student_publication_form('move', $item_id, $row); - - break; - } - } - - return $return; - } - - /** - * Displays a basic form on the overview page for changing the item title and the item description. - * - * @param string $item_type - * @param string $title - * @param array $data - * @return string - */ - function display_item_small_form($item_type, $title = '', $data) - { - $return .= '
    ' . "\n"; - - $return .= '

    ' . $title . '

    '; - - $return .= '
    ' . "\n"; - - $return .= ''; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t\t" . '' . "\n"; - - $return .= "\t\t" . '' . "\n"; - - $return .= "\t\t" . '
    ' . "\n"; - - $return .= "\t" . '' . "\n"; - $return .= "\t" . '' . "\n"; - - $return .= '
    '; - - $return .= '
    '; - - return $return; - } - - /** - * Enter description here... - * - * @param unknown_type $item_id - * @return unknown - */ - function display_item_prerequisites_form($item_id) - { - $tbl_lp_item = Database::get_course_table('lp_item'); - - /* current prerequisite */ - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE id = " . $item_id; - $result = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($result); - - $preq_id = $row['prerequisite']; - $preq_min = $row['min_score']; - $preq_max = $row['max_score']; - - $return = $this->display_manipulate($item_id, TOOL_DOCUMENT); - - $return .= '
    '; - - $return .= '

    Add/edit prerequisites

    '; - - $return .= '
    '; - - $return .= ''; - - $return .= ''; - - $return .= ''; - $return .= ''; - $return .= ''; - - $return .= ''; - - $return .= ''; - - $return .= ''; - - $return .= ''; - - $sql = " - SELECT * - FROM " . $tbl_lp_item . " - WHERE - lp_id = " . $this->lp_id; - - $result = api_sql_query($sql, __FILE__, __LINE__); - - $arrLP = array(); - - while($row = Database::fetch_array($result)) - { - $arrLP[] = array( - 'id' => $row['id'], - 'item_type' => $row['item_type'], - 'title' => $row['title'], - 'description' => $row['description'], - 'parent_item_id' => $row['parent_item_id'], - 'previous_item_id' => $row['previous_item_id'], - 'next_item_id' => $row['next_item_id'], - 'display_order' => $row['display_order']); - } - - $this->tree_array($arrLP); - - $arrLP = $this->arrMenu; - - unset($this->arrMenu); - - for($i = 0; $i < count($arrLP); $i++) - { - if($arrLP[$i]['id'] == $item_id) - break; - - $return .= ''; - - $return .= ''; - - if($arrLP[$i]['item_type'] == TOOL_QUIZ) - { - $return .= ''; - - $return .= ''; - } - - $return .= ''; - } - - $return .= ''; - - $return .= '' . "\n"; - - $return .= ''; - - $return .= ''; - - $return .= '
    MinimumMaximum
    '; - - $return .= ''; - $return .= ''; - - $return .= '
    '; - - $return .= ''; - $return .= ''; - $return .= ''; - - $return .= ''; - - $return .= ''; - - $return .= ''; - - $return .= ''; - - $return .= '
    '; - - $return .= '
    '; - - $return .= '
    '; - - $return .= '
    '; - - return $return; - } - - /** - * Creates a list with all the documents in it - * - * @return string - */ - function get_documents() - { - global $_course; - - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE); - - $sql_doc = " - SELECT * - FROM " . $tbl_doc . " - WHERE - path NOT LIKE '%_DELETED_%' - ORDER BY path ASC"; - $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__); - - $return = '
    Document
    '; - $return .= '
    '; - - while($row_doc = Database::fetch_array($res_doc)) - { - $explode = explode('/', $row_doc['path']); - $num = count($explode) - 2; - - $return .= '
    '; - - $return .= ''; - - if($row_doc['filetype'] == 'file') - $return .= '' . $row_doc['title'] . ''; - else - $return .= $row_doc['title']; - - $return .= '
    '; - } - - if(Database::num_rows($res_doc) == 0) - $return .= '
    No documents
    '; - - $return .= '
    '; - - return $return; - } - - /** - * Creates a list with all the exercises (quiz) in it - * - * @return string - */ - function get_exercises() - { - $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE); - - $sql_quiz = " - SELECT * - FROM " . $tbl_quiz . " - ORDER BY title ASC"; - $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__); - - $return .= '
    Exercises
    '; - $return .= '
    '; - - while($row_quiz = Database::fetch_array($res_quiz)) - { - $return .= '
    '; - - $return .= ''; - $return .= '' . $row_quiz['title'] . ''; - //$return .= $row_quiz['title']; - - $return .= '
    '; - } - - if(Database::num_rows($res_quiz) == 0) - $return .= '
    No exercises available
    '; - - $return .= '
    '; - - return $return; - } - - /** - * Creates a list with all the links in it - * - * @return string - */ - function get_links() - { - $tbl_link = Database::get_course_table(LINK_TABLE); - - $sql_link = " - SELECT * - FROM " . $tbl_link . " - ORDER BY title ASC"; - $res_link = api_sql_query($sql_link, __FILE__, __LINE__); - - $return .= '
    Links
    '; - $return .= ''; - - return $return; - } - - /** - * Creates a list with all the student publications in it - * - * @return unknown - */ - function get_student_publications() - { - $tbl_student = Database::get_course_table(STUDENT_PUBLICATION_TABLE); - - $sql_student = " - SELECT * - FROM " . $tbl_student . " - ORDER BY title ASC"; - $res_student = api_sql_query($sql_student, __FILE__, __LINE__); - - $return .= '
    Student Publications
    '; - $return .= '
    '; - - while($row_student = Database::fetch_array($res_student)) - { - $return .= '
    '; - - $return .= ''; - $return .= '' . $row_student['title'] . ''; - - $return .= '
    '; - } - - if(Database::num_rows($res_student) == 0) - $return .= '
    No student publications available
    '; - - $return .= '
    '; - - return $return; - } -} - + + * @license GNU/GPL - See Dokeos license directory for details + */ +/** + * Defines the learnpath parent class + * @package dokeos.learnpath + */ +class learnpath { + + var $attempt = 0; //the number for the current ID view + var $cc; //course (code) this learnpath is located in + var $current; //id of the current item the user is viewing + var $current_score; //the score of the current item + var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet) + var $current_time_stop; //the time the user closed this resource + var $default_status = 'not attempted'; + var $encoding = 'ISO-8859-1'; + var $error = ''; + var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath + var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue() + var $index; //the index of the active learnpath_item in $ordered_items array + var $items = array(); + var $last; //item_id of last item viewed in the learning path + var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized + var $license; //which license this course has been given - not used yet on 20060522 + var $lp_id; //DB ID for this learnpath + var $lp_view_id; //DB ID for lp_view + var $log_file; //file where to log learnpath API msg + var $maker; //which maker has conceived the content (ENI, Articulate, ...) + var $message = ''; + var $mode='embedded'; //holds the video display mode (fullscreen or embedded) + var $name; //learnpath name (they generally have one) + var $ordered_items = array(); //list of the learnpath items in the order they are to be read + var $path = ''; //path inside the scorm directory (if scorm) + + // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1) + var $prevent_reinit = 1; + + // Describes the mode of progress bar display + var $progress_bar_mode = '%'; + + // Percentage progress as saved in the db + var $progress_db = '0'; + var $proximity; //wether the content is distant or local or unknown + var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match. + //!!!This array (refs_list) is built differently depending on the nature of the LP. + //If SCORM, uses ref, if Dokeos, uses id to keep a unique value + var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ... + //TODO check if this type variable is useful here (instead of just in the controller script) + var $user_id; //ID of the user that is viewing/using the course + var $update_queue = array(); + var $scorm_debug = 0; + + var $arrMenu = array(); //array for the menu items + + var $debug = 0; //logging level + + + + /** + * Class constructor. Needs a database handler, a course code and a learnpath id from the database. + * Also builds the list of items into $this->items. + * @param string Course code + * @param integer Learnpath ID + * @param integer User ID + * @return boolean True on success, false on error + */ + function learnpath($course, $lp_id, $user_id) { + //check params + //check course code + if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);} + if(empty($course)){ + $this->error = 'Course code is empty'; + return false; + } + else + { + $main_table = Database::get_main_table(TABLE_MAIN_COURSE); + //$course = Database::escape_string($course); + $course = $this->escape_string($course); + $sql = "SELECT * FROM $main_table WHERE code = '$course'"; + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);} + //$res = Database::query($sql); + $res = api_sql_query($sql); + if(Database::num_rows($res)>0) + { + $this->cc = $course; + } + else + { + $this->error = 'Course code does not exist in database ('.$sql.')'; + return false; + } + } + //check learnpath ID + if(empty($lp_id)) + { + $this->error = 'Learnpath ID is empty'; + return false; + } + else + { + //TODO make it flexible to use any course_code (still using env course code here) + //$lp_table = Database::get_course_table(LEARNPATH_TABLE); + $lp_db = Database::get_current_course_database(); + $lp_pref = Database::get_course_table_prefix(); + $lp_table = $lp_db.'.'.$lp_pref.'lp'; + + //$id = Database::escape_integer($id); + $lp_id = $this->escape_string($lp_id); + $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'"; + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);} + //$res = Database::query($sql); + $res = api_sql_query($sql); + if(Database::num_rows($res)>0) + { + $this->lp_id = $lp_id; + $row = Database::fetch_array($res); + $this->type = $row['lp_type']; + $this->name = stripslashes($row['name']); + $this->encoding = $row['default_encoding']; + $this->proximity = $row['content_local']; + $this->maker = $row['content_maker']; + $this->prevent_reinit = $row['prevent_reinit']; + $this->license = $row['content_license']; + $this->scorm_debug = $row['debug']; + $this->js_lib = $row['js_lib']; + $this->path = $row['path']; + if($this->type == 2){ + if($row['force_commit'] == 1){ + $this->force_commit = true; + } + } + $this->mode = $row['default_view_mod']; + } + else + { + $this->error = 'Learnpath ID does not exist in database ('.$sql.')'; + return false; + } + } + //check user ID + if(empty($user_id)){ + $this->error = 'User ID is empty'; + return false; + } + else + { + //$main_table = Database::get_main_user_table(); + $main_table = Database::get_main_table(TABLE_MAIN_USER); + //$user_id = Database::escape_integer($user_id); + $user_id = $this->escape_string($user_id); + $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'"; + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);} + //$res = Database::query($sql); + $res = api_sql_query($sql); + if(Database::num_rows($res)>0) + { + $this->user_id = $user_id; + } + else + { + $this->error = 'User ID does not exist in database ('.$sql.')'; + return false; + } + } + //end of variables checking + + //now get the latest attempt from this user on this LP, if available, otherwise create a new one + //$lp_table = Database::get_course_table(LEARNPATH_VIEW_TABLE); + $lp_db = Database::get_current_course_database(); + $lp_pref = Database::get_course_table_prefix(); + $lp_table = $lp_db.'.'.$lp_pref.'lp_view'; + //selecting by view_count descending allows to get the highest view_count first + $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC"; + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);} + //$res = Database::query($sql); + $res = api_sql_query($sql); + $view_id = 0; //used later to query lp_item_view + if(Database::num_rows($res)>0) + { + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);} + $row = Database::fetch_array($res); + $this->attempt = $row['view_count']; + $this->lp_view_id = $row['id']; + $this->last_item_seen = $row['last_item']; + $this->progress_db = $row['progress']; + } + else + { + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);} + $this->attempt = 1; + $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)"; + $res_ins = api_sql_query($sql_ins); + $this->lp_view_id = Database::get_last_insert_id(); + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);} + } + + //initialise items + $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item'; + $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order"; + $res = api_sql_query($sql); + + while($row = Database::fetch_array($res)) + { + $oItem = ''; + //$this->ordered_items[] = $row['id']; + switch($this->type){ + + case 3: //aicc + $oItem = new aiccItem('db',$row['id']); + if(is_object($oItem)){ + $oItem->set_lp_view($this->lp_view_id); + $oItem->set_prevent_reinit($this->prevent_reinit); + $id = $oItem->get_id(); + // Don't use reference here as the next loop will make the pointed object change + $this->items[$id] = $oItem; + $this->refs_list[$oItem->ref]=$id; + if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$id.' set in items[]',0);} + } + break; + case 2: + + require_once('scorm.class.php'); + require_once('scormItem.class.php'); + $oItem = new scormItem('db',$row['id']); + if(is_object($oItem)){ + $oItem->set_lp_view($this->lp_view_id); + $oItem->set_prevent_reinit($this->prevent_reinit); + // Don't use reference here as the next loop will make the pointed object change + $this->items[$oItem->get_id()] = $oItem; + $this->refs_list[$oItem->ref]=$oItem->get_id(); + if($this->debug>2){error_log('New LP - object with id '.$oItem->get_id().' set in items[]',0);} + } + break; + + case 1: + + default: + require_once('learnpathItem.class.php'); + $oItem = new learnpathItem($row['id'],$user_id); + if(is_object($oItem)){ + //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists + $oItem->set_prevent_reinit($this->prevent_reinit); + // Don't use reference here as the next loop will make the pointed object change + $this->items[$oItem->get_id()] = $oItem; + $this->refs_list[$oItem->get_id()]=$oItem->get_id(); + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$oItem->get_id().' set in items[]',0);} + } + break; + } + + //items is a list of pointers to all items, classified by DB ID, not SCO id + if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){ + $this->items[$row['id']]->set_level(0); + }else{ + $level = $this->items[$row['parent_item_id']]->get_level()+1; + $this->items[$row['id']]->set_level($level); + if(is_object($this->items[$row['parent_item_id']])){ + //items is a list of pointers from item DB ids to item objects + $this->items[$row['parent_item_id']]->add_child($row['id']); + }else{ + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - The parent item ('.$row['parent_item_id'].') of item '.$row['id'].' could not be found',0);} + } + } + + //get last viewing vars + //$learnpath_items_view_table = Database::get_course_table(LEARNPATH_ITEM_VIEW_TABLE); + $lp_item_view_table = $lp_db.'.'.$lp_pref.'lp_item_view'; + //this query should only return one or zero result + $sql = "SELECT * " . + "FROM $lp_item_view_table " . + "WHERE lp_view_id = ".$this->lp_view_id." " . + "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC "; + if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);} + //get the item status + $res2 = api_sql_query($sql); + if(Database::num_rows($res2)>0) + { + //if this learnpath has already been used by this user, get his last attempt count and + //the last item seen back into this object + //$max = 0; + $row2 = Database::fetch_array($res2); + if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);} + $this->items[$row['id']]->set_status($row2['status']); + if(empty($row2['status'])){ + $this->items[$row['id']]->set_status($this->default_status); + } + //$this->attempt = $row['view_count']; + //$this->last_item = $row['id']; + } + else //no item found in lp_item_view for this view + { + //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available) + //TODO if the learnpath has not got attempts activated, always use attempt '1' + //$this->attempt = 1; + //$this->last_item = 0; + $this->items[$row['id']]->set_status($this->default_status); + //Add that row to the lp_item_view table so that we have something to show in the stats page + $sql_ins = "INSERT INTO $lp_item_view_table " . + "(lp_item_id, lp_view_id, view_count, status) VALUES " . + "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')"; + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);} + $res_ins = api_sql_query($sql_ins); + } + //setting the view in the item object + $this->items[$row['id']]->set_lp_view($this->lp_view_id); + } + $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0); + $this->max_ordered_items = 0; + foreach($this->ordered_items as $index=>$dummy){ + if($index > $this->max_ordered_items AND !empty($dummy)){ + $this->max_ordered_items = $index; + } + } + //TODO define the current item better + $this->first(); + if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);} + } + + /** + * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and + * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description. + * + * @param int $parent + * @param int $previous + * @param string $type + * @param int $id + * @param string $title + * @param string $description + * @return int + */ + function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description) + { + if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);} + + $tbl_lp_item = Database::get_course_table('lp_item'); + $parent = (int) $parent; + + $sql_count = " + SELECT COUNT(id) AS num + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->get_id() . " AND + parent_item_id = " . $parent; + + $res_count = api_sql_query($sql_count, __FILE__, __LINE__); + $row = Database::fetch_array($res_count); + + $num = $row['num']; + + if($num > 0) + { + if($previous == 0) + { + $sql = " + SELECT + id, + next_item_id, + display_order + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->get_id() . " AND + parent_item_id = " . $parent . " AND + previous_item_id = 0"; + + $result = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $tmp_previous = 0; + $next = $row['id']; + $display_order = 0; + } + else + { + $previous = (int) $previous; + + $sql = " + SELECT + id, + previous_item_id, + next_item_id, + display_order + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->get_id() . " AND + id = " . $previous; + + $result = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $tmp_previous = $row['id']; + $next = $row['next_item_id']; + + $display_order = $row['display_order']; + } + } + else + { + $tmp_previous = 0; + $next = 0; + $display_order = 0; + } + + $new_item_id = -1; + $id = $this->escape_string($id); + + //insert new item + $sql_ins = " + INSERT INTO " . $tbl_lp_item . " ( + lp_id, + item_type, + ref, + title, + description, + path, + parent_item_id, + previous_item_id, + next_item_id, + display_order + ) VALUES ( + " . $this->get_id() . ", + '" . $type . "', + '', + '" . $this->escape_string(htmlentities($title)) . "', + '" . $this->escape_string(htmlentities($description)) . "', + '" . $id . "', + " . $parent . ", + " . $previous . ", + " . $next . ", + " . ($display_order + 1) . " + )"; + + //echo $sql_ins; // for debug + + if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);} + + $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__); + + if($res_ins > 0) + { + $new_item_id = Database::get_last_insert_id($res_ins); + + //update the item that should come after the new item + $sql_update_next = " + UPDATE " . $tbl_lp_item . " + SET previous_item_id = " . $new_item_id . " + WHERE id = " . $next; + + $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__); + + //update the item that should be before the new item + $sql_update_previous = " + UPDATE " . $tbl_lp_item . " + SET next_item_id = " . $new_item_id . " + WHERE id = " . $tmp_previous; + + $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__); + + //update all the items after the new item + $sql_update_order = " + UPDATE " . $tbl_lp_item . " + SET display_order = display_order + 1 + WHERE + lp_id = " . $this->get_id() . " AND + id <> " . $new_item_id . " AND + parent_item_id = " . $parent . " AND + display_order > " . $display_order; + + $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__); + } + + return $new_item_id; + } + + + /** + * Adds an item to the current learnpath + * @param integer Parent ID + * @param integer Previous elem ID (0 if first) + * @param string Resource type to add ('file','dokeos_item') + * @param string Resource ID or path if 'file' or name if 'dokeos_chapter' + * @return integer New element ID + */ + function old_add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title) + { + //TODO + if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);} + + $tbl_lp_item = Database::get_course_table('lp_item'); + $parent = (int) $parent; + $display_order = 1; + + if($previous == -1){ + //insert in latest position available + $sql_check = "SELECT MAX(previous_item_id) as prev, id FROM $tbl_lp_item WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent; + + if($this->debug>1){error_log('New LP - checking for latest item at this level: '.$sql_check,0);} + + $res = mysql_query($sql_check) or die(mysql_error()); + + $res_check = api_sql_query($sql_check, __FILE__, __LINE__); + $num = Database::num_rows($res_check); + + if($num>0){ + $row = Database::fetch_array($res_check); + $previous = $row['id']; + }else{ + $previous = 0; + } + }else{ + $previous = (int) $previous; + } + + $new_item_id = -1; + //check type + switch ($type){ + case 'dokeos_step': + $id = $this->escape_string($id); + //check the next item + $sql_check = "SELECT * FROM $tbl_lp_item " . + "WHERE lp_id = ".$this->get_id()." " . + "AND previous_item_id = $previous " . + "AND parent_item_id = $parent"; + if($this->debug>2){error_log('New LP - Getting info from the next element: '.$sql_check,0);} + $res_check = api_sql_query($sql_check); + if(Database::num_rows($res_check)){ + $row = Database::fetch_array($res_check); + $next = $row['id']; + //TODO check display_order + $display_order = $row['display_order']+1; + }else{ + $next = 0; + $display_order = 1; + } + + //insert new item + $sql_ins = "INSERT INTO $tbl_lp_item " . + "(lp_id,item_type,ref,title," . + "path,parent_item_id," . + "previous_item_id,next_item_id,display_order)" . + "VALUES" . + "(".$this->get_id().",'$type','','$title','$id'," . + "$parent," . + "$previous,$next,$display_order)"; + if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);} + $res_ins = api_sql_query($sql_ins); + if($res_ins>0){ + $new_item_id = Database::get_last_insert_id($res_ins); + //now update previous item + $sql_upd = "UPDATE $tbl_lp_item " . + "SET next_item_id = $new_item_id " . + "WHERE lp_id = ".$this->get_id()." " . + "AND id = $previous AND parent_item_id = $parent"; + + if($this->debug>2){error_log('New LP - Updating previous item: '.$sql_upd,0);} + + $res_upd = api_sql_query($sql_upd); + + //now update next item + + $sql_upd = "UPDATE $tbl_lp_item " . + + "SET previous_item_id = $new_item_id " . + + "WHERE lp_id = ".$this->get_id()." " . + + "AND id = $next AND parent_item_id = $parent"; + + if($this->debug>2){error_log('New LP - Updating next item: '.$sql_upd,0);} + + $res_upd = api_sql_query($sql_upd); + + } + + break; + + default: + + break; + + } + + return $new_item_id; + + } + + /** + + * Static admin function allowing addition of a learnpath to a course. + + * @param string Course code + + * @param string Learnpath name + + * @param string Learnpath description string, if provided + + * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) + + * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) + + * @param string Zip file containing the learnpath or directory containing the learnpath + + * @return integer The new learnpath ID on success, 0 on failure + + */ + + function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='') + + { + + //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);} + + //TODO + + $tbl_lp = Database::get_course_table('lp'); + + //check course code exists + + //check lp_name doesn't exist, otherwise append something + + $i = 0; + + $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities() + + $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'"; + + //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);} + + $res_name = api_sql_query($check_name); + + while(Database::num_rows($res_name)){ + + //there is already one such name, update the current one a bit + + $i++; + + $name = $name.' - '.$i; + + $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'"; + + //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);} + + $res_name = api_sql_query($check_name); + + } + + //new name does not exist yet; keep it + + //escape description + + $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities() + + $type = 1; + + switch($learnpath){ + + case 'guess': + + break; + + case 'dokeos': + + $type = 1; + + break; + + case 'aicc': + + break; + + } + + switch($origin){ + + case 'zip': + + //check zipname string. If empty, we are currently creating a new Dokeos learnpath + + break; + + case 'manual': + + $get_max = "SELECT MAX(display_order) FROM $tbl_lp"; + + $res_max = api_sql_query($get_max); + + if(Database::num_rows($res_max)<1){ + + $dsp = 1; + + }else{ + + $row = Database::fetch_array($res_max); + + $dsp = $row[0]+1; + + } + + $sql_insert = "INSERT INTO $tbl_lp " . + + "(lp_type,name,description,path,default_view_mod," . + + "default_encoding,display_order,content_maker," . + + "content_local,js_lib) " . + + "VALUES ($type,'$name','$description','','embedded'," . + + "'ISO-8859-1','$dsp','Dokeos'," . + + "'local','')"; + + //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);} + + $res_insert = api_sql_query($sql_insert); + + $id = Database::get_last_insert_id(); + + if($id>0){ + + return $id; + + } + + break; + + } + + } + + /** + + * Appends a message to the message attribute + + * @param string Message to append. + + */ + + function append_message($string) + + { + + if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);} + + $this->message .= $string; + + } + + /** + + * Autocompletes the parents of an item in case it's been completed or passed + + * @param integer Optional ID of the item from which to look for parents + + */ + + function autocomplete_parents($item) + + { + + if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);} + + if(empty($item)){ + + $item = $this->current; + + } + + $parent_id = $this->items[$item]->get_parent(); + + if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);} + + if(is_object($this->items[$item]) and !empty($parent_id)) + + {//if $item points to an object and there is a parent + + if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);} + + $current_item =& $this->items[$item]; + + $parent =& $this->items[$parent_id]; //get the parent + + //new experiment including failed and browsed in completed status + $current_status = $current_item->get_status(); + if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed'){ + + //if the current item is completed or passes or succeeded + + $completed = true; + + if($this->debug>2){error_log('New LP - Status of current item is alright',0);} + + foreach($parent->get_children() as $child){ + + //check all his brothers (his parent's children) for completion status + + if($child!= $item){ + + if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);} + + //if($this->items[$child]->status_is(array('completed','passed','succeeded'))) + //Trying completing parents of failed and browsed items as well + if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed'))) + { + + //keep completion status to true + + }else{ + + if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);} + + $completed = false; + + } + + } + + } + + if($completed == true){ //if all the children were completed + + $parent->set_status('completed'); + + $parent->save(false); + + $this->update_queue[$parent->get_id()] = $parent->get_status(); + + if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);} + + $this->autocomplete_parents($parent->get_id()); //recursive call + + } + + }else{ + + //error_log('New LP - status of current item is not enough to get bothered',0); + + } + + } + + } + + /** + + * Autosaves the current results into the database for the whole learnpath + + */ + + function autosave() + + { + + if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);} + + //TODO add aditionnal save operations for the learnpath itself + + } + + /** + + * Clears the message attribute + + */ + + function clear_message() + + { + + if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);} + + $this->message = ''; + + } + + /** + + * Closes the current resource + + * + + * Stops the timer + + * Saves into the database if required + + * Clears the current resource data from this object + + * @return boolean True on success, false on failure + + */ + + function close() + + { + + if($this->debug>0){error_log('New LP - In learnpath::close()',0);} + + if(empty($this->lp_id)) + + { + + $this->error = 'Trying to close this learnpath but no ID is set'; + + return false; + + } + + $this->current_time_stop = time(); + + if($this->save) + + { + + $learnpath_view_table = Database::get_course_table(LEARNPATH_VIEW_TABLE); + + /* + + $sql = "UPDATE $learnpath_view_table " . + + "SET " . + + "stop_time = ".$this->current_time_stop.", " . + + "score = ".$this->current_score.", ". + + "WHERE learnpath_id = '".$this->lp_id."'"; + + //$res = Database::query($sql); + + $res = api_sql_query($res); + + if(mysql_affected_rows($res)<1) + + { + + $this->error = 'Could not update learnpath_view table while closing learnpath'; + + return false; + + } + + */ + + } + + $this->ordered_items = array(); + + $this->index=0; + + unset($this->lp_id); + + //unset other stuff + + return true; + + } + + /** + + * Static admin function allowing removal of a learnpath + + * @param string Course code + + * @param integer Learnpath ID + + * @param string Whether to delete data or keep it (default: 'keep', others: 'remove') + + * @return boolean True on success, false on failure (might change that to return number of elements deleted) + + */ + + function delete($course=null,$id=null,$delete='keep') + + { + + //TODO implement a way of getting this to work when the current object is not set + + //In clear: implement this in the item class as well (abstract class) and use the given ID in queries + + //if(empty($course)){$course = api_get_course_id();} + + //if(empty($id)){$id = $this->get_id();} + + + + //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);} + + foreach($this->items as $id => $dummy) + + { + + $this->items[$id]->delete(); + + } + + $lp = Database::get_course_table('lp'); + + $lp_view = Database::get_course_table('lp_view'); + + $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id; + + //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);} + + $res_del_view = api_sql_query($sql_del_view); + + //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);} + + if($this->type == 2 OR $this->type==3){ + //this is a scorm learning path, delete the files as well + $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id; + $res = api_sql_query($sql); + if(Database::num_rows($res)>0){ + $row = Database::fetch_array($res); + $path = $row['path']; + $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id; + $res = api_sql_query($sql); + if(Database::num_rows($res)>0) + { //another learning path uses this directory, so don't delete it + if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);} + }else{ + //no other LP uses that directory, delete it + $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses + $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course + if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){ + if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);} + exec('rm -rf '.$course_scorm_dir.$path); + } + } + } + } + $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id; + //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);} + $res_del_lp = api_sql_query($sql_del_lp); + //TODO: also delete items and item-views + } + + /** + + * Removes all the children of one item - dangerous! + + * @param integer Element ID of which children have to be removed + + * @return integer Total number of children removed + + */ + + function delete_children_items($id){ + + if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);} + + $num = 0; + + if(empty($id) || $id != strval(intval($id))){return false;} + + $lp_item = Database::get_course_table('lp_item'); + + $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id"; + + $res = api_sql_query($sql); + + while($row = Database::fetch_array($res)){ + + $num += $this->delete_children_items($row['id']); + + $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id']; + + $res_del = api_sql_query($sql_del); + + $num++; + + } + + return $num; + + } + + /** + + * Removes an item from the current learnpath + + * @param integer Elem ID (0 if first) + + * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove') + + * @return integer Number of elements moved + + * @todo implement resource removal + + */ + + function delete_item($id, $remove='keep') + + { + + if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);} + + //TODO - implement the resource removal + + if(empty($id) || $id != strval(intval($id))){return false;} + + //first select item to get previous, next, and display order + + $lp_item = Database::get_course_table('lp_item'); + + $sql_sel = "SELECT * FROM $lp_item WHERE id = $id"; + + $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__); + + if(Database::num_rows($res_sel)<1){return false;} + + $row = Database::fetch_array($res_sel); + + $previous = $row['previous_item_id']; + + $next = $row['next_item_id']; + + $display = $row['display_order']; + + $parent = $row['parent_item_id']; + + $lp = $row['lp_id']; + + //delete children items + + $num = $this->delete_children_items($id); + + if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);} + + //now delete the item + + $sql_del = "DELETE FROM $lp_item WHERE id = $id"; + + if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);} + + $res_del = api_sql_query($sql_del,__FILE__,__LINE__); + + //now update surrounding items + + $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous"; + + $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__); + + $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next"; + + $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__); + + //now update all following items with new display order + + $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display"; + + $res_all = api_sql_query($sql_all,__FILE__,__LINE__); + + } + + /** + + * Updates an item's content in place + + * @param integer Element ID + + * @param string New content + + * @return boolean True on success, false on error + + */ + + function old_edit_item($id,$content) + + { + + if($this->debug>0){error_log('New LP - In learnpath::edit_item()',0);} + + if(empty($id) or ($id != strval(intval($id))) or empty($content)){ return false; } + + $content = $this->escape_string($content); + + $lp_item = Database::get_course_table('lp_item'); + + $sql_upd = "UPDATE $lp_item SET title = '$content' WHERE id = $id"; + + $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__); + + //TODO update the item object (can be ignored for now because refreshed) + + return true; + + } + + function edit_item($id, $parent, $previous, $title, $description) + { + if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);} + + if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; } + + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql_select = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE id = " . $id; + $res_select = api_sql_query($sql_select, __FILE__, __LINE__); + $row_select = Database::fetch_array($res_select); + + $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false; + $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false; + + if($same_parent && $same_previous) + { + //only update title and description + $sql_update = " + UPDATE " . $tbl_lp_item . " + SET + title = '" . $this->escape_string(htmlentities($title)) . "', + description = '" . $this->escape_string(htmlentities($description)) . "' + WHERE id = " . $id; + $res_update = api_sql_query($sql_update, __FILE__, __LINE__); + } + else + { + $old_parent = $row_select['parent_item_id']; + $old_previous = $row_select['previous_item_id']; + $old_next = $row_select['next_item_id']; + $old_order = $row_select['display_order']; + + /* BEGIN -- virtually remove the current item id */ + /* for the next and previous item it is like the current item doesn't exist anymore */ + + if($old_previous != 0) + { + $sql_update_next = " + UPDATE " . $tbl_lp_item . " + SET next_item_id = " . $old_next . " + WHERE id = " . $old_previous; + $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__); + + //echo '

    ' . $sql_update_next . '

    '; + } + + if($old_next != 0) + { + $sql_update_previous = " + UPDATE " . $tbl_lp_item . " + SET previous_item_id = " . $old_previous . " + WHERE id = " . $old_next; + $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__); + + //echo '

    ' . $sql_update_previous . '

    '; + } + + //display_order - 1 for every item with a display_order bigger then the display_order of the current item + $sql_update_order = " + UPDATE " . $tbl_lp_item . " + SET display_order = display_order - 1 + WHERE + display_order > " . $old_order . " AND + parent_item_id = " . $old_parent; + $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__); + + //echo '

    ' . $sql_update_order . '

    '; + + /* END -- virtually remove the current item id */ + + /* BEGIN -- update the current item id to his new location */ + + if($previous == 0) + { + //select the data of the item that should come after the current item + $sql_select_old = " + SELECT + id, + display_order + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id . " AND + parent_item_id = " . $parent . " AND + previous_item_id = " . $previous; + $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__); + $row_select_old = Database::fetch_array($res_select_old); + + //echo '

    ' . $sql_select_old . '

    '; + + //if the new parent doesn't had children before + if(Database::num_rows($res_select_old) == 0) + { + $new_next = 0; + $new_order = 1; + } + else + { + $new_next = $row_select_old['id']; + $new_order = $row_select_old['display_order']; + } + + //echo 'New next_item_id of current item: ' . $new_next . '
    '; + //echo 'New previous_item_id of current item: ' . $previous . '
    '; + //echo 'New display_order of current item: ' . $new_order . '
    '; + + + } + else + { + //select the data of the item that should come before the current item + $sql_select_old = " + SELECT + next_item_id, + display_order + FROM " . $tbl_lp_item . " + WHERE id = " . $previous; + $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__); + $row_select_old = Database::fetch_array($res_select_old); + + //echo '

    ' . $sql_select_old . '

    '; + + //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '
    '; + //echo 'New previous_item_id of current item: ' . $previous . '
    '; + //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '
    '; + + $new_next = $row_select_old['next_item_id']; + $new_order = $row_select_old['display_order'] + 1; + } + + //update the current item with the new data + $sql_update = " + UPDATE " . $tbl_lp_item . " + SET + title = '" . $this->escape_string(htmlentities($title)) . "', + description = '" . $this->escape_string(htmlentities($description)) . "', + parent_item_id = " . $parent . ", + previous_item_id = " . $previous . ", + next_item_id = " . $new_next . ", + display_order = " . $new_order . " + WHERE id = " . $id; + $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__); + //echo '

    ' . $sql_update . '

    '; + + if($previous != 0) + { + //update the previous item his next_item_id + $sql_update_previous = " + UPDATE " . $tbl_lp_item . " + SET next_item_id = " . $id . " + WHERE id = " . $previous; + $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__); + //echo '

    ' . $sql_update_previous . '

    '; + } + + if($new_next != 0) + { + //update the next item his previous_item_id + $sql_update_next = " + UPDATE " . $tbl_lp_item . " + SET previous_item_id = " . $id . " + WHERE id = " . $new_next; + $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__); + //echo '

    ' . $sql_update_next . '

    '; + } + + //update all the items with the same or a bigger display_order then the current item + $sql_update_order = " + UPDATE " . $tbl_lp_item . " + SET display_order = display_order + 1 + WHERE + lp_id = " . $this->get_id() . " AND + id <> " . $id . " AND + parent_item_id = " . $parent . " AND + display_order >= " . $new_order; + + $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__); + //echo '

    ' . $sql_update_order . '

    '; + + /* END -- update the current item id to his new location */ + } + } + + /** + + * Updates an item's prereq in place + + * @param integer Element ID + + * @param string Prerequisite Element ID + * + * @param string Prerequisite item type + * + * @param string Prerequisite min score + * + * @param string Prerequisite max score + + * @return boolean True on success, false on error + + */ + + function edit_item_prereq($id, $prerequisite_id, $min_score = 0, $max_score = 100) + + { + + if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq()',0);} + + if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; } + + $prerequisite_id = $this->escape_string($prerequisite_id); + + $tbl_lp_item = Database::get_course_table('lp_item'); + + if(!is_numeric($min_score) || $min_score < 0 || $min_score > 100) + $min_score = 0; + + if(!is_numeric($max_score) || $max_score < 0 || $max_score > 100) + $max_score = 100; + + if($min_score > $max_score) + $max_score = $min_score; + + if(!is_numeric($prerequisite_id)) + $prerequisite_id = 'NULL'; + + $sql_upd = " + UPDATE " . $tbl_lp_item . " + SET + min_score = " . $min_score . ", + max_score = " . $max_score . ", + prerequisite = " . $prerequisite_id . " + WHERE id = " . $id; + + $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__); + + //TODO update the item object (can be ignored for now because refreshed) + + return true; + + } + + /** + + * Escapes a string with the available database escape function + + * @param string String to escape + + * @return string String escaped + + */ + + function escape_string($string){ + + //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);} + + return mysql_real_escape_string($string); + + } + + /** + + * Static admin function exporting a learnpath into a zip file + + * @param string Export type (scorm, zip, cd) + + * @param string Course code + + * @param integer Learnpath ID + + * @param string Zip file name + + * @return string Zip file path (or false on error) + + */ + + function export_lp($type, $course, $id, $zipname) + + { + + //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);} + + //TODO + + if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;} + + $url = ''; + + switch($type){ + + case 'scorm': + + break; + + case 'zip': + + break; + + case 'cdrom': + + break; + + } + + return $url; + + } + + /** + + * Gets all the chapters belonging to the same parent as the item/chapter given + + * Can also be called as abstract method + + * @param integer Item ID + + * @return array A list of all the "brother items" (or an empty array on failure) + + */ + + function get_brother_chapters($id){ + + if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);} + + if(empty($id) OR $id != strval(intval($id))){ return array();} + + $lp_item = Database::get_course_table('lp_item'); + + $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'"; + + $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__); + + if(Database::num_rows($res_parent)>0){ + + $row_parent = Database::fetch_array($res_parent); + + $parent = $row_parent['parent_item_id']; + + $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order"; + + $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__); + + $list = array(); + + while ($row_bro = Database::fetch_array($res_bros)){ + + $list[] = $row_bro; + + } + + return $list; + + } + + return array(); + + } + + /** + + * Gets all the items belonging to the same parent as the item given + + * Can also be called as abstract method + + * @param integer Item ID + + * @return array A list of all the "brother items" (or an empty array on failure) + + */ + + function get_brother_items($id){ + + if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);} + + if(empty($id) OR $id != strval(intval($id))){ return array();} + + $lp_item = Database::get_course_table('lp_item'); + + $sql_parent = "SELECT * FROM $lp_item WHERE id = $id"; + + $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__); + + if(Database::num_rows($res_parent)>0){ + + $row_parent = Database::fetch_array($res_parent); + + $parent = $row_parent['parent_item_id']; + + $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order"; + + $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__); + + $list = array(); + + while ($row_bro = Database::fetch_array($res_bros)){ + + $list[] = $row_bro; + + } + + return $list; + + } + + return array(); + + } + + /** + + * Gets the number of items currently completed + + * @return integer The number of items currently completed + + */ + + function get_complete_items_count() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);} + + $i = 0; + + foreach($this->items as $id => $dummy){ + + //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){ + //Trying failed and browsed considered "progressed" as well + if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))){ + + $i++; + + } + + } + + return $i; + + } + + /** + * Gets the current item ID + * @return integer The current learnpath item id + */ + function get_current_item_id() + { + $current = 0; + if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);} + if(!empty($this->current)) + { + $current = $this->current; + } + if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);} + return $current; + } + /** + * Gets the total number of items available for viewing in this SCORM + * @return integer The total number of items + */ + function get_total_items_count() + { + if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);} + return count($this->items); + } + /** + * Gets the first element URL. + * @return string URL to load into the viewer + */ + function first() + { + if($this->debug>0){error_log('New LP - In learnpath::first()',0);} + //test if the last_item_seen exists and is not a dir + if(!empty($this->last_item_seen) + && !empty($this->items[$this->last_item_seen]) + && $this->items[$this->last_item_seen]->get_type() != 'dir' + && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' + && $this->items[$this->last_item_seen]->is_done() != true + ){ + if($this->debug>2){error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(),0);} + $index = -1; + foreach($this->ordered_items as $myindex => $item_id){ + if($item_id == $this->last_item_seen){ + $index = $myindex; + break; + } + } + if($index==-1){ + //index hasn't changed, so item not found - panic (this shouldn't happen) + if($this->debug>2){error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!',0);} + return false; + }else{ + $this->last = $this->last_item_seen; + $this->current = $this->last_item_seen; + $this->index = $index; + } + }else{ + if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);} + $index = 0; + while (!empty($this->ordered_items[$index]) + AND + ( + $this->items[$this->ordered_items[$index]]->get_type() == 'dir' + OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' + OR $this->items[$this->ordered_items[$index]]->is_done() === true + ) + AND $index < $this->max_ordered_items) + { + $index ++; + } + $this->last = $this->current; + //current is + $this->current = $this->ordered_items[$index]; + $this->index = $index; + if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);} + } + if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());} + } + + /** + + * Gets the information about an item in a format usable as JavaScript to update + + * the JS API by just printing this content into the section of the message frame + + * @param integer Item ID + + * @return string + + */ + + function get_js_info($item_id=''){ + + if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);} + + $info = ''; + + $item_id = $this->escape_string($item_id); + + if(!empty($item_id) && is_object($this->items[$item_id])){ + + //if item is defined, return values from DB + + $oItem = $this->items[$item_id]; + + $info .= ''; + + if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);} + + return $info; + + }else{ + + //if item_id is empty, just update to default SCORM data + + $info .= ''; + + if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);} + + return $info; + + } + + } + /** + * Gets the js library from the database + * @return string The name of the javascript library to be used + */ + function get_js_lib(){ + $lib = ''; + if(!empty($this->js_lib)){ + $lib = $this->js_lib; + } + return $lib; + } + /** + + * Gets the learnpath database ID + + * @return integer Learnpath ID in the lp table + + */ + + function get_id() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);} + + if(!empty($this->lp_id)) + + { + + return $this->lp_id; + + }else{ + + return 0; + + } + + } + + /** + + * Gets the last element URL. + + * @return string URL to load into the viewer + + */ + + function get_last() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);} + + $this->index = count($this->ordered_items)-1; + + return $this->ordered_items[$this->index]; + + } + + /** + + * Gets the navigation bar for the learnpath display screen + + * @return string The HTML string to use as a navigation bar + + */ + + function get_navigation_bar() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);} + + //TODO find a good value for the following variables + + $file = ''; + + $openDir = ''; + + $edoceo = ''; + + $time = 0; + + $navbar = ''; + + $RequestUri = ''; + + $mycurrentitemid = $this->get_current_item_id(); + + if($this->mode == 'fullscreen'){ + + $navbar = ''."\n". + + ' '."\n" . + + ' '."\n" . + + ' '."\n" . + + '
    '."\n" . + + '
    '."\n" . + + '  '."\n" . + + '  '."\n" . + + ' '."\n" . + + ' '."\n" . + + '
    '."\n" . + + '
    '."\n" ; + + + + }else{ + + $navbar = ''."\n". + + ' '."\n" . + + ' '."\n" . + + ' '."\n" . + + '
    '."\n" . + + '
    '."\n" . + + '  '."\n" . + + '  '."\n" . + + '  '."\n" . + + ' '."\n" . + + '
    '."\n" . + + '
    '."\n" ; + + } + + return $navbar; + + } + + /** + + * Gets the next resource in queue (url). + + * @return string URL to load into the viewer + + */ + + function get_next_index() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);} + + //TODO + + $index = $this->index; + + $index ++; + + if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]['type'],0);} + + while(!empty($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir' AND $index < $this->max_ordered_items) + + { + + $index ++; + + if($index == $this->max_ordered_items) + + { + + return $this->index; + + } + + } + + if(empty($this->ordered_items[$index])){ + + return $this->index; + + } + + if($this->debug>2){error_log('New LP - index is now '.$index,0);} + + return $index; + + } + + /** + + * Gets item_id for the next element + + * @return integer Next item (DB) ID + + */ + + function get_next_item_id() + + { + + $new_index = $this->get_next_index(); + + return $this->ordered_items[$new_index]; + + } + /** + * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...) + * + * Generally, the package provided is in the form of a zip file, so the function + * has been written to test a zip file. If not a zip, the function will return the + * default return value: '' + * @param string the path to the file + * @param string the original name of the file + * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized + */ + function get_package_type($file_path,$file_name){ + //error_log('In learnpath::get_package_type("'.$file_path.'","'.$file_name.'")',0); + + //get name of the zip file without the extension + $file_info = pathinfo($file_name); + $filename = $file_info['basename'];//name including extension + $extension = $file_info['extension'];//extension only + + if(in_array($extension,array('ppt','odp'))) + { + return 'ppt'; + } + + $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension + + $zipFile = new pclZip($file_path); + // Check the zip content (real size and file extension) + $zipContentArray = $zipFile->listContent(); + $package_type=''; + $at_root = false; + $manifest = ''; + + //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?) + foreach($zipContentArray as $thisContent) + { + if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) ) + { + return ''; + } + elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE) + { + $manifest = $thisContent['filename']; //just the relative directory inside scorm/ + $package_type = 'scorm'; + break;//exit the foreach loop + } + elseif(stristr($thisContent['filename'],'AICC')!==FALSE) + { + $package_type='aicc'; + break;//exit the foreach loop + } + else + { + $package_type = ''; + } + } + return $package_type; + } + /** + + * Gets the previous resource in queue (url). Also initialises time values for this viewing + + * @return string URL to load into the viewer + + */ + + function get_previous_index() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);} + + $index = $this->index; + + if(isset($this->ordered_items[$index-1])){ + + $index --; + + while(isset($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir') + + { + + $index --; + + if($index < 0){ + + return $this->index; + + } + + } + + }else{ + + if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);} + + //no previous item + + } + + return $index; + + } + + /** + + * Gets item_id for the next element + + * @return integer Previous item (DB) ID + + */ + + function get_previous_item_id() + + { + + $new_index = $this->get_previous_index(); + + return $this->ordered_items[$new_index]; + + } + + /** + + * Gets the progress value from the progress_db attribute + + * @return integer Current progress value + + */ + + function get_progress(){ + + if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);} + + if(!empty($this->progress_db)){ + + return $this->progress_db; + + } + + return 0; + + } + /** + * Gets the progress value from the progress field in the database (allows use as abstract method) + * @param integer Learnpath ID + * @param integer User ID + * @param string Mode of display ('%','abs' or 'both') + * @return integer Current progress value as found in the database + */ + function get_db_progress($lp_id,$user_id,$mode='%'){ + //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);} + $table = Database::get_course_table('lp_view'); + $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id"; + $res = api_sql_query($sql,__FILE__,__LINE__); + $view_id = 0; + if(Database::num_rows($res)>0){ + $row = Database::fetch_array($res); + $progress = $row['progress']; + $view_id = $row['id']; + } + if(!$progress){ + $progress = '0'; + } + if($mode == '%'){ + return $progress.'%'; + }else{ + //get the number of items completed and the number of items total + $tbl = Database::get_course_table('lp_item'); + $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id; + $res = api_sql_query($sql); + $row = Database::fetch_array($res); + $total = $row[0]; + $tbl = Database::get_course_table('lp_item_view'); + //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')"; + //trying as also counting browsed and failed items + $sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded','browsed','failed')"; + $res = api_sql_query($sql); + $row = Database::fetch_array($res); + $completed = $row[0]; + if($mode == 'abs'){ + return $completed.'/'.$total; + } + elseif($mode == 'both') + { + if($progress<($completed/($total?$total:1))){ + $progress = number_format(($completed/($total?$total:1))*100,0); + } + return $progress.'% ('.$completed.'/'.$total.')'; + } + } + return $progress; + } + + /** + + * Gets a progress bar for the learnpath by counting the number of items in it and the number of items + + * completed so far. + + * @param string Mode in which we want the values + + * @param integer Progress value to display (optional but mandatory if used in abstract context) + + * @param string Text to display near the progress value (optional but mandatory in abstract context) + + * @return string HTML string containing the progress bar + + */ + + function get_progress_bar($mode='',$percentage=-1,$text_add='') + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);} + + if($percentage=='-1' OR $text_add==''){ + + list ($percentage, $text_add) = $this->get_progress_bar_text($mode); + + } + + $text = $percentage.$text_add; + + $output = '' + + //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."
    " + + .'
    ' + + .'' + + .'' + + .''; + + if($percentage <= 98){ + + $output .= ''; + + }else{ + + $output .= ''; + + } + + $output .= '
    ' + + .'
    '.$text.'
    '; + + return $output; + + } + + /** + + * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php + + * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements + + * //@param integer Additional steps to fake as completed + + * @return list Percentage or number and symbol (% or /xx) + + */ + + function get_progress_bar_text($mode='',$add=0) + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);} + + if(empty($mode)){$mode = $this->progress_bar_mode;} + + $total_items = $this->get_total_items_count(); + + if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);} + + $i = $this->get_complete_items_count(); + + if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);} + + if($add != 0){ + + $i += $add; + + if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);} + + } + + $text = ''; + + if($i>$total_items){ + + $i = $total_items; + + } + + if($mode == '%'){ + + $percentage = ((float)$i/(float)$total_items)*100; + + $percentage = number_format($percentage,0); + + $text = '%'; + + }elseif($mode == 'abs'){ + + $percentage = $i; + + $text = '/'.$total_items; + + } + + return array($percentage,$text); + + } + + /** + + * Gets the progress bar mode + + * @return string The progress bar mode attribute + + */ + + function get_progress_bar_mode() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);} + + if(!empty($this->progress_bar_mode)) + + { + + return $this->progress_bar_mode; + + }else{ + + return '%'; + + } + + } + + + + /** + + * Returns a usable array of stats related to the current learnpath and user + + * @return array Well-formatted array containing status for the current learnpath + + */ + + function get_stats() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);} + + //TODO + + } + + /** + + * Static method. Can be re-implemented by children. Gives an array of statistics for + + * the given course (for all learnpaths and all users) + + * @param string Course code + + * @return array Well-formatted array containing status for the course's learnpaths + + */ + + function get_stats_course($course) + + { + + //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);} + + //TODO + + } + + /** + + * Static method. Can be re-implemented by children. Gives an array of statistics for + + * the given course and learnpath (for all users) + + * @param string Course code + + * @param integer Learnpath ID + + * @return array Well-formatted array containing status for the specified learnpath + + */ + + function get_stats_lp($course,$lp) + + { + + //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);} + + //TODO + + } + + /** + + * Static method. Can be re-implemented by children. Gives an array of statistics for + + * the given course, learnpath and user. + + * @param string Course code + + * @param integer Learnpath ID + + * @param integer User ID + + * @return array Well-formatted array containing status for the specified learnpath and user + + */ + + function get_stats_lp_user($course,$lp,$user) + + { + + //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);} + + //TODO + + } + + /** + + * Static method. Can be re-implemented by children. Gives an array of statistics for + + * the given course and learnpath (for all users) + + * @param string Course code + + * @param integer User ID + + * @return array Well-formatted array containing status for the user's learnpaths + + */ + + function get_stats_user($course,$user) + + { + + //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);} + + //TODO + + } + + /** + + * Gets the status list for all LP's items + + * @return array Array of [index] => [item ID => current status] + + */ + + function get_items_status_list(){ + + if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);} + + $list = array(); + + foreach($this->ordered_items as $item_id) + + { + + $list[]= array($item_id => $this->items[$item_id]->get_status()); + + } + + return $list; + + } + /** + * Generate and return the table of contents for this learnpath. The (flat) table returned can be + * used by get_html_toc() to be ready to display + * @return array TOC as a table with 4 elements per row: title, link, status and level + */ + function get_toc() + { + if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);} + $toc = array(); + //echo "
    ".print_r($this->items,true)."
    "; + foreach($this->ordered_items as $item_id) + { + if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);} + //TODO change this link generation and use new function instead + $toc[] = array( + 'id'=>$item_id, + 'title'=>$this->items[$item_id]->get_title(), + //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1), + 'status'=>$this->items[$item_id]->get_status(), + 'level'=>$this->items[$item_id]->get_level(), + 'type' =>$this->items[$item_id]->get_type(), + ); + } + if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);} + return $toc; + } + /** + * Gets the learning path type + * @param boolean Return the name? If false, return the ID. Default is false. + * @return mixed Type ID or name, depending on the parameter + */ + function get_type($get_name = false) + { + $res = false; + if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);} + if(!empty($this->type)) + { + if($get_name) + { + //get it from the lp_type table in main db + }else{ + $res = $this->type; + } + } + if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);} + return $res; + } + + /** + * Gets a flat list of item IDs ordered for display (level by level ordered by order_display) + * This method can be used as abstract and is recursive + * @param integer Learnpath ID + * @param integer Parent ID of the items to look for + * @return mixed Ordered list of item IDs or false on error + */ + function get_flat_ordered_items_list($lp,$parent=0){ + if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);} + $list = array(); + if(empty($lp)){return false;} + $tbl_lp_item = Database::get_course_table('lp_item'); + $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order"; + $res = api_sql_query($sql,__FILE__,__LINE__); + while($row = Database::fetch_array($res)){ + $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']); + $list[] = $row['id']; + foreach($sublist as $item){ + $list[] = $item; + } + } + return $list; + } + /** + * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display + * @return string HTML TOC ready to display + */ + function get_html_toc() + { + if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);} + $list = $this->get_toc(); + //echo $this->current; + //$parent = $this->items[$this->current]->get_parent(); + //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];} + $html = '
    '."\n" ; + // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n"; + require_once('resourcelinker.inc.php'); + + //temp variables + $mycurrentitemid = $this->get_current_item_id(); + + foreach($list as $item) + { + if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);} + //TODO complete this + $icon_name = array('not attempted' => 'notattempted.png', + 'incomplete' => 'incomplete.png', + 'failed' => 'failed.png', + 'completed' => 'completed.png', + 'passed' => 'passed.png', + 'succeeded' => 'succeeded.png', + 'browsed' => 'completed.png'); + + $style = 'scorm_item'; + if($item['id'] == $this->current){ + $style = 'scorm_item_highlight'; + } + //the anchor will let us center the TOC on the currently viewed item &^D + $html .= '\n"; + } + $html .= "
    \n"; + return $html; + } + /** + * Gets the user-friendly message stored in $this->message + * @return string Message + */ + function get_message(){ + + if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);} + return $this->message; + } + /** + * Gets the learnpath name/title + * @return string Learnpath name/title + */ + function get_name() + { + if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);} + if(!empty($this->name)){return $this->name;}else{return 'N/A';} + } + /** + * Gets a link to the resource from the present location, depending on item ID. + * @param string Type of link expected + * @param integer Learnpath item ID + * @return string Link to the lp_item resource + */ + function get_link($type='http',$item_id=null) + { + if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);} + if(empty($item_id)) + { + if($this->debug>2){error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: '.$this->get_current_item_id(),0);} + $item_id = $this->get_current_item_id(); + } + + if(empty($item_id)){ + if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);} + //still empty, this means there was no item_id given and we are not in an object context or + //the object property is empty, return empty link + $item_id = $this->first(); + return ''; + } + + $file = ''; + $lp_db = Database::get_current_course_database(); + $lp_pref = Database::get_course_table_prefix(); + $lp_table = $lp_db.'.'.$lp_pref.'lp'; + $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item'; + $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath " . + "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id"; + if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);} + $res = api_sql_query($sel); + if(Database::num_rows($res)>0) + { + $row = Database::fetch_array($res); + //var_dump($row); + $lp_type = $row['ltype']; + $lp_path = $row['lpath']; + $lp_item_type = $row['litype']; + $lp_item_path = $row['lipath']; + if($type == 'http'){ + $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path + }else{ + $course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); //system path + } + //now go through the specific cases to get the end of the path + switch($lp_type){ + case 1: + if($lp_item_type == 'dokeos_chapter'){ + $file = 'lp_content.php?type=dir'; + }else{ + require_once('resourcelinker.inc.php'); + $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id); + } + break; + case 2: + if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);} + if($lp_item_type!='dir'){ + //Quite complex here: + //we want to make sure 'http://' (and similar) links can + //be loaded as is (withouth the Dokeos path in front) but + //some contents use this form: resource.htm?resource=http://blablabla + //which means we have to find a protocol at the path's start, otherwise + //it should not be considered as an external URL + + //if($this->prerequisites_match($item_id)){ + if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){ + if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);} + //distant url, return as is + $file = $lp_item_path; + }else{ + if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);} + //prevent getting untranslatable urls + $lp_item_path = preg_replace('/%2F/','/',$lp_item_path); + $lp_item_path = preg_replace('/%3A/',':',$lp_item_path); + //prepare the path + $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; + //TODO fix this for urls with protocol header + $file = str_replace('//','/',$file); + $file = str_replace(':/','://',$file); + } + //}else{ + //prerequisites did not match + //$file = 'blank.php'; + //} + }else{ + $file = 'lp_content.php?type=dir'; + } + break; + case 3: + if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);} + //formatting AICC HACP append URL + $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&'; + if($lp_item_type!='dir'){ + //Quite complex here: + //we want to make sure 'http://' (and similar) links can + //be loaded as is (withouth the Dokeos path in front) but + //some contents use this form: resource.htm?resource=http://blablabla + //which means we have to find a protocol at the path's start, otherwise + //it should not be considered as an external URL + + if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){ + if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);} + //distant url, return as is + $file = $lp_item_path; + /* + if(stristr($file,'')!==false){ + $file = str_replace('',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path); + } + */ + $file .= $aicc_append; + }else{ + if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);} + //prevent getting untranslatable urls + $lp_item_path = preg_replace('/%2F/','/',$lp_item_path); + $lp_item_path = preg_replace('/%3A/',':',$lp_item_path); + //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name + $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; + //TODO fix this for urls with protocol header + $file = str_replace('//','/',$file); + $file = str_replace(':/','://',$file); + $file .= $aicc_append; + } + }else{ + $file = 'lp_content.php?type=dir'; + } + + break; + + case 4: + + break; + + default: + + break; + + } + + } + + if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);} + + return $file; + + } + + /** + + * Gets the latest usable view or generate a new one + + * @param integer Optional attempt number. If none given, takes the highest from the lp_view table + + * @return integer DB lp_view id + + */ + + function get_view($attempt_num=0) + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);} + + $search = ''; + + //use $attempt_num to enable multi-views management (disabled so far) + + if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) + + { + + $search = 'AND view_count = '.$attempt_num; + + } + + //when missing $attempt_num, search for a unique lp_view record for this lp and user + + $lp_view_table = Database::get_course_table('lp_view'); + + $sql = "SELECT id, view_count FROM $lp_view_table " . + + "WHERE lp_id = ".$this->get_id()." " . + + "AND user_id = ".$this->get_user_id()." " . + + $search . + + " ORDER BY view_count DESC"; + + $res = api_sql_query($sql); + + if(Database::num_rows($res)>0) + + { + + $row = Database::fetch_array($res); + + $this->lp_view_id = $row['id']; + + }else{ + + //no database record, create one + + $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" . + + "VALUES (".$this->get_id().",".$this->get_user_id().",1)"; + + $res = api_sql_query($sql); + + $id = Database::get_last_insert_id(); + + $this->lp_view_id = $id; + + } + + } + + /** + + * Gets the current view id + + * @return integer View ID (from lp_view) + + */ + + function get_view_id() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);} + + if(!empty($this->lp_view_id)) + + { + + return $this->lp_view_id; + + }else{ + + return 0; + + } + + } + + /** + + * Gets the update queue + + * @return array Array containing IDs of items to be updated by JavaScript + + */ + + function get_update_queue() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);} + + return $this->update_queue; + + } + + /** + + * Gets the user ID + + * @return integer User ID + + */ + + function get_user_id() + + { + + if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);} + + if(!empty($this->user_id)) + + { + + return $this->user_id; + + }else{ + + return false; + + } + + } + + /** + + * Logs a message into a file + + * @param string Message to log + + * @return boolean True on success, false on error or if msg empty + + */ + + function log($msg) + + { + + if($this->debug>0){error_log('New LP - In learnpath::log()',0);} + + //TODO + + $this->error .= $msg."\n"; + + return true; + + } + + /** + + * Moves an item up and down at its level + + * @param integer Item to move up and down + + * @param string Direction 'up' or 'down' + + * @return integer New display order, or false on error + + */ + + function move_item($id, $direction){ + + if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);} + + if(empty($id) or empty($direction)){return false;} + + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql_sel = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE id = " . $id; + $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__); + + //check if elem exists + + if(Database::num_rows($res_sel)<1){return false;} + + //gather data + + $row = Database::fetch_array($res_sel); + + $previous = $row['previous_item_id']; + + $next = $row['next_item_id']; + + $display = $row['display_order']; + + $parent = $row['parent_item_id']; + + $lp = $row['lp_id']; + + //update the item (switch with previous/next one) + + switch($direction) + { + case 'up': + if($this->debug>2){error_log('Movement up detected',0);} + + if($display <= 1){/*do nothing*/} + + else{ + + $sql_sel2 = "SELECT * + FROM $tbl_lp_item + WHERE id = $previous"; + + if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);} + + $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__); + + if(Database::num_rows($res_sel2)<1){$previous_previous = 0;} + + //gather data + + $row2 = Database::fetch_array($res_sel2); + + $previous_previous = $row2['previous_item_id']; + + //update previous_previous item (switch "next" with current) + + if($previous_previous != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_$previous"; + + if($this->debug>2){error_log($sql_upd2,0);} + + $res_upd2 = api_sql_query($sql_upd2); + + } + + //update previous item (switch with current) + + if($previous != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous"; + + if($this->debug>2){error_log($sql_upd2,0);} + + $res_upd2 = api_sql_query($sql_upd2); + + } + + //update current item (switch with previous) + + if($id != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id"; + + if($this->debug>2){error_log($sql_upd2,0);} + + $res_upd2 = api_sql_query($sql_upd2); + + } + + //update next item (new previous item) + + if($next != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next"; + + if($this->debug>2){error_log($sql_upd2,0);} + + $res_upd2 = api_sql_query($sql_upd2); + + } + + $display = $display-1; + + } + + break; + + case 'down': + + if($this->debug>2){error_log('Movement down detected',0);} + + if($next == 0){/*do nothing*/} + + else{ + + $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next"; + + if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);} + + $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__); + + if(Database::num_rows($res_sel2)<1){$next_next = 0;} + + //gather data + + $row2 = Database::fetch_array($res_sel2); + + $next_next = $row2['next_item_id']; + + //update previous item (switch with current) + + if($previous != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous"; + + $res_upd2 = api_sql_query($sql_upd2); + + } + + //update current item (switch with previous) + + if($id != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id"; + + $res_upd2 = api_sql_query($sql_upd2); + + } + + //update next item (new previous item) + + if($next != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next"; + + $res_upd2 = api_sql_query($sql_upd2); + + } + + //update next_next item (switch "previous" with current) + + if($next_next != 0){ + + $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next"; + + $res_upd2 = api_sql_query($sql_upd2); + + } + + $display = $display+1; + + } + + break; + + default: + + return false; + + } + + return $display; + + } + + /** + + * Updates learnpath attributes to point to the next element + + * The last part is similar to set_current_item but processing the other way around + + */ + + function next(){ + + if($this->debug>0){error_log('New LP - In learnpath::next()',0);} + + $this->last = $this->get_current_item_id(); + + $this->items[$this->last]->save(false); + + $this->autocomplete_parents($this->last); + + $new_index = $this->get_next_index(); + + if($this->debug>2){error_log('New LP - New index: '.$new_index,0);} + + $this->index = $new_index; + + if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);} + + $this->current = $this->ordered_items[$new_index]; + + if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);} + + } + + /** + + * Open a resource = initialise all local variables relative to this resource. Depending on the child + + * class, this might be redefined to allow several behaviours depending on the document type. + + * @param integer Resource ID + + * @return boolean True on success, false otherwise + + */ + + function open($id) + + { + + if($this->debug>0){error_log('New LP - In learnpath::open()',0);} + + //TODO + + //set the current resource attribute to this resource + + //switch on element type (redefine in child class?) + + //set status for this item to "opened" + + //start timer + + //initialise score + + $this->index = 0; //or = the last item seen (see $this->last) + + } + + /** + + * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false + + * and the prerequisite string on error. + + * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108. + + * @param integer Optional item ID. If none given, uses the current open item. + + * @return boolean True if prerequisites are matched, false otherwise + + * @return string Empty string if true returned, prerequisites string otherwise. + + */ + + function prerequisites_match($item = null){ + + if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);} + + if(empty($item)){$item = $this->current;} + + if(is_object($this->items[$item])){ + + $prereq_string = $this->items[$item]->get_prereq_string(); + + if(empty($prereq_string)){return true;} + + //clean spaces + + $prereq_string = str_replace(' ','',$prereq_string); + + if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);} + + //now send to the parse_prereq() function that will check this component's prerequisites + + $result = $this->items[$item]->parse_prereq($prereq_string,$this); + + if($result === false){ + + $this->set_error_msg($this->items[$item]->prereq_alert); + + } + + }else{ + + $result = true; + + if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);} + + } + + if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);} + + return $result; + + } + + /** + + * Updates learnpath attributes to point to the previous element + + * The last part is similar to set_current_item but processing the other way around + + */ + + function previous(){ + + if($this->debug>0){error_log('New LP - In learnpath::previous()',0);} + + $this->last = $this->get_current_item_id(); + + $this->items[$this->last]->save(false); + + $this->autocomplete_parents($this->last); + + $new_index = $this->get_previous_index(); + + $this->index = $new_index; + + $this->current = $this->ordered_items[$new_index]; + + } + + /** + + * Publishes a learnpath. This basically means show or hide the learnpath + + * to normal users. + + * Can be used as abstract + + * @param integer Learnpath ID + + * @param string New visibility + + */ + + function toggle_visibility($lp_id,$set_visibility='v') + + { + + //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);} + + $tbl_lp = Database::get_course_table('lp'); + + $sql="SELECT * FROM $tbl_lp where id=$lp_id"; + + $result=api_sql_query($sql,__FILE__,__LINE__); + + $row=Database::fetch_array($result); + + $name=domesticate($row['name']); + + if($set_visibility == 'i') { + + $s=$name." ".get_lang('_no_published'); + + $dialogBox=$s; + + $v=0; + + } + + if($set_visibility == 'v') { + + $s=$name." ".get_lang('_published'); + + $dialogBox=$s; + + $v=1; + + } + + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); + + $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id; + + $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'"; + + $result=api_sql_query($sql,__FILE__,__LINE__); + + $num=Database::num_rows($result); + + $row2=Database::fetch_array($result); + + //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);} + + if(($set_visibility == 'i') && ($num>0)) + + { + + //it is visible or hidden but once was published + + if(($row2['visibility'])==1) + + { + + $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')"; + + } + + else + + { + + $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')"; + + } + + } + + elseif(($set_visibility == 'v') && ($num==0)) + + { + + $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)"; + + } + + else + + { + + //parameter and database incompatible, do nothing + + } + + $result=api_sql_query($sql,__FILE__,__LINE__); + + //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);} + + } + /** + * Restart the whole learnpath. Return the URL of the first element. + * Make sure the results are saved with anoter method. This method should probably be + * redefined in children classes. + * @return string URL to load in the viewer + */ + function restart() + { + if($this->debug>0){error_log('New LP - In learnpath::restart()',0);} + //TODO + //call autosave method to save the current progress + //$this->index = 0; + $lp_view_table = Database::get_course_table('lp_view'); + $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " . + "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")"; + if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);} + $res = api_sql_query($sql); + if($view_id = Database::get_last_insert_id($res)) + { + $this->lp_view_id = $view_id; + $this->attempt = $this->attempt+1; + }else{ + $this->error = 'Could not insert into item_view table...'; + return false; + } + $this->autocomplete_parents($this->current); + foreach($this->items as $index=>$dummy){ + $this->items[$index]->restart(); + $this->items[$index]->set_lp_view($this->lp_view_id); + } + $this->first(); + return true; + } + /** + * Saves the current item + * @return boolean + */ + function save_current(){ + if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);} + //TODO do a better check on the index pointing to the right item (it is supposed to be working + // on $ordered_items[] but not sure it's always safe to use with $items[]) + if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);} + if($this->debug>2){error_log(''.print_r($this->items,true),0);} + if(is_object($this->items[$this->current])){ + $res = $this->items[$this->current]->save(false); + $this->autocomplete_parents($this->current); + $status = $this->items[$this->current]->get_status(); + $this->append_message('new_item_status: '.$status); + $this->update_queue[$this->current] = $status; + return $res; + } + return false; + } + /** + * Saves the given item + * @param integer Item ID. Optional (will take from $_REQUEST if null) + * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true + * @return boolean + */ + function save_item($item_id=null,$from_outside=true){ + if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);} + //TODO do a better check on the index pointing to the right item (it is supposed to be working + // on $ordered_items[] but not sure it's always safe to use with $items[]) + if(empty($item_id)){ + $item_id = $this->escape_string($_REQUEST['id']); + } + if(empty($item_id)) + { + $item_id = $this->get_current_item_id(); + } + if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);} + if(is_object($this->items[$item_id])){ + $res = $this->items[$item_id]->save($from_outside); + $this->autocomplete_parents($item_id); + $status = $this->items[$item_id]->get_status(); + $this->append_message('new_item_status: '.$status); + $this->update_queue[$item_id] = $status; + return $res; + } + return false; + } + /** + * Saves the last item seen's ID only in case + */ + function save_last(){ + + if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);} + + $table = Database::get_course_table('lp_view'); + + if(isset($this->current)){ + + if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);} + + $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " . + + "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id(); + + if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);} + + $res = api_sql_query($sql,__FILE__,__LINE__); + + } + + //save progress + + list($progress,$text) = $this->get_progress_bar_text('%'); + + if($progress>=0 AND $progress<=100){ + + $progress= (int)$progress; + + $sql = "UPDATE $table SET progress = $progress " . + + "WHERE lp_id = ".$this->get_id()." AND " . + + "user_id = ".$this->get_user_id(); + + $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet + + $this->progress_db = $progress; + + } + + } + /** + * Sets the current item ID (checks if valid and authorized first) + * @param integer New item ID. If not given or not authorized, defaults to current + */ + function set_current_item($item_id=null) + { + if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);} + if(empty($item_id)){ + if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);} + //do nothing + }else{ + if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);} + $item_id = $this->escape_string($item_id); + //TODO check in database here + $this->last = $this->current; + $this->current = $item_id; + //TODO update $this->index as well + foreach($this->ordered_items as $index => $item) + { + if($item == $this->current) + { + $this->index = $index; + break; + } + } + if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);} + } + } + /** + * Sets the encoding + * @param string New encoding + */ + function set_encoding($enc='ISO-8859-1'){ + if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);} + $enc = strtoupper($enc); + $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS'); + if(in_array($enc,$encodings)){ + $lp = $this->get_id(); + if($lp!=0){ + $tbl_lp = Database::get_course_table('lp'); + $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp; + $res = api_sql_query($sql); + return $res; + } + } + return false; + } + /** + * Sets the JS lib setting in the database directly. + * This is the JavaScript library file this lp needs to load on startup + * @param string Proximity setting + */ + function set_jslib($lib=''){ + if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);} + $lp = $this->get_id(); + if($lp!=0){ + $tbl_lp = Database::get_course_table('lp'); + $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp; + $res = api_sql_query($sql); + return $res; + }else{ + return false; + } + } + /** + * Sets the name of the LP maker (publisher) (and save) + * @param string Optional string giving the new content_maker of this learnpath + */ + function set_maker($name=''){ + + if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);} + + if(empty($name))return false; + + + + $this->maker = $this->escape_string($name); + + $lp_table = Database::get_course_table('lp'); + + $lp_id = $this->get_id(); + + $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'"; + + if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);} + + //$res = Database::query($sql); + + $res = api_sql_query($sql); + + return true; + + } + + /** + + * Sets the name of the current learnpath (and save) + + * @param string Optional string giving the new name of this learnpath + + */ + + function set_name($name=''){ + + if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);} + + if(empty($name))return false; + + + + $this->name = $this->escape_string($name); + + $lp_table = Database::get_course_table('lp'); + + $lp_id = $this->get_id(); + + $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'"; + + if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);} + + //$res = Database::query($sql); + + $res = api_sql_query($sql); + + return true; + + } + + /** + * Sets the location/proximity of the LP (local/remote) (and save) + * @param string Optional string giving the new location of this learnpath + */ + function set_proximity($name=''){ + if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);} + if(empty($name))return false; + + $this->proximity = $this->escape_string($name); + $lp_table = Database::get_course_table('lp'); + $lp_id = $this->get_id(); + $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'"; + if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);} + //$res = Database::query($sql); + $res = api_sql_query($sql); + return true; + } + /** + * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item + * @param integer DB ID of the item + */ + function set_previous_item($id) + { + if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);} + $this->last = $id; + } + /** + * Sets the object's error message + * @param string Error message. If empty, reinits the error string + * @return void + */ + function set_error_msg($error='') + { + if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);} + if(empty($error)){ + $this->error = ''; + }else{ + $this->error .= $error; + } + } + /** + * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB) + * + */ + function start_current_item(){ + if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);} + if($this->current != 0 AND + is_object($this->items[$this->current])) + { + $type = $this->get_type(); + if( + ($type == 2 && $this->items[$this->current]->get_type()!='sco') + OR + ($type == 3 && $this->items[$this->current]->get_type()!='au') + OR + ($type==1) + ) + { + $this->items[$this->current]->open(); + $this->items[$this->current]->save(false); + $this->autocomplete_parents($this->current); + $this->prerequisites_match(); //launch the prerequisites check and set error if needed + //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); + }else{ + //if sco, then it is supposed to have been updated by some other call + } + } + return true; + } + + /** + + * Stops the processing and counters for the old item (as held in $this->last) + + * @param + + */ + + function stop_previous_item(){ + + if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);} + + if($this->last != 0 AND is_object($this->items[$this->last])) + { + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);} + switch($this->get_type()){ + case '3': + if($this->items[$this->last]->get_type()!='au') + { + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);} + $this->items[$this->last]->close(); + //$this->autocomplete_parents($this->last); + //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); + }else{ + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);} + } + case '2': + if($this->items[$this->last]->get_type()!='sco') + { + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);} + $this->items[$this->last]->close(); + //$this->autocomplete_parents($this->last); + //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); + }else{ + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);} + } + break; + case '1': + default: + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);} + $this->items[$this->last]->close(); + break; + } + }else{ + if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);} + return false; + } + return true; + } + + /** + + * Updates the default view mode from fullscreen to embedded and inversely + + * @return string The current default view mode ('fullscreen' or 'embedded') + + */ + + function update_default_view_mode() + + { + + if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);} + + $lp_table = Database::get_course_table('lp'); + + $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql); + + if(Database::num_rows($res)>0){ + + $row = Database::fetch_array($res); + + $view_mode = $row['default_view_mod']; + + if($view_mode == 'fullscreen'){ + + $view_mode = 'embedded'; + + }elseif($view_mode == 'embedded'){ + + $view_mode = 'fullscreen'; + + } + + $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql); + + $this->mode = $view_mode; + + return $view_mode; + + }else{ + + if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);} + + } + + return -1; + + } + + /** + + * Updates the default behaviour about auto-commiting SCORM updates + + * @return boolean True if auto-commit has been set to 'on', false otherwise + + */ + + function update_default_scorm_commit(){ + + if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);} + + $lp_table = Database::get_course_table('lp'); + + $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql); + + if(Database::num_rows($res)>0){ + + $row = Database::fetch_array($res); + + $force = $row['force_commit']; + + if($force == 1){ + + $force = 0; + + $force_return = false; + + }elseif($force == 0){ + + $force = 1; + + $force_return = true; + + } + + $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql); + + $this->force_commit = $force_return; + + return $force_return; + + }else{ + + if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);} + + } + + return -1; + + } + + /** + + * Updates the "prevent_reinit" value that enables control on reinitialising items on second view + + * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case) + + */ + + function update_reinit(){ + + if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);} + + $lp_table = Database::get_course_table('lp'); + + $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql); + + if(Database::num_rows($res)>0){ + + $row = Database::fetch_array($res); + + $force = $row['prevent_reinit']; + + if($force == 1){ + + $force = 0; + + }elseif($force == 0){ + + $force = 1; + + } + + $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql,__FILE__,__LINE__); + + $this->prevent_reinit = $force; + + return $force; + + }else{ + + if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);} + + } + + return -1; + + } + + /** + + * Updates the "scorm_debug" value that shows or hide the debug window + + * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case) + + */ + + function update_scorm_debug(){ + + if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);} + + $lp_table = Database::get_course_table('lp'); + + $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql); + + if(Database::num_rows($res)>0){ + + $row = Database::fetch_array($res); + + $force = $row['debug']; + + if($force == 1){ + + $force = 0; + + }elseif($force == 0){ + + $force = 1; + + } + + $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id(); + + $res = api_sql_query($sql,__FILE__,__LINE__); + + $this->scorm_debug = $force; + + return $force; + + }else{ + + if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);} + + } + + return -1; + + } + + /** + * Function that makes a call to the function sort_tree_array and create_tree_array + * + * @author Kevin Van Den Haute + * + * @param unknown_type $array + */ + function tree_array($array) + { + $array = $this->sort_tree_array($array); + $this->create_tree_array($array); + } + + /** + * Creates an array with the elements of the learning path tree in it + * + * @author Kevin Van Den Haute + * + * @param array $array + * @param int $parent + * @param int $depth + * @param array $tmp + */ + function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array()) + { + if(is_array($array)) + { + for($i = 0; $i < count($array); $i++) + { + if($array[$i]['parent_item_id'] == $parent) + { + if(!in_array($array[$i]['parent_item_id'], $tmp)) + { + $tmp[] = $array[$i]['parent_item_id']; + $depth++; + } + + $this->arrMenu[] = array( + 'id' => $array[$i]['id'], + 'item_type' => $array[$i]['item_type'], + 'title' => $array[$i]['title'], + 'path' => $array[$i]['path'], + 'description' => $array[$i]['description'], + 'parent_item_id' => $array[$i]['parent_item_id'], + 'previous_item_id' => $array[$i]['previous_item_id'], + 'next_item_id' => $array[$i]['next_item_id'], + 'display_order' => $array[$i]['display_order'], + 'depth' => $depth + ); + + $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp); + } + } + } + } + + /** + * Sorts a multi dimensional array by parent id and display order + * @author Kevin Van Den Haute + * + * @param array $array (array with al the learning path items in it) + * + * @return array + */ + function sort_tree_array($array) + { + foreach($array as $key => $row) + { + $parent[$key] = $row['parent_item_id']; + $position[$key] = $row['display_order']; + } + + if(count($array) > 0) + array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array); + + return $array; + } + + + + /** + * Function that creates a table structure with a learning path his modules, chapters and documents. + * Also the actions for the modules, chapters and documents are in this table. + * + * @author Kevin Van Den Haute + * + * @param int $lp_id + * + * @return string + */ + function overview() + { + $return = ''; + + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + if(api_is_allowed_to_edit()) + $return .= '

    Advanced

    '; + + $return .= '' . "\n"; + + $return .= "\t" . '' . "\n"; + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= "\t" . '' . "\n"; + + for($i = 0; $i < count($arrLP); $i++) + { + if($arrLP[$i]['description'] == '') + $arrLP[$i]['description'] = ' '; + + $return .= "\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + $return .= "\t\t" . '' . "\n"; + + if(api_is_allowed_to_edit()) + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t" . '' . "\n"; + } + + if(count($arrLP) == 0) + { + $return .= "\t" . '' . "\n"; + $return .= "\t\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + } + + $return .= '
    TitleDescriptionMoveActions
    ' . stripslashes($arrLP[$i]['title']) . '' . stripslashes($arrLP[$i]['description']) . '' . "\n"; + + if($arrLP[$i]['previous_item_id'] != 0) + { + $return .= "\t\t\t" . ''; + $return .= ''; + $return .= '' . "\n"; + } + else + $return .= "\t\t\t" . '' . "\n"; + + if($arrLP[$i]['next_item_id'] != 0) + { + $return .= "\t\t\t" . ''; + $return .= ''; + $return .= '' . "\n"; + } + else + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') + { + $return .= "\t\t\t" . ''; + $return .= ''; + $return .= '' . "\n"; + } + else + { + $return .= "\t\t\t" . ''; + $return .= ''; + $return .= '' . "\n"; + } + + $return .= "\t\t\t" . ''; + $return .= ''; + $return .= '' . "\n"; + + $return .= "\t\t" . '
    There are no items in the learning path for this moment. Click on "Advanced" for creating your learning path items.
    ' . "\n"; + + return $return; + } + + /** + * This functions builds the LP tree based on data from the database. + * + * @return string + * @uses dtree.js :: necessary javascript for building this tree + */ + function build_tree() + { + $return = "\n"; + + return $return; + } + + /** + * Create a new document //still needs some finetuning + * + * @param array $_course + * @return string + */ + function create_document($_course) + { + $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting + + if(strstr($dir, '..')) + $dir = '/'; + + if($dir[0] == '.') + $dir = substr($dir, 1); + + if($dir[0] != '/') + $dir = '/'.$dir; + + if($dir[strlen($dir) - 1] != '/') + $dir .= '/'; + + $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir; + + if(!is_dir($filepath)) + { + $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/'; + + $dir = '/'; + } + + $title = replace_dangerous_char($_POST['title']); + $filename = $title; + $content = $_POST['content']; + + $tmp_filename = $filename; + + while(file_exists($filepath . $tmp_filename . '.html')) + $tmp_filename = $filename . '_' . ++$i; + + $filename = $tmp_filename . '.html'; + + $content = stripslashes(text_filter($content)); + + $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir; + $content = str_replace($path_to_remove, './', $content); + + if(!file_exists($filepath . $filename)) + { + if($fp = @fopen($filepath . $filename, 'w')) + { + fputs($fp, $content); + fclose($fp); + + $file_size = filesize($filepath . $filename); + $save_file_path = $dir . $filename; + + $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html'); + + if($document_id) + { + api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id); + + //update parent folders + //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']); + + $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : ''; + $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : ''; + + if($new_comment || $new_title) + { + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); + $ct = ''; + + if($new_comment) + $ct .= ", comment='" . $new_comment . "'"; + + if($new_title) + $ct .= ", title='" . $new_title . ".html '"; + + $sql_update = " + UPDATE " . $tbl_doc . " + SET " . substr($ct, 1) . " + WHERE id = " . $document_id; + api_sql_query($sql_update, __FILE__, __LINE__); + } + } + + return $document_id; + } + } + } + + /** + * Enter description here... + * + * @param array $_course + */ + function edit_document($_course) + { + $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting + + if(strstr($dir, '..')) + $dir = '/'; + + if($dir[0] == '.') + $dir = substr($dir, 1); + + if($dir[0] != '/') + $dir = '/'.$dir; + + if($dir[strlen($dir) - 1] != '/') + $dir .= '/'; + + $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir; + + if(!is_dir($filepath)) + { + $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/'; + + $dir = '/'; + } + + $table_doc = Database::get_course_table(TABLE_DOCUMENT); + + $sql = " + SELECT path + FROM " . $table_doc . " + WHERE id = " . $_POST['path']; + $res = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($res); + + $content = stripslashes($_POST['content']); + $file = $filepath . $row['path']; + + + if($fp = @fopen($file, 'w')) + { + $content = text_filter($content); + $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir; + $content = str_replace($path_to_remove, './', $content); + + fputs($fp, $content); + fclose($fp); + } + } + + /** + * Displays the selected item, with a panel for manipulating the item + * + * @param int $item_id + * @param string $msg + * @return string + */ + function display_item($item_id, $iframe = true, $msg = '') + { + global $_course; //will disappear + + $return = ''; + + if(is_numeric($item_id)) + { + $tbl_lp_item = Database::get_course_table('lp_item'); + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); + + $sql = " + SELECT + lp.* + FROM " . $tbl_lp_item . " as lp + WHERE + lp.id = " . $item_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + while($row = Database::fetch_array($result)) + { + $return .= $this->display_manipulate($item_id, $row['item_type']); + + $return .= '
    '; + + if($msg != '') + $return .= $msg; + + $return .= '

    ' . stripslashes($row['title']) . '

    '; + $return .= '

    ' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '

    '; + + $return .= '
    '; + + if($row['item_type'] == TOOL_DOCUMENT) + $return .= $this->display_document($row['path'], true, true); + + $return .= '
    '; + } + } + + return $return; + } + + /** + * Shows the needed forms for editing a specific item + * + * @param int $item_id + * @return string + */ + function display_edit_item($item_id) + { + global $_course; //will disappear + + $return = ''; + + if(is_numeric($item_id)) + { + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE id = " . $item_id; + + $res = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($res); + + switch($row['item_type']) + { + case 'dokeos_chapter': + + if(isset($_GET['view']) && $_GET['view'] == 'build') + { + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_item_form($row['item_type'], 'Edit the current chapter:', 'edit', $item_id, $row); + } + else + { + $return .= $this->display_item_small_form($row['item_type'], 'Edit the current chapter:', $row); + } + + break; + + case TOOL_DOCUMENT: + + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); + + $sql_step = " + SELECT + lp.*, + doc.path as dir + FROM " . $tbl_lp_item . " as lp + LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path + WHERE + lp.id = " . $item_id; + $res_step = api_sql_query($sql_step, __FILE__, __LINE__); + $row_step = Database::fetch_array($res_step); + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_document_form('edit', $item_id, $row_step); + + break; + + case TOOL_LINK: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_link_form('edit', $item_id, $row); + + break; + + case 'dokeos_module': + + if(isset($_GET['view']) && $_GET['view'] == 'build') + { + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_item_form($row['item_type'], 'Edit the current module:', 'edit', $item_id, $row); + } + else + { + $return .= $this->display_item_small_form($row['item_type'], 'Edit the current module:', $row); + } + + break; + + case TOOL_QUIZ: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_quiz_form('edit', $item_id, $row); + + break; + + case TOOL_STUDENTPUBLICATION: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_student_publication_form('edit', $item_id, $row); + + break; + } + } + + return $return; + } + + /** + * Function that displays a list with al the resources that could be added to the learning path + * + * @return string + */ + function display_resources() + { + global $_course; //TODO: don't use globals + + $return = '
    ' . "\n"; + + $return .= '

    Create a new step:

    '; + + $return .= ''; + + $return .= '

    Or use an existing resource:

    '; + + /* get al the docs */ + $return .= $this->get_documents(); + + /* get al the exercises */ + $return .= $this->get_exercises(); + + /* get al links */ + $return .= $this->get_links(); + + /* get al the student publications */ + $return .= $this->get_student_publications(); + + $return .= '
    ' . "\n"; + + return $return; + } + + /** + * Returns the extension of a document + * + * @param unknown_type $filename + * @return unknown + */ + function get_extension($filename) + { + $explode = explode('.', $filename); + + return $explode[count($explode) - 1]; + } + + /** + * Displays a document by id + * + * @param unknown_type $id + * @return unknown + */ + function display_document($id, $show_title = false, $iframe = true, $edit_link = false) + { + global $_course; //temporary + + $return = ''; + + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); + + $sql_doc = " + SELECT * + FROM " . $tbl_doc . " + WHERE id = " . $id; + $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__); + $row_doc = Database::fetch_array($res_doc); + + if($show_title) + $return .= '

    ' . $row_doc['title'] . ($edit_link ? ' [ Edit this document ]' : '') . '

    '; + + //TODO: add a path filter + if($iframe) + $return .= ''; + else + $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']); + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $action + * @param unknown_type $id + * @param unknown_type $extra_info + * @return unknown + */ + function display_quiz_form($action = 'add', $id = 0, $extra_info = '') + { + $tbl_lp_item = Database::get_course_table('lp_item'); + $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE); + + if($id != 0 && is_array($extra_info)) + { + $item_title = stripslashes($extra_info['title']); + $item_description = stripslashes($extra_info['description']); + } + elseif(is_numeric($extra_info)) + { + $sql_quiz = " + SELECT + title, + description + FROM " . $tbl_quiz . " + WHERE id = " . $extra_info; + + $result = api_sql_query($sql_quiz, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $item_title = $row['title']; + $item_description = $row['description']; + } + else + { + $item_title = ''; + $item_description = ''; + } + + $return = '
    '; + + if($id != 0 && is_array($extra_info)) + $parent = $extra_info['parent_item_id']; + else + $parent = 0; + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'path' => $row['path'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + if($action == 'add') + $return .= '

    Create the exercise:

    ' . "\n"; + elseif($action == 'move') + $return .= '

    Move the current exercise:

    ' . "\n"; + else + $return .= '

    Edit the current exercise:

    ' . "\n"; + + if(isset($_GET['edit']) && $_GET['edit'] == 'true') + { + $return .= '
    '; + + $return .= '

    Warning !

    '; + $return .= 'When you edit an existing document in the Learning Path, the new version of the document will not overwrite the old version but will be saved as a new document. If you want to edit a document definitively, you can do that with the document tool.'; + + $return .= '
    '; + } + + $return .= '
    ' . "\n"; + + $return .= "\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if($action != 'move') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + if($action == 'move') + { + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + } + + if(is_numeric($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + elseif(is_array($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= '
    ' . "\n"; + + $return .= '
    ' . "\n"; + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $item_type + * @param unknown_type $title + * @param unknown_type $action + * @param unknown_type $id + * @param unknown_type $extra_info + * @return unknown + */ + function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') + { + $tbl_lp_item = Database::get_course_table('lp_item'); + + if($id != 0 && is_array($extra_info)) + { + $item_title = stripslashes($extra_info['title']); + $item_description = stripslashes($extra_info['description']); + } + else + { + $item_title = ''; + $item_description = ''; + } + + $return = '
    '; + + if($id != 0 && is_array($extra_info)) + $parent = $extra_info['parent_item_id']; + else + $parent = 0; + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + if($item_type == 'module') + $sql .= " AND parent_item_id = 0"; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'path' => $row['path'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + $return .= '

    ' . $title . '

    ' . "\n"; + + $return .= '
    ' . "\n"; + + $return .= "\t" . '' . "\n"; + + if($item_type != 'module' && $item_type != 'dokeos_module') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if($action != 'move') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + if($item_type == 'module' || $item_type == 'dokeos_module') + $return .= "\t" . '' . "\n"; + + if($action == 'move') + { + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + } + /*if($id != 0 && is_array($extra_info)) + { + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + }*/ + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= '
    ' . "\n"; + $return .= '
    ' . "\n"; + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $action + * @param unknown_type $id + * @param unknown_type $extra_info + * @return unknown + */ + function display_document_form($action = 'add', $id = 0, $extra_info = 'new') + { + $tbl_lp_item = Database::get_course_table('lp_item'); + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); + + if($id != 0 && is_array($extra_info)) + { + $item_title = stripslashes($extra_info['title']); + $item_description = stripslashes($extra_info['description']); + } + elseif(is_numeric($extra_info)) + { + $sql_doc = " + SELECT title + FROM " . $tbl_doc . " + WHERE id = " . $extra_info; + + $result = api_sql_query($sql_doc, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $explode = explode('.', $row['title']); + + for($i = 0; $i < count($explode) - 1; $i++) + $item_title .= $explode[$i]; + + $item_title = str_replace('_', ' ', $item_title); + } + else + { + $item_title = ''; + $item_description = ''; + } + + $return = '
    '; + + if($id != 0 && is_array($extra_info)) + $parent = $extra_info['parent_item_id']; + else + $parent = 0; + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'path' => $row['path'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + if($action == 'add') + $return .= '

    Create the document:

    ' . "\n"; + elseif($action == 'move') + $return .= '

    Move the current document:

    ' . "\n"; + else + $return .= '

    Edit the current document:

    ' . "\n"; + + if(isset($_GET['edit']) && $_GET['edit'] == 'true') + { + $return .= '
    '; + + $return .= '

    Warning !

    '; + $return .= 'When you edit an existing document in the Learning Path, the new version of the document will not overwrite the old version but will be saved as a new document. If you want to edit a document definitively, you can do that with the document tool.'; + + $return .= '
    '; + } + + $return .= '
    ' . "\n"; + + $return .= "\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if($action != 'move') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) + { + if($action == 'add' || $_GET['edit'] == 'true') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + elseif(is_numeric($extra_info)) + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    '; + + $sql_doc = " + SELECT * + FROM " . $tbl_doc . " + WHERE + filetype = 'folder' + ORDER BY path ASC"; + + $result = api_sql_query($sql_doc, __FILE__, __LINE__); + + $return .= "\t\t\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '
    ' . "\n"; + + if(isset($_POST['content'])) + $content = stripslashes($_POST['content']); + elseif(is_array($extra_info)) + $content = $this->display_document($extra_info['path'], false, false); + elseif(is_numeric($extra_info)) + $content = $this->display_document($extra_info, false, false); + else + $content = ''; + + $oFCKeditor = new FCKeditor('content_lp') ; + $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ; + $oFCKeditor->Height = '400'; + $oFCKeditor->Width = '100%'; + $oFCKeditor->Value = $content; + + $return .= $oFCKeditor->CreateHtml(); + + $return .= "\t\t\t" . '
    ' . "\n"; + + $return .= $this->display_document($extra_info, true, true, true); + + $return .= "\t\t\t" . '
    ' . "\n"; + + if($action == 'move') + { + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + } + + if(is_numeric($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + elseif(is_array($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= '
    ' . "\n"; + $return .= '
    ' . "\n"; + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $action + * @param unknown_type $id + * @param unknown_type $extra_info + */ + function display_link_form($action = 'add', $id = 0, $extra_info = '') + { + $tbl_lp_item = Database::get_course_table('lp_item'); + $tbl_link = Database::get_course_table(TABLE_LINK); + + if($id != 0 && is_array($extra_info)) + { + $item_title = stripslashes($extra_info['title']); + $item_description = stripslashes($extra_info['description']); + } + elseif(is_numeric($extra_info)) + { + $sql_link = " + SELECT + title, + description, + url + FROM " . $tbl_link . " + WHERE id = " . $extra_info; + + $result = api_sql_query($sql_link, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $item_title = $row['title']; + $item_description = $row['description']; + $item_url = $row['url']; + } + else + { + $item_title = ''; + $item_description = ''; + } + + $return = '
    '; + + if($id != 0 && is_array($extra_info)) + $parent = $extra_info['parent_item_id']; + else + $parent = 0; + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'path' => $row['path'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + if($action == 'add') + $return .= '

    Create the link:

    ' . "\n"; + elseif($action == 'move') + $return .= '

    Move the current link:

    ' . "\n"; + else + $return .= '

    Edit the current link:

    ' . "\n"; + + $return .= '
    ' . "\n"; + + $return .= "\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if($action != 'move') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + if($action == 'move') + { + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + } + + if(is_numeric($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + elseif(is_array($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= '
    ' . "\n"; + + $return .= '
    ' . "\n"; + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $action + * @param unknown_type $id + * @param unknown_type $extra_info + * @return unknown + */ + function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') + { + $tbl_lp_item = Database::get_course_table('lp_item'); + $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + + if($id != 0 && is_array($extra_info)) + { + $item_title = stripslashes($extra_info['title']); + $item_description = stripslashes($extra_info['description']); + } + elseif(is_numeric($extra_info)) + { + $sql_publication = " + SELECT + title, + description + FROM " . $tbl_publication . " + WHERE id = " . $extra_info; + + $result = api_sql_query($sql_publication, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $item_title = $row['title']; + $item_description = $row['description']; + } + else + { + $item_title = ''; + $item_description = ''; + } + + $return = '
    '; + + if($id != 0 && is_array($extra_info)) + $parent = $extra_info['parent_item_id']; + else + $parent = 0; + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'path' => $row['path'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + if($action == 'add') + $return .= '

    Create the student publication:

    ' . "\n"; + elseif($action == 'move') + $return .= '

    Move the current student publication:

    ' . "\n"; + else + $return .= '

    Edit the current student publication:

    ' . "\n"; + + $return .= '
    ' . "\n"; + + $return .= "\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + if($action != 'move') + { + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + } + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + $return .= "\t\t\t\t" . ''; + + $return .= "\t\t\t" . '
    ' . "\n"; + + if($action == 'move') + { + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + } + + if(is_numeric($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + elseif(is_array($extra_info)) + { + $return .= "\t" . '' . "\n"; + } + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= '
    ' . "\n"; + + $return .= '
    ' . "\n"; + + return $return; + } + + /** + * Displays the menu for manipulating a step + * + * @return unknown + */ + function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) + { + $return = '
    '; + + switch($item_type) + { + case 'dokeos_chapter': + case 'chapter': + + $lang = get_lang('TitleManipulateChapter'); + /* temp */ $lang = 'Manipulate the current chapter'; + break; + + case 'dokeos_module': + case 'module': + + $lang = get_lang('TitleManipulateModule'); + /* temp */ $lang = 'Manipulate the current module'; + + break; + + case TOOL_DOCUMENT: + + $lang = get_lang('TitleManipulateDocument'); + /* temp */ $lang = 'Manipulate the current document'; + + break; + + case TOOL_LINK: + case 'link': + + $lang = get_lang('TitleManipulateLink'); + /* temp */ $lang = 'Manipulate the current link'; + + break; + + case TOOL_QUIZ: + + $lang = get_lang('TitleManipulateQuiz'); + /* temp */ $lang = 'Manipulate the current exercise'; + + break; + + case TOOL_STUDENTPUBLICATION: + + $lang = get_lang('TitleManipulateStudentPublication'); + /* temp */ $lang = 'Manipulate the current student publication'; + + break; + } + + $return .= '

    ' . $lang . '

    '; + + $return .= 'Edit the current item Edit'; + $return .= 'Move the current item Move'; + + if($item_type != 'chapter' && $item_type != 'dokeos_chapter' && $item_type != 'module' && $item_type != 'dokeos_module') + $return .= 'Edit the prerequisites of the current item Prerequisites'; + + $return .= 'Delete the current item Delete'; + + $return .= '
    '; + + return $return; + } + + /** + * Creates the javascript needed for filling up the checkboxes without page reload + * + * @return string + */ + function create_js() + { + $return = '' . "\n"; + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $item_id + * @return unknown + */ + function display_move_item($item_id) + { + global $_course; //will disappear + + $return = ''; + + if(is_numeric($item_id)) + { + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE id = " . $item_id; + + $res = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($res); + + switch($row['item_type']) + { + case 'dokeos_chapter': + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_item_form($row['item_type'], 'Move the current chapter:', 'move', $item_id, $row); + + break; + + case 'dokeos_module': + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row); + + break; + + case TOOL_DOCUMENT: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_document_form('move', $item_id, $row); + + break; + + case TOOL_LINK: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_link_form('move', $item_id, $row); + + break; + + case TOOL_QUIZ: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_quiz_form('move', $item_id, $row); + + break; + + case TOOL_STUDENTPUBLICATION: + + $return .= $this->display_manipulate($item_id, $row['item_type']); + $return .= $this->display_student_publication_form('move', $item_id, $row); + + break; + } + } + + return $return; + } + + /** + * Displays a basic form on the overview page for changing the item title and the item description. + * + * @param string $item_type + * @param string $title + * @param array $data + * @return string + */ + function display_item_small_form($item_type, $title = '', $data) + { + $return .= '
    ' . "\n"; + + $return .= '

    ' . $title . '

    '; + + $return .= '
    ' . "\n"; + + $return .= ''; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t\t" . '' . "\n"; + + $return .= "\t\t" . '' . "\n"; + + $return .= "\t\t" . '
    ' . "\n"; + + $return .= "\t" . '' . "\n"; + $return .= "\t" . '' . "\n"; + + $return .= '
    '; + + $return .= '
    '; + + return $return; + } + + /** + * Enter description here... + * + * @param unknown_type $item_id + * @return unknown + */ + function display_item_prerequisites_form($item_id) + { + $tbl_lp_item = Database::get_course_table('lp_item'); + + /* current prerequisite */ + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE id = " . $item_id; + $result = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($result); + + $preq_id = $row['prerequisite']; + $preq_min = $row['min_score']; + $preq_max = $row['max_score']; + + $return = $this->display_manipulate($item_id, TOOL_DOCUMENT); + + $return .= '
    '; + + $return .= '

    Add/edit prerequisites

    '; + + $return .= '
    '; + + $return .= ''; + + $return .= ''; + + $return .= ''; + $return .= ''; + $return .= ''; + + $return .= ''; + + $return .= ''; + + $return .= ''; + + $return .= ''; + + $sql = " + SELECT * + FROM " . $tbl_lp_item . " + WHERE + lp_id = " . $this->lp_id; + + $result = api_sql_query($sql, __FILE__, __LINE__); + + $arrLP = array(); + + while($row = Database::fetch_array($result)) + { + $arrLP[] = array( + 'id' => $row['id'], + 'item_type' => $row['item_type'], + 'title' => $row['title'], + 'description' => $row['description'], + 'parent_item_id' => $row['parent_item_id'], + 'previous_item_id' => $row['previous_item_id'], + 'next_item_id' => $row['next_item_id'], + 'display_order' => $row['display_order']); + } + + $this->tree_array($arrLP); + + $arrLP = $this->arrMenu; + + unset($this->arrMenu); + + for($i = 0; $i < count($arrLP); $i++) + { + if($arrLP[$i]['id'] == $item_id) + break; + + $return .= ''; + + $return .= ''; + + if($arrLP[$i]['item_type'] == TOOL_QUIZ) + { + $return .= ''; + + $return .= ''; + } + + $return .= ''; + } + + $return .= ''; + + $return .= '' . "\n"; + + $return .= ''; + + $return .= ''; + + $return .= '
    MinimumMaximum
    '; + + $return .= ''; + $return .= ''; + + $return .= '
    '; + + $return .= ''; + $return .= ''; + $return .= ''; + + $return .= ''; + + $return .= ''; + + $return .= ''; + + $return .= ''; + + $return .= '
    '; + + $return .= '
    '; + + $return .= '
    '; + + $return .= '
    '; + + return $return; + } + + /** + * Creates a list with all the documents in it + * + * @return string + */ + function get_documents() + { + global $_course; + + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); + + $sql_doc = " + SELECT * + FROM " . $tbl_doc . " + WHERE + path NOT LIKE '%_DELETED_%' + ORDER BY path ASC"; + $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__); + + $return = '
    Document
    '; + $return .= '
    '; + + while($row_doc = Database::fetch_array($res_doc)) + { + $explode = explode('/', $row_doc['path']); + $num = count($explode) - 2; + + $return .= '
    '; + + $return .= ''; + + if($row_doc['filetype'] == 'file') + $return .= '' . $row_doc['title'] . ''; + else + $return .= $row_doc['title']; + + $return .= '
    '; + } + + if(Database::num_rows($res_doc) == 0) + $return .= '
    No documents
    '; + + $return .= '
    '; + + return $return; + } + + /** + * Creates a list with all the exercises (quiz) in it + * + * @return string + */ + function get_exercises() + { + $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE); + + $sql_quiz = " + SELECT * + FROM " . $tbl_quiz . " + ORDER BY title ASC"; + $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__); + + $return .= '
    Exercises
    '; + $return .= '
    '; + + while($row_quiz = Database::fetch_array($res_quiz)) + { + $return .= '
    '; + + $return .= ''; + $return .= '' . $row_quiz['title'] . ''; + //$return .= $row_quiz['title']; + + $return .= '
    '; + } + + if(Database::num_rows($res_quiz) == 0) + $return .= '
    No exercises available
    '; + + $return .= '
    '; + + return $return; + } + + /** + * Creates a list with all the links in it + * + * @return string + */ + function get_links() + { + $tbl_link = Database::get_course_table(TABLE_LINK); + + $sql_link = " + SELECT * + FROM " . $tbl_link . " + ORDER BY title ASC"; + $res_link = api_sql_query($sql_link, __FILE__, __LINE__); + + $return .= '
    Links
    '; + $return .= ''; + + return $return; + } + + /** + * Creates a list with all the student publications in it + * + * @return unknown + */ + function get_student_publications() + { + $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + + $sql_student = " + SELECT * + FROM " . $tbl_student . " + ORDER BY title ASC"; + $res_student = api_sql_query($sql_student, __FILE__, __LINE__); + + $return .= '
    Student Publications
    '; + $return .= '
    '; + + while($row_student = Database::fetch_array($res_student)) + { + $return .= '
    '; + + $return .= ''; + $return .= '' . $row_student['title'] . ''; + + $return .= '
    '; + } + + if(Database::num_rows($res_student) == 0) + $return .= '
    No student publications available
    '; + + $return .= '
    '; + + return $return; + } +} + ?> \ No newline at end of file diff --git a/main/newscorm/learnpathList.class.php b/main/newscorm/learnpathList.class.php index fe683d776c..c528c607ca 100644 --- a/main/newscorm/learnpathList.class.php +++ b/main/newscorm/learnpathList.class.php @@ -1,100 +1,100 @@ - - */ -/** - * This class is only a learning path list container with several practical methods for sorting the list and - * provide links to specific paths - * @uses Database.lib.php to use the database - * @uses learnpath.class.php to generate learnpath objects to get in the list - */ -class learnpathList { - var $list = array(); //holds a flat list of learnpaths data from the database - var $ref_list = array(); //holds a list of references to the learnpaths objects (only filled by get_refs()) - var $alpha_list = array(); //holds a flat list of learnpaths sorted by alphabetical name order - var $course_code; - var $user_id; - var $refs_active = false; - - /** - * This method is the constructor for the learnpathList. It gets a list of available learning paths from - * the database and creates the learnpath objects. This list depends on the user that is connected - * (only displays) items if he has enough permissions to view them. - * @param integer User ID - * @param string Optional course code (otherwise we use api_get_course_id()) - * @return void - */ - function learnpathList($user_id,$course_code='') { - if(!empty($course_code)){ - //proceed with course code given - }else{ - $course_code = api_get_course_id(); - $lp_table = Database::get_course_table('lp'); - } - $this->course_code = $course_code; - $this->user_id = $user_id; - $sql = "SELECT * FROM $lp_table ORDER BY name ASC"; - $res = api_sql_query($sql); - $names = array(); - while ($row = Database::fetch_array($res)) - { - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE); - //use domesticate here instead of mysql_real_escape_string because - //it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility()) - //is done using domesticate() - $myname = domesticate($row['name']); - $mylink = 'newscorm/lp_controller.php?mode=view&lp_id='.$row['id']; - $sql2="SELECT * FROM $tbl_tool where (name='$myname' and image='scormbuilder.gif' and link LIKE '$mylink%')"; - //error_log('New LP - learnpathList::learnpathList - getting visibility - '.$sql2,0); - $res2 = api_sql_query($sql2,__FILE__,__LINE__); - if(Database::num_rows($res2)>0){ - $row2 = Database::fetch_array($res2); - $vis = $row2['visibility']; - }else{ - $vis = 'i'; - } - - $this->list[$row['id']] = array( - 'lp_type' => $row['lp_type'], - 'lp_name' => stripslashes($row['name']), - 'lp_desc' => stripslashes($row['description']), - 'lp_path' => $row['path'], - 'lp_view_mode' => $row['default_view_mod'], - 'lp_force_commit' => $row['force_commit'], - 'lp_maker' => stripslashes($row['content_maker']), - 'lp_proximity' => $row['content_local'], - 'lp_encoding' => $row['default_encoding'], - 'lp_progress' => $row['progress'], - 'lp_visibility' => $vis, - 'lp_prevent_reinit' => $row['prevent_reinit'], - 'lp_scorm_debug' => $row['debug'], - ); - $names[$row['name']]=$row['id']; - } - $this->alpha_list = asort($names); - } - /** - * Gets references to learnpaths for all learnpaths IDs kept in the local list. - * This applies a transformation internally on list and ref_list and returns a copy of the refs list - * @return array List of references to learnpath objects - */ - function get_refs(){ - foreach($this->list as $id => $dummy) - { - $this->ref_list[$id] = new learnpath($this->course_code,$id,$this->user_id); - } - $this->refs_active = true; - return $this->ref_list; - } - /** - * Gets a table of the different learnpaths we have at the moment - * @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...) - */ - function get_flat_list() - { - return $this->list; - } -} -?> + + */ +/** + * This class is only a learning path list container with several practical methods for sorting the list and + * provide links to specific paths + * @uses Database.lib.php to use the database + * @uses learnpath.class.php to generate learnpath objects to get in the list + */ +class learnpathList { + var $list = array(); //holds a flat list of learnpaths data from the database + var $ref_list = array(); //holds a list of references to the learnpaths objects (only filled by get_refs()) + var $alpha_list = array(); //holds a flat list of learnpaths sorted by alphabetical name order + var $course_code; + var $user_id; + var $refs_active = false; + + /** + * This method is the constructor for the learnpathList. It gets a list of available learning paths from + * the database and creates the learnpath objects. This list depends on the user that is connected + * (only displays) items if he has enough permissions to view them. + * @param integer User ID + * @param string Optional course code (otherwise we use api_get_course_id()) + * @return void + */ + function learnpathList($user_id,$course_code='') { + if(!empty($course_code)){ + //proceed with course code given + }else{ + $course_code = api_get_course_id(); + $lp_table = Database::get_course_table('lp'); + } + $this->course_code = $course_code; + $this->user_id = $user_id; + $sql = "SELECT * FROM $lp_table ORDER BY name ASC"; + $res = api_sql_query($sql); + $names = array(); + while ($row = Database::fetch_array($res)) + { + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); + //use domesticate here instead of mysql_real_escape_string because + //it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility()) + //is done using domesticate() + $myname = domesticate($row['name']); + $mylink = 'newscorm/lp_controller.php?mode=view&lp_id='.$row['id']; + $sql2="SELECT * FROM $tbl_tool where (name='$myname' and image='scormbuilder.gif' and link LIKE '$mylink%')"; + //error_log('New LP - learnpathList::learnpathList - getting visibility - '.$sql2,0); + $res2 = api_sql_query($sql2,__FILE__,__LINE__); + if(Database::num_rows($res2)>0){ + $row2 = Database::fetch_array($res2); + $vis = $row2['visibility']; + }else{ + $vis = 'i'; + } + + $this->list[$row['id']] = array( + 'lp_type' => $row['lp_type'], + 'lp_name' => stripslashes($row['name']), + 'lp_desc' => stripslashes($row['description']), + 'lp_path' => $row['path'], + 'lp_view_mode' => $row['default_view_mod'], + 'lp_force_commit' => $row['force_commit'], + 'lp_maker' => stripslashes($row['content_maker']), + 'lp_proximity' => $row['content_local'], + 'lp_encoding' => $row['default_encoding'], + 'lp_progress' => $row['progress'], + 'lp_visibility' => $vis, + 'lp_prevent_reinit' => $row['prevent_reinit'], + 'lp_scorm_debug' => $row['debug'], + ); + $names[$row['name']]=$row['id']; + } + $this->alpha_list = asort($names); + } + /** + * Gets references to learnpaths for all learnpaths IDs kept in the local list. + * This applies a transformation internally on list and ref_list and returns a copy of the refs list + * @return array List of references to learnpath objects + */ + function get_refs(){ + foreach($this->list as $id => $dummy) + { + $this->ref_list[$id] = new learnpath($this->course_code,$id,$this->user_id); + } + $this->refs_active = true; + return $this->ref_list; + } + /** + * Gets a table of the different learnpaths we have at the moment + * @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...) + */ + function get_flat_list() + { + return $this->list; + } +} +?> diff --git a/main/newscorm/learnpath_functions.inc.php b/main/newscorm/learnpath_functions.inc.php index 8bf563dfd7..9d94e50e15 100644 --- a/main/newscorm/learnpath_functions.inc.php +++ b/main/newscorm/learnpath_functions.inc.php @@ -1713,7 +1713,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false //------------------------AGENDA BEGIN------------------- case "Agenda" : //1 Get agenda event data from the database table - $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); $sql = "SELECT * FROM ".$TABLEAGENDA." where (id=$item_id)"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -1788,7 +1788,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false //------------------------ANNOUNCEMENT BEGIN------------------- case "Ad_Valvas" : //1 Get the announcement data from the database - $tbl_announcement = Database :: get_course_announcement_table(); + $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $sql = "SELECT * FROM $tbl_announcement where id='$item_id'"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -1834,7 +1834,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false //------------------------Course_description BEGIN------------------- case "Course_description" : //1 Get course description data from database - $tbl_course_description = Database :: get_course_description_table(); + $tbl_course_description = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); $result = api_sql_query("SELECT id, title, content FROM ".$tbl_course_description." ORDER BY id", __FILE__, __LINE__); //2 Check this element @@ -1864,7 +1864,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false //------------------------DOCUMENT BEGIN------------------- case "Document" : //1 Get the document data from the database - $tbl_document = Database :: get_course_document_table(); + $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $sql_query = "SELECT * FROM $tbl_document WHERE id=$item_id"; $sql_result = api_sql_query($sql_query, __FILE__, __LINE__); $myrow = mysql_fetch_array($sql_result); @@ -1989,7 +1989,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false //------------------------HotPotatoes BEGIN------------------- case "HotPotatoes" : //1 Get HotPotatoes data from the document table - $tbl_document = Database :: get_course_document_table(); + $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $result = api_sql_query("SELECT * FROM $tbl_document WHERE id=$item_id", __FILE__, __LINE__); $myrow = mysql_fetch_array($result); //2 Get the document path diff --git a/main/newscorm/resourcelinker.inc.php b/main/newscorm/resourcelinker.inc.php index 56b67670f9..b679620ce2 100644 --- a/main/newscorm/resourcelinker.inc.php +++ b/main/newscorm/resourcelinker.inc.php @@ -1,2063 +1,2063 @@ -".get_lang('LevelUp').""; - } - if ($level and $level != 0 and $level != 1) - { - $folder_up=$folder; - $folder_temp=explode('/',$folder); - $last=count($folder_temp)-1; - unset($folder_temp[$last]); - $folder_up=implode('/',$folder_temp); - echo "".get_lang('LevelUp').""; - } -} - -/** - * Shows the documents of the document tool - * @param $folder - */ -function show_documents($folder) -{ - global $_course; - global $source_id, $action, $learnpath_id, $chapter_id, $originalresource; - - // documents are a special case: the teacher can add an invisible document (it will be viewable by the user) - // other tools do not have this feature. This only counts - if (is_allowed_to_edit()) - { - $visibility="visibility<>'2'"; - } - else - { - $visibility="visibility='1'"; - } - - $item_property_table = Database::get_course_table(ITEM_PROPERTY_TABLE); - $document_table = Database::get_course_table(DOCUMENT_TABLE); - $sql="SELECT * from $document_table, $item_property_table WHERE id=ref AND tool = '".TOOL_DOCUMENT."' AND $visibility AND to_group_id = 0 AND to_user_id IS NULL ORDER BY path ASC"; - $result=api_sql_query($sql,__FILE__,__LINE__); - while ($row=mysql_fetch_array($result)) - { - if (!$folder) - { - if (get_levels($row['path'])-1==1) - { - // showing the right icon - if (file_or_folder($row['path'])) - { - echo ''; - } - else - { - $image = choose_image($row['path']); - echo ""; - } - - // folders should be clickable - if (file_or_folder($row['path'])) - { - echo "".substr($row['path'],1).'
    '; - } - else - { - echo substr($row['path'],1).' '; - echo showorhide_addresourcelink('Document',$row['id']); - echo '
    '; - } - } - } - else - { - // we calculate the level we are in by using the $folder in the url - // we put +1 because it does not start with an / and in the database it does - $level=get_levels($folder)+1; - - // we calculate each level of the database entry - $file_level=get_levels($row['path'])-1; - // if the level of the database entry is equal to the level we ar in, we put it into an array - // as this is a potential good entry - if ($file_level==$level) - { - $good_paths[]=$row['path']; - $good_ids[]=$row['id']; - } - //$haystack=$row['path']; - //$conform_folder=strstr($haystack, $folder); - //if (str_replace($folder.'/','',$conform_folder)!==$folder) - // { - // $good_folders[]=$row['path']; - //echo str_replace($folder.'/','',$conform_folder); - // echo '
    '; - // }// if (str_replace($folder.'/','',$conform_folder)!==$folder) - } // else (if (!$folder)) - } //while ($row=mysql_fetch_array($result)) - - // this is code for the case that we are in a subfolder - if ($good_paths) - { - // we have all the potential good database entries, the good ones are those that start with $folder - foreach ($good_paths as $path) - { - if (strstr($path,$folder)) - { - $good_key=key($good_paths); - // showing the right icon - if (file_or_folder($path)) - { - echo ''; - } - else - { - $image = choose_image($path); - echo ""; - } - - // folders should be clickable - if (file_or_folder($path)) - { - $path=substr($path,1); // remove the first / in folder_up - $uri=str_replace($folder,$path,$_SERVER['REQUEST_URI']); - $newuri=str_replace('add=','addnot=',$uri); - //using the correct name of the folder - $folder_name=str_replace($folder.'/','',$path); - echo "".$folder_name.'
    '; - } - else - { - echo str_replace("/$folder/", '',$path).' '; - echo showorhide_addresourcelink('Document',$good_ids[$good_key]); - echo '
    '; - } - } - next($good_paths); - } - } -} - -/** - * Checks wether something is a file or a folder - * 0 means file, 1 means folder - * @param $filefolder - * @todo: use true and false instead of 1 and 0. - */ -function file_or_folder($filefolder) -{ - global $_course; - global $baseServDir; - - $courseDir = $_course['path'].'/document'; - $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir; - - return (is_dir($baseWorkDir.$filefolder) ? 1 : 0); -} - -/** - * Inserts a resource into the database - * - * @param $source_type - * @param $source_id - */ -function store_resources($source_type, $source_id) -{ - global $_course; - $resource_table = Database::get_course_table(LINKED_RESOURCES_TABLE); - - $addedresource = $_SESSION['addedresource']; - $addedresourceid = $_SESSION['addedresourceid']; - if ($_SESSION['addedresource']) - { - foreach ($addedresource as $resource_type) - { - $sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')"; - api_sql_query($sql,__FILE__,__LINE__); - $i=key($addedresource); - next($addedresource); - } - $_SESSION['addedresource']=''; - $_SESSION['addedresourceid']=''; - } -} - -/** - * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED - * Displays the link that opens a new browser window that views the added resource. - * - * @author Patrick Cool , Ghent University - * @param $type the type of the tool - * @param $id the id of the resource - * @param $style this is used to style the link (for instance when a resource is hidden => the added resources should also be styled like they are hidden) - * @todo use the constants for the type definitions. - */ -function display_addedresource_link($type, $id, $style='') -{ - global $_course; - - // styling the link of the added resource - if ($style <> '') - { - $styling = ' class="'.$style.'"'; - } - - switch ($type) - { - case 'Agenda': - $TABLEAGENDA = $_course['dbNameGlu'].'calendar_event'; - $result = api_sql_query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - echo ' '.$myrow['title']."
    \n"; - break; - case 'Ad_Valvas': - $tbl_announcement = $_course['dbNameGlu'].'announcement'; - $result = api_sql_query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - echo ' '.$myrow['title']."
    \n"; - break; - case 'Link': - $TABLETOOLLINK = $_course['dbNameGlu'].'link'; - $result = api_sql_query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - echo ' '.$myrow['title']."
    \n"; - break; - case 'Exercise': - $TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; - $result = api_sql_query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - echo ' '.$myrow['title']."
    \n"; - break; - case 'Forum': - $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; - $result = api_sql_query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - echo ' '.$myrow['forum_name']."
    \n"; - break; - case 'Thread': //=topics - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; - $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; - $result = api_sql_query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - // grabbing the title of the post - $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; - $result_title = api_sql_query($sql_title,__FILE__,__LINE__); - $myrow_title = mysql_fetch_array($result_title); - echo ' '.$myrow_title['post_title']."
    \n"; - break; - case 'Post': - $tbl_post = Database::get_course_table(TABLE_FORUM_POST); - $tbl_post_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE); - $sql = "SELECT * FROM $tbl_post p, $tbl_post_text t WHERE p.post_id = t.post_id AND p.post_id = $id"; - $result = api_sql_query($sql,__FILE__,__LINE__); - $post = mysql_fetch_object($result); - echo ' '.$post->post_title."
    \n"; - break; - case 'Document': - $dbTable = $_course['dbNameGlu'].'document'; - $result = api_sql_query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__); - $myrow = mysql_fetch_array($result); - $pathname = explode('/',$myrow['path']); // making a correct name for the link - $last = count($pathname) - 1; // making a correct name for the link - $filename = $pathname[$last]; // making a correct name for the link - $image = choose_image($filename); - $ext = explode('.',$filename); - $ext = strtolower($ext[sizeof($ext)-1]); - $myrow['path'] = rawurlencode($myrow['path']); - $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png')); - echo ' '.$filename."
    \n"; - break; - case 'Externallink': - echo ' '.$id."
    \n"; - break; - } -} - -/** -* This function is to display the added resources (lessons) in the learning path player and builder -* this function is a modification of display_addedresource_link($type, $id) function -* the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was -* building upon it. - Denes -* -* Parameters: -* @param completed - if ="completed" then green presentation with checkbox -* @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table -* @param id - that is the correspondent id in the mirror tool (like Agenda item 2) -* @param type - that is the correspondent type in the mirror tool (like this is a Link item) -* @param builder - if ="builder" then onclick shows in new window -* @param icon - if ="icon" then the small icon will appear -* if ="wrap" then wrapped settings are used (and no icon is displayed) -* if ="nolink" then only the name is returned with no href and no icon (note:only in this case, the result is not displayed, but returned) -* @todo this function is too long, rewrite -*/ -function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0) -{ - global $_course, $learnpath_id, $tbl_learnpath_item, $items; - global $curDirPath, $_configuration, $enableDocumentParsing, $_course, $_user, $_cid; - - $tbl_lp_item = Database::get_course_table('lp_item'); - $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"' - - $length = ((($builder == 'builder') and ($icon == 'nolink')) ? 65 : 32); - - if ($builder != 'builder') $origin = 'learnpath'; //origin = learnpath in student view - $linktype = $type; - if (($type == 'Link _self') or ($type == 'Link _blank')) $type = 'Link'; - - //YW switched litteral tool names to use of constants declared in main_api.lib.php - switch ($type) - { - case TOOL_CALENDAR_EVENT: - case "Agenda": - $TABLEAGENDA = $_course['dbNameGlu']."calendar_event"; - $result = api_sql_query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["title"]=$row['title']; } - $desc=$row['description']; - $agenda_id=$row['item_id']; - echo str_repeat(" >",$level); - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($myrow["title"]=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); } - if ($icon == 'icon') { echo "agenda"; } - if ($builder != 'builder') - { - echo "".shorten($myrow["title"],($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($myrow["title"],($length-3*$level)).""; - } - break; - - case TOOL_ANNOUNCEMENT: - case "Ad_Valvas": - $tbl_announcement = $_course['dbNameGlu']."announcement"; - $result = api_sql_query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["content"]=$row['title']; } - $desc=$row['description']; - $ann_id=$row['item_id']; - echo str_repeat(" >",$level); - - // the title and the text are in the content field and we only want to display the title - list($title, $text)=split('
    ',$myrow['content']); - if ($title=='') { $title=$myrow['content']; } - $title=$myrow['title']; - $text=$myrow['content']; - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($title=='') { - $type="Announcement"; - echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; - return(true); - } - - if ($icon == 'nolink') { return(shorten($title,$length)); } - if ($icon == 'icon') { echo "ad valvas"; } - if ($builder != 'builder') - { - echo "".shorten($title,($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($title,($length-3*$level)).""; - } - break; - - case TOOL_LINK: - case "Link" : - $TABLETOOLLINK = $_course['dbNameGlu']."link"; - $result= api_sql_query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["title"]=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($myrow["title"]=='') - { - echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; - return(true); - } - - if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); } - if ($icon == 'icon') - { - if ($linktype=='Link _self') { echo "links"; } - else { echo "blank links"; } - } - $thelink=$myrow["url"]; - if ($builder != 'builder') - { - echo "".shorten($myrow["title"],($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($myrow["title"],($length-3*$level)).""; - } - break; - - case TOOL_QUIZ: - case "Exercise": - $TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; - $result= api_sql_query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - if ($builder=='builder') { $origin='builder'; } - //this is needed for the exercise_submit.php can delete the session info about tests - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); - $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["title"]=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($myrow["title"]=='') { - echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; - return(true); - } - - if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); } - if ($icon == 'icon') { echo "quizz"; } - if ($builder != 'builder') - { - echo "".shorten($myrow["title"],($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($myrow["title"],($length-3*$level)).""; - } - break; - - case 'hotpotatoes': - case "HotPotatoes": - $TBL_DOCUMENT = $_course['dbNameGlu'].'document'; - $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'; - $result = api_sql_query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id"); - $myrow= mysql_fetch_array($result); - $path=$myrow["path"]; - $name=GetQuizName($path,$documentPath); - - if ($builder=='builder') { $origin='builder'; } - //this is needed for the exercise_submit.php can delete the session info about tests - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo "hot potatoes"; } - - $cid = $_course['official_code']; - - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo " ".shorten($name,($length-3*$level)).""; - } - break; - - case TOOL_FORUM: - case "Forum": - $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; - $result= api_sql_query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($myrow["forum_name"]=='') { $type="Forum"; echo "".get_lang('StepDeleted1')." $type ".get_lang('step_deleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($myrow["forum_name"],$length)); } - if ($icon == 'icon') { echo "forum"; } - $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; - if ($builder != 'builder') - { - echo "".shorten($myrow["forum_name"],($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($myrow["forum_name"],($length-3*$level)).""; - } - break; - - case TOOL_THREAD: - case "Thread": //forum post - $tbl_topics = $_course['dbNameGlu'].'bb_topics'; - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; - $sql="SELECT * FROM `$tbl_topics` where topic_id=$id"; - $result= api_sql_query($sql,__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($myrow["topic_title"]=='') { $type="Forum Post"; echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($myrow["topic_title"],$length)); } - if ($icon == 'icon') { echo "forum"; } - if ($builder != 'builder') - { - echo "".shorten($myrow["topic_title"],($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($myrow["topic_title"],($length-3*$level)).""; - } - break; - - case TOOL_POST: - case "Post": - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; - $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; - $result= api_sql_query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - // grabbing the title of the post - $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; - $result_titel=api_sql_query($sql_titel,__FILE__,__LINE__); - $myrow_titel=mysql_fetch_array($result_titel); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - $posternom=$myrow['nom']; $posterprenom=$myrow['prenom']; - $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text']; - $posttitle=$myrow_titel['post_title']; - $posttext = str_replace('"',"'",$posttext); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($myrow_titel["post_title"]=='') - { - $type="Forum"; - echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); - } - - if ($icon == 'nolink') { return(shorten($myrow_titel["post_title"],$length)); } - if ($icon == 'icon') { echo "forum"; } - if ($builder != 'builder') - { - echo "".shorten($myrow_titel["post_title"],($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($myrow_titel["post_title"],($length-3*$level)).""; - } - break; - - case TOOL_DOCUMENT: - case "Document": - $dbTable = $_course['dbNameGlu']."document"; - $mysql = "SELECT * FROM `$dbTable` WHERE id=$id"; - //error_log('New LP - Querying document table: '.$mysql,0); - $result = api_sql_query($mysql,__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $pathname=explode("/",$myrow["path"]); // making a correct name for the link - $last=count($pathname)-1; // making a correct name for the link - $filename=$pathname[$last]; // making a correct name for the link - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - echo str_repeat(" >",$level); - - if ($icon != 'nolink') { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - $image=choose_image($filename); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - //error_log('New LP - Querying lp_item table: '.$sql,0); - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $filename=$row['title']; } - $desc=$row['description']; - - if (($myrow["path"]=='') and ($filename=='')) { - echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; - return(true); - } - - if ($icon == 'nolink') { return(shorten($filename,$length)); } - if ($icon == 'icon') { echo "$image"; } - if ($builder != 'builder') - { - echo "".shorten($filename,($length-3*$level)).""; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path"; - } - else - { - $enableDocumentParsing=yes; - if (!$enableDocumentParsing) - { //this is the solution for the non-parsing version in the builder - $file=urlencode($myrow["path"]); - echo "".shorten($filename,($length-3*$level)).""; - } - else - { - echo "".shorten($filename,($length-3*$level)).""; - } - } - break; - - case 'assignments': - case "Assignments": - $name=get_lang('Assignments'); - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') - { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') - { - echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); - } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo ""; } - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path"; - if ($desc != '') - { - if ($icon != 'wrap') - { - echo "
      ".shorten($desc,($length-3*$level))."
    "; - } - else - { - echo "
         ".shorten($desc,($length-3*$level))."
    "; - } - } - } - else - { - echo "".shorten($name,($length-3*$level)).""; - } - break; - - case TOOL_DROPBOX: - case "Dropbox": - $name=get_lang('Dropbox'); - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo ""; } - - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path"; - if ($desc != '') { - if ($icon != 'wrap') { - echo "
      ".shorten($desc,($length-3*$level))."
    "; } - else { - echo "
         ".shorten($desc,($length-3*$level))."
    "; } - } - } else { - echo "".shorten($name,($length-3*$level)).""; - } - break; - - case 'introduction_text': - case "Introduction_text": - $name=get_lang('IntroductionText'); - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo "introduction"; } - - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; - $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path"; - if ($desc != '') { - if ($icon != 'wrap') { - echo "
      ".shorten($desc,($length-3*$level))."
    "; } - else { - echo "
         ".shorten($desc,($length-3*$level))."
    "; } - } - } else { - $s=api_get_path('WEB_COURSE_PATH')."$_cid/index.php?intro_cmdEdit=1"; - echo "".shorten($name,($length-3*$level)).""; - } - break; - - case TOOL_COURSE_DESCRIPTION: - case "Course_description": - $name=get_lang('CourseDescription'); - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo "info"; } - - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path"; - if ($desc != '') { - if ($icon != 'wrap') { - echo "
      ".shorten($desc,($length-3*$level))."
    "; } - else { - echo "
         ".shorten($desc,($length-3*$level))."
    "; } - } - } else { - $s=api_get_path('WEB_CODE_PATH')."course_description"; - echo "".shorten($name,($length-3*$level)).""; - } - break; - - case TOOL_GROUP: - case "Groups": - $name=get_lang('Groups'); - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo "group"; } - - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path"; - if ($desc != '') { - if ($icon != 'wrap') { - echo "
      ".shorten($desc,($length-3*$level))."
    "; } - else { - echo "
         ".shorten($desc,($length-3*$level))."
    "; } - } - } else { - echo "".shorten($name,($length-3*$level)).""; - } - break; - - case TOOL_USER: - case "Users": - $name=get_lang('Users'); - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $name=$row['title']; } - $desc=$row['description']; - echo str_repeat(" >",$level); - - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - if ($icon != 'nolink') { - if ($completed=='completed') { - echo "on"; - } else { - echo "on"; - //echo " "; - } - } - if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - - if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } - - if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo "members"; } - - if ($builder != 'builder') - { - echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path"; - if ($desc != '') { - if ($icon != 'wrap') { - echo "
      ".shorten($desc,($length-3*$level))."
    "; } - else { - echo "
         ".shorten($desc,($length-3*$level))."
    "; } - } - } else { - echo "".shorten($name,($length-3*$level)).""; - } - break; - }//end huge switch-statement -} - -/** -* This function is to create and return a link to the added resources (lessons). -* It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display -* anything. -* -* Parameters: -* @param type - that is the correspondent type in the mirror tool (like this is a Link item) -* @param id - that is the correspondent id in the mirror tool (like Agenda item 2) -* @param id_in_path - the unique index in the items table -*/ -function get_addedresource_link_in_learnpath($type, $id, $id_in_path) -{ - global $_course, $learnpath_id, $tbl_learnpath_item, $items; - global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid; - - $tbl_lp_item = Database::get_course_table('lp_item'); - $hyperlink_target_parameter = ""; //or e.g. target='_blank' - $builder = 'player'; - $origin='learnpath'; - - $linktype=$type; - if (($type=="Link _self") or ($type=="Link _blank")) { $type="Link"; } - - $link = ''; - - switch ($type) - { - case "Agenda": - $TABLEAGENDA = $_course['dbNameGlu']."calendar_event"; - $result = api_sql_query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["title"]=$row['title']; } - $desc=$row['description']; - $agenda_id=$row['item_id']; - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path"; - } - else - { - $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id"; - } - break; - - case "Ad_Valvas": - $tbl_announcement = Database::get_course_announcement_table(); - $result = api_sql_query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$id#$id_in_path"; - } - else - { - $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id"; - } - break; - - case "Link" : - $TABLETOOLLINK = $_course['dbNameGlu']."link"; - $result= api_sql_query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - - $thelink=$myrow["url"]; - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path"; - } - else - { - $link .= $thelink; - } - break; - - case "Exercise": - $TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; - $result= api_sql_query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - if ($builder=='builder') { $origin='builder'; } - //this is needed for the exercise_submit.php can delete the session info about tests - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["title"]=$row['title']; } - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path"; - } - else - { - $link .= "../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow["id"]; - } - break; - - case "HotPotatoes": - $TBL_DOCUMENT = $_course['dbNameGlu'].'document'; - $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'; - $result = api_sql_query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id"); - $myrow= mysql_fetch_array($result); - $path=$myrow["path"]; - $name=GetQuizName($path,$documentPath); - - if ($builder=='builder') { $origin='builder'; } - - $cid = $_course['official_code']; - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path"; - } - else - { - $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']; - } - break; - - case "Forum": - $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; - $result= api_sql_query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - if ($builder=='builder') { $origin='builder'; } - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; } - - if ($myrow["forum_name"]=='') { $type="Forum"; } - - $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path"; - } - else - { - $link .= "../phpbb/viewforum.php?$forumparameters"; - } - break; - - case "Thread": //forum post - $tbl_topics = $_course['dbNameGlu'].'bb_topics'; - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; - $sql="SELECT * FROM `$tbl_topics` where topic_id=$id"; - $result= api_sql_query($sql,__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path"; - } - else - { - $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; - } - break; - - case "Post": - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; - $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; - $result= api_sql_query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - // grabbing the title of the post - $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; - $result_titel=api_sql_query($sql_titel,__FILE__,__LINE__); - $myrow_titel=mysql_fetch_array($result_titel); - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; } - $desc=$row['description']; - $link .= str_repeat(" >",$level); - - $posternom=$myrow['nom']; $posterprenom=$myrow['prenom']; - $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text']; - $posttitle=$myrow_titel['post_title']; - $posttext = str_replace('"',"'",$posttext); - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path"; - } - else - { - $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; - } - break; - - case "Document": - $dbTable = $_course['dbNameGlu']."document"; - $result=api_sql_query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__); - $myrow=mysql_fetch_array($result); - - $pathname=explode("/",$myrow["path"]); // making a correct name for the link - $last=count($pathname)-1; // making a correct name for the link - $filename=$pathname[$last]; // making a correct name for the link - - $sql="select * from $tbl_lp_item where id=$id_in_path"; - $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path"; - - } - else - { - $enableDocumentParsing=yes; - if (!$enableDocumentParsing) - { //this is the solution for the non-parsing version in the builder - $file=urlencode($myrow["path"]); - $link .= "../document/showinframes.php?file=$file"; - } - else - { - $link .= "../document/download.php?doc_url=".$myrow["path"]; - } - } - break; - - case "Assignments": - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path"; - } - else - { - $link .= "../work/work.php"; - } - break; - case "Dropbox": - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path"; - } else { - $link .= "../dropbox/index.php"; - } - break; - case "Introduction_text": - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path"; - } else { - $s=api_get_path('WEB_COURSE_PATH')."$_cid/index.php?intro_cmdEdit=1"; - $link .= $s; - } - break; - case "Course_description": - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path"; - } else { - $s=api_get_path('WEB_CODE_PATH')."course_description"; - $link .= $s; - } - break; - case "Groups": - - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path"; - } else { - $link .= "../group/group.php?origin=$origin"; - } - break; - case "Users": - if ($builder != 'builder') - { - $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path"; - } else { - $link .= "../user/user.php?origin=$origin"; - } - break; - }//end huge switch-statement - return $link; -} - -/** -* This function is to remove an resource item from the array -*/ -function remove_resource($resource_key) -{ - $addedresource = $_SESSION['addedresource']; - $addedresourceid = $_SESSION['addedresourceid']; - unset($addedresource[$resource_key]); - unset($addedresourceid[$resource_key]); - $_SESSION['addedresource']=$addedresource; - $_SESSION['addedresourceid']=$addedresourceid ; -} - -/** -* This function is to show the button "click to add resource" on the tool page -* @author Patrick Cool , Ghent University -*/ -function show_addresource_button($additionalparameters = '') -{ - echo ''; -} - -/** -* this function is to delete ONE specific resource that were added to a specific item -*/ -function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id) -{ - echo "delete_one_added_resource"; - global $_course; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - - $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'"; - api_sql_query($sql,__FILE__,__LINE__); -} - -/** -* this function is to delete the resources that were added to a specific item -*/ -function delete_added_resource($type, $id) -{ - global $_course; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - - $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'"; - api_sql_query($sql,__FILE__,__LINE__); -} - -/** -* this function is te delete all resources of a specific type (only used in announcements -- delete all) -* Author : Frederik Vermeire -*/ -function delete_all_resources_type($type) -{ - global $_course; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - - $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type'"; - - api_sql_query($sql,__FILE__,__LINE__); -} - -/** -* this function checks wether there are added resources or not -*/ -function check_added_resources($type, $id) -{ - global $_course, $origin; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'"; - $result=api_sql_query($sql,__FILE__,__LINE__); - $number_added=mysql_num_rows($result); - if ($number_added<>0) - return true; - else - return false; -} - - -/** -* this function is to load the resources that were added to a specific item -* into the session variables -*/ -function edit_added_resources($type, $id) -{ - global $_course; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - - $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id=$id"; - $result=api_sql_query($sql,__FILE__,__LINE__); - while ($row=mysql_fetch_array($result)) - { - $addedresource[]=$row["resource_type"]; - $addedresourceid[]=$row["resource_id"]; - } - $_SESSION['addedresource']=$addedresource; - $_SESSION['addedresourceid']=$addedresourceid; -} - -/** -* this function is store the modified resources -* first we delete all the added resources in the database, -* then we add all the resources from the session object. -*/ -function update_added_resources($type, $id) -{ - global $_course; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - // delete all the added resources for this item in the database; - $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' AND source_id='$id'"; - //echo $sql; - api_sql_query($sql,__FILE__,__LINE__); - - // store the resources from the session into the database - store_resources($type, $id); - - //delete_added_resource_($type, $id); - unset_session_resources(); -} - -/** -* this function is to display the resources that were added to a specific item -*/ -function display_added_resources($type, $id, $style='') -{ - // the array containing the icons - $arr_icons=array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' ); - - global $_course, $origin; - $TABLERESOURCE = $_course['dbNameGlu']."resource"; - - $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'"; - $result=api_sql_query($sql,__FILE__,__LINE__); - while ($row=mysql_fetch_array($result)) - { - if ($origin != 'learnpath') - { - display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ; - } - else - { - display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "
    "; - } - } -} - - -/** -* This function is to show the added resources when adding an item -* $showdeleteimg determine if the delete image should appear or not. -* deleting an added resource is only possible through the resource linker file itself -*/ -function display_resources($showdeleteimg) -{ - global $action; - global $resourceaction; - global $id; - global $locationkey; - global $source_id, $action, $learnpath_id, $chapter_id, $originalresource; - - if ($resourceaction=="removeresource") - { - remove_resource($locationkey); - } - $addedresource=$_SESSION['addedresource']; - $addedresourceid=$_SESSION['addedresourceid']; - if (is_array($addedresource)) - { - echo ''; - foreach ($addedresource as $resource) - { - echo ''; - next($addedresource); - } - echo '
    '; - display_addedresource_link($resource,$addedresourceid[key($addedresource)]); - echo ''; - - // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource - // should also contain this id. - $test=parse_url($_SERVER['REQUEST_URI']); - $output = array(); - parse_str($test[query],$output); - - if ($showdeleteimg==1) - { - echo "resource ".get_lang(
    "; - } - echo '
    '; - } - else // it is a string - { - echo ''; - } -} // end of the display_resources function - - -/** -* This function checks wether the link add resource should be displayed next the item in the linker page -* So we have to check if the specific id of that tool is already in the array of the added resources -* if it is already in, the link should not be showed since it would make it possible to add -* the same resource a second time (=duplication of added resources) -*/ -function showorhide_addresourcelink($type, $id) -{ - global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target; - $addedresource=$_SESSION['addedresource']; - $addedresourceid=$_SESSION['addedresourceid']; - - if (is_array($_SESSION['addedresource'])) - { - foreach ($addedresource as $toolcompare) - { - if ($toolcompare==$type and $addedresourceid[key($addedresource)]==$id) - { - $show=0; - } - next($addedresource); - } - if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); } - if ($show!==0) - { - if ($type=="Document") - { - echo "".$lang_add_it_or_resource.""; - } - else - { - echo "".$lang_add_it_or_resource.""; - } - } - } - else // if it is not an array, it is a string - { - if ($_SESSION['addedresource']!==$type or $_SESSION['addedresourceid']!==$id) - { - if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); } - echo "".$lang_add_it_or_resource.""; - } - } -} - -/** - * Gets the link to the given added resource. - * - * @author Patrick Cool , Ghent University - * @author Yannick Warnier , Dokeos - rebranding - * @param string Course code - * @param string The tool type (using constants declared in main_api.lib.php) - * @param integer The resource ID - * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden) - * @param boolean Open in a new window (true) or in the current frame/window (false)? - * @todo use the constants for the type definitions. - */ -function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_window=true) -{ - //$_course = Database::get_course_info($course_code); - $_course = Database::get_course_info_from_code($course_code); - - // styling the link of the added resource - if ($style <> '') $styling = ' class="'.$style.'"'; - if($new_window == true){ $target = ' target = "_blank" ';}else{$target = ' target = "_self" ';} - - $output = ''; - - switch ($type) - { - case TOOL_CALENDAR_EVENT: - $TABLEAGENDA = Database::get_course_table(AGENDA_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $TABLEAGENDA WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = ' '.$myrow['title']."
    \n"; - break; - case TOOL_ANNOUNCEMENT: - $tbl_announcement = Database::get_course_table(ANNOUNCEMENT_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = ' '.$myrow['title']."
    \n"; - break; - case TOOL_LINK: - //doesn't take $target into account - $TABLETOOLLINK = Database::get_course_table(LINK_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = ' '.$myrow['title']."
    \n"; - break; - case TOOL_QUIZ: - $TBL_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $TBL_EXERCICES WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = ' '.$myrow['title']."
    \n"; - break; - case TOOL_FORUM: - $TBL_FORUMS = Database::get_course_table(TOOL_FORUM,$_course['database']); - $result = api_sql_query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = ' '.$myrow['forum_name']."
    \n"; - break; - case TOOL_THREAD: //=topics - if(!empty($_SESSION['dokeos_version']) AND $_SESSION['dokeos_version']>=1.8){ - //$tbl_forum = Database::get_course_table(TABLE_FORUM,$_course['database']); - //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']); - $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); - // grabbing the title of the post - $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id; - $result_title = api_sql_query($sql_title,__FILE__,__LINE__); - $myrow_title = Database::fetch_array($result_title); - $output = ' '.$myrow_title['post_title']."
    \n"; - }else{//older dokeos versions - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; - $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; - $result = api_sql_query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - // grabbing the title of the post - $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; - $result_title = api_sql_query($sql_title,__FILE__,__LINE__); - $myrow_title = Database::fetch_array($result_title); - $output = ' '.$myrow_title['post_title']."
    \n"; - } - break; - case TOOL_POST: - $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); - //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE); - $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id"; - $result = api_sql_query($sql,__FILE__,__LINE__); - $post = Database::fetch_array($result); - $output = ' '.$post['post_title']."
    \n"; - break; - case TOOL_DOCUMENT: - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $tbl_doc WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $pathname = explode('/',$myrow['path']); // making a correct name for the link - $last = count($pathname) - 1; // making a correct name for the link - $filename = $pathname[$last]; // making a correct name for the link - $image = choose_image($filename); - $ext = explode('.',$filename); - $ext = strtolower($ext[sizeof($ext)-1]); - $myrow['path'] = rawurlencode($myrow['path']); - $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png')); - $output = ' '.$filename."
    \n"; - break; - /* - case 'Externallink': - $output = ' '.$id."
    \n"; - break; - */ - } - return $output; -} -/** -* Returns an HTML-formatted link to a resource, to incorporate directly into -* the new learning path tool. -* -* The function is a big switch on tool type. -* In each case, we query the corresponding table for information and build the link -* with that information. -* @author Yannick Warnier - rebranding based on previous work (display_addedresource_link_in_learnpath()) -* @param string Course code -* @param integer The learning path ID (in lp table) -* @param integer The database ID for that item in the lp_item table -* @param -* @param string Type (as one of the TOOL_ constants declared in main_api.lib.php) -* @param integer ID of the database item to get (from that tool's table) -* @param id - that is the correspondent id in the mirror tool (like Agenda item 2) -* @param id_in_path - the unique index in the items table -*/ -function rl_get_resource_link_for_learnpath($course_code, $learnpath_id, $id_in_path) -{ - //error_log('In rl_get_resource_link_for_learnpath()',0); - global $my_version; //added global variable just for cross compatibility. I hate it. - if($my_version=='1.8'){ - $_course = Database::get_course_info($course_code); - }else{ - $_course = Database::get_course_info_from_code($course_code); - } - - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql_item = "SELECT * FROM $tbl_lp_item " . - "WHERE lp_id = $learnpath_id AND id = $id_in_path"; - $res_item = api_sql_query($sql_item,__FILE__,__LINE__); - if(Database::num_rows($res_item<1)) return -1; //exit - $row_item = Database::fetch_array($res_item); - - $type = strtolower($row_item['item_type']); - $id = $row_item['path']; - - $origin='learnpath'; - $main_dir_path = api_get_path(WEB_CODE_PATH); - $main_course_path = api_get_path(WEB_COURSE_PATH).$_course['directory'].'/'; - - $link = ''; - - switch ($type) - { - case 'dokeos_chapter': - $link .= $main_dir_path.'newscorm/blank.php'; - case TOOL_CALENDAR_EVENT: - $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id; - break; - - case TOOL_ANNOUNCEMENT: - $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id; - break; - - case TOOL_LINK: - $TABLETOOLLINK = Database::get_course_table(LINK_TABLE,$_course['database']); - $result= api_sql_query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__); - $myrow=Database::fetch_array($result); - $thelink=$myrow["url"]; - $link .= $thelink; - break; - - case TOOL_QUIZ: - $TBL_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE,$_course['database']); - $sql = "SELECT * FROM $TBL_EXERCICES WHERE id=$id"; - $result= api_sql_query($sql,__FILE__,__LINE__); - $myrow=Database::fetch_array($result); - - if ($row_item['title'] != '') { $myrow["title"]=$row_item['title']; } - $link .= $main_dir_path.'exercice/exercice_submit.php?lp_init=1&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&exerciseId='.$id; - break; - - case "hotpotatoes": //lowercase because of strtolower above - - $TBL_DOCUMENT = Database::get_course_table(DOCUMENT_TABLE); - $result = api_sql_query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id",__FILE__,__LINE__); - $myrow= Database::fetch_array($result); - $path=$myrow["path"]; - $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' . - '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' . - '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path; - break; - - case TOOL_FORUM: - $link .= $main_dir_path.'phpbb/viewforum.php?forum='.$id.'&lp=true'; - break; - - case TOOL_THREAD: //forum post - $tbl_topics = Database::get_course_table(TOOL_FORUM_THREAD,$_course['database']); - $sql="SELECT * FROM $tbl_topics where thread_id=$id"; - $result= api_sql_query($sql,__FILE__,__LINE__); - $myrow=Database::fetch_array($result); - $link .= $main_dir_path.'phpbb/viewtopic.php?topic='.$id.'' . - '&forum='.$myrow['forum_id'].'&lp=true'; - break; - - case TOOL_POST: - $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); - $result= api_sql_query("SELECT * FROM $tbl_post where post_id=$id",__FILE__,__LINE__); - $myrow=Database::fetch_array($result); - $title=$myrow['post_title']; - - $desc=$row_item['description']; - - $posternom=$myrow['poster_name']; - $posttime=$myrow['post_date']; - $posttext=$myrow['post_text']; - $posttitle=$title; - $posttext = str_replace('"',"'",$posttext); - - $link .= $main_dir_path.'phpbb/viewpost.php?post='.$id.'' . - '&topic='.$myrow['topic_id'].'&forum='.$myrow['forum_id'].'' . - '&lp=true'; - break; - - case TOOL_DOCUMENT: - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE,$_course['database']); - $sql = "SELECT * FROM $tbl_doc WHERE id=$id"; - $result=api_sql_query($sql,__FILE__,__LINE__); - $myrow=Database::fetch_array($result); - $docurl=$myrow['path']; - $link .= $main_course_path.'document'.$docurl; - $openmethod=2; - $officedoc=false; - api_session_register('openmethod'); - api_session_register('officedoc'); - break; - - case "assignments": - $link .= $main_dir_path.'work/work.php?origin='.$origin; - break; - case TOOL_DROPBOX: - $link .= $main_dir_path.'dropbox/index.php?origin=learnpath'; - break; - case "introduction_text": //DEPRECATED - $link .= ''; - break; - case TOOL_COURSE_DESCRIPTION: - $link .= $main_dir_path.'course_description?origin='.$learnpath; - break; - case TOOL_GROUP: - $link .= $main_dir_path.'group/group.php?origin='.$origin; - break; - case TOOL_USER: - $link .= $main_dir_path.'user/user.php?origin='.$origin; - break; - }//end switch - return $link; -} -/** - * Gets the name of a resource (generally used in learnpath when no name is provided) - * - * @author Yannick Warnier , Dokeos - rebranding - * @param string Course code - * @param string The tool type (using constants declared in main_api.lib.php) - * @param integer The resource ID - */ -function rl_get_resource_name($course_code, $learnpath_id, $id_in_path) -{ - global $my_version; - if($my_version == '1.8'){ - $_course = Database::get_course_info($course_code); - }else{ - $_course = Database::get_course_info_from_code($course_code); - } - - $tbl_lp_item = Database::get_course_table('lp_item'); - - $sql_item = "SELECT * FROM $tbl_lp_item " . - "WHERE lp_id = $learnpath_id AND id = $id_in_path"; - $res_item = api_sql_query($sql_item,__FILE__,__LINE__); - if(Database::num_rows($res_item<1)) return ''; //exit - $row_item = Database::fetch_array($res_item); - $type = strtolower($row_item['item_type']); - $id = $row_item['ref']; - $output = ''; - - switch ($type) - { - case TOOL_CALENDAR_EVENT: - $TABLEAGENDA = Database::get_course_table(AGENDA_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $TABLEAGENDA WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = $myrow['title']; - break; - case TOOL_ANNOUNCEMENT: - $tbl_announcement = Database::get_course_table(ANNOUNCEMENT_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = $myrow['title']; - break; - case TOOL_LINK: - //doesn't take $target into account - $TABLETOOLLINK = Database::get_course_table(LINK_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = $myrow['title']; - break; - case TOOL_QUIZ: - $TBL_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $TBL_EXERCICES WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = $myrow['title']; - break; - case TOOL_FORUM: - $TBL_FORUMS = Database::get_course_table(TOOL_FORUM,$_course['database']); - $result = api_sql_query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $output = $myrow['forum_name']; - break; - case TOOL_THREAD: //=topics - if(!empty($_SESSION['dokeos_version']) AND $_SESSION['dokeos_version']>=1.8){ - //$tbl_forum = Database::get_course_table(TABLE_FORUM,$_course['database']); - //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']); - $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); - // grabbing the title of the post - $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id; - $result_title = api_sql_query($sql_title,__FILE__,__LINE__); - $myrow_title = Database::fetch_array($result_title); - $output = $myrow_title['post_title']; - }else{//older dokeos versions - $tbl_posts = $_course['dbNameGlu'].'bb_posts'; - $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; - $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; - $result = api_sql_query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - // grabbing the title of the post - $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; - $result_title = api_sql_query($sql_title,__FILE__,__LINE__); - $myrow_title = Database::fetch_array($result_title); - $output = $myrow_title['post_title']; - } - break; - case TOOL_POST: - $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); - //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE); - $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id"; - $result = api_sql_query($sql,__FILE__,__LINE__); - $post = Database::fetch_array($result); - $output = $post['post_title']; - break; - case TOOL_DOCUMENT: - case 'hotpotatoes': - $tbl_doc = Database::get_course_table(DOCUMENT_TABLE,$_course['database']); - $result = api_sql_query("SELECT * FROM $tbl_doc WHERE id=$id",__FILE__,__LINE__); - $myrow = Database::fetch_array($result); - $pathname = explode('/',$myrow['path']); // making a correct name for the link - $last = count($pathname) - 1; // making a correct name for the link - $filename = $pathname[$last]; // making a correct name for the link - $image = choose_image($filename); - $ext = explode('.',$filename); - $ext = strtolower($ext[sizeof($ext)-1]); - $myrow['path'] = rawurlencode($myrow['path']); - $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png')); - $output = $filename; - break; - /* - case 'externallink': - $output = ' '.$id."
    \n"; - break; - */ - } - - return stripslashes($output); -} -?> +".get_lang('LevelUp').""; + } + if ($level and $level != 0 and $level != 1) + { + $folder_up=$folder; + $folder_temp=explode('/',$folder); + $last=count($folder_temp)-1; + unset($folder_temp[$last]); + $folder_up=implode('/',$folder_temp); + echo "".get_lang('LevelUp').""; + } +} + +/** + * Shows the documents of the document tool + * @param $folder + */ +function show_documents($folder) +{ + global $_course; + global $source_id, $action, $learnpath_id, $chapter_id, $originalresource; + + // documents are a special case: the teacher can add an invisible document (it will be viewable by the user) + // other tools do not have this feature. This only counts + if (is_allowed_to_edit()) + { + $visibility="visibility<>'2'"; + } + else + { + $visibility="visibility='1'"; + } + + $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); + $document_table = Database::get_course_table(TABLE_DOCUMENT); + $sql="SELECT * from $document_table, $item_property_table WHERE id=ref AND tool = '".TOOL_DOCUMENT."' AND $visibility AND to_group_id = 0 AND to_user_id IS NULL ORDER BY path ASC"; + $result=api_sql_query($sql,__FILE__,__LINE__); + while ($row=mysql_fetch_array($result)) + { + if (!$folder) + { + if (get_levels($row['path'])-1==1) + { + // showing the right icon + if (file_or_folder($row['path'])) + { + echo ''; + } + else + { + $image = choose_image($row['path']); + echo ""; + } + + // folders should be clickable + if (file_or_folder($row['path'])) + { + echo "".substr($row['path'],1).'
    '; + } + else + { + echo substr($row['path'],1).' '; + echo showorhide_addresourcelink('Document',$row['id']); + echo '
    '; + } + } + } + else + { + // we calculate the level we are in by using the $folder in the url + // we put +1 because it does not start with an / and in the database it does + $level=get_levels($folder)+1; + + // we calculate each level of the database entry + $file_level=get_levels($row['path'])-1; + // if the level of the database entry is equal to the level we ar in, we put it into an array + // as this is a potential good entry + if ($file_level==$level) + { + $good_paths[]=$row['path']; + $good_ids[]=$row['id']; + } + //$haystack=$row['path']; + //$conform_folder=strstr($haystack, $folder); + //if (str_replace($folder.'/','',$conform_folder)!==$folder) + // { + // $good_folders[]=$row['path']; + //echo str_replace($folder.'/','',$conform_folder); + // echo '
    '; + // }// if (str_replace($folder.'/','',$conform_folder)!==$folder) + } // else (if (!$folder)) + } //while ($row=mysql_fetch_array($result)) + + // this is code for the case that we are in a subfolder + if ($good_paths) + { + // we have all the potential good database entries, the good ones are those that start with $folder + foreach ($good_paths as $path) + { + if (strstr($path,$folder)) + { + $good_key=key($good_paths); + // showing the right icon + if (file_or_folder($path)) + { + echo ''; + } + else + { + $image = choose_image($path); + echo ""; + } + + // folders should be clickable + if (file_or_folder($path)) + { + $path=substr($path,1); // remove the first / in folder_up + $uri=str_replace($folder,$path,$_SERVER['REQUEST_URI']); + $newuri=str_replace('add=','addnot=',$uri); + //using the correct name of the folder + $folder_name=str_replace($folder.'/','',$path); + echo "".$folder_name.'
    '; + } + else + { + echo str_replace("/$folder/", '',$path).' '; + echo showorhide_addresourcelink('Document',$good_ids[$good_key]); + echo '
    '; + } + } + next($good_paths); + } + } +} + +/** + * Checks wether something is a file or a folder + * 0 means file, 1 means folder + * @param $filefolder + * @todo: use true and false instead of 1 and 0. + */ +function file_or_folder($filefolder) +{ + global $_course; + global $baseServDir; + + $courseDir = $_course['path'].'/document'; + $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir; + + return (is_dir($baseWorkDir.$filefolder) ? 1 : 0); +} + +/** + * Inserts a resource into the database + * + * @param $source_type + * @param $source_id + */ +function store_resources($source_type, $source_id) +{ + global $_course; + $resource_table = Database::get_course_table(LINKED_RESOURCES_TABLE); + + $addedresource = $_SESSION['addedresource']; + $addedresourceid = $_SESSION['addedresourceid']; + if ($_SESSION['addedresource']) + { + foreach ($addedresource as $resource_type) + { + $sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')"; + api_sql_query($sql,__FILE__,__LINE__); + $i=key($addedresource); + next($addedresource); + } + $_SESSION['addedresource']=''; + $_SESSION['addedresourceid']=''; + } +} + +/** + * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED + * Displays the link that opens a new browser window that views the added resource. + * + * @author Patrick Cool , Ghent University + * @param $type the type of the tool + * @param $id the id of the resource + * @param $style this is used to style the link (for instance when a resource is hidden => the added resources should also be styled like they are hidden) + * @todo use the constants for the type definitions. + */ +function display_addedresource_link($type, $id, $style='') +{ + global $_course; + + // styling the link of the added resource + if ($style <> '') + { + $styling = ' class="'.$style.'"'; + } + + switch ($type) + { + case 'Agenda': + $TABLEAGENDA = $_course['dbNameGlu'].'calendar_event'; + $result = api_sql_query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + echo ' '.$myrow['title']."
    \n"; + break; + case 'Ad_Valvas': + $tbl_announcement = $_course['dbNameGlu'].'announcement'; + $result = api_sql_query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + echo ' '.$myrow['title']."
    \n"; + break; + case 'Link': + $TABLETOOLLINK = $_course['dbNameGlu'].'link'; + $result = api_sql_query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + echo ' '.$myrow['title']."
    \n"; + break; + case 'Exercise': + $TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; + $result = api_sql_query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + echo ' '.$myrow['title']."
    \n"; + break; + case 'Forum': + $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; + $result = api_sql_query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + echo ' '.$myrow['forum_name']."
    \n"; + break; + case 'Thread': //=topics + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; + $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; + $result = api_sql_query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + // grabbing the title of the post + $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; + $result_title = api_sql_query($sql_title,__FILE__,__LINE__); + $myrow_title = mysql_fetch_array($result_title); + echo ' '.$myrow_title['post_title']."
    \n"; + break; + case 'Post': + $tbl_post = Database::get_course_table(TABLE_FORUM_POST); + $tbl_post_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE); + $sql = "SELECT * FROM $tbl_post p, $tbl_post_text t WHERE p.post_id = t.post_id AND p.post_id = $id"; + $result = api_sql_query($sql,__FILE__,__LINE__); + $post = mysql_fetch_object($result); + echo ' '.$post->post_title."
    \n"; + break; + case 'Document': + $dbTable = $_course['dbNameGlu'].'document'; + $result = api_sql_query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__); + $myrow = mysql_fetch_array($result); + $pathname = explode('/',$myrow['path']); // making a correct name for the link + $last = count($pathname) - 1; // making a correct name for the link + $filename = $pathname[$last]; // making a correct name for the link + $image = choose_image($filename); + $ext = explode('.',$filename); + $ext = strtolower($ext[sizeof($ext)-1]); + $myrow['path'] = rawurlencode($myrow['path']); + $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png')); + echo ' '.$filename."
    \n"; + break; + case 'Externallink': + echo ' '.$id."
    \n"; + break; + } +} + +/** +* This function is to display the added resources (lessons) in the learning path player and builder +* this function is a modification of display_addedresource_link($type, $id) function +* the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was +* building upon it. - Denes +* +* Parameters: +* @param completed - if ="completed" then green presentation with checkbox +* @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table +* @param id - that is the correspondent id in the mirror tool (like Agenda item 2) +* @param type - that is the correspondent type in the mirror tool (like this is a Link item) +* @param builder - if ="builder" then onclick shows in new window +* @param icon - if ="icon" then the small icon will appear +* if ="wrap" then wrapped settings are used (and no icon is displayed) +* if ="nolink" then only the name is returned with no href and no icon (note:only in this case, the result is not displayed, but returned) +* @todo this function is too long, rewrite +*/ +function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0) +{ + global $_course, $learnpath_id, $tbl_learnpath_item, $items; + global $curDirPath, $_configuration, $enableDocumentParsing, $_course, $_user, $_cid; + + $tbl_lp_item = Database::get_course_table('lp_item'); + $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"' + + $length = ((($builder == 'builder') and ($icon == 'nolink')) ? 65 : 32); + + if ($builder != 'builder') $origin = 'learnpath'; //origin = learnpath in student view + $linktype = $type; + if (($type == 'Link _self') or ($type == 'Link _blank')) $type = 'Link'; + + //YW switched litteral tool names to use of constants declared in main_api.lib.php + switch ($type) + { + case TOOL_CALENDAR_EVENT: + case "Agenda": + $TABLEAGENDA = $_course['dbNameGlu']."calendar_event"; + $result = api_sql_query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["title"]=$row['title']; } + $desc=$row['description']; + $agenda_id=$row['item_id']; + echo str_repeat(" >",$level); + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($myrow["title"]=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); } + if ($icon == 'icon') { echo "agenda"; } + if ($builder != 'builder') + { + echo "".shorten($myrow["title"],($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($myrow["title"],($length-3*$level)).""; + } + break; + + case TOOL_ANNOUNCEMENT: + case "Ad_Valvas": + $tbl_announcement = $_course['dbNameGlu']."announcement"; + $result = api_sql_query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["content"]=$row['title']; } + $desc=$row['description']; + $ann_id=$row['item_id']; + echo str_repeat(" >",$level); + + // the title and the text are in the content field and we only want to display the title + list($title, $text)=split('
    ',$myrow['content']); + if ($title=='') { $title=$myrow['content']; } + $title=$myrow['title']; + $text=$myrow['content']; + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($title=='') { + $type="Announcement"; + echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; + return(true); + } + + if ($icon == 'nolink') { return(shorten($title,$length)); } + if ($icon == 'icon') { echo "ad valvas"; } + if ($builder != 'builder') + { + echo "".shorten($title,($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($title,($length-3*$level)).""; + } + break; + + case TOOL_LINK: + case "Link" : + $TABLETOOLLINK = $_course['dbNameGlu']."link"; + $result= api_sql_query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["title"]=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($myrow["title"]=='') + { + echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; + return(true); + } + + if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); } + if ($icon == 'icon') + { + if ($linktype=='Link _self') { echo "links"; } + else { echo "blank links"; } + } + $thelink=$myrow["url"]; + if ($builder != 'builder') + { + echo "".shorten($myrow["title"],($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($myrow["title"],($length-3*$level)).""; + } + break; + + case TOOL_QUIZ: + case "Exercise": + $TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; + $result= api_sql_query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + if ($builder=='builder') { $origin='builder'; } + //this is needed for the exercise_submit.php can delete the session info about tests + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); + $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["title"]=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($myrow["title"]=='') { + echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; + return(true); + } + + if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); } + if ($icon == 'icon') { echo "quizz"; } + if ($builder != 'builder') + { + echo "".shorten($myrow["title"],($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($myrow["title"],($length-3*$level)).""; + } + break; + + case 'hotpotatoes': + case "HotPotatoes": + $TBL_DOCUMENT = $_course['dbNameGlu'].'document'; + $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'; + $result = api_sql_query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id"); + $myrow= mysql_fetch_array($result); + $path=$myrow["path"]; + $name=GetQuizName($path,$documentPath); + + if ($builder=='builder') { $origin='builder'; } + //this is needed for the exercise_submit.php can delete the session info about tests + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo "hot potatoes"; } + + $cid = $_course['official_code']; + + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo " ".shorten($name,($length-3*$level)).""; + } + break; + + case TOOL_FORUM: + case "Forum": + $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; + $result= api_sql_query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($myrow["forum_name"]=='') { $type="Forum"; echo "".get_lang('StepDeleted1')." $type ".get_lang('step_deleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($myrow["forum_name"],$length)); } + if ($icon == 'icon') { echo "forum"; } + $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; + if ($builder != 'builder') + { + echo "".shorten($myrow["forum_name"],($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($myrow["forum_name"],($length-3*$level)).""; + } + break; + + case TOOL_THREAD: + case "Thread": //forum post + $tbl_topics = $_course['dbNameGlu'].'bb_topics'; + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; + $sql="SELECT * FROM `$tbl_topics` where topic_id=$id"; + $result= api_sql_query($sql,__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($myrow["topic_title"]=='') { $type="Forum Post"; echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($myrow["topic_title"],$length)); } + if ($icon == 'icon') { echo "forum"; } + if ($builder != 'builder') + { + echo "".shorten($myrow["topic_title"],($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($myrow["topic_title"],($length-3*$level)).""; + } + break; + + case TOOL_POST: + case "Post": + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; + $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; + $result= api_sql_query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + // grabbing the title of the post + $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; + $result_titel=api_sql_query($sql_titel,__FILE__,__LINE__); + $myrow_titel=mysql_fetch_array($result_titel); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + $posternom=$myrow['nom']; $posterprenom=$myrow['prenom']; + $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text']; + $posttitle=$myrow_titel['post_title']; + $posttext = str_replace('"',"'",$posttext); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($myrow_titel["post_title"]=='') + { + $type="Forum"; + echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); + } + + if ($icon == 'nolink') { return(shorten($myrow_titel["post_title"],$length)); } + if ($icon == 'icon') { echo "forum"; } + if ($builder != 'builder') + { + echo "".shorten($myrow_titel["post_title"],($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($myrow_titel["post_title"],($length-3*$level)).""; + } + break; + + case TOOL_DOCUMENT: + case "Document": + $dbTable = $_course['dbNameGlu']."document"; + $mysql = "SELECT * FROM `$dbTable` WHERE id=$id"; + //error_log('New LP - Querying document table: '.$mysql,0); + $result = api_sql_query($mysql,__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $pathname=explode("/",$myrow["path"]); // making a correct name for the link + $last=count($pathname)-1; // making a correct name for the link + $filename=$pathname[$last]; // making a correct name for the link + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + echo str_repeat(" >",$level); + + if ($icon != 'nolink') { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + $image=choose_image($filename); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + //error_log('New LP - Querying lp_item table: '.$sql,0); + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $filename=$row['title']; } + $desc=$row['description']; + + if (($myrow["path"]=='') and ($filename=='')) { + echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; + return(true); + } + + if ($icon == 'nolink') { return(shorten($filename,$length)); } + if ($icon == 'icon') { echo "$image"; } + if ($builder != 'builder') + { + echo "".shorten($filename,($length-3*$level)).""; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path"; + } + else + { + $enableDocumentParsing=yes; + if (!$enableDocumentParsing) + { //this is the solution for the non-parsing version in the builder + $file=urlencode($myrow["path"]); + echo "".shorten($filename,($length-3*$level)).""; + } + else + { + echo "".shorten($filename,($length-3*$level)).""; + } + } + break; + + case 'assignments': + case "Assignments": + $name=get_lang('Assignments'); + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') + { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') + { + echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); + } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo ""; } + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path"; + if ($desc != '') + { + if ($icon != 'wrap') + { + echo "
      ".shorten($desc,($length-3*$level))."
    "; + } + else + { + echo "
         ".shorten($desc,($length-3*$level))."
    "; + } + } + } + else + { + echo "".shorten($name,($length-3*$level)).""; + } + break; + + case TOOL_DROPBOX: + case "Dropbox": + $name=get_lang('Dropbox'); + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo ""; } + + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path"; + if ($desc != '') { + if ($icon != 'wrap') { + echo "
      ".shorten($desc,($length-3*$level))."
    "; } + else { + echo "
         ".shorten($desc,($length-3*$level))."
    "; } + } + } else { + echo "".shorten($name,($length-3*$level)).""; + } + break; + + case 'introduction_text': + case "Introduction_text": + $name=get_lang('IntroductionText'); + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo "introduction"; } + + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; + $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path"; + if ($desc != '') { + if ($icon != 'wrap') { + echo "
      ".shorten($desc,($length-3*$level))."
    "; } + else { + echo "
         ".shorten($desc,($length-3*$level))."
    "; } + } + } else { + $s=api_get_path('WEB_COURSE_PATH')."$_cid/index.php?intro_cmdEdit=1"; + echo "".shorten($name,($length-3*$level)).""; + } + break; + + case TOOL_COURSE_DESCRIPTION: + case "Course_description": + $name=get_lang('CourseDescription'); + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo "info"; } + + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path"; + if ($desc != '') { + if ($icon != 'wrap') { + echo "
      ".shorten($desc,($length-3*$level))."
    "; } + else { + echo "
         ".shorten($desc,($length-3*$level))."
    "; } + } + } else { + $s=api_get_path('WEB_CODE_PATH')."course_description"; + echo "".shorten($name,($length-3*$level)).""; + } + break; + + case TOOL_GROUP: + case "Groups": + $name=get_lang('Groups'); + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo "group"; } + + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path"; + if ($desc != '') { + if ($icon != 'wrap') { + echo "
      ".shorten($desc,($length-3*$level))."
    "; } + else { + echo "
         ".shorten($desc,($length-3*$level))."
    "; } + } + } else { + echo "".shorten($name,($length-3*$level)).""; + } + break; + + case TOOL_USER: + case "Users": + $name=get_lang('Users'); + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $name=$row['title']; } + $desc=$row['description']; + echo str_repeat(" >",$level); + + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + if ($icon != 'nolink') { + if ($completed=='completed') { + echo "on"; + } else { + echo "on"; + //echo " "; + } + } + if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } + + if ($name=='') { echo "".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } + + if ($icon == 'nolink') { return(shorten($name,$length)); } + if ($icon == 'icon') { echo "members"; } + + if ($builder != 'builder') + { + echo "".shorten($name,($length-3*$level)).""; $items[]=$_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path"; + if ($desc != '') { + if ($icon != 'wrap') { + echo "
      ".shorten($desc,($length-3*$level))."
    "; } + else { + echo "
         ".shorten($desc,($length-3*$level))."
    "; } + } + } else { + echo "".shorten($name,($length-3*$level)).""; + } + break; + }//end huge switch-statement +} + +/** +* This function is to create and return a link to the added resources (lessons). +* It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display +* anything. +* +* Parameters: +* @param type - that is the correspondent type in the mirror tool (like this is a Link item) +* @param id - that is the correspondent id in the mirror tool (like Agenda item 2) +* @param id_in_path - the unique index in the items table +*/ +function get_addedresource_link_in_learnpath($type, $id, $id_in_path) +{ + global $_course, $learnpath_id, $tbl_learnpath_item, $items; + global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid; + + $tbl_lp_item = Database::get_course_table('lp_item'); + $hyperlink_target_parameter = ""; //or e.g. target='_blank' + $builder = 'player'; + $origin='learnpath'; + + $linktype=$type; + if (($type=="Link _self") or ($type=="Link _blank")) { $type="Link"; } + + $link = ''; + + switch ($type) + { + case "Agenda": + $TABLEAGENDA = $_course['dbNameGlu']."calendar_event"; + $result = api_sql_query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["title"]=$row['title']; } + $desc=$row['description']; + $agenda_id=$row['item_id']; + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path"; + } + else + { + $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id"; + } + break; + + case "Ad_Valvas": + $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); + $result = api_sql_query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$id#$id_in_path"; + } + else + { + $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id"; + } + break; + + case "Link" : + $TABLETOOLLINK = $_course['dbNameGlu']."link"; + $result= api_sql_query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + + $thelink=$myrow["url"]; + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path"; + } + else + { + $link .= $thelink; + } + break; + + case "Exercise": + $TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; + $result= api_sql_query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + if ($builder=='builder') { $origin='builder'; } + //this is needed for the exercise_submit.php can delete the session info about tests + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["title"]=$row['title']; } + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path"; + } + else + { + $link .= "../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow["id"]; + } + break; + + case "HotPotatoes": + $TBL_DOCUMENT = $_course['dbNameGlu'].'document'; + $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'; + $result = api_sql_query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id"); + $myrow= mysql_fetch_array($result); + $path=$myrow["path"]; + $name=GetQuizName($path,$documentPath); + + if ($builder=='builder') { $origin='builder'; } + + $cid = $_course['official_code']; + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path"; + } + else + { + $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']; + } + break; + + case "Forum": + $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; + $result= api_sql_query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + if ($builder=='builder') { $origin='builder'; } + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; } + + if ($myrow["forum_name"]=='') { $type="Forum"; } + + $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path"; + } + else + { + $link .= "../phpbb/viewforum.php?$forumparameters"; + } + break; + + case "Thread": //forum post + $tbl_topics = $_course['dbNameGlu'].'bb_topics'; + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; + $sql="SELECT * FROM `$tbl_topics` where topic_id=$id"; + $result= api_sql_query($sql,__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path"; + } + else + { + $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; + } + break; + + case "Post": + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; + $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; + $result= api_sql_query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + // grabbing the title of the post + $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; + $result_titel=api_sql_query($sql_titel,__FILE__,__LINE__); + $myrow_titel=mysql_fetch_array($result_titel); + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; } + $desc=$row['description']; + $link .= str_repeat(" >",$level); + + $posternom=$myrow['nom']; $posterprenom=$myrow['prenom']; + $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text']; + $posttitle=$myrow_titel['post_title']; + $posttext = str_replace('"',"'",$posttext); + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path"; + } + else + { + $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]; + } + break; + + case "Document": + $dbTable = $_course['dbNameGlu']."document"; + $result=api_sql_query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__); + $myrow=mysql_fetch_array($result); + + $pathname=explode("/",$myrow["path"]); // making a correct name for the link + $last=count($pathname)-1; // making a correct name for the link + $filename=$pathname[$last]; // making a correct name for the link + + $sql="select * from $tbl_lp_item where id=$id_in_path"; + $result=api_sql_query($sql,__FILE__,__LINE__); $row=mysql_fetch_array($result); + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path"; + + } + else + { + $enableDocumentParsing=yes; + if (!$enableDocumentParsing) + { //this is the solution for the non-parsing version in the builder + $file=urlencode($myrow["path"]); + $link .= "../document/showinframes.php?file=$file"; + } + else + { + $link .= "../document/download.php?doc_url=".$myrow["path"]; + } + } + break; + + case "Assignments": + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path"; + } + else + { + $link .= "../work/work.php"; + } + break; + case "Dropbox": + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path"; + } else { + $link .= "../dropbox/index.php"; + } + break; + case "Introduction_text": + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path"; + } else { + $s=api_get_path('WEB_COURSE_PATH')."$_cid/index.php?intro_cmdEdit=1"; + $link .= $s; + } + break; + case "Course_description": + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path"; + } else { + $s=api_get_path('WEB_CODE_PATH')."course_description"; + $link .= $s; + } + break; + case "Groups": + + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path"; + } else { + $link .= "../group/group.php?origin=$origin"; + } + break; + case "Users": + if ($builder != 'builder') + { + $link .= $_SERVER['PHP_SELF']."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path"; + } else { + $link .= "../user/user.php?origin=$origin"; + } + break; + }//end huge switch-statement + return $link; +} + +/** +* This function is to remove an resource item from the array +*/ +function remove_resource($resource_key) +{ + $addedresource = $_SESSION['addedresource']; + $addedresourceid = $_SESSION['addedresourceid']; + unset($addedresource[$resource_key]); + unset($addedresourceid[$resource_key]); + $_SESSION['addedresource']=$addedresource; + $_SESSION['addedresourceid']=$addedresourceid ; +} + +/** +* This function is to show the button "click to add resource" on the tool page +* @author Patrick Cool , Ghent University +*/ +function show_addresource_button($additionalparameters = '') +{ + echo ''; +} + +/** +* this function is to delete ONE specific resource that were added to a specific item +*/ +function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id) +{ + echo "delete_one_added_resource"; + global $_course; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + + $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'"; + api_sql_query($sql,__FILE__,__LINE__); +} + +/** +* this function is to delete the resources that were added to a specific item +*/ +function delete_added_resource($type, $id) +{ + global $_course; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + + $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'"; + api_sql_query($sql,__FILE__,__LINE__); +} + +/** +* this function is te delete all resources of a specific type (only used in announcements -- delete all) +* Author : Frederik Vermeire +*/ +function delete_all_resources_type($type) +{ + global $_course; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + + $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type'"; + + api_sql_query($sql,__FILE__,__LINE__); +} + +/** +* this function checks wether there are added resources or not +*/ +function check_added_resources($type, $id) +{ + global $_course, $origin; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'"; + $result=api_sql_query($sql,__FILE__,__LINE__); + $number_added=mysql_num_rows($result); + if ($number_added<>0) + return true; + else + return false; +} + + +/** +* this function is to load the resources that were added to a specific item +* into the session variables +*/ +function edit_added_resources($type, $id) +{ + global $_course; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + + $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id=$id"; + $result=api_sql_query($sql,__FILE__,__LINE__); + while ($row=mysql_fetch_array($result)) + { + $addedresource[]=$row["resource_type"]; + $addedresourceid[]=$row["resource_id"]; + } + $_SESSION['addedresource']=$addedresource; + $_SESSION['addedresourceid']=$addedresourceid; +} + +/** +* this function is store the modified resources +* first we delete all the added resources in the database, +* then we add all the resources from the session object. +*/ +function update_added_resources($type, $id) +{ + global $_course; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + // delete all the added resources for this item in the database; + $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' AND source_id='$id'"; + //echo $sql; + api_sql_query($sql,__FILE__,__LINE__); + + // store the resources from the session into the database + store_resources($type, $id); + + //delete_added_resource_($type, $id); + unset_session_resources(); +} + +/** +* this function is to display the resources that were added to a specific item +*/ +function display_added_resources($type, $id, $style='') +{ + // the array containing the icons + $arr_icons=array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' ); + + global $_course, $origin; + $TABLERESOURCE = $_course['dbNameGlu']."resource"; + + $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'"; + $result=api_sql_query($sql,__FILE__,__LINE__); + while ($row=mysql_fetch_array($result)) + { + if ($origin != 'learnpath') + { + display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ; + } + else + { + display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "
    "; + } + } +} + + +/** +* This function is to show the added resources when adding an item +* $showdeleteimg determine if the delete image should appear or not. +* deleting an added resource is only possible through the resource linker file itself +*/ +function display_resources($showdeleteimg) +{ + global $action; + global $resourceaction; + global $id; + global $locationkey; + global $source_id, $action, $learnpath_id, $chapter_id, $originalresource; + + if ($resourceaction=="removeresource") + { + remove_resource($locationkey); + } + $addedresource=$_SESSION['addedresource']; + $addedresourceid=$_SESSION['addedresourceid']; + if (is_array($addedresource)) + { + echo ''; + foreach ($addedresource as $resource) + { + echo ''; + next($addedresource); + } + echo '
    '; + display_addedresource_link($resource,$addedresourceid[key($addedresource)]); + echo ''; + + // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource + // should also contain this id. + $test=parse_url($_SERVER['REQUEST_URI']); + $output = array(); + parse_str($test[query],$output); + + if ($showdeleteimg==1) + { + echo "resource ".get_lang(
    "; + } + echo '
    '; + } + else // it is a string + { + echo ''; + } +} // end of the display_resources function + + +/** +* This function checks wether the link add resource should be displayed next the item in the linker page +* So we have to check if the specific id of that tool is already in the array of the added resources +* if it is already in, the link should not be showed since it would make it possible to add +* the same resource a second time (=duplication of added resources) +*/ +function showorhide_addresourcelink($type, $id) +{ + global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target; + $addedresource=$_SESSION['addedresource']; + $addedresourceid=$_SESSION['addedresourceid']; + + if (is_array($_SESSION['addedresource'])) + { + foreach ($addedresource as $toolcompare) + { + if ($toolcompare==$type and $addedresourceid[key($addedresource)]==$id) + { + $show=0; + } + next($addedresource); + } + if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); } + if ($show!==0) + { + if ($type=="Document") + { + echo "".$lang_add_it_or_resource.""; + } + else + { + echo "".$lang_add_it_or_resource.""; + } + } + } + else // if it is not an array, it is a string + { + if ($_SESSION['addedresource']!==$type or $_SESSION['addedresourceid']!==$id) + { + if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); } + echo "".$lang_add_it_or_resource.""; + } + } +} + +/** + * Gets the link to the given added resource. + * + * @author Patrick Cool , Ghent University + * @author Yannick Warnier , Dokeos - rebranding + * @param string Course code + * @param string The tool type (using constants declared in main_api.lib.php) + * @param integer The resource ID + * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden) + * @param boolean Open in a new window (true) or in the current frame/window (false)? + * @todo use the constants for the type definitions. + */ +function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_window=true) +{ + //$_course = Database::get_course_info($course_code); + $_course = Database::get_course_info_from_code($course_code); + + // styling the link of the added resource + if ($style <> '') $styling = ' class="'.$style.'"'; + if($new_window == true){ $target = ' target = "_blank" ';}else{$target = ' target = "_self" ';} + + $output = ''; + + switch ($type) + { + case TOOL_CALENDAR_EVENT: + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['database']); + $result = api_sql_query("SELECT * FROM $TABLEAGENDA WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = ' '.$myrow['title']."
    \n"; + break; + case TOOL_ANNOUNCEMENT: + $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['database']); + $result = api_sql_query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = ' '.$myrow['title']."
    \n"; + break; + case TOOL_LINK: + //doesn't take $target into account + $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']); + $result = api_sql_query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = ' '.$myrow['title']."
    \n"; + break; + case TOOL_QUIZ: + $TBL_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE,$_course['database']); + $result = api_sql_query("SELECT * FROM $TBL_EXERCICES WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = ' '.$myrow['title']."
    \n"; + break; + case TOOL_FORUM: + $TBL_FORUMS = Database::get_course_table(TOOL_FORUM,$_course['database']); + $result = api_sql_query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = ' '.$myrow['forum_name']."
    \n"; + break; + case TOOL_THREAD: //=topics + if(!empty($_SESSION['dokeos_version']) AND $_SESSION['dokeos_version']>=1.8){ + //$tbl_forum = Database::get_course_table(TABLE_FORUM,$_course['database']); + //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']); + $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); + // grabbing the title of the post + $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id; + $result_title = api_sql_query($sql_title,__FILE__,__LINE__); + $myrow_title = Database::fetch_array($result_title); + $output = ' '.$myrow_title['post_title']."
    \n"; + }else{//older dokeos versions + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; + $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; + $result = api_sql_query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + // grabbing the title of the post + $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; + $result_title = api_sql_query($sql_title,__FILE__,__LINE__); + $myrow_title = Database::fetch_array($result_title); + $output = ' '.$myrow_title['post_title']."
    \n"; + } + break; + case TOOL_POST: + $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); + //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE); + $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id"; + $result = api_sql_query($sql,__FILE__,__LINE__); + $post = Database::fetch_array($result); + $output = ' '.$post['post_title']."
    \n"; + break; + case TOOL_DOCUMENT: + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']); + $result = api_sql_query("SELECT * FROM $tbl_doc WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $pathname = explode('/',$myrow['path']); // making a correct name for the link + $last = count($pathname) - 1; // making a correct name for the link + $filename = $pathname[$last]; // making a correct name for the link + $image = choose_image($filename); + $ext = explode('.',$filename); + $ext = strtolower($ext[sizeof($ext)-1]); + $myrow['path'] = rawurlencode($myrow['path']); + $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png')); + $output = ' '.$filename."
    \n"; + break; + /* + case 'Externallink': + $output = ' '.$id."
    \n"; + break; + */ + } + return $output; +} +/** +* Returns an HTML-formatted link to a resource, to incorporate directly into +* the new learning path tool. +* +* The function is a big switch on tool type. +* In each case, we query the corresponding table for information and build the link +* with that information. +* @author Yannick Warnier - rebranding based on previous work (display_addedresource_link_in_learnpath()) +* @param string Course code +* @param integer The learning path ID (in lp table) +* @param integer The database ID for that item in the lp_item table +* @param +* @param string Type (as one of the TOOL_ constants declared in main_api.lib.php) +* @param integer ID of the database item to get (from that tool's table) +* @param id - that is the correspondent id in the mirror tool (like Agenda item 2) +* @param id_in_path - the unique index in the items table +*/ +function rl_get_resource_link_for_learnpath($course_code, $learnpath_id, $id_in_path) +{ + //error_log('In rl_get_resource_link_for_learnpath()',0); + global $my_version; //added global variable just for cross compatibility. I hate it. + if($my_version=='1.8'){ + $_course = Database::get_course_info($course_code); + }else{ + $_course = Database::get_course_info_from_code($course_code); + } + + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql_item = "SELECT * FROM $tbl_lp_item " . + "WHERE lp_id = $learnpath_id AND id = $id_in_path"; + $res_item = api_sql_query($sql_item,__FILE__,__LINE__); + if(Database::num_rows($res_item<1)) return -1; //exit + $row_item = Database::fetch_array($res_item); + + $type = strtolower($row_item['item_type']); + $id = $row_item['path']; + + $origin='learnpath'; + $main_dir_path = api_get_path(WEB_CODE_PATH); + $main_course_path = api_get_path(WEB_COURSE_PATH).$_course['directory'].'/'; + + $link = ''; + + switch ($type) + { + case 'dokeos_chapter': + $link .= $main_dir_path.'newscorm/blank.php'; + case TOOL_CALENDAR_EVENT: + $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id; + break; + + case TOOL_ANNOUNCEMENT: + $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id; + break; + + case TOOL_LINK: + $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']); + $result= api_sql_query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__); + $myrow=Database::fetch_array($result); + $thelink=$myrow["url"]; + $link .= $thelink; + break; + + case TOOL_QUIZ: + $TBL_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE,$_course['database']); + $sql = "SELECT * FROM $TBL_EXERCICES WHERE id=$id"; + $result= api_sql_query($sql,__FILE__,__LINE__); + $myrow=Database::fetch_array($result); + + if ($row_item['title'] != '') { $myrow["title"]=$row_item['title']; } + $link .= $main_dir_path.'exercice/exercice_submit.php?lp_init=1&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&exerciseId='.$id; + break; + + case "hotpotatoes": //lowercase because of strtolower above + + $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); + $result = api_sql_query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id",__FILE__,__LINE__); + $myrow= Database::fetch_array($result); + $path=$myrow["path"]; + $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' . + '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' . + '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path; + break; + + case TOOL_FORUM: + $link .= $main_dir_path.'phpbb/viewforum.php?forum='.$id.'&lp=true'; + break; + + case TOOL_THREAD: //forum post + $tbl_topics = Database::get_course_table(TOOL_FORUM_THREAD,$_course['database']); + $sql="SELECT * FROM $tbl_topics where thread_id=$id"; + $result= api_sql_query($sql,__FILE__,__LINE__); + $myrow=Database::fetch_array($result); + $link .= $main_dir_path.'phpbb/viewtopic.php?topic='.$id.'' . + '&forum='.$myrow['forum_id'].'&lp=true'; + break; + + case TOOL_POST: + $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); + $result= api_sql_query("SELECT * FROM $tbl_post where post_id=$id",__FILE__,__LINE__); + $myrow=Database::fetch_array($result); + $title=$myrow['post_title']; + + $desc=$row_item['description']; + + $posternom=$myrow['poster_name']; + $posttime=$myrow['post_date']; + $posttext=$myrow['post_text']; + $posttitle=$title; + $posttext = str_replace('"',"'",$posttext); + + $link .= $main_dir_path.'phpbb/viewpost.php?post='.$id.'' . + '&topic='.$myrow['topic_id'].'&forum='.$myrow['forum_id'].'' . + '&lp=true'; + break; + + case TOOL_DOCUMENT: + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']); + $sql = "SELECT * FROM $tbl_doc WHERE id=$id"; + $result=api_sql_query($sql,__FILE__,__LINE__); + $myrow=Database::fetch_array($result); + $docurl=$myrow['path']; + $link .= $main_course_path.'document'.$docurl; + $openmethod=2; + $officedoc=false; + api_session_register('openmethod'); + api_session_register('officedoc'); + break; + + case "assignments": + $link .= $main_dir_path.'work/work.php?origin='.$origin; + break; + case TOOL_DROPBOX: + $link .= $main_dir_path.'dropbox/index.php?origin=learnpath'; + break; + case "introduction_text": //DEPRECATED + $link .= ''; + break; + case TOOL_COURSE_DESCRIPTION: + $link .= $main_dir_path.'course_description?origin='.$learnpath; + break; + case TOOL_GROUP: + $link .= $main_dir_path.'group/group.php?origin='.$origin; + break; + case TOOL_USER: + $link .= $main_dir_path.'user/user.php?origin='.$origin; + break; + }//end switch + return $link; +} +/** + * Gets the name of a resource (generally used in learnpath when no name is provided) + * + * @author Yannick Warnier , Dokeos - rebranding + * @param string Course code + * @param string The tool type (using constants declared in main_api.lib.php) + * @param integer The resource ID + */ +function rl_get_resource_name($course_code, $learnpath_id, $id_in_path) +{ + global $my_version; + if($my_version == '1.8'){ + $_course = Database::get_course_info($course_code); + }else{ + $_course = Database::get_course_info_from_code($course_code); + } + + $tbl_lp_item = Database::get_course_table('lp_item'); + + $sql_item = "SELECT * FROM $tbl_lp_item " . + "WHERE lp_id = $learnpath_id AND id = $id_in_path"; + $res_item = api_sql_query($sql_item,__FILE__,__LINE__); + if(Database::num_rows($res_item<1)) return ''; //exit + $row_item = Database::fetch_array($res_item); + $type = strtolower($row_item['item_type']); + $id = $row_item['ref']; + $output = ''; + + switch ($type) + { + case TOOL_CALENDAR_EVENT: + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['database']); + $result = api_sql_query("SELECT * FROM $TABLEAGENDA WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = $myrow['title']; + break; + case TOOL_ANNOUNCEMENT: + $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['database']); + $result = api_sql_query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = $myrow['title']; + break; + case TOOL_LINK: + //doesn't take $target into account + $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']); + $result = api_sql_query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = $myrow['title']; + break; + case TOOL_QUIZ: + $TBL_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE,$_course['database']); + $result = api_sql_query("SELECT * FROM $TBL_EXERCICES WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = $myrow['title']; + break; + case TOOL_FORUM: + $TBL_FORUMS = Database::get_course_table(TOOL_FORUM,$_course['database']); + $result = api_sql_query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $output = $myrow['forum_name']; + break; + case TOOL_THREAD: //=topics + if(!empty($_SESSION['dokeos_version']) AND $_SESSION['dokeos_version']>=1.8){ + //$tbl_forum = Database::get_course_table(TABLE_FORUM,$_course['database']); + //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']); + $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); + // grabbing the title of the post + $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id; + $result_title = api_sql_query($sql_title,__FILE__,__LINE__); + $myrow_title = Database::fetch_array($result_title); + $output = $myrow_title['post_title']; + }else{//older dokeos versions + $tbl_posts = $_course['dbNameGlu'].'bb_posts'; + $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text'; + $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums'; + $result = api_sql_query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + // grabbing the title of the post + $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"]; + $result_title = api_sql_query($sql_title,__FILE__,__LINE__); + $myrow_title = Database::fetch_array($result_title); + $output = $myrow_title['post_title']; + } + break; + case TOOL_POST: + $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']); + //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE); + $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id"; + $result = api_sql_query($sql,__FILE__,__LINE__); + $post = Database::fetch_array($result); + $output = $post['post_title']; + break; + case TOOL_DOCUMENT: + case 'hotpotatoes': + $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']); + $result = api_sql_query("SELECT * FROM $tbl_doc WHERE id=$id",__FILE__,__LINE__); + $myrow = Database::fetch_array($result); + $pathname = explode('/',$myrow['path']); // making a correct name for the link + $last = count($pathname) - 1; // making a correct name for the link + $filename = $pathname[$last]; // making a correct name for the link + $image = choose_image($filename); + $ext = explode('.',$filename); + $ext = strtolower($ext[sizeof($ext)-1]); + $myrow['path'] = rawurlencode($myrow['path']); + $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png')); + $output = $filename; + break; + /* + case 'externallink': + $output = ' '.$id."
    \n"; + break; + */ + } + + return stripslashes($output); +} +?> diff --git a/main/newscorm/resourcelinker.php b/main/newscorm/resourcelinker.php index 083effe2a9..82a133cbc3 100644 --- a/main/newscorm/resourcelinker.php +++ b/main/newscorm/resourcelinker.php @@ -57,8 +57,8 @@ include ('resourcelinker.inc.php'); ----------------------------------------------------------- */ -$link_table = Database :: get_course_table(LINK_TABLE); -$item_property_table = Database :: get_course_table(ITEM_PROPERTY_TABLE); +$link_table = Database :: get_course_table(TABLE_LINK); +$item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); //$tbl_learnpath_main = Database :: get_course_table(LEARNPATH_MAIN_TABLE); //$tbl_learnpath_chapter = Database :: get_course_table(LEARNPATH_CHAPTER_TABLE); @@ -305,7 +305,7 @@ if ($add) case 'Document': $addedresource_item = TOOL_DOCUMENT; //get title from tool-type table - $tooltable = Database::get_course_table(DOCUMENT_TABLE); + $tooltable = Database::get_course_table(TABLE_DOCUMENT); $result = api_sql_query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__); $myrow=mysql_fetch_array($result); $title = $myrow['title']; @@ -325,7 +325,7 @@ if ($add) case 'Agenda': $addedresource_item = TOOL_CALENDAR_EVENT; //get title from tool-type table - $tooltable = Database::get_course_table(AGENDA_TABLE); + $tooltable = Database::get_course_table(TABLE_AGENDA); $result = api_sql_query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__); $myrow=mysql_fetch_array($result); $title = $myrow['title']; @@ -333,7 +333,7 @@ if ($add) case 'Ad_Valvas': $addedresource_item = TOOL_ANNOUNCEMENT; //get title from tool-type table - $tooltable = Database::get_course_table(ANNOUNCEMENT_TABLE); + $tooltable = Database::get_course_table(TABLE_ANNOUNCEMENT); $result = api_sql_query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__); $myrow=mysql_fetch_array($result); $title = $myrow['title']; @@ -518,7 +518,7 @@ echo ""; // We use this to check which resources a student may add (only the modules that are active) // see http://www.dokeos.com/forum/viewtopic.php?t=4858 $active_modules=array(); -$tool_table = Database::get_course_table(TOOL_LIST_TABLE); +$tool_table = Database::get_course_table(TABLE_TOOL_LIST); $sql_select_active="SELECT * FROM $tool_table WHERE visibility='1'"; $result_select_active=api_sql_query($sql_select_active); while ($row=mysql_fetch_array($result_select_active)) @@ -724,8 +724,8 @@ if ($from_learnpath != 'yes') if ($content == "Agenda") { include (api_get_path(LIBRARY_PATH)."text.lib.php"); - $TABLEAGENDA = Database::get_course_table(AGENDA_TABLE); - $TABLE_ITEM_PROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); + $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties @@ -803,7 +803,7 @@ if ($content == "Document" OR (empty($content) AND (is_allowed_to_edit() OR in_a if ($content == "Ad_Valvas") { include (api_get_path(LIBRARY_PATH)."text.lib.php"); - $tbl_announcement = Database :: get_course_table(ANNOUNCEMENT_TABLE); + $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT); $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i WHERE i.tool = '".TOOL_ANNOUNCEMENT."' AND a.id=i.ref AND i.visibility='1' AND i.to_group_id = 0 AND i.to_user_id IS NULL ORDER BY a.display_order ASC"; //error_log($sql,0); $result = api_sql_query($sql,__FILE__,__LINE__); @@ -910,7 +910,7 @@ if ($content == "Link") // including the links functions file include ("../link/linkfunctions.php"); - $tbl_categories = Database::get_course_table(LINK_CATEGORY_TABLE); + $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); if (($learnpath_id != '') and ($content == 'Link')) { echo "
    "; @@ -979,7 +979,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes")) if ($from_learnpath == 'yes') { $uploadPath = "/HotPotatoes_files"; - $TBL_DOCUMENT = Database::get_course_table(DOCUMENT_TABLE); + $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $documentPath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'; $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY `id` ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -1024,7 +1024,7 @@ if ($content == "Externallink") "; $res_scodoc = api_sql_query($sql_scodoc,__FILE__,__LINE__); @@ -1083,7 +1083,7 @@ foreach($scorms as $my_course_code => $paths_list ) } } /** - * Migrate links on the homepage as well now (look into the TOOL_LIST_TABLE table and + * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and * update the links to newscorm/lp_controller.php?action=view&lp_id=x) * See scorm_migrate_hometools.php */ @@ -1095,7 +1095,7 @@ foreach($scorms as $my_course_code => $paths_list ) /** * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php */ - $tbl_intro = $db_name.TOOL_INTRO_TABLE; + $tbl_intro = $db_name.TABLE_TOOL_INTRO; $sql_i = "SELECT * FROM $tbl_intro WHERE id='course_homepage'"; $res_i = api_sql_query($sql_i,__FILE__,__LINE__); //$link_to_course1 = 'scorm/scormdocument.php'; diff --git a/main/newscorm/scorm_migrate_db_one_course.php b/main/newscorm/scorm_migrate_db_one_course.php index e8948a3ee6..85540547f0 100644 --- a/main/newscorm/scorm_migrate_db_one_course.php +++ b/main/newscorm/scorm_migrate_db_one_course.php @@ -417,11 +417,11 @@ foreach($courses_list as $db) $msg = "(found $incoherences incoherences between views and items - ignored)"; } /** - * Migrate links on the homepage as well now (look into the TOOL_LIST_TABLE table and + * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and * update the links to newscorm/lp_controller.php?action=view&lp_id=x) * Only normal learnpaths were visible from the homepage so we only need to update here */ - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE,$db); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$db); $sql_tool = "SELECT * FROM $tbl_tool WHERE image='scormbuilder.gif' AND link LIKE '%learnpath_handler%'"; $res_tool = api_sql_query($sql_tool,__FILE__,__LINE__); while($row_tool = Database::fetch_array($res_tool)){ @@ -491,7 +491,7 @@ while($course_row = Database::fetch_array($res_crs)){ //reinit the scormdocuments list //$scormdocuments_lps = array(); $db_name = $courses_id_list[$my_course_code]; - $tblscodoc = Database::get_course_table(SCORMDOC_TABLE,$db_name); + $tblscodoc = Database::get_course_table(TABLE_SCORMDOC,$db_name); $sql_scodoc = "SELECT path FROM $tblscodoc WHERE path IS NOT NULL AND path != ''"; echo "$sql_scodoc
    "; $res_scodoc = api_sql_query($sql_scodoc,__FILE__,__LINE__); @@ -894,7 +894,7 @@ foreach($scorms as $my_course_code => $paths_list ) } } /** - * Migrate links on the homepage as well now (look into the TOOL_LIST_TABLE table and + * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and * update the links to newscorm/lp_controller.php?action=view&lp_id=x) * See scorm_migrate_hometools.php */ diff --git a/main/newscorm/scorm_migrate_hometools.php b/main/newscorm/scorm_migrate_hometools.php index a6ef937687..cd6274561d 100644 --- a/main/newscorm/scorm_migrate_hometools.php +++ b/main/newscorm/scorm_migrate_hometools.php @@ -20,7 +20,7 @@ while ($row = Database::fetch_array($res)) $courses_list[] = $row['db_name']; //TODO add check for learnpath element. If not exist, create one. - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE,$row['db_name']); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$row['db_name']); $sql_t = "UPDATE $tbl_tool SET link = 'newscorm/lp_controller.php' WHERE name='learnpath'"; $res_t = api_sql_query($sql_t,__FILE__,__LINE__); if(!$res_t){ diff --git a/main/newscorm/scorm_migrate_hometools_reverse.php b/main/newscorm/scorm_migrate_hometools_reverse.php index 121357154a..1946ba7b46 100644 --- a/main/newscorm/scorm_migrate_hometools_reverse.php +++ b/main/newscorm/scorm_migrate_hometools_reverse.php @@ -20,7 +20,7 @@ while ($row = Database::fetch_array($res)) $courses_list[] = $row['db_name']; //TODO add check for learnpath element. If not exist, create one. - $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE,$row['db_name']); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$row['db_name']); $sql_t = "UPDATE $tbl_tool SET link = 'scorm/scormdocument.php' WHERE name='learnpath'"; $res_t = @mysql_query($sql_t); if(!$res_t){ diff --git a/main/permissions/blog_permissions.inc.php b/main/permissions/blog_permissions.inc.php index 346bd5530d..fa46641996 100644 --- a/main/permissions/blog_permissions.inc.php +++ b/main/permissions/blog_permissions.inc.php @@ -10,7 +10,7 @@ $rights_full=array("article_add","article_delete","article_edit","article_rate","article_comments_add","article_comments_delete","article_comments_rate","task_management","member_management","role_management"); $rights_limited=array("Add","Edit","Delete"); $rights_blog=array("article_add","article_delete","article_edit","article_rate","article_comments_add","article_comments_delete","article_comments_rate","task_management","member_management","role_management"); -$course_tool_table = Database::get_course_table(TOOL_LIST_TABLE); +$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); // Get all user $blog_users = Blog::get_blog_users(mysql_escape_string($_GET['blog_id'])); diff --git a/main/resourcelinker/resourcelinker.inc.php b/main/resourcelinker/resourcelinker.inc.php index 020813bff8..0c934587fb 100644 --- a/main/resourcelinker/resourcelinker.inc.php +++ b/main/resourcelinker/resourcelinker.inc.php @@ -1,4 +1,4 @@ -"; // We use this to check which resources a student may add (only the modules that are active) // see http://www.dokeos.com/forum/viewtopic.php?t=4858 $active_modules=array(); -$tool_table = Database::get_course_table(TOOL_LIST_TABLE); +$tool_table = Database::get_course_table(TABLE_TOOL_LIST); $sql_select_active="SELECT * FROM $tool_table WHERE visibility='1'"; $result_select_active=api_sql_query($sql_select_active); while ($row=mysql_fetch_array($result_select_active)) @@ -640,8 +640,8 @@ if ($from_learnpath != 'yes') // Agenda items --> if ($content == "Agenda") { - $TABLEAGENDA = Database::get_course_table(AGENDA_TABLE); - $TABLE_ITEM_PROPERTY = Database::get_course_table(LAST_TOOL_EDIT_TABLE); + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); + $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties @@ -718,7 +718,7 @@ if ($content == "Document" OR (empty($content) AND (is_allowed_to_edit() OR in_a */ if ($content == "Ad_Valvas") { - $tbl_announcement = Database :: get_course_table(ANNOUNCEMENT_TABLE); + $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT); $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i WHERE i.tool = '".TOOL_ANNOUNCEMENT."' AND a.id=i.ref AND i.visibility='1' AND i.to_group_id = 0 AND i.to_user_id IS NULL ORDER BY a.display_order ASC"; $result = api_sql_query($sql,__FILE__,__LINE__); @@ -825,7 +825,7 @@ if ($content == "Link") // including the links functions file include ("../link/linkfunctions.php"); - $tbl_categories = Database::get_course_table(LINK_CATEGORY_TABLE); + $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); if (($learnpath_id != '') and ($content == 'Link')) { echo "
    "; @@ -894,7 +894,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes")) if ($from_learnpath == 'yes') { $uploadPath = "/HotPotatoes_files"; - $TBL_DOCUMENT = Database::get_course_table(DOCUMENT_TABLE); + $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $documentPath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'; $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY `id` ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -939,7 +939,7 @@ if ($content == "Externallink") - */ -/** - * Process the document and return to the document tool - */ - -/* ------------------------------------------------------------ - Libraries ------------------------------------------------------------ -*/ - -//many useful functions in main_api.lib.php, by default included - -require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'); -require_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php'); -require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php'); -require_once('../document/document.inc.php'); - -//REMOVE -// If we want to unzip a file, we need the library -if (isset($_POST['unzip']) && $_POST['unzip'] == 1) -{ - require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'); -} -/* ------------------------------------------------------------ - Variables - - some need defining before inclusion of libraries ------------------------------------------------------------ -*/ -$courseDir = $_course['path']."/document"; -$sys_course_path = api_get_path(SYS_COURSE_PATH); -$base_work_dir = $sys_course_path.$courseDir; -$noPHP_SELF=true; -$max_filled_space = DocumentManager::get_course_quota(); - -//what's the current path? -if(isset($_POST['curdirpath'])) { - $path = $_POST['curdirpath']; -}else{ - $path = '/'; -} - -// Check the path -// If the path is not found (no document id), set the path to / -if(!DocumentManager::get_document_id($_course,$path)) { $path = '/'; } - -/** - * Header - */ - -$nameTools = get_lang('UplUploadDocument'); -$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments); -Display::display_header($nameTools,"Doc"); -//show the title -api_display_tool_title($nameTools.$add_group_to_title); - -/** - * Process - */ - -//user has submitted a file -if(isset($_FILES['user_upload'])) -{ - //echo("
    ");
    -	//print_r($_FILES['user_upload']);
    -	//echo("
    "); - - $upload_ok = process_uploaded_file($_FILES['user_upload']); - if($upload_ok) - { - //file got on the server without problems, now process it - $new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space,$_POST['unzip'],$_POST['if_exists']); - $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; - $new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; - - if ($new_path && ($new_comment || $new_title)) - if (($docid = DocumentManager::get_document_id($_course, $new_path))) - { - $table_document = Database::get_course_table(DOCUMENT_TABLE); - $ct = ''; - if ($new_comment) $ct .= ", comment='$new_comment'"; - if ($new_title) $ct .= ", title='$new_title'"; - api_sql_query("UPDATE $table_document SET" . substr($ct, 1) . - " WHERE id = '$docid'", __FILE__, __LINE__); - } - //check for missing images in html files - $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path); - if($missing_files) - { - //show a form to upload the missing files - Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name'])); - } - } -} -//missing images are submitted -if(isset($_POST['submit_image'])) -{ - $number_of_uploaded_images = count($_FILES['img_file']['name']); - //if images are uploaded - if ($number_of_uploaded_images > 0) - { - //we could also create a function for this, I'm not sure... - //create a directory for the missing files - $img_directory = str_replace('.','_',$_POST['related_file']."_files"); - $missing_files_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$img_directory); - //put the uploaded files in the new directory and get the paths - $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space); - //open the html file and replace the paths - replace_img_path_in_html_file($_POST['img_file_path'],$paths_to_replace_in_file,$base_work_dir.$_POST['related_file']); - //update parent folders - item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']); - } -} -//they want to create a directory -if(isset($_POST['create_dir']) && $_POST['dirname']!='') -{ - $added_slash = ($path=='/')?'':'/'; - $dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']); - $created_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']); - if($created_dir) - { - //Display::display_normal_message("".$created_dir." was created!"); - Display::display_normal_message(get_lang('DirCr')); - $path = $created_dir; - } - else - { - display_error(get_lang('CannotCreateDir')); - } -} - -//tracking not needed here? -//event_access_tool(TOOL_DOCUMENT); - -/*============================================================================*/ -?> - -'; - $new_folder_text .= ''; - $new_folder_text .= get_lang('NewDir') .' '; - $new_folder_text .= ''; - $new_folder_text .= ''; - $new_folder_text .= ''; - //show the form - Display::display_normal_message($new_folder_text); -} -else { //give them a link to create a directory - ?> -

    - - -
    - -
    - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - -
    - - --
    --
    -   
    -   
    -    - -
    - - - - - - -

    - - + */ +/** + * Process the document and return to the document tool + */ + +/* +----------------------------------------------------------- + Libraries +----------------------------------------------------------- +*/ + +//many useful functions in main_api.lib.php, by default included + +require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'); +require_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php'); +require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php'); +require_once('../document/document.inc.php'); + +//REMOVE +// If we want to unzip a file, we need the library +if (isset($_POST['unzip']) && $_POST['unzip'] == 1) +{ + require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'); +} +/* +----------------------------------------------------------- + Variables + - some need defining before inclusion of libraries +----------------------------------------------------------- +*/ +$courseDir = $_course['path']."/document"; +$sys_course_path = api_get_path(SYS_COURSE_PATH); +$base_work_dir = $sys_course_path.$courseDir; +$noPHP_SELF=true; +$max_filled_space = DocumentManager::get_course_quota(); + +//what's the current path? +if(isset($_POST['curdirpath'])) { + $path = $_POST['curdirpath']; +}else{ + $path = '/'; +} + +// Check the path +// If the path is not found (no document id), set the path to / +if(!DocumentManager::get_document_id($_course,$path)) { $path = '/'; } + +/** + * Header + */ + +$nameTools = get_lang('UplUploadDocument'); +$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments); +Display::display_header($nameTools,"Doc"); +//show the title +api_display_tool_title($nameTools.$add_group_to_title); + +/** + * Process + */ + +//user has submitted a file +if(isset($_FILES['user_upload'])) +{ + //echo("
    ");
    +	//print_r($_FILES['user_upload']);
    +	//echo("
    "); + + $upload_ok = process_uploaded_file($_FILES['user_upload']); + if($upload_ok) + { + //file got on the server without problems, now process it + $new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space,$_POST['unzip'],$_POST['if_exists']); + $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; + $new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; + + if ($new_path && ($new_comment || $new_title)) + if (($docid = DocumentManager::get_document_id($_course, $new_path))) + { + $table_document = Database::get_course_table(TABLE_DOCUMENT); + $ct = ''; + if ($new_comment) $ct .= ", comment='$new_comment'"; + if ($new_title) $ct .= ", title='$new_title'"; + api_sql_query("UPDATE $table_document SET" . substr($ct, 1) . + " WHERE id = '$docid'", __FILE__, __LINE__); + } + //check for missing images in html files + $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path); + if($missing_files) + { + //show a form to upload the missing files + Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name'])); + } + } +} +//missing images are submitted +if(isset($_POST['submit_image'])) +{ + $number_of_uploaded_images = count($_FILES['img_file']['name']); + //if images are uploaded + if ($number_of_uploaded_images > 0) + { + //we could also create a function for this, I'm not sure... + //create a directory for the missing files + $img_directory = str_replace('.','_',$_POST['related_file']."_files"); + $missing_files_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$img_directory); + //put the uploaded files in the new directory and get the paths + $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space); + //open the html file and replace the paths + replace_img_path_in_html_file($_POST['img_file_path'],$paths_to_replace_in_file,$base_work_dir.$_POST['related_file']); + //update parent folders + item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']); + } +} +//they want to create a directory +if(isset($_POST['create_dir']) && $_POST['dirname']!='') +{ + $added_slash = ($path=='/')?'':'/'; + $dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']); + $created_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']); + if($created_dir) + { + //Display::display_normal_message("".$created_dir." was created!"); + Display::display_normal_message(get_lang('DirCr')); + $path = $created_dir; + } + else + { + display_error(get_lang('CannotCreateDir')); + } +} + +//tracking not needed here? +//event_access_tool(TOOL_DOCUMENT); + +/*============================================================================*/ +?> + +'; + $new_folder_text .= ''; + $new_folder_text .= get_lang('NewDir') .' '; + $new_folder_text .= ''; + $new_folder_text .= ''; + $new_folder_text .= ''; + //show the form + Display::display_normal_message($new_folder_text); +} +else { //give them a link to create a directory + ?> +

    + + +
    + +
    + + +
    + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + +-
    +-
    +   
    +   
    +    + +
    + + +
    + + + +

    + + \ No newline at end of file diff --git a/main/user/user.php b/main/user/user.php index 20eb973153..1275bf2550 100644 --- a/main/user/user.php +++ b/main/user/user.php @@ -411,7 +411,7 @@ function get_user_data($from, $number_of_items, $column, $direction) ug.group_id group_id, sg.name FROM " . Database::get_course_table(GROUP_USER_TABLE) . " ug - LEFT JOIN " . Database::get_course_table(GROUP_TABLE) . " sg ON ug.group_id = sg.id + LEFT JOIN " . Database::get_course_table(TABLE_GROUP) . " sg ON ug.group_id = sg.id WHERE ug.user_id IN ('".implode("','", $user_ids)."')"; $res = api_sql_query($sql,__FILE__,__LINE__); @@ -481,7 +481,7 @@ function get_user_data($from, $number_of_items, $column, $direction) $sql = "SELECT ug.user_id, ug.group_id group_id, sg.name FROM ".Database::get_course_table(GROUP_USER_TABLE)." ug - LEFT JOIN ".Database::get_course_table(GROUP_TABLE)." sg + LEFT JOIN ".Database::get_course_table(TABLE_GROUP)." sg ON ug.group_id = sg.id WHERE ug.user_id IN ('".implode("','", $user_ids)."')"; $res = api_sql_query($sql,__FILE__,__LINE__); diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 57515458af..9c495d072f 100644 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -41,7 +41,7 @@ function display_action_links($always_show_tool_options, $always_show_upload_for function display_tool_options($uploadvisibledisabled, $origin) { $is_allowed_to_edit = api_is_allowed_to_edit(); - $work_table = Database::get_course_table(STUDENT_PUBLICATION_TABLE); + $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); if (! $is_allowed_to_edit) return; @@ -126,8 +126,8 @@ function display_default_visibility_form($uploadvisibledisabled, $origin) function display_student_publications_list($currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin) { //init - $work_table = Database::get_course_table(STUDENT_PUBLICATION_TABLE); - $iprop_table = Database::get_course_table(ITEM_PROPERTY_TABLE); + $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $is_allowed_to_edit = api_is_allowed_to_edit(); $user_id = api_get_user_id(); $publications_list = array(); diff --git a/main/work/work.php b/main/work/work.php index 24f3304862..a0e439e11f 100644 --- a/main/work/work.php +++ b/main/work/work.php @@ -113,8 +113,8 @@ $user_id = api_get_user_id(); $course_code = $_course['sysCode']; $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $_SESSION['id_session']); -$work_table = Database::get_course_table(STUDENT_PUBLICATION_TABLE); -$iprop_table = Database::get_course_table(ITEM_PROPERTY_TABLE); +$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); +$iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH) . $_course["path"]."/"; $currentCourseRepositoryWeb = api_get_path(WEB_COURSE_PATH) . $_course["path"]."/"; $currentUserFirstName = $_user['firstName']; diff --git a/myStudents.php b/myStudents.php index ca42ed0deb..64a151c87d 100644 --- a/myStudents.php +++ b/myStudents.php @@ -133,7 +133,7 @@ function exportCsv($a_infosUser,$tableTitle,$a_header,$a_dataLearnpath,$a_dataEx $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); $tbl_stats_exercices = Database :: get_statistic_table(STATISTIC_TRACK_E_EXERCICES_TABLE); - $course_student_publication = Database :: get_course_table(STUDENT_PUBLICATION_TABLE); + $course_student_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $statistics_database = Database :: get_statistic_database(); /** diff --git a/user_portal.php b/user_portal.php index e652cb3524..f0490e8dcd 100644 --- a/user_portal.php +++ b/user_portal.php @@ -547,8 +547,8 @@ function get_logged_user_course_html($my_course) // Table definitions //$statistic_database = Database::get_statistic_database(); - $course_tool_table = Database :: get_course_table(TOOL_LIST_TABLE, $course_database); - $tool_edit_table = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $course_database); + $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database); + $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database); $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database); $user_id = api_get_user_id(); @@ -777,8 +777,8 @@ function show_notification($my_course) $statistic_database = Database :: get_statistic_database(); $user_id = api_get_user_id(); $course_database = $my_course['db']; - $course_tool_table = Database::get_course_table(TOOL_LIST_TABLE, $course_database); - $tool_edit_table = Database::get_course_table(LAST_TOOL_EDIT_TABLE, $course_database); + $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database); + $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database); $course_group_user_table = Database :: get_course_table(GROUP_USER_TABLE, $course_database); // get the user's last access dates to all tools of this course $sqlLastTrackInCourse = "SELECT * FROM $statistic_database.track_e_lastaccess @@ -968,7 +968,7 @@ else ----------------------------------------------------------- */ $course_database = $my_course['db']; - $course_tool_table = Database::get_course_table(TOOL_LIST_TABLE, $course_database); + $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database); $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1"; $result = api_sql_query($query); // collect from announcements, but only if tool is visible for the course @@ -976,7 +976,7 @@ else { //Search announcements table //Take the entries listed at the top of advalvas/announcements tool - $course_announcement_table = Database :: get_course_announcement_table($thisCourseDbName); + $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT); $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content FROM ".$course_announcement_table; switch (CONFVAL_limitPreviewTo) @@ -1011,7 +1011,7 @@ else ----------------------------------------------------------- */ $course_database = $my_course['db']; - $course_tool_table = Database :: get_course_table(TOOL_LIST_TABLE,$course_database); + $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database); $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1"; $result = api_sql_query($query); $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda