/** * this function is store the modified resources * first we delete all the added resources in the database, * then we add all the resources from the session object. */ function update_added_resources($type, $id) { $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES); $course_id = api_get_course_int_id(); $id = intval($id); $type = Database::escape_string($type); // delete all the added resources for this item in the database; $sql="DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' AND source_id='$id'"; //echo $sql; Database::query($sql); // store the resources from the session into the database store_resources($type, $id); //delete_added_resource_($type, $id); unset_session_resources(); }
/** * this function is store the modified resources * first we delete all the added resources in the database, * then we add all the resources from the session object. */ function update_added_resources($type, $id) { global $_course; $course_id = api_get_course_int_id(); $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES); // delete all the added resources for this item in the database; $sql = "DELETE FROM {$TABLERESOURCE} WHERE c_id = {$course_id} AND source_type='{$type}' AND source_id='{$id}'"; //echo $sql; Database::query($sql); // Store the resources from the session into the database. store_resources($type, $id); //delete_added_resource_($type, $id); unset_session_resources(); }
/** * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters * @param array Course info * @param string Event title * @param string Event content/description * @param string Start date * @param string End date * @param array List of groups to which this event is added * @param int Parent id (optional) * @return int The new item's DB ID */ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to = array(), $parent_id = null, $file_comment = '') { $user_id = api_get_user_id(); // database table definitions $t_agenda = Database::get_course_table(TABLE_AGENDA); $item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); // some filtering of the input data $title = Database::escape_string($title); $content = Database::escape_string($content); $db_start_date = api_get_utc_datetime($db_start_date); $start_date = Database::escape_string($db_start_date); if (!empty($db_end_date)) { $db_end_date = api_get_utc_datetime($db_end_date); } $end_date = Database::escape_string($db_end_date); $id_session = api_get_session_id(); $course_id = api_get_course_int_id(); $group_id = api_get_group_id(); // check if exists in calendar_event table and if it is not deleted! $sql = "SELECT * FROM {$t_agenda} agenda, {$item_property} item_property\n \t\t\tWHERE\n \t\t\tagenda.c_id = {$course_id} AND\n \t\t\titem_property.c_id = {$course_id} AND\n \t\t\tagenda.title = '{$title}'\n \t\t\tAND agenda.content = '{$content}'\n \t\t\tAND agenda.start_date = '{$start_date}'\n \t\t\tAND agenda.end_date = '{$end_date}' " . (!empty($parent_id) ? "\n \t\t\tAND agenda.parent_event_id = '{$parent_id}'" : "") . "\n \t\t\tAND agenda.session_id = '{$id_session}'\n \t\t\tAND item_property.tool = '" . TOOL_CALENDAR_EVENT . "'\n \t\t\tAND item_property.ref = agenda.id\n \t\t\tAND item_property.visibility <> 2"; $result = Database::query($sql); $count = Database::num_rows($result); if ($count > 0) { return false; } $course_id = api_get_course_int_id(); $sql = "INSERT INTO " . $t_agenda . " (c_id, title,content, start_date, end_date" . (!empty($parent_id) ? ',parent_event_id' : '') . ", session_id)\n VALUES({$course_id}, '" . $title . "','" . $content . "', '" . $start_date . "','" . $end_date . "'" . (!empty($parent_id) ? ',' . (int) $parent_id : '') . ", '" . $id_session . "')"; Database::query($sql); $last_id = Database::insert_id(); // add a attachment file in agenda add_agenda_attachment_file($file_comment, $last_id); // store in last_tooledit (first the groups, then the users if (!empty($to)) { $send_to = separate_users_groups($to); // storing the selected groups if (is_array($send_to['groups'])) { foreach ($send_to['groups'] as $group) { api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group, 0, $start_date, $end_date); $done = true; } } // storing the selected users if (is_array($send_to['users'])) { foreach ($send_to['users'] as $user) { api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, $user, $start_date, $end_date); $done = true; } } if (isset($send_to['everyone']) && $send_to['everyone']) { api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, 0, $start_date, $end_date); } } // storing the resources if (!empty($_SESSION['source_type']) && !empty($last_id)) { store_resources($_SESSION['source_type'], $last_id); } return $last_id; }