diff --git a/main/attendance/attendance_add.php b/main/attendance/attendance_add.php index a1f1cad10c..8b06461257 100755 --- a/main/attendance/attendance_add.php +++ b/main/attendance/attendance_add.php @@ -37,24 +37,34 @@ $form->addHtmlEditor( array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '150') ); -// Adavanced Parameters +// Advanced Parameters if ((api_get_session_id() != 0 && Gradebook::is_active()) || api_get_session_id() == 0) { $form->addButtonAdvancedSettings('id_qualify'); $form->addElement('html',''); } $form->addButtonCreate(get_lang('Save')); diff --git a/main/attendance/attendance_calendar.php b/main/attendance/attendance_calendar.php index a9bf59cd34..c087164211 100755 --- a/main/attendance/attendance_calendar.php +++ b/main/attendance/attendance_calendar.php @@ -46,7 +46,6 @@ if (isset($error_checkdate) && $error_checkdate) { Display::display_error_message($message, false); } - if (isset($action) && $action == 'calendar_add') { $groupList = GroupManager::get_group_list(null, null, 1); $groupIdList = array('--'); @@ -62,13 +61,11 @@ if (isset($action) && $action == 'calendar_add') { '' ); $form->addElement('header', get_lang('AddADateTime')); - //$form->addElement('date_time_picker', 'date_time'); - $form->addDateTimePicker( - 'date_time', - array(get_lang('StartDate')), - array('id' => 'date_time') - ); + 'date_time', + array(get_lang('StartDate')), + array('id' => 'date_time') + ); $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time())); @@ -97,7 +94,12 @@ if (isset($action) && $action == 'calendar_add') { ); $form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type); - $form->addElement('date_picker', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add')); + $form->addElement( + 'date_picker', + 'end_date_time', + get_lang('RepeatEnd'), + array('form_name'=>'attendance_calendar_add') + ); $defaults['end_date_time'] = date('Y-m-d'); $form->addElement('html', ''); @@ -123,7 +125,7 @@ if (isset($action) && $action == 'calendar_add') { foreach ($attendance_calendar as $calendar) { echo '
  • '; - if ((isset($action) && $action == 'calendar_edit') && + if ((isset($action) && $action === 'calendar_edit') && (isset($calendar_id) && $calendar_id == $calendar['id']) ) { // calendar edit form @@ -134,7 +136,12 @@ if (isset($action) && $action == 'calendar_add') { 'index.php?action=calendar_edit&attendance_id=' . $attendance_id . '&calendar_id=' . $calendar_id . '&' . api_get_cidreq(), '' ); - $form->addDateTimePicker('date_time', array(get_lang('Date')), array('form_name'=>'attendance_calendar_edit'), 5); + $form->addDateTimePicker( + 'date_time', + array(get_lang('Date')), + array('form_name'=>'attendance_calendar_edit'), + 5 + ); $defaults['date_time'] = $calendar['date_time']; $form->addButtonSave(get_lang('Save')); $form->addButtonCancel(get_lang('Cancel'), 'cancel'); diff --git a/main/attendance/attendance_controller.php b/main/attendance/attendance_controller.php index 80ba155ee8..0f6a5ccb32 100755 --- a/main/attendance/attendance_controller.php +++ b/main/attendance/attendance_controller.php @@ -50,8 +50,7 @@ class AttendanceController $attendance = new Attendance(); $data = array(); - if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { - + if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { if (!empty($_POST['title'])) { $check = Security::check_token(); if ($check) { @@ -95,8 +94,7 @@ class AttendanceController $data = array(); $attendance_id = intval($attendance_id); - if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { - + if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { if (!empty($_POST['title'])) { $check = Security::check_token(); if ($check) { @@ -112,7 +110,7 @@ class AttendanceController ) { $link_to_gradebook = true; } - $attendance->attendance_edit($attendance_id,$link_to_gradebook); + $attendance->attendance_edit($attendance_id, $link_to_gradebook); Security::clear_token(); header('location:index.php?action=attendance_list&'.api_get_cidreq()); exit; @@ -203,7 +201,6 @@ class AttendanceController $this->attendance_list(); } - /** * Restores an attendance entry and fallback to attendances rendering * @param int $attendance_id @@ -223,8 +220,8 @@ class AttendanceController /** * Lock or unlock an attendance * render to attendance_list view - * @param string action (lock_attendance or unlock_attendance) - * @param int attendance id + * @param string $action (lock_attendance or unlock_attendance) + * @param int $attendance_id * render to attendance_list view */ public function lock_attendance($action, $attendance_id) @@ -301,7 +298,7 @@ class AttendanceController $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id); - if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { + if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { if (isset($_POST['hidden_input'])) { foreach ($_POST['hidden_input'] as $cal_id) { $users_present = array(); @@ -408,7 +405,7 @@ class AttendanceController $action = 'calendar_list'; } } - } else if ($action == 'calendar_edit') { + } else if ($action === 'calendar_edit') { $data['calendar_id'] = $calendar_id; if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if (!isset($_POST['cancel'])) { @@ -507,9 +504,7 @@ class AttendanceController } // Get data table - $data_table = array(); - $head_table = array('#', get_lang('Name')); foreach ($data_array['attendant_calendar'] as $class_day) { $head_table[] = @@ -529,12 +524,13 @@ class AttendanceController $result['full_name'] = api_get_person_name($user['firstname'], $user['lastname']); foreach ($data_array['attendant_calendar'] as $class_day) { if ($class_day['done_attendance'] == 1) { - if ($data_users_presence[$user['user_id']][$class_day['id']]['presence'] == 1) + if ($data_users_presence[$user['user_id']][$class_day['id']]['presence'] == 1) { $result[$class_day['id']] = get_lang('UserAttendedSymbol'); - else + } else { $result[$class_day['id']] = ''.get_lang('UserNotAttendedSymbol').''; + } } else { - $result[$class_day['id']] = " "; + $result[$class_day['id']] = ' '; } $cols++; } diff --git a/main/attendance/attendance_edit.php b/main/attendance/attendance_edit.php index 4bcbd90e13..0c7e6f6f67 100755 --- a/main/attendance/attendance_edit.php +++ b/main/attendance/attendance_edit.php @@ -31,7 +31,7 @@ $form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'attendance_id', $attendance_id); $form->addText('title', get_lang('Title'), true); -$form->applyFilter('title','html_filter'); +$form->applyFilter('title', 'html_filter'); $form->addHtmlEditor( 'description', get_lang('Description'), @@ -50,21 +50,38 @@ if (Gradebook::is_active()) { if (!empty($attendance_qualify_title) || !empty($attendance_weight)) { $form->addButtonAdvancedSettings('id_qualify'); $form->addElement('html','
    '); - $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'),array('checked'=>'true','onclick'=>'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}')); + $form->addElement( + 'checkbox', + 'attendance_qualify_gradebook', + '', + get_lang('QualifyAttendanceGradebook'), + array('checked'=>'true','onclick'=>'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}') + ); $form->addElement('html','
    '); } else { $form->addButtonAdvancedSettings('id_qualify'); $form->addElement('html',''); + $form->addElement('html', '
    '); + $form->addElement('html', '
    '); } $form->addButtonUpdate(get_lang('Save')); diff --git a/main/attendance/attendance_list.php b/main/attendance/attendance_list.php index e334022f1d..71ec5c7f4f 100755 --- a/main/attendance/attendance_list.php +++ b/main/attendance/attendance_list.php @@ -13,7 +13,7 @@ api_protect_course_script(true); 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(); diff --git a/main/attendance/attendance_sheet.php b/main/attendance/attendance_sheet.php index b4fc676e69..7e9bffa9d8 100755 --- a/main/attendance/attendance_sheet.php +++ b/main/attendance/attendance_sheet.php @@ -74,8 +74,6 @@ if (api_is_allowed_to_edit(null, true) || ['id' => 'filter_id', 'onchange' => 'submit();'] ); - //$form->addElement('select', 'filter', get_lang('Filter'), $values, array('id' => 'filter_id')); - $groupList = GroupManager::get_group_list(null, null, 1); $groupIdList = array('--'); foreach ($groupList as $group) { @@ -442,7 +440,7 @@ if (api_is_allowed_to_edit(null, true) || $i = 0; foreach ($users_presence[$user_id] as $presence) { $class = ''; - if ($i%2==0) { + if ($i % 2 == 0) { $class = 'row_even'; } else { $class = 'row_odd'; diff --git a/main/attendance/calendar_logins.php b/main/attendance/calendar_logins.php index 9acbdf68ec..df017de8bd 100644 --- a/main/attendance/calendar_logins.php +++ b/main/attendance/calendar_logins.php @@ -6,6 +6,5 @@ echo '
    '; echo ''. Display::return_icon('back.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).''; echo '
    '; - echo $form; echo $table; diff --git a/main/attendance/index.php b/main/attendance/index.php index cd5ac40967..1d9ddeecdd 100755 --- a/main/attendance/index.php +++ b/main/attendance/index.php @@ -9,9 +9,7 @@ * @package chamilo.attendance */ -// including files require_once '../inc/global.inc.php'; - require_once 'attendance_controller.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php'; diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index 64238a6456..7d34a95ff5 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -165,8 +165,14 @@ class CoursesController * @param $limit * @param boolean $justVisible Whether to search only in courses visibles in the catalogue */ - public function search_courses($search_term, $message = '', $error = '', $content = null, $limit = array(), $justVisible = false) - { + public function search_courses( + $search_term, + $message = '', + $error = '', + $content = null, + $limit = array(), + $justVisible = false + ) { $data = array(); $limit = !empty($limit) ? $limit : CourseCategory::getLimitArray(); @@ -264,8 +270,8 @@ class CoursesController /** * Change course category * render to listing view - * @param string Course code - * @param int Category id + * @param string $course_code + * @param int $category_id */ public function change_course_category($course_code, $category_id) { @@ -283,9 +289,9 @@ class CoursesController /** * Move up/down courses inside a category * render to listing view - * @param string move to up or down - * @param string Course code - * @param int Category id + * @param string $move move to up or down + * @param string $course_code + * @param int $category_id Category id */ public function move_course($move, $course_code, $category_id) { @@ -300,8 +306,8 @@ class CoursesController /** * Move up/down categories * render to listing view - * @param string move to up or down - * @param int Category id + * @param string $move move to up or down + * @param int $category_id Category id */ public function move_category($move, $category_id) { @@ -316,8 +322,8 @@ class CoursesController /** * Edit course category * render to listing view - * @param string Category title - * @param int Category id + * @param string $title Category title + * @param int $category Category id */ public function edit_course_category($title, $category) { diff --git a/main/inc/lib/CourseChatUtils.php b/main/inc/lib/CourseChatUtils.php index d2f428c5ae..63b5f27189 100644 --- a/main/inc/lib/CourseChatUtils.php +++ b/main/inc/lib/CourseChatUtils.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ use Michelf\MarkdownExtra; +use Doctrine\Common\Collections\Criteria; /** * Class CourseChat @@ -23,10 +24,10 @@ class CourseChatUtils */ public function __construct($courseId, $userId, $sessionId = 0, $groupId = 0) { - $this->courseId = intval($courseId); - $this->userId = intval($userId); - $this->sessionId = intval($sessionId); - $this->groupId = intval($groupId); + $this->courseId = (int) $courseId; + $this->userId = (int) $userId; + $this->sessionId = (int) $sessionId; + $this->groupId = (int) $groupId; } /** @@ -42,10 +43,7 @@ class CourseChatUtils $course = $em->find('ChamiloCoreBundle:Course', $this->courseId); if ($this->sessionId) { - $criteria = \Doctrine\Common\Collections\Criteria::create() - ->where( - \Doctrine\Common\Collections\Criteria::expr()->eq("course", $course) - ); + $criteria = Criteria::create()->where(Criteria::expr()->eq("course", $course)); return $em ->find('ChamiloCoreBundle:Session', $this->sessionId) @@ -1506,7 +1504,6 @@ class CourseChatUtils public function getFileName($absolute = false, $friendId = 0) { $date = date('Y-m-d'); - $base = 'messages-' . $date . '.log.html'; if ($this->groupId && !$friendId) { diff --git a/main/inc/lib/GamificationUtils.php b/main/inc/lib/GamificationUtils.php index 6704026e59..c5dc8ca679 100644 --- a/main/inc/lib/GamificationUtils.php +++ b/main/inc/lib/GamificationUtils.php @@ -9,7 +9,6 @@ */ class GamificationUtils { - /** * Get the calculated points on session with gamification mode * @param int $userId The user ID @@ -26,6 +25,7 @@ class GamificationUtils ); if (empty($sessions)) { + return 0; } @@ -222,5 +222,4 @@ class GamificationUtils return round($progress / count($sessions), 2); } - } diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php index 484d1531e9..14965a07c9 100755 --- a/main/inc/lib/auth.lib.php +++ b/main/inc/lib/auth.lib.php @@ -406,7 +406,7 @@ class Auth * @param boolean $justVisible search only on visible courses in the catalogue * @return array An array containing a list of all the courses matching the the search term. */ - public function search_courses($search_term, $limit, $justVisible=false) + public function search_courses($search_term, $limit, $justVisible = false) { $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); $extraFieldTable = Database :: get_main_table(TABLE_EXTRA_FIELD); @@ -434,7 +434,7 @@ class Auth $without_special_courses = ' AND course.code NOT IN (' . implode(',', $special_course_list) . ')'; } - $visibilityCondition = ($justVisible?CourseManager::getCourseVisibilitySQLCondition('course'):''); + $visibilityCondition = $justVisible ? CourseManager::getCourseVisibilitySQLCondition('course') : ''; $search_term_safe = Database::escape_string($search_term); $sql_find = "SELECT * FROM $courseTable @@ -503,7 +503,7 @@ class Auth /** * unsubscribe the user from a given course - * @param string Course code + * @param string $course_code * @return bool True if it success */ public function remove_user_from_course($course_code) @@ -678,8 +678,7 @@ class Auth $em = Database::getManager(); $qb = $em->createQueryBuilder(); - $_sessions = $qb->select('s') - ->from('ChamiloCoreBundle:Session', 's'); + $_sessions = $qb->select('s')->from('ChamiloCoreBundle:Session', 's'); if (!empty($limit)) { $_sessions->setFirstResult($limit['start']) @@ -788,12 +787,10 @@ SQL; ->getResult(); $sessionsToBrowse = []; - foreach ($sessions as $session) { if ($session->getNbrCourses() === 0) { continue; } - $sessionsToBrowse[] = $session; } diff --git a/main/inc/lib/blog.lib.php b/main/inc/lib/blog.lib.php index d72e000a27..9dca3b1895 100755 --- a/main/inc/lib/blog.lib.php +++ b/main/inc/lib/blog.lib.php @@ -13,116 +13,114 @@ */ class Blog { - /** - * Get the title of a blog - * @author Toon Keppens - * - * @param int $blog_id - * - * @return String Blog Title - */ - public static function get_blog_title ($blog_id) - { - $course_id = api_get_course_int_id(); - - if (is_numeric($blog_id)) { - $tbl_blogs = Database::get_course_table(TABLE_BLOGS); - - $sql = "SELECT blog_name - FROM " . $tbl_blogs . " - WHERE c_id = $course_id AND blog_id = " . intval($blog_id); - - $result = Database::query($sql); - $blog = Database::fetch_array($result); - - return stripslashes($blog['blog_name']); - } - } + /** + * Get the title of a blog + * @author Toon Keppens + * + * @param int $blog_id + * + * @return String Blog Title + */ + public static function get_blog_title($blog_id) + { + $course_id = api_get_course_int_id(); + if (is_numeric($blog_id)) { + $tbl_blogs = Database::get_course_table(TABLE_BLOGS); - /** - * Get the description of a blog - * @author Toon Keppens - * - * @param Integer $blog_id - * - * @return String Blog description - */ - public static function get_blog_subtitle($blog_id) - { - $tbl_blogs = Database::get_course_table(TABLE_BLOGS); - $course_id = api_get_course_int_id(); - $sql = "SELECT blog_subtitle FROM $tbl_blogs - WHERE c_id = $course_id AND blog_id ='".intval($blog_id)."'"; - $result = Database::query($sql); - $blog = Database::fetch_array($result); - - return stripslashes($blog['blog_subtitle']); - } + $sql = "SELECT blog_name + FROM " . $tbl_blogs . " + WHERE c_id = $course_id AND blog_id = " . intval($blog_id); - /** - * Get the users of a blog - * @author Toon Keppens - * - * @param Integer $blog_id - * - * @return Array Returns an array with [userid]=>[username] - */ - public static function get_blog_users($blog_id) - { - // Database table definitions - $tbl_users = Database::get_main_table(TABLE_MAIN_USER); - $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); - - $course_id = api_get_course_int_id(); - - // Get blog members - $sql = "SELECT user.user_id, user.firstname, user.lastname - FROM " . $tbl_blogs_rel_user . " blogs_rel_user - INNER JOIN " . $tbl_users . " user - ON blogs_rel_user.user_id = user.user_id - WHERE - blogs_rel_user.c_id = $course_id AND - blogs_rel_user.blog_id = '" . (int)$blog_id."'"; - $result = Database::query($sql); - $blog_members = array (); - while($user = Database::fetch_array($result)) { - $blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']); - } + $result = Database::query($sql); + $blog = Database::fetch_array($result); - return $blog_members; - } + return stripslashes($blog['blog_name']); + } + } + + /** + * Get the description of a blog + * @author Toon Keppens + * + * @param Integer $blog_id + * + * @return String Blog description + */ + public static function get_blog_subtitle($blog_id) + { + $tbl_blogs = Database::get_course_table(TABLE_BLOGS); + $course_id = api_get_course_int_id(); + $sql = "SELECT blog_subtitle FROM $tbl_blogs + WHERE c_id = $course_id AND blog_id ='".intval($blog_id)."'"; + $result = Database::query($sql); + $blog = Database::fetch_array($result); + + return stripslashes($blog['blog_subtitle']); + } + + /** + * Get the users of a blog + * @author Toon Keppens + * + * @param Integer $blog_id + * + * @return Array Returns an array with [userid]=>[username] + */ + public static function get_blog_users($blog_id) + { + // Database table definitions + $tbl_users = Database::get_main_table(TABLE_MAIN_USER); + $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); - /** - * Creates a new blog in the given course - * @author Toon Keppens - * @param string $title - */ - public static function create_blog($title, $subtitle) - { - $_user = api_get_user_info(); $course_id = api_get_course_int_id(); - $current_date=date('Y-m-d H:i:s',time()); - $session_id = api_get_session_id(); - // Tabel definitions + // Get blog members + $sql = "SELECT user.user_id, user.firstname, user.lastname + FROM " . $tbl_blogs_rel_user . " blogs_rel_user + INNER JOIN " . $tbl_users . " user + ON blogs_rel_user.user_id = user.user_id + WHERE + blogs_rel_user.c_id = $course_id AND + blogs_rel_user.blog_id = '" . (int)$blog_id."'"; + $result = Database::query($sql); + $blog_members = array (); + while ($user = Database::fetch_array($result)) { + $blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']); + } + + return $blog_members; + } + + /** + * Creates a new blog in the given course + * @author Toon Keppens + * @param string $title + */ + public static function create_blog($title, $subtitle) + { + $_user = api_get_user_info(); + $course_id = api_get_course_int_id(); + + $current_date = date('Y-m-d H:i:s', time()); + $session_id = api_get_session_id(); $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); - //verified if exist blog - $sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.' - WHERE - c_id = '.$course_id.' AND - blog_name="'.Database::escape_string($title).'" AND - blog_subtitle="'.Database::escape_string($subtitle).'"'; + //verified if exist blog + $sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.' + WHERE + c_id = '.$course_id.' AND + blog_name="'.Database::escape_string($title).'" AND + blog_subtitle="'.Database::escape_string($subtitle).'"'; $res = Database::query($sql); $info_count = Database::result($res, 0, 0); if ($info_count == 0) { - // Create the blog + // Create the blog $params = [ - 'blog_id' => 0, + 'blog_id' => 0, 'c_id' => $course_id, 'blog_name' => $title, 'blog_subtitle' => $subtitle, @@ -130,14 +128,14 @@ class Blog 'visibility' => 1 , 'session_id' => $session_id, ]; - $this_blog_id = Database::insert($tbl_blogs, $params); + $this_blog_id = Database::insert($tbl_blogs, $params); - if ($this_blog_id > 0) { + if ($this_blog_id > 0) { $sql = "UPDATE $tbl_blogs SET blog_id = iid WHERE iid = $this_blog_id"; Database::query($sql); - // insert into item_property + // insert into item_property api_item_property_update( api_get_course_info(), TOOL_BLOGS, @@ -145,12 +143,12 @@ class Blog 'BlogAdded', api_get_user_id() ); - } + } - // Make first post. :) + // Make first post. :) $params = [ - 'post_id' => 0, + 'post_id' => 0, 'c_id' => $course_id, 'title' => get_lang("Welcome"), 'full_text' => get_lang('FirstPostText'), @@ -164,10 +162,10 @@ class Blog Database::query($sql); } - // Put it on course homepage - $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target) - VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')"; - Database::query($sql); + // Put it on course homepage + $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target) + VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')"; + Database::query($sql); $toolId = Database::insert_id(); if ($toolId) { @@ -175,35 +173,35 @@ class Blog Database::query($sql); } - // Subscribe the teacher to this blog - Blog::set_user_subscribed($this_blog_id, $_user['user_id']); - } - } + // Subscribe the teacher to this blog + Blog::set_user_subscribed($this_blog_id, $_user['user_id']); + } + } - /** - * Update title and subtitle of a blog in the given course - * @author Toon Keppens - * @param string $title - */ - public static function edit_blog($blog_id, $title, $subtitle) - { - // Table definitions - $tbl_blogs = Database::get_course_table(TABLE_BLOGS); - $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); + /** + * Update title and subtitle of a blog in the given course + * @author Toon Keppens + * @param string $title + */ + public static function edit_blog($blog_id, $title, $subtitle) + { + // Table definitions + $tbl_blogs = Database::get_course_table(TABLE_BLOGS); + $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $course_id = api_get_course_int_id(); - // Update the blog - $sql = "UPDATE $tbl_blogs SET - blog_name = '".Database::escape_string($title)."', - blog_subtitle = '".Database::escape_string($subtitle)."' - WHERE - c_id = $course_id AND - blog_id ='".Database::escape_string((int)$blog_id)."' + // Update the blog + $sql = "UPDATE $tbl_blogs SET + blog_name = '".Database::escape_string($title)."', + blog_subtitle = '".Database::escape_string($subtitle)."' + WHERE + c_id = $course_id AND + blog_id ='".Database::escape_string((int)$blog_id)."' LIMIT 1"; - Database::query($sql); + Database::query($sql); - //update item_property (update) + //update item_property (update) api_item_property_update( api_get_course_info(), TOOL_BLOGS, @@ -212,21 +210,21 @@ class Blog api_get_user_id() ); - // Update course homepage link - $sql = "UPDATE $tbl_tool SET - name = '".Database::escape_string($title)."' - WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int)$blog_id."' LIMIT 1"; - Database::query($sql); - } + // Update course homepage link + $sql = "UPDATE $tbl_tool SET + name = '".Database::escape_string($title)."' + WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int)$blog_id."' LIMIT 1"; + Database::query($sql); + } - /** - * Deletes a blog and it's posts from the course database - * @author Toon Keppens - * @param Integer $blog_id - */ - public static function delete_blog($blog_id) - { - // Init + /** + * Deletes a blog and it's posts from the course database + * @author Toon Keppens + * @param Integer $blog_id + */ + public static function delete_blog($blog_id) + { + // Init $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); $tbl_blogs_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS); @@ -237,34 +235,34 @@ class Blog $course_id = api_get_course_int_id(); $blog_id = intval($blog_id); - // Delete posts from DB and the attachments - delete_all_blog_attachment($blog_id); + // Delete posts from DB and the attachments + delete_all_blog_attachment($blog_id); - //Delete comments - $sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; - Database::query($sql); + //Delete comments + $sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; + Database::query($sql); - // Delete posts - $sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; - Database::query($sql); + // Delete posts + $sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; + Database::query($sql); - // Delete tasks - $sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; - Database::query($sql); + // Delete tasks + $sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; + Database::query($sql); - // Delete ratings - $sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; - Database::query($sql); + // Delete ratings + $sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; + Database::query($sql); - // Delete blog - $sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; - Database::query($sql); + // Delete blog + $sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'"; + Database::query($sql); - // Delete from course homepage - $sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'"; - Database::query($sql); + // Delete from course homepage + $sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'"; + Database::query($sql); - //update item_property (delete) + //update item_property (delete) api_item_property_update( api_get_course_info(), TOOL_BLOGS, @@ -272,152 +270,152 @@ class Blog 'delete', api_get_user_id() ); - } + } - /** - * Creates a new post in a given blog - * @author Toon Keppens - * @param String $title - * @param String $full_text - * @param Integer $blog_id - */ - public static function create_post($title, $full_text, $file_comment, $blog_id) - { - $_user = api_get_user_info(); - $_course = api_get_course_info(); - $course_id = $_course['real_id']; - - $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); - $upload_ok=true; - $has_attachment=false; - $current_date = api_get_utc_datetime(); - - if (!empty($_FILES['user_upload']['name'])) { - $upload_ok = process_uploaded_file($_FILES['user_upload']); - $has_attachment=true; - } + /** + * Creates a new post in a given blog + * @author Toon Keppens + * @param String $title + * @param String $full_text + * @param Integer $blog_id + */ + public static function create_post($title, $full_text, $file_comment, $blog_id) + { + $_user = api_get_user_info(); + $_course = api_get_course_info(); + $course_id = $_course['real_id']; + + $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); + $upload_ok=true; + $has_attachment=false; + $current_date = api_get_utc_datetime(); + + if (!empty($_FILES['user_upload']['name'])) { + $upload_ok = process_uploaded_file($_FILES['user_upload']); + $has_attachment=true; + } - if ($upload_ok) { - // Table Definitions - $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); + if ($upload_ok) { + // Table Definitions + $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); - // Create the post - $sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id ) - VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');"; + // Create the post + $sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id ) + VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');"; - Database::query($sql); - $last_post_id = Database::insert_id(); + Database::query($sql); + $last_post_id = Database::insert_id(); if ($last_post_id) { $sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $last_post_id"; Database::query($sql); } - if ($has_attachment) { - $courseDir = $_course['path'].'/upload/blog'; - $sys_course_path = api_get_path(SYS_COURSE_PATH); - $updir = $sys_course_path.$courseDir; - - // Try to add an extension to the file if it hasn't one - $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']); - - // user's file name - $file_name = $_FILES['user_upload']['name']; - - if (!filter_extension($new_file_name)) { - Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); - } else { - $new_file_name = uniqid(''); - $new_path = $updir.'/'.$new_file_name; - $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); - $comment = Database::escape_string($file_comment); - - // Storing the attachments if any - if ($result) { - $sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '. - "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."', '".$blog_id."', '0' )"; - Database::query($sql); + if ($has_attachment) { + $courseDir = $_course['path'].'/upload/blog'; + $sys_course_path = api_get_path(SYS_COURSE_PATH); + $updir = $sys_course_path.$courseDir; + + // Try to add an extension to the file if it hasn't one + $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']); + + // user's file name + $file_name = $_FILES['user_upload']['name']; + + if (!filter_extension($new_file_name)) { + Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); + } else { + $new_file_name = uniqid(''); + $new_path = $updir.'/'.$new_file_name; + $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); + $comment = Database::escape_string($file_comment); + + // Storing the attachments if any + if ($result) { + $sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '. + "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."', '".$blog_id."', '0' )"; + Database::query($sql); $id = Database::insert_id(); if ($id) { $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id"; Database::query($sql); } - } - } - } - } else { - Display::display_error_message(get_lang('UplNoFileUploaded')); - } - } + } + } + } + } else { + Display::display_error_message(get_lang('UplNoFileUploaded')); + } + } - /** - * Edits a post in a given blog - * @author Toon Keppens - * @param Integer $blog_id - * @param String $title - * @param String $full_text - * @param Integer $blog_id - */ - public static function edit_post($post_id, $title, $full_text, $blog_id) - { - $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); + /** + * Edits a post in a given blog + * @author Toon Keppens + * @param Integer $blog_id + * @param String $title + * @param String $full_text + * @param Integer $blog_id + */ + public static function edit_post($post_id, $title, $full_text, $blog_id) + { + $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); $course_id = api_get_course_int_id(); - // Create the post - $sql = "UPDATE $tbl_blogs_posts SET - title = '" . Database::escape_string($title)."', - full_text = '" . Database::escape_string($full_text)."' - WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."' - LIMIT 1 "; - Database::query($sql); - } + // Create the post + $sql = "UPDATE $tbl_blogs_posts SET + title = '" . Database::escape_string($title)."', + full_text = '" . Database::escape_string($full_text)."' + WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."' + LIMIT 1 "; + Database::query($sql); + } - /** - * Deletes an article and it's comments - * @author Toon Keppens - * @param int $blog_id - * @param int $post_id - */ - public static function delete_post($blog_id, $post_id) - { - $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); - $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); - $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); + /** + * Deletes an article and it's comments + * @author Toon Keppens + * @param int $blog_id + * @param int $post_id + */ + public static function delete_post($blog_id, $post_id) + { + $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); + $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); + $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); $course_id = api_get_course_int_id(); - // Delete ratings on this comment - $sql = "DELETE FROM $tbl_blogs_rating - WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'"; - Database::query($sql); + // Delete ratings on this comment + $sql = "DELETE FROM $tbl_blogs_rating + WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'"; + Database::query($sql); - // Delete the post - $sql = "DELETE FROM $tbl_blogs_posts - WHERE c_id = $course_id AND post_id = '".(int)$post_id."'"; - Database::query($sql); + // Delete the post + $sql = "DELETE FROM $tbl_blogs_posts + WHERE c_id = $course_id AND post_id = '".(int)$post_id."'"; + Database::query($sql); - // Delete the comments - $sql = "DELETE FROM $tbl_blogs_comments - WHERE c_id = $course_id AND post_id = '".(int)$post_id."' AND blog_id = '".(int)$blog_id."'"; - Database::query($sql); + // Delete the comments + $sql = "DELETE FROM $tbl_blogs_comments + WHERE c_id = $course_id AND post_id = '".(int)$post_id."' AND blog_id = '".(int)$blog_id."'"; + Database::query($sql); - // Delete posts and attachments - delete_all_blog_attachment($blog_id,$post_id); - } + // Delete posts and attachments + delete_all_blog_attachment($blog_id,$post_id); + } - /** - * Creates a comment on a post in a given blog - * @author Toon Keppens - * @param String $title - * @param String $full_text - * @param Integer $blog_id - * @param Integer $post_id - * @param Integer $parent_id - */ - public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL') - { - $_user = api_get_user_info(); - $_course = api_get_course_info(); + /** + * Creates a comment on a post in a given blog + * @author Toon Keppens + * @param String $title + * @param String $full_text + * @param Integer $blog_id + * @param Integer $post_id + * @param Integer $parent_id + */ + public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL') + { + $_user = api_get_user_info(); + $_course = api_get_course_info(); $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); $upload_ok = true; @@ -425,55 +423,55 @@ class Blog $current_date = api_get_utc_datetime(); $course_id = api_get_course_int_id(); - if (!empty($_FILES['user_upload']['name'])) { - $upload_ok = process_uploaded_file($_FILES['user_upload']); - $has_attachment=true; - } + if (!empty($_FILES['user_upload']['name'])) { + $upload_ok = process_uploaded_file($_FILES['user_upload']); + $has_attachment=true; + } - if ($upload_ok) { - // Table Definition - $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); + if ($upload_ok) { + // Table Definition + $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); - // Create the comment - $sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id ) - VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')"; - Database::query($sql); + // Create the comment + $sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id ) + VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')"; + Database::query($sql); - // Empty post values, or they are shown on the page again - $last_id = Database::insert_id(); + // Empty post values, or they are shown on the page again + $last_id = Database::insert_id(); if ($last_id) { $sql = "UPDATE $tbl_blogs_comments SET comment_id = iid WHERE iid = $last_id"; Database::query($sql); } - if ($has_attachment) { - $courseDir = $_course['path'].'/upload/blog'; - $sys_course_path = api_get_path(SYS_COURSE_PATH); - $updir = $sys_course_path.$courseDir; - - // Try to add an extension to the file if it hasn't one - $new_file_name = add_ext_on_mime( - stripslashes($_FILES['user_upload']['name']), - $_FILES['user_upload']['type'] - ); - - // user's file name - $file_name =$_FILES['user_upload']['name']; - - if (!filter_extension($new_file_name)) { - Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); - } else { - $new_file_name = uniqid(''); - $new_path=$updir.'/'.$new_file_name; - $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); - $comment = Database::escape_string($file_comment); - - // Storing the attachments if any - if ($result) { - $sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '. - "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."', '".$blog_id."', '".$last_id."' )"; - Database::query($sql); + if ($has_attachment) { + $courseDir = $_course['path'].'/upload/blog'; + $sys_course_path = api_get_path(SYS_COURSE_PATH); + $updir = $sys_course_path.$courseDir; + + // Try to add an extension to the file if it hasn't one + $new_file_name = add_ext_on_mime( + stripslashes($_FILES['user_upload']['name']), + $_FILES['user_upload']['type'] + ); + + // user's file name + $file_name =$_FILES['user_upload']['name']; + + if (!filter_extension($new_file_name)) { + Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); + } else { + $new_file_name = uniqid(''); + $new_path=$updir.'/'.$new_file_name; + $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); + $comment = Database::escape_string($file_comment); + + // Storing the attachments if any + if ($result) { + $sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '. + "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."', '".$blog_id."', '".$last_id."' )"; + Database::query($sql); $id = Database::insert_id(); @@ -481,91 +479,91 @@ class Blog $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id"; Database::query($sql); } - } - } - } - } - } + } + } + } + } + } - /** - * Deletes a comment from a blogpost - * @author Toon Keppens - * @param int $blog_id - * @param int $comment_id - */ - public static function delete_comment($blog_id, $post_id, $comment_id) - { - $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); - $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); - $blog_id = intval($blog_id); - $post_id = intval($post_id); - $comment_id = intval($comment_id); + /** + * Deletes a comment from a blogpost + * @author Toon Keppens + * @param int $blog_id + * @param int $comment_id + */ + public static function delete_comment($blog_id, $post_id, $comment_id) + { + $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); + $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); + $blog_id = intval($blog_id); + $post_id = intval($post_id); + $comment_id = intval($comment_id); $course_id = api_get_course_int_id(); - delete_all_blog_attachment($blog_id, $post_id, $comment_id); - - // Delete ratings on this comment - $sql = "DELETE FROM $tbl_blogs_rating - WHERE - c_id = $course_id AND - blog_id = '".$blog_id."' AND - item_id = '".$comment_id."' AND - rating_type = 'comment'"; - Database::query($sql); - - // select comments that have the selected comment as their parent - $sql = "SELECT comment_id FROM $tbl_blogs_comments - WHERE c_id = $course_id AND parent_comment_id = '".$comment_id."'"; - $result = Database::query($sql); - - // Delete them recursively - while ($comment = Database::fetch_array($result)) { - Blog::delete_comment($blog_id,$post_id,$comment['comment_id']); - } + delete_all_blog_attachment($blog_id, $post_id, $comment_id); - // Finally, delete the selected comment to - $sql = "DELETE FROM $tbl_blogs_comments - WHERE c_id = $course_id AND comment_id = '".$comment_id."'"; - Database::query($sql); - } + // Delete ratings on this comment + $sql = "DELETE FROM $tbl_blogs_rating + WHERE + c_id = $course_id AND + blog_id = '".$blog_id."' AND + item_id = '".$comment_id."' AND + rating_type = 'comment'"; + Database::query($sql); + + // select comments that have the selected comment as their parent + $sql = "SELECT comment_id FROM $tbl_blogs_comments + WHERE c_id = $course_id AND parent_comment_id = '".$comment_id."'"; + $result = Database::query($sql); + + // Delete them recursively + while ($comment = Database::fetch_array($result)) { + Blog::delete_comment($blog_id,$post_id,$comment['comment_id']); + } + + // Finally, delete the selected comment to + $sql = "DELETE FROM $tbl_blogs_comments + WHERE c_id = $course_id AND comment_id = '".$comment_id."'"; + Database::query($sql); + } - /** - * Creates a new task in a blog - * @author Toon Keppens - * @param Integer $blog_id - * @param String $title - * @param String $description - * @param String $color - */ - public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color) - { - $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); - $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); + /** + * Creates a new task in a blog + * @author Toon Keppens + * @param Integer $blog_id + * @param String $title + * @param String $description + * @param String $color + */ + public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color) + { + $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); + $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); - // Create the task - $sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task) - VALUES ($course_id , '".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');"; - Database::query($sql); + // Create the task + $sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task) + VALUES ($course_id , '".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');"; + Database::query($sql); - $task_id = Database::insert_id(); + $task_id = Database::insert_id(); if ($task_id) { $sql = "UPDATE $tbl_blogs_tasks SET task_id = iid WHERE iid = $task_id"; Database::query($sql); } - $tool = 'BLOG_' . $blog_id; + $tool = 'BLOG_' . $blog_id; - if ($articleDelete == 'on') { - $sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES ( - '" . (int)$course_id . "', - '" . (int)$task_id . "', - '" . Database::escape_string($tool) . "', - 'article_delete' - )"; - Database::query($sql); + if ($articleDelete == 'on') { + $sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES ( + '" . (int)$course_id . "', + '" . (int)$task_id . "', + '" . Database::escape_string($tool) . "', + 'article_delete' + )"; + Database::query($sql); $id = Database::insert_id(); @@ -575,171 +573,179 @@ class Blog } } - if ($articleEdit == 'on') { - $sql = " - INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES ( - '" . (int)$course_id . "', - '" . (int)$task_id . "', - '" . Database::escape_string($tool) . "', - 'article_edit' - )"; - Database::query($sql); + if ($articleEdit == 'on') { + $sql = " + INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES ( + '" . (int)$course_id . "', + '" . (int)$task_id . "', + '" . Database::escape_string($tool) . "', + 'article_edit' + )"; + Database::query($sql); $id = Database::insert_id(); if ($id) { $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; Database::query($sql); } - } + } - if ($commentsDelete == 'on') { - $sql = " - INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES ( - '" . (int)$course_id . "', - '" . (int)$task_id . "', - '" . Database::escape_string($tool) . "', - 'article_comments_delete' - )"; - Database::query($sql); + if ($commentsDelete == 'on') { + $sql = " + INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES ( + '" . (int)$course_id . "', + '" . (int)$task_id . "', + '" . Database::escape_string($tool) . "', + 'article_comments_delete' + )"; + Database::query($sql); $id = Database::insert_id(); if ($id) { $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; Database::query($sql); } - } - } + } + } - /** - * Edit a task in a blog - * @author Toon Keppens - * @param Integer $task_id - * @param String $title - * @param String $description - * @param String $color - */ - public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color) - { - $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); - $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); + /** + * Edit a task in a blog + * @author Toon Keppens + * @param Integer $task_id + * @param String $title + * @param String $description + * @param String $color + */ + public static function edit_task( + $blog_id, + $task_id, + $title, + $description, + $articleDelete, + $articleEdit, + $commentsDelete, + $color + ) { + $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); + $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); $course_id = api_get_course_int_id(); - // Create the task - $sql = "UPDATE $tbl_blogs_tasks SET - title = '".Database::escape_string($title)."', - description = '".Database::escape_string($description)."', - color = '".Database::escape_string($color)."' - WHERE c_id = $course_id AND task_id ='".(int)$task_id."' LIMIT 1"; - Database::query($sql); - - $tool = 'BLOG_' . $blog_id; - - $sql = "DELETE FROM " . $tbl_tasks_permissions . " - WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'"; - Database::query($sql); - - if ($articleDelete == 'on') { - $sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES ( - '" . (int)$course_id . "', - '" . (int)$task_id . "', - '" . Database::escape_string($tool) . "', - 'article_delete' - )"; - Database::query($sql); + // Create the task + $sql = "UPDATE $tbl_blogs_tasks SET + title = '".Database::escape_string($title)."', + description = '".Database::escape_string($description)."', + color = '".Database::escape_string($color)."' + WHERE c_id = $course_id AND task_id ='".(int)$task_id."' LIMIT 1"; + Database::query($sql); + + $tool = 'BLOG_' . $blog_id; + + $sql = "DELETE FROM " . $tbl_tasks_permissions . " + WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'"; + Database::query($sql); + + if ($articleDelete == 'on') { + $sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES ( + '" . (int)$course_id . "', + '" . (int)$task_id . "', + '" . Database::escape_string($tool) . "', + 'article_delete' + )"; + Database::query($sql); $id = Database::insert_id(); if ($id) { $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; Database::query($sql); } - } + } - if ($articleEdit == 'on') { - $sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES ( - '" . (int)$course_id . "', - '" . (int)$task_id . "', - '" . Database::escape_string($tool) . "', - 'article_edit' - )"; - Database::query($sql); + if ($articleEdit == 'on') { + $sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES ( + '" . (int)$course_id . "', + '" . (int)$task_id . "', + '" . Database::escape_string($tool) . "', + 'article_edit' + )"; + Database::query($sql); $id = Database::insert_id(); if ($id) { $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; Database::query($sql); } - } + } - if ($commentsDelete == 'on') { - $sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES ( - '" . (int)$course_id . "', - '" . (int)$task_id . "', - '" . Database::escape_string($tool) . "', - 'article_comments_delete' - )"; - Database::query($sql); + if ($commentsDelete == 'on') { + $sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES ( + '" . (int)$course_id . "', + '" . (int)$task_id . "', + '" . Database::escape_string($tool) . "', + 'article_comments_delete' + )"; + Database::query($sql); $id = Database::insert_id(); if ($id) { $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; Database::query($sql); } - } - } + } + } - /** - * Deletes a task from a blog - * @param Integer $blog_id - * @param Integer $task_id - */ - public static function delete_task($blog_id, $task_id) - { - $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); - $course_id = api_get_course_int_id(); - - // Delete posts - $sql = "DELETE FROM $tbl_blogs_tasks - WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."'"; - Database::query($sql); - } + /** + * Deletes a task from a blog + * @param Integer $blog_id + * @param Integer $task_id + */ + public static function delete_task($blog_id, $task_id) + { + $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); + $course_id = api_get_course_int_id(); + + // Delete posts + $sql = "DELETE FROM $tbl_blogs_tasks + WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."'"; + Database::query($sql); + } - /** - * Deletes an assigned task from a blog - * @param Integer $blog_id - */ - public static function delete_assigned_task($blog_id, $task_id, $user_id) - { - $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); + /** + * Deletes an assigned task from a blog + * @param Integer $blog_id + */ + public static function delete_assigned_task($blog_id, $task_id, $user_id) + { + $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); $course_id = api_get_course_int_id(); - // Delete posts - $sql = "DELETE FROM $tbl_blogs_tasks_rel_user - WHERE - c_id = $course_id AND - blog_id = '".(int)$blog_id."' AND - task_id = '".(int)$task_id."' AND - user_id = '".(int)$user_id."'"; - Database::query($sql); - } + // Delete posts + $sql = "DELETE FROM $tbl_blogs_tasks_rel_user + WHERE + c_id = $course_id AND + blog_id = '".(int)$blog_id."' AND + task_id = '".(int)$task_id."' AND + user_id = '".(int)$user_id."'"; + Database::query($sql); + } - /** - * Get personal task list - * @author Toon Keppens - * @return Returns an unsorted list () with the users' tasks - */ - public static function get_personal_task_list() - { - $_user = api_get_user_info(); + /** + * Get personal task list + * @author Toon Keppens + * @return Returns an unsorted list () with the users' tasks + */ + public static function get_personal_task_list() + { + $_user = api_get_user_info(); - $tbl_blogs = Database::get_course_table(TABLE_BLOGS); - $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); - $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); + $tbl_blogs = Database::get_course_table(TABLE_BLOGS); + $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); + $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); - if ($_user['user_id']) { - $sql = "SELECT task_rel_user.*, task.title, blog.blog_name + if ($_user['user_id']) { + $sql = "SELECT task_rel_user.*, task.title, blog.blog_name FROM $tbl_blogs_tasks_rel_user task_rel_user INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id @@ -753,332 +759,332 @@ class Blog task_rel_user.user_id = ".(int)$_user['user_id']." ORDER BY target_date ASC"; - $result = Database::query($sql); - - if (Database::num_rows($result) > 0) { - echo '