Completed
Push — 1.10.x ( 67073c...77bf11 )
by Angel Fernando Quiroz
81:48 queued 37:47
created
main/admin/specific_fields_add.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 $tool_name = get_lang('AddSpecificSearchField');
28 28
 
29 29
 if (isset($_GET['action']) && $_GET['action'] === 'edit') {
30
-  $tool_name = get_lang('EditSpecificSearchField');
30
+    $tool_name = get_lang('EditSpecificSearchField');
31 31
 }
32 32
 // Create the form
33 33
 $form = new FormValidator('specific_fields_add');
Please login to merge, or discard this patch.
main/exercice/TestCategory.php 1 patch
Indentation   +504 added lines, -504 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
     public $name;
14 14
     public $description;
15 15
 
16
-	/**
17
-	 * Constructor of the class Category
18
-	 * If you give an in_id and no in_name, you get info concerning the category of id=in_id
19
-	 * otherwise, you've got an category objet avec your in_id, in_name, in_descr
20
-	 *
16
+    /**
17
+     * Constructor of the class Category
18
+     * If you give an in_id and no in_name, you get info concerning the category of id=in_id
19
+     * otherwise, you've got an category objet avec your in_id, in_name, in_descr
20
+     *
21 21
      * @param int    $id
22 22
      * @param string $name
23 23
      * @param string $description
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
         }
62 62
     }
63 63
 
64
-	/**
64
+    /**
65 65
      * add TestCategory in the database if name doesn't already exists
66
-	 */
66
+     */
67 67
     public function addCategoryInBDD()
68 68
     {
69 69
         $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 
109 109
             return false;
110 110
         }
111
-	}
111
+    }
112 112
 
113
-	/**
113
+    /**
114 114
      * Removes the category from the database
115 115
      * if there were question in this category, the link between question and category is removed
116
-	 */
116
+     */
117 117
     public function removeCategory()
118 118
     {
119 119
         $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 
144 144
             return true;
145 145
         }
146
-	}
146
+    }
147 147
 
148
-	/**
148
+    /**
149 149
      * Modify category name or description of category with id=in_id
150
-	 */
150
+     */
151 151
     public function modifyCategory()
152 152
     {
153 153
         $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
@@ -175,40 +175,40 @@  discard block
 block discarded – undo
175 175
 
176 176
             return true;
177 177
         }
178
-	}
178
+    }
179 179
 
180
-	/**
180
+    /**
181 181
      * Gets the number of question of category id=in_id
182
-	 */
182
+     */
183 183
     public function getCategoryQuestionsNumber()
184 184
     {
185
-		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
186
-		$in_id = intval($this->id);
187
-		$sql = "SELECT count(*) AS nb
185
+        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
186
+        $in_id = intval($this->id);
187
+        $sql = "SELECT count(*) AS nb
188 188
 		        FROM $table
189 189
 		        WHERE category_id=$in_id AND c_id=".api_get_course_int_id();
190
-		$res = Database::query($sql);
191
-		$row = Database::fetch_array($res);
190
+        $res = Database::query($sql);
191
+        $row = Database::fetch_array($res);
192 192
 
193
-		return $row['nb'];
194
-	}
193
+        return $row['nb'];
194
+    }
195 195
 
196 196
     /**
197 197
      * @param string $in_color
198 198
      */
199 199
     public function display($in_color="#E0EBF5")
200 200
     {
201
-		echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>";
202
-		print_r($this);
203
-		echo "</textarea>";
204
-	}
201
+        echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>";
202
+        print_r($this);
203
+        echo "</textarea>";
204
+    }
205 205
 
206
-	/**
206
+    /**
207 207
      * Return an array of all Category objects in the database
208
-	 * If in_field=="" Return an array of all category objects in the database
209
-	 * Otherwise, return an array of all in_field value
210
-	 * in the database (in_field = id or name or description)
211
-	 */
208
+     * If in_field=="" Return an array of all category objects in the database
209
+     * Otherwise, return an array of all in_field value
210
+     * in the database (in_field = id or name or description)
211
+     */
212 212
     public static function getCategoryListInfo($in_field = "", $courseId = "")
213 213
     {
214 214
         if (empty($courseId) || $courseId=="") {
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
             }
240 240
         }
241 241
 
242
-		return $tabres;
243
-	}
242
+        return $tabres;
243
+    }
244 244
 
245 245
     /**
246 246
      * Return the TestCategory id for question with question_id = $questionId
@@ -251,246 +251,246 @@  discard block
 block discarded – undo
251 251
      *
252 252
      * @return int
253 253
      */
254
-	public static function getCategoryForQuestion($questionId, $courseId ="")
254
+    public static function getCategoryForQuestion($questionId, $courseId ="")
255 255
     {
256
-		$result = 0;
256
+        $result = 0;
257 257
         if (empty($courseId) || $courseId == "") {
258 258
             $courseId = api_get_course_int_id();
259 259
         }
260
-		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
260
+        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
261 261
         $questionId = intval($questionId);
262
-		$sql = "SELECT category_id
262
+        $sql = "SELECT category_id
263 263
 		        FROM $table
264 264
 		        WHERE question_id = $questionId AND c_id = $courseId";
265
-		$res = Database::query($sql);
266
-		if (Database::num_rows($res) > 0) {
265
+        $res = Database::query($sql);
266
+        if (Database::num_rows($res) > 0) {
267 267
             $data = Database::fetch_array($res);
268
-			$result = $data['category_id'];
269
-		}
268
+            $result = $data['category_id'];
269
+        }
270 270
 
271
-		return $result;
272
-	}
271
+        return $result;
272
+    }
273 273
 
274
-	/**
275
-	 * true if question id has a category
276
-	 */
277
-	public static function isQuestionHasCategory($questionId)
274
+    /**
275
+     * true if question id has a category
276
+     */
277
+    public static function isQuestionHasCategory($questionId)
278 278
     {
279
-		if (TestCategory::getCategoryForQuestion($questionId) > 0) {
280
-			return true;
281
-		}
282
-		return false;
283
-	}
279
+        if (TestCategory::getCategoryForQuestion($questionId) > 0) {
280
+            return true;
281
+        }
282
+        return false;
283
+    }
284 284
 
285
-	/**
285
+    /**
286 286
 	 Return the category name for question with question_id = $questionId
287 287
 	 In this version, a question has only 1 category.
288 288
 	 Return the category id, "" if none
289
-	 */
289
+     */
290 290
     public static function getCategoryNameForQuestion(
291 291
         $questionId,
292 292
         $courseId = ""
293 293
     ) {
294
-		if (empty($courseId) || $courseId=="") {
295
-			$courseId = api_get_course_int_id();
296
-		}
297
-		$catid = TestCategory::getCategoryForQuestion($questionId, $courseId);
298
-		$result = "";	// result
299
-		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
300
-		$catid = intval($catid);
301
-		$sql = "SELECT title FROM $table
294
+        if (empty($courseId) || $courseId=="") {
295
+            $courseId = api_get_course_int_id();
296
+        }
297
+        $catid = TestCategory::getCategoryForQuestion($questionId, $courseId);
298
+        $result = "";	// result
299
+        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
300
+        $catid = intval($catid);
301
+        $sql = "SELECT title FROM $table
302 302
 		        WHERE id = $catid  AND c_id = $courseId";
303
-		$res = Database::query($sql);
304
-		$data = Database::fetch_array($res);
305
-		if (Database::num_rows($res) > 0) {
306
-			$result = $data['title'];
307
-		}
308
-
309
-		return $result;
310
-	}
311
-
312
-	/**
313
-	 * Return the list of differents categories ID for a test in the current course
314
-	 * input : test_id
315
-	 * return : array of category id (integer)
316
-	 * hubert.borderiou 07-04-2011
317
-	 * @param int $exerciseId
318
-	 */
319
-	public static function getListOfCategoriesIDForTest($exerciseId)
303
+        $res = Database::query($sql);
304
+        $data = Database::fetch_array($res);
305
+        if (Database::num_rows($res) > 0) {
306
+            $result = $data['title'];
307
+        }
308
+
309
+        return $result;
310
+    }
311
+
312
+    /**
313
+     * Return the list of differents categories ID for a test in the current course
314
+     * input : test_id
315
+     * return : array of category id (integer)
316
+     * hubert.borderiou 07-04-2011
317
+     * @param int $exerciseId
318
+     */
319
+    public static function getListOfCategoriesIDForTest($exerciseId)
320 320
     {
321
-		// parcourir les questions d'un test, recup les categories uniques dans un tableau
322
-		$exercise = new Exercise();
323
-		$exercise->read($exerciseId, false);
324
-		$categoriesInExercise = $exercise->getQuestionWithCategories();
325
-		// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
326
-		$categories = array();
321
+        // parcourir les questions d'un test, recup les categories uniques dans un tableau
322
+        $exercise = new Exercise();
323
+        $exercise->read($exerciseId, false);
324
+        $categoriesInExercise = $exercise->getQuestionWithCategories();
325
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
326
+        $categories = array();
327 327
         if (!empty($categoriesInExercise)) {
328
-			foreach ($categoriesInExercise as $category) {
329
-				//$category['id'] = $category['iid'];
330
-				$categories[$category['id']] = $category;
331
-			}
332
-		}
333
-
334
-		return $categories;
335
-	}
336
-
337
-	/**
338
-	 * @param Exercise $exercise_obj
339
-	 * @return array
340
-	 */
341
-	public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj)
342
-	{
343
-		// parcourir les questions d'un test, recup les categories uniques dans un tableau
344
-		$categories_in_exercise = array();
345
-		// $question_list = $exercise_obj->getQuestionList();
346
-		$question_list = $exercise_obj->getQuestionOrderedListByName();
347
-
348
-		// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
349
-		foreach ($question_list as $questionInfo) {
350
-			$question_id = $questionInfo['question_id'];
351
-			$category_list = self::getCategoryForQuestion($question_id);
352
-			if (is_numeric($category_list)) {
353
-				$category_list = array($category_list);
354
-			}
355
-
356
-			if (!empty($category_list)) {
357
-				$categories_in_exercise = array_merge($categories_in_exercise, $category_list);
358
-			}
359
-		}
360
-		if (!empty($categories_in_exercise)) {
361
-			$categories_in_exercise = array_unique(array_filter($categories_in_exercise));
362
-		}
363
-		return $categories_in_exercise;
364
-	}
365
-
366
-	/**
367
-	 * Return the list of differents categories NAME for a test
368
-	 * @param int exercise id
369
-	 * @param bool
370
-	 * @return array of string
371
-	 *
328
+            foreach ($categoriesInExercise as $category) {
329
+                //$category['id'] = $category['iid'];
330
+                $categories[$category['id']] = $category;
331
+            }
332
+        }
333
+
334
+        return $categories;
335
+    }
336
+
337
+    /**
338
+     * @param Exercise $exercise_obj
339
+     * @return array
340
+     */
341
+    public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj)
342
+    {
343
+        // parcourir les questions d'un test, recup les categories uniques dans un tableau
344
+        $categories_in_exercise = array();
345
+        // $question_list = $exercise_obj->getQuestionList();
346
+        $question_list = $exercise_obj->getQuestionOrderedListByName();
347
+
348
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
349
+        foreach ($question_list as $questionInfo) {
350
+            $question_id = $questionInfo['question_id'];
351
+            $category_list = self::getCategoryForQuestion($question_id);
352
+            if (is_numeric($category_list)) {
353
+                $category_list = array($category_list);
354
+            }
355
+
356
+            if (!empty($category_list)) {
357
+                $categories_in_exercise = array_merge($categories_in_exercise, $category_list);
358
+            }
359
+        }
360
+        if (!empty($categories_in_exercise)) {
361
+            $categories_in_exercise = array_unique(array_filter($categories_in_exercise));
362
+        }
363
+        return $categories_in_exercise;
364
+    }
365
+
366
+    /**
367
+     * Return the list of differents categories NAME for a test
368
+     * @param int exercise id
369
+     * @param bool
370
+     * @return array of string
371
+     *
372 372
      * @author function rewrote by jmontoya
373
-	 */
374
-	public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true)
373
+     */
374
+    public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true)
375 375
     {
376
-		$result = array();
377
-		$categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category);
376
+        $result = array();
377
+        $categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category);
378 378
 
379
-		foreach ($categories as $catInfo) {
380
-			$categoryId = $catInfo['id'];
381
-			if (!empty($categoryId)) {
382
-				$result[$categoryId] = array(
379
+        foreach ($categories as $catInfo) {
380
+            $categoryId = $catInfo['id'];
381
+            if (!empty($categoryId)) {
382
+                $result[$categoryId] = array(
383 383
                     'title' => $catInfo['title'],
384 384
                     //'parent_id' =>  $catInfo['parent_id'],
385
-					'parent_id' => '',
385
+                    'parent_id' => '',
386 386
                     'c_id' => $catInfo['c_id']
387 387
                 );
388
-		}
389
-		}
390
-
391
-		return $result;
392
-	}
393
-
394
-	/**
395
-	 * @param Exercise $exercise_obj
396
-	 * @return array
397
-	 */
398
-	public static function getListOfCategoriesForTest(Exercise $exercise_obj)
399
-	{
400
-		$result = array();
401
-		$categories = self::getListOfCategoriesIDForTestObject($exercise_obj);
402
-		foreach ($categories as $cat_id) {
403
-			$cat = new TestCategory($cat_id);
404
-			$cat = (array)$cat;
405
-			$cat['iid'] = $cat['id'];
406
-			$cat['title'] = $cat['name'];
407
-			$result[$cat['id']] = $cat;
408
-		}
409
-		return $result;
410
-	}
411
-
412
-	/**
413
-	 * return the number of differents categories for a test
414
-	 * input : test_id
415
-	 * return : integer
416
-	 * hubert.borderiou 07-04-2011
417
-	 */
418
-	public static function getNumberOfCategoriesForTest($id)
388
+        }
389
+        }
390
+
391
+        return $result;
392
+    }
393
+
394
+    /**
395
+     * @param Exercise $exercise_obj
396
+     * @return array
397
+     */
398
+    public static function getListOfCategoriesForTest(Exercise $exercise_obj)
399
+    {
400
+        $result = array();
401
+        $categories = self::getListOfCategoriesIDForTestObject($exercise_obj);
402
+        foreach ($categories as $cat_id) {
403
+            $cat = new TestCategory($cat_id);
404
+            $cat = (array)$cat;
405
+            $cat['iid'] = $cat['id'];
406
+            $cat['title'] = $cat['name'];
407
+            $result[$cat['id']] = $cat;
408
+        }
409
+        return $result;
410
+    }
411
+
412
+    /**
413
+     * return the number of differents categories for a test
414
+     * input : test_id
415
+     * return : integer
416
+     * hubert.borderiou 07-04-2011
417
+     */
418
+    public static function getNumberOfCategoriesForTest($id)
419 419
     {
420
-		return count(TestCategory::getListOfCategoriesIDForTest($id));
421
-	}
420
+        return count(TestCategory::getListOfCategoriesIDForTest($id));
421
+    }
422 422
 
423
-	/**
424
-	 * return the number of question of a category id in a test
425
-	 * @param int $exerciseId
423
+    /**
424
+     * return the number of question of a category id in a test
425
+     * @param int $exerciseId
426 426
      * @param int $categoryId
427 427
      *
428
-	 * @return integer
428
+     * @return integer
429 429
      *
430
-	 * @author hubert.borderiou 07-04-2011
431
-	 */
432
-	public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId)
430
+     * @author hubert.borderiou 07-04-2011
431
+     */
432
+    public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId)
433 433
     {
434
-		$nbCatResult = 0;
435
-		$quiz = new Exercise();
436
-		$quiz->read($exerciseId);
437
-		$tabQuestionList = $quiz->selectQuestionList();
438
-		// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ?
439
-		for ($i=1; $i <= count($tabQuestionList); $i++) {
440
-			if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) {
441
-				$nbCatResult++;
442
-			}
443
-		}
444
-
445
-		return $nbCatResult;
446
-	}
447
-
448
-	/**
449
-	 * return the number of question for a test using random by category
450
-	 * input  : test_id, number of random question (min 1)
451
-	 * hubert.borderiou 07-04-2011
452
-	 * question without categories are not counted
453
-	 */
454
-	public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom)
434
+        $nbCatResult = 0;
435
+        $quiz = new Exercise();
436
+        $quiz->read($exerciseId);
437
+        $tabQuestionList = $quiz->selectQuestionList();
438
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ?
439
+        for ($i=1; $i <= count($tabQuestionList); $i++) {
440
+            if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) {
441
+                $nbCatResult++;
442
+            }
443
+        }
444
+
445
+        return $nbCatResult;
446
+    }
447
+
448
+    /**
449
+     * return the number of question for a test using random by category
450
+     * input  : test_id, number of random question (min 1)
451
+     * hubert.borderiou 07-04-2011
452
+     * question without categories are not counted
453
+     */
454
+    public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom)
455 455
     {
456
-		$nbquestionresult = 0;
457
-		$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
458
-		for ($i=0; $i < count($tabcatid); $i++) {
459
-			if ($tabcatid[$i] > 0 && $tabcatid[$i] > 0) {	// 0 = no category for this questio
460
-				$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]);
461
-				if ($nbQuestionInThisCat > $in_nbrandom) {
462
-					$nbquestionresult += $in_nbrandom;
463
-				}
464
-				else {
465
-					$nbquestionresult += $nbQuestionInThisCat;
466
-				}
467
-			}
468
-		}
469
-
470
-		return $nbquestionresult;
471
-	}
472
-
473
-	/**
474
-	 * Return an array (id=>name)
475
-	 * tabresult[0] = get_lang('NoCategory');
456
+        $nbquestionresult = 0;
457
+        $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
458
+        for ($i=0; $i < count($tabcatid); $i++) {
459
+            if ($tabcatid[$i] > 0 && $tabcatid[$i] > 0) {	// 0 = no category for this questio
460
+                $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]);
461
+                if ($nbQuestionInThisCat > $in_nbrandom) {
462
+                    $nbquestionresult += $in_nbrandom;
463
+                }
464
+                else {
465
+                    $nbquestionresult += $nbQuestionInThisCat;
466
+                }
467
+            }
468
+        }
469
+
470
+        return $nbquestionresult;
471
+    }
472
+
473
+    /**
474
+     * Return an array (id=>name)
475
+     * tabresult[0] = get_lang('NoCategory');
476 476
      *
477 477
      * @param int $courseId
478 478
      *
479 479
      * @return array
480
-	 *
481
-	 */
480
+     *
481
+     */
482 482
     public static function getCategoriesIdAndName($courseId = "")
483 483
     {
484
-		if (empty($courseId)) {
485
-			$courseId = api_get_course_int_id();
486
-		}
487
-	 	$tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
488
-	 	$tabresult = array("0"=>get_lang('NoCategorySelected'));
489
-	 	for ($i=0; $i < count($tabcatobject); $i++) {
490
-	 		$tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
491
-	 	}
492
-	 	return $tabresult;
493
-	}
484
+        if (empty($courseId)) {
485
+            $courseId = api_get_course_int_id();
486
+        }
487
+            $tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
488
+            $tabresult = array("0"=>get_lang('NoCategorySelected'));
489
+            for ($i=0; $i < count($tabcatobject); $i++) {
490
+                $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
491
+            }
492
+            return $tabresult;
493
+    }
494 494
 
495 495
     /**
496 496
      * Returns an array of question ids for each category
@@ -499,10 +499,10 @@  discard block
 block discarded – undo
499 499
      * @param int exercise
500 500
      * @param array $check_in_question_list
501 501
      * @param array $categoriesAddedInExercise
502
-    *
503
-    * @param int $exerciseId
504
-    * @return array
505
-    */
502
+     *
503
+     * @param int $exerciseId
504
+     * @return array
505
+     */
506 506
     static function getQuestionsByCat(
507 507
         $exerciseId,
508 508
         $check_in_question_list = array(),
@@ -580,28 +580,28 @@  discard block
 block discarded – undo
580 580
         }
581 581
 
582 582
         return $categories;
583
-	}
583
+    }
584 584
 
585
-	/**
586
-	 * return a tab of $in_number random elements of $in_tab
587
-	 */
585
+    /**
586
+     * return a tab of $in_number random elements of $in_tab
587
+     */
588 588
     public static function getNElementsFromArray($in_tab, $in_number)
589 589
     {
590
-		$tabres = $in_tab;
591
-		shuffle($tabres);
592
-		if ($in_number < count($tabres)) {
593
-			$tabres = array_slice($tabres, 0, $in_number);
594
-		}
595
-		return $tabres;
596
-	}
597
-
598
-	/**
599
-	 * display the category
600
-	 */
601
-	public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
590
+        $tabres = $in_tab;
591
+        shuffle($tabres);
592
+        if ($in_number < count($tabres)) {
593
+            $tabres = array_slice($tabres, 0, $in_number);
594
+        }
595
+        return $tabres;
596
+    }
597
+
598
+    /**
599
+     * display the category
600
+     */
601
+    public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
602 602
     {
603 603
         echo self::returnCategoryAndTitle($questionId, $in_display_category_name);
604
-	}
604
+    }
605 605
 
606 606
     /**
607 607
      * @param int $questionId
@@ -617,98 +617,98 @@  discard block
 block discarded – undo
617 617
             $in_display_category_name = $objExercise->display_category_name;
618 618
         }
619 619
         $content = null;
620
-		if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
620
+        if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
621 621
             $content .= '<div class="page-header">';
622 622
             $content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($questionId).'</h4>';
623 623
             $content .= "</div>";
624
-		}
624
+        }
625 625
         return $content;
626
-	}
626
+    }
627 627
 
628 628
     /**
629
-    * Display signs [+] and/or (>0) after question title if question has options
630
-    * scoreAlwaysPositive and/or uncheckedMayScore
631
-    */
629
+     * Display signs [+] and/or (>0) after question title if question has options
630
+     * scoreAlwaysPositive and/or uncheckedMayScore
631
+     */
632 632
     public function displayQuestionOption($in_objQuestion)
633 633
     {
634
-		if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) {
635
-			echo "<span style='font-size:75%'> (>0)</span>";
636
-		}
637
-		if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) {
638
-			echo "<span style='font-size:75%'> [+]</span>";
639
-		}
640
-	}
641
-
642
-	/**
643
-	 * sortTabByBracketLabel ($tabCategoryQuestions)
644
-	 * key of $tabCategoryQuestions are the category id (0 for not in a category)
645
-	 * value is the array of question id of this category
646
-	 * Sort question by Category
647
-	*/
634
+        if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) {
635
+            echo "<span style='font-size:75%'> (>0)</span>";
636
+        }
637
+        if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) {
638
+            echo "<span style='font-size:75%'> [+]</span>";
639
+        }
640
+    }
641
+
642
+    /**
643
+     * sortTabByBracketLabel ($tabCategoryQuestions)
644
+     * key of $tabCategoryQuestions are the category id (0 for not in a category)
645
+     * value is the array of question id of this category
646
+     * Sort question by Category
647
+     */
648 648
     public static function sortTabByBracketLabel($in_tab)
649 649
     {
650
-		$tabResult = array();
651
-		$tabCatName = array();	// tab of category name
652
-		while (list($cat_id, $tabquestion) = each($in_tab)) {
653
-			$catTitle = new TestCategory($cat_id);
654
-			$tabCatName[$cat_id] = $catTitle->name;
655
-		}
656
-		reset($in_tab);
657
-		// sort table by value, keeping keys as they are
658
-		asort($tabCatName);
659
-		// keys of $tabCatName are keys order for $in_tab
660
-		while (list($key, $val) = each($tabCatName)) {
661
-			$tabResult[$key] = $in_tab[$key];
662
-		}
663
-		return $tabResult;
664
-	}
650
+        $tabResult = array();
651
+        $tabCatName = array();	// tab of category name
652
+        while (list($cat_id, $tabquestion) = each($in_tab)) {
653
+            $catTitle = new TestCategory($cat_id);
654
+            $tabCatName[$cat_id] = $catTitle->name;
655
+        }
656
+        reset($in_tab);
657
+        // sort table by value, keeping keys as they are
658
+        asort($tabCatName);
659
+        // keys of $tabCatName are keys order for $in_tab
660
+        while (list($key, $val) = each($tabCatName)) {
661
+            $tabResult[$key] = $in_tab[$key];
662
+        }
663
+        return $tabResult;
664
+    }
665 665
 
666 666
     /**
667
-	 * return total score for test exe_id for all question in the category $in_cat_id for user
668
-	 * If no question for this category, return ""
669
-	 */
670
-	public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
671
-	{
672
-		$tbl_track_attempt		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
673
-		$tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
674
-		$in_cat_id = intval($in_cat_id);
675
-		$in_exe_id = intval($in_exe_id);
676
-		$in_user_id = intval($in_user_id);
677
-
678
-		$query = "SELECT DISTINCT
667
+     * return total score for test exe_id for all question in the category $in_cat_id for user
668
+     * If no question for this category, return ""
669
+     */
670
+    public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
671
+    {
672
+        $tbl_track_attempt		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
673
+        $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
674
+        $in_cat_id = intval($in_cat_id);
675
+        $in_exe_id = intval($in_exe_id);
676
+        $in_user_id = intval($in_user_id);
677
+
678
+        $query = "SELECT DISTINCT
679 679
 		            marks, exe_id, user_id, ta.question_id, category_id
680 680
                   FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc
681 681
                   WHERE
682 682
                     ta.question_id=qrc.question_id AND
683 683
                     qrc.category_id=$in_cat_id AND
684 684
                     exe_id=$in_exe_id AND user_id=$in_user_id";
685
-		$res = Database::query($query);
686
-		$totalcatscore = "";
687
-		while ($data = Database::fetch_array($res)) {
688
-			$totalcatscore += $data['marks'];
689
-		}
690
-		return $totalcatscore;
691
-	}
692
-
693
-	/**
685
+        $res = Database::query($query);
686
+        $totalcatscore = "";
687
+        while ($data = Database::fetch_array($res)) {
688
+            $totalcatscore += $data['marks'];
689
+        }
690
+        return $totalcatscore;
691
+    }
692
+
693
+    /**
694 694
      * return the number max of question in a category
695 695
      * count the number of questions in all categories, and return the max
696 696
      * @param int $exerciseId
697 697
      * @author - hubert borderiou
698
-    */
698
+     */
699 699
     public static function getNumberMaxQuestionByCat($exerciseId)
700 700
     {
701 701
         $res_num_max = 0;
702 702
         // foreach question
703
-		$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
704
-		for ($i=0; $i < count($tabcatid); $i++) {
705
-			if ($tabcatid[$i] > 0) {	// 0 = no category for this question
706
-				$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]);
703
+        $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
704
+        for ($i=0; $i < count($tabcatid); $i++) {
705
+            if ($tabcatid[$i] > 0) {	// 0 = no category for this question
706
+                $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]);
707 707
                 if ($nbQuestionInThisCat > $res_num_max) {
708 708
                     $res_num_max = $nbQuestionInThisCat;
709 709
                 }
710
-			}
711
-		}
710
+            }
711
+        }
712 712
         return $res_num_max;
713 713
     }
714 714
 
@@ -768,34 +768,34 @@  discard block
 block discarded – undo
768 768
     }
769 769
 
770 770
     /**
771
-	 * @return array
772
-	 */
773
-	function get_all_categories()
774
-	{
775
-		$table = Database::get_course_table(TABLE_QUIZ_CATEGORY);
776
-		$sql = "SELECT * FROM $table ORDER BY title ASC";
777
-		$res = Database::query($sql);
778
-		while ($row = Database::fetch_array($res,'ASSOC')) {
779
-			$array[] = $row;
780
-		}
781
-		return $array;
782
-	}
783
-
784
-	/**
785
-	 * @param Exercise $exercise
786
-	 * @param int $course_id
787
-	 * @param string $order
788
-	 * @param bool $shuffle
789
-	 * @param bool $excludeCategoryWithNoQuestions
790
-	 * @return array|bool
791
-	 */
792
-	public function getCategoryExerciseTree(
793
-		$exercise,
794
-		$course_id,
795
-		$order = null,
796
-		$shuffle = false,
797
-		$excludeCategoryWithNoQuestions = true
798
-	) {
771
+     * @return array
772
+     */
773
+    function get_all_categories()
774
+    {
775
+        $table = Database::get_course_table(TABLE_QUIZ_CATEGORY);
776
+        $sql = "SELECT * FROM $table ORDER BY title ASC";
777
+        $res = Database::query($sql);
778
+        while ($row = Database::fetch_array($res,'ASSOC')) {
779
+            $array[] = $row;
780
+        }
781
+        return $array;
782
+    }
783
+
784
+    /**
785
+     * @param Exercise $exercise
786
+     * @param int $course_id
787
+     * @param string $order
788
+     * @param bool $shuffle
789
+     * @param bool $excludeCategoryWithNoQuestions
790
+     * @return array|bool
791
+     */
792
+    public function getCategoryExerciseTree(
793
+        $exercise,
794
+        $course_id,
795
+        $order = null,
796
+        $shuffle = false,
797
+        $excludeCategoryWithNoQuestions = true
798
+    ) {
799 799
         if (empty($exercise)) {
800 800
             return array();
801 801
         }
@@ -805,165 +805,165 @@  discard block
 block discarded – undo
805 805
         }
806 806
 
807 807
         $course_id = intval($course_id);
808
-		$table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
808
+        $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
809 809
         $categoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
810
-		$sql = "SELECT * FROM $table qc
810
+        $sql = "SELECT * FROM $table qc
811 811
               	LEFT JOIN $categoryTable c
812 812
                 ON (qc.c_id = c.c_id AND c.id = qc.category_id)
813 813
                 WHERE qc.c_id = $course_id AND exercise_id = {$exercise->id} ";
814 814
 
815
-		if (!empty($order)) {
816
-			$sql .= "ORDER BY $order";
817
-		}
818
-
819
-		$categories = array();
820
-
821
-		$result = Database::query($sql);
822
-		if (Database::num_rows($result)) {
823
-			while ($row = Database::fetch_array($result, 'ASSOC')) {
824
-				if ($excludeCategoryWithNoQuestions) {
825
-					if ($row['count_questions'] == 0) {
826
-						continue;
827
-					}
828
-				}
829
-				if (empty($row['title']) && empty($row['category_id'])) {
830
-					$row['title'] = get_lang('NoCategory');
831
-				}
815
+        if (!empty($order)) {
816
+            $sql .= "ORDER BY $order";
817
+        }
818
+
819
+        $categories = array();
820
+
821
+        $result = Database::query($sql);
822
+        if (Database::num_rows($result)) {
823
+            while ($row = Database::fetch_array($result, 'ASSOC')) {
824
+                if ($excludeCategoryWithNoQuestions) {
825
+                    if ($row['count_questions'] == 0) {
826
+                        continue;
827
+                    }
828
+                }
829
+                if (empty($row['title']) && empty($row['category_id'])) {
830
+                    $row['title'] = get_lang('NoCategory');
831
+                }
832 832
                 $categories[$row['category_id']] = $row;
833
-			}
834
-		}
835
-
836
-		if ($shuffle) {
837
-			shuffle_assoc($categories);
838
-		}
839
-
840
-		return $categories;
841
-	}
842
-
843
-	public function getForm(& $form, $action = 'new')
844
-	{
845
-		switch($action) {
846
-			case 'new':
847
-				$header = get_lang('AddACategory');
848
-				$submit = get_lang('AddTestCategory');
849
-				break;
850
-			case 'edit':
851
-				$header = get_lang('EditCategory');
852
-				$submit = get_lang('ModifyCategory');
853
-				break;
854
-		}
855
-
856
-		// settting the form elements
857
-		$form->addElement('header', $header);
858
-		$form->addElement('hidden', 'category_id');
859
-		$form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
860
-		$form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
861
-		$category_parent_list = array();
862
-
863
-		$options = array(
864
-				'1' => get_lang('Visible'),
865
-				'0' => get_lang('Hidden')
866
-		);
867
-		$form->addElement('select', 'visibility', get_lang('Visibility'), $options);
868
-		$script = null;
869
-		if (!empty($this->parent_id)) {
870
-			$parent_cat = new TestCategory($this->parent_id);
871
-			$category_parent_list = array($parent_cat->id => $parent_cat->name);
872
-			$script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>';
873
-		}
874
-		$form->addElement('html', $script);
875
-
876
-		$form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id'));
877
-		$form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"');
878
-
879
-		// setting the defaults
880
-		$defaults = array();
881
-		$defaults["category_id"] = $this->id;
882
-		$defaults["category_name"] = $this->name;
883
-		$defaults["category_description"] = $this->description;
884
-		$defaults["parent_id"] = $this->parent_id;
885
-		$defaults["visibility"] = $this->visibility;
886
-		$form->setDefaults($defaults);
887
-
888
-		// setting the rules
889
-		$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
890
-	}
891
-
892
-	/**
893
-	 * Returns the category form.
894
-	 * @param Exercise $exercise_obj
895
-	 * @return string
896
-	 */
897
-	public function returnCategoryForm(Exercise $exercise_obj)
898
-	{
899
-		$categories = $this->getListOfCategoriesForTest($exercise_obj);
900
-
901
-		$saved_categories = $exercise_obj->get_categories_in_exercise();
902
-		$return = null;
903
-
904
-		if (!empty($categories)) {
905
-			$nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory();
906
-			$exercise_obj->setCategoriesGrouping(true);
907
-			$real_question_count = count($exercise_obj->getQuestionList());
908
-
909
-			$warning = null;
910
-			if ($nbQuestionsTotal != $real_question_count) {
911
-				$warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning');
912
-			}
913
-
914
-			$return .= $warning;
915
-			$return .= '<table class="data_table">';
916
-			$return .= '<tr>';
917
-			$return .= '<th height="24">' . get_lang('Categories') . '</th>';
918
-			$return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>';
919
-
920
-			$emptyCategory = array(
921
-				'id' => '0',
922
-				'name' => get_lang('NoCategory'),
923
-				'description' => '',
924
-				'iid' => '0',
925
-				'title' => get_lang('NoCategory')
926
-			);
927
-
928
-			$categories[] = $emptyCategory;
929
-
930
-			foreach ($categories as $category) {
931
-				$cat_id = $category['iid'];
932
-				$return .= '<tr>';
933
-				$return .= '<td>';
934
-				//$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : '');
935
-				$return .= Display::div($category['name']);
936
-				$return .= '</td>';
937
-				$return .= '<td>';
938
-				$value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1;
939
-				$return .= '<input name="category['.$cat_id.']" value="' .$value.'" />';
940
-				$return .= '</td>';
941
-				$return .= '</tr>';
942
-			}
943
-
944
-			$return .= '</table>';
945
-			$return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected');
946
-			return $return;
947
-		}
948
-	}
949
-
950
-	/**
951
-	 * Sorts an array
952
-	 * @param $array
953
-	 * @return mixed
954
-	 */
955
-	public function sort_tree_array($array)
956
-	{
957
-		foreach ($array as $key => $row) {
958
-			$parent[$key] = $row['parent_id'];
959
-		}
960
-		if (count($array) > 0) {
961
-			array_multisort($parent, SORT_ASC, $array);
962
-		}
963
-		return $array;
964
-	}
965
-
966
-	/**
833
+            }
834
+        }
835
+
836
+        if ($shuffle) {
837
+            shuffle_assoc($categories);
838
+        }
839
+
840
+        return $categories;
841
+    }
842
+
843
+    public function getForm(& $form, $action = 'new')
844
+    {
845
+        switch($action) {
846
+            case 'new':
847
+                $header = get_lang('AddACategory');
848
+                $submit = get_lang('AddTestCategory');
849
+                break;
850
+            case 'edit':
851
+                $header = get_lang('EditCategory');
852
+                $submit = get_lang('ModifyCategory');
853
+                break;
854
+        }
855
+
856
+        // settting the form elements
857
+        $form->addElement('header', $header);
858
+        $form->addElement('hidden', 'category_id');
859
+        $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
860
+        $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
861
+        $category_parent_list = array();
862
+
863
+        $options = array(
864
+                '1' => get_lang('Visible'),
865
+                '0' => get_lang('Hidden')
866
+        );
867
+        $form->addElement('select', 'visibility', get_lang('Visibility'), $options);
868
+        $script = null;
869
+        if (!empty($this->parent_id)) {
870
+            $parent_cat = new TestCategory($this->parent_id);
871
+            $category_parent_list = array($parent_cat->id => $parent_cat->name);
872
+            $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>';
873
+        }
874
+        $form->addElement('html', $script);
875
+
876
+        $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id'));
877
+        $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"');
878
+
879
+        // setting the defaults
880
+        $defaults = array();
881
+        $defaults["category_id"] = $this->id;
882
+        $defaults["category_name"] = $this->name;
883
+        $defaults["category_description"] = $this->description;
884
+        $defaults["parent_id"] = $this->parent_id;
885
+        $defaults["visibility"] = $this->visibility;
886
+        $form->setDefaults($defaults);
887
+
888
+        // setting the rules
889
+        $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
890
+    }
891
+
892
+    /**
893
+     * Returns the category form.
894
+     * @param Exercise $exercise_obj
895
+     * @return string
896
+     */
897
+    public function returnCategoryForm(Exercise $exercise_obj)
898
+    {
899
+        $categories = $this->getListOfCategoriesForTest($exercise_obj);
900
+
901
+        $saved_categories = $exercise_obj->get_categories_in_exercise();
902
+        $return = null;
903
+
904
+        if (!empty($categories)) {
905
+            $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory();
906
+            $exercise_obj->setCategoriesGrouping(true);
907
+            $real_question_count = count($exercise_obj->getQuestionList());
908
+
909
+            $warning = null;
910
+            if ($nbQuestionsTotal != $real_question_count) {
911
+                $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning');
912
+            }
913
+
914
+            $return .= $warning;
915
+            $return .= '<table class="data_table">';
916
+            $return .= '<tr>';
917
+            $return .= '<th height="24">' . get_lang('Categories') . '</th>';
918
+            $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>';
919
+
920
+            $emptyCategory = array(
921
+                'id' => '0',
922
+                'name' => get_lang('NoCategory'),
923
+                'description' => '',
924
+                'iid' => '0',
925
+                'title' => get_lang('NoCategory')
926
+            );
927
+
928
+            $categories[] = $emptyCategory;
929
+
930
+            foreach ($categories as $category) {
931
+                $cat_id = $category['iid'];
932
+                $return .= '<tr>';
933
+                $return .= '<td>';
934
+                //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : '');
935
+                $return .= Display::div($category['name']);
936
+                $return .= '</td>';
937
+                $return .= '<td>';
938
+                $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1;
939
+                $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />';
940
+                $return .= '</td>';
941
+                $return .= '</tr>';
942
+            }
943
+
944
+            $return .= '</table>';
945
+            $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected');
946
+            return $return;
947
+        }
948
+    }
949
+
950
+    /**
951
+     * Sorts an array
952
+     * @param $array
953
+     * @return mixed
954
+     */
955
+    public function sort_tree_array($array)
956
+    {
957
+        foreach ($array as $key => $row) {
958
+            $parent[$key] = $row['parent_id'];
959
+        }
960
+        if (count($array) > 0) {
961
+            array_multisort($parent, SORT_ASC, $array);
962
+        }
963
+        return $array;
964
+    }
965
+
966
+    /**
967 967
      * Return true if a category already exists with the same name
968 968
      * @param string $in_name
969 969
      *
@@ -1010,8 +1010,8 @@  discard block
 block discarded – undo
1010 1010
      * @param int $categoryId
1011 1011
      * @param int $questionId
1012 1012
      * @param int $courseId
1013
-	 *
1014
-	 * @return int
1013
+     *
1014
+     * @return int
1015 1015
      */
1016 1016
     public static function add_category_for_question_id($categoryId, $questionId, $courseId)
1017 1017
     {
@@ -1019,18 +1019,18 @@  discard block
 block discarded – undo
1019 1019
         // if question doesn't have a category
1020 1020
         // @todo change for 1.10 when a question can have several categories
1021 1021
         if (TestCategory::getCategoryForQuestion($questionId, $courseId) == 0 &&
1022
-			$questionId > 0 &&
1023
-			$courseId > 0
1022
+            $questionId > 0 &&
1023
+            $courseId > 0
1024 1024
         ) {
1025 1025
             $sql = "INSERT INTO $table (c_id, question_id, category_id)
1026 1026
                     VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")";
1027 1027
             Database::query($sql);
1028
-			$id = Database::insert_id();
1028
+            $id = Database::insert_id();
1029 1029
 
1030
-			return $id;
1030
+            return $id;
1031 1031
         }
1032 1032
 
1033
-		return false;
1033
+        return false;
1034 1034
     }
1035 1035
 
1036 1036
     /**
Please login to merge, or discard this patch.
main/exercice/exercise_submit.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     if (!$objExercise->read($exerciseId) ||
117 117
         (!$objExercise->selectStatus() && !$is_allowedToEdit && $origin != 'learnpath')
118 118
     ) {
119
-    	if ($debug) {error_log('1.1. Error while reading the exercise'); };
119
+        if ($debug) {error_log('1.1. Error while reading the exercise'); };
120 120
         unset ($objExercise);
121 121
         $error = get_lang('ExerciseNotFound');
122 122
     } else {
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 
131 131
 //2. Checking if $objExercise is set
132 132
 if (!isset($objExercise) && isset($exerciseInSession)) {
133
-	if ($debug) { error_log('2. Loading $objExercise from session'); };
133
+    if ($debug) { error_log('2. Loading $objExercise from session'); };
134 134
     $objExercise = $exerciseInSession;
135 135
 }
136 136
 
137 137
 //3. $objExercise is not set, then return to the exercise list
138 138
 if (!is_object($objExercise)) {
139
-	if ($debug) {error_log('3. $objExercise was not set, kill the script'); };
139
+    if ($debug) {error_log('3. $objExercise was not set, kill the script'); };
140 140
     header('Location: exercise.php');
141 141
     exit;
142 142
 }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 
158 158
 $time_control = false;
159 159
 if ($objExercise->expired_time != 0) {
160
-	$time_control = true;
160
+    $time_control = true;
161 161
 }
162 162
 
163 163
 // Generating the time control key for the user
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
 $_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
167 167
 
168 168
 if ($time_control) {
169
-	// Get the expired time of the current exercise in track_e_exercises
170
-	$total_seconds = $objExercise->expired_time*60;
169
+    // Get the expired time of the current exercise in track_e_exercises
170
+    $total_seconds = $objExercise->expired_time*60;
171 171
 }
172 172
 
173 173
 $show_clock = true;
174 174
 $user_id = api_get_user_id();
175 175
 if ($objExercise->selectAttempts() > 0) {
176
-	$attempt_html = '';
176
+    $attempt_html = '';
177 177
     $attempt_count = Event::get_attempt_count(
178 178
         $user_id,
179 179
         $exerciseId,
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
         $learnpath_item_view_id
183 183
     );
184 184
 
185
-	if ($attempt_count >= $objExercise->selectAttempts()) {
186
-		$show_clock = false;
187
-		if (!api_is_allowed_to_edit(null,true)) {
185
+    if ($attempt_count >= $objExercise->selectAttempts()) {
186
+        $show_clock = false;
187
+        if (!api_is_allowed_to_edit(null,true)) {
188 188
             if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
189 189
 
190 190
                 // Showing latest attempt according with task BT#1628
@@ -223,29 +223,29 @@  discard block
 block discarded – undo
223 223
                             $attempt_html .= Display::div(get_lang('Score').' '.$marks, array('id'=>'question_question_titlescore'));
224 224
                         }
225 225
                     }
226
-					$score =  ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
227
-					$attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
228
-				} else {
229
-					$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
230
-				}
231
-			} else {
232
-				$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
233
-			}
234
-		} else {
235
-			$attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
236
-		}
226
+                    $score =  ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
227
+                    $attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
228
+                } else {
229
+                    $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
230
+                }
231
+            } else {
232
+                $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
233
+            }
234
+        } else {
235
+            $attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
236
+        }
237 237
 
238
-		if ($origin == 'learnpath') {
239
-			Display :: display_reduced_header();
240
-		} else {
241
-			Display :: display_header($nameTools,'Exercises');
242
-		}
238
+        if ($origin == 'learnpath') {
239
+            Display :: display_reduced_header();
240
+        } else {
241
+            Display :: display_header($nameTools,'Exercises');
242
+        }
243 243
 
244
-		echo $attempt_html;
245
-		if ($origin != 'learnpath')
246
-			Display :: display_footer();
247
-		exit;
248
-	}
244
+        echo $attempt_html;
245
+        if ($origin != 'learnpath')
246
+            Display :: display_footer();
247
+        exit;
248
+    }
249 249
 }
250 250
 
251 251
 if ($debug) {
@@ -296,26 +296,26 @@  discard block
 block discarded – undo
296 296
 
297 297
 if (empty($exercise_stat_info)) {
298 298
     if ($debug)  error_log('5  $exercise_stat_info is empty ');
299
-	$total_weight = 0;
300
-	$questionList = $objExercise->get_validated_question_list();
301
-	foreach ($questionListUncompressed as $question_id) {
302
-		$objQuestionTmp = Question::read($question_id);
303
-		$total_weight += floatval($objQuestionTmp->weighting);
304
-	}
299
+    $total_weight = 0;
300
+    $questionList = $objExercise->get_validated_question_list();
301
+    foreach ($questionListUncompressed as $question_id) {
302
+        $objQuestionTmp = Question::read($question_id);
303
+        $total_weight += floatval($objQuestionTmp->weighting);
304
+    }
305 305
 
306
-	if ($time_control) {
307
-		$expected_time = $current_timestamp + $total_seconds;
306
+    if ($time_control) {
307
+        $expected_time = $current_timestamp + $total_seconds;
308 308
 
309
-		if ($debug)  error_log('5.1. $current_timestamp '.$current_timestamp);
310
-		if ($debug)  error_log('5.2. $expected_time '.$expected_time);
309
+        if ($debug)  error_log('5.1. $current_timestamp '.$current_timestamp);
310
+        if ($debug)  error_log('5.2. $expected_time '.$expected_time);
311 311
 
312
-		$clock_expired_time 	= api_get_utc_datetime($expected_time);
313
-		if ($debug) error_log('5.3. $expected_time '.$clock_expired_time);
312
+        $clock_expired_time 	= api_get_utc_datetime($expected_time);
313
+        if ($debug) error_log('5.3. $expected_time '.$clock_expired_time);
314 314
 
315
-		//Sessions  that contain the expired time
316
-		$_SESSION['expired_time'][$current_expired_time_key] 	 = $clock_expired_time;
317
-		if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
318
-	}
315
+        //Sessions  that contain the expired time
316
+        $_SESSION['expired_time'][$current_expired_time_key] 	 = $clock_expired_time;
317
+        if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
318
+    }
319 319
 
320 320
     $exe_id = $objExercise->save_stat_track_exercise_info(
321 321
         $clock_expired_time,
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
     );
333 333
     if ($debug)  error_log("5.5  exercise_stat_info[] exists getting exe_id $exe_id");
334 334
 } else {
335
-	$exe_id = $exercise_stat_info['exe_id'];
335
+    $exe_id = $exercise_stat_info['exe_id'];
336 336
     // Remember last question id position.
337 337
     $isFirstTime = Session::read('firstTime');
338 338
     if ($isFirstTime && $objExercise->type == ONE_PER_PAGE) {
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called::  '.print_r($exercise_stat_info, 1)); };
363 363
 
364 364
 if (!empty($exercise_stat_info['questions_to_check'])) {
365
-	$my_remind_list = $exercise_stat_info['questions_to_check'];
366
-	$my_remind_list = explode(',', $my_remind_list);
367
-	$my_remind_list = array_filter($my_remind_list);
365
+    $my_remind_list = $exercise_stat_info['questions_to_check'];
366
+    $my_remind_list = explode(',', $my_remind_list);
367
+    $my_remind_list = array_filter($my_remind_list);
368 368
 }
369 369
 
370 370
 $params = "exe_id=$exe_id&exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq();
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
 
373 373
 if ($reminder == 2 && empty($my_remind_list)) {
374 374
     if ($debug) { error_log("6.2 calling the exercise_reminder.php "); };
375
-	header('Location: exercise_reminder.php?'.$params);
376
-	exit;
375
+    header('Location: exercise_reminder.php?'.$params);
376
+    exit;
377 377
 }
378 378
 
379 379
 /*
@@ -381,56 +381,56 @@  discard block
 block discarded – undo
381 381
  * If the expired time is major that zero(0) then the expired time is compute on this time.
382 382
  */
383 383
 if ($time_control) {
384
-	if ($debug) error_log('7.1. Time control is enabled');
385
-	if ($debug) error_log('7.2. $current_expired_time_key  '.$current_expired_time_key);
386
-	if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key]  '.$_SESSION['expired_time'][$current_expired_time_key]);
384
+    if ($debug) error_log('7.1. Time control is enabled');
385
+    if ($debug) error_log('7.2. $current_expired_time_key  '.$current_expired_time_key);
386
+    if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key]  '.$_SESSION['expired_time'][$current_expired_time_key]);
387 387
 
388 388
     if (!isset($_SESSION['expired_time'][$current_expired_time_key])) {
389 389
         //Timer - Get expired_time for a student
390 390
         if (!empty($exercise_stat_info)) {
391
-        	if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
392
-	        $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
393
-			if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
394
-	        // Get the last attempt of an exercise
395
-	    	$last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']);
391
+            if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
392
+            $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
393
+            if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
394
+            // Get the last attempt of an exercise
395
+            $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']);
396 396
 
397
-	    	/* This means that the user enters the exam but do not answer the
397
+            /* This means that the user enters the exam but do not answer the
398 398
 	    	   first question we get the date from the track_e_exercises not from
399 399
 	    	   the track_et_attempt see #2069 */
400
-	    	if (empty($last_attempt_date)) {
401
-	    		$diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
402
-	    		$last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff);
403
-	    	} else {
404
-	    		//Recalculate the time control due #2069
405
-	    		$diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC');
406
-	    		$last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff);
407
-	    	}
408
-	        if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); }
409
-
410
-	        //New expired time - it is due to the possible closure of session
411
-	        $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC');
412
-	        if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); }
413
-
414
-	        $expected_time	= $current_timestamp + $new_expired_time_in_seconds;
415
-	        if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); }
416
-
417
-	        $clock_expired_time  = api_get_utc_datetime($expected_time);
418
-	        if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
419
-
420
-			// First we update the attempt to today
421
-			/* How the expired time is changed into "track_e_exercises" table,
400
+            if (empty($last_attempt_date)) {
401
+                $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
402
+                $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff);
403
+            } else {
404
+                //Recalculate the time control due #2069
405
+                $diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC');
406
+                $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff);
407
+            }
408
+            if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); }
409
+
410
+            //New expired time - it is due to the possible closure of session
411
+            $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC');
412
+            if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); }
413
+
414
+            $expected_time	= $current_timestamp + $new_expired_time_in_seconds;
415
+            if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); }
416
+
417
+            $clock_expired_time  = api_get_utc_datetime($expected_time);
418
+            if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
419
+
420
+            // First we update the attempt to today
421
+            /* How the expired time is changed into "track_e_exercises" table,
422 422
                then the last attempt for this student should be changed too */
423
-	        $sql = "UPDATE $exercise_attempt_table SET
423
+            $sql = "UPDATE $exercise_attempt_table SET
424 424
 	                tms = '".api_get_utc_datetime()."'
425 425
 	                WHERE
426 426
 	                    exe_id = '".$exercise_stat_info['exe_id']."' AND
427 427
 	                    tms = '".$last_attempt_date."' ";
428
-	        if ($debug) {error_log('7.10. $sql: '.$sql); }
429
-	        Database::query($sql);
428
+            if ($debug) {error_log('7.10. $sql: '.$sql); }
429
+            Database::query($sql);
430 430
 
431
-	        //Sessions  that contain the expired time
432
-	        $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
433
-	        if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
431
+            //Sessions  that contain the expired time
432
+            $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
433
+            if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
434 434
         }
435 435
     } else {
436 436
         $clock_expired_time =  $_SESSION['expired_time'][$current_expired_time_key];
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
  * for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock
448 448
  */
449 449
 if ($time_control) { //Sends the exercise form when the expired time is finished
450
-	$htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
450
+    $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
451 451
 }
452 452
 
453 453
 // if the user has submitted the form
@@ -461,14 +461,14 @@  discard block
 block discarded – undo
461 461
     // selects the list of question ID
462 462
     $questionList = $objExercise->get_validated_question_list();
463 463
     if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) {
464
-    	$questionList = explode(',', $exercise_stat_info['data_tracking']);
464
+        $questionList = explode(',', $exercise_stat_info['data_tracking']);
465 465
     }
466 466
     Session::write('questionList', $questionList);
467 467
     if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
468 468
 } else {
469
-	if (isset($objExercise) && isset($_SESSION['objExercise'])) {
470
-    	$questionList = $_SESSION['questionList'];
471
-	}
469
+    if (isset($objExercise) && isset($_SESSION['objExercise'])) {
470
+        $questionList = $_SESSION['questionList'];
471
+    }
472 472
 }
473 473
 
474 474
 if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1));
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 //Real question count
477 477
 $question_count = 0;
478 478
 if (!empty($questionList)) {
479
-	$question_count = count($questionList);
479
+    $question_count = count($questionList);
480 480
 }
481 481
 
482 482
 if ($formSent && isset($_POST)) {
@@ -518,11 +518,11 @@  discard block
 block discarded – undo
518 518
                 //saving each question
519 519
                 if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
520 520
                     $nro_question = $current_question; // - 1;
521
-                 	$questionId   = $key;
521
+                        $questionId   = $key;
522 522
                     // gets the student choice for this question
523 523
                     $choice = $exerciseResult[$questionId];
524 524
                     if (isset($exe_id)) {
525
-                    	// Manage the question and answer attempts
525
+                        // Manage the question and answer attempts
526 526
                         if ($debug) { error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1)); }
527 527
                         $objExercise->manage_answer(
528 528
                             $exe_id,
@@ -611,58 +611,58 @@  discard block
 block discarded – undo
611 611
 }
612 612
 
613 613
 if ($question_count != 0) {
614
-	if (($objExercise->type == ALL_ON_ONE_PAGE ||
614
+    if (($objExercise->type == ALL_ON_ONE_PAGE ||
615 615
         $current_question > $question_count)
616 616
     ) {
617
-	    if (api_is_allowed_to_session_edit()) {
618
-	        // goes to the script that will show the result of the exercise
619
-	        if ($objExercise->type == ALL_ON_ONE_PAGE) {
620
-	            if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
621
-
622
-	            //We check if the user attempts before sending to the exercise_result.php
623
-	            if ($objExercise->selectAttempts() > 0) {
624
-	                $attempt_count = Event::get_attempt_count(
617
+        if (api_is_allowed_to_session_edit()) {
618
+            // goes to the script that will show the result of the exercise
619
+            if ($objExercise->type == ALL_ON_ONE_PAGE) {
620
+                if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
621
+
622
+                //We check if the user attempts before sending to the exercise_result.php
623
+                if ($objExercise->selectAttempts() > 0) {
624
+                    $attempt_count = Event::get_attempt_count(
625 625
                         api_get_user_id(),
626 626
                         $exerciseId,
627 627
                         $learnpath_id,
628 628
                         $learnpath_item_id,
629 629
                         $learnpath_item_view_id
630 630
                     );
631
-	                if ($attempt_count >= $objExercise->selectAttempts()) {
632
-	                    Display :: display_warning_message(
631
+                    if ($attempt_count >= $objExercise->selectAttempts()) {
632
+                        Display :: display_warning_message(
633 633
                             sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()),
634 634
                             false
635 635
                         );
636
-	                    if ($origin != 'learnpath') {
637
-	                        //so we are not in learnpath tool
638
-	                        echo '</div>'; //End glossary div
639
-	                        Display :: display_footer();
640
-	                    } else {
641
-	                        echo '</body></html>';
642
-	                    }
643
-	                    exit;
644
-	                }
645
-	            }
646
-	        } else {
647
-	            if ($objExercise->review_answers) {
648
-	            	header('Location: exercise_reminder.php?'.$params);
649
-	            	exit;
650
-	            } else {
636
+                        if ($origin != 'learnpath') {
637
+                            //so we are not in learnpath tool
638
+                            echo '</div>'; //End glossary div
639
+                            Display :: display_footer();
640
+                        } else {
641
+                            echo '</body></html>';
642
+                        }
643
+                        exit;
644
+                    }
645
+                }
646
+            } else {
647
+                if ($objExercise->review_answers) {
648
+                    header('Location: exercise_reminder.php?'.$params);
649
+                    exit;
650
+                } else {
651 651
                     header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
652 652
                     exit;
653
-	            }
654
-	        }
655
-	    } else {
656
-	        if ($debug) { error_log('Redirecting to exercise_submit.php'); }
657
-	        exit;
658
-	    }
659
-	}
653
+                }
654
+            }
655
+        } else {
656
+            if ($debug) { error_log('Redirecting to exercise_submit.php'); }
657
+            exit;
658
+        }
659
+    }
660 660
 } else {
661
-	$error = get_lang('ThereAreNoQuestionsForThisExercise');
662
-	// if we are in the case where user select random by category, but didn't choose the number of random question
663
-	if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) {
664
-		$error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion');
665
-	}
661
+    $error = get_lang('ThereAreNoQuestionsForThisExercise');
662
+    // if we are in the case where user select random by category, but didn't choose the number of random question
663
+    if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) {
664
+        $error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion');
665
+    }
666 666
 }
667 667
 
668 668
 if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
@@ -701,9 +701,9 @@  discard block
 block discarded – undo
701 701
 if (api_is_course_admin() && $origin != 'learnpath') {
702 702
     echo '<div class="actions">';
703 703
     if ($show_quiz_edition == false) {
704
-    	echo '<a href="exercise_admin.php?' . api_get_cidreq() . '&modifyExercise=yes&exerciseId=' . $objExercise->id . '">'.Display :: return_icon('settings.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>';
704
+        echo '<a href="exercise_admin.php?' . api_get_cidreq() . '&modifyExercise=yes&exerciseId=' . $objExercise->id . '">'.Display :: return_icon('settings.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>';
705 705
     } else {
706
-    	echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>';
706
+        echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>';
707 707
     }
708 708
     echo '</div>';
709 709
 }
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
             $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet');
747 747
             Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()));
748 748
             if ($origin != 'learnpath') {
749
-            	Display :: display_footer();
749
+                Display :: display_footer();
750 750
             }
751 751
             exit;
752 752
         } else {
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 if (isset($_custom['exercises_hidden_when_no_start_date']) &&
762 762
     $_custom['exercises_hidden_when_no_start_date']
763 763
 ) {
764
-	if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') {
764
+    if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') {
765 765
         Display:: display_warning_message(
766 766
             sprintf(
767 767
                 get_lang('ExerciseNoStartedYet'),
@@ -769,20 +769,20 @@  discard block
 block discarded – undo
769 769
                 $objExercise->selectAttempts()
770 770
             )
771 771
         );
772
-		if ($origin != 'learnpath') {
773
-			Display :: display_footer();
774
-		}
775
-	}
772
+        if ($origin != 'learnpath') {
773
+            Display :: display_footer();
774
+        }
775
+    }
776 776
 }
777 777
 
778 778
 //Timer control
779 779
 if ($time_control) {
780 780
     echo $objExercise->return_time_left_div();
781
-	echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>';
781
+    echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>';
782 782
 }
783 783
 
784 784
 if ($origin != 'learnpath') {
785
-   echo '<div id="highlight-plugin" class="glossary-content">';
785
+    echo '<div id="highlight-plugin" class="glossary-content">';
786 786
 }
787 787
 
788 788
 if ($reminder == 2)  {
@@ -794,53 +794,53 @@  discard block
 block discarded – undo
794 794
     $current_question = 1; //set by default the 1st question
795 795
 
796 796
     if (!empty($my_remind_list)) {
797
-    	// Checking which questions we are going to call from the remind list
798
-		for ($i = 0; $i < count($data_tracking); $i++) {
799
-			for($j = 0; $j < count($my_remind_list); $j++) {
800
-
801
-				if (!empty($remind_question_id)) {
802
-					if ($remind_question_id == $my_remind_list[$j]) {
803
-
804
-			        	if ($remind_question_id == $data_tracking[$i]) {
805
-			        		if (isset($my_remind_list[$j+1])) {
806
-			        			$remind_question_id = $my_remind_list[$j+1];
807
-			        			$current_question = $i + 1;
808
-			        		} else {
797
+        // Checking which questions we are going to call from the remind list
798
+        for ($i = 0; $i < count($data_tracking); $i++) {
799
+            for($j = 0; $j < count($my_remind_list); $j++) {
800
+
801
+                if (!empty($remind_question_id)) {
802
+                    if ($remind_question_id == $my_remind_list[$j]) {
803
+
804
+                        if ($remind_question_id == $data_tracking[$i]) {
805
+                            if (isset($my_remind_list[$j+1])) {
806
+                                $remind_question_id = $my_remind_list[$j+1];
807
+                                $current_question = $i + 1;
808
+                            } else {
809 809
                                 // We end the remind list we go to the exercise_reminder.php please
810
-			        			$remind_question_id = -1;
811
-			        			$current_question = $i + 1; // last question
812
-			        		}
813
-			        		break 2;
814
-			            }
815
-					}
816
-				} else {
817
-					if ($my_remind_list[$j] == $data_tracking[$i]) {
818
-						if (isset($my_remind_list[$j+1])) {
819
-							$remind_question_id = $my_remind_list[$j+1];
820
-							$current_question = $i + 1; // last question
821
-						} else {
810
+                                $remind_question_id = -1;
811
+                                $current_question = $i + 1; // last question
812
+                            }
813
+                            break 2;
814
+                        }
815
+                    }
816
+                } else {
817
+                    if ($my_remind_list[$j] == $data_tracking[$i]) {
818
+                        if (isset($my_remind_list[$j+1])) {
819
+                            $remind_question_id = $my_remind_list[$j+1];
820
+                            $current_question = $i + 1; // last question
821
+                        } else {
822 822
                             // We end the remind list we go to the exercise_reminder.php please
823
-							$remind_question_id = -1;
824
-							$current_question = $i + 1; // last question
825
-						}
826
-						break 2;
827
-					}
828
-				}
829
-			}
823
+                            $remind_question_id = -1;
824
+                            $current_question = $i + 1; // last question
825
+                        }
826
+                        break 2;
827
+                    }
828
+                }
829
+            }
830 830
         }
831 831
     } else {
832
-    	if ($objExercise->review_answers) {
832
+        if ($objExercise->review_answers) {
833 833
             if ($debug) { error_log('. redirecting to exercise_reminder.php '); }
834
-	    	header("Location: exercise_reminder.php?$params");
835
-	    	exit;
836
-    	}
834
+            header("Location: exercise_reminder.php?$params");
835
+            exit;
836
+        }
837 837
     }
838 838
 }
839 839
 
840 840
 if ($objExercise->review_answers) {
841
-	$script_php = 'exercise_reminder.php';
841
+    $script_php = 'exercise_reminder.php';
842 842
 } else {
843
-	$script_php = 'exercise_result.php';
843
+    $script_php = 'exercise_result.php';
844 844
 }
845 845
 
846 846
 if (!empty($error)) {
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
          <input type="hidden" name="learnpath_item_id" 		value="'.$learnpath_item_id . '" />
1085 1085
          <input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id . '" />';
1086 1086
 
1087
-	// Show list of questions
1087
+    // Show list of questions
1088 1088
     $i = 1;
1089 1089
     $attempt_list = array();
1090 1090
     if (isset($exe_id)) {
@@ -1134,10 +1134,10 @@  discard block
 block discarded – undo
1134 1134
 
1135 1135
         $attributes = array('id' =>'remind_list['.$questionId.']');
1136 1136
         if (in_array($questionId, $remind_list)) {
1137
-        	$is_remind_on = true;
1138
-        	$attributes['checked'] = 1;
1139
-        	$remind_question = true;
1140
-        	$remind_highlight = ' remind_highlight ';
1137
+            $is_remind_on = true;
1138
+            $attributes['checked'] = 1;
1139
+            $remind_question = true;
1140
+            $remind_highlight = ' remind_highlight ';
1141 1141
         }
1142 1142
 
1143 1143
         // Showing the exercise description
@@ -1211,8 +1211,8 @@  discard block
 block discarded – undo
1211 1211
     }
1212 1212
     // end foreach()
1213 1213
     if ($objExercise->type == ALL_ON_ONE_PAGE) {
1214
-    	$exercise_actions =  $objExercise->show_button($questionId, $current_question);
1215
-    	echo Display::div($exercise_actions, array('class'=>'exercise_actions'));
1214
+        $exercise_actions =  $objExercise->show_button($questionId, $current_question);
1215
+        echo Display::div($exercise_actions, array('class'=>'exercise_actions'));
1216 1216
         echo '<br>';
1217 1217
     }
1218 1218
     echo '</form>';
Please login to merge, or discard this patch.
app/Resources/public/assets/ckeditor/samples/old/assets/posteddata.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,22 +27,22 @@
 block discarded – undo
27 27
 
28 28
 if (!empty($_POST))
29 29
 {
30
-	foreach ( $_POST as $key => $value )
31
-	{
32
-		if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) )
33
-			continue;
30
+    foreach ( $_POST as $key => $value )
31
+    {
32
+        if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) )
33
+            continue;
34 34
 
35
-		if ( get_magic_quotes_gpc() )
36
-			$value = htmlspecialchars( stripslashes((string)$value) );
37
-		else
38
-			$value = htmlspecialchars( (string)$value );
35
+        if ( get_magic_quotes_gpc() )
36
+            $value = htmlspecialchars( stripslashes((string)$value) );
37
+        else
38
+            $value = htmlspecialchars( (string)$value );
39 39
 ?>
40 40
 		<tr>
41 41
 			<th style="vertical-align: top"><?php echo htmlspecialchars( (string)$key ); ?></th>
42 42
 			<td><pre class="samples"><?php echo $value; ?></pre></td>
43 43
 		</tr>
44 44
 	<?php
45
-	}
45
+    }
46 46
 }
47 47
 ?>
48 48
 	</table>
Please login to merge, or discard this patch.
main/gradebook/lib/fe/resulttable.class.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -10,166 +10,166 @@
 block discarded – undo
10 10
  */
11 11
 class ResultTable extends SortableTable
12 12
 {
13
-	private $datagen;
14
-	private $evaluation;
15
-	private $allresults;
16
-	private $iscourse;
17
-
18
-	/**
19
-	 * Constructor
20
-	 */
13
+    private $datagen;
14
+    private $evaluation;
15
+    private $allresults;
16
+    private $iscourse;
17
+
18
+    /**
19
+     * Constructor
20
+     */
21 21
     public function __construct($evaluation, $results = array(), $iscourse, $addparams = null,$forprint = false)
22
-	{
23
-    	parent :: __construct ('resultlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1);
24
-
25
-		$this->datagen = new ResultsDataGenerator($evaluation, $results, true);
26
-
27
-		$this->evaluation = $evaluation;
28
-		$this->iscourse = $iscourse;
29
-		$this->forprint = $forprint;
30
-
31
-		if (isset ($addparams))  {
32
-			$this->set_additional_parameters($addparams);
33
-		}
34
-		$scoredisplay = ScoreDisplay :: instance();
35
-		$column= 0;
36
-		if ($this->iscourse == '1') {
37
-			$this->set_header($column++, '', false);
38
-			$this->set_form_actions(array (
39
-					'delete' => get_lang('Delete')
40
-			));
41
-		}
42
-		if (api_is_western_name_order()) {
43
-			$this->set_header($column++, get_lang('FirstName'));
44
-			$this->set_header($column++, get_lang('LastName'));
45
-		} else {
46
-			$this->set_header($column++, get_lang('LastName'));
47
-			$this->set_header($column++, get_lang('FirstName'));
48
-		}
49
-		$this->set_header($column++, get_lang('Score'));
50
-		if ($scoredisplay->is_custom()) {
51
-			$this->set_header($column++, get_lang('Display'));
52
-		}
53
-		if (!$this->forprint) {
54
-			$this->set_header($column++, get_lang('Modify'),false);
55
-		}
22
+    {
23
+        parent :: __construct ('resultlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1);
24
+
25
+        $this->datagen = new ResultsDataGenerator($evaluation, $results, true);
26
+
27
+        $this->evaluation = $evaluation;
28
+        $this->iscourse = $iscourse;
29
+        $this->forprint = $forprint;
30
+
31
+        if (isset ($addparams))  {
32
+            $this->set_additional_parameters($addparams);
33
+        }
34
+        $scoredisplay = ScoreDisplay :: instance();
35
+        $column= 0;
36
+        if ($this->iscourse == '1') {
37
+            $this->set_header($column++, '', false);
38
+            $this->set_form_actions(array (
39
+                    'delete' => get_lang('Delete')
40
+            ));
41
+        }
42
+        if (api_is_western_name_order()) {
43
+            $this->set_header($column++, get_lang('FirstName'));
44
+            $this->set_header($column++, get_lang('LastName'));
45
+        } else {
46
+            $this->set_header($column++, get_lang('LastName'));
47
+            $this->set_header($column++, get_lang('FirstName'));
48
+        }
49
+        $this->set_header($column++, get_lang('Score'));
50
+        if ($scoredisplay->is_custom()) {
51
+            $this->set_header($column++, get_lang('Display'));
52
+        }
53
+        if (!$this->forprint) {
54
+            $this->set_header($column++, get_lang('Modify'),false);
55
+        }
56 56
     }
57 57
 
58 58
 
59
-	/**
60
-	 * Function used by SortableTable to get total number of items in the table
61
-	 */
62
-	public function get_total_number_of_items ()
59
+    /**
60
+     * Function used by SortableTable to get total number of items in the table
61
+     */
62
+    public function get_total_number_of_items ()
63 63
     {
64
-		return $this->datagen->get_total_results_count();
65
-	}
66
-
67
-	/**
68
-	 * Function used by SortableTable to generate the data to display
69
-	 */
70
-	public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) {
71
-
72
-		$is_western_name_order = api_is_western_name_order();
73
-		$scoredisplay = ScoreDisplay :: instance();
74
-
75
-		// determine sorting type
76
-		$col_adjust = $this->iscourse == '1' ? 1 : 0;
77
-
78
-		switch ($this->column) {
79
-			// first name or last name
80
-			case (0 + $col_adjust):
81
-				if ($is_western_name_order) {
82
-					$sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME;
83
-				} else {
84
-					$sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME;
85
-				}
86
-				break;
64
+        return $this->datagen->get_total_results_count();
65
+    }
66
+
67
+    /**
68
+     * Function used by SortableTable to generate the data to display
69
+     */
70
+    public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) {
71
+
72
+        $is_western_name_order = api_is_western_name_order();
73
+        $scoredisplay = ScoreDisplay :: instance();
74
+
75
+        // determine sorting type
76
+        $col_adjust = $this->iscourse == '1' ? 1 : 0;
77
+
78
+        switch ($this->column) {
87 79
             // first name or last name
88
-			case (1 + $col_adjust):
89
-				if ($is_western_name_order) {
90
-					$sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME;
91
-				} else {
92
-					$sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME;
93
-				}
94
-				break;
80
+            case (0 + $col_adjust):
81
+                if ($is_western_name_order) {
82
+                    $sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME;
83
+                } else {
84
+                    $sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME;
85
+                }
86
+                break;
87
+            // first name or last name
88
+            case (1 + $col_adjust):
89
+                if ($is_western_name_order) {
90
+                    $sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME;
91
+                } else {
92
+                    $sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME;
93
+                }
94
+                break;
95 95
             //Score
96
-			case (2 + $col_adjust):
97
-				$sorting = ResultsDataGenerator :: RDG_SORT_SCORE;
98
-				break;
99
-			case (3 + $col_adjust):
100
-				$sorting = ResultsDataGenerator :: RDG_SORT_MASK;
101
-				break;
102
-		}
103
-
104
-		if ($this->direction == 'DESC') {
105
-			$sorting |= ResultsDataGenerator :: RDG_SORT_DESC;
106
-		} else {
107
-			$sorting |= ResultsDataGenerator :: RDG_SORT_ASC;
108
-		}
109
-
110
-		$data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
111
-
112
-		// generate the data to display
113
-		$sortable_data = array();
114
-		foreach ($data_array as $item) {
115
-			$row = array ();
116
-			if ($this->iscourse == '1') {
117
-				 $row[] = $item['result_id'];
118
-			}
119
-			if ($is_western_name_order) {
120
-				$row[] = $item['firstname'];
121
-				$row[] = $item['lastname'];
122
-			} else {
123
-				$row[] = $item['lastname'];
124
-				$row[] = $item['firstname'];
125
-			}
126
-
127
-			$row[] =  Display::bar_progress($item['percentage_score'], false, $item['score']);
96
+            case (2 + $col_adjust):
97
+                $sorting = ResultsDataGenerator :: RDG_SORT_SCORE;
98
+                break;
99
+            case (3 + $col_adjust):
100
+                $sorting = ResultsDataGenerator :: RDG_SORT_MASK;
101
+                break;
102
+        }
103
+
104
+        if ($this->direction == 'DESC') {
105
+            $sorting |= ResultsDataGenerator :: RDG_SORT_DESC;
106
+        } else {
107
+            $sorting |= ResultsDataGenerator :: RDG_SORT_ASC;
108
+        }
109
+
110
+        $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
111
+
112
+        // generate the data to display
113
+        $sortable_data = array();
114
+        foreach ($data_array as $item) {
115
+            $row = array ();
116
+            if ($this->iscourse == '1') {
117
+                    $row[] = $item['result_id'];
118
+            }
119
+            if ($is_western_name_order) {
120
+                $row[] = $item['firstname'];
121
+                $row[] = $item['lastname'];
122
+            } else {
123
+                $row[] = $item['lastname'];
124
+                $row[] = $item['firstname'];
125
+            }
126
+
127
+            $row[] =  Display::bar_progress($item['percentage_score'], false, $item['score']);
128 128
             //$row[] =  Display::bar_progress($item['percentage_score'], true);
129
-			if ($scoredisplay->is_custom()) {
130
-				$row[] = $item['display'];
131
-			}
132
-			if (!$this->forprint) {
133
-				$row[] = $this->build_edit_column ($item);
134
-			}
135
-			$sortable_data[] = $row;
136
-		}
137
-
138
-		return $sortable_data;
139
-	}
140
-
141
-	private function build_edit_column ($item)
142
-	{
143
-		$status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
144
-		$locked_status = $this->evaluation->get_locked();
145
-		if (api_is_allowed_to_edit(null, true) && $locked_status == 0) {
146
-			//api_is_course_admin()
147
-			$edit_column = '<a href="' . api_get_self() . '?editres=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id().'&'.api_get_cidreq().'">'.
148
-				Display::return_icon('edit.png', get_lang('Modify'),'','22').'</a>';
149
-			$edit_column .= ' <a href="' . api_get_self() . '?delete_mark=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id().'&'.api_get_cidreq().'">'.
150
-				Display::return_icon('delete.png', get_lang('Delete'),'','22').'</a>';
151
-		}
152
-
153
-		if ($this->evaluation->get_course_code() == null) {
154
-			$edit_column .= '&nbsp;<a href="' . api_get_self() . '?resultdelete=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '" onclick="return confirmationuser();">';
155
-			$edit_column .= Display::return_icon('delete.png', get_lang('Delete'));
156
-			$edit_column .= '</a>';
157
-		    $edit_column .= '&nbsp;<a href="user_stats.php?userid=' . $item['id'] . '&selecteval=' . $this->evaluation->get_id() . '&'.api_get_cidreq().'">';
158
-			$edit_column .= Display::return_icon('statistics.gif', get_lang('Statistics'));
159
-		    $edit_column .= '</a>';
160
-		}
161
-
162
-		// Evaluation's origin is a link
163
-		if ($this->evaluation->get_category_id() < 0) {
164
-			$link = LinkFactory::get_evaluation_link($this->evaluation->get_id());
165
-			$doc_url = $link->get_view_url($item['id']);
166
-
167
-			if ($doc_url != null) {
168
-				$edit_column .= '&nbsp;<a href="'. $doc_url . '" target="_blank">';
169
-				$edit_column .= Display::return_icon('link.gif', get_lang('OpenDocument')).'</a>';
170
-			}
171
-		}
172
-
173
-		return $edit_column;
174
-	}
129
+            if ($scoredisplay->is_custom()) {
130
+                $row[] = $item['display'];
131
+            }
132
+            if (!$this->forprint) {
133
+                $row[] = $this->build_edit_column ($item);
134
+            }
135
+            $sortable_data[] = $row;
136
+        }
137
+
138
+        return $sortable_data;
139
+    }
140
+
141
+    private function build_edit_column ($item)
142
+    {
143
+        $status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
144
+        $locked_status = $this->evaluation->get_locked();
145
+        if (api_is_allowed_to_edit(null, true) && $locked_status == 0) {
146
+            //api_is_course_admin()
147
+            $edit_column = '<a href="' . api_get_self() . '?editres=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id().'&'.api_get_cidreq().'">'.
148
+                Display::return_icon('edit.png', get_lang('Modify'),'','22').'</a>';
149
+            $edit_column .= ' <a href="' . api_get_self() . '?delete_mark=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id().'&'.api_get_cidreq().'">'.
150
+                Display::return_icon('delete.png', get_lang('Delete'),'','22').'</a>';
151
+        }
152
+
153
+        if ($this->evaluation->get_course_code() == null) {
154
+            $edit_column .= '&nbsp;<a href="' . api_get_self() . '?resultdelete=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '" onclick="return confirmationuser();">';
155
+            $edit_column .= Display::return_icon('delete.png', get_lang('Delete'));
156
+            $edit_column .= '</a>';
157
+            $edit_column .= '&nbsp;<a href="user_stats.php?userid=' . $item['id'] . '&selecteval=' . $this->evaluation->get_id() . '&'.api_get_cidreq().'">';
158
+            $edit_column .= Display::return_icon('statistics.gif', get_lang('Statistics'));
159
+            $edit_column .= '</a>';
160
+        }
161
+
162
+        // Evaluation's origin is a link
163
+        if ($this->evaluation->get_category_id() < 0) {
164
+            $link = LinkFactory::get_evaluation_link($this->evaluation->get_id());
165
+            $doc_url = $link->get_view_url($item['id']);
166
+
167
+            if ($doc_url != null) {
168
+                $edit_column .= '&nbsp;<a href="'. $doc_url . '" target="_blank">';
169
+                $edit_column .= Display::return_icon('link.gif', get_lang('OpenDocument')).'</a>';
170
+            }
171
+        }
172
+
173
+        return $edit_column;
174
+    }
175 175
 }
Please login to merge, or discard this patch.
main/admin/configure_homepage.php 1 patch
Indentation   +846 added lines, -846 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_APP_PATH).'home/';
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,577 +204,577 @@  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
-				// Write
227
-				if (is_writable($homep)) {
228
-					// Default
229
-					if (is_writable($homep.$topf.'_'.$lang.$ext)) {
230
-						$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
231
-						fputs($fp, $home_top);
232
-						fclose($fp);
233
-
234
-						// Language
235
-						foreach ($_languages['name'] as $key => $value) {
236
-							$lang_name = $_languages['folder'][$key];
237
-							if (isset($_POST[$lang_name])) {
238
-								$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
239
-								fputs($fp, $home_top);
240
-								fclose($fp);
241
-							}
242
-						}
243
-					} else {
244
-						$errorMsg = get_lang('HomePageFilesNotWritable');
245
-					}
246
-				} else {
247
-					//File does not exist
248
-					$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
249
-					fputs($fp, $home_top);
250
-					fclose($fp);
251
-
252
-					foreach ($_languages['name'] as $key => $value) {
253
-						$lang_name = $_languages['folder'][$key];
254
-						if (isset($_POST[$lang_name])) {
255
-							if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
256
-								$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
257
-								fputs($fp, $home_top);
258
-								fclose($fp);
259
-							}
260
-						}
261
-					}
262
-				}
263
-
264
-				if (EventsMail::check_if_using_class('portal_homepage_edited')) {
265
-					EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id()));
266
-				}
267
-				Event::addEvent(
268
-					LOG_HOMEPAGE_CHANGED,
269
-					'edit_top',
270
-					cut(strip_tags($home_top), 254),
271
-					api_get_utc_datetime(),
272
-					api_get_user_id()
273
-				);
274
-				break;
275
-			case 'edit_notice':
276
-				// Filter
277
-				$notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
278
-				$notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>')));
279
-				if (empty($notice_title) || empty($notice_text)) {
280
-					$errorMsg = get_lang('NoticeWillBeNotDisplayed');
281
-				}
282
-				// Write
283
-				if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
284
-					if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
285
-						$fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
286
-						if ($errorMsg == '') {
287
-							fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
288
-
289
-							foreach ($_languages['name'] as $key => $value) {
290
-								$lang_name = $_languages['folder'][$key];
291
-								if (isset($_POST[$lang_name])) {
292
-									if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
293
-										if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) {
294
-											$fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
295
-											fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
296
-											fclose($fp);
297
-										}
298
-									}
299
-								}
300
-							}
301
-						} else {
302
-							fputs($fp, '');
303
-
304
-							foreach ($_languages['name'] as $key => $value) {
305
-								$lang_name = $_languages['folder'][$key];
306
-								if (isset($_POST[$lang_name])) {
307
-									if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
308
-										$fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
309
-										fputs($fp1, '');
310
-										fclose($fp1);
311
-									}
312
-								}
313
-							}
314
-						}
315
-						fclose($fp);
316
-					} else {
317
-						$errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
318
-					}
319
-				} else {
320
-					//File does not exist
321
-					$fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
322
-					fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
323
-					fclose($fp);
324
-				}
325
-				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
+                // Write
227
+                if (is_writable($homep)) {
228
+                    // Default
229
+                    if (is_writable($homep.$topf.'_'.$lang.$ext)) {
230
+                        $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
231
+                        fputs($fp, $home_top);
232
+                        fclose($fp);
233
+
234
+                        // Language
235
+                        foreach ($_languages['name'] as $key => $value) {
236
+                            $lang_name = $_languages['folder'][$key];
237
+                            if (isset($_POST[$lang_name])) {
238
+                                $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
239
+                                fputs($fp, $home_top);
240
+                                fclose($fp);
241
+                            }
242
+                        }
243
+                    } else {
244
+                        $errorMsg = get_lang('HomePageFilesNotWritable');
245
+                    }
246
+                } else {
247
+                    //File does not exist
248
+                    $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
249
+                    fputs($fp, $home_top);
250
+                    fclose($fp);
251
+
252
+                    foreach ($_languages['name'] as $key => $value) {
253
+                        $lang_name = $_languages['folder'][$key];
254
+                        if (isset($_POST[$lang_name])) {
255
+                            if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
256
+                                $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
257
+                                fputs($fp, $home_top);
258
+                                fclose($fp);
259
+                            }
260
+                        }
261
+                    }
262
+                }
263
+
264
+                if (EventsMail::check_if_using_class('portal_homepage_edited')) {
265
+                    EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id()));
266
+                }
267
+                Event::addEvent(
268
+                    LOG_HOMEPAGE_CHANGED,
269
+                    'edit_top',
270
+                    cut(strip_tags($home_top), 254),
271
+                    api_get_utc_datetime(),
272
+                    api_get_user_id()
273
+                );
274
+                break;
275
+            case 'edit_notice':
276
+                // Filter
277
+                $notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
278
+                $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>')));
279
+                if (empty($notice_title) || empty($notice_text)) {
280
+                    $errorMsg = get_lang('NoticeWillBeNotDisplayed');
281
+                }
282
+                // Write
283
+                if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
284
+                    if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
285
+                        $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
286
+                        if ($errorMsg == '') {
287
+                            fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
288
+
289
+                            foreach ($_languages['name'] as $key => $value) {
290
+                                $lang_name = $_languages['folder'][$key];
291
+                                if (isset($_POST[$lang_name])) {
292
+                                    if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
293
+                                        if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) {
294
+                                            $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
295
+                                            fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
296
+                                            fclose($fp);
297
+                                        }
298
+                                    }
299
+                                }
300
+                            }
301
+                        } else {
302
+                            fputs($fp, '');
303
+
304
+                            foreach ($_languages['name'] as $key => $value) {
305
+                                $lang_name = $_languages['folder'][$key];
306
+                                if (isset($_POST[$lang_name])) {
307
+                                    if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
308
+                                        $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
309
+                                        fputs($fp1, '');
310
+                                        fclose($fp1);
311
+                                    }
312
+                                }
313
+                            }
314
+                        }
315
+                        fclose($fp);
316
+                    } else {
317
+                        $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
318
+                    }
319
+                } else {
320
+                    //File does not exist
321
+                    $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
322
+                    fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
323
+                    fclose($fp);
324
+                }
325
+                Event::addEvent(
326 326
                     LOG_HOMEPAGE_CHANGED,
327 327
                     'edit_notice',
328 328
                     cut(strip_tags($notice_title), 254),
329 329
                     api_get_utc_datetime(),
330 330
                     api_get_user_id()
331 331
                 );
332
-				break;
333
-			case 'edit_news':
334
-				//Filter
335
-				$home_news = trim(stripslashes($_POST['home_news']));
336
-
337
-				//Write
338
-				if ($s_languages_news != 'all') {
339
-					if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
340
-						if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
341
-							$fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
342
-							fputs($fp, $home_news);
343
-							fclose($fp);
344
-						} else {
345
-							$errorMsg = get_lang('HomePageFilesNotWritable');
346
-						}
347
-					} else {
348
-						// File does not exist
349
-						$fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
350
-						fputs($fp, $home_news);
351
-						fclose($fp);
352
-					}
353
-				} else {
354
-					// We update all the news file
355
-					foreach ($_languages['name'] as $key => $value) {
356
-						$english_name = $_languages['folder'][$key];
357
-						if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
358
-							if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
359
-								$fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
360
-								fputs($fp, $home_news);
361
-								fclose($fp);
362
-							} else {
363
-								$errorMsg = get_lang('HomePageFilesNotWritable');
364
-							}
365
-						} else {
366
-							// File does not exist
367
-							$fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
368
-							fputs($fp, $home_news);
369
-							fclose($fp);
370
-						}
371
-					}
372
-				}
373
-				Event::addEvent(
332
+                break;
333
+            case 'edit_news':
334
+                //Filter
335
+                $home_news = trim(stripslashes($_POST['home_news']));
336
+
337
+                //Write
338
+                if ($s_languages_news != 'all') {
339
+                    if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
340
+                        if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
341
+                            $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
342
+                            fputs($fp, $home_news);
343
+                            fclose($fp);
344
+                        } else {
345
+                            $errorMsg = get_lang('HomePageFilesNotWritable');
346
+                        }
347
+                    } else {
348
+                        // File does not exist
349
+                        $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
350
+                        fputs($fp, $home_news);
351
+                        fclose($fp);
352
+                    }
353
+                } else {
354
+                    // We update all the news file
355
+                    foreach ($_languages['name'] as $key => $value) {
356
+                        $english_name = $_languages['folder'][$key];
357
+                        if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
358
+                            if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
359
+                                $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
360
+                                fputs($fp, $home_news);
361
+                                fclose($fp);
362
+                            } else {
363
+                                $errorMsg = get_lang('HomePageFilesNotWritable');
364
+                            }
365
+                        } else {
366
+                            // File does not exist
367
+                            $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
368
+                            fputs($fp, $home_news);
369
+                            fclose($fp);
370
+                        }
371
+                    }
372
+                }
373
+                Event::addEvent(
374 374
                     LOG_HOMEPAGE_CHANGED,
375 375
                     'edit_news',
376 376
                     strip_tags(cut($home_news, 254)),
377 377
                     api_get_utc_datetime(),
378 378
                     api_get_user_id()
379 379
                 );
380
-				break;
381
-			case 'insert_tabs':
382
-			case 'edit_tabs':
383
-			case 'insert_link':
384
-			case 'edit_link':
385
-				$link_index     = intval($_POST['link_index']);
386
-				$insert_where   = intval($_POST['insert_where']);
387
-				$link_name      = trim(stripslashes($_POST['link_name']));
388
-				$link_url       = trim(stripslashes($_POST['link_url']));
389
-				$add_in_tab     = intval($_POST['add_in_tab']);
390
-				$link_html = trim(stripslashes($_POST['link_html']));
391
-				$filename = trim(stripslashes($_POST['filename']));
392
-				$target_blank = $_POST['target_blank'] ? true : false;
393
-
394
-				if ($link_url == 'http://' || $link_url == 'https://') {
395
-					$link_url = '';
396
-				} elseif (!empty($link_url) && !strstr($link_url, '://')) {
397
-					$link_url='http://'.$link_url;
398
-				}
399
-				$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf;
400
-
401
-				if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
402
-					$errorMsg = get_lang('HomePageFilesNotWritable');
403
-				} elseif (empty($link_name)) {
404
-					$errorMsg = get_lang('PleaseEnterLinkName');
405
-				} else {
406
-					// New links are added as new files in the home/ directory
407
-					if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) {
408
-						$filename = api_replace_dangerous_char($link_name).'.html';
409
-					}
410
-
411
-					// "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
412
-					if (!empty($filename)) {
413
-						$filename = str_replace('home_', 'user_', $filename);
414
-					}
415
-					// If the typical language suffix is not found in the file name,
416
-					// replace the ".html" suffix by "_en.html" or the active menu language
417
-					if (!strstr($filename,'_'.$lang.$ext)) {
418
-						$filename = str_replace($ext, '_'.$lang.$ext, $filename);
419
-					}
420
-					// Get the contents of home_menu_en.html (or active menu language
421
-					// version) into $home_menu as an array of one entry per line
422
-					$home_menu = file($homep.$menuf.'_'.$lang.$ext);
423
-					$home_menu = implode("\n", $home_menu);
424
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
425
-					$home_menu = explode("\n", $home_menu);
426
-					$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
427
-					// Prepare place to insert the new link into (default is end of file)
428
-					if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
429
-						$insert_where = sizeof($home_menu) - 1;
430
-					}
431
-					//
432
-					// For each line of the file, remove trailing spaces and special chars
433
-					//foreach ($home_menu as $key => $enreg) {
434
-					//	$home_menu[$key] = trim($enreg);
435
-					//}
436
-					//
437
-					// If the given link url is empty, then replace the link url by a link to the link file created
438
-
439
-					if (empty($link_url) || $link_url == 'http://' ||  $link_url == 'https://') {
440
-						$link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
441
-						// If the file doesn't exist, then create it and
442
-						// fill it with default text
443
-
444
-						$fp = @fopen($homep.$filename, 'w');
445
-						if ($fp) {
446
-							if (empty($link_html)) {
447
-								fputs($fp, get_lang('MyTextHere'));
448
-								home_tabs($homep.$filename);
449
-							} else {
450
-								fputs($fp, $link_html);
451
-								home_tabs($homep.$filename);
452
-							}
453
-							fclose($fp);
454
-						}
455
-					}
456
-					// If the requested action is to edit a link, open the file and
457
-					// write to it (if the file doesn't exist, create it)
458
-					if (in_array($action, array('edit_link'))  && !empty($link_html)) {
459
-						$fp = @fopen($homep.$filename, 'w');
460
-						if ($fp) {
461
-							fputs($fp, $link_html);
462
-							home_tabs($homep.$filename);
463
-							fclose($fp);
464
-						}
465
-					}
380
+                break;
381
+            case 'insert_tabs':
382
+            case 'edit_tabs':
383
+            case 'insert_link':
384
+            case 'edit_link':
385
+                $link_index     = intval($_POST['link_index']);
386
+                $insert_where   = intval($_POST['insert_where']);
387
+                $link_name      = trim(stripslashes($_POST['link_name']));
388
+                $link_url       = trim(stripslashes($_POST['link_url']));
389
+                $add_in_tab     = intval($_POST['add_in_tab']);
390
+                $link_html = trim(stripslashes($_POST['link_html']));
391
+                $filename = trim(stripslashes($_POST['filename']));
392
+                $target_blank = $_POST['target_blank'] ? true : false;
393
+
394
+                if ($link_url == 'http://' || $link_url == 'https://') {
395
+                    $link_url = '';
396
+                } elseif (!empty($link_url) && !strstr($link_url, '://')) {
397
+                    $link_url='http://'.$link_url;
398
+                }
399
+                $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf;
400
+
401
+                if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
402
+                    $errorMsg = get_lang('HomePageFilesNotWritable');
403
+                } elseif (empty($link_name)) {
404
+                    $errorMsg = get_lang('PleaseEnterLinkName');
405
+                } else {
406
+                    // New links are added as new files in the home/ directory
407
+                    if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) {
408
+                        $filename = api_replace_dangerous_char($link_name).'.html';
409
+                    }
410
+
411
+                    // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
412
+                    if (!empty($filename)) {
413
+                        $filename = str_replace('home_', 'user_', $filename);
414
+                    }
415
+                    // If the typical language suffix is not found in the file name,
416
+                    // replace the ".html" suffix by "_en.html" or the active menu language
417
+                    if (!strstr($filename,'_'.$lang.$ext)) {
418
+                        $filename = str_replace($ext, '_'.$lang.$ext, $filename);
419
+                    }
420
+                    // Get the contents of home_menu_en.html (or active menu language
421
+                    // version) into $home_menu as an array of one entry per line
422
+                    $home_menu = file($homep.$menuf.'_'.$lang.$ext);
423
+                    $home_menu = implode("\n", $home_menu);
424
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
425
+                    $home_menu = explode("\n", $home_menu);
426
+                    $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
427
+                    // Prepare place to insert the new link into (default is end of file)
428
+                    if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
429
+                        $insert_where = sizeof($home_menu) - 1;
430
+                    }
431
+                    //
432
+                    // For each line of the file, remove trailing spaces and special chars
433
+                    //foreach ($home_menu as $key => $enreg) {
434
+                    //	$home_menu[$key] = trim($enreg);
435
+                    //}
436
+                    //
437
+                    // If the given link url is empty, then replace the link url by a link to the link file created
438
+
439
+                    if (empty($link_url) || $link_url == 'http://' ||  $link_url == 'https://') {
440
+                        $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
441
+                        // If the file doesn't exist, then create it and
442
+                        // fill it with default text
443
+
444
+                        $fp = @fopen($homep.$filename, 'w');
445
+                        if ($fp) {
446
+                            if (empty($link_html)) {
447
+                                fputs($fp, get_lang('MyTextHere'));
448
+                                home_tabs($homep.$filename);
449
+                            } else {
450
+                                fputs($fp, $link_html);
451
+                                home_tabs($homep.$filename);
452
+                            }
453
+                            fclose($fp);
454
+                        }
455
+                    }
456
+                    // If the requested action is to edit a link, open the file and
457
+                    // write to it (if the file doesn't exist, create it)
458
+                    if (in_array($action, array('edit_link'))  && !empty($link_html)) {
459
+                        $fp = @fopen($homep.$filename, 'w');
460
+                        if ($fp) {
461
+                            fputs($fp, $link_html);
462
+                            home_tabs($homep.$filename);
463
+                            fclose($fp);
464
+                        }
465
+                    }
466 466
 
467 467
                     $class_add_in_tab = 'class="show_menu"';
468 468
 
469
-					if (!$add_in_tab) {
470
-						$class_add_in_tab = 'class="hide_menu"';
471
-					}
469
+                    if (!$add_in_tab) {
470
+                        $class_add_in_tab = 'class="hide_menu"';
471
+                    }
472 472
 
473
-					// If the requested action is to create a link, make some room
474
-					// for the new link in the home_menu array at the requested place
475
-					// and insert the new link there
473
+                    // If the requested action is to create a link, make some room
474
+                    // for the new link in the home_menu array at the requested place
475
+                    // and insert the new link there
476 476
                     
477
-					if ($action == 'insert_link' || $action == 'insert_tabs') {
478
-						for ($i = sizeof($home_menu); $i; $i--) {
479
-							if ($i > $insert_where) {
480
-								$home_menu[$i] = $home_menu[$i - 1];
481
-							} else {
482
-								break;
483
-							}
484
-						}
485
-						$home_menu[$insert_where + 1] = '<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>';
486
-					} else {
487
-						// If the request is about a link edition, change the link
488
-						$home_menu[$link_index]='<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>';
489
-					}
490
-					// Re-build the file from the home_menu array
491
-					$home_menu = implode("\n", $home_menu);
492
-					// Write
493
-					if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
494
-						if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
495
-							$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
496
-							fputs($fp, $home_menu);
497
-							home_tabs($homep.$menuf.'_'.$lang.$ext);
498
-							fclose($fp);
499
-
500
-							foreach ($_languages['name'] as $key => $value) {
501
-								$lang_name = $_languages['folder'][$key];
502
-								if (isset($_POST[$lang_name])) {
503
-									$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
504
-									fputs($fp, $home_menu);
505
-									home_tabs($homep.$menuf.'_'.$lang_name.$ext);
506
-									fclose($fp);
507
-								}
508
-							}
509
-
510
-							if (file_exists($homep.$menuf.$ext)) {
511
-								if (is_writable($homep.$menuf.$ext)) {
512
-									$fpo = fopen($homep.$menuf.$ext, 'w');
513
-									fputs($fpo, $home_menu);
514
-									home_tabs($homep.$menuf.$ext);
515
-									fclose($fpo);
516
-								}
517
-							}
518
-						} else {
519
-							$errorMsg = get_lang('HomePageFilesNotWritable');
520
-						}
521
-					} else {
522
-						//File does not exist
523
-						$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
524
-						fputs($fp, $home_menu);
525
-						home_tabs($homep.$menuf.'_'.$lang.$ext);
526
-						fclose($fp);
527
-
528
-						foreach ($_languages['name'] as $key => $value) {
529
-							$lang_name = $_languages['folder'][$key];
530
-							if (isset($_POST[$lang_name])) {
531
-								$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
532
-								fputs($fp, $home_menu);
533
-								home_tabs($homep.$menuf.'_'.$lang_name.$ext);
534
-								fclose($fp);
535
-							}
536
-						}
537
-					}
538
-				}
539
-				Event::addEvent(
540
-					LOG_HOMEPAGE_CHANGED,
541
-					$action,
542
-					cut($link_name . ':' . $link_url, 254),
543
-					api_get_utc_datetime(),
544
-					api_get_user_id()
545
-				);
546
-				break;
547
-		} //end of switch($action)
548
-
549
-		if (empty($errorMsg)) {
550
-			header('Location: '.$selfUrl.'?language='.$languageGet);
551
-			exit();
552
-		}
553
-	} else {
554
-		//if POST[formSent] is not set
555
-		switch ($action) {
556
-			case 'open_link':
557
-				// Previously, filtering of GET['link'] was done here but it left
558
-				// a security threat. Filtering has now been moved outside conditions
559
-				break;
560
-			case 'delete_tabs':
561
-			case 'delete_link':
562
-				// A link is deleted by getting the file into an array, removing the
563
-				// link and re-writing the array to the file
564
-				$link_index = intval($_GET['link_index']);
565
-				$menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf;
566
-				$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
567
-				if (empty($home_menu)) {
568
-					$home_menu = array();
569
-				}
570
-				foreach ($home_menu as $key => $enreg) {
571
-					if ($key == $link_index) {
572
-						unset($home_menu[$key]);
573
-					} else {
574
-						$home_menu[$key] = trim($enreg);
575
-					}
576
-				}
577
-				$home_menu = implode("\n", $home_menu);
578
-				$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
579
-
580
-				$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
581
-				fputs($fp, $home_menu);
582
-				home_tabs($homep.$menuf.'_'.$lang.$ext);
583
-				fclose($fp);
584
-				if (file_exists($homep.$menuf.$ext)) {
585
-					if (is_writable($homep.$menuf.$ext)) {
586
-						$fpo = fopen($homep.$menuf.$ext,'w');
587
-						fputs($fpo, $home_menu);
588
-						home_tabs($homep.$menuf.$ext);
589
-						fclose($fpo);
590
-					}
591
-				}
592
-				header('Location: '.$selfUrl);
593
-				exit();
594
-				break;
595
-			case 'edit_top':
596
-				// This request is only the preparation for the update of the home_top
597
-				$home_top = '';
598
-				if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
599
-					$home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
600
-				} elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
601
-					$home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
602
-				} else {
603
-					$errorMsg = get_lang('HomePageFilesNotReadable');
604
-				}
605
-				$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
606
-				break;
607
-			case 'edit_notice':
608
-				// This request is only the preparation for the update of the home_notice
609
-				$home_notice = '';
610
-				if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
611
-					$home_notice = @file($homep.$noticef.'_'.$lang.$ext);
612
-				} elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
613
-					$home_notice = @file($homep.$noticef.$lang.$ext);
614
-				} else {
615
-					$errorMsg = get_lang('HomePageFilesNotReadable');
616
-				}
617
-				if (empty($home_notice)) {
618
-					$home_notice = array();
619
-				}
620
-				$notice_title = strip_tags($home_notice[0]);
621
-				$notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
622
-				$notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
623
-				$notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
624
-				break;
625
-			case 'edit_news':
626
-				// This request is the preparation for the update of the home_news page
627
-				$home_news = '';
628
-				if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
629
-					$home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
630
-				} elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
631
-					$home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
632
-				} else {
633
-					$errorMsg = get_lang('HomePageFilesNotReadable');
634
-				}
635
-				$home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
636
-				break;
637
-			case 'insert_link':
638
-				// This request is the preparation for the addition of an item in home_menu
639
-				$home_menu = '';
640
-				$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
641
-				if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
642
-					$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
643
-				} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
644
-					$home_menu = @file($homep.$menuf.$lang.$ext);
645
-				} else {
646
-					$errorMsg = get_lang('HomePageFilesNotReadable');
647
-				}
648
-				if (empty($home_menu)) {
649
-					$home_menu = array();
650
-				}
651
-				if (!empty($home_menu)) {
652
-					$home_menu = implode("\n", $home_menu);
653
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
654
-					$home_menu = explode("\n", $home_menu);
655
-				}
656
-				$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
657
-				break;
658
-			case 'insert_tabs':
659
-				// This request is the preparation for the addition of an item in home_menu
660
-				$home_menu = '';
661
-				if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
662
-					$home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
663
-				} elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
664
-					$home_menu = @file($homep.$mtloggedin.$lang.$ext);
665
-				} elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) {
666
-					$home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
667
-				} else {
668
-					$errorMsg = get_lang('HomePageFilesNotReadable');
669
-				}
670
-				if (empty($home_menu)) {
671
-					$home_menu = array();
672
-				}
673
-				if (!empty($home_menu)) {
674
-					$home_menu = implode("\n", $home_menu);
675
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
676
-					$home_menu = explode("\n", $home_menu);
677
-				}
678
-				$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
679
-				break;
680
-			case 'edit_tabs':
681
-			case 'edit_link':
682
-				// This request is the preparation for the edition of the links array
683
-				$home_menu = '';
684
-				$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
685
-				if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
686
-					$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
687
-				} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
688
-					$home_menu = @file($homep.$menuf.$lang.$ext);
689
-				} else {
690
-					$errorMsg = get_lang('HomePageFilesNotReadable');
691
-				}
692
-
693
-				if (empty($home_menu)) {
694
-					if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
695
-						$home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
696
-					}
697
-				}
698
-
699
-				if (empty($home_menu)) {
700
-					$home_menu = array();
701
-				}
702
-				if (!empty($home_menu)) {
703
-					$home_menu = implode("\n", $home_menu);
704
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
705
-					$home_menu = explode("\n", $home_menu);
706
-				}
707
-
708
-				$link_index = intval($_GET['link_index']);
709
-
710
-				$target_blank = false;
711
-				$link_name = '';
712
-				$link_url = '';
713
-
714
-				//$home_menu_new = array();
715
-				//
716
-				//Cleaning array
717
-				//foreach ($home_menu as $item) {
718
-				//	if(!empty($item)) {
719
-				//		$home_menu_new[] = $item;
720
-				//	}
721
-				//}
722
-				//$home_menu = $home_menu_new;
723
-
724
-				// Cleaning the array
725
-				$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
726
-
727
-				// For each line of the home_menu file
728
-				foreach ($home_menu as $key => $enreg) {
729
-
730
-					// Check if the current item is the one we want to update
731
-					if ($key == $link_index) {
732
-						// This is the link we want to update
733
-						// Check if the target should be "_blank"
734
-						if (strstr($enreg, 'target="_blank"')) {
735
-							$target_blank = true;
736
-						}
737
-
738
-						if (strstr($enreg, 'hide_menu')) {
739
-							$add_in_tab = false;
740
-						} else {
741
-							$add_in_tab = true;
742
-						}
743
-
744
-						// Remove dangerous HTML tags from the link itself (this is an
745
-						// additional measure in case a link previously contained
746
-						// unsecure tags)
747
-						$link_name = strip_tags($enreg);
748
-
749
-						// Get the contents of "href" attribute in $link_url
750
-						$enreg = explode('href="',$enreg);
751
-						list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
752
-
753
-						// If the link contains the web root of this portal, then strip
754
-						// it off and keep only the name of the file that needs edition
755
-						if (strstr($link_url, '?include=')) {
756
-							$link_url = explode('?include=', $link_url);
757
-
758
-							$filename = $link_url[sizeof($link_url) - 1];
759
-
760
-							if (!strstr($filename, '/') && strstr($filename, '.html')) {
761
-								// Get oonly the contents of the link file
762
-								$link_html = @file($homep.$filename);
763
-								$link_html = implode('', $link_html);
764
-								$link_url = '';
765
-							} else {
766
-								$filename = '';
767
-							}
768
-						}
769
-						break;
770
-					}
771
-				}
772
-				break;
773
-		}//end of second switch($action) (when POST['formSent'] was not set, yet)
774
-	}// end of "else" in if($_POST['formSent']) condition
477
+                    if ($action == 'insert_link' || $action == 'insert_tabs') {
478
+                        for ($i = sizeof($home_menu); $i; $i--) {
479
+                            if ($i > $insert_where) {
480
+                                $home_menu[$i] = $home_menu[$i - 1];
481
+                            } else {
482
+                                break;
483
+                            }
484
+                        }
485
+                        $home_menu[$insert_where + 1] = '<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>';
486
+                    } else {
487
+                        // If the request is about a link edition, change the link
488
+                        $home_menu[$link_index]='<li ' . $class_add_in_tab . '><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>';
489
+                    }
490
+                    // Re-build the file from the home_menu array
491
+                    $home_menu = implode("\n", $home_menu);
492
+                    // Write
493
+                    if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
494
+                        if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
495
+                            $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
496
+                            fputs($fp, $home_menu);
497
+                            home_tabs($homep.$menuf.'_'.$lang.$ext);
498
+                            fclose($fp);
499
+
500
+                            foreach ($_languages['name'] as $key => $value) {
501
+                                $lang_name = $_languages['folder'][$key];
502
+                                if (isset($_POST[$lang_name])) {
503
+                                    $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
504
+                                    fputs($fp, $home_menu);
505
+                                    home_tabs($homep.$menuf.'_'.$lang_name.$ext);
506
+                                    fclose($fp);
507
+                                }
508
+                            }
509
+
510
+                            if (file_exists($homep.$menuf.$ext)) {
511
+                                if (is_writable($homep.$menuf.$ext)) {
512
+                                    $fpo = fopen($homep.$menuf.$ext, 'w');
513
+                                    fputs($fpo, $home_menu);
514
+                                    home_tabs($homep.$menuf.$ext);
515
+                                    fclose($fpo);
516
+                                }
517
+                            }
518
+                        } else {
519
+                            $errorMsg = get_lang('HomePageFilesNotWritable');
520
+                        }
521
+                    } else {
522
+                        //File does not exist
523
+                        $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
524
+                        fputs($fp, $home_menu);
525
+                        home_tabs($homep.$menuf.'_'.$lang.$ext);
526
+                        fclose($fp);
527
+
528
+                        foreach ($_languages['name'] as $key => $value) {
529
+                            $lang_name = $_languages['folder'][$key];
530
+                            if (isset($_POST[$lang_name])) {
531
+                                $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
532
+                                fputs($fp, $home_menu);
533
+                                home_tabs($homep.$menuf.'_'.$lang_name.$ext);
534
+                                fclose($fp);
535
+                            }
536
+                        }
537
+                    }
538
+                }
539
+                Event::addEvent(
540
+                    LOG_HOMEPAGE_CHANGED,
541
+                    $action,
542
+                    cut($link_name . ':' . $link_url, 254),
543
+                    api_get_utc_datetime(),
544
+                    api_get_user_id()
545
+                );
546
+                break;
547
+        } //end of switch($action)
548
+
549
+        if (empty($errorMsg)) {
550
+            header('Location: '.$selfUrl.'?language='.$languageGet);
551
+            exit();
552
+        }
553
+    } else {
554
+        //if POST[formSent] is not set
555
+        switch ($action) {
556
+            case 'open_link':
557
+                // Previously, filtering of GET['link'] was done here but it left
558
+                // a security threat. Filtering has now been moved outside conditions
559
+                break;
560
+            case 'delete_tabs':
561
+            case 'delete_link':
562
+                // A link is deleted by getting the file into an array, removing the
563
+                // link and re-writing the array to the file
564
+                $link_index = intval($_GET['link_index']);
565
+                $menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf;
566
+                $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
567
+                if (empty($home_menu)) {
568
+                    $home_menu = array();
569
+                }
570
+                foreach ($home_menu as $key => $enreg) {
571
+                    if ($key == $link_index) {
572
+                        unset($home_menu[$key]);
573
+                    } else {
574
+                        $home_menu[$key] = trim($enreg);
575
+                    }
576
+                }
577
+                $home_menu = implode("\n", $home_menu);
578
+                $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
579
+
580
+                $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
581
+                fputs($fp, $home_menu);
582
+                home_tabs($homep.$menuf.'_'.$lang.$ext);
583
+                fclose($fp);
584
+                if (file_exists($homep.$menuf.$ext)) {
585
+                    if (is_writable($homep.$menuf.$ext)) {
586
+                        $fpo = fopen($homep.$menuf.$ext,'w');
587
+                        fputs($fpo, $home_menu);
588
+                        home_tabs($homep.$menuf.$ext);
589
+                        fclose($fpo);
590
+                    }
591
+                }
592
+                header('Location: '.$selfUrl);
593
+                exit();
594
+                break;
595
+            case 'edit_top':
596
+                // This request is only the preparation for the update of the home_top
597
+                $home_top = '';
598
+                if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
599
+                    $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
600
+                } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
601
+                    $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
602
+                } else {
603
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
604
+                }
605
+                $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
606
+                break;
607
+            case 'edit_notice':
608
+                // This request is only the preparation for the update of the home_notice
609
+                $home_notice = '';
610
+                if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
611
+                    $home_notice = @file($homep.$noticef.'_'.$lang.$ext);
612
+                } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
613
+                    $home_notice = @file($homep.$noticef.$lang.$ext);
614
+                } else {
615
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
616
+                }
617
+                if (empty($home_notice)) {
618
+                    $home_notice = array();
619
+                }
620
+                $notice_title = strip_tags($home_notice[0]);
621
+                $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
622
+                $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
623
+                $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
624
+                break;
625
+            case 'edit_news':
626
+                // This request is the preparation for the update of the home_news page
627
+                $home_news = '';
628
+                if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
629
+                    $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
630
+                } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
631
+                    $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
632
+                } else {
633
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
634
+                }
635
+                $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
636
+                break;
637
+            case 'insert_link':
638
+                // This request is the preparation for the addition of an item in home_menu
639
+                $home_menu = '';
640
+                $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
641
+                if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
642
+                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
643
+                } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
644
+                    $home_menu = @file($homep.$menuf.$lang.$ext);
645
+                } else {
646
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
647
+                }
648
+                if (empty($home_menu)) {
649
+                    $home_menu = array();
650
+                }
651
+                if (!empty($home_menu)) {
652
+                    $home_menu = implode("\n", $home_menu);
653
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
654
+                    $home_menu = explode("\n", $home_menu);
655
+                }
656
+                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
657
+                break;
658
+            case 'insert_tabs':
659
+                // This request is the preparation for the addition of an item in home_menu
660
+                $home_menu = '';
661
+                if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
662
+                    $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
663
+                } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
664
+                    $home_menu = @file($homep.$mtloggedin.$lang.$ext);
665
+                } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) {
666
+                    $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
667
+                } else {
668
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
669
+                }
670
+                if (empty($home_menu)) {
671
+                    $home_menu = array();
672
+                }
673
+                if (!empty($home_menu)) {
674
+                    $home_menu = implode("\n", $home_menu);
675
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
676
+                    $home_menu = explode("\n", $home_menu);
677
+                }
678
+                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
679
+                break;
680
+            case 'edit_tabs':
681
+            case 'edit_link':
682
+                // This request is the preparation for the edition of the links array
683
+                $home_menu = '';
684
+                $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
685
+                if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
686
+                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
687
+                } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
688
+                    $home_menu = @file($homep.$menuf.$lang.$ext);
689
+                } else {
690
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
691
+                }
692
+
693
+                if (empty($home_menu)) {
694
+                    if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
695
+                        $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
696
+                    }
697
+                }
698
+
699
+                if (empty($home_menu)) {
700
+                    $home_menu = array();
701
+                }
702
+                if (!empty($home_menu)) {
703
+                    $home_menu = implode("\n", $home_menu);
704
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
705
+                    $home_menu = explode("\n", $home_menu);
706
+                }
707
+
708
+                $link_index = intval($_GET['link_index']);
709
+
710
+                $target_blank = false;
711
+                $link_name = '';
712
+                $link_url = '';
713
+
714
+                //$home_menu_new = array();
715
+                //
716
+                //Cleaning array
717
+                //foreach ($home_menu as $item) {
718
+                //	if(!empty($item)) {
719
+                //		$home_menu_new[] = $item;
720
+                //	}
721
+                //}
722
+                //$home_menu = $home_menu_new;
723
+
724
+                // Cleaning the array
725
+                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
726
+
727
+                // For each line of the home_menu file
728
+                foreach ($home_menu as $key => $enreg) {
729
+
730
+                    // Check if the current item is the one we want to update
731
+                    if ($key == $link_index) {
732
+                        // This is the link we want to update
733
+                        // Check if the target should be "_blank"
734
+                        if (strstr($enreg, 'target="_blank"')) {
735
+                            $target_blank = true;
736
+                        }
737
+
738
+                        if (strstr($enreg, 'hide_menu')) {
739
+                            $add_in_tab = false;
740
+                        } else {
741
+                            $add_in_tab = true;
742
+                        }
743
+
744
+                        // Remove dangerous HTML tags from the link itself (this is an
745
+                        // additional measure in case a link previously contained
746
+                        // unsecure tags)
747
+                        $link_name = strip_tags($enreg);
748
+
749
+                        // Get the contents of "href" attribute in $link_url
750
+                        $enreg = explode('href="',$enreg);
751
+                        list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
752
+
753
+                        // If the link contains the web root of this portal, then strip
754
+                        // it off and keep only the name of the file that needs edition
755
+                        if (strstr($link_url, '?include=')) {
756
+                            $link_url = explode('?include=', $link_url);
757
+
758
+                            $filename = $link_url[sizeof($link_url) - 1];
759
+
760
+                            if (!strstr($filename, '/') && strstr($filename, '.html')) {
761
+                                // Get oonly the contents of the link file
762
+                                $link_html = @file($homep.$filename);
763
+                                $link_html = implode('', $link_html);
764
+                                $link_url = '';
765
+                            } else {
766
+                                $filename = '';
767
+                            }
768
+                        }
769
+                        break;
770
+                    }
771
+                }
772
+                break;
773
+        }//end of second switch($action) (when POST['formSent'] was not set, yet)
774
+    }// end of "else" in if($_POST['formSent']) condition
775 775
 } else {
776
-	//if $action is empty, then prepare a list of the course categories to display (?)
777
-	$Categories = getCategoriesToDisplayInHomePage();
776
+    //if $action is empty, then prepare a list of the course categories to display (?)
777
+    $Categories = getCategoriesToDisplayInHomePage();
778 778
 }
779 779
 
780 780
 // Display section
@@ -782,25 +782,25 @@  discard block
 block discarded – undo
782 782
 Display::display_header($tool_name);
783 783
 
784 784
 switch ($action) {
785
-	case 'open_link':
786
-		if (!empty($link)) {
787
-			// $link is only set in case of action=open_link and is filtered
788
-			$open = @(string)file_get_contents($homep.$link);
789
-			$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
790
-			echo $open;
791
-		}
792
-		break;
793
-	case 'edit_notice':
794
-		// Display for edit_notice case
795
-		?>
785
+    case 'open_link':
786
+        if (!empty($link)) {
787
+            // $link is only set in case of action=open_link and is filtered
788
+            $open = @(string)file_get_contents($homep.$link);
789
+            $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
790
+            echo $open;
791
+        }
792
+        break;
793
+    case 'edit_notice':
794
+        // Display for edit_notice case
795
+        ?>
796 796
 		<form action="<?php echo $selfUrl; ?>?action=<?php echo $action; ?>" method="post" class="form-horizontal">
797 797
 			<legend><?php echo $tool_name; ?></legend>
798 798
 			<input type="hidden" name="formSent" value="1"/>
799 799
 			<?php
800
-			if (!empty($errorMsg)) {
801
-				Display::display_normal_message($errorMsg);
802
-			}
803
-			?>
800
+            if (!empty($errorMsg)) {
801
+                Display::display_normal_message($errorMsg);
802
+            }
803
+            ?>
804 804
                         <div class="row">
805 805
                             <div class="col-md-12">
806 806
                                 <p><?php echo get_lang('LetThoseFieldsEmptyToHideTheNotice'); ?></p>
@@ -838,170 +838,170 @@  discard block
 block discarded – undo
838 838
                         </div>
839 839
 		</form>
840 840
 		<?php
841
-		break;
842
-	case 'insert_tabs':
843
-	case 'edit_tabs':
844
-	case 'insert_link':
845
-	case 'edit_link':
846
-		$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
847
-		if (!empty($errorMsg)) {
848
-			Display::display_normal_message($errorMsg);
849
-		}
850
-		$default = array();
851
-		$form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
852
-		$renderer =& $form->defaultRenderer();
853
-
854
-		$form->addElement('header', '', $tool_name);
855
-		$form->addElement('hidden', 'formSent', '1');
856
-		$form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
857
-		$form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
858
-
859
-		$form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
860
-		if (!empty($link_name)) {
861
-			$default['link_name'] = $link_name;
862
-		}
863
-		$default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
864
-		$linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
865
-		$form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
866
-
867
-		$options = array('-1' => get_lang('FirstPlace'));
868
-
869
-		$selected = '';
870
-
871
-		if ($action == 'insert_link' || $action == 'insert_tabs') {
872
-			$add_in_tab = 1;
873
-			if (is_array($home_menu)){
874
-				foreach ($home_menu as $key => $enreg) {
875
-					if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
876
-						$options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
877
-						$formSentCheck = (!empty($_POST['formSent']) ? true : false);
878
-						$selected = $formSentCheck && $insert_where == $key ? $key : '';
879
-					}
880
-				}
881
-			}
882
-			$default['insert_link'] = $selected;
883
-			$form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
884
-		}
885
-
886
-		$target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
887
-
888
-		if ($action == 'insert_tabs' || $action == 'edit_tabs') {
889
-			$form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
890
-			$default['add_in_tab'] = $add_in_tab;
891
-		}
892
-
893
-		if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); }
894
-
895
-		if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
896
-			$default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
897
-			$form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
841
+        break;
842
+    case 'insert_tabs':
843
+    case 'edit_tabs':
844
+    case 'insert_link':
845
+    case 'edit_link':
846
+        $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
847
+        if (!empty($errorMsg)) {
848
+            Display::display_normal_message($errorMsg);
849
+        }
850
+        $default = array();
851
+        $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
852
+        $renderer =& $form->defaultRenderer();
853
+
854
+        $form->addElement('header', '', $tool_name);
855
+        $form->addElement('hidden', 'formSent', '1');
856
+        $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
857
+        $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
858
+
859
+        $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
860
+        if (!empty($link_name)) {
861
+            $default['link_name'] = $link_name;
862
+        }
863
+        $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
864
+        $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
865
+        $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
866
+
867
+        $options = array('-1' => get_lang('FirstPlace'));
868
+
869
+        $selected = '';
870
+
871
+        if ($action == 'insert_link' || $action == 'insert_tabs') {
872
+            $add_in_tab = 1;
873
+            if (is_array($home_menu)){
874
+                foreach ($home_menu as $key => $enreg) {
875
+                    if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
876
+                        $options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
877
+                        $formSentCheck = (!empty($_POST['formSent']) ? true : false);
878
+                        $selected = $formSentCheck && $insert_where == $key ? $key : '';
879
+                    }
880
+                }
881
+            }
882
+            $default['insert_link'] = $selected;
883
+            $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
884
+        }
885
+
886
+        $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
887
+
888
+        if ($action == 'insert_tabs' || $action == 'edit_tabs') {
889
+            $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
890
+            $default['add_in_tab'] = $add_in_tab;
891
+        }
892
+
893
+        if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); }
894
+
895
+        if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
896
+            $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
897
+            $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
898 898
             $form->addButtonSave(get_lang('Save'),'submit');
899 899
 
900
-		} else {
901
-			if (in_array($action, array('edit_tabs','insert_tabs'))) {
902
-				$default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
903
-				$form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
904
-			}
905
-			$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
906
-			$form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
907
-			$i = 0;
908
-			foreach ($_languages['name'] as $key => $value) {
909
-				$i++;
910
-				$lang_name = $_languages['folder'][$key];
911
-				$html_langs = '<td width="300">';
912
-				$html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
913
-				$html_langs .= '</td>';
914
-				if ($i % 5 == 0) {
915
-					$html_langs .= '</tr><tr>';
916
-				}
917
-				$form->addElement('html', $html_langs);
918
-			}
919
-			$form->addElement('html','</tr></table><br/>');
900
+        } else {
901
+            if (in_array($action, array('edit_tabs','insert_tabs'))) {
902
+                $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
903
+                $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
904
+            }
905
+            $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
906
+            $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
907
+            $i = 0;
908
+            foreach ($_languages['name'] as $key => $value) {
909
+                $i++;
910
+                $lang_name = $_languages['folder'][$key];
911
+                $html_langs = '<td width="300">';
912
+                $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
913
+                $html_langs .= '</td>';
914
+                if ($i % 5 == 0) {
915
+                    $html_langs .= '</tr><tr>';
916
+                }
917
+                $form->addElement('html', $html_langs);
918
+            }
919
+            $form->addElement('html','</tr></table><br/>');
920 920
             $form->addButtonSave(get_lang('Save'),'submit');
921
-		}
922
-
923
-		$form->setDefaults($default);
924
-		$form->display();
925
-
926
-		break;
927
-	case 'edit_top':
928
-	case 'edit_news':
929
-		if ($action == 'edit_top') {
930
-			$name = $topf;
931
-			$open = $home_top;
932
-		} else {
933
-			$name = $newsf;
934
-			$open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
935
-		}
936
-		$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
937
-
938
-		if (!empty($errorMsg)) {
939
-			Display::display_normal_message($errorMsg); //main API
940
-		}
941
-
942
-		$default = array();
943
-		$form = new FormValidator(
944
-			'configure_homepage_'.$action,
945
-			'post',
946
-			$selfUrl.'?action='.$action,
947
-			'',
948
-			array('style' => 'margin: 0px;')
949
-		);
950
-		$renderer =& $form->defaultRenderer();
951
-		$renderer->setHeaderTemplate('');
952
-		$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
953
-		$renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
954
-		$renderer->setRequiredNoteTemplate('');
955
-		$form->addElement('hidden', 'formSent', '1');
956
-
957
-		if ($action == 'edit_news') {
958
-			$_languages = api_get_languages();
959
-			$html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
960
-			$html .= '<select name="news_languages">';
961
-			$html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
962
-			foreach ($_languages['name'] as $key => $value) {
963
-				$english_name = $_languages['folder'][$key];
964
-				if ($language == $english_name) {
965
-					$html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
966
-				} else {
967
-					$html .= '<option value="'.$english_name.'">'.$value.'</option>';
968
-				}
969
-			}
970
-			$html .= '</select></td></tr>';
971
-			$form->addElement('html', $html);
972
-		}
973
-
974
-		$default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
975
-		$form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
976
-		$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
977
-		$form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
978
-
979
-		$currentLanguage = api_get_interface_language();
980
-		$i = 0;
981
-		foreach ($_languages['name'] as $key => $value) {
982
-			$lang_name = $_languages['folder'][$key];
983
-			$i++;
984
-
985
-			$checked = null;
986
-			if ($languageGet == $lang_name)  {
987
-				$checked = "checked";
988
-			}
989
-			$html_langs = '<td width="300">';
990
-			$html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
991
-			$html_langs .= '</td>';
992
-			if ($i % 5 == 0) {
993
-				$html_langs .= '</tr><tr>';
994
-			}
995
-			$form->addElement('html', $html_langs);
996
-		}
997
-		$form->addElement('html','</tr></table><br/>');
998
-		$form->addButtonSave(get_lang('Save'));
999
-		$form->setDefaults($default);
1000
-		$form->display();
1001
-
1002
-		break;
1003
-	default: // When no action applies, default page to update campus homepage
1004
-		?>
921
+        }
922
+
923
+        $form->setDefaults($default);
924
+        $form->display();
925
+
926
+        break;
927
+    case 'edit_top':
928
+    case 'edit_news':
929
+        if ($action == 'edit_top') {
930
+            $name = $topf;
931
+            $open = $home_top;
932
+        } else {
933
+            $name = $newsf;
934
+            $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
935
+        }
936
+        $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
937
+
938
+        if (!empty($errorMsg)) {
939
+            Display::display_normal_message($errorMsg); //main API
940
+        }
941
+
942
+        $default = array();
943
+        $form = new FormValidator(
944
+            'configure_homepage_'.$action,
945
+            'post',
946
+            $selfUrl.'?action='.$action,
947
+            '',
948
+            array('style' => 'margin: 0px;')
949
+        );
950
+        $renderer =& $form->defaultRenderer();
951
+        $renderer->setHeaderTemplate('');
952
+        $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
953
+        $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
954
+        $renderer->setRequiredNoteTemplate('');
955
+        $form->addElement('hidden', 'formSent', '1');
956
+
957
+        if ($action == 'edit_news') {
958
+            $_languages = api_get_languages();
959
+            $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
960
+            $html .= '<select name="news_languages">';
961
+            $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
962
+            foreach ($_languages['name'] as $key => $value) {
963
+                $english_name = $_languages['folder'][$key];
964
+                if ($language == $english_name) {
965
+                    $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
966
+                } else {
967
+                    $html .= '<option value="'.$english_name.'">'.$value.'</option>';
968
+                }
969
+            }
970
+            $html .= '</select></td></tr>';
971
+            $form->addElement('html', $html);
972
+        }
973
+
974
+        $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
975
+        $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
976
+        $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
977
+        $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
978
+
979
+        $currentLanguage = api_get_interface_language();
980
+        $i = 0;
981
+        foreach ($_languages['name'] as $key => $value) {
982
+            $lang_name = $_languages['folder'][$key];
983
+            $i++;
984
+
985
+            $checked = null;
986
+            if ($languageGet == $lang_name)  {
987
+                $checked = "checked";
988
+            }
989
+            $html_langs = '<td width="300">';
990
+            $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
991
+            $html_langs .= '</td>';
992
+            if ($i % 5 == 0) {
993
+                $html_langs .= '</tr><tr>';
994
+            }
995
+            $form->addElement('html', $html_langs);
996
+        }
997
+        $form->addElement('html','</tr></table><br/>');
998
+        $form->addButtonSave(get_lang('Save'));
999
+        $form->setDefaults($default);
1000
+        $form->display();
1001
+
1002
+        break;
1003
+    default: // When no action applies, default page to update campus homepage
1004
+        ?>
1005 1005
 
1006 1006
 <section id="page-home">
1007 1007
     <div class="row">
@@ -1157,53 +1157,53 @@  discard block
 block discarded – undo
1157 1157
             ?>
1158 1158
 
1159 1159
             <?php
1160
-		if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
1160
+        if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
1161 1161
                     $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
1162 1162
                     $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1163 1163
                     echo $open;
1164
-		} else {
1164
+        } else {
1165 1165
                     $open = @(string)file_get_contents($homep.$newsf.$ext);
1166 1166
                     $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1167 1167
                     echo $open;
1168
-		}
1168
+        }
1169 1169
             ?>
1170 1170
 
1171 1171
             <?php
1172 1172
                 // Add new page
1173
-		$home_menu = '';
1174
-		if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
1173
+        $home_menu = '';
1174
+        if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
1175 1175
                     $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
1176
-		} else {
1176
+        } else {
1177 1177
                     $home_menu = @file($homep.$mtloggedin.$ext);
1178
-		}
1179
-		if (empty($home_menu)) {
1178
+        }
1179
+        if (empty($home_menu)) {
1180 1180
                     if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
1181
-			$home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
1181
+            $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
1182 1182
                     }
1183
-		}
1184
-		if (empty($home_menu)) {
1183
+        }
1184
+        if (empty($home_menu)) {
1185 1185
                     $home_menu = array();
1186
-		}
1187
-		if (!empty($home_menu)) {
1186
+        }
1187
+        if (!empty($home_menu)) {
1188 1188
                     $home_menu = implode("\n", $home_menu);
1189 1189
                     $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
1190 1190
                     $home_menu = explode("\n", $home_menu);
1191
-		}
1192
-		$link_list = '';
1193
-		$tab_counter = 0;
1191
+        }
1192
+        $link_list = '';
1193
+        $tab_counter = 0;
1194 1194
                     foreach ($home_menu as $enreg) {
1195 1195
                     $enreg = trim($enreg);
1196
-			if (!empty($enreg)) {
1196
+            if (!empty($enreg)) {
1197 1197
                             $edit_link   = ' <a href="'.$selfUrl.'?action=edit_tabs&amp;link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.png', get_lang('Edit')).'</span></a>';
1198 1198
                             $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>';
1199 1199
                             $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'),
1200 1200
                                 array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.$delete_link.'</li>'),
1201
-				$enreg);
1201
+                $enreg);
1202 1202
                             $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string);
1203
-				$link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
1204
-				$tab_counter++;
1205
-			}
1206
-		}
1203
+                $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
1204
+                $tab_counter++;
1205
+            }
1206
+        }
1207 1207
             ?>
1208 1208
             <div class="actions">
1209 1209
 		<a href="<?php echo $selfUrl; ?>?action=insert_tabs">
@@ -1211,9 +1211,9 @@  discard block
 block discarded – undo
1211 1211
                 </a>
1212 1212
             </div>
1213 1213
             <?php
1214
-		echo '<ul id="list-hiperlink" class="list-group">';
1215
-		echo $link_list;
1216
-		echo '</ul>';
1214
+        echo '<ul id="list-hiperlink" class="list-group">';
1215
+        echo $link_list;
1216
+        echo '</ul>';
1217 1217
             ?>
1218 1218
         </div>
1219 1219
     </div>
Please login to merge, or discard this patch.
custompages/language.inc.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
     krsort($langs, SORT_NUMERIC);
30 30
     // Choosing the best match
31 31
     foreach($langs as $weight => $codes) {
32
-		foreach ($codes as $code) {
33
-        	if (in_array($code, $available_langs)) {
34
-            	return $code;
35
-        	}
36
-		}
32
+        foreach ($codes as $code) {
33
+            if (in_array($code, $available_langs)) {
34
+                return $code;
35
+            }
36
+        }
37 37
     }
38 38
     // No match
39 39
     return null;
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
  * use this if you want to avoid translation caching issues
45 45
  */
46 46
 function cp_get_lang($variable) {
47
-	return get_lang($variable, null, $_SESSION['user_language_choice']);
47
+    return get_lang($variable, null, $_SESSION['user_language_choice']);
48 48
 }
49 49
 /**
50 50
  * Code
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 
64 64
 // Chamilo overrides this parameters at some places, e.g. in the logout link
65 65
 if (isset($_REQUEST['language']) && !empty($_REQUEST['language']) && in_array($_REQUEST['language'], $chamilo_langs)) {
66
-	$lang_match = $_REQUEST['language'];
66
+    $lang_match = $_REQUEST['language'];
67 67
 }
68 68
 
69 69
 // Maybe a language had already been selected, we should honor this
70 70
 if (isset($_SESSION['user_language_choice']) && in_array($_SESSION['user_language_choice'], $chamilo_langs)) {
71
-	$lang_match = $_SESSION['user_language_choice'];
71
+    $lang_match = $_SESSION['user_language_choice'];
72 72
 }
73 73
 
74 74
 // We need to set the relevant session variables to the best match, to use Chamilo's i18n lib.
Please login to merge, or discard this patch.
custompages/first_login-dist.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * Security checks
15 15
  */
16 16
 if (! isset($_SESSION['conditional_login']['uid']))
17
-  die("Not Authorised");
17
+    die("Not Authorised");
18 18
 
19 19
 if (isset($_POST['password'])) {
20 20
     $u = api_get_user_info($_SESSION['conditional_login']['uid']);
@@ -27,26 +27,26 @@  discard block
 block discarded – undo
27 27
         exit();
28 28
     }
29 29
     $password = $_POST['password'];
30
-	$updated = UserManager::update_user(
31
-		$u['user_id'],
32
-		$u['firstname'],
33
-		$u['lastname'],
34
-		$u['username'],
35
-		$password,
36
-		$u['auth_source'],
37
-		$u['email'],
38
-		$u['status'],
39
-		$u['official_code'],
40
-		$u['phone'],
41
-		$u['picture_uri'],
42
-		$u['expiration_date'],
43
-		$u['active'],
44
-		$u['creator_id'],
45
-		$u['hr_dept_id'],
46
-		null,
47
-		$u['language'],
48
-		''
49
-	);
30
+    $updated = UserManager::update_user(
31
+        $u['user_id'],
32
+        $u['firstname'],
33
+        $u['lastname'],
34
+        $u['username'],
35
+        $password,
36
+        $u['auth_source'],
37
+        $u['email'],
38
+        $u['status'],
39
+        $u['official_code'],
40
+        $u['phone'],
41
+        $u['picture_uri'],
42
+        $u['expiration_date'],
43
+        $u['active'],
44
+        $u['creator_id'],
45
+        $u['hr_dept_id'],
46
+        null,
47
+        $u['language'],
48
+        ''
49
+    );
50 50
 
51 51
     if ($updated !== false) {
52 52
         UserManager::update_extra_field_value($u['user_id'], 'already_logged_in', 'true');
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 		<div id="changepassword-form-box" class="form-box">
105 105
       <div class="info"> <?php echo custompages_get_lang('FirstLoginChangePassword');?> </div>
106 106
 		<?php if (isset($error_message)) {
107
-			echo '<div id="changepassword-form-error" class="form-error">'.$error_message.'</div>';
108
-		}?>
107
+            echo '<div id="changepassword-form-error" class="form-error">'.$error_message.'</div>';
108
+        }?>
109 109
 			<form id="changepassword-form" class="form" method="post">
110 110
 				<div>
111 111
           <label for="password">*<?php echo custompages_get_lang('Password');?></label>
Please login to merge, or discard this patch.
custompages/language.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -9,30 +9,30 @@  discard block
 block discarded – undo
9 9
  * Get the preferred language base on the browser headers
10 10
  */
11 11
 function get_preferred_language($available_langs) {
12
-	$langs = array();
13
-	foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $httplang) {
14
-		$rawlang = explode(';q=', $httplang);
15
-		if (strpos($rawlang[0], '-') !== FALSE) {
16
-			$rawlang[0] = substr($rawlang[0], 0, strpos($rawlang[0], '-'));
17
-		}
18
-		if (count($rawlang) == 1) {
19
-			$rawlang[1] = 1.0;
20
-		}
21
-		$langs[$rawlang[1]] = $rawlang[0];
22
-	}
23
-	krsort($langs, SORT_NUMERIC);
24
-	foreach($langs as $weight => $code) {
25
-		if (in_array($code, $available_langs)) {
26
-			return $code;
27
-		}
28
-	}
29
-	return null;
12
+    $langs = array();
13
+    foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $httplang) {
14
+        $rawlang = explode(';q=', $httplang);
15
+        if (strpos($rawlang[0], '-') !== FALSE) {
16
+            $rawlang[0] = substr($rawlang[0], 0, strpos($rawlang[0], '-'));
17
+        }
18
+        if (count($rawlang) == 1) {
19
+            $rawlang[1] = 1.0;
20
+        }
21
+        $langs[$rawlang[1]] = $rawlang[0];
22
+    }
23
+    krsort($langs, SORT_NUMERIC);
24
+    foreach($langs as $weight => $code) {
25
+        if (in_array($code, $available_langs)) {
26
+            return $code;
27
+        }
28
+    }
29
+    return null;
30 30
 }
31 31
 /**
32 32
  * Get a language variable in a specific language
33 33
  */
34 34
 function custompages_get_lang($variable) {
35
-	return get_lang($variable, null, $_SESSION['user_language_choice']);
35
+    return get_lang($variable, null, $_SESSION['user_language_choice']);
36 36
 }
37 37
 
38 38
 $available_langs = array('en', 'fr', 'es', 'gl', 'eu');
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
 $lang_match = $chamilo_langs[get_preferred_language($available_langs)];
50 50
 // recover previous value ...
51 51
 if (isset($_SESSION['user_language_choice']))
52
-	$lang_match = $_SESSION['user_language_choice'];
52
+    $lang_match = $_SESSION['user_language_choice'];
53 53
 
54 54
 // Chamilo parameter, on logout
55 55
 if (isset($_REQUEST['language']) && !empty($_REQUEST['language']) && in_array($_REQUEST['language'], $chamilo_langs)) {
56
-	$lang_match = $_REQUEST['language'];
56
+    $lang_match = $_REQUEST['language'];
57 57
 }
58 58
 // Incoming link parameter
59 59
 if (isset($_REQUEST['lang']) && !empty($_REQUEST['lang']) && in_array($_REQUEST['lang'], $available_langs)) {
60
-	$lang_match = $chamilo_langs[$_REQUEST['lang']];
60
+    $lang_match = $chamilo_langs[$_REQUEST['lang']];
61 61
 }
62 62
 
63 63
 $detect = api_get_setting('auto_detect_language_custom_pages');
Please login to merge, or discard this patch.