protected function isModuleAllowed() { $moduleData = get_module_data($this->moduleLabel); if ($moduleData['type'] == 'tool') { $contextList = get_module_context_list($this->moduleLabel); if (claro_is_in_a_course()) { $_mainToolId = get_tool_id_from_module_label($this->moduleLabel); $_profileId = claro_get_current_user_profile_id_in_course(); $_cid = claro_get_current_course_id(); if (claro_is_in_a_group()) { $_groupProperties = claro_get_main_group_properties(claro_get_current_course_id()); $_mainToolId = get_tool_id_from_module_label('CLGRP'); $is_toolAllowed = array_key_exists($this->moduleLabel, $_groupProperties['tools']) && $_groupProperties['tools'][$this->moduleLabel] && claro_is_allowed_tool_read($_mainToolId, $_profileId, $_cid); if ($_groupProperties['private']) { $is_toolAllowed = $is_toolAllowed && (claro_is_group_member() || claro_is_group_tutor()); } $is_toolAllowed = $is_toolAllowed || (claro_is_course_manager() || claro_is_platform_admin()); } else { // we ignore course visibility if (!claro_is_allowed_tool_edit($_mainToolId, $_profileId, $_cid) && !claro_is_allowed_tool_read($_mainToolId, $_profileId, $_cid)) { $is_toolAllowed = false; } else { $is_toolAllowed = true; } } } else { if (in_array('platform', iterator_to_array($contextList))) { $is_toolAllowed = get_module_data($this->moduleLabel, 'activation') == 'activated'; } else { $is_toolAllowed = false; } } return $is_toolAllowed; } else { // if an applet "tool", return true if activated // and let module manage it's access by itself return $moduleData['activation'] == 'activated'; } }
$is_groupAllowed = !empty($_SESSION['is_groupAllowed']) ? $_SESSION['is_groupAllowed'] : null; } /*--------------------------------------------------------------------------- COURSE TOOL / USER / GROUP REL. INIT ---------------------------------------------------------------------------*/ if ($uidReset || $cidReset || $gidReset || $tidReset) { if ($_tid && $_gid) { //echo 'passed here'; $toolLabel = trim($_courseTool['label'], '_'); $is_toolAllowed = array_key_exists($toolLabel, $_groupProperties['tools']) && $_groupProperties['tools'][$toolLabel] && claro_is_allowed_tool_read(get_tool_id_from_module_label('CLGRP'), $_profileId, $_cid); if ($_groupProperties['private']) { $is_toolAllowed = $is_toolAllowed && ($is_groupMember || claro_is_group_tutor()); } $is_toolAllowed = $is_toolAllowed || ($is_courseAdmin || $is_platformAdmin); } elseif ($_tid) { if (!$_courseTool['visibility'] && !claro_is_allowed_tool_edit($_mainToolId, $_profileId, $_cid) || !claro_is_allowed_tool_read($_mainToolId, $_profileId, $_cid)) { $is_toolAllowed = false; } else { $is_toolAllowed = true; } } else { $is_toolAllowed = false; } } else { $is_toolAllowed = !empty($_SESSION['is_toolAllowed']) ? $_SESSION['is_toolAllowed'] : null; } /*--------------------------------------------------------------------------- Course tool list initialisation for current user ---------------------------------------------------------------------------*/ if ($uidReset || $cidReset) { if ($_cid) {
/** * Return the tool list for a course according a certain access level. * * @param string $courseIdReq - the requested course id * @param int $profileIdReq - the requested profile id * @param boolean $force (optionnal) - reset the result cache, default is false * @param boolean $active (optionnal) - get the list of active tool only if set * to true (default behaviour) * @param mixed $courseActive (optional) - set to true (default behaviour) to get * only activated course tools, set to false to get all course tools * * @return array the courses list */ function claro_get_course_tool_list($courseIdReq, $profileIdReq, $force = false, $active = true, $courseActive = true) { static $courseToolList = null, $courseId = null, $profileId = null; if (is_null($courseToolList) || $courseId != $courseIdReq || $profileId != $profileIdReq || $force) { $courseId = $courseIdReq; $profileId = $profileIdReq; $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_tool_list = $tbl_mdb_names['tool']; $tbl_module = $tbl_mdb_names['module']; $tbl_cdb_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($courseIdReq)); $tbl_course_tool_list = $tbl_cdb_names['tool']; /* * Search all the tool corresponding to this access levels */ // find module or claroline existing tools $sql = "SELECT DISTINCT ctl.id AS id,\n pct.id AS tool_id,\n pct.claro_label AS label,\n ctl.script_name AS external_name,\n ctl.visibility AS visibility,\n IFNULL(pct.icon,'tool.png') AS icon,\n ISNULL(ctl.tool_id) AS external,\n m.activation ,\n m.name AS name,\n ctl.activated AS activated,\n ctl.installed AS installed,\n IFNULL( ctl.script_url ,\n pct.script_url ) AS url\n FROM `" . $tbl_course_tool_list . "` AS ctl,\n `" . $tbl_module . "` AS m,\n `" . $tbl_tool_list . "` AS pct\n\n WHERE pct.id = ctl.tool_id\n AND pct.claro_label = m.label\n " . ($active ? " AND m.activation = 'activated' " : "") . "\n " . ($courseActive ? " AND ctl.activated = 'true' " : "") . "\n ORDER BY external, pct.def_rank, ctl.rank"; $courseToolList = claro_sql_query_fetch_all($sql); // right profile management $size = count($courseToolList); for ($i = 0; $i < $size; $i++) { $toolId = $courseToolList[$i]['tool_id']; $visibility = (bool) $courseToolList[$i]['visibility']; // delete tool from course tool list if : // 1. tool is invisible and profile has no right to edit tool // 2. profile has no right to view tool if ($visibility == false && !claro_is_allowed_tool_edit($toolId, $profileId, $courseId) || !claro_is_allowed_tool_read($toolId, $profileId, $courseId)) { unset($courseToolList[$i]); } } // find external url added by teacher $sql = "SELECT DISTINCT ctl.id AS id,\n NULL AS tool_id,\n NULL AS label,\n ctl.script_name AS external_name,\n ctl.visibility AS visibility,\n 'tool.png' AS icon,\n ISNULL(ctl.tool_id) AS external,\n NULL AS name,\n ctl.script_url AS url\n\n FROM `" . $tbl_course_tool_list . "` AS ctl\n WHERE ISNULL(ctl.tool_id) "; if (!get_init('is_courseAdmin')) { $sql .= 'AND ctl.visibility = 1'; } $result = claro_sql_query_fetch_all($sql); $courseToolList = array_merge($courseToolList, $result); } return $courseToolList; }