Example #1
0
 /**
  * @param int $id contains the resource id
  * @param string $back_url contains the back url (not used yet)
  */
 function del($id, $back_url = NULL)
 {
     //checkPerm('view', false, 'storage');
     unset($_SESSION['last_error']);
     require_once _base_ . '/lib/lib.upload.php';
     $path_to_file = '/appLms/' . Get::sett('pathlesson');
     list($old_file) = sql_fetch_row(sql_query("\r\n\t\tSELECT path \r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_materials_lesson \r\n\t\tWHERE idLesson = '" . $id . "'"));
     $size = Get::file_size($GLOBALS['where_files_relative'] . $path_to_file . $old_file);
     if ($old_file != '') {
         sl_open_fileoperations();
         if (!sl_unlink($path_to_file . $old_file)) {
             sl_close_fileoperations();
             $_SESSION['last_error'] = Lang::t('_OPERATION_FAILURE', 'item');
             return false;
         }
         sl_close_fileoperations();
         if (isset($_SESSION['idCourse']) && defined("LMS")) {
             $GLOBALS['course_descriptor']->subFileToUsedSpace(false, $size);
         }
     }
     $delete_query = "\r\n\t\tDELETE FROM " . $GLOBALS['prefix_lms'] . "_materials_lesson \r\n\t\tWHERE idLesson = '" . $id . "'";
     if (!sql_query($delete_query)) {
         $_SESSION['last_error'] = Lang::t('_OPERATION_FAILURE', 'item');
         return false;
     }
     return $id;
 }
Example #2
0
 /**
  * Return the size in bytes of the specified directory
  * @param <string> $path The target dir
  * @return <int> The size of the dir in bytes
  */
 public static function dir_size($path)
 {
     if (!is_dir($path)) {
         return Get::file_size($path);
     }
     if ($scan_dir = opendir($path)) {
         $size = 0;
         while ($file = readdir($scan_dir)) {
             if ($file != '..' && $file != '.' && $file != '') {
                 $size += self::dir_size($path . '/' . $file);
             }
         }
     }
     closedir($scan_dir);
     return $size;
 }
Example #3
0
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;
}
Example #4
0
 function insertFile($id_file, $area, $title, $description, $file_descriptor, $file_policy)
 {
     require_once _base_ . '/lib/lib.user.php';
     require_once _base_ . '/lib/lib.user_profile.php';
     $user_data = new DoceboUser(getLogUserId());
     $user_profile_data = new UserProfileData();
     $file_name = '';
     if ($file_descriptor != '') {
         // save file
         $file_name = $this->saveFile($area, $file_descriptor);
     }
     $file_size = Get::file_size($GLOBALS['where_files_relative'] . $this->getFilePath() . $file_name);
     if (!$file_size) {
         $file_size = 0;
     }
     $total_used_quota = $file_size + $user_profile_data->getUsedQuota(getLogUserId());
     $max_quota = $user_profile_data->getQuotaLimit(getLogUserId()) * 1024 * 1024;
     if ($total_used_quota <= $max_quota) {
         if (!$id_file) {
             if ($file_name == '') {
                 return false;
             }
             $query = "\r\n\t\t\t\tINSERT INTO " . $this->getFilesTable() . " ( owner, area, title, description, file_name, file_policy, size ) VALUES \r\n\t\t\t\t(\t'" . $this->id_user . "', \r\n\t\t\t\t\t'" . $area . "', \r\n\t\t\t\t\t'" . $title . "', \r\n\t\t\t\t\t'" . $description . "', \r\n\t\t\t\t\t'" . addslashes($file_name) . "', \r\n\t\t\t\t\t'" . $file_policy . "', \r\n\t\t\t\t\t'" . $file_size . "' )";
             if (!$this->_query($query)) {
                 return false;
             }
             $result = $user_data->updateUserUsedSpace($this->id_user);
             $id_file = $this->_last_id();
             return $id_file;
         } else {
             $query = "\r\n\t\t\t\tUPDATE " . $this->getFilesTable() . " \r\n\t\t\t\tSET area = '" . $area . "', \r\n\t\t\t\t\ttitle = '" . $title . "', \r\n\t\t\t\t\tdescription = '" . $description . "', \r\n\t\t\t\t\tfile_policy = '" . $file_policy . "' ";
             if ($file_name != '' || $file_name != false) {
                 $query .= ", file_name = '" . addslashes($file_name) . "'";
             }
             $query .= " WHERE id_file = '" . $id_file . "' AND owner = '" . $this->id_user . "'";
             if (!$this->_query($query)) {
                 return false;
             }
             return $id_file;
         }
     }
     sl_open_fileoperations();
     sl_unlink($this->getFilePath() . $file_name);
     sl_close_fileoperations();
     return false;
 }
Example #5
0
 function subFileToUsedSpace($path = false, $manual_size = false)
 {
     if ($manual_size === false) {
         $size = Get::file_size($path);
     } else {
         $size = $manual_size;
     }
     $course_size = $this->course_info['used_space'] - $size;
     $this->course_info['used_space'] = $course_size < 0 ? 0 : $course_size;
     return $this->setValues(array('used_space' => $course_size));
 }
Example #6
0
 function remfiles()
 {
     checkPerm('mod');
     $lang =& DoceboLanguage::createInstance('course');
     require_once _base_ . '/lib/lib.upload.php';
     if (isset($_GET['confirm']) && $_GET['confirm'] == '1') {
         list($old_file) = sql_fetch_row(sql_query("\r\n\t\tSELECT path \r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_course_file \r\n\t\tWHERE id_course='" . $_SESSION['idCourse'] . "' AND id_file='" . (int) $_GET['id_file'] . "'"));
         $size = Get::file_size($GLOBALS['where_files_relative'] . _PATH_COURSE . $old_file);
         if (!sl_unlink(_PATH_COURSE . $old_file)) {
             $GLOBALS['page']->add(getErrorUi($lang->def('_OPERATION_FAILURE')));
             return;
         }
         $GLOBALS['course_descriptor']->subFileToUsedSpace(false, $size);
         if (!sql_query("\r\n\t\tDELETE FROM " . $GLOBALS['prefix_lms'] . "_course_file \r\n\t\tWHERE id_course = '" . (int) $_SESSION['idCourse'] . "' AND id_file = '" . (int) $_GET['id_file'] . "'")) {
             $GLOBALS['page']->add(getErrorUi($lang->def('_OPERATION_FAILURE')));
             return;
         }
         Util::jump_to('index.php?modname=course&op=infocourse');
     } else {
         list($title, $file) = sql_fetch_row(sql_query("\r\n\t\tSELECT title, path \r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_course_file \r\n\t\tWHERE id_course = '" . (int) $_SESSION['idCourse'] . "' AND id_file = '" . (int) $_GET['id_file'] . "'"));
         //request erase confirm
         $GLOBALS['page']->add(getTitleArea(array('index.php?modname=course&amp;op=infocourse' => $lang->def('_INFO'), $lang->def('_DEL')), 'infocourse') . '<div class="std_block">' . getDeleteUi($lang->def('_AREYOUSURE'), '<img src="' . getPathImage('fw') . mimeDetect($file) . '" alt="mime-type" /> ' . $title, true, 'index.php?modname=course&amp;op=remfiles&amp;id_file=' . (int) $_GET['id_file'] . '&amp;confirm=1', 'index.php?modname=course&amp;op=infocourse') . '</div>', 'content');
     }
 }
Example #7
0
 function upitem()
 {
     //checkPerm('view', false, 'storage');
     require_once _base_ . '/lib/lib.upload.php';
     $back_url = urldecode($_POST['back_url']);
     //scanning title
     if (trim($_POST['title']) == "") {
         $_POST['title'] = Lang::t('_NOTITLE', 'item', 'lms');
     }
     //save file
     if ($_FILES['attach']['name'] != '') {
         $path = '/appLms/' . Get::sett('pathlesson');
         // retrive and delte ld file --------------------------------------------------
         list($old_file) = sql_fetch_row(sql_query("\r\n\t\tSELECT path \r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_materials_lesson \r\n\t\tWHERE idLesson = '" . (int) $_POST['idItem'] . "'"));
         $size = Get::file_size($GLOBALS['where_files_relative'] . $path . $old_file);
         if (!sl_unlink($path . $old_file)) {
             sl_close_fileoperations();
             $_SESSION['last_error'] = Lang::t('_OPERATION_FAILURE', 'item', 'lms');
             Util::jump_to($back_url . '&id_lo=' . (int) $_POST['idItem'] . '&mod_result=0');
         }
         $GLOBALS['course_descriptor']->subFileToUsedSpace(false, $size);
         // control course quota ---------------------------------------------------
         $quota = $GLOBALS['course_descriptor']->getQuotaLimit();
         $used = $GLOBALS['course_descriptor']->getUsedSpace();
         if (Util::exceed_quota($_FILES['attach']['tmp_name'], $quota, $used)) {
             $_SESSION['last_error'] = Lang::t('_QUOTA_EXCEDED');
             Util::jump_to($back_url . '&create_result=0');
         }
         // save new file ------------------------------------------------------------
         sl_open_fileoperations();
         $savefile = $_SESSION['idCourse'] . '_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['attach']['name'];
         if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) {
             if (!sl_upload($_FILES['attach']['tmp_name'], $path . $savefile)) {
                 sl_close_fileoperations();
                 $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD', 'item', 'lms');
                 Util::jump_to($back_url . '&id_lo=' . (int) $_POST['idItem'] . '&mod_result=0');
             }
             sl_close_fileoperations();
         } else {
             $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD', 'item', 'lms');
             Util::jump_to($back_url . '&id_lo=' . (int) $_POST['idItem'] . '&mod_result=0');
         }
         $new_file = ", path = '" . $savefile . "'";
     }
     $insert_query = "\r\n\tUPDATE " . $GLOBALS['prefix_lms'] . "_materials_lesson \r\n\tSET author = '" . getLogUserId() . "',\r\n\t\ttitle = '" . $_POST['title'] . "',\r\n\t\tdescription = '" . $_POST['description'] . "'\r\n\t\t{$new_file}\r\n\tWHERE idLesson = '" . (int) $_POST['idItem'] . "'";
     if (!sql_query($insert_query)) {
         sl_unlink($path . $savefile);
         $_SESSION['last_error'] = Lang::t('_OPERATION_FAILURE', 'item', 'lms');
         Util::jump_to($back_url . '&id_lo=' . (int) $_POST['idItem'] . '&mod_result=0');
     }
     if (isset($_SESSION['idCourse']) && defined("LMS")) {
         $GLOBALS['course_descriptor']->addFileToUsedSpace($GLOBALS['where_files_relative'] . $path . $savefile);
         require_once $GLOBALS['where_lms'] . '/class.module/track.object.php';
         Track_Object::updateObjectTitle($_POST['idItem'], 'item', $_POST['title']);
     }
     Util::jump_to($back_url . '&id_lo=' . (int) $_POST['idItem'] . '&mod_result=1');
 }