Completed
Push — 1.10.x ( 5d5324...cf3164 )
by Julito
60:26
created
main/inc/lib/dashboard.lib.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -249,283 +249,283 @@
 block discarded – undo
249 249
         return $affected_rows;
250 250
     }
251 251
 
252
-	/**
253
-	 * Get all plugins path inside dashboard directory
254
-	 * @return array name plugins directories
255
-	 */
256
-	public static function getPossibleDashboardPluginsPath()
252
+    /**
253
+     * Get all plugins path inside dashboard directory
254
+     * @return array name plugins directories
255
+     */
256
+    public static function getPossibleDashboardPluginsPath()
257 257
     {
258
-		// get all plugins path inside plugin directory
259
-		/* We scan the plugin directory. Each folder is a potential plugin. */
260
-		$possiblePlugins = array();
261
-		$dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH).'dashboard/';
262
-		$handle = @opendir($dashboard_pluginpath);
263
-		while (false !== ($file = readdir($handle))) {
264
-			if ($file <> '.' AND $file <> '..' AND is_dir($dashboard_pluginpath.$file)) {
265
-				$possiblePlugins[] = $file;
266
-			}
267
-		}
268
-		@closedir($handle);
269
-
270
-		return $possiblePlugins;
271
-	}
272
-
273
-	/**
274
-	 * Get all blocks data without plugin directory
275
-	 * @return array Block data
276
-	 */
277
-	public static function get_block_data_without_plugin()
258
+        // get all plugins path inside plugin directory
259
+        /* We scan the plugin directory. Each folder is a potential plugin. */
260
+        $possiblePlugins = array();
261
+        $dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH).'dashboard/';
262
+        $handle = @opendir($dashboard_pluginpath);
263
+        while (false !== ($file = readdir($handle))) {
264
+            if ($file <> '.' AND $file <> '..' AND is_dir($dashboard_pluginpath.$file)) {
265
+                $possiblePlugins[] = $file;
266
+            }
267
+        }
268
+        @closedir($handle);
269
+
270
+        return $possiblePlugins;
271
+    }
272
+
273
+    /**
274
+     * Get all blocks data without plugin directory
275
+     * @return array Block data
276
+     */
277
+    public static function get_block_data_without_plugin()
278 278
     {
279
-		$tbl_block = Database :: get_main_table(TABLE_MAIN_BLOCK);
280
-		$possibleplugins = self::getPossibleDashboardPluginsPath();
281
-
282
-		// We check if plugin exists inside directory for updating active field
283
-		$sql = "SELECT * FROM $tbl_block";
284
-		$rs = Database::query($sql);
285
-		if (Database::num_rows($rs) > 0){
286
-			while ($row = Database::fetch_array($rs)) {
287
-				$path = $row['path'];
288
-				if (!in_array($row['path'],$possibleplugins)) {
289
-					$active = 0;
290
-				} else {
291
-					$active = 1;
292
-				}
293
-				// update active
294
-				$upd = "UPDATE $tbl_block SET active = '$active'
279
+        $tbl_block = Database :: get_main_table(TABLE_MAIN_BLOCK);
280
+        $possibleplugins = self::getPossibleDashboardPluginsPath();
281
+
282
+        // We check if plugin exists inside directory for updating active field
283
+        $sql = "SELECT * FROM $tbl_block";
284
+        $rs = Database::query($sql);
285
+        if (Database::num_rows($rs) > 0){
286
+            while ($row = Database::fetch_array($rs)) {
287
+                $path = $row['path'];
288
+                if (!in_array($row['path'],$possibleplugins)) {
289
+                    $active = 0;
290
+                } else {
291
+                    $active = 1;
292
+                }
293
+                // update active
294
+                $upd = "UPDATE $tbl_block SET active = '$active'
295 295
 				        WHERE path = '".$row['path']."'";
296
-				Database::query($upd);
297
-			}
298
-		}
299
-
300
-		// get disabled block data
301
-		$block_data = array();
302
-		$sql = "SELECT * FROM $tbl_block WHERE active = 0";
303
-		$rs_block = Database::query($sql);
304
-		if (Database::num_rows($rs_block) > 0) {
305
-			while ($row_block = Database::fetch_array($rs_block)) {
306
-				$block_data[] = $row_block;
307
-			}
308
-		}
309
-
310
-		return $block_data;
311
-
312
-	}
313
-
314
-	/**
315
-	 * get data about enabled dashboard block (stored insise block table)
316
-	 * @param  string	plugin path
317
-	 * @return array 	data
318
-	 */
319
-	public static function get_enabled_dashboard_blocks($path = '')
296
+                Database::query($upd);
297
+            }
298
+        }
299
+
300
+        // get disabled block data
301
+        $block_data = array();
302
+        $sql = "SELECT * FROM $tbl_block WHERE active = 0";
303
+        $rs_block = Database::query($sql);
304
+        if (Database::num_rows($rs_block) > 0) {
305
+            while ($row_block = Database::fetch_array($rs_block)) {
306
+                $block_data[] = $row_block;
307
+            }
308
+        }
309
+
310
+        return $block_data;
311
+
312
+    }
313
+
314
+    /**
315
+     * get data about enabled dashboard block (stored insise block table)
316
+     * @param  string	plugin path
317
+     * @return array 	data
318
+     */
319
+    public static function get_enabled_dashboard_blocks($path = '')
320 320
     {
321
-		$tbl_block = Database :: get_main_table(TABLE_MAIN_BLOCK);
322
-		$condition_path = '';
323
-		if (!empty($path)) {
324
-			$path = Database::escape_string($path);
325
-			$condition_path = ' AND path = "'.$path.'" ';
326
-		}
327
-
328
-		$sql = "SELECT * FROM $tbl_block WHERE active = 1 $condition_path ";
329
-		$rs  = Database::query($sql);
330
-		$block_data = array();
331
-		if (Database::num_rows($rs) > 0) {
332
-			while ($row = Database::fetch_array($rs)) {
333
-				$block_data[$row['path']] = $row;
334
-			}
335
-		}
336
-		return $block_data;
337
-	}
338
-
339
-	/**
340
-	 * display user dashboard list
341
-	 * @param int  User id
342
-	 * @return void
343
-	 */
344
-	public static function display_user_dashboard_list($user_id)
321
+        $tbl_block = Database :: get_main_table(TABLE_MAIN_BLOCK);
322
+        $condition_path = '';
323
+        if (!empty($path)) {
324
+            $path = Database::escape_string($path);
325
+            $condition_path = ' AND path = "'.$path.'" ';
326
+        }
327
+
328
+        $sql = "SELECT * FROM $tbl_block WHERE active = 1 $condition_path ";
329
+        $rs  = Database::query($sql);
330
+        $block_data = array();
331
+        if (Database::num_rows($rs) > 0) {
332
+            while ($row = Database::fetch_array($rs)) {
333
+                $block_data[$row['path']] = $row;
334
+            }
335
+        }
336
+        return $block_data;
337
+    }
338
+
339
+    /**
340
+     * display user dashboard list
341
+     * @param int  User id
342
+     * @return void
343
+     */
344
+    public static function display_user_dashboard_list($user_id)
345 345
     {
346
-		$enabled_dashboard_plugins = self::get_enabled_dashboard_blocks();
347
-		$user_block_data = self::get_user_block_data($user_id);
348
-
349
-		if (count($enabled_dashboard_plugins) > 0) {
350
-			echo '<div style="margin-top:20px">';
351
-			echo '<div><strong>'.get_lang('SelectBlockForDisplayingInsideBlocksDashboardView').'</strong></div><br />';
352
-			echo '<form name="dashboard_list" method="post" action="index.php?action=store_user_block">';
353
-			echo '<table class="data_table">';
354
-			echo '<tr>';
355
-			echo '<th width="5%">';
356
-			echo get_lang('Enabled');
357
-			echo '</th>';
358
-			echo '<th width="30%">';
359
-			echo get_lang('Name');
360
-			echo '</th>';
361
-			echo '<th width="40%">';
362
-			echo get_lang('Description');
363
-			echo '</th>';
364
-			echo '<th>';
365
-			echo get_lang('ColumnPosition');
366
-			echo '</th>';
367
-			echo '</tr>';
368
-
369
-			// We display all enabled plugins and the checkboxes
370
-			foreach ($enabled_dashboard_plugins as $block) {
371
-
372
-				$path = $block['path'];
373
-				$controller_class = $block['controller'];
374
-				$filename_controller = $path.'.class.php';
375
-				$dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
376
-				require_once $dashboard_plugin_path.$filename_controller;
377
-				if (class_exists($controller_class)) {
378
-					$obj_block = new $controller_class($user_id);
379
-
380
-					// check if user is allowed to see the block
381
-					if (method_exists($obj_block, 'is_block_visible_for_user')) {
382
-						$is_block_visible_for_user = $obj_block->is_block_visible_for_user($user_id);
383
-						if (!$is_block_visible_for_user) continue;
384
-					}
385
-
386
-					echo '<tr>';
387
-					// checkboxes
388
-					self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
389
-					echo '<td>'.$block['name'].'</td>';
390
-					echo '<td>'.$block['description'].'</td>';
391
-					echo '<td>
346
+        $enabled_dashboard_plugins = self::get_enabled_dashboard_blocks();
347
+        $user_block_data = self::get_user_block_data($user_id);
348
+
349
+        if (count($enabled_dashboard_plugins) > 0) {
350
+            echo '<div style="margin-top:20px">';
351
+            echo '<div><strong>'.get_lang('SelectBlockForDisplayingInsideBlocksDashboardView').'</strong></div><br />';
352
+            echo '<form name="dashboard_list" method="post" action="index.php?action=store_user_block">';
353
+            echo '<table class="data_table">';
354
+            echo '<tr>';
355
+            echo '<th width="5%">';
356
+            echo get_lang('Enabled');
357
+            echo '</th>';
358
+            echo '<th width="30%">';
359
+            echo get_lang('Name');
360
+            echo '</th>';
361
+            echo '<th width="40%">';
362
+            echo get_lang('Description');
363
+            echo '</th>';
364
+            echo '<th>';
365
+            echo get_lang('ColumnPosition');
366
+            echo '</th>';
367
+            echo '</tr>';
368
+
369
+            // We display all enabled plugins and the checkboxes
370
+            foreach ($enabled_dashboard_plugins as $block) {
371
+
372
+                $path = $block['path'];
373
+                $controller_class = $block['controller'];
374
+                $filename_controller = $path.'.class.php';
375
+                $dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
376
+                require_once $dashboard_plugin_path.$filename_controller;
377
+                if (class_exists($controller_class)) {
378
+                    $obj_block = new $controller_class($user_id);
379
+
380
+                    // check if user is allowed to see the block
381
+                    if (method_exists($obj_block, 'is_block_visible_for_user')) {
382
+                        $is_block_visible_for_user = $obj_block->is_block_visible_for_user($user_id);
383
+                        if (!$is_block_visible_for_user) continue;
384
+                    }
385
+
386
+                    echo '<tr>';
387
+                    // checkboxes
388
+                    self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
389
+                    echo '<td>'.$block['name'].'</td>';
390
+                    echo '<td>'.$block['description'].'</td>';
391
+                    echo '<td>
392 392
                             <select class="selectpicker show-tick form-control" name="columns['.$block['id'].']">
393 393
                             <option value="1" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column']==1?'selected':'').' >1</option>
394 394
                             <option value="2" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column']==2?'selected':'').' >2</option>
395 395
                             </select>
396 396
                           </td>';
397
-					echo '</tr>';
398
-				} else {
399
-					echo Display::tag('tr',  Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
400
-				}
401
-			}
402
-
403
-			echo '</table>';
404
-			echo '<div class="row"><div class="col-md-12">';
405
-			echo '<button class="btn btn-default" type="submit" name="submit_dashboard_list" value="'.get_lang('EnableDashboardBlock').'"><em class="fa fa-check-square"></em> '.
397
+                    echo '</tr>';
398
+                } else {
399
+                    echo Display::tag('tr',  Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
400
+                }
401
+            }
402
+
403
+            echo '</table>';
404
+            echo '<div class="row"><div class="col-md-12">';
405
+            echo '<button class="btn btn-default" type="submit" name="submit_dashboard_list" value="'.get_lang('EnableDashboardBlock').'"><em class="fa fa-check-square"></em> '.
406 406
                 get_lang('EnableDashboardBlock').'</button></form>';
407
-			echo '</div></div>';
408
-		} else {
409
-			echo '<div style="margin-top:20px">'.get_lang('ThereAreNoEnabledDashboardPlugins').'</div>';
410
-			if (api_is_platform_admin()) {
411
-				echo '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'.
407
+            echo '</div></div>';
408
+        } else {
409
+            echo '<div style="margin-top:20px">'.get_lang('ThereAreNoEnabledDashboardPlugins').'</div>';
410
+            if (api_is_platform_admin()) {
411
+                echo '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'.
412 412
                     get_lang('ConfigureDashboardPlugin').'</a>';
413
-			}
414
-		}
415
-	}
416
-
417
-	/**
418
-	 * display checkboxes for user dashboard list
419
-	 * @param int 	User id
420
-	 * @param int	Block id
421
-	 * @return void
422
-	 */
423
-	public static function display_user_dashboard_list_checkboxes($user_id, $block_id) {
424
-
425
-		$user_id = intval($user_id);
426
-		$user_block_data = self::get_user_block_data($user_id);
427
-		$enabled_blocks_id = array_keys($user_block_data);
428
-
429
-		$checked = '';
430
-		if (in_array($block_id, $enabled_blocks_id)) {
431
-			$checked = "checked";
432
-		}
433
-
434
-		echo "<td align=\"center\">";
435
-		echo '<input type="checkbox" name="enabled_blocks['.$block_id.']" value="true" '.$checked.'/>';
436
-		echo "</td>";
437
-	}
438
-
439
-	/**
440
-	 * This function store enabled blocks id with its column position (block_id1:colum;block_id2:colum; ...) inside extra user fields
441
-	 * @param int User id
442
-	 * @param array selected blocks
443
-	 * @param array columns position
444
-	 * @return bool
445
-	 */
446
-	public static function store_user_blocks($user_id, $enabled_blocks, $columns) {
447
-		$selected_blocks_id  = array();
448
-		if (is_array($enabled_blocks) && count($enabled_blocks) > 0) {
449
-			$selected_blocks_id = array_keys($enabled_blocks);
450
-		}
451
-
452
-		// build data for storing inside extra user field
453
-		$fname = 'dashboard';
454
-		$fvalue = array();
455
-		foreach ($selected_blocks_id as $block_id) {
456
-			$fvalue[] = $block_id.':'.$columns[$block_id];
457
-		}
413
+            }
414
+        }
415
+    }
416
+
417
+    /**
418
+     * display checkboxes for user dashboard list
419
+     * @param int 	User id
420
+     * @param int	Block id
421
+     * @return void
422
+     */
423
+    public static function display_user_dashboard_list_checkboxes($user_id, $block_id) {
424
+
425
+        $user_id = intval($user_id);
426
+        $user_block_data = self::get_user_block_data($user_id);
427
+        $enabled_blocks_id = array_keys($user_block_data);
428
+
429
+        $checked = '';
430
+        if (in_array($block_id, $enabled_blocks_id)) {
431
+            $checked = "checked";
432
+        }
433
+
434
+        echo "<td align=\"center\">";
435
+        echo '<input type="checkbox" name="enabled_blocks['.$block_id.']" value="true" '.$checked.'/>';
436
+        echo "</td>";
437
+    }
438
+
439
+    /**
440
+     * This function store enabled blocks id with its column position (block_id1:colum;block_id2:colum; ...) inside extra user fields
441
+     * @param int User id
442
+     * @param array selected blocks
443
+     * @param array columns position
444
+     * @return bool
445
+     */
446
+    public static function store_user_blocks($user_id, $enabled_blocks, $columns) {
447
+        $selected_blocks_id  = array();
448
+        if (is_array($enabled_blocks) && count($enabled_blocks) > 0) {
449
+            $selected_blocks_id = array_keys($enabled_blocks);
450
+        }
451
+
452
+        // build data for storing inside extra user field
453
+        $fname = 'dashboard';
454
+        $fvalue = array();
455
+        foreach ($selected_blocks_id as $block_id) {
456
+            $fvalue[] = $block_id.':'.$columns[$block_id];
457
+        }
458 458
         $upd_extra_field = UserManager::update_extra_field_value(
459 459
             $user_id,
460 460
             $fname,
461 461
             $fvalue
462 462
         );
463 463
 
464
-		return $upd_extra_field;
464
+        return $upd_extra_field;
465 465
 
466
-	}
466
+    }
467 467
 
468
-	/**
469
-	 * This function get user block data (block id with its number of column) from extra user data
470
-	 * @param int  		User id
471
-	 * @return array  	data (block_id,column)
472
-	 */
473
-	public static function get_user_block_data($user_id)
468
+    /**
469
+     * This function get user block data (block id with its number of column) from extra user data
470
+     * @param int  		User id
471
+     * @return array  	data (block_id,column)
472
+     */
473
+    public static function get_user_block_data($user_id)
474 474
     {
475
-		$user_id = intval($user_id);
476
-		$field_variable = 'dashboard';
477
-		$extra_user_data = UserManager::get_extra_user_data_by_field($user_id, $field_variable);
478
-		$extra_user_data = explode(';',$extra_user_data[$field_variable]);
479
-		$data = array();
480
-		foreach ($extra_user_data as $extra) {
481
-			$split_extra = explode(':',$extra);
482
-			if (!empty($split_extra)) {
483
-				$block_id = $split_extra[0];
484
-				$column = isset($split_extra[1]) ? $split_extra[1] : null;
485
-				$data[$block_id] = array('block_id' => $block_id, 'column' => $column);
486
-			}
487
-		}
488
-
489
-		return $data;
490
-	}
491
-
492
-	/**
493
-	 * This function update extra user blocks data after closing a dashboard block
494
-	 * @param int 		User id
495
-	 * @param string	plugin path
496
-	 * @param integer $user_id
497
-	 * @return bool
498
-	 */
499
-	public static function close_user_block($user_id, $path)
475
+        $user_id = intval($user_id);
476
+        $field_variable = 'dashboard';
477
+        $extra_user_data = UserManager::get_extra_user_data_by_field($user_id, $field_variable);
478
+        $extra_user_data = explode(';',$extra_user_data[$field_variable]);
479
+        $data = array();
480
+        foreach ($extra_user_data as $extra) {
481
+            $split_extra = explode(':',$extra);
482
+            if (!empty($split_extra)) {
483
+                $block_id = $split_extra[0];
484
+                $column = isset($split_extra[1]) ? $split_extra[1] : null;
485
+                $data[$block_id] = array('block_id' => $block_id, 'column' => $column);
486
+            }
487
+        }
488
+
489
+        return $data;
490
+    }
491
+
492
+    /**
493
+     * This function update extra user blocks data after closing a dashboard block
494
+     * @param int 		User id
495
+     * @param string	plugin path
496
+     * @param integer $user_id
497
+     * @return bool
498
+     */
499
+    public static function close_user_block($user_id, $path)
500 500
     {
501
-		$enabled_dashboard_blocks = self::get_enabled_dashboard_blocks($path);
502
-		$user_block_data = self::get_user_block_data($user_id);
503
-
504
-		foreach ($enabled_dashboard_blocks as $enabled_block) {
505
-			unset($user_block_data[$enabled_block['id']]);
506
-		}
507
-
508
-		// get columns and blocks id for updating extra user data
509
-		$columns = array();
510
-		$user_blocks_id = array();
511
-		foreach ($user_block_data as $data) {
512
-			$user_blocks_id[$data['block_id']] = true;
513
-			$columns[$data['block_id']] = $data['column'];
514
-		}
515
-
516
-		// update extra user blocks data
517
-		$upd_extra_field = self::store_user_blocks($user_id, $user_blocks_id, $columns);
518
-
519
-		return $upd_extra_field;
520
-	}
521
-
522
-	/**
523
-	 * get links for styles from dashboard plugins
524
-	 * @return string   links
525
-	 */
526
-	public static function get_links_for_styles_from_dashboard_plugins() {
527
-
528
-		return '<link rel="stylesheet" href="'.api_get_path(WEB_PLUGIN_PATH).'dashboard/css/default.css" type="text/css" />'.PHP_EOL;
529
-	}
501
+        $enabled_dashboard_blocks = self::get_enabled_dashboard_blocks($path);
502
+        $user_block_data = self::get_user_block_data($user_id);
503
+
504
+        foreach ($enabled_dashboard_blocks as $enabled_block) {
505
+            unset($user_block_data[$enabled_block['id']]);
506
+        }
507
+
508
+        // get columns and blocks id for updating extra user data
509
+        $columns = array();
510
+        $user_blocks_id = array();
511
+        foreach ($user_block_data as $data) {
512
+            $user_blocks_id[$data['block_id']] = true;
513
+            $columns[$data['block_id']] = $data['column'];
514
+        }
515
+
516
+        // update extra user blocks data
517
+        $upd_extra_field = self::store_user_blocks($user_id, $user_blocks_id, $columns);
518
+
519
+        return $upd_extra_field;
520
+    }
521
+
522
+    /**
523
+     * get links for styles from dashboard plugins
524
+     * @return string   links
525
+     */
526
+    public static function get_links_for_styles_from_dashboard_plugins() {
527
+
528
+        return '<link rel="stylesheet" href="'.api_get_path(WEB_PLUGIN_PATH).'dashboard/css/default.css" type="text/css" />'.PHP_EOL;
529
+    }
530 530
 
531 531
 }
Please login to merge, or discard this patch.
main/inc/lib/blog.lib.php 1 patch
Indentation   +1823 added lines, -1824 removed lines patch added patch discarded remove patch
@@ -6,112 +6,111 @@  discard block
 block discarded – undo
6 6
  *
7 7
  * Contains several functions dealing with displaying,
8 8
  * editing,... of a blog
9
-
10 9
  * @package chamilo.blogs
11 10
  * @author Toon Keppens <[email protected]>
12 11
  * @author Julio Montoya - Cleaning code
13 12
  */
14 13
 class Blog
15 14
 {
16
-	/**
17
-	 * Get the title of a blog
18
-	 * @author Toon Keppens
19
-	 *
20
-	 * @param int $blog_id
21
-	 *
22
-	 * @return String Blog Title
23
-	 */
24
-	public static function get_blog_title ($blog_id)
25
-	{
26
-	    $course_id = api_get_course_int_id();
27
-
28
-		if (is_numeric($blog_id)) {
29
-			$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
30
-
31
-			$sql = "SELECT blog_name
15
+    /**
16
+     * Get the title of a blog
17
+     * @author Toon Keppens
18
+     *
19
+     * @param int $blog_id
20
+     *
21
+     * @return String Blog Title
22
+     */
23
+    public static function get_blog_title ($blog_id)
24
+    {
25
+        $course_id = api_get_course_int_id();
26
+
27
+        if (is_numeric($blog_id)) {
28
+            $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
29
+
30
+            $sql = "SELECT blog_name
32 31
 					FROM " . $tbl_blogs . "
33 32
 					WHERE c_id = $course_id AND blog_id = " . intval($blog_id);
34 33
 
35
-			$result = Database::query($sql);
36
-			$blog = Database::fetch_array($result);
37
-
38
-			return stripslashes($blog['blog_name']);
39
-		}
40
-	}
41
-
42
-
43
-	/**
44
-	 * Get the description of a blog
45
-	 * @author Toon Keppens
46
-	 *
47
-	 * @param Integer $blog_id
48
-	 *
49
-	 * @return String Blog description
50
-	 */
51
-	public static function get_blog_subtitle($blog_id)
52
-	{
53
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
54
-	  	$course_id = api_get_course_int_id();
55
-		$sql = "SELECT blog_subtitle FROM $tbl_blogs
34
+            $result = Database::query($sql);
35
+            $blog = Database::fetch_array($result);
36
+
37
+            return stripslashes($blog['blog_name']);
38
+        }
39
+    }
40
+
41
+
42
+    /**
43
+     * Get the description of a blog
44
+     * @author Toon Keppens
45
+     *
46
+     * @param Integer $blog_id
47
+     *
48
+     * @return String Blog description
49
+     */
50
+    public static function get_blog_subtitle($blog_id)
51
+    {
52
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
53
+            $course_id = api_get_course_int_id();
54
+        $sql = "SELECT blog_subtitle FROM $tbl_blogs
56 55
 				WHERE c_id = $course_id AND blog_id ='".intval($blog_id)."'";
57
-		$result = Database::query($sql);
58
-		$blog = Database::fetch_array($result);
59
-
60
-		return stripslashes($blog['blog_subtitle']);
61
-	}
62
-
63
-	/**
64
-	 * Get the users of a blog
65
-	 * @author Toon Keppens
66
-	 *
67
-	 * @param Integer $blog_id
68
-	 *
69
-	 * @return Array Returns an array with [userid]=>[username]
70
-	 */
71
-	public static function get_blog_users($blog_id)
72
-	{
73
-		// Database table definitions
74
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
75
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
76
-
77
-		$course_id = api_get_course_int_id();
78
-
79
-		// Get blog members
80
-		$sql = "SELECT user.user_id, user.firstname, user.lastname
56
+        $result = Database::query($sql);
57
+        $blog = Database::fetch_array($result);
58
+
59
+        return stripslashes($blog['blog_subtitle']);
60
+    }
61
+
62
+    /**
63
+     * Get the users of a blog
64
+     * @author Toon Keppens
65
+     *
66
+     * @param Integer $blog_id
67
+     *
68
+     * @return Array Returns an array with [userid]=>[username]
69
+     */
70
+    public static function get_blog_users($blog_id)
71
+    {
72
+        // Database table definitions
73
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
74
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
75
+
76
+        $course_id = api_get_course_int_id();
77
+
78
+        // Get blog members
79
+        $sql = "SELECT user.user_id, user.firstname, user.lastname
81 80
 				FROM " . $tbl_blogs_rel_user . " blogs_rel_user
82 81
 				INNER JOIN " . $tbl_users . " user
83 82
 				ON blogs_rel_user.user_id = user.user_id
84 83
 				WHERE
85 84
 				    blogs_rel_user.c_id = $course_id AND
86 85
 					blogs_rel_user.blog_id = '" . (int)$blog_id."'";
87
-		$result = Database::query($sql);
88
-		$blog_members = array ();
89
-		while($user = Database::fetch_array($result)) {
90
-			$blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
91
-		}
92
-
93
-		return $blog_members;
94
-	}
95
-
96
-	/**
97
-	 * Creates a new blog in the given course
98
-	 * @author Toon Keppens
99
-	 * @param string $title
100
-	 */
101
-	public static function create_blog($title, $subtitle)
102
-	{
103
-		$_user = api_get_user_info();
86
+        $result = Database::query($sql);
87
+        $blog_members = array ();
88
+        while($user = Database::fetch_array($result)) {
89
+            $blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
90
+        }
91
+
92
+        return $blog_members;
93
+    }
94
+
95
+    /**
96
+     * Creates a new blog in the given course
97
+     * @author Toon Keppens
98
+     * @param string $title
99
+     */
100
+    public static function create_blog($title, $subtitle)
101
+    {
102
+        $_user = api_get_user_info();
104 103
         $course_id = api_get_course_int_id();
105 104
 
106
-		$current_date=date('Y-m-d H:i:s',time());
107
-		$session_id = api_get_session_id();
108
-		// Tabel definitions
105
+        $current_date=date('Y-m-d H:i:s',time());
106
+        $session_id = api_get_session_id();
107
+        // Tabel definitions
109 108
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
110 109
         $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
111 110
         $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
112 111
 
113
-		//verified if exist blog
114
-		$sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
112
+        //verified if exist blog
113
+        $sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
115 114
 			  	WHERE
116 115
 			  	    c_id = '.$course_id.' AND
117 116
 			  	    blog_name="'.Database::escape_string($title).'" AND
@@ -120,9 +119,9 @@  discard block
 block discarded – undo
120 119
         $info_count = Database::result($res, 0, 0);
121 120
 
122 121
         if ($info_count == 0) {
123
-			// Create the blog
122
+            // Create the blog
124 123
             $params = [
125
-				'blog_id' => 0,
124
+                'blog_id' => 0,
126 125
                 'c_id' => $course_id,
127 126
                 'blog_name' => $title,
128 127
                 'blog_subtitle' =>  $subtitle,
@@ -130,14 +129,14 @@  discard block
 block discarded – undo
130 129
                 'visibility' => 1 ,
131 130
                 'session_id' => $session_id,
132 131
             ];
133
-			$this_blog_id = Database::insert($tbl_blogs, $params);
132
+            $this_blog_id = Database::insert($tbl_blogs, $params);
134 133
 
135
-			if ($this_blog_id > 0) {
134
+            if ($this_blog_id > 0) {
136 135
 
137 136
                 $sql = "UPDATE $tbl_blogs SET blog_id = iid WHERE iid = $this_blog_id";
138 137
                 Database::query($sql);
139 138
 
140
-				// insert into item_property
139
+                // insert into item_property
141 140
                 api_item_property_update(
142 141
                     api_get_course_info(),
143 142
                     TOOL_BLOGS,
@@ -145,12 +144,12 @@  discard block
 block discarded – undo
145 144
                     'BlogAdded',
146 145
                     api_get_user_id()
147 146
                 );
148
-			}
147
+            }
149 148
 
150
-			// Make first post. :)
149
+            // Make first post. :)
151 150
 
152 151
             $params = [
153
-				'post_id' => 0,
152
+                'post_id' => 0,
154 153
                 'c_id' => $course_id,
155 154
                 'title' => get_lang("Welcome"),
156 155
                 'full_text' => get_lang('FirstPostText'),
@@ -164,10 +163,10 @@  discard block
 block discarded – undo
164 163
                 Database::query($sql);
165 164
             }
166 165
 
167
-			// Put it on course homepage
168
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target)
166
+            // Put it on course homepage
167
+            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target)
169 168
 					VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')";
170
-			Database::query($sql);
169
+            Database::query($sql);
171 170
 
172 171
             $toolId = Database::insert_id();
173 172
             if ($toolId) {
@@ -175,35 +174,35 @@  discard block
 block discarded – undo
175 174
                 Database::query($sql);
176 175
             }
177 176
 
178
-			// Subscribe the teacher to this blog
179
-			Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
180
-		}
181
-	}
182
-
183
-	/**
184
-	 * Update title and subtitle of a blog in the given course
185
-	 * @author Toon Keppens
186
-	 * @param string $title
187
-	 */
188
-	public static function edit_blog($blog_id, $title, $subtitle)
189
-	{
190
-		// Table definitions
191
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
192
-		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
177
+            // Subscribe the teacher to this blog
178
+            Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
179
+        }
180
+    }
181
+
182
+    /**
183
+     * Update title and subtitle of a blog in the given course
184
+     * @author Toon Keppens
185
+     * @param string $title
186
+     */
187
+    public static function edit_blog($blog_id, $title, $subtitle)
188
+    {
189
+        // Table definitions
190
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
191
+        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
193 192
 
194 193
         $course_id = api_get_course_int_id();
195 194
 
196
-		// Update the blog
197
-		$sql = "UPDATE $tbl_blogs SET
195
+        // Update the blog
196
+        $sql = "UPDATE $tbl_blogs SET
198 197
 		        blog_name = '".Database::escape_string($title)."',
199 198
 		        blog_subtitle = '".Database::escape_string($subtitle)."'
200 199
 		        WHERE
201 200
 		            c_id = $course_id AND
202 201
 		            blog_id ='".Database::escape_string((int)$blog_id)."'
203 202
                 LIMIT 1";
204
-		Database::query($sql);
203
+        Database::query($sql);
205 204
 
206
-		//update item_property (update)
205
+        //update item_property (update)
207 206
         api_item_property_update(
208 207
             api_get_course_info(),
209 208
             TOOL_BLOGS,
@@ -212,21 +211,21 @@  discard block
 block discarded – undo
212 211
             api_get_user_id()
213 212
         );
214 213
 
215
-		// Update course homepage link
216
-		$sql = "UPDATE $tbl_tool SET
214
+        // Update course homepage link
215
+        $sql = "UPDATE $tbl_tool SET
217 216
 		        name = '".Database::escape_string($title)."'
218 217
 		        WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int)$blog_id."' LIMIT 1";
219
-		Database::query($sql);
220
-	}
221
-
222
-	/**
223
-	 * Deletes a blog and it's posts from the course database
224
-	 * @author Toon Keppens
225
-	 * @param Integer $blog_id
226
-	 */
227
-	public static function delete_blog($blog_id)
228
-	{
229
-		// Init
218
+        Database::query($sql);
219
+    }
220
+
221
+    /**
222
+     * Deletes a blog and it's posts from the course database
223
+     * @author Toon Keppens
224
+     * @param Integer $blog_id
225
+     */
226
+    public static function delete_blog($blog_id)
227
+    {
228
+        // Init
230 229
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
231 230
         $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
232 231
         $tbl_blogs_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS);
@@ -237,34 +236,34 @@  discard block
 block discarded – undo
237 236
         $course_id = api_get_course_int_id();
238 237
         $blog_id = intval($blog_id);
239 238
 
240
-		// Delete posts from DB and the attachments
241
-		delete_all_blog_attachment($blog_id);
239
+        // Delete posts from DB and the attachments
240
+        delete_all_blog_attachment($blog_id);
242 241
 
243
-		//Delete comments
244
-		$sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
245
-   		Database::query($sql);
242
+        //Delete comments
243
+        $sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
244
+            Database::query($sql);
246 245
 
247
-		// Delete posts
248
-   		$sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
249
-   		Database::query($sql);
246
+        // Delete posts
247
+            $sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
248
+            Database::query($sql);
250 249
 
251
-		// Delete tasks
252
-		$sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
253
-		Database::query($sql);
250
+        // Delete tasks
251
+        $sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
252
+        Database::query($sql);
254 253
 
255
-		// Delete ratings
256
-		$sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
257
-		Database::query($sql);
254
+        // Delete ratings
255
+        $sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
256
+        Database::query($sql);
258 257
 
259
-		// Delete blog
260
-		$sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
261
-		Database::query($sql);
258
+        // Delete blog
259
+        $sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
260
+        Database::query($sql);
262 261
 
263
-		// Delete from course homepage
264
-		$sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
265
-		Database::query($sql);
262
+        // Delete from course homepage
263
+        $sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
264
+        Database::query($sql);
266 265
 
267
-		//update item_property (delete)
266
+        //update item_property (delete)
268 267
         api_item_property_update(
269 268
             api_get_course_info(),
270 269
             TOOL_BLOGS,
@@ -272,152 +271,152 @@  discard block
 block discarded – undo
272 271
             'delete',
273 272
             api_get_user_id()
274 273
         );
275
-	}
276
-
277
-	/**
278
-	 * Creates a new post in a given blog
279
-	 * @author Toon Keppens
280
-	 * @param String $title
281
-	 * @param String $full_text
282
-	 * @param Integer $blog_id
283
-	 */
284
-	public static function create_post($title, $full_text, $file_comment, $blog_id)
285
-	{
286
-		$_user = api_get_user_info();
287
-		$_course = api_get_course_info();
288
-		$course_id = $_course['real_id'];
289
-
290
-		$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
291
-		$upload_ok=true;
292
-		$has_attachment=false;
293
-		$current_date = api_get_utc_datetime();
294
-
295
-		if (!empty($_FILES['user_upload']['name'])) {
296
-			$upload_ok = process_uploaded_file($_FILES['user_upload']);
297
-			$has_attachment=true;
298
-		}
299
-
300
-		if ($upload_ok) {
301
-			// Table Definitions
302
-			$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
303
-
304
-			// Create the post
305
-			$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
274
+    }
275
+
276
+    /**
277
+     * Creates a new post in a given blog
278
+     * @author Toon Keppens
279
+     * @param String $title
280
+     * @param String $full_text
281
+     * @param Integer $blog_id
282
+     */
283
+    public static function create_post($title, $full_text, $file_comment, $blog_id)
284
+    {
285
+        $_user = api_get_user_info();
286
+        $_course = api_get_course_info();
287
+        $course_id = $_course['real_id'];
288
+
289
+        $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
290
+        $upload_ok=true;
291
+        $has_attachment=false;
292
+        $current_date = api_get_utc_datetime();
293
+
294
+        if (!empty($_FILES['user_upload']['name'])) {
295
+            $upload_ok = process_uploaded_file($_FILES['user_upload']);
296
+            $has_attachment=true;
297
+        }
298
+
299
+        if ($upload_ok) {
300
+            // Table Definitions
301
+            $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
302
+
303
+            // Create the post
304
+            $sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
306 305
 					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');";
307 306
 
308
-			Database::query($sql);
309
-			$last_post_id = Database::insert_id();
307
+            Database::query($sql);
308
+            $last_post_id = Database::insert_id();
310 309
 
311 310
             if ($last_post_id) {
312 311
                 $sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $last_post_id";
313 312
                 Database::query($sql);
314 313
             }
315 314
 
316
-			if ($has_attachment) {
317
-				$courseDir   = $_course['path'].'/upload/blog';
318
-				$sys_course_path = api_get_path(SYS_COURSE_PATH);
319
-				$updir = $sys_course_path.$courseDir;
320
-
321
-				// Try to add an extension to the file if it hasn't one
322
-				$new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
323
-
324
-				// user's file name
325
-				$file_name = $_FILES['user_upload']['name'];
326
-
327
-				if (!filter_extension($new_file_name)) {
328
-					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
329
-				} else {
330
-					$new_file_name = uniqid('');
331
-					$new_path = $updir.'/'.$new_file_name;
332
-					$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
333
-					$comment = Database::escape_string($file_comment);
334
-
335
-					// Storing the attachments if any
336
-					if ($result) {
337
-						$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
338
-							   "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."',  '".$blog_id."', '0' )";
339
-						Database::query($sql);
315
+            if ($has_attachment) {
316
+                $courseDir   = $_course['path'].'/upload/blog';
317
+                $sys_course_path = api_get_path(SYS_COURSE_PATH);
318
+                $updir = $sys_course_path.$courseDir;
319
+
320
+                // Try to add an extension to the file if it hasn't one
321
+                $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
322
+
323
+                // user's file name
324
+                $file_name = $_FILES['user_upload']['name'];
325
+
326
+                if (!filter_extension($new_file_name)) {
327
+                    Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
328
+                } else {
329
+                    $new_file_name = uniqid('');
330
+                    $new_path = $updir.'/'.$new_file_name;
331
+                    $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
332
+                    $comment = Database::escape_string($file_comment);
333
+
334
+                    // Storing the attachments if any
335
+                    if ($result) {
336
+                        $sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
337
+                                "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."',  '".$blog_id."', '0' )";
338
+                        Database::query($sql);
340 339
                         $id = Database::insert_id();
341 340
                         if ($id) {
342 341
                             $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
343 342
                             Database::query($sql);
344 343
                         }
345
-					}
346
-				}
347
-			}
348
-		} else {
349
-			Display::display_error_message(get_lang('UplNoFileUploaded'));
350
-		}
351
-	}
352
-
353
-	/**
354
-	 * Edits a post in a given blog
355
-	 * @author Toon Keppens
356
-	 * @param Integer $blog_id
357
-	 * @param String $title
358
-	 * @param String $full_text
359
-	 * @param Integer $blog_id
360
-	 */
361
-	public static function edit_post($post_id, $title, $full_text, $blog_id)
362
-	{
363
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
344
+                    }
345
+                }
346
+            }
347
+        } else {
348
+            Display::display_error_message(get_lang('UplNoFileUploaded'));
349
+        }
350
+    }
351
+
352
+    /**
353
+     * Edits a post in a given blog
354
+     * @author Toon Keppens
355
+     * @param Integer $blog_id
356
+     * @param String $title
357
+     * @param String $full_text
358
+     * @param Integer $blog_id
359
+     */
360
+    public static function edit_post($post_id, $title, $full_text, $blog_id)
361
+    {
362
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
364 363
         $course_id = api_get_course_int_id();
365 364
 
366
-		// Create the post
367
-		$sql = "UPDATE $tbl_blogs_posts SET
365
+        // Create the post
366
+        $sql = "UPDATE $tbl_blogs_posts SET
368 367
 		        title = '" . Database::escape_string($title)."',
369 368
 		        full_text = '" . Database::escape_string($full_text)."'
370 369
 		        WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."'
371 370
 		        LIMIT 1 ";
372
-		Database::query($sql);
373
-	}
374
-
375
-	/**
376
-	 * Deletes an article and it's comments
377
-	 * @author Toon Keppens
378
-	 * @param int $blog_id
379
-	 * @param int $post_id
380
-	 */
381
-	public static function delete_post($blog_id, $post_id)
382
-	{
383
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
384
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
385
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
371
+        Database::query($sql);
372
+    }
373
+
374
+    /**
375
+     * Deletes an article and it's comments
376
+     * @author Toon Keppens
377
+     * @param int $blog_id
378
+     * @param int $post_id
379
+     */
380
+    public static function delete_post($blog_id, $post_id)
381
+    {
382
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
383
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
384
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
386 385
 
387 386
         $course_id = api_get_course_int_id();
388 387
 
389
-		// Delete ratings on this comment
390
-		$sql = "DELETE FROM $tbl_blogs_rating
388
+        // Delete ratings on this comment
389
+        $sql = "DELETE FROM $tbl_blogs_rating
391 390
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'";
392
-		Database::query($sql);
391
+        Database::query($sql);
393 392
 
394
-		// Delete the post
395
-		$sql = "DELETE FROM $tbl_blogs_posts
393
+        // Delete the post
394
+        $sql = "DELETE FROM $tbl_blogs_posts
396 395
 				WHERE c_id = $course_id AND post_id = '".(int)$post_id."'";
397
-		Database::query($sql);
396
+        Database::query($sql);
398 397
 
399
-		// Delete the comments
400
-		$sql = "DELETE FROM $tbl_blogs_comments
398
+        // Delete the comments
399
+        $sql = "DELETE FROM $tbl_blogs_comments
401 400
 				WHERE c_id = $course_id AND post_id = '".(int)$post_id."' AND blog_id = '".(int)$blog_id."'";
402
-		Database::query($sql);
403
-
404
-		// Delete posts and attachments
405
-		delete_all_blog_attachment($blog_id,$post_id);
406
-	}
407
-
408
-	/**
409
-	 * Creates a comment on a post in a given blog
410
-	 * @author Toon Keppens
411
-	 * @param String $title
412
-	 * @param String $full_text
413
-	 * @param Integer $blog_id
414
-	 * @param Integer $post_id
415
-	 * @param Integer $parent_id
416
-	 */
417
-	public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
418
-	{
419
-		$_user = api_get_user_info();
420
-		$_course = api_get_course_info();
401
+        Database::query($sql);
402
+
403
+        // Delete posts and attachments
404
+        delete_all_blog_attachment($blog_id,$post_id);
405
+    }
406
+
407
+    /**
408
+     * Creates a comment on a post in a given blog
409
+     * @author Toon Keppens
410
+     * @param String $title
411
+     * @param String $full_text
412
+     * @param Integer $blog_id
413
+     * @param Integer $post_id
414
+     * @param Integer $parent_id
415
+     */
416
+    public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
417
+    {
418
+        $_user = api_get_user_info();
419
+        $_course = api_get_course_info();
421 420
         $blog_table_attachment 	= Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
422 421
 
423 422
         $upload_ok = true;
@@ -425,55 +424,55 @@  discard block
 block discarded – undo
425 424
         $current_date = api_get_utc_datetime();
426 425
         $course_id = api_get_course_int_id();
427 426
 
428
-		if (!empty($_FILES['user_upload']['name'])) {
429
-			$upload_ok = process_uploaded_file($_FILES['user_upload']);
430
-			$has_attachment=true;
431
-		}
427
+        if (!empty($_FILES['user_upload']['name'])) {
428
+            $upload_ok = process_uploaded_file($_FILES['user_upload']);
429
+            $has_attachment=true;
430
+        }
432 431
 
433
-		if ($upload_ok) {
434
-			// Table Definition
435
-			$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
432
+        if ($upload_ok) {
433
+            // Table Definition
434
+            $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
436 435
 
437
-			// Create the comment
438
-			$sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
436
+            // Create the comment
437
+            $sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
439 438
 					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')";
440
-			Database::query($sql);
439
+            Database::query($sql);
441 440
 
442
-			// Empty post values, or they are shown on the page again
443
-			$last_id = Database::insert_id();
441
+            // Empty post values, or they are shown on the page again
442
+            $last_id = Database::insert_id();
444 443
 
445 444
             if ($last_id) {
446 445
                 $sql = "UPDATE $tbl_blogs_comments SET comment_id = iid WHERE iid = $last_id";
447 446
                 Database::query($sql);
448 447
             }
449 448
 
450
-			if ($has_attachment) {
451
-				$courseDir   = $_course['path'].'/upload/blog';
452
-				$sys_course_path = api_get_path(SYS_COURSE_PATH);
453
-				$updir = $sys_course_path.$courseDir;
454
-
455
-				// Try to add an extension to the file if it hasn't one
456
-				$new_file_name = add_ext_on_mime(
457
-					stripslashes($_FILES['user_upload']['name']),
458
-					$_FILES['user_upload']['type']
459
-				);
460
-
461
-				// user's file name
462
-				$file_name =$_FILES['user_upload']['name'];
463
-
464
-				if (!filter_extension($new_file_name)) {
465
-					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
466
-				} else {
467
-					$new_file_name = uniqid('');
468
-					$new_path=$updir.'/'.$new_file_name;
469
-					$result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
470
-					$comment = Database::escape_string($file_comment);
471
-
472
-					// Storing the attachments if any
473
-					if ($result) {
474
-						$sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
475
-							 "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."',  '".$blog_id."', '".$last_id."'  )";
476
-						Database::query($sql);
449
+            if ($has_attachment) {
450
+                $courseDir   = $_course['path'].'/upload/blog';
451
+                $sys_course_path = api_get_path(SYS_COURSE_PATH);
452
+                $updir = $sys_course_path.$courseDir;
453
+
454
+                // Try to add an extension to the file if it hasn't one
455
+                $new_file_name = add_ext_on_mime(
456
+                    stripslashes($_FILES['user_upload']['name']),
457
+                    $_FILES['user_upload']['type']
458
+                );
459
+
460
+                // user's file name
461
+                $file_name =$_FILES['user_upload']['name'];
462
+
463
+                if (!filter_extension($new_file_name)) {
464
+                    Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
465
+                } else {
466
+                    $new_file_name = uniqid('');
467
+                    $new_path=$updir.'/'.$new_file_name;
468
+                    $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
469
+                    $comment = Database::escape_string($file_comment);
470
+
471
+                    // Storing the attachments if any
472
+                    if ($result) {
473
+                        $sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
474
+                                "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."',  '".$blog_id."', '".$last_id."'  )";
475
+                        Database::query($sql);
477 476
 
478 477
                         $id = Database::insert_id();
479 478
 
@@ -481,91 +480,91 @@  discard block
 block discarded – undo
481 480
                             $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
482 481
                             Database::query($sql);
483 482
                         }
484
-					}
485
-				}
486
-			}
487
-		}
488
-	}
489
-
490
-	/**
491
-	 * Deletes a comment from a blogpost
492
-	 * @author Toon Keppens
493
-	 * @param int $blog_id
494
-	 * @param int $comment_id
495
-	 */
496
-	public static function delete_comment($blog_id, $post_id, $comment_id)
497
-	{
498
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
499
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
500
-		$blog_id = intval($blog_id);
501
-		$post_id = intval($post_id);
502
-		$comment_id = intval($comment_id);
483
+                    }
484
+                }
485
+            }
486
+        }
487
+    }
488
+
489
+    /**
490
+     * Deletes a comment from a blogpost
491
+     * @author Toon Keppens
492
+     * @param int $blog_id
493
+     * @param int $comment_id
494
+     */
495
+    public static function delete_comment($blog_id, $post_id, $comment_id)
496
+    {
497
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
498
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
499
+        $blog_id = intval($blog_id);
500
+        $post_id = intval($post_id);
501
+        $comment_id = intval($comment_id);
503 502
         $course_id = api_get_course_int_id();
504 503
 
505
-		delete_all_blog_attachment($blog_id, $post_id, $comment_id);
504
+        delete_all_blog_attachment($blog_id, $post_id, $comment_id);
506 505
 
507
-		// Delete ratings on this comment
508
-		$sql = "DELETE FROM $tbl_blogs_rating
506
+        // Delete ratings on this comment
507
+        $sql = "DELETE FROM $tbl_blogs_rating
509 508
 				WHERE
510 509
 				    c_id = $course_id AND
511 510
 				    blog_id = '".$blog_id."' AND
512 511
 				    item_id = '".$comment_id."' AND
513 512
 				    rating_type = 'comment'";
514
-		Database::query($sql);
513
+        Database::query($sql);
515 514
 
516
-		// select comments that have the selected comment as their parent
517
-		$sql = "SELECT comment_id FROM $tbl_blogs_comments
515
+        // select comments that have the selected comment as their parent
516
+        $sql = "SELECT comment_id FROM $tbl_blogs_comments
518 517
 				WHERE c_id = $course_id AND parent_comment_id = '".$comment_id."'";
519
-		$result = Database::query($sql);
518
+        $result = Database::query($sql);
520 519
 
521
-		// Delete them recursively
522
-		while ($comment = Database::fetch_array($result)) {
523
-			Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
524
-		}
520
+        // Delete them recursively
521
+        while ($comment = Database::fetch_array($result)) {
522
+            Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
523
+        }
525 524
 
526
-		// Finally, delete the selected comment to
527
-		$sql = "DELETE FROM $tbl_blogs_comments
525
+        // Finally, delete the selected comment to
526
+        $sql = "DELETE FROM $tbl_blogs_comments
528 527
 				WHERE c_id = $course_id AND comment_id = '".$comment_id."'";
529
-		Database::query($sql);
530
-	}
531
-
532
-	/**
533
-	 * Creates a new task in a blog
534
-	 * @author Toon Keppens
535
-	 * @param Integer $blog_id
536
-	 * @param String $title
537
-	 * @param String $description
538
-	 * @param String $color
539
-	 */
540
-	public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
541
-	{
542
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
543
-		$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
544
-
545
-		$course_id = api_get_course_int_id();
546
-
547
-		// Create the task
548
-		$sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
528
+        Database::query($sql);
529
+    }
530
+
531
+    /**
532
+     * Creates a new task in a blog
533
+     * @author Toon Keppens
534
+     * @param Integer $blog_id
535
+     * @param String $title
536
+     * @param String $description
537
+     * @param String $color
538
+     */
539
+    public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
540
+    {
541
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
542
+        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
543
+
544
+        $course_id = api_get_course_int_id();
545
+
546
+        // Create the task
547
+        $sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
549 548
 				VALUES ($course_id , '".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');";
550
-		Database::query($sql);
549
+        Database::query($sql);
551 550
 
552
-		$task_id = Database::insert_id();
551
+        $task_id = Database::insert_id();
553 552
 
554 553
         if ($task_id) {
555 554
             $sql = "UPDATE $tbl_blogs_tasks SET task_id = iid WHERE iid = $task_id";
556 555
             Database::query($sql);
557 556
         }
558 557
 
559
-		$tool = 'BLOG_' . $blog_id;
558
+        $tool = 'BLOG_' . $blog_id;
560 559
 
561
-		if ($articleDelete == 'on') {
562
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
560
+        if ($articleDelete == 'on') {
561
+            $sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
563 562
 					'" . (int)$course_id . "',
564 563
 					'" . (int)$task_id . "',
565 564
 					'" . Database::escape_string($tool) . "',
566 565
 					'article_delete'
567 566
 				)";
568
-			Database::query($sql);
567
+            Database::query($sql);
569 568
 
570 569
             $id = Database::insert_id();
571 570
 
@@ -575,171 +574,171 @@  discard block
 block discarded – undo
575 574
             }
576 575
         }
577 576
 
578
-		if ($articleEdit == 'on') {
579
-			$sql = "
577
+        if ($articleEdit == 'on') {
578
+            $sql = "
580 579
 				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
581 580
 					'" . (int)$course_id . "',
582 581
 					'" . (int)$task_id . "',
583 582
 					'" . Database::escape_string($tool) . "',
584 583
 					'article_edit'
585 584
 				)";
586
-			Database::query($sql);
585
+            Database::query($sql);
587 586
             $id = Database::insert_id();
588 587
 
589 588
             if ($id) {
590 589
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
591 590
                 Database::query($sql);
592 591
             }
593
-		}
592
+        }
594 593
 
595
-		if ($commentsDelete == 'on') {
596
-			$sql = "
594
+        if ($commentsDelete == 'on') {
595
+            $sql = "
597 596
 				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
598 597
 					'" . (int)$course_id . "',
599 598
 					'" . (int)$task_id . "',
600 599
 					'" . Database::escape_string($tool) . "',
601 600
 					'article_comments_delete'
602 601
 				)";
603
-			Database::query($sql);
602
+            Database::query($sql);
604 603
             $id = Database::insert_id();
605 604
 
606 605
             if ($id) {
607 606
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
608 607
                 Database::query($sql);
609 608
             }
610
-		}
611
-	}
612
-
613
-	/**
614
-	 * Edit a task in a blog
615
-	 * @author Toon Keppens
616
-	 * @param Integer $task_id
617
-	 * @param String $title
618
-	 * @param String $description
619
-	 * @param String $color
620
-	 */
621
-	public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
622
-	{
623
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
624
-		$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
609
+        }
610
+    }
611
+
612
+    /**
613
+     * Edit a task in a blog
614
+     * @author Toon Keppens
615
+     * @param Integer $task_id
616
+     * @param String $title
617
+     * @param String $description
618
+     * @param String $color
619
+     */
620
+    public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
621
+    {
622
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
623
+        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
625 624
 
626 625
         $course_id = api_get_course_int_id();
627 626
 
628
-		// Create the task
629
-		$sql = "UPDATE $tbl_blogs_tasks SET
627
+        // Create the task
628
+        $sql = "UPDATE $tbl_blogs_tasks SET
630 629
 					title = '".Database::escape_string($title)."',
631 630
 					description = '".Database::escape_string($description)."',
632 631
 					color = '".Database::escape_string($color)."'
633 632
 				WHERE c_id = $course_id AND task_id ='".(int)$task_id."' LIMIT 1";
634
-		Database::query($sql);
633
+        Database::query($sql);
635 634
 
636
-		$tool = 'BLOG_' . $blog_id;
635
+        $tool = 'BLOG_' . $blog_id;
637 636
 
638
-		$sql = "DELETE FROM " . $tbl_tasks_permissions . "
637
+        $sql = "DELETE FROM " . $tbl_tasks_permissions . "
639 638
 				WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
640
-		Database::query($sql);
639
+        Database::query($sql);
641 640
 
642
-		if ($articleDelete == 'on') {
643
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
641
+        if ($articleDelete == 'on') {
642
+            $sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
644 643
 					'" . (int)$course_id . "',
645 644
 					'" . (int)$task_id . "',
646 645
 					'" . Database::escape_string($tool) . "',
647 646
 					'article_delete'
648 647
 				)";
649
-			Database::query($sql);
648
+            Database::query($sql);
650 649
             $id = Database::insert_id();
651 650
 
652 651
             if ($id) {
653 652
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
654 653
                 Database::query($sql);
655 654
             }
656
-		}
655
+        }
657 656
 
658
-		if ($articleEdit == 'on') {
659
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
657
+        if ($articleEdit == 'on') {
658
+            $sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
660 659
 					'" . (int)$course_id . "',
661 660
 					'" . (int)$task_id . "',
662 661
 					'" . Database::escape_string($tool) . "',
663 662
 					'article_edit'
664 663
 				)";
665
-			Database::query($sql);
664
+            Database::query($sql);
666 665
             $id = Database::insert_id();
667 666
 
668 667
             if ($id) {
669 668
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
670 669
                 Database::query($sql);
671 670
             }
672
-		}
671
+        }
673 672
 
674
-		if ($commentsDelete == 'on') {
675
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
673
+        if ($commentsDelete == 'on') {
674
+            $sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
676 675
 					'" . (int)$course_id . "',
677 676
 					'" . (int)$task_id . "',
678 677
 					'" . Database::escape_string($tool) . "',
679 678
 					'article_comments_delete'
680 679
 				)";
681
-			Database::query($sql);
680
+            Database::query($sql);
682 681
             $id = Database::insert_id();
683 682
 
684 683
             if ($id) {
685 684
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
686 685
                 Database::query($sql);
687 686
             }
688
-		}
689
-	}
690
-
691
-	/**
692
-	 * Deletes a task from a blog
693
-	 * @param Integer $blog_id
694
-	 * @param Integer $task_id
695
-	 */
696
-	public static function delete_task($blog_id, $task_id)
697
-	{
698
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
699
-		$course_id = api_get_course_int_id();
700
-
701
-		// Delete posts
702
-		$sql = "DELETE FROM $tbl_blogs_tasks
687
+        }
688
+    }
689
+
690
+    /**
691
+     * Deletes a task from a blog
692
+     * @param Integer $blog_id
693
+     * @param Integer $task_id
694
+     */
695
+    public static function delete_task($blog_id, $task_id)
696
+    {
697
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
698
+        $course_id = api_get_course_int_id();
699
+
700
+        // Delete posts
701
+        $sql = "DELETE FROM $tbl_blogs_tasks
703 702
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."'";
704
-		Database::query($sql);
705
-	}
706
-
707
-	/**
708
-	 * Deletes an assigned task from a blog
709
-	 * @param Integer $blog_id
710
-	 */
711
-	public static function delete_assigned_task($blog_id, $task_id, $user_id)
712
-	{
713
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
703
+        Database::query($sql);
704
+    }
705
+
706
+    /**
707
+     * Deletes an assigned task from a blog
708
+     * @param Integer $blog_id
709
+     */
710
+    public static function delete_assigned_task($blog_id, $task_id, $user_id)
711
+    {
712
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
714 713
         $course_id = api_get_course_int_id();
715 714
 
716
-		// Delete posts
717
-		$sql = "DELETE FROM $tbl_blogs_tasks_rel_user
715
+        // Delete posts
716
+        $sql = "DELETE FROM $tbl_blogs_tasks_rel_user
718 717
 				WHERE
719 718
 				    c_id = $course_id AND
720 719
 				    blog_id = '".(int)$blog_id."' AND
721 720
 				    task_id = '".(int)$task_id."' AND
722 721
 				    user_id = '".(int)$user_id."'";
723
-		Database::query($sql);
724
-	}
725
-
726
-	/**
727
-	 * Get personal task list
728
-	 * @author Toon Keppens
729
-	 * @return Returns an unsorted list (<ul></ul>) with the users' tasks
730
-	 */
731
-	public static function get_personal_task_list()
732
-	{
733
-		$_user = api_get_user_info();
734
-
735
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
736
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
737
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
738
-
739
-		$course_id = api_get_course_int_id();
740
-
741
-		if ($_user['user_id']) {
742
-			$sql = "SELECT task_rel_user.*, task.title, blog.blog_name
722
+        Database::query($sql);
723
+    }
724
+
725
+    /**
726
+     * Get personal task list
727
+     * @author Toon Keppens
728
+     * @return Returns an unsorted list (<ul></ul>) with the users' tasks
729
+     */
730
+    public static function get_personal_task_list()
731
+    {
732
+        $_user = api_get_user_info();
733
+
734
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
735
+        $tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
736
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
737
+
738
+        $course_id = api_get_course_int_id();
739
+
740
+        if ($_user['user_id']) {
741
+            $sql = "SELECT task_rel_user.*, task.title, blog.blog_name
743 742
                     FROM $tbl_blogs_tasks_rel_user task_rel_user
744 743
                     INNER JOIN $tbl_blogs_tasks task
745 744
                     ON task_rel_user.task_id = task.task_id
@@ -753,85 +752,85 @@  discard block
 block discarded – undo
753 752
                         task_rel_user.user_id = ".(int)$_user['user_id']."
754 753
                     ORDER BY target_date ASC";
755 754
 
756
-			$result = Database::query($sql);
757
-
758
-			if (Database::num_rows($result) > 0) {
759
-				echo '<ul>';
760
-				while ($mytask = Database::fetch_array($result)) {
761
-					echo '<li><a href="blog.php?action=execute_task&blog_id=' . $mytask['blog_id'] . '&task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: '.stripslashes($mytask['blog_name']) . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
762
-				}
763
-				echo '<ul>';
764
-			} else {
765
-				echo get_lang('NoTasks');
766
-			}
767
-		} else {
768
-			echo get_lang('NoTasks');
769
-		}
770
-	}
771
-
772
-	/**
773
-	 * Changes the visibility of a blog
774
-	 * @author Toon Keppens
775
-	 * @param Integer $blog_id
776
-	 */
777
-	public static function change_blog_visibility($blog_id)
778
-	{
779
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
780
-		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
781
-		$course_id = api_get_course_int_id();
782
-
783
-		// Get blog properties
784
-		$sql = "SELECT blog_name, visibility FROM $tbl_blogs
755
+            $result = Database::query($sql);
756
+
757
+            if (Database::num_rows($result) > 0) {
758
+                echo '<ul>';
759
+                while ($mytask = Database::fetch_array($result)) {
760
+                    echo '<li><a href="blog.php?action=execute_task&blog_id=' . $mytask['blog_id'] . '&task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: '.stripslashes($mytask['blog_name']) . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
761
+                }
762
+                echo '<ul>';
763
+            } else {
764
+                echo get_lang('NoTasks');
765
+            }
766
+        } else {
767
+            echo get_lang('NoTasks');
768
+        }
769
+    }
770
+
771
+    /**
772
+     * Changes the visibility of a blog
773
+     * @author Toon Keppens
774
+     * @param Integer $blog_id
775
+     */
776
+    public static function change_blog_visibility($blog_id)
777
+    {
778
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
779
+        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
780
+        $course_id = api_get_course_int_id();
781
+
782
+        // Get blog properties
783
+        $sql = "SELECT blog_name, visibility FROM $tbl_blogs
785 784
 				WHERE c_id = $course_id AND blog_id='".(int)$blog_id."'";
786
-		$result = Database::query($sql);
787
-		$blog = Database::fetch_array($result);
788
-		$visibility = $blog['visibility'];
789
-		$title = $blog['blog_name'];
790
-
791
-		if ($visibility == 1) {
792
-			// Change visibility state, remove from course home.
793
-			$sql = "UPDATE $tbl_blogs SET visibility = '0'
785
+        $result = Database::query($sql);
786
+        $blog = Database::fetch_array($result);
787
+        $visibility = $blog['visibility'];
788
+        $title = $blog['blog_name'];
789
+
790
+        if ($visibility == 1) {
791
+            // Change visibility state, remove from course home.
792
+            $sql = "UPDATE $tbl_blogs SET visibility = '0'
794 793
 					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
795
-			Database::query($sql);
794
+            Database::query($sql);
796 795
 
797
-			$sql = "DELETE FROM $tbl_tool
796
+            $sql = "DELETE FROM $tbl_tool
798 797
 					WHERE c_id = $course_id AND name = '".Database::escape_string($title)."' LIMIT 1";
799
-			Database::query($sql);
800
-		} else {
801
-			// Change visibility state, add to course home.
802
-			$sql = "UPDATE $tbl_blogs SET visibility = '1'
798
+            Database::query($sql);
799
+        } else {
800
+            // Change visibility state, add to course home.
801
+            $sql = "UPDATE $tbl_blogs SET visibility = '1'
803 802
 					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
804
-			Database::query($sql);
803
+            Database::query($sql);
805 804
 
806
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
805
+            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
807 806
 					VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
808
-			Database::query($sql);
807
+            Database::query($sql);
809 808
             $id = Database::insert_id();
810 809
 
811 810
             if ($id) {
812 811
                 $sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $id";
813 812
                 Database::query($sql);
814 813
             }
815
-		}
816
-	}
817
-
818
-	/**
819
-	 * Shows the posts of a blog
820
-	 * @author Toon Keppens
821
-	 *
822
-	 * @param Integer $blog_id
823
-	 */
824
-	public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
814
+        }
815
+    }
816
+
817
+    /**
818
+     * Shows the posts of a blog
819
+     * @author Toon Keppens
820
+     *
821
+     * @param Integer $blog_id
822
+     */
823
+    public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
825 824
     {
826
-		// Init
827
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
828
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
829
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
825
+        // Init
826
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
827
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
828
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
830 829
 
831
-		$course_id = api_get_course_int_id();
830
+        $course_id = api_get_course_int_id();
832 831
 
833
-		// Get posts and authors
834
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
832
+        // Get posts and authors
833
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
835 834
 		        FROM $tbl_blogs_posts post
836 835
                 INNER JOIN $tbl_users user
837 836
                 ON post.author_id = user.user_id
@@ -839,131 +838,131 @@  discard block
 block discarded – undo
839 838
 						post.c_id = $course_id AND
840 839
 						$filter
841 840
 				ORDER BY post_id DESC LIMIT 0,".(int)$max_number_of_posts;
842
-		$result = Database::query($sql);
843
-
844
-		// Display
845
-		if(Database::num_rows($result) > 0) {
846
-		    $limit = 200;
847
-			while ($blog_post = Database::fetch_array($result)) {
848
-				// Get number of comments
849
-				$sql = "SELECT COUNT(1) as number_of_comments
841
+        $result = Database::query($sql);
842
+
843
+        // Display
844
+        if(Database::num_rows($result) > 0) {
845
+            $limit = 200;
846
+            while ($blog_post = Database::fetch_array($result)) {
847
+                // Get number of comments
848
+                $sql = "SELECT COUNT(1) as number_of_comments
850 849
 						FROM $tbl_blogs_comments
851 850
 						WHERE
852 851
 						    c_id = $course_id AND
853 852
 						    blog_id = '".(int)$blog_id."' AND
854 853
 						    post_id = '" . (int)$blog_post['post_id']."'";
855
-				$tmp = Database::query($sql);
856
-				$blog_post_comments = Database::fetch_array($tmp);
857
-
858
-				// Prepare data
859
-				$blog_post_id = $blog_post['post_id'];
860
-				$blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
861
-				$blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
862
-
863
-				// Create an introduction text (but keep FULL sentences)
864
-				$words = 0;
865
-				$blog_post_text_cut = cut($blog_post_text, $limit) ;
866
-				$words = strlen($blog_post_text);
867
-
868
-				if ($words >= $limit) {
869
-					$readMoreLink = ' <div class="link" onclick="document.getElementById(\'blogpost_text_' . $blog_post_id . '\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_' . $blog_post_id . '\').style.display=\'none\'">' . get_lang('ReadMore') . '</div>';
870
-					$introduction_text = $blog_post_text_cut;
871
-				} else {
872
-				    $introduction_text = $blog_post_text;
873
-					$readMoreLink = '';
874
-				}
875
-
876
-				$introduction_text = stripslashes($introduction_text);
877
-
878
-				echo '<div class="blogpost">';
879
-				echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
880
-				echo '<span class="blogpost_date"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . $blog_post_date . '</a></span>';
881
-				echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
882
-				echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
883
-
884
-				$file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
885
-
886
-				if (!empty($file_name_array)) {
887
-					echo '<br /><br />';
888
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
889
-					echo '<a href="download.php?file=';
890
-					echo $file_name_array['path'];
891
-					echo ' "> '.$file_name_array['filename'].' </a><br />';
892
-					echo '</span>';
893
-				}
894
-				$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
895
-				echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - <a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '</a></span>';
896
-				echo '</div>';
897
-			}
898
-		} else {
899
-			if($filter == '1=1') {
900
-				echo get_lang('NoArticles');
901
-			} else {
902
-				echo get_lang('NoArticleMatches');
903
-			}
904
-		}
854
+                $tmp = Database::query($sql);
855
+                $blog_post_comments = Database::fetch_array($tmp);
856
+
857
+                // Prepare data
858
+                $blog_post_id = $blog_post['post_id'];
859
+                $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
860
+                $blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
861
+
862
+                // Create an introduction text (but keep FULL sentences)
863
+                $words = 0;
864
+                $blog_post_text_cut = cut($blog_post_text, $limit) ;
865
+                $words = strlen($blog_post_text);
866
+
867
+                if ($words >= $limit) {
868
+                    $readMoreLink = ' <div class="link" onclick="document.getElementById(\'blogpost_text_' . $blog_post_id . '\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_' . $blog_post_id . '\').style.display=\'none\'">' . get_lang('ReadMore') . '</div>';
869
+                    $introduction_text = $blog_post_text_cut;
870
+                } else {
871
+                    $introduction_text = $blog_post_text;
872
+                    $readMoreLink = '';
873
+                }
874
+
875
+                $introduction_text = stripslashes($introduction_text);
876
+
877
+                echo '<div class="blogpost">';
878
+                echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
879
+                echo '<span class="blogpost_date"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . $blog_post_date . '</a></span>';
880
+                echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
881
+                echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
882
+
883
+                $file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
884
+
885
+                if (!empty($file_name_array)) {
886
+                    echo '<br /><br />';
887
+                    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
888
+                    echo '<a href="download.php?file=';
889
+                    echo $file_name_array['path'];
890
+                    echo ' "> '.$file_name_array['filename'].' </a><br />';
891
+                    echo '</span>';
892
+                }
893
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
894
+                echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - <a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '</a></span>';
895
+                echo '</div>';
896
+            }
897
+        } else {
898
+            if($filter == '1=1') {
899
+                echo get_lang('NoArticles');
900
+            } else {
901
+                echo get_lang('NoArticleMatches');
902
+            }
903
+        }
905 904
 }
906 905
 
907
-	/**
908
-	 * Display the search results
909
-	 *
910
-	 * @param Integer $blog_id
911
-	 * @param String $query_string
912
-	 */
913
-	public static function display_search_results ($blog_id, $query_string)
914
-	{
915
-		// Init
916
-		$query_string = Database::escape_string($query_string);
917
-		$query_string_parts = explode(' ',$query_string);
918
-		$query_string = array();
919
-		foreach ($query_string_parts as $query_part) {
920
-			$query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
921
-		}
922
-		$query_string = '('.implode('OR',$query_string) . ')';
923
-
924
-		// Display the posts
925
-		echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
926
-		Blog::display_blog_posts($blog_id, $query_string);
927
-	}
928
-
929
-	/**
930
-	 * Display posts from a certain date
931
-	 *
932
-	 * @param Integer $blog_id
933
-	 * @param String $query_string
934
-	 */
935
-	public static function display_day_results($blog_id, $query_string)
936
-	{
937
-		$date_output = $query_string;
938
-		$date = explode('-',$query_string);
939
-		$query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
940
-
941
-		// Put date in correct output format
942
-		$date_output = api_format_date($date_output, DATE_FORMAT_LONG);
943
-
944
-		// Display the posts
945
-		echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
946
-		Blog::display_blog_posts($blog_id, $query_string);
947
-	}
948
-
949
-	/**
950
-	 * Displays a post and his comments
951
-	 *
952
-	 * @param Integer $blog_id
953
-	 * @param Integer $post_id
954
-	 */
955
-	public static function display_post($blog_id, $post_id)
956
-	{
957
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
958
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
959
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
960
-
961
-		global $charset, $dateFormatLong;
962
-
963
-		$course_id = api_get_course_int_id();
964
-
965
-		// Get posts and author
966
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
906
+    /**
907
+     * Display the search results
908
+     *
909
+     * @param Integer $blog_id
910
+     * @param String $query_string
911
+     */
912
+    public static function display_search_results ($blog_id, $query_string)
913
+    {
914
+        // Init
915
+        $query_string = Database::escape_string($query_string);
916
+        $query_string_parts = explode(' ',$query_string);
917
+        $query_string = array();
918
+        foreach ($query_string_parts as $query_part) {
919
+            $query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
920
+        }
921
+        $query_string = '('.implode('OR',$query_string) . ')';
922
+
923
+        // Display the posts
924
+        echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
925
+        Blog::display_blog_posts($blog_id, $query_string);
926
+    }
927
+
928
+    /**
929
+     * Display posts from a certain date
930
+     *
931
+     * @param Integer $blog_id
932
+     * @param String $query_string
933
+     */
934
+    public static function display_day_results($blog_id, $query_string)
935
+    {
936
+        $date_output = $query_string;
937
+        $date = explode('-',$query_string);
938
+        $query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
939
+
940
+        // Put date in correct output format
941
+        $date_output = api_format_date($date_output, DATE_FORMAT_LONG);
942
+
943
+        // Display the posts
944
+        echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
945
+        Blog::display_blog_posts($blog_id, $query_string);
946
+    }
947
+
948
+    /**
949
+     * Displays a post and his comments
950
+     *
951
+     * @param Integer $blog_id
952
+     * @param Integer $post_id
953
+     */
954
+    public static function display_post($blog_id, $post_id)
955
+    {
956
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
957
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
958
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
959
+
960
+        global $charset, $dateFormatLong;
961
+
962
+        $course_id = api_get_course_int_id();
963
+
964
+        // Get posts and author
965
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
967 966
 		        FROM $tbl_blogs_posts post
968 967
 					INNER JOIN $tbl_users user
969 968
 					ON post.author_id = user.user_id
@@ -972,113 +971,113 @@  discard block
 block discarded – undo
972 971
                     post.blog_id = '".(int)$blog_id."' AND
973 972
                     post.post_id = '".(int)$post_id."'
974 973
                 ORDER BY post_id DESC";
975
-		$result = Database::query($sql);
976
-		$blog_post = Database::fetch_array($result);
974
+        $result = Database::query($sql);
975
+        $blog_post = Database::fetch_array($result);
977 976
 
978
-		// Get number of comments
979
-		$sql = "SELECT COUNT(1) as number_of_comments
977
+        // Get number of comments
978
+        $sql = "SELECT COUNT(1) as number_of_comments
980 979
 		        FROM $tbl_blogs_comments
981 980
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND post_id = '".(int)$post_id."'";
982
-		$result = Database::query($sql);
983
-		$blog_post_comments = Database::fetch_array($result);
981
+        $result = Database::query($sql);
982
+        $blog_post_comments = Database::fetch_array($result);
984 983
 
985
-		// Prepare data
986
-		$blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
987
-		$blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
988
-		$blog_post_actions = "";
984
+        // Prepare data
985
+        $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
986
+        $blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
987
+        $blog_post_actions = "";
989 988
 
990
-		$task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
989
+        $task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
991 990
 
992
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
993
-			$blog_post_actions .= '<a href="blog.php?action=edit_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('EditThisPost') . '">';
994
-			$blog_post_actions .=  Display::return_icon('edit.png');
995
-			$blog_post_actions .= '</a>';
991
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
992
+            $blog_post_actions .= '<a href="blog.php?action=edit_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('EditThisPost') . '">';
993
+            $blog_post_actions .=  Display::return_icon('edit.png');
994
+            $blog_post_actions .= '</a>';
996 995
         }
997 996
 
998
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
999
-			$blog_post_actions .= '<a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&do=delete_article&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('DeleteThisArticle') . '" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;">';
997
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
998
+            $blog_post_actions .= '<a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&do=delete_article&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('DeleteThisArticle') . '" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;">';
1000 999
             $blog_post_actions .= Display::return_icon('delete.png');
1001 1000
             $blog_post_actions .= '</a>';
1002 1001
         }
1003 1002
 
1004
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1005
-			$rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1003
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1004
+            $rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1006 1005
 
1007
-		$blog_post_text=stripslashes($blog_post_text);
1006
+        $blog_post_text=stripslashes($blog_post_text);
1008 1007
 
1009
-		// Display post
1010
-		echo '<div class="blogpost">';
1011
-		echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
1012
-		echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1013
-		echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1008
+        // Display post
1009
+        echo '<div class="blogpost">';
1010
+        echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
1011
+        echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1012
+        echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1014 1013
 
1015
-		$file_name_array = get_blog_attachment($blog_id, $post_id);
1014
+        $file_name_array = get_blog_attachment($blog_id, $post_id);
1016 1015
 
1017 1016
         if (!empty($file_name_array)) {
1018
-			echo ' <br />';
1019
-			echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1020
-			echo '<a href="download.php?file=';
1021
-			echo $file_name_array['path'];
1022
-			echo ' "> '.$file_name_array['filename'].' </a>';
1023
-			echo '</span>';
1024
-			echo '<span class="attachment_comment">';
1025
-			echo $file_name_array['comment'];
1026
-			echo '</span>';
1027
-			echo '<br />';
1028
-		}
1017
+            echo ' <br />';
1018
+            echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1019
+            echo '<a href="download.php?file=';
1020
+            echo $file_name_array['path'];
1021
+            echo ' "> '.$file_name_array['filename'].' </a>';
1022
+            echo '</span>';
1023
+            echo '<span class="attachment_comment">';
1024
+            echo $file_name_array['comment'];
1025
+            echo '</span>';
1026
+            echo '<br />';
1027
+        }
1029 1028
         $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1030
-		echo '<span class="blogpost_info">'.get_lang('Author').': ' .Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - '.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].' - '.get_lang('Rating').': '.Blog::display_rating('post',$blog_id,$post_id).$rating_select.'</span>';
1031
-		echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1032
-		echo '</div>';
1033
-
1034
-		// Display comments if there are any
1035
-		if($blog_post_comments['number_of_comments'] > 0) {
1036
-			echo '<div class="comments">';
1037
-				echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1038
-				Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1039
-			echo '</div>';
1040
-		}
1041
-
1042
-		// Display comment form
1043
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1044
-			Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1045
-		}
1046
-	}
1047
-
1048
-	/**
1049
-	 * Adds rating to a certain post or comment
1050
-	 * @author Toon Keppens
1051
-	 *
1052
-	 * @param String $type
1053
-	 * @param Integer $blog_id
1054
-	 * @param Integer $item_id
1055
-	 * @param Integer $rating
1056
-	 *
1057
-	 * @return Boolean success
1058
-	 */
1059
-	public static function add_rating($type, $blog_id, $item_id, $rating)
1060
-	{
1061
-		$_user = api_get_user_info();
1062
-
1063
-		// Init
1064
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1065
-		$course_id = api_get_course_int_id();
1066
-
1067
-		// Check if the user has already rated this post/comment
1068
-		$sql = "SELECT rating_id FROM $tbl_blogs_rating
1029
+        echo '<span class="blogpost_info">'.get_lang('Author').': ' .Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - '.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].' - '.get_lang('Rating').': '.Blog::display_rating('post',$blog_id,$post_id).$rating_select.'</span>';
1030
+        echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1031
+        echo '</div>';
1032
+
1033
+        // Display comments if there are any
1034
+        if($blog_post_comments['number_of_comments'] > 0) {
1035
+            echo '<div class="comments">';
1036
+                echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1037
+                Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1038
+            echo '</div>';
1039
+        }
1040
+
1041
+        // Display comment form
1042
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1043
+            Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1044
+        }
1045
+    }
1046
+
1047
+    /**
1048
+     * Adds rating to a certain post or comment
1049
+     * @author Toon Keppens
1050
+     *
1051
+     * @param String $type
1052
+     * @param Integer $blog_id
1053
+     * @param Integer $item_id
1054
+     * @param Integer $rating
1055
+     *
1056
+     * @return Boolean success
1057
+     */
1058
+    public static function add_rating($type, $blog_id, $item_id, $rating)
1059
+    {
1060
+        $_user = api_get_user_info();
1061
+
1062
+        // Init
1063
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1064
+        $course_id = api_get_course_int_id();
1065
+
1066
+        // Check if the user has already rated this post/comment
1067
+        $sql = "SELECT rating_id FROM $tbl_blogs_rating
1069 1068
                 WHERE
1070 1069
                     c_id = $course_id AND
1071 1070
                     blog_id = '".(int)$blog_id."' AND
1072 1071
                     item_id = '".(int)$item_id."' AND
1073 1072
                     rating_type = '".Database::escape_string($type)."' AND
1074 1073
                     user_id = '".(int)$_user['user_id']."'";
1075
-		$result = Database::query($sql);
1074
+        $result = Database::query($sql);
1076 1075
 
1077 1076
         // Add rating
1078
-		if (Database::num_rows($result) == 0) {
1079
-			$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1077
+        if (Database::num_rows($result) == 0) {
1078
+            $sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1080 1079
 					VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".Database::escape_string($rating)."')";
1081
-			Database::query($sql);
1080
+            Database::query($sql);
1082 1081
 
1083 1082
             $id = Database::insert_id();
1084 1083
             if ($id) {
@@ -1086,105 +1085,105 @@  discard block
 block discarded – undo
1086 1085
                 Database::query($sql);
1087 1086
             }
1088 1087
 
1089
-			return true;
1088
+            return true;
1090 1089
         } else {
1091
-			return false;
1092
-		}
1093
-	}
1094
-
1095
-	/**
1096
-	 * Shows the rating of user
1097
-	 *
1098
-	 * @param String $type
1099
-	 * @param Integer $blog_id
1100
-	 * @param Integer $item_id
1101
-	 *
1102
-	 * @return array()
1103
-	 */
1104
-	public static function display_rating($type, $blog_id, $item_id)
1105
-	{
1106
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1107
-		$course_id = api_get_course_int_id();
1108
-
1109
-		// Calculate rating
1110
-		$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1090
+            return false;
1091
+        }
1092
+    }
1093
+
1094
+    /**
1095
+     * Shows the rating of user
1096
+     *
1097
+     * @param String $type
1098
+     * @param Integer $blog_id
1099
+     * @param Integer $item_id
1100
+     *
1101
+     * @return array()
1102
+     */
1103
+    public static function display_rating($type, $blog_id, $item_id)
1104
+    {
1105
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1106
+        $course_id = api_get_course_int_id();
1107
+
1108
+        // Calculate rating
1109
+        $sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1111 1110
 				WHERE
1112 1111
 				    c_id = $course_id AND
1113 1112
 				    blog_id = '".(int)$blog_id."' AND
1114 1113
 				    item_id = '".(int)$item_id."' AND
1115 1114
 				    rating_type = '".Database::escape_string($type)."' ";
1116
-		$result = Database::query($sql);
1117
-		$result = Database::fetch_array($result);
1118
-		return round($result['rating'], 2);
1119
-	}
1120
-
1121
-	/**
1122
-	 * Shows the rating form if not already rated by that user
1123
-	 * @author Toon Keppens
1124
-	 *
1125
-	 * @param String $type
1126
-	 * @param Integer $blog_id
1127
-	 * @param integer $post_id
1128
-	 */
1129
-	public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1130
-	{
1131
-		$_user = api_get_user_info();
1132
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1115
+        $result = Database::query($sql);
1116
+        $result = Database::fetch_array($result);
1117
+        return round($result['rating'], 2);
1118
+    }
1119
+
1120
+    /**
1121
+     * Shows the rating form if not already rated by that user
1122
+     * @author Toon Keppens
1123
+     *
1124
+     * @param String $type
1125
+     * @param Integer $blog_id
1126
+     * @param integer $post_id
1127
+     */
1128
+    public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1129
+    {
1130
+        $_user = api_get_user_info();
1131
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1133 1132
         $course_id = api_get_course_int_id();
1134 1133
 
1135 1134
         if ($type == 'post') {
1136
-			// Check if the user has already rated this post
1137
-			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1135
+            // Check if the user has already rated this post
1136
+            $sql = "SELECT rating_id FROM $tbl_blogs_rating
1138 1137
 					WHERE c_id = $course_id AND
1139 1138
 					blog_id = '".(int)$blog_id."'
1140 1139
 					AND item_id = '".(int)$post_id."'
1141 1140
 					AND rating_type = '".Database::escape_string($type)."'
1142 1141
 					AND user_id = '".(int)$_user['user_id']."'";
1143
-			$result = Database::query($sql);
1142
+            $result = Database::query($sql);
1144 1143
             // Add rating
1145 1144
             if (Database::num_rows($result) == 0) {
1146
-				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';
1145
+                return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';
1147 1146
             } else {
1148
-				return '';
1149
-			}
1150
-		}
1147
+                return '';
1148
+            }
1149
+        }
1151 1150
 
1152 1151
         if ($type = 'comment') {
1153
-			// Check if the user has already rated this comment
1154
-			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1152
+            // Check if the user has already rated this comment
1153
+            $sql = "SELECT rating_id FROM $tbl_blogs_rating
1155 1154
 					WHERE c_id = $course_id AND blog_id = '".(int)$blog_id ."'
1156 1155
 					AND item_id = '".(int)$comment_id."'
1157 1156
 					AND rating_type = '".Database::escape_string($type)."'
1158 1157
 					AND user_id = '".(int)$_user['user_id']."'";
1159
-			$result = Database::query($sql);
1158
+            $result = Database::query($sql);
1160 1159
 
1161 1160
             if (Database::num_rows($result) == 0) {
1162
-				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';
1161
+                return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';
1163 1162
             } else {
1164
-				return '';
1165
-			}
1166
-		}
1167
-	}
1168
-
1169
-	/**
1170
-	 * This functions gets all replys to a post, threaded.
1171
-	 *
1172
-	 * @param Integer $current
1173
-	 * @param Integer $current_level
1174
-	 * @param Integer $blog_id
1175
-	 * @param Integer $post_id
1176
-	 */
1177
-	public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
1178
-	{
1179
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
1180
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1181
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1182
-		global $charset;
1183
-
1184
-		$course_id = api_get_course_int_id();
1185
-
1186
-		// Select top level comments
1187
-		$next_level = $current_level + 1;
1163
+                return '';
1164
+            }
1165
+        }
1166
+    }
1167
+
1168
+    /**
1169
+     * This functions gets all replys to a post, threaded.
1170
+     *
1171
+     * @param Integer $current
1172
+     * @param Integer $current_level
1173
+     * @param Integer $blog_id
1174
+     * @param Integer $post_id
1175
+     */
1176
+    public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
1177
+    {
1178
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
1179
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1180
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1181
+        global $charset;
1182
+
1183
+        $course_id = api_get_course_int_id();
1184
+
1185
+        // Select top level comments
1186
+        $next_level = $current_level + 1;
1188 1187
         $sql = "SELECT comments.*, user.lastname, user.firstname, user.username, task.color
1189 1188
                 FROM $tbl_blogs_comments comments
1190 1189
                 INNER JOIN $tbl_users user
@@ -1196,11 +1195,11 @@  discard block
 block discarded – undo
1196 1195
                     parent_comment_id = $current AND
1197 1196
                     comments.blog_id = '".(int)$blog_id."' AND
1198 1197
                     comments.post_id = '".(int)$post_id."'";
1199
-		$result = Database::query($sql);
1198
+        $result = Database::query($sql);
1200 1199
 
1201
-		while($comment = Database::fetch_array($result)) {
1202
-			// Select the children recursivly
1203
-			$tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1200
+        while($comment = Database::fetch_array($result)) {
1201
+            // Select the children recursivly
1202
+            $tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1204 1203
 			        FROM $tbl_blogs_comments comments
1205 1204
 					INNER JOIN $tbl_users user
1206 1205
 					ON comments.author_id = user.user_id
@@ -1209,15 +1208,15 @@  discard block
 block discarded – undo
1209 1208
 						comment_id = $current
1210 1209
 						AND blog_id = '".(int)$blog_id."'
1211 1210
 						AND post_id = '".(int)$post_id."'";
1212
-			$tmp = Database::query($tmp);
1213
-			$tmp = Database::fetch_array($tmp);
1214
-			$parent_cat = $tmp['parent_comment_id'];
1215
-			$border_color = '';
1216
-
1217
-			// Prepare data
1218
-			$comment_text = make_clickable(stripslashes($comment['comment']));
1219
-			$blog_comment_date = api_convert_and_format_date($comment['date_creation'], null, date_default_timezone_get());
1220
-			$blog_comment_actions = "";
1211
+            $tmp = Database::query($tmp);
1212
+            $tmp = Database::fetch_array($tmp);
1213
+            $parent_cat = $tmp['parent_comment_id'];
1214
+            $border_color = '';
1215
+
1216
+            // Prepare data
1217
+            $comment_text = make_clickable(stripslashes($comment['comment']));
1218
+            $blog_comment_date = api_convert_and_format_date($comment['date_creation'], null, date_default_timezone_get());
1219
+            $blog_comment_actions = "";
1221 1220
             if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id)) {
1222 1221
                 $blog_comment_actions .= '<a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$post_id.'&do=delete_comment&comment_id='.$comment['comment_id'].'&task_id='.$task_id.'" title="'.get_lang(
1223 1222
                         'DeleteThisComment'
@@ -1232,167 +1231,167 @@  discard block
 block discarded – undo
1232 1231
                 $rating_select = Blog::display_rating_form('comment', $blog_id, $post_id, $comment['comment_id']);
1233 1232
             }
1234 1233
 
1235
-			if (!is_null($comment['task_id'])) {
1236
-				$border_color = ' border-left: 3px solid #' . $comment['color'];
1237
-			}
1238
-
1239
-			$comment_text = stripslashes($comment_text);
1240
-
1241
-			// Output...
1242
-			$margin = $current_level * 30;
1243
-			echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1244
-				echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';
1245
-				echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1246
-				echo '<span class="blogpost_text">' . $comment_text . '</span>';
1247
-
1248
-				$file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1249
-				if (!empty($file_name_array)) {
1250
-					echo '<br /><br />';
1251
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1252
-					echo '<a href="download.php?file=';
1253
-					echo $file_name_array['path'];
1254
-					echo ' "> '.$file_name_array['filename'].' </a>';
1255
-					echo '<span class="attachment_comment">';
1256
-					echo $file_name_array['comment'];
1257
-					echo '</span><br />';
1258
-				}
1259
-                $username = api_htmlentities(sprintf(get_lang('LoginX'), $comment['username']), ENT_QUOTES);
1260
-				echo '<span class="blogpost_comment_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($comment['firstname'], $comment['lastname']), array('title'=>$username)).' - '.get_lang('Rating').': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']).$rating_select.'</span>';
1261
-				echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1262
-			echo '</div>';
1263
-
1264
-			// Go further down the tree.
1265
-			Blog::get_threaded_comments($comment['comment_id'], $next_level, $blog_id, $post_id);
1266
-		}
1267
-	}
1268
-
1269
-	/**
1270
-	 * Displays the form to create a new post
1271
-	 * @author Toon Keppens
1272
-	 *
1273
-	 * @param Integer $blog_id
1274
-	 */
1275
-	public static function display_form_new_post($blog_id)
1276
-	{
1277
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1278
-			$form = new FormValidator(
1279
-				'add_post',
1280
-				'post',
1281
-				api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1282
-				null,
1283
-				array('enctype' => 'multipart/form-data')
1284
-			);
1285
-			$form->addHidden('post_title_edited', 'false');
1286
-			$form->addHeader(get_lang('NewPost'));
1287
-			$form->addText('title', get_lang('Title'));
1288
-			$config = array();
1289
-			if (!api_is_allowed_to_edit()) {
1290
-				$config['ToolbarSet'] = 'ProjectStudent';
1291
-			} else {
1292
-				$config['ToolbarSet'] = 'Project';
1293
-			}
1294
-			$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1295
-			$form->addFile('user_upload', get_lang('AddAnAttachment'));
1296
-			$form->addTextarea('post_file_comment', get_lang('FileComment'));
1297
-			$form->addHidden('new_post_submit', 'true');
1298
-			$form->addButton('save', get_lang('Save'));
1299
-
1300
-			$form->display();
1301
-		} else {
1302
-			api_not_allowed();
1303
-		}
1304
-	}
1305
-
1306
-	/**
1307
-	 * Displays the form to edit a post
1308
-	 * @author Toon Keppens
1309
-	 *
1310
-	 * @param Integer $blog_id
1311
-	 */
1312
-	public static function display_form_edit_post($blog_id, $post_id)
1313
-	{
1314
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1315
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1316
-
1317
-		$course_id = api_get_course_int_id();
1318
-
1319
-		// Get posts and author
1320
-		$sql = "SELECT post.*, user.lastname, user.firstname
1321
-				FROM $tbl_blogs_posts post
1322
-				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1323
-				WHERE
1324
-				post.c_id 			= $course_id AND
1325
-				post.blog_id 		= '".(int)$blog_id ."'
1326
-				AND post.post_id	= '".(int)$post_id."'
1327
-				ORDER BY post_id DESC";
1328
-		$result = Database::query($sql);
1329
-		$blog_post = Database::fetch_array($result);
1330
-
1331
-		// Form
1332
-		$form = new FormValidator(
1333
-			'edit_post',
1334
-			'post',
1335
-			api_get_path(WEB_CODE_PATH).'blog/blog.php?action=edit_post&post_id=' . intval($_GET['post_id']) . '&blog_id=' . intval($blog_id) . '&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id'])
1336
-		);
1337
-
1338
-		$form->addHeader(get_lang('EditPost'));
1339
-		$form->addText('title', get_lang('Title'));
1340
-
1341
-		if (!api_is_allowed_to_edit()) {
1342
-			$config['ToolbarSet'] = 'ProjectStudent';
1343
-		} else {
1344
-			$config['ToolbarSet'] = 'Project';
1345
-		}
1346
-		$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1347
-
1348
-		$form->addHidden('action', '');
1349
-		$form->addHidden('edit_post_submit', 'true');
1350
-		$form->addHidden('post_id', intval($_GET['post_id']));
1351
-		$form->addButton('save', get_lang('Save'));
1352
-		$form->setDefaults($blog_post);
1353
-		$form->display();
1354
-	}
1355
-
1356
-	/**
1357
-	 * Displays a list of tasks in this blog
1358
-	 * @author Toon Keppens
1359
-	 *
1360
-	 * @param Integer $blog_id
1361
-	 */
1362
-	public static function display_task_list($blog_id)
1234
+            if (!is_null($comment['task_id'])) {
1235
+                $border_color = ' border-left: 3px solid #' . $comment['color'];
1236
+            }
1237
+
1238
+            $comment_text = stripslashes($comment_text);
1239
+
1240
+            // Output...
1241
+            $margin = $current_level * 30;
1242
+            echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1243
+                echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';
1244
+                echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1245
+                echo '<span class="blogpost_text">' . $comment_text . '</span>';
1246
+
1247
+                $file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1248
+                if (!empty($file_name_array)) {
1249
+                    echo '<br /><br />';
1250
+                    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1251
+                    echo '<a href="download.php?file=';
1252
+                    echo $file_name_array['path'];
1253
+                    echo ' "> '.$file_name_array['filename'].' </a>';
1254
+                    echo '<span class="attachment_comment">';
1255
+                    echo $file_name_array['comment'];
1256
+                    echo '</span><br />';
1257
+                }
1258
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $comment['username']), ENT_QUOTES);
1259
+                echo '<span class="blogpost_comment_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($comment['firstname'], $comment['lastname']), array('title'=>$username)).' - '.get_lang('Rating').': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']).$rating_select.'</span>';
1260
+                echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1261
+            echo '</div>';
1262
+
1263
+            // Go further down the tree.
1264
+            Blog::get_threaded_comments($comment['comment_id'], $next_level, $blog_id, $post_id);
1265
+        }
1266
+    }
1267
+
1268
+    /**
1269
+     * Displays the form to create a new post
1270
+     * @author Toon Keppens
1271
+     *
1272
+     * @param Integer $blog_id
1273
+     */
1274
+    public static function display_form_new_post($blog_id)
1275
+    {
1276
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1277
+            $form = new FormValidator(
1278
+                'add_post',
1279
+                'post',
1280
+                api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1281
+                null,
1282
+                array('enctype' => 'multipart/form-data')
1283
+            );
1284
+            $form->addHidden('post_title_edited', 'false');
1285
+            $form->addHeader(get_lang('NewPost'));
1286
+            $form->addText('title', get_lang('Title'));
1287
+            $config = array();
1288
+            if (!api_is_allowed_to_edit()) {
1289
+                $config['ToolbarSet'] = 'ProjectStudent';
1290
+            } else {
1291
+                $config['ToolbarSet'] = 'Project';
1292
+            }
1293
+            $form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1294
+            $form->addFile('user_upload', get_lang('AddAnAttachment'));
1295
+            $form->addTextarea('post_file_comment', get_lang('FileComment'));
1296
+            $form->addHidden('new_post_submit', 'true');
1297
+            $form->addButton('save', get_lang('Save'));
1298
+
1299
+            $form->display();
1300
+        } else {
1301
+            api_not_allowed();
1302
+        }
1303
+    }
1304
+
1305
+    /**
1306
+     * Displays the form to edit a post
1307
+     * @author Toon Keppens
1308
+     *
1309
+     * @param Integer $blog_id
1310
+     */
1311
+    public static function display_form_edit_post($blog_id, $post_id)
1312
+    {
1313
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1314
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1315
+
1316
+        $course_id = api_get_course_int_id();
1317
+
1318
+        // Get posts and author
1319
+        $sql = "SELECT post.*, user.lastname, user.firstname
1320
+				FROM $tbl_blogs_posts post
1321
+				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1322
+				WHERE
1323
+				post.c_id 			= $course_id AND
1324
+				post.blog_id 		= '".(int)$blog_id ."'
1325
+				AND post.post_id	= '".(int)$post_id."'
1326
+				ORDER BY post_id DESC";
1327
+        $result = Database::query($sql);
1328
+        $blog_post = Database::fetch_array($result);
1329
+
1330
+        // Form
1331
+        $form = new FormValidator(
1332
+            'edit_post',
1333
+            'post',
1334
+            api_get_path(WEB_CODE_PATH).'blog/blog.php?action=edit_post&post_id=' . intval($_GET['post_id']) . '&blog_id=' . intval($blog_id) . '&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id'])
1335
+        );
1336
+
1337
+        $form->addHeader(get_lang('EditPost'));
1338
+        $form->addText('title', get_lang('Title'));
1339
+
1340
+        if (!api_is_allowed_to_edit()) {
1341
+            $config['ToolbarSet'] = 'ProjectStudent';
1342
+        } else {
1343
+            $config['ToolbarSet'] = 'Project';
1344
+        }
1345
+        $form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1346
+
1347
+        $form->addHidden('action', '');
1348
+        $form->addHidden('edit_post_submit', 'true');
1349
+        $form->addHidden('post_id', intval($_GET['post_id']));
1350
+        $form->addButton('save', get_lang('Save'));
1351
+        $form->setDefaults($blog_post);
1352
+        $form->display();
1353
+    }
1354
+
1355
+    /**
1356
+     * Displays a list of tasks in this blog
1357
+     * @author Toon Keppens
1358
+     *
1359
+     * @param Integer $blog_id
1360
+     */
1361
+    public static function display_task_list($blog_id)
1363 1362
     {
1364
-		global $charset;
1363
+        global $charset;
1365 1364
         $course_id = api_get_course_int_id();
1366 1365
 
1367
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1368
-			$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1369
-			$counter = 0;
1370
-			global $color2;
1366
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1367
+            $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1368
+            $counter = 0;
1369
+            global $color2;
1371 1370
 
1372
-			echo '<div class="actions">';
1373
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1371
+            echo '<div class="actions">';
1372
+            echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1374 1373
             echo Display::return_icon('blog_newtasks.gif', get_lang('AddTasks'));
1375 1374
             echo get_lang('AddTasks') . '</a> ';
1376
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1375
+            echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1377 1376
             echo Display::return_icon('blog_task.gif', get_lang('AssignTasks'));
1378 1377
             echo get_lang('AssignTasks') . '</a>';
1379
-			?>
1378
+            ?>
1380 1379
 				<a href="<?php echo api_get_self(); ?>?action=manage_rights&blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageRights') ?>">
1381 1380
                     <?php echo Display::return_icon('blog_admin_users.png', get_lang('RightsManager'),'',ICON_SIZE_SMALL). get_lang('RightsManager') ?></a>
1382 1381
 			<?php
1383
-			echo '</div>';
1382
+            echo '</div>';
1384 1383
 
1385
-			echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1386
-			echo "<table class=\"data_table\">";
1387
-			echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1388
-					 "<th width='240'><b>",get_lang('Title'),"</b></th>",
1389
-					 "<th><b>",get_lang('Description'),"</b></th>",
1390
-					 "<th><b>",get_lang('Color'),"</b></th>",
1391
-					 "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1392
-				"</tr>";
1384
+            echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1385
+            echo "<table class=\"data_table\">";
1386
+            echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1387
+                        "<th width='240'><b>",get_lang('Title'),"</b></th>",
1388
+                        "<th><b>",get_lang('Description'),"</b></th>",
1389
+                        "<th><b>",get_lang('Color'),"</b></th>",
1390
+                        "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1391
+                "</tr>";
1393 1392
 
1394 1393
 
1395
-			$sql = " SELECT
1394
+            $sql = " SELECT
1396 1395
                         blog_id,
1397 1396
                         task_id,
1398 1397
                         blog_id,
@@ -1403,64 +1402,64 @@  discard block
 block discarded – undo
1403 1402
                     FROM " . $tbl_blogs_tasks . "
1404 1403
                     WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1405 1404
                     ORDER BY system_task, title";
1406
-			$result = Database::query($sql);
1405
+            $result = Database::query($sql);
1407 1406
 
1408
-			while ($task = Database::fetch_array($result)) {
1409
-				$counter++;
1410
-				$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1411
-				$delete_icon = ($task['system_task'] == '1') ? "delete_na.png" : "delete.png";
1412
-				$delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1413
-				$delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1414
-				$delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1407
+            while ($task = Database::fetch_array($result)) {
1408
+                $counter++;
1409
+                $css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1410
+                $delete_icon = ($task['system_task'] == '1') ? "delete_na.png" : "delete.png";
1411
+                $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1412
+                $delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1413
+                $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1415 1414
 
1416
-				echo '<tr class="' . $css_class . '" valign="top">';
1415
+                echo '<tr class="' . $css_class . '" valign="top">';
1417 1416
                 echo '<td width="240">'.Security::remove_XSS($task['title']).'</td>';
1418 1417
                 echo '<td>'.Security::remove_XSS($task['description']).'</td>';
1419 1418
                 echo '<td><span style="background-color: #'.$task['color'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>';
1420 1419
                 echo '<td width="50">';
1421 1420
                 echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$task['blog_id'].'&do=edit&task_id='.$task['task_id'].'">';
1422 1421
                 echo Display::return_icon('edit.png', get_lang('EditTask'));
1423
-                      echo "</a>";
1424
-                      echo '<a href="'.$delete_link.'"';
1425
-                      echo $delete_confirm;
1426
-                       echo '>';
1422
+                        echo "</a>";
1423
+                        echo '<a href="'.$delete_link.'"';
1424
+                        echo $delete_confirm;
1425
+                        echo '>';
1427 1426
                         echo Display::return_icon($delete_icon, $delete_title);
1428
-                       echo "</a>";
1429
-                     echo '</td>';
1430
-                   echo '</tr>';
1431
-			}
1432
-			echo "</table>";
1433
-		}
1434
-	}
1435
-
1436
-	/**
1437
-	 * Displays a list of tasks assigned to a user in this blog
1438
-	 * @author Toon Keppens
1439
-	 *
1440
-	 * @param Integer $blog_id
1441
-	 */
1442
-	public static function display_assigned_task_list ($blog_id)
1427
+                        echo "</a>";
1428
+                        echo '</td>';
1429
+                    echo '</tr>';
1430
+            }
1431
+            echo "</table>";
1432
+        }
1433
+    }
1434
+
1435
+    /**
1436
+     * Displays a list of tasks assigned to a user in this blog
1437
+     * @author Toon Keppens
1438
+     *
1439
+     * @param Integer $blog_id
1440
+     */
1441
+    public static function display_assigned_task_list ($blog_id)
1443 1442
     {
1444
-		// Init
1445
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1446
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1447
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1448
-		$counter = 0;
1449
-		global $charset,$color2;
1450
-
1451
-		echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1452
-		echo "<table class=\"data_table\">";
1453
-		echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1454
-				 "<th width='240'><b>",get_lang('Member'),"</b></th>",
1455
-				 "<th><b>",get_lang('Task'),"</b></th>",
1456
-				 "<th><b>",get_lang('Description'),"</b></th>",
1457
-				 "<th><b>",get_lang('TargetDate'),"</b></th>",
1458
-				 "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1459
-			"</tr>";
1460
-
1461
-		$course_id = api_get_course_int_id();
1462
-
1463
-		$sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id
1443
+        // Init
1444
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1445
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1446
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1447
+        $counter = 0;
1448
+        global $charset,$color2;
1449
+
1450
+        echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1451
+        echo "<table class=\"data_table\">";
1452
+        echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1453
+                    "<th width='240'><b>",get_lang('Member'),"</b></th>",
1454
+                    "<th><b>",get_lang('Task'),"</b></th>",
1455
+                    "<th><b>",get_lang('Description'),"</b></th>",
1456
+                    "<th><b>",get_lang('TargetDate'),"</b></th>",
1457
+                    "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1458
+            "</tr>";
1459
+
1460
+        $course_id = api_get_course_int_id();
1461
+
1462
+        $sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id
1464 1463
 				FROM $tbl_blogs_tasks_rel_user task_rel_user
1465 1464
 				INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
1466 1465
 				INNER JOIN $tbl_users user ON task_rel_user.user_id = user.user_id
@@ -1469,15 +1468,15 @@  discard block
 block discarded – undo
1469 1468
 					task.c_id = $course_id AND
1470 1469
 					task_rel_user.blog_id = '".(int)$blog_id."'
1471 1470
 				ORDER BY target_date ASC";
1472
-		$result = Database::query($sql);
1471
+        $result = Database::query($sql);
1473 1472
 
1474
-		while ($assignment = Database::fetch_array($result)) {
1475
-			$counter++;
1476
-			$css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1477
-			$delete_icon = ($assignment['system_task'] == '1') ? "delete_na.png" : "delete.png";
1478
-			$delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1479
-			$delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1480
-			$delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1473
+        while ($assignment = Database::fetch_array($result)) {
1474
+            $counter++;
1475
+            $css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1476
+            $delete_icon = ($assignment['system_task'] == '1') ? "delete_na.png" : "delete.png";
1477
+            $delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1478
+            $delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1479
+            $delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1481 1480
 
1482 1481
             $username = api_htmlentities(sprintf(get_lang('LoginX'), $assignment['username']), ENT_QUOTES);
1483 1482
 
@@ -1492,26 +1491,26 @@  discard block
 block discarded – undo
1492 1491
             echo '<td>'.$assignment['target_date'].'</td>';
1493 1492
             echo '<td width="50">';
1494 1493
             echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=edit_assignment&task_id='.$assignment['task_id'].'&user_id='.$assignment['user_id'].'">';
1495
-	            echo Display::return_icon('edit.png', get_lang('EditTask'));
1496
-				echo "</a>";
1497
-				echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=delete_assignment&task_id='.$assignment['task_id'].'&user_id='.$assignment['user_id'].'" ';
1498
-				echo 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"';
1494
+                echo Display::return_icon('edit.png', get_lang('EditTask'));
1495
+                echo "</a>";
1496
+                echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=delete_assignment&task_id='.$assignment['task_id'].'&user_id='.$assignment['user_id'].'" ';
1497
+                echo 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"';
1499 1498
                 echo Display::return_icon($delete_icon, $delete_title);
1500
-				echo "</a>";
1501
-				echo '</td>';
1502
-				echo '</tr>';
1503
-		}
1504
-		echo "</table>";
1505
-	}
1506
-
1507
-	/**
1508
-	 * Displays new task form
1509
-	 * @author Toon Keppens
1510
-	 *
1511
-	 */
1512
-	public static function display_new_task_form ($blog_id)
1513
-	{
1514
-		// Init
1499
+                echo "</a>";
1500
+                echo '</td>';
1501
+                echo '</tr>';
1502
+        }
1503
+        echo "</table>";
1504
+    }
1505
+
1506
+    /**
1507
+     * Displays new task form
1508
+     * @author Toon Keppens
1509
+     *
1510
+     */
1511
+    public static function display_new_task_form ($blog_id)
1512
+    {
1513
+        // Init
1515 1514
         $colors = array(
1516 1515
             'FFFFFF',
1517 1516
             'FFFF99',
@@ -1530,14 +1529,14 @@  discard block
 block discarded – undo
1530 1529
             '000000'
1531 1530
         );
1532 1531
 
1533
-		// form
1534
-		echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1532
+        // form
1533
+        echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1535 1534
 
1536
-		// form title
1537
-		echo '<legend>'.get_lang('AddTask').'</legend>';
1535
+        // form title
1536
+        echo '<legend>'.get_lang('AddTask').'</legend>';
1538 1537
 
1539
-		// task title
1540
-		echo '	<div class="control-group">
1538
+        // task title
1539
+        echo '	<div class="control-group">
1541 1540
 					<label class="control-label">
1542 1541
 						<span class="form_required">*</span>' . get_lang('Title') . '
1543 1542
 					</label>
@@ -1546,8 +1545,8 @@  discard block
 block discarded – undo
1546 1545
 					</div>
1547 1546
 				</div>';
1548 1547
 
1549
-		// task comment
1550
-		echo '	<div class="control-group">
1548
+        // task comment
1549
+        echo '	<div class="control-group">
1551 1550
 					<label class="control-label">
1552 1551
 						' . get_lang('Description') . '
1553 1552
 					</label>
@@ -1556,8 +1555,8 @@  discard block
 block discarded – undo
1556 1555
 					</div>
1557 1556
 				</div>';
1558 1557
 
1559
-		// task management
1560
-		echo '	<div class="control-group">
1558
+        // task management
1559
+        echo '	<div class="control-group">
1561 1560
 					<label class="control-label">
1562 1561
 						' . get_lang('TaskManager') . '
1563 1562
 					</label>
@@ -1578,12 +1577,12 @@  discard block
 block discarded – undo
1578 1577
                         echo '<td style="border:1px dotted #808080; text-align:center;"><input id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1579 1578
                     echo '</tr>';
1580 1579
                 echo '</table>';
1581
-		echo '		</div>
1580
+        echo '		</div>
1582 1581
 				</div>';
1583 1582
 
1584 1583
 
1585
-		// task color
1586
-		echo '	<div class="control-group">
1584
+        // task color
1585
+        echo '	<div class="control-group">
1587 1586
 					<label class="control-label">
1588 1587
 						' . get_lang('Color') . '
1589 1588
 					</label>
@@ -1594,40 +1593,40 @@  discard block
 block discarded – undo
1594 1593
                     echo '<option value="' . $color . '" ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1595 1594
                 }
1596 1595
         echo '</select>';
1597
-		echo '		</div>
1596
+        echo '		</div>
1598 1597
 				</div>';
1599 1598
 
1600
-		// submit
1601
-		echo '	<div class="control-group">
1599
+        // submit
1600
+        echo '	<div class="control-group">
1602 1601
 					<div class="controls">
1603 1602
 							<input type="hidden" name="action" value="" />
1604 1603
 							<input type="hidden" name="new_task_submit" value="true" />
1605 1604
 						<button class="save" type="submit" name="Submit">' . get_lang('Save') . '</button>
1606 1605
 					</div>
1607 1606
 				</div>';
1608
-		echo '</form>';
1607
+        echo '</form>';
1609 1608
 
1610
-		echo '<div style="clear:both; margin-bottom: 10px;"></div>';
1611
-	}
1609
+        echo '<div style="clear:both; margin-bottom: 10px;"></div>';
1610
+    }
1612 1611
 
1613 1612
 
1614
-	/**
1615
-	 * Displays edit task form
1616
-	 * @author Toon Keppens
1617
-	 *
1618
-	 */
1619
-	public static function display_edit_task_form ($blog_id, $task_id) {
1620
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1613
+    /**
1614
+     * Displays edit task form
1615
+     * @author Toon Keppens
1616
+     *
1617
+     */
1618
+    public static function display_edit_task_form ($blog_id, $task_id) {
1619
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1621 1620
         $course_id = api_get_course_int_id();
1622 1621
 
1623
-		$colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1622
+        $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1624 1623
 
1625
-		$sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1626
-		$result = Database::query($sql);
1627
-		$task = Database::fetch_array($result);
1624
+        $sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1625
+        $result = Database::query($sql);
1626
+        $task = Database::fetch_array($result);
1628 1627
 
1629
-		// Display
1630
-		echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1628
+        // Display
1629
+        echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1631 1630
 					<legend>' . get_lang('EditTask') . '</legend>
1632 1631
 					<table width="100%" border="0" cellspacing="2">
1633 1632
 						<tr>
@@ -1639,42 +1638,42 @@  discard block
 block discarded – undo
1639 1638
 					   <td><textarea name="task_description" cols="45">'.Security::remove_XSS($task['description']).'</textarea></td>
1640 1639
 						</tr>';
1641 1640
 
1642
-						/* edit by Kevin Van Den Haute ([email protected]) */
1643
-						$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1641
+                        /* edit by Kevin Van Den Haute ([email protected]) */
1642
+                        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1644 1643
 
1645
-						$sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1644
+                        $sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1646 1645
 							     WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
1647
-						$result = Database::query($sql);
1648
-
1649
-						$arrPermissions = array();
1650
-
1651
-						while ($row = Database::fetch_array($result))
1652
-							$arrPermissions[] = $row['action'];
1653
-
1654
-						    echo '<tr>';
1655
-							echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1656
-							echo '<td>';
1657
-								echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1658
-									echo '<tr>';
1659
-										echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1660
-										echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1661
-									echo '</tr>';
1662
-									echo '<tr>';
1663
-										echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1664
-										echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1665
-										echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1666
-									echo '</tr>';
1667
-									echo '<tr>';
1668
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1669
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1670
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1671
-									echo '</tr>';
1672
-								echo '</table>';
1673
-							echo '</td>';
1674
-						echo '</tr>';
1675
-						/* end of edit */
1676
-
1677
-						echo '<tr>
1646
+                        $result = Database::query($sql);
1647
+
1648
+                        $arrPermissions = array();
1649
+
1650
+                        while ($row = Database::fetch_array($result))
1651
+                            $arrPermissions[] = $row['action'];
1652
+
1653
+                            echo '<tr>';
1654
+                            echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1655
+                            echo '<td>';
1656
+                                echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1657
+                                    echo '<tr>';
1658
+                                        echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1659
+                                        echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1660
+                                    echo '</tr>';
1661
+                                    echo '<tr>';
1662
+                                        echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1663
+                                        echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1664
+                                        echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1665
+                                    echo '</tr>';
1666
+                                    echo '<tr>';
1667
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1668
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1669
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1670
+                                    echo '</tr>';
1671
+                                echo '</table>';
1672
+                            echo '</td>';
1673
+                        echo '</tr>';
1674
+                        /* end of edit */
1675
+
1676
+                        echo '<tr>
1678 1677
 					   <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
1679 1678
 					   <td>
1680 1679
 					   	<select name="task_color" id="color" style="width: 150px; background-color: #' . $task['color'] . '" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
@@ -1683,7 +1682,7 @@  discard block
 block discarded – undo
1683 1682
                                 $style = 'style="background-color: #' . $color . '"';
1684 1683
                                 echo '<option value="' . $color . '" ' . $style . ' ' . $selected . ' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1685 1684
                             }
1686
-		echo '			   </select>
1685
+        echo '			   </select>
1687 1686
 						  </td>
1688 1687
 						</tr>
1689 1688
 						<tr>
@@ -1696,34 +1695,34 @@  discard block
 block discarded – undo
1696 1695
 						</tr>
1697 1696
 					</table>
1698 1697
 				</form>';
1699
-	}
1700
-
1701
-	/**
1702
-	 * @param $blog_id
1703
-	 * @return FormValidator
1704
-	 */
1705
-	public static function getTaskForm($blog_id)
1706
-	{
1707
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1708
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1709
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1710
-		$course_id = api_get_course_int_id();
1711
-
1712
-		// Get users in this blog / make select list of it
1713
-		$sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
1698
+    }
1699
+
1700
+    /**
1701
+     * @param $blog_id
1702
+     * @return FormValidator
1703
+     */
1704
+    public static function getTaskForm($blog_id)
1705
+    {
1706
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1707
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1708
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1709
+        $course_id = api_get_course_int_id();
1710
+
1711
+        // Get users in this blog / make select list of it
1712
+        $sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
1714 1713
 				FROM $tbl_users user
1715 1714
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
1716 1715
 				ON user.user_id = blogs_rel_user.user_id
1717 1716
 				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
1718
-		$result = Database::query($sql);
1717
+        $result = Database::query($sql);
1719 1718
 
1720
-		$options = array();
1721
-		while ($user = Database::fetch_array($result)) {
1722
-			$options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
1723
-		}
1719
+        $options = array();
1720
+        while ($user = Database::fetch_array($result)) {
1721
+            $options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
1722
+        }
1724 1723
 
1725
-		// Get tasks in this blog / make select list of it
1726
-		$sql = "
1724
+        // Get tasks in this blog / make select list of it
1725
+        $sql = "
1727 1726
 			SELECT
1728 1727
 				blog_id,
1729 1728
 				task_id,
@@ -1735,97 +1734,97 @@  discard block
 block discarded – undo
1735 1734
 			FROM $tbl_blogs_tasks
1736 1735
 			WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1737 1736
 			ORDER BY system_task, title";
1738
-		$result = Database::query($sql);
1739
-
1740
-		$taskOptions = array();
1741
-		while ($task = Database::fetch_array($result)) {
1742
-			$taskOptions[$task['task_id']] = stripslashes($task['title']);
1743
-		}
1744
-
1745
-		$form = new FormValidator(
1746
-			'assign_task',
1747
-			'post',
1748
-			api_get_path(
1749
-				WEB_CODE_PATH
1750
-			).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id
1751
-		);
1752
-
1753
-		$form->addHeader(get_lang('AssignTask'));
1754
-		$form->addSelect('task_user_id', get_lang('SelectUser'), $options);
1755
-		$form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions);
1756
-		$form->addDatePicker('task_day', get_lang('SelectTargetDate'));
1757
-
1758
-		$form->addHidden('action', '');
1759
-		$form->addButtonSave(get_lang('Ok'));
1760
-
1761
-		return $form;
1762
-	}
1763
-
1764
-	/**
1765
-	 * Displays assign task form
1766
-	 * @author Toon Keppens
1767
-	 *
1768
-	 */
1769
-	public static function display_assign_task_form($blog_id)
1770
-	{
1771
-		$form = self::getTaskForm($blog_id);
1772
-		$form->addHidden('assign_task_submit', 'true');
1773
-		$form->display();
1774
-		echo '<div style="clear: both; margin-bottom:10px;"></div>';
1775
-	}
1776
-
1777
-	/**
1778
-	 * Displays assign task form
1779
-	 * @author Toon Keppens
1780
-	 *
1781
-	 */
1782
-	public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1783
-	{
1784
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1785
-
1786
-		$course_id = api_get_course_int_id();
1787
-
1788
-		// Get assignd date;
1789
-		$sql = "
1737
+        $result = Database::query($sql);
1738
+
1739
+        $taskOptions = array();
1740
+        while ($task = Database::fetch_array($result)) {
1741
+            $taskOptions[$task['task_id']] = stripslashes($task['title']);
1742
+        }
1743
+
1744
+        $form = new FormValidator(
1745
+            'assign_task',
1746
+            'post',
1747
+            api_get_path(
1748
+                WEB_CODE_PATH
1749
+            ).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id
1750
+        );
1751
+
1752
+        $form->addHeader(get_lang('AssignTask'));
1753
+        $form->addSelect('task_user_id', get_lang('SelectUser'), $options);
1754
+        $form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions);
1755
+        $form->addDatePicker('task_day', get_lang('SelectTargetDate'));
1756
+
1757
+        $form->addHidden('action', '');
1758
+        $form->addButtonSave(get_lang('Ok'));
1759
+
1760
+        return $form;
1761
+    }
1762
+
1763
+    /**
1764
+     * Displays assign task form
1765
+     * @author Toon Keppens
1766
+     *
1767
+     */
1768
+    public static function display_assign_task_form($blog_id)
1769
+    {
1770
+        $form = self::getTaskForm($blog_id);
1771
+        $form->addHidden('assign_task_submit', 'true');
1772
+        $form->display();
1773
+        echo '<div style="clear: both; margin-bottom:10px;"></div>';
1774
+    }
1775
+
1776
+    /**
1777
+     * Displays assign task form
1778
+     * @author Toon Keppens
1779
+     *
1780
+     */
1781
+    public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1782
+    {
1783
+        $tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1784
+
1785
+        $course_id = api_get_course_int_id();
1786
+
1787
+        // Get assignd date;
1788
+        $sql = "
1790 1789
 			SELECT target_date
1791 1790
 			FROM $tbl_blogs_tasks_rel_user
1792 1791
 			WHERE c_id = $course_id AND
1793 1792
 			      blog_id = '".(int)$blog_id."' AND
1794 1793
 			      user_id = '".(int)$user_id."' AND
1795 1794
 			      task_id = '".(int)$task_id."'";
1796
-		$result = Database::query($sql);
1797
-		$row = Database::fetch_assoc($result);
1798
-
1799
-		$date = $row['target_date'];
1800
-
1801
-		$defaults = [
1802
-			'task_user_id' => $user_id,
1803
-			'task_task_id' => $task_id,
1804
-			'task_day' => $date
1805
-		];
1806
-		$form = self::getTaskForm($blog_id);
1807
-		$form->addHidden('old_task_id', $task_id);
1808
-		$form->addHidden('old_user_id', $user_id);
1809
-		$form->addHidden('old_target_date', $date);
1810
-		$form->addHidden('assign_task_edit_submit', 'true');
1811
-		$form->setDefaults($defaults);
1812
-		$form->display();
1813
-	}
1814
-
1815
-	/**
1816
-	 * Assigns a task to a user in a blog
1817
-	 *
1818
-	 * @param Integer $blog_id
1819
-	 * @param Integer $user_id
1820
-	 * @param Integer $task_id
1821
-	 * @param Date $target_date
1822
-	 */
1823
-	public static function assign_task($blog_id, $user_id, $task_id, $target_date)
1824
-	{
1825
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1826
-		$course_id = api_get_course_int_id();
1827
-
1828
-		$sql = "
1795
+        $result = Database::query($sql);
1796
+        $row = Database::fetch_assoc($result);
1797
+
1798
+        $date = $row['target_date'];
1799
+
1800
+        $defaults = [
1801
+            'task_user_id' => $user_id,
1802
+            'task_task_id' => $task_id,
1803
+            'task_day' => $date
1804
+        ];
1805
+        $form = self::getTaskForm($blog_id);
1806
+        $form->addHidden('old_task_id', $task_id);
1807
+        $form->addHidden('old_user_id', $user_id);
1808
+        $form->addHidden('old_target_date', $date);
1809
+        $form->addHidden('assign_task_edit_submit', 'true');
1810
+        $form->setDefaults($defaults);
1811
+        $form->display();
1812
+    }
1813
+
1814
+    /**
1815
+     * Assigns a task to a user in a blog
1816
+     *
1817
+     * @param Integer $blog_id
1818
+     * @param Integer $user_id
1819
+     * @param Integer $task_id
1820
+     * @param Date $target_date
1821
+     */
1822
+    public static function assign_task($blog_id, $user_id, $task_id, $target_date)
1823
+    {
1824
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1825
+        $course_id = api_get_course_int_id();
1826
+
1827
+        $sql = "
1829 1828
 			SELECT COUNT(*) as 'number'
1830 1829
 			FROM " . $tbl_blogs_tasks_rel_user . "
1831 1830
 			WHERE c_id = $course_id AND
@@ -1834,11 +1833,11 @@  discard block
 block discarded – undo
1834 1833
 			AND	task_id = " . (int)$task_id . "
1835 1834
 		";
1836 1835
 
1837
-		$result = Database::query($sql);
1838
-		$row = Database::fetch_assoc($result);
1836
+        $result = Database::query($sql);
1837
+        $row = Database::fetch_assoc($result);
1839 1838
 
1840
-		if ($row['number'] == 0) {
1841
-			$sql = "
1839
+        if ($row['number'] == 0) {
1840
+            $sql = "
1842 1841
 				INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
1843 1842
 					c_id,
1844 1843
 					blog_id,
@@ -1853,9 +1852,9 @@  discard block
 block discarded – undo
1853 1852
 					'" . Database::escape_string($target_date) . "'
1854 1853
 				)";
1855 1854
 
1856
-			Database::query($sql);
1857
-		}
1858
-	}
1855
+            Database::query($sql);
1856
+        }
1857
+    }
1859 1858
 
1860 1859
     /**
1861 1860
      * @param $blog_id
@@ -1875,11 +1874,11 @@  discard block
 block discarded – undo
1875 1874
         $old_task_id,
1876 1875
         $old_target_date
1877 1876
     ) {
1878
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1877
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1879 1878
 
1880
-		$course_id = api_get_course_int_id();
1879
+        $course_id = api_get_course_int_id();
1881 1880
 
1882
-		$sql = "SELECT COUNT(*) as 'number'
1881
+        $sql = "SELECT COUNT(*) as 'number'
1883 1882
                 FROM " . $tbl_blogs_tasks_rel_user . "
1884 1883
                 WHERE
1885 1884
                     c_id = $course_id AND
@@ -1888,11 +1887,11 @@  discard block
 block discarded – undo
1888 1887
                     task_id = " . (int)$task_id . "
1889 1888
             ";
1890 1889
 
1891
-		$result = Database::query($sql);
1892
-		$row = Database::fetch_assoc($result);
1890
+        $result = Database::query($sql);
1891
+        $row = Database::fetch_assoc($result);
1893 1892
 
1894
-		if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1895
-			$sql = "
1893
+        if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1894
+            $sql = "
1896 1895
 				UPDATE " . $tbl_blogs_tasks_rel_user . "
1897 1896
 				SET
1898 1897
 					user_id = " . (int)$user_id . ",
@@ -1905,76 +1904,76 @@  discard block
 block discarded – undo
1905 1904
 					task_id = " . (int)$old_task_id . " AND
1906 1905
 					target_date = '" . Database::escape_string($old_target_date) . "'
1907 1906
 			";
1908
-			Database::query($sql);
1909
-		}
1910
-	}
1911
-
1912
-	/**
1913
-	 * Displays a list with posts a user can select to execute his task.
1914
-	 *
1915
-	 * @param Integer $blog_id
1916
-	 * @param unknown_type $task_id
1917
-	 */
1918
-	public static function display_select_task_post($blog_id, $task_id)
1907
+            Database::query($sql);
1908
+        }
1909
+    }
1910
+
1911
+    /**
1912
+     * Displays a list with posts a user can select to execute his task.
1913
+     *
1914
+     * @param Integer $blog_id
1915
+     * @param unknown_type $task_id
1916
+     */
1917
+    public static function display_select_task_post($blog_id, $task_id)
1919 1918
     {
1920
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1921
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1922
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1923
-		$course_id = api_get_course_int_id();
1919
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1920
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1921
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1922
+        $course_id = api_get_course_int_id();
1924 1923
 
1925 1924
 
1926
-		$sql = "SELECT title, description FROM $tbl_blogs_tasks
1925
+        $sql = "SELECT title, description FROM $tbl_blogs_tasks
1927 1926
 				WHERE task_id = '".(int)$task_id."'
1928 1927
 				AND c_id = $course_id";
1929
-		$result = Database::query($sql);
1930
-		$row = Database::fetch_assoc($result);
1931
-		// Get posts and authors
1932
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
1928
+        $result = Database::query($sql);
1929
+        $row = Database::fetch_assoc($result);
1930
+        // Get posts and authors
1931
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
1933 1932
 				FROM $tbl_blogs_posts post
1934 1933
 				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1935 1934
 				WHERE post.blog_id = '".(int)$blog_id."' AND post.c_id = $course_id
1936 1935
 				ORDER BY post_id DESC
1937 1936
 				LIMIT 0, 100";
1938
-		$result = Database::query($sql);
1937
+        $result = Database::query($sql);
1939 1938
 
1940
-		// Display
1941
-		echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1942
-		echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1939
+        // Display
1940
+        echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1941
+        echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1943 1942
 
1944
-		if (Database::num_rows($result) > 0) {
1945
-			while($blog_post = Database::fetch_array($result)) {
1946
-			    $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1947
-				echo '<a href="blog.php?action=execute_task&blog_id=' . $blog_id . '&task_id=' . $task_id . '&post_id=' . $blog_post['post_id'] . '#add_comment">'.stripslashes($blog_post['title']) . '</a>, ' . get_lang('WrittenBy') . ' ' . stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))) . '<br />';
1948
-			}
1943
+        if (Database::num_rows($result) > 0) {
1944
+            while($blog_post = Database::fetch_array($result)) {
1945
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1946
+                echo '<a href="blog.php?action=execute_task&blog_id=' . $blog_id . '&task_id=' . $task_id . '&post_id=' . $blog_post['post_id'] . '#add_comment">'.stripslashes($blog_post['title']) . '</a>, ' . get_lang('WrittenBy') . ' ' . stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))) . '<br />';
1947
+            }
1949 1948
         } else {
1950 1949
             echo get_lang('NoArticles');
1951 1950
         }
1952
-	}
1953
-
1954
-	/**
1955
-	 * Subscribes a user to a given blog
1956
-	 * @author Toon Keppens
1957
-	 *
1958
-	 * @param Integer $blog_id
1959
-	 * @param Integer $user_id
1960
-	 */
1961
-	public static function set_user_subscribed($blog_id, $user_id)
1951
+    }
1952
+
1953
+    /**
1954
+     * Subscribes a user to a given blog
1955
+     * @author Toon Keppens
1956
+     *
1957
+     * @param Integer $blog_id
1958
+     * @param Integer $user_id
1959
+     */
1960
+    public static function set_user_subscribed($blog_id, $user_id)
1962 1961
     {
1963
-		// Init
1964
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1965
-		$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
1962
+        // Init
1963
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1964
+        $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
1966 1965
 
1967
-		$course_id = api_get_course_int_id();
1966
+        $course_id = api_get_course_int_id();
1968 1967
 
1969
-		// Subscribe the user
1970
-		$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1968
+        // Subscribe the user
1969
+        $sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1971 1970
 		        VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
1972
-		Database::query($sql);
1971
+        Database::query($sql);
1973 1972
 
1974
-		// Give this user basic rights
1975
-		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1973
+        // Give this user basic rights
1974
+        $sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1976 1975
 		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
1977
-		Database::query($sql);
1976
+        Database::query($sql);
1978 1977
 
1979 1978
         $id = Database::insert_id();
1980 1979
         if ($id) {
@@ -1982,9 +1981,9 @@  discard block
 block discarded – undo
1982 1981
             Database::query($sql);
1983 1982
         }
1984 1983
 
1985
-		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1984
+        $sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1986 1985
 		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
1987
-		Database::query($sql);
1986
+        Database::query($sql);
1988 1987
 
1989 1988
         $id = Database::insert_id();
1990 1989
         if ($id) {
@@ -1992,197 +1991,197 @@  discard block
 block discarded – undo
1992 1991
             Database::query($sql);
1993 1992
         }
1994 1993
 
1995
-	}
1994
+    }
1996 1995
 
1997
-	/**
1998
-	 * Unsubscribe a user from a given blog
1999
-	 * @author Toon Keppens
2000
-	 *
2001
-	 * @param Integer $blog_id
2002
-	 * @param Integer $user_id
2003
-	 */
2004
-	public static function set_user_unsubscribed($blog_id, $user_id)
1996
+    /**
1997
+     * Unsubscribe a user from a given blog
1998
+     * @author Toon Keppens
1999
+     *
2000
+     * @param Integer $blog_id
2001
+     * @param Integer $user_id
2002
+     */
2003
+    public static function set_user_unsubscribed($blog_id, $user_id)
2005 2004
     {
2006
-		// Init
2005
+        // Init
2007 2006
         $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2008 2007
         $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
2009 2008
 
2010
-		// Unsubscribe the user
2011
-		$sql = "DELETE FROM $tbl_blogs_rel_user
2009
+        // Unsubscribe the user
2010
+        $sql = "DELETE FROM $tbl_blogs_rel_user
2012 2011
 		        WHERE blog_id = '".(int)$blog_id."' AND user_id = '".(int)$user_id."'";
2013
-		Database::query($sql);
2012
+        Database::query($sql);
2014 2013
 
2015
-		// Remove this user's permissions.
2016
-		$sql = "DELETE FROM $tbl_user_permissions
2014
+        // Remove this user's permissions.
2015
+        $sql = "DELETE FROM $tbl_user_permissions
2017 2016
 		        WHERE user_id = '".(int)$user_id."'";
2018
-		Database::query($sql);
2019
-	}
2020
-
2021
-	/**
2022
-	 * Displays the form to register users in a blog (in a course)
2023
-	 * The listed users are users subcribed in the course.
2024
-	 * @author Toon Keppens
2025
-	 *
2026
-	 * @param Integer $blog_id
2027
-	 *
2028
-	 * @return Html Form with sortable table with users to subcribe in a blog, in a course.
2029
-	 */
2030
-	public static function display_form_user_subscribe($blog_id)
2031
-	{
2032
-		$_course = api_get_course_info();
2033
-		$is_western_name_order = api_is_western_name_order();
2034
-		$session_id = api_get_session_id();
2035
-		$course_id = $_course['real_id'];
2036
-
2037
-		$currentCourse = $_course['code'];
2038
-		$tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2039
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2040
-
2041
-		echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
2042
-
2043
-		$properties["width"] = "100%";
2044
-
2045
-		// Get blog members' id.
2046
-		$sql = "SELECT user.user_id FROM $tbl_users user
2017
+        Database::query($sql);
2018
+    }
2019
+
2020
+    /**
2021
+     * Displays the form to register users in a blog (in a course)
2022
+     * The listed users are users subcribed in the course.
2023
+     * @author Toon Keppens
2024
+     *
2025
+     * @param Integer $blog_id
2026
+     *
2027
+     * @return Html Form with sortable table with users to subcribe in a blog, in a course.
2028
+     */
2029
+    public static function display_form_user_subscribe($blog_id)
2030
+    {
2031
+        $_course = api_get_course_info();
2032
+        $is_western_name_order = api_is_western_name_order();
2033
+        $session_id = api_get_session_id();
2034
+        $course_id = $_course['real_id'];
2035
+
2036
+        $currentCourse = $_course['code'];
2037
+        $tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2038
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2039
+
2040
+        echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
2041
+
2042
+        $properties["width"] = "100%";
2043
+
2044
+        // Get blog members' id.
2045
+        $sql = "SELECT user.user_id FROM $tbl_users user
2047 2046
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2048 2047
 				ON user.user_id = blogs_rel_user.user_id
2049 2048
 				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".intval($blog_id)."'";
2050
-		$result = Database::query($sql);
2051
-
2052
-		$blog_member_ids = array();
2053
-		while($user = Database::fetch_array($result)) {
2054
-			$blog_member_ids[] = $user['user_id'];
2055
-		}
2056
-
2057
-		// Set table headers
2058
-		$column_header[] = array ('', false, '');
2059
-		if ($is_western_name_order) {
2060
-			$column_header[] = array(get_lang('FirstName'), true, '');
2061
-			$column_header[] = array(get_lang('LastName'), true, '');
2062
-		} else {
2063
-			$column_header[] = array(get_lang('LastName'), true, '');
2064
-			$column_header[] = array(get_lang('FirstName'), true, '');
2065
-		}
2066
-		$column_header[] = array(get_lang('Email'), false, '');
2067
-		$column_header[] = array(get_lang('Register'), false, '');
2049
+        $result = Database::query($sql);
2050
+
2051
+        $blog_member_ids = array();
2052
+        while($user = Database::fetch_array($result)) {
2053
+            $blog_member_ids[] = $user['user_id'];
2054
+        }
2055
+
2056
+        // Set table headers
2057
+        $column_header[] = array ('', false, '');
2058
+        if ($is_western_name_order) {
2059
+            $column_header[] = array(get_lang('FirstName'), true, '');
2060
+            $column_header[] = array(get_lang('LastName'), true, '');
2061
+        } else {
2062
+            $column_header[] = array(get_lang('LastName'), true, '');
2063
+            $column_header[] = array(get_lang('FirstName'), true, '');
2064
+        }
2065
+        $column_header[] = array(get_lang('Email'), false, '');
2066
+        $column_header[] = array(get_lang('Register'), false, '');
2068 2067
 
2069 2068
         $student_list = CourseManager:: get_student_list_from_course_code(
2070 2069
             $currentCourse,
2071 2070
             false,
2072 2071
             $session_id
2073 2072
         );
2074
-		$user_data = array();
2075
-
2076
-		// Add users that are not in this blog to the list.
2077
-		foreach ($student_list as $key=>$user) {
2078
-			if(isset($user['id_user'])) {
2079
-				$user['user_id'] = $user['id_user'];
2080
-			}
2081
-			if(!in_array($user['user_id'],$blog_member_ids)) {
2082
-				$a_infosUser = api_get_user_info($user['user_id']);
2083
-				$row = array ();
2084
-				$row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2085
-				$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2086
-				if ($is_western_name_order) {
2087
-					$row[] = $a_infosUser["firstname"];
2088
-					$row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2089
-				} else {
2090
-					$row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2091
-					$row[] = $a_infosUser["firstname"];
2092
-				}
2093
-				$row[] = Display::icon_mailto_link($a_infosUser["email"]);
2094
-
2095
-				//Link to register users
2096
-				if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2097
-					$row[] = "<a class=\"btn btn-primary \" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&register=yes&user_id=" . $a_infosUser["user_id"]."\">" . get_lang('Register')."</a>";
2098
-				} else {
2099
-					$row[] = '';
2100
-				}
2101
-				$user_data[] = $row;
2102
-			}
2103
-		}
2104
-
2105
-		// Display
2106
-		$query_vars['action'] = 'manage_members';
2107
-		$query_vars['blog_id'] = $blog_id;
2108
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2109
-			Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2110
-			$link = '';
2111
-			$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2112
-			$link .= "blog_id=$blog_id&";
2113
-
2114
-			echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2115
-			echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2116
-			echo get_lang('WithSelected') . ' : ';
2117
-			echo '<select name="action">';
2118
-			echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2119
-			echo '</select>';
2120
-			echo '<input type="hidden" name="register" value="true" />';
2121
-			echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2122
-		echo '</form>';
2123
-	}
2124
-
2125
-	/**
2126
-	 * Displays the form to register users in a blog (in a course)
2127
-	 * The listed users are users subcribed in the course.
2128
-	 * @author Toon Keppens
2129
-	 *
2130
-	 * @param Integer $blog_id
2131
-	 *
2132
-	 * @return false|null Form with sortable table with users to unsubcribe from a blog.
2133
-	 */
2134
-	public static function display_form_user_unsubscribe ($blog_id)
2135
-	{
2136
-		$_user = api_get_user_info();
2137
-		$is_western_name_order = api_is_western_name_order();
2138
-
2139
-		// Init
2140
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2141
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2142
-
2143
-		echo '<legend>'.get_lang('UnsubscribeMembers').'</legend>';
2144
-
2145
-		$properties["width"] = "100%";
2146
-		//table column titles
2147
-		$column_header[] = array ('', false, '');
2148
-		if ($is_western_name_order) {
2149
-			$column_header[] = array (get_lang('FirstName'), true, '');
2150
-			$column_header[] = array (get_lang('LastName'), true, '');
2151
-		} else {
2152
-			$column_header[] = array (get_lang('LastName'), true, '');
2153
-			$column_header[] = array (get_lang('FirstName'), true, '');
2154
-		}
2155
-		$column_header[] = array (get_lang('Email'), false, '');
2156
-		$column_header[] = array (get_lang('TaskManager'), true, '');
2157
-		$column_header[] = array (get_lang('UnRegister'), false, '');
2158
-
2159
-		$course_id = api_get_course_int_id();
2160
-
2161
-		$sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2073
+        $user_data = array();
2074
+
2075
+        // Add users that are not in this blog to the list.
2076
+        foreach ($student_list as $key=>$user) {
2077
+            if(isset($user['id_user'])) {
2078
+                $user['user_id'] = $user['id_user'];
2079
+            }
2080
+            if(!in_array($user['user_id'],$blog_member_ids)) {
2081
+                $a_infosUser = api_get_user_info($user['user_id']);
2082
+                $row = array ();
2083
+                $row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2084
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2085
+                if ($is_western_name_order) {
2086
+                    $row[] = $a_infosUser["firstname"];
2087
+                    $row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2088
+                } else {
2089
+                    $row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2090
+                    $row[] = $a_infosUser["firstname"];
2091
+                }
2092
+                $row[] = Display::icon_mailto_link($a_infosUser["email"]);
2093
+
2094
+                //Link to register users
2095
+                if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2096
+                    $row[] = "<a class=\"btn btn-primary \" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&register=yes&user_id=" . $a_infosUser["user_id"]."\">" . get_lang('Register')."</a>";
2097
+                } else {
2098
+                    $row[] = '';
2099
+                }
2100
+                $user_data[] = $row;
2101
+            }
2102
+        }
2103
+
2104
+        // Display
2105
+        $query_vars['action'] = 'manage_members';
2106
+        $query_vars['blog_id'] = $blog_id;
2107
+        echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2108
+            Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2109
+            $link = '';
2110
+            $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2111
+            $link .= "blog_id=$blog_id&";
2112
+
2113
+            echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2114
+            echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2115
+            echo get_lang('WithSelected') . ' : ';
2116
+            echo '<select name="action">';
2117
+            echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2118
+            echo '</select>';
2119
+            echo '<input type="hidden" name="register" value="true" />';
2120
+            echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2121
+        echo '</form>';
2122
+    }
2123
+
2124
+    /**
2125
+     * Displays the form to register users in a blog (in a course)
2126
+     * The listed users are users subcribed in the course.
2127
+     * @author Toon Keppens
2128
+     *
2129
+     * @param Integer $blog_id
2130
+     *
2131
+     * @return false|null Form with sortable table with users to unsubcribe from a blog.
2132
+     */
2133
+    public static function display_form_user_unsubscribe ($blog_id)
2134
+    {
2135
+        $_user = api_get_user_info();
2136
+        $is_western_name_order = api_is_western_name_order();
2137
+
2138
+        // Init
2139
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2140
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2141
+
2142
+        echo '<legend>'.get_lang('UnsubscribeMembers').'</legend>';
2143
+
2144
+        $properties["width"] = "100%";
2145
+        //table column titles
2146
+        $column_header[] = array ('', false, '');
2147
+        if ($is_western_name_order) {
2148
+            $column_header[] = array (get_lang('FirstName'), true, '');
2149
+            $column_header[] = array (get_lang('LastName'), true, '');
2150
+        } else {
2151
+            $column_header[] = array (get_lang('LastName'), true, '');
2152
+            $column_header[] = array (get_lang('FirstName'), true, '');
2153
+        }
2154
+        $column_header[] = array (get_lang('Email'), false, '');
2155
+        $column_header[] = array (get_lang('TaskManager'), true, '');
2156
+        $column_header[] = array (get_lang('UnRegister'), false, '');
2157
+
2158
+        $course_id = api_get_course_int_id();
2159
+
2160
+        $sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2162 2161
                 FROM $tbl_users user INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2163 2162
                 ON user.user_id = blogs_rel_user.user_id
2164 2163
                 WHERE blogs_rel_user.c_id = $course_id AND  blogs_rel_user.blog_id = '".(int)$blog_id."'";
2165 2164
 
2166
-		if (!($sql_result = Database::query($sql))) {
2167
-			return false;
2168
-		}
2169
-
2170
-		$user_data = array ();
2171
-
2172
-		while ($myrow = Database::fetch_array($sql_result)) {
2173
-			$row = array ();
2174
-			$row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2175
-			$username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2176
-			if ($is_western_name_order) {
2177
-				$row[] = $myrow["firstname"];
2178
-				$row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2179
-			} else {
2180
-				$row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2181
-				$row[] = $myrow["firstname"];
2182
-			}
2183
-			$row[] = Display::icon_mailto_link($myrow["email"]);
2184
-
2185
-			$sql = "SELECT bt.title task
2165
+        if (!($sql_result = Database::query($sql))) {
2166
+            return false;
2167
+        }
2168
+
2169
+        $user_data = array ();
2170
+
2171
+        while ($myrow = Database::fetch_array($sql_result)) {
2172
+            $row = array ();
2173
+            $row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2174
+            $username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2175
+            if ($is_western_name_order) {
2176
+                $row[] = $myrow["firstname"];
2177
+                $row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2178
+            } else {
2179
+                $row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2180
+                $row[] = $myrow["firstname"];
2181
+            }
2182
+            $row[] = Display::icon_mailto_link($myrow["email"]);
2183
+
2184
+            $sql = "SELECT bt.title task
2186 2185
 					FROM " . Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER) . " btu
2187 2186
 					INNER JOIN " . Database::get_course_table(TABLE_BLOGS_TASKS) . " bt
2188 2187
 					ON btu.task_id = bt.task_id
@@ -2190,157 +2189,157 @@  discard block
 block discarded – undo
2190 2189
 							bt.c_id 	= $course_id  AND
2191 2190
 							btu.blog_id = $blog_id AND
2192 2191
 							btu.user_id = " . $myrow['user_id'];
2193
-			$sql_res = Database::query($sql);
2194
-
2195
-			$task = '';
2196
-
2197
-			while($r = Database::fetch_array($sql_res)) {
2198
-				$task .= stripslashes($r['task']) . ', ';
2199
-			}
2200
-			//echo $task;
2201
-			$task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
2202
-			$row[] = $task;
2203
-			//Link to register users
2204
-
2205
-			if ($myrow["user_id"] != $_user['user_id']) {
2206
-				$row[] = "<a class=\"btn btn-primary\" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=" . $myrow['user_id']."\">" . get_lang('UnRegister')."</a>";
2207
-			} else {
2208
-				$row[] = '';
2209
-			}
2210
-
2211
-			$user_data[] = $row;
2212
-		}
2213
-
2214
-		$query_vars['action'] = 'manage_members';
2215
-		$query_vars['blog_id'] = $blog_id;
2216
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2217
-		Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2218
-		$link = '';
2219
-		$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2220
-		$link .= "blog_id=$blog_id&";
2221
-
2222
-		echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2223
-		echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2224
-		echo get_lang('WithSelected') . ' : ';
2225
-		echo '<select name="action">';
2226
-		echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2227
-		echo '</select>';
2228
-		echo '<input type="hidden" name="unregister" value="true" />';
2229
-		echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2230
-		echo '</form>';
2231
-	}
2232
-
2233
-	/**
2234
-	 * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
2235
-	 * The blog admin can thus select what a certain user can do in the current blog
2236
-	 *
2237
-	 * @param Integer $blog_id
2238
-	 */
2239
-	public static function display_form_user_rights ($blog_id)
2192
+            $sql_res = Database::query($sql);
2193
+
2194
+            $task = '';
2195
+
2196
+            while($r = Database::fetch_array($sql_res)) {
2197
+                $task .= stripslashes($r['task']) . ', ';
2198
+            }
2199
+            //echo $task;
2200
+            $task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
2201
+            $row[] = $task;
2202
+            //Link to register users
2203
+
2204
+            if ($myrow["user_id"] != $_user['user_id']) {
2205
+                $row[] = "<a class=\"btn btn-primary\" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=" . $myrow['user_id']."\">" . get_lang('UnRegister')."</a>";
2206
+            } else {
2207
+                $row[] = '';
2208
+            }
2209
+
2210
+            $user_data[] = $row;
2211
+        }
2212
+
2213
+        $query_vars['action'] = 'manage_members';
2214
+        $query_vars['blog_id'] = $blog_id;
2215
+        echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2216
+        Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2217
+        $link = '';
2218
+        $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2219
+        $link .= "blog_id=$blog_id&";
2220
+
2221
+        echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2222
+        echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2223
+        echo get_lang('WithSelected') . ' : ';
2224
+        echo '<select name="action">';
2225
+        echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2226
+        echo '</select>';
2227
+        echo '<input type="hidden" name="unregister" value="true" />';
2228
+        echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2229
+        echo '</form>';
2230
+    }
2231
+
2232
+    /**
2233
+     * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
2234
+     * The blog admin can thus select what a certain user can do in the current blog
2235
+     *
2236
+     * @param Integer $blog_id
2237
+     */
2238
+    public static function display_form_user_rights ($blog_id)
2239
+    {
2240
+        echo '<legend>'.get_lang('RightsManager').'</legend>';
2241
+        echo '<br />';
2242
+
2243
+        // Integration of patricks permissions system.
2244
+        require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php';
2245
+    }
2246
+
2247
+    /**
2248
+     * Displays the form to create a new post
2249
+     * @author Toon Keppens
2250
+     *
2251
+     * @param Integer $blog_id
2252
+     * @param integer $post_id
2253
+     */
2254
+    public static function display_new_comment_form($blog_id, $post_id, $title)
2240 2255
     {
2241
-		echo '<legend>'.get_lang('RightsManager').'</legend>';
2242
-		echo '<br />';
2243
-
2244
-		// Integration of patricks permissions system.
2245
-		require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php';
2246
-	}
2247
-
2248
-	/**
2249
-	 * Displays the form to create a new post
2250
-	 * @author Toon Keppens
2251
-	 *
2252
-	 * @param Integer $blog_id
2253
-	 * @param integer $post_id
2254
-	 */
2255
-	public static function display_new_comment_form($blog_id, $post_id, $title)
2256
-	{
2257
-		$form = new FormValidator(
2258
-			'add_post',
2259
-			'post',
2260
-			api_get_path(WEB_CODE_PATH)."blog/blog.php?action=view_post&blog_id=" . intval($blog_id)  . "&post_id=".intval($post_id)."&".api_get_cidreq(),
2261
-			null,
2262
-			array('enctype' => 'multipart/form-data')
2263
-		);
2264
-
2265
-		$header = get_lang('AddNewComment');
2266
-		if (isset($_GET['task_id'])) {
2267
-			$header = get_lang('ExecuteThisTask');
2268
-		}
2269
-		$form->addHeader($header);
2270
-		$form->addText('title', get_lang('Title'));
2271
-
2272
-		$config = array();
2273
-		if (!api_is_allowed_to_edit()) {
2274
-			$config['ToolbarSet'] = 'ProjectComment';
2275
-		} else {
2276
-			$config['ToolbarSet'] = 'ProjectCommentStudent';
2277
-		}
2278
-		$form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
2279
-		$form->addFile('user_upload', get_lang('AddAnAttachment'));
2280
-
2281
-		$form->addTextarea('post_file_comment', get_lang('FileComment'));
2282
-
2283
-		$form->addHidden('action', null);
2284
-		$form->addHidden('comment_parent_id', 0);
2285
-
2286
-		if (isset($_GET['task_id'])) {
2287
-			$form->addHidden('new_task_execution_submit', 'true');
2288
-			$form->addHidden('task_id', intval($_GET['task_id']));
2289
-		} else {
2290
-			$form->addHidden('new_comment_submit', 'true');
2291
-		}
2292
-		$form->addButton('save', get_lang('Save'));
2293
-		$form->display();
2294
-	}
2295
-
2296
-
2297
-	/**
2298
-	 * show the calender of the given month
2299
-	 * @author Patrick Cool
2300
-	 * @author Toon Keppens
2301
-	 *
2302
-	 * @param Integer $month: the integer value of the month we are viewing
2303
-	 * @param Integer $year: the 4-digit year indication e.g. 2005
2304
-	 *
2305
-	 * @return html code
2306
-	*/
2307
-	public static function display_minimonthcalendar($month, $year, $blog_id)
2308
-	{
2309
-		// Init
2310
-		$_user = api_get_user_info();
2311
-		global $DaysShort;
2312
-		global $MonthsLong;
2313
-
2314
-		$posts = array();
2315
-		$tasks = array();
2316
-
2317
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2318
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
2319
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
2320
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
2321
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2322
-
2323
-		$course_id = api_get_course_int_id();
2324
-
2325
-		//Handle leap year
2326
-		$numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2327
-
2328
-		if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2329
-			$numberofdays[2] = 29;
2330
-
2331
-		//Get the first day of the month
2332
-		$dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2333
-		$monthName = $MonthsLong[$month-1];
2334
-
2335
-		//Start the week on monday
2336
-		$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2337
-		$blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2338
-		$filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2339
-		$backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2340
-		$forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2341
-
2342
-		// Get posts for this month
2343
-		$sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
2256
+        $form = new FormValidator(
2257
+            'add_post',
2258
+            'post',
2259
+            api_get_path(WEB_CODE_PATH)."blog/blog.php?action=view_post&blog_id=" . intval($blog_id)  . "&post_id=".intval($post_id)."&".api_get_cidreq(),
2260
+            null,
2261
+            array('enctype' => 'multipart/form-data')
2262
+        );
2263
+
2264
+        $header = get_lang('AddNewComment');
2265
+        if (isset($_GET['task_id'])) {
2266
+            $header = get_lang('ExecuteThisTask');
2267
+        }
2268
+        $form->addHeader($header);
2269
+        $form->addText('title', get_lang('Title'));
2270
+
2271
+        $config = array();
2272
+        if (!api_is_allowed_to_edit()) {
2273
+            $config['ToolbarSet'] = 'ProjectComment';
2274
+        } else {
2275
+            $config['ToolbarSet'] = 'ProjectCommentStudent';
2276
+        }
2277
+        $form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
2278
+        $form->addFile('user_upload', get_lang('AddAnAttachment'));
2279
+
2280
+        $form->addTextarea('post_file_comment', get_lang('FileComment'));
2281
+
2282
+        $form->addHidden('action', null);
2283
+        $form->addHidden('comment_parent_id', 0);
2284
+
2285
+        if (isset($_GET['task_id'])) {
2286
+            $form->addHidden('new_task_execution_submit', 'true');
2287
+            $form->addHidden('task_id', intval($_GET['task_id']));
2288
+        } else {
2289
+            $form->addHidden('new_comment_submit', 'true');
2290
+        }
2291
+        $form->addButton('save', get_lang('Save'));
2292
+        $form->display();
2293
+    }
2294
+
2295
+
2296
+    /**
2297
+     * show the calender of the given month
2298
+     * @author Patrick Cool
2299
+     * @author Toon Keppens
2300
+     *
2301
+     * @param Integer $month: the integer value of the month we are viewing
2302
+     * @param Integer $year: the 4-digit year indication e.g. 2005
2303
+     *
2304
+     * @return html code
2305
+     */
2306
+    public static function display_minimonthcalendar($month, $year, $blog_id)
2307
+    {
2308
+        // Init
2309
+        $_user = api_get_user_info();
2310
+        global $DaysShort;
2311
+        global $MonthsLong;
2312
+
2313
+        $posts = array();
2314
+        $tasks = array();
2315
+
2316
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2317
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
2318
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
2319
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
2320
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2321
+
2322
+        $course_id = api_get_course_int_id();
2323
+
2324
+        //Handle leap year
2325
+        $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2326
+
2327
+        if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2328
+            $numberofdays[2] = 29;
2329
+
2330
+        //Get the first day of the month
2331
+        $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2332
+        $monthName = $MonthsLong[$month-1];
2333
+
2334
+        //Start the week on monday
2335
+        $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2336
+        $blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2337
+        $filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2338
+        $backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2339
+        $forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2340
+
2341
+        // Get posts for this month
2342
+        $sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
2344 2343
 				FROM $tbl_blogs_posts post
2345 2344
 				INNER JOIN $tbl_users user
2346 2345
 				ON post.author_id = user.user_id
@@ -2350,20 +2349,20 @@  discard block
 block discarded – undo
2350 2349
 					MONTH(date_creation) = '".(int)$month."' AND
2351 2350
 					YEAR(date_creation) = '".(int)$year."'
2352 2351
 				ORDER BY date_creation";
2353
-		$result = Database::query($sql);
2354
-
2355
-		// We will create an array of days on which there are posts.
2356
-		if( Database::num_rows($result) > 0) {
2357
-			while($blog_post = Database::fetch_array($result)) {
2358
-				// If the day of this post is not yet in the array, add it.
2359
-				if (!in_array($blog_post['post_day'], $posts))
2360
-					$posts[] = $blog_post['post_day'];
2361
-			}
2362
-		}
2363
-
2364
-		// Get tasks for this month
2365
-		if ($_user['user_id']) {
2366
-			$sql = " SELECT task_rel_user.*,  DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
2352
+        $result = Database::query($sql);
2353
+
2354
+        // We will create an array of days on which there are posts.
2355
+        if( Database::num_rows($result) > 0) {
2356
+            while($blog_post = Database::fetch_array($result)) {
2357
+                // If the day of this post is not yet in the array, add it.
2358
+                if (!in_array($blog_post['post_day'], $posts))
2359
+                    $posts[] = $blog_post['post_day'];
2360
+            }
2361
+        }
2362
+
2363
+        // Get tasks for this month
2364
+        if ($_user['user_id']) {
2365
+            $sql = " SELECT task_rel_user.*,  DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
2367 2366
 				FROM $tbl_blogs_tasks_rel_user task_rel_user
2368 2367
 				INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
2369 2368
 				INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
@@ -2375,85 +2374,85 @@  discard block
 block discarded – undo
2375 2374
 					MONTH(target_date) = '".(int)$month."' AND
2376 2375
 					YEAR(target_date) = '".(int)$year."'
2377 2376
 				ORDER BY target_date ASC";
2378
-			$result = Database::query($sql);
2379
-
2380
-			if (Database::num_rows($result) > 0) {
2381
-				while ($mytask = Database::fetch_array($result)) {
2382
-					$tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
2383
-					$tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
2384
-					$tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
2385
-					$tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
2386
-					$tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
2387
-				}
2388
-			}
2389
-		}
2390
-
2391
-		echo 	'<table id="smallcalendar" class="table table-responsive">',
2392
-				"<tr id=\"title\">",
2393
-				"<th width=\"10%\"><a href=\"", $backwardsURL, "\">&laquo;</a></th>",
2394
-				"<th align=\"center\" width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>",
2395
-				"<th width=\"10%\" align=\"right\"><a href=\"", $forewardsURL, "\">&raquo;</a></th>", "</tr>";
2396
-
2397
-		echo "<tr>";
2398
-
2399
-		for($ii = 1; $ii < 8; $ii ++)
2400
-			echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2401
-
2402
-		echo "</tr>";
2403
-
2404
-		$curday = -1;
2405
-		$today = getdate();
2406
-
2407
-		while ($curday <= $numberofdays[$month]) {
2408
-			echo "<tr>";
2409
-			for ($ii = 0; $ii < 7; $ii ++) {
2410
-				if (($curday == -1) && ($ii == $startdayofweek))
2411
-					$curday = 1;
2412
-
2413
-			 	if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2414
-					$bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2415
-					$dayheader = "$curday";
2416
-
2417
-					if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2418
-						$dayheader = "$curday";
2419
-						$class = "class=\"days_today\"";
2420
-					}
2421
-
2422
-					echo "<td " . $class.">";
2423
-
2424
-					// If there are posts on this day, create a filter link.
2425
-					if(in_array($curday, $posts))
2426
-						echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2427
-					else
2428
-						echo $dayheader;
2429
-
2430
-					if (count($tasks) > 0) {
2431
-						if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2432
-							// Add tasks to calendar
2433
-							foreach ($tasks[$curday] as $task) {
2434
-								echo '<a href="blog.php?action=execute_task&blog_id=' . $task['blog_id'] . '&task_id='.stripslashes($task['task_id']) . '" title="' . $task['title'] . ' : ' . get_lang('InBlog') . ' : ' . $task['blog_name'] . ' - ' . get_lang('ExecuteThisTask') . '">';
2435
-								echo Display::return_icon('blog_task.gif', get_lang('ExecuteThisTask'));
2377
+            $result = Database::query($sql);
2378
+
2379
+            if (Database::num_rows($result) > 0) {
2380
+                while ($mytask = Database::fetch_array($result)) {
2381
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
2382
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
2383
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
2384
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
2385
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
2386
+                }
2387
+            }
2388
+        }
2389
+
2390
+        echo 	'<table id="smallcalendar" class="table table-responsive">',
2391
+                "<tr id=\"title\">",
2392
+                "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&laquo;</a></th>",
2393
+                "<th align=\"center\" width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>",
2394
+                "<th width=\"10%\" align=\"right\"><a href=\"", $forewardsURL, "\">&raquo;</a></th>", "</tr>";
2395
+
2396
+        echo "<tr>";
2397
+
2398
+        for($ii = 1; $ii < 8; $ii ++)
2399
+            echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2400
+
2401
+        echo "</tr>";
2402
+
2403
+        $curday = -1;
2404
+        $today = getdate();
2405
+
2406
+        while ($curday <= $numberofdays[$month]) {
2407
+            echo "<tr>";
2408
+            for ($ii = 0; $ii < 7; $ii ++) {
2409
+                if (($curday == -1) && ($ii == $startdayofweek))
2410
+                    $curday = 1;
2411
+
2412
+                    if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2413
+                    $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2414
+                    $dayheader = "$curday";
2415
+
2416
+                    if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2417
+                        $dayheader = "$curday";
2418
+                        $class = "class=\"days_today\"";
2419
+                    }
2420
+
2421
+                    echo "<td " . $class.">";
2422
+
2423
+                    // If there are posts on this day, create a filter link.
2424
+                    if(in_array($curday, $posts))
2425
+                        echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2426
+                    else
2427
+                        echo $dayheader;
2428
+
2429
+                    if (count($tasks) > 0) {
2430
+                        if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2431
+                            // Add tasks to calendar
2432
+                            foreach ($tasks[$curday] as $task) {
2433
+                                echo '<a href="blog.php?action=execute_task&blog_id=' . $task['blog_id'] . '&task_id='.stripslashes($task['task_id']) . '" title="' . $task['title'] . ' : ' . get_lang('InBlog') . ' : ' . $task['blog_name'] . ' - ' . get_lang('ExecuteThisTask') . '">';
2434
+                                echo Display::return_icon('blog_task.gif', get_lang('ExecuteThisTask'));
2436 2435
                                 echo '</a>';
2437
-							}
2438
-						}
2439
-					}
2440
-
2441
-					echo "</td>";
2442
-					$curday ++;
2443
-				} else
2444
-					echo "<td>&nbsp;</td>";
2445
-			}
2446
-			echo "</tr>";
2447
-		}
2448
-		echo "</table>";
2449
-	}
2450
-
2451
-	/**
2452
-	 * Blog admin | Display the form to add a new blog.
2453
-	 *
2454
-	 */
2455
-	public static function display_new_blog_form()
2456
-	{
2436
+                            }
2437
+                        }
2438
+                    }
2439
+
2440
+                    echo "</td>";
2441
+                    $curday ++;
2442
+                } else
2443
+                    echo "<td>&nbsp;</td>";
2444
+            }
2445
+            echo "</tr>";
2446
+        }
2447
+        echo "</table>";
2448
+    }
2449
+
2450
+    /**
2451
+     * Blog admin | Display the form to add a new blog.
2452
+     *
2453
+     */
2454
+    public static function display_new_blog_form()
2455
+    {
2457 2456
         $form = new FormValidator('add_blog', 'post', 'blog_admin.php?action=add');
2458 2457
         $form->addElement('header', get_lang('AddBlog'));
2459 2458
         $form->addElement('text', 'blog_name', get_lang('Title'));
@@ -2463,34 +2462,34 @@  discard block
 block discarded – undo
2463 2462
         $form->addButtonSave(get_lang('SaveProject'));
2464 2463
 
2465 2464
         $defaults = array(
2466
-			'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null,
2467
-        	'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null
2468
-		);
2465
+            'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null,
2466
+            'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null
2467
+        );
2469 2468
         $form->setDefaults($defaults);
2470 2469
         $form->display();
2471
-	}
2472
-
2473
-	/**
2474
-	 * Blog admin | Display the form to edit a blog.
2475
-	 *
2476
-	 */
2477
-	public static function display_edit_blog_form($blog_id)
2478
-	{
2479
-	    $course_id = api_get_course_int_id();
2480
-		$blog_id= intval($blog_id);
2481
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2482
-
2483
-		$sql = "SELECT blog_id, blog_name, blog_subtitle
2470
+    }
2471
+
2472
+    /**
2473
+     * Blog admin | Display the form to edit a blog.
2474
+     *
2475
+     */
2476
+    public static function display_edit_blog_form($blog_id)
2477
+    {
2478
+        $course_id = api_get_course_int_id();
2479
+        $blog_id= intval($blog_id);
2480
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2481
+
2482
+        $sql = "SELECT blog_id, blog_name, blog_subtitle
2484 2483
 		        FROM $tbl_blogs
2485 2484
 		        WHERE c_id = $course_id AND blog_id = '".$blog_id."'";
2486
-		$result = Database::query($sql);
2487
-		$blog = Database::fetch_array($result);
2485
+        $result = Database::query($sql);
2486
+        $blog = Database::fetch_array($result);
2488 2487
 
2489
-		// the form contained errors but we do not want to lose the changes the user already did
2490
-		if ($_POST) {
2491
-			$blog['blog_name'] = Security::remove_XSS($_POST['blog_name']);
2492
-			$blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2493
-		}
2488
+        // the form contained errors but we do not want to lose the changes the user already did
2489
+        if ($_POST) {
2490
+            $blog['blog_name'] = Security::remove_XSS($_POST['blog_name']);
2491
+            $blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2492
+        }
2494 2493
 
2495 2494
         $form = new FormValidator('edit_blog', 'post','blog_admin.php?action=edit&blog_id='.intval($_GET['blog_id']));
2496 2495
         $form->addElement('header', get_lang('EditBlog'));
@@ -2506,76 +2505,76 @@  discard block
 block discarded – undo
2506 2505
         $defaults['blog_subtitle'] = $blog['blog_subtitle'];
2507 2506
         $form->setDefaults($defaults);
2508 2507
         $form->display();
2509
-	}
2508
+    }
2510 2509
 
2511
-	/**
2512
-	 * Blog admin | Returns table with blogs in this course
2513
-	 */
2514
-	public static function display_blog_list()
2510
+    /**
2511
+     * Blog admin | Returns table with blogs in this course
2512
+     */
2513
+    public static function display_blog_list()
2515 2514
     {
2516
-		global $charset;
2517
-		$_user = api_get_user_info();
2515
+        global $charset;
2516
+        $_user = api_get_user_info();
2518 2517
         $course_id = api_get_course_int_id();
2519 2518
 
2520
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2519
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2521 2520
 
2522
-		//condition for the session
2523
-		$session_id = api_get_session_id();
2521
+        //condition for the session
2522
+        $session_id = api_get_session_id();
2524 2523
 
2525
-		$sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id
2524
+        $sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id
2526 2525
 				FROM $tbl_blogs WHERE c_id = $course_id
2527 2526
 				ORDER BY date_creation DESC";
2528
-		$result = Database::query($sql);
2529
-		$list_info = array();
2530
-		if (Database::num_rows($result)) {
2531
-			while ($row_project=Database::fetch_row($result)) {
2532
-				$list_info[]=$row_project;
2533
-			}
2534
-		}
2535
-
2536
-		$list_content_blog = array();
2537
-		$list_body_blog = array();
2538
-
2539
-		if (is_array($list_info)) {
2540
-			foreach ($list_info as $key => $info_log) {
2541
-				// Validation when belongs to a session
2542
-				$session_img = api_get_session_image($info_log[4], $_user['status']);
2543
-
2544
-				$url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2545
-				$title = $info_log[0];
2527
+        $result = Database::query($sql);
2528
+        $list_info = array();
2529
+        if (Database::num_rows($result)) {
2530
+            while ($row_project=Database::fetch_row($result)) {
2531
+                $list_info[]=$row_project;
2532
+            }
2533
+        }
2534
+
2535
+        $list_content_blog = array();
2536
+        $list_body_blog = array();
2537
+
2538
+        if (is_array($list_info)) {
2539
+            foreach ($list_info as $key => $info_log) {
2540
+                // Validation when belongs to a session
2541
+                $session_img = api_get_session_image($info_log[4], $_user['status']);
2542
+
2543
+                $url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2544
+                $title = $info_log[0];
2546 2545
                         $image = Display::return_icon('blog.png', $title);
2547
-    			$list_name = '<div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_blog.'">' . $image . '</a></div><a href="'.$url_start_blog.'">' .$title. '</a>' . $session_img;
2546
+                $list_name = '<div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_blog.'">' . $image . '</a></div><a href="'.$url_start_blog.'">' .$title. '</a>' . $session_img;
2548 2547
 
2549
-				$list_body_blog[] = $list_name;
2550
-				$list_body_blog[] = $info_log[1];
2548
+                $list_body_blog[] = $list_name;
2549
+                $list_body_blog[] = $info_log[1];
2551 2550
 
2552
-				$visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2553
-				$visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2554
-			 	$my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2551
+                $visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2552
+                $visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2553
+                    $my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2555 2554
                                 $my_image.= Display::return_icon('edit.png', get_lang('EditBlog'));
2556 2555
 
2557
-				$my_image.= "</a>";
2558
-				$my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2559
-				$my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2556
+                $my_image.= "</a>";
2557
+                $my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2558
+                $my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2560 2559
                                 $my_image.= Display::return_icon('delete.png', get_lang('DeleteBlog'));
2561 2560
 
2562
-				$my_image.= "</a>";
2563
-				$my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2561
+                $my_image.= "</a>";
2562
+                $my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2564 2563
                                 $my_image.= Display::return_icon($visibility_icon . '.gif', get_lang($visibility_info));
2565 2564
 
2566
-				$my_image.= "</a>";
2567
-				$list_body_blog[]=$my_image;
2568
-				$list_content_blog[]=$list_body_blog;
2569
-				$list_body_blog = array();
2570
-			}
2571
-
2572
-			$table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2573
-			$table->set_header(0, get_lang('Title'));
2574
-			$table->set_header(1, get_lang('SubTitle'));
2575
-			$table->set_header(2, get_lang('Modify'));
2576
-			$table->display();
2577
-		}
2578
-	}
2565
+                $my_image.= "</a>";
2566
+                $list_body_blog[]=$my_image;
2567
+                $list_content_blog[]=$list_body_blog;
2568
+                $list_body_blog = array();
2569
+            }
2570
+
2571
+            $table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2572
+            $table->set_header(0, get_lang('Title'));
2573
+            $table->set_header(1, get_lang('SubTitle'));
2574
+            $table->set_header(2, get_lang('Modify'));
2575
+            $table->display();
2576
+        }
2577
+    }
2579 2578
 }
2580 2579
 
2581 2580
 /**
@@ -2596,34 +2595,34 @@  discard block
 block discarded – undo
2596 2595
  */
2597 2596
 function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
2598 2597
 {
2599
-	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2600
-
2601
-	$blog_id = intval($blog_id);
2602
-	$comment_id = intval($comment_id);
2603
-	$post_id = intval($post_id);
2604
-	$row=array();
2605
-	$where='';
2606
-	if (!empty ($post_id) && is_numeric($post_id)) {
2607
-		$where.=' AND post_id ="'.$post_id.'" ';
2608
-	}
2609
-
2610
-	if (!empty ($comment_id) && is_numeric($comment_id)) {
2611
-		if (!empty ($post_id)) {
2612
-			$where.= ' AND ';
2613
-		}
2614
-		$where.=' comment_id ="'.$comment_id.'" ';
2615
-	}
2598
+    $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2599
+
2600
+    $blog_id = intval($blog_id);
2601
+    $comment_id = intval($comment_id);
2602
+    $post_id = intval($post_id);
2603
+    $row=array();
2604
+    $where='';
2605
+    if (!empty ($post_id) && is_numeric($post_id)) {
2606
+        $where.=' AND post_id ="'.$post_id.'" ';
2607
+    }
2608
+
2609
+    if (!empty ($comment_id) && is_numeric($comment_id)) {
2610
+        if (!empty ($post_id)) {
2611
+            $where.= ' AND ';
2612
+        }
2613
+        $where.=' comment_id ="'.$comment_id.'" ';
2614
+    }
2616 2615
 
2617 2616
     $course_id = api_get_course_int_id();
2618 2617
 
2619
-	$sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2618
+    $sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2620 2619
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2621 2620
 
2622
-	$result=Database::query($sql);
2623
-	if (Database::num_rows($result)!=0) {
2624
-		$row=Database::fetch_array($result);
2625
-	}
2626
-	return $row;
2621
+    $result=Database::query($sql);
2622
+    if (Database::num_rows($result)!=0) {
2623
+        $row=Database::fetch_array($result);
2624
+    }
2625
+    return $row;
2627 2626
 }
2628 2627
 
2629 2628
 /**
@@ -2640,16 +2639,16 @@  discard block
 block discarded – undo
2640 2639
 
2641 2640
 function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null)
2642 2641
 {
2643
-	$_course = api_get_course_info();
2644
-	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2645
-	$blog_id = intval($blog_id);
2646
-	$comment_id = intval($comment_id);
2647
-	$post_id = intval($post_id);
2642
+    $_course = api_get_course_info();
2643
+    $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2644
+    $blog_id = intval($blog_id);
2645
+    $comment_id = intval($comment_id);
2646
+    $post_id = intval($post_id);
2648 2647
 
2649 2648
     $course_id = api_get_course_int_id();
2650
-	$where = null;
2649
+    $where = null;
2651 2650
 
2652
-	// delete files in DB
2651
+    // delete files in DB
2653 2652
     if (!empty ($post_id) && is_numeric($post_id)) {
2654 2653
         $where .= ' AND post_id ="'.$post_id.'" ';
2655 2654
     }
@@ -2661,25 +2660,25 @@  discard block
 block discarded – undo
2661 2660
         $where .= ' comment_id ="'.$comment_id.'" ';
2662 2661
     }
2663 2662
 
2664
-	// delete all files in directory
2665
-	$courseDir   = $_course['path'].'/upload/blog';
2666
-	$sys_course_path = api_get_path(SYS_COURSE_PATH);
2667
-	$updir = $sys_course_path.$courseDir;
2663
+    // delete all files in directory
2664
+    $courseDir   = $_course['path'].'/upload/blog';
2665
+    $sys_course_path = api_get_path(SYS_COURSE_PATH);
2666
+    $updir = $sys_course_path.$courseDir;
2668 2667
 
2669
-	$sql = 'SELECT path FROM '.$blog_table_attachment.'
2668
+    $sql = 'SELECT path FROM '.$blog_table_attachment.'
2670 2669
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2671
-	$result=Database::query($sql);
2672
-
2673
-	while ($row=Database::fetch_row($result)) {
2674
-		$file=$updir.'/'.$row[0];
2675
-		if (Security::check_abs_path($file,$updir) )
2676
-		{
2677
-			@ unlink($file);
2678
-		}
2679
-	}
2680
-	$sql = 'DELETE FROM '. $blog_table_attachment.'
2670
+    $result=Database::query($sql);
2671
+
2672
+    while ($row=Database::fetch_row($result)) {
2673
+        $file=$updir.'/'.$row[0];
2674
+        if (Security::check_abs_path($file,$updir) )
2675
+        {
2676
+            @ unlink($file);
2677
+        }
2678
+    }
2679
+    $sql = 'DELETE FROM '. $blog_table_attachment.'
2681 2680
 	        WHERE c_id = '.$course_id.' AND  blog_id ="'.intval($blog_id).'"  '.$where;
2682
-	Database::query($sql);
2681
+    Database::query($sql);
2683 2682
 }
2684 2683
 
2685 2684
 /**
@@ -2689,12 +2688,12 @@  discard block
 block discarded – undo
2689 2688
  */
2690 2689
 function get_blog_post_from_user($course_code, $user_id)
2691 2690
 {
2692
-	$tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2693
-	$tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2694
-	$course_info 	= api_get_course_info($course_code);
2695
-	$course_id 		= $course_info['real_id'];
2691
+    $tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2692
+    $tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2693
+    $course_info 	= api_get_course_info($course_code);
2694
+    $course_id 		= $course_info['real_id'];
2696 2695
 
2697
-	$sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
2696
+    $sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
2698 2697
 			FROM $tbl_blogs blog
2699 2698
 			INNER JOIN  $tbl_blog_post post
2700 2699
 			ON (blog.blog_id = post.blog_id)
@@ -2703,19 +2702,19 @@  discard block
 block discarded – undo
2703 2702
 				post.c_id = $course_id AND
2704 2703
 				author_id =  $user_id AND visibility = 1
2705 2704
 			ORDER BY post.date_creation DESC ";
2706
-	$result = Database::query($sql);
2707
-	$return_data = '';
2708
-
2709
-	if (Database::num_rows($result)!=0) {
2710
-		while ($row=Database::fetch_array($result)) {
2711
-			$return_data.=  '<div class="clear"></div><br />';
2712
-			$return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.Display::return_icon('blog_article.png',get_lang('BlogPosts')).' '.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$my_course_id.' " >'.get_lang('SeeBlog').'</a></div></div>';
2713
-			$return_data.=  '<br / >';
2714
-			$return_data.= $row['full_text'];
2715
-			$return_data.= '<br /><br />';
2716
-		}
2717
-	}
2718
-	return $return_data;
2705
+    $result = Database::query($sql);
2706
+    $return_data = '';
2707
+
2708
+    if (Database::num_rows($result)!=0) {
2709
+        while ($row=Database::fetch_array($result)) {
2710
+            $return_data.=  '<div class="clear"></div><br />';
2711
+            $return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.Display::return_icon('blog_article.png',get_lang('BlogPosts')).' '.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$my_course_id.' " >'.get_lang('SeeBlog').'</a></div></div>';
2712
+            $return_data.=  '<br / >';
2713
+            $return_data.= $row['full_text'];
2714
+            $return_data.= '<br /><br />';
2715
+        }
2716
+    }
2717
+    return $return_data;
2719 2718
 }
2720 2719
 
2721 2720
 /**
@@ -2732,7 +2731,7 @@  discard block
 block discarded – undo
2732 2731
     $course_info = api_get_course_info($course_code);
2733 2732
     $course_id = $course_info['real_id'];
2734 2733
 
2735
-	$sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation
2734
+    $sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation
2736 2735
 			FROM $tbl_blogs blog INNER JOIN  $tbl_blog_comment comment
2737 2736
 			ON (blog.blog_id = comment.blog_id)
2738 2737
 			WHERE 	blog.c_id = $course_id AND
@@ -2740,18 +2739,18 @@  discard block
 block discarded – undo
2740 2739
 					author_id =  $user_id AND
2741 2740
 					visibility = 1
2742 2741
 			ORDER BY blog_name";
2743
-	$result = Database::query($sql);
2744
-	$return_data = '';
2745
-	if (Database::num_rows($result)!=0) {
2746
-		while ($row=Database::fetch_array($result)) {
2747
-			$return_data.=  '<div class="clear"></div><br />';
2748
-			$return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($course_code).' " >'.get_lang('SeeBlog').'</a></div></div>';
2749
-			$return_data.=  '<br / >';
2750
-			//$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2751
-			$return_data.=  $row['comment'];
2752
-			$return_data.=  '<br />';
2753
-		}
2754
-	}
2755
-	return $return_data;
2742
+    $result = Database::query($sql);
2743
+    $return_data = '';
2744
+    if (Database::num_rows($result)!=0) {
2745
+        while ($row=Database::fetch_array($result)) {
2746
+            $return_data.=  '<div class="clear"></div><br />';
2747
+            $return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($course_code).' " >'.get_lang('SeeBlog').'</a></div></div>';
2748
+            $return_data.=  '<br / >';
2749
+            //$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2750
+            $return_data.=  $row['comment'];
2751
+            $return_data.=  '<br />';
2752
+        }
2753
+    }
2754
+    return $return_data;
2756 2755
 }
2757 2756
 
Please login to merge, or discard this patch.
main/coursecopy/classes/Course.class.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
     }
327 327
 
328 328
     /**
329
-    * Serialize the course with the best serializer available
330
-    * @return string
331
-    */
329
+     * Serialize the course with the best serializer available
330
+     * @return string
331
+     */
332 332
     public static function serialize($course)
333 333
     {
334 334
         if (extension_loaded('igbinary')) {
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
     }
340 340
 
341 341
     /**
342
-    * Unserialize the course with the best serializer available
343
-    * @param string $course
344
-    */
342
+     * Unserialize the course with the best serializer available
343
+     * @param string $course
344
+     */
345 345
     public static function unserialize($course)
346 346
     {
347 347
         if (extension_loaded('igbinary')) {
Please login to merge, or discard this patch.
main/coursecopy/classes/CourseRestorer.class.php 1 patch
Indentation   +717 added lines, -717 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class CourseRestorer
38 38
 {
39
-	/**
40
-	 * The course-object
41
-	 */
39
+    /**
40
+     * The course-object
41
+     */
42 42
     public $course;
43 43
     public $destination_course_info;
44 44
 
45
-	/**
46
-	 * What to do with files with same name (FILE_SKIP, FILE_RENAME or
47
-	 * FILE_OVERWRITE)
48
-	 */
45
+    /**
46
+     * What to do with files with same name (FILE_SKIP, FILE_RENAME or
47
+     * FILE_OVERWRITE)
48
+     */
49 49
     public $file_option;
50 50
     public $set_tools_invisible_by_default;
51 51
     public $skip_content;
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         'events',
58 58
         'forum_category',
59 59
         'forums',
60
-       // 'forum_topics',
60
+        // 'forum_topics',
61 61
         'glossary',
62 62
         'quizzes',
63 63
         'test_category',
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
         $this->tool_copy_settings = $array;
127 127
     }
128 128
 
129
-	/**
130
-	 * Restore a course.
129
+    /**
130
+     * Restore a course.
131 131
      *
132
-	 * @param string    $destination_course_code code of the Chamilo-course in
133
-	 * @param int	    $session_id
134
-	 * @param bool	    $update_course_settings Course settings are going to be restore?
132
+     * @param string    $destination_course_code code of the Chamilo-course in
133
+     * @param int	    $session_id
134
+     * @param bool	    $update_course_settings Course settings are going to be restore?
135 135
      * @param bool      $respect_base_content
136 136
      * @return false|null
137
-	 */
137
+     */
138 138
     public function restore(
139 139
         $destination_course_code = '',
140 140
         $session_id = 0,
@@ -277,17 +277,17 @@  discard block
 block discarded – undo
277 277
         }
278 278
     }
279 279
 
280
-	/**
281
-	 * Restore only harmless course settings:
280
+    /**
281
+     * Restore only harmless course settings:
282 282
      * course_language, visibility, department_name,department_url,
283 283
      * subscribe, unsubscribe ,category_code
284
-	 *
285
-	 * @param string $destination_course_code
286
-	 */
284
+     *
285
+     * @param string $destination_course_code
286
+     */
287 287
     public function restore_course_settings($destination_course_code)
288 288
     {
289
-	    $origin_course_info = api_get_course_info($destination_course_code);
290
-	    $course_info = $this->course->info;
289
+        $origin_course_info = api_get_course_info($destination_course_code);
290
+        $course_info = $this->course->info;
291 291
         $params['course_language'] = $course_info['language'];
292 292
         $params['visibility'] = $course_info['visibility'];
293 293
         $params['department_name'] = $course_info['department_name'];
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
         $params['category_code'] = $course_info['categoryCode'];
297 297
         $params['subscribe'] = $course_info['subscribe_allowed'];
298 298
         $params['unsubscribe'] = $course_info['unsubscribe'];
299
-	    CourseManager::update_attributes($origin_course_info['real_id'], $params);
300
-	}
299
+        CourseManager::update_attributes($origin_course_info['real_id'], $params);
300
+    }
301 301
 
302 302
     /**
303 303
      * Restore documents
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
         $course_info = api_get_course_info($destination_course_code);
312 312
 
313 313
         if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
314
-			$table = Database :: get_course_table(TABLE_DOCUMENT);
315
-			$resources = $this->course->resources;
314
+            $table = Database :: get_course_table(TABLE_DOCUMENT);
315
+            $resources = $this->course->resources;
316 316
             $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
317 317
 
318
-			foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
318
+            foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
319 319
 
320 320
                 if (empty($document->item_properties[0]['id_session'])) {
321 321
                     $my_session_id = 0;
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
                             }
386 386
                         }
387 387
                     }
388
-		    	} elseif ($document->file_type == DOCUMENT) {
388
+                } elseif ($document->file_type == DOCUMENT) {
389 389
                     //Checking if folder exists in the database otherwise we created it
390 390
                     $dir_to_create = dirname($document->path);
391 391
 
@@ -441,19 +441,19 @@  discard block
 block discarded – undo
441 441
                         }
442 442
                     }
443 443
 
444
-					if (file_exists($path.$document->path)) {
445
-						switch ($this->file_option) {
446
-							case FILE_OVERWRITE:
444
+                    if (file_exists($path.$document->path)) {
445
+                        switch ($this->file_option) {
446
+                            case FILE_OVERWRITE:
447 447
                                 $origin_path = $this->course->backup_path.'/'.$document->path;
448 448
 
449
-								if (file_exists($origin_path)) {
450
-        						    copy($origin_path, $path.$document->path);
449
+                                if (file_exists($origin_path)) {
450
+                                    copy($origin_path, $path.$document->path);
451 451
                                     $sql = "SELECT id FROM $table
452 452
                                             WHERE
453 453
                                                 c_id = ".$this->destination_course_id." AND
454 454
                                                 path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'";
455 455
 
456
-        						    $res = Database::query($sql);
456
+                                    $res = Database::query($sql);
457 457
                                     $count = Database::num_rows($res);
458 458
 
459 459
                                     if ($count == 0) {
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
                                             'session_id' => $my_session_id,
468 468
                                         ];
469 469
 
470
-    									$document_id = Database::insert($table, $params);
470
+                                        $document_id = Database::insert($table, $params);
471 471
 
472 472
                                         if ($document_id) {
473 473
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -575,83 +575,83 @@  discard block
 block discarded – undo
575 575
                                             ],
576 576
                                         ]
577 577
                                     );
578
-								}
578
+                                }
579 579
 
580
-								break;
581
-							case FILE_SKIP:
582
-								$sql = "SELECT id FROM $table
580
+                                break;
581
+                            case FILE_SKIP:
582
+                                $sql = "SELECT id FROM $table
583 583
 								        WHERE
584 584
 								            c_id = ".$this->destination_course_id." AND
585 585
 								            path='/".self::DBUTF8escapestring(substr($document->path, 9))."'";
586
-								$res = Database::query($sql);
587
-								$obj = Database::fetch_object($res);
588
-								$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
589
-								break;
590
-							case FILE_RENAME:
591
-								$i = 1;
592
-								$ext = explode('.', basename($document->path));
593
-								if (count($ext) > 1) {
594
-									$ext = array_pop($ext);
595
-									$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
596
-									$ext = '.'.$ext;
597
-								} else {
598
-									$ext = '';
599
-									$file_name_no_ext = $document->path;
600
-								}
601
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
602
-								$file_exists = file_exists($path.$new_file_name);
603
-								while ($file_exists) {
604
-									$i ++;
605
-									$new_file_name = $file_name_no_ext.'_'.$i.$ext;
606
-									$file_exists = file_exists($path.$new_file_name);
607
-								}
608
-
609
-								if (!empty($session_id)) {
610
-
611
-									$document_path = explode('/',$document->path,3);
612
-									$course_path = $path;
613
-									$orig_base_folder = $document_path[1];
614
-									$orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
615
-
616
-									if (is_dir($orig_base_path)) {
617
-
618
-										$new_base_foldername = $orig_base_folder;
619
-										$new_base_path = $orig_base_path;
620
-
621
-										if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
622
-											unset($_SESSION['new_base_foldername']);
623
-											unset($_SESSION['orig_base_foldername']);
624
-											unset($_SESSION['new_base_path']);
625
-										}
626
-
627
-										$folder_exists = file_exists($new_base_path);
628
-										if ($folder_exists) {
629
-											$_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
630
-											$x = '';
631
-											while ($folder_exists) {
632
-												$x = $x + 1;
633
-												$new_base_foldername = $document_path[1].'_'.$x;
634
-												$new_base_path = $orig_base_path.'_'.$x;
586
+                                $res = Database::query($sql);
587
+                                $obj = Database::fetch_object($res);
588
+                                $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
589
+                                break;
590
+                            case FILE_RENAME:
591
+                                $i = 1;
592
+                                $ext = explode('.', basename($document->path));
593
+                                if (count($ext) > 1) {
594
+                                    $ext = array_pop($ext);
595
+                                    $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
596
+                                    $ext = '.'.$ext;
597
+                                } else {
598
+                                    $ext = '';
599
+                                    $file_name_no_ext = $document->path;
600
+                                }
601
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
602
+                                $file_exists = file_exists($path.$new_file_name);
603
+                                while ($file_exists) {
604
+                                    $i ++;
605
+                                    $new_file_name = $file_name_no_ext.'_'.$i.$ext;
606
+                                    $file_exists = file_exists($path.$new_file_name);
607
+                                }
608
+
609
+                                if (!empty($session_id)) {
610
+
611
+                                    $document_path = explode('/',$document->path,3);
612
+                                    $course_path = $path;
613
+                                    $orig_base_folder = $document_path[1];
614
+                                    $orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
615
+
616
+                                    if (is_dir($orig_base_path)) {
617
+
618
+                                        $new_base_foldername = $orig_base_folder;
619
+                                        $new_base_path = $orig_base_path;
620
+
621
+                                        if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
622
+                                            unset($_SESSION['new_base_foldername']);
623
+                                            unset($_SESSION['orig_base_foldername']);
624
+                                            unset($_SESSION['new_base_path']);
625
+                                        }
626
+
627
+                                        $folder_exists = file_exists($new_base_path);
628
+                                        if ($folder_exists) {
629
+                                            $_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
630
+                                            $x = '';
631
+                                            while ($folder_exists) {
632
+                                                $x = $x + 1;
633
+                                                $new_base_foldername = $document_path[1].'_'.$x;
634
+                                                $new_base_path = $orig_base_path.'_'.$x;
635 635
                                                 if ($_SESSION['new_base_foldername'] == $new_base_foldername) {
636 636
                                                     break;
637 637
                                                 }
638
-												$folder_exists = file_exists($new_base_path);
639
-											}
640
-											$_SESSION['new_base_foldername'] = $new_base_foldername;
641
-											$_SESSION['new_base_path'] = $new_base_path;
642
-										}
643
-
644
-										if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
645
-											$new_base_foldername = $_SESSION['new_base_foldername'];
646
-											$new_base_path = $_SESSION['new_base_path'];
647
-										}
648
-
649
-										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
650
-										$basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
651
-										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
652
-										$path_title = '/'.$new_base_foldername.'/'.$document_path[2];
653
-
654
-										copy_folder_course_session(
638
+                                                $folder_exists = file_exists($new_base_path);
639
+                                            }
640
+                                            $_SESSION['new_base_foldername'] = $new_base_foldername;
641
+                                            $_SESSION['new_base_path'] = $new_base_path;
642
+                                        }
643
+
644
+                                        if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
645
+                                            $new_base_foldername = $_SESSION['new_base_foldername'];
646
+                                            $new_base_path = $_SESSION['new_base_path'];
647
+                                        }
648
+
649
+                                        $dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
650
+                                        $basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
651
+                                        $base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
652
+                                        $path_title = '/'.$new_base_foldername.'/'.$document_path[2];
653
+
654
+                                        copy_folder_course_session(
655 655
                                             $basedir_dest_path,
656 656
                                             $base_path_document,
657 657
                                             $session_id,
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
                                             'session_id' => $my_session_id,
694 694
                                         ];
695 695
 
696
-										$document_id = Database::insert($table, $params);
696
+                                        $document_id = Database::insert($table, $params);
697 697
 
698 698
                                         if ($document_id) {
699 699
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -722,10 +722,10 @@  discard block
 block discarded – undo
722 722
                                             null,
723 723
                                             $my_session_id
724 724
                                         );
725
-									} else {
726
-									    if (file_exists($path.$document->path)) {
725
+                                    } else {
726
+                                        if (file_exists($path.$document->path)) {
727 727
                                             copy($path.$document->path, $path.$new_file_name);
728
-									    }
728
+                                        }
729 729
                                         //Replace old course code with the new destination code see BT#1985
730 730
                                         if (file_exists($path.$new_file_name)) {
731 731
                                             $file_info = pathinfo($path.$new_file_name);
@@ -784,10 +784,10 @@  discard block
 block discarded – undo
784 784
                                                 $my_session_id
785 785
                                             );
786 786
                                         }
787
-									}
788
-								} else {
787
+                                    }
788
+                                } else {
789 789
 
790
-									copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
790
+                                    copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
791 791
 
792 792
                                     //Replace old course code with the new destination code see BT#1985
793 793
                                     if (file_exists($path.$new_file_name)) {
@@ -847,20 +847,20 @@  discard block
 block discarded – undo
847 847
                                         null,
848 848
                                         $my_session_id
849 849
                                     );
850
-								}
851
-								break;
852
-
853
-						} // end switch
854
-					} else {
855
-					    // end if file exists
856
-						//make sure the source file actually exists
857
-						if (is_file($this->course->backup_path.'/'.$document->path) &&
850
+                                }
851
+                                break;
852
+
853
+                        } // end switch
854
+                    } else {
855
+                        // end if file exists
856
+                        //make sure the source file actually exists
857
+                        if (is_file($this->course->backup_path.'/'.$document->path) &&
858 858
                             is_readable($this->course->backup_path.'/'.$document->path) &&
859 859
                             is_dir(dirname($path.$document->path)) &&
860 860
                             is_writeable(dirname($path.$document->path))
861 861
                         ) {
862
-						    //echo 'Copying';
863
-							copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
862
+                            //echo 'Copying';
863
+                            copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
864 864
 
865 865
                             //Replace old course code with the new destination code see BT#1985
866 866
                             if (file_exists($path.$document->path)) {
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
                                 Database::query($sql);
899 899
                             }
900 900
 
901
-							$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
901
+                            $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
902 902
 
903 903
                             $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
904 904
                             $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
@@ -920,79 +920,79 @@  discard block
 block discarded – undo
920 920
                                 null,
921 921
                                 $my_session_id
922 922
                             );
923
-						} else {
924
-							if (is_file($this->course->backup_path.'/'.$document->path) &&
923
+                        } else {
924
+                            if (is_file($this->course->backup_path.'/'.$document->path) &&
925 925
                                 is_readable($this->course->backup_path.'/'.$document->path)
926 926
                             ) {
927
-								error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
928
-							}
929
-							if (!is_dir(dirname($path.$document->path))) {
930
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
931
-							}
932
-							if (!is_writeable(dirname($path.$document->path))) {
933
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
934
-							}
935
-						}
936
-					} // end file doesn't exist
937
-				}
938
-			} // end for each
939
-
940
-    		// Delete sessions for the copy the new folder in session
941
-    		unset($_SESSION['new_base_foldername']);
942
-    		unset($_SESSION['orig_base_foldername']);
943
-    		unset($_SESSION['new_base_path']);
944
-		}
945
-	}
946
-
947
-	/**
948
-	 * Restore scorm documents
949
-	 * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
927
+                                error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
928
+                            }
929
+                            if (!is_dir(dirname($path.$document->path))) {
930
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
931
+                            }
932
+                            if (!is_writeable(dirname($path.$document->path))) {
933
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
934
+                            }
935
+                        }
936
+                    } // end file doesn't exist
937
+                }
938
+            } // end for each
939
+
940
+            // Delete sessions for the copy the new folder in session
941
+            unset($_SESSION['new_base_foldername']);
942
+            unset($_SESSION['orig_base_foldername']);
943
+            unset($_SESSION['new_base_path']);
944
+        }
945
+    }
946
+
947
+    /**
948
+     * Restore scorm documents
949
+     * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
950 950
      * see #7029
951
-	 */
952
-	public function restore_scorm_documents()
951
+     */
952
+    public function restore_scorm_documents()
953 953
     {
954
-		$perm = api_get_permissions_for_new_directories();
954
+        $perm = api_get_permissions_for_new_directories();
955 955
 
956
-		if ($this->course->has_resources(RESOURCE_SCORM)) {
957
-			$resources = $this->course->resources;
956
+        if ($this->course->has_resources(RESOURCE_SCORM)) {
957
+            $resources = $this->course->resources;
958 958
 
959
-			foreach ($resources[RESOURCE_SCORM] as $document) {
960
-				$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
959
+            foreach ($resources[RESOURCE_SCORM] as $document) {
960
+                $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
961 961
 
962
-				@mkdir(dirname($path.$document->path), $perm, true);
962
+                @mkdir(dirname($path.$document->path), $perm, true);
963 963
 
964
-				if (file_exists($path.$document->path)) {
965
-					switch ($this->file_option) {
966
-						case FILE_OVERWRITE:
967
-							rmdirr($path.$document->path);
964
+                if (file_exists($path.$document->path)) {
965
+                    switch ($this->file_option) {
966
+                        case FILE_OVERWRITE:
967
+                            rmdirr($path.$document->path);
968 968
                             copyDirTo(
969 969
                                 $this->course->backup_path . '/' . $document->path,
970 970
                                 $path . dirname($document->path),
971 971
                                 false
972 972
                             );
973
-							break;
974
-						case FILE_SKIP:
975
-							break;
973
+                            break;
974
+                        case FILE_SKIP:
975
+                            break;
976 976
                         case FILE_RENAME:
977
-							$i = 1;
978
-							$ext = explode('.', basename($document->path));
979
-							if (count($ext) > 1) {
980
-								$ext = array_pop($ext);
981
-								$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
982
-								$ext = '.'.$ext;
983
-							} else {
984
-								$ext = '';
985
-								$file_name_no_ext = $document->path;
986
-							}
987
-
988
-							$new_file_name = $file_name_no_ext.'_'.$i.$ext;
989
-							$file_exists = file_exists($path.$new_file_name);
990
-
991
-							while ($file_exists) {
992
-								$i ++;
993
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
994
-								$file_exists = file_exists($path.$new_file_name);
995
-							}
977
+                            $i = 1;
978
+                            $ext = explode('.', basename($document->path));
979
+                            if (count($ext) > 1) {
980
+                                $ext = array_pop($ext);
981
+                                $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
982
+                                $ext = '.'.$ext;
983
+                            } else {
984
+                                $ext = '';
985
+                                $file_name_no_ext = $document->path;
986
+                            }
987
+
988
+                            $new_file_name = $file_name_no_ext.'_'.$i.$ext;
989
+                            $file_exists = file_exists($path.$new_file_name);
990
+
991
+                            while ($file_exists) {
992
+                                $i ++;
993
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
994
+                                $file_exists = file_exists($path.$new_file_name);
995
+                            }
996 996
 
997 997
                             rename(
998 998
                                 $this->course->backup_path . '/' . $document->path,
@@ -1008,30 +1008,30 @@  discard block
 block discarded – undo
1008 1008
                                 $this->course->backup_path . '/' . $document->path
1009 1009
                             );
1010 1010
 
1011
-							break;
1012
-					} // end switch
1013
-				} else {
1011
+                            break;
1012
+                    } // end switch
1013
+                } else {
1014 1014
                     // end if file exists
1015 1015
                     copyDirTo(
1016 1016
                         $this->course->backup_path . '/' . $document->path,
1017 1017
                         $path . dirname($document->path),
1018 1018
                         false
1019 1019
                     );
1020
-				}
1021
-			} // end for each
1022
-		}
1023
-	}
1024
-
1025
-	/**
1026
-	 * Restore forums
1027
-	 */
1028
-	public function restore_forums($sessionId = 0)
1020
+                }
1021
+            } // end for each
1022
+        }
1023
+    }
1024
+
1025
+    /**
1026
+     * Restore forums
1027
+     */
1028
+    public function restore_forums($sessionId = 0)
1029 1029
     {
1030
-		if ($this->course->has_resources(RESOURCE_FORUM)) {
1030
+        if ($this->course->has_resources(RESOURCE_FORUM)) {
1031 1031
             $sessionId = intval($sessionId);
1032
-			$table_forum = Database::get_course_table(TABLE_FORUM);
1033
-			$resources = $this->course->resources;
1034
-			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1032
+            $table_forum = Database::get_course_table(TABLE_FORUM);
1033
+            $resources = $this->course->resources;
1034
+            foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1035 1035
                 $params = (array)$forum->obj;
1036 1036
                 $cat_id = '';
1037 1037
                 if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) &&
@@ -1077,33 +1077,33 @@  discard block
 block discarded – undo
1077 1077
                     Database::query($sql);
1078 1078
                 }
1079 1079
 
1080
-				$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1081
-
1082
-				$forum_topics = 0;
1083
-				if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1084
-					foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1085
-						if ($topic->obj->forum_id == $id) {
1086
-							$this->restore_topic($topic_id, $new_id, $sessionId);
1087
-							$forum_topics ++;
1088
-						}
1089
-					}
1090
-				}
1091
-				if ($forum_topics > 0) {
1092
-					$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1080
+                $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1081
+
1082
+                $forum_topics = 0;
1083
+                if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1084
+                    foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1085
+                        if ($topic->obj->forum_id == $id) {
1086
+                            $this->restore_topic($topic_id, $new_id, $sessionId);
1087
+                            $forum_topics ++;
1088
+                        }
1089
+                    }
1090
+                }
1091
+                if ($forum_topics > 0) {
1092
+                    $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1093 1093
                             WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
1094
-					Database::query($sql);
1095
-				}
1096
-			}
1097
-		}
1098
-	}
1099
-
1100
-	/**
1101
-	 * Restore forum-categories
1102
-	 */
1094
+                    Database::query($sql);
1095
+                }
1096
+            }
1097
+        }
1098
+    }
1099
+
1100
+    /**
1101
+     * Restore forum-categories
1102
+     */
1103 1103
     public function restore_forum_category($my_id = null, $sessionId = 0)
1104 1104
     {
1105
-		$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1106
-		$resources = $this->course->resources;
1105
+        $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1106
+        $resources = $this->course->resources;
1107 1107
         if (!empty($resources[RESOURCE_FORUMCATEGORY])) {
1108 1108
             foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
1109 1109
                 if (!empty($my_id)) {
@@ -1150,16 +1150,16 @@  discard block
 block discarded – undo
1150 1150
                 }
1151 1151
             }
1152 1152
         }
1153
-	}
1153
+    }
1154 1154
 
1155
-	/**
1156
-	 * Restore a forum-topic
1157
-	 * @param false|string $forum_id
1158
-	 */
1155
+    /**
1156
+     * Restore a forum-topic
1157
+     * @param false|string $forum_id
1158
+     */
1159 1159
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1160 1160
     {
1161
-		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1162
-		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1161
+        $table = Database :: get_course_table(TABLE_FORUM_THREAD);
1162
+        $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1163 1163
 
1164 1164
         $params = (array)$topic->obj;
1165 1165
         $params = self::DBUTF8_array($params);
@@ -1195,28 +1195,28 @@  discard block
 block discarded – undo
1195 1195
             $sessionId
1196 1196
         );
1197 1197
 
1198
-		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1198
+        $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1199 1199
 
1200
-		$topic_replies = -1;
1200
+        $topic_replies = -1;
1201 1201
 
1202
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1203
-			if ($post->obj->thread_id == $thread_id) {
1204
-				$topic_replies++;
1205
-				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1206
-			}
1207
-		}
1208
-		return $new_id;
1209
-	}
1202
+        foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1203
+            if ($post->obj->thread_id == $thread_id) {
1204
+                $topic_replies++;
1205
+                $this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1206
+            }
1207
+        }
1208
+        return $new_id;
1209
+    }
1210 1210
 
1211
-	/**
1212
-	 * Restore a forum-post
1213
-	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
-	 * @param false|string $topic_id
1215
-	 */
1211
+    /**
1212
+     * Restore a forum-post
1213
+     * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
+     * @param false|string $topic_id
1215
+     */
1216 1216
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1217 1217
     {
1218
-		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
1219
-		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1218
+        $table_post = Database :: get_course_table(TABLE_FORUM_POST);
1219
+        $post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1220 1220
         $params = (array) $post->obj;
1221 1221
         $params['c_id'] = $this->destination_course_id;
1222 1222
         $params['forum_id'] = $forum_id;
@@ -1251,37 +1251,37 @@  discard block
 block discarded – undo
1251 1251
             null,
1252 1252
             $sessionId
1253 1253
         );
1254
-		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1254
+        $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1255 1255
 
1256
-		return $new_id;
1257
-	}
1256
+        return $new_id;
1257
+    }
1258 1258
 
1259
-	/**
1260
-	 * Restore links
1261
-	 */
1259
+    /**
1260
+     * Restore links
1261
+     */
1262 1262
     public function restore_links($session_id = 0)
1263 1263
     {
1264
-		if ($this->course->has_resources(RESOURCE_LINK)) {
1265
-			$link_table = Database :: get_course_table(TABLE_LINK);
1266
-			$resources = $this->course->resources;
1264
+        if ($this->course->has_resources(RESOURCE_LINK)) {
1265
+            $link_table = Database :: get_course_table(TABLE_LINK);
1266
+            $resources = $this->course->resources;
1267 1267
 
1268
-			foreach ($resources[RESOURCE_LINK] as $id => $link) {
1268
+            foreach ($resources[RESOURCE_LINK] as $id => $link) {
1269 1269
                 $cat_id = $this->restore_link_category(
1270 1270
                     $link->category_id,
1271 1271
                     $session_id
1272 1272
                 );
1273
-				$sql = "SELECT MAX(display_order)
1273
+                $sql = "SELECT MAX(display_order)
1274 1274
 				        FROM $link_table
1275 1275
 				        WHERE
1276 1276
 				            c_id = ".$this->destination_course_id." AND
1277 1277
 				            category_id='" . intval($cat_id). "'";
1278
-				$result = Database::query($sql);
1279
-    			list($max_order) = Database::fetch_array($result);
1278
+                $result = Database::query($sql);
1279
+                list($max_order) = Database::fetch_array($result);
1280 1280
 
1281 1281
                 $params = [];
1282
-    			if (!empty($session_id)) {
1282
+                if (!empty($session_id)) {
1283 1283
                     $params['session_id'] = $session_id;
1284
-    			}
1284
+                }
1285 1285
 
1286 1286
                 $params['c_id'] = $this->destination_course_id;
1287 1287
                 $params['url'] = self::DBUTF8($link->url);
@@ -1310,9 +1310,9 @@  discard block
 block discarded – undo
1310 1310
                     }
1311 1311
                     $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id;
1312 1312
                 }
1313
-			}
1314
-		}
1315
-	}
1313
+            }
1314
+        }
1315
+    }
1316 1316
 
1317 1317
     /**
1318 1318
      * Restore a link-category
@@ -1356,21 +1356,21 @@  discard block
 block discarded – undo
1356 1356
         return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id;
1357 1357
     }
1358 1358
 
1359
-	/**
1360
-	 * Restore tool intro
1361
-	 */
1359
+    /**
1360
+     * Restore tool intro
1361
+     */
1362 1362
     public function restore_tool_intro($sessionId = 0)
1363 1363
     {
1364
-		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1364
+        if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1365 1365
             $sessionId = intval($sessionId);
1366
-			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1367
-			$resources = $this->course->resources;
1368
-			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1369
-				$sql = "DELETE FROM ".$tool_intro_table."
1366
+            $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1367
+            $resources = $this->course->resources;
1368
+            foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1369
+                $sql = "DELETE FROM ".$tool_intro_table."
1370 1370
 				        WHERE
1371 1371
 				            c_id = ".$this->destination_course_id." AND
1372 1372
 				            id='".self::DBUTF8escapestring($tool_intro->id)."'";
1373
-				Database::query($sql);
1373
+                Database::query($sql);
1374 1374
 
1375 1375
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1376 1376
                     $tool_intro->intro_text,
@@ -1398,21 +1398,21 @@  discard block
 block discarded – undo
1398 1398
 
1399 1399
                     $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id;
1400 1400
                 }
1401
-			}
1402
-		}
1403
-	}
1401
+            }
1402
+        }
1403
+    }
1404 1404
 
1405
-	/**
1406
-	 * Restore events
1407
-	 */
1405
+    /**
1406
+     * Restore events
1407
+     */
1408 1408
     public function restore_events($sessionId = 0)
1409 1409
     {
1410
-		if ($this->course->has_resources(RESOURCE_EVENT)) {
1410
+        if ($this->course->has_resources(RESOURCE_EVENT)) {
1411 1411
             $sessionId = intval($sessionId);
1412
-			$table = Database :: get_course_table(TABLE_AGENDA);
1413
-			$resources = $this->course->resources;
1414
-			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1415
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1412
+            $table = Database :: get_course_table(TABLE_AGENDA);
1413
+            $resources = $this->course->resources;
1414
+            foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1415
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1416 1416
                 $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1417 1417
                     $event->content,
1418 1418
                     $this->course->code,
@@ -1430,7 +1430,7 @@  discard block
 block discarded – undo
1430 1430
                     'end_date' => $event->end_date,
1431 1431
                     'session_id' => $sessionId,
1432 1432
                 ];
1433
-				$new_event_id = Database::insert($table, $params);
1433
+                $new_event_id = Database::insert($table, $params);
1434 1434
 
1435 1435
                 if ($new_event_id) {
1436 1436
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id";
@@ -1443,30 +1443,30 @@  discard block
 block discarded – undo
1443 1443
                     $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
1444 1444
                 }
1445 1445
 
1446
-				// Copy event attachment
1446
+                // Copy event attachment
1447 1447
 
1448
-				$origin_path = $this->course->backup_path.'/upload/calendar/';
1449
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1448
+                $origin_path = $this->course->backup_path.'/upload/calendar/';
1449
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1450 1450
 
1451
-				if (!empty($this->course->orig)) {
1451
+                if (!empty($this->course->orig)) {
1452 1452
 
1453
-					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1454
-					$sql = 'SELECT path, comment, size, filename
1453
+                    $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1454
+                    $sql = 'SELECT path, comment, size, filename
1455 1455
 					        FROM '.$table_attachment.'
1456 1456
 					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
1457
-					$attachment_event = Database::query($sql);
1458
-					$attachment_event = Database::fetch_object($attachment_event);
1457
+                    $attachment_event = Database::query($sql);
1458
+                    $attachment_event = Database::fetch_object($attachment_event);
1459 1459
 
1460
-					if (file_exists($origin_path.$attachment_event->path) &&
1460
+                    if (file_exists($origin_path.$attachment_event->path) &&
1461 1461
                         !is_dir($origin_path.$attachment_event->path)
1462 1462
                     ) {
1463
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1464
-						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1465
-						//$copy_result = true;
1466
-						if ($copy_result) {
1467
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1463
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1464
+                        $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1465
+                        //$copy_result = true;
1466
+                        if ($copy_result) {
1467
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1468 1468
 
1469
-							$params = [
1469
+                            $params = [
1470 1470
                                 'c_id' => $this->destination_course_id,
1471 1471
                                 'path' => self::DBUTF8($new_filename),
1472 1472
                                 'comment' => self::DBUTF8($attachment_event->comment),
@@ -1480,17 +1480,17 @@  discard block
 block discarded – undo
1480 1480
                                 Database::query($sql);
1481 1481
                             }
1482 1482
                         }
1483
-					}
1484
-				} else {
1485
-					// get the info of the file
1486
-					if (!empty($event->attachment_path) &&
1483
+                    }
1484
+                } else {
1485
+                    // get the info of the file
1486
+                    if (!empty($event->attachment_path) &&
1487 1487
                         is_file($origin_path.$event->attachment_path) &&
1488 1488
                         is_readable($origin_path.$event->attachment_path)
1489 1489
                     ) {
1490
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1491
-						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1492
-						if ($copy_result) {
1493
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1490
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1491
+                        $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1492
+                        if ($copy_result) {
1493
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1494 1494
 
1495 1495
                             $params = [
1496 1496
                                 'c_id' => $this->destination_course_id,
@@ -1506,29 +1506,29 @@  discard block
 block discarded – undo
1506 1506
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id";
1507 1507
                                 Database::query($sql);
1508 1508
                             }
1509
-						}
1510
-					}
1511
-				}
1512
-			}
1513
-		}
1514
-	}
1515
-
1516
-	/**
1517
-	 * Restore course-description
1518
-	 */
1509
+                        }
1510
+                    }
1511
+                }
1512
+            }
1513
+        }
1514
+    }
1515
+
1516
+    /**
1517
+     * Restore course-description
1518
+     */
1519 1519
     public function restore_course_descriptions($session_id = 0)
1520 1520
     {
1521
-		if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1522
-			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1523
-			$resources = $this->course->resources;
1524
-			foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1521
+        if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1522
+            $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1523
+            $resources = $this->course->resources;
1524
+            foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1525 1525
                 $courseDescription = (array) $cd;
1526 1526
 
1527 1527
                 $content = isset($courseDescription['content']) ? $courseDescription['content'] : '';
1528 1528
                 $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : '';
1529 1529
                 $title = isset($courseDescription['title']) ? $courseDescription['title'] : '';
1530 1530
 
1531
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1531
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1532 1532
                 $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1533 1533
                     $content,
1534 1534
                     $this->course->code,
@@ -1556,22 +1556,22 @@  discard block
 block discarded – undo
1556 1556
                     }
1557 1557
                     $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id;
1558 1558
                 }
1559
-			}
1560
-		}
1561
-	}
1559
+            }
1560
+        }
1561
+    }
1562 1562
 
1563
-	/**
1564
-	 * Restore announcements
1565
-	 */
1563
+    /**
1564
+     * Restore announcements
1565
+     */
1566 1566
     public function restore_announcements($sessionId = 0)
1567 1567
     {
1568
-		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1568
+        if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1569 1569
             $sessionId = intval($sessionId);
1570
-			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1571
-			$resources = $this->course->resources;
1572
-			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1570
+            $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1571
+            $resources = $this->course->resources;
1572
+            foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1573 1573
 
1574
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1574
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1575 1575
                 $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1576 1576
                     $announcement->content,
1577 1577
                     $this->course->code,
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
                     'session_id' => $sessionId,
1591 1591
                 ];
1592 1592
 
1593
-				$new_announcement_id = Database::insert($table, $params);
1593
+                $new_announcement_id = Database::insert($table, $params);
1594 1594
 
1595 1595
                 if ($new_announcement_id) {
1596 1596
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id";
@@ -1602,32 +1602,32 @@  discard block
 block discarded – undo
1602 1602
                     $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
1603 1603
                 }
1604 1604
 
1605
-				$origin_path = $this->course->backup_path.'/upload/announcements/';
1606
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1605
+                $origin_path = $this->course->backup_path.'/upload/announcements/';
1606
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1607 1607
 
1608
-				// Copy announcement attachment file
1609
-				if (!empty($this->course->orig)) {
1608
+                // Copy announcement attachment file
1609
+                if (!empty($this->course->orig)) {
1610 1610
 
1611
-					$table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1612
-					$sql = 'SELECT path, comment, size, filename
1611
+                    $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1612
+                    $sql = 'SELECT path, comment, size, filename
1613 1613
 					        FROM '.$table_attachment.'
1614 1614
 					        WHERE
1615 1615
 					            c_id = '.$this->destination_course_id.' AND
1616 1616
 					            announcement_id = '.$id;
1617
-					$attachment_event = Database::query($sql);
1618
-					$attachment_event = Database::fetch_object($attachment_event);
1617
+                    $attachment_event = Database::query($sql);
1618
+                    $attachment_event = Database::fetch_object($attachment_event);
1619 1619
 
1620
-					if (file_exists($origin_path.$attachment_event->path) &&
1620
+                    if (file_exists($origin_path.$attachment_event->path) &&
1621 1621
                         !is_dir($origin_path.$attachment_event->path)
1622 1622
                     ) {
1623
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1623
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1624 1624
                         $copy_result = copy(
1625 1625
                             $origin_path.$attachment_event->path,
1626 1626
                             $destination_path.$new_filename
1627 1627
                         );
1628 1628
 
1629
-						if ($copy_result) {
1630
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1629
+                        if ($copy_result) {
1630
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1631 1631
 
1632 1632
                             $params = [
1633 1633
                                 'c_id' => $this->destination_course_id,
@@ -1644,20 +1644,20 @@  discard block
 block discarded – undo
1644 1644
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1645 1645
                                 Database::query($sql);
1646 1646
                             }
1647
-						}
1648
-					}
1649
-				} else {
1650
-					// get the info of the file
1651
-					if (!empty($announcement->attachment_path) &&
1647
+                        }
1648
+                    }
1649
+                } else {
1650
+                    // get the info of the file
1651
+                    if (!empty($announcement->attachment_path) &&
1652 1652
                         is_file($origin_path.$announcement->attachment_path) &&
1653 1653
                         is_readable($origin_path.$announcement->attachment_path)
1654 1654
                     ) {
1655
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1656
-						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1655
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1656
+                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1657 1657
 
1658
-						if ($copy_result) {
1659
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1660
-							/*$sql = "INSERT INTO ".$table_attachment." SET
1658
+                        if ($copy_result) {
1659
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1660
+                            /*$sql = "INSERT INTO ".$table_attachment." SET
1661 1661
 							        c_id = ".$this->destination_course_id." ,
1662 1662
 							        path = '".self::DBUTF8escapestring($new_filename)."',
1663 1663
 							        comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."',
@@ -1680,12 +1680,12 @@  discard block
 block discarded – undo
1680 1680
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1681 1681
                                 Database::query($sql);
1682 1682
                             }
1683
-						}
1684
-					}
1685
-				}
1686
-			}
1687
-		}
1688
-	}
1683
+                        }
1684
+                    }
1685
+                }
1686
+            }
1687
+        }
1688
+    }
1689 1689
 
1690 1690
     /**
1691 1691
      * Restore Quiz
@@ -1696,13 +1696,13 @@  discard block
 block discarded – undo
1696 1696
         $session_id = 0,
1697 1697
         $respect_base_content = false
1698 1698
     ) {
1699
-		if ($this->course->has_resources(RESOURCE_QUIZ)) {
1700
-			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1701
-			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1702
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1703
-			$resources = $this->course->resources;
1699
+        if ($this->course->has_resources(RESOURCE_QUIZ)) {
1700
+            $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1701
+            $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1702
+            $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1703
+            $resources = $this->course->resources;
1704 1704
 
1705
-			foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1705
+            foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1706 1706
 
1707 1707
                 if (isset($quiz->obj)) {
1708 1708
                     //For new imports
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
                     $quiz->obj = $quiz;
1713 1713
                 }
1714 1714
 
1715
-				$doc = '';
1715
+                $doc = '';
1716 1716
                 if (!empty($quiz->sound)) {
1717 1717
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1718 1718
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
@@ -1720,14 +1720,14 @@  discard block
 block discarded – undo
1720 1720
                                 WHERE
1721 1721
                                     c_id = " . $this->destination_course_id . "  AND
1722 1722
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1723
-						$doc = Database::query($sql);
1724
-						$doc = Database::fetch_object($doc);
1725
-						$doc = str_replace('/audio/', '', $doc->path);
1726
-					}
1727
-				}
1728
-
1729
-				if ($id != -1) {
1730
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1723
+                        $doc = Database::query($sql);
1724
+                        $doc = Database::fetch_object($doc);
1725
+                        $doc = str_replace('/audio/', '', $doc->path);
1726
+                    }
1727
+                }
1728
+
1729
+                if ($id != -1) {
1730
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1731 1731
                     $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1732 1732
                         $quiz->description,
1733 1733
                         $this->course->code,
@@ -1736,13 +1736,13 @@  discard block
 block discarded – undo
1736 1736
                         $this->course->info['path']
1737 1737
                     );
1738 1738
 
1739
-					global $_custom;
1740
-					if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1739
+                    global $_custom;
1740
+                    if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1741 1741
                         $_custom['exercises_clean_dates_when_restoring']
1742 1742
                     ) {
1743
-						$quiz->start_time = null;
1744
-						$quiz->end_time   = null;
1745
-					}
1743
+                        $quiz->start_time = null;
1744
+                        $quiz->end_time   = null;
1745
+                    }
1746 1746
 
1747 1747
                     $params = array(
1748 1748
                         'c_id' => $this->destination_course_id,
@@ -1774,10 +1774,10 @@  discard block
 block discarded – undo
1774 1774
                         }
1775 1775
                         $params['session_id'] = $my_session_id;
1776 1776
                     } else {
1777
-        				if (!empty($session_id)) {
1778
-        					$session_id = intval($session_id);
1777
+                        if (!empty($session_id)) {
1778
+                            $session_id = intval($session_id);
1779 1779
                             $params['session_id'] = $session_id;
1780
-    				    }
1780
+                        }
1781 1781
                     }
1782 1782
                     $new_id = Database::insert($table_qui, $params);
1783 1783
 
@@ -1786,15 +1786,15 @@  discard block
 block discarded – undo
1786 1786
                         Database::query($sql);
1787 1787
                     }
1788 1788
 
1789
-				} else {
1790
-					// $id = -1 identifies the fictionary test for collecting
1791
-					// orphan questions. We do not store it in the database.
1792
-					$new_id = -1;
1793
-				}
1789
+                } else {
1790
+                    // $id = -1 identifies the fictionary test for collecting
1791
+                    // orphan questions. We do not store it in the database.
1792
+                    $new_id = -1;
1793
+                }
1794 1794
 
1795
-				$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1795
+                $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1796 1796
 
1797
-				$order = 0;
1797
+                $order = 0;
1798 1798
                 if (!empty($quiz->question_ids)) {
1799 1799
                     foreach ($quiz->question_ids as $index => $question_id) {
1800 1800
                         $qid = $this->restore_quiz_question($question_id);
@@ -1807,30 +1807,30 @@  discard block
 block discarded – undo
1807 1807
                         Database::query($sql);
1808 1808
                     }
1809 1809
                 }
1810
-			}
1811
-		}
1812
-	}
1810
+            }
1811
+        }
1812
+    }
1813 1813
 
1814
-	/**
1815
-	 * Restore quiz-questions
1814
+    /**
1815
+     * Restore quiz-questions
1816 1816
      * @params int question id
1817
-	 */
1817
+     */
1818 1818
     public function restore_quiz_question($id)
1819 1819
     {
1820
-		$resources = $this->course->resources;
1820
+        $resources = $this->course->resources;
1821 1821
         $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
1822 1822
 
1823
-		$new_id = 0;
1823
+        $new_id = 0;
1824 1824
 
1825
-		if (is_object($question)) {
1826
-			if ($question->is_restored()) {
1827
-				return $question->destination_id;
1828
-			}
1829
-			$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1830
-			$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1825
+        if (is_object($question)) {
1826
+            if ($question->is_restored()) {
1827
+                return $question->destination_id;
1828
+            }
1829
+            $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1830
+            $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1831 1831
             $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
1832 1832
 
1833
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
1833
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
1834 1834
             $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1835 1835
                 $question->description,
1836 1836
                 $this->course->code,
@@ -1851,7 +1851,7 @@  discard block
 block discarded – undo
1851 1851
                 'extra' => self::DBUTF8($question->extra),
1852 1852
             ];
1853 1853
 
1854
-			$new_id = Database::insert($table_que, $params);
1854
+            $new_id = Database::insert($table_que, $params);
1855 1855
 
1856 1856
             if ($new_id) {
1857 1857
 
@@ -1892,7 +1892,7 @@  discard block
 block discarded – undo
1892 1892
 
1893 1893
                 foreach ($temp as $index => $answer) {
1894 1894
                     //id = '".$index."',
1895
-					$params = [
1895
+                    $params = [
1896 1896
                         'c_id' => $this->destination_course_id,
1897 1897
                         'question_id' => $new_id,
1898 1898
                         'answer' => self::DBUTF8($answer['answer']),
@@ -1909,12 +1909,12 @@  discard block
 block discarded – undo
1909 1909
                         $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId";
1910 1910
                         Database::query($sql);
1911 1911
                     }
1912
-				}
1913
-			} else {
1912
+                }
1913
+            } else {
1914 1914
                 $correct_answers = array();
1915
-				foreach ($question->answers as $index => $answer) {
1915
+                foreach ($question->answers as $index => $answer) {
1916 1916
 
1917
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1917
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1918 1918
                     $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1919 1919
                         $answer['answer'],
1920 1920
                         $this->course->code,
@@ -1953,8 +1953,8 @@  discard block
 block discarded – undo
1953 1953
                     }
1954 1954
 
1955 1955
                     $correct_answers[$answerId] = $answer['correct'];
1956
-				}
1957
-			}
1956
+                }
1957
+            }
1958 1958
 
1959 1959
             //Current course id
1960 1960
             $course_id = api_get_course_int_id();
@@ -2051,12 +2051,12 @@  discard block
 block discarded – undo
2051 2051
                     }
2052 2052
                 }
2053 2053
             }
2054
-			$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2055
-		}
2056
-		return $new_id;
2057
-	}
2054
+            $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2055
+        }
2056
+        return $new_id;
2057
+    }
2058 2058
 
2059
-	/**
2059
+    /**
2060 2060
      * @todo : add session id when used for session
2061 2061
      */
2062 2062
     public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
@@ -2136,21 +2136,21 @@  discard block
 block discarded – undo
2136 2136
         $sessionId = intval($sessionId);
2137 2137
 
2138 2138
         if ($this->course->has_resources(RESOURCE_SURVEY)) {
2139
-			$table_sur = Database :: get_course_table(TABLE_SURVEY);
2140
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2141
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2142
-			$resources = $this->course->resources;
2143
-			foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2139
+            $table_sur = Database :: get_course_table(TABLE_SURVEY);
2140
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2141
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2142
+            $resources = $this->course->resources;
2143
+            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2144 2144
 
2145
-				$sql = 'SELECT survey_id FROM '.$table_sur.'
2145
+                $sql = 'SELECT survey_id FROM '.$table_sur.'
2146 2146
                         WHERE
2147 2147
                             c_id = '.$this->destination_course_id.' AND
2148 2148
                             code = "'.self::DBUTF8escapestring($survey->code).'" AND
2149 2149
                             lang = "'.self::DBUTF8escapestring($survey->lang).'" ';
2150 2150
 
2151
-				$result_check = Database::query($sql);
2151
+                $result_check = Database::query($sql);
2152 2152
 
2153
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2153
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2154 2154
                 $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2155 2155
                     $survey->title,
2156 2156
                     $this->course->code,
@@ -2204,20 +2204,20 @@  discard block
 block discarded – undo
2204 2204
                     'session_id' => $sessionId,
2205 2205
                 ];
2206 2206
 
2207
-				//An existing survey exists with the same code and the same language
2208
-				if (Database::num_rows($result_check) == 1) {
2209
-					switch ($this->file_option) {
2210
-						case FILE_SKIP:
2211
-							//Do nothing
2212
-							break;
2213
-						case FILE_RENAME:
2214
-							$survey_code = $survey->code.'_';
2215
-							$i=1;
2216
-							$temp_survey_code = $survey_code.$i;
2217
-							while (!$this->is_survey_code_available($temp_survey_code)) {
2218
-								$temp_survey_code = $survey_code.++$i;
2219
-							}
2220
-							$survey_code = $temp_survey_code;
2207
+                //An existing survey exists with the same code and the same language
2208
+                if (Database::num_rows($result_check) == 1) {
2209
+                    switch ($this->file_option) {
2210
+                        case FILE_SKIP:
2211
+                            //Do nothing
2212
+                            break;
2213
+                        case FILE_RENAME:
2214
+                            $survey_code = $survey->code.'_';
2215
+                            $i=1;
2216
+                            $temp_survey_code = $survey_code.$i;
2217
+                            while (!$this->is_survey_code_available($temp_survey_code)) {
2218
+                                $temp_survey_code = $survey_code.++$i;
2219
+                            }
2220
+                            $survey_code = $temp_survey_code;
2221 2221
 
2222 2222
                             $params['code'] = $survey_code;
2223 2223
                             $new_id = Database::insert($table_sur, $params);
@@ -2236,25 +2236,25 @@  discard block
 block discarded – undo
2236 2236
                                     Database::query($sql);
2237 2237
                                 }
2238 2238
                             }
2239
-							break;
2240
-						case FILE_OVERWRITE:
2241
-							// Delete the existing survey with the same code and language and import the one of the source course
2242
-							// getting the information of the survey (used for when the survey is shared)
2239
+                            break;
2240
+                        case FILE_OVERWRITE:
2241
+                            // Delete the existing survey with the same code and language and import the one of the source course
2242
+                            // getting the information of the survey (used for when the survey is shared)
2243 2243
 
2244
-							$sql = "SELECT * FROM $table_sur
2244
+                            $sql = "SELECT * FROM $table_sur
2245 2245
 							        WHERE
2246 2246
 							            c_id = ".$this->destination_course_id." AND
2247 2247
 							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2248
-							$result = Database::query($sql);
2249
-							$survey_data = Database::fetch_array($result,'ASSOC');
2248
+                            $result = Database::query($sql);
2249
+                            $survey_data = Database::fetch_array($result,'ASSOC');
2250 2250
 
2251
-							// if the survey is shared => also delete the shared content
2252
-							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2251
+                            // if the survey is shared => also delete the shared content
2252
+                            if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2253 2253
                                 SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2254
-							}
2255
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2254
+                            }
2255
+                            SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2256 2256
 
2257
-							// Insert the new source survey
2257
+                            // Insert the new source survey
2258 2258
                             $new_id = Database::insert($table_sur, $params);
2259 2259
 
2260 2260
                             if ($new_id) {
@@ -2275,11 +2275,11 @@  discard block
 block discarded – undo
2275 2275
                                     Database::query($sql);
2276 2276
                                 }
2277 2277
                             }
2278
-							break;
2279
-						default:
2280
-							break;
2281
-					}
2282
-				} else {
2278
+                            break;
2279
+                        default:
2280
+                            break;
2281
+                    }
2282
+                } else {
2283 2283
                     // No existing survey with the same language and the same code, we just copy the survey
2284 2284
                     $new_id = Database::insert($table_sur, $params);
2285 2285
 
@@ -2301,45 +2301,45 @@  discard block
 block discarded – undo
2301 2301
                             Database::query($sql);
2302 2302
                         }
2303 2303
                     }
2304
-				}
2305
-			}
2306
-		}
2307
-	}
2308
-
2309
-	/**
2310
-	 * Check availability of a survey code
2311
-	 * @param string $survey_code
2312
-	 */
2304
+                }
2305
+            }
2306
+        }
2307
+    }
2308
+
2309
+    /**
2310
+     * Check availability of a survey code
2311
+     * @param string $survey_code
2312
+     */
2313 2313
     public function is_survey_code_available($survey_code)
2314 2314
     {
2315
-		$table_sur = Database :: get_course_table(TABLE_SURVEY);
2316
-		$sql = "SELECT * FROM $table_sur
2315
+        $table_sur = Database :: get_course_table(TABLE_SURVEY);
2316
+        $sql = "SELECT * FROM $table_sur
2317 2317
 		        WHERE
2318 2318
 		            c_id = ".$this->destination_course_id." AND
2319 2319
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2320
-		$result = Database::query($sql);
2321
-		if (Database::num_rows($result) > 0) return false; else return true;
2322
-	}
2323
-
2324
-	/**
2325
-	 * Restore survey-questions
2326
-	 * @param string $survey_id
2327
-	 */
2320
+        $result = Database::query($sql);
2321
+        if (Database::num_rows($result) > 0) return false; else return true;
2322
+    }
2323
+
2324
+    /**
2325
+     * Restore survey-questions
2326
+     * @param string $survey_id
2327
+     */
2328 2328
     public function restore_survey_question($id, $survey_id)
2329 2329
     {
2330
-		$resources = $this->course->resources;
2331
-		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2330
+        $resources = $this->course->resources;
2331
+        $question = $resources[RESOURCE_SURVEYQUESTION][$id];
2332 2332
 
2333
-		$new_id=0;
2333
+        $new_id=0;
2334 2334
 
2335
-		if (is_object($question)) {
2336
-			if ($question->is_restored()) {
2337
-				return $question->destination_id;
2338
-			}
2339
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2340
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2335
+        if (is_object($question)) {
2336
+            if ($question->is_restored()) {
2337
+                return $question->destination_id;
2338
+            }
2339
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2340
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2341 2341
 
2342
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
2342
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
2343 2343
             $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2344 2344
                 $question->survey_question,
2345 2345
                 $this->course->code,
@@ -2393,10 +2393,10 @@  discard block
 block discarded – undo
2393 2393
                 }
2394 2394
                 $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
2395 2395
             }
2396
-		}
2396
+        }
2397 2397
 
2398
-		return $new_id;
2399
-	}
2398
+        return $new_id;
2399
+    }
2400 2400
 
2401 2401
     /**
2402 2402
      * Restoring learning paths
@@ -2407,20 +2407,20 @@  discard block
 block discarded – undo
2407 2407
     {
2408 2408
         $session_id = intval($session_id);
2409 2409
 
2410
-		if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2410
+        if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2411 2411
             $table_main = Database::get_course_table(TABLE_LP_MAIN);
2412 2412
             $table_item = Database::get_course_table(TABLE_LP_ITEM);
2413 2413
             $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
2414 2414
 
2415
-			$resources = $this->course->resources;
2415
+            $resources = $this->course->resources;
2416 2416
 
2417
-			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2418
-			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2417
+            $origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2418
+            $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2419 2419
 
2420
-			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2420
+            foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2421 2421
 
2422
-				$condition_session = "";
2423
-				if (!empty($session_id)) {
2422
+                $condition_session = "";
2423
+                if (!empty($session_id)) {
2424 2424
                     if ($respect_base_content) {
2425 2425
                         $my_session_id = $lp->session_id;
2426 2426
                         if (!empty($lp->session_id)) {
@@ -2431,21 +2431,21 @@  discard block
 block discarded – undo
2431 2431
                         $session_id = intval($session_id);
2432 2432
                         $condition_session = $session_id;
2433 2433
                     }
2434
-				}
2435
-
2436
-				// Adding the author's image
2437
-				if (!empty($lp->preview_image)) {
2438
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2439
-					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2440
-						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2441
-						//$copy_result = true;
2442
-						if ($copy_result) {
2443
-							$lp->preview_image = $new_filename;
2444
-						} else {
2445
-							$lp->preview_image ='';
2446
-						}
2447
-					}
2448
-				}
2434
+                }
2435
+
2436
+                // Adding the author's image
2437
+                if (!empty($lp->preview_image)) {
2438
+                    $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2439
+                    if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2440
+                        $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2441
+                        //$copy_result = true;
2442
+                        if ($copy_result) {
2443
+                            $lp->preview_image = $new_filename;
2444
+                        } else {
2445
+                            $lp->preview_image ='';
2446
+                        }
2447
+                    }
2448
+                }
2449 2449
 
2450 2450
                 if ($this->add_text_in_items) {
2451 2451
                     $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix');
@@ -2492,7 +2492,7 @@  discard block
 block discarded – undo
2492 2492
                     $params['session_id'] = $condition_session;
2493 2493
                 }
2494 2494
 
2495
-				$new_lp_id = Database::insert($table_main, $params);
2495
+                $new_lp_id = Database::insert($table_main, $params);
2496 2496
 
2497 2497
                 if ($new_lp_id) {
2498 2498
 
@@ -2553,13 +2553,13 @@  discard block
 block discarded – undo
2553 2553
                 $old_refs = array();
2554 2554
                 $prerequisite_ids = array();
2555 2555
 
2556
-				foreach ($lp->get_items() as $index => $item) {
2557
-					// we set the ref code here and then we update in a for loop
2558
-					$ref = $item['ref'];
2556
+                foreach ($lp->get_items() as $index => $item) {
2557
+                    // we set the ref code here and then we update in a for loop
2558
+                    $ref = $item['ref'];
2559 2559
 
2560
-					// Dealing with path the same way as ref as some data has
2560
+                    // Dealing with path the same way as ref as some data has
2561 2561
                     // been put into path when it's a local resource
2562
-					// Only fix the path for no scos
2562
+                    // Only fix the path for no scos
2563 2563
                     if ($item['item_type'] == 'sco') {
2564 2564
                         $path = $item['path'];
2565 2565
                     } else {
@@ -2588,128 +2588,128 @@  discard block
 block discarded – undo
2588 2588
                         'launch_data' => self::DBUTF8($item['launch_data']),
2589 2589
                     ];
2590 2590
 
2591
-					$new_item_id = Database::insert($table_item, $params);
2591
+                    $new_item_id = Database::insert($table_item, $params);
2592 2592
 
2593 2593
                     $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
2594 2594
                     Database::query($sql);
2595 2595
 
2596
-					//save a link between old and new item IDs
2597
-					$new_item_ids[$item['id']] = $new_item_id;
2598
-					//save a reference of items that need a parent_item_id refresh
2599
-					$parent_item_ids[$new_item_id] = $item['parent_item_id'];
2600
-					//save a reference of items that need a previous_item_id refresh
2601
-					$previous_item_ids[$new_item_id] = $item['previous_item_id'];
2602
-					//save a reference of items that need a next_item_id refresh
2603
-					$next_item_ids[$new_item_id] = $item['next_item_id'];
2604
-
2605
-					if (!empty($item['prerequisite'])) {
2606
-						if ($lp->lp_type =='2') {
2607
-							// if is an sco
2608
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2609
-						} else {
2610
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2611
-						}
2612
-					}
2613
-
2614
-					if (!empty($ref)) {
2615
-						if ($lp->lp_type =='2') {
2616
-							// if is an sco
2617
-							$old_refs[$new_item_id]= $ref;
2618
-						} else {
2596
+                    //save a link between old and new item IDs
2597
+                    $new_item_ids[$item['id']] = $new_item_id;
2598
+                    //save a reference of items that need a parent_item_id refresh
2599
+                    $parent_item_ids[$new_item_id] = $item['parent_item_id'];
2600
+                    //save a reference of items that need a previous_item_id refresh
2601
+                    $previous_item_ids[$new_item_id] = $item['previous_item_id'];
2602
+                    //save a reference of items that need a next_item_id refresh
2603
+                    $next_item_ids[$new_item_id] = $item['next_item_id'];
2604
+
2605
+                    if (!empty($item['prerequisite'])) {
2606
+                        if ($lp->lp_type =='2') {
2607
+                            // if is an sco
2608
+                            $old_prerequisite[$new_item_id]= $item['prerequisite'];
2609
+                        } else {
2610
+                            $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2611
+                        }
2612
+                    }
2613
+
2614
+                    if (!empty($ref)) {
2615
+                        if ($lp->lp_type =='2') {
2616
+                            // if is an sco
2617
+                            $old_refs[$new_item_id]= $ref;
2618
+                        } else {
2619 2619
                             $old_refs[$new_item_id]= $new_item_ids[$ref];
2620
-						}
2621
-					}
2620
+                        }
2621
+                    }
2622 2622
 
2623
-					$prerequisite_ids[$new_item_id] = $item['prerequisite'];
2624
-				}
2623
+                    $prerequisite_ids[$new_item_id] = $item['prerequisite'];
2624
+                }
2625 2625
 
2626
-				// Updating prerequisites
2627
-				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2628
-					if($my_old_prerequisite != ''){
2629
-						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2626
+                // Updating prerequisites
2627
+                foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2628
+                    if($my_old_prerequisite != ''){
2629
+                        $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2630 2630
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2631
-						Database::query($sql);
2632
-					}
2633
-				}
2634
-
2635
-				// Updating refs
2636
-				foreach ($old_refs  as $key=>$my_old_ref) {
2637
-					if ($my_old_ref != '') {
2638
-						$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2631
+                        Database::query($sql);
2632
+                    }
2633
+                }
2634
+
2635
+                // Updating refs
2636
+                foreach ($old_refs  as $key=>$my_old_ref) {
2637
+                    if ($my_old_ref != '') {
2638
+                        $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2639 2639
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2640
-						Database::query($sql);
2641
-					}
2642
-				}
2643
-
2644
-				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2645
-					$parent_new_id = 0;
2646
-					if($parent_item_old_id != 0){
2647
-						$parent_new_id = $new_item_ids[$parent_item_old_id];
2648
-					}
2649
-					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2640
+                        Database::query($sql);
2641
+                    }
2642
+                }
2643
+
2644
+                foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2645
+                    $parent_new_id = 0;
2646
+                    if($parent_item_old_id != 0){
2647
+                        $parent_new_id = $new_item_ids[$parent_item_old_id];
2648
+                    }
2649
+                    $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2650 2650
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2651
-					Database::query($sql);
2652
-				}
2653
-				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2654
-					$previous_new_id = 0;
2655
-					if($previous_item_old_id != 0){
2656
-						$previous_new_id = $new_item_ids[$previous_item_old_id];
2657
-					}
2658
-					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2651
+                    Database::query($sql);
2652
+                }
2653
+                foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2654
+                    $previous_new_id = 0;
2655
+                    if($previous_item_old_id != 0){
2656
+                        $previous_new_id = $new_item_ids[$previous_item_old_id];
2657
+                    }
2658
+                    $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2659 2659
 					        WHERE  c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2660
-					Database::query($sql);
2661
-				}
2662
-
2663
-				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2664
-					$next_new_id = 0;
2665
-					if($next_item_old_id != 0){
2666
-						$next_new_id = $new_item_ids[$next_item_old_id];
2667
-					}
2668
-					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2660
+                    Database::query($sql);
2661
+                }
2662
+
2663
+                foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2664
+                    $next_new_id = 0;
2665
+                    if($next_item_old_id != 0){
2666
+                        $next_new_id = $new_item_ids[$next_item_old_id];
2667
+                    }
2668
+                    $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2669 2669
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2670
-					Database::query($sql);
2671
-				}
2672
-
2673
-				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2674
-					$prerequisite_new_id = 0;
2675
-					if($prerequisite_old_id != 0){
2676
-						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2677
-					}
2678
-					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2670
+                    Database::query($sql);
2671
+                }
2672
+
2673
+                foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2674
+                    $prerequisite_new_id = 0;
2675
+                    if($prerequisite_old_id != 0){
2676
+                        $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2677
+                    }
2678
+                    $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2679 2679
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2680
-					Database::query($sql);
2681
-				}
2682
-				$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2683
-			}
2684
-		}
2685
-	}
2686
-
2687
-	/**
2688
-	 * Restore works
2680
+                    Database::query($sql);
2681
+                }
2682
+                $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2683
+            }
2684
+        }
2685
+    }
2686
+
2687
+    /**
2688
+     * Restore works
2689 2689
      * @deprecated use restore_works
2690 2690
      *
2691
-	 */
2692
-	public function restore_student_publication($sessionId = 0)
2691
+     */
2692
+    public function restore_student_publication($sessionId = 0)
2693 2693
     {
2694 2694
         $sessionId = intval($sessionId);
2695
-		$work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2696
-		$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2697
-		$item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2695
+        $work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2696
+        $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2697
+        $item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2698 2698
 
2699
-		// Query in student publication
2700
-		$sql = 'SELECT * FROM '.$work_table.'
2699
+        // Query in student publication
2700
+        $sql = 'SELECT * FROM '.$work_table.'
2701 2701
 		        WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) ';
2702 2702
 
2703
-		$result = Database::query($sql);
2704
-		$folders = Database::store_result($result, 'ASSOC');
2703
+        $result = Database::query($sql);
2704
+        $folders = Database::store_result($result, 'ASSOC');
2705 2705
 
2706
-		foreach ($folders  as $folder) {
2707
-		    $old_id = $folder['id'];
2706
+        foreach ($folders  as $folder) {
2707
+            $old_id = $folder['id'];
2708 2708
             unset($folder['id']);
2709
-			$folder['c_id'] = $this->destination_course_id;
2709
+            $folder['c_id'] = $this->destination_course_id;
2710 2710
             $folder['parent_id'] = 0;
2711 2711
             $folder['session_id'] = $sessionId;
2712
-			$new_id = Database::insert($work_table, $folder);
2712
+            $new_id = Database::insert($work_table, $folder);
2713 2713
 
2714 2714
             if ($new_id) {
2715 2715
                 //query in item property
@@ -2768,23 +2768,23 @@  discard block
 block discarded – undo
2768 2768
                     }
2769 2769
                 }
2770 2770
             }
2771
-		}
2771
+        }
2772 2772
 
2773
-		$destination = '../../courses/'.$this->course->destination_path.'/work/';
2774
-		$origin = '../../courses/'.$this->course->info['path'].'/work/';
2775
-		self::allow_create_all_directory($origin,$destination,false);
2776
-	}
2773
+        $destination = '../../courses/'.$this->course->destination_path.'/work/';
2774
+        $origin = '../../courses/'.$this->course->info['path'].'/work/';
2775
+        self::allow_create_all_directory($origin,$destination,false);
2776
+    }
2777 2777
 
2778 2778
     /**
2779
-    * copy all directory and sub directory
2780
-    * @param string The path origin
2781
-    * @param string The path destination
2782
-    * @param boolean Option Overwrite
2783
-    * @param string $source
2784
-    * @param string $dest
2785
-    * @return void()
2786
-    * @deprecated
2787
-    */
2779
+     * copy all directory and sub directory
2780
+     * @param string The path origin
2781
+     * @param string The path destination
2782
+     * @param boolean Option Overwrite
2783
+     * @param string $source
2784
+     * @param string $dest
2785
+     * @return void()
2786
+     * @deprecated
2787
+     */
2788 2788
     public function allow_create_all_directory($source, $dest, $overwrite = false)
2789 2789
     {
2790 2790
         if (!is_dir($dest)) {
@@ -2795,14 +2795,14 @@  discard block
 block discarded – undo
2795 2795
                 if ($file != '.' && $file != '..') {
2796 2796
                     $path = $source . '/' . $file;
2797 2797
                     if (is_file($path)) {
2798
-                       /* if (!is_file($dest . '/' . $file) || $overwrite)
2798
+                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2799 2799
                         if (!@copy($path, $dest . '/' . $file)) {
2800 2800
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2801 2801
                         }*/
2802 2802
                     } elseif(is_dir($path)) {
2803 2803
                         if (!is_dir($dest . '/' . $file))
2804 2804
                         mkdir($dest . '/' . $file);
2805
-                       self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2805
+                        self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2806 2806
                     }
2807 2807
                 }
2808 2808
             }
@@ -2810,12 +2810,12 @@  discard block
 block discarded – undo
2810 2810
         }
2811 2811
     }
2812 2812
 
2813
-	/**
2814
-	 * Gets the new ID of one specific tool item from the tool name and the old ID
2815
-	 * @param	string	Tool name
2816
-	 * @param	integer	Old ID
2817
-	 * @return	integer	New ID
2818
-	 */
2813
+    /**
2814
+     * Gets the new ID of one specific tool item from the tool name and the old ID
2815
+     * @param	string	Tool name
2816
+     * @param	integer	Old ID
2817
+     * @return	integer	New ID
2818
+     */
2819 2819
     public function get_new_id($tool, $ref)
2820 2820
     {
2821 2821
         // Check if the value exist in the current array.
@@ -2837,25 +2837,25 @@  discard block
 block discarded – undo
2837 2837
         }
2838 2838
 
2839 2839
         return '';
2840
-	}
2840
+    }
2841 2841
 
2842
-	/**
2843
-	 * Restore glossary
2844
-	 */
2842
+    /**
2843
+     * Restore glossary
2844
+     */
2845 2845
     public function restore_glossary($session_id = 0)
2846 2846
     {
2847
-		if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2848
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2849
-			$resources = $this->course->resources;
2850
-			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2847
+        if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2848
+            $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2849
+            $resources = $this->course->resources;
2850
+            foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2851 2851
 
2852 2852
                 $params = [];
2853
-    			if (!empty($session_id)) {
2854
-    				$session_id = intval($session_id);
2853
+                if (!empty($session_id)) {
2854
+                    $session_id = intval($session_id);
2855 2855
                     $params['session_id'] = $session_id;
2856
-    			}
2856
+                }
2857 2857
 
2858
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2858
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2859 2859
                 $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2860 2860
                     $glossary->description,
2861 2861
                     $this->course->code,
@@ -2889,27 +2889,27 @@  discard block
 block discarded – undo
2889 2889
 
2890 2890
                     $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id;
2891 2891
                 }
2892
-			}
2893
-		}
2894
-	}
2892
+            }
2893
+        }
2894
+    }
2895 2895
 
2896 2896
     /**
2897 2897
      * @param int $session_id
2898 2898
      */
2899 2899
     public function restore_wiki($session_id = 0)
2900 2900
     {
2901
-		if ($this->course->has_resources(RESOURCE_WIKI)) {
2902
-			// wiki table of the target course
2903
-			$table_wiki = Database :: get_course_table(TABLE_WIKI);
2904
-			$table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2901
+        if ($this->course->has_resources(RESOURCE_WIKI)) {
2902
+            // wiki table of the target course
2903
+            $table_wiki = Database :: get_course_table(TABLE_WIKI);
2904
+            $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2905 2905
 
2906
-			// storing all the resources that have to be copied in an array
2907
-			$resources = $this->course->resources;
2906
+            // storing all the resources that have to be copied in an array
2907
+            $resources = $this->course->resources;
2908 2908
 
2909
-			foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2910
-				// the sql statement to insert the groups from the old course to the new course
2909
+            foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2910
+                // the sql statement to insert the groups from the old course to the new course
2911 2911
 
2912
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2912
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2913 2913
                 $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2914 2914
                     $wiki->content,
2915 2915
                     $this->course->code,
@@ -2932,7 +2932,7 @@  discard block
 block discarded – undo
2932 2932
                     'session_id' => !empty($session_id) ? intval($session_id) : 0,
2933 2933
                 ];
2934 2934
 
2935
-				$new_id = Database::insert($table_wiki, $params);
2935
+                $new_id = Database::insert($table_wiki, $params);
2936 2936
 
2937 2937
                 if ($new_id) {
2938 2938
 
@@ -2963,9 +2963,9 @@  discard block
 block discarded – undo
2963 2963
 
2964 2964
                     Database::insert($table_wiki_conf, $params);
2965 2965
                 }
2966
-			}
2967
-		}
2968
-	}
2966
+            }
2967
+        }
2968
+    }
2969 2969
 
2970 2970
     /**
2971 2971
      * Restore Thematics
@@ -2973,15 +2973,15 @@  discard block
 block discarded – undo
2973 2973
      */
2974 2974
     public function restore_thematic($session_id = 0)
2975 2975
     {
2976
-		if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2976
+        if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2977 2977
             $table_thematic = Database:: get_course_table(TABLE_THEMATIC);
2978 2978
             $table_thematic_advance = Database:: get_course_table(TABLE_THEMATIC_ADVANCE);
2979 2979
             $table_thematic_plan = Database:: get_course_table(TABLE_THEMATIC_PLAN);
2980 2980
 
2981
-			$resources = $this->course->resources;
2982
-			foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2981
+            $resources = $this->course->resources;
2982
+            foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2983 2983
 
2984
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2984
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2985 2985
                 $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2986 2986
                     $thematic->params['content'],
2987 2987
                     $this->course->code,
@@ -2989,13 +2989,13 @@  discard block
 block discarded – undo
2989 2989
                     $this->course->backup_path,
2990 2990
                     $this->course->info['path']
2991 2991
                 );
2992
-				$thematic->params['c_id']  = $this->destination_course_id;
2993
-				unset($thematic->params['id']);
2992
+                $thematic->params['c_id']  = $this->destination_course_id;
2993
+                unset($thematic->params['id']);
2994 2994
                 unset($thematic->params['iid']);
2995 2995
 
2996
-				$last_id = Database::insert($table_thematic, $thematic->params, false);
2996
+                $last_id = Database::insert($table_thematic, $thematic->params, false);
2997 2997
 
2998
-				if ($last_id) {
2998
+                if ($last_id) {
2999 2999
 
3000 3000
                     $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id";
3001 3001
                     Database::query($sql);
@@ -3008,19 +3008,19 @@  discard block
 block discarded – undo
3008 3008
                         api_get_user_id()
3009 3009
                     );
3010 3010
 
3011
-					foreach ($thematic->thematic_advance_list as $thematic_advance) {
3012
-						unset($thematic_advance['id']);
3011
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
3012
+                        unset($thematic_advance['id']);
3013 3013
                         unset($thematic_advance['iid']);
3014
-						$thematic_advance['attendance_id'] = 0;
3015
-						$thematic_advance['thematic_id'] = $last_id;
3016
-						$thematic_advance['c_id']  = $this->destination_course_id;
3014
+                        $thematic_advance['attendance_id'] = 0;
3015
+                        $thematic_advance['thematic_id'] = $last_id;
3016
+                        $thematic_advance['c_id']  = $this->destination_course_id;
3017 3017
                         $my_id = Database::insert(
3018 3018
                             $table_thematic_advance,
3019 3019
                             $thematic_advance,
3020 3020
                             false
3021 3021
                         );
3022 3022
 
3023
-						if ($my_id) {
3023
+                        if ($my_id) {
3024 3024
 
3025 3025
                             $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id";
3026 3026
                             Database::query($sql);
@@ -3032,17 +3032,17 @@  discard block
 block discarded – undo
3032 3032
                                 "ThematicAdvanceAdded",
3033 3033
                                 api_get_user_id()
3034 3034
                             );
3035
-						}
3036
-					}
3035
+                        }
3036
+                    }
3037 3037
 
3038
-					foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
-						unset($thematic_plan['id']);
3038
+                    foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
+                        unset($thematic_plan['id']);
3040 3040
                         unset($thematic_plan['iid']);
3041
-						$thematic_plan['thematic_id'] = $last_id;
3042
-						$thematic_plan['c_id'] = $this->destination_course_id;
3043
-						$my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3041
+                        $thematic_plan['thematic_id'] = $last_id;
3042
+                        $thematic_plan['c_id'] = $this->destination_course_id;
3043
+                        $my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3044 3044
 
3045
-						if ($my_id) {
3045
+                        if ($my_id) {
3046 3046
 
3047 3047
                             $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id";
3048 3048
                             Database::query($sql);
@@ -3054,12 +3054,12 @@  discard block
 block discarded – undo
3054 3054
                                 "ThematicPlanAdded",
3055 3055
                                 api_get_user_id()
3056 3056
                             );
3057
-						}
3058
-					}
3059
-				}
3060
-			}
3061
-		}
3062
-	}
3057
+                        }
3058
+                    }
3059
+                }
3060
+            }
3061
+        }
3062
+    }
3063 3063
 
3064 3064
     /**
3065 3065
      * Restore Attendance
@@ -3067,14 +3067,14 @@  discard block
 block discarded – undo
3067 3067
      */
3068 3068
     public function restore_attendance($session_id = 0)
3069 3069
     {
3070
-		if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
-			$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
-			$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3070
+        if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
+            $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
+            $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3073 3073
 
3074
-			$resources = $this->course->resources;
3075
-			foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3074
+            $resources = $this->course->resources;
3075
+            foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3076 3076
 
3077
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
3077
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
3078 3078
                 $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
3079 3079
                     $obj->params['description'],
3080 3080
                     $this->course->code,
@@ -3086,11 +3086,11 @@  discard block
 block discarded – undo
3086 3086
                 unset($obj->params['id']);
3087 3087
                 unset($obj->params['iid']);
3088 3088
 
3089
-				$obj->params['c_id'] = $this->destination_course_id;
3089
+                $obj->params['c_id'] = $this->destination_course_id;
3090 3090
 
3091
-				$last_id = Database::insert($table_attendance, $obj->params);
3091
+                $last_id = Database::insert($table_attendance, $obj->params);
3092 3092
 
3093
-				if (is_numeric($last_id)) {
3093
+                if (is_numeric($last_id)) {
3094 3094
 
3095 3095
                     $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id";
3096 3096
                     Database::query($sql);
@@ -3104,11 +3104,11 @@  discard block
 block discarded – undo
3104 3104
                     );
3105 3105
 
3106 3106
                     foreach ($obj->attendance_calendar as $attendance_calendar) {
3107
-						unset($attendance_calendar['id']);
3107
+                        unset($attendance_calendar['id']);
3108 3108
                         unset($attendance_calendar['iid']);
3109 3109
 
3110
-						$attendance_calendar['attendance_id'] = $last_id;
3111
-						$attendance_calendar['c_id'] = $this->destination_course_id;
3110
+                        $attendance_calendar['attendance_id'] = $last_id;
3111
+                        $attendance_calendar['c_id'] = $this->destination_course_id;
3112 3112
                         $attendanceCalendarId = Database::insert(
3113 3113
                             $table_attendance_calendar,
3114 3114
                             $attendance_calendar
@@ -3116,11 +3116,11 @@  discard block
 block discarded – undo
3116 3116
 
3117 3117
                         $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId";
3118 3118
                         Database::query($sql);
3119
-					}
3120
-				}
3121
-			}
3122
-		}
3123
-	}
3119
+                    }
3120
+                }
3121
+            }
3122
+        }
3123
+    }
3124 3124
 
3125 3125
     /**
3126 3126
      * Restore Works
@@ -3262,11 +3262,11 @@  discard block
 block discarded – undo
3262 3262
      */
3263 3263
     public function DBUTF8($str)
3264 3264
     {
3265
-		if (UTF8_CONVERT) {
3265
+        if (UTF8_CONVERT) {
3266 3266
             $str = utf8_encode($str);
3267 3267
         }
3268
-		return $str;
3269
-	}
3268
+        return $str;
3269
+    }
3270 3270
 
3271 3271
     /**
3272 3272
      * @param string $str
@@ -3277,8 +3277,8 @@  discard block
 block discarded – undo
3277 3277
         if (UTF8_CONVERT) {
3278 3278
             $str = utf8_encode($str);
3279 3279
         }
3280
-		return Database::escape_string($str);
3281
-	}
3280
+        return Database::escape_string($str);
3281
+    }
3282 3282
 
3283 3283
     /**
3284 3284
      * @param array $array
Please login to merge, or discard this patch.
main/exercice/fill_blanks.class.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -728,43 +728,43 @@  discard block
 block discarded – undo
728 728
     }
729 729
 
730 730
     /**
731
-    * Return an array of student state answers for fill the blank questions
732
-    * for each students that answered the question
733
-    * -2  : didn't answer
734
-    * -1  : student answer is wrong
735
-    *  0  : student answer is correct
736
-    * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
737
-    *
738
-    * @param integer $testId
739
-    * @param integer $questionId
740
-    * @param $studentsIdList
741
-    * @param string $startDate
742
-    * @param string $endDate
743
-    * @param bool $useLastAnswerredAttempt
744
-    * @return array
745
-    * (
746
-    *     [student_id] => Array
747
-    *         (
748
-    *             [first fill the blank for question] => -1
749
-    *             [second fill the blank for question] => 2
750
-    *             [third fill the blank for question] => -1
751
-    *         )
752
-    * )
753
-    */
731
+     * Return an array of student state answers for fill the blank questions
732
+     * for each students that answered the question
733
+     * -2  : didn't answer
734
+     * -1  : student answer is wrong
735
+     *  0  : student answer is correct
736
+     * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
737
+     *
738
+     * @param integer $testId
739
+     * @param integer $questionId
740
+     * @param $studentsIdList
741
+     * @param string $startDate
742
+     * @param string $endDate
743
+     * @param bool $useLastAnswerredAttempt
744
+     * @return array
745
+     * (
746
+     *     [student_id] => Array
747
+     *         (
748
+     *             [first fill the blank for question] => -1
749
+     *             [second fill the blank for question] => 2
750
+     *             [third fill the blank for question] => -1
751
+     *         )
752
+     * )
753
+     */
754 754
     public static function getFillTheBlankTabResult($testId, $questionId, $studentsIdList, $startDate, $endDate, $useLastAnswerredAttempt = true) {
755 755
 
756
-       $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
757
-       $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
758
-       $courseId = api_get_course_int_id();
756
+        $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
757
+        $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
758
+        $courseId = api_get_course_int_id();
759 759
 
760
-       require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php';
760
+        require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php';
761 761
 
762
-       // request to have all the answers of student for this question
763
-       // student may have doing it several time
764
-       // student may have not answered the bracket id, in this case, is result of the answer is empty
762
+        // request to have all the answers of student for this question
763
+        // student may have doing it several time
764
+        // student may have not answered the bracket id, in this case, is result of the answer is empty
765 765
 
766
-       // we got the less recent attempt first
767
-       $sql = '
766
+        // we got the less recent attempt first
767
+        $sql = '
768 768
            SELECT * FROM '.$tblTrackEAttempt.' tea
769 769
 
770 770
            LEFT JOIN '.$tblTrackEExercise.' tee
@@ -780,49 +780,49 @@  discard block
 block discarded – undo
780 780
            ORDER BY user_id, tea.exe_id;
781 781
        ';
782 782
 
783
-       $res = Database::query($sql);
784
-       $tabUserResult = array();
785
-       $bracketNumber = 0;
786
-       // foreach attempts for all students starting with his older attempt
787
-       while ($data = Database::fetch_array($res)) {
788
-           $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
783
+        $res = Database::query($sql);
784
+        $tabUserResult = array();
785
+        $bracketNumber = 0;
786
+        // foreach attempts for all students starting with his older attempt
787
+        while ($data = Database::fetch_array($res)) {
788
+            $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
789 789
 
790
-           // for each bracket to find in this question
791
-           foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
790
+            // for each bracket to find in this question
791
+            foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
792 792
 
793
-               if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
794
-                   // student has answered this bracket, cool
795
-                   switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
796
-                       case self::FILL_THE_BLANK_MENU :
793
+                if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
794
+                    // student has answered this bracket, cool
795
+                    switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
796
+                        case self::FILL_THE_BLANK_MENU :
797 797
                            // get the indice of the choosen answer in the menu
798 798
                            // we know that the right answer is the first entry of the menu, ie 0
799 799
                            // (remember, menu entries are shuffled when taking the test)
800 800
                            $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum($tabAnswer['tabwords'][$bracketNumber], $tabAnswer['studentanswer'][$bracketNumber]);
801
-                           break;
802
-                       default :
801
+                            break;
802
+                        default :
803 803
                            if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) {
804
-                               $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
805
-                           } else {
806
-                               $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
807
-                           }
808
-                   }
809
-               } else {
810
-                   // student didn't answer this bracket
811
-                   if ($useLastAnswerredAttempt) {
812
-                       // if we take into account the last answered attempt
813
-                       if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
814
-                           $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
815
-                       }
816
-                   } else {
817
-                       // we take the last attempt, even if the student answer the question before
818
-                       $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
819
-                   }
820
-               }
821
-           }
822
-
823
-
824
-       }
825
-       return $tabUserResult;
804
+                                $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
805
+                            } else {
806
+                                $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
807
+                            }
808
+                    }
809
+                } else {
810
+                    // student didn't answer this bracket
811
+                    if ($useLastAnswerredAttempt) {
812
+                        // if we take into account the last answered attempt
813
+                        if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
814
+                            $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
815
+                        }
816
+                    } else {
817
+                        // we take the last attempt, even if the student answer the question before
818
+                        $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
819
+                    }
820
+                }
821
+            }
822
+
823
+
824
+        }
825
+        return $tabUserResult;
826 826
     }
827 827
 
828 828
 
Please login to merge, or discard this patch.
main/exercice/TestCategory.php 1 patch
Indentation   +486 added lines, -486 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,210 +251,210 @@  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 integer 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 integer 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);
456
+        $nbquestionresult = 0;
457
+        $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
458 458
 
459 459
         foreach ($tabcatid as $category) {
460 460
             if (empty($category['id'])) {
@@ -470,30 +470,30 @@  discard block
 block discarded – undo
470 470
             }
471 471
         }
472 472
 
473
-		return $nbquestionresult;
474
-	}
473
+        return $nbquestionresult;
474
+    }
475 475
 
476
-	/**
477
-	 * Return an array (id=>name)
478
-	 * tabresult[0] = get_lang('NoCategory');
476
+    /**
477
+     * Return an array (id=>name)
478
+     * tabresult[0] = get_lang('NoCategory');
479 479
      *
480 480
      * @param int $courseId
481 481
      *
482 482
      * @return array
483
-	 *
484
-	 */
483
+     *
484
+     */
485 485
     public static function getCategoriesIdAndName($courseId = "")
486 486
     {
487
-		if (empty($courseId)) {
488
-			$courseId = api_get_course_int_id();
489
-		}
490
-	 	$tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
491
-	 	$tabresult = array("0"=>get_lang('NoCategorySelected'));
492
-	 	for ($i=0; $i < count($tabcatobject); $i++) {
493
-	 		$tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
494
-	 	}
495
-	 	return $tabresult;
496
-	}
487
+        if (empty($courseId)) {
488
+            $courseId = api_get_course_int_id();
489
+        }
490
+            $tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
491
+            $tabresult = array("0"=>get_lang('NoCategorySelected'));
492
+            for ($i=0; $i < count($tabcatobject); $i++) {
493
+                $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
494
+            }
495
+            return $tabresult;
496
+    }
497 497
 
498 498
     /**
499 499
      * Returns an array of question ids for each category
@@ -502,10 +502,10 @@  discard block
 block discarded – undo
502 502
      * @param int exercise
503 503
      * @param array $check_in_question_list
504 504
      * @param array $categoriesAddedInExercise
505
-    *
506
-    * @param int $exerciseId
507
-    * @return array
508
-    */
505
+     *
506
+     * @param int $exerciseId
507
+     * @return array
508
+     */
509 509
     static function getQuestionsByCat(
510 510
         $exerciseId,
511 511
         $check_in_question_list = array(),
@@ -583,28 +583,28 @@  discard block
 block discarded – undo
583 583
         }
584 584
 
585 585
         return $categories;
586
-	}
586
+    }
587 587
 
588
-	/**
589
-	 * return a tab of $in_number random elements of $in_tab
590
-	 */
588
+    /**
589
+     * return a tab of $in_number random elements of $in_tab
590
+     */
591 591
     public static function getNElementsFromArray($in_tab, $in_number)
592 592
     {
593
-		$tabres = $in_tab;
594
-		shuffle($tabres);
595
-		if ($in_number < count($tabres)) {
596
-			$tabres = array_slice($tabres, 0, $in_number);
597
-		}
598
-		return $tabres;
599
-	}
600
-
601
-	/**
602
-	 * display the category
603
-	 */
604
-	public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
593
+        $tabres = $in_tab;
594
+        shuffle($tabres);
595
+        if ($in_number < count($tabres)) {
596
+            $tabres = array_slice($tabres, 0, $in_number);
597
+        }
598
+        return $tabres;
599
+    }
600
+
601
+    /**
602
+     * display the category
603
+     */
604
+    public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
605 605
     {
606 606
         echo self::returnCategoryAndTitle($questionId, $in_display_category_name);
607
-	}
607
+    }
608 608
 
609 609
     /**
610 610
      * @param int $questionId
@@ -620,90 +620,90 @@  discard block
 block discarded – undo
620 620
             $in_display_category_name = $objExercise->display_category_name;
621 621
         }
622 622
         $content = null;
623
-		if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
623
+        if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
624 624
             $content .= '<div class="page-header">';
625 625
             $content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($questionId).'</h4>';
626 626
             $content .= "</div>";
627
-		}
627
+        }
628 628
         return $content;
629
-	}
629
+    }
630 630
 
631 631
     /**
632
-    * Display signs [+] and/or (>0) after question title if question has options
633
-    * scoreAlwaysPositive and/or uncheckedMayScore
634
-    */
632
+     * Display signs [+] and/or (>0) after question title if question has options
633
+     * scoreAlwaysPositive and/or uncheckedMayScore
634
+     */
635 635
     public function displayQuestionOption($in_objQuestion)
636 636
     {
637
-		if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) {
638
-			echo "<span style='font-size:75%'> (>0)</span>";
639
-		}
640
-		if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) {
641
-			echo "<span style='font-size:75%'> [+]</span>";
642
-		}
643
-	}
644
-
645
-	/**
646
-	 * sortTabByBracketLabel ($tabCategoryQuestions)
647
-	 * key of $tabCategoryQuestions are the category id (0 for not in a category)
648
-	 * value is the array of question id of this category
649
-	 * Sort question by Category
650
-	*/
637
+        if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) {
638
+            echo "<span style='font-size:75%'> (>0)</span>";
639
+        }
640
+        if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) {
641
+            echo "<span style='font-size:75%'> [+]</span>";
642
+        }
643
+    }
644
+
645
+    /**
646
+     * sortTabByBracketLabel ($tabCategoryQuestions)
647
+     * key of $tabCategoryQuestions are the category id (0 for not in a category)
648
+     * value is the array of question id of this category
649
+     * Sort question by Category
650
+     */
651 651
     public static function sortTabByBracketLabel($in_tab)
652 652
     {
653
-		$tabResult = array();
654
-		$tabCatName = array();	// tab of category name
655
-		while (list($cat_id, $tabquestion) = each($in_tab)) {
656
-			$catTitle = new TestCategory($cat_id);
657
-			$tabCatName[$cat_id] = $catTitle->name;
658
-		}
659
-		reset($in_tab);
660
-		// sort table by value, keeping keys as they are
661
-		asort($tabCatName);
662
-		// keys of $tabCatName are keys order for $in_tab
663
-		while (list($key, $val) = each($tabCatName)) {
664
-			$tabResult[$key] = $in_tab[$key];
665
-		}
666
-		return $tabResult;
667
-	}
653
+        $tabResult = array();
654
+        $tabCatName = array();	// tab of category name
655
+        while (list($cat_id, $tabquestion) = each($in_tab)) {
656
+            $catTitle = new TestCategory($cat_id);
657
+            $tabCatName[$cat_id] = $catTitle->name;
658
+        }
659
+        reset($in_tab);
660
+        // sort table by value, keeping keys as they are
661
+        asort($tabCatName);
662
+        // keys of $tabCatName are keys order for $in_tab
663
+        while (list($key, $val) = each($tabCatName)) {
664
+            $tabResult[$key] = $in_tab[$key];
665
+        }
666
+        return $tabResult;
667
+    }
668 668
 
669 669
     /**
670
-	 * return total score for test exe_id for all question in the category $in_cat_id for user
671
-	 * If no question for this category, return ""
672
-	 */
673
-	public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
674
-	{
675
-		$tbl_track_attempt		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
676
-		$tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
677
-		$in_cat_id = intval($in_cat_id);
678
-		$in_exe_id = intval($in_exe_id);
679
-		$in_user_id = intval($in_user_id);
680
-
681
-		$query = "SELECT DISTINCT
670
+     * return total score for test exe_id for all question in the category $in_cat_id for user
671
+     * If no question for this category, return ""
672
+     */
673
+    public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
674
+    {
675
+        $tbl_track_attempt		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
676
+        $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
677
+        $in_cat_id = intval($in_cat_id);
678
+        $in_exe_id = intval($in_exe_id);
679
+        $in_user_id = intval($in_user_id);
680
+
681
+        $query = "SELECT DISTINCT
682 682
 		            marks, exe_id, user_id, ta.question_id, category_id
683 683
                   FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc
684 684
                   WHERE
685 685
                     ta.question_id=qrc.question_id AND
686 686
                     qrc.category_id=$in_cat_id AND
687 687
                     exe_id=$in_exe_id AND user_id=$in_user_id";
688
-		$res = Database::query($query);
689
-		$totalcatscore = "";
690
-		while ($data = Database::fetch_array($res)) {
691
-			$totalcatscore += $data['marks'];
692
-		}
693
-		return $totalcatscore;
694
-	}
695
-
696
-	/**
688
+        $res = Database::query($query);
689
+        $totalcatscore = "";
690
+        while ($data = Database::fetch_array($res)) {
691
+            $totalcatscore += $data['marks'];
692
+        }
693
+        return $totalcatscore;
694
+    }
695
+
696
+    /**
697 697
      * return the number max of question in a category
698 698
      * count the number of questions in all categories, and return the max
699 699
      * @param int $exerciseId
700 700
      * @author - hubert borderiou
701
-    */
701
+     */
702 702
     public static function getNumberMaxQuestionByCat($exerciseId)
703 703
     {
704 704
         $res_num_max = 0;
705 705
         // foreach question
706
-		$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
706
+        $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
707 707
 
708 708
         foreach ($tabcatid as $category) {
709 709
             if (empty($category['id'])) {
@@ -775,34 +775,34 @@  discard block
 block discarded – undo
775 775
     }
776 776
 
777 777
     /**
778
-	 * @return array
779
-	 */
780
-	function get_all_categories()
781
-	{
782
-		$table = Database::get_course_table(TABLE_QUIZ_CATEGORY);
783
-		$sql = "SELECT * FROM $table ORDER BY title ASC";
784
-		$res = Database::query($sql);
785
-		while ($row = Database::fetch_array($res,'ASSOC')) {
786
-			$array[] = $row;
787
-		}
788
-		return $array;
789
-	}
790
-
791
-	/**
792
-	 * @param Exercise $exercise
793
-	 * @param int $course_id
794
-	 * @param string $order
795
-	 * @param bool $shuffle
796
-	 * @param bool $excludeCategoryWithNoQuestions
797
-	 * @return array|bool
798
-	 */
799
-	public function getCategoryExerciseTree(
800
-		$exercise,
801
-		$course_id,
802
-		$order = null,
803
-		$shuffle = false,
804
-		$excludeCategoryWithNoQuestions = true
805
-	) {
778
+     * @return array
779
+     */
780
+    function get_all_categories()
781
+    {
782
+        $table = Database::get_course_table(TABLE_QUIZ_CATEGORY);
783
+        $sql = "SELECT * FROM $table ORDER BY title ASC";
784
+        $res = Database::query($sql);
785
+        while ($row = Database::fetch_array($res,'ASSOC')) {
786
+            $array[] = $row;
787
+        }
788
+        return $array;
789
+    }
790
+
791
+    /**
792
+     * @param Exercise $exercise
793
+     * @param int $course_id
794
+     * @param string $order
795
+     * @param bool $shuffle
796
+     * @param bool $excludeCategoryWithNoQuestions
797
+     * @return array|bool
798
+     */
799
+    public function getCategoryExerciseTree(
800
+        $exercise,
801
+        $course_id,
802
+        $order = null,
803
+        $shuffle = false,
804
+        $excludeCategoryWithNoQuestions = true
805
+    ) {
806 806
         if (empty($exercise)) {
807 807
             return array();
808 808
         }
@@ -812,165 +812,165 @@  discard block
 block discarded – undo
812 812
         }
813 813
 
814 814
         $course_id = intval($course_id);
815
-		$table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
815
+        $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
816 816
         $categoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
817
-		$sql = "SELECT * FROM $table qc
817
+        $sql = "SELECT * FROM $table qc
818 818
               	LEFT JOIN $categoryTable c
819 819
                 ON (qc.c_id = c.c_id AND c.id = qc.category_id)
820 820
                 WHERE qc.c_id = $course_id AND exercise_id = {$exercise->id} ";
821 821
 
822
-		if (!empty($order)) {
823
-			$sql .= "ORDER BY $order";
824
-		}
825
-
826
-		$categories = array();
827
-
828
-		$result = Database::query($sql);
829
-		if (Database::num_rows($result)) {
830
-			while ($row = Database::fetch_array($result, 'ASSOC')) {
831
-				if ($excludeCategoryWithNoQuestions) {
832
-					if ($row['count_questions'] == 0) {
833
-						continue;
834
-					}
835
-				}
836
-				if (empty($row['title']) && empty($row['category_id'])) {
837
-					$row['title'] = get_lang('NoCategory');
838
-				}
822
+        if (!empty($order)) {
823
+            $sql .= "ORDER BY $order";
824
+        }
825
+
826
+        $categories = array();
827
+
828
+        $result = Database::query($sql);
829
+        if (Database::num_rows($result)) {
830
+            while ($row = Database::fetch_array($result, 'ASSOC')) {
831
+                if ($excludeCategoryWithNoQuestions) {
832
+                    if ($row['count_questions'] == 0) {
833
+                        continue;
834
+                    }
835
+                }
836
+                if (empty($row['title']) && empty($row['category_id'])) {
837
+                    $row['title'] = get_lang('NoCategory');
838
+                }
839 839
                 $categories[$row['category_id']] = $row;
840
-			}
841
-		}
842
-
843
-		if ($shuffle) {
844
-			shuffle_assoc($categories);
845
-		}
846
-
847
-		return $categories;
848
-	}
849
-
850
-	public function getForm(& $form, $action = 'new')
851
-	{
852
-		switch($action) {
853
-			case 'new':
854
-				$header = get_lang('AddACategory');
855
-				$submit = get_lang('AddTestCategory');
856
-				break;
857
-			case 'edit':
858
-				$header = get_lang('EditCategory');
859
-				$submit = get_lang('ModifyCategory');
860
-				break;
861
-		}
862
-
863
-		// settting the form elements
864
-		$form->addElement('header', $header);
865
-		$form->addElement('hidden', 'category_id');
866
-		$form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
867
-		$form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
868
-		$category_parent_list = array();
869
-
870
-		$options = array(
871
-				'1' => get_lang('Visible'),
872
-				'0' => get_lang('Hidden')
873
-		);
874
-		$form->addElement('select', 'visibility', get_lang('Visibility'), $options);
875
-		$script = null;
876
-		if (!empty($this->parent_id)) {
877
-			$parent_cat = new TestCategory($this->parent_id);
878
-			$category_parent_list = array($parent_cat->id => $parent_cat->name);
879
-			$script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>';
880
-		}
881
-		$form->addElement('html', $script);
882
-
883
-		$form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id'));
884
-		$form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"');
885
-
886
-		// setting the defaults
887
-		$defaults = array();
888
-		$defaults["category_id"] = $this->id;
889
-		$defaults["category_name"] = $this->name;
890
-		$defaults["category_description"] = $this->description;
891
-		$defaults["parent_id"] = $this->parent_id;
892
-		$defaults["visibility"] = $this->visibility;
893
-		$form->setDefaults($defaults);
894
-
895
-		// setting the rules
896
-		$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
897
-	}
898
-
899
-	/**
900
-	 * Returns the category form.
901
-	 * @param Exercise $exercise_obj
902
-	 * @return string
903
-	 */
904
-	public function returnCategoryForm(Exercise $exercise_obj)
905
-	{
906
-		$categories = $this->getListOfCategoriesForTest($exercise_obj);
907
-
908
-		$saved_categories = $exercise_obj->get_categories_in_exercise();
909
-		$return = null;
910
-
911
-		if (!empty($categories)) {
912
-			$nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory();
913
-			$exercise_obj->setCategoriesGrouping(true);
914
-			$real_question_count = count($exercise_obj->getQuestionList());
915
-
916
-			$warning = null;
917
-			if ($nbQuestionsTotal != $real_question_count) {
918
-				$warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning');
919
-			}
920
-
921
-			$return .= $warning;
922
-			$return .= '<table class="data_table">';
923
-			$return .= '<tr>';
924
-			$return .= '<th height="24">' . get_lang('Categories') . '</th>';
925
-			$return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>';
926
-
927
-			$emptyCategory = array(
928
-				'id' => '0',
929
-				'name' => get_lang('NoCategory'),
930
-				'description' => '',
931
-				'iid' => '0',
932
-				'title' => get_lang('NoCategory')
933
-			);
934
-
935
-			$categories[] = $emptyCategory;
936
-
937
-			foreach ($categories as $category) {
938
-				$cat_id = $category['iid'];
939
-				$return .= '<tr>';
940
-				$return .= '<td>';
941
-				//$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : '');
942
-				$return .= Display::div($category['name']);
943
-				$return .= '</td>';
944
-				$return .= '<td>';
945
-				$value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1;
946
-				$return .= '<input name="category['.$cat_id.']" value="' .$value.'" />';
947
-				$return .= '</td>';
948
-				$return .= '</tr>';
949
-			}
950
-
951
-			$return .= '</table>';
952
-			$return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected');
953
-			return $return;
954
-		}
955
-	}
956
-
957
-	/**
958
-	 * Sorts an array
959
-	 * @param $array
960
-	 * @return mixed
961
-	 */
962
-	public function sort_tree_array($array)
963
-	{
964
-		foreach ($array as $key => $row) {
965
-			$parent[$key] = $row['parent_id'];
966
-		}
967
-		if (count($array) > 0) {
968
-			array_multisort($parent, SORT_ASC, $array);
969
-		}
970
-		return $array;
971
-	}
972
-
973
-	/**
840
+            }
841
+        }
842
+
843
+        if ($shuffle) {
844
+            shuffle_assoc($categories);
845
+        }
846
+
847
+        return $categories;
848
+    }
849
+
850
+    public function getForm(& $form, $action = 'new')
851
+    {
852
+        switch($action) {
853
+            case 'new':
854
+                $header = get_lang('AddACategory');
855
+                $submit = get_lang('AddTestCategory');
856
+                break;
857
+            case 'edit':
858
+                $header = get_lang('EditCategory');
859
+                $submit = get_lang('ModifyCategory');
860
+                break;
861
+        }
862
+
863
+        // settting the form elements
864
+        $form->addElement('header', $header);
865
+        $form->addElement('hidden', 'category_id');
866
+        $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
867
+        $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
868
+        $category_parent_list = array();
869
+
870
+        $options = array(
871
+                '1' => get_lang('Visible'),
872
+                '0' => get_lang('Hidden')
873
+        );
874
+        $form->addElement('select', 'visibility', get_lang('Visibility'), $options);
875
+        $script = null;
876
+        if (!empty($this->parent_id)) {
877
+            $parent_cat = new TestCategory($this->parent_id);
878
+            $category_parent_list = array($parent_cat->id => $parent_cat->name);
879
+            $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>';
880
+        }
881
+        $form->addElement('html', $script);
882
+
883
+        $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id'));
884
+        $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"');
885
+
886
+        // setting the defaults
887
+        $defaults = array();
888
+        $defaults["category_id"] = $this->id;
889
+        $defaults["category_name"] = $this->name;
890
+        $defaults["category_description"] = $this->description;
891
+        $defaults["parent_id"] = $this->parent_id;
892
+        $defaults["visibility"] = $this->visibility;
893
+        $form->setDefaults($defaults);
894
+
895
+        // setting the rules
896
+        $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
897
+    }
898
+
899
+    /**
900
+     * Returns the category form.
901
+     * @param Exercise $exercise_obj
902
+     * @return string
903
+     */
904
+    public function returnCategoryForm(Exercise $exercise_obj)
905
+    {
906
+        $categories = $this->getListOfCategoriesForTest($exercise_obj);
907
+
908
+        $saved_categories = $exercise_obj->get_categories_in_exercise();
909
+        $return = null;
910
+
911
+        if (!empty($categories)) {
912
+            $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory();
913
+            $exercise_obj->setCategoriesGrouping(true);
914
+            $real_question_count = count($exercise_obj->getQuestionList());
915
+
916
+            $warning = null;
917
+            if ($nbQuestionsTotal != $real_question_count) {
918
+                $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning');
919
+            }
920
+
921
+            $return .= $warning;
922
+            $return .= '<table class="data_table">';
923
+            $return .= '<tr>';
924
+            $return .= '<th height="24">' . get_lang('Categories') . '</th>';
925
+            $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>';
926
+
927
+            $emptyCategory = array(
928
+                'id' => '0',
929
+                'name' => get_lang('NoCategory'),
930
+                'description' => '',
931
+                'iid' => '0',
932
+                'title' => get_lang('NoCategory')
933
+            );
934
+
935
+            $categories[] = $emptyCategory;
936
+
937
+            foreach ($categories as $category) {
938
+                $cat_id = $category['iid'];
939
+                $return .= '<tr>';
940
+                $return .= '<td>';
941
+                //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : '');
942
+                $return .= Display::div($category['name']);
943
+                $return .= '</td>';
944
+                $return .= '<td>';
945
+                $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1;
946
+                $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />';
947
+                $return .= '</td>';
948
+                $return .= '</tr>';
949
+            }
950
+
951
+            $return .= '</table>';
952
+            $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected');
953
+            return $return;
954
+        }
955
+    }
956
+
957
+    /**
958
+     * Sorts an array
959
+     * @param $array
960
+     * @return mixed
961
+     */
962
+    public function sort_tree_array($array)
963
+    {
964
+        foreach ($array as $key => $row) {
965
+            $parent[$key] = $row['parent_id'];
966
+        }
967
+        if (count($array) > 0) {
968
+            array_multisort($parent, SORT_ASC, $array);
969
+        }
970
+        return $array;
971
+    }
972
+
973
+    /**
974 974
      * Return true if a category already exists with the same name
975 975
      * @param string $in_name
976 976
      *
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
      * @param int $categoryId
1017 1017
      * @param int $questionId
1018 1018
      * @param int $courseId
1019
-	 *
1020
-	 * @return string|false
1019
+     *
1020
+     * @return string|false
1021 1021
      */
1022 1022
     public static function add_category_for_question_id($categoryId, $questionId, $courseId)
1023 1023
     {
@@ -1025,18 +1025,18 @@  discard block
 block discarded – undo
1025 1025
         // if question doesn't have a category
1026 1026
         // @todo change for 1.10 when a question can have several categories
1027 1027
         if (TestCategory::getCategoryForQuestion($questionId, $courseId) == 0 &&
1028
-			$questionId > 0 &&
1029
-			$courseId > 0
1028
+            $questionId > 0 &&
1029
+            $courseId > 0
1030 1030
         ) {
1031 1031
             $sql = "INSERT INTO $table (c_id, question_id, category_id)
1032 1032
                     VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")";
1033 1033
             Database::query($sql);
1034
-			$id = Database::insert_id();
1034
+            $id = Database::insert_id();
1035 1035
 
1036
-			return $id;
1036
+            return $id;
1037 1037
         }
1038 1038
 
1039
-		return false;
1039
+        return false;
1040 1040
     }
1041 1041
 
1042 1042
     /**
Please login to merge, or discard this patch.
main/dropbox/dropbox_class.inc.php 1 patch
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
         }
78 78
     }
79 79
 
80
-	/**
81
-	 * private function creating a new work object
82
-	 *
83
-	 * @param int $uploader_id
84
-	 * @param string $title
85
-	 * @param string $description
86
-	 * @param string $author
87
-	 * @param string $filename
88
-	 * @param int $filesize
89
-	 *
90
-	 * @todo 	$author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
91
-	 * 			As a consequence this parameter can be removed
92
-	 */
93
-	public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
80
+    /**
81
+     * private function creating a new work object
82
+     *
83
+     * @param int $uploader_id
84
+     * @param string $title
85
+     * @param string $description
86
+     * @param string $author
87
+     * @param string $filename
88
+     * @param int $filesize
89
+     *
90
+     * @todo 	$author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
91
+     * 			As a consequence this parameter can be removed
92
+     */
93
+    public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
94 94
     {
95 95
         $dropbox_cnf = getDropboxConf();
96 96
 
@@ -108,17 +108,17 @@  discard block
 block discarded – undo
108 108
         // Check if object exists already. If it does, the old object is used
109 109
         // with updated information (authors, description, upload_date)
110 110
         $this->isOldWork = false;
111
-		$sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']."
111
+        $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']."
112 112
 				WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'";
113 113
         $result = Database::query($sql);
114
-		$res = Database::fetch_array($result);
115
-		if ($res) {
116
-			$this->isOldWork = true;
117
-		}
118
-		// Insert or update the dropbox_file table and set the id property
119
-		if ($this->isOldWork) {
120
-			$this->id = $res['id'];
121
-			$this->upload_date = $res['upload_date'];
114
+        $res = Database::fetch_array($result);
115
+        if ($res) {
116
+            $this->isOldWork = true;
117
+        }
118
+        // Insert or update the dropbox_file table and set the id property
119
+        if ($this->isOldWork) {
120
+            $this->id = $res['id'];
121
+            $this->upload_date = $res['upload_date'];
122 122
 
123 123
             $params = [
124 124
                 'filesize' => $this->filesize,
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
                 ['c_id = ? AND id = ?' => [$course_id, $this->id]]
136 136
             );
137 137
 
138
-		} else {
139
-			$this->upload_date = $this->last_upload_date;
140
-			$params = [
138
+        } else {
139
+            $this->upload_date = $this->last_upload_date;
140
+            $params = [
141 141
                 'c_id' => $course_id,
142 142
                 'uploader_id' => $this->uploader_id,
143 143
                 'filename' => $this->filename,
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
                 'last_upload_date' => $this->last_upload_date,
150 150
                 'session_id' => api_get_session_id(),
151 151
                 'cat_id' => 0
152
-			];
152
+            ];
153 153
 
154
-			$this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
155
-			if ($this->id) {
156
-				$sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
157
-				Database::query($sql);
158
-			}
159
-		}
154
+            $this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
155
+            if ($this->id) {
156
+                $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
157
+                Database::query($sql);
158
+            }
159
+        }
160 160
 
161 161
         $sql = "SELECT count(file_id) as count
162 162
         		FROM ".$dropbox_cnf['tbl_person']."
@@ -170,16 +170,16 @@  discard block
 block discarded – undo
170 170
                     VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")";
171 171
             Database::query($sql);
172 172
         }
173
-	}
174
-
175
-	/**
176
-	 * private function creating existing object by retreiving info from db
177
-	 *
178
-	 * @param int $id
179
-	 */
180
-	public function _createExistingWork($id)
173
+    }
174
+
175
+    /**
176
+     * private function creating existing object by retreiving info from db
177
+     *
178
+     * @param int $id
179
+     */
180
+    public function _createExistingWork($id)
181 181
     {
182
-	    $course_id = api_get_course_int_id();
182
+        $course_id = api_get_course_int_id();
183 183
         $dropbox_cnf = getDropboxConf();
184 184
 
185 185
         $action = isset($_GET['action']) ? $_GET['action'] : null;
@@ -229,52 +229,52 @@  discard block
 block discarded – undo
229 229
             }
230 230
             $this->feedback2= $feedback2;
231 231
         }
232
-	}
232
+    }
233 233
 }
234 234
 
235 235
 class Dropbox_SentWork extends Dropbox_Work
236 236
 {
237
-	public $recipients;	//array of ['id']['name'] arrays
238
-
239
-	/**
240
-	 * Constructor calls private functions to create a new work or retreive an existing work from DB
241
-	 * depending on the number of parameters
242
-	 *
243
-	 * @param unknown_type $arg1
244
-	 * @param unknown_type $arg2
245
-	 * @param unknown_type $arg3
246
-	 * @param unknown_type $arg4
247
-	 * @param unknown_type $arg5
248
-	 * @param unknown_type $arg6
249
-	 * @param unknown_type $arg7
250
-	 * @return Dropbox_SentWork
251
-	 */
252
-	public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
237
+    public $recipients;	//array of ['id']['name'] arrays
238
+
239
+    /**
240
+     * Constructor calls private functions to create a new work or retreive an existing work from DB
241
+     * depending on the number of parameters
242
+     *
243
+     * @param unknown_type $arg1
244
+     * @param unknown_type $arg2
245
+     * @param unknown_type $arg3
246
+     * @param unknown_type $arg4
247
+     * @param unknown_type $arg5
248
+     * @param unknown_type $arg6
249
+     * @param unknown_type $arg7
250
+     * @return Dropbox_SentWork
251
+     */
252
+    public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
253 253
     {
254
-		if (func_num_args() > 1) {
255
-		    $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
256
-		} else {
257
-			$this->_createExistingSentWork($arg1);
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * private function creating a new SentWork object
263
-	 *
264
-	 * @param int $uploader_id
265
-	 * @param string $title
266
-	 * @param string $description
267
-	 * @param string $author
268
-	 * @param string $filename
269
-	 * @param int $filesize
270
-	 * @param array $recipient_ids
271
-	 */
272
-	public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
254
+        if (func_num_args() > 1) {
255
+            $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
256
+        } else {
257
+            $this->_createExistingSentWork($arg1);
258
+        }
259
+    }
260
+
261
+    /**
262
+     * private function creating a new SentWork object
263
+     *
264
+     * @param int $uploader_id
265
+     * @param string $title
266
+     * @param string $description
267
+     * @param string $author
268
+     * @param string $filename
269
+     * @param int $filesize
270
+     * @param array $recipient_ids
271
+     */
272
+    public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
273 273
     {
274 274
         $dropbox_cnf = getDropboxConf();
275 275
         $_course = api_get_course_info();
276 276
 
277
-		// Call constructor of Dropbox_Work object
277
+        // Call constructor of Dropbox_Work object
278 278
         parent::__construct(
279 279
             $uploader_id,
280 280
             $title,
@@ -284,31 +284,31 @@  discard block
 block discarded – undo
284 284
             $filesize
285 285
         );
286 286
 
287
-		$course_id = api_get_course_int_id();
288
-
289
-		// Do sanity checks on recipient_ids array & property fillin
290
-		// The sanity check for ex-coursemembers is already done in base constructor
291
-		settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type
287
+        $course_id = api_get_course_int_id();
292 288
 
293
-		$justSubmit = false;
294
-		if ( is_int($recipient_ids)) {
295
-			$justSubmit = true;
296
-			$recipient_ids = array($recipient_ids + $this->id);
297
-		} elseif ( count($recipient_ids) == 0) {
298
-			$justSubmit = true;
299
-			$recipient_ids = array($uploader_id);
300
-		}
289
+        // Do sanity checks on recipient_ids array & property fillin
290
+        // The sanity check for ex-coursemembers is already done in base constructor
291
+        settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type
292
+
293
+        $justSubmit = false;
294
+        if ( is_int($recipient_ids)) {
295
+            $justSubmit = true;
296
+            $recipient_ids = array($recipient_ids + $this->id);
297
+        } elseif ( count($recipient_ids) == 0) {
298
+            $justSubmit = true;
299
+            $recipient_ids = array($uploader_id);
300
+        }
301 301
 
302
-		if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
303
-			die(get_lang('GeneralError').' (code 209)');
304
-		}
302
+        if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
303
+            die(get_lang('GeneralError').' (code 209)');
304
+        }
305 305
 
306
-		foreach ($recipient_ids as $rec) {
307
-			if (empty($rec)) die(get_lang('GeneralError').' (code 210)');
308
-			//if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
309
-				//this check is done when validating submitted data
310
-			$this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec));
311
-		}
306
+        foreach ($recipient_ids as $rec) {
307
+            if (empty($rec)) die(get_lang('GeneralError').' (code 210)');
308
+            //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
309
+                //this check is done when validating submitted data
310
+            $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec));
311
+        }
312 312
 
313 313
         $table_post = $dropbox_cnf['tbl_post'];
314 314
         $table_person = $dropbox_cnf['tbl_person'];
@@ -317,13 +317,13 @@  discard block
 block discarded – undo
317 317
         $user  = api_get_user_id();
318 318
         $now = api_get_utc_datetime();
319 319
 
320
-		// Insert data in dropbox_post and dropbox_person table for each recipient
321
-		foreach ($this->recipients as $rec) {
320
+        // Insert data in dropbox_post and dropbox_person table for each recipient
321
+        foreach ($this->recipients as $rec) {
322 322
             $file_id = (int)$this->id;
323 323
             $user_id = (int)$rec['id'];
324
-			$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
324
+            $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
325 325
                     VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)";
326
-	        Database::query($sql);
326
+            Database::query($sql);
327 327
             // If work already exists no error is generated
328 328
 
329 329
             /**
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
                 }
341 341
             }
342 342
 
343
-			// Update item_property table for each recipient
344
-			if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
345
-			    $ownerid = getUserOwningThisMailing($ownerid);
346
-			}
347
-			if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
348
-			    $recipid = $ownerid;  // mailing file recipient = mailing id, not a person
349
-			}
343
+            // Update item_property table for each recipient
344
+            if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
345
+                $ownerid = getUserOwningThisMailing($ownerid);
346
+            }
347
+            if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
348
+                $recipid = $ownerid;  // mailing file recipient = mailing id, not a person
349
+            }
350 350
             api_item_property_update(
351 351
                 $_course,
352 352
                 TOOL_DROPBOX,
@@ -356,92 +356,92 @@  discard block
 block discarded – undo
356 356
                 null,
357 357
                 $recipid
358 358
             );
359
-		}
360
-	}
361
-
362
-	/**
363
-	 * private function creating existing object by retreiving info from db
364
-	 *
365
-	 * @param unknown_type $id
366
-	 */
367
-	public function _createExistingSentWork($id)
359
+        }
360
+    }
361
+
362
+    /**
363
+     * private function creating existing object by retreiving info from db
364
+     *
365
+     * @param unknown_type $id
366
+     */
367
+    public function _createExistingSentWork($id)
368 368
     {
369 369
         $dropbox_cnf = getDropboxConf();
370 370
         $id = intval($id);
371 371
 
372
-		$course_id = api_get_course_int_id();
372
+        $course_id = api_get_course_int_id();
373 373
 
374
-		// Call constructor of Dropbox_Work object
375
-		parent::__construct($id);
374
+        // Call constructor of Dropbox_Work object
375
+        parent::__construct($id);
376 376
 
377
-		// Fill in recipients array
378
-		$this->recipients = array();
379
-		$sql = "SELECT dest_user_id, feedback_date, feedback
377
+        // Fill in recipients array
378
+        $this->recipients = array();
379
+        $sql = "SELECT dest_user_id, feedback_date, feedback
380 380
 				FROM ".$dropbox_cnf['tbl_post']."
381 381
 				WHERE c_id = $course_id AND file_id = ".intval($id)."";
382 382
         $result = Database::query($sql);
383
-		while ($res = Database::fetch_array($result, 'ASSOC')) {
384
-
385
-			// Check for deleted users
386
-			$dest_user_id = $res['dest_user_id'];
387
-			$user_info = api_get_user_info($dest_user_id);
388
-			//$this->category = $res['cat_id'];
389
-			if (!$user_info) {
390
-				$this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
391
-			} else {
392
-				$this->recipients[] = array(
383
+        while ($res = Database::fetch_array($result, 'ASSOC')) {
384
+
385
+            // Check for deleted users
386
+            $dest_user_id = $res['dest_user_id'];
387
+            $user_info = api_get_user_info($dest_user_id);
388
+            //$this->category = $res['cat_id'];
389
+            if (!$user_info) {
390
+                $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
391
+            } else {
392
+                $this->recipients[] = array(
393 393
                     'id' => $dest_user_id,
394 394
                     'name' => $user_info['complete_name'],
395 395
                     'user_id' => $dest_user_id,
396
-				    'feedback_date' => $res['feedback_date'],
396
+                    'feedback_date' => $res['feedback_date'],
397 397
                     'feedback' => $res['feedback']
398 398
                 );
399
-			}
400
-		}
401
-	}
399
+            }
400
+        }
401
+    }
402 402
 }
403 403
 
404 404
 class Dropbox_Person
405 405
 {
406
-	// The receivedWork and the sentWork arrays are sorted.
407
-	public $receivedWork;	// an array of Dropbox_Work objects
408
-	public $sentWork;		// an array of Dropbox_SentWork objects
409
-
410
-	public $userId = 0;
411
-	public $isCourseAdmin = false;
412
-	public $isCourseTutor = false;
413
-	public $_orderBy = '';	// private property that determines by which field
414
-
415
-	/**
416
-	 * Constructor for recreating the Dropbox_Person object
417
-	 *
418
-	 * @param int $userId
419
-	 * @param bool $isCourseAdmin
420
-	 * @param bool $isCourseTutor
421
-	 * @return Dropbox_Person
422
-	 */
423
-	public function __construct($userId, $isCourseAdmin, $isCourseTutor)
406
+    // The receivedWork and the sentWork arrays are sorted.
407
+    public $receivedWork;	// an array of Dropbox_Work objects
408
+    public $sentWork;		// an array of Dropbox_SentWork objects
409
+
410
+    public $userId = 0;
411
+    public $isCourseAdmin = false;
412
+    public $isCourseTutor = false;
413
+    public $_orderBy = '';	// private property that determines by which field
414
+
415
+    /**
416
+     * Constructor for recreating the Dropbox_Person object
417
+     *
418
+     * @param int $userId
419
+     * @param bool $isCourseAdmin
420
+     * @param bool $isCourseTutor
421
+     * @return Dropbox_Person
422
+     */
423
+    public function __construct($userId, $isCourseAdmin, $isCourseTutor)
424 424
     {
425
-	    $course_id = api_get_course_int_id();
425
+        $course_id = api_get_course_int_id();
426 426
 
427
-		// Fill in properties
427
+        // Fill in properties
428 428
         $this->userId = $userId;
429 429
         $this->isCourseAdmin = $isCourseAdmin;
430 430
         $this->isCourseTutor = $isCourseTutor;
431 431
         $this->receivedWork = array();
432 432
         $this->sentWork = array();
433 433
 
434
-		// Note: perhaps include an ex coursemember check to delete old files
434
+        // Note: perhaps include an ex coursemember check to delete old files
435 435
 
436
-		$session_id = api_get_session_id();
437
-		$condition_session = api_get_session_condition($session_id);
436
+        $session_id = api_get_session_id();
437
+        $condition_session = api_get_session_condition($session_id);
438 438
 
439
-		$post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
440
-		$person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
441
-		$file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
439
+        $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
440
+        $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
441
+        $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
442 442
 
443 443
         // Find all entries where this person is the recipient
444
-		$sql = "SELECT DISTINCT r.file_id, r.cat_id
444
+        $sql = "SELECT DISTINCT r.file_id, r.cat_id
445 445
                 FROM $post_tbl r
446 446
                 INNER JOIN $person_tbl p
447 447
                     ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id )
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
                      r.dest_user_id = ".intval($this->userId)." $condition_session ";
451 451
 
452 452
         $result = Database::query($sql);
453
-		while ($res = Database::fetch_array($result)) {
454
-			$temp = new Dropbox_Work($res['file_id']);
455
-			$temp->category = $res['cat_id'];
456
-			$this->receivedWork[] = $temp;
457
-		}
458
-		// Find all entries where this person is the sender/uploader
453
+        while ($res = Database::fetch_array($result)) {
454
+            $temp = new Dropbox_Work($res['file_id']);
455
+            $temp->category = $res['cat_id'];
456
+            $this->receivedWork[] = $temp;
457
+        }
458
+        // Find all entries where this person is the sender/uploader
459 459
         $sql = "SELECT DISTINCT f.id
460 460
 				FROM $file_tbl f
461 461
 				INNER JOIN $person_tbl p
@@ -466,261 +466,261 @@  discard block
 block discarded – undo
466 466
                     $condition_session
467 467
                 ";
468 468
         $result = Database::query($sql);
469
-		while ($res = Database::fetch_array($result)) {
470
-			$this->sentWork[] = new Dropbox_SentWork($res['id']);
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * This private method is used by the usort function in  the
476
-	 * orderSentWork and orderReceivedWork methods.
477
-	 * It compares 2 work-objects by 1 of the properties of that object, dictated by the
478
-	 * private property _orderBy
479
-	 *
480
-	 * @param unknown_type $a
481
-	 * @param unknown_type $b
482
-	 * @return -1, 0 or 1 dependent of the result of the comparison.
483
-	 */
484
-	function _cmpWork($a, $b)
469
+        while ($res = Database::fetch_array($result)) {
470
+            $this->sentWork[] = new Dropbox_SentWork($res['id']);
471
+        }
472
+    }
473
+
474
+    /**
475
+     * This private method is used by the usort function in  the
476
+     * orderSentWork and orderReceivedWork methods.
477
+     * It compares 2 work-objects by 1 of the properties of that object, dictated by the
478
+     * private property _orderBy
479
+     *
480
+     * @param unknown_type $a
481
+     * @param unknown_type $b
482
+     * @return -1, 0 or 1 dependent of the result of the comparison.
483
+     */
484
+    function _cmpWork($a, $b)
485 485
     {
486
-		$sort = $this->_orderBy;
487
-		$aval = $a->$sort;
488
-		$bval = $b->$sort;
489
-		if ($sort == 'recipients') {
490
-		    // The recipients property is an array so we do the comparison based
491
-		    // on the first item of the recipients array
492
-		    $aval = $aval[0]['name'];
493
-			$bval = $bval[0]['name'];
494
-		}
495
-		if ($sort == 'filesize') {    // Filesize is not a string, so we use other comparison technique
496
-			return $aval < $bval ? -1 : 1;
497
-		} elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly"
498
-			return api_strnatcmp($aval, $bval);
499
-		} else {
500
-		    return api_strcasecmp($aval, $bval);
501
-		}
502
-	}
503
-
504
-	/**
505
-	 * A method that sorts the objects in the sentWork array, dependent on the $sort parameter.
506
-	 * $sort can be lastDate, firstDate, title, size, ...
507
-	 *
508
-	 * @param unknown_type $sort
509
-	 */
510
-	function orderSentWork($sort)
486
+        $sort = $this->_orderBy;
487
+        $aval = $a->$sort;
488
+        $bval = $b->$sort;
489
+        if ($sort == 'recipients') {
490
+            // The recipients property is an array so we do the comparison based
491
+            // on the first item of the recipients array
492
+            $aval = $aval[0]['name'];
493
+            $bval = $bval[0]['name'];
494
+        }
495
+        if ($sort == 'filesize') {    // Filesize is not a string, so we use other comparison technique
496
+            return $aval < $bval ? -1 : 1;
497
+        } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly"
498
+            return api_strnatcmp($aval, $bval);
499
+        } else {
500
+            return api_strcasecmp($aval, $bval);
501
+        }
502
+    }
503
+
504
+    /**
505
+     * A method that sorts the objects in the sentWork array, dependent on the $sort parameter.
506
+     * $sort can be lastDate, firstDate, title, size, ...
507
+     *
508
+     * @param unknown_type $sort
509
+     */
510
+    function orderSentWork($sort)
511 511
     {
512
-		switch($sort) {
513
-			case 'lastDate':
514
-				$this->_orderBy = 'last_upload_date';
515
-				break;
516
-			case 'firstDate':
517
-				$this->_orderBy = 'upload_date';
518
-				break;
519
-			case 'title':
520
-				$this->_orderBy = 'title';
521
-				break;
522
-			case 'size':
523
-				$this->_orderBy = 'filesize';
524
-				break;
525
-			case 'author':
526
-				$this->_orderBy = 'author';
527
-				break;
528
-			case 'recipient':
529
-				$this->_orderBy = 'recipients';
530
-				break;
531
-			default:
532
-				$this->_orderBy = 'last_upload_date';
533
-		}
534
-
535
-		usort($this->sentWork, array($this, '_cmpWork'));
536
-	}
537
-
538
-	/**
539
-	 * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
540
-	 * $sort can be lastDate, firstDate, title, size, ...
541
-	 * @param unknown_type $sort
542
-	 */
543
-	function orderReceivedWork($sort)
512
+        switch($sort) {
513
+            case 'lastDate':
514
+                $this->_orderBy = 'last_upload_date';
515
+                break;
516
+            case 'firstDate':
517
+                $this->_orderBy = 'upload_date';
518
+                break;
519
+            case 'title':
520
+                $this->_orderBy = 'title';
521
+                break;
522
+            case 'size':
523
+                $this->_orderBy = 'filesize';
524
+                break;
525
+            case 'author':
526
+                $this->_orderBy = 'author';
527
+                break;
528
+            case 'recipient':
529
+                $this->_orderBy = 'recipients';
530
+                break;
531
+            default:
532
+                $this->_orderBy = 'last_upload_date';
533
+        }
534
+
535
+        usort($this->sentWork, array($this, '_cmpWork'));
536
+    }
537
+
538
+    /**
539
+     * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
540
+     * $sort can be lastDate, firstDate, title, size, ...
541
+     * @param unknown_type $sort
542
+     */
543
+    function orderReceivedWork($sort)
544 544
     {
545
-		switch($sort) {
546
-			case 'lastDate':
547
-				$this->_orderBy = 'last_upload_date';
548
-				break;
549
-			case 'firstDate':
550
-				$this->_orderBy = 'upload_date';
551
-				break;
552
-			case 'title':
553
-				$this->_orderBy = 'title';
554
-				break;
555
-			case 'size':
556
-				$this->_orderBy = 'filesize';
557
-				break;
558
-			case 'author':
559
-				$this->_orderBy = 'author';
560
-				break;
561
-			case 'sender':
562
-				$this->_orderBy = 'uploaderName';
563
-				break;
564
-			default:
565
-				$this->_orderBy = 'last_upload_date';
566
-		}
567
-
568
-		usort($this->receivedWork, array($this, '_cmpWork'));
569
-	}
570
-
571
-	/**
572
-	 * Deletes all the received work of this person
573
-	 */
574
-	function deleteAllReceivedWork()
545
+        switch($sort) {
546
+            case 'lastDate':
547
+                $this->_orderBy = 'last_upload_date';
548
+                break;
549
+            case 'firstDate':
550
+                $this->_orderBy = 'upload_date';
551
+                break;
552
+            case 'title':
553
+                $this->_orderBy = 'title';
554
+                break;
555
+            case 'size':
556
+                $this->_orderBy = 'filesize';
557
+                break;
558
+            case 'author':
559
+                $this->_orderBy = 'author';
560
+                break;
561
+            case 'sender':
562
+                $this->_orderBy = 'uploaderName';
563
+                break;
564
+            default:
565
+                $this->_orderBy = 'last_upload_date';
566
+        }
567
+
568
+        usort($this->receivedWork, array($this, '_cmpWork'));
569
+    }
570
+
571
+    /**
572
+     * Deletes all the received work of this person
573
+     */
574
+    function deleteAllReceivedWork()
575 575
     {
576
-	    $course_id = api_get_course_int_id();
576
+        $course_id = api_get_course_int_id();
577 577
         $dropbox_cnf = getDropboxConf();
578
-		// Delete entries in person table concerning received works
579
-		foreach ($this->receivedWork as $w) {
578
+        // Delete entries in person table concerning received works
579
+        foreach ($this->receivedWork as $w) {
580 580
             $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
581 581
 			        WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'";
582
-			Database::query($sql);
583
-		}
582
+            Database::query($sql);
583
+        }
584 584
         // Check for unused files
585
-		removeUnusedFiles();
586
-	}
587
-
588
-	/**
589
-	 * Deletes all the received categories and work of this person
590
-	 * @param integer $id
591
-	 */
592
-	function deleteReceivedWorkFolder($id)
585
+        removeUnusedFiles();
586
+    }
587
+
588
+    /**
589
+     * Deletes all the received categories and work of this person
590
+     * @param integer $id
591
+     */
592
+    function deleteReceivedWorkFolder($id)
593 593
     {
594 594
         $dropbox_cnf = getDropboxConf();
595 595
         $course_id = api_get_course_int_id();
596 596
 
597
-		$id = intval($id);
598
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_file']."
597
+        $id = intval($id);
598
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']."
599 599
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
600
-		if (!Database::query($sql)) return false;
601
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
600
+        if (!Database::query($sql)) return false;
601
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
602 602
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
603
-		if (!Database::query($sql)) return false;
604
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_post']."
603
+        if (!Database::query($sql)) return false;
604
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']."
605 605
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
606
-		if (!Database::query($sql)) return false;
607
-		return true;
608
-	}
609
-
610
-	/**
611
-	 * Deletes a received dropbox file of this person with id=$id
612
-	 *
613
-	 * @param integer $id
614
-	 */
615
-	function deleteReceivedWork($id)
606
+        if (!Database::query($sql)) return false;
607
+        return true;
608
+    }
609
+
610
+    /**
611
+     * Deletes a received dropbox file of this person with id=$id
612
+     *
613
+     * @param integer $id
614
+     */
615
+    function deleteReceivedWork($id)
616 616
     {
617
-	    $course_id = api_get_course_int_id();
617
+        $course_id = api_get_course_int_id();
618 618
         $dropbox_cnf = getDropboxConf();
619
-		$id = intval($id);
620
-
621
-		// index check
622
-		$found = false;
623
-		foreach ($this->receivedWork as $w) {
624
-			if ($w->id == $id) {
625
-			   $found = true;
626
-			   break;
627
-			}
628
-		}
629
-
630
-		if (!$found) {
631
-			if (!$this->deleteReceivedWorkFolder($id)) {
632
-				die(get_lang('GeneralError').' (code 216)');
633
-			}
634
-		}
635
-		// Delete entries in person table concerning received works
619
+        $id = intval($id);
620
+
621
+        // index check
622
+        $found = false;
623
+        foreach ($this->receivedWork as $w) {
624
+            if ($w->id == $id) {
625
+                $found = true;
626
+                break;
627
+            }
628
+        }
629
+
630
+        if (!$found) {
631
+            if (!$this->deleteReceivedWorkFolder($id)) {
632
+                die(get_lang('GeneralError').' (code 216)');
633
+            }
634
+        }
635
+        // Delete entries in person table concerning received works
636 636
         $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
637 637
                 WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'";
638
-		Database::query($sql);
639
-		removeUnusedFiles();	// Check for unused files
640
-	}
641
-
642
-	/**
643
-	 * Deletes all the sent dropbox files of this person
644
-	 */
645
-	function deleteAllSentWork()
638
+        Database::query($sql);
639
+        removeUnusedFiles();	// Check for unused files
640
+    }
641
+
642
+    /**
643
+     * Deletes all the sent dropbox files of this person
644
+     */
645
+    function deleteAllSentWork()
646 646
     {
647
-	    $course_id = api_get_course_int_id();
647
+        $course_id = api_get_course_int_id();
648 648
         $dropbox_cnf = getDropboxConf();
649
-		//delete entries in person table concerning sent works
650
-		foreach ($this->sentWork as $w) {
649
+        //delete entries in person table concerning sent works
650
+        foreach ($this->sentWork as $w) {
651 651
             $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
652 652
                     WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'";
653
-			Database::query($sql);
654
-			removeMoreIfMailing($w->id);
655
-		}
656
-		removeUnusedFiles();	// Check for unused files
657
-	}
658
-
659
-	/**
660
-	 * Deletes a sent dropbox file of this person with id=$id
661
-	 *
662
-	 * @param unknown_type $id
663
-	 */
664
-	function deleteSentWork($id)
653
+            Database::query($sql);
654
+            removeMoreIfMailing($w->id);
655
+        }
656
+        removeUnusedFiles();	// Check for unused files
657
+    }
658
+
659
+    /**
660
+     * Deletes a sent dropbox file of this person with id=$id
661
+     *
662
+     * @param unknown_type $id
663
+     */
664
+    function deleteSentWork($id)
665 665
     {
666
-	    $course_id = api_get_course_int_id();
666
+        $course_id = api_get_course_int_id();
667 667
         $dropbox_cnf = getDropboxConf();
668 668
 
669
-		$id = intval($id);
670
-
671
-		// index check
672
-		$found = false;
673
-		foreach ($this->sentWork as $w) {
674
-			if ($w->id == $id) {
675
-			   $found = true;
676
-			   break;
677
-			}
678
-		}
679
-		if (!$found) {
680
-			if (!$this->deleteReceivedWorkFolder($id)) {
681
-				die(get_lang('GeneralError').' (code 219)');
682
-			}
683
-		}
684
-		//$file_id = $this->sentWork[$index]->id;
685
-		// Delete entries in person table concerning sent works
669
+        $id = intval($id);
670
+
671
+        // index check
672
+        $found = false;
673
+        foreach ($this->sentWork as $w) {
674
+            if ($w->id == $id) {
675
+                $found = true;
676
+                break;
677
+            }
678
+        }
679
+        if (!$found) {
680
+            if (!$this->deleteReceivedWorkFolder($id)) {
681
+                die(get_lang('GeneralError').' (code 219)');
682
+            }
683
+        }
684
+        //$file_id = $this->sentWork[$index]->id;
685
+        // Delete entries in person table concerning sent works
686 686
         $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
687 687
                 WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'";
688
-		Database::query($sql);
689
-		removeMoreIfMailing($id);
690
-		removeUnusedFiles();	// Check for unused files
691
-	}
692
-
693
-	/**
694
-	 * Updates feedback for received work of this person with id=$id
695
-	 *
696
-	 * @param string $id
697
-	 * @param string $text
698
-	 */
699
-	function updateFeedback($id, $text)
688
+        Database::query($sql);
689
+        removeMoreIfMailing($id);
690
+        removeUnusedFiles();	// Check for unused files
691
+    }
692
+
693
+    /**
694
+     * Updates feedback for received work of this person with id=$id
695
+     *
696
+     * @param string $id
697
+     * @param string $text
698
+     */
699
+    function updateFeedback($id, $text)
700 700
     {
701
-	    $course_id = api_get_course_int_id();
701
+        $course_id = api_get_course_int_id();
702 702
         $_course = api_get_course_info();
703 703
         $dropbox_cnf = getDropboxConf();
704 704
 
705
-		$id = intval($id);
706
-
707
-		// index check
708
-		$found = false;
709
-		$wi = -1;
710
-		foreach ($this->receivedWork as $w) {
711
-			$wi++;
712
-			if ($w->id == $id){
713
-			   $found = true;
714
-			   break;
715
-			}  // foreach (... as $wi -> $w) gives error 221! (no idea why...)
716
-		}
717
-		if (!$found) {
718
-			die(get_lang('GeneralError').' (code 221)');
719
-		}
720
-
721
-		$feedback_date = api_get_utc_datetime();
722
-		$this->receivedWork[$wi]->feedback_date = $feedback_date;
723
-		$this->receivedWork[$wi]->feedback = $text;
705
+        $id = intval($id);
706
+
707
+        // index check
708
+        $found = false;
709
+        $wi = -1;
710
+        foreach ($this->receivedWork as $w) {
711
+            $wi++;
712
+            if ($w->id == $id){
713
+                $found = true;
714
+                break;
715
+            }  // foreach (... as $wi -> $w) gives error 221! (no idea why...)
716
+        }
717
+        if (!$found) {
718
+            die(get_lang('GeneralError').' (code 221)');
719
+        }
720
+
721
+        $feedback_date = api_get_utc_datetime();
722
+        $this->receivedWork[$wi]->feedback_date = $feedback_date;
723
+        $this->receivedWork[$wi]->feedback = $text;
724 724
 
725 725
         $params = [
726 726
             'feedback_date' => $feedback_date,
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
             ]
739 739
         );
740 740
 
741
-		// Update item_property table
741
+        // Update item_property table
742 742
 
743
-		if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
744
-		    $ownerid = getUserOwningThisMailing($ownerid);
745
-		}
743
+        if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
744
+            $ownerid = getUserOwningThisMailing($ownerid);
745
+        }
746 746
         api_item_property_update(
747 747
             $_course,
748 748
             TOOL_DROPBOX,
@@ -753,31 +753,31 @@  discard block
 block discarded – undo
753 753
             $ownerid
754 754
         );
755 755
 
756
-	}
756
+    }
757 757
 
758
-	/**
759
-	 * Filter the received work
760
-	 * @param string $type
761
-	 * @param string $value
762
-	 */
763
-	function filter_received_work($type, $value)
758
+    /**
759
+     * Filter the received work
760
+     * @param string $type
761
+     * @param string $value
762
+     */
763
+    function filter_received_work($type, $value)
764 764
     {
765 765
         $dropbox_cnf = getDropboxConf();
766
-    	$new_received_work = array();
767
-		foreach ($this->receivedWork as $work) {
768
-			switch ($type) {
769
-				case 'uploader_id':
770
-					if ($work->uploader_id == $value ||
771
-						($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
766
+        $new_received_work = array();
767
+        foreach ($this->receivedWork as $work) {
768
+            switch ($type) {
769
+                case 'uploader_id':
770
+                    if ($work->uploader_id == $value ||
771
+                        ($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
772 772
                         getUserOwningThisMailing($work->uploader_id) == $value)
773 773
                     ) {
774
-						$new_received_work[] = $work;
775
-					}
776
-					break;
777
-				default:
778
-					$new_received_work[] = $work;
779
-			}
780
-		}
781
-		$this->receivedWork = $new_received_work;
782
-	}
774
+                        $new_received_work[] = $work;
775
+                    }
776
+                    break;
777
+                default:
778
+                    $new_received_work[] = $work;
779
+            }
780
+        }
781
+        $this->receivedWork = $new_received_work;
782
+    }
783 783
 }
Please login to merge, or discard this patch.
main/admin/index.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -399,10 +399,10 @@
 block discarded – undo
399 399
     if(count($_plugins['menu_administrator']) > 0) {
400 400
         $blocks['plugins']['icon'] = Display::return_icon(
401 401
             'plugins.png',
402
-             get_lang('Plugins'),
403
-             array(),
404
-             ICON_SIZE_MEDIUM,
405
-             false
402
+                get_lang('Plugins'),
403
+                array(),
404
+                ICON_SIZE_MEDIUM,
405
+                false
406 406
         );
407 407
         $blocks['plugins']['label'] = api_ucfirst(get_lang('Plugins'));
408 408
         $blocks['plugins']['class'] = 'block-admin-platform';
Please login to merge, or discard this patch.
main/inc/lib/usermanager.lib.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1231,13 +1231,13 @@  discard block
 block discarded – undo
1231 1231
     }
1232 1232
 
1233 1233
     /**
1234
-    * Get the users by ID
1235
-    * @param array $ids student ids
1236
-    * @param string $active
1237
-    * @param string $order
1238
-    * @param string $limit
1239
-    * @return array $result student information
1240
-    */
1234
+     * Get the users by ID
1235
+     * @param array $ids student ids
1236
+     * @param string $active
1237
+     * @param string $order
1238
+     * @param string $limit
1239
+     * @return array $result student information
1240
+     */
1241 1241
     public static function get_user_list_by_ids($ids = array(), $active = null, $order = null, $limit = null)
1242 1242
     {
1243 1243
         if (empty($ids)) {
@@ -2275,7 +2275,7 @@  discard block
 block discarded – undo
2275 2275
      *
2276 2276
      * @return array with extra data info of a user i.e array('field_variable'=>'value');
2277 2277
      */
2278
-     public static function get_extra_user_data_by_value($field_variable, $field_value, $all_visibility = true)
2278
+        public static function get_extra_user_data_by_value($field_variable, $field_value, $all_visibility = true)
2279 2279
     {
2280 2280
         $extraField = new ExtraFieldValue('user');
2281 2281
 
@@ -3352,12 +3352,12 @@  discard block
 block discarded – undo
3352 3352
         if ($tag_id == 0) {
3353 3353
             //the tag doesn't exist
3354 3354
             $sql = "INSERT INTO $table_user_tag (tag, field_id,count) VALUES ('$tag','$field_id', count + 1)";
3355
-             Database::query($sql);
3355
+                Database::query($sql);
3356 3356
             $last_insert_id = Database::insert_id();
3357 3357
         } else {
3358 3358
             //the tag exists we update it
3359 3359
             $sql = "UPDATE $table_user_tag SET count = count + 1 WHERE id  = $tag_id";
3360
-             Database::query($sql);
3360
+                Database::query($sql);
3361 3361
             $last_insert_id = $tag_id;
3362 3362
         }
3363 3363
 
@@ -3552,9 +3552,9 @@  discard block
 block discarded – undo
3552 3552
     }
3553 3553
 
3554 3554
     /**
3555
-      * Get extra filtrable user fields (only type select)
3556
-      * @return array
3557
-      */
3555
+     * Get extra filtrable user fields (only type select)
3556
+     * @return array
3557
+     */
3558 3558
     public static function get_extra_filtrable_fields()
3559 3559
     {
3560 3560
         $extraFieldList = UserManager::get_extra_fields();
@@ -3579,9 +3579,9 @@  discard block
 block discarded – undo
3579 3579
     }
3580 3580
 
3581 3581
     /**
3582
-      * Get extra where clauses for finding users based on extra filtrable user fields (type select)
3583
-      * @return string With AND clauses based on user's ID which have the values to search in extra user fields
3584
-      */
3582
+     * Get extra where clauses for finding users based on extra filtrable user fields (type select)
3583
+     * @return string With AND clauses based on user's ID which have the values to search in extra user fields
3584
+     */
3585 3585
     public static function get_search_form_where_extra_fields()
3586 3586
     {
3587 3587
         $useExtraFields = false;
@@ -3900,23 +3900,23 @@  discard block
 block discarded – undo
3900 3900
     }
3901 3901
 
3902 3902
     /**
3903
-    * Get users followed by human resource manager
3904
-    * @param int $userId
3905
-    * @param int  $userStatus Filter users by status (STUDENT, COURSEMANAGER, etc)
3906
-    * @param bool $getOnlyUserId
3907
-    * @param bool $getSql
3908
-    * @param bool $getCount
3909
-    * @param int $from
3910
-    * @param int $numberItems
3911
-    * @param int $column
3912
-    * @param string $direction
3913
-    * @param int $active
3914
-    * @param string $lastConnectionDate
3915
-    * @param int $status the function is called by who? COURSEMANAGER, DRH?
3916
-    * @param string $keyword
3903
+     * Get users followed by human resource manager
3904
+     * @param int $userId
3905
+     * @param int  $userStatus Filter users by status (STUDENT, COURSEMANAGER, etc)
3906
+     * @param bool $getOnlyUserId
3907
+     * @param bool $getSql
3908
+     * @param bool $getCount
3909
+     * @param int $from
3910
+     * @param int $numberItems
3911
+     * @param int $column
3912
+     * @param string $direction
3913
+     * @param int $active
3914
+     * @param string $lastConnectionDate
3915
+     * @param int $status the function is called by who? COURSEMANAGER, DRH?
3916
+     * @param string $keyword
3917 3917
      *
3918
-    * @return array user list
3919
-    */
3918
+     * @return array user list
3919
+     */
3920 3920
     public static function getUsersFollowedByUser(
3921 3921
         $userId,
3922 3922
         $userStatus = null,
Please login to merge, or discard this patch.