function in_archiv ($sem_id) { global $SEM_CLASS,$SEM_TYPE, $ARCHIV_PATH, $TMP_PATH, $ZIP_PATH, $ZIP_OPTIONS, $_fullname_sql; NotificationCenter::postNotification('CourseWillArchive', $sem_id); //Besorgen der Grunddaten des Seminars $query = "SELECT Seminar_id, Name, Untertitel, Beschreibung, start_time, Institut_id, status FROM seminare WHERE Seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($sem_id)); $row = $statement->fetch(PDO::FETCH_ASSOC); $seminar_id = $row['Seminar_id']; $name = $row['Name']; $untertitel = $row['Untertitel']; $beschreibung = $row['Beschreibung']; $start_time = $row['start_time']; $heimat_inst_id = $row['Institut_id']; //Besorgen von einzelnen Daten zu dem Seminar $semester = new SemesterData; $all_semester = $semester->getAllSemesterData(); foreach ($all_semester as $sem) { if (($start_time >= $sem['beginn']) && ($start_time <= $sem['ende'])) { $semester_tmp = $sem['name']; } } //Studienbereiche if ($SEM_CLASS[$SEM_TYPE[$row['status']]['class']]['bereiche']) { $sem_path = get_sem_tree_path($seminar_id); if (is_array($sem_path)) { $studienbereiche = join(', ', $sem_path); } } // das Heimatinstitut als erstes $query = "SELECT Name FROM Institute WHERE Institut_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($heimat_inst_id)); $institute = $statement->fetchColumn(); // jetzt den Rest $query = "SELECT Name FROM Institute LEFT JOIN seminar_inst USING (institut_id) WHERE seminar_id = ? AND Institute.Institut_id != ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id, $heimat_inst_id)); while ($temp = $statement->fetchColumn()) { $institute .= ', ' . $temp; } $query = "SELECT GROUP_CONCAT({$_fullname_sql['full']} SEPARATOR ', ') FROM seminar_user LEFT JOIN auth_user_md5 USING (user_id) LEFT JOIN user_info USING (user_id) WHERE seminar_id = ? AND seminar_user.status = 'dozent'"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id)); $dozenten = $statement->fetchColumn(); $query = "SELECT fakultaets_id FROM seminare LEFT JOIN Institute USING (Institut_id) WHERE Seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id)); $fakultaet_id = $statement->fetchColumn(); $query = "SELECT GROUP_CONCAT(DISTINCT c.Name SEPARATOR ' | ') FROM seminar_inst AS a LEFT JOIN Institute AS b USING (Institut_id) LEFT JOIN Institute AS c ON (c.Institut_id = b.fakultaets_id) WHERE a.seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id)); $fakultaet = $statement->fetchColumn(); setTempLanguage(); // use $DEFAULT_LANGUAGE for archiv-dumps //Dump holen $dump = dump_sem($sem_id, 'nobody'); //Forumdump holen foreach (PluginEngine::getPlugins('ForumModule', $sem_id) as $plugin) { $forumdump .= $plugin->getDump($sem_id); } // Wikidump holen $wikidump = getAllWikiPages($sem_id, $name, FALSE); restoreLanguage(); //OK, naechster Schritt: Kopieren der Personendaten aus seminar_user in archiv_user $query = "INSERT INTO archiv_user (seminar_id, user_id, status) SELECT Seminar_id, user_id, status FROM seminar_user WHERE Seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id)); // Eventuelle Vertretungen in der Veranstaltung haben weiterhin Zugriff mit Dozentenrechten if (get_config('DEPUTIES_ENABLE')) { $deputies = getDeputies($seminar_id); // Eintragen ins Archiv mit Zugriffsberechtigung "dozent" $query = "INSERT IGNORE INTO archiv_user SET seminar_id = ?, user_id = ?, status = 'dozent'"; $statement = DBManager::get()->prepare($query); foreach ($deputies as $deputy) { $statement->execute(array($seminar_id, $deputy['user_id'])); } } $Modules = new Modules; $Modules = $Modules->getLocalModules($sem_id); $folder_tree = TreeAbstract::GetInstance('StudipDocumentTree', array('range_id' => $sem_id,'entity_type' => 'sem')); if ($Modules['documents_folder_permissions'] || StudipDocumentTree::ExistsGroupFolders($sem_id)) { $unreadable_folders = $folder_tree->getUnReadableFolders('nobody'); } $query = "SELECT COUNT(dokument_id) FROM dokumente WHERE seminar_id = ? AND url = ''"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id)); $count = $statement->fetchColumn(); if ($count) { $hash_secret = "frauen"; $archiv_file_id = md5(uniqid($hash_secret,1)); //temporaeres Verzeichnis anlegen $tmp_full_path = "$TMP_PATH/$archiv_file_id"; mkdir($tmp_full_path, 0700); if($folder_tree->getNumKids('root')) { $list = $folder_tree->getKids('root'); } if (is_array($list) && count($list) > 0) { $query = "SELECT folder_id, name FROM folder WHERE range_id IN (?) ORDER BY name"; $statement = DBManager::get()->prepare($query); $statement->execute(array($list)); $folder = 0; while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $folder += 1; $temp_folder = $tmp_full_path . "/[$folder]_" . prepareFilename($row['name'], FALSE); mkdir($temp_folder, 0700); createTempFolder($row['folder_id'], $temp_folder, $seminar_id, 'nobody'); } //zip all the stuff $archiv_full_path = "$ARCHIV_PATH/$archiv_file_id"; create_zip_from_directory($tmp_full_path, $tmp_full_path); @rename($tmp_full_path . '.zip', $archiv_full_path); } rmdirr($tmp_full_path); if (is_array($unreadable_folders)) { $query = "SELECT dokument_id FROM dokumente WHERE seminar_id = ? AND url = '' AND range_id IN (?)"; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar_id, $unreadable_folders)); $archiv_protected_file_id = createSelectedZip($statement->fetchAll(PDO::FETCH_COLUMN), false, false); @rename("$TMP_PATH/$archiv_protected_file_id", "$ARCHIV_PATH/$archiv_protected_file_id"); } } else { $archiv_file_id = ''; } //Reinschreiben von diversem Klumpatsch in die Datenbank $query = "INSERT INTO archiv (seminar_id, name, untertitel, beschreibung, start_time, semester, heimat_inst_id, institute, dozenten, fakultaet, dump, archiv_file_id,archiv_protected_file_id, forumdump, wikidump, studienbereiche, mkdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP())"; $statement = DBManager::get()->prepare($query); $success = $statement->execute(array( $seminar_id, $name ?: '', $untertitel ?: '', $beschreibung ?: '', $start_time, $semester_tmp ?: '', $heimat_inst_id, $institute ?: '', $dozenten ?: '', $fakultaet ?: '', $dump ?: '', $archiv_file_id ?: '', $archiv_protected_file_id ?: '', $forumdump ?: '', $wikidump ?: '', $studienbereiche ?: '', )); if ($success) { NotificationCenter::postNotification('CourseDidArchive', $seminar_id); } }
/** * used by createFolderZip() to dive into subfolders * collects a list of file metadata and returns it when recursion finishes * * @param string $folder_id id of a folder * @param string $tmp_full_path temporary path * @param bool $perm_check if true, files are checked for folder permissions * @param bool $in_recursion used internally to indicate recursive call * @return array assoc array with metadata from zipped files */ function createTempFolder($folder_id, $tmp_full_path, $sem_id, $perm_check = TRUE, $in_recursion = false) { static $filelist; if ($in_recursion === false) { $filelist = array(); $tmp_path = $tmp_full_path; } if ($perm_check){ $folder_tree = TreeAbstract::GetInstance('StudipDocumentTree', array('range_id' => $sem_id)); $check_for = $perm_check === true ? $GLOBALS['user']->id : $perm_check; if (!$folder_tree->isDownloadFolder($folder_id, $check_for)) return false; } //copy all documents from this folder to the temporary folder $linkinfo = FALSE; $query = "SELECT dokument_id, filename, url, author_name, filesize, name, description, FROM_UNIXTIME(chdate) AS chdate FROM dokumente WHERE range_id = ? AND seminar_id = IFNULL(?, seminar_id) ORDER BY name, filename"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $folder_id, $perm_check ? (string)$sem_id : null )); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { if ($row['url'] != '') { // just a linked file $linkinfo .= "\r\n" . $row['filename']; } else if(check_protected_download($row['dokument_id'])) { $filename = prepareFilename($row['filename'], FALSE, $tmp_full_path); if (copy(get_upload_file_path($row['dokument_id']), $tmp_full_path . '/' . $filename)) { TrackAccess($row['dokument_id'], 'dokument'); $filelist[] = $row + array('path' => $tmp_full_path . '/' . $filename); } } } if ($linkinfo) { $linkinfo = _("Hinweis: die folgenden Dateien sind nicht im Archiv enthalten, da sie lediglich verlinkt wurden:").$linkinfo; $fp = fopen ("$tmp_full_path/info.txt","a"); fwrite ($fp, $linkinfo); fclose ($fp); } $query = "SELECT folder_id, name FROM folder WHERE range_id = ? ORDER BY name"; $statement = DBManager::get()->prepare($query); $statement->execute(array($folder_id)); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $foldername = prepareFilename($row['name'], FALSE, $tmp_full_path); $tmp_sub_full_path = $tmp_full_path . '/' . $foldername; mkdir($tmp_sub_full_path, 0700); createTempFolder($row['folder_id'], $tmp_sub_full_path, $sem_id, $perm_check, true); } if ($in_recursion === false) { array_walk($filelist, create_function('&$a', '$a["path"] = substr($a["path"], ' . (int)strlen($tmp_path) . ');')); return $filelist; } else { return true; } }