123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- $path = $_GET['path'];
- if(empty($path))
- {
- $path='/';
- }
- include(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php');
- $remove_dir = ($path!='/') ? substr($path,0,strlen($path) - strlen(basename($path))) : '/';
- $temp_zip_dir = $sys_course_path.$_course['path']."/temp";
- if (!is_dir($temp_zip_dir)) {
- mkdir($temp_zip_dir);
- } else {
-
- $handle=opendir($temp_zip_dir);
- while (false!==($file = readdir($handle))) {
- if ($file != "." && $file != "..") {
-
- $Diff = (time() - filemtime("$temp_zip_dir/$file"))/60/60;
-
- if ($Diff > 4) {
- unlink("$temp_zip_dir/$file");
- }
- }
- }
- closedir($handle);
- }
- $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
- $zip_folder= new PclZip($temp_zip_file);
- $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
- $prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
- if (is_allowed_to_edit()) {
-
-
-
-
-
- if($path=='/') {
- $querypath='';
- } else {
- $querypath=$path;
- }
-
- $query = Database::query("SELECT url FROM $tbl_student_publication AS work,$prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'2'",__FILE__,__LINE__);
-
- while ($not_deleted_file = mysql_fetch_assoc($query)) {
- $zip_folder->add($sys_course_path.$_course['path']."/".$not_deleted_file['url'],PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path']."/work".$remove_dir);
- }
- }
- else
- {
- if ($path=='/') {
- $querypath='';
- } else {
- $querypath=$path;
- }
-
-
-
- $query = Database::query("SELECT url FROM $tbl_student_publication AS work,$prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility='1' AND props.lastedit_user_id='".api_get_user_id()."'",__FILE__,__LINE__);
-
- $all_visible_files_path = array();
- while ($all_visible_files = mysql_fetch_assoc($query)) {
- $all_visible_files_path[] = $all_visible_files['url'];
- }
-
- $query2 = Database::query("SELECT url FROM $tbl_student_publication AS work,$prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'1' AND props.lastedit_user_id='".api_get_user_id()."'",__FILE__,__LINE__);
-
- if (Database::num_rows($query2)>0) {
-
- while ($invisible_folders = mysql_fetch_assoc($query2)) {
-
- $query3 = Database::query("SELECT url FROM $tbl_student_publication AS work,$prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$invisible_folders['path']."/%' AND work.filetype='file' AND props.visibility='1' AND props.lastedit_user_id='".api_get_user_id()."'",__FILE__,__LINE__);
-
- while ($files_in_invisible_folder = mysql_fetch_assoc($query3)) {
- $files_in_invisible_folder_path[] = $files_in_invisible_folder['url'];
- }
- }
-
-
- $files_for_zipfile = diff((array) $all_visible_files_path,(array) $files_in_invisible_folder_path);
- } else {
-
- $files_for_zipfile = $all_visible_files_path;
- }
-
- for ($i=0;$i<count($files_for_zipfile);$i++) {
- $zip_folder->add($sys_course_path.$_course['path']."/".$files_for_zipfile[$i],PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path']."/work".$remove_dir);
- }
- }
- event_download(basename($path).'.zip (folder)');
- $name = basename($path).'.zip';
- DocumentManager::file_send_for_download($temp_zip_file,true,$name);
- @unlink($temp_zip_file);
- exit;
- function diff($arr1,$arr2) {
- $res = array(); $r=0;
- foreach ($arr1 as $av) {
- if (!in_array($av,$arr2)){
- $res[$r]=$av; $r++;
- }
- }
- return $res;
- }
|