Example #1
0
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);
    }
}
Example #2
0
 /**
  * Download a ZIP file containing the given plugin.
  *
  * @param integer   id of plugin to download
  */
 public function download_action($plugin_id)
 {
     $plugin_manager = PluginManager::getInstance();
     $plugin = $plugin_manager->getPluginInfoById($plugin_id);
     // prepare file name for download
     $pluginpath = get_config('PLUGINS_PATH') . '/' . $plugin['path'];
     $manifest = $plugin_manager->getPluginManifest($pluginpath);
     $filename = $plugin['class'] . '-' . $manifest['version'] . '.zip';
     $filepath = get_config('TMP_PATH') . '/' . $filename;
     create_zip_from_directory($pluginpath, $filepath);
     header('Content-Type: application/zip');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Content-Length: ' . filesize($filepath));
     header('Pragma: public');
     $this->render_nothing();
     readfile($filepath);
     unlink($filepath);
 }
Example #3
0
/**
 * creates a zip file from all files in given folder, including subfolders
 *
 * @param string $folder_id id of document folder
 * @param bool $perm_check if true, files are checked for folder permissions
 * @param bool $size_check if true, number and size of files are checked against config values
 * @return string filename(id) of the created zip without path
 */
function createFolderZip ($folder_id, $perm_check = TRUE, $size_check = false) {
    global $TMP_PATH, $ZIP_PATH, $SessSemName;
    $zip_file_id = false;
    $max_files = Config::GetInstance()->getValue('ZIP_DOWNLOAD_MAX_FILES');
    $max_size = Config::GetInstance()->getValue('ZIP_DOWNLOAD_MAX_SIZE') * 1024 * 1024;
    if(!$max_files && !$max_size) $size_check = false;

    if(!($size_check && (doc_count($folder_id) > $max_files || doc_sum_filesize($folder_id) > $max_size))){
        $zip_file_id = md5(uniqid("jabba",1));

        //create temporary Folder
        $tmp_full_path = "$TMP_PATH/$zip_file_id";
        mkdir($tmp_full_path,0700);

        //create folder content
        $filelist = createTempFolder($folder_id, $tmp_full_path, $SessSemName[1], $perm_check);

        $caption = array('filename' => _("Dateiname"), 'filesize' => _("Größe"), 'author_name' => _("Ersteller"), 'chdate' => _("Datum"), 'name' =>  _("Name"), 'description' => _("Beschreibung"), 'path' => _("Pfad"));
        array_to_csv($filelist, $tmp_full_path . '/' . _("dateiliste.csv"), $caption);
        //zip stuff
        create_zip_from_directory($tmp_full_path, $tmp_full_path);
        rmdirr($tmp_full_path);
        @rename($tmp_full_path .".zip" , $tmp_full_path);
    }
    return $zip_file_id;
}
Example #4
0
 /**
  * Downloads an admission rule as ZIP file.
  * @param String $ruleName Class name of the admission rule, is used for file name. 
  *   
  */
 public function download_action($ruleName)
 {
     $dirname = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . 'admissionrules/' . strtolower($ruleName);
     $filename = $ruleName . '.zip';
     $filepath = get_config('TMP_PATH') . '/' . $filename;
     create_zip_from_directory($dirname, $filepath);
     header('Content-Type: application/zip');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Content-Length: ' . filesize($filepath));
     header('Pragma: public');
     $this->render_nothing();
     readfile($filepath);
     unlink($filepath);
 }
 protected function installFromDirectory($dir, $originalfile = null)
 {
     $manifest = PluginManager::getInstance()->getPluginManifest($dir);
     if ($manifest['pluginclassname']) {
         $this->plugin['pluginclassname'] = $manifest['pluginclassname'];
         $this->plugin->store();
     }
     $this['studip_min_version'] = $manifest['studipMinVersion'];
     $this['studip_max_version'] = $manifest['studipMaxVersion'];
     if (!$this['studip_max_version']) {
         $versions = PluginMarket::getStudipReleases();
         $manifest['studipMaxVersion'] = $this['studip_max_version'] = array_pop($versions) . ".99";
         if (!$this['studip_max_version']) {
             PageLayout::postMessage(MessageBox::info(sprintf(_("Die studipMaxVersion wurde auf %s gesetzt, da keine andere angegeben wurde."), $manifest['studipMaxVersion'])));
         }
     }
     if (version_compare($this['studip_min_version'], $this['studip_max_version'], ">")) {
         $this['studip_max_version'] = $this['studip_min_version'];
     }
     $this['version'] = $manifest['version'];
     if ($this['repository_overwrites_descriptionfrom']) {
         $readme = "";
         $scanner = scandir($dir);
         foreach ($scanner as $file) {
             if (strtolower($file) === "readme.md" || strtolower($file) === "readme.markdown") {
                 $readme = file_get_contents($dir . "/" . $file);
             }
         }
         if ($readme) {
             $html = Parsedown::instance()->text($readme);
             $this->plugin['description'] = "<div>" . studip_utf8decode($html) . "</div>";
             $this->plugin->store();
         }
     }
     $this->store();
     file_put_contents($dir . "/plugin.manifest", $this->createManifest($manifest));
     $hash = md5(uniqid());
     $plugin_raw = $GLOBALS['TMP_PATH'] . "/plugin_{$hash}.zip";
     create_zip_from_directory($dir, $plugin_raw);
     if ($manifest['studipMaxVersion'] !== $this['studip_max_version']) {
         copy($plugin_raw, $this->getFilePath());
     } else {
         copy($originalfile, $this->getFilePath());
     }
     unlink($plugin_raw);
     return true;
 }
 function prepare_download($path, $filename)
 {
     $id = md5($filename);
     if (!file_exists($GLOBALS['TMP_PATH'] . '/' . $id . '.zip')) {
         @rmdirr($GLOBALS['TMP_PATH'] . '/' . $id);
         exec($this->svncmd . ' --force export ' . $this->svnurl . $path . ' ' . $GLOBALS['TMP_PATH'] . '/' . $id, $out, $ret);
         create_zip_from_directory($GLOBALS['TMP_PATH'] . '/' . $id, $GLOBALS['TMP_PATH'] . '/' . $id . '.zip');
         @rmdirr($GLOBALS['TMP_PATH'] . '/' . $id);
         return $id;
     } else {
         return $id;
     }
 }