/** * Save profile tool list action value */ public function save() { $this->toolActionList; // delete all relation $sql = "DELETE FROM `" . $this->tbl['rel_profile_action'] . "`\n WHERE profile_id=" . $this->profile->id . "\n AND courseId = '' "; claro_sql_query($sql); // insert new relation foreach ($this->toolActionList as $toolId => $actionList) { foreach ($actionList as $actionName => $actionValue) { if ($actionValue == true) { $actionValue = 1; } else { $actionValue = 0; } $action = new RightToolAction(); $action->load($actionName, $toolId); $actionId = $action->getId(); $sql = "INSERT INTO `" . $this->tbl['rel_profile_action'] . "`\n SET profile_id = " . $this->profile->id . ",\n action_id = " . $actionId . ",\n value = " . $actionValue . ",\n courseId = '' "; claro_sql_query($sql); } } }
/** * Upgrade right (from main database) to 1.8 * @return step value, 0 if succeed */ function upgrade_main_database_right_to_18() { include_once $GLOBALS['includePath'] . '/lib/right/right_profile.lib.php'; include_once $GLOBALS['includePath'] . '/../install/init_profile_right.lib.php'; $tbl_mdb_names = claro_sql_get_main_tbl(); $tool = 'RIGHT_18'; switch ($step = get_upgrade_status($tool)) { case 1: // add right tables $sqlForUpdate[] = " CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_profile'] . "` (\n `profile_id` int(11) NOT NULL auto_increment,\n `type` enum('COURSE','PLATFORM') NOT NULL default 'COURSE',\n `name` varchar(255) NOT NULL default '',\n `label` varchar(50) NOT NULL default '',\n `description` varchar(255) default '',\n `courseManager` tinyint(4) default '0',\n `mailingList` tinyint(4) default '0',\n `userlistPublic` tinyint(4) default '0',\n `groupTutor` tinyint(4) default '0',\n `locked` tinyint(4) default '0',\n `required` tinyint(4) default '0',\n PRIMARY KEY (`profile_id`),\n KEY `type` (`type`)\n )ENGINE=MyISAM "; $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_action'] . "` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL default '',\n `description` varchar(255) default '',\n `tool_id` int(11) default NULL,\n `rank` int(11) default '0',\n `type` enum('COURSE','PLATFORM') NOT NULL default 'COURSE',\n PRIMARY KEY (`id`),\n KEY `tool_id` (`tool_id`),\n KEY `type` (`type`)\n )ENGINE=MyISAM "; $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_rel_profile_action'] . "` (\n `profile_id` int(11) NOT NULL,\n `action_id` int(11) NOT NULL,\n `courseId` varchar(40) NOT NULL default '',\n `value` tinyint(4) default '0',\n PRIMARY KEY (`profile_id`,`action_id`,`courseId`)\n ) ENGINE=MyISAM "; if (upgrade_apply_sql($sqlForUpdate)) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } unset($sqlForUpdate); case 2: create_required_profile(); $step = set_upgrade_status($tool, $step + 1); case 3: // Init action/right $sql = " SELECT id\n FROM `" . $tbl_mdb_names['tool'] . "`"; $result = claro_sql_query_fetch_all_cols($sql); $toolIdList = $result['id']; foreach ($toolIdList as $toolId) { // Manage right - Add read action $action = new RightToolAction(); $action->setName('read'); $action->setToolId($toolId); $action->save(); // Manage right - Add edit action $action = new RightToolAction(); $action->setName('edit'); $action->setToolId($toolId); $action->save(); } $step = set_upgrade_status($tool, $step + 1); case 4: init_default_right_profile(); $step = set_upgrade_status($tool, $step + 1); case 5: // set profile_id in rel course_user $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['rel_course_user'] . "` SET `profile_id` = " . claro_get_profile_id(USER_PROFILE) . "\n WHERE `isCourseManager` = 0"; $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['rel_course_user'] . "` SET `profile_id` = " . claro_get_profile_id(MANAGER_PROFILE) . "\n WHERE `isCourseManager` = 1"; // set default profile_id in course if (upgrade_apply_sql($sqlForUpdate)) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } unset($sqlForUpdate); default: $step = set_upgrade_status($tool, 0); return $step; } return false; }
/** * 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; } }
/** * Save profile tool list action value */ public function save() { // delete all relation $sql = "DELETE FROM `" . $this->tbl['rel_profile_action'] . "`\n WHERE profile_id=" . $this->profile->id . "\n AND courseId = '" . claro_sql_escape($this->courseId) . "'"; claro_sql_query($sql); // insert new relation foreach ($this->toolActionList as $toolId => $actionList) { // get difference between default and course $toolActionListDiff = array_diff_assoc($this->defaultToolActionList[$toolId], $actionList); if (!empty($toolActionListDiff)) { foreach ($actionList as $actionName => $actionValue) { if ($actionValue == true) { $actionValue = 1; } else { $actionValue = 0; } $action = new RightToolAction(); $action->load($actionName, $toolId); $actionId = $action->getId(); $sql = "INSERT INTO `" . $this->tbl['rel_profile_action'] . "`\n SET profile_id = " . $this->profile->id . ",\n action_id = " . $actionId . ",\n value = " . $actionValue . ",\n courseId = '" . claro_sql_escape($this->courseId) . "'"; claro_sql_query($sql); } } } }