/** * @brief Process resource actions * @global type $tool_content * @global type $id * @global type $langResourceCourseUnitDeleted * @global type $langResourceUnitModified * @global type $course_id * @global type $course_code * @return string */ function process_actions() { global $tool_content, $id, $langResourceCourseUnitDeleted, $langResourceUnitModified, $course_id, $course_code, $webDir; // update index and refresh course metadata require_once 'modules/search/indexer.class.php'; require_once 'modules/course_metadata/CourseXML.php'; if (isset($_REQUEST['edit'])) { $res_id = intval($_GET['edit']); if ($id = check_admin_unit_resource($res_id)) { return edit_res($res_id); } } elseif (isset($_REQUEST['edit_res_submit'])) { // edit resource $res_id = intval($_REQUEST['resource_id']); if ($id = check_admin_unit_resource($res_id)) { @($restitle = $_REQUEST['restitle']); $rescomments = purify($_REQUEST['rescomments']); $result = Database::get()->query("UPDATE course_weekly_view_activities SET\n title = ?s,\n comments = ?s\n WHERE course_weekly_view_id = ?d AND id = ?d", $restitle, $rescomments, $id, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); } $tool_content .= "<div class='alert alert-success'>{$langResourceUnitModified}</div>"; } elseif (isset($_REQUEST['del'])) { // delete resource from course unit $res_id = intval($_GET['del']); if ($id = check_admin_unit_resource($res_id)) { Database::get()->query("DELETE FROM course_weekly_view_activities WHERE id = ?d", $res_id); Indexer::queueAsync(Indexer::REQUEST_REMOVE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); $tool_content .= "<div class='alert alert-success'>{$langResourceCourseUnitDeleted}</div>"; } } elseif (isset($_REQUEST['vis'])) { // modify visibility in text resources only $res_id = intval($_REQUEST['vis']); if ($id = check_admin_unit_resource($res_id)) { $vis = Database::get()->querySingle("SELECT `visible` FROM course_weekly_view_activities WHERE id = ?d", $res_id)->visible; $newvis = $vis == 1 ? 0 : 1; Database::get()->query("UPDATE course_weekly_view_activities SET visible = '{$newvis}' WHERE id = ?d", $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); } } elseif (isset($_REQUEST['down'])) { // change order down $res_id = intval($_REQUEST['down']); if ($id = check_admin_unit_resource($res_id)) { move_order('course_weekly_view_activities', 'id', $res_id, 'order', 'down', "course_weekly_view_id={$id}"); } } elseif (isset($_REQUEST['up'])) { // change order up $res_id = intval($_REQUEST['up']); if ($id = check_admin_unit_resource($res_id)) { move_order('course_weekly_view_activities', 'id', $res_id, 'order', 'up', "course_weekly_view_id={$id}"); } } return ''; }
/** * Refresh the hierarchy nodes (departments) that a course belongs to. All previous belonging * nodes get deleted and then refreshed with the ones given as array arguments. * * @param int $id - Id for a given course * @param array $departments - Array containing the node ids that the given course should belong to */ public function refresh($id, $departments) { if ($departments != null) { Database::get()->query("DELETE FROM {$this->departmenttable} WHERE course = ?d", $id); foreach (array_unique($departments) as $key => $department) { Database::get()->query("INSERT INTO {$this->departmenttable} (course, department) VALUES (?d,?d)", $id, $department); } } // refresh index global $webDir; // required for indexer require_once 'modules/search/indexer.class.php'; Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $id); // refresh course metadata require_once 'modules/course_metadata/CourseXML.php'; CourseXMLElement::refreshCourse($id, course_id_to_code($id)); }
/** * @brief insert ebook in database * @global type $course_id * @global type $course_code * @param type $id */ function insert_ebook($id) { global $course_id, $course_code; $order = Database::get()->querySingle("SELECT MAX(`order`) AS maxorder FROM unit_resources WHERE unit_id = ?d", $id)->maxorder; foreach (array('ebook', 'section', 'subsection') as $type) { if (isset($_POST[$type]) and count($_POST[$type]) > 0) { foreach ($_POST[$type] as $ebook_id) { $order++; $q = Database::get()->query("INSERT INTO unit_resources SET unit_id = ?d, type = '$type', title = ?s, comments = '', visible=1, `order` = ?d, `date` = " . DBHelper::timeAfter() . ",res_id = ?d", $id, $_POST[$type . '_title'][$ebook_id], $order, $ebook_id); $uresId = $q->lastInsertID; Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNITRESOURCE, $uresId); } } } Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); header('Location: index.php?course=' . $course_code . '&id=' . $id); exit; }
if (($id = check_admin_unit_resource($res_id))) { Database::get()->query("DELETE FROM course_weekly_view_activities WHERE id = ?d", $res_id); Indexer::queueAsync(Indexer::REQUEST_REMOVE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); $tool_content .= "<div class='alert alert-success'>$langResourceCourseUnitDeleted</div>"; } } } elseif (isset($_REQUEST['vis'])) { // modify visibility $id = intval(getDirectReference($_REQUEST['vis'])); $vis = Database::get()->querySingle("SELECT `visible` FROM course_units WHERE id = ?d", $id)->visible; $newvis = ($vis == 1) ? 0 : 1; Database::get()->query("UPDATE course_units SET visible = ?d WHERE id = ?d AND course_id = ?d", $newvis, $id, $course_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNIT, $id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); } elseif (isset($_REQUEST['access'])) { if ($course_viewType == 'weekly') { $id = intval(getDirectReference($_REQUEST['access'])); $access = Database::get()->querySingle("SELECT `public` FROM course_weekly_view WHERE id = ?d", $id); $newaccess = ($access->public == '1') ? '0' : '1'; Database::get()->query("UPDATE course_weekly_view SET public = ?d WHERE id = ?d AND course_id = ?d", $newaccess, $id, $course_id); } else { $id = intval(getDirectReference($_REQUEST['access'])); $access = Database::get()->querySingle("SELECT `public` FROM course_units WHERE id = ?d", $id); $newaccess = ($access->public == '1') ? '0' : '1'; Database::get()->query("UPDATE course_units SET public = ?d WHERE id = ?d AND course_id = ?d", $newaccess, $id, $course_id); } } elseif (isset($_REQUEST['down'])) { $id = intval(getDirectReference($_REQUEST['down'])); // change order down if ($course_info->view_type == 'units' or $course_info->view_type == 'simple') {
function updateCourseDescription($cdId, $title, $comments, $type) { global $course_id, $course_code; $type = (isset($type)) ? intval($type) : null; if ($cdId !== null) { Database::get()->query("UPDATE course_description SET title = ?s, comments = ?s, type = ?d, update_dt = NOW() WHERE id = ?d", $title, $comments, $type, intval($cdId)); } else { $res = Database::get()->querySingle("SELECT MAX(`order`) AS max FROM course_description WHERE course_id = ?d", $course_id); $maxorder = ($res->max !== false) ? intval($res->max) + 1 : 1; Database::get()->query("INSERT INTO course_description SET course_id = ?d, title = ?s, comments = ?s, type = ?d, `order` = ?d, update_dt = NOW()", $course_id, $title, purify($comments), $type, $maxorder); } CourseXMLElement::refreshCourse($course_id, $course_code); }
/** * * @global type $langCourseUnitModified * @global type $langCourseUnitAdded * @global null $maxorder * @global type $course_id * @global type $course_code * @global type $webDir * @return type */ function handle_unit_info_edit() { global $langCourseUnitModified, $langCourseUnitAdded, $maxorder, $course_id, $course_code, $webDir; require_once 'modules/tags/moduleElement.class.php'; $title = $_REQUEST['unittitle']; $descr = $_REQUEST['unitdescr']; if (isset($_REQUEST['unit_id'])) { // update course unit $unit_id = $_REQUEST['unit_id']; Database::get()->query("UPDATE course_units SET\n title = ?s,\n comments = ?s\n WHERE id = ?d AND course_id = ?d", $title, $descr, $unit_id, $course_id); // tags if (isset($_POST['tags'])) { $tagsArray = explode(',', $_POST['tags']); $moduleTag = new ModuleElement($unit_id); $moduleTag->syncTags($tagsArray); } $successmsg = $langCourseUnitModified; } else { // add new course unit $order = $maxorder + 1; $q = Database::get()->query("INSERT INTO course_units SET\n title = ?s, comments = ?s, visible = 1,\n `order` = ?d, course_id = ?d", $title, $descr, $order, $course_id); $successmsg = $langCourseUnitAdded; $unit_id = $q->lastInsertID; // tags if (isset($_POST['tags'])) { $tagsArray = explode(',', $_POST['tags']); $moduleTag = new ModuleElement($unit_id); $moduleTag->attachTags($tagsArray); } } // update index require_once 'modules/search/indexer.class.php'; Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNIT, $unit_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); // refresh course metadata require_once 'modules/course_metadata/CourseXML.php'; CourseXMLElement::refreshCourse($course_id, $course_code); Session::Messages($successmsg, 'alert-success'); redirect_to_home_page("modules/units/index.php?course={$course_code}&id={$unit_id}"); }
/** * * @global type $langCourseUnitModified * @global type $langCourseUnitAdded * @global null $maxorder * @global type $course_id * @global type $course_code * @global type $webDir * @return type */ function handle_unit_info_edit() { global $langCourseUnitModified, $langCourseUnitAdded, $maxorder, $course_id, $course_code, $webDir; $title = $_REQUEST['unittitle']; $descr = $_REQUEST['unitdescr']; if (isset($_REQUEST['unit_id'])) { // update course unit $unit_id = $_REQUEST['unit_id']; Database::get()->query("UPDATE course_units SET\n title = ?s,\n comments = ?s\n WHERE id = ?d AND course_id = ?d", $title, $descr, $unit_id, $course_id); $successmsg = $langCourseUnitModified; } else { // add new course unit $order = $maxorder + 1; $q = Database::get()->query("INSERT INTO course_units SET\n title = ?s, comments = ?s, visible = 1,\n `order` = ?d, course_id = ?d", $title, $descr, $order, $course_id); $successmsg = $langCourseUnitAdded; $unit_id = $q->lastInsertID; } // update index require_once 'modules/search/indexer.class.php'; Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNIT, $unit_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); // refresh course metadata require_once 'modules/course_metadata/CourseXML.php'; CourseXMLElement::refreshCourse($course_id, $course_code); return "<div class='alert alert-success'>{$successmsg}</div>"; }
/** * @brief Process resource actions * @global type $tool_content * @global type $id * @global type $langResourceCourseUnitDeleted * @global type $langResourceUnitModified * @global type $course_id * @global type $course_code * @return string */ function process_actions() { global $tool_content, $id, $langResourceCourseUnitDeleted, $langResourceUnitModified, $course_id, $course_code, $webDir, $cnt, $langBack, $urlAppend, $head_content; // update index and refresh course metadata require_once 'modules/search/indexer.class.php'; require_once 'modules/course_metadata/CourseXML.php'; if (isset($_REQUEST['edit'])) { $res_id = intval($_GET['edit']); if ($id = check_admin_unit_resource($res_id)) { $tool_content .= action_bar(array( array( 'title' => $langBack, 'url' => "{$urlAppend}modules/weeks/index.php?course=$course_code&id=$id&cnt=$cnt", 'icon' => 'fa-reply', 'level' => 'primary-label'))); $tool_content .= edit_res($res_id); draw($tool_content, 2, null, $head_content); exit; } } elseif (isset($_REQUEST['edit_res_submit'])) { // edit resource $res_id = intval($_REQUEST['resource_id']); if ($id = check_admin_unit_resource($res_id)) { @$restitle = $_REQUEST['restitle']; $rescomments = purify($_REQUEST['rescomments']); $result = Database::get()->query("UPDATE course_weekly_view_activities SET title = ?s, comments = ?s WHERE course_weekly_view_id = ?d AND id = ?d", $restitle, $rescomments, $id, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); redirect_to_home_page("modules/weeks/index.php?course=$course_code&id=$id&cnt=$cnt"); } $tool_content .= "<div class='alert alert-success'>$langResourceUnitModified</div>"; } elseif (isset($_REQUEST['del'])) { // delete resource from course unit $res_id = intval($_GET['del']); if ($id = check_admin_unit_resource($res_id)) { Database::get()->query("DELETE FROM course_weekly_view_activities WHERE id = ?d", $res_id); Indexer::queueAsync(Indexer::REQUEST_REMOVE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); Session::Messages($langResourceCourseUnitDeleted, 'alert-success'); redirect_to_home_page("modules/weeks/index.php?course=$course_code&id=$id&cnt=$cnt"); } } elseif (isset($_REQUEST['vis'])) { // modify visibility in text resources only $res_id = intval($_REQUEST['vis']); if ($id = check_admin_unit_resource($res_id)) { $vis = Database::get()->querySingle("SELECT `visible` FROM course_weekly_view_activities WHERE id = ?d", $res_id)->visible; $newvis = ($vis == 1) ? 0 : 1; Database::get()->query("UPDATE course_weekly_view_activities SET visible = '$newvis' WHERE id = ?d", $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNITRESOURCE, $res_id); Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id); CourseXMLElement::refreshCourse($course_id, $course_code); redirect_to_home_page("modules/weeks/index.php?course=$course_code&id=$id&cnt=$cnt"); } } elseif (isset($_REQUEST['down'])) { // change order down $res_id = intval($_REQUEST['down']); if ($id = check_admin_unit_resource($res_id)) { move_order('course_weekly_view_activities', 'id', $res_id, 'order', 'down', "course_weekly_view_id=$id"); redirect_to_home_page("modules/weeks/index.php?course=$course_code&id=$id&cnt=$cnt"); } } elseif (isset($_REQUEST['up'])) { // change order up $res_id = intval($_REQUEST['up']); if ($id = check_admin_unit_resource($res_id)) { move_order('course_weekly_view_activities', 'id', $res_id, 'order', 'up', "course_weekly_view_id=$id"); redirect_to_home_page("modules/weeks/index.php?course=$course_code&id=$id&cnt=$cnt"); } } return ''; }
/** * @brief upgrade to 2.10 * @global type $langUpgCourse * @param type $code * @param type $course_id * @param type $extramessage */ function upgrade_course_2_10($code, $course_id) { global $langUpgCourse; Database::get()->query("USE `$code`"); Database::get()->query("ALTER TABLE `dropbox_file` CHANGE `description` `description` TEXT"); // refresh XML metadata require_once "modules/course_metadata/CourseXML.php"; if (file_exists(CourseXMLConfig::getCourseXMLPath($code))) { CourseXMLElement::refreshCourse($course_id, $code, true); } if (!DBHelper::fieldExists('poll', 'description', $code)) { Database::get()->query('ALTER TABLE poll ADD description MEDIUMTEXT NOT NULL, ADD end_message MEDIUMTEXT NOT NULL, ADD anonymized INT(1) NOT NULL DEFAULT 0'); Database::get()->query('ALTER TABLE poll_question CHANGE qtype qtype tinyint(3) UNSIGNED NOT NULL'); } }