function saveAttachment($attach) { require_once _base_ . '/lib/lib.upload.php'; $path = _PATH_MESSAGE; $file = ''; sl_open_fileoperations(); if (isset($attach['tmp_name']['attach']) && $attach['tmp_name']['attach'] != '') { $file = getLogUserId() . '_' . mt_rand(0, 100) . '_' . time() . '_' . $attach['name']['attach']; if (!sl_upload($attach['tmp_name']['attach'], $path . $file)) { $error = 1; $file = ''; } } sl_close_fileoperations(); if (!$error) { return $file; } return false; }
function manageCertificateFile($new_file_id, $old_file, $path, $delete_old, $is_image = false) { require_once _base_ . '/lib/lib.upload.php'; $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); sl_open_fileoperations(); if (($delete_old || $arr_new_file !== false) && $old_file != '') { sl_unlink($path . $old_file); } // the flag for file delete is checked or a new file was uploaded --------------------- 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 (!sl_upload($arr_new_file['tmp_name'], $path . $filename)) { return false; } else { return $filename; } } sl_close_fileoperations(); return ''; }
function loadImportCourseUser2() { require_once _base_ . '/lib/lib.upload.php'; require_once $GLOBALS['where_framework'] . '/lib/lib.import.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.course.php'; require_once _base_ . '/lib/lib.table.php'; $lang =& DoceboLanguage::CreateInstance('subscribe', 'lms'); $back_url = 'index.php?modname=course&op=course_list'; $acl_man =& Docebo::user()->getAclManager(); $out =& $GLOBALS['page']; $out->setWorkingZone('content'); $id_course = importVar('id_course', true, 0); $id_course_edition = importVar('edition', true, 0); $level_idst =& getCourseLevel($id_course); if (count($level_idst) == 0) { $level_idst =& DoceboCourse::createCourseLevel($id_course); } // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { $_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); Util::jump_to($back_url . '&import_result=-1'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($back_url . '&import_result=-1'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($back_url . '&create_result=-1'); } } $out->add(getTitleArea($lang->def('_SUBSCRIBE')) . '<div class="std_block">'); $separator = importVar('import_separator', false, ','); if ($separator == '') { $separator = ','; } $first_row_header = importVar('import_first_row_header', false, false); $import_charset = importVar('import_charset', false, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $src->connect(); $user_added = 0; $user_error = 0; $user_not_needed = 0; $id_user_added = array(); $counter = 0; if (is_array($row = $src->get_first_row()) && !empty($row)) { $user_info = $acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; // Add in group for permission $acl_man->addToGroup($level_idst['3'], $id_user); // Add to edition group if ($id_course_edition > 0) { $group = '/lms/course_edition/' . $id_course_edition . '/subscribed'; $group_idst = $acl_man->getGroupST($group); if ($group_idst === FALSE) { $group_idst = $acl_man->registerGroup($group, 'all the user of a course edition', true, "course"); } $acl_man->addToGroup($group_idst, $id_user); } // Add in table $re = sql_query("\r\n\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t( idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr )\r\n\t\t\tVALUES\r\n\t\t\t( '" . $id_user . "', '" . $id_course . "', '" . $id_course_edition . "', '3', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t"); if ($re) { addUserToTimeTable($id_user, $id_course, $id_course_edition); $user_added++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_CORRECT'; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $id_course . "'" . " AND edition_id = '" . $id_course_edition . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } $counter++; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } while (is_array($row = $src->get_next_row()) && !empty($row)) { $user_info = $acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; // Add in group for permission $acl_man->addToGroup($level_idst['3'], $id_user); // Add to edition group if ($id_course_edition > 0) { $group = '/lms/course_edition/' . $id_course_edition . '/subscribed'; $group_idst = $acl_man->getGroupST($group); if ($group_idst === FALSE) { $group_idst = $acl_man->registerGroup($group, 'all the user of a course edition', true, "course"); } $acl_man->addToGroup($group_idst, $id_user); } // Add in table $re = sql_query("\r\n\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t( idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr )\r\n\t\t\tVALUES\r\n\t\t\t( '" . $id_user . "', '" . $id_course . "', '" . $id_course_edition . "', '3', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t"); if ($re) { addUserToTimeTable($id_user, $id_course, $id_course_edition); $user_added++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_CORRECT'; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $id_course . "'" . " AND edition_id = '" . $id_course_edition . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } $counter++; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } $src->close(); unset($row); $type_h = array('align_center', 'align_center', 'align_center', 'align_center'); $cont_h = array($lang->def('_USERNAME'), $lang->def('_LASTNAME'), $lang->def('_FIRSTNAME'), $lang->def('_INSER_STATUS')); $tb = new Table(false, $lang->def('_USER_SUBSCRIBED'), $lang->def('_USER_SUBSCRIBED')); $tb->addHead($cont_h, $type_h); while (list(, $id_user_added_detail) = each($id_user_added)) { $cont = array(); $user_info = $acl_man->getUser($id_user_added_detail['id_user'], false); $cont[] = $acl_man->relativeId($user_info[ACL_INFO_USERID]); $cont[] = $user_info[ACL_INFO_FIRSTNAME]; $cont[] = $user_info[ACL_INFO_LASTNAME]; $cont[] = $lang->def($id_user_added_detail['status']); $tb->addBody($cont); } sl_open_fileoperations(); sl_unlink($path . $savefile); sl_close_fileoperations(); $out->add(getBackUi($back_url, $lang->def('_BACK')) . '<b>' . $lang->def('_INSERT_CORRECT') . ' : ' . '</b>' . $user_added . ' ' . '<b>' . $lang->def('_OPERATION_FAILURE') . ' : ' . '</b>' . $user_error . ' ' . '<b>' . $lang->def('_INSERT_NOT_NEEDED') . ' : ' . '</b>' . $user_not_needed . '<br/>' . '<br/>' . $tb->getTable() . '<br/>' . getBackUi($back_url, $lang->def('_BACK')) . '</div>'); }
function edit_files($mode = "edit") { require_once _base_ . '/lib/lib.upload.php'; require_once _base_ . '/lib/lib.form.php'; $form = new Form(); $out =& $GLOBALS['page']; $out->setWorkingZone('content'); $lang =& DoceboLanguage::createInstance('project', "lms"); // Controllo che l'utente non cerchi di entrare in progetti a cui non e' iscritto. $id = $_GET["id"]; $itemid = importVar("itemid"); $myprj = user_projects(Docebo::user()->getIdSt()); $view_perm = checkPerm('view', true); if ($view_perm && in_array($id, $myprj) && (is_owner(Docebo::user()->getIdSt(), $id) || is_admin(Docebo::user()->getIdSt(), $id))) { //area title $out->add(getTitleArea($lang->def("_PROJECT_MANAGER"), "project")); $out->add('<div class="std_block">'); if ($mode == "edit") { $goto = "prjedititem"; } if ($mode == "new") { $goto = "prjadditem"; } if (isset($_POST["applychanges"])) { $ftitle = $_POST["ftitle"]; $fver = $_POST["fver"]; $fdesc = $_POST["fdesc"]; if ($mode == "new") { $ok = 1; //save file sl_open_fileoperations(); if (!isset($_FILES['attach']) || $_FILES['attach']['name'] == '') { $savefile = ''; } else { $savefile = $_SESSION['idCourse'] . '_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['attach']['name']; if (!file_exists(_FPATH_INTERNAL . $savefile)) { if (!sl_upload($_FILES['attach']['tmp_name'], _FPATH_INTERNAL . $savefile)) { $savefile = ''; $ok = 0; } } else { $savefile = ''; $ok = 0; } } sl_close_fileoperations(); if ($ok && $savefile != "") { $query = sql_query("INSERT INTO " . $GLOBALS["prefix_lms"] . "_prj_files (pid,fname,ftitle,fver,fdesc) VALUES('{$id}','" . (get_magic_quotes_gpc() ? $savefile : mysql_escape_string($savefile)) . "','{$ftitle}','{$fver}','{$fdesc}');"); } } if ($mode == "edit") { $query = sql_query("UPDATE " . $GLOBALS["prefix_lms"] . "_prj_files SET ftitle='{$ftitle}',fver='{$fver}',fdesc='{$fdesc}' WHERE id='{$itemid}' LIMIT 1;"); } Util::jump_to(" index.php?modname=project&op=showprj&id={$id}"); } $url = "index.php?modname=project&op=showprj&id=" . $id; $out->add(getBackUi($url, $lang->def('_BACK'))); if ($mode == "edit") { $query = sql_query("SELECT * FROM " . $GLOBALS["prefix_lms"] . "_prj_files WHERE pid='{$id}' AND id='{$itemid}';"); if ($query && mysql_num_rows($query) > 0) { $row = mysql_fetch_array($query); } $label = $lang->def("_SAVE"); } else { if ($mode == "new") { $row = array(); $label = $lang->def("_SAVE"); } } $ftitle = isset($row["ftitle"]) ? $row["ftitle"] : ''; $fver = isset($row["fver"]) ? $row["fver"] : ''; $fdesc = isset($row["fdesc"]) ? $row["fdesc"] : ''; $url = "index.php?modname=project&op={$goto}&type=file&id={$id}&itemid=" . $itemid; $out->add($form->openForm("form_name", $url, "", "", "multipart/form-data")); $out->add($form->openElementSpace()); if ($mode == "new") { $out->add($form->getFilefield($lang->def("_FILE"), "attach", "attach")); } $out->add($form->getTextfield($lang->def("_TITLE"), "ftitle", "ftitle", 255, $ftitle)); $out->add($form->getTextfield($lang->def("_VERSION"), "fver", "fver", 255, $fver)); $out->add($form->getSimpleTextarea($lang->def("_DESCRIPTION"), "fdesc", "fdesc", $fdesc)); $out->add($form->getHidden("applychanges", "applychanges", 1)); $out->add($form->closeElementSpace()); $out->add($form->openButtonSpace()); $out->add($form->getButton('save', 'save', $label)); $out->add($form->getButton('undo', 'undo', $lang->def('_UNDO'))); $out->add($form->closeButtonSpace()); $out->add($form->closeForm()); $out->add('<br /></div>'); return 0; $out->add("<form method=\"post\" action=\"index.php?modname=project&op={$goto}&type=file&id={$id}&itemid={$itemid}\" enctype=\"multipart/form-data\">\n" . '<input type="hidden" id="authentic_request_prj" name="authentic_request" value="' . Util::getSignature() . '" />'); $query = sql_query("SELECT * FROM " . $GLOBALS["prefix_lms"] . "_prj_files WHERE pid='{$id}' AND id='{$itemid}';"); if ($query && mysql_num_rows($query) > 0 || $mode == "new") { if ($mode == "edit") { $row = mysql_fetch_array($query); } if ($mode == "new") { $row = array(); } $out->add("<table><tr>\n"); if ($mode != "edit") { $out->add($lang->def("_FILE") . ":<br /><input type=\"file\" id=\"attach\" name=\"attach\" size=\"50\" /><br /><br />\n"); } $out->add($lang->def("_TITLE") . ": <input type=\"text\" size=\"40\" id=\"ttitle\" name=\"ftitle\" value=\"" . (isset($row["ftitle"]) ? $row["ftitle"] : '') . "\" /></td>\n"); $out->add("</tr><tr><td>" . $lang->def("_VERSION") . "\n "); $out->add("<input type=\"text\" size=\"35\" id=\"fver\" name=\"fver\" value=\"" . (isset($row["fver"]) ? $row["fver"] : '') . "\" /></td>\n"); $out->add("</tr><tr><td colspan=\"2\"><textarea rows=\"6\" cols=\"30\" id=\"fdesc\" name=\"fdesc\">\n"); $out->add(isset($row["fdesc"]) ? $row["fdesc"] : ''); $out->add("</textarea>\n"); $out->add("</td></tr></table><br />\n"); } if ($mode == "edit") { $label = $lang->def("_SAVE"); } if ($mode == "new") { $label = $lang->def("_SAVE"); } $out->add("<input type=\"hidden\" id=\"applychanges\" name=\"applychanges\" value=\"1\" />\n"); $out->add("<input class=\"button\" type=\"submit\" value=\"" . $label . "\" />\n"); $out->add("</form><br />\n"); //$out->add("<div align=\"center\"><b>[ <a href=\"index.php?modname=project&op=showprj&id=$id\">".$lang->def("_BACK")."</a> ]</b></div>\n"); $url = "index.php?modname=project&op=showprj&id=" . $id; $out->add(getBackUi($url, $lang->def('_BACK'))); $out->add('<br /></div>'); } else { $out->add("You can't access"); } }
/** * store the value inserted by a user into the database, if a entry exists it will be overwrite * * @param int $id_user the user * @param int $no_overwrite if a entry exists do not overwrite it * * @return bool true if operation success false otherwise * * @access public */ function store($id_user, $no_overwrite) { require_once _base_ . '/lib/lib.upload.php'; $path = '/appCore/field/'; $file = ''; sl_open_fileoperations(); if (isset($_FILES['field_' . $this->getFieldType()]['tmp_name'][$this->id_common]) && $_FILES['field_' . $this->getFieldType()]['tmp_name'][$this->id_common] != '') { $file = $id_user . '_' . $this->id_common . '_' . time() . '_' . $_FILES['field_' . $this->getFieldType()]['name'][$this->id_common]; if (!sl_upload($_FILES['field_' . $this->getFieldType()]['tmp_name'][$this->id_common], $path . $file)) { $error = 1; $file = ''; } } sl_close_fileoperations(); if (empty($_FILES['field_' . $this->getFieldType()]['name'][$this->id_common])) { return true; } $re_entry = sql_query("\r\n\t\tSELECT user_entry\r\n\t\tFROM " . $this->_getUserEntryTable() . "\r\n\t\tWHERE id_user = '******' AND\r\n\t\t\tid_common = '" . (int) $this->id_common . "' AND\r\n\t\t\tid_common_son = '0'"); $some_entry = mysql_num_rows($re_entry); list($old_file) = sql_fetch_row($re_entry); if ($some_entry) { if ($no_overwrite) { return true; } sl_unlink($path . $old_file); if (!sql_query("\r\n\t\t\tUPDATE " . $this->_getUserEntryTable() . "\r\n\t\t\tSET user_entry = '" . addslashes($file) . "'\r\n\t\t\tWHERE id_user = '******' AND\r\n\t\t\tid_common = '" . (int) $this->id_common . "' AND\r\n\t\t\tid_common_son = '0'")) { return false; } } else { if (!sql_query("\r\n\t\t\tINSERT INTO " . $this->_getUserEntryTable() . "\r\n\t\t\t( id_user, id_common, id_common_son, user_entry ) VALUES\r\n\t\t\t(\t'" . (int) $id_user . "',\r\n\t\t\t\t'" . (int) $this->id_common . "',\r\n\t\t\t\t'0',\r\n\t\t\t\t'" . $file . "')")) { return false; } } return true; }
function init_send() { checkPerm('view'); require_once _base_ . '/lib/lib.upload.php'; require_once _base_ . '/lib/lib.json.php'; $json = new Services_JSON(); $savefile = ''; $max_file = Get::req('file_number', DOTY_INT, 0); $savefile = array(); for ($i = 1; $i <= $max_file; $i++) { if ($_FILES['file_' . $i]['error'] == 0) { //$savefile = rand(0,100).'_'.time().'_'.$_FILES['file']['name']; $savefile[] = $_FILES['file_' . $i]['name']; $path = '/appCore/newsletter/'; sl_open_fileoperations(); sl_upload($_FILES['file_' . $i]['tmp_name'], $path . $_FILES['file_' . $i]['name']); sl_close_fileoperations(); } } $lang_list = Docebo::langManager()->getAllLangCode(); array_unshift($lang_list, "default", "any"); $sel_lang = importVar('sel_lang'); if ($sel_lang > 0) { $lang_selected = $lang_list[$sel_lang]; } else { if ($sel_lang === 0) { // Default language $lang_selected = getLanguage(); } else { $lang_selected = $sel_lang; } } $translate_table = getTranslateTable(); $sub = translateChr($_POST["sub"], $translate_table, true); $msg = translateChr($_POST["msg"], $translate_table, true); $fromemail = $_POST["fromemail"]; $send_type = $_POST["send_type"]; // ..who said spring cleanings have to be done in spring?? $qtxt = "DELETE FROM " . $GLOBALS["prefix_fw"] . "_newsletter WHERE stime < (DATE_SUB(NOW(), INTERVAL 1 DAY))"; $q = sql_query($qtxt); $qtxt = "DELETE FROM " . $GLOBALS["prefix_fw"] . "_newsletter_sendto WHERE stime < (DATE_SUB(NOW(), INTERVAL 1 DAY))"; $q = sql_query($qtxt); $qtxt = "INSERT INTO " . $GLOBALS["prefix_fw"] . "_newsletter (sub, msg, fromemail, language, send_type, stime) "; $qtxt .= "VALUES ('" . $sub . "', '" . $msg . "', '" . $fromemail . "', '" . $lang_selected . "', '" . $send_type . "', NOW())"; $q = sql_query($qtxt); //echo mysql_error(); $qtxt = "SELECT LAST_INSERT_ID() as last_id FROM " . $GLOBALS["prefix_fw"] . "_newsletter"; $q = sql_query($qtxt); $row = mysql_fetch_array($q); $last_id = $row["last_id"]; $qtxt = "UPDATE " . $GLOBALS["prefix_fw"] . "_newsletter SET id_send='" . $last_id . "' WHERE id='{$last_id}'"; $q = sql_query($qtxt); $url = "index.php?modname=public_newsletter_admin&op=selsendto&id_send=" . $last_id . "&load=1"; Util::jump_to($url); }
public function mod() { if (!$this->permissions['mod']) { $this->render('invalid', array('message' => $this->_getMessage('no permission'), 'back_url' => 'index.php?r=alms/label/show')); return; } $id_common_label = Get::req('id_common_label', DOTY_INT, 0); if (isset($_POST['undo'])) { Util::jump_to('index.php?r=alms/label/show'); } $all_languages = Docebo::langManager()->getAllLangCode(); $res = true; if (isset($_POST['update'])) { require_once _base_ . '/lib/lib.upload.php'; $path = '/appLms/label/'; if (isset($_POST['del_label_image'])) { $file_name = $this->model->getLabelFile($id_common_label); if ($file_name !== '' && sl_file_exists($path . $file_name)) { sl_open_fileoperations(); sl_unlink($path . $file_name); sl_close_fileoperations(); } $file_name = ''; } else { $file_name = $this->model->getLabelFile($id_common_label); } if ($_FILES['label_image']['error'] == 0) { $extension = end(explode('.', $_FILES['label_image']['name'])); $file_name = 'label_image_' . $id_common_label . '.' . $extension; sl_open_fileoperations(); $file_name_del = $this->model->getLabelFile($id_common_label); if ($file_name_del !== '' && sl_file_exists($path . $file_name_del)) { sl_unlink($path . $file_name_del); } sl_upload($_FILES['label_image']['tmp_name'], $path . $file_name); sl_close_fileoperations(); } foreach ($all_languages as $lang_code) { $title = Get::req($lang_code . '_title', DOTY_MIXED, ''); $description = Get::req($lang_code . '_description', DOTY_MIXED, ''); $tmp_res = $this->model->updateLabel($id_common_label, $lang_code, $title, $description, $file_name); if (!$tmp_res) { $res = false; } } if ($res) { Util::jump_to('index.php?r=alms/label/show&res=_ok_mod'); } Util::jump_to('index.php?r=alms/label/show&err=_err_mod'); } $label_info = $this->model->getLabelInfo($id_common_label); $params = array('model' => $this->model, 'all_languages' => $all_languages, 'label_info' => $label_info, 'id_common_label' => $id_common_label); $this->render('mod', $params); }
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'); }
function importToGroup_step2() { require_once _base_ . '/lib/lib.upload.php'; // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { $_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); Util::jump_to('index.php?modname=directory&op=listgroup&import_result=-1'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to('index.php?modname=directory&op=listgroup&import_result=-1'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to('index.php?modname=directory&op=listgroup&import_result=-1'); } } require_once _base_ . '/lib/lib.form.php'; $form = new Form(); $tree = getTitleArea($this->lang->def('_ORG_CHART_IMPORT_USERS', 'organization_chart'), 'directory_group') . '<div class="std_block">' . $form->openForm('directory_importgroupuser', 'index.php?modname=directory&op=import_groupuser_3', false, false, 'multipart/form-data'); $tree .= $form->openElementSpace(); require_once $GLOBALS['where_framework'] . '/modules/org_chart/import.org_chart.php'; $separator = importVar('import_separator', false, ','); $first_row_header = isset($_POST['import_first_row_header']) ? $_POST['import_first_row_header'] == 'true' : FALSE; $import_charset = importVar('import_charset', false, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportGroupUser(array('dbconn' => $GLOBALS['dbConn'])); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $tree .= $importer->getUIMap(); $tree .= $form->getHidden('filename', 'filename', $GLOBALS['where_files_relative'] . $path . $savefile); $tree .= $form->getHidden('import_first_row_header', 'import_first_row_header', $first_row_header ? 'true' : 'false'); $tree .= $form->getHidden('import_separator', 'import_separator', $separator); $tree .= $form->getHidden('import_charset', 'import_charset', $import_charset); $tree .= $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('next_importusers_3', 'next_importusers_3', $this->lang->def('_NEXT')) . $form->getButton('import_groupcancel', 'import_groupcancel', $this->lang->def('_UNDO')) . $form->closeButtonSpace(); $tree .= Form::closeForm() . '</div>'; $GLOBALS['page']->add($tree, 'content'); }
function confirmModCourseEdition() { checkPerm('mod'); require_once _base_ . '/lib/lib.upload.php'; require_once _base_ . '/lib/lib.multimedia.php'; $array_lang = Docebo::langManager()->getAllLangCode(); $array_lang[] = 'none'; list($id_course_edition) = each($_POST['mod_course_edition']); $path = '/appLms/' . Get::sett('pathcourse'); if (substr($path, -1) != '/' && substr($path, -1) != '\\') { $path = $path . '/'; } $error = 0; $show_level = 0; $file_edition_material = ''; $file_edition_othermaterial = ''; // manage file upload ----------------------------------------- if (is_array($_FILES) && !empty($_FILES) || is_array($_POST["file_to_del"])) { sl_open_fileoperations(); } if (is_array($_POST["file_to_del"])) { foreach ($_POST["file_to_del"] as $field_id => $old_file) { sl_unlink($path . $old_file); } } if (isset($_FILES['course_edition_material']) && $_FILES['course_edition_material']['tmp_name'] != '') { // delete old file if (isset($_POST["old_course_edition_material"]) && !empty($_POST["old_course_edition_material"])) { sl_unlink($path . $_POST["old_course_edition_material"]); } // upload new file $file_edition_material = 'usermaterial_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_material']['name']; if (!sl_upload($_FILES['course_edition_material']['tmp_name'], $path . $file_edition_material)) { $error = true; $file_edition_material = ''; } } elseif (!isset($_POST["file_to_del"]["course_edition_material"])) { // new not loaded use old file $file_edition_material = isset($_POST["old_course_edition_material"]) ? $_POST["old_course_edition_material"] : ""; } if (isset($_FILES['course_edition_othermaterial']) && $_FILES['course_edition_othermaterial']['tmp_name'] != '') { // delete old file if (isset($_POST["old_course_edition_othermaterial"]) && !empty($_POST["old_course_edition_othermaterial"])) { sl_unlink($path . $_POST["old_course_edition_othermaterial"]); } // upload new file $file_edition_othermaterial = 'otherusermaterial_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_othermaterial']['name']; if (!sl_upload($_FILES['course_edition_othermaterial']['tmp_name'], $path . $file_edition_othermaterial)) { $error = true; $file_edition_othermaterial = ''; } } else { if (!isset($_POST["file_to_del"]["course_edition_othermaterial"])) { // new not loaded use old file $file_edition_othermaterial = isset($_POST["old_course_edition_othermaterial"]) ? $_POST["old_course_edition_othermaterial"] : ""; } } sl_close_fileoperations(); // save mod in db --------------------------------------- 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") . "'"; } $date_begin = Format::dateDb($_POST['course_edition_date_begin'], 'date'); $date_end = Format::dateDb($_POST['course_edition_date_end'], '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']; } } $query_course_edition = "\r\n\tUPDATE " . $GLOBALS['prefix_lms'] . "_course_edition\r\n\tSET code \t\t\t\t= '" . $_POST['course_edition_code'] . "',\r\n\t\tname \t\t\t\t= '" . $_POST['course_edition_name'] . "',\r\n\t\tdescription \t\t= '" . $_POST['course_edition_descr'] . "',\r\n\t\tstatus \t\t\t\t= '" . (int) $_POST['course_edition_status'] . "',\r\n\r\n\t\timg_material \t\t='" . $file_edition_material . "',\r\n\t\timg_othermaterial \t='" . $file_edition_othermaterial . "',\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\tmin_num_subscribe \t= '" . (int) $_POST["min_num_subscribe"] . "',\r\n\t\tmax_num_subscribe \t= '" . (int) $_POST["max_num_subscribe"] . "',\r\n\t\tprice \t\t\t\t= '" . $_POST["edition_price"] . "',\r\n\t\tadvance \t\t\t= '" . $_POST["edition_advance"] . "',\r\n\r\n\t\tedition_type \t\t= '" . $_POST["edition_type"] . "',\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= " . $sub_start_date . ",\r\n\t\tsub_end_date \t\t= " . $sub_end_date . "\r\n\r\n\tWHERE idCourseEdition = '" . $id_course_edition . "'"; if (!sql_query($query_course_edition)) { $error = 1; if ($file_edition_material != '') { sl_unlink($path . $file_edition_material); } if ($file_edition_othermaterial != '') { sl_unlink($path . $file_edition_othermaterial); } } else { $acl_manager =& Docebo::user()->getAclManager(); $group = '/lms/course_edition/' . $id_course_edition . '/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"); } // -- Let's update the classroom occupation schedule if course type is classroom ---- if (hasClassroom($_POST["edition_type"])) { $old_date_begin = $_POST["old_date_begin"]; $old_date_end = $_POST["old_date_end"]; updateCourseTimtable($_POST["course_id"], $id_course_edition, $date_begin, $date_end, $old_date_begin, $old_date_end); } // ---------------------------------------------------------------------------------- } Util::jump_to('index.php?modname=course&op=course_list&course_category_status=' . importVar('course_category_status') . '&result=ok_course'); }
function save_file($file) { require_once _base_ . '/lib/lib.upload.php'; $path = '/appLms/' . Get::sett('pathforum'); if ($file['name'] != '') { $savefile = PUBLIC_FORUM_COURSE_ID . '_' . rand(0, 100) . '_' . time() . '_' . $file['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($file['tmp_name'], $path . $savefile)) { $savefile = ''; } sl_close_fileoperations(); return $savefile; } } return ''; }
function save_file($file) { require_once _base_ . '/lib/lib.upload.php'; $path = '/appLms/htmlpages/'; if ($file['name'] != '') { $savefile = $_SESSION['idCourse'] . '_' . rand(0, 100) . '_' . time() . '_' . $file['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($file['tmp_name'], $path . $savefile)) { $savefile = ''; } sl_close_fileoperations(); return $savefile; } } return ''; }
public function import_csv() { if (!$this->permissions['subscribe_course']) { $this->render('invalid', array('message' => $this->_getErrorMessage('no permission'), 'back_url' => 'index.php?r=' . $this->link_course . '/show')); return; } require_once _base_ . '/lib/lib.form.php'; //Step info $step = Get::req('step', DOTY_INT, 1); if (isset($_POST['next'])) { $step++; } if (isset($_POST['back'])) { $step--; } if (isset($_POST['undo'])) { $step = 0; } switch ($step) { case '0': Util::jump_to('index.php?r=' . $this->link_course . '/show'); break; case '1': $course_info = $this->model->getCourseInfoForSubscription(); $course_name = ($course_info['code'] !== '' ? '[' . $course_info['code'] . '] ' : '') . $course_info['name']; $params = array('table' => $tb, 'id_course' => $this->id_course, 'id_date' => $this->id_date, 'id_edition' => $this->id_edition, 'course_name' => $course_name, 'model' => $this->model); $this->render('import_csv_step_1', $params); break; case '2': require_once _lms_ . '/lib/lib.course.php'; require_once _base_ . '/lib/lib.upload.php'; require_once _adm_ . '/lib/lib.import.php'; $separator = Get::req('import_separator', DOTY_MIXED, ','); $first_row_header = Get::req('import_first_row_header', DOTY_BOOL, false); $import_charset = Get::req('import_charset', DOTY_MIXED, 'UTF-8'); $docebo_course = new DoceboCourse($this->id_course); $level_idst =& $docebo_course->getCourseLevel($this->id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($this->id_course); } $back_url = 'index.php?r=' . $this->link . '/show&id_course=' . $this->id_course . '&id_edition=' . $this->id_edition . '&id_date=' . $this->id_date; // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { $_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); jumpTo($back_url . '&err=_file_unspecified'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD', 'subscribe'); jumpTo($back_url . '&err=_err_upload'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD', 'subscribe'); jumpTo($back_url . '&err=_err_upload'); } } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $src->connect(); $user_added = 0; $user_error = 0; $user_not_needed = 0; $id_user_added = array(); $counter = 0; $course_info = $this->model->getCourseInfoForSubscription(); $can_subscribe = true; $max_num_subscribe = $course_info['max_num_subscribe']; $subscribe_method = $course_info['subscribe_method']; if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) { $limited_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.limit_course_subscribe'); $max_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.max_course_subscribe'); $direct_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.direct_course_subscribe'); if ($limited_subscribe == 'on') { $limited_subscribe = true; } else { $limited_subscribe = false; } if ($direct_subscribe == 'on') { $direct_subscribe = true; } else { $direct_subscribe = false; } } else { $limited_subscribe = false; $max_subscribe = 0; $direct_subscribe = true; } if (is_array($row = $src->get_first_row()) && !empty($row)) { $user_info = $this->acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; if ($can_subscribe) { require_once _lms_ . '/lib/lib.course.php'; $docebo_course = new DoceboCourse($this->id_course); $level_idst =& $docebo_course->getCourseLevel($this->id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($this->id_course); } if (!$direct_subscribe) { $waiting = 1; } else { $waiting = 0; } if (!$limited_subscribe || $max_subscribe) { //$this->acl_man->addToGroup($level_idst['3'], $id_user); $this->_addToCourseGroup($level_idst['3'], $id_user); if ($this->model->subscribeUser($id_user, '3', $waiting)) { $user_added++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_CORRECT'; $user_subscribed[] = $id_user; $max_subscribe--; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $this->id_course . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; $this->acl_man->removeFromGroup($level_idst['3'], $id_user); } } } } } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } $counter++; } while (is_array($row = $src->get_next_row()) && !empty($row)) { $user_info = $this->acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; if ($can_subscribe) { require_once _lms_ . '/lib/lib.course.php'; $docebo_course = new DoceboCourse($this->id_course); $level_idst =& $docebo_course->getCourseLevel($this->id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($this->id_course); } if (!$direct_subscribe) { $waiting = 1; } else { $waiting = 0; } if (!$limited_subscribe || $max_subscribe) { //$this->acl_man->addToGroup($level_idst['3'], $id_user); $this->_addToCourseGroup($level_idst['3'], $id_user); if ($this->model->subscribeUser($id_user, '3', $waiting)) { $user_added++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_CORRECT'; $user_subscribed[] = $id_user; $max_subscribe--; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $this->id_course . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; $this->acl_man->removeFromGroup($level_idst['3'], $id_user); } } } } } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } $counter++; } $src->close(); unset($row); require_once _base_ . '/lib/lib.table.php'; $type_h = array('align_center', 'align_center', 'align_center', 'align_center'); $cont_h = array(Lang::t('_USERNAME', 'subscribe'), Lang::t('_LASTNAME', 'subscribe'), Lang::t('_FIRSTNAME', 'subscribe'), Lang::t('_INSER_STATUS', 'subscribe')); $tb = new Table(false, Lang::t('_USER_SUBSCRIBED', 'subscribe'), Lang::t('_USER_SUBSCRIBED', 'subscribe')); $tb->addHead($cont_h, $type_h); while (list(, $id_user_added_detail) = each($id_user_added)) { $cont = array(); $user_info = $this->acl_man->getUser(false, $id_user_added_detail['id_user']); $cont[] = $this->acl_man->relativeId($user_info[ACL_INFO_USERID]); $cont[] = $user_info[ACL_INFO_FIRSTNAME]; $cont[] = $user_info[ACL_INFO_LASTNAME]; $cont[] = Lang::t($id_user_added_detail['status'], 'subscribe'); $tb->addBody($cont); } sl_open_fileoperations(); sl_unlink($GLOBALS['where_files_relative'] . $path . $savefile); sl_close_fileoperations(); $course_info = $this->model->getCourseInfoForSubscription(); $course_name = ($course_info['code'] !== '' ? '[' . $course_info['code'] . '] ' : '') . $course_info['name']; $params = array('table' => $tb, 'id_course' => $this->id_course, 'id_date' => $this->id_date, 'id_edition' => $this->id_edition, 'course_name' => $course_name, 'back_link' => getBackUi('index.php?r=' . $this->link . '/show&id_course=' . $this->id_course . '&id_edition=' . $this->id_edition . '&id_date=' . $this->id_date, Lang::t('_BACK', 'subscribe'))); $this->render('import_csv_step_2', $params); break; } }
public function importusers() { $base_url = 'index.php?r=' . $this->link . '/show'; //check permissions if (!$this->permissions['add_user']) { Util::jump_to($base_url); } $idOrg = Get::req('id', DOTY_INT, -1); if ($idOrg < 0) { return false; } $step = Get::req('step', DOTY_INT, 1); $params = array('id_org' => $idOrg, 'step' => $step); $undo = Get::req('import_groupcancel', DOTY_MIXED, false); if ($undo) { Util::jump_to($base_url); } switch ($step) { case 1: $params['orgchart_list'] = $this->model->getOrgChartDropdownList(Docebo::user()->getIdSt()); break; case 2: require_once _base_ . '/lib/lib.upload.php'; // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { //$_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); Util::jump_to($base_url . '&err=no_file'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists(Get::rel_path('base') . '/files' . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); //$_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($base_url . '&err=no_upload'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($base_url . '&err=no_upload'); } } require_once _adm_ . '/modules/org_chart/import.org_chart.php'; $separator_info = Get::req('import_separator', DOTY_STRING, ','); $separator = false; switch ($separator_info) { case "comma": $separator = ","; break; case "dotcomma": $separator = ";"; break; case "manual": $separator = Get::req('import_separator_manual', DOTY_STRING, ""); break; } $first_row_header = Get::req('import_first_row_header', DOTY_STRING, 'false') == 'true'; $import_charset = Get::req('import_charset', DOTY_STRING, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $pwd_force_change_policy = Get::req('pwd_force_change_policy', DOTY_STRING, 'do_nothing'); $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportUser(array('dbconn' => $GLOBALS['dbConn'], 'tree' => $idOrg, 'pwd_force_change_policy' => $pwd_force_change_policy, 'send_alert' => 0, 'insert_update' => 0)); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $params['UIMap'] = $importer->getUIMap(); $params['filename'] = $GLOBALS['where_files_relative'] . $path . $savefile; $params['first_row_header'] = $first_row_header; $params['separator'] = $separator; $params['import_charset'] = $import_charset; $params['pwd_force_change_policy'] = $pwd_force_change_policy; break; case 3: $filename = Get::req('filename', DOTY_STRING, ""); if ($filename == "") { return false; } $separator = Get::req('import_separator', DOTY_STRING, ','); $first_row_header = Get::req('import_first_row_header', DOTY_STRING, 'false') == 'true'; $import_charset = Get::req('import_charset', DOTY_STRING, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } require_once _adm_ . '/modules/org_chart/import.org_chart.php'; $src = new DeceboImport_SourceCSV(array('filename' => $filename, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportUser(array('dbconn' => $GLOBALS['dbConn'], 'tree' => $idOrg, 'pwd_force_change_policy' => Get::req('pwd_force_change_policy', DOTY_STRING, 'do_nothing'), 'send_alert' => Get::pReq('send_alert', DOTY_INT, 0), 'insert_update' => Get::pReq('insert_update', DOTY_INT, 0))); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $importer->parseMap(); $results = $importer->doImport(); $users = $dst->getNewImportedIdst(); //apply enroll rules if (!empty($users)) { $enrollrules = new EnrollrulesAlms(); $enrollrules->newRules('_NEW_IMPORTED_USER', $users, 'all', $idOrg); } $src->close(); $dst->close(); $buffer = ""; if (count($results) > 1) { require_once _base_ . '/lib/lib.table.php'; $buffer .= Lang::t('_ERRORS', 'admin_directory') . ': <b>' . (count($results) - 1) . '</b><br/>'; $table = new Table(Get::sett('visuItem', 25), Lang::t('_ERRORS', 'admin_directory'), Lang::t('_ERRORS', 'admin_directory')); $table->setColsStyle(array('', '')); $table->addHead(array(Lang::t('_ROW', 'admin_directory'), Lang::t('_DESCRIPTION', 'admin_directory'))); foreach ($results as $key => $err_val) { if ($key != 0) { $table->addBody(array($key, $err_val)); } } $buffer .= $table->getTable(); } if ($buffer === '') { $buffer = '<br/><br/>'; } $params['backUi'] = getBackUi($base_url, Lang::t('_BACK', 'standard')); $params['resultUi'] = Lang::t('_IMPORT', 'standard') . ': <b>' . ($first_row_header ? $results[0] - 1 : $results[0]) . '</b><br />'; $params['results'] = $results; $params['table'] = $buffer; // remove uploaded file: require_once _base_ . '/lib/lib.upload.php'; sl_open_fileoperations(); unlink($filename); sl_close_fileoperations(); break; } $this->render('importusers', $params); }
function save_file($file) { $path = '/common/comment/'; require_once _base_ . '/lib/lib.upload.php'; if ($file['name'] != '') { $savefile = rand(0, 100) . _ . time() . _ . $file['name']; if (!file_exists($path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($file['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); // errorCommunication(_ERROR_UPLOAD); return ''; } sl_close_fileoperations(); return $savefile; } else { // errorCommunication(_ERROR_UPLOAD); return ''; } } else { return ''; } }
function uploadImageWitouthResize($tmp_pathfile, $dst_pathfile) { sl_unlink($dst_pathfile); if (sl_upload($tmp_pathfile, $dst_pathfile)) { return 0; } return -2; }
/** * save the answer to the question in an proper format * * @param int $id_track the relative id_track * @param array $source source of the answer send by the user * @param bool $can_overwrite if the answer for this question exists and this is true, the old answer * is updated, else the old answer will be leaved * * @return bool true if success false otherwise * * @access public * @author Fabio Pirovano (fabio@docebo.com) */ function storeAnswer($id_track, &$source, $can_overwrite = false) { require_once _base_ . '/lib/lib.upload.php'; if ($this->userDoAnswer($id_track)) { if ($can_overwrite) { return $this->updateAnswer($id_track, $source); } else { return false; } } $savefile = ''; //save file-------------------------------------------------------- if (isset($_FILES['quest']['name'][$this->id]) && $_FILES['quest']['name'][$this->id] != '') { $path = '/appLms/' . Get::sett('pathtest'); $savefile = $_SESSION['idCourse'] . '_' . $this->id . '_' . mt_rand(0, 100) . time() . '_' . $_FILES['quest']['name'][$this->id]; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['quest']['tmp_name'][$this->id], $path . $savefile)) { $savefile = Lang::t('_QUEST_ERR_IN_UPLOAD'); } sl_close_fileoperations(); } else { $savefile = Lang::t('_QUEST_ERR_IN_UPLOAD'); } } //answer checked by the user $track_query = "\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_testtrack_answer ( idTrack, idQuest, idAnswer, score_assigned, more_info, user_answer ) \r\n\t\tVALUES (\r\n\t\t\t'" . (int) $id_track . "', \r\n\t\t\t'" . (int) $this->id . "', \r\n\t\t\t'0', \r\n\t\t\t'0', \r\n\t\t\t'" . addslashes($savefile) . "',\r\n\t\t\t1 )"; return sql_query($track_query); }
function importCode_step2() { require_once _base_ . '/lib/lib.upload.php'; require_once $GLOBALS['where_framework'] . '/lib/lib.import.php'; require_once _base_ . '/lib/lib.table.php'; if ($_FILES['file_import']['name'] == '') { Util::jump_to('index.php?modname=code&op=list&result=err'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); Util::jump_to('index.php?modname=code&op=list&result=err'); } sl_close_fileoperations(); } else { Util::jump_to('index.php?modname=directory&op=listgroup&import_result=-1'); } } $lang =& DoceboLanguage::createInstance('code'); $code_manager = new CodeManager(); $id_code_group = Get::req('id_code_group', DOTY_INT, '0'); cout(getTitleArea($lang->def('_CODE')) . '<div class="std_block">'); $separator = Get::req('import_separator', DOTY_MIXED, ','); $first_row_header = isset($_POST['import_first_row_header']) ? $_POST['import_first_row_header'] == 'true' : FALSE; $import_charset = Get::req('import_charset', DOTY_MIXED, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $src->connect(); $code_added = array(); $code_error = array(); $code_present = array(); if (is_array($row = $src->get_first_row()) && !empty($row)) { $code = addslashes($row[0]); $result = $code_manager->addCode($code, $id_code_group); if ($result === 'dup') { $code_present[] = $code; } elseif ($result) { $code_added[] = $code; } else { $code_error[] = $code; } } while (is_array($row = $src->get_next_row()) && !empty($row)) { $code = addslashes($row[0]); $result = $code_manager->addCode($code, $id_code_group); if ($result === 'dup') { $code_present[] = $code; } elseif ($result) { $code_added[] = $code; } else { $code_error[] = $code; } } $src->close(); unset($row); sl_open_fileoperations(); sl_unlink($path . $savefile); sl_close_fileoperations(); cout(getBackUi('index.php?modname=code&op=list', $lang->def('_BACK')) . '<br/>' . $lang->def('_CODE_ADDED') . ' : ' . count($code_added) . '<br/>' . $lang->def('_CODE_PRESENT') . ' : ' . count($code_present) . '<br/>' . $lang->def('_CODE_ERROR') . ' : ' . count($code_error) . '<br/>'); if (count($code_present)) { $tb = new Table(false, $lang->def('_CODE_PRESENT'), $lang->def('_CODE_PRESENT')); $type_h = array('align_center'); $cont_h = array($lang->def('_CODE')); $tb->setColsStyle($type_h); $tb->addHead($cont_h); foreach ($code_present as $code) { $cont = array(); $cont[] = stripslashes($code); $tb->addBody($cont); } cout($tb->getTable()); } if (count($code_error)) { $tb = new Table(false, $lang->def('_CODE_ERROR'), $lang->def('_CODE_ERROR')); $type_h = array('align_center'); $cont_h = array($lang->def('_CODE')); $tb->setColsStyle($type_h); $tb->addHead($cont_h); foreach ($code_error as $code) { $cont = array(); $cont[] = stripslashes($code); $tb->addBody($cont); } cout($tb->getTable()); } cout(getBackUi('index.php?modname=code&op=list', $lang->def('_BACK')) . '</div>'); }
function saveCurriculum($id_portfolio, $id_user, $file_descriptor) { $curriculum_file = ''; 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'; $curriculum_file = $id_user . '_' . mt_rand(0, 100) . '_' . time() . '_' . $file_descriptor['name']; if (!file_exists($GLOBALS['where_files_relative'] . $this->getCurriculumPath() . $curriculum_file)) { sl_open_fileoperations(); $upload = sl_upload($file_descriptor['tmp_name'], $this->getCurriculumPath() . $curriculum_file); sl_close_fileoperations(); if (!$upload) { return false; } } $sel_query = "\r\n\t\tSELECT curriculum_file \r\n\t\tFROM " . $this->getTableCurriculum() . " \r\n\t\tWHERE id_portfolio = '" . $id_portfolio . "' \r\n\t\t\tAND id_user = '******' "; if (!($re_curriculum = $this->_query($sel_query))) { die('table problem ' . mysql_error()); return false; } if (!mysql_num_rows($re_curriculum)) { $query = "\r\n\t\t\tINSERT INTO " . $this->getTableCurriculum() . " \r\n\t\t\t( id_portfolio, id_user, curriculum_file, update_date ) VALUES \r\n\t\t\t(\t'" . $id_portfolio . "', \r\n\t\t\t\t'" . $id_user . "', \r\n\t\t\t\t'" . $curriculum_file . "',\r\n\t\t\t\t'" . date("Y-m-d H:i:s") . "' )"; } else { list($old_curriculum_file) = sql_fetch_row($re_curriculum); sl_unlink($old_curriculum_file); $query = "\r\n\t\t\tUPDATE " . $this->getTableCurriculum() . "\r\n\t\t\tSET curriculum_file = '" . $curriculum_file . "',\r\n\t\t\t\tupdate_date = '" . date("Y-m-d H:i:s") . "'\r\n\t\t\tWHERE id_portfolio = '" . $id_portfolio . "' \r\n\t\t\t\tAND id_user = '******'"; } if (!$this->_query($query)) { die('table problem 2'); return false; } return true; }
function saveFile($area, $file_descriptor) { $file_name = ''; if (!isset($file_descriptor['error'])) { return $file_name; } if ($file_descriptor['error'] != UPLOAD_ERR_OK) { return $file_name; } if ($file_descriptor['name'] == '') { return $file_name; } require_once _base_ . '/lib/lib.upload.php'; // if the area need custom management the file can be manipulated here switch ($area) { default: $savefile = $this->id_user . '_' . mt_rand(0, 100) . '_' . time() . '_' . $file_descriptor['name']; if (!file_exists($GLOBALS['where_files_relative'] . $this->getFilePath() . $savefile)) { sl_open_fileoperations(); if (sl_upload($file_descriptor['tmp_name'], $this->getFilePath() . $savefile)) { $file_name = $savefile; } sl_close_fileoperations(); } } return $file_name; }
function upfiles() { checkPerm('mod'); $lang =& DoceboLanguage::createInstance('course'); require_once _base_ . '/lib/lib.upload.php'; if ($_POST['title'] == "") { $_POST['title'] = $lang->def('_NOTITLE'); } $savefile = ''; if ($_FILES['attach']['name'] != '') { 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) $_POST['id_file'] . "'")); $GLOBALS['course_descriptor']->subFileToUsedSpace($GLOBALS['where_files_relative'] . _PATH_COURSE . $old_file); $quota = $GLOBALS['course_descriptor']->getQuotaLimit(); $used = $GLOBALS['course_descriptor']->getUsedSpace(); sl_unlink(_PATH_COURSE . $old_file); if (Util::exceed_quota($_FILES['attach']['tmp_name'], $quota, $used)) { $GLOBALS['page']->add(getErrorUi($lang->def('_QUOTA_EXCEDED'))); return; } $savefile = $_SESSION['idCourse'] . '_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['attach']['name']; if (!file_exists($GLOBALS['where_files_relative'] . _PATH_COURSE . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['attach']['tmp_name'], _PATH_COURSE . $savefile)) { sl_close_fileoperations(); $GLOBALS['page']->add(getErrorUi($lang->def('_ERROR_UPLOAD'))); return; } sl_close_fileoperations(); } else { $GLOBALS['page']->add(getErrorUi($lang->def('_ERROR_UPLOAD'))); return; } } $insertQuery = "\r\n\tUPDATE " . $GLOBALS['prefix_lms'] . "_course_file \r\n\tSET id_course = '" . (int) $_SESSION["idCourse"] . "', \r\n\t\ttitle = '" . $_POST['title'] . "'"; if ($savefile != '') { $insertQuery .= ", path = '" . $savefile . "'"; } $insertQuery .= " WHERE id_file = '" . (int) $_POST['id_file'] . "'"; if (!sql_query($insertQuery)) { $GLOBALS['page']->add(getErrorUi($lang->def('_OPERATION_FAILURE'))); sl_unlink(_PATH_COURSE . $savefile); return; } $GLOBALS['course_descriptor']->addFileToUsedSpace($GLOBALS['where_files_relative'] . _PATH_COURSE . $savefile); Util::jump_to('index.php?modname=course&op=infocourse'); }
function ins_personal_media() { if (!canAccessPersonalMedia()) { die("You can't access!"); } include_once _base_ . '/lib/lib.upload.php'; include_once _base_ . '/lib/lib.multimedia.php'; $url = getPopupBaseUrl() . "&op=personal"; $user_id = Docebo::user()->getIdSt(); $is_streaming = FALSE; if (isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])) { $fname = $_FILES["file"]["name"]; $size = $_FILES["file"]["size"]; $tmp_fname = $_FILES["file"]["tmp_name"]; $real_fname = $user_id . '_' . mt_rand(0, 100) . '_' . time() . '_' . $fname; } else { $media_url = $_POST["media_url"]; $fname = ""; $real_fname = ""; if (!empty($media_url)) { $is_streaming = TRUE; if (isYouTube($media_url)) { $fname = str_replace("http://www.", "", strtolower($media_url)); } else { $fname = basename($media_url); $fname = strpos($fname, "?") !== FALSE ? preg_replace("/(\\?.*)/", "", $fname) : $fname; } } } if (!$is_streaming) { $valid_ext = array("png", "mng", "gif", "jpg", "jpeg", "wmv", "flv", "mov", "mp3", "swf", "mp4"); $ext = strtolower(end(explode(".", $fname))); if (!in_array($ext, $valid_ext)) { Util::jump_to($url . '&result=invalid_ext'); } sl_open_fileoperations(); $f1 = sl_upload($tmp_fname, _USER_FPATH_INTERNAL . $real_fname); sl_close_fileoperations(); if (!$f1) { // upload error Util::jump_to($url . '&result=upload_err'); } } $qtxt = "INSERT INTO " . $GLOBALS["prefix_fw"] . "_user_file "; $qtxt .= " ( user_idst, type, fname, real_fname, media_url, size, uldate ) VALUES "; $qtxt .= " ('" . $user_id . "', 'image', '" . $fname . "', '" . addslashes($real_fname) . "', '" . $media_url . "', '" . $size . "', NOW())"; $q = sql_query($qtxt); Util::jump_to($url . '&result=' . ($q ? 'upload_ok' : 'upload_err')); }
function insitem() { //checkPerm( 'view', FALSE, 'storage' ); require_once _base_ . '/lib/lib.upload.php'; require_once _base_ . '/addons/pclzip/pclzip.lib.php'; require_once dirname(__FILE__) . '/RendererDb.php'; require_once dirname(__FILE__) . '/CPManager.php'; $back_url = urldecode($_POST['back_url']); // there is a file? if ($_FILES['attach']['name'] == '') { $_SESSION['last_error'] = _FILEUNSPECIFIED; Util::jump_to('' . $back_url . '&create_result=0'); } $path = str_replace('\\', '/', '/appLms/' . Get::sett('pathscorm')); $savefile = getLogUserId() . '_' . rand(0, 100) . '_' . time() . '_' . $_FILES['attach']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['attach']['tmp_name'], $path . $savefile)) { //if( !move_uploaded_file($_FILES['attach']['tmp_name'], $GLOBALS['where_files_relative'].$path.$savefile ) ) { sl_close_fileoperations(); $_SESSION['last_error'] = _ERROR_UPLOAD; Util::jump_to('' . $back_url . '&create_result=0'); } } else { sl_close_fileoperations(); $_SESSION['last_error'] = _ERROR_UPLOAD; Util::jump_to('' . $back_url . '&create_result=0'); } // compute filepath $filepath = $path . $savefile . STRPOSTCONTENT; // extract zip file $zip = new PclZip($path . $savefile); // check disk quota -------------------------------------------------- if (isset($_SESSION['idCourse']) && defined("LMS")) { $zip_content = $zip->listContent(); $zip_extracted_size = 0; while (list(, $file_info) = each($zip_content)) { $zip_extracted_size += $file_info['size']; } $quota = $GLOBALS['course_descriptor']->getQuotaLimit(); $used = $GLOBALS['course_descriptor']->getUsedSpace(); if (Util::exceed_quota(false, $quota, $used, $zip_extracted_size)) { sl_unlink($path . $savefile); $_SESSION['last_error'] = Lang::t('_QUOTA_EXCEDED'); Util::jump_to('' . $back_url . '&create_result=0'); } $GLOBALS['course_descriptor']->addFileToUsedSpace(false, $zip_extracted_size); } // extract zip ------------------------------------------------------ $zip->extract(PCLZIP_OPT_PATH, $filepath); if ($zip->errorCode() != PCLZIP_ERR_NO_ERROR && $zip->errorCode() != 1) { sl_unlink($path . $savefile); $_SESSION['last_error'] = _ERROR_UPLOAD; sl_close_fileoperations(); Util::jump_to('' . $back_url . '&create_result=0'); } /* remove zip file */ sl_unlink($path . $savefile); sl_close_fileoperations(); $cpm = new CPManager(); // try to open content package if (!$cpm->Open($GLOBALS['where_files_relative'] . $filepath)) { $_SESSION['last_error'] = 'Error: ' . $cpm->errText . ' [' . $cpm->errCode . ']'; Util::jump_to('' . $back_url . '&create_result=0'); } // and parse the manifest if (!$cpm->ParseManifest()) { $_SESSION['last_error'] = 'Error: ' . $cpm->errText . ' [' . $cpm->errCode . ']'; Util::jump_to('' . $back_url . '&create_result=0'); } // create entry in content package table $query = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_scorm_package" . " (idpackage,idProg,path,defaultOrg,idUser,scormVersion) VALUES" . " ('" . addslashes($cpm->identifier) . "','0','" . $savefile . STRPOSTCONTENT . "','" . addslashes($cpm->defaultOrg) . "','" . (int) getLogUserId() . "','" . $cpm->scorm_version . "')"; if (!($result = sql_query($query))) { $_SESSION['last_error'] = _OPERATION_FAILURE; Util::jump_to('' . $back_url . '&create_result=0'); } $idscorm_package = mysql_insert_id(); // create the n entries in resources table for ($i = 0; $i < $cpm->GetResourceNumber(); $i++) { $info = $cpm->GetResourceInfo($cpm->GetResourceIdentifier($i)); $query = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_scorm_resources (idsco,idscorm_package,scormtype,href)" . " VALUES ('" . addslashes($info['identifier']) . "','" . (int) $idscorm_package . "','" . $info['scormtype'] . "','" . addslashes($info['href']) . "')"; $result = sql_query($query); if (!$result) { $_SESSION['last_error'] = _OPERATION_FAILURE; Util::jump_to('' . $back_url . '&create_result=0'); } else { if (mysql_affected_rows() == 0) { $_SESSION['last_error'] = _OPERATION_FAILURE; Util::jump_to('' . $back_url . '&create_result=0'); } } } $rdb = new RendererDb($GLOBALS['dbConn'], $GLOBALS['prefix_lms'], $idscorm_package); $orgElems = $cpm->orgElems; // save all organizations for ($iOrg = 0; $iOrg < $orgElems->getLength(); $iOrg++) { $org = $orgElems->item($iOrg); $cpm->RenderOrganization($org->getAttribute('identifier'), $rdb); } if ($_POST['lesson_resources'] == 'import' || $cpm->defaultOrg == '-resource-') { // save flat organization with resources $cpm->RenderOrganization('-resource-', $rdb); } $so = new Scorm_Organization($cpm->defaultOrg, $idscorm_package, $GLOBALS['dbConn']); if ($so->err_code > 0) { $_SESSION['last_error'] = 'Error: ' . $so->getErrorText() . ' [' . $so->getErrorCode() . ']'; Util::jump_to('' . $back_url . '&create_result=0'); } else { //Util::jump_to( ''.$back_url.'&id_lo='.$so->idscorm_organization.'&create_result=1' ); Util::jump_to('' . $back_url . '&id_lo=' . $idscorm_package . '&create_result=2'); } }
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; }
function loadImportUsers2() { require_once _base_ . '/lib/lib.upload.php'; $tdb =& $this->tdb; $folder = $tdb->getFolderById($this->getSelectedFolderId()); $back_url = 'index.php?modname=directory&op=org_chart'; // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { $_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); Util::jump_to($back_url . '&import_result=-1'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($back_url . '&import_result=-1'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($back_url . '&create_result=-1'); } } require_once _base_ . '/lib/lib.form.php'; $form = new Form(); $tree = $form->getFormHeader($this->lang->def('_ORG_CHART_IMPORT_USERS')); $tree .= $form->openElementSpace(); $tree .= $this->printState(); require_once dirname(__FILE__) . '/import.org_chart.php'; $separator = isset($_POST['import_separator']) ? $_POST['import_separator'] : ','; $first_row_header = isset($_POST['import_first_row_header']) ? $_POST['import_first_row_header'] == 'true' : FALSE; $import_charset = isset($_POST['import_charset']) ? $_POST['import_charset'] : 'UTF-8'; if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportUser(array('dbconn' => $GLOBALS['dbConn'], 'tree' => &$this)); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $tree .= $importer->getUIMap(); $tree .= $form->getHidden($this->id . '_filename', $this->id . '[filename]', $GLOBALS['where_files_relative'] . $path . $savefile); $tree .= $form->getHidden('import_first_row_header', 'import_first_row_header', $first_row_header ? 'true' : 'false'); $tree .= $form->getHidden('import_separator', 'import_separator', $separator); $tree .= $form->getHidden('import_charset', 'import_charset', $import_charset); $tree .= $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('next2_importusers' . $this->id, $this->id . '[next2_importusers]', $this->lang->def('_SAVE')) . $form->getButton($this->_getCancelId(), $this->_getCancelId(), $this->lang->def('_UNDO')) . $form->closeButtonSpace(); return $tree; }