예제 #1
0
    function toStringPreview () {
        $time = time();
        // preview data
        $data[] = array("dokument_id" => 1, "description" => _("Das ist eine Text-Datei."),
            "filename" => "text_file.txt", "mkdate" => ($time - 100000), "chdate" => ($time - 50000),
            "filesize" => 26378, "Vorname" => "Julius", "Nachname" => "Rodman");
        $data[] = array("dokument_id" => 2, "description" => _("Das ist eine Powerpoint-Datei."),
            "filename" => "powerpoint_file.ppt", "mkdate" => ($time - 200000), "chdate" => ($time - 150000),
            "filesize" => 263784, "Vorname" => "William", "Nachname" => "Wilson");
        $data[] = array("dokument_id" => 3, "description" => _("Das ist eine ZIP-Datei."),
            "filename" => "zip_file.zip", "mkdate" => ($time - 300000), "chdate" => ($time - 250000),
            "filesize" => 63784, "Vorname" => "August", "Nachname" => "Bedloe");
        $data[] = array("dokument_id" => 4, "description" => _("Das ist eine Excel-Datei."),
            "filename" => "excel_file.txt", "mkdate" => ($time - 400000), "chdate" => ($time - 350000),
            "filesize" => 23784, "Vorname" => "Ernst", "Nachname" => "Waldemar");
        $data[] = array("dokument_id" => 5, "description" => _("Das ist eine Bild-Datei."),
            "filename" => "bild_jpeg_file.jpg", "mkdate" => ($time - 500000), "chdate" => ($time - 450000),
            "filesize" => 53784, "Vorname" => "Absalom", "Nachname" => "Hicks");
        $data[] = array("dokument_id" => 6, "description" => _("Das ist ein Dokument im Microsoft Rich-Text-Format."),
            "filename" => "microsoft_rtf_file.rtf", "mkdate" => ($time - 600000), "chdate" => ($time - 550000),
            "filesize" => 563784, "Vorname" => "Dirk", "Nachname" => "Peters");
        $data[] = array("dokument_id" => 7, "description" => _("Das ist ein Adobe PDF-Dokument."),
            "filename" => "adobe_pdf_file.pdf", "mkdate" => ($time - 700000), "chdate" => ($time - 650000),
            "filesize" => 13784, "Vorname" => "Augustus", "Nachname" => "Barnard");
        $data[] = array("dokument_id" => 8, "description" => _("Und noch ein ZIP-Archiv."),
            "filename" => "gnu_zip_file.tar.gz", "mkdate" => ($time - 800000), "chdate" => ($time - 750000),
            "filesize" => 2684, "Vorname" => "Gordon", "Nachname" => "Pym");
        $data[] = array("dokument_id" => 9, "description" => _("Eine weitere Text-Datei."),
            "filename" => "text2_file.txt", "mkdate" => ($time - 900000), "chdate" => ($time - 850000),
            "filesize" => 123784, "Vorname" => "Hans", "Nachname" => "Pfaal");
        $data[] = array("dokument_id" => 10, "description" => _("Ein Bild im PNG-Format."),
            "filename" => "picture_png_file.png", "mkdate" => ($time - 1000000), "chdate" => ($time - 950000),
            "filesize" => 813784, "Vorname" => "John", "Nachname" => "Greely");
        $data[] = array("dokument_id" => 11, "description" => _("Eine anderes Format."),
            "filename" => "good_music.mp3", "mkdate" => ($time - 1150000), "chdate" => ($time - 653900),
            "filesize" => 934651, "Vorname" => "Augustus", "Nachname" => "Barnard");

        $table_row_data["data_fields"] = $this->data_fields;
        $out = $this->elements["TableHeadrow"]->toString();

        foreach ($data as $db) {

            preg_match("/^.+\.([a-z1-9_-]+)$/i", $db["filename"], $file_suffix);

            // choose the icon for the given file format
            $icon = "";
            switch ($file_suffix[1]) {
                case "txt" :
                    if (!$picture_file = $this->config->getValue("Main", "icontxt"))
                        $icon = Icon::create("file-text", "clickable");
                    break;
                case "xls" :
                    if (!$picture_file = $this->config->getValue("Main", "iconxls"))
                        $icon = Icon::create("file-xls", "clickable");
                    break;
                case "ppt" :
                    if (!$picture_file = $this->config->getValue("Main", "iconppt"))
                        $icon = Icon::create("file-presentation", "clickable");
                    break;
                case "rtf" :
                    if (!$picture_file = $this->config->getValue("Main", "iconrtf"))
                        $icon = Icon::create("file-text", "clickable");
                    break;
                case "zip" :
                case "tgz" :
                case "gz" :
                    if (!$picture_file = $this->config->getValue("Main", "iconzip"))
                        $icon = Icon::create("file-archive", "clickable");
                    break;
                case "jpg" :
                case "png" :
                case "gif" :
                case "jpeg" :
                case "tif" :
                    if (!$picture_file = $this->config->getValue("Main", "iconpic"))
                        $icon = Icon::create("file-image", "clickable");
                    break;
                case "pdf" :
                    if (!$picture_file = $this->config->getValue("Main", "iconpdf"))
                        $icon = Icon::create("file-pdf", "clickable");
                    break;
                default :
                    if (!$picture_file = $this->config->getValue("Main", "icondefault"))
                        $icon = Icon::create("file-generic", "clickable");
            }

            if ($icon)
                $picture_file = $icon;

            // Aufbereiten der Daten
            $table_row_data["content"] = array(
                "icon"        => $this->elements["Link"]->toString(
                    [
                        "content" => is_string($picture_file)
                                     ? Assets::img($picture_file)
                                     : $picture_file->asImg(),
                        "link"    => ""]),

                "filename"    => $this->elements["Link"]->toString(array("content" =>
                                                    htmlReady($db["filename"]), "link" => "")),

                "description" => htmlReady(mila_extern($db["description"],
                                                    $this->config->getValue("Main", "lengthdesc"))),

                "mkdate"      => strftime($this->config->getValue("Main", "dateformat"), $db["mkdate"]),

                "filesize"    => $db["filesize"] > 1048576 ? round($db["filesize"] / 1048576, 1) . " MB"
                                                    : round($db["filesize"] / 1024, 1) . " kB",

                "fullname"    => $this->elements["LinkIntern"]->toString(
                                                    array("content" => htmlReady($db["Vorname"]." ".$db["Nachname"])))

            );
            $out .= $this->elements["TableRow"]->toString($table_row_data);
        }

        return $this->elements["TableHeader"]->toString(array("content" => $out));
    }
    function getContent ($args = NULL, $raw = FALSE) {
        $error_message = "";
        if (!$args) {
            $args = array();
        }
        $content = array();

        // check for valid range_id
        if(!$this->checkRangeId($this->config->range_id)) {
            $error_message = $GLOBALS['EXTERN_ERROR_MESSAGE'];
        }
        // if $args['seminar_id'] is given, check for free access
        if ($args['seminar_id']) {
            $seminar_id = $args['seminar_id'];
            $query = "SELECT Lesezugriff FROM seminare s LEFT JOIN seminar_inst si ";
            $query .= "USING(seminar_id) WHERE s.seminar_id = ? ";
            $query .= "AND si.institut_id = ?";
            $params = array($seminar_id, $this->config->range_id);
            $statement = DBManager::get()->prepare($query);
            $statement->execute($params);
            $row = $statement->fetchColumn();
            if ($row !== false && $row == 0 ) {
                 $error_message = $GLOBALS['EXTERN_ERROR_MESSAGE'];
            }
        } else {
            $seminar_id = $this->config->range_id;
        }

        $sort = (array) $this->config->getValue('Main', 'sort');
        $query_order = '';
        foreach ($sort as $key => $position) {
            if ($position > 0) {
                $query_order[$position] = $this->data_fields[$key];
            }
        }
        if ($query_order) {
            ksort($query_order, SORT_NUMERIC);
            $query_order = ' ORDER BY ' . implode(',', $query_order) . ' DESC';
        }

        if (!$nameformat = $this->config->getValue('Main', 'nameformat')) {
            $nameformat = 'no_title_short';
        }

        // generic data fields
        $generic_datafields = $this->config->getValue('TemplateGeneric', 'genericdatafields');

        $folder_tree = TreeAbstract::GetInstance('StudipDocumentTree', array('range_id' => $seminar_id));

        $allowed_folders = $folder_tree->getReadableFolders('nobody');
        $mrks =  str_repeat('?,', count($allowed_folders) - 1) . '?';
        $query = "SELECT dokument_id, name, description, filename, d.mkdate, d.chdate, filesize, ";
        $query .= $GLOBALS['_fullname_sql'][$nameformat];
        $query .= "AS fullname, Vorname, Nachname, title_front, title_rear, username, aum.user_id, author_name FROM dokumente d LEFT JOIN user_info USING (user_id) ";
        $query .= "LEFT JOIN auth_user_md5 aum USING (user_id) WHERE ";
        $query .= "seminar_id = ? AND range_id IN ($mrks)$query_order";

        $parameters = $allowed_folders;
        $parameters[] = $seminar_id;          
        $statement = DBManager::get()->prepare($query);
        $statement->execute($parameters);
        $row = $statement->fetch(PDO::FETCH_ASSOC);
        if ( !$row ) {
            $content['NO-FILES']['NO-FILES-TEXT'] = $this->config->getValue('Main', 'nodatatext');
        } else {
            $i = 0;
            do {
                preg_match("/^.+\.([a-z1-9_-]+)$/i", $row['filename'], $file_suffix);

                $icon = '';
                switch ($file_suffix[1]) {
                    case 'txt' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'icontxt'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-text', 'clickable')->asImagePath(16);
                        break;
                    case 'xls' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'iconxls'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-xls', 'clickable')->asImagePath(16);
                        break;
                    case 'ppt' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'iconppt'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-presentation', 'clickable')->asImagePath(16);
                        break;
                    case 'rtf' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'iconrtf'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-text', 'clickable')->asImagePath(16);
                        break;
                    case 'zip' :
                    case 'tgz' :
                    case 'gz' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'iconzip'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-archive', 'clickable')->asImagePath(16);
                        break;
                    case 'jpg' :
                    case 'png' :
                    case 'gif' :
                    case 'jpeg' :
                    case 'tif' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'iconpic'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-pic', 'clickable')->asImagePath(16);
                        break;
                    case 'pdf' :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'iconpdf'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-pdf', 'clickable')->asImagePath(16);
                        break;
                    default :
                        if (!$content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = $this->config->getValue('Main', 'icondefault'))
                            $content['FILES']['FILE'][$i]['FILE_ICON-HREF'] = Icon::create('file-generic', 'clickable')->asImagePath(16);
                }
                $content['FILES']['FILE'][$i]['FILE_NO'] = $i + 1;

                $download_link = GetDownloadLink($row['dokument_id'], $row['filename']);

                $content['FILES']['FILE'][$i]['FILE_HREF'] = $download_link;
                $content['FILES']['FILE'][$i]['FILE_NAME'] = ExternModule::ExtHtmlReady($row['name']);
                $content['FILES']['FILE'][$i]['FILE_FILE-NAME'] = ExternModule::ExtHtmlReady($row['filename']);
                $content['FILES']['FILE'][$i]['FILE_DESCRIPTION'] = ExternModule::ExtHtmlReady(mila_extern($row["description"],
                                                     $this->config->getValue("Main", "lengthdesc")));
                $content['FILES']['FILE'][$i]['FILE_UPLOAD-DATE'] = strftime($this->config->getValue("Main", "dateformat"), $row["mkdate"]);
                $content['FILES']['FILE'][$i]['FILE_SIZE'] = $row['filesize'] > 1048576 ? round($row['filesize'] / 1048576, 1) . " MB" : round($row["filesize"] / 1024, 1) . " kB";

                $content['FILES']['FILE'][$i]['USERNAME'] = $row['username'];
                $content['FILES']['FILE'][$i]['FULLNAME'] = ExternModule::ExtHtmlReady($row['fullname'] ? $row['fullname'] : $row['author_name']);
                $content['FILES']['FILE'][$i]['FIRSTNAME'] = ExternModule::ExtHtmlReady($row['Vorname']);
                $content['FILES']['FILE'][$i]['LASTNAME'] = ExternModule::ExtHtmlReady($row['Nachname']);
                $content['FILES']['FILE'][$i]['TITLEFRONT'] = ExternModule::ExtHtmlReady($row['title_front']);
                $content['FILES']['FILE'][$i]['TITLEREAR'] = ExternModule::ExtHtmlReady($row['title_rear']);
                $content['FILES']['FILE'][$i]['PERSONDETAIL-HREF'] = $this->elements['LinkInternTemplate']->createUrl('Persondetails', array('link_args' => 'username='******'username']));

                // if user is member of a group then link name to details page
                $link_persondetail = '';
                if (GetRoleNames(GetAllStatusgruppen($this->config->range_id, $row['user_id']))) {
                    $content['FILES']['FILE'][$i]['PERSONDETAIL-LINK']['LINK_PERSONDETAIL-HREF'] = $this->elements['LinkInternTemplate']->createUrl('Persondetails', array('link_args' => 'username='******'username']));
                    $content['FILES']['FILE'][$i]['PERSONDETAIL-LINK']['LINK_FULLNAME'] = ExternModule::ExtHtmlReady($row['fullname'] ? $row['fullname'] : $row['author_name']);
                    $content['FILES']['FILE'][$i]['PERSONDETAIL-LINK']['LINK_FIRSTNAME'] = ExternModule::ExtHtmlReady($row['Vorname']);
                    $content['FILES']['FILE'][$i]['PERSONDETAIL-LINK']['LINK_LASTNAME'] = ExternModule::ExtHtmlReady($row['Nachname']);
                    $content['FILES']['FILE'][$i]['PERSONDETAIL-LINK']['LINK_TITLEFRONT'] = ExternModule::ExtHtmlReady($row['title_front']);
                    $content['FILES']['FILE'][$i]['PERSONDETAIL-LINK']['LINK_TITLEREAR'] = ExternModule::ExtHtmlReady($row['title_rear']);
                }

                // generic data fields
                if (is_array($generic_datafields)) {
                    $localEntries = DataFieldEntry::getDataFieldEntries($row['user_id'], 'user');
                    $k = 1;
                    foreach ($generic_datafields as $datafield) {
                        if (isset($localEntries[$datafield]) && is_object($localEntries[$datafield])) {
                            $localEntry = $localEntries[$datafield]->getDisplayValue();
                            if ($localEntry) {
                                $content['FILES']['FILE'][$i]['DATAFIELD_' . $k] = $localEntry;
                            }
                        }
                        $k++;
                    }
                }

                $i++;
            }while($row = $statement->fetch(PDO::FETCH_ASSOC));
        }
        $content = array('DOWNLOAD' => $content);
        $content['__GLOBAL__']['FILES-COUNT'] = $i;

        return $content;
    }