/** * Constructor */ public function HTML_QuickForm_datepicker($elementName = null, $elementLabel = null, $attributes = null, $optionIncrement = null) { $js_form_name = api_get_unique_id(); HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_appendName = true; $this->_type = 'datepicker'; $popup_link = '<a href="javascript:openCalendar(\'' . $js_form_name . '\',\'' . $elementName . '\')"> <img src="' . api_get_path(WEB_IMG_PATH) . 'calendar_select.gif" style="vertical-align:middle;" alt="Select Date" /></a>'; $hour_minute_devider = get_lang("HourMinuteDivider"); $special_chars = array('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' '); foreach ($special_chars as $char) { $popup_link = str_replace($char, "\\" . $char, $popup_link); $hour_minute_devider = str_replace($char, "\\" . $char, $hour_minute_devider); } $lang_code = api_get_language_isocode(); // If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation if (!array_key_exists($lang_code, $this->_locale)) { $this->_locale[$lang_code]['months_long'] = api_get_months_long(); } $this->_options['format'] = 'dFY ' . $popup_link . ' H ' . $hour_minute_devider . ' i'; $this->_options['minYear'] = date('Y') - 5; $this->_options['maxYear'] = date('Y') + 10; $this->_options['language'] = $lang_code; if (isset($optionIncrement)) { $this->_options['optionIncrement']['i'] = intval($optionIncrement); } }
/** * @param User $user */ public static function sendResetEmail(User $user) { //if (null === $user->getConfirmationToken()) { $uniqueId = api_get_unique_id(); $user->setConfirmationToken($uniqueId); $user->setPasswordRequestedAt(new \DateTime()); Database::getManager()->persist($user); Database::getManager()->flush(); $url = api_get_path(WEB_CODE_PATH) . 'auth/reset.php?token=' . $uniqueId; $mailTemplate = new Template(null, false, false, false, false, false); $mailTemplate->assign('complete_user_name', $user->getCompleteName()); $mailTemplate->assign('link', $url); $mailLayout = $mailTemplate->get_template('mail/reset_password.tpl'); $mailSubject = get_lang('ResetPasswordInstructions'); $mailBody = $mailTemplate->fetch($mailLayout); api_mail_html($user->getCompleteName(), $user->getEmail(), $mailSubject, $mailBody); Display::addFlash(Display::return_message(get_lang('CheckYourEmailAndFollowInstructions'))); //} }
/** * Write a course and all its resources to a zip-file. * @return string A pointer to the zip-file */ static function write_course($course) { $perm_dirs = api_get_permissions_for_new_directories(); CourseArchiver::clean_backup_dir(); // Create a temp directory $tmp_dir_name = 'CourseArchiver_' . api_get_unique_id(); $backup_dir = api_get_path(SYS_ARCHIVE_PATH) . $tmp_dir_name . '/'; // All course-information will be stored in course_info.dat $course_info_file = $backup_dir . 'course_info.dat'; $zip_dir = api_get_path(SYS_ARCHIVE_PATH); $user = api_get_user_info(); $date = new DateTime(api_get_local_time()); $zip_file = $user['user_id'] . '_' . $course->code . '_' . $date->format('Ymd-His') . '.zip'; $php_errormsg = ''; $res = @mkdir($backup_dir, $perm_dirs); if ($res === false) { //TODO set and handle an error message telling the user to review the permissions on the archive directory error_log(__FILE__ . ' line ' . __LINE__ . ': ' . (ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini') . ' - This error, occuring because your archive directory will not let this script write data into it, will prevent courses backups to be created', 0); } // Write the course-object to the file $fp = @fopen($course_info_file, 'w'); if ($fp === false) { error_log(__FILE__ . ' line ' . __LINE__ . ': ' . (ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0); } $res = @fwrite($fp, base64_encode(serialize($course))); if ($res === false) { error_log(__FILE__ . ' line ' . __LINE__ . ': ' . (ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0); } $res = @fclose($fp); if ($res === false) { error_log(__FILE__ . ' line ' . __LINE__ . ': ' . (ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0); } // Copy all documents to the temp-dir if (isset($course->resources[RESOURCE_DOCUMENT]) && is_array($course->resources[RESOURCE_DOCUMENT])) { foreach ($course->resources[RESOURCE_DOCUMENT] as $document) { if ($document->file_type == DOCUMENT) { $doc_dir = $backup_dir . $document->path; @mkdir(dirname($doc_dir), $perm_dirs, true); if (file_exists($course->path . $document->path)) { copy($course->path . $document->path, $doc_dir); } } else { @mkdir($backup_dir . $document->path, $perm_dirs, true); } } } // Copy all scorm documents to the temp-dir if (isset($course->resources[RESOURCE_SCORM]) && is_array($course->resources[RESOURCE_SCORM])) { foreach ($course->resources[RESOURCE_SCORM] as $document) { $doc_dir = dirname($backup_dir . $document->path); @mkdir($doc_dir, $perm_dirs, true); FileManager::copyDirTo($course->path . $document->path, $doc_dir, false); } } // Copy calendar attachments. if (isset($course->resources[RESOURCE_EVENT]) && is_array($course->resources[RESOURCE_EVENT])) { $doc_dir = dirname($backup_dir . '/upload/calendar/'); @mkdir($doc_dir, $perm_dirs, true); FileManager::copyDirTo($course->path . 'upload/calendar/', $doc_dir, false); } // Copy Learning path author image. if (isset($course->resources[RESOURCE_LEARNPATH]) && is_array($course->resources[RESOURCE_LEARNPATH])) { $doc_dir = dirname($backup_dir . '/upload/learning_path/'); @mkdir($doc_dir, $perm_dirs, true); FileManager::copyDirTo($course->path . 'upload/learning_path/', $doc_dir, false); } // Copy announcements attachments. if (isset($course->resources[RESOURCE_ANNOUNCEMENT]) && is_array($course->resources[RESOURCE_ANNOUNCEMENT])) { $doc_dir = dirname($backup_dir . '/upload/announcements/'); @mkdir($doc_dir, $perm_dirs, true); FileManager::copyDirTo($course->path . 'upload/announcements/', $doc_dir, false); } // Copy work folders (only folders) if (isset($course->resources[RESOURCE_WORK]) && is_array($course->resources[RESOURCE_WORK])) { $doc_dir = dirname($backup_dir . '/upload/work/'); @mkdir($doc_dir, $perm_dirs, true); // @todo: adjust to only create subdirs, but not copy files FileManager::copyDirTo($course->path . 'upload/work/', $doc_dir, false); } // Zip the course-contents $zip = new PclZip($zip_dir . $zip_file); $zip->create($zip_dir . $tmp_dir_name, PCLZIP_OPT_REMOVE_PATH, $zip_dir . $tmp_dir_name . '/'); //$zip->deleteByIndex(0); // Remove the temp-dir. api_rmdirr($backup_dir); return $zip_file; }
$urlFile = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document/audio/' . $lp_item->audio . '?' . api_get_cidreq(); if (!file_exists($file)) { $file = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio; $urlFile = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio . '?' . api_get_cidreq(); } } $page = $_SESSION['oLP']->build_action_menu(true); $page .= '<div class="row" style="overflow:hidden">'; $page .= '<div id="lp_sidebar" class="col-md-4">'; $page .= $_SESSION['oLP']->return_new_tree(null, true); // Show the template list. $page .= '</div>'; $recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice')); $page .= '<div id="doc_form" class="col-md-8">'; $tpl = new Template(null); $tpl->assign('unique_file_id', api_get_unique_id()); $tpl->assign('course_code', api_get_course_id()); $tpl->assign('php_session_id', session_id()); $tpl->assign('filename', $lp_item->get_title() . '_nano.wav'); $tpl->assign('enable_nanogong', api_get_setting('enable_nanogong') == 'true' ? 1 : 0); $tpl->assign('enable_wami', api_get_setting('enable_wami_record') == 'true' ? 1 : 0); $tpl->assign('cur_dir_path', '/audio'); $tpl->assign('lp_item_id', $lp_item_id); $tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir'])); $recordVoiceForm .= $tpl->fetch('default/learnpath/record_voice.tpl'); $form->addElement('header', get_lang('Or')); $form->addElement('header', get_lang('AudioFile')); $form->addElement('html', sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title())); if (!empty($file)) { $audioPlayer = '<div id="preview">' . Display::getMediaPlayer($file, array('url' => $urlFile)) . "</div>"; $form->addElement('label', get_lang('Listen'), $audioPlayer);
<?php /* For licensing terms, see /license.txt */ //require_once '../inc/global.inc.php'; $survey_id = isset($_REQUEST['i']) ? intval($_REQUEST['i']) : null; if (empty($survey_id)) { api_not_allowed(true); } if (!survey_manager::survey_generation_hash_available()) { api_not_allowed(true); } $course_info = api_get_course_info_by_id($_REQUEST['c']); $hash_is_valid = survey_manager::validate_survey_hash($survey_id, $_REQUEST['c'], $_REQUEST['s'], $_REQUEST['g'], $_REQUEST['h']); if ($hash_is_valid && $course_info) { $survey_data = survey_manager::get_survey($survey_id, null, $course_info['code']); $invitation_code = api_get_unique_id(); $params = array('c_id' => $_REQUEST['c'], 'session_id' => $_REQUEST['s'], 'user' => $invitation_code, 'survey_code' => $survey_data['code'], 'invitation_code' => $invitation_code, 'invitation_date' => api_get_utc_datetime()); $invitation_id = SurveyUtil::save_invitation($params); if ($invitation_id) { $link = api_get_path(WEB_CODE_PATH) . 'survey/fillsurvey.php?invitationcode=' . $invitation_code . '&course=' . $course_info['code']; header('Location: ' . $link); exit; } } else { api_not_allowed(true); }
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true); $parent_id = $document_data['parent_id']; } if (isset($document_data) && $document_data['path'] == '/certificates') { $is_certificate_mode = true; } if (!$parent_id) { $parent_id = 0; } $current_folder_id = $document_id; // Show preview if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) { if (isset($_GET['set_preview'])) { // Generate document HTML $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), api_get_course_id(), api_get_session_id(), true); $filename = 'certificate_preview/' . api_get_unique_id() . '.png'; $qr_code_filename = api_get_path(SYS_ARCHIVE_PATH) . $filename; $temp_folder = api_get_path(SYS_ARCHIVE_PATH) . 'certificate_preview'; if (!is_dir($temp_folder)) { mkdir($temp_folder, api_get_permissions_for_new_directories()); } $qr_code_web_filename = api_get_path(WEB_ARCHIVE_PATH) . $filename; $certificate = new Certificate(); $text = $certificate->parse_certificate_variables($content_html['variables']); $result = $certificate->generate_qr($text, $qr_code_filename); $new_content_html = $content_html['content']; $path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/images/gallery'; $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html); $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document'; $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html); $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
$urlFile = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document/audio/' . $lp_item->audio . '?' . api_get_cidreq(); if (!file_exists($file)) { $file = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio; $urlFile = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio . '?' . api_get_cidreq(); } } $page = $learnPath->build_action_menu(true); $page .= '<div class="row" style="overflow:hidden">'; $page .= '<div id="lp_sidebar" class="col-md-4">'; $page .= $learnPath->return_new_tree(null, true); // Show the template list. $page .= '</div>'; $recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice')); $page .= '<div id="doc_form" class="col-md-8">'; $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig(); $tpl->addGlobal('unique_file_id', api_get_unique_id()); $tpl->addGlobal('course_code', api_get_course_id()); $tpl->addGlobal('php_session_id', session_id()); $tpl->addGlobal('filename', $lp_item->get_title() . '_nano.wav'); $tpl->addGlobal('enable_nanogong', api_get_setting('document.enable_nanogong') == 'true' ? 1 : 0); $tpl->addGlobal('enable_wami', api_get_setting('document.enable_wami_record') == 'true' ? 1 : 0); $tpl->addGlobal('cur_dir_path', '/audio'); $tpl->addGlobal('lp_item_id', $lp_item_id); $tpl->addGlobal('lp_dir', api_remove_trailing_slash($lpPathInfo['dir'])); $recordVoiceForm .= $tpl->render('@template_style/learnpath/record_voice.html.twig'); $form->addElement('header', get_lang('Or')); $form->addElement('header', get_lang('AudioFile')); $form->addElement('html', sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title())); if (!empty($file)) { $audioPlayer = '<div id="preview">' . Display::getMediaPlayer($file, array('url' => $urlFile)) . "</div>"; $form->addElement('label', get_lang('Listen'), $audioPlayer);
} $query = Database::query($sql); //add tem to the zip file while ($not_deleted_file = Database::fetch_assoc($query)) { $user_info = api_get_user_info($not_deleted_file['insert_user_id']); $insert_date = api_get_local_time($not_deleted_file['insert_date']); $insert_date = str_replace(array(':', '-', ' '), '_', $insert_date); $filename = $insert_date . '_' . $user_info['username'] . '_' . basename($not_deleted_file['title']); if (file_exists($sys_course_path . $_course['path'] . '/' . $not_deleted_file['url']) && !empty($not_deleted_file['url'])) { $files[basename($not_deleted_file['url'])] = $filename; $zip_folder->add($sys_course_path . $_course['path'] . '/' . $not_deleted_file['url'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path . $_course['path'] . '/work', PCLZIP_CB_PRE_ADD, 'my_pre_add_callback'); } //Convert texts in html files if ($not_deleted_file['contains_file'] == 0) { $filename = trim($filename) . ".html"; $work_temp = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . '_' . $filename; file_put_contents($work_temp, $not_deleted_file['description']); $files[basename($work_temp)] = $filename; $zip_folder->add($work_temp, PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_ARCHIVE_PATH), PCLZIP_CB_PRE_ADD, 'my_pre_add_callback'); @unlink($work_temp); } } if (!empty($files)) { //logging event_download(basename($work_data['title']) . '.zip (folder)'); //start download of created file $name = basename($work_data['title']) . '.zip'; if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) { DocumentManager::file_send_for_download($temp_zip_file, true, $name); @unlink($temp_zip_file); exit;
/** * Manages all the unzipping process of an uploaded document * This uses the item_property table for properties of documents * * @author Hugues Peeters <*****@*****.**> * @author Bert Vanderkimpen * * @param array $courseInfo * @param array $userInfo * @param array $uploaded_file - follows the $_FILES Structure * @param string $upload_path - destination of the upload. * This path is to append to $base_work_dir * @param string $base_work_dir - base working directory of the module * @param int $maxFilledSpace - amount of bytes to not exceed in the base * working directory * @param int $sessionId * @param int $groupId * @param boolean $output Optional. If no output not wanted on success, set to false. * * @return boolean true if it succeeds false otherwise */ function unzip_uploaded_document($courseInfo, $userInfo, $uploaded_file, $uploadPath, $base_work_dir, $maxFilledSpace, $sessionId = 0, $groupId = 0, $output = true) { $zip = new PclZip($uploaded_file['tmp_name']); // Check the zip content (real size and file extension) $zip_content_array = (array) $zip->listContent(); $realSize = 0; foreach ($zip_content_array as &$this_content) { $realSize += $this_content['size']; } if (!DocumentManager::enough_space($realSize, $maxFilledSpace)) { Display::display_error_message(get_lang('UplNotEnoughSpace')); return false; } $folder = api_get_unique_id(); $destinationDir = api_get_path(SYS_ARCHIVE_PATH) . $folder; mkdir($destinationDir, api_get_permissions_for_new_directories(), true); /* Uncompress zip file*/ // We extract using a callback function that "cleans" the path $zip->extract(PCLZIP_OPT_PATH, $destinationDir, PCLZIP_CB_PRE_EXTRACT, 'clean_up_files_in_zip', PCLZIP_OPT_REPLACE_NEWER); // Add all documents in the unzipped folder to the database add_all_documents_in_folder_to_database($courseInfo, $userInfo, $base_work_dir, $destinationDir, $sessionId, $groupId, $output, array('path' => $uploadPath)); if (is_dir($destinationDir)) { rmdirr($destinationDir); } return true; }
/** * Downloads all user files per user * @param int $userId * @param array $courseInfo * @return bool */ function downloadAllFilesPerUser($userId, $courseInfo) { $userInfo = api_get_user_info($userId); if (empty($userInfo) || empty($courseInfo)) { return false; } require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; $tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip"; $coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work/'; $zip = new PclZip($tempZipFile); $workPerUser = getWorkPerUser($userId); if (!empty($workPerUser)) { $files = array(); foreach ($workPerUser as $work) { $work = $work['work']; foreach ($work->user_results as $userResult) { if (empty($userResult['url']) || empty($userResult['contains_file'])) { continue; } $data = getFileContents($userResult['id'], $courseInfo); if (!empty($data) && isset($data['path'])) { $files[basename($data['path'])] = array( 'title' => $data['title'], 'path' => $data['path'] ); } } } if (!empty($files)) { Session::write('files', $files); foreach ($files as $data) { $zip->add( $data['path'], PCLZIP_OPT_REMOVE_PATH, $coursePath, PCLZIP_CB_PRE_ADD, 'preAddAllWorkStudentCallback' ); } } // Start download of created file $name = basename(replace_dangerous_char($userInfo['complete_name'])).'.zip'; event_download($name.'.zip (folder)'); if (Security::check_abs_path($tempZipFile, api_get_path(SYS_ARCHIVE_PATH))) { DocumentManager::file_send_for_download($tempZipFile, true, $name); @unlink($tempZipFile); exit; } } exit; }
/** * Generates the filename with the next format: * (course_id)/(session_id)/(user_id)/(exercise_id)/(question_id)/(exe_id) * * @return string */ public function generate_filename() { if (!empty($this->params)) { //filename //course_id/session_id/user_id/exercise_id/question_id/exe_id $filename_array = array($this->params['course_id'], $this->params['session_id'], $this->params['user_id'], $this->params['exercise_id'], $this->params['question_id'], $this->params['exe_id']); return implode('-', $filename_array); } else { return api_get_unique_id(); } }
/** * @param FormValidator $form * @param array $row */ public function setForm($form, $row = array()) { $toolBar = api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400') : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student'); $form->addHtmlEditor('content', get_lang('Content'), false, false, $toolBar); //$content $form->addElement('text', 'comment', get_lang('Comments')); $progress = array('', 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); $form->addElement('select', 'progress', get_lang('Progress'), $progress); if ((api_is_allowed_to_edit(false, true) || api_is_platform_admin()) && isset($row['reflink']) && $row['reflink'] != 'index') { $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="advanced_params_options" style="display:none">'); $form->addHtmlEditor('task', get_lang('DescriptionOfTheTask'), false, false, array('ToolbarSet' => 'WikiTask', 'Width' => '100%', 'Height' => '200')); $form->addElement('label', null, get_lang('AddFeedback')); $form->addElement('textarea', 'feedback1', get_lang('Feedback1')); $form->addElement('select', 'fprogress1', get_lang('FProgress'), $progress); $form->addElement('textarea', 'feedback2', get_lang('Feedback2')); $form->addElement('select', 'fprogress2', get_lang('FProgress'), $progress); $form->addElement('textarea', 'feedback3', get_lang('Feedback3')); $form->addElement('select', 'fprogress3', get_lang('FProgress'), $progress); $form->addElement('checkbox', 'initstartdate', null, get_lang('StartDate'), array('id' => 'start_date_toggle')); $style = "display:block"; $row['initstartdate'] = 1; if ($row['startdate_assig'] == '0000-00-00 00:00:00') { $style = "display:none"; $row['initstartdate'] = null; } $form->addElement('html', '<div id="start_date" style="' . $style . '">'); $form->addElement('DatePicker', 'startdate_assig'); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'initenddate', null, get_lang('EndDate'), array('id' => 'end_date_toggle')); $style = "display:block"; $row['initenddate'] = 1; if ($row['enddate_assig'] == '0000-00-00 00:00:00') { $style = "display:none"; $row['initenddate'] = null; } $form->addElement('html', '<div id="end_date" style="' . $style . '">'); $form->addElement('DatePicker', 'enddate_assig'); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'delayedsubmit', null, get_lang('AllowLaterSends')); $form->addElement('text', 'max_text', get_lang('NMaxWords')); $form->addElement('text', 'max_version', get_lang('NMaxVersion')); $form->addElement('checkbox', 'assignment', null, get_lang('CreateAssignmentPage')); $form->addElement('html', '</div>'); } $form->addElement('hidden', 'page_id'); $form->addElement('hidden', 'reflink'); // $form->addElement('hidden', 'assignment'); $form->addElement('hidden', 'version'); $form->addElement('hidden', 'wpost_id', api_get_unique_id()); }
/** * This function downloads all the files of the input array into one zip * @param array $fileList containing all the ids of the files that have to be downloaded. * @author Patrick Cool <*****@*****.**>, Ghent University * @todo consider removing the check if the user has received or sent this file (zip download of a folder already sufficiently checks for this). * @todo integrate some cleanup function that removes zip files that are older than 2 days * * @author Patrick Cool <*****@*****.**>, Ghent University * @author Julio Montoya Addin c_id support * @version march 2006 */ function zip_download($fileList) { $_course = api_get_course_info(); $dropbox_cnf = getDropboxConf(); $course_id = api_get_course_int_id(); $fileList = array_map('intval', $fileList); // note: we also have to add the check if the user has received or sent this file. $sql = "SELECT DISTINCT file.filename, file.title, file.author, file.description\n FROM " . $dropbox_cnf['tbl_file'] . " file\n INNER JOIN " . $dropbox_cnf['tbl_person'] . " person\n ON (person.file_id=file.id AND file.c_id = {$course_id} AND person.c_id = {$course_id})\n INNER JOIN " . $dropbox_cnf['tbl_post'] . " post\n ON (post.file_id = file.id AND post.c_id = {$course_id} AND file.c_id = {$course_id})\n WHERE\n file.id IN (" . implode(', ', $fileList) . ") AND\n file.id = person.file_id AND\n (\n person.user_id = '" . api_get_user_id() . "' OR\n post.dest_user_id = '" . api_get_user_id() . "'\n ) "; $result = Database::query($sql); $files = array(); while ($row = Database::fetch_array($result)) { $files[$row['filename']] = array('filename' => $row['filename'], 'title' => $row['title'], 'author' => $row['author'], 'description' => $row['description']); } // Step 3: create the zip file and add all the files to it $temp_zip_file = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . ".zip"; Session::write('dropbox_files_to_download', $files); $zip = new PclZip($temp_zip_file); foreach ($files as $value) { $zip->add(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/dropbox/' . $value['filename'], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_CB_PRE_ADD, 'my_pre_add_callback'); } Session::erase('dropbox_files_to_download'); $name = 'dropbox-' . api_get_utc_datetime() . '.zip'; DocumentManager::file_send_for_download($temp_zip_file, true, $name); @unlink($temp_zip_file); exit; }
if ($form->validate()) { $values = $form->getSubmitValues(); $upload = process_uploaded_file($_FILES['file'], false); if ($upload) { $zip = new PclZip($_FILES['file']['tmp_name']); // Check the zip content (real size and file extension) $zipFileList = (array) $zip->listContent(); $realSize = 0; foreach ($zipFileList as &$this_content) { $realSize += $this_content['size']; } $maxSpace = DocumentManager::get_course_quota(); if (!DocumentManager::enough_space($realSize, $maxSpace)) { Display::addFlash(Display::return_message(get_lang('UplNotEnoughSpace'), 'warning')); } $folder = api_get_unique_id(); $destinationDir = api_get_path(SYS_ARCHIVE_PATH) . $folder; mkdir($destinationDir, api_get_permissions_for_new_directories(), true); /* Uncompress zip file*/ // We extract using a callback function that "cleans" the path $zip->extract(PCLZIP_OPT_PATH, $destinationDir, PCLZIP_CB_PRE_EXTRACT, 'clean_up_files_in_zip', PCLZIP_OPT_REPLACE_NEWER); $result = get_work_user_list(null, null, null, null, $workId); if (empty($result)) { Display::addFlash(Display::return_message(get_lang('NoDataAvailable'), 'warning')); } $finalResult = []; foreach ($result as $item) { $title = $item['title_clean']; $title = api_replace_dangerous_char($title); $finalResult[$title] = $item['id']; }
try to look the file inside the session */ if (empty($documentInfo)) { $documentInfo = DocumentManager::get_document_data_by_id($_GET['id'], $courseCode, false, $sessionId); } } $path = $documentInfo['path']; if (empty($path)) { $path = '/'; } // A student should not be able to download a root shared directory if (($path == '/shared_folder' || $path == '/shared_folder_session_' . api_get_session_id()) && (!api_is_allowed_to_edit() || !api_is_platform_admin())) { api_not_allowed(true); exit; } // Creating a ZIP file. $tempZipFile = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . ".zip"; $zip = new PclZip($tempZipFile); $doc_table = Database::get_course_table(TABLE_DOCUMENT); $prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); // We need this path to clean it out of the zip file // I'm not using dir name as it gives too much problems (cfr.) $remove_dir = $path != '/' ? substr($path, 0, strlen($path) - strlen(basename($path))) : '/'; // Put the files in the zip // 2 possibilities: Admins get all files and folders in the selected folder (except for the deleted ones) // Normal users get only visible files that are in visible folders function fixDocumentNameCallback($p_event, &$p_header) { global $remove_dir; $files = Session::read('doc_files_to_download'); $storedFile = $remove_dir . $p_header['stored_filename']; if (!isset($files[$storedFile])) {
$gradebook = ''; } if (!empty($gradebook) && $gradebook == 'view') { $interbreadcrumb[] = array('url' => '../gradebook/' . $_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook')); } $nameTools = get_lang('Exercices'); if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') { require_once 'export/qti2/qti2_export.php'; $export = export_exercise($exerciseId, true); $archive_path = api_get_path(SYS_ARCHIVE_PATH); $temp_dir_short = api_get_unique_id(); $temp_zip_dir = $archive_path . "/" . $temp_dir_short; if (!is_dir($temp_zip_dir)) { mkdir($temp_zip_dir, api_get_permissions_for_new_directories()); } $temp_zip_file = $temp_zip_dir . "/" . api_get_unique_id() . ".zip"; $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml'; file_put_contents($temp_xml_file, $export); $zip_folder = new PclZip($temp_zip_file); $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH); $name = 'qti2_export_' . $exerciseId . '.zip'; //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml'); DocumentManager::file_send_for_download($temp_zip_file, true, $name); unlink($temp_zip_file); unlink($temp_xml_file); rmdir($temp_zip_dir); exit; //otherwise following clicks may become buggy } $htmlHeadXtra[] = '<script> $(document).ready(function() {
/** * @param array $courseInfo * @param int $sessionId * * @return bool */ public static function downloadAllDeletedDocument($courseInfo, $sessionId) { // Zip library for creation of the zip file. require api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php'; $files = self::getDeletedDocuments($courseInfo, $sessionId); if (empty($files)) { return false; } $coursePath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document'; // Creating a ZIP file. $tempZipFile = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . ".zip"; $zip = new PclZip($tempZipFile); foreach ($files as $file) { $zip->add($coursePath . $file['path'], PCLZIP_OPT_REMOVE_PATH, $coursePath); } if (Security::check_abs_path($tempZipFile, api_get_path(SYS_ARCHIVE_PATH))) { DocumentManager::file_send_for_download($tempZipFile, true); @unlink($tempZipFile); exit; } }
public static function generate_accordion($items, $type = 'jquery', $id = null) { $html = null; if (!empty($items)) { if (empty($id)) { $id = api_get_unique_id(); } if ($type == 'jquery') { $html = '<div class="accordion_jquery" id="' . $id . '">'; //using jquery } else { $html = '<div class="accordion" id="' . $id . '">'; //using bootstrap } $count = 1; foreach ($items as $item) { $html .= '<div class="accordion-my-group">'; $html .= '<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#' . $id . '" href="#collapse' . $count . '"> ' . $item['title'] . ' </a> </div>'; $html .= '<div id="collapse' . $count . '" class="accordion-body">'; $html .= '<div class="accordion-my-inner"> ' . $item['content'] . ' </div> </div>'; } $html .= '</div>'; } return $html; }
/** * @param int $userId * @param int $courseId * @param int $sessionId */ public function updateMailAgreementLink($userId, $courseId, $sessionId) { $data = $this->getUserAcceptedLegal($userId, $courseId, $sessionId); if (!empty($data)) { $table = Database::get_main_table('session_rel_course_rel_user_legal'); $uniqueId = api_get_unique_id(); Database::update($table, array('mail_agreement_link' => $uniqueId), array('id = ? ' => array($data['id']))); $this->sendMailLink($uniqueId, $userId, $courseId, $sessionId); } }
// Transform any .php file in .phps fo security $new_file_name = php2phps($new_file_name); $filesize = filesize($_FILES['file']['tmp_name']); if (empty($filesize)) { $error_message .= Display::return_message(get_lang('UplUploadFailedSizeIsZero'), 'error'); $succeed = false; } elseif (!filter_extension($new_file_name)) { //filter extension $error_message .= Display::return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'error'); $succeed = false; } if (!$title) { $title = $_FILES['file']['name']; } // Compose a unique file name to avoid any conflict $new_file_name = api_get_unique_id(); $curdirpath = basename($my_folder_data['url']); // If we come from the group tools the groupid will be saved in $work_table $result = move_uploaded_file($_FILES['file']['tmp_name'], $updir . $curdirpath . '/' . $new_file_name); if ($result) { $url = 'work/' . $curdirpath . '/' . $new_file_name; $contains_file = 1; } } if (empty($title)) { $title = get_lang('Untitled'); } $documents_total_space = DocumentManager::documents_total_space(); $course_max_space = DocumentManager::get_course_quota(); $total_size = $filesize + $documents_total_space; if ($total_size > $course_max_space) {