require_once 'lib/php/vt/VtAction.php';
$messageProduct = optional_param("messageProduct", "");
$messageAction = optional_param("messageAction", "");
$notool = optional_param("novoicetools", "false");
$keys = array_merge(getKeysOfGeneralParameters(), getKeyWimbaVoiceForm());
foreach ($keys as $param) {
    $value = optional_param($param["value"], $param["default_value"], $param["type"]);
    if ($value != null) {
        $params[$param["value"]] = $value;
    }
}
wimba_add_log(WIMBA_DEBUG, voicepresentation_LOGS, "manageAction : parameters  \n" . print_r($params, true));
require_login($params["enc_course_id"]);
$session = new WimbaMoodleSession($params);
$redirectionUrl = 'welcome.php?id=' . $params["enc_course_id"] . '&' . voicepresentation_get_url_params($params["enc_course_id"]) . '&time=' . $session->timeOfLoad;
$urlModuleForm = $CFG->wwwroot . '/course/mod.php?section=0&sesskey=' . sesskey() . '&id=' . $session->getCourseId() . '&add=voicepresentation&rid=';
$messageType = "";
if ($session->error === false && $session != NULL) {
    $vtAction = new vtAction($session->getEmail(), $params);
    if ($params['action'] == 'launch') {
        $session->setCurrentVtUSer($params["type"]);
        if ($params["studentView"] == "true") {
            $session->setVtUserRigths($params["type"], "student");
        }
        $resource = voicetools_api_get_resource($params["resource_id"]);
        $result = $vtAction->getVtSession($resource, $session->getVtUser(), $session->getVtUserRigths());
        if ($result != NULL) {
            wimba_add_log(WIMBA_DEBUG, voicepresentation_LOGS, "launch the " . $params["type"] . ", nid =" . $result->getNid());
            if (!empty($params["filter_screen_name"])) {
                redirection($CFG->voicetools_servername . '/' . $params["type"] . '?action=display_popup&nid=' . $result->getNid() . "&filter_screen_name=" . $params["filter_screen_name"]);
            } else {
    $params[$param["value"]] = $value;
}
require_login($params["enc_course_id"]);
$action = $params["action"];
$roomId = $params["resource_id"];
$rid_audio = $params["rid_audio"];
$session = new WimbaMoodleSession($params);
$xml = new WimbaXml();
if ($session->error === false && $session != NULL) {
    $api = new LCAction($session, $CFG->liveclassroom_servername, $CFG->liveclassroom_adminusername, $CFG->liveclassroom_adminpassword, $CFG->dataroot);
    $prefix = $api->getPrefix();
    switch ($action) {
        case "launch":
            $roomId = required_param('resource_id', PARAM_SAFEDIR);
            if ($params["studentView"] == "true") {
                $authToken = $api->getAuthokenNormal($session->getCourseId() . "_S", $session->getFirstname(), $session->getLastname());
            } else {
                $authToken = $api->getAuthoken();
            }
            redirection($CFG->liveclassroom_servername . '/main/horizon_ui.pl.epl?' . 'channel=' . $api->getPrefix() . $roomId . '&hzA=' . $authToken);
            break;
        case "create":
            $id = $api->createRoom($roomId, "false");
            $messageAction = "created";
            $messageProduct = "room";
            break;
        case "createDefault":
            $id = $api->createSimpleRoom($params["longname"], "true", $params["enc_course_id"]);
            echo $prefix . $id;
            exit;
            break;