/** * create a new category definition for the user information * * @param string $title - category title * @param string $comment - title comment * @param int $nbline - lines number for the field the user will fill. * @return boolean TRUE if succeed, else boolean FALSE */ function claro_user_info_create_cat_def($title = '', $comment = '', $nbline = '5', $course_id = NULL) { $tbl_cdb_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($course_id)); $tbl_userinfo_def = $tbl_cdb_names['userinfo_def']; if (0 == (int) $nbline || empty($title)) { return FALSE; } $sql = "SELECT MAX(`rank`) maxRank\n FROM `" . $tbl_userinfo_def . "`"; $result = claro_sql_query($sql); if ($result) { $maxRank = mysql_fetch_array($result); } $maxRank = $maxRank['maxRank']; $thisRank = $maxRank + 1; $title = trim($title); $comment = trim($comment); $sql = "INSERT INTO `" . $tbl_userinfo_def . "` SET\n `title` = '" . claro_sql_escape($title) . "',\n `comment` = '" . claro_sql_escape($comment) . "',\n `nbline` = " . (int) $nbline . ",\n `rank` = " . (int) $thisRank; return claro_sql_query_insert_id($sql); }
/** * save object in db * * @author Sebastien Piraux <*****@*****.**> * @return boolean result of operation */ public function save() { if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblAnswer . "`\n SET `questionId` = " . (int) $this->questionId . ",\n `trueFeedback` = '" . claro_sql_escape($this->trueFeedback) . "',\n `trueGrade` = '" . claro_sql_escape($this->trueGrade) . "',\n `falseFeedback` = '" . claro_sql_escape($this->falseFeedback) . "',\n `falseGrade` = '" . claro_sql_escape($this->falseGrade) . "',\n `correctAnswer` = '" . claro_sql_escape($this->correctAnswer) . "'"; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; return $this->id; } else { return false; } } else { // update $sql = "UPDATE `" . $this->tblAnswer . "`\n SET `trueFeedback` = '" . claro_sql_escape($this->trueFeedback) . "',\n `trueGrade` = '" . claro_sql_escape($this->trueGrade) . "',\n `falseFeedback` = '" . claro_sql_escape($this->falseFeedback) . "',\n `falseGrade` = '" . claro_sql_escape($this->falseGrade) . "',\n `correctAnswer` = '" . claro_sql_escape($this->correctAnswer) . "'\n WHERE `id` = " . (int) $this->id; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }
/** * Create a new group * * @param string $groupName - name of the group * @param integer $maxMember - max user allowed for this group * @return integer : id of the new group * * @copyright (c) 2001-2011, Universite catholique de Louvain (UCL) */ function create_group($prefixGroupName, $maxMember) { require_once dirname(__FILE__) . '/forum.lib.php'; require_once dirname(__FILE__) . '/fileManage.lib.php'; $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_groups = $tbl_cdb_names['group_team']; // Check name of group $sql = "SELECT name FROM `" . $tbl_groups . "` WHERE name LIKE '" . claro_sql_escape($prefixGroupName) . "%'"; $existingGroupList = claro_sql_query_fetch_all_cols($sql); $existingGroupList = $existingGroupList['name']; $i = 1; do { $groupName = $prefixGroupName . str_pad($i, 4, ' ', STR_PAD_LEFT); $i++; if ($i - 2 > count($existingGroupList)) { die($groupName . 'infiniteloop'); } } while (in_array($groupName, $existingGroupList)); /** * Create a directory allowing group student to upload documents */ // Create a Unique ID path preventing other enter $globalPath = $GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/'; do { $groupRepository = str_replace(' ', '_', substr(uniqid(substr($groupName, 0, 19) . ' ', ''), 0, 30)); } while (check_name_exist($globalPath . $groupRepository)); claro_mkdir($globalPath . $groupRepository, CLARO_FILE_PERMISSIONS); /* * Insert a new group in the course group table and keep its ID */ $sql = "INSERT INTO `" . $tbl_groups . "`\n SET name = '" . $groupName . "',\n `maxStudent` = " . (is_null($maxMember) ? 'NULL' : "'" . (int) $maxMember . "'") . ",\n secretDirectory = '" . claro_sql_escape($groupRepository) . "'"; $createdGroupId = claro_sql_query_insert_id($sql); /* * Create a forum for the group in the forum table */ if (is_tool_activated_in_course(get_tool_id_from_module_label('CLFRM'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLFRM')) { create_forum($groupName . ' - ' . strtolower(get_lang('Forum')), '', 2, (int) GROUP_FORUMS_CATEGORY, '', $createdGroupId); } if (is_tool_activated_in_course(get_tool_id_from_module_label('CLWIKI'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLWIKI')) { require_once get_module_path('CLWIKI') . '/lib/lib.createwiki.php'; create_wiki($createdGroupId, $groupName . ' - Wiki'); } return $createdGroupId; }
/** * save assignment to DB * * @author Sebastien Piraux <*****@*****.**> * @return mixed false or id of the record */ public function save() { // TODO method to validate data if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblAssignment . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `def_submission_visibility` = '" . claro_sql_escape($this->defaultSubmissionVisibility) . "',\n `assignment_type` = '" . claro_sql_escape($this->assignmentType) . "',\n `authorized_content` = '" . claro_sql_escape($this->submissionType) . "',\n `allow_late_upload` = '" . claro_sql_escape($this->allowLateUpload) . "',\n `start_date` = FROM_UNIXTIME('" . claro_sql_escape($this->startDate) . "'),\n `end_date` = FROM_UNIXTIME('" . claro_sql_escape($this->endDate) . "'),\n `prefill_text` = '" . claro_sql_escape($this->autoFeedbackText) . "',\n `prefill_doc_path` = '" . claro_sql_escape($this->autoFeedbackFilename) . "',\n `prefill_submit` = '" . claro_sql_escape($this->autoFeedbackSubmitMethod) . "'"; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; $this->buildDirPaths(); // create the assignment directory if query was successfull and dir not already exists if (!is_dir($this->assigDirSys)) { claro_mkdir($this->assigDirSys, CLARO_FILE_PERMISSIONS, true); } return $this->id; } else { return false; } } else { if ($this->applyVisibilityChangeToOldSubmissions) { // get current assignment defaultSubmissionVisibility $sqlGetOldData = "SELECT `def_submission_visibility`\n FROM `" . $this->tblAssignment . "`\n WHERE `id` = '" . $this->id . "'"; $prevDefaultSubmissionVisibility = claro_sql_query_get_single_value($sqlGetOldData); // change visibility of all works only if defaultSubmissionVisibility has changed if ($this->_forceVisibilityChange || $this->defaultSubmissionVisibility != $prevDefaultSubmissionVisibility) { $this->updateAllSubmissionsVisibility($this->defaultSubmissionVisibility, true); } } // update, main query $sql = "UPDATE `" . $this->tblAssignment . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `def_submission_visibility` = '" . claro_sql_escape($this->defaultSubmissionVisibility) . "',\n `assignment_type` = '" . claro_sql_escape($this->assignmentType) . "',\n `authorized_content` = '" . claro_sql_escape($this->submissionType) . "',\n `allow_late_upload` = '" . claro_sql_escape($this->allowLateUpload) . "',\n `start_date` = FROM_UNIXTIME('" . claro_sql_escape($this->startDate) . "'),\n `end_date` = FROM_UNIXTIME('" . claro_sql_escape($this->endDate) . "'),\n `prefill_text` = '" . claro_sql_escape($this->autoFeedbackText) . "',\n `prefill_doc_path` = '" . claro_sql_escape($this->autoFeedbackFilename) . "',\n `prefill_submit` = '" . claro_sql_escape($this->autoFeedbackSubmitMethod) . "'\n WHERE `id` = '" . $this->id . "'"; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }
/** * add an new event in the given or current course * * @param string $title title of the new item * @param string $content content of the new item * @param date $time publication dat of the item def:now * @param string $courseCode sysCode of the course (leaveblank for current course) * @author Christophe Gesche <*****@*****.**> * @return id of the new item * @since 1.7 */ function agenda_add_item($title = '', $content = '', $day = null, $hour = null, $lasting = '', $speakers = '', $location = '', $visibility = 'SHOW', $courseCode = null) { $tbl_c_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($courseCode)); $tbl_calendar_event = $tbl_c_names['calendar_event']; if (is_null($day)) { $day = date('Y-m-d'); } if (is_null($hour)) { $hour = date('H:i:s'); } $speakers = !empty($speakers) ? "'" . claro_sql_escape($speakers) . "'" : "null"; $sql = "INSERT INTO `" . $tbl_calendar_event . "`\n SET\n titre = '" . claro_sql_escape(trim($title)) . "',\n contenu = '" . claro_sql_escape(trim($content)) . "',\n day = '" . $day . "',\n hour = '" . $hour . "',\n visibility = '" . ($visibility == 'HIDE' ? 'HIDE' : 'SHOW') . "',\n lasting = '" . claro_sql_escape(trim($lasting)) . "',\n speakers = " . $speakers . ",\n location = '" . claro_sql_escape(trim($location)) . "',\n group_id = " . (int) claro_get_current_group_id(); return claro_sql_query_insert_id($sql); }
/** * save object in db * * @author Sebastien Piraux <*****@*****.**> * @return boolean result of operation */ public function save() { $sqlGradeList = implode(',', $this->gradeList); $sqlWrongAnswerList = implode(',', $this->wrongAnswerList); if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblAnswer . "`\n SET `questionId` = " . (int) $this->questionId . ",\n `answer` = '" . claro_sql_escape($this->answerText) . "',\n `gradeList` = '" . claro_sql_escape($sqlGradeList) . "',\n `wrongAnswerList` = '" . claro_sql_escape($sqlWrongAnswerList) . "',\n `type` = " . (int) $this->type; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; return $this->id; } else { return false; } } else { // update $sql = "UPDATE `" . $this->tblAnswer . "`\n SET `answer` = '" . claro_sql_escape($this->answerText) . "',\n `gradeList` = '" . claro_sql_escape($sqlGradeList) . "',\n `wrongAnswerList` = '" . claro_sql_escape($sqlWrongAnswerList) . "',\n `type` = " . (int) $this->type . "\n WHERE `id` = " . (int) $this->id; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }
/** * Add a new tool in course_tool table * * @param string claro_label * @param string script_url * @param string icon * @param string default_access * @param string add_in_course * @param string access_manager * * @return boolean */ function register_tool_in_main_database($claro_label, $script_url, $icon, $default_access = 'ALL', $add_in_course = 'AUTOMATIC', $access_manager = 'COURSE_ADMIN') { $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_tool = $tbl_mdb_names['tool']; $sql = "SELECT `id`\n FROM `" . $tbl_tool . "`\n WHERE `claro_label` = '" . claro_sql_escape($claro_label) . "'"; $result = upgrade_sql_query($sql); if (mysql_num_rows($result) == 0) { // tool not registered // find max default rank $sql = "SELECT MAX(def_rank)\n FROM `" . $tbl_tool . "`"; $default_rank = claro_sql_query_get_single_value($sql); $default_rank++; // add tool in course_tool table $sql = "INSERT INTO `" . $tbl_tool . "`\n (`claro_label`,`script_url`,`icon`,`def_access`,`def_rank`,`add_in_course`,`access_manager`)\n VALUES\n ('" . claro_sql_escape($claro_label) . "','" . claro_sql_escape($script_url) . "','" . claro_sql_escape($icon) . "',\n '" . claro_sql_escape($default_access) . "','" . claro_sql_escape($default_rank) . "',\n '" . claro_sql_escape($add_in_course) . "','" . claro_sql_escape($access_manager) . "')"; return claro_sql_query_insert_id($sql); } else { return FALSE; } }
/** * Record result of user when an exercice was done * @param exerciseTrackId id in qwz_tracking table * @param questionId id of the question * @param values array with user answers * @param questionResult result of this question * * @author Sebastien Piraux <*****@*****.**> */ function track_exercise_details($exerciseTrackId, $questionId, $values, $questionResult) { // get table names $tblList = get_module_course_tbl(array('qwz_tracking_questions', 'qwz_tracking_answers'), claro_get_current_course_id()); $tbl_qwz_tracking_questions = $tblList['qwz_tracking_questions']; $tbl_qwz_tracking_answers = $tblList['qwz_tracking_answers']; // add the answer tracking informations $sql = "INSERT INTO `" . $tbl_qwz_tracking_questions . "`\n SET `exercise_track_id` = " . (int) $exerciseTrackId . ",\n `question_id` = '" . (int) $questionId . "',\n `result` = '" . (double) $questionResult . "'"; $details_id = claro_sql_query_insert_id($sql); // check if previous query succeed to add answers if ($details_id && is_array($values)) { // add, if needed, the different answers of the user // one line by answer // each entry of $values should be correctly formatted depending on the question type foreach ($values as $answer) { $sql = "INSERT INTO `" . $tbl_qwz_tracking_answers . "`\n SET `details_id` = " . (int) $details_id . ",\n `answer` = '" . claro_sql_escape($answer) . "'"; claro_sql_query($sql); } } return 1; }
$sql = "SELECT `id`, `title`\n FROM `" . $tbl_quiz_exercise . "`"; $exerciseList = claro_sql_query_fetch_all($sql); // for each exercise checked, try to add it to the learning path. foreach ($exerciseList as $exercise) { if (isset($_REQUEST['insertExercise']) && isset($_REQUEST['check_' . $exercise['id']])) { // check if a module of this course already used the same exercise $sql = "SELECT M.`module_id`\n FROM `" . $TABLEMODULE . "` AS M, `" . $TABLEASSET . "` AS A\n WHERE A.`module_id` = M.`module_id`\n AND A.`path` LIKE '" . (int) $exercise['id'] . "'\n AND M.`contentType` = '" . CTEXERCISE_ . "'"; $existingModule = claro_sql_query_get_single_row($sql); // no module exists using this exercise if (!$existingModule) { // create new module $sql = "INSERT INTO `" . $TABLEMODULE . "`\n (`name` , `comment`, `contentType`, `launch_data`)\n VALUES ('" . claro_sql_escape($exercise['title']) . "' , '" . claro_sql_escape(get_block('blockDefaultModuleComment')) . "', '" . CTEXERCISE_ . "', '')"; $moduleId = claro_sql_query_insert_id($sql); // create new asset $sql = "INSERT INTO `" . $TABLEASSET . "`\n (`path` , `module_id` , `comment`)\n VALUES ('" . (int) $exercise['id'] . "', " . (int) $moduleId . " , '')"; $assetId = claro_sql_query_insert_id($sql); // update start asset id in module $sql = "UPDATE `" . $TABLEMODULE . "`\n SET `startAsset_id` = " . (int) $assetId . "\n WHERE `module_id` = " . (int) $moduleId; claro_sql_query($sql); // determine the default order of this Learning path $sql = "SELECT MAX(`rank`)\n FROM `" . $TABLELEARNPATHMODULE . "`"; $orderMax = claro_sql_query_get_single_value($sql); $order = $orderMax + 1; // finally : insert in learning path $sql = "INSERT INTO `" . $TABLELEARNPATHMODULE . "`\n (`learnPath_id`, `module_id`, `specificComment`, `rank`, `lock`)\n VALUES ('" . (int) $_SESSION['path_id'] . "', '" . (int) $moduleId . "','" . claro_sql_escape(get_block('blockDefaultModuleAddedComment')) . "', " . $order . ",'OPEN')"; claro_sql_query($sql); $msgList['info'][] = get_lang("%moduleName has been added as module", array('%moduleName' => $exercise['title'])) . '<br />' . "\n"; } else { // check if this is this LP that used this exercise as a module $sql = "SELECT COUNT(*)\n FROM `" . $TABLELEARNPATHMODULE . "` AS LPM,\n `" . $TABLEMODULE . "` AS M,\n `" . $TABLEASSET . "` AS A\n WHERE M.`module_id` = LPM.`module_id`\n AND M.`startAsset_id` = A.`asset_id`\n AND A.`path` = " . (int) $exercise['id'] . "\n AND LPM.`learnPath_id` = " . (int) $_SESSION['path_id']; $num = claro_sql_query_get_single_value($sql);
/** * insert a new description to DB * * @return mixed false or id of the record * @author Sebastien Piraux <*****@*****.**> */ public function insert() { // insert $sql = "INSERT INTO `" . $this->tblCourseDescription . "`\n SET `category` = " . $this->getCategory() . ",\n `title` = '" . claro_sql_escape($this->getTitle()) . "',\n `content` = '" . claro_sql_escape($this->getContent()) . "',\n `lastEditDate` = NOW(),\n `visibility` = '" . claro_sql_escape($this->getVisibility()) . "'"; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->setId($insertedId); return $this->getId(); } else { return false; } }
/** * Create a new forum (set of threads) * * @param string $forum_name * @param string $forum_desc * @param boolean $forum_post_allowed * @param integer $cat_id * @param integer $group_id default null(current) * @param string $course_id default null(current) * * @return integer id of new forum; * */ function create_forum($forum_name, $forum_desc, $forum_post_allowed, $cat_id, $anonymity_type = 'forbidden', $group_id = null, $course_id = NULL) { $tbl_cdb_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($course_id)); $tbl_forum_forums = $tbl_cdb_names['bb_forums']; // find order in the category we have to give to the newly created forum $sql = "SELECT MAX(`forum_order`)\n FROM `" . $tbl_forum_forums . "`\n WHERE cat_id = " . (int) $cat_id; $result = claro_sql_query($sql); list($orderMax) = mysql_fetch_row($result); $order = $orderMax + 1; //temporary fix for 1.9 releases : avoids change in database definition (using unused 'forum_type' field) //TODO : use a specific enum field (field name: anonymity) in bb_forum table switch ($anonymity_type) { case 'forbidden': $forum_type = 0; break; case 'allowed': $forum_type = 1; break; case 'default': $forum_type = 2; break; default: $forum_type = 0; break; } // add new forum in DB $sql = "INSERT INTO `" . $tbl_forum_forums . "`\n SET forum_name = '" . claro_sql_escape($forum_name) . "',\n group_id = " . (is_null($group_id) ? "NULL" : (int) $group_id) . ",\n forum_desc = '" . claro_sql_escape($forum_desc) . "',\n forum_access = " . ($forum_post_allowed ? 2 : 0) . ",\n forum_moderator = 1,\n cat_id = " . (int) $cat_id . ",\n forum_type = " . (int) $forum_type . ",\n forum_order = " . (int) $order; return claro_sql_query_insert_id($sql); }
} else { $introCmd = false; } $intro_exDel = false; /*========================================================= INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) ========================================================*/ if ($intro_editAllowed) { /* Replace command */ if ($introCmd == 'exAdd') { // DETERMINE THE ORDER OF THE NEW ANNOUNCEMENT $sql = "SELECT (MAX(rank) + 1) AS nextRank\n FROM `" . $TBL_INTRODUCTION . "`"; $nextRank = claro_sql_query_get_single_value($sql); $intro_content = trim($_REQUEST['intro_content']); $sql = "INSERT INTO `" . $TBL_INTRODUCTION . "`\n SET content = '" . claro_sql_escape($intro_content) . "',\n rank = " . (int) $nextRank; $introId = claro_sql_query_insert_id($sql); if ($introId) { $currentLocator = ResourceLinker::$Navigator->getCurrentLocator(array('id' => (int) $introId)); $resourceList = isset($_REQUEST['resourceList']) ? $_REQUEST['resourceList'] : array(); ResourceLinker::updateLinkList($currentLocator, $resourceList); } } if ($introCmd == 'exEd') { $intro_content = trim($_REQUEST['intro_content']); $introId = $_REQUEST['introId']; if (!empty($intro_content)) { $sql = "UPDATE `" . $TBL_INTRODUCTION . "`\n SET `content` = '" . claro_sql_escape($intro_content) . "'\n WHERE `id` = " . (int) $introId; if (claro_sql_query($sql) != false) { $currentLocator = ResourceLinker::$Navigator->getCurrentLocator(array('id' => (int) $introId)); $resourceList = isset($_REQUEST['resourceList']) ? $_REQUEST['resourceList'] : array(); ResourceLinker::updateLinkList($currentLocator, $resourceList);
public function save() { // TODO method to validate data if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblSubmission . "`\n SET `assignment_id` = '" . claro_sql_escape($this->assignmentId) . "',\n `user_id` = " . (is_null($this->userId) ? 'NULL' : $this->userId) . ",\n `group_id` = " . (is_null($this->groupId) ? 'NULL' : $this->groupId) . ",\n `title` = '" . claro_sql_escape($this->title) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `creation_date` = NOW(),\n `last_edit_date` = NOW(),\n `authors` = '" . claro_sql_escape($this->author) . "',\n `submitted_text` = '" . claro_sql_escape($this->submittedText) . "',\n `submitted_doc_path` = '" . claro_sql_escape($this->submittedFilename) . "',\n `parent_id` = " . (is_null($this->parentId) ? 'NULL' : $this->parentId) . ",\n `original_id` = " . (is_null($this->originalId) ? 'NULL' : $this->originalId) . ",\n `private_feedback` = '" . claro_sql_escape($this->privateFeedback) . "',\n `score` = " . (is_null($this->score) ? 'NULL' : $this->score); // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; return $this->id; } else { return false; } } else { // update $sql = "UPDATE `" . $this->tblSubmission . "`\n SET `assignment_id` = '" . claro_sql_escape($this->assignmentId) . "',\n `user_id` = " . (is_null($this->userId) ? 'NULL' : $this->userId) . ",\n `group_id` = " . (is_null($this->groupId) ? 'NULL' : $this->groupId) . ",\n `title` = '" . claro_sql_escape($this->title) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `last_edit_date` = NOW(),\n `authors` = '" . claro_sql_escape($this->author) . "',\n `submitted_text` = '" . claro_sql_escape($this->submittedText) . "',\n `submitted_doc_path` = '" . claro_sql_escape($this->submittedFilename) . "',\n `parent_id` = " . (is_null($this->parentId) ? 'NULL' : $this->parentId) . ",\n `original_id` = " . (is_null($this->originalId) ? 'NULL' : $this->originalId) . ",\n `private_feedback` = '" . claro_sql_escape($this->privateFeedback) . "',\n `score` = " . (is_null($this->score) ? 'NULL' : $this->score) . "\n WHERE `id` = '" . $this->id . "'"; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }
/** * Upgrade module (from main database) to 1.8 * @return step value, 0 if succeed */ function upgrade_main_database_module_to_18() { $tbl_mdb_names = claro_sql_get_main_tbl(); $tool = 'MODULE_18'; switch ($step = get_upgrade_status($tool)) { case 1: // module $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['module'] . "` (\n `id` smallint unsigned NOT NULL auto_increment,\n `label` char(8) NOT NULL default '',\n `name` char(100) NOT NULL default '',\n `activation` enum('activated','desactivated') NOT NULL default 'desactivated',\n `type` enum('tool','applet') NOT NULL default 'applet',\n `script_url` char(255) NOT NULL default 'entry.php',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM"; $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['module_info'] . "` (\n id smallint NOT NULL auto_increment,\n module_id smallint NOT NULL default '0',\n version varchar(10) NOT NULL default '',\n author varchar(50) default NULL,\n author_email varchar(100) default NULL,\n author_website varchar(255) default NULL,\n description varchar(255) default NULL,\n website varchar(255) default NULL,\n license varchar(50) default NULL,\n PRIMARY KEY (id)\n ) ENGINE=MyISAM AUTO_INCREMENT=0"; $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['dock'] . "` (\n id smallint unsigned NOT NULL auto_increment,\n module_id smallint unsigned NOT NULL default '0',\n name varchar(50) NOT NULL default '',\n rank tinyint unsigned NOT NULL default '0',\n PRIMARY KEY (id)\n ) ENGINE=MyISAM AUTO_INCREMENT=0"; if (upgrade_apply_sql($sqlForUpdate)) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } unset($sqlForUpdate); case 3: $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "`\n SET claro_label = TRIM(TRAILING '_' FROM claro_label )"; $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "`\n SET `script_url` = SUBSTRING_INDEX( `script_url` , '/', -1 ) "; $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "`\n SET `script_url` = 'exercise.php' WHERE `script_url` = 'exercice.php' "; if (upgrade_apply_sql($sqlForUpdate)) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } unset($sqlForUpdate); case 4: // include libray to manage module require_once $GLOBALS['includePath'] . '/lib/module/manage.lib.php'; $error = false; $sql = " SELECT id, claro_label, script_url, icon, def_access, def_rank, add_in_course, access_manager\n FROM `" . $tbl_mdb_names['tool'] . "`"; $toolList = claro_sql_query_fetch_all($sql); foreach ($toolList as $tool) { $toolLabel = $tool['claro_label']; // get module path, for read module manifest $toolPath = get_module_path($toolLabel); if (($toolInfo = readModuleManifest($toolPath)) !== false) { // get script url if (isset($toolInfo['ENTRY'])) { $script_url = $toolInfo['ENTRY']; } else { $script_url = 'entry.php'; } } else { // init toolInfo $toolInfo['LABEL'] = $tool['claro_label']; $toolInfo['NAME'] = $tool['claro_label']; $toolInfo['TYPE'] = 'tool'; $toolInfo['VERSION'] = '1.8'; $toolInfo['AUTHOR']['NAME'] = ''; $toolInfo['AUTHOR']['EMAIL'] = ''; $toolInfo['AUTHOR']['WEB'] = ''; $toolInfo['DESCRIPTION'] = ''; $toolInfo['LICENSE'] = 'unknown'; $script_url = $tool['script_url']; } // fill table module and module_info // code from register_module_core from inc/lib/module.manage.lib.php $sql = "INSERT INTO `" . $tbl_mdb_names['module'] . "`\n SET label = '" . claro_sql_escape($toolInfo['LABEL']) . "',\n name = '" . claro_sql_escape($toolInfo['NAME']) . "',\n type = '" . claro_sql_escape($toolInfo['TYPE']) . "',\n activation = 'activated' ,\n script_url = '" . claro_sql_escape($script_url) . "'"; $moduleId = claro_sql_query_insert_id($sql); $sql = "INSERT INTO `" . $tbl_mdb_names['module_info'] . "`\n SET module_id = " . (int) $moduleId . ",\n version = '" . claro_sql_escape($toolInfo['VERSION']) . "',\n author = '" . claro_sql_escape($toolInfo['AUTHOR']['NAME']) . "',\n author_email = '" . claro_sql_escape($toolInfo['AUTHOR']['EMAIL']) . "',\n website = '" . claro_sql_escape($toolInfo['AUTHOR']['WEB']) . "',\n description = '" . claro_sql_escape($toolInfo['DESCRIPTION']) . "',\n license = '" . claro_sql_escape($toolInfo['LICENSE']) . "'"; if (upgrade_sql_query($sql) === false) { $error = true; break; } } if (!$error) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } default: $step = set_upgrade_status($tool, 0); return $step; } return false; }
/** * Add a new user * * @param $settingList array to fill the form * @param $creatorId id of account creator * (null means created by owner) * default null * * @author Mathieu Laurent <*****@*****.**> */ function user_create($settingList, $creatorId = null) { $requiredSettingList = array('lastname', 'firstname', 'username', 'password', 'language', 'email', 'officialCode', 'phone', 'isCourseCreator', 'isPlatformAdmin'); // Set non compulsory fields if (!isset($settingList['language'])) { $settingList['language'] = ''; } if (!isset($settingList['phone'])) { $settingList['phone'] = ''; } if (!isset($settingList['isCourseCreator'])) { $settingList['isCourseCreator'] = false; } if (!isset($settingList['officialEmail'])) { $settingList['officialEmail'] = false; } if (!isset($settingList['isPlatformAdmin'])) { $settingList['isPlatformAdmin'] = false; } // Verify required fields foreach ($requiredSettingList as $thisRequiredSetting) { if (array_key_exists($thisRequiredSetting, $settingList)) { continue; } else { return trigger_error('MISSING_DATA : ', E_USER_ERROR); } } // Check if the username is available if (!is_username_available($settingList['username'])) { return false; } $password = get_conf('userPasswordCrypted') ? md5($settingList['password']) : $settingList['password']; $tbl = claro_sql_get_main_tbl(); $sql = "INSERT INTO `" . $tbl['user'] . "`\n SET nom = '" . claro_sql_escape($settingList['lastname']) . "',\n prenom = '" . claro_sql_escape($settingList['firstname']) . "',\n username = '******'username']) . "',\n language = '" . claro_sql_escape($settingList['language']) . "',\n email = '" . claro_sql_escape($settingList['email']) . "',\n officialCode = '" . claro_sql_escape($settingList['officialCode']) . "',\n officialEmail = '" . claro_sql_escape($settingList['officialEmail']) . "',\n phoneNumber = '" . claro_sql_escape($settingList['phone']) . "',\n password = '******',\n isCourseCreator = " . (int) $settingList['isCourseCreator'] . ",\n isPlatformAdmin = " . (int) $settingList['isPlatformAdmin'] . ",\n creatorId = " . ($creatorId > 0 ? (int) $creatorId : 'NULL'); $adminId = claro_sql_query_insert_id($sql); if (false !== $adminId) { return $adminId; } else { return claro_failure::set_failure('Cant create user|' . mysql_error() . '|'); } }
/** * save profile to DB * * @return mixed false or id of the profile */ public function save() { if ($this->id == 0) { // insert $sql = "INSERT INTO `" . $this->tbl['profile'] . "`\n SET `name` = '" . claro_sql_escape($this->name) . "',\n `label` = '" . claro_sql_escape($this->label) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `type` = '" . claro_sql_escape($this->type) . "',\n `courseManager` = " . (int) $this->isCourseManager . ",\n `mailingList` = " . (int) $this->isEmailNotify . ",\n `userlistPublic` = " . (int) $this->isUserPublic . ",\n `groupTutor` = " . (int) $this->isTutor . ",\n `locked` = " . (int) $this->isLocked . ",\n `required` = " . (int) $this->isRequired . ""; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; return $this->id; } else { return false; } } else { // update, main query $sql = "UPDATE `" . $this->tbl['profile'] . "`\n SET `name` = '" . claro_sql_escape($this->name) . "',\n `label` = '" . claro_sql_escape($this->label) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `type` = '" . claro_sql_escape($this->type) . "',\n `courseManager` = " . (int) $this->isCourseManager . ",\n `mailingList` = " . (int) $this->isEmailNotify . ",\n `userlistPublic` = " . (int) $this->isUserPublic . ",\n `groupTutor` = " . (int) $this->isTutor . ",\n `locked` = " . (int) $this->isLocked . ",\n `required` = " . (int) $this->isRequired . "\n WHERE `profile_id` = '" . (int) $this->id . "'"; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }
/** * * * @author Fragile <*****@*****.**> * @access private */ function _addNode($node, $values = "") { if (strlen($values) > 0) { $values .= ","; } $sql = "INSERT INTO `" . $this->table . "`\n SET " . $values . "`" . $this->leftCol . "` = " . $node['left'] . ",\n `" . $this->rightCol . "` = " . $node['right'] . ",\n `" . $this->deepCol . "` = " . $node['deep']; // handle multiple trees allowed in same table if (!empty($this->treeCol)) { $sql .= ", `" . $this->treeCol . "` = " . $node['tree']; } // insert node and return inserted id return claro_sql_query_insert_id($sql); }
case "create": // create form sent if (isset($_POST["newPathName"]) && $_POST["newPathName"] != "") { // check if name already exists $sql = "SELECT `name`\n FROM `" . $TABLELEARNPATH . "`\n WHERE `name` = '" . claro_sql_escape($_POST['newPathName']) . "'"; $query = claro_sql_query($sql); $num = mysql_num_rows($query); if ($num == 0) { // determine the default order of this Learning path $result = claro_sql_query("SELECT MAX(`rank`)\n FROM `" . $TABLELEARNPATH . "`"); list($orderMax) = mysql_fetch_row($result); $order = $orderMax + 1; // create new learning path $sql = "INSERT\n INTO `" . $TABLELEARNPATH . "`\n (`name`, `comment`, `rank`)\n VALUES ('" . claro_sql_escape($_POST['newPathName']) . "','" . claro_sql_escape(trim($_POST['newComment'])) . "'," . (int) $order . ")"; //echo $sql; $lp_id = claro_sql_query_insert_id($sql); // notify the creation to eventmanager $eventNotifier->notifyCourseEvent("learningpath_created", claro_get_current_course_id(), claro_get_current_tool_id(), $lp_id, claro_get_current_group_id(), "0"); } else { // display error message $dialogBox->error(get_lang('Error : Name already exists in the learning path or in the module pool')); } } else { $dialogBox->form("\n\n" . '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">' . "\n" . '<fieldset>' . claro_form_relay_context() . '<h4>' . get_lang('Create a new learning path') . '</h4>' . "\n" . '<dl>' . '<dt><label for="newPathName">' . get_lang('Title') . '</label></dt>' . "\n" . '<dd><input type="text" name="newPathName" id="newPathName" maxlength="255" /></dd>' . "\n" . '<dt><label for="newComment">' . get_lang('Comment') . '</label></dt>' . "\n" . '<dd>' . claro_html_textarea_editor('newComment', '', 15, 55) . '</dd>' . '</dl>' . "\n" . '</fieldset>' . "\n" . '<input type="hidden" name="cmd" value="create" />' . "\n" . '<input type="submit" value="' . get_lang('Ok') . '" /> ' . "\n" . claro_html_button('learningPathList.php', get_lang('Cancel')) . '</form>' . "\n"); } break; } // IF ORDER COMMAND RECEIVED // CHANGE ORDER if (isset($sortDirection) && $sortDirection) { $sql = "SELECT `learnPath_id`, `rank`\n FROM `" . $TABLELEARNPATH . "`\n ORDER BY `rank` {$sortDirection}";
/** * Register installed course tool in course database * @author Frederic Minne <*****@*****.**> */ function update_course_tool_list($courseDbName) { $toolList = get_course_installable_tool_list(); $courseDbName = get_conf('courseTablePrefix') . $courseDbName . get_conf('dbGlu'); $tbl_cdb_names = claro_sql_get_course_tbl($courseDbName); $tbl_courseToolList = $tbl_cdb_names['tool']; foreach ($toolList as $courseTool) { $sql_insert = " INSERT INTO `" . $tbl_courseToolList . "` " . " (tool_id, rank, visibility, activated, installed) " . " VALUES ('" . $courseTool['id'] . "'," . "'" . $courseTool['def_rank'] . "'," . "'" . ($courseTool['def_access'] == 'ALL' ? 1 : 0) . "'," . "'" . ($courseTool['add_in_course'] == 'AUTOMATIC' ? 'true' : 'false') . "'," . "'" . ($courseTool['add_in_course'] == 'AUTOMATIC' ? 'true' : 'false') . "' )"; claro_sql_query_insert_id($sql_insert); } }
/** * save category to DB * * @return mixed false or id of the record */ public function save() { // TODO method to validate data if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblQuestionCategory . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "'"; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->setId($insertedId); return true; } else { return false; } } else { // update, main query $sql = "UPDATE `" . $this->tblQuestionCategory . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "'\n WHERE `id` = '" . $this->id . "'"; // execute and return main query if (claro_sql_query($sql)) { return true; } else { return false; } } }
<?php // $Id: course_install.php 13708 2011-10-19 10:46:34Z abourguignon $ // vim: expandtab sw=4 ts=4 sts=4: if (count(get_included_files()) == 1) { die('---'); } ############################## EXERCISES ####################################### $moduleWorkingDirectory = get_path('coursesRepositorySys') . $courseDirectory . '/exercise'; if (!claro_mkdir($moduleWorkingDirectory, CLARO_FILE_PERMISSIONS, true)) { return claro_failure::set_failure(get_lang('Unable to create folder %folder', array('%folder' => $moduleWorkingDirectory))); } if (get_conf('fill_course_example', true)) { // Exercise $TABLEQWZEXERCISE = $moduleCourseTblList['qwz_exercise']; $TABLEQWZQUESTION = $moduleCourseTblList['qwz_question']; $TABLEQWZRELEXERCISEQUESTION = $moduleCourseTblList['qwz_rel_exercise_question']; $TABLEQWZANSWERMULTIPLECHOICE = $moduleCourseTblList['qwz_answer_multiple_choice']; // create question $questionId = claro_sql_query_insert_id("INSERT INTO `" . $TABLEQWZQUESTION . "` (`title`, `description`, `attachment`, `type`, `grade`)\n VALUES\n ('" . claro_sql_escape(get_lang('sampleQuizQuestionTitle')) . "', '" . claro_sql_escape(get_lang('sampleQuizQuestionText')) . "', '', 'MCMA', '10' )"); claro_sql_query("INSERT INTO `" . $TABLEQWZANSWERMULTIPLECHOICE . "`(`questionId`,`answer`,`correct`,`grade`,`comment`)\n VALUES\n ('" . $questionId . "','" . claro_sql_escape(get_lang('sampleQuizAnswer1')) . "','0','-5','" . claro_sql_escape(get_lang('sampleQuizAnswer1Comment')) . "'),\n ('" . $questionId . "','" . claro_sql_escape(get_lang('sampleQuizAnswer2')) . "','0','-5','" . claro_sql_escape(get_lang('sampleQuizAnswer2Comment')) . "'),\n ('" . $questionId . "','" . claro_sql_escape(get_lang('sampleQuizAnswer3')) . "','1','5','" . claro_sql_escape(get_lang('sampleQuizAnswer3Comment')) . "'),\n ('" . $questionId . "','" . claro_sql_escape(get_lang('sampleQuizAnswer4')) . "','1','5','" . claro_sql_escape(get_lang('sampleQuizAnswer4Comment')) . "')"); // create exercise $exerciseId = claro_sql_query_insert_id("INSERT INTO `" . $TABLEQWZEXERCISE . "` (`title`, `description`, `visibility`, `startDate`, `endDate`, `quizEndMessage`)\n VALUES\n ('" . claro_sql_escape(get_lang('sampleQuizTitle')) . "', '" . claro_sql_escape(get_lang('sampleQuizDescription')) . "', 'INVISIBLE', NOW(), DATE_ADD(NOW(), INTERVAL 1 YEAR), '' )"); // put question in exercise claro_sql_query("INSERT INTO `" . $TABLEQWZRELEXERCISEQUESTION . "` VALUES ({$exerciseId}, {$questionId}, 1)"); }
/** * Store all unique info about a tool during install * @param integer $moduleId * @param array $moduleToolData, data from manifest * @return int tool id or false */ function register_module_tool($moduleId, $module_info) { $tbl = claro_sql_get_tbl('course_tool'); if (is_array($module_info)) { $icon = array_key_exists('ICON', $module_info) ? "'" . claro_sql_escape($module_info['ICON']) . "'" : 'NULL'; if (!isset($module_info['ENTRY'])) { $module_info['ENTRY'] = 'entry.php'; } // find max rank in the course_tool table $sql = "SELECT MAX(def_rank) AS maxrank FROM `" . $tbl['course_tool'] . "`"; $maxresult = claro_sql_query_get_single_row($sql); // insert the new course tool $sql = "INSERT INTO `" . $tbl['course_tool'] . "`\n SET\n claro_label = '" . claro_sql_escape($module_info['LABEL']) . "',\n script_url = '" . claro_sql_escape($module_info['ENTRY']) . "',\n icon = " . $icon . ",\n def_access = 'ALL',\n def_rank = (" . (int) $maxresult['maxrank'] . "+1),\n add_in_course = 'AUTOMATIC',\n access_manager = 'COURSE_ADMIN' "; $tool_id = claro_sql_query_insert_id($sql); // Init action/right // Manage right - Add read action $action = new RightToolAction(); $action->setName('read'); $action->setToolId($tool_id); $action->save(); // Manage right - Add edit action $action = new RightToolAction(); $action->setName('edit'); $action->setToolId($tool_id); $action->save(); // Init all profile/right $profileList = array_keys(claro_get_all_profile_name_list()); foreach ($profileList as $profileId) { $profile = new RightProfile(); $profile->load($profileId); $profileRight = new RightProfileToolRight(); $profileRight->load($profile); if (claro_get_profile_id('manager') == $profileId) { $profileRight->setToolRight($tool_id, 'manager'); } else { $profileRight->setToolRight($tool_id, 'user'); } $profileRight->save(); } return $tool_id; } else { return false; } }
/** * Add a new announcement in the given or current course. * * @param string $title title of the new item * @param string $content content of the new item * @param date $visibleFrom * @param date $visibleUntil * @param bool visibility * @param date $time publication date of the item def:now * @param string $course_id sysCode of the course (leaveblank for current course) * @return id of the new item * @since 1.7 * @todo convert to param date timestamp */ function announcement_add_item($title = '', $content = '', $visible_from = null, $visible_until = null, $visibility = null, $time = null, $course_id = null) { $tbl = claro_sql_get_course_tbl(claro_get_course_db_name_glued($course_id)); $sqlTime = is_null($time) ? $sqlTime = "NOW()" : "FROM_UNIXTIME('" . (int) $time . "')"; // Determine the position of the new announcement $sql = "SELECT (MAX(ordre) + 1) AS nextRank\n FROM `" . $tbl['announcement'] . "`"; $nextRank = claro_sql_query_get_single_value($sql); $visibility = $visibility == 1 ? "SHOW" : "HIDE"; $visible_from = !is_null($visible_from) ? "'" . claro_sql_escape($visible_from) . "'" : "NULL"; $visible_until = !is_null($visible_until) ? "'" . claro_sql_escape($visible_until) . "'" : "NULL"; // Insert announcement $sql = "INSERT INTO `" . $tbl['announcement'] . "`\n SET title = '" . claro_sql_escape(trim($title)) . "',\n contenu = '" . claro_sql_escape(trim($content)) . "',\n temps = " . $sqlTime . ",\n visibleFrom = " . $visible_from . ",\n visibleUntil = " . $visible_until . ",\n ordre = '" . (int) $nextRank . "',\n visibility = '" . $visibility . "'"; return claro_sql_query_insert_id($sql); }
/** * save exercise to DB * * @author Sebastien Piraux <*****@*****.**> * @return mixed false or id of the record */ public function save() { // TODO method to validate data if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblExercise . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `displayType` = '" . claro_sql_escape($this->displayType) . "',\n `shuffle` = " . (int) $this->shuffle . ",\n `useSameShuffle` = '" . (int) $this->useSameShuffle . "',\n `showAnswers` = '" . claro_sql_escape($this->showAnswers) . "',\n `startDate` = FROM_UNIXTIME(" . claro_sql_escape($this->startDate) . "),\n `endDate` = " . (is_null($this->endDate) ? "'0000-00-00 00:00:00'" : "FROM_UNIXTIME(" . claro_sql_escape($this->endDate) . ")") . ",\n `timeLimit` = " . (int) $this->timeLimit . ",\n `attempts` = " . (int) $this->attempts . ",\n `anonymousAttempts` = '" . claro_sql_escape($this->anonymousAttempts) . "',\n `quizEndMessage` = '" . claro_sql_escape($this->quizEndMessage) . "'"; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; return $this->id; } else { return false; } } else { // update, main query $sql = "UPDATE `" . $this->tblExercise . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `displayType` = '" . claro_sql_escape($this->displayType) . "',\n `shuffle` = " . (int) $this->shuffle . ",\n `useSameShuffle` = '" . (int) $this->useSameShuffle . "',\n `showAnswers` = '" . claro_sql_escape($this->showAnswers) . "',\n `startDate` = FROM_UNIXTIME('" . claro_sql_escape($this->startDate) . "'),\n `endDate` = " . (is_null($this->endDate) ? "'0000-00-00 00:00:00'" : "FROM_UNIXTIME(" . claro_sql_escape($this->endDate) . ")") . ",\n `timeLimit` = " . (int) $this->timeLimit . ",\n `attempts` = " . (int) $this->attempts . ",\n `anonymousAttempts` = '" . claro_sql_escape($this->anonymousAttempts) . "',\n `quizEndMessage` = '" . claro_sql_escape($this->quizEndMessage) . "'\n WHERE `id` = '" . $this->id . "'"; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }