/**
  * Create a class
  * @param string $name
  */
 public static function create_class($name)
 {
     $table_class = Database::get_main_table(TABLE_MAIN_CLASS);
     $sql = "INSERT INTO {$table_class} SET name='" . Database::escape_string($name) . "'";
     Database::query($sql);
     return Database::affected_rows() == 1;
 }
        }
        break;
    case 'delete':
        // Delete course from session.
        $idChecked = isset($_GET['idChecked']) ? $_GET['idChecked'] : null;
        if (is_array($idChecked)) {
            $usersToDelete = array();
            foreach ($idChecked as $courseCode) {
                // forcing the escape_string
                $courseInfo = api_get_course_info($courseCode);
                SessionManager::unsubscribe_course_from_session($sessionId, $courseInfo['real_id']);
            }
        }
        if (!empty($_GET['class'])) {
            $result = Database::query("DELETE FROM {$tbl_session_rel_class}\n                             WHERE session_id='{$sessionId}' AND class_id=" . intval($_GET['class']));
            $nbr_affected_rows = Database::affected_rows($result);
            Database::query("UPDATE {$tbl_session} SET nbr_classes=nbr_classes-{$nbr_affected_rows} WHERE id='{$sessionId}'");
        }
        if (!empty($_GET['user'])) {
            SessionManager::unsubscribe_user_from_session($sessionId, $_GET['user']);
        }
        break;
}
$sessionHeader = Display::page_header(Display::return_icon('session.png', get_lang('Session')) . ' ' . $sessionInfo['name'], null, 'h3');
$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_edit.php?page=resume_session.php&id={$sessionId}");
$sessionTitle = Display::page_subheader(get_lang('GeneralProperties') . $url);
$generalCoach = api_get_user_info($sessionInfo['id_coach']);
$sessionField = new ExtraField('session');
$extraFieldData = $sessionField->getDataAndFormattedValues($sessionId);
$multiple_url_is_on = api_get_multiple_access_url();
$urlList = [];
function WSUnsuscribeCoursesFromSession($params)
{
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    // Initialisation
    $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
    $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
    $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
    $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
    $coursessessions_params = $params['coursessessions'];
    $results = array();
    $orig_course_id_value = array();
    $orig_session_id_value = array();
    foreach ($coursessessions_params as $coursesession_param) {
        $original_session_id_value = $coursesession_param['original_session_id_value'];
        $original_session_id_name = $coursesession_param['original_session_id_name'];
        $original_course_id_name = $coursesession_param['original_course_id_name'];
        $original_course_id_values = $coursesession_param['original_course_id_values'];
        $orig_session_id_value[] = $original_session_id_value;
        $id_session = SessionManager::getSessionIdFromOriginalId($original_session_id_value, $original_session_id_name);
        if (empty($id_session)) {
            $results[] = 0;
            continue;
        }
        // Get courses list from row_original_course_id_values
        $course_list = array();
        $courseIdList = [];
        foreach ($original_course_id_values as $row_original_course_list) {
            $course_code = Database::escape_string($row_original_course_list['course_code']);
            // Check whether exits $x_course_code into user_field_values table.
            $courseInfo = CourseManager::getCourseInfoFromOriginalId($row_original_course_list['course_code'], $original_course_id_name);
            if (empty($courseInfo) || isset($courseInfo) && $courseInfo['visibility'] == 0) {
                continue;
                // Course_code doesn't exist'
            }
            $course_list[] = $courseInfo['code'];
            $courseIdList[] = $courseInfo['real_id'];
        }
        if (empty($course_list)) {
            $results[] = 0;
            continue;
        }
        $orig_course_id_value[] = implode(',', $course_list);
        foreach ($courseIdList as $courseId) {
            $courseId = intval($courseId);
            Database::query("DELETE FROM {$tbl_session_rel_course}\n                            WHERE c_id ='{$courseId}' AND session_id='{$id_session}'");
            $result = Database::query("DELETE FROM {$tbl_session_rel_course_rel_user} WHERE c_id='{$courseId}' AND session_id = '{$id_session}'");
            Event::addEvent(LOG_SESSION_DELETE_COURSE, LOG_COURSE_ID, $courseId, api_get_utc_datetime(), api_get_user_id(), $courseId, $id_session);
            $return = Database::affected_rows($result);
        }
        $nbr_courses = 0;
        $sql = "SELECT nbr_courses FROM {$tbl_session} WHERE id = '{$id_session}'";
        $res_nbr_courses = Database::query($sql);
        $row_nbr_courses = Database::fetch_row($res_nbr_courses);
        if (Database::num_rows($res_nbr_courses) > 0) {
            $nbr_users = $row_nbr_courses[0] - $return;
        }
        // Update number of users in the session.
        $update_sql = "UPDATE {$tbl_session} SET nbr_courses= {$nbr_courses} WHERE id='{$id_session}' ";
        Database::query($update_sql);
        $results[] = 1;
        continue;
    }
    $count_results = count($results);
    $output = array();
    for ($i = 0; $i < $count_results; $i++) {
        $output[] = array('original_course_id_values' => $orig_course_id_value[$i], 'original_session_id_value' => $orig_session_id_value[$i], 'result' => $results[$i]);
    }
    return $output;
}
    static function delete_note($notebook_id)
    {
        if (empty($notebook_id) or $notebook_id != strval(intval($notebook_id))) {
            return false;
        }
        // Database table definition
        $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);

        $course_id = api_get_course_int_id();

        $sql = "DELETE FROM $t_notebook WHERE c_id = $course_id AND notebook_id='" . intval($notebook_id) . "' AND user_id = '" . api_get_user_id() . "'";
        $result = Database::query($sql);
        $affected_rows = Database::affected_rows();
        if ($affected_rows != 1) {
            return false;
        }
        //update item_property (delete)
        api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, intval($notebook_id), 'delete', api_get_user_id());
        return true;
    }
 /**
  * deletes groups and their data.
  * @author Christophe Gesche <*****@*****.**>
  * @author Hugues Peeters <*****@*****.**>
  * @author Bart Mollet
  * @param  mixed   $groupIdList - group(s) to delete. It can be a single id
  *                                (int) or a list of id (array).
  * @param string $course_code Default is current course
  * @return integer              - number of groups deleted.
  */
 public static function delete_groups($group_ids, $course_code = null)
 {
     $course_info = api_get_course_info($course_code);
     $course_id = $course_info['real_id'];
     // Database table definitions
     $group_table = Database::get_course_table(TABLE_GROUP);
     $forum_table = Database::get_course_table(TABLE_FORUM);
     $group_ids = is_array($group_ids) ? $group_ids : array($group_ids);
     $group_ids = array_map('intval', $group_ids);
     if (!api_is_platform_admin() && api_is_course_coach()) {
         // A coach can only delete courses from his session
         for ($i = 0; $i < count($group_ids); $i++) {
             if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) {
                 array_splice($group_ids, $i, 1);
                 $i--;
             }
         }
         if (count($group_ids) == 0) {
             return 0;
         }
     }
     // Unsubscribe all users
     self::unsubscribe_all_users($group_ids);
     $sql = "SELECT iid, secret_directory, session_id\n                FROM {$group_table}\n                WHERE c_id = {$course_id} AND iid IN (" . implode(' , ', $group_ids) . ")";
     $db_result = Database::query($sql);
     while ($group = Database::fetch_object($db_result)) {
         // move group-documents to garbage
         $source_directory = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . "/document" . $group->secret_directory;
         //File to renamed
         $destination_dir = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . "/document" . $group->secret_directory . '_DELETED_' . $group->iid;
         if (!empty($group->secret_directory)) {
             //Deleting from document tool
             DocumentManager::delete_document($course_info, $group->secret_directory, $source_directory);
             if (file_exists($source_directory)) {
                 if (api_get_setting('permanently_remove_deleted_files') == 'true') {
                     // Delete
                     my_delete($source_directory);
                 } else {
                     // Rename
                     rename($source_directory, $destination_dir);
                 }
             }
         }
     }
     // delete the groups
     $sql = "DELETE FROM " . $group_table . " WHERE c_id = {$course_id} AND iid IN ('" . implode("' , '", $group_ids) . "')";
     Database::query($sql);
     $sql = "DELETE FROM " . $forum_table . " WHERE c_id = {$course_id} AND forum_of_group IN ('" . implode("' , '", $group_ids) . "')";
     Database::query($sql);
     return Database::affected_rows($result);
 }
/**
 * Extended information about the course (from the course table as well as
 * the buy_course table)
 * @param string $code The course code
 * @return array Info about the course
 */
function courseInfo($code)
{
    $tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
    $tableCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    $tableUser = Database::get_main_table(TABLE_MAIN_USER);
    $currentUserId = api_get_user_id();
    $code = Database::escape_string($code);
    $sql = "SELECT a.course_id, a.visible, a.price, b.*\r\n            FROM {$tableBuyCourse} a, course b\r\n            WHERE\r\n                a.course_id=b.id AND\r\n                a.visible = 1 AND\r\n                b.id = '" . $code . "'";
    $res = Database::query($sql);
    $row = Database::fetch_assoc($res);
    // Check teacher
    $sql = "SELECT lastname, firstname\r\n        FROM {$tableCourseRelUser} a, {$tableUser} b\r\n        WHERE\r\n            a.c_id = '" . $row['id'] . "' AND\r\n            a.status <> 6 AND\r\n            a.user_id = b.user_id;";
    $tmp = Database::query($sql);
    $rowTmp = Database::fetch_assoc($tmp);
    $row['teacher'] = $rowTmp['firstname'] . ' ' . $rowTmp['lastname'];
    //Check if student is enrolled
    if ($currentUserId > 0) {
        $sql = "SELECT 1 FROM {$tableCourseRelUser}\r\n                WHERE\r\n                    c_id ='" . $row['id'] . "' AND\r\n                    user_id='" . $currentUserId . "';";
        $result = Database::query($sql);
        if (Database::affected_rows($result) > 0) {
            $row['enrolled'] = "YES";
        } else {
            $row['enrolled'] = "NO";
        }
    } else {
        $row['enrolled'] = "NO";
    }
    //check img
    if (file_exists("../../courses/" . $row['code'] . "/course-pic85x85.png")) {
        $row['course_img'] = "courses/" . $row['code'] . "/course-pic85x85.png";
    } else {
        $row['course_img'] = "main/img/without_picture.png";
    }
    $row['price'] = number_format($row['price'], 2, '.', ' ');
    return $row;
}
 /**
  * @param $id_session
  * @param $courseId
  */
 static function delete_course_in_session($id_session, $courseId)
 {
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $id_session = intval($id_session);
     $courseId = Database::escape_string($courseId);
     if (!empty($id_session) && !empty($courseId)) {
         $result = Database::query("DELETE FROM {$tbl_session_rel_course} WHERE id_session='{$id_session}' AND c_id = '{$courseId}'");
         $nbr_affected_rows = Database::affected_rows($result);
         Database::query("DELETE FROM {$tbl_session_rel_course_rel_user} WHERE id_session='{$id_session}' AND c_id = '{$courseId}'");
         Database::query("UPDATE {$tbl_session} SET nbr_courses=nbr_courses-{$nbr_affected_rows} WHERE id='{$id_session}'");
     }
 }
 /**
  * Sets the name of the current learnpath (and save)
  * @param    string    Optional string giving the new name of this learnpath
  * @return  boolean True/False
  */
 public function set_name($name = null)
 {
     if ($this->debug > 0) {
         error_log('New LP - In learnpath::set_name()', 0);
     }
     if (empty($name)) {
         return false;
     }
     $this->name = Database::escape_string($name);
     $lp_table = Database::get_course_table(TABLE_LP_MAIN);
     $lp_id = $this->get_id();
     $course_id = api_get_course_int_id();
     $sql = "UPDATE {$lp_table} SET name = '" . $this->name . "' WHERE c_id = " . $course_id . " AND id = '{$lp_id}'";
     if ($this->debug > 2) {
         error_log('New LP - lp updated with new name : ' . $this->name, 0);
     }
     $result = Database::query($sql);
     // If the lp is visible on the homepage, change his name there.
     if (Database::affected_rows($result)) {
         $session_id = api_get_session_id();
         $session_condition = api_get_session_condition($session_id);
         $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
         $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '&id_session=' . $session_id;
         $sql = "UPDATE {$tbl_tool} SET name = '{$this->name}'\n            \t    WHERE c_id = " . $course_id . " AND (link='{$link}' and image='scormbuilder.gif' {$session_condition})";
         Database::query($sql);
         return true;
     } else {
         return false;
     }
 }
Exemple #9
0
 /**
  * This function allows easy activating and inactivating
  * of plugins and save them inside db
  * @param array $plugin_paths dashboard plugin paths
  * return int affected rows
  */
 public static function store_dashboard_plugins($plugin_paths)
 {
     $tbl_block = Database::get_main_table(TABLE_MAIN_BLOCK);
     $affected_rows = 0;
     // get all plugins path inside plugin directory
     $dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH) . 'dashboard/';
     $possibleplugins = self::get_posible_dashboard_plugins_path();
     if (count($possibleplugins) > 0) {
         $selected_plugins = array_intersect(array_keys($plugin_paths), $possibleplugins);
         $not_selected_plugins = array_diff($possibleplugins, array_keys($plugin_paths));
         // get blocks id from not selected path
         $not_selected_blocks_id = array();
         foreach ($not_selected_plugins as $plugin) {
             $block_data = self::get_enabled_dashboard_blocks($plugin);
             if (!empty($block_data[$plugin])) {
                 $not_selected_blocks_id[] = $block_data[$plugin]['id'];
             }
         }
         /* clean not selected plugins for extra user data and block data */
         // clean from extra user data
         $field_variable = 'dashboard';
         $extra_user_data = UserManager::get_extra_user_data_by_field_variable($field_variable);
         foreach ($extra_user_data as $key => $user_data) {
             $user_id = $key;
             $user_block_data = self::get_user_block_data($user_id);
             $user_block_id = array_keys($user_block_data);
             // clean disabled block data
             foreach ($user_block_id as $block_id) {
                 if (in_array($block_id, $not_selected_blocks_id)) {
                     unset($user_block_data[$block_id]);
                 }
             }
             // get columns and blocks id for updating extra user data
             $columns = array();
             $user_blocks_id = array();
             foreach ($user_block_data as $data) {
                 $user_blocks_id[$data['block_id']] = true;
                 $columns[$data['block_id']] = $data['column'];
             }
             // update extra user blocks data
             $upd_extra_field = self::store_user_blocks($user_id, $user_blocks_id, $columns);
         }
         // clean from block data
         if (!empty($not_selected_blocks_id)) {
             $sql_check = "SELECT id FROM {$tbl_block} WHERE id IN(" . implode(',', $not_selected_blocks_id) . ")";
             $rs_check = Database::query($sql_check);
             if (Database::num_rows($rs_check) > 0) {
                 $del = "DELETE FROM {$tbl_block} WHERE id IN(" . implode(',', $not_selected_blocks_id) . ")";
                 Database::query($del);
             }
         }
         // store selected plugins
         foreach ($selected_plugins as $testplugin) {
             $selected_path = Database::escape_string($testplugin);
             // check if the path already stored inside block table for updating or adding it
             $sql = "SELECT path FROM {$tbl_block} WHERE path = '{$selected_path}'";
             $rs = Database::query($sql);
             if (Database::num_rows($rs) > 0) {
                 // update
                 $upd = "UPDATE {$tbl_block} SET active = 1 WHERE path = '{$selected_path}'";
                 $result = Database::query($upd);
                 $affected_rows = Database::affected_rows($result);
             } else {
                 // insert
                 $plugin_info_file = $dashboard_pluginpath . $testplugin . "/{$testplugin}.info";
                 $plugin_info = array();
                 if (file_exists($plugin_info_file)) {
                     $plugin_info = parse_info_file($plugin_info_file);
                 }
                 // change keys to lower case
                 $plugin_info = array_change_key_case($plugin_info);
                 // setting variables
                 $plugin_name = $testplugin;
                 $plugin_description = '';
                 $plugin_controller = '';
                 $plugin_path = $testplugin;
                 if (isset($plugin_info['name'])) {
                     $plugin_name = Database::escape_string($plugin_info['name']);
                 }
                 if (isset($plugin_info['description'])) {
                     $plugin_description = Database::escape_string($plugin_info['description']);
                 }
                 if (isset($plugin_info['controller'])) {
                     $plugin_controller = Database::escape_string($plugin_info['controller']);
                 }
                 $ins = "INSERT INTO {$tbl_block}(name, description, path, controller)\n\t\t\t\t\t\t\tVALUES ('{$plugin_name}', '{$plugin_description}', '{$plugin_path}', '{$plugin_controller}')";
                 $result = Database::query($ins);
                 $affected_rows = Database::affected_rows($result);
             }
         }
     }
     return $affected_rows;
 }
if (!(list($session_name) = Database::fetch_row($result))) {
    header('Location: session_list.php');
    exit;
}
if ($action == 'delete') {
    $idChecked = $_REQUEST['idChecked'];
    if (is_array($idChecked) && count($idChecked) > 0) {
        $my_temp = array();
        foreach ($idChecked as $id) {
            $my_temp[] = Database::escape_string($id);
            // forcing the escape_string
        }
        $idChecked = $my_temp;
        $idChecked = "'" . implode("','", $idChecked) . "'";
        Database::query("DELETE FROM {$tbl_session_rel_course} WHERE id_session='{$id_session}' AND course_code IN({$idChecked})");
        $nbr_affected_rows = Database::affected_rows();
        Database::query("DELETE FROM {$tbl_session_rel_course_rel_user} WHERE id_session='{$id_session}' AND course_code IN({$idChecked})");
        Database::query("UPDATE {$tbl_session} SET nbr_courses=nbr_courses-{$nbr_affected_rows} WHERE id='{$id_session}'");
    }
    header('Location: ' . api_get_self() . '?id_session=' . $id_session . '&sort=' . $sort);
    exit;
}
$limit = 20;
$from = $page * $limit;
$sql = "SELECT code, title, nbr_users FROM {$tbl_session_rel_course}, {$tbl_course} WHERE course_code=code AND id_session='{$id_session}' ORDER BY {$sort} LIMIT {$from}," . ($limit + 1);
$result = Database::query($sql);
$Courses = Database::store_result($result);
$tool_name = api_htmlentities($session_name, ENT_QUOTES, $charset) . ' : ' . get_lang('CourseListInSession');
$interbreadcrumb[] = array('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => "session_list.php", "name" => get_lang('SessionList'));
$interbreadcrumb[] = array('url' => "resume_session.php?id_session=" . Security::remove_XSS($_REQUEST['id_session']), "name" => get_lang('SessionOverview'));
/**
 * Update forum attachment data, used to update comment and post ID.
 * @param $array Array (field => value) to update forum attachment row.
 * @param $id Attach ID to find row to update.
 * @param null $courseId Course ID to find row to update.
 * @return int Number of affected rows.
 */
function editAttachedFile($array, $id, $courseId = null)
{
    // Init variables
    $setString = '';
    $id = intval($id);
    $courseId = intval($courseId);
    if (empty($courseId)) {
        // $courseId can be null, use api method
        $courseId = api_get_course_int_id();
    }
    /*
     * Check if Attachment ID and Course ID are greater than zero
     * and array of field values is not empty
     */
    if ($id > 0 && $courseId > 0 && !empty($array) && is_array($array)) {
        foreach ($array as $key => &$item) {
            $item = Database::escape_string($item);
            $setString .= $key . ' = "' . $item . '", ';
        }
        // Delete last comma
        $setString = substr($setString, 0, strlen($setString) - 2);
        $forumAttachmentTable = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
        $sql = "UPDATE {$forumAttachmentTable} SET {$setString} WHERE c_id = {$courseId} AND id = {$id}";
        $result = Database::query($sql);
        if ($result !== false) {
            $affectedRows = Database::affected_rows($result);
            if ($affectedRows > 0) {
                /*
                 * If exist in $_SESSION variable, then delete them from it
                 * because they would be deprecated
                 */
                if (!empty($_SESSION['forum']['upload_file'][$courseId][$id])) {
                    unset($_SESSION['forum']['upload_file'][$courseId][$id]);
                }
            }
            return $affectedRows;
        }
    }
    return 0;
}
Exemple #12
0
/**
 * Inserts a record in the track_e_item_property table (No update)
 * @param string $tool
 * @param int $ref
 * @param string $title
 * @param string $content
 * @param int $progress
 * @return bool|int
 */
function api_track_item_property_update($tool, $ref, $title, $content, $progress)
{
    $tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
    $course_id = api_get_real_course_id();
    //numeric
    $course_code = api_get_course_id();
    //alphanumeric
    $item_property_id = api_get_item_property_id($course_code, $tool, $ref);
    if (!empty($item_property_id)) {
        $sql = "INSERT IGNORE INTO {$tbl_stats_item_property} SET\n                course_id           = '{$course_id}',\n                item_property_id    = '{$item_property_id}',\n                title               = '" . Database::escape_string($title) . "',\n                content             = '" . Database::escape_string($content) . "',\n                progress            = '" . intval($progress) . "',\n                lastedit_date       = '" . api_get_utc_datetime() . "',\n                lastedit_user_id    = '" . api_get_user_id() . "',\n                session_id          = '" . api_get_session_id() . "'";
        $result = Database::query($sql);
        $affected_rows = Database::affected_rows($result);
        return $affected_rows;
    }
    return false;
}
 /**
  * delete a datetime from attendance calendar table
  * @param	int		attendance calendar id
  * @param	int		attendance id
  * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
  * @return	int affected rows
  */
 public function attendance_calendar_delete($calendar_id, $attendance_id, $all_delete = false)
 {
     $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
     $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
     $session_id = api_get_session_id();
     $attendance_id = intval($attendance_id);
     // get all registered users inside current course
     $users = $this->get_users_rel_course();
     $user_ids = array_keys($users);
     $course_id = api_get_course_int_id();
     if ($all_delete) {
         $attendance_calendar = $this->get_attendance_calendar($attendance_id);
         $calendar_ids = array();
         // get all dates from calendar by current attendance
         if (!empty($attendance_calendar)) {
             foreach ($attendance_calendar as $cal) {
                 // delete all data from attendance sheet
                 $sql = "DELETE FROM {$tbl_attendance_sheet} WHERE c_id = {$course_id} AND attendance_calendar_id = '" . intval($cal['id']) . "'";
                 Database::query($sql);
                 // delete data from attendance calendar
                 $sql = "DELETE FROM {$tbl_attendance_calendar} WHERE c_id = {$course_id} AND id = '" . intval($cal['id']) . "'";
                 $result = Database::query($sql);
             }
         }
     } else {
         // delete just one row from attendance sheet by the calendar id
         $sql = "DELETE FROM {$tbl_attendance_sheet} WHERE c_id = {$course_id} AND attendance_calendar_id = '" . intval($calendar_id) . "'";
         Database::query($sql);
         // delete data from attendance calendar
         $sql = "DELETE FROM {$tbl_attendance_calendar} WHERE c_id = {$course_id} AND id = '" . intval($calendar_id) . "'";
         $result = Database::query($sql);
     }
     $affected_rows = Database::affected_rows($result);
     // update users' results
     $this->update_users_results($user_ids, $attendance_id);
     return $affected_rows;
 }
    /**
     * @param $status_id
     * @param $ticket_id
     * @param $user_id
     * @return bool
     */
    public static function update_ticket_status(
        $status_id,
        $ticket_id,
        $user_id
    ) {
        $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);

        $ticket_id = intval($ticket_id);
        $status_id = intval($status_id);
        $user_id = intval($user_id);

        $now = api_get_utc_datetime();
        $sql = "UPDATE " . $table_support_tickets . " SET
                status_id = '$status_id',
                sys_lastedit_user_id ='$user_id',
                sys_lastedit_datetime ='" . $now . "'
                WHERE ticket_id ='$ticket_id'";
        Database::query($sql);
        if (Database::affected_rows() > 0) {
            return true;
        } else {
            return false;
        }
    }
/**
 * Delete a user field (and also the options and values entered by the users)
 *
 * @param integer $field_id the id of the field that has to be deleted
 * @return boolean true if the field has been deleted, false if the field could not be deleted (for whatever reason)
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
 * @version July 2008
 * @since Dokeos 1.8.6
 */
function delete_user_fields($field_id)
{
    // Database table definitions
    $table_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
    $table_user_field_options = Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
    $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
    // delete the fields
    $sql = "DELETE FROM {$table_user_field} WHERE id = '" . Database::escape_string($field_id) . "'";
    $result = Database::query($sql);
    if (Database::affected_rows($result) == 1) {
        // delete the field options
        $sql = "DELETE FROM {$table_user_field_options} WHERE field_id = '" . Database::escape_string($field_id) . "'";
        $result = Database::query($sql);
        // delete the field values
        $sql = "DELETE FROM {$table_user_field_values} WHERE field_id = '" . Database::escape_string($field_id) . "'";
        $result = Database::query($sql);
        // recalculate the field_order because the value is used to show/hide the up/down icon
        // and the field_order value cannot be bigger than the number of fields
        $sql = "SELECT * FROM {$table_user_field} ORDER BY field_order ASC";
        $result = Database::query($sql);
        $i = 1;
        while ($row = Database::fetch_array($result)) {
            $sql_reorder = "UPDATE {$table_user_field} SET field_order = '" . Database::escape_string($i) . "' WHERE id = '" . Database::escape_string($row['id']) . "'";
            $result_reorder = Database::query($sql_reorder);
            $i++;
        }
        // field was deleted so we return true
        return true;
    } else {
        // the field was not deleted so we return false
        return false;
    }
}
Exemple #16
0
 /**
  * stores the user course category in the chamilo_user database
  * @param   string  Category title
  * @return  bool    True if it success
  */
 public function store_course_category($category_title)
 {
     $tucc = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
     // protect data
     $current_user_id = api_get_user_id();
     $category_title = Database::escape_string($category_title);
     $result = false;
     // step 1: we determine the max value of the user defined course categories
     $sql = "SELECT sort FROM {$tucc} WHERE user_id='" . $current_user_id . "' ORDER BY sort DESC";
     $rs_sort = Database::query($sql);
     $maxsort = Database::fetch_array($rs_sort);
     $nextsort = $maxsort['sort'] + 1;
     // step 2: we check if there is already a category with this name, if not we store it, else we give an error.
     $sql = "SELECT * FROM {$tucc} WHERE user_id='" . $current_user_id . "' AND title='" . $category_title . "'ORDER BY sort DESC";
     $rs = Database::query($sql);
     if (Database::num_rows($rs) == 0) {
         $sql_insert = "INSERT INTO {$tucc} (user_id, title,sort)\n                           VALUES ('" . $current_user_id . "', '" . api_htmlentities($category_title, ENT_QUOTES, api_get_system_encoding()) . "', '" . $nextsort . "')";
         $resultQuery = Database::query($sql_insert);
         if (Database::affected_rows($resultQuery)) {
             $result = true;
         }
     } else {
         $result = false;
     }
     return $result;
 }
Exemple #17
0
function storage_set($sv_user, $sv_course, $sv_sco, $sv_key, $sv_value)
{
    $sv_value = Database::escape_string($sv_value);
    $sql = "replace into " . Database::get_main_table(TABLE_TRACK_STORED_VALUES) . "\n\t\t(user_id, sco_id, course_id, sv_key, sv_value)\n\t\tvalues\n\t\t('{$sv_user}','{$sv_sco}','{$sv_course}','{$sv_key}','{$sv_value}')";
    $res = Database::query($sql);
    return Database::affected_rows($res);
}
 /**
  * update done thematic advances from thematic details interface
  * @param 	int		Thematic id
  * @return	int		Affected rows
  */
 public function update_done_thematic_advances($thematic_advance_id)
 {
     $_course = api_get_course_info();
     $thematic_data = $this->get_thematic_list(null, api_get_course_id());
     $thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
     $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
     $affected_rows = 0;
     $user_id = api_get_user_id();
     $all = array();
     if (!empty($thematic_data)) {
         foreach ($thematic_data as $thematic) {
             $thematic_id = $thematic['id'];
             if (!empty($thematic_advance_data[$thematic['id']])) {
                 foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
                     $all[] = $thematic_advance['id'];
                 }
             }
         }
     }
     $error = null;
     $a_thematic_advance_ids = array();
     $course_id = api_get_course_int_id();
     $sessionId = api_get_session_id();
     if (!empty($thematic_data)) {
         foreach ($thematic_data as $thematic) {
             $my_affected_rows = 0;
             $thematic_id = $thematic['id'];
             if (!empty($thematic_advance_data[$thematic['id']])) {
                 foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
                     $item_info = api_get_item_property_info(api_get_course_int_id(), 'thematic_advance', $thematic_advance['id'], $sessionId);
                     if ($item_info['id_session'] == $sessionId) {
                         $a_thematic_advance_ids[] = $thematic_advance['id'];
                         // update done thematic for previous advances ((done_advance = 1))
                         $upd = "UPDATE {$tbl_thematic_advance} SET\n                                    done_advance = 1\n                                    WHERE c_id = {$course_id} AND id = " . $thematic_advance['id'] . " ";
                         $result = Database::query($upd);
                         $my_affected_rows = Database::affected_rows($result);
                         $affected_rows += $my_affected_rows;
                         //if ($my_affected_rows) {
                         api_item_property_update($_course, 'thematic_advance', $thematic_advance['id'], "ThematicAdvanceDone", $user_id);
                         //}
                         if ($thematic_advance['id'] == $thematic_advance_id) {
                             break 2;
                         }
                     }
                 }
             }
         }
     }
     // Update done thematic for others advances (done_advance = 0)
     if (!empty($a_thematic_advance_ids) && count($a_thematic_advance_ids) > 0) {
         $diff = array_diff($all, $a_thematic_advance_ids);
         if (!empty($diff)) {
             $upd = "UPDATE {$tbl_thematic_advance} SET done_advance = 0\n    \t\t\t        WHERE c_id = {$course_id} AND id IN(" . implode(',', $diff) . ") ";
             Database::query($upd);
         }
         // update item_property
         $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
         $sql = "SELECT ref FROM {$tbl_item_property}\n                    WHERE\n                        c_id = {$course_id} AND\n                        tool='thematic_advance' AND\n                        lastedit_type='ThematicAdvanceDone' AND\n                        session_id = {$sessionId} ";
         // get all thematic advance done
         $rs_thematic_done = Database::query($sql);
         if (Database::num_rows($rs_thematic_done) > 0) {
             while ($row_thematic_done = Database::fetch_array($rs_thematic_done)) {
                 $ref = $row_thematic_done['ref'];
                 if (in_array($ref, $a_thematic_advance_ids)) {
                     continue;
                 }
                 // update items
                 $sql = "UPDATE {$tbl_item_property} SET\n                                lastedit_date='" . api_get_utc_datetime() . "',\n                                lastedit_type='ThematicAdvanceUpdated',\n                                lastedit_user_id = {$user_id}\n                            WHERE\n                                c_id = {$course_id} AND\n                                tool='thematic_advance' AND\n                                ref={$ref} AND\n                                session_id = {$sessionId}  ";
                 Database::query($sql);
             }
         }
     }
     return $affected_rows;
 }
 /**
  * Add subscribed users to a user by relation type
  * @param int $userId The user id
  * @param array $subscribedUsersId The id of suscribed users
  * @param action $relationType The relation type
  */
 public static function subscribeUsersToUser($userId, $subscribedUsersId, $relationType)
 {
     $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
     $userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
     $userId = intval($userId);
     $relationType = intval($relationType);
     $affectedRows = 0;
     if (api_get_multiple_access_url()) {
         //Deleting assigned users to hrm_id
         $sql = "SELECT s.user_id FROM {$userRelUserTable} s " . "INNER JOIN {$userRelAccessUrlTable} a ON (a.user_id = s.user_id) " . "WHERE friend_user_id = {$userId} " . "AND relation_type = {$relationType} " . "AND access_url_id = " . api_get_current_access_url_id() . "";
     } else {
         $sql = "SELECT user_id FROM {$userRelUserTable} " . "WHERE friend_user_id = {$userId} " . "AND relation_type = {$relationType}";
     }
     $result = Database::query($sql);
     if (Database::num_rows($result) > 0) {
         while ($row = Database::fetch_array($result)) {
             $sql = "DELETE FROM {$userRelUserTable} " . "WHERE user_id = {$row['user_id']} " . "AND friend_user_id = {$userId} " . "AND relation_type = {$relationType}";
             Database::query($sql);
         }
     }
     // Inserting new user list
     if (is_array($subscribedUsersId)) {
         foreach ($subscribedUsersId as $subscribedUserId) {
             $subscribedUserId = intval($subscribedUserId);
             $sql = "INSERT IGNORE INTO {$userRelUserTable}(user_id, friend_user_id, relation_type) " . "VALUES ({$subscribedUserId}, {$userId}, {$relationType})";
             $result = Database::query($sql);
             $affectedRows = Database::affected_rows($result);
         }
     }
     return $affectedRows;
 }
 public static function temp_hack_2_delete($entity_id, $row_id, $c_id)
 {
     if (self::_debug) {
         error_log('Entering ' . __FUNCTION__ . ' in ' . __FILE__);
     }
     $row_entity_id = self::get_row_entity_id_by_row_id($entity_id, $row_id, $c_id);
     if ($row_entity_id !== false) {
         $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
         $sql = "DELETE FROM {$row_table} WHERE id = {$row_entity_id}";
         $result = Database::query($sql);
         if (Database::affected_rows() > 0) {
             return Database::affected_rows();
         }
     }
     return false;
 }
Exemple #21
0
 /**
  * add attendances sheet inside table
  * @param 	int	   $calendar_id attendance calendar id
  * @param  	array  $users_present present users during current class
  * @param	int	   $attendance_id
  * @return 	int    affected rows
  */
 public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
 {
     $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
     $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
     $calendar_id = intval($calendar_id);
     $attendance_id = intval($attendance_id);
     $users = $this->get_users_rel_course();
     $course_id = api_get_course_int_id();
     $user_ids = array_keys($users);
     $users_absent = array_diff($user_ids, $users_present);
     $affected_rows = 0;
     // get last edit type
     $calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
     $lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
     if ($calendar_data['done_attendance']) {
         $lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
     }
     // save users present in class
     foreach ($users_present as $user_present) {
         $uid = intval($user_present);
         // check if user already was registered with the $calendar_id
         $sql = "SELECT user_id FROM {$tbl_attendance_sheet}\n\t\t\t\t\tWHERE c_id = {$course_id} AND user_id='{$uid}' AND attendance_calendar_id = '{$calendar_id}'";
         $rs = Database::query($sql);
         if (Database::num_rows($rs) == 0) {
             $sql = "INSERT INTO {$tbl_attendance_sheet} SET\n\t\t\t\t\t\tc_id\t\t\t\t\t= {$course_id},\n\t\t\t\t\t\tuser_id \t\t\t\t= '{$uid}',\n\t\t\t\t\t\tattendance_calendar_id \t= '{$calendar_id}',\n\t\t\t\t\t\tpresence \t\t\t\t= 1";
             $result = Database::query($sql);
             $affected_rows += Database::affected_rows($result);
         } else {
             $sql = "UPDATE {$tbl_attendance_sheet} SET presence = 1\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tc_id = {$course_id} AND\n\t\t\t\t\t\t\tuser_id ='{$uid}' AND\n\t\t\t\t\t\t\tattendance_calendar_id = '{$calendar_id}'\n\t\t\t\t\t\t";
             $result = Database::query($sql);
             $affected_rows += Database::affected_rows($result);
         }
     }
     // save users absent in class
     foreach ($users_absent as $user_absent) {
         $uid = intval($user_absent);
         // check if user already was registered with the $calendar_id
         $sql = "SELECT user_id FROM {$tbl_attendance_sheet}\n\t\t\t\t\tWHERE c_id = {$course_id} AND user_id='{$uid}' AND attendance_calendar_id = '{$calendar_id}'";
         $rs = Database::query($sql);
         if (Database::num_rows($rs) == 0) {
             $sql = "INSERT INTO {$tbl_attendance_sheet} SET\n\t\t\t\t\t\tc_id = {$course_id},\n\t\t\t\t\t\tuser_id ='{$uid}',\n\t\t\t\t\t\tattendance_calendar_id = '{$calendar_id}',\n\t\t\t\t\t\tpresence = 0";
             $result = Database::query($sql);
             Database::insert_id();
             $affected_rows += Database::affected_rows($result);
         } else {
             $sql = "UPDATE {$tbl_attendance_sheet} SET presence = 0\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tc_id = {$course_id} AND\n\t\t\t\t\t\t\tuser_id ='{$uid}' AND\n\t\t\t\t\t\t\tattendance_calendar_id = '{$calendar_id}'";
             $result = Database::query($sql);
             $affected_rows += Database::affected_rows($result);
         }
     }
     // update done_attendance inside attendance calendar table
     $sql = "UPDATE {$tbl_attendance_calendar} SET done_attendance = 1\n\t\t\t\tWHERE  c_id = {$course_id} AND id = '{$calendar_id}'";
     Database::query($sql);
     // save users' results
     $this->update_users_results($user_ids, $attendance_id);
     if ($affected_rows) {
         //save attendance sheet log
         $lastedit_date = api_get_utc_datetime();
         $lastedit_user_id = api_get_user_id();
         $calendar_date_value = $calendar_data['date_time'];
         $this->save_attendance_sheet_log($attendance_id, $lastedit_date, $lastedit_type, $lastedit_user_id, $calendar_date_value);
     }
     return $affected_rows;
 }
Exemple #22
0
 /**
  * Subscribes courses to human resource manager (Dashboard feature)
  * @param    int   $hr_manager_id      Human Resource Manager id
  * @param    array $courses_list       Courses code
  * @return int
  **/
 public static function subscribeCoursesToDrhManager($hr_manager_id, $courses_list)
 {
     $tbl_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
     $hr_manager_id = intval($hr_manager_id);
     $affected_rows = 0;
     //Deleting assigned courses to hrm_id
     if (api_is_multiple_url_enabled()) {
         $sql = "SELECT s.c_id FROM {$tbl_course_rel_user} s\n                    INNER JOIN {$tbl_course_rel_access_url} a\n                    ON (a.c_id = s.c_id)\n                    WHERE\n                        user_id = {$hr_manager_id} AND\n                        relation_type=" . COURSE_RELATION_TYPE_RRHH . " AND\n                        access_url_id = " . api_get_current_access_url_id() . "";
     } else {
         $sql = "SELECT c_id FROM {$tbl_course_rel_user}\n                    WHERE user_id = {$hr_manager_id} AND relation_type=" . COURSE_RELATION_TYPE_RRHH . " ";
     }
     $result = Database::query($sql);
     if (Database::num_rows($result) > 0) {
         while ($row = Database::fetch_array($result)) {
             $sql = "DELETE FROM {$tbl_course_rel_user}\n                        WHERE\n                            c_id = '{$row['c_id']}' AND\n                            user_id = {$hr_manager_id} AND\n                            relation_type=" . COURSE_RELATION_TYPE_RRHH . " ";
             Database::query($sql);
         }
     }
     // inserting new courses list
     if (is_array($courses_list)) {
         foreach ($courses_list as $course_code) {
             $courseInfo = api_get_course_info($course_code);
             $courseId = $courseInfo['real_id'];
             $sql = "INSERT IGNORE INTO {$tbl_course_rel_user}(c_id, user_id, status, relation_type)\n                        VALUES({$courseId}, {$hr_manager_id}, '" . DRH . "', '" . COURSE_RELATION_TYPE_RRHH . "')";
             $result = Database::query($sql);
             if (Database::affected_rows($result)) {
                 $affected_rows++;
             }
         }
     }
     return $affected_rows;
 }
 /**
  * Modify category name or description of category with id=in_id
  */
 public function modifyCategory()
 {
     $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
     $v_id = intval($this->id);
     $v_name = Database::escape_string($this->name);
     $v_description = Database::escape_string($this->description);
     $sql = "UPDATE {$table} SET\n                title = '{$v_name}',\n                description = '{$v_description}'\n                WHERE id = {$v_id} AND c_id=" . api_get_course_int_id();
     $result = Database::query($sql);
     if (Database::affected_rows($result) <= 0) {
         return false;
     } else {
         // item_property update
         $course_id = api_get_course_int_id();
         $course_info = api_get_course_info_by_id($course_id);
         api_item_property_update($course_info, TOOL_TEST_CATEGORY, $this->id, 'TestCategoryModified', api_get_user_id());
         return true;
     }
 }
 /**
  * Delete a description, first you must set description_type and session_id
  * properties with the object CourseDescription
  * @return int    affected rows
  */
 public function delete()
 {
     $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
     $course_id = api_get_course_int_id();
     $sql = "DELETE FROM {$tbl_course_description}\n\t\t\t \tWHERE\n\t\t\t \t    c_id = {$course_id} AND\n\t\t\t \t    id = '" . intval($this->id) . "' AND\n\t\t\t \t    session_id = '" . intval($this->session_id) . "'";
     $result = Database::query($sql);
     $affected_rows = Database::affected_rows($result);
     if ($this->id > 0) {
         //insert into item_property
         api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $this->id, 'CourseDescriptionDeleted', api_get_user_id());
     }
     return $affected_rows;
 }
/**
 * @author Hugues Peeters - peeters@ipm.ucl.ac.be
 * @param  int     $user_id
 * @param  string  $course_code
 * @param  array   $properties - should contain 'role', 'status', 'tutor_id'
 * @return boolean true if succeed false otherwise
 */
function update_user_course_properties($user_id, $course_code, $properties)
{
    global $tbl_coursUser, $_user;
    $sqlChangeStatus = "";
    $user_id = strval(intval($user_id));
    //filter integer
    $course_code = Database::escape_string($course_code);
    if ($user_id != $_user['user_id']) {
        $sqlChangeStatus = "status     = '" . Database::escape_string($properties['status']) . "',";
    }
    //feature deprecated   tutor_id      	= '".Database::escape_string($properties['tutor'])."'
    $sql = "UPDATE {$tbl_coursUser}\n    \t\t\t\t\tSET \t" . $sqlChangeStatus . "\n\t                    role      \t\t= '" . Database::escape_string($properties['role']) . "',\n\t                    tutor_id      \t= '" . Database::escape_string($properties['tutor']) . "'\n\t                    WHERE   user_id\t    \t= '" . $user_id . "'\n\t                    AND     course_code\t\t= '" . $course_code . "'";
    $result = Database::query($sql);
    if (Database::affected_rows($result) > 0) {
        return true;
    } else {
        return false;
    }
}
Exemple #26
0
function remove_engine_entries($url, $path, $file = '')
{
	global $charset;

    $and_path = " AND path = '" . addslashes($path) . "'";
    if ($file) $and_path .= " AND file LIKE '" . addslashes(
        str_replace(array('_', '%'), array('\_', '\%'), $file)) . "%'";

    $result = Database::query("SELECT spider_id FROM " . PHPDIG_DB_PREFIX .
        "spider WHERE site_id=" . ($site_id = find_site($url)) . $and_path);  // find page(s)

    while ($row = Database::fetch_array($result))
    {
        Database::query("DELETE FROM " . PHPDIG_DB_PREFIX .
            "engine WHERE spider_id=" . (int)$row['spider_id']);  // delete all references to keywords
        $aff .= ' +' . Database::affected_rows();
    }

    Database::query("DELETE FROM " . PHPDIG_DB_PREFIX .
        "spider WHERE site_id=" . $site_id . $and_path);  // delete page

    echo htmlspecialchars($url . $path . $file, ENT_QUOTES, $charset), ' (site_id ',
        $site_id, '): ', Database::affected_rows(), $aff,
        ' pages + word references removed from index.<br />';

    return $site_id;
}
Exemple #27
0
    /**
     * Sets the name of the current learnpath (and save)
     * @param	string	Optional string giving the new name of this learnpath
     */
    function set_name($name = '')
    {
        if ($this->debug > 0) {
            error_log('New LP - In learnpath::set_name()', 0);
        }
        if (empty($name)) {
            return false;
        }
        $this->name = $this->escape_string($name);
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
        $lp_id = $this->get_id();
        $sql = "UPDATE {$lp_table} SET name = '" . $this->name . "' WHERE id = '{$lp_id}'";
        if ($this->debug > 2) {
            error_log('New LP - lp updated with new name : ' . $this->name, 0);
        }
        //$res = Database::query($sql);
        $res = Database::query($sql, __FILE__, __LINE__);
        // if the lp is visible on the homepage, change his name there
        if (Database::affected_rows()) {
            $table = Database::get_course_table(TABLE_TOOL_LIST);
            $sql = 'UPDATE ' . $table . ' SET
									name = "' . $this->name . '"
								WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
            Database::query($sql, __FILE__, __LINE__);
        }
        return true;
    }
 /**
  * @param string $tool of the tool
  * @author Sebastien Piraux <*****@*****.**>
  * @desc Record information for access event for tools
  *
  *  $tool can take this values :
  *  Links, Calendar, Document, Announcements,
  *  Group, Video, Works, Users, Exercices, Course Desc
  *  ...
  *  Values can be added if new modules are created (15char max)
  *  I encourage to use $nameTool as $tool when calling this function
  *
  * 	Functionality for "what's new" notification is added by Toon Van Hoecke
  */
 public static function event_access_tool($tool)
 {
     if (empty($tool)) {
         return false;
     }
     $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
     //for "what's new" notification
     $TABLETRACK_LASTACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
     $_course = api_get_course_info();
     $courseId = api_get_course_int_id();
     $id_session = api_get_session_id();
     $tool = Database::escape_string($tool);
     $reallyNow = api_get_utc_datetime();
     $user_id = api_get_user_id();
     // record information
     // only if user comes from the course $_cid
     //if( eregi($_configuration['root_web'].$_cid,$_SERVER['HTTP_REFERER'] ) )
     //$pos = strpos($_SERVER['HTTP_REFERER'],$_configuration['root_web'].$_cid);
     $coursePath = isset($_course['path']) ? $_course['path'] : null;
     $pos = isset($_SERVER['HTTP_REFERER']) ? strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower(api_get_path(WEB_COURSE_PATH) . $coursePath)) : false;
     // added for "what's new" notification
     $pos2 = isset($_SERVER['HTTP_REFERER']) ? strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower(api_get_path(WEB_PATH) . "index")) : false;
     // end "what's new" notification
     if ($pos !== false || $pos2 !== false) {
         $sql = "INSERT INTO " . $TABLETRACK_ACCESS . "\n                        (access_user_id,\n                         c_id,\n                         access_tool,\n                         access_date,\n                         access_session_id\n                         )\n                    VALUES\n                        (" . $user_id . "," . "'" . $courseId . "' ,\n                        '" . $tool . "',\n                        '" . $reallyNow . "',\n                        '" . $id_session . "')";
         Database::query($sql);
     }
     // "what's new" notification
     $sql = "UPDATE {$TABLETRACK_LASTACCESS}\n                SET access_date = '{$reallyNow}'\n                WHERE access_user_id = " . $user_id . " AND c_id = '" . $courseId . "' AND access_tool = '" . $tool . "' AND access_session_id=" . $id_session;
     $result = Database::query($sql);
     if (Database::affected_rows($result) == 0) {
         $sql = "INSERT INTO {$TABLETRACK_LASTACCESS} (access_user_id, c_id, access_tool, access_date, access_session_id)\n                    VALUES (" . $user_id . ", '" . $courseId . "' , '{$tool}', '{$reallyNow}', {$id_session})";
         Database::query($sql);
     }
     return 1;
 }
 /**
  * Delete a glossary term (and re-order all the others)
  *
  * @param integer The id of the glossary term to delete
  * @return bool    True on success, false on failure
  * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
  * @version januari 2009, dokeos 1.8.6
  */
 public static function delete_glossary($glossary_id, $message = true)
 {
     // Database table definition
     $t_glossary = Database::get_course_table(TABLE_GLOSSARY);
     $course_id = api_get_course_int_id();
     if (empty($glossary_id)) {
         return false;
     }
     $sql = "DELETE FROM {$t_glossary} WHERE c_id = {$course_id} AND glossary_id='" . intval($glossary_id) . "'";
     $result = Database::query($sql);
     if ($result === false or Database::affected_rows($result) < 1) {
         return false;
     }
     //update item_property (delete)
     api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, intval($glossary_id), 'delete', api_get_user_id());
     // reorder the remaining terms
     GlossaryManager::reorder_glossary();
     Session::write('max_glossary_display', GlossaryManager::get_max_glossary_item());
     Display::display_confirmation_message(get_lang('TermDeleted'));
     return true;
 }
            $courseId = Database::escape_string($courseId);
            $sql_delete = "DELETE FROM {$tbl_session_rel_course_rel_user}\n\t\t\t\t\t\t\tWHERE id_user='******' AND c_id ='" . $courseId . "' AND id_session = {$id_session}";
            $result = Database::query($sql_delete);
            if (Database::affected_rows($result)) {
                //update session rel course table
                $sql_update = "UPDATE {$tbl_session_rel_course} SET nbr_users= nbr_users - 1 WHERE id_session='{$id_session}' AND c_id = '{$courseId}'";
                Database::query($sql_update);
            }
        }
    }
    foreach ($existingCourses as $existingCourse) {
        if (!in_array($existingCourse['id'], $CourseList)) {
            $courseId = Database::escape_string($existingCourse['id']);
            $sql_insert = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user}(id_session,c_id,id_user) VALUES('{$id_session}','{$courseId}','{$id_user}')";
            $result = Database::query($sql_insert);
            if (Database::affected_rows($result)) {
                //update session rel course table
                $sql_update = "UPDATE {$tbl_session_rel_course} SET nbr_users= nbr_users + 1 WHERE id_session='{$id_session}' AND c_id='{$courseId}'";
                Database::query($sql_update);
            }
        }
    }
    header('Location: session_course_user.php?id_session=' . $id_session . '&id_user='******'&msg=' . get_lang('CoursesUpdated'));
    exit;
}
// display the dokeos header
Display::display_header($tool_name);
if (!empty($_GET['msg'])) {
    Display::display_normal_message(urldecode($_GET['msg']));
}
// the form header