Esempio n. 1
0
function courseUpdate()
{
    require_once _base_ . '/lib/lib.upload.php';
    require_once _base_ . '/lib/lib.multimedia.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.manmenu.php';
    $array_lang = Docebo::langManager()->getAllLangCode();
    $array_lang[] = 'none';
    $acl_man =& Docebo::user()->getAclManager();
    if ($_POST['course_type'] === 'classroom') {
        $url = 'index.php?r=alms/classroom/show&result=';
    } else {
        $url = 'index.php?modname=course&op=course_list&result=';
    }
    if (isset($_POST['mod_course'])) {
        list($id_course) = each($_POST['mod_course']);
    } else {
        list($id_course) = $_GET['mod_course'];
    }
    require_once _lms_ . '/admin/models/LabelAlms.php';
    $label_model = new LabelAlms();
    $label = Get::req('label', DOTY_INT, 0);
    $label_model->associateLabelToCourse($label, $id_course);
    // calc quota limit
    $quota = $_POST['course_quota'];
    if (isset($_POST['inherit_quota'])) {
        $quota = Get::sett('course_quota');
        $_POST['course_quota'] = COURSE_QUOTA_INHERIT;
    }
    $quota = $quota * 1024 * 1024;
    $course_man = new DoceboCourse($id_course);
    $used = $course_man->getUsedSpace();
    if ($_POST['course_name'] == '') {
        $_POST['course_name'] = Lang::t('_NO_NAME', 'course', 'lms');
    }
    // restriction on course status ------------------------------------------
    $user_status = 0;
    if (isset($_POST['user_status'])) {
        while (list($status) = each($_POST['user_status'])) {
            $user_status |= 1 << $status;
        }
    }
    // level that will be showed in the course --------------------------------
    $show_level = 0;
    if (isset($_POST['course_show_level'])) {
        while (list($lv) = each($_POST['course_show_level'])) {
            $show_level |= 1 << $lv;
        }
    }
    // save the file uploaded -------------------------------------------------
    $error = false;
    $quota_exceeded = false;
    $path = Get::sett('pathcourse');
    $path = '/appLms/' . Get::sett('pathcourse') . (substr($path, -1) != '/' && substr($path, -1) != '\\' ? '/' : '');
    $old_file_size = 0;
    if (is_array($_FILES) && !empty($_FILES) || is_array($_POST["file_to_del"])) {
        sl_open_fileoperations();
    }
    // load user material ---------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_user_material', $_POST["old_course_user_material"], $path, $quota != 0 ? $quota - $used : false, isset($_POST['file_to_del']['course_user_material']));
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_material = $arr_file['filename'];
    $used = $used + ($arr_file['new_size'] - $arr_file['old_size']);
    $old_file_size += $arr_file['old_size'];
    // course otheruser material -------------------------------------------------------------------
    $arr_file = manageCourseFile('course_otheruser_material', $_POST["old_course_otheruser_material"], $path, $quota != 0 ? $quota - $used : false, isset($_POST['file_to_del']['course_otheruser_material']));
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_othermaterial = $arr_file['filename'];
    $used = $used + ($arr_file['new_size'] - $arr_file['old_size']);
    $old_file_size += $arr_file['old_size'];
    // course demo-----------------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_demo', $_POST["old_course_demo"], $path, $quota != 0 ? $quota - $used : false, isset($_POST['file_to_del']['course_demo']));
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_demo = $arr_file['filename'];
    $used = $used + ($arr_file['new_size'] - $arr_file['old_size']);
    $old_file_size += $arr_file['old_size'];
    // course sponsor---------------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_sponsor_logo', $_POST["old_course_sponsor_logo"], $path, $quota != 0 ? $quota - $used : false, isset($_POST['file_to_del']['course_sponsor_logo']), true);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_sponsor = $arr_file['filename'];
    $used = $used + ($arr_file['new_size'] - $arr_file['old_size']);
    $old_file_size += $arr_file['old_size'];
    // course logo-----------------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_logo', $_POST["old_course_logo"], $path, $quota != 0 ? $quota - $used : false, isset($_POST['file_to_del']['course_logo']), true);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_logo = $arr_file['filename'];
    $used = $used + ($arr_file['new_size'] - $arr_file['old_size']);
    $old_file_size += $arr_file['old_size'];
    // ----------------------------------------------------------------------------------------------
    sl_close_fileoperations();
    $date_begin = Format::dateDb($_POST['course_date_begin'], "date");
    $date_end = Format::dateDb($_POST['course_date_end'], "date");
    if ($_POST["can_subscribe"] == "2") {
        $sub_start_date = Format::dateDb($_POST["sub_start_date"], "date");
        $sub_end_date = Format::dateDb($_POST["sub_end_date"], "date");
    }
    $hour_begin = '-1';
    $hour_end = '-1';
    if ($_POST['hour_begin']['hour'] != '-1') {
        $hour_begin = strlen($_POST['hour_begin']['hour']) == 1 ? '0' . $_POST['hour_begin']['hour'] : $_POST['hour_begin']['hour'];
        if ($_POST['hour_begin']['quarter'] == '-1') {
            $hour_begin .= ':00';
        } else {
            $hour_begin .= ':' . $_POST['hour_begin']['quarter'];
        }
    }
    if ($_POST['hour_end']['hour'] != '-1') {
        $hour_end = strlen($_POST['hour_end']['hour']) == 1 ? '0' . $_POST['hour_end']['hour'] : $_POST['hour_end']['hour'];
        if ($_POST['hour_end']['quarter'] == '-1') {
            $hour_end .= ':00';
        } else {
            $hour_end .= ':' . $_POST['hour_end']['quarter'];
        }
    }
    // update database ----------------------------------------------------
    $query_course = "\r\n\tUPDATE " . $GLOBALS['prefix_lms'] . "_course\r\n\tSET code \t\t\t\t= '" . $_POST['course_code'] . "',\r\n\t\tname \t\t\t\t= '" . $_POST['course_name'] . "',\r\n\t\tdescription \t\t= '" . $_POST['course_descr'] . "',\r\n\t\tlang_code \t\t\t= '" . $array_lang[$_POST['course_lang']] . "',\r\n\t\tstatus \t\t\t\t= '" . (int) $_POST['course_status'] . "',\r\n\t\tlevel_show_user \t= '" . $show_level . "',\r\n\t\tsubscribe_method \t= '" . (int) $_POST['course_subs'] . "',\r\n\t\tidCategory\t\t\t= '" . (int) $_POST['idCategory'] . "',\r\n\r\n\t\tlinkSponsor \t\t= '" . $_POST['course_sponsor_link'] . "',\r\n\r\n\t\timgSponsor \t\t\t= '" . $file_sponsor . "',\r\n\t\timg_course \t\t\t= '" . $file_logo . "',\r\n\t\timg_material \t\t= '" . $file_material . "',\r\n\t\timg_othermaterial \t= '" . $file_othermaterial . "',\r\n\t\tcourse_demo \t\t= '" . $file_demo . "',\r\n\r\n\t\tmediumTime \t\t\t= '" . $_POST['course_medium_time'] . "',\r\n\t\tpermCloseLO \t\t= '" . $_POST['course_em'] . "',\r\n\t\tuserStatusOp \t\t= '" . $user_status . "',\r\n\t\tdifficult \t\t\t= '" . $_POST['course_difficult'] . "',\r\n\r\n\t\tshow_progress \t\t= '" . (isset($_POST['course_progress']) ? 1 : 0) . "',\r\n\t\tshow_time \t\t\t= '" . (isset($_POST['course_time']) ? 1 : 0) . "',\r\n\r\n\t\tshow_who_online\t\t= '" . $_POST['show_who_online'] . "',\r\n\r\n\t\tshow_extra_info \t= '" . (isset($_POST['course_advanced']) ? 1 : 0) . "',\r\n\t\tshow_rules \t\t\t= '" . (int) $_POST['course_show_rules'] . "',\r\n\r\n\t\tdirect_play \t\t= '" . (isset($_POST['direct_play']) ? 1 : 0) . "',\r\n\r\n\t\tdate_begin \t\t\t= '" . $date_begin . "',\r\n\t\tdate_end \t\t\t= '" . $date_end . "',\r\n\t\thour_begin \t\t\t= '" . $hour_begin . "',\r\n\t\thour_end \t\t\t= '" . $hour_end . "',\r\n\r\n\t\tvalid_time \t\t\t= '" . (int) $_POST['course_day_of'] . "',\r\n\r\n\t\tmin_num_subscribe \t= '" . (int) $_POST['min_num_subscribe'] . "',\r\n\t\tmax_num_subscribe \t= '" . (int) $_POST['max_num_subscribe'] . "',\r\n\r\n\t\tcourse_type \t\t= '" . $_POST['course_type'] . "',\r\n\t\tpoint_to_all \t\t= '" . (isset($_POST['point_to_all']) ? $_POST['point_to_all'] : 0) . "',\r\n\t\tcourse_edition \t\t= '" . (isset($_POST['course_edition']) ? $_POST['course_edition'] : 0) . "',\r\n\t\tselling \t\t\t= '" . (isset($_POST['course_sell']) ? 1 : 0) . "',\r\n\t\tprize \t\t\t\t= '" . (isset($_POST['course_prize']) ? $_POST['course_prize'] : 0) . "',\r\n\t\tpolicy_point \t\t= '" . $_POST['policy_point'] . "',\r\n\r\n\t\tcourse_quota \t\t= '" . $_POST['course_quota'] . "',\r\n\r\n\t\tallow_overbooking \t= '" . (isset($_POST["allow_overbooking"]) ? 1 : 0) . "',\r\n\t\tcan_subscribe \t\t= '" . (int) $_POST["can_subscribe"] . "',\r\n\t\tsub_start_date \t\t= " . ($_POST["can_subscribe"] == "2" ? "'" . $sub_start_date . "'" : 'NULL') . ",\r\n\t\tsub_end_date \t\t= " . ($_POST["can_subscribe"] == "2" ? "'" . $sub_end_date . "'" : 'NULL') . ",\r\n\r\n\t\tadvance \t\t\t= '" . $_POST['advance'] . "',\r\n\t\tshow_result \t\t= '" . (isset($_POST['show_result']) ? 1 : 0) . "',\r\n\r\n\r\n\t\tuse_logo_in_courselist = '" . (isset($_POST['use_logo_in_courselist']) ? '1' : '0') . "'";
    if (isset($_POST['random_course_autoregistration_code'])) {
        $control = 1;
        $str = '';
        while ($control) {
            for ($i = 0; $i < 10; $i++) {
                $seed = mt_rand(0, 10);
                if ($seed > 5) {
                    $str .= mt_rand(0, 9);
                } else {
                    $str .= chr(mt_rand(65, 90));
                }
            }
            $control_query = "SELECT COUNT(*)" . " " . $GLOBALS['prefix_lms'] . "_course" . " WHERE autoregistration_code = '" . $str . "'" . " AND idCourse <> '" . $id_course . "'";
            $control_result = sql_query($control_query);
            list($result) = sql_fetch_row($control_result);
            $control = $result;
        }
        $query_course .= ", autoregistration_code = '" . $str . "'";
    } else {
        $query_course .= ", autoregistration_code = '" . $_POST['course_autoregistration_code'] . "'";
    }
    $query_course .= " WHERE idCourse = '" . $id_course . "'";
    if (!sql_query($query_course)) {
        if ($file_sponsor != '') {
            sl_unlink($path . $file_sponsor);
        }
        if ($file_logo != '') {
            sl_unlink($path . $file_logo);
        }
        if ($file_material != '') {
            sl_unlink($path . $file_material);
        }
        if ($file_othermaterial != '') {
            sl_unlink($path . $file_othermaterial);
        }
        if ($file_demo != '') {
            sl_unlink($path . $file_demo);
        }
        $course_man->subFileToUsedSpace(false, $old_file_size);
        Util::jump_to($url . 'err_course');
    }
    // Let's update the classroom occupation schedule if course type is classroom -------
    if (hasClassroom($_POST["general_course_type"])) {
        $old_date_begin = $_POST["old_date_begin"];
        $old_date_end = $_POST["old_date_end"];
        updateCourseTimtable($id_course, FALSE, $date_begin, $date_end, $old_date_begin, $old_date_end);
    }
    // cascade modify on all the edition of thi course ---------------------------------
    if (isset($_POST['cascade_on_ed'])) {
        $query_editon = "\r\n\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_course_edition\r\n\t\tSET code \t\t\t= '" . $_POST['course_code'] . "',\r\n\t\t\tname \t\t\t= '" . $_POST['course_name'] . "',\r\n\t\t\tdescription \t= '" . $_POST['course_descr'] . "',\r\n\t\t\tedition_type \t= '" . $_POST['course_type'] . "',\r\n\t\t\tstatus \t\t\t= '" . $_POST['course_status'] . "'\r\n\t\tWHERE idCourse = '" . $id_course . "'";
        sql_query($query_editon);
    }
    Util::jump_to($url . 'ok_course' . ($quota_exceeded ? '&limit_reach=1' : ''));
}