From 7a11b484f5f21401d051353de69c400ec346e75c Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 10 Sep 2015 16:28:46 -0500 Subject: [PATCH 01/26] Show session_admin on Resume Session page - BT#10248 --- main/session/resume_session.php | 1 + main/template/default/session/resume_session.tpl | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/main/session/resume_session.php b/main/session/resume_session.php index 8ccc80f01b..b287b0eda7 100644 --- a/main/session/resume_session.php +++ b/main/session/resume_session.php @@ -377,6 +377,7 @@ $tpl = new Template(get_lang('Session')); $tpl->assign('session_header', $sessionHeader); $tpl->assign('title', $sessionTitle); $tpl->assign('general_coach', $generalCoach); +$tpl->assign('session_admin', api_get_user_info($session->getSessionAdminId())); $tpl->assign('session', $sessionInfo); $tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName()); $tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo)); diff --git a/main/template/default/session/resume_session.tpl b/main/template/default/session/resume_session.tpl index 88a6316e1b..a9248627dc 100644 --- a/main/template/default/session/resume_session.tpl +++ b/main/template/default/session/resume_session.tpl @@ -6,6 +6,10 @@ {{ title }} + + + + From 32deadc366dc36cd68f3c2960e2b0dc0df29ac86 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 10 Sep 2015 16:29:50 -0500 Subject: [PATCH 02/26] Minor - Update language files - refs BT#10248 --- main/lang/english/trad4all.inc.php | 1 + main/lang/spanish/trad4all.inc.php | 1 + 2 files changed, 2 insertions(+) diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index c2dbb8b348..088f08cf89 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -7510,4 +7510,5 @@ $SkillXDisabled = "Skill \"%s\" disabled"; $ShowFullSkillNameOnSkillWheelTitle = "Show full skill name on skill wheel"; $ShowFullSkillNameOnSkillWheelComment = "On the wheel of skills, it shows the name of the skill when it has short code."; $DBPort = "Port"; +$CreatedBy = "Created by"; ?> \ No newline at end of file diff --git a/main/lang/spanish/trad4all.inc.php b/main/lang/spanish/trad4all.inc.php index 1b72e48051..899fb2098c 100644 --- a/main/lang/spanish/trad4all.inc.php +++ b/main/lang/spanish/trad4all.inc.php @@ -7535,4 +7535,5 @@ $SkillXDisabled = "Competencia \"%s\" deshabilitada"; $ShowFullSkillNameOnSkillWheelTitle = "Mostrar nombre completo de la competencias en rueda de competencias"; $ShowFullSkillNameOnSkillWheelComment = "En la rueda de competencias, permite mostrar el nombre de la competencia cuando ésta tiene código corto."; $DBPort = "Puerto"; +$CreatedBy = "Creado por"; ?> \ No newline at end of file From 00372ccfacaa7688990ad616a2273ec035ffc2de Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 08:42:52 +0200 Subject: [PATCH 03/26] Fix session_id in queries. --- .../classes/CourseBuilder.class.php | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/main/coursecopy/classes/CourseBuilder.class.php b/main/coursecopy/classes/CourseBuilder.class.php index a03263df58..926cb85732 100755 --- a/main/coursecopy/classes/CourseBuilder.class.php +++ b/main/coursecopy/classes/CourseBuilder.class.php @@ -163,6 +163,7 @@ class CourseBuilder } } } + // Once we've built the resources array a bit more, try to get items // from the item_property table and order them in the "resources" array foreach ($this->course->resources as $type => $resources) { @@ -173,7 +174,7 @@ class CourseBuilder WHERE c_id = $courseId AND tool = '".$tool."' AND - ref='".$resource->get_id()."'"; + ref = '".$resource->get_id()."'"; $res = Database::query($sql); $all_properties = array(); while ($item_property = Database::fetch_array($res)) { @@ -276,7 +277,7 @@ class CourseBuilder p.visibility != 2 AND path NOT LIKE '/images/gallery%' AND $avoid_paths AND - d.session_id = 0 + (d.session_id = 0 OR d.session_id IS NULL) ORDER BY path"; } else { $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size @@ -288,7 +289,7 @@ class CourseBuilder tool = '".TOOL_DOCUMENT."' AND p.visibility != 2 AND $avoid_paths AND - d.session_id = 0 + (d.session_id = 0 OR d.session_id IS NULL) ORDER BY path"; } @@ -484,7 +485,7 @@ class CourseBuilder p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND - l.session_id = 0 + (l.session_id = 0 OR l.session_id IS NULL) ORDER BY l.display_order"; } @@ -536,7 +537,8 @@ class CourseBuilder $with_base_content ); - $sql = "SELECT * FROM $table WHERE c_id = $courseId $sessionCondition"; + $sql = "SELECT * FROM $table + WHERE c_id = $courseId $sessionCondition"; $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { @@ -609,7 +611,7 @@ class CourseBuilder //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes) } else { $sql = "SELECT * FROM $table_qui - WHERE c_id = $courseId AND active >=0 AND session_id = 0"; + WHERE c_id = $courseId AND active >=0 AND (session_id = 0 OR session_id IS NULL)"; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes) } @@ -933,7 +935,8 @@ class CourseBuilder $with_base_content ); - $sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$courseId.' '.$sessionCondition; + $sql = 'SELECT * FROM '.$table_survey.' + WHERE c_id = '.$courseId.' '.$sessionCondition; $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { $survey = new Survey( @@ -1189,7 +1192,7 @@ class CourseBuilder WHERE c_id = '.$courseId.' '.$session_condition; } else { $sql = 'SELECT * FROM '.$table_main.' - WHERE c_id = '.$courseId.' AND session_id = 0'; + WHERE c_id = '.$courseId.' AND (session_id = 0 OR session_id IS NULL)'; } if (!empty($id_list)) { @@ -1201,7 +1204,8 @@ class CourseBuilder if ($db_result) { while ($obj = Database::fetch_object($db_result)) { $items = array(); - $sql_items = "SELECT * FROM ".$table_item." WHERE c_id = '$courseId' AND lp_id = ".$obj->id; + $sql_items = "SELECT * FROM ".$table_item." + WHERE c_id = '$courseId' AND lp_id = ".$obj->id; $db_items = Database::query($sql_items); while ($obj_item = Database::fetch_object($db_items)) { $item['id'] = $obj_item->id; @@ -1316,19 +1320,21 @@ class CourseBuilder } //@todo check this queries are the same ... if (!empty($this->course->type) && $this->course->type == 'partial') { - $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$courseId.' '.$session_condition; + $sql = 'SELECT * FROM '.$table_glossary.' g + WHERE g.c_id = '.$courseId.' '.$session_condition; } else { - $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$courseId.' '.$session_condition; + $sql = 'SELECT * FROM '.$table_glossary.' g + WHERE g.c_id = '.$courseId.' '.$session_condition; } } else { $table_glossary = Database:: get_course_table(TABLE_GLOSSARY); //@todo check this queries are the same ... ayayay if (!empty($this->course->type) && $this->course->type == 'partial') { $sql = 'SELECT * FROM '.$table_glossary.' g - WHERE g.c_id = '.$courseId.' AND session_id = 0'; + WHERE g.c_id = '.$courseId.' AND (session_id = 0 OR session_id IS NULL)'; } else { $sql = 'SELECT * FROM '.$table_glossary.' g - WHERE g.c_id = '.$courseId.' AND session_id = 0'; + WHERE g.c_id = '.$courseId.' AND (session_id = 0 OR session_id IS NULL)'; } } $db_result = Database::query($sql); @@ -1415,7 +1421,7 @@ class CourseBuilder } else { $tbl_wiki = Database::get_course_table(TABLE_WIKI); $sql = 'SELECT * FROM '.$tbl_wiki.' - WHERE c_id = '.$courseId.' AND session_id = 0'; + WHERE c_id = '.$courseId.' AND (session_id = 0 OR session_id IS NULL)'; } $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { @@ -1497,10 +1503,7 @@ class CourseBuilder t.c_id = $courseId AND tp.c_id = $courseId AND thematic_id = {$row['id']} AND - tp.id IN (".implode( - ', ', - $thematic_plan_id_list - ).") "; + tp.id IN (".implode(', ', $thematic_plan_id_list).") "; $result = Database::query($sql); while ($sub_row = Database::fetch_array($result, 'ASSOC')) { From a17d52df4a19559365fc8ac454d6b00a7176822f Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 09:23:13 +0200 Subject: [PATCH 04/26] Fixing PHP warnings. --- .../classes/CourseRecycler.class.php | 31 ++-- .../classes/CourseRestorer.class.php | 155 ++++++++++++------ 2 files changed, 123 insertions(+), 63 deletions(-) diff --git a/main/coursecopy/classes/CourseRecycler.class.php b/main/coursecopy/classes/CourseRecycler.class.php index 417e4328f4..8087dc49cc 100755 --- a/main/coursecopy/classes/CourseRecycler.class.php +++ b/main/coursecopy/classes/CourseRecycler.class.php @@ -46,9 +46,9 @@ class CourseRecycler $this->type = $type; - $table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO); + $table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO); $table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES); - $table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY); + $table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY); $this->recycle_links(); $this->recycle_link_categories(); @@ -117,7 +117,8 @@ class CourseRecycler } $ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT]))); - $sql = "DELETE FROM $table WHERE c_id = ".$this->course_id." AND id IN(".$ids.")"; + $sql = "DELETE FROM $table + WHERE c_id = ".$this->course_id." AND id IN(".$ids.")"; Database::query($sql); } } @@ -129,8 +130,8 @@ class CourseRecycler public function recycle_wiki() { if ($this->course->has_resources(RESOURCE_WIKI)) { - $table_wiki = Database::get_course_table(TABLE_WIKI); - $table_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF); + $table_wiki = Database::get_course_table(TABLE_WIKI); + $table_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF); $pages = array(); foreach ($this->course->resources[RESOURCE_WIKI] as $resource) { $pages[] = $resource->page_id; @@ -138,9 +139,11 @@ class CourseRecycler $wiki_ids = implode(',', (array_keys($this->course->resources[RESOURCE_WIKI]))); $page_ids = implode(',', $pages); - $sql = "DELETE FROM ".$table_wiki." WHERE c_id = ".$this->course_id." AND id IN(".$wiki_ids.")"; + $sql = "DELETE FROM ".$table_wiki." + WHERE c_id = ".$this->course_id." AND id IN(".$wiki_ids.")"; Database::query($sql); - $sql = "DELETE FROM ".$table_wiki_conf." WHERE c_id = ".$this->course_id." AND page_id IN(".$page_ids.")"; + $sql = "DELETE FROM ".$table_wiki_conf." + WHERE c_id = ".$this->course_id." AND page_id IN(".$page_ids.")"; Database::query($sql); } } @@ -279,7 +282,6 @@ class CourseRecycler WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")"; Database::query($sql); } - } /** @@ -374,10 +376,11 @@ class CourseRecycler public function recycle_quizzes() { if ($this->course->has_resources(RESOURCE_QUIZ)) { + $table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION); $table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER); - $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); - $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); + $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); + $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); $table_qui_que_opt = Database :: get_course_table(TABLE_QUIZ_QUESTION_OPTION); $table_qui_que_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $table_qui_que_rel_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); @@ -617,7 +620,13 @@ class CourseRecycler } $cond = array('id = ? AND c_id = ?'=>array($last_id, $this->course_id)); Database::delete($table_attendance, $cond); - api_item_property_update($this->course_info, TOOL_ATTENDANCE, $last_id,'AttendanceDeleted', api_get_user_id()); + api_item_property_update( + $this->course_info, + TOOL_ATTENDANCE, + $last_id, + 'AttendanceDeleted', + api_get_user_id() + ); } } } diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 1cdb9cc2a8..648df55dbe 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -78,6 +78,7 @@ class CourseRestorer * **/ public $add_text_in_items = false; + public $destination_course_id; /** * Create a new CourseRestorer @@ -149,7 +150,9 @@ class CourseRestorer $this->destination_course_id = $course_info['real_id']; //Getting first teacher (for the forums) - $teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['code']); + $teacher_list = CourseManager::get_teacher_list_from_course_code( + $course_info['code'] + ); $this->first_teacher_id = api_get_user_id(); if (!empty($teacher_list)) { @@ -194,48 +197,70 @@ class CourseRestorer } // Restore the item properties - $table = Database :: get_course_table(TABLE_ITEM_PROPERTY); + $table = Database::get_course_table(TABLE_ITEM_PROPERTY); foreach ($this->course->resources as $type => $resources) { - if (is_array($resources)) { - foreach ($resources as $id => $resource) { - foreach ($resource->item_properties as $property) { - // First check if there isn't already a record for this resource - $sql = "SELECT * FROM $table - WHERE - c_id = ".$this->destination_course_id." AND - tool = '".$property['tool']."' AND - ref = '".$resource->destination_id."'"; - - $params = []; - if (!empty($session_id)) { - $params['session_id'] = intval($session_id); - } + if (is_array($resources)) { + foreach ($resources as $id => $resource) { + if (isset($resource->item_properties)) { + foreach ($resource->item_properties as $property) { + // First check if there isn't already a record for this resource + $sql = "SELECT * FROM $table + WHERE + c_id = ".$this->destination_course_id." AND + tool = '".$property['tool']."' AND + ref = '".$resource->destination_id."'"; - $res = Database::query($sql); - if (Database::num_rows($res) == 0) { - /* The to_group_id and to_user_id are set to default - values as users/groups possibly not exist in - the target course*/ - - $params['c_id'] = $this->destination_course_id; - $params['tool'] = self::DBUTF8($property['tool']); - $params['insert_user_id'] = self::DBUTF8($property['insert_user_id']); - $params['insert_date'] = self::DBUTF8($property['insert_date']); - $params['lastedit_date'] = self::DBUTF8($property['lastedit_date']); - $params['ref'] = $resource->destination_id; - $params['lastedit_type'] = self::DBUTF8($property['lastedit_type']); - $params['lastedit_user_id'] = self::DBUTF8($property['lastedit_user_id']); - $params['visibility'] = self::DBUTF8($property['visibility']); - $params['start_visible'] = self::DBUTF8($property['start_visible']); - $params['end_visible'] = self::DBUTF8($property['end_visible']); - $params['to_user_id'] = self::DBUTF8($property['to_user_id']); - //$params['to_group_id'] = 'NULL'; - - $id = Database::insert($table, $params); - if ($id) { - $sql = "UPDATE $table SET id = iid WHERE iid = $id"; - Database::query($sql); + $params = []; + if (!empty($session_id)) { + $params['session_id'] = intval($session_id); + } + + $res = Database::query($sql); + if (Database::num_rows($res) == 0) { + /* The to_group_id and to_user_id are set to default + values as users/groups possibly not exist in + the target course*/ + + $params['c_id'] = $this->destination_course_id; + $params['tool'] = self::DBUTF8( + $property['tool'] + ); + $params['insert_user_id'] = self::DBUTF8( + $property['insert_user_id'] + ); + $params['insert_date'] = self::DBUTF8( + $property['insert_date'] + ); + $params['lastedit_date'] = self::DBUTF8( + $property['lastedit_date'] + ); + $params['ref'] = $resource->destination_id; + $params['lastedit_type'] = self::DBUTF8( + $property['lastedit_type'] + ); + $params['lastedit_user_id'] = self::DBUTF8( + $property['lastedit_user_id'] + ); + $params['visibility'] = self::DBUTF8( + $property['visibility'] + ); + $params['start_visible'] = self::DBUTF8( + $property['start_visible'] + ); + $params['end_visible'] = self::DBUTF8( + $property['end_visible'] + ); + $params['to_user_id'] = self::DBUTF8( + $property['to_user_id'] + ); + //$params['to_group_id'] = 'NULL'; + + $id = Database::insert($table, $params); + if ($id) { + $sql = "UPDATE $table SET id = iid WHERE iid = $id"; + Database::query($sql); + } } } } @@ -868,7 +893,7 @@ class CourseRestorer $params = [ 'c_id' => $this->destination_course_id, - 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), + 'path' => "/".self::DBUTF8("/".substr($document->path, 9)), 'comment'=> self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), @@ -1087,7 +1112,7 @@ class CourseRestorer } } if ($forum_cat && !$forum_cat->is_restored()) { - $title = $forum_cat->obj->cat_title; + /*$title = $forum_cat->obj->cat_title; if (!empty($title)) { if (!preg_match('/.*\((.+)\)$/', $title, $matches)) { // This is for avoiding repetitive adding of training code after several backup/restore cycles. @@ -1095,7 +1120,7 @@ class CourseRestorer $title = $title.' ('.$this->course->code.')'; } } - } + }*/ $params = (array) $forum_cat->obj; $params['c_id'] = $this->destination_course_id; $params['cat_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( @@ -1237,9 +1262,14 @@ class CourseRestorer if ($this->course->has_resources(RESOURCE_LINK)) { $link_table = Database :: get_course_table(TABLE_LINK); $resources = $this->course->resources; + foreach ($resources[RESOURCE_LINK] as $id => $link) { - $cat_id = $this->restore_link_category($link->category_id, $session_id); - $sql = "SELECT MAX(display_order) FROM $link_table + $cat_id = $this->restore_link_category( + $link->category_id, + $session_id + ); + $sql = "SELECT MAX(display_order) + FROM $link_table WHERE c_id = ".$this->destination_course_id." AND category_id='" . intval($cat_id). "'"; @@ -1264,9 +1294,21 @@ class CourseRestorer if ($id) { $sql = "UPDATE $link_table SET id = iid WHERE iid = $id"; Database::query($sql); - } - $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; + api_item_property_update( + $this->destination_course_info, + TOOL_LINK, + $id, + 'LinkAdded', + api_get_user_id() + ); + + if (!isset($this->course->resources[RESOURCE_LINK][$id])) { + $this->course->resources[RESOURCE_LINK][$id] = new stdClass(); + } + $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; + + } } } } @@ -1304,6 +1346,7 @@ class CourseRestorer if ($new_id) { $sql = "UPDATE $link_cat_table SET id = iid WHERE iid = $new_id"; Database::query($sql); + api_set_default_visibility($new_id, TOOL_LINK_CATEGORY); } $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id; @@ -1347,9 +1390,13 @@ class CourseRestorer if ($id) { $sql = "UPDATE $tool_intro_table SET id = iid WHERE iid = $id"; Database::query($sql); - } - $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id; + if (!isset($this->course->resources[RESOURCE_TOOL_INTRO][$id])) { + $this->course->resources[RESOURCE_TOOL_INTRO][$id] = new stdClass(); + } + + $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id; + } } } } @@ -1387,11 +1434,15 @@ class CourseRestorer if ($new_event_id) { $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; Database::query($sql); - } - $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; + if (!isset($this->course->resources[RESOURCE_EVENT][$id])) { + $this->course->resources[RESOURCE_EVENT][$id] = new stdClass(); + } + + $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; + } - //Copy event attachment + // Copy event attachment $origin_path = $this->course->backup_path.'/upload/calendar/'; $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; From ce40418e537a20c2ef3ac5b60bc55aaec6bc3790 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 09:23:29 +0200 Subject: [PATCH 05/26] Minor - format code. --- main/admin/index.php | 5 +++-- main/coursecopy/recycle_course.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/main/admin/index.php b/main/admin/index.php index 8cb9db6bb5..b36e6f8152 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -36,7 +36,9 @@ if (api_is_multiple_url_enabled()) { $message = ''; if (api_is_platform_admin()) { - if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) && !is_writable(api_get_path(SYS_ARCHIVE_PATH))) { + if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) && + !is_writable(api_get_path(SYS_ARCHIVE_PATH)) + ) { $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'warning'); } @@ -76,7 +78,6 @@ if (!empty($hook)) { } /* Users */ - $blocks['users']['icon'] = Display::return_icon('members.gif', get_lang('Users'), array(), ICON_SIZE_MEDIUM, false); $blocks['users']['label'] = api_ucfirst(get_lang('Users')); $blocks['users']['class'] = 'block-admin-users'; diff --git a/main/coursecopy/recycle_course.php b/main/coursecopy/recycle_course.php index 053db7a29c..1af50c0f0c 100755 --- a/main/coursecopy/recycle_course.php +++ b/main/coursecopy/recycle_course.php @@ -1,5 +1,6 @@ Date: Fri, 11 Sep 2015 09:52:38 +0200 Subject: [PATCH 06/26] Minor - format code. --- .../classes/CourseSelectForm.class.php | 25 ++++++++++++------- main/coursecopy/import_backup.php | 7 +++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/main/coursecopy/classes/CourseSelectForm.class.php b/main/coursecopy/classes/CourseSelectForm.class.php index dfcc6445b4..3460481d64 100755 --- a/main/coursecopy/classes/CourseSelectForm.class.php +++ b/main/coursecopy/classes/CourseSelectForm.class.php @@ -394,11 +394,10 @@ class CourseSelectForm // Loading the results from the checkboxes of ethe javascript $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; - $course_info = api_get_course_info($course_code); - $table_doc = Database::get_course_table(TABLE_DOCUMENT); - $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); - - $course_id = $course_info['real_id']; + $course_info = api_get_course_info($course_code); + $table_doc = Database::get_course_table(TABLE_DOCUMENT); + $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); + $course_id = $course_info['real_id']; /* Searching the documents resource that have been set to null because $avoid_serialize is true in the display_form() function*/ @@ -420,13 +419,20 @@ class CourseSelectForm WHERE d.c_id = '.$course_id.' AND p.c_id = '.$course_id.' AND - tool = \''.TOOL_DOCUMENT.'\' AND - p.ref = d.id AND p.visibility != 2 AND - d.id = '.$resource_item.$condition_session.' + tool = \''.TOOL_DOCUMENT.'\' AND + p.ref = d.id AND p.visibility != 2 AND + d.id = '.$resource_item.$condition_session.' ORDER BY path'; $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { - $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size); + $doc = new Document( + $obj->id, + $obj->path, + $obj->comment, + $obj->title, + $obj->filetype, + $obj->size + ); if ($doc) { $course->add_resource($doc); // adding item property @@ -449,6 +455,7 @@ class CourseSelectForm if (is_array($course->resources)) { foreach ($course->resources as $type => $resources) { + switch ($type) { case RESOURCE_SURVEYQUESTION: foreach($resources as $id => $obj) { diff --git a/main/coursecopy/import_backup.php b/main/coursecopy/import_backup.php index 48cf94412f..cf15d11a2d 100755 --- a/main/coursecopy/import_backup.php +++ b/main/coursecopy/import_backup.php @@ -7,8 +7,7 @@ * @package chamilo.backup */ -// Including the global initialization file -require '../inc/global.inc.php'; +require_once '../inc/global.inc.php'; $current_course_tool = TOOL_COURSE_MAINTENANCE; api_protect_course_script(true); @@ -71,7 +70,9 @@ if (Security::check_token('post') && ( $delete_file = false; } else { if ($_FILES['backup']['error'] == 0) { - $filename = CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']); + $filename = CourseArchiver::import_uploaded_file( + $_FILES['backup']['tmp_name'] + ); if ($filename === false) { $error = true; } else { From a5ac9aa8e7ba6eb150dafec3ba958e3480143aa2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 09:52:59 +0200 Subject: [PATCH 07/26] Fix PHP warnings, fix import from zip --- .../classes/CourseRestorer.class.php | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 648df55dbe..7530c00de2 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -1307,7 +1307,6 @@ class CourseRestorer $this->course->resources[RESOURCE_LINK][$id] = new stdClass(); } $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; - } } } @@ -1544,9 +1543,12 @@ class CourseRestorer if ($id) { $sql = "UPDATE $table SET id = iid WHERE iid = $id"; Database::query($sql); - } - $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id; + if (!isset($this->course->resources[RESOURCE_COURSEDESCRIPTION][$id])) { + $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id] = new stdClass(); + } + $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id; + } } } } @@ -1586,10 +1588,12 @@ class CourseRestorer if ($new_announcement_id) { $sql = "UPDATE $table SET id = iid WHERE iid = $id"; Database::query($sql); + if (!isset($this->course->resources[RESOURCE_ANNOUNCEMENT][$id])) { + $this->course->resources[RESOURCE_ANNOUNCEMENT][$id] = new stdClass(); + } + $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id; } - $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id; - $origin_path = $this->course->backup_path.'/upload/announcements/'; $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/'; @@ -2451,7 +2455,7 @@ class CourseRestorer 'author' => self::DBUTF8($lp->author), 'preview_image' => self::DBUTF8($lp->preview_image), 'use_max_score' => self::DBUTF8($lp->use_max_score), - 'autolaunch' => self::DBUTF8($lp->autolaunch), + 'autolaunch' => self::DBUTF8(isset($lp->autolaunch) ? $lp->autolaunch : ''), 'created_on' => self::DBUTF8($lp->created_on), 'modified_on' => self::DBUTF8($lp->modified_on), 'publicated_on' => empty($lp->publicated_on) ? api_get_utc_datetime() : self::DBUTF8($lp->publicated_on), @@ -2818,8 +2822,6 @@ class CourseRestorer foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) { $params = []; - - $condition_session = ""; if (!empty($session_id)) { $session_id = intval($session_id); $params['session_id'] = $session_id; @@ -2841,6 +2843,10 @@ class CourseRestorer $my_id = Database::insert($table_glossary, $params); if ($my_id) { + + $sql = "UPDATE $table_glossary SET glossary_id = iid WHERE iid = $my_id"; + Database::query($sql); + api_item_property_update( $this->destination_course_info, TOOL_GLOSSARY, @@ -2848,6 +2854,11 @@ class CourseRestorer "GlossaryAdded", api_get_user_id() ); + + if (!isset($this->course->resources[RESOURCE_GLOSSARY][$id])) { + $this->course->resources[RESOURCE_GLOSSARY][$id] = new stdClass(); + } + $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id; } } @@ -2941,6 +2952,7 @@ class CourseRestorer $resources = $this->course->resources; foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) { + // check resources inside html from ckeditor tool and copy correct urls into recipient course $thematic->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( $thematic->content, @@ -2952,9 +2964,10 @@ class CourseRestorer $thematic->params['c_id'] = $this->destination_course_id; unset($thematic->params['id']); unset($thematic->params['iid']); + var_dump($thematic->params); $last_id = Database::insert($table_thematic, $thematic->params, false); - if (is_numeric($last_id)) { + if ($last_id) { $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id"; Database::query($sql); @@ -2973,9 +2986,13 @@ class CourseRestorer $thematic_advance['attendance_id'] = 0; $thematic_advance['thematic_id'] = $last_id; $thematic_advance['c_id'] = $this->destination_course_id; - $my_id = Database::insert($table_thematic_advance, $thematic_advance, false); + $my_id = Database::insert( + $table_thematic_advance, + $thematic_advance, + false + ); - if (is_numeric($my_id)) { + if ($my_id) { $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id"; Database::query($sql); @@ -2997,7 +3014,7 @@ class CourseRestorer $thematic_plan['c_id'] = $this->destination_course_id; $my_id = Database::insert($table_thematic_plan, $thematic_plan, false); - if (is_numeric($my_id)) { + if ($my_id) { $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id"; Database::query($sql); From c0b18f0cea0a97e860ee3eb928e6f02bd7950e2c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 09:54:49 +0200 Subject: [PATCH 08/26] Remove var_dump --- main/coursecopy/classes/CourseRestorer.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 7530c00de2..d2477cd886 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -2951,8 +2951,6 @@ class CourseRestorer $resources = $this->course->resources; foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) { - - // check resources inside html from ckeditor tool and copy correct urls into recipient course $thematic->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( $thematic->content, @@ -2964,7 +2962,7 @@ class CourseRestorer $thematic->params['c_id'] = $this->destination_course_id; unset($thematic->params['id']); unset($thematic->params['iid']); - var_dump($thematic->params); + $last_id = Database::insert($table_thematic, $thematic->params, false); if ($last_id) { From 8d4f4df1af5e37d6260324a65a17033f04c0c6a6 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 09:57:19 +0200 Subject: [PATCH 09/26] Minor - format code. --- main/newscorm/learnpath.class.php | 57 +++++++++++++------------------ 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 8aebb62f6b..4e2392b071 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -1046,12 +1046,14 @@ class learnpath if ($this->type == 2 || $this->type == 3) { // This is a scorm learning path, delete the files as well. - $sql = "SELECT path FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id; + $sql = "SELECT path FROM $lp + WHERE c_id = ".$course_id." AND id = " . $this->lp_id; $res = Database::query($sql); if (Database :: num_rows($res) > 0) { $row = Database :: fetch_array($res); $path = $row['path']; - $sql = "SELECT id FROM $lp WHERE c_id = ".$course_id." AND path = '$path' AND id != " . $this->lp_id; + $sql = "SELECT id FROM $lp + WHERE c_id = ".$course_id." AND path = '$path' AND id != " . $this->lp_id; $res = Database::query($sql); if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it. if ($this->debug > 2) { @@ -1079,7 +1081,8 @@ class learnpath $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST); $link = 'newscorm/lp_controller.php?action=view&lp_id='.$this->lp_id; // Delete tools - $sql = "DELETE FROM $tbl_tool WHERE c_id = ".$course_id." AND (link LIKE '$link%' AND image='scormbuilder.gif')"; + $sql = "DELETE FROM $tbl_tool + WHERE c_id = ".$course_id." AND (link LIKE '$link%' AND image='scormbuilder.gif')"; Database::query($sql); $sql = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id; @@ -1095,20 +1098,6 @@ class learnpath api_get_user_id() ); - // Delete link of gradebook tool - //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); - /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";'; - $result = Database::query($sql); - $row = Database :: fetch_array($result, 'ASSOC');*/ - - // Fixing gradebook link deleted see #5229. - /* - if (!empty($row['id'])) { - $link = LinkFactory :: load($row['id']); - if ($link[0] != null) { - $link[0]->delete(); - } - }*/ $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id()); if ($link_info !== false) { GradebookUtils::remove_resource_from_course_gradebook($link_info['id']); @@ -1588,12 +1577,12 @@ class learnpath $row_parent = Database :: fetch_array($res_parent); $parent = $row_parent['parent_item_id']; $sql_bros = "SELECT * FROM $lp_item - WHERE - c_id = ".$course_id." AND - parent_item_id = $parent AND - id = $id AND - item_type='dokeos_chapter' - ORDER BY display_order"; + WHERE + c_id = ".$course_id." AND + parent_item_id = $parent AND + id = $id AND + item_type='dokeos_chapter' + ORDER BY display_order"; $res_bros = Database::query($sql_bros); $list = array (); while ($row_bro = Database :: fetch_array($res_bros)) { @@ -1610,7 +1599,8 @@ class learnpath * @param integer Item ID * @return array A list of all the "brother items" (or an empty array on failure) */ - public function get_brother_items($id) { + public function get_brother_items($id) + { $course_id = api_get_course_int_id(); if ($this->debug > 0) { error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0); @@ -1965,6 +1955,7 @@ class learnpath '; } + return $navbar; } @@ -2125,7 +2116,7 @@ class learnpath $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' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter')) { + while (isset($this->ordered_items[$index]) && ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter')) { $index--; if ($index < 0) { return $this->index; @@ -2588,7 +2579,6 @@ class learnpath */ public function get_preview_image_path($size = null, $path_type = 'web') { - $preview_image = $this->get_preview_image(); if (isset($preview_image) && !empty($preview_image)) { $image_sys_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/'; @@ -2618,7 +2608,7 @@ class learnpath /** * Gets the learnpath author - * @return string LP's author + * @return string LP's author */ public function get_author() { @@ -3895,9 +3885,9 @@ class learnpath /** * Move a learnpath up (display_order) - * @param integer Learnpath ID + * @param integer $lp_id Learnpath ID */ - public function move_up($lp_id) + public static function move_up($lp_id) { $course_id = api_get_course_int_id(); $lp_table = Database :: get_course_table(TABLE_LP_MAIN); @@ -3942,9 +3932,9 @@ class learnpath /** * Move a learnpath down (display_order) - * @param integer Learnpath ID + * @param integer $lp_id Learnpath ID */ - public function move_down($lp_id) + public static function move_down($lp_id) { $course_id = api_get_course_int_id(); $lp_table = Database :: get_course_table(TABLE_LP_MAIN); @@ -3952,8 +3942,9 @@ class learnpath WHERE c_id = ".$course_id." ORDER BY display_order"; $res = Database::query($sql); - if ($res === false) + if ($res === false) { return false; + } $lps = array (); $lp_order = array (); $num = Database :: num_rows($res); @@ -3968,7 +3959,7 @@ class learnpath $need_fix = true; $sql_u = "UPDATE $lp_table SET display_order = $i WHERE c_id = ".$course_id." AND id = " . $row['id']; - $res_u = Database::query($sql_u); + Database::query($sql_u); } $row['display_order'] = $i; $lps[$row['id']] = $row; From 8371a3754f643658cd9e71e811bbd804bb560373 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 10:06:37 +0200 Subject: [PATCH 10/26] XFrameOptions work around see BT#10217 --- main/newscorm/blank.php | 11 ++++++++ main/newscorm/learnpath.class.php | 44 +++++++++++++++++++++++++++++++ main/newscorm/lp_content.php | 2 ++ main/newscorm/lp_view.php | 33 +++++++++++++++-------- 4 files changed, 79 insertions(+), 11 deletions(-) diff --git a/main/newscorm/blank.php b/main/newscorm/blank.php index b2a7ea6c71..57be87bc21 100755 --- a/main/newscorm/blank.php +++ b/main/newscorm/blank.php @@ -28,6 +28,17 @@ if (isset($_GET['error'])) { echo '

'; Display::display_warning_message(get_lang('ReachedOneAttempt')); break; + case 'x_frames_options': + if (isset($_SESSION['x_frame_source'])) { + $src = $_SESSION['x_frame_source']; + echo Display::return_message( + Display::url($src, $src, ['target' => '_blank']), + 'normal', + false + ); + unset($_SESSION['x_frame_source']); + } + break; default: break; } diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 4e2392b071..58fc5069b5 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -10348,6 +10348,50 @@ EOD; return $totalExercisesResult + $totalEvaluationResult; } + + /** + * Check if URL is not allowed to be show in a iframe + * @param string $src + * + * @return string + */ + public function checkXFrameOptions($src) + { + if (strpos($src, api_get_path(WEB_CODE_PATH)) === false) { + // Check X-Frame-Options + $ch = curl_init(); + + $options = array( + CURLOPT_URL => $src, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_ENCODING => "", + CURLOPT_AUTOREFERER => true, + CURLOPT_CONNECTTIMEOUT => 120, + CURLOPT_TIMEOUT => 120, + CURLOPT_MAXREDIRS => 10, + ); + curl_setopt_array($ch, $options); + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch); + $headers = substr($response, 0, $httpCode['header_size']); + + $error = false; + if (stripos($headers, 'X-Frame-Options: DENY') > -1 || + stripos($headers, 'X-Frame-Options: SAMEORIGIN')>-1 + ) { + $error = true; + } + + if ($error) { + $_SESSION['x_frame_source'] = $src; + $src = 'blank.php?error=x_frames_options'; + } + } + + return $src; + } } if (!function_exists('trim_value')) { diff --git a/main/newscorm/lp_content.php b/main/newscorm/lp_content.php index 1ddecf3c11..98cf761d98 100755 --- a/main/newscorm/lp_content.php +++ b/main/newscorm/lp_content.php @@ -56,6 +56,8 @@ if ($dokeos_chapter) { } else { $src = 'blank.php?error=prerequisites'; } + + $src = $_SESSION['oLP']->checkXFrameOptions($src); break; case 2: $_SESSION['oLP']->stop_previous_item(); diff --git a/main/newscorm/lp_view.php b/main/newscorm/lp_view.php index a908584326..7eae567c48 100755 --- a/main/newscorm/lp_view.php +++ b/main/newscorm/lp_view.php @@ -150,19 +150,27 @@ if (!isset($src)) { $htmlHeadXtra[] = ''; $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); if ($prereq_check === true) { - $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list); + $src = $_SESSION['oLP']->get_link( + 'http', + $lp_item_id, + $get_toc_list + ); // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP. $file_info = parse_url($src); - $file_info = pathinfo($file_info['path']); + if (isset($file_info['path'])) { + $file_info = pathinfo($file_info['path']); + } + if ( isset($file_info['extension']) && api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf') ) { - $src = api_get_path(WEB_CODE_PATH) - . 'newscorm/lp_view_item.php?lp_item_id=' . $lp_item_id - . '&' . api_get_cidreq(); + $src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?lp_item_id='.$lp_item_id.'&'.api_get_cidreq(); } + + $src = $_SESSION['oLP']->checkXFrameOptions($src); + $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset } else { $src = 'blank.php?error=prerequisites'; @@ -183,11 +191,14 @@ if (!isset($src)) { case 3: // aicc $_SESSION['oLP']->stop_previous_item(); // save status manually if asset - $htmlHeadXtra[] = ''; + $htmlHeadXtra[] = ''; $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); if ($prereq_check === true) { - $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list); + $src = $_SESSION['oLP']->get_link( + 'http', + $lp_item_id, + $get_toc_list + ); $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset } else { $src = 'blank.php'; @@ -294,7 +305,8 @@ $save_setting = api_get_setting('show_navigation_menu'); global $_setting; $_setting['show_navigation_menu'] = 'false'; $scorm_css_header = true; -$lp_theme_css = $_SESSION['oLP']->get_theme(); // Sets the css theme of the LP this call is also use at the frames (toc, nav, message). +$lp_theme_css = $_SESSION['oLP']->get_theme(); +// Sets the css theme of the LP this call is also use at the frames (toc, nav, message). if ($_SESSION['oLP']->mode == 'fullscreen') { $htmlHeadXtra[] = ""; @@ -391,8 +403,7 @@ if (api_get_course_setting('lp_return_link') == 1) { $buttonHomeText = get_lang('LearningPathList'); } -$lpPreviewImagePath = 'unknown.png'; - +$lpPreviewImagePath = api_get_path(WEB_CODE_PATH).'img/icons/64/unknown.png'; if ($_SESSION['oLP']->get_preview_image()) { $lpPreviewImagePath = $_SESSION['oLP']->get_preview_image_path(); } From 861027dd44c00fd2fd893d26bf72a9958a5f73b0 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 10:35:10 +0200 Subject: [PATCH 11/26] Minor - no particular background in the blank.php page --- main/newscorm/blank.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main/newscorm/blank.php b/main/newscorm/blank.php index 57be87bc21..f36156134b 100755 --- a/main/newscorm/blank.php +++ b/main/newscorm/blank.php @@ -9,6 +9,11 @@ $use_anonymous = true; require_once '../inc/global.inc.php'; Display::display_reduced_header(); +$htmlHeadXtra[] = " + +"; if (isset($_GET['error'])) { switch ($_GET['error']){ From e0a8d7fdf89737ce244c3899f92377fc913f5a1f Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 10:54:17 +0200 Subject: [PATCH 12/26] Fix delete button see #7825 --- main/inc/lib/attendance.lib.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php index 7341c73979..af7312a547 100755 --- a/main/inc/lib/attendance.lib.php +++ b/main/inc/lib/attendance.lib.php @@ -198,7 +198,7 @@ class Attendance Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).''; $attendance[2] = ''.$attendance[2].''; } - if ($allowDelete) { + if ($allowDelete === 'true') { $actions .= '' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . ''; } @@ -487,6 +487,7 @@ class Attendance $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); $user_id = api_get_user_id(); $course_id = $_course['real_id']; + if (is_array($attendance_id)) { foreach ($attendance_id as $id) { $id = intval($id); @@ -506,9 +507,10 @@ class Attendance } } } else { - $attendance_id = intval($attendance_id); + $attendance_id= intval($attendance_id); $sql = "UPDATE $tbl_attendance SET active = 2 WHERE c_id = $course_id AND id = '$attendance_id'"; + $result = Database::query($sql); $affected_rows = Database::affected_rows($result); if (!empty($affected_rows)) { From 0202560ebd13a493d28c787e8b2873754a951f95 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 10:56:25 +0200 Subject: [PATCH 13/26] Minor - format code --- main/attendance/attendance_controller.php | 21 ++++++++++++++------- main/attendance/attendance_list.php | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/main/attendance/attendance_controller.php b/main/attendance/attendance_controller.php index 59c9e7d01d..ccb0d30397 100755 --- a/main/attendance/attendance_controller.php +++ b/main/attendance/attendance_controller.php @@ -112,7 +112,9 @@ class AttendanceController $attendance->category_id = $_POST['category_id']; $link_to_gradebook = false; - if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) { + if (isset($_POST['attendance_qualify_gradebook']) && + $_POST['attendance_qualify_gradebook'] == 1 + ) { $link_to_gradebook = true; } $last_id = $attendance->attendance_edit($attendance_id,$link_to_gradebook); @@ -135,10 +137,12 @@ class AttendanceController } } else { // default values - $attendance_data = $attendance->get_attendance_by_id($attendance_id); - $data['attendance_id'] = $attendance_data['id']; - $data['title'] = $attendance_data['name']; - $data['description'] = $attendance_data['description']; + $attendance_data = $attendance->get_attendance_by_id( + $attendance_id + ); + $data['attendance_id'] = $attendance_data['id']; + $data['title'] = $attendance_data['name']; + $data['description'] = $attendance_data['description']; $data['attendance_qualify_title'] = $attendance_data['attendance_qualify_title']; $data['attendance_weight'] = $attendance_data['attendance_weight']; @@ -159,12 +163,15 @@ class AttendanceController $allowDeleteAttendance = api_get_setting('allow_delete_attendance'); if ($allowDeleteAttendance !== 'true') { $this->attendance_list(); + return false; } + $attendance = new Attendance(); if (!empty($attendance_id)) { $affected_rows = $attendance->attendance_delete($attendance_id); } + if ($affected_rows) { $message['message_attendance_delete'] = true; } @@ -256,8 +263,8 @@ class AttendanceController * It's used for controlling attendance sheet (list, add), * render to attendance_sheet view * @param string $action - * @param int $attendance_id - * @param int $student_id + * @param int $attendance_id + * @param int $student_id * @param bool $edit */ public function attendance_sheet($action, $attendance_id, $student_id = 0, $edit = true) diff --git a/main/attendance/attendance_list.php b/main/attendance/attendance_list.php index b2349e1bc2..3e777e0971 100755 --- a/main/attendance/attendance_list.php +++ b/main/attendance/attendance_list.php @@ -17,7 +17,7 @@ if (api_is_allowed_to_edit(null, true)) { } echo '
'; echo ''. - Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).''; + Display::return_icon('new_attendance_list.png', get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).''; echo '
'; } $attendance = new Attendance(); From e8847d6de095d226a9151e5cc13838c28311ee28 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 11 Sep 2015 11:14:44 +0200 Subject: [PATCH 14/26] Fix PHP warnings see #7826 --- .../formvalidator/Element/DateRangePicker.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/main/inc/lib/formvalidator/Element/DateRangePicker.php b/main/inc/lib/formvalidator/Element/DateRangePicker.php index dff454e07c..e1754f6eff 100755 --- a/main/inc/lib/formvalidator/Element/DateRangePicker.php +++ b/main/inc/lib/formvalidator/Element/DateRangePicker.php @@ -62,30 +62,34 @@ class DateRangePicker extends HTML_QuickForm_text } $minDate = null; - if (!empty($this->getAttribute('minDate'))) { + $minDateValue = $this->getAttribute('minDate'); + if (!empty($minDateValue)) { $minDate = " - minDate: '{$this->getAttribute('minDate')}', + minDate: '{$minDateValue}', "; } $maxDate = null; - if (!empty($this->getAttribute('maxDate'))) { + $maxDateValue = $this->getAttribute('maxDate'); + if (!empty($maxDateValue)) { $maxDate = " - maxDate: '{$this->getAttribute('maxDate')}', + maxDate: '{$maxDateValue}', "; } $format = 'YYYY-MM-DD HH:mm'; - if (!empty($this->getAttribute('format'))) { - $format = $this->getAttribute('format'); + $formatValue = $this->getAttribute('format'); + if (!empty($formatValue)) { + $format = $formatValue; } $timePicker = 'true'; - if (!empty($this->getAttribute('timePicker'))) { - $timePicker = $this->getAttribute('timePicker'); + $timePickerValue = $this->getAttribute('timePicker'); + if (!empty($timePickerValue)) { + $timePicker = $timePickerValue; } - //timeFormat: 'hh:mm' + // timeFormat: 'hh:mm' $js .= "
{{ 'CreatedBy'|get_lang }}{{ session_admin.complete_name }}
{{ 'GeneralCoach' | get_lang}} : {{ general_coach.complete_name }}