123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- Use Model\StudentPublication;
- Use Model\Course;
- require_once __DIR__ . '/../inc/autoload.inc.php';
- KeyAuth::enable();
- require_once __DIR__ . '/../inc/global.inc.php';
- $has_access = api_protect_course_script();
- if (!$has_access) {
- exit;
- }
- session_cache_limiter('none');
- $ids = Request::get('id', '');
- $ids = $ids ? explode(',', $ids) : array();
- $course = Course::current();
- if (count($ids) == 0 || empty($course)) {
- Response::not_found();
- }
- if (count($ids) == 1) {
- $id = reset($ids);
- $pub = StudentPublication::get_by_id($course, $id);
- if (empty($pub)) {
- Response::not_found();
- }
- $has_access = $pub->is_accessible();
- if (!$has_access) {
- Response::not_found();
- }
- if ($pub->is_file()) {
- event_download(Uri::here());
- DocumentManager::file_send_for_download($pub->get_absolute_path(), false, $pub->get_title());
- exit;
- }
-
- $items = array();
- $children = $pub->get_children();
- foreach ($children as $child) {
- if ($child->is_accessible()) {
- $items[] = $child;
- }
- }
- if (count($items) == 0) {
- Response::not_found();
- }
- $zip = Chamilo::temp_zip();
- foreach ($items as $item) {
- $path = $item->get_absolute_path();
- $title = $item->get_title();
- $zip->add($path, $title);
- }
- event_download(Uri::here());
- DocumentManager::file_send_for_download($zip->get_path(), false, $pub->get_title() . '.zip');
- }
- $items = array();
- foreach ($ids as $id) {
- $pub = StudentPublication::get_by_id($course, $id);
- if (!$pub->is_accessible()) {
- break;
- }
- if ($pub->is_file()) {
- $items[] = $pub;
- }
-
- }
- if (count($items) == 0) {
- Response::not_found();
- }
- $zip = Chamilo::temp_zip();
- foreach ($items as $item) {
- $path = $item->get_absolute_path();
- $title = $item->get_title();
- $zip->add($path, $title);
- }
- event_download(Uri::here());
- DocumentManager::file_send_for_download($zip->get_path(), false, get_lang('StudentPublications') . '.zip');
|