Exemplo n.º 1
0
    $sql = " SELECT pct.id                    AS toolId       ,\n                  pct.claro_label           AS label\n\n            FROM `" . $_course['dbNameGlu'] . "tool_list` AS ctl\n            INNER JOIN `" . $tbl_tool . "` AS pct\n            ON `ctl`.`tool_id` = `pct`.`id`\n            WHERE ctl.installed = 'true'";
    $courseToolList = claro_sql_query_fetch_all_rows($sql);
    $tmp = array();
    foreach ($courseToolList as $thisCourseTool) {
        $tmp[$thisCourseTool['label']] = $thisCourseTool['toolId'];
    }
    // 3. compare the two lists and register and install/activate missing tool if necessary
    $listOfToolsToAdd = array();
    foreach ($mainCourseToolList as $thisToolId => $thisMainCourseTool) {
        if (!array_key_exists($thisMainCourseTool['label'], $tmp)) {
            $listOfToolsToAdd[$thisMainCourseTool['label']] = $thisToolId;
        }
    }
    foreach ($listOfToolsToAdd as $toolLabel => $toolId) {
        if (!is_module_registered_in_course($toolId, $_cid)) {
            register_module_in_single_course($toolId, $_cid);
        }
        if (!is_module_installed_in_course($toolLabel, $_cid) && 'AUTOMATIC' == get_module_data($toolLabel, 'add_in_course')) {
            install_module_in_course($toolLabel, $_cid);
        }
        if ('AUTOMATIC' == get_module_data($toolLabel, 'add_in_course')) {
            if ('activated' == get_module_data($toolLabel, 'activation')) {
                update_course_tool_activation_in_course($toolId, $_cid, true);
                set_module_visibility_in_course($toolId, $_cid, true);
            }
        }
    }
}
/*---------------------------------------------------------------------------
  Course / tool relation initialisation
 ---------------------------------------------------------------------------*/
Exemplo n.º 2
0
        } else {
            $dialogBox->error(get_lang('Not a valid tool'));
        }
    }
}
if ('exAddTool' == $cmd) {
    if (is_null($toolLabel)) {
        $dialogBox->error(get_lang('Missing tool label'));
    } else {
        $moduleData = get_module_data($toolLabel);
        if ($moduleData['access_manager'] == 'COURSE_ADMIN' || claro_is_platform_admin()) {
            // get tool id
            $toolId = get_tool_id_from_module_label($toolLabel);
            if ($toolId) {
                if (!is_module_registered_in_course($toolId, claro_get_current_course_id())) {
                    register_module_in_single_course($toolId, claro_get_current_course_id());
                }
                // update course_tool.activated
                if (update_course_tool_activation_in_course($toolId, claro_get_current_course_id(), true)) {
                    set_module_visibility_in_course($toolId, $_cid, true);
                    $dialogBox->success(get_lang('Tool added to course'));
                    $cidReset = TRUE;
                    $cidReq = claro_get_current_course_id();
                    $groupToolList = get_group_tool_label_list();
                    foreach ($groupToolList as $group) {
                        if ($group['label'] == $toolLabel) {
                            // this is a group tool, enable it in groups
                            activate_module_in_groups(Claroline::getDatabase(), $toolLabel, claro_get_current_course_id());
                        }
                    }
                    include get_path('incRepositorySys') . '/claro_init_local.inc.php';
Exemplo n.º 3
0
/**
 * Change the activation status for the given tool in the given course
 * @param int $toolId main tool id
 * @param string $courseId
 * @param boolean $activated
 * @return boolean
 */
function update_course_tool_activation_in_course($toolId, $courseId, $activated)
{
    if ($activated && !course_tool_already_installed($toolId, $courseId)) {
        $tLabel = get_module_label_from_tool_id($toolId);
        if ($tLabel) {
            if (!is_tool_registered_in_course($toolId, $courseId)) {
                register_module_in_single_course($toolId, $courseId);
            }
            install_module_in_course($tLabel, $courseId);
            update_tool_installation_in_course($toolId, $courseId);
        }
    }
    $sql_activated = $activated ? "'true'" : "'false'";
    $tbl_cdb_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($courseId));
    $tblCourseToolList = $tbl_cdb_names['tool'];
    $sql = "UPDATE `{$tblCourseToolList}`\n" . "SET `activated` = " . $sql_activated . "\n" . "WHERE tool_id = " . (int) $toolId;
    if (claro_sql_query($sql)) {
        return claro_sql_affected_rows();
    } else {
        false;
    }
}
Exemplo n.º 4
0
function chat_upgrade_to_19($course_code)
{
    global $currentCourseVersion;
    $versionRequiredToProceed = '/^1.8/';
    $tool = 'CLCHT';
    $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
    if (preg_match($versionRequiredToProceed, $currentCourseVersion)) {
        $coursePath = get_path('coursesRepositorySys') . claro_get_course_path($course_code);
        $courseChatPath = $coursePath . '/chat/';
        $toolId = get_tool_id_from_module_label('CLCHAT');
        if (!$toolId) {
            // get out of here if new chat module is missing
            log_message('New Chat module not found : keep the old one !');
            $step = set_upgrade_status($tool, 0, $course_code);
            return $step;
        }
        // On init , $step = 1
        switch ($step = get_upgrade_status($tool, $course_code)) {
            case 1:
                // get all chat files
                log_message("Search in " . $courseChatPath);
                if (!file_exists($courseChatPath)) {
                    log_message("Cannot save chat : folder {$courseChatPath} does not exists");
                    $error = true;
                } else {
                    try {
                        $it = new DirectoryIterator($courseChatPath);
                        $error = false;
                        foreach ($it as $file) {
                            if (!$file->isFile()) {
                                continue;
                            }
                            if ($file->getFilename() == $course_code . '.chat.html') {
                                // chat de cours
                                log_message("Try to export course chat : " . $file->getFilename());
                                $exportFileDir = $coursePath . '/document/recovered_chat/';
                                $groupId = null;
                            } else {
                                // group chat
                                log_message("Try to export group chat : " . $file->getFilename());
                                // get groupId
                                $matches = array();
                                preg_match('/\\w+\\.(\\d+)\\.chat\\.html/', $file->getFilename(), $matches);
                                if (isset($matches[1])) {
                                    $groupId = (int) $matches[1];
                                } else {
                                    log_message('Cannot find group id in chat filename : ' . $file->getFilename());
                                    break;
                                }
                                if (!($groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $course_code, CLARO_CONTEXT_GROUP => $groupId)))) {
                                    // group cannot be found, save in document
                                    $exportFileDir = $coursePath . '/document/recovered_chat/';
                                    log_message('Cannot find group so save chat filename in course : ' . $file->getFilename());
                                } else {
                                    $exportFileDir = $coursePath . '/group/' . $groupData['directory'] . '/recovered_chat/';
                                }
                            }
                            // create dire
                            claro_mkdir($exportFileDir, CLARO_FILE_PERMISSIONS, true);
                            // try to find a unique filename
                            $fileNamePrefix = 'chat.' . date('Y-m-j') . '_';
                            if (!is_null($groupId)) {
                                $fileNamePrefix .= $groupId . '_';
                            }
                            $i = 1;
                            while (file_exists($exportFileDir . $fileNamePrefix . $i . '.html')) {
                                $i++;
                            }
                            $savedFileName = $fileNamePrefix . $i . '.html';
                            // prepare output
                            $out = '<html>' . '<head>' . '<title>Discussion - archive</title>' . '</head>' . '<body>' . file_get_contents($file->getPathname()) . '</body>' . '</html>';
                            // write to file
                            if (!file_put_contents($exportFileDir . $savedFileName, $out)) {
                                log_message('Cannot save chat : ' . $exportFileDir . $savedFileName);
                                $error = true;
                            }
                        }
                    } catch (Exception $e) {
                        log_message('Cannot save chat : ' . $e->getMessage());
                        $error = true;
                    }
                }
                // save those with group id in group space
                if (!$error) {
                    $step = set_upgrade_status($tool, $step + 1, $course_code);
                } else {
                    return $step;
                }
            case 2:
                // activate new chat in each course
                $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
                if (!register_module_in_single_course($toolId, $course_code)) {
                    log_message("register_module_in_single_course( {$toolId}, {$course_code} ) failed");
                    return $step;
                }
                $sqlForUpdate[] = "UPDATE `" . $currentCourseDbNameGlu . "tool_list`\n                SET `activated` = 'true',\n                    `installed` = 'false'\n                WHERE tool_id = " . (int) $toolId;
                if (upgrade_apply_sql($sqlForUpdate)) {
                    $step = set_upgrade_status($tool, $step + 1, $course_code);
                } else {
                    return $step;
                }
                unset($sqlForUpdate);
            default:
                $step = set_upgrade_status($tool, 0, $course_code);
                return $step;
        }
    }
    return false;
}