Completed
Push — 1.11.x ( 6904fa...6a92e6 )
by José
525:44 queued 484:20
created
main/user/add_users_to_session.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -49,29 +49,29 @@  discard block
 block discarded – undo
49 49
     $extra_field_list = UserManager::get_extra_fields();
50 50
     $new_field_list = array();
51 51
     if (is_array($extra_field_list)) {
52
-    	foreach ($extra_field_list as $extra_field) {
53
-    		//if is enabled to filter and is a "<select>" field type
54
-    		if ($extra_field[8]==1 && $extra_field[2]==4 ) {
52
+        foreach ($extra_field_list as $extra_field) {
53
+            //if is enabled to filter and is a "<select>" field type
54
+            if ($extra_field[8]==1 && $extra_field[2]==4 ) {
55 55
                 $new_field_list[] = array(
56 56
                     'name' => $extra_field[3],
57 57
                     'variable' => $extra_field[1],
58 58
                     'data' => $extra_field[9],
59 59
                 );
60
-    		}
61
-    	}
60
+            }
61
+        }
62 62
     }
63 63
 
64 64
     function search_users($needle, $type)
65 65
     {
66
-    	global $id_session;
66
+        global $id_session;
67 67
 
68 68
         $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
69 69
         $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
70 70
 
71
-    	$xajax_response = new xajaxResponse();
72
-    	$return = '';
71
+        $xajax_response = new xajaxResponse();
72
+        $return = '';
73 73
 
74
-    	if (!empty($needle) && !empty($type)) {
74
+        if (!empty($needle) && !empty($type)) {
75 75
 
76 76
             //normal behaviour
77 77
             if ($type == 'any_session' && $needle == 'false')  {
@@ -79,32 +79,32 @@  discard block
 block discarded – undo
79 79
                 $needle = '';
80 80
             }
81 81
 
82
-    		// xajax send utf8 datas... datas in db can be non-utf8 datas
83
-    		$charset = api_get_system_encoding();
84
-    		$needle = Database::escape_string($needle);
85
-    		$needle = api_convert_encoding($needle, $charset, 'utf-8');
82
+            // xajax send utf8 datas... datas in db can be non-utf8 datas
83
+            $charset = api_get_system_encoding();
84
+            $needle = Database::escape_string($needle);
85
+            $needle = api_convert_encoding($needle, $charset, 'utf-8');
86 86
 
87
-    		$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
88
-    		$cond_user_id = '';
87
+            $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
88
+            $cond_user_id = '';
89 89
 
90 90
             //Only for single & multiple
91 91
             if (in_array($type, array('single','multiple'))) {
92
-        		if (!empty($id_session)) {
93
-        		    $id_session = intval($id_session);
94
-        			// check id_user from session_rel_user table
95
-        			$sql = 'SELECT user_id FROM '.$tbl_session_rel_user.'
92
+                if (!empty($id_session)) {
93
+                    $id_session = intval($id_session);
94
+                    // check id_user from session_rel_user table
95
+                    $sql = 'SELECT user_id FROM '.$tbl_session_rel_user.'
96 96
         			        WHERE session_id ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' ';
97
-        			$res = Database::query($sql);
98
-        			$user_ids = array();
99
-        			if (Database::num_rows($res) > 0) {
100
-        				while ($row = Database::fetch_row($res)) {
101
-        					$user_ids[] = (int)$row[0];
102
-        				}
103
-        			}
104
-        			if (count($user_ids) > 0) {
105
-        				$cond_user_id = ' AND user.user_id NOT IN('.implode(",",$user_ids).')';
106
-        			}
107
-        		}
97
+                    $res = Database::query($sql);
98
+                    $user_ids = array();
99
+                    if (Database::num_rows($res) > 0) {
100
+                        while ($row = Database::fetch_row($res)) {
101
+                            $user_ids[] = (int)$row[0];
102
+                        }
103
+                    }
104
+                    if (count($user_ids) > 0) {
105
+                        $cond_user_id = ' AND user.user_id NOT IN('.implode(",",$user_ids).')';
106
+                    }
107
+                }
108 108
             }
109 109
 
110 110
             switch ($type) {
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
                                 user.status <> 6 '.$cond_user_id.
137 137
                             $order_clause;
138 138
                     break;
139
-    		}
140
-    		if (api_is_multiple_url_enabled()) {
141
-    			$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
142
-    			$access_url_id = api_get_current_access_url_id();
143
-    			if ($access_url_id != -1) {
139
+            }
140
+            if (api_is_multiple_url_enabled()) {
141
+                $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
142
+                $access_url_id = api_get_current_access_url_id();
143
+                if ($access_url_id != -1) {
144 144
                     switch ($type) {
145 145
                         case 'single':
146 146
                             $sql = 'SELECT user.user_id, username, lastname, firstname
@@ -178,36 +178,36 @@  discard block
 block discarded – undo
178 178
                                         user.status<>6 '.$cond_user_id.
179 179
                             $order_clause;
180 180
                             break;
181
-    				}
182
-    			}
183
-    		}
181
+                    }
182
+                }
183
+            }
184 184
 
185
-    		$rs = Database::query($sql);
185
+            $rs = Database::query($sql);
186 186
             $i=0;
187
-    		if ($type == 'single') {
188
-    			while ($user = Database::fetch_array($rs)) {
189
-    	            $i++;
190
-    	            if ($i<=10) {
191
-                		$person_name = api_get_person_name($user['firstname'], $user['lastname']);
192
-    					$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
193
-    	            } else {
194
-    	            	$return .= '...<br />';
195
-    	            }
196
-    			}
197
-
198
-    			$xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
199
-    		} else {
200
-    			global $nosessionUsersList;
201
-    			$return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
202
-    			while ($user = Database :: fetch_array($rs)) {
203
-    				$person_name = api_get_person_name($user['firstname'], $user['lastname']);
204
-    	            $return .= '<option value="'.$user['user_id'].'">'.$person_name.' ('.$user['username'].')</option>';
205
-    			}
206
-    			$return .= '</select>';
207
-    			$xajax_response -> addAssign('ajax_list_users_multiple','innerHTML',api_utf8_encode($return));
208
-    		}
209
-    	}
210
-    	return $xajax_response;
187
+            if ($type == 'single') {
188
+                while ($user = Database::fetch_array($rs)) {
189
+                    $i++;
190
+                    if ($i<=10) {
191
+                        $person_name = api_get_person_name($user['firstname'], $user['lastname']);
192
+                        $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
193
+                    } else {
194
+                        $return .= '...<br />';
195
+                    }
196
+                }
197
+
198
+                $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
199
+            } else {
200
+                global $nosessionUsersList;
201
+                $return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
202
+                while ($user = Database :: fetch_array($rs)) {
203
+                    $person_name = api_get_person_name($user['firstname'], $user['lastname']);
204
+                    $return .= '<option value="'.$user['user_id'].'">'.$person_name.' ('.$user['username'].')</option>';
205
+                }
206
+                $return .= '</select>';
207
+                $xajax_response -> addAssign('ajax_list_users_multiple','innerHTML',api_utf8_encode($return));
208
+            }
209
+        }
210
+        return $xajax_response;
211 211
     }
212 212
 
213 213
     $xajax -> processRequests();
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 
344 344
         if ($use_extra_fields) {
345 345
             $final_result = array();
346
-           	if (count($extra_field_result)>1) {
347
-    	    for($i=0;$i<count($extra_field_result)-1;$i++) {
346
+                if (count($extra_field_result)>1) {
347
+            for($i=0;$i<count($extra_field_result)-1;$i++) {
348 348
                     if (is_array($extra_field_result[$i+1])) {
349 349
                         $final_result = array_intersect(
350 350
                             $extra_field_result[$i],
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
                     'un' => $user['username']
423 423
                 );
424 424
                 unset($users[$uid]);
425
-    	}
425
+        }
426 426
         }
427 427
         unset($users); //clean to free memory
428 428
 
@@ -467,13 +467,13 @@  discard block
 block discarded – undo
467 467
     }
468 468
 
469 469
     if ($add_type == 'multiple') {
470
-    	$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
471
-    	$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
470
+        $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
471
+        $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
472 472
     } else {
473
-    	$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
474
-    	$link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&amp;add='.Security::remove_XSS($_GET['add']).'&amp;add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
473
+        $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
474
+        $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&amp;add='.Security::remove_XSS($_GET['add']).'&amp;add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
475 475
     }
476
-    	$link_add_group = '<a href="usergroups.php">'.Display::return_icon('multiple.gif',get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups').'</a>';
476
+        $link_add_group = '<a href="usergroups.php">'.Display::return_icon('multiple.gif',get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups').'</a>';
477 477
     ?>
478 478
     <div class="actions">
479 479
     	<?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>&nbsp;|&nbsp;<?php echo $link_add_group; ?>
@@ -482,30 +482,30 @@  discard block
 block discarded – undo
482 482
     <?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
483 483
     <?php
484 484
     if ($add_type == 'multiple') {
485
-    	if (is_array($extra_field_list)) {
486
-    		if (is_array($new_field_list) && count($new_field_list)>0 ) {
487
-    			echo '<h3>'.get_lang('FilterUsers').'</h3>';
488
-    			foreach ($new_field_list as $new_field) {
489
-    				echo $new_field['name'];
490
-    				$varname = 'field_'.$new_field['variable'];
491
-    				echo '&nbsp;<select name="'.$varname.'">';
492
-    				echo '<option value="0">--'.get_lang('Select').'--</option>';
493
-    				foreach	($new_field['data'] as $option) {
494
-    					$checked='';
495
-    					if (isset($_POST[$varname])) {
496
-    						if ($_POST[$varname] == $option[1]) {
497
-    							$checked = 'selected="true"';
498
-    						}
499
-    					}
500
-    					echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
501
-    				}
502
-    				echo '</select>';
503
-    				echo '&nbsp;&nbsp;';
504
-    			}
505
-    			echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
506
-    			echo '<br /><br />';
507
-    		}
508
-    	}
485
+        if (is_array($extra_field_list)) {
486
+            if (is_array($new_field_list) && count($new_field_list)>0 ) {
487
+                echo '<h3>'.get_lang('FilterUsers').'</h3>';
488
+                foreach ($new_field_list as $new_field) {
489
+                    echo $new_field['name'];
490
+                    $varname = 'field_'.$new_field['variable'];
491
+                    echo '&nbsp;<select name="'.$varname.'">';
492
+                    echo '<option value="0">--'.get_lang('Select').'--</option>';
493
+                    foreach	($new_field['data'] as $option) {
494
+                        $checked='';
495
+                        if (isset($_POST[$varname])) {
496
+                            if ($_POST[$varname] == $option[1]) {
497
+                                $checked = 'selected="true"';
498
+                            }
499
+                        }
500
+                        echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
501
+                    }
502
+                    echo '</select>';
503
+                    echo '&nbsp;&nbsp;';
504
+                }
505
+                echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
506
+                echo '<br /><br />';
507
+            }
508
+        }
509 509
     }
510 510
     ?>
511 511
 
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 
515 515
     <?php
516 516
     if (!empty($errorMsg)) {
517
-    	Display::display_normal_message($errorMsg); //main API
517
+        Display::display_normal_message($errorMsg); //main API
518 518
     }
519 519
     ?>
520 520
     <div class="row">
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                 <div id="content_source">
536 536
                 <?php
537 537
                 if (!($add_type == 'multiple')) {
538
-                  ?>
538
+                    ?>
539 539
                   <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
540 540
                   <div id="ajax_list_users_single"></div>
541 541
                   <?php
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
                 <div id="ajax_list_users_multiple">
545 545
                 <select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" class="span5">
546 546
                   <?php
547
-                  foreach ($nosessionUsersList as $uid => $enreg) {
548
-                  ?>
547
+                    foreach ($nosessionUsersList as $uid => $enreg) {
548
+                    ?>
549 549
                       <option value="<?php echo $uid; ?>" <?php if(in_array($uid,$UserList)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['fn'], $enreg['ln']).' ('.$enreg['un'].')'; ?></option>
550 550
                   <?php
551
-                  }
552
-                  ?>
551
+                    }
552
+                    ?>
553 553
                 </select>
554 554
                 </div>
555 555
                     <input type="checkbox" onchange="checked_in_no_session(this.checked);" name="user_with_any_session" id="user_with_any_session_id">
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
                 <?php
558 558
                 }
559 559
                 unset($nosessionUsersList);
560
-               ?>
560
+                ?>
561 561
             </div>
562 562
         </div>
563 563
 
@@ -584,13 +584,13 @@  discard block
 block discarded – undo
584 584
             <br />
585 585
             <br />
586 586
     		<?php
587
-    		if (isset($_GET['add'])) {
588
-    			echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('FinishSessionCreation').'</button>';
587
+            if (isset($_GET['add'])) {
588
+                echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('FinishSessionCreation').'</button>';
589 589
             } else {
590 590
                 //@todo see that the call to "valide()" doesn't duplicate the onsubmit of the form (necessary to avoid delete on "enter" key pressed)
591
-    			echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToSession').'</button>';
591
+                echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToSession').'</button>';
592 592
             }
593
-    		?>
593
+            ?>
594 594
         </div>
595 595
         <div class="span5">
596 596
             <div class="multiple_select_header">
Please login to merge, or discard this patch.
main/inc/lib/fileManage.lib.php 1 patch
Indentation   +185 added lines, -186 removed lines patch added patch discarded remove patch
@@ -170,37 +170,37 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function my_rename($file_path, $new_file_name) {
172 172
 
173
-	$save_dir = getcwd();
174
-	$path = dirname($file_path);
175
-	$old_file_name = basename($file_path);
176
-	$new_file_name = api_replace_dangerous_char($new_file_name);
177
-
178
-	// If no extension, take the old one
179
-	if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) {
180
-		$new_file_name .= substr($old_file_name, $dotpos);
181
-	}
182
-
183
-	// Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
184
-	// This is useful for folder names, where otherwise '.' would be sticky
185
-
186
-	// Extension PHP is not allowed, change to PHPS
187
-	$new_file_name = php2phps($new_file_name);
188
-
189
-	if ($new_file_name == $old_file_name) {
190
-		return $old_file_name;
191
-	}
192
-
193
-	if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) {
194
-		return false;
195
-	}
196
-	// On a Windows server, it would be better not to do the above check
197
-	// because it succeeds for some new names resembling the old name.
198
-	// But on Unix/Linux the check must be done because rename overwrites.
199
-
200
-	chdir($path);
201
-	$res = rename($old_file_name, $new_file_name) ? $new_file_name : false;
202
-	chdir($save_dir);
203
-	return $res;
173
+    $save_dir = getcwd();
174
+    $path = dirname($file_path);
175
+    $old_file_name = basename($file_path);
176
+    $new_file_name = api_replace_dangerous_char($new_file_name);
177
+
178
+    // If no extension, take the old one
179
+    if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) {
180
+        $new_file_name .= substr($old_file_name, $dotpos);
181
+    }
182
+
183
+    // Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
184
+    // This is useful for folder names, where otherwise '.' would be sticky
185
+
186
+    // Extension PHP is not allowed, change to PHPS
187
+    $new_file_name = php2phps($new_file_name);
188
+
189
+    if ($new_file_name == $old_file_name) {
190
+        return $old_file_name;
191
+    }
192
+
193
+    if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) {
194
+        return false;
195
+    }
196
+    // On a Windows server, it would be better not to do the above check
197
+    // because it succeeds for some new names resembling the old name.
198
+    // But on Unix/Linux the check must be done because rename overwrites.
199
+
200
+    chdir($path);
201
+    $res = rename($old_file_name, $new_file_name) ? $new_file_name : false;
202
+    chdir($save_dir);
203
+    return $res;
204 204
 }
205 205
 
206 206
 /**
@@ -217,38 +217,38 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function move($source, $target, $forceMove = false, $moveContent = false)
219 219
 {
220
-	if (check_name_exist($source)) {
221
-		$file_name = basename($source);
220
+    if (check_name_exist($source)) {
221
+        $file_name = basename($source);
222 222
         $isWindowsOS = api_is_windows_os();
223 223
         $canExec = function_exists('exec');
224 224
 
225
-		/* File case */
226
-		if (is_file($source)) {
227
-			if ($forceMove && !$isWindowsOS && $canExec) {
228
-				exec('mv ' . $source . ' ' . $target . '/' . $file_name);
229
-			} else {
230
-				copy($source, $target . '/' . $file_name);
231
-				unlink($source);
232
-			}
233
-			return true;
234
-		} elseif (is_dir($source)) {
235
-			/* Directory */
236
-			if ($forceMove && !$isWindowsOS && $canExec) {
237
-				if ($moveContent) {
238
-					$base = basename($source);
239
-					exec('mv '.$source.'/* '.$target.$base.'/');
240
-					exec('rm -rf '.$source);
241
-				} else {
242
-					exec('mv $source $target');
243
-				}
244
-			} else {
245
-				copyDirTo($source, $target);
246
-			}
247
-			return true;
248
-		}
249
-	} else {
250
-		return false;
251
-	}
225
+        /* File case */
226
+        if (is_file($source)) {
227
+            if ($forceMove && !$isWindowsOS && $canExec) {
228
+                exec('mv ' . $source . ' ' . $target . '/' . $file_name);
229
+            } else {
230
+                copy($source, $target . '/' . $file_name);
231
+                unlink($source);
232
+            }
233
+            return true;
234
+        } elseif (is_dir($source)) {
235
+            /* Directory */
236
+            if ($forceMove && !$isWindowsOS && $canExec) {
237
+                if ($moveContent) {
238
+                    $base = basename($source);
239
+                    exec('mv '.$source.'/* '.$target.$base.'/');
240
+                    exec('rm -rf '.$source);
241
+                } else {
242
+                    exec('mv $source $target');
243
+                }
244
+            } else {
245
+                copyDirTo($source, $target);
246
+            }
247
+            return true;
248
+        }
249
+    } else {
250
+        return false;
251
+    }
252 252
 }
253 253
 
254 254
 /**
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
  * @param 	string	$filename 		filename
280 280
  */
281 281
 function getextension($filename) {
282
-	$bouts = explode('.', $filename);
283
-	return array(array_pop($bouts), implode('.', $bouts));
282
+    $bouts = explode('.', $filename);
283
+    return array(array_pop($bouts), implode('.', $bouts));
284 284
 }
285 285
 
286 286
 /**
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
  * @param 	boolean $recursive if true , include subdir in total
292 292
  */
293 293
 function dirsize($root, $recursive = true) {
294
-	$dir = @opendir($root);
295
-	$size = 0;
296
-	while ($file = @readdir($dir)) {
297
-		if (!in_array($file, array('.', '..'))) {
298
-			if (is_dir($root.'/'.$file)) {
299
-				$size += $recursive ? dirsize($root.'/'.$file) : 0;
300
-			} else {
301
-				$size += @filesize($root.'/'.$file);
302
-			}
303
-		}
304
-	}
305
-	@closedir($dir);
306
-	return $size;
294
+    $dir = @opendir($root);
295
+    $size = 0;
296
+    while ($file = @readdir($dir)) {
297
+        if (!in_array($file, array('.', '..'))) {
298
+            if (is_dir($root.'/'.$file)) {
299
+                $size += $recursive ? dirsize($root.'/'.$file) : 0;
300
+            } else {
301
+                $size += @filesize($root.'/'.$file);
302
+            }
303
+        }
304
+    }
305
+    @closedir($dir);
306
+    return $size;
307 307
 }
308 308
 
309 309
 /*	CLASS FileManager */
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 */
323 323
 class FileManager
324 324
 {
325
-	/**
325
+    /**
326 326
 		Returns a list of all directories, except the base dir,
327 327
 		of the current course. This function uses recursion.
328 328
 
@@ -330,131 +330,130 @@  discard block
 block discarded – undo
330 330
 
331 331
 		@author Roan Embrechts
332 332
 		@version 1.0.1
333
-	*/
334
-	function list_all_directories($path)
333
+     */
334
+    function list_all_directories($path)
335 335
     {
336
-		$result_array = array();
337
-		if (is_dir($path)) {
338
-			$save_dir = getcwd();
339
-			chdir($path);
340
-			$handle = opendir($path);
341
-			while ($element = readdir($handle)) {
342
-				if ($element == '.' || $element == '..') continue;
336
+        $result_array = array();
337
+        if (is_dir($path)) {
338
+            $save_dir = getcwd();
339
+            chdir($path);
340
+            $handle = opendir($path);
341
+            while ($element = readdir($handle)) {
342
+                if ($element == '.' || $element == '..') continue;
343 343
                 // Skip the current and parent directories
344
-				if (is_dir($element)) {
345
-					$dir_array[] = $path.'/'.$element;
346
-				}
347
-			}
348
-			closedir($handle);
349
-			// Recursive operation if subdirectories exist
350
-			$dir_number = sizeof($dir_array);
351
-			if ($dir_number > 0) {
352
-				for ($i = 0 ; $i < $dir_number ; $i++) {
353
-					$sub_dir_array = FileManager::list_all_directories($dir_array[$i]); // Function recursivity
354
-					if (is_array($dir_array) && is_array($sub_dir_array)) {
355
-						$dir_array  =  array_merge($dir_array, $sub_dir_array); // Data merge
356
-					}
357
-				}
358
-			}
359
-			$result_array  =  $dir_array;
360
-			chdir($save_dir) ;
361
-		}
362
-		return $result_array ;
363
-	}
364
-
365
-	/**
344
+                if (is_dir($element)) {
345
+                    $dir_array[] = $path.'/'.$element;
346
+                }
347
+            }
348
+            closedir($handle);
349
+            // Recursive operation if subdirectories exist
350
+            $dir_number = sizeof($dir_array);
351
+            if ($dir_number > 0) {
352
+                for ($i = 0 ; $i < $dir_number ; $i++) {
353
+                    $sub_dir_array = FileManager::list_all_directories($dir_array[$i]); // Function recursivity
354
+                    if (is_array($dir_array) && is_array($sub_dir_array)) {
355
+                        $dir_array  =  array_merge($dir_array, $sub_dir_array); // Data merge
356
+                    }
357
+                }
358
+            }
359
+            $result_array  =  $dir_array;
360
+            chdir($save_dir) ;
361
+        }
362
+        return $result_array ;
363
+    }
364
+
365
+    /**
366 366
 		This function receives a list of directories.
367 367
 		It returns a list of all files in these directories
368 368
 
369 369
 		@author Roan Embrechts
370 370
 		@version 1.0
371
-	*/
372
-	function list_all_files($dir_array)
371
+     */
372
+    function list_all_files($dir_array)
373 373
     {
374
-		$element_array = array();
375
-		if (is_dir($dir_array)) {
376
-
377
-			$save_dir = getcwd();
378
-			foreach ($dir_array as $directory) {
379
-				chdir($directory);
380
-				$handle = opendir($directory);
381
-			   	while ($element = readdir($handle)) {
382
-					if ($element == '.' || $element == '..' || $element == '.htaccess') continue;
374
+        $element_array = array();
375
+        if (is_dir($dir_array)) {
376
+
377
+            $save_dir = getcwd();
378
+            foreach ($dir_array as $directory) {
379
+                chdir($directory);
380
+                $handle = opendir($directory);
381
+                    while ($element = readdir($handle)) {
382
+                    if ($element == '.' || $element == '..' || $element == '.htaccess') continue;
383 383
                     // Skip the current and parent directories
384
-					if (!is_dir($element)) {
385
-						$element_array[] = $directory.'/'.$element;
386
-					}
387
-				}
388
-				closedir($handle);
389
-				chdir('..');
390
-				chdir($save_dir);
391
-			}
392
-		}
393
-
394
-		return $element_array;
395
-	}
396
-
397
-	/**
384
+                    if (!is_dir($element)) {
385
+                        $element_array[] = $directory.'/'.$element;
386
+                    }
387
+                }
388
+                closedir($handle);
389
+                chdir('..');
390
+                chdir($save_dir);
391
+            }
392
+        }
393
+
394
+        return $element_array;
395
+    }
396
+
397
+    /**
398 398
 		Loads contents of file $filename into memory and returns them as a string.
399 399
 		Function kept for compatibility with older PHP versions.
400 400
 		Function is binary safe (is needed on Windows)
401
-	*/
402
-	function compat_load_file($file_name)
401
+     */
402
+    function compat_load_file($file_name)
403 403
     {
404
-		$buffer = '';
405
-		if (file_exists($file_name)) {
406
-			$fp = fopen($file_name, 'rb');
407
-			$buffer = fread ($fp, filesize($file_name));
408
-			fclose ($fp);
409
-		}
410
-		return $buffer;
411
-	}
412
-
413
-	/**
414
-	 * Adds file/folder to document table in database
415
-	 * improvement from set_default_settings (see below):
416
-	 * take all info from function parameters
417
-	 * no global variables needed
418
-	 *
419
-	 * NOTE $glued_table should already have backticks around it
420
-	 * (get it from the database library, and it is done automatically)
421
-	 *
422
-	 * @param	path, filename, filetype,
423
-				$glued_table, default_visibility
404
+        $buffer = '';
405
+        if (file_exists($file_name)) {
406
+            $fp = fopen($file_name, 'rb');
407
+            $buffer = fread ($fp, filesize($file_name));
408
+            fclose ($fp);
409
+        }
410
+        return $buffer;
411
+    }
424 412
 
425
-	 * action:	Adds an entry to the document table with the default settings.
426
-	 * @author	Olivier Cauberghe <[email protected]>
427
-	 * @author	Roan Embrechts
428
-	 * @version 1.2
429
-	 */
430
-	function set_default_settings($upload_path, $filename, $filetype = 'file', $glued_table, $default_visibility = 'v')
413
+    /**
414
+     * Adds file/folder to document table in database
415
+     * improvement from set_default_settings (see below):
416
+     * take all info from function parameters
417
+     * no global variables needed
418
+     *
419
+     * NOTE $glued_table should already have backticks around it
420
+     * (get it from the database library, and it is done automatically)
421
+     *
422
+     * @param	path, filename, filetype,
423
+				$glued_table, default_visibility
424
+     * action:	Adds an entry to the document table with the default settings.
425
+     * @author	Olivier Cauberghe <[email protected]>
426
+     * @author	Roan Embrechts
427
+     * @version 1.2
428
+     */
429
+    function set_default_settings($upload_path, $filename, $filetype = 'file', $glued_table, $default_visibility = 'v')
431 430
     {
432
-		if (!$default_visibility) $default_visibility = 'v';
433
-
434
-		// Make sure path is not wrongly formed
435
-		$upload_path = !empty($upload_path) ? "/$upload_path" : '';
436
-
437
-		$endchar = substr($filename, strlen($filename) - 1, 1);
438
-		if ($endchar == "\\" || $endchar == '/') {
439
-			$filename = substr($filename, 0, strlen($filename) - 1);
440
-		}
441
-
442
-		$full_file_name = $upload_path.'/'.$filename;
443
-		$full_file_name = str_replace("//", '/', $full_file_name);
444
-
445
-		$sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'";
446
-		$sql_result = Database::query($sql_query);
447
-		$result = Database::fetch_array($sql_result);
448
-		// Determine which query to execute
449
-		if ($result['number_existing'] > 0) {
450
-			// Entry exists, update
451
-			$query = "UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype'
431
+        if (!$default_visibility) $default_visibility = 'v';
432
+
433
+        // Make sure path is not wrongly formed
434
+        $upload_path = !empty($upload_path) ? "/$upload_path" : '';
435
+
436
+        $endchar = substr($filename, strlen($filename) - 1, 1);
437
+        if ($endchar == "\\" || $endchar == '/') {
438
+            $filename = substr($filename, 0, strlen($filename) - 1);
439
+        }
440
+
441
+        $full_file_name = $upload_path.'/'.$filename;
442
+        $full_file_name = str_replace("//", '/', $full_file_name);
443
+
444
+        $sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'";
445
+        $sql_result = Database::query($sql_query);
446
+        $result = Database::fetch_array($sql_result);
447
+        // Determine which query to execute
448
+        if ($result['number_existing'] > 0) {
449
+            // Entry exists, update
450
+            $query = "UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype'
452 451
 			          WHERE path='$full_file_name'";
453
-		} else {
454
-			// No entry exists, create new one
455
-			$query = "INSERT INTO $glued_table (path,visibility,filetype)
452
+        } else {
453
+            // No entry exists, create new one
454
+            $query = "INSERT INTO $glued_table (path,visibility,filetype)
456 455
 			          VALUES ('$full_file_name','$default_visibility','$filetype')";
457
-		}
458
-		Database::query($query);
459
-	}
456
+        }
457
+        Database::query($query);
458
+    }
460 459
 }
Please login to merge, or discard this patch.
main/inc/lib/formvalidator/Element/SelectLanguage.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
main/document/record_audio.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 
19 19
 $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
20 20
 if (empty($document_data)) {
21
-	if (api_is_in_group()) {
22
-		$group_properties   = GroupManager::get_group_properties(api_get_group_id());
23
-		$document_id        = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
24
-		$document_data      = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
25
-	}
21
+    if (api_is_in_group()) {
22
+        $group_properties   = GroupManager::get_group_properties(api_get_group_id());
23
+        $document_id        = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
24
+        $document_data      = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
25
+    }
26 26
 }
27 27
 
28 28
 $document_id = $document_data['id'];
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 //make some vars
32 32
 $wamidir=$dir;
33 33
 if($wamidir=="/"){
34
-	$wamidir="";
34
+    $wamidir="";
35 35
 }
36 36
 $wamiurlplay = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$wamidir."/";
37 37
 $groupId = api_get_group_id();
@@ -41,48 +41,48 @@  discard block
 block discarded – undo
41 41
 // Please, do not modify this dirname formatting
42 42
 
43 43
 if (strstr($dir, '..')) {
44
-	$dir = '/';
44
+    $dir = '/';
45 45
 }
46 46
 
47 47
 if ($dir[0] == '.') {
48
-	$dir = substr($dir, 1);
48
+    $dir = substr($dir, 1);
49 49
 }
50 50
 
51 51
 if ($dir[0] != '/') {
52
-	$dir = '/'.$dir;
52
+    $dir = '/'.$dir;
53 53
 }
54 54
 
55 55
 if ($dir[strlen($dir) - 1] != '/') {
56
-	$dir .= '/';
56
+    $dir .= '/';
57 57
 }
58 58
 
59 59
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
60 60
 
61 61
 if (!is_dir($filepath)) {
62
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
63
-	$dir = '/';
62
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
63
+    $dir = '/';
64 64
 }
65 65
 
66 66
 //groups //TODO: clean
67 67
 if (!empty($groupId)) {
68
-	$interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
69
-	$noPHP_SELF = true;
70
-	$group = GroupManager :: get_group_properties($groupId);
71
-	$path = explode('/', $dir);
72
-	if ('/'.$path[1] != $group['directory']) {
73
-		api_not_allowed(true);
74
-	}
68
+    $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
69
+    $noPHP_SELF = true;
70
+    $group = GroupManager :: get_group_properties($groupId);
71
+    $path = explode('/', $dir);
72
+    if ('/'.$path[1] != $group['directory']) {
73
+        api_not_allowed(true);
74
+    }
75 75
 }
76 76
 
77 77
 $interbreadcrumb[] = array("url" => "./document.php?id=".$document_id.'&'.api_get_cidreq(), "name" => get_lang('Documents'));
78 78
 
79 79
 if (!$is_allowed_in_course) {
80
-	api_not_allowed(true);
80
+    api_not_allowed(true);
81 81
 }
82 82
 
83 83
 if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
84
-	DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) {
85
-	api_not_allowed(true);
84
+    DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) {
85
+    api_not_allowed(true);
86 86
 }
87 87
 
88 88
 /*	Header */
@@ -90,26 +90,26 @@  discard block
 block discarded – undo
90 90
 
91 91
 $display_dir = $dir;
92 92
 if (isset ($group)) {
93
-	$display_dir = explode('/', $dir);
94
-	unset ($display_dir[0]);
95
-	unset ($display_dir[1]);
96
-	$display_dir = implode('/', $display_dir);
93
+    $display_dir = explode('/', $dir);
94
+    unset ($display_dir[0]);
95
+    unset ($display_dir[1]);
96
+    $display_dir = implode('/', $display_dir);
97 97
 }
98 98
 
99 99
 // Interbreadcrumb for the current directory root path
100 100
 $counter = 0;
101 101
 if (isset($document_data['parents'])) {
102
-	foreach($document_data['parents'] as $document_sub_data) {
103
-		//fixing double group folder in breadcrumb
104
-		if (api_get_group_id()) {
105
-			if ($counter == 0) {
106
-				$counter++;
107
-				continue;
108
-			}
109
-		}
110
-		$interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
111
-		$counter++;
112
-	}
102
+    foreach($document_data['parents'] as $document_sub_data) {
103
+        //fixing double group folder in breadcrumb
104
+        if (api_get_group_id()) {
105
+            if ($counter == 0) {
106
+                $counter++;
107
+                continue;
108
+            }
109
+        }
110
+        $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
111
+        $counter++;
112
+    }
113 113
 }
114 114
 
115 115
 //make some vars
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 $htmlHeadXtra[] = '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'swfobject/swfobject.js"></script>';
122 122
 
123 123
 $actions = Display::toolbarButton(
124
-	get_lang('BackTo') . ' ' . get_lang('DocumentsOverview'),
125
-	'document.php?' . api_get_cidreq() . "&id=$document_id",
126
-	'arrow-left',
127
-	'default',
128
-	[],
129
-	false
124
+    get_lang('BackTo') . ' ' . get_lang('DocumentsOverview'),
125
+    'document.php?' . api_get_cidreq() . "&id=$document_id",
126
+    'arrow-left',
127
+    'default',
128
+    [],
129
+    false
130 130
 );
131 131
 
132 132
 $template = new Template($nameTools);
Please login to merge, or discard this patch.
main/document/show_content.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -91,11 +91,11 @@
 block discarded – undo
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().'&amp;rand='.mt_rand(1, 1000).'"></iframe>';
Please login to merge, or discard this patch.
main/admin/configure_homepage.php 1 patch
Indentation   +849 added lines, -849 removed lines patch added patch discarded remove patch
@@ -17,35 +17,35 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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').' &quot;'.$enreg.'&quot;';
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').' &quot;'.$enreg.'&quot;';
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.'" />&nbsp;'.$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.'" />&nbsp;'.$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.'" />&nbsp;'.$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.'" />&nbsp;'.$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
 block discarded – undo
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&amp;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&amp;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
 block discarded – undo
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>
Please login to merge, or discard this patch.
main/admin/ldap_synchro.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -44,121 +44,121 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
main/inc/lib/formvalidator/Element/receivers.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -10,66 +10,66 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
src/Chamilo/CoreBundle/Menu/NavBuilder.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@
 block discarded – undo
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',
Please login to merge, or discard this patch.