aboutsummaryrefslogtreecommitdiff
path: root/lib/extern/sri.inc.php
blob: cfdf38a4c62a9209f6188f9660039de1947b26a8 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
* sri.inc.php
*
* The Stud.IP-remote-include interface to extern modules.
*
*
* @author       Peter Thienel <pthienel@web.de>, Suchi & Berg GmbH <info@data-quest.de>
* @access       public
* @modulegroup  extern
* @module       extern
* @package  studip_extern
*/

// +---------------------------------------------------------------------------+
// This file is part of Stud.IP
// sri.inc.php
// Stud.IP-remote-include interface to extern modules.
// Copyright (C) 2003 Peter Thienel <pthienel@web.de>,
// Suchi & Berg GmbH <info@data-quest.de>
// +---------------------------------------------------------------------------+
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
// +---------------------------------------------------------------------------+
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// +---------------------------------------------------------------------------+

if (!Config::get()->EXTERN_SRI_ENABLE) {
    echo $EXTERN_ERROR_MESSAGE;
    exit;
}

if (!ini_get('allow_url_fopen')){
    @ini_set('allow_url_fopen','1');
}
// this script is included in extern.inc.php

$all_semester = Semester::findAllVisible(false);

if ($sri_file = @file($page_url))
    $sri_page = implode("", $sri_file);
else {
    echo $EXTERN_ERROR_MESSAGE;
    exit;
}

$sri_pattern = "'(.*)(\<studip_remote_include\>.*\<\/studip_remote_include\>)(.*)'is";

if (!preg_match($sri_pattern, $sri_page, $sri_matches)) {
    echo $EXTERN_ERROR_MESSAGE;
    exit;
}

$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $sri_matches[2], $xml_values, $xml_tags);

$allowed_xml_tags = ["module", "range", "config", "sem", "global"];

foreach ($allowed_xml_tags as $xml_tag) {
    if ($xml_tags[$xml_tag]) {
        $attributes = $xml_values[$xml_tags[$xml_tag][0]]["attributes"];
        foreach ($attributes as $attribute => $value) {
            $parameter_name = $xml_tag . "_" . $attribute;
            $$parameter_name = $value;
        }
    }
}

// check given data
// no range_id? sorry...
if (!$range_id) {
    echo $EXTERN_ERROR_MESSAGE;
    exit;
}

// Is it a valid module name?
reset($EXTERN_MODULE_TYPES);
foreach ($EXTERN_MODULE_TYPES as $module_type => $module_data) {
    if ($module_data["module"] == $module_name) {
        $type = $module_type;
        break;
    }
}
// Wrong module name!
if (!$type) {
    echo $EXTERN_ERROR_MESSAGE;
    exit;
}

// if there is no config_id or config_name, take the DEFAULT configuration
if ($config_name) {
    // check for valid configuration name and convert it into a config_id
    if (!$config_id = ExternConfig::GetConfigurationByName($range_id, $type, $config_name)) {
        echo $EXTERN_ERROR_MESSAGE;
        exit;
    }
}
elseif (!$config_id) {
    // check for standard configuration
    if ($id = ExternConfig::GetStandardConfiguration($range_id, $type)) {
        $config_id = $id;
    } else {
        if (Config::get()->EXTERN_ALLOW_ACCESS_WITHOUT_CONFIG) {
            // use default configuraion
            $default = 'DEFAULT';
            $config_id = '';
        } else {
            echo $EXTERN_ERROR_MESSAGE;
            exit;
        }
    }
}

// if there is no global_id or global_name, take the DEFAULT global configuration
if ($global_name) {
    // check for valid configuration name and convert it into a config_id
    if (!$global_id = ExternConfig::GetConfigurationByName($range_id, $type, $config_name)) {
        echo $EXTERN_ERROR_MESSAGE;
        exit;
    }
}
elseif (!$global_id) {
    // check for standard configuration
    if ($id = ExternConfig::GetGlobalConfiguration($range_id))
        $global_id = $id;
    else {
        // use no global configuration
        $global_id = NULL;
    }
}

// sem == -1: show data from last semester
// sem == +1: show data from next semester
// other values: show data from current semester
$now = time();
foreach ($all_semester as $key => $sem_record) {
    if ($now >= $sem_record["beginn"] && $now <= $sem_record["ende"]) {
        $current = $key;
        break;
    }
}
if ($sem_offset == "-1") {
    $start = $all_semester[$current - 1]["beginn"];
    $end = $all_semester[$current - 1]["ende"];
} elseif ($sem_offset == "+1") {
    $start = $all_semester[$current + 1]["beginn"];
    $end = $all_semester[$current + 1]["ende"];
} else {
    $start = $all_semester[$current]["beginn"];
    $end = $all_semester[$current]["ende"];
}

// all parameters ok, instantiate module and print data
foreach ($EXTERN_MODULE_TYPES as $type) {
    if ($type["module"] == $module_name) {
        $class_name = "ExternModule" . $module_name;
        require_once "lib/extern/modules/$class_name.class.php";
        $module_obj = ExternModule::GetInstance($range_id, $module_name, $config_id, $default, $global_id);
    }
}
// drop URL parameters from page_url
$page_url = preg_replace('/\?.*/', '', Request::get('page_url'));

$sri_url = $module_obj->config->getValue('Main', 'sriurl');

if (isset($sri_url)) {
    // drop URL parameters from sri_url
    $sri_url = preg_replace('/\?.*/', '', $sri_url);
}

if ($page_url != $sri_url || !sri_is_enabled($module_obj->config->range_id)) {

    echo $EXTERN_ERROR_MESSAGE;
    exit;
}

$args = $module_obj->getArgs();
foreach ($args as $arg) {
    $arguments[$arg] = Request::quoted($arg);
}

echo $sri_matches[1];
$module_obj->printout($arguments);
echo $sri_matches[3];