aboutsummaryrefslogtreecommitdiff
path: root/lib/extern/modules/views/news.inc.php
blob: 46eba77a4b1f2e43d23d8fcbdb1ea5c18e72134f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?
# Lifter002: TODO
# Lifter003: TEST
# Lifter007: TODO
# Lifter010: TODO

$error_message = "";

// stimmt die übergebene range_id?
$query = "SELECT 1 FROM Institute WHERE Institut_id = ?";
$statement = DBManager::get()->prepare($query);
$statement->execute([$this->config->range_id]);
if (!$statement->fetchColumn()) {
    $error_message = $GLOBALS["EXTERN_ERROR_MESSAGE"];
}

if (!$nameformat = $this->config->getValue("Main", "nameformat"))
    $nameformat = "no_title";
if ($nameformat == 'last') $GLOBALS['_fullname_sql']['last'] = ' Nachname ';

$news = StudipNews::GetNewsByRange($this->config->range_id, true, true);
if (!count($news))
    $error_message = $this->config->getValue("Main", "nodatatext");

if ($this->config->getValue("Main", "studiplink")) {
    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" ";
    echo "width=\"" . $this->config->getValue("TableHeader", "table_width");
    echo "\" align=\"" . $this->config->getValue("TableHeader", "table_align") . "\">\n";

    $studip_link = URLHelper::getLink('dispatch.php/institute/overview?again=yes&cid='. $this->config->range_id);
    if ($this->config->getValue("Main", "studiplink") == "top") {
        $args = ["width" => "100%",
        "height" => "40", "link" => $studip_link];
        echo "<tr><td width=\"100%\">\n";
        $this->elements["StudipLink"]->printout($args);
        echo "</td></tr>";
    }
    $table_attr = $this->config->getAttributes("TableHeader", "table");
    $pattern = ["/width=\"[0-9%]+\"/", "/align=\"[a-z]+\"/"];
    $replace = ["width=\"100%\"", ""];
    $table_attr = preg_replace($pattern, $replace, $table_attr);
    echo "<tr><td width=\"100%\">\n<table$table_attr>\n";
}
else
    echo "<table" . $this->config->getAttributes("TableHeader", "table") . ">\n";

$i = 0;
$this->elements["TableHeadrow"]->printout();

// no data to print
if ($error_message) {
    echo "<tr" . $this->config->getAttributes("TableRow", "tr") . ">\n";
    echo "<td" . $this->config->getAttributes("TableRow", "td") . " colspan=\"$i\">\n";
    echo $error_message;
    echo "</td></tr>\n</table>\n";
}
else {
    $data["data_fields"] = $this->data_fields;
    $dateform = $this->config->getValue("Main", "dateformat");
    $show_date_author = $this->config->getValue("Main", "showdateauthor");
    $not_author_link = $this->config->getValue("Main", "notauthorlink");

    $query = "SELECT COUNT(*)
              FROM Institute AS i
              LEFT JOIN user_inst AS ui USING(Institut_id)
              LEFT JOIN auth_user_md5 AS aum USING(user_id)
              WHERE Institut_id = ? AND user_id = ? AND ui.inst_perms IN ('autor','tutor','dozent')";
    $statement = DBManager::get()->prepare($query);

    foreach($news as $news_id => $news_detail){
        // Mitarbeiter/in am Institut
        $statement->execute([
            $this->config->range_id,
            $news_detail->user_id,
        ]);
        $institute_user = $statement->fetchColumn() ?: 0;
        $statement->closeCursor();

        // !!! LinkInternSimple is not the type of this element,
        // the type of this element is LinkIntern !!!
        // this is for compatibiliy reasons only
        if ($show_date_author !== 'date') {
            if ($not_author_link || !$institute_user)
                $author_name = htmlReady(get_fullname($news_detail->user_id, $nameformat));
            else
                $author_name = $this->elements["LinkInternSimple"]->toString([
                    'content'   => htmlReady(get_fullname($news_detail->user_id, $nameformat)),
                    'link_args' => 'username=' . get_username($news_detail->user_id),
                    'module'    => 'Persondetails'
                ]);
        }

        switch ($show_date_author) {
            case 'date' :
                $data["content"]["date"] = strftime($dateform, $news_detail->date);
                break;
            case 'author' :
                $data["content"]["date"] = $author_name;
                break;
            default :
                $data["content"]["date"] = strftime($dateform, $news_detail->date) . "<br>" . $author_name;
        }

        $data["content"]["topic"] = $this->elements["ContentNews"]->toString([
            "content" => [
                "topic" => htmlReady((string) $news_detail->topic),
                "body"  => formatReady((string) $news_detail->body, TRUE, TRUE),
            ]
        ]);

        $this->elements["TableRow"]->printout($data);
    }

    echo "\n</table>";
}
if ($this->config->getValue("Main", "studiplink")) {
    if ($this->config->getValue("Main", "studiplink") == "bottom") {
        $args = ["width" => "100%",
        "height" => "40", "link" => $studip_link];
        echo "</td></tr>\n<tr><td width=\"100%\">\n";
        $this->elements["StudipLink"]->printout($args);
    }
    echo "</td></tr></table>\n";
}