示例#1
0
function insCourseEdition()
{
    checkPerm('mod');
    require_once _base_ . '/lib/lib.upload.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once _base_ . '/lib/lib.multimedia.php';
    $array_lang = Docebo::langManager()->getAllLangCode();
    $array_lang[] = 'none';
    $id_course = $_POST['course_id'];
    if ($_POST['course_edition_name'] == '') {
        $_POST['course_edition_name'] = Lang::t('_NO_NAME', 'course', 'lms');
    }
    $path = '/appLms/' . Get::sett('pathcourse');
    if (substr($path, -1) != '/' && substr($path, -1) != '\\') {
        $path = $path . '/';
    }
    $file_sponsor = '';
    $file_logo = '';
    $file_material = '';
    $file_othermaterial = '';
    $error = 0;
    $show_level = 0;
    $user_status = 0;
    if (isset($_POST['user_status'])) {
        while (list($status) = each($_POST['user_status'])) {
            $user_status |= 1 << $status;
        }
    }
    if (isset($_POST['course_edition_show_level'])) {
        while (list($lv) = each($_POST['course_edition_show_level'])) {
            $show_level |= 1 << $lv;
        }
    }
    sl_open_fileoperations();
    if ($_FILES['course_edition_user_material']['tmp_name'] != '') {
        $file_material = 'edition_user_material_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_user_material']['name'];
        $re = createImageFromTmp($_FILES['course_edition_user_material']['tmp_name'], $path . $file_material, $_FILES['course_edition_user_material']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_material = '';
        }
    }
    if ($_FILES['course_edition_otheruser_material']['tmp_name'] != '') {
        $file_othermaterial = 'edition_otheruser_material_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_otheruser_material']['name'];
        $re = createImageFromTmp($_FILES['course_edition_otheruser_material']['tmp_name'], $path . $file_othermaterial, $_FILES['course_edition_otheruser_material']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_othermaterial = '';
        }
    }
    if ($_FILES['course_edition_sponsor_logo']['tmp_name'] != '') {
        $file_sponsor = 'edition_sponsor_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_sponsor_logo']['name'];
        $re = createImageFromTmp($_FILES['course_edition_sponsor_logo']['tmp_name'], $path . $file_sponsor, $_FILES['course_edition_sponsor_logo']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_sponsor = '';
        }
    }
    if ($_FILES['course_edition_logo']['tmp_name'] != '') {
        $file_logo = 'edition_logo_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_logo']['name'];
        $re = createImageFromTmp($_FILES['course_edition_logo']['tmp_name'], $path . $file_logo, $_FILES['course_edition_logo']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_sponsor = '';
        }
    }
    sl_close_fileoperations();
    // if subsribe gap is defined with the date -------------------------------
    if ($_POST["can_subscribe"] != "2") {
        $sub_start_date = "NULL";
        $sub_end_date = "NULL";
    } else {
        $sub_start_date = "'" . Format::dateDb($_POST["sub_start_date"], "date") . "'";
        $sub_end_date = "'" . Format::dateDb($_POST["sub_end_date"], "date") . "'";
    }
    // insert the course in database -----------------------------------------------------------
    $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'];
        }
    }
    $query_course_edition = "\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_course_edition\r\n\t\tSET idCourse \t\t\t= '" . $id_course . "',\r\n\t\t\tcode \t\t\t\t= '" . $_POST['course_edition_code'] . "',\r\n\t\t\tname \t\t\t\t= '" . $_POST['course_edition_name'] . "',\r\n\t\t\tdescription \t\t= '" . $_POST['course_edition_descr'] . "',\r\n\t\t\tstatus \t\t\t\t= '" . (int) $_POST['course_edition_status'] . "',\r\n\r\n\t\t\tdate_begin \t\t\t= '" . Format::dateDb($_POST['course_edition_date_begin'], 'date') . "',\r\n\t\t\tdate_end \t\t\t= '" . Format::dateDb($_POST['course_edition_date_end'], 'date') . "',\r\n\t\t\thour_begin \t\t\t= '" . $hour_begin . "',\r\n\t\t\thour_end \t\t\t= '" . $hour_end . "',\r\n\r\n\t\t\timg_material \t\t= '" . $file_material . "',\r\n\t\t\timg_othermaterial \t= '" . $file_othermaterial . "',\r\n\r\n\t\t\tmin_num_subscribe \t= '" . (int) $_POST["min_num_subscribe"] . "',\r\n\t\t\tmax_num_subscribe \t= '" . (int) $_POST["max_num_subscribe"] . "',\r\n\t\t\tprice \t\t\t\t= '" . $_POST["edition_price"] . "',\r\n\t\t\tadvance \t\t\t= '" . $_POST["edition_advance"] . "',\r\n\r\n\t\t\tedition_type \t\t= '" . $_POST["edition_type"] . "',\r\n\t\t\tallow_overbooking \t= '" . (isset($_POST["allow_overbooking"]) ? 1 : 0) . "',\r\n\t\t\tcan_subscribe \t\t= '" . (int) $_POST["can_subscribe"] . "',\r\n\t\t\tsub_start_date \t\t= " . $sub_start_date . ",\r\n\t\t\tsub_end_date \t\t= " . $sub_end_date . "";
    if (!sql_query($query_course_edition)) {
        $error = 1;
        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);
        }
        Util::jump_to('index.php?modname=course&op=course_list&result=err_course');
    } else {
        $edition_id = sql_insert_id();
        $acl_manager =& Docebo::user()->getAclManager();
        $group = '/lms/course_edition/' . $edition_id . '/subscribed';
        $group_idst = $acl_manager->getGroupST($group);
        if ($group_idst === FALSE) {
            $group_idst = $acl_manager->registerGroup($group, 'all the user of a course edition', true, "course");
        }
        // send alert ---------------------------------------------------------------------------
        require_once _base_ . '/lib/lib.eventmanager.php';
        $msg_composer = new EventMessageComposer();
        $msg_composer->setSubjectLangText('email', '_ALERT_SUBJECT', false);
        $msg_composer->setBodyLangText('email', '_ALERT_TEXT', array('[url]' => Get::sett('url'), '[course_code]' => $_POST['course_edition_code'], '[course]' => $_POST['course_edition_name']));
        $msg_composer->setBodyLangText('sms', '_ALERT_TEXT_SMS', array('[url]' => Get::sett('url'), '[course_code]' => $_POST['course_edition_code'], '[course]' => $_POST['course_edition_name']));
        require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
        $course_man = new Man_Course();
        $recipients = $course_man->getIdUserOfLevel($id_course);
        createNewAlert('CoursePropModified', 'course', 'add', '1', 'Inserted course ' . $_POST['course_name'], $recipients, $msg_composer);
        Util::jump_to('index.php?modname=course&op=course_list&result=ok_course');
    }
}
示例#2
0
 /**
  * save a new avatar for the user
  */
 function saveAvatarData($id_user, $file_descriptor, $max_width, $max_height)
 {
     if (!$this->deleteAvatarData($id_user)) {
         return false;
     }
     if (!isset($file_descriptor['error'])) {
         return false;
     }
     if ($file_descriptor['error'] != UPLOAD_ERR_OK) {
         return false;
     }
     if ($file_descriptor['name'] == '') {
         return false;
     }
     require_once _base_ . '/lib/lib.upload.php';
     require_once _base_ . '/lib/lib.multimedia.php';
     $savefile = $id_user . 'a_' . mt_rand(0, 100) . '_' . time() . '_' . $file_descriptor['name'];
     if (file_exists($GLOBALS['where_files_relative'] . $this->getPAPath() . $savefile)) {
         return false;
     }
     sl_open_fileoperations();
     if (createImageFromTmp($file_descriptor['tmp_name'], $this->getPAPath() . $savefile, $file_descriptor['name'], $max_width, $max_height, true) != 0) {
         sl_close_fileoperations();
         return false;
     }
     sl_close_fileoperations();
     if (!$this->acl_man->updateUser($id_user, false, false, false, false, false, $savefile, false)) {
         sl_unlink(substr($this->getPAPath(), 1) . $savefile);
         return false;
     }
     return true;
 }
示例#3
0
 public function manageCourseFile($new_file_id, $old_file, $path, $quota_available, $delete_old, $is_image = false)
 {
     $arr_new_file = isset($_FILES[$new_file_id]) && $_FILES[$new_file_id]['tmp_name'] != '' ? $_FILES[$new_file_id] : false;
     $return = array('filename' => $old_file, 'new_size' => 0, 'old_size' => 0, 'error' => false, 'quota_exceeded' => false);
     if (($delete_old || $arr_new_file !== false) && $old_file != '') {
         // the flag for file delete is checked or a new file was uploaded ---------------------
         $return['old_size'] = Get::file_size($GLOBALS['where_files_relative'] . $path . $old_file);
         $quota_available -= $return['old_size'];
         sl_unlink($path . $old_file);
         $return['filename'] = '';
     }
     if (!empty($arr_new_file)) {
         // if present load the new file --------------------------------------------------------
         $filename = $new_file_id . '_' . mt_rand(0, 100) . '_' . time() . '_' . $arr_new_file['name'];
         if ($is_image) {
             $re = createImageFromTmp($arr_new_file['tmp_name'], $path . $filename, $arr_new_file['name'], 150, 150, true);
             if ($re < 0) {
                 $return['error'] = true;
             } else {
                 // after resize check size ------------------------------------------------------------
                 $size = Get::file_size($GLOBALS['where_files_relative'] . $path . $filename);
                 if ($quota_available != 0 && $size > $quota_available) {
                     $return['quota_exceeded'] = true;
                     sl_unlink($path . $filename);
                 } else {
                     $return['new_size'] = $size;
                     $return['filename'] = $filename;
                 }
             }
         } else {
             // check if the filesize don't exceed the quota ----------------------------------------
             $size = Get::file_size($arr_new_file['tmp_name']);
             if ($quota_available != 0 && $size > $quota_available) {
                 $return['quota_exceeded'] = true;
             } else {
                 // save file ---------------------------------------------------------------------------
                 if (!sl_upload($arr_new_file['tmp_name'], $path . $filename)) {
                     $return['error'] = true;
                 } else {
                     $return['new_size'] = $size;
                     $return['filename'] = $filename;
                 }
             }
         }
     }
     return $return;
 }