@@ -7,22 +7,22 @@ |
||
7 | 7 | */ |
8 | 8 | class SelectLanguage extends HTML_QuickForm_select |
9 | 9 | { |
10 | - /** |
|
11 | - * Class constructor |
|
12 | - */ |
|
13 | - public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null) |
|
14 | - { |
|
15 | - parent::__construct($elementName, $elementLabel, $options, $attributes); |
|
16 | - // Get all languages |
|
17 | - $languages = api_get_languages(); |
|
18 | - $this->_options = array(); |
|
19 | - $this->_values = array(); |
|
20 | - foreach ($languages['name'] as $index => $name) { |
|
21 | - if ($languages['folder'][$index] == api_get_setting('platformLanguage')) { |
|
22 | - $this->addOption($name, $languages['folder'][$index], array('selected'=>'selected')); |
|
23 | - } else { |
|
24 | - $this->addOption($name, $languages['folder'][$index]); |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
10 | + /** |
|
11 | + * Class constructor |
|
12 | + */ |
|
13 | + public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null) |
|
14 | + { |
|
15 | + parent::__construct($elementName, $elementLabel, $options, $attributes); |
|
16 | + // Get all languages |
|
17 | + $languages = api_get_languages(); |
|
18 | + $this->_options = array(); |
|
19 | + $this->_values = array(); |
|
20 | + foreach ($languages['name'] as $index => $name) { |
|
21 | + if ($languages['folder'][$index] == api_get_setting('platformLanguage')) { |
|
22 | + $this->addOption($name, $languages['folder'][$index], array('selected'=>'selected')); |
|
23 | + } else { |
|
24 | + $this->addOption($name, $languages['folder'][$index]); |
|
25 | + } |
|
26 | + } |
|
27 | + } |
|
28 | 28 | } |
@@ -91,11 +91,11 @@ |
||
91 | 91 | $pathinfo = pathinfo($header_file); |
92 | 92 | |
93 | 93 | if ($pathinfo['extension']=='swf') { |
94 | - $width='83%'; |
|
95 | - $height='83%'; |
|
94 | + $width='83%'; |
|
95 | + $height='83%'; |
|
96 | 96 | } else { |
97 | - $width='100%'; |
|
98 | - $height='100%'; |
|
97 | + $width='100%'; |
|
98 | + $height='100%'; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | echo '<iframe border="0" frameborder="0" scrolling="no" style="width:'.$width.'; height:'.$height.';background-color:#ffffff;" id="mainFrame" name="mainFrame" src="'.$file_url_web.'?'.api_get_cidreq().'&rand='.mt_rand(1, 1000).'"></iframe>'; |
@@ -17,35 +17,35 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function home_tabs($file_logged_in) |
19 | 19 | { |
20 | - $post = strpos($file_logged_in, "_logged_in"); |
|
21 | - if ($post !== false) { |
|
22 | - $file_logged_out = str_replace('_logged_in','', $file_logged_in); |
|
23 | - //variables initialization |
|
24 | - $data_logged_out = array(); |
|
25 | - $data_logged_in = array(); |
|
26 | - |
|
27 | - //we read the file with all links |
|
28 | - $file = file($file_logged_in); |
|
29 | - foreach ($file as $line) { |
|
30 | - $line = str_replace("\n", '',$line); |
|
31 | - //not logged user only sees public links |
|
32 | - if (!preg_match('/::private/',$line)) { |
|
33 | - $data_logged_out[] = $line; |
|
34 | - } |
|
35 | - //logged user only sees all links |
|
36 | - $data_logged_in[] = $line; |
|
37 | - } |
|
38 | - //tabs file for logged out users |
|
39 | - if (file_exists($file_logged_out)) { |
|
40 | - $fp = fopen($file_logged_out, 'w'); |
|
41 | - fputs($fp, implode("\n", $data_logged_out)); |
|
42 | - fclose($fp); |
|
43 | - } |
|
44 | - //tabs file for logged in users |
|
45 | - $fp = fopen($file_logged_in, 'w'); |
|
46 | - fputs($fp, implode("\n", $data_logged_in)); |
|
47 | - fclose($fp); |
|
48 | - } |
|
20 | + $post = strpos($file_logged_in, "_logged_in"); |
|
21 | + if ($post !== false) { |
|
22 | + $file_logged_out = str_replace('_logged_in','', $file_logged_in); |
|
23 | + //variables initialization |
|
24 | + $data_logged_out = array(); |
|
25 | + $data_logged_in = array(); |
|
26 | + |
|
27 | + //we read the file with all links |
|
28 | + $file = file($file_logged_in); |
|
29 | + foreach ($file as $line) { |
|
30 | + $line = str_replace("\n", '',$line); |
|
31 | + //not logged user only sees public links |
|
32 | + if (!preg_match('/::private/',$line)) { |
|
33 | + $data_logged_out[] = $line; |
|
34 | + } |
|
35 | + //logged user only sees all links |
|
36 | + $data_logged_in[] = $line; |
|
37 | + } |
|
38 | + //tabs file for logged out users |
|
39 | + if (file_exists($file_logged_out)) { |
|
40 | + $fp = fopen($file_logged_out, 'w'); |
|
41 | + fputs($fp, implode("\n", $data_logged_out)); |
|
42 | + fclose($fp); |
|
43 | + } |
|
44 | + //tabs file for logged in users |
|
45 | + $fp = fopen($file_logged_in, 'w'); |
|
46 | + fputs($fp, implode("\n", $data_logged_in)); |
|
47 | + fclose($fp); |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | $cidReset = true; |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | $_languages = api_get_languages(); |
77 | 77 | $selfUrl = api_get_self(); |
78 | 78 | $interbreadcrumb[] = array( |
79 | - 'url' => 'index.php', |
|
80 | - 'name' => get_lang('PlatformAdmin') |
|
79 | + 'url' => 'index.php', |
|
80 | + 'name' => get_lang('PlatformAdmin') |
|
81 | 81 | ); |
82 | 82 | |
83 | 83 | if (!empty($action)) { |
84 | - $interbreadcrumb[] = array( |
|
85 | - 'url' => 'configure_homepage.php', |
|
86 | - 'name' => get_lang('ConfigureHomePage') |
|
87 | - ); |
|
88 | - |
|
89 | - switch ($action) { |
|
90 | - case 'edit_top': |
|
91 | - $tool_name = get_lang('EditHomePage'); |
|
92 | - break; |
|
93 | - case 'edit_news': |
|
94 | - $tool_name = get_lang('EditNews'); |
|
95 | - break; |
|
96 | - case 'edit_notice': |
|
97 | - $tool_name = get_lang('EditNotice'); |
|
98 | - break; |
|
99 | - case 'insert_link': |
|
100 | - $tool_name = get_lang('InsertLink'); |
|
101 | - break; |
|
102 | - case 'edit_link': |
|
103 | - $tool_name = get_lang('EditLink'); |
|
104 | - break; |
|
105 | - case 'insert_tabs': |
|
106 | - $tool_name = get_lang('InsertTabs'); |
|
107 | - break; |
|
108 | - case 'edit_tabs': |
|
109 | - $tool_name = get_lang('EditTabs'); |
|
110 | - break; |
|
111 | - } |
|
84 | + $interbreadcrumb[] = array( |
|
85 | + 'url' => 'configure_homepage.php', |
|
86 | + 'name' => get_lang('ConfigureHomePage') |
|
87 | + ); |
|
88 | + |
|
89 | + switch ($action) { |
|
90 | + case 'edit_top': |
|
91 | + $tool_name = get_lang('EditHomePage'); |
|
92 | + break; |
|
93 | + case 'edit_news': |
|
94 | + $tool_name = get_lang('EditNews'); |
|
95 | + break; |
|
96 | + case 'edit_notice': |
|
97 | + $tool_name = get_lang('EditNotice'); |
|
98 | + break; |
|
99 | + case 'insert_link': |
|
100 | + $tool_name = get_lang('InsertLink'); |
|
101 | + break; |
|
102 | + case 'edit_link': |
|
103 | + $tool_name = get_lang('EditLink'); |
|
104 | + break; |
|
105 | + case 'insert_tabs': |
|
106 | + $tool_name = get_lang('InsertTabs'); |
|
107 | + break; |
|
108 | + case 'edit_tabs': |
|
109 | + $tool_name = get_lang('EditTabs'); |
|
110 | + break; |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // The global logic for language priorities should be: |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | |
132 | 132 | $lang = ''; //el for "Edit Language" |
133 | 133 | if (!empty($_SESSION['user_language_choice'])) { |
134 | - $lang = $_SESSION['user_language_choice']; |
|
134 | + $lang = $_SESSION['user_language_choice']; |
|
135 | 135 | } elseif (!empty($_SESSION['_user']['language'])) { |
136 | - $lang = $_SESSION['_user']['language']; |
|
136 | + $lang = $_SESSION['_user']['language']; |
|
137 | 137 | } else { |
138 | - $lang = api_get_setting('platformLanguage'); |
|
138 | + $lang = api_get_setting('platformLanguage'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $languageGet = isset($_GET['language']) ? Security::remove_XSS($_GET['language']) : $lang; |
@@ -144,25 +144,25 @@ discard block |
||
144 | 144 | $homePath = api_get_path(SYS_HOME_PATH); |
145 | 145 | |
146 | 146 | if (api_is_multiple_url_enabled()) { |
147 | - $access_url_id = api_get_current_access_url_id(); |
|
148 | - if ($access_url_id != -1) { |
|
149 | - $url_info = api_get_access_url($access_url_id); |
|
150 | - $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); |
|
151 | - $clean_url = api_replace_dangerous_char($url); |
|
152 | - $clean_url = str_replace('/', '-', $clean_url); |
|
153 | - $clean_url .= '/'; |
|
154 | - |
|
155 | - $homep = $homePath; //homep for Home Path |
|
156 | - $homep_new = $homePath.$clean_url; //homep for Home Path added the url |
|
157 | - $new_url_dir = $homePath.$clean_url; |
|
158 | - //we create the new dir for the new sites |
|
159 | - if (!is_dir($new_url_dir)) { |
|
160 | - mkdir($new_url_dir, api_get_permissions_for_new_directories()); |
|
161 | - } |
|
162 | - } |
|
147 | + $access_url_id = api_get_current_access_url_id(); |
|
148 | + if ($access_url_id != -1) { |
|
149 | + $url_info = api_get_access_url($access_url_id); |
|
150 | + $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); |
|
151 | + $clean_url = api_replace_dangerous_char($url); |
|
152 | + $clean_url = str_replace('/', '-', $clean_url); |
|
153 | + $clean_url .= '/'; |
|
154 | + |
|
155 | + $homep = $homePath; //homep for Home Path |
|
156 | + $homep_new = $homePath.$clean_url; //homep for Home Path added the url |
|
157 | + $new_url_dir = $homePath.$clean_url; |
|
158 | + //we create the new dir for the new sites |
|
159 | + if (!is_dir($new_url_dir)) { |
|
160 | + mkdir($new_url_dir, api_get_permissions_for_new_directories()); |
|
161 | + } |
|
162 | + } |
|
163 | 163 | } else { |
164 | - $homep_new = ''; |
|
165 | - $homep = $homePath; //homep for Home Path |
|
164 | + $homep_new = ''; |
|
165 | + $homep = $homePath; //homep for Home Path |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $menuf = 'home_menu'; //menuf for Menu File |
@@ -177,25 +177,25 @@ discard block |
||
177 | 177 | |
178 | 178 | // If language-specific file does not exist, create it by copying default file |
179 | 179 | foreach ($homef as $my_file) { |
180 | - if (api_is_multiple_url_enabled()) { |
|
181 | - if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { |
|
182 | - if (!file_exists($homep.$my_file.$ext)) { |
|
183 | - touch($homep.$my_file.$ext); |
|
184 | - } |
|
185 | - @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); |
|
186 | - } |
|
187 | - } else { |
|
188 | - if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { |
|
189 | - if (!file_exists($homep.$my_file.$ext)) { |
|
190 | - touch($homep.$my_file.$ext); |
|
191 | - } |
|
192 | - @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); |
|
193 | - } |
|
194 | - } |
|
180 | + if (api_is_multiple_url_enabled()) { |
|
181 | + if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { |
|
182 | + if (!file_exists($homep.$my_file.$ext)) { |
|
183 | + touch($homep.$my_file.$ext); |
|
184 | + } |
|
185 | + @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); |
|
186 | + } |
|
187 | + } else { |
|
188 | + if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { |
|
189 | + if (!file_exists($homep.$my_file.$ext)) { |
|
190 | + touch($homep.$my_file.$ext); |
|
191 | + } |
|
192 | + @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | if (api_is_multiple_url_enabled()) { |
198 | - $homep = $homep_new; |
|
198 | + $homep = $homep_new; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // Check WCAG settings and prepare edition using WCAG |
@@ -204,578 +204,578 @@ discard block |
||
204 | 204 | // Filter link param |
205 | 205 | $link = ''; |
206 | 206 | if (!empty($_GET['link'])) { |
207 | - $link = $_GET['link']; |
|
208 | - // If the link parameter is suspicious, empty it |
|
209 | - if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) { |
|
210 | - $link = ''; |
|
211 | - $action = ''; |
|
212 | - } |
|
207 | + $link = $_GET['link']; |
|
208 | + // If the link parameter is suspicious, empty it |
|
209 | + if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) { |
|
210 | + $link = ''; |
|
211 | + $action = ''; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | // Start analysing requested actions |
216 | 216 | if (!empty($action)) { |
217 | - if (!empty($_POST['formSent'])) { |
|
218 | - // Variables used are $homep for home path, $menuf for menu file, $newsf |
|
219 | - // for news file, $topf for top file, $noticef for noticefile, |
|
220 | - // $ext for '.html' |
|
221 | - switch ($action) { |
|
222 | - case 'edit_top': |
|
223 | - // Filter |
|
224 | - $home_top = trim(stripslashes($_POST['home_top'])); |
|
225 | - |
|
226 | - |
|
227 | - // Write |
|
228 | - if (is_writable($homep)) { |
|
229 | - // Default |
|
230 | - if (is_writable($homep.$topf.'_'.$lang.$ext)) { |
|
231 | - $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
232 | - fputs($fp, $home_top); |
|
233 | - fclose($fp); |
|
234 | - |
|
235 | - // Language |
|
236 | - foreach ($_languages['name'] as $key => $value) { |
|
237 | - $lang_name = $_languages['folder'][$key]; |
|
238 | - if (isset($_POST[$lang_name])) { |
|
239 | - $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
240 | - fputs($fp, $home_top); |
|
241 | - fclose($fp); |
|
242 | - } |
|
243 | - } |
|
244 | - } else { |
|
245 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
246 | - } |
|
247 | - } else { |
|
248 | - //File does not exist |
|
249 | - $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
250 | - fputs($fp, $home_top); |
|
251 | - fclose($fp); |
|
252 | - |
|
253 | - foreach ($_languages['name'] as $key => $value) { |
|
254 | - $lang_name = $_languages['folder'][$key]; |
|
255 | - if (isset($_POST[$lang_name])) { |
|
256 | - if (file_exists($homep.$topf.'_'.$lang_name.$ext)) { |
|
257 | - $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
258 | - fputs($fp, $home_top); |
|
259 | - fclose($fp); |
|
260 | - } |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - if (EventsMail::check_if_using_class('portal_homepage_edited')) { |
|
266 | - EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id())); |
|
267 | - } |
|
268 | - Event::addEvent( |
|
269 | - LOG_HOMEPAGE_CHANGED, |
|
270 | - 'edit_top', |
|
271 | - cut(strip_tags($home_top), 254), |
|
272 | - api_get_utc_datetime(), |
|
273 | - api_get_user_id() |
|
274 | - ); |
|
275 | - break; |
|
276 | - case 'edit_notice': |
|
277 | - // Filter |
|
278 | - $notice_title = trim(strip_tags(stripslashes($_POST['notice_title']))); |
|
279 | - $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>'))); |
|
280 | - if (empty($notice_title) || empty($notice_text)) { |
|
281 | - $errorMsg = get_lang('NoticeWillBeNotDisplayed'); |
|
282 | - } |
|
283 | - // Write |
|
284 | - if (file_exists($homep.$noticef.'_'.$lang.$ext)) { |
|
285 | - if (is_writable($homep.$noticef.'_'.$lang.$ext)) { |
|
286 | - $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
287 | - if ($errorMsg == '') { |
|
288 | - fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
289 | - |
|
290 | - foreach ($_languages['name'] as $key => $value) { |
|
291 | - $lang_name = $_languages['folder'][$key]; |
|
292 | - if (isset($_POST[$lang_name])) { |
|
293 | - if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
294 | - if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) { |
|
295 | - $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
296 | - fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
297 | - fclose($fp); |
|
298 | - } |
|
299 | - } |
|
300 | - } |
|
301 | - } |
|
302 | - } else { |
|
303 | - fputs($fp, ''); |
|
304 | - |
|
305 | - foreach ($_languages['name'] as $key => $value) { |
|
306 | - $lang_name = $_languages['folder'][$key]; |
|
307 | - if (isset($_POST[$lang_name])) { |
|
308 | - if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
309 | - $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
310 | - fputs($fp1, ''); |
|
311 | - fclose($fp1); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - } |
|
316 | - fclose($fp); |
|
317 | - } else { |
|
318 | - $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable'); |
|
319 | - } |
|
320 | - } else { |
|
321 | - //File does not exist |
|
322 | - $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
323 | - fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
324 | - fclose($fp); |
|
325 | - } |
|
326 | - Event::addEvent( |
|
217 | + if (!empty($_POST['formSent'])) { |
|
218 | + // Variables used are $homep for home path, $menuf for menu file, $newsf |
|
219 | + // for news file, $topf for top file, $noticef for noticefile, |
|
220 | + // $ext for '.html' |
|
221 | + switch ($action) { |
|
222 | + case 'edit_top': |
|
223 | + // Filter |
|
224 | + $home_top = trim(stripslashes($_POST['home_top'])); |
|
225 | + |
|
226 | + |
|
227 | + // Write |
|
228 | + if (is_writable($homep)) { |
|
229 | + // Default |
|
230 | + if (is_writable($homep.$topf.'_'.$lang.$ext)) { |
|
231 | + $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
232 | + fputs($fp, $home_top); |
|
233 | + fclose($fp); |
|
234 | + |
|
235 | + // Language |
|
236 | + foreach ($_languages['name'] as $key => $value) { |
|
237 | + $lang_name = $_languages['folder'][$key]; |
|
238 | + if (isset($_POST[$lang_name])) { |
|
239 | + $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
240 | + fputs($fp, $home_top); |
|
241 | + fclose($fp); |
|
242 | + } |
|
243 | + } |
|
244 | + } else { |
|
245 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
246 | + } |
|
247 | + } else { |
|
248 | + //File does not exist |
|
249 | + $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
250 | + fputs($fp, $home_top); |
|
251 | + fclose($fp); |
|
252 | + |
|
253 | + foreach ($_languages['name'] as $key => $value) { |
|
254 | + $lang_name = $_languages['folder'][$key]; |
|
255 | + if (isset($_POST[$lang_name])) { |
|
256 | + if (file_exists($homep.$topf.'_'.$lang_name.$ext)) { |
|
257 | + $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
258 | + fputs($fp, $home_top); |
|
259 | + fclose($fp); |
|
260 | + } |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + if (EventsMail::check_if_using_class('portal_homepage_edited')) { |
|
266 | + EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id())); |
|
267 | + } |
|
268 | + Event::addEvent( |
|
269 | + LOG_HOMEPAGE_CHANGED, |
|
270 | + 'edit_top', |
|
271 | + cut(strip_tags($home_top), 254), |
|
272 | + api_get_utc_datetime(), |
|
273 | + api_get_user_id() |
|
274 | + ); |
|
275 | + break; |
|
276 | + case 'edit_notice': |
|
277 | + // Filter |
|
278 | + $notice_title = trim(strip_tags(stripslashes($_POST['notice_title']))); |
|
279 | + $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>'))); |
|
280 | + if (empty($notice_title) || empty($notice_text)) { |
|
281 | + $errorMsg = get_lang('NoticeWillBeNotDisplayed'); |
|
282 | + } |
|
283 | + // Write |
|
284 | + if (file_exists($homep.$noticef.'_'.$lang.$ext)) { |
|
285 | + if (is_writable($homep.$noticef.'_'.$lang.$ext)) { |
|
286 | + $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
287 | + if ($errorMsg == '') { |
|
288 | + fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
289 | + |
|
290 | + foreach ($_languages['name'] as $key => $value) { |
|
291 | + $lang_name = $_languages['folder'][$key]; |
|
292 | + if (isset($_POST[$lang_name])) { |
|
293 | + if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
294 | + if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) { |
|
295 | + $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
296 | + fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
297 | + fclose($fp); |
|
298 | + } |
|
299 | + } |
|
300 | + } |
|
301 | + } |
|
302 | + } else { |
|
303 | + fputs($fp, ''); |
|
304 | + |
|
305 | + foreach ($_languages['name'] as $key => $value) { |
|
306 | + $lang_name = $_languages['folder'][$key]; |
|
307 | + if (isset($_POST[$lang_name])) { |
|
308 | + if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
309 | + $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
310 | + fputs($fp1, ''); |
|
311 | + fclose($fp1); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + } |
|
316 | + fclose($fp); |
|
317 | + } else { |
|
318 | + $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable'); |
|
319 | + } |
|
320 | + } else { |
|
321 | + //File does not exist |
|
322 | + $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
323 | + fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
324 | + fclose($fp); |
|
325 | + } |
|
326 | + Event::addEvent( |
|
327 | 327 | LOG_HOMEPAGE_CHANGED, |
328 | 328 | 'edit_notice', |
329 | 329 | cut(strip_tags($notice_title), 254), |
330 | 330 | api_get_utc_datetime(), |
331 | 331 | api_get_user_id() |
332 | 332 | ); |
333 | - break; |
|
334 | - case 'edit_news': |
|
335 | - //Filter |
|
336 | - $home_news = trim(stripslashes($_POST['home_news'])); |
|
337 | - |
|
338 | - //Write |
|
339 | - if ($s_languages_news != 'all') { |
|
340 | - if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
341 | - if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
342 | - $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
343 | - fputs($fp, $home_news); |
|
344 | - fclose($fp); |
|
345 | - } else { |
|
346 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
347 | - } |
|
348 | - } else { |
|
349 | - // File does not exist |
|
350 | - $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
351 | - fputs($fp, $home_news); |
|
352 | - fclose($fp); |
|
353 | - } |
|
354 | - } else { |
|
355 | - // We update all the news file |
|
356 | - foreach ($_languages['name'] as $key => $value) { |
|
357 | - $english_name = $_languages['folder'][$key]; |
|
358 | - if (file_exists($homep.$newsf.'_'.$english_name.$ext)) { |
|
359 | - if (is_writable($homep.$newsf.'_'.$english_name.$ext)) { |
|
360 | - $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
361 | - fputs($fp, $home_news); |
|
362 | - fclose($fp); |
|
363 | - } else { |
|
364 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
365 | - } |
|
366 | - } else { |
|
367 | - // File does not exist |
|
368 | - $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
369 | - fputs($fp, $home_news); |
|
370 | - fclose($fp); |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
374 | - Event::addEvent( |
|
333 | + break; |
|
334 | + case 'edit_news': |
|
335 | + //Filter |
|
336 | + $home_news = trim(stripslashes($_POST['home_news'])); |
|
337 | + |
|
338 | + //Write |
|
339 | + if ($s_languages_news != 'all') { |
|
340 | + if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
341 | + if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
342 | + $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
343 | + fputs($fp, $home_news); |
|
344 | + fclose($fp); |
|
345 | + } else { |
|
346 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
347 | + } |
|
348 | + } else { |
|
349 | + // File does not exist |
|
350 | + $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
351 | + fputs($fp, $home_news); |
|
352 | + fclose($fp); |
|
353 | + } |
|
354 | + } else { |
|
355 | + // We update all the news file |
|
356 | + foreach ($_languages['name'] as $key => $value) { |
|
357 | + $english_name = $_languages['folder'][$key]; |
|
358 | + if (file_exists($homep.$newsf.'_'.$english_name.$ext)) { |
|
359 | + if (is_writable($homep.$newsf.'_'.$english_name.$ext)) { |
|
360 | + $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
361 | + fputs($fp, $home_news); |
|
362 | + fclose($fp); |
|
363 | + } else { |
|
364 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
365 | + } |
|
366 | + } else { |
|
367 | + // File does not exist |
|
368 | + $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
369 | + fputs($fp, $home_news); |
|
370 | + fclose($fp); |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | + Event::addEvent( |
|
375 | 375 | LOG_HOMEPAGE_CHANGED, |
376 | 376 | 'edit_news', |
377 | 377 | strip_tags(cut($home_news, 254)), |
378 | 378 | api_get_utc_datetime(), |
379 | 379 | api_get_user_id() |
380 | 380 | ); |
381 | - break; |
|
382 | - case 'insert_tabs': |
|
383 | - case 'edit_tabs': |
|
384 | - case 'insert_link': |
|
385 | - case 'edit_link': |
|
386 | - $link_index = intval($_POST['link_index']); |
|
387 | - $insert_where = intval($_POST['insert_where']); |
|
388 | - $link_name = trim(stripslashes($_POST['link_name'])); |
|
389 | - $link_url = trim(stripslashes($_POST['link_url'])); |
|
390 | - $add_in_tab = intval($_POST['add_in_tab']); |
|
391 | - $link_html = trim(stripslashes($_POST['link_html'])); |
|
392 | - $filename = trim(stripslashes($_POST['filename'])); |
|
393 | - $target_blank = $_POST['target_blank'] ? true : false; |
|
394 | - |
|
395 | - if ($link_url == 'http://' || $link_url == 'https://') { |
|
396 | - $link_url = ''; |
|
397 | - } elseif (!empty($link_url) && !strstr($link_url, '://')) { |
|
398 | - $link_url='http://'.$link_url; |
|
399 | - } |
|
400 | - $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf; |
|
401 | - |
|
402 | - if (!is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
403 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
404 | - } elseif (empty($link_name)) { |
|
405 | - $errorMsg = get_lang('PleaseEnterLinkName'); |
|
406 | - } else { |
|
407 | - // New links are added as new files in the home/ directory |
|
408 | - if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) { |
|
409 | - $filename = api_replace_dangerous_char($link_name).'.html'; |
|
410 | - } |
|
411 | - |
|
412 | - // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files) |
|
413 | - if (!empty($filename)) { |
|
414 | - $filename = str_replace('home_', 'user_', $filename); |
|
415 | - } |
|
416 | - // If the typical language suffix is not found in the file name, |
|
417 | - // replace the ".html" suffix by "_en.html" or the active menu language |
|
418 | - if (!strstr($filename,'_'.$lang.$ext)) { |
|
419 | - $filename = str_replace($ext, '_'.$lang.$ext, $filename); |
|
420 | - } |
|
421 | - // Get the contents of home_menu_en.html (or active menu language |
|
422 | - // version) into $home_menu as an array of one entry per line |
|
423 | - $home_menu = file($homep.$menuf.'_'.$lang.$ext); |
|
424 | - $home_menu = implode("\n", $home_menu); |
|
425 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
426 | - $home_menu = explode("\n", $home_menu); |
|
427 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
428 | - // Prepare place to insert the new link into (default is end of file) |
|
429 | - if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) { |
|
430 | - $insert_where = sizeof($home_menu) - 1; |
|
431 | - } |
|
432 | - // |
|
433 | - // For each line of the file, remove trailing spaces and special chars |
|
434 | - //foreach ($home_menu as $key => $enreg) { |
|
435 | - // $home_menu[$key] = trim($enreg); |
|
436 | - //} |
|
437 | - // |
|
438 | - // If the given link url is empty, then replace the link url by a link to the link file created |
|
439 | - |
|
440 | - if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') { |
|
441 | - $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename); |
|
442 | - // If the file doesn't exist, then create it and |
|
443 | - // fill it with default text |
|
444 | - |
|
445 | - $fp = @fopen($homep.$filename, 'w'); |
|
446 | - if ($fp) { |
|
447 | - if (empty($link_html)) { |
|
448 | - fputs($fp, get_lang('MyTextHere')); |
|
449 | - home_tabs($homep.$filename); |
|
450 | - } else { |
|
451 | - fputs($fp, $link_html); |
|
452 | - home_tabs($homep.$filename); |
|
453 | - } |
|
454 | - fclose($fp); |
|
455 | - } |
|
456 | - } |
|
457 | - // If the requested action is to edit a link, open the file and |
|
458 | - // write to it (if the file doesn't exist, create it) |
|
459 | - if (in_array($action, array('edit_link')) && !empty($link_html)) { |
|
460 | - $fp = @fopen($homep.$filename, 'w'); |
|
461 | - if ($fp) { |
|
462 | - fputs($fp, $link_html); |
|
463 | - home_tabs($homep.$filename); |
|
464 | - fclose($fp); |
|
465 | - } |
|
466 | - } |
|
381 | + break; |
|
382 | + case 'insert_tabs': |
|
383 | + case 'edit_tabs': |
|
384 | + case 'insert_link': |
|
385 | + case 'edit_link': |
|
386 | + $link_index = intval($_POST['link_index']); |
|
387 | + $insert_where = intval($_POST['insert_where']); |
|
388 | + $link_name = trim(stripslashes($_POST['link_name'])); |
|
389 | + $link_url = trim(stripslashes($_POST['link_url'])); |
|
390 | + $add_in_tab = intval($_POST['add_in_tab']); |
|
391 | + $link_html = trim(stripslashes($_POST['link_html'])); |
|
392 | + $filename = trim(stripslashes($_POST['filename'])); |
|
393 | + $target_blank = $_POST['target_blank'] ? true : false; |
|
394 | + |
|
395 | + if ($link_url == 'http://' || $link_url == 'https://') { |
|
396 | + $link_url = ''; |
|
397 | + } elseif (!empty($link_url) && !strstr($link_url, '://')) { |
|
398 | + $link_url='http://'.$link_url; |
|
399 | + } |
|
400 | + $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf; |
|
401 | + |
|
402 | + if (!is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
403 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
404 | + } elseif (empty($link_name)) { |
|
405 | + $errorMsg = get_lang('PleaseEnterLinkName'); |
|
406 | + } else { |
|
407 | + // New links are added as new files in the home/ directory |
|
408 | + if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) { |
|
409 | + $filename = api_replace_dangerous_char($link_name).'.html'; |
|
410 | + } |
|
411 | + |
|
412 | + // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files) |
|
413 | + if (!empty($filename)) { |
|
414 | + $filename = str_replace('home_', 'user_', $filename); |
|
415 | + } |
|
416 | + // If the typical language suffix is not found in the file name, |
|
417 | + // replace the ".html" suffix by "_en.html" or the active menu language |
|
418 | + if (!strstr($filename,'_'.$lang.$ext)) { |
|
419 | + $filename = str_replace($ext, '_'.$lang.$ext, $filename); |
|
420 | + } |
|
421 | + // Get the contents of home_menu_en.html (or active menu language |
|
422 | + // version) into $home_menu as an array of one entry per line |
|
423 | + $home_menu = file($homep.$menuf.'_'.$lang.$ext); |
|
424 | + $home_menu = implode("\n", $home_menu); |
|
425 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
426 | + $home_menu = explode("\n", $home_menu); |
|
427 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
428 | + // Prepare place to insert the new link into (default is end of file) |
|
429 | + if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) { |
|
430 | + $insert_where = sizeof($home_menu) - 1; |
|
431 | + } |
|
432 | + // |
|
433 | + // For each line of the file, remove trailing spaces and special chars |
|
434 | + //foreach ($home_menu as $key => $enreg) { |
|
435 | + // $home_menu[$key] = trim($enreg); |
|
436 | + //} |
|
437 | + // |
|
438 | + // If the given link url is empty, then replace the link url by a link to the link file created |
|
439 | + |
|
440 | + if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') { |
|
441 | + $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename); |
|
442 | + // If the file doesn't exist, then create it and |
|
443 | + // fill it with default text |
|
444 | + |
|
445 | + $fp = @fopen($homep.$filename, 'w'); |
|
446 | + if ($fp) { |
|
447 | + if (empty($link_html)) { |
|
448 | + fputs($fp, get_lang('MyTextHere')); |
|
449 | + home_tabs($homep.$filename); |
|
450 | + } else { |
|
451 | + fputs($fp, $link_html); |
|
452 | + home_tabs($homep.$filename); |
|
453 | + } |
|
454 | + fclose($fp); |
|
455 | + } |
|
456 | + } |
|
457 | + // If the requested action is to edit a link, open the file and |
|
458 | + // write to it (if the file doesn't exist, create it) |
|
459 | + if (in_array($action, array('edit_link')) && !empty($link_html)) { |
|
460 | + $fp = @fopen($homep.$filename, 'w'); |
|
461 | + if ($fp) { |
|
462 | + fputs($fp, $link_html); |
|
463 | + home_tabs($homep.$filename); |
|
464 | + fclose($fp); |
|
465 | + } |
|
466 | + } |
|
467 | 467 | |
468 | 468 | $class_add_in_tab = 'class="show_menu"'; |
469 | 469 | |
470 | - if (!$add_in_tab) { |
|
471 | - $class_add_in_tab = 'class="hide_menu"'; |
|
472 | - } |
|
473 | - |
|
474 | - // If the requested action is to create a link, make some room |
|
475 | - // for the new link in the home_menu array at the requested place |
|
476 | - // and insert the new link there |
|
477 | - |
|
478 | - if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
479 | - for ($i = sizeof($home_menu); $i; $i--) { |
|
480 | - if ($i > $insert_where) { |
|
481 | - $home_menu[$i] = $home_menu[$i - 1]; |
|
482 | - } else { |
|
483 | - break; |
|
484 | - } |
|
485 | - } |
|
486 | - $home_menu[$insert_where + 1] = '<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>'; |
|
487 | - } else { |
|
488 | - // If the request is about a link edition, change the link |
|
489 | - $home_menu[$link_index]='<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>'; |
|
490 | - } |
|
491 | - // Re-build the file from the home_menu array |
|
492 | - $home_menu = implode("\n", $home_menu); |
|
493 | - // Write |
|
494 | - if (file_exists($homep.$menuf.'_'.$lang.$ext)) { |
|
495 | - if (is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
496 | - $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
497 | - fputs($fp, $home_menu); |
|
498 | - home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
499 | - fclose($fp); |
|
500 | - |
|
501 | - foreach ($_languages['name'] as $key => $value) { |
|
502 | - $lang_name = $_languages['folder'][$key]; |
|
503 | - if (isset($_POST[$lang_name])) { |
|
504 | - $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
505 | - fputs($fp, $home_menu); |
|
506 | - home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
507 | - fclose($fp); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - if (file_exists($homep.$menuf.$ext)) { |
|
512 | - if (is_writable($homep.$menuf.$ext)) { |
|
513 | - $fpo = fopen($homep.$menuf.$ext, 'w'); |
|
514 | - fputs($fpo, $home_menu); |
|
515 | - home_tabs($homep.$menuf.$ext); |
|
516 | - fclose($fpo); |
|
517 | - } |
|
518 | - } |
|
519 | - } else { |
|
520 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
521 | - } |
|
522 | - } else { |
|
523 | - //File does not exist |
|
524 | - $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
525 | - fputs($fp, $home_menu); |
|
526 | - home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
527 | - fclose($fp); |
|
528 | - |
|
529 | - foreach ($_languages['name'] as $key => $value) { |
|
530 | - $lang_name = $_languages['folder'][$key]; |
|
531 | - if (isset($_POST[$lang_name])) { |
|
532 | - $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
533 | - fputs($fp, $home_menu); |
|
534 | - home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
535 | - fclose($fp); |
|
536 | - } |
|
537 | - } |
|
538 | - } |
|
539 | - } |
|
540 | - Event::addEvent( |
|
541 | - LOG_HOMEPAGE_CHANGED, |
|
542 | - $action, |
|
543 | - cut($link_name . ':' . $link_url, 254), |
|
544 | - api_get_utc_datetime(), |
|
545 | - api_get_user_id() |
|
546 | - ); |
|
547 | - break; |
|
548 | - } //end of switch($action) |
|
549 | - |
|
550 | - if (empty($errorMsg)) { |
|
551 | - header('Location: '.$selfUrl.'?language='.$languageGet); |
|
552 | - exit(); |
|
553 | - } |
|
554 | - } else { |
|
555 | - //if POST[formSent] is not set |
|
556 | - switch ($action) { |
|
557 | - case 'open_link': |
|
558 | - // Previously, filtering of GET['link'] was done here but it left |
|
559 | - // a security threat. Filtering has now been moved outside conditions |
|
560 | - break; |
|
561 | - case 'delete_tabs': |
|
562 | - case 'delete_link': |
|
563 | - // A link is deleted by getting the file into an array, removing the |
|
564 | - // link and re-writing the array to the file |
|
565 | - $link_index = intval($_GET['link_index']); |
|
566 | - $menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf; |
|
567 | - $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
568 | - if (empty($home_menu)) { |
|
569 | - $home_menu = array(); |
|
570 | - } |
|
571 | - foreach ($home_menu as $key => $enreg) { |
|
572 | - if ($key == $link_index) { |
|
573 | - unset($home_menu[$key]); |
|
574 | - } else { |
|
575 | - $home_menu[$key] = trim($enreg); |
|
576 | - } |
|
577 | - } |
|
578 | - $home_menu = implode("\n", $home_menu); |
|
579 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
580 | - |
|
581 | - $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
582 | - fputs($fp, $home_menu); |
|
583 | - home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
584 | - fclose($fp); |
|
585 | - if (file_exists($homep.$menuf.$ext)) { |
|
586 | - if (is_writable($homep.$menuf.$ext)) { |
|
587 | - $fpo = fopen($homep.$menuf.$ext,'w'); |
|
588 | - fputs($fpo, $home_menu); |
|
589 | - home_tabs($homep.$menuf.$ext); |
|
590 | - fclose($fpo); |
|
591 | - } |
|
592 | - } |
|
593 | - header('Location: '.$selfUrl); |
|
594 | - exit(); |
|
595 | - break; |
|
596 | - case 'edit_top': |
|
597 | - // This request is only the preparation for the update of the home_top |
|
598 | - $home_top = ''; |
|
599 | - if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { |
|
600 | - $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); |
|
601 | - } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { |
|
602 | - $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext); |
|
603 | - } else { |
|
604 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
605 | - } |
|
606 | - $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); |
|
607 | - break; |
|
608 | - case 'edit_notice': |
|
609 | - // This request is only the preparation for the update of the home_notice |
|
610 | - $home_notice = ''; |
|
611 | - if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) { |
|
612 | - $home_notice = @file($homep.$noticef.'_'.$lang.$ext); |
|
613 | - } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) { |
|
614 | - $home_notice = @file($homep.$noticef.$lang.$ext); |
|
615 | - } else { |
|
616 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
617 | - } |
|
618 | - if (empty($home_notice)) { |
|
619 | - $home_notice = array(); |
|
620 | - } |
|
621 | - $notice_title = strip_tags($home_notice[0]); |
|
622 | - $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title)); |
|
623 | - $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>'); |
|
624 | - $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text))); |
|
625 | - break; |
|
626 | - case 'edit_news': |
|
627 | - // This request is the preparation for the update of the home_news page |
|
628 | - $home_news = ''; |
|
629 | - if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) { |
|
630 | - $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
631 | - } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) { |
|
632 | - $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext); |
|
633 | - } else { |
|
634 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
635 | - } |
|
636 | - $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news))); |
|
637 | - break; |
|
638 | - case 'insert_link': |
|
639 | - // This request is the preparation for the addition of an item in home_menu |
|
640 | - $home_menu = ''; |
|
641 | - $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
642 | - if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
643 | - $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
644 | - } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
645 | - $home_menu = @file($homep.$menuf.$lang.$ext); |
|
646 | - } else { |
|
647 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
648 | - } |
|
649 | - if (empty($home_menu)) { |
|
650 | - $home_menu = array(); |
|
651 | - } |
|
652 | - if (!empty($home_menu)) { |
|
653 | - $home_menu = implode("\n", $home_menu); |
|
654 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
655 | - $home_menu = explode("\n", $home_menu); |
|
656 | - } |
|
657 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
658 | - break; |
|
659 | - case 'insert_tabs': |
|
660 | - // This request is the preparation for the addition of an item in home_menu |
|
661 | - $home_menu = ''; |
|
662 | - if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
663 | - $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
664 | - } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) { |
|
665 | - $home_menu = @file($homep.$mtloggedin.$lang.$ext); |
|
666 | - } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
667 | - $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
668 | - } else { |
|
669 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
670 | - } |
|
671 | - if (empty($home_menu)) { |
|
672 | - $home_menu = array(); |
|
673 | - } |
|
674 | - if (!empty($home_menu)) { |
|
675 | - $home_menu = implode("\n", $home_menu); |
|
676 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
677 | - $home_menu = explode("\n", $home_menu); |
|
678 | - } |
|
679 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
680 | - break; |
|
681 | - case 'edit_tabs': |
|
682 | - case 'edit_link': |
|
683 | - // This request is the preparation for the edition of the links array |
|
684 | - $home_menu = ''; |
|
685 | - $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
686 | - if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
687 | - $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
688 | - } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
689 | - $home_menu = @file($homep.$menuf.$lang.$ext); |
|
690 | - } else { |
|
691 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
692 | - } |
|
693 | - |
|
694 | - if (empty($home_menu)) { |
|
695 | - if (file_exists($homep.$menutabs.'_'.$lang.$ext)) { |
|
696 | - $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
697 | - } |
|
698 | - } |
|
699 | - |
|
700 | - if (empty($home_menu)) { |
|
701 | - $home_menu = array(); |
|
702 | - } |
|
703 | - if (!empty($home_menu)) { |
|
704 | - $home_menu = implode("\n", $home_menu); |
|
705 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
706 | - $home_menu = explode("\n", $home_menu); |
|
707 | - } |
|
708 | - |
|
709 | - $link_index = intval($_GET['link_index']); |
|
710 | - |
|
711 | - $target_blank = false; |
|
712 | - $link_name = ''; |
|
713 | - $link_url = ''; |
|
714 | - |
|
715 | - //$home_menu_new = array(); |
|
716 | - // |
|
717 | - //Cleaning array |
|
718 | - //foreach ($home_menu as $item) { |
|
719 | - // if(!empty($item)) { |
|
720 | - // $home_menu_new[] = $item; |
|
721 | - // } |
|
722 | - //} |
|
723 | - //$home_menu = $home_menu_new; |
|
724 | - |
|
725 | - // Cleaning the array |
|
726 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
727 | - |
|
728 | - // For each line of the home_menu file |
|
729 | - foreach ($home_menu as $key => $enreg) { |
|
730 | - |
|
731 | - // Check if the current item is the one we want to update |
|
732 | - if ($key == $link_index) { |
|
733 | - // This is the link we want to update |
|
734 | - // Check if the target should be "_blank" |
|
735 | - if (strstr($enreg, 'target="_blank"')) { |
|
736 | - $target_blank = true; |
|
737 | - } |
|
738 | - |
|
739 | - if (strstr($enreg, 'hide_menu')) { |
|
740 | - $add_in_tab = false; |
|
741 | - } else { |
|
742 | - $add_in_tab = true; |
|
743 | - } |
|
744 | - |
|
745 | - // Remove dangerous HTML tags from the link itself (this is an |
|
746 | - // additional measure in case a link previously contained |
|
747 | - // unsecure tags) |
|
748 | - $link_name = strip_tags($enreg); |
|
749 | - |
|
750 | - // Get the contents of "href" attribute in $link_url |
|
751 | - $enreg = explode('href="',$enreg); |
|
752 | - list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]); |
|
753 | - |
|
754 | - // If the link contains the web root of this portal, then strip |
|
755 | - // it off and keep only the name of the file that needs edition |
|
756 | - if (strstr($link_url, '?include=')) { |
|
757 | - $link_url = explode('?include=', $link_url); |
|
758 | - |
|
759 | - $filename = $link_url[sizeof($link_url) - 1]; |
|
760 | - |
|
761 | - if (!strstr($filename, '/') && strstr($filename, '.html')) { |
|
762 | - // Get oonly the contents of the link file |
|
763 | - $link_html = @file($homep.$filename); |
|
764 | - $link_html = implode('', $link_html); |
|
765 | - $link_url = ''; |
|
766 | - } else { |
|
767 | - $filename = ''; |
|
768 | - } |
|
769 | - } |
|
770 | - break; |
|
771 | - } |
|
772 | - } |
|
773 | - break; |
|
774 | - }//end of second switch($action) (when POST['formSent'] was not set, yet) |
|
775 | - }// end of "else" in if($_POST['formSent']) condition |
|
470 | + if (!$add_in_tab) { |
|
471 | + $class_add_in_tab = 'class="hide_menu"'; |
|
472 | + } |
|
473 | + |
|
474 | + // If the requested action is to create a link, make some room |
|
475 | + // for the new link in the home_menu array at the requested place |
|
476 | + // and insert the new link there |
|
477 | + |
|
478 | + if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
479 | + for ($i = sizeof($home_menu); $i; $i--) { |
|
480 | + if ($i > $insert_where) { |
|
481 | + $home_menu[$i] = $home_menu[$i - 1]; |
|
482 | + } else { |
|
483 | + break; |
|
484 | + } |
|
485 | + } |
|
486 | + $home_menu[$insert_where + 1] = '<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>'; |
|
487 | + } else { |
|
488 | + // If the request is about a link edition, change the link |
|
489 | + $home_menu[$link_index]='<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>'; |
|
490 | + } |
|
491 | + // Re-build the file from the home_menu array |
|
492 | + $home_menu = implode("\n", $home_menu); |
|
493 | + // Write |
|
494 | + if (file_exists($homep.$menuf.'_'.$lang.$ext)) { |
|
495 | + if (is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
496 | + $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
497 | + fputs($fp, $home_menu); |
|
498 | + home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
499 | + fclose($fp); |
|
500 | + |
|
501 | + foreach ($_languages['name'] as $key => $value) { |
|
502 | + $lang_name = $_languages['folder'][$key]; |
|
503 | + if (isset($_POST[$lang_name])) { |
|
504 | + $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
505 | + fputs($fp, $home_menu); |
|
506 | + home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
507 | + fclose($fp); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + if (file_exists($homep.$menuf.$ext)) { |
|
512 | + if (is_writable($homep.$menuf.$ext)) { |
|
513 | + $fpo = fopen($homep.$menuf.$ext, 'w'); |
|
514 | + fputs($fpo, $home_menu); |
|
515 | + home_tabs($homep.$menuf.$ext); |
|
516 | + fclose($fpo); |
|
517 | + } |
|
518 | + } |
|
519 | + } else { |
|
520 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
521 | + } |
|
522 | + } else { |
|
523 | + //File does not exist |
|
524 | + $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
525 | + fputs($fp, $home_menu); |
|
526 | + home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
527 | + fclose($fp); |
|
528 | + |
|
529 | + foreach ($_languages['name'] as $key => $value) { |
|
530 | + $lang_name = $_languages['folder'][$key]; |
|
531 | + if (isset($_POST[$lang_name])) { |
|
532 | + $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
533 | + fputs($fp, $home_menu); |
|
534 | + home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
535 | + fclose($fp); |
|
536 | + } |
|
537 | + } |
|
538 | + } |
|
539 | + } |
|
540 | + Event::addEvent( |
|
541 | + LOG_HOMEPAGE_CHANGED, |
|
542 | + $action, |
|
543 | + cut($link_name . ':' . $link_url, 254), |
|
544 | + api_get_utc_datetime(), |
|
545 | + api_get_user_id() |
|
546 | + ); |
|
547 | + break; |
|
548 | + } //end of switch($action) |
|
549 | + |
|
550 | + if (empty($errorMsg)) { |
|
551 | + header('Location: '.$selfUrl.'?language='.$languageGet); |
|
552 | + exit(); |
|
553 | + } |
|
554 | + } else { |
|
555 | + //if POST[formSent] is not set |
|
556 | + switch ($action) { |
|
557 | + case 'open_link': |
|
558 | + // Previously, filtering of GET['link'] was done here but it left |
|
559 | + // a security threat. Filtering has now been moved outside conditions |
|
560 | + break; |
|
561 | + case 'delete_tabs': |
|
562 | + case 'delete_link': |
|
563 | + // A link is deleted by getting the file into an array, removing the |
|
564 | + // link and re-writing the array to the file |
|
565 | + $link_index = intval($_GET['link_index']); |
|
566 | + $menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf; |
|
567 | + $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
568 | + if (empty($home_menu)) { |
|
569 | + $home_menu = array(); |
|
570 | + } |
|
571 | + foreach ($home_menu as $key => $enreg) { |
|
572 | + if ($key == $link_index) { |
|
573 | + unset($home_menu[$key]); |
|
574 | + } else { |
|
575 | + $home_menu[$key] = trim($enreg); |
|
576 | + } |
|
577 | + } |
|
578 | + $home_menu = implode("\n", $home_menu); |
|
579 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
580 | + |
|
581 | + $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
582 | + fputs($fp, $home_menu); |
|
583 | + home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
584 | + fclose($fp); |
|
585 | + if (file_exists($homep.$menuf.$ext)) { |
|
586 | + if (is_writable($homep.$menuf.$ext)) { |
|
587 | + $fpo = fopen($homep.$menuf.$ext,'w'); |
|
588 | + fputs($fpo, $home_menu); |
|
589 | + home_tabs($homep.$menuf.$ext); |
|
590 | + fclose($fpo); |
|
591 | + } |
|
592 | + } |
|
593 | + header('Location: '.$selfUrl); |
|
594 | + exit(); |
|
595 | + break; |
|
596 | + case 'edit_top': |
|
597 | + // This request is only the preparation for the update of the home_top |
|
598 | + $home_top = ''; |
|
599 | + if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { |
|
600 | + $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); |
|
601 | + } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { |
|
602 | + $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext); |
|
603 | + } else { |
|
604 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
605 | + } |
|
606 | + $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); |
|
607 | + break; |
|
608 | + case 'edit_notice': |
|
609 | + // This request is only the preparation for the update of the home_notice |
|
610 | + $home_notice = ''; |
|
611 | + if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) { |
|
612 | + $home_notice = @file($homep.$noticef.'_'.$lang.$ext); |
|
613 | + } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) { |
|
614 | + $home_notice = @file($homep.$noticef.$lang.$ext); |
|
615 | + } else { |
|
616 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
617 | + } |
|
618 | + if (empty($home_notice)) { |
|
619 | + $home_notice = array(); |
|
620 | + } |
|
621 | + $notice_title = strip_tags($home_notice[0]); |
|
622 | + $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title)); |
|
623 | + $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>'); |
|
624 | + $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text))); |
|
625 | + break; |
|
626 | + case 'edit_news': |
|
627 | + // This request is the preparation for the update of the home_news page |
|
628 | + $home_news = ''; |
|
629 | + if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) { |
|
630 | + $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
631 | + } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) { |
|
632 | + $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext); |
|
633 | + } else { |
|
634 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
635 | + } |
|
636 | + $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news))); |
|
637 | + break; |
|
638 | + case 'insert_link': |
|
639 | + // This request is the preparation for the addition of an item in home_menu |
|
640 | + $home_menu = ''; |
|
641 | + $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
642 | + if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
643 | + $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
644 | + } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
645 | + $home_menu = @file($homep.$menuf.$lang.$ext); |
|
646 | + } else { |
|
647 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
648 | + } |
|
649 | + if (empty($home_menu)) { |
|
650 | + $home_menu = array(); |
|
651 | + } |
|
652 | + if (!empty($home_menu)) { |
|
653 | + $home_menu = implode("\n", $home_menu); |
|
654 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
655 | + $home_menu = explode("\n", $home_menu); |
|
656 | + } |
|
657 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
658 | + break; |
|
659 | + case 'insert_tabs': |
|
660 | + // This request is the preparation for the addition of an item in home_menu |
|
661 | + $home_menu = ''; |
|
662 | + if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
663 | + $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
664 | + } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) { |
|
665 | + $home_menu = @file($homep.$mtloggedin.$lang.$ext); |
|
666 | + } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
667 | + $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
668 | + } else { |
|
669 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
670 | + } |
|
671 | + if (empty($home_menu)) { |
|
672 | + $home_menu = array(); |
|
673 | + } |
|
674 | + if (!empty($home_menu)) { |
|
675 | + $home_menu = implode("\n", $home_menu); |
|
676 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
677 | + $home_menu = explode("\n", $home_menu); |
|
678 | + } |
|
679 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
680 | + break; |
|
681 | + case 'edit_tabs': |
|
682 | + case 'edit_link': |
|
683 | + // This request is the preparation for the edition of the links array |
|
684 | + $home_menu = ''; |
|
685 | + $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
686 | + if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
687 | + $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
688 | + } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
689 | + $home_menu = @file($homep.$menuf.$lang.$ext); |
|
690 | + } else { |
|
691 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
692 | + } |
|
693 | + |
|
694 | + if (empty($home_menu)) { |
|
695 | + if (file_exists($homep.$menutabs.'_'.$lang.$ext)) { |
|
696 | + $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
697 | + } |
|
698 | + } |
|
699 | + |
|
700 | + if (empty($home_menu)) { |
|
701 | + $home_menu = array(); |
|
702 | + } |
|
703 | + if (!empty($home_menu)) { |
|
704 | + $home_menu = implode("\n", $home_menu); |
|
705 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
706 | + $home_menu = explode("\n", $home_menu); |
|
707 | + } |
|
708 | + |
|
709 | + $link_index = intval($_GET['link_index']); |
|
710 | + |
|
711 | + $target_blank = false; |
|
712 | + $link_name = ''; |
|
713 | + $link_url = ''; |
|
714 | + |
|
715 | + //$home_menu_new = array(); |
|
716 | + // |
|
717 | + //Cleaning array |
|
718 | + //foreach ($home_menu as $item) { |
|
719 | + // if(!empty($item)) { |
|
720 | + // $home_menu_new[] = $item; |
|
721 | + // } |
|
722 | + //} |
|
723 | + //$home_menu = $home_menu_new; |
|
724 | + |
|
725 | + // Cleaning the array |
|
726 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
727 | + |
|
728 | + // For each line of the home_menu file |
|
729 | + foreach ($home_menu as $key => $enreg) { |
|
730 | + |
|
731 | + // Check if the current item is the one we want to update |
|
732 | + if ($key == $link_index) { |
|
733 | + // This is the link we want to update |
|
734 | + // Check if the target should be "_blank" |
|
735 | + if (strstr($enreg, 'target="_blank"')) { |
|
736 | + $target_blank = true; |
|
737 | + } |
|
738 | + |
|
739 | + if (strstr($enreg, 'hide_menu')) { |
|
740 | + $add_in_tab = false; |
|
741 | + } else { |
|
742 | + $add_in_tab = true; |
|
743 | + } |
|
744 | + |
|
745 | + // Remove dangerous HTML tags from the link itself (this is an |
|
746 | + // additional measure in case a link previously contained |
|
747 | + // unsecure tags) |
|
748 | + $link_name = strip_tags($enreg); |
|
749 | + |
|
750 | + // Get the contents of "href" attribute in $link_url |
|
751 | + $enreg = explode('href="',$enreg); |
|
752 | + list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]); |
|
753 | + |
|
754 | + // If the link contains the web root of this portal, then strip |
|
755 | + // it off and keep only the name of the file that needs edition |
|
756 | + if (strstr($link_url, '?include=')) { |
|
757 | + $link_url = explode('?include=', $link_url); |
|
758 | + |
|
759 | + $filename = $link_url[sizeof($link_url) - 1]; |
|
760 | + |
|
761 | + if (!strstr($filename, '/') && strstr($filename, '.html')) { |
|
762 | + // Get oonly the contents of the link file |
|
763 | + $link_html = @file($homep.$filename); |
|
764 | + $link_html = implode('', $link_html); |
|
765 | + $link_url = ''; |
|
766 | + } else { |
|
767 | + $filename = ''; |
|
768 | + } |
|
769 | + } |
|
770 | + break; |
|
771 | + } |
|
772 | + } |
|
773 | + break; |
|
774 | + }//end of second switch($action) (when POST['formSent'] was not set, yet) |
|
775 | + }// end of "else" in if($_POST['formSent']) condition |
|
776 | 776 | } else { |
777 | - //if $action is empty, then prepare a list of the course categories to display (?) |
|
778 | - $Categories = CourseCategory::getCategoriesToDisplayInHomePage(); |
|
777 | + //if $action is empty, then prepare a list of the course categories to display (?) |
|
778 | + $Categories = CourseCategory::getCategoriesToDisplayInHomePage(); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | // Display section |
@@ -783,25 +783,25 @@ discard block |
||
783 | 783 | Display::display_header($tool_name); |
784 | 784 | |
785 | 785 | switch ($action) { |
786 | - case 'open_link': |
|
787 | - if (!empty($link)) { |
|
788 | - // $link is only set in case of action=open_link and is filtered |
|
789 | - $open = @(string)file_get_contents($homep.$link); |
|
790 | - $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
791 | - echo $open; |
|
792 | - } |
|
793 | - break; |
|
794 | - case 'edit_notice': |
|
795 | - // Display for edit_notice case |
|
796 | - ?> |
|
786 | + case 'open_link': |
|
787 | + if (!empty($link)) { |
|
788 | + // $link is only set in case of action=open_link and is filtered |
|
789 | + $open = @(string)file_get_contents($homep.$link); |
|
790 | + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
791 | + echo $open; |
|
792 | + } |
|
793 | + break; |
|
794 | + case 'edit_notice': |
|
795 | + // Display for edit_notice case |
|
796 | + ?> |
|
797 | 797 | <form action="<?php echo $selfUrl; ?>?action=<?php echo $action; ?>" method="post" class="form-horizontal"> |
798 | 798 | <legend><?php echo $tool_name; ?></legend> |
799 | 799 | <input type="hidden" name="formSent" value="1"/> |
800 | 800 | <?php |
801 | - if (!empty($errorMsg)) { |
|
802 | - Display::display_normal_message($errorMsg); |
|
803 | - } |
|
804 | - ?> |
|
801 | + if (!empty($errorMsg)) { |
|
802 | + Display::display_normal_message($errorMsg); |
|
803 | + } |
|
804 | + ?> |
|
805 | 805 | <div class="row"> |
806 | 806 | <div class="col-md-12"> |
807 | 807 | <p><?php echo get_lang('LetThoseFieldsEmptyToHideTheNotice'); ?></p> |
@@ -839,170 +839,170 @@ discard block |
||
839 | 839 | </div> |
840 | 840 | </form> |
841 | 841 | <?php |
842 | - break; |
|
843 | - case 'insert_tabs': |
|
844 | - case 'edit_tabs': |
|
845 | - case 'insert_link': |
|
846 | - case 'edit_link': |
|
847 | - $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf; |
|
848 | - if (!empty($errorMsg)) { |
|
849 | - Display::display_normal_message($errorMsg); |
|
850 | - } |
|
851 | - $default = array(); |
|
852 | - $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;')); |
|
853 | - $renderer =& $form->defaultRenderer(); |
|
854 | - |
|
855 | - $form->addElement('header', '', $tool_name); |
|
856 | - $form->addElement('hidden', 'formSent', '1'); |
|
857 | - $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0'); |
|
858 | - $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : ''); |
|
859 | - |
|
860 | - $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50')); |
|
861 | - if (!empty($link_name)) { |
|
862 | - $default['link_name'] = $link_name; |
|
863 | - } |
|
864 | - $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES); |
|
865 | - $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : ''; |
|
866 | - $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;')); |
|
867 | - |
|
868 | - $options = array('-1' => get_lang('FirstPlace')); |
|
869 | - |
|
870 | - $selected = ''; |
|
871 | - |
|
872 | - if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
873 | - $add_in_tab = 1; |
|
874 | - if (is_array($home_menu)){ |
|
875 | - foreach ($home_menu as $key => $enreg) { |
|
876 | - if (strlen($enreg = trim(strip_tags($enreg))) > 0) { |
|
877 | - $options[$key] = get_lang('After').' "'.$enreg.'"'; |
|
878 | - $formSentCheck = (!empty($_POST['formSent']) ? true : false); |
|
879 | - $selected = $formSentCheck && $insert_where == $key ? $key : ''; |
|
880 | - } |
|
881 | - } |
|
882 | - } |
|
883 | - $default['insert_link'] = $selected; |
|
884 | - $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options); |
|
885 | - } |
|
886 | - |
|
887 | - $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1); |
|
888 | - |
|
889 | - if ($action == 'insert_tabs' || $action == 'edit_tabs') { |
|
890 | - $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1); |
|
891 | - $default['add_in_tab'] = $add_in_tab; |
|
892 | - } |
|
893 | - |
|
894 | - if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); } |
|
895 | - |
|
896 | - if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) { |
|
897 | - $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html; |
|
898 | - $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
842 | + break; |
|
843 | + case 'insert_tabs': |
|
844 | + case 'edit_tabs': |
|
845 | + case 'insert_link': |
|
846 | + case 'edit_link': |
|
847 | + $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf; |
|
848 | + if (!empty($errorMsg)) { |
|
849 | + Display::display_normal_message($errorMsg); |
|
850 | + } |
|
851 | + $default = array(); |
|
852 | + $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;')); |
|
853 | + $renderer =& $form->defaultRenderer(); |
|
854 | + |
|
855 | + $form->addElement('header', '', $tool_name); |
|
856 | + $form->addElement('hidden', 'formSent', '1'); |
|
857 | + $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0'); |
|
858 | + $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : ''); |
|
859 | + |
|
860 | + $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50')); |
|
861 | + if (!empty($link_name)) { |
|
862 | + $default['link_name'] = $link_name; |
|
863 | + } |
|
864 | + $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES); |
|
865 | + $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : ''; |
|
866 | + $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;')); |
|
867 | + |
|
868 | + $options = array('-1' => get_lang('FirstPlace')); |
|
869 | + |
|
870 | + $selected = ''; |
|
871 | + |
|
872 | + if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
873 | + $add_in_tab = 1; |
|
874 | + if (is_array($home_menu)){ |
|
875 | + foreach ($home_menu as $key => $enreg) { |
|
876 | + if (strlen($enreg = trim(strip_tags($enreg))) > 0) { |
|
877 | + $options[$key] = get_lang('After').' "'.$enreg.'"'; |
|
878 | + $formSentCheck = (!empty($_POST['formSent']) ? true : false); |
|
879 | + $selected = $formSentCheck && $insert_where == $key ? $key : ''; |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | + $default['insert_link'] = $selected; |
|
884 | + $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options); |
|
885 | + } |
|
886 | + |
|
887 | + $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1); |
|
888 | + |
|
889 | + if ($action == 'insert_tabs' || $action == 'edit_tabs') { |
|
890 | + $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1); |
|
891 | + $default['add_in_tab'] = $add_in_tab; |
|
892 | + } |
|
893 | + |
|
894 | + if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); } |
|
895 | + |
|
896 | + if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) { |
|
897 | + $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html; |
|
898 | + $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
899 | 899 | $form->addButtonSave(get_lang('Save'),'submit'); |
900 | 900 | |
901 | - } else { |
|
902 | - if (in_array($action, array('edit_tabs','insert_tabs'))) { |
|
903 | - $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : ''); |
|
904 | - $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
905 | - } |
|
906 | - $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs')); |
|
907 | - $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>'); |
|
908 | - $i = 0; |
|
909 | - foreach ($_languages['name'] as $key => $value) { |
|
910 | - $i++; |
|
911 | - $lang_name = $_languages['folder'][$key]; |
|
912 | - $html_langs = '<td width="300">'; |
|
913 | - $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" /> '.$lang_name.'<label/>'; |
|
914 | - $html_langs .= '</td>'; |
|
915 | - if ($i % 5 == 0) { |
|
916 | - $html_langs .= '</tr><tr>'; |
|
917 | - } |
|
918 | - $form->addElement('html', $html_langs); |
|
919 | - } |
|
920 | - $form->addElement('html','</tr></table><br/>'); |
|
901 | + } else { |
|
902 | + if (in_array($action, array('edit_tabs','insert_tabs'))) { |
|
903 | + $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : ''); |
|
904 | + $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
905 | + } |
|
906 | + $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs')); |
|
907 | + $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>'); |
|
908 | + $i = 0; |
|
909 | + foreach ($_languages['name'] as $key => $value) { |
|
910 | + $i++; |
|
911 | + $lang_name = $_languages['folder'][$key]; |
|
912 | + $html_langs = '<td width="300">'; |
|
913 | + $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" /> '.$lang_name.'<label/>'; |
|
914 | + $html_langs .= '</td>'; |
|
915 | + if ($i % 5 == 0) { |
|
916 | + $html_langs .= '</tr><tr>'; |
|
917 | + } |
|
918 | + $form->addElement('html', $html_langs); |
|
919 | + } |
|
920 | + $form->addElement('html','</tr></table><br/>'); |
|
921 | 921 | $form->addButtonSave(get_lang('Save'),'submit'); |
922 | - } |
|
923 | - |
|
924 | - $form->setDefaults($default); |
|
925 | - $form->display(); |
|
926 | - |
|
927 | - break; |
|
928 | - case 'edit_top': |
|
929 | - case 'edit_news': |
|
930 | - if ($action == 'edit_top') { |
|
931 | - $name = $topf; |
|
932 | - $open = $home_top; |
|
933 | - } else { |
|
934 | - $name = $newsf; |
|
935 | - $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
936 | - } |
|
937 | - $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
938 | - |
|
939 | - if (!empty($errorMsg)) { |
|
940 | - Display::display_normal_message($errorMsg); //main API |
|
941 | - } |
|
942 | - |
|
943 | - $default = array(); |
|
944 | - $form = new FormValidator( |
|
945 | - 'configure_homepage_'.$action, |
|
946 | - 'post', |
|
947 | - $selfUrl.'?action='.$action, |
|
948 | - '', |
|
949 | - array('style' => 'margin: 0px;') |
|
950 | - ); |
|
951 | - $renderer =& $form->defaultRenderer(); |
|
952 | - $renderer->setHeaderTemplate(''); |
|
953 | - $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>'); |
|
954 | - $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>'); |
|
955 | - $renderer->setRequiredNoteTemplate(''); |
|
956 | - $form->addElement('hidden', 'formSent', '1'); |
|
957 | - |
|
958 | - if ($action == 'edit_news') { |
|
959 | - $_languages = api_get_languages(); |
|
960 | - $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : '; |
|
961 | - $html .= '<select name="news_languages">'; |
|
962 | - $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>'; |
|
963 | - foreach ($_languages['name'] as $key => $value) { |
|
964 | - $english_name = $_languages['folder'][$key]; |
|
965 | - if ($language == $english_name) { |
|
966 | - $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>'; |
|
967 | - } else { |
|
968 | - $html .= '<option value="'.$english_name.'">'.$value.'</option>'; |
|
969 | - } |
|
970 | - } |
|
971 | - $html .= '</select></td></tr>'; |
|
972 | - $form->addElement('html', $html); |
|
973 | - } |
|
974 | - |
|
975 | - $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); |
|
976 | - $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
977 | - $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs')); |
|
978 | - $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>'); |
|
979 | - |
|
980 | - $currentLanguage = api_get_interface_language(); |
|
981 | - $i = 0; |
|
982 | - foreach ($_languages['name'] as $key => $value) { |
|
983 | - $lang_name = $_languages['folder'][$key]; |
|
984 | - $i++; |
|
985 | - |
|
986 | - $checked = null; |
|
987 | - if ($languageGet == $lang_name) { |
|
988 | - $checked = "checked"; |
|
989 | - } |
|
990 | - $html_langs = '<td width="300">'; |
|
991 | - $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" /> '.$value.'<label/>'; |
|
992 | - $html_langs .= '</td>'; |
|
993 | - if ($i % 5 == 0) { |
|
994 | - $html_langs .= '</tr><tr>'; |
|
995 | - } |
|
996 | - $form->addElement('html', $html_langs); |
|
997 | - } |
|
998 | - $form->addElement('html','</tr></table><br/>'); |
|
999 | - $form->addButtonSave(get_lang('Save')); |
|
1000 | - $form->setDefaults($default); |
|
1001 | - $form->display(); |
|
1002 | - |
|
1003 | - break; |
|
1004 | - default: // When no action applies, default page to update campus homepage |
|
1005 | - ?> |
|
922 | + } |
|
923 | + |
|
924 | + $form->setDefaults($default); |
|
925 | + $form->display(); |
|
926 | + |
|
927 | + break; |
|
928 | + case 'edit_top': |
|
929 | + case 'edit_news': |
|
930 | + if ($action == 'edit_top') { |
|
931 | + $name = $topf; |
|
932 | + $open = $home_top; |
|
933 | + } else { |
|
934 | + $name = $newsf; |
|
935 | + $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
936 | + } |
|
937 | + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
938 | + |
|
939 | + if (!empty($errorMsg)) { |
|
940 | + Display::display_normal_message($errorMsg); //main API |
|
941 | + } |
|
942 | + |
|
943 | + $default = array(); |
|
944 | + $form = new FormValidator( |
|
945 | + 'configure_homepage_'.$action, |
|
946 | + 'post', |
|
947 | + $selfUrl.'?action='.$action, |
|
948 | + '', |
|
949 | + array('style' => 'margin: 0px;') |
|
950 | + ); |
|
951 | + $renderer =& $form->defaultRenderer(); |
|
952 | + $renderer->setHeaderTemplate(''); |
|
953 | + $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>'); |
|
954 | + $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>'); |
|
955 | + $renderer->setRequiredNoteTemplate(''); |
|
956 | + $form->addElement('hidden', 'formSent', '1'); |
|
957 | + |
|
958 | + if ($action == 'edit_news') { |
|
959 | + $_languages = api_get_languages(); |
|
960 | + $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : '; |
|
961 | + $html .= '<select name="news_languages">'; |
|
962 | + $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>'; |
|
963 | + foreach ($_languages['name'] as $key => $value) { |
|
964 | + $english_name = $_languages['folder'][$key]; |
|
965 | + if ($language == $english_name) { |
|
966 | + $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>'; |
|
967 | + } else { |
|
968 | + $html .= '<option value="'.$english_name.'">'.$value.'</option>'; |
|
969 | + } |
|
970 | + } |
|
971 | + $html .= '</select></td></tr>'; |
|
972 | + $form->addElement('html', $html); |
|
973 | + } |
|
974 | + |
|
975 | + $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); |
|
976 | + $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
977 | + $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs')); |
|
978 | + $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>'); |
|
979 | + |
|
980 | + $currentLanguage = api_get_interface_language(); |
|
981 | + $i = 0; |
|
982 | + foreach ($_languages['name'] as $key => $value) { |
|
983 | + $lang_name = $_languages['folder'][$key]; |
|
984 | + $i++; |
|
985 | + |
|
986 | + $checked = null; |
|
987 | + if ($languageGet == $lang_name) { |
|
988 | + $checked = "checked"; |
|
989 | + } |
|
990 | + $html_langs = '<td width="300">'; |
|
991 | + $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" /> '.$value.'<label/>'; |
|
992 | + $html_langs .= '</td>'; |
|
993 | + if ($i % 5 == 0) { |
|
994 | + $html_langs .= '</tr><tr>'; |
|
995 | + } |
|
996 | + $form->addElement('html', $html_langs); |
|
997 | + } |
|
998 | + $form->addElement('html','</tr></table><br/>'); |
|
999 | + $form->addButtonSave(get_lang('Save')); |
|
1000 | + $form->setDefaults($default); |
|
1001 | + $form->display(); |
|
1002 | + |
|
1003 | + break; |
|
1004 | + default: // When no action applies, default page to update campus homepage |
|
1005 | + ?> |
|
1006 | 1006 | |
1007 | 1007 | <section id="page-home"> |
1008 | 1008 | <div class="row"> |
@@ -1158,53 +1158,53 @@ discard block |
||
1158 | 1158 | ?> |
1159 | 1159 | |
1160 | 1160 | <?php |
1161 | - if (file_exists($homep.$newsf.'_'.$lang.$ext)) { |
|
1161 | + if (file_exists($homep.$newsf.'_'.$lang.$ext)) { |
|
1162 | 1162 | $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
1163 | 1163 | $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
1164 | 1164 | echo $open; |
1165 | - } else { |
|
1165 | + } else { |
|
1166 | 1166 | $open = @(string)file_get_contents($homep.$newsf.$ext); |
1167 | 1167 | $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
1168 | 1168 | echo $open; |
1169 | - } |
|
1169 | + } |
|
1170 | 1170 | ?> |
1171 | 1171 | |
1172 | 1172 | <?php |
1173 | 1173 | // Add new page |
1174 | - $home_menu = ''; |
|
1175 | - if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
1174 | + $home_menu = ''; |
|
1175 | + if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
1176 | 1176 | $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
1177 | - } else { |
|
1177 | + } else { |
|
1178 | 1178 | $home_menu = @file($homep.$mtloggedin.$ext); |
1179 | - } |
|
1180 | - if (empty($home_menu)) { |
|
1179 | + } |
|
1180 | + if (empty($home_menu)) { |
|
1181 | 1181 | if (file_exists($homep.$menutabs.'_'.$lang.$ext)) { |
1182 | - $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
1182 | + $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
1183 | 1183 | } |
1184 | - } |
|
1185 | - if (empty($home_menu)) { |
|
1184 | + } |
|
1185 | + if (empty($home_menu)) { |
|
1186 | 1186 | $home_menu = array(); |
1187 | - } |
|
1188 | - if (!empty($home_menu)) { |
|
1187 | + } |
|
1188 | + if (!empty($home_menu)) { |
|
1189 | 1189 | $home_menu = implode("\n", $home_menu); |
1190 | 1190 | $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
1191 | 1191 | $home_menu = explode("\n", $home_menu); |
1192 | - } |
|
1193 | - $link_list = ''; |
|
1194 | - $tab_counter = 0; |
|
1192 | + } |
|
1193 | + $link_list = ''; |
|
1194 | + $tab_counter = 0; |
|
1195 | 1195 | foreach ($home_menu as $enreg) { |
1196 | 1196 | $enreg = trim($enreg); |
1197 | - if (!empty($enreg)) { |
|
1197 | + if (!empty($enreg)) { |
|
1198 | 1198 | $edit_link = ' <a href="'.$selfUrl.'?action=edit_tabs&link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.png', get_lang('Edit')).'</span></a>'; |
1199 | 1199 | $delete_link = ' <a href="'.$selfUrl.'?action=delete_tabs&link_index='.$tab_counter.'" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;"><span>'.Display::return_icon('delete.png', get_lang('Delete')).'</span></a>'; |
1200 | 1200 | $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'), |
1201 | 1201 | array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.$delete_link.'</li>'), |
1202 | - $enreg); |
|
1202 | + $enreg); |
|
1203 | 1203 | $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string); |
1204 | - $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item')); |
|
1205 | - $tab_counter++; |
|
1206 | - } |
|
1207 | - } |
|
1204 | + $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item')); |
|
1205 | + $tab_counter++; |
|
1206 | + } |
|
1207 | + } |
|
1208 | 1208 | ?> |
1209 | 1209 | <div class="actions"> |
1210 | 1210 | <a href="<?php echo $selfUrl; ?>?action=insert_tabs"> |
@@ -1212,9 +1212,9 @@ discard block |
||
1212 | 1212 | </a> |
1213 | 1213 | </div> |
1214 | 1214 | <?php |
1215 | - echo '<ul id="list-hiperlink" class="list-group">'; |
|
1216 | - echo $link_list; |
|
1217 | - echo '</ul>'; |
|
1215 | + echo '<ul id="list-hiperlink" class="list-group">'; |
|
1216 | + echo $link_list; |
|
1217 | + echo '</ul>'; |
|
1218 | 1218 | ?> |
1219 | 1219 | </div> |
1220 | 1220 | </div> |
@@ -44,121 +44,121 @@ |
||
44 | 44 | $users=Database::store_result($result); |
45 | 45 | |
46 | 46 | foreach($Sessions as $session){ |
47 | - $id_session = $session['id']; |
|
48 | - $name_session = $session['name']; |
|
49 | - $UserList=array(); |
|
50 | - $UserUpdate=array(); |
|
51 | - $UserAdd=array(); |
|
47 | + $id_session = $session['id']; |
|
48 | + $name_session = $session['name']; |
|
49 | + $UserList=array(); |
|
50 | + $UserUpdate=array(); |
|
51 | + $UserAdd=array(); |
|
52 | 52 | |
53 | - // Parse des code etape de la session |
|
54 | - /* |
|
53 | + // Parse des code etape de la session |
|
54 | + /* |
|
55 | 55 | $sql = "SELECT id_session, code_etape, etape_description, code_ufr, annee |
56 | 56 | FROM $tbl_session_rel_etape |
57 | 57 | WHERE id_session='$id_session' |
58 | 58 | ORDER BY code_ufr, code_etape"; |
59 | 59 | $result = Database::query($sql); |
60 | 60 | */ |
61 | - $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError')); |
|
62 | - ldap_set_version($ds); |
|
63 | - // Import des utilisateurs des etapes dans la session |
|
64 | - if ($ds) |
|
65 | - { |
|
66 | - $r = false; |
|
67 | - $res = ldap_handle_bind($ds, $r); |
|
68 | - $UserList=array(); |
|
69 | - if($result !== false) |
|
70 | - { |
|
71 | - //while($row = Database::fetch_array($result)) |
|
72 | - //{ |
|
73 | - /* |
|
61 | + $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError')); |
|
62 | + ldap_set_version($ds); |
|
63 | + // Import des utilisateurs des etapes dans la session |
|
64 | + if ($ds) |
|
65 | + { |
|
66 | + $r = false; |
|
67 | + $res = ldap_handle_bind($ds, $r); |
|
68 | + $UserList=array(); |
|
69 | + if($result !== false) |
|
70 | + { |
|
71 | + //while($row = Database::fetch_array($result)) |
|
72 | + //{ |
|
73 | + /* |
|
74 | 74 | $annee = $row['annee']; |
75 | 75 | $code_ufr = $row['code_ufr']; |
76 | 76 | $etape = $row['code_etape']; |
77 | 77 | */ |
78 | - // LDAP Query |
|
79 | - // edupersonorgunitdn=ou=12CI1,ou=2006,ou=diploma,o=Paris1,dc=univ-paris1,dc=fr |
|
80 | - //etapescommented |
|
81 | - //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "edupersonorgunitdn=ou=$etape,ou=$annee,ou=diploma,$LDAPbasedn"); |
|
82 | - $sr = @ ldap_search($ds, $ldap_basedn, '(uid=*)'); |
|
83 | - $info = ldap_get_entries($ds, $sr); |
|
84 | - for ($key = 0; $key < $info["count"]; $key ++) |
|
85 | - { |
|
86 | - echo "<pre>"; |
|
87 | - print_r($info[$key]); |
|
88 | - echo "</pre>"; |
|
89 | - $lastname = api_utf8_decode($info[$key]["sn"][0]); |
|
90 | - $firstname = api_utf8_decode($info[$key]["givenname"][0]); |
|
91 | - $email = $info[$key]["mail"][0]; |
|
92 | - // Get uid from dn |
|
93 | - $dn_array=ldap_explode_dn($info[$key]["dn"],1); |
|
94 | - $username = $dn_array[0]; // uid is first key |
|
95 | - $outab[] = $info[$key]["edupersonprimaryaffiliation"][0]; // Ici "student" |
|
96 | - $val = ldap_get_values_len($ds, $sr, "userPassword"); |
|
97 | - $password = $val[0]; |
|
98 | - // Pour faciliter la gestion on ajoute le code "etape-annee" |
|
99 | - $official_code=$etape."-".$annee; |
|
100 | - $auth_source="ldap"; |
|
101 | - // Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire LDAP) |
|
102 | - $expiration_date=''; |
|
103 | - $active=1; |
|
104 | - // Ajout de l'utilisateur |
|
105 | - if (UserManager::is_username_available($username)) { |
|
106 | - $user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,api_get_setting('platformLanguage'),$phone,$picture_uri,$auth_source,$expiration_date,$active); |
|
107 | - $UserAdd[]=$user_id; |
|
108 | - } else { |
|
109 | - $user = api_get_user_info_from_username($username); |
|
110 | - $user_id=$user['user_id']; |
|
111 | - UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active); |
|
112 | - $UserUpdate[]=$user_id; |
|
113 | - } |
|
114 | - $UserList[]=$user_id; |
|
115 | - } |
|
116 | - //} |
|
117 | - } |
|
118 | - if (isset($included) && ($included)) |
|
119 | - { |
|
120 | - $message .= "> $name_session: ".count($UserAdd)." ".get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified').'<br/>'; |
|
121 | - } |
|
122 | - else |
|
123 | - { |
|
124 | - print "> $name_session: ".count($UserAdd).get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified')."\n"; |
|
125 | - } |
|
78 | + // LDAP Query |
|
79 | + // edupersonorgunitdn=ou=12CI1,ou=2006,ou=diploma,o=Paris1,dc=univ-paris1,dc=fr |
|
80 | + //etapescommented |
|
81 | + //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "edupersonorgunitdn=ou=$etape,ou=$annee,ou=diploma,$LDAPbasedn"); |
|
82 | + $sr = @ ldap_search($ds, $ldap_basedn, '(uid=*)'); |
|
83 | + $info = ldap_get_entries($ds, $sr); |
|
84 | + for ($key = 0; $key < $info["count"]; $key ++) |
|
85 | + { |
|
86 | + echo "<pre>"; |
|
87 | + print_r($info[$key]); |
|
88 | + echo "</pre>"; |
|
89 | + $lastname = api_utf8_decode($info[$key]["sn"][0]); |
|
90 | + $firstname = api_utf8_decode($info[$key]["givenname"][0]); |
|
91 | + $email = $info[$key]["mail"][0]; |
|
92 | + // Get uid from dn |
|
93 | + $dn_array=ldap_explode_dn($info[$key]["dn"],1); |
|
94 | + $username = $dn_array[0]; // uid is first key |
|
95 | + $outab[] = $info[$key]["edupersonprimaryaffiliation"][0]; // Ici "student" |
|
96 | + $val = ldap_get_values_len($ds, $sr, "userPassword"); |
|
97 | + $password = $val[0]; |
|
98 | + // Pour faciliter la gestion on ajoute le code "etape-annee" |
|
99 | + $official_code=$etape."-".$annee; |
|
100 | + $auth_source="ldap"; |
|
101 | + // Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire LDAP) |
|
102 | + $expiration_date=''; |
|
103 | + $active=1; |
|
104 | + // Ajout de l'utilisateur |
|
105 | + if (UserManager::is_username_available($username)) { |
|
106 | + $user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,api_get_setting('platformLanguage'),$phone,$picture_uri,$auth_source,$expiration_date,$active); |
|
107 | + $UserAdd[]=$user_id; |
|
108 | + } else { |
|
109 | + $user = api_get_user_info_from_username($username); |
|
110 | + $user_id=$user['user_id']; |
|
111 | + UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active); |
|
112 | + $UserUpdate[]=$user_id; |
|
113 | + } |
|
114 | + $UserList[]=$user_id; |
|
115 | + } |
|
116 | + //} |
|
117 | + } |
|
118 | + if (isset($included) && ($included)) |
|
119 | + { |
|
120 | + $message .= "> $name_session: ".count($UserAdd)." ".get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified').'<br/>'; |
|
121 | + } |
|
122 | + else |
|
123 | + { |
|
124 | + print "> $name_session: ".count($UserAdd).get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified')."\n"; |
|
125 | + } |
|
126 | 126 | |
127 | - // Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter la session |
|
128 | - $result=Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id='$id_session'"); |
|
129 | - $CourseList=array(); |
|
130 | - while($row=Database::fetch_array($result)) { |
|
131 | - $CourseList[]= $row['c_id']; |
|
132 | - } |
|
127 | + // Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter la session |
|
128 | + $result=Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id='$id_session'"); |
|
129 | + $CourseList=array(); |
|
130 | + while($row=Database::fetch_array($result)) { |
|
131 | + $CourseList[]= $row['c_id']; |
|
132 | + } |
|
133 | 133 | |
134 | - foreach ($CourseList as $enreg_course) { |
|
135 | - // On ajoute la relation entre l'utilisateur et le cours |
|
136 | - foreach ($UserList as $enreg_user) { |
|
137 | - $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(session_id,c_id,user_id) |
|
134 | + foreach ($CourseList as $enreg_course) { |
|
135 | + // On ajoute la relation entre l'utilisateur et le cours |
|
136 | + foreach ($UserList as $enreg_user) { |
|
137 | + $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(session_id,c_id,user_id) |
|
138 | 138 | VALUES('$id_session','$enreg_course','$enreg_user')"; |
139 | - Database::query($sql); |
|
140 | - } |
|
141 | - $sql = "SELECT COUNT(user_id) as nbUsers " . |
|
142 | - "FROM $tbl_session_rel_course_rel_user " . |
|
143 | - "WHERE session_id='$id_session' AND c_id='$enreg_course'"; |
|
144 | - $rs = Database::query($sql); |
|
145 | - list($nbr_users) = Database::fetch_array($rs); |
|
146 | - $sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users |
|
139 | + Database::query($sql); |
|
140 | + } |
|
141 | + $sql = "SELECT COUNT(user_id) as nbUsers " . |
|
142 | + "FROM $tbl_session_rel_course_rel_user " . |
|
143 | + "WHERE session_id='$id_session' AND c_id='$enreg_course'"; |
|
144 | + $rs = Database::query($sql); |
|
145 | + list($nbr_users) = Database::fetch_array($rs); |
|
146 | + $sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users |
|
147 | 147 | WHERE session_id='$id_session' AND c_id = '$enreg_course'"; |
148 | - Database::query($sql); |
|
149 | - } |
|
150 | - // On ajoute la relation entre l'utilisateur et la session |
|
151 | - foreach($UserList as $enreg_user){ |
|
152 | - $sql = "INSERT IGNORE INTO $tbl_session_rel_user(session_id, user_id, registered_at) " . |
|
153 | - "VALUES('$id_session','$enreg_user', '" . api_get_utc_datetime() . "')"; |
|
154 | - Database::query($sql); |
|
155 | - } |
|
156 | - $sql = "SELECT COUNT(user_id) as nbUsers " . |
|
157 | - "FROM $tbl_session_rel_user " . |
|
158 | - "WHERE session_id='$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH.""; |
|
159 | - $rs = Database::query($sql); |
|
160 | - list($nbr_users) = Database::fetch_array($rs); |
|
161 | - $sql = "UPDATE $tbl_session SET nbr_users=$nbr_users WHERE id='$id_session'"; |
|
162 | - Database::query($sql); |
|
163 | - } |
|
148 | + Database::query($sql); |
|
149 | + } |
|
150 | + // On ajoute la relation entre l'utilisateur et la session |
|
151 | + foreach($UserList as $enreg_user){ |
|
152 | + $sql = "INSERT IGNORE INTO $tbl_session_rel_user(session_id, user_id, registered_at) " . |
|
153 | + "VALUES('$id_session','$enreg_user', '" . api_get_utc_datetime() . "')"; |
|
154 | + Database::query($sql); |
|
155 | + } |
|
156 | + $sql = "SELECT COUNT(user_id) as nbUsers " . |
|
157 | + "FROM $tbl_session_rel_user " . |
|
158 | + "WHERE session_id='$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH.""; |
|
159 | + $rs = Database::query($sql); |
|
160 | + list($nbr_users) = Database::fetch_array($rs); |
|
161 | + $sql = "UPDATE $tbl_session SET nbr_users=$nbr_users WHERE id='$id_session'"; |
|
162 | + Database::query($sql); |
|
163 | + } |
|
164 | 164 | } |
@@ -10,66 +10,66 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class HTML_QuickForm_receivers extends HTML_QuickForm_group |
12 | 12 | { |
13 | - /** |
|
14 | - * Array of all receivers |
|
15 | - */ |
|
16 | - var $receivers; |
|
17 | - /** |
|
18 | - * Array of selected receivers |
|
19 | - */ |
|
20 | - var $receivers_selected; |
|
13 | + /** |
|
14 | + * Array of all receivers |
|
15 | + */ |
|
16 | + var $receivers; |
|
17 | + /** |
|
18 | + * Array of selected receivers |
|
19 | + */ |
|
20 | + var $receivers_selected; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Constructor |
|
24 | - * @param string $elementName |
|
25 | - * @param string $elementLabel |
|
26 | - * @param array $attributes This should contain the keys 'receivers' and |
|
27 | - * 'receivers_selected' |
|
28 | - */ |
|
29 | - public function __construct($elementName = null, $elementLabel = null, $attributes = null) |
|
30 | - { |
|
31 | - $this->receivers = $attributes['receivers']; |
|
32 | - $this->receivers_selected = $attributes['receivers_selected']; |
|
33 | - unset($attributes['receivers']); |
|
34 | - unset($attributes['receivers_selected']); |
|
35 | - parent::__construct($elementName, $elementLabel, $attributes); |
|
36 | - $this->_persistantFreeze = true; |
|
37 | - $this->_appendName = true; |
|
38 | - $this->_type = 'receivers'; |
|
39 | - } |
|
40 | - /** |
|
41 | - * Create the form elements to build this element group |
|
42 | - */ |
|
43 | - function _createElements() |
|
44 | - { |
|
45 | - $this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('Everybody'), '0', array ('onclick' => 'javascript:receivers_hide(\'receivers_to\')')); |
|
46 | - $this->_elements[0]->setChecked(true); |
|
47 | - $this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('SelectGroupsUsers'), '1', array ('onclick' => 'javascript:receivers_show(\'receivers_to\')')); |
|
48 | - $this->_elements[] = new HTML_QuickForm_advmultiselect('to', '', $this->receivers); |
|
49 | - $this->_elements[2]->setSelected($this->receivers_selected); |
|
50 | - } |
|
51 | - /** |
|
52 | - * HTML representation |
|
53 | - */ |
|
54 | - public function toHtml() |
|
55 | - { |
|
56 | - include_once ('HTML/QuickForm/Renderer/Default.php'); |
|
57 | - $this->_separator = '<br/>'; |
|
58 | - $renderer = & new HTML_QuickForm_Renderer_Default(); |
|
59 | - $renderer->setElementTemplate('{element}'); |
|
60 | - $select_boxes = $this->_elements[2]; |
|
61 | - $select_boxes->setElementTemplate('<div style="margin-left:20px;display:block;" id="receivers_'.$select_boxes->getName().'">'.$select_boxes->_elementTemplate.'</div>'); |
|
62 | - parent :: accept($renderer); |
|
63 | - $js = $this->getElementJS(); |
|
64 | - return $renderer->toHtml().$js; |
|
65 | - } |
|
22 | + /** |
|
23 | + * Constructor |
|
24 | + * @param string $elementName |
|
25 | + * @param string $elementLabel |
|
26 | + * @param array $attributes This should contain the keys 'receivers' and |
|
27 | + * 'receivers_selected' |
|
28 | + */ |
|
29 | + public function __construct($elementName = null, $elementLabel = null, $attributes = null) |
|
30 | + { |
|
31 | + $this->receivers = $attributes['receivers']; |
|
32 | + $this->receivers_selected = $attributes['receivers_selected']; |
|
33 | + unset($attributes['receivers']); |
|
34 | + unset($attributes['receivers_selected']); |
|
35 | + parent::__construct($elementName, $elementLabel, $attributes); |
|
36 | + $this->_persistantFreeze = true; |
|
37 | + $this->_appendName = true; |
|
38 | + $this->_type = 'receivers'; |
|
39 | + } |
|
40 | + /** |
|
41 | + * Create the form elements to build this element group |
|
42 | + */ |
|
43 | + function _createElements() |
|
44 | + { |
|
45 | + $this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('Everybody'), '0', array ('onclick' => 'javascript:receivers_hide(\'receivers_to\')')); |
|
46 | + $this->_elements[0]->setChecked(true); |
|
47 | + $this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('SelectGroupsUsers'), '1', array ('onclick' => 'javascript:receivers_show(\'receivers_to\')')); |
|
48 | + $this->_elements[] = new HTML_QuickForm_advmultiselect('to', '', $this->receivers); |
|
49 | + $this->_elements[2]->setSelected($this->receivers_selected); |
|
50 | + } |
|
51 | + /** |
|
52 | + * HTML representation |
|
53 | + */ |
|
54 | + public function toHtml() |
|
55 | + { |
|
56 | + include_once ('HTML/QuickForm/Renderer/Default.php'); |
|
57 | + $this->_separator = '<br/>'; |
|
58 | + $renderer = & new HTML_QuickForm_Renderer_Default(); |
|
59 | + $renderer->setElementTemplate('{element}'); |
|
60 | + $select_boxes = $this->_elements[2]; |
|
61 | + $select_boxes->setElementTemplate('<div style="margin-left:20px;display:block;" id="receivers_'.$select_boxes->getName().'">'.$select_boxes->_elementTemplate.'</div>'); |
|
62 | + parent :: accept($renderer); |
|
63 | + $js = $this->getElementJS(); |
|
64 | + return $renderer->toHtml().$js; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Get the necessary javascript |
|
69 | - */ |
|
67 | + /** |
|
68 | + * Get the necessary javascript |
|
69 | + */ |
|
70 | 70 | public function getElementJS() |
71 | - { |
|
72 | - $js = "<script type=\"text/javascript\"> |
|
71 | + { |
|
72 | + $js = "<script type=\"text/javascript\"> |
|
73 | 73 | /* <![CDATA[ */ |
74 | 74 | receivers_hide('receivers_to'); |
75 | 75 | function receivers_show(item) { |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | } |
83 | 83 | /* ]]> */ |
84 | 84 | </script>\n"; |
85 | - return $js; |
|
86 | - } |
|
87 | - /** |
|
88 | - * accept renderer |
|
89 | - */ |
|
90 | - function accept(& $renderer, $required = false, $error = null) |
|
91 | - { |
|
92 | - $renderer->renderElement($this, $required, $error); |
|
93 | - } |
|
85 | + return $js; |
|
86 | + } |
|
87 | + /** |
|
88 | + * accept renderer |
|
89 | + */ |
|
90 | + function accept(& $renderer, $required = false, $error = null) |
|
91 | + { |
|
92 | + $renderer->renderElement($this, $required, $error); |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | ?> |
@@ -136,7 +136,7 @@ |
||
136 | 136 | ); |
137 | 137 | /** @var Category $category */ |
138 | 138 | foreach ($categories as $category) { |
139 | - $faq->addChild( |
|
139 | + $faq->addChild( |
|
140 | 140 | $category->getHeadline(), |
141 | 141 | array( |
142 | 142 | 'route' => 'faq', |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | $this_section = SECTION_COURSES; |
19 | 19 | |
20 | 20 | if (!api_is_allowed_to_edit(false, true)) { |
21 | - Display :: display_header(get_lang('ToolSurvey')); |
|
22 | - Display :: display_error_message(get_lang('NotAllowed'), false); |
|
23 | - Display :: display_footer(); |
|
24 | - exit; |
|
21 | + Display :: display_header(get_lang('ToolSurvey')); |
|
22 | + Display :: display_error_message(get_lang('NotAllowed'), false); |
|
23 | + Display :: display_footer(); |
|
24 | + exit; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | // Database table definitions |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | $survey_id = Security::remove_XSS($_GET['survey_id']); |
38 | 38 | $survey_data = SurveyManager::get_survey($survey_id); |
39 | 39 | if (empty($survey_data)) { |
40 | - Display :: display_header(get_lang('ToolSurvey')); |
|
41 | - Display :: display_error_message(get_lang('InvallidSurvey'), false); |
|
42 | - Display :: display_footer(); |
|
43 | - exit; |
|
40 | + Display :: display_header(get_lang('ToolSurvey')); |
|
41 | + Display :: display_error_message(get_lang('InvallidSurvey'), false); |
|
42 | + Display :: display_footer(); |
|
43 | + exit; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)); |
47 | 47 | if (api_strlen(strip_tags($survey_data['title'])) > 40) { |
48 | - $urlname .= '...'; |
|
48 | + $urlname .= '...'; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // Breadcrumbs |
@@ -80,23 +80,23 @@ discard block |
||
80 | 80 | WHERE c_id = $course_id AND code='".Database::escape_string($survey_data['code'])."'"; |
81 | 81 | $result = Database::query($sql); |
82 | 82 | if (Database::num_rows($result) > 1) { |
83 | - Display::display_warning_message(get_lang('IdenticalSurveycodeWarning')); |
|
83 | + Display::display_warning_message(get_lang('IdenticalSurveycodeWarning')); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | // Invited / answered message |
87 | 87 | if ($survey_data['invited'] > 0 && !isset($_POST['submit'])) { |
88 | - $message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> '; |
|
89 | - $message .= get_lang('HaveAnswered').' '; |
|
90 | - $message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> '; |
|
91 | - $message .= get_lang('WereInvited'); |
|
92 | - Display::display_normal_message($message, false); |
|
88 | + $message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> '; |
|
89 | + $message .= get_lang('HaveAnswered').' '; |
|
90 | + $message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> '; |
|
91 | + $message .= get_lang('WereInvited'); |
|
92 | + Display::display_normal_message($message, false); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Building the form for publishing the survey |
96 | 96 | $form = new FormValidator( |
97 | - 'publish_form', |
|
98 | - 'post', |
|
99 | - api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq() |
|
97 | + 'publish_form', |
|
98 | + 'post', |
|
99 | + api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq() |
|
100 | 100 | ); |
101 | 101 | $form->addElement('header', '', $tool_name); |
102 | 102 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | ); |
110 | 110 | $possible_users = array(); |
111 | 111 | foreach ($complete_user_list as & $user) { |
112 | - $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']); |
|
112 | + $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | |
126 | 126 | // Additional users |
127 | 127 | $form->addElement( |
128 | - 'textarea', |
|
129 | - 'additional_users', |
|
130 | - array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), |
|
131 | - array('rows' => 5) |
|
128 | + 'textarea', |
|
129 | + 'additional_users', |
|
130 | + array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), |
|
131 | + array('rows' => 5) |
|
132 | 132 | ); |
133 | 133 | |
134 | 134 | $form->addElement('html', '<div id="check_mail">'); |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | $form->addText('mail_title', get_lang('MailTitle'), false); |
142 | 142 | // The text of the mail |
143 | 143 | $form->addHtmlEditor( |
144 | - 'mail_text', |
|
145 | - array(get_lang('MailText'), get_lang('UseLinkSyntax')), |
|
146 | - false, |
|
147 | - array('ToolbarSet' => 'Survey', 'Height' => '150') |
|
144 | + 'mail_text', |
|
145 | + array(get_lang('MailText'), get_lang('UseLinkSyntax')), |
|
146 | + false, |
|
147 | + array('ToolbarSet' => 'Survey', 'Height' => '150') |
|
148 | 148 | ); |
149 | 149 | $form->addElement('html', '</div>'); |
150 | 150 | // You cab send a reminder to unanswered people if the survey is not anonymous |
151 | 151 | if ($survey_data['anonymous'] != 1) { |
152 | - $form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered')); |
|
152 | + $form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered')); |
|
153 | 153 | } |
154 | 154 | // Allow resending to all selected users |
155 | 155 | $form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers')); |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | }*/ |
164 | 164 | $portal_url = api_get_path(WEB_PATH); |
165 | 165 | if (api_is_multiple_url_enabled()) { |
166 | - $access_url_id = api_get_current_access_url_id(); |
|
167 | - if ($access_url_id != -1) { |
|
168 | - $url = api_get_access_url($access_url_id); |
|
169 | - $portal_url = $url['url']; |
|
170 | - } |
|
166 | + $access_url_id = api_get_current_access_url_id(); |
|
167 | + if ($access_url_id != -1) { |
|
168 | + $url = api_get_access_url($access_url_id); |
|
169 | + $portal_url = $url['url']; |
|
170 | + } |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | // Show the URL that can be used by users to fill a survey without invitation |
@@ -177,56 +177,56 @@ discard block |
||
177 | 177 | $form->addElement('label', null, $auto_survey_link); |
178 | 178 | |
179 | 179 | if ($form->validate()) { |
180 | - $values = $form->exportValues(); |
|
180 | + $values = $form->exportValues(); |
|
181 | 181 | if (isset($values['send_mail']) && $values['send_mail'] == 1) { |
182 | 182 | if (empty($values['mail_title']) || empty($values['mail_text'])) { |
183 | 183 | Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete')); |
184 | 184 | // Getting the invited users |
185 | - $defaults = SurveyUtil::get_invited_users($survey_data['code']); |
|
186 | - |
|
187 | - // Getting the survey mail text |
|
188 | - if (!empty($survey_data['reminder_mail'])) { |
|
189 | - $defaults['mail_text'] = $survey_data['reminder_mail']; |
|
190 | - } else { |
|
191 | - $defaults['mail_text'] = $survey_data['invite_mail']; |
|
192 | - } |
|
193 | - $defaults['mail_title'] = $survey_data['mail_subject']; |
|
194 | - $defaults['send_mail'] = 1; |
|
195 | - $form->setDefaults($defaults); |
|
185 | + $defaults = SurveyUtil::get_invited_users($survey_data['code']); |
|
186 | + |
|
187 | + // Getting the survey mail text |
|
188 | + if (!empty($survey_data['reminder_mail'])) { |
|
189 | + $defaults['mail_text'] = $survey_data['reminder_mail']; |
|
190 | + } else { |
|
191 | + $defaults['mail_text'] = $survey_data['invite_mail']; |
|
192 | + } |
|
193 | + $defaults['mail_title'] = $survey_data['mail_subject']; |
|
194 | + $defaults['send_mail'] = 1; |
|
195 | + $form->setDefaults($defaults); |
|
196 | 196 | $form->display(); |
197 | 197 | return; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | // Save the invitation mail |
201 | - SurveyUtil::save_invite_mail( |
|
202 | - $values['mail_text'], |
|
203 | - $values['mail_title'], |
|
204 | - !empty($survey_data['invite_mail']) |
|
205 | - ); |
|
201 | + SurveyUtil::save_invite_mail( |
|
202 | + $values['mail_text'], |
|
203 | + $values['mail_title'], |
|
204 | + !empty($survey_data['invite_mail']) |
|
205 | + ); |
|
206 | 206 | |
207 | 207 | $resendAll = isset($values['resend_to_all']) ? $values['resend_to_all'] : ''; |
208 | 208 | $sendMail = isset($values['send_mail']) ? $values['send_mail'] : ''; |
209 | 209 | $remindUnAnswered = isset($values['remindUnAnswered']) ? $values['remindUnAnswered'] : ''; |
210 | 210 | |
211 | - // Saving the invitations for the course users |
|
212 | - $count_course_users = SurveyUtil::saveInvitations( |
|
213 | - $values['users'], |
|
214 | - $values['mail_title'], |
|
215 | - $values['mail_text'], |
|
211 | + // Saving the invitations for the course users |
|
212 | + $count_course_users = SurveyUtil::saveInvitations( |
|
213 | + $values['users'], |
|
214 | + $values['mail_title'], |
|
215 | + $values['mail_text'], |
|
216 | 216 | $resendAll, |
217 | 217 | $sendMail, |
218 | 218 | $remindUnAnswered |
219 | - ); |
|
219 | + ); |
|
220 | 220 | |
221 | - // Saving the invitations for the additional users |
|
222 | - $values['additional_users'] = $values['additional_users'].';'; // This is for the case when you enter only one email |
|
223 | - $temp = str_replace(',', ';', $values['additional_users']); // This is to allow , and ; as email separators |
|
224 | - $additional_users = explode(';', $temp); |
|
225 | - for ($i = 0; $i < count($additional_users); $i++) { |
|
226 | - $additional_users[$i] = trim($additional_users[$i]); |
|
227 | - } |
|
221 | + // Saving the invitations for the additional users |
|
222 | + $values['additional_users'] = $values['additional_users'].';'; // This is for the case when you enter only one email |
|
223 | + $temp = str_replace(',', ';', $values['additional_users']); // This is to allow , and ; as email separators |
|
224 | + $additional_users = explode(';', $temp); |
|
225 | + for ($i = 0; $i < count($additional_users); $i++) { |
|
226 | + $additional_users[$i] = trim($additional_users[$i]); |
|
227 | + } |
|
228 | 228 | |
229 | - $counter_additional_users = SurveyUtil::saveInvitations( |
|
229 | + $counter_additional_users = SurveyUtil::saveInvitations( |
|
230 | 230 | $additional_users, |
231 | 231 | $values['mail_title'], |
232 | 232 | $values['mail_text'], |
@@ -235,43 +235,43 @@ discard block |
||
235 | 235 | $remindUnAnswered |
236 | 236 | ); |
237 | 237 | |
238 | - // Updating the invited field in the survey table |
|
239 | - SurveyUtil::update_count_invited($survey_data['code']); |
|
240 | - $total_count = $count_course_users + $counter_additional_users; |
|
238 | + // Updating the invited field in the survey table |
|
239 | + SurveyUtil::update_count_invited($survey_data['code']); |
|
240 | + $total_count = $count_course_users + $counter_additional_users; |
|
241 | 241 | $table_survey = Database :: get_course_table(TABLE_SURVEY); |
242 | - // Counting the number of people that are invited |
|
243 | - $sql = "SELECT * FROM $table_survey |
|
242 | + // Counting the number of people that are invited |
|
243 | + $sql = "SELECT * FROM $table_survey |
|
244 | 244 | WHERE |
245 | 245 | c_id = $course_id AND |
246 | 246 | code = '".Database::escape_string($survey_data['code'])."' |
247 | 247 | "; |
248 | - $result = Database::query($sql); |
|
249 | - $row = Database::fetch_array($result); |
|
250 | - $total_invited = $row['invited']; |
|
248 | + $result = Database::query($sql); |
|
249 | + $row = Database::fetch_array($result); |
|
250 | + $total_invited = $row['invited']; |
|
251 | 251 | if ($total_invited > 0) { |
252 | - $message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'">'. |
|
253 | - $survey_data['answered'].'</a> '; |
|
254 | - $message .= get_lang('HaveAnswered').' '; |
|
255 | - $message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'">'. |
|
256 | - $total_invited.'</a> '; |
|
257 | - $message .= get_lang('WereInvited'); |
|
258 | - Display::display_normal_message($message, false); |
|
259 | - Display::display_confirmation_message($total_count.' '.get_lang('InvitationsSend')); |
|
252 | + $message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'">'. |
|
253 | + $survey_data['answered'].'</a> '; |
|
254 | + $message .= get_lang('HaveAnswered').' '; |
|
255 | + $message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'">'. |
|
256 | + $total_invited.'</a> '; |
|
257 | + $message .= get_lang('WereInvited'); |
|
258 | + Display::display_normal_message($message, false); |
|
259 | + Display::display_confirmation_message($total_count.' '.get_lang('InvitationsSend')); |
|
260 | 260 | } |
261 | 261 | } else { |
262 | - // Getting the invited users |
|
263 | - $defaults = SurveyUtil::get_invited_users($survey_data['code']); |
|
264 | - |
|
265 | - // Getting the survey mail text |
|
266 | - if (!empty($survey_data['reminder_mail'])) { |
|
267 | - $defaults['mail_text'] = $survey_data['reminder_mail']; |
|
268 | - } else { |
|
269 | - $defaults['mail_text'] = $survey_data['invite_mail']; |
|
270 | - } |
|
271 | - $defaults['mail_title'] = $survey_data['mail_subject']; |
|
272 | - $defaults['send_mail'] = 1; |
|
273 | - |
|
274 | - $form->setDefaults($defaults); |
|
262 | + // Getting the invited users |
|
263 | + $defaults = SurveyUtil::get_invited_users($survey_data['code']); |
|
264 | + |
|
265 | + // Getting the survey mail text |
|
266 | + if (!empty($survey_data['reminder_mail'])) { |
|
267 | + $defaults['mail_text'] = $survey_data['reminder_mail']; |
|
268 | + } else { |
|
269 | + $defaults['mail_text'] = $survey_data['invite_mail']; |
|
270 | + } |
|
271 | + $defaults['mail_title'] = $survey_data['mail_subject']; |
|
272 | + $defaults['send_mail'] = 1; |
|
273 | + |
|
274 | + $form->setDefaults($defaults); |
|
275 | 275 | $form->display(); |
276 | 276 | } |
277 | 277 | Display :: display_footer(); |
@@ -8,48 +8,48 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class AttendanceLink extends AbstractLink |
10 | 10 | { |
11 | - private $attendance_table = null; |
|
12 | - private $itemprop_table = null; |
|
11 | + private $attendance_table = null; |
|
12 | + private $itemprop_table = null; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Constructor |
|
16 | - */ |
|
17 | - public function __construct() |
|
18 | - { |
|
19 | - parent::__construct(); |
|
20 | - $this->set_type(LINK_ATTENDANCE); |
|
21 | - } |
|
14 | + /** |
|
15 | + * Constructor |
|
16 | + */ |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + parent::__construct(); |
|
20 | + $this->set_type(LINK_ATTENDANCE); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function get_type_name() |
|
27 | - { |
|
28 | - return get_lang('Attendance'); |
|
29 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function get_type_name() |
|
27 | + { |
|
28 | + return get_lang('Attendance'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function is_allowed_to_change_name() |
|
35 | - { |
|
36 | - return false; |
|
37 | - } |
|
31 | + /** |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function is_allowed_to_change_name() |
|
35 | + { |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Generate an array of attendances that a teacher hasn't created a link for. |
|
41 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
42 | - * @todo seems to be depracated |
|
43 | - */ |
|
44 | - public function get_not_created_links() |
|
45 | - { |
|
46 | - return false; |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
39 | + /** |
|
40 | + * Generate an array of attendances that a teacher hasn't created a link for. |
|
41 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
42 | + * @todo seems to be depracated |
|
43 | + */ |
|
44 | + public function get_not_created_links() |
|
45 | + { |
|
46 | + return false; |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
51 | 51 | |
52 | - $sql = 'SELECT att.id, att.name, att.attendance_qualify_title |
|
52 | + $sql = 'SELECT att.id, att.name, att.attendance_qualify_title |
|
53 | 53 | FROM '.$this->get_attendance_table().' att |
54 | 54 | WHERE |
55 | 55 | att.c_id = '.$this->course_id.' AND |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | course_code = "'.Database::escape_string($this->get_course_code()).'" |
61 | 61 | ) |
62 | 62 | AND att.session_id='.api_get_session_id().''; |
63 | - $result = Database::query($sql); |
|
63 | + $result = Database::query($sql); |
|
64 | 64 | |
65 | 65 | $cats = array(); |
66 | 66 | while ($data = Database::fetch_array($result)) { |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - return $cats; |
|
75 | - } |
|
74 | + return $cats; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Generate an array of all attendances available. |
|
79 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | - */ |
|
77 | + /** |
|
78 | + * Generate an array of all attendances available. |
|
79 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | + */ |
|
81 | 81 | public function get_all_links() |
82 | 82 | { |
83 | 83 | if (empty($this->course_code)) { |
@@ -104,55 +104,55 @@ discard block |
||
104 | 104 | $my_cats = isset($cats) ? $cats : null; |
105 | 105 | |
106 | 106 | return $my_cats; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Has anyone done this exercise yet ? |
|
111 | - */ |
|
112 | - public function has_results() |
|
113 | - { |
|
114 | - $tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT); |
|
115 | - $session_id = api_get_session_id(); |
|
116 | - $sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result." |
|
109 | + /** |
|
110 | + * Has anyone done this exercise yet ? |
|
111 | + */ |
|
112 | + public function has_results() |
|
113 | + { |
|
114 | + $tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT); |
|
115 | + $session_id = api_get_session_id(); |
|
116 | + $sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result." |
|
117 | 117 | WHERE |
118 | 118 | session_id = $session_id AND |
119 | 119 | c_id = '.$this->course_id.' AND |
120 | 120 | attendance_id = '".intval($this->get_ref_id())."'"; |
121 | - $result = Database::query($sql); |
|
122 | - $number = Database::fetch_row($result); |
|
121 | + $result = Database::query($sql); |
|
122 | + $number = Database::fetch_row($result); |
|
123 | 123 | |
124 | - return $number[0] != 0; |
|
125 | - } |
|
124 | + return $number[0] != 0; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param int $stud_id |
|
129 | - * @return array|null |
|
130 | - */ |
|
131 | - public function calc_score($stud_id = null, $type = null) |
|
132 | - { |
|
133 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
134 | - $session_id = api_get_session_id(); |
|
127 | + /** |
|
128 | + * @param int $stud_id |
|
129 | + * @return array|null |
|
130 | + */ |
|
131 | + public function calc_score($stud_id = null, $type = null) |
|
132 | + { |
|
133 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
134 | + $session_id = api_get_session_id(); |
|
135 | 135 | |
136 | - // get attendance qualify max |
|
137 | - $sql = 'SELECT att.attendance_qualify_max |
|
136 | + // get attendance qualify max |
|
137 | + $sql = 'SELECT att.attendance_qualify_max |
|
138 | 138 | FROM '.$this->get_attendance_table().' att |
139 | 139 | WHERE |
140 | 140 | att.c_id = '.$this->course_id.' AND |
141 | 141 | att.id = '.intval($this->get_ref_id()).' AND |
142 | 142 | att.session_id='.intval($session_id).''; |
143 | - $query = Database::query($sql); |
|
144 | - $attendance = Database::fetch_array($query, 'ASSOC'); |
|
143 | + $query = Database::query($sql); |
|
144 | + $attendance = Database::fetch_array($query, 'ASSOC'); |
|
145 | 145 | |
146 | - // Get results |
|
147 | - $sql = 'SELECT * |
|
146 | + // Get results |
|
147 | + $sql = 'SELECT * |
|
148 | 148 | FROM '.$tbl_attendance_result.' |
149 | 149 | WHERE c_id = '.$this->course_id.' AND attendance_id = '.intval($this->get_ref_id()); |
150 | - if (isset($stud_id)) { |
|
151 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
152 | - } |
|
153 | - $scores = Database::query($sql); |
|
154 | - // for 1 student |
|
155 | - if (isset($stud_id)) { |
|
150 | + if (isset($stud_id)) { |
|
151 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
152 | + } |
|
153 | + $scores = Database::query($sql); |
|
154 | + // for 1 student |
|
155 | + if (isset($stud_id)) { |
|
156 | 156 | if ($data = Database::fetch_array($scores, 'ASSOC')) { |
157 | 157 | return array( |
158 | 158 | $data['score'], |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | //We sent the 0/attendance_qualify_max instead of null for correct calculations |
163 | 163 | return array(0, $attendance['attendance_qualify_max']); |
164 | 164 | } |
165 | - } else { |
|
165 | + } else { |
|
166 | 166 | // all students -> get average |
167 | 167 | $students = array(); // user list, needed to make sure we only |
168 | 168 | // take first attempts into account |
@@ -171,144 +171,144 @@ discard block |
||
171 | 171 | $sumResult = 0; |
172 | 172 | $bestResult = 0; |
173 | 173 | |
174 | - while ($data = Database::fetch_array($scores)) { |
|
175 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
176 | - if ($attendance['attendance_qualify_max'] != 0) { |
|
177 | - $students[$data['user_id']] = $data['score']; |
|
178 | - $rescount++; |
|
179 | - $sum += $data['score'] / $attendance['attendance_qualify_max']; |
|
180 | - $sumResult += $data['score']; |
|
181 | - if ($data['score'] > $bestResult) { |
|
182 | - $bestResult = $data['score']; |
|
183 | - } |
|
184 | - $weight = $attendance['attendance_qualify_max']; |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
174 | + while ($data = Database::fetch_array($scores)) { |
|
175 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
176 | + if ($attendance['attendance_qualify_max'] != 0) { |
|
177 | + $students[$data['user_id']] = $data['score']; |
|
178 | + $rescount++; |
|
179 | + $sum += $data['score'] / $attendance['attendance_qualify_max']; |
|
180 | + $sumResult += $data['score']; |
|
181 | + if ($data['score'] > $bestResult) { |
|
182 | + $bestResult = $data['score']; |
|
183 | + } |
|
184 | + $weight = $attendance['attendance_qualify_max']; |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | 188 | |
189 | - if ($rescount == 0) { |
|
190 | - return null; |
|
191 | - } else { |
|
192 | - switch ($type) { |
|
193 | - case 'best': |
|
194 | - return array($bestResult, $weight); |
|
195 | - break; |
|
196 | - case 'average': |
|
197 | - return array($sumResult / $rescount, $weight); |
|
198 | - break; |
|
199 | - case 'ranking': |
|
200 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
201 | - break; |
|
202 | - default: |
|
203 | - return array($sum, $rescount); |
|
204 | - break; |
|
205 | - } |
|
206 | - } |
|
207 | - } |
|
208 | - } |
|
189 | + if ($rescount == 0) { |
|
190 | + return null; |
|
191 | + } else { |
|
192 | + switch ($type) { |
|
193 | + case 'best': |
|
194 | + return array($bestResult, $weight); |
|
195 | + break; |
|
196 | + case 'average': |
|
197 | + return array($sumResult / $rescount, $weight); |
|
198 | + break; |
|
199 | + case 'ranking': |
|
200 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
201 | + break; |
|
202 | + default: |
|
203 | + return array($sum, $rescount); |
|
204 | + break; |
|
205 | + } |
|
206 | + } |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Lazy load function to get the database table of the student publications |
|
212 | - */ |
|
213 | - private function get_attendance_table() |
|
214 | - { |
|
215 | - $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE); |
|
216 | - return $this->attendance_table; |
|
217 | - } |
|
210 | + /** |
|
211 | + * Lazy load function to get the database table of the student publications |
|
212 | + */ |
|
213 | + private function get_attendance_table() |
|
214 | + { |
|
215 | + $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE); |
|
216 | + return $this->attendance_table; |
|
217 | + } |
|
218 | 218 | |
219 | - public function needs_name_and_description() |
|
220 | - { |
|
221 | - return false; |
|
222 | - } |
|
219 | + public function needs_name_and_description() |
|
220 | + { |
|
221 | + return false; |
|
222 | + } |
|
223 | 223 | |
224 | - public function needs_max() |
|
225 | - { |
|
226 | - return false; |
|
227 | - } |
|
224 | + public function needs_max() |
|
225 | + { |
|
226 | + return false; |
|
227 | + } |
|
228 | 228 | |
229 | - public function needs_results() |
|
230 | - { |
|
231 | - return false; |
|
232 | - } |
|
229 | + public function needs_results() |
|
230 | + { |
|
231 | + return false; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public function get_name() |
|
238 | - { |
|
239 | - $this->get_attendance_data(); |
|
240 | - $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : ''; |
|
241 | - $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : ''; |
|
242 | - if ( isset($attendance_qualify_title) && $attendance_qualify_title != '') { |
|
243 | - return $this->attendance_data['attendance_qualify_title']; |
|
244 | - } else { |
|
245 | - return $attendance_title; |
|
246 | - } |
|
247 | - } |
|
234 | + /** |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public function get_name() |
|
238 | + { |
|
239 | + $this->get_attendance_data(); |
|
240 | + $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : ''; |
|
241 | + $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : ''; |
|
242 | + if ( isset($attendance_qualify_title) && $attendance_qualify_title != '') { |
|
243 | + return $this->attendance_data['attendance_qualify_title']; |
|
244 | + } else { |
|
245 | + return $attendance_title; |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @return string |
|
251 | - */ |
|
252 | - public function get_description() |
|
253 | - { |
|
254 | - return ''; |
|
255 | - } |
|
249 | + /** |
|
250 | + * @return string |
|
251 | + */ |
|
252 | + public function get_description() |
|
253 | + { |
|
254 | + return ''; |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Check if this still links to an exercise |
|
259 | - */ |
|
260 | - public function is_valid_link() |
|
261 | - { |
|
262 | - $session_id = api_get_session_id(); |
|
263 | - $sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att |
|
257 | + /** |
|
258 | + * Check if this still links to an exercise |
|
259 | + */ |
|
260 | + public function is_valid_link() |
|
261 | + { |
|
262 | + $session_id = api_get_session_id(); |
|
263 | + $sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att |
|
264 | 264 | WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' '; |
265 | - $result = Database::query($sql); |
|
266 | - $number = Database::fetch_row($result); |
|
267 | - return ($number[0] != 0); |
|
268 | - } |
|
265 | + $result = Database::query($sql); |
|
266 | + $number = Database::fetch_row($result); |
|
267 | + return ($number[0] != 0); |
|
268 | + } |
|
269 | 269 | |
270 | - public function get_test_id() |
|
271 | - { |
|
272 | - return 'DEBUG:ID'; |
|
273 | - } |
|
270 | + public function get_test_id() |
|
271 | + { |
|
272 | + return 'DEBUG:ID'; |
|
273 | + } |
|
274 | 274 | |
275 | - public function get_link() |
|
276 | - { |
|
277 | - //it was extracts the attendance id |
|
278 | - $session_id = api_get_session_id(); |
|
279 | - $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
275 | + public function get_link() |
|
276 | + { |
|
277 | + //it was extracts the attendance id |
|
278 | + $session_id = api_get_session_id(); |
|
279 | + $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
280 | 280 | WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' '; |
281 | - $result = Database::query($sql); |
|
282 | - $row = Database::fetch_array($result,'ASSOC'); |
|
283 | - $attendance_id = $row['id']; |
|
284 | - $url = api_get_path(WEB_PATH).'main/attendance/index.php?action=attendance_sheet_list&gradebook=view&attendance_id='.$attendance_id.'&'.api_get_cidreq_params($this->get_course_code(), $session_id); |
|
281 | + $result = Database::query($sql); |
|
282 | + $row = Database::fetch_array($result,'ASSOC'); |
|
283 | + $attendance_id = $row['id']; |
|
284 | + $url = api_get_path(WEB_PATH).'main/attendance/index.php?action=attendance_sheet_list&gradebook=view&attendance_id='.$attendance_id.'&'.api_get_cidreq_params($this->get_course_code(), $session_id); |
|
285 | 285 | |
286 | - return $url; |
|
287 | - } |
|
286 | + return $url; |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * @return array|bool |
|
291 | - */ |
|
292 | - private function get_attendance_data() |
|
293 | - { |
|
294 | - $tbl_name = $this->get_attendance_table(); |
|
295 | - $session_id = api_get_session_id(); |
|
296 | - if ($tbl_name == '') { |
|
297 | - return false; |
|
298 | - } elseif (!isset($this->attendance_data)) { |
|
299 | - $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
289 | + /** |
|
290 | + * @return array|bool |
|
291 | + */ |
|
292 | + private function get_attendance_data() |
|
293 | + { |
|
294 | + $tbl_name = $this->get_attendance_table(); |
|
295 | + $session_id = api_get_session_id(); |
|
296 | + if ($tbl_name == '') { |
|
297 | + return false; |
|
298 | + } elseif (!isset($this->attendance_data)) { |
|
299 | + $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
300 | 300 | WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' '; |
301 | - $query = Database::query($sql); |
|
302 | - $this->attendance_data = Database::fetch_array($query); |
|
303 | - } |
|
304 | - return $this->attendance_data; |
|
305 | - } |
|
301 | + $query = Database::query($sql); |
|
302 | + $this->attendance_data = Database::fetch_array($query); |
|
303 | + } |
|
304 | + return $this->attendance_data; |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function get_icon_name() |
|
311 | - { |
|
312 | - return 'attendance'; |
|
313 | - } |
|
307 | + /** |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function get_icon_name() |
|
311 | + { |
|
312 | + return 'attendance'; |
|
313 | + } |
|
314 | 314 | } |
@@ -8,98 +8,98 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class SurveyLink extends AbstractLink |
10 | 10 | { |
11 | - private $survey_table = null; |
|
12 | - |
|
13 | - /** |
|
14 | - * Constructor |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - parent::__construct(); |
|
19 | - $this->set_type(LINK_SURVEY); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function get_name() |
|
26 | - { |
|
27 | - $this->get_survey_data(); |
|
11 | + private $survey_table = null; |
|
12 | + |
|
13 | + /** |
|
14 | + * Constructor |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + parent::__construct(); |
|
19 | + $this->set_type(LINK_SURVEY); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function get_name() |
|
26 | + { |
|
27 | + $this->get_survey_data(); |
|
28 | 28 | |
29 | - return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']); |
|
30 | - } |
|
31 | - |
|
32 | - public function get_description() |
|
33 | - { |
|
34 | - $this->get_survey_data(); |
|
35 | - return $this->survey_data['subtitle']; |
|
36 | - } |
|
37 | - |
|
38 | - public function get_type_name() |
|
39 | - { |
|
40 | - return get_lang('Survey'); |
|
41 | - } |
|
42 | - |
|
43 | - public function is_allowed_to_change_name() |
|
44 | - { |
|
45 | - return false; |
|
46 | - } |
|
47 | - |
|
48 | - public function needs_name_and_description() |
|
49 | - { |
|
50 | - return false; |
|
51 | - } |
|
52 | - |
|
53 | - public function needs_max() |
|
54 | - { |
|
55 | - return false; |
|
56 | - } |
|
57 | - |
|
58 | - public function needs_results() |
|
59 | - { |
|
60 | - return false; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Generates an array of all surveys available. |
|
65 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
66 | - */ |
|
67 | - public function get_all_links() |
|
68 | - { |
|
69 | - if (empty($this->course_code)) { |
|
70 | - die('Error in get_all_links() : course code not set'); |
|
71 | - } |
|
72 | - $tbl_survey = $this->get_survey_table(); |
|
73 | - $session_id = api_get_session_id(); |
|
74 | - $course_id = api_get_course_int_id(); |
|
75 | - $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.' |
|
29 | + return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']); |
|
30 | + } |
|
31 | + |
|
32 | + public function get_description() |
|
33 | + { |
|
34 | + $this->get_survey_data(); |
|
35 | + return $this->survey_data['subtitle']; |
|
36 | + } |
|
37 | + |
|
38 | + public function get_type_name() |
|
39 | + { |
|
40 | + return get_lang('Survey'); |
|
41 | + } |
|
42 | + |
|
43 | + public function is_allowed_to_change_name() |
|
44 | + { |
|
45 | + return false; |
|
46 | + } |
|
47 | + |
|
48 | + public function needs_name_and_description() |
|
49 | + { |
|
50 | + return false; |
|
51 | + } |
|
52 | + |
|
53 | + public function needs_max() |
|
54 | + { |
|
55 | + return false; |
|
56 | + } |
|
57 | + |
|
58 | + public function needs_results() |
|
59 | + { |
|
60 | + return false; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Generates an array of all surveys available. |
|
65 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
66 | + */ |
|
67 | + public function get_all_links() |
|
68 | + { |
|
69 | + if (empty($this->course_code)) { |
|
70 | + die('Error in get_all_links() : course code not set'); |
|
71 | + } |
|
72 | + $tbl_survey = $this->get_survey_table(); |
|
73 | + $session_id = api_get_session_id(); |
|
74 | + $course_id = api_get_course_int_id(); |
|
75 | + $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.' |
|
76 | 76 | WHERE c_id = '.$course_id.' AND session_id = '.intval($session_id).''; |
77 | - $result = Database::query($sql); |
|
78 | - while ($data = Database::fetch_array($result)) { |
|
79 | - $links[] = array( |
|
80 | - $data['survey_id'], |
|
81 | - api_trunc_str( |
|
82 | - $data['code'] . ': ' . self::html_to_text($data['title']), |
|
83 | - 80 |
|
84 | - ) |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - return isset($links) ? $links : null; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Generates an array of surveys that a teacher hasn't created a link for. |
|
93 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
94 | - */ |
|
95 | - public function get_not_created_links() |
|
96 | - { |
|
97 | - if (empty($this->course_code)) { |
|
98 | - die('Error in get_not_created_links() : course code not set'); |
|
99 | - } |
|
100 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
101 | - |
|
102 | - $sql = 'SELECT survey_id, title, code |
|
77 | + $result = Database::query($sql); |
|
78 | + while ($data = Database::fetch_array($result)) { |
|
79 | + $links[] = array( |
|
80 | + $data['survey_id'], |
|
81 | + api_trunc_str( |
|
82 | + $data['code'] . ': ' . self::html_to_text($data['title']), |
|
83 | + 80 |
|
84 | + ) |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + return isset($links) ? $links : null; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Generates an array of surveys that a teacher hasn't created a link for. |
|
93 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
94 | + */ |
|
95 | + public function get_not_created_links() |
|
96 | + { |
|
97 | + if (empty($this->course_code)) { |
|
98 | + die('Error in get_not_created_links() : course code not set'); |
|
99 | + } |
|
100 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
101 | + |
|
102 | + $sql = 'SELECT survey_id, title, code |
|
103 | 103 | FROM '.$this->get_survey_table().' AS srv |
104 | 104 | WHERE survey_id NOT IN |
105 | 105 | ( |
@@ -110,28 +110,28 @@ discard block |
||
110 | 110 | ) |
111 | 111 | AND srv.session_id = '.api_get_session_id(); |
112 | 112 | |
113 | - $result = Database::query($sql); |
|
114 | - |
|
115 | - $links = array(); |
|
116 | - while ($data = Database::fetch_array($result)) { |
|
117 | - $links[] = array( |
|
118 | - $data['survey_id'], |
|
119 | - api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80) |
|
120 | - ); |
|
121 | - } |
|
122 | - return $links; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Has anyone done this survey yet? |
|
127 | - */ |
|
128 | - public function has_results($stud_id=null) |
|
129 | - { |
|
130 | - $ref_id = intval($this->get_ref_id()); |
|
131 | - $session_id = api_get_session_id(); |
|
132 | - $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
133 | - $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
134 | - $sql = "SELECT |
|
113 | + $result = Database::query($sql); |
|
114 | + |
|
115 | + $links = array(); |
|
116 | + while ($data = Database::fetch_array($result)) { |
|
117 | + $links[] = array( |
|
118 | + $data['survey_id'], |
|
119 | + api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80) |
|
120 | + ); |
|
121 | + } |
|
122 | + return $links; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Has anyone done this survey yet? |
|
127 | + */ |
|
128 | + public function has_results($stud_id=null) |
|
129 | + { |
|
130 | + $ref_id = intval($this->get_ref_id()); |
|
131 | + $session_id = api_get_session_id(); |
|
132 | + $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
133 | + $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
134 | + $sql = "SELECT |
|
135 | 135 | COUNT(i.answered) |
136 | 136 | FROM $tbl_survey AS s |
137 | 137 | JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code |
@@ -141,30 +141,30 @@ discard block |
||
141 | 141 | s.survey_id = $ref_id AND |
142 | 142 | i.session_id = $session_id"; |
143 | 143 | |
144 | - $sql_result = Database::query($sql); |
|
145 | - $data = Database::fetch_array($sql_result); |
|
144 | + $sql_result = Database::query($sql); |
|
145 | + $data = Database::fetch_array($sql_result); |
|
146 | 146 | |
147 | - return ($data[0] != 0); |
|
148 | - } |
|
147 | + return ($data[0] != 0); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @param int $stud_id |
|
152 | - * @return array|null |
|
153 | - */ |
|
154 | - public function calc_score($stud_id = null, $type = null) |
|
155 | - { |
|
156 | - // Note: Max score is assumed to be always 1 for surveys, |
|
157 | - // only student's participation is to be taken into account. |
|
158 | - $max_score = 1; |
|
150 | + /** |
|
151 | + * @param int $stud_id |
|
152 | + * @return array|null |
|
153 | + */ |
|
154 | + public function calc_score($stud_id = null, $type = null) |
|
155 | + { |
|
156 | + // Note: Max score is assumed to be always 1 for surveys, |
|
157 | + // only student's participation is to be taken into account. |
|
158 | + $max_score = 1; |
|
159 | 159 | |
160 | - $ref_id = intval($this->get_ref_id()); |
|
161 | - $session_id = api_get_session_id(); |
|
162 | - $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
163 | - $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
160 | + $ref_id = intval($this->get_ref_id()); |
|
161 | + $session_id = api_get_session_id(); |
|
162 | + $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
163 | + $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
164 | 164 | |
165 | - $get_individual_score = !is_null($stud_id); |
|
165 | + $get_individual_score = !is_null($stud_id); |
|
166 | 166 | |
167 | - $sql = "SELECT i.answered |
|
167 | + $sql = "SELECT i.answered |
|
168 | 168 | FROM $tbl_survey AS s |
169 | 169 | JOIN $tbl_survey_invitation AS i |
170 | 170 | ON s.code = i.survey_code |
@@ -175,131 +175,131 @@ discard block |
||
175 | 175 | i.session_id = $session_id |
176 | 176 | "; |
177 | 177 | |
178 | - if ($get_individual_score) { |
|
179 | - $sql .= ' AND i.user = '.intval($stud_id); |
|
180 | - } |
|
181 | - |
|
182 | - $sql_result = Database::query($sql); |
|
183 | - |
|
184 | - if ($get_individual_score) { |
|
185 | - // for 1 student |
|
186 | - if ($data = Database::fetch_array($sql_result)) { |
|
187 | - return array($data['answered'] ? $max_score : 0, $max_score); |
|
188 | - } |
|
189 | - return array(0, $max_score); |
|
190 | - } else { |
|
191 | - // for all the students -> get average |
|
192 | - $rescount = 0; |
|
193 | - $sum = 0; |
|
194 | - $bestResult = 0; |
|
195 | - $weight = 0; |
|
196 | - while ($data = Database::fetch_array($sql_result)) { |
|
197 | - $sum += $data['answered'] ? $max_score : 0; |
|
198 | - $rescount++; |
|
199 | - if ($data['answered'] > $bestResult) { |
|
200 | - $bestResult = $data['answered']; |
|
201 | - $weight = $assignment['qualification']; |
|
202 | - } |
|
203 | - } |
|
204 | - $sum = $sum / $max_score; |
|
205 | - |
|
206 | - if ($rescount == 0) { |
|
207 | - return null; |
|
208 | - } |
|
209 | - |
|
210 | - switch ($type) { |
|
211 | - case 'best': |
|
212 | - return array($bestResult, $rescount); |
|
213 | - break; |
|
214 | - case 'average': |
|
215 | - return array($sum, $rescount); |
|
216 | - break; |
|
217 | - case 'ranking': |
|
218 | - return null; |
|
219 | - break; |
|
220 | - default: |
|
221 | - return array($sum, $rescount); |
|
222 | - break; |
|
223 | - } |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Lazy load function to get the database table of the surveys |
|
229 | - */ |
|
230 | - private function get_survey_table() |
|
231 | - { |
|
232 | - $this->survey_table = Database :: get_course_table(TABLE_SURVEY); |
|
233 | - return $this->survey_table; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Check if this still links to a survey |
|
238 | - */ |
|
239 | - public function is_valid_link() |
|
240 | - { |
|
241 | - $session_id = api_get_session_id(); |
|
242 | - $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().' |
|
178 | + if ($get_individual_score) { |
|
179 | + $sql .= ' AND i.user = '.intval($stud_id); |
|
180 | + } |
|
181 | + |
|
182 | + $sql_result = Database::query($sql); |
|
183 | + |
|
184 | + if ($get_individual_score) { |
|
185 | + // for 1 student |
|
186 | + if ($data = Database::fetch_array($sql_result)) { |
|
187 | + return array($data['answered'] ? $max_score : 0, $max_score); |
|
188 | + } |
|
189 | + return array(0, $max_score); |
|
190 | + } else { |
|
191 | + // for all the students -> get average |
|
192 | + $rescount = 0; |
|
193 | + $sum = 0; |
|
194 | + $bestResult = 0; |
|
195 | + $weight = 0; |
|
196 | + while ($data = Database::fetch_array($sql_result)) { |
|
197 | + $sum += $data['answered'] ? $max_score : 0; |
|
198 | + $rescount++; |
|
199 | + if ($data['answered'] > $bestResult) { |
|
200 | + $bestResult = $data['answered']; |
|
201 | + $weight = $assignment['qualification']; |
|
202 | + } |
|
203 | + } |
|
204 | + $sum = $sum / $max_score; |
|
205 | + |
|
206 | + if ($rescount == 0) { |
|
207 | + return null; |
|
208 | + } |
|
209 | + |
|
210 | + switch ($type) { |
|
211 | + case 'best': |
|
212 | + return array($bestResult, $rescount); |
|
213 | + break; |
|
214 | + case 'average': |
|
215 | + return array($sum, $rescount); |
|
216 | + break; |
|
217 | + case 'ranking': |
|
218 | + return null; |
|
219 | + break; |
|
220 | + default: |
|
221 | + return array($sum, $rescount); |
|
222 | + break; |
|
223 | + } |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Lazy load function to get the database table of the surveys |
|
229 | + */ |
|
230 | + private function get_survey_table() |
|
231 | + { |
|
232 | + $this->survey_table = Database :: get_course_table(TABLE_SURVEY); |
|
233 | + return $this->survey_table; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Check if this still links to a survey |
|
238 | + */ |
|
239 | + public function is_valid_link() |
|
240 | + { |
|
241 | + $session_id = api_get_session_id(); |
|
242 | + $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().' |
|
243 | 243 | WHERE |
244 | 244 | c_id = '.$this->course_id.' AND |
245 | 245 | survey_id = '.intval($this->get_ref_id()).' AND |
246 | 246 | session_id='.intval($session_id).''; |
247 | - $result = Database::query($sql); |
|
248 | - $number = Database::fetch_row($result); |
|
249 | - return ($number[0] != 0); |
|
250 | - } |
|
251 | - |
|
252 | - public function get_test_id() |
|
253 | - { |
|
254 | - return 'DEBUG:ID'; |
|
255 | - } |
|
256 | - |
|
257 | - public function get_link() |
|
258 | - { |
|
259 | - if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool. |
|
260 | - $tbl_name = $this->get_survey_table(); |
|
261 | - $session_id = api_get_session_id(); |
|
262 | - if ($tbl_name != '') { |
|
263 | - $sql = 'SELECT survey_id FROM '.$this->get_survey_table().' |
|
247 | + $result = Database::query($sql); |
|
248 | + $number = Database::fetch_row($result); |
|
249 | + return ($number[0] != 0); |
|
250 | + } |
|
251 | + |
|
252 | + public function get_test_id() |
|
253 | + { |
|
254 | + return 'DEBUG:ID'; |
|
255 | + } |
|
256 | + |
|
257 | + public function get_link() |
|
258 | + { |
|
259 | + if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool. |
|
260 | + $tbl_name = $this->get_survey_table(); |
|
261 | + $session_id = api_get_session_id(); |
|
262 | + if ($tbl_name != '') { |
|
263 | + $sql = 'SELECT survey_id FROM '.$this->get_survey_table().' |
|
264 | 264 | WHERE |
265 | 265 | c_id = '.$this->course_id.' AND |
266 | 266 | survey_id = '.intval($this->get_ref_id()).' AND |
267 | 267 | session_id = '.intval($session_id).' '; |
268 | - $result = Database::query($sql); |
|
269 | - $row = Database::fetch_array($result, 'ASSOC'); |
|
270 | - $survey_id = $row['survey_id']; |
|
271 | - return api_get_path(WEB_PATH).'main/survey/reporting.php?'.api_get_cidreq_params($this->get_course_code(), $session_id).'&survey_id='.$survey_id; |
|
272 | - } |
|
273 | - } |
|
274 | - return null; |
|
275 | - } |
|
276 | - |
|
277 | - private function get_survey_data() |
|
278 | - { |
|
279 | - $tbl_name = $this->get_survey_table(); |
|
280 | - $session_id = api_get_session_id(); |
|
281 | - if ($tbl_name == '') { |
|
282 | - return false; |
|
283 | - } elseif (!isset($this->survey_data)) { |
|
284 | - $sql = 'SELECT * FROM '.$tbl_name.' |
|
268 | + $result = Database::query($sql); |
|
269 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
270 | + $survey_id = $row['survey_id']; |
|
271 | + return api_get_path(WEB_PATH).'main/survey/reporting.php?'.api_get_cidreq_params($this->get_course_code(), $session_id).'&survey_id='.$survey_id; |
|
272 | + } |
|
273 | + } |
|
274 | + return null; |
|
275 | + } |
|
276 | + |
|
277 | + private function get_survey_data() |
|
278 | + { |
|
279 | + $tbl_name = $this->get_survey_table(); |
|
280 | + $session_id = api_get_session_id(); |
|
281 | + if ($tbl_name == '') { |
|
282 | + return false; |
|
283 | + } elseif (!isset($this->survey_data)) { |
|
284 | + $sql = 'SELECT * FROM '.$tbl_name.' |
|
285 | 285 | WHERE |
286 | 286 | c_id = '.$this->course_id.' AND |
287 | 287 | survey_id = '.intval($this->get_ref_id()).' AND |
288 | 288 | session_id='.intval($session_id).''; |
289 | - $query = Database::query($sql); |
|
290 | - $this->survey_data = Database::fetch_array($query); |
|
291 | - } |
|
292 | - return $this->survey_data; |
|
293 | - } |
|
294 | - |
|
295 | - public function get_icon_name() |
|
296 | - { |
|
297 | - return 'survey'; |
|
298 | - } |
|
299 | - |
|
300 | - private static function html_to_text($string) |
|
301 | - { |
|
302 | - return strip_tags($string); |
|
303 | - //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES)); |
|
304 | - } |
|
289 | + $query = Database::query($sql); |
|
290 | + $this->survey_data = Database::fetch_array($query); |
|
291 | + } |
|
292 | + return $this->survey_data; |
|
293 | + } |
|
294 | + |
|
295 | + public function get_icon_name() |
|
296 | + { |
|
297 | + return 'survey'; |
|
298 | + } |
|
299 | + |
|
300 | + private static function html_to_text($string) |
|
301 | + { |
|
302 | + return strip_tags($string); |
|
303 | + //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES)); |
|
304 | + } |
|
305 | 305 | } |