Completed
Push — 1.10.x ( 9d8f25...0ad4ea )
by Angel Fernando Quiroz
80:30 queued 40:12
created
main/gradebook/lib/be/forumthreadlink.class.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class ForumThreadLink extends AbstractLink
12 12
 {
13
-	private $forum_thread_table = null;
14
-	private $itemprop_table = null;
15
-
16
-	/**
17
-	 * Constructor
18
-	 */
19
-	public function __construct()
20
-	{
21
-		parent::__construct();
22
-		$this->set_type(LINK_FORUM_THREAD);
23
-	}
24
-
25
-	/**
26
-	 * @return string
27
-	 */
28
-	public function get_type_name()
29
-	{
30
-		return get_lang('ForumThreads');
31
-	}
32
-
33
-	/**
34
-	 * @return bool
35
-	 */
36
-	public function is_allowed_to_change_name()
37
-	{
38
-		return false;
39
-	}
40
-
41
-	/**
42
-	 * Generate an array of exercises that a teacher hasn't created a link for.
43
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
44
-	 */
45
-	public function get_not_created_links()
46
-	{
47
-		if (empty($this->course_code)) {
48
-			die('Error in get_not_created_links() : course code not set');
49
-		}
50
-
51
-		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
52
-
53
-		$sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table()
54
-			.' forum_thread WHERE thread_id NOT IN'
55
-			.' (SELECT ref_id FROM '.$tbl_grade_links
56
-			.' WHERE type = '.LINK_FORUM_THREAD
57
-			." AND c_id = ".intval($this->course_id)
58
-			.') AND forum_thread.session_id='.api_get_session_id().'';
59
-
60
-		$result = Database::query($sql);
13
+    private $forum_thread_table = null;
14
+    private $itemprop_table = null;
15
+
16
+    /**
17
+     * Constructor
18
+     */
19
+    public function __construct()
20
+    {
21
+        parent::__construct();
22
+        $this->set_type(LINK_FORUM_THREAD);
23
+    }
24
+
25
+    /**
26
+     * @return string
27
+     */
28
+    public function get_type_name()
29
+    {
30
+        return get_lang('ForumThreads');
31
+    }
32
+
33
+    /**
34
+     * @return bool
35
+     */
36
+    public function is_allowed_to_change_name()
37
+    {
38
+        return false;
39
+    }
40
+
41
+    /**
42
+     * Generate an array of exercises that a teacher hasn't created a link for.
43
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
44
+     */
45
+    public function get_not_created_links()
46
+    {
47
+        if (empty($this->course_code)) {
48
+            die('Error in get_not_created_links() : course code not set');
49
+        }
50
+
51
+        $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
52
+
53
+        $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table()
54
+            .' forum_thread WHERE thread_id NOT IN'
55
+            .' (SELECT ref_id FROM '.$tbl_grade_links
56
+            .' WHERE type = '.LINK_FORUM_THREAD
57
+            ." AND c_id = ".intval($this->course_id)
58
+            .') AND forum_thread.session_id='.api_get_session_id().'';
59
+
60
+        $result = Database::query($sql);
61 61
 
62 62
         $cats = array();
63 63
         while ($data = Database::fetch_array($result)) {
@@ -72,29 +72,29 @@  discard block
 block discarded – undo
72 72
         }
73 73
 
74 74
         return $cats;
75
-	}
76
-
77
-	/**
78
-	 * Generate an array of all exercises available.
79
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
-	 */
81
-	public function get_all_links()
82
-	{
83
-		if (empty($this->course_code)) {
84
-			die('Error in get_not_created_links() : course code not set');
85
-		}
86
-
87
-		$tbl_grade_links 	= Database :: get_course_table(TABLE_FORUM_THREAD);
88
-		$tbl_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
89
-		$session_id = api_get_session_id();
90
-
91
-		if ($session_id) {
92
-			$session_condition = 'tl.session_id='.api_get_session_id();
93
-		} else {
94
-			$session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
95
-		}
96
-
97
-		$sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
75
+    }
76
+
77
+    /**
78
+     * Generate an array of all exercises available.
79
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
+     */
81
+    public function get_all_links()
82
+    {
83
+        if (empty($this->course_code)) {
84
+            die('Error in get_not_created_links() : course code not set');
85
+        }
86
+
87
+        $tbl_grade_links 	= Database :: get_course_table(TABLE_FORUM_THREAD);
88
+        $tbl_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
89
+        $session_id = api_get_session_id();
90
+
91
+        if ($session_id) {
92
+            $session_condition = 'tl.session_id='.api_get_session_id();
93
+        } else {
94
+            $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
95
+        }
96
+
97
+        $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
98 98
 				FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip
99 99
 				ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id )
100 100
 				WHERE
@@ -105,24 +105,24 @@  discard block
 block discarded – undo
105 105
                     '.$session_condition.'
106 106
                 ';
107 107
 
108
-		$result = Database::query($sql);
108
+        $result = Database::query($sql);
109 109
 
110
-		while ($data = Database::fetch_array($result)) {
111
-			if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){
112
-				$cats[] = array ($data['thread_id'], $data['thread_title_qualify']);
113
-			} else {
114
-				$cats[] = array ($data['thread_id'], $data['thread_title']);
115
-			}
116
-		}
117
-		$my_cats = isset($cats) ? $cats : null;
110
+        while ($data = Database::fetch_array($result)) {
111
+            if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){
112
+                $cats[] = array ($data['thread_id'], $data['thread_title_qualify']);
113
+            } else {
114
+                $cats[] = array ($data['thread_id'], $data['thread_title']);
115
+            }
116
+        }
117
+        $my_cats = isset($cats) ? $cats : null;
118 118
 
119
-		return $my_cats;
120
-	}
119
+        return $my_cats;
120
+    }
121 121
 
122 122
     /**
123
-    * Has anyone done this exercise yet ?
124
-    * @return boolean
125
-    */
123
+     * Has anyone done this exercise yet ?
124
+     * @return boolean
125
+     */
126 126
     public function has_results()
127 127
     {
128 128
         $table = Database :: get_course_table(TABLE_FORUM_POST);
@@ -134,40 +134,40 @@  discard block
 block discarded – undo
134 134
         $number = Database::fetch_row($result);
135 135
 
136 136
         return $number[0] != 0;
137
-	}
137
+    }
138 138
 
139
-	/**
140
-	 * @param int    $stud_id
139
+    /**
140
+     * @param int    $stud_id
141 141
      * @param string $type
142 142
      *
143
-	 * @return array|null
144
-	 */
145
-	public function calc_score($stud_id = null, $type = null)
146
-	{
143
+     * @return array|null
144
+     */
145
+    public function calc_score($stud_id = null, $type = null)
146
+    {
147 147
         require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
148 148
         $threadInfo = get_thread_information($this->get_ref_id());
149 149
 
150
-		$thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
150
+        $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
151 151
 
152
-		$sql = 'SELECT thread_qualify_max
152
+        $sql = 'SELECT thread_qualify_max
153 153
 		        FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)."
154 154
   				WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'";
155
-		$query = Database::query($sql);
156
-		$assignment = Database::fetch_array($query);
155
+        $query = Database::query($sql);
156
+        $assignment = Database::fetch_array($query);
157 157
 
158
-		$sql = "SELECT * FROM $thread_qualify
158
+        $sql = "SELECT * FROM $thread_qualify
159 159
 				WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id();
160
-		if (isset($stud_id)) {
161
-			$sql .= ' AND user_id = '.intval($stud_id);
162
-		}
160
+        if (isset($stud_id)) {
161
+            $sql .= ' AND user_id = '.intval($stud_id);
162
+        }
163 163
 
164
-		// order by id, that way the student's first attempt is accessed first
165
-		$sql .= ' ORDER BY qualify_time DESC';
164
+        // order by id, that way the student's first attempt is accessed first
165
+        $sql .= ' ORDER BY qualify_time DESC';
166 166
 
167
-		$scores = Database::query($sql);
167
+        $scores = Database::query($sql);
168 168
 
169
-		// for 1 student
170
-		if (isset($stud_id)) {
169
+        // for 1 student
170
+        if (isset($stud_id)) {
171 171
             if ($threadInfo['thread_peer_qualify'] == 0) {
172 172
                 // Classic way of calculate score
173 173
                 if ($data = Database::fetch_array($scores)) {
@@ -195,174 +195,174 @@  discard block
 block discarded – undo
195 195
                 }
196 196
                 return [$score/$counter, $assignment['thread_qualify_max']];
197 197
             }
198
-		} else {
199
-			// All students -> get average
200
-			$students = array();  // user list, needed to make sure we only
201
-			// take first attempts into account
202
-			$counter = 0;
203
-			$sum = 0;
204
-			$bestResult = 0;
205
-			$weight = 0;
206
-			$sumResult = 0;
207
-
208
-			while ($data = Database::fetch_array($scores)) {
209
-				if (!(array_key_exists($data['user_id'], $students))) {
210
-					if ($assignment['thread_qualify_max'] != 0) {
211
-						$students[$data['user_id']] = $data['qualify'];
212
-						$counter++;
213
-						$sum += $data['qualify'] / $assignment['thread_qualify_max'];
214
-						$sumResult += $data['qualify'];
215
-						if ($data['qualify'] > $bestResult) {
216
-							$bestResult = $data['qualify'];
217
-						}
218
-						$weight = $assignment['thread_qualify_max'];
219
-					}
220
-				}
221
-			}
222
-
223
-			if ($counter == 0) {
224
-				return null;
225
-			} else {
226
-				switch ($type) {
227
-					case 'best':
228
-						return array($bestResult, $weight);
229
-						break;
230
-					case 'average':
231
-						return array($sumResult/$counter, $weight);
232
-						break;
233
-					case 'ranking':
234
-						return AbstractLink::getCurrentUserRanking($stud_id, $students);
235
-						break;
236
-					default:
237
-						return array($sum, $counter);
238
-						break;
239
-				}
240
-			}
241
-		}
242
-	}
243
-
244
-	/**
245
-	 * Lazy load function to get the database table of the student publications
246
-	 */
247
-	private function get_forum_thread_table()
248
-	{
249
-		return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
250
-	}
251
-
252
-	public function needs_name_and_description()
253
-	{
254
-		return false;
255
-	}
256
-
257
-	public function needs_max()
258
-	{
259
-		return false;
260
-	}
261
-
262
-	public function needs_results()
263
-	{
264
-		return false;
265
-	}
198
+        } else {
199
+            // All students -> get average
200
+            $students = array();  // user list, needed to make sure we only
201
+            // take first attempts into account
202
+            $counter = 0;
203
+            $sum = 0;
204
+            $bestResult = 0;
205
+            $weight = 0;
206
+            $sumResult = 0;
207
+
208
+            while ($data = Database::fetch_array($scores)) {
209
+                if (!(array_key_exists($data['user_id'], $students))) {
210
+                    if ($assignment['thread_qualify_max'] != 0) {
211
+                        $students[$data['user_id']] = $data['qualify'];
212
+                        $counter++;
213
+                        $sum += $data['qualify'] / $assignment['thread_qualify_max'];
214
+                        $sumResult += $data['qualify'];
215
+                        if ($data['qualify'] > $bestResult) {
216
+                            $bestResult = $data['qualify'];
217
+                        }
218
+                        $weight = $assignment['thread_qualify_max'];
219
+                    }
220
+                }
221
+            }
222
+
223
+            if ($counter == 0) {
224
+                return null;
225
+            } else {
226
+                switch ($type) {
227
+                    case 'best':
228
+                        return array($bestResult, $weight);
229
+                        break;
230
+                    case 'average':
231
+                        return array($sumResult/$counter, $weight);
232
+                        break;
233
+                    case 'ranking':
234
+                        return AbstractLink::getCurrentUserRanking($stud_id, $students);
235
+                        break;
236
+                    default:
237
+                        return array($sum, $counter);
238
+                        break;
239
+                }
240
+            }
241
+        }
242
+    }
243
+
244
+    /**
245
+     * Lazy load function to get the database table of the student publications
246
+     */
247
+    private function get_forum_thread_table()
248
+    {
249
+        return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
250
+    }
251
+
252
+    public function needs_name_and_description()
253
+    {
254
+        return false;
255
+    }
256
+
257
+    public function needs_max()
258
+    {
259
+        return false;
260
+    }
261
+
262
+    public function needs_results()
263
+    {
264
+        return false;
265
+    }
266 266
 
267 267
     /**
268 268
      * @return string
269 269
      */
270
-	public function get_name()
271
-	{
272
-		$this->get_exercise_data();
273
-		$thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : '';
274
-		$thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : '';
275
-		if ( isset($thread_title_qualify) && $thread_title_qualify!="") {
276
-			return $this->exercise_data['thread_title_qualify'];
277
-		} else {
278
-			return $thread_title;
279
-		}
280
-	}
270
+    public function get_name()
271
+    {
272
+        $this->get_exercise_data();
273
+        $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : '';
274
+        $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : '';
275
+        if ( isset($thread_title_qualify) && $thread_title_qualify!="") {
276
+            return $this->exercise_data['thread_title_qualify'];
277
+        } else {
278
+            return $thread_title;
279
+        }
280
+    }
281 281
 
282 282
     /**
283 283
      * @return string
284 284
      */
285
-	public function get_description()
286
-	{
287
-		return '';//$this->exercise_data['description'];
288
-	}
289
-
290
-	/**
291
-	 * Check if this still links to an exercise
292
-	 */
293
-	public function is_valid_link()
294
-	{
295
-		$sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
285
+    public function get_description()
286
+    {
287
+        return '';//$this->exercise_data['description'];
288
+    }
289
+
290
+    /**
291
+     * Check if this still links to an exercise
292
+     */
293
+    public function is_valid_link()
294
+    {
295
+        $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
296 296
         		WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
297
-		$result = Database::query($sql);
298
-		$number = Database::fetch_row($result);
299
-		return ($number[0] != 0);
300
-	}
301
-
302
-	public function get_test_id()
303
-	{
304
-		return 'DEBUG:ID';
305
-	}
306
-
307
-	public function get_link()
308
-	{
309
-		//it was extracts the forum id
310
-		$sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
297
+        $result = Database::query($sql);
298
+        $number = Database::fetch_row($result);
299
+        return ($number[0] != 0);
300
+    }
301
+
302
+    public function get_test_id()
303
+    {
304
+        return 'DEBUG:ID';
305
+    }
306
+
307
+    public function get_link()
308
+    {
309
+        //it was extracts the forum id
310
+        $sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
311 311
     			WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id()."";
312
-		$result = Database::query($sql);
313
-		$row    = Database::fetch_array($result,'ASSOC');
314
-		$forum_id=$row['forum_id'];
315
-
316
-		$url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
317
-		return $url;
318
-	}
319
-
320
-	private function get_exercise_data()
321
-	{
322
-		$session_id = api_get_session_id();
323
-		if ($session_id) {
324
-			$session_condition = 'session_id='.api_get_session_id();
325
-		} else {
326
-			$session_condition = '(session_id = 0 OR session_id IS NULL)';
327
-		}
328
-
329
-		if (!isset($this->exercise_data)) {
330
-			$sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
312
+        $result = Database::query($sql);
313
+        $row    = Database::fetch_array($result,'ASSOC');
314
+        $forum_id=$row['forum_id'];
315
+
316
+        $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
317
+        return $url;
318
+    }
319
+
320
+    private function get_exercise_data()
321
+    {
322
+        $session_id = api_get_session_id();
323
+        if ($session_id) {
324
+            $session_condition = 'session_id='.api_get_session_id();
325
+        } else {
326
+            $session_condition = '(session_id = 0 OR session_id IS NULL)';
327
+        }
328
+
329
+        if (!isset($this->exercise_data)) {
330
+            $sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
331 331
                     WHERE c_id = '.$this->course_id.' AND  thread_id = '.$this->get_ref_id().' AND '.$session_condition;
332
-			$query = Database::query($sql);
333
-			$this->exercise_data = Database::fetch_array($query);
334
-		}
335
-		return $this->exercise_data;
336
-	}
337
-
338
-	public function get_icon_name()
339
-	{
340
-		return 'forum';
341
-	}
342
-
343
-	function save_linked_data()
344
-	{
345
-		$weight = (float)$this->get_weight();
346
-		$ref_id = $this->get_ref_id();
347
-
348
-		if (!empty($ref_id)) {
349
-			$sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
332
+            $query = Database::query($sql);
333
+            $this->exercise_data = Database::fetch_array($query);
334
+        }
335
+        return $this->exercise_data;
336
+    }
337
+
338
+    public function get_icon_name()
339
+    {
340
+        return 'forum';
341
+    }
342
+
343
+    function save_linked_data()
344
+    {
345
+        $weight = (float)$this->get_weight();
346
+        $ref_id = $this->get_ref_id();
347
+
348
+        if (!empty($ref_id)) {
349
+            $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
350 350
                     WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
351
-			Database::query($sql);
352
-		}
353
-	}
354
-
355
-	function delete_linked_data()
356
-	{
357
-		$ref_id = $this->get_ref_id();
358
-		if (!empty($ref_id)) {
359
-			//Cleans forum
360
-			$sql = 'UPDATE '.$this->get_forum_thread_table().' SET
351
+            Database::query($sql);
352
+        }
353
+    }
354
+
355
+    function delete_linked_data()
356
+    {
357
+        $ref_id = $this->get_ref_id();
358
+        if (!empty($ref_id)) {
359
+            //Cleans forum
360
+            $sql = 'UPDATE '.$this->get_forum_thread_table().' SET
361 361
 			        thread_qualify_max = 0,
362 362
 			        thread_weight = 0,
363 363
 			        thread_title_qualify = ""
364 364
                     WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
365
-			Database::query($sql);
366
-		}
367
-	}
365
+            Database::query($sql);
366
+        }
367
+    }
368 368
 }
Please login to merge, or discard this patch.
main/inc/lib/chat.lib.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
     }
40 40
 
41 41
     /**
42
-    * Set user chat status
43
-    * @param int 0 if disconnected, 1 if connected
44
-    * @param integer $status
42
+     * Set user chat status
43
+     * @param int 0 if disconnected, 1 if connected
44
+     * @param integer $status
45 45
      *
46
-    * @return void
47
-    */
46
+     * @return void
47
+     */
48 48
     public function setUserStatus($status)
49 49
     {
50 50
         UserManager::update_extra_field_value(api_get_user_id(), 'user_chat_status', $status);
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
     }
149 149
 
150 150
     /**
151
-    * Returns an array of messages inside a chat session with a specific user
152
-    * @param int The ID of the user with whom the current user is chatting
153
-    * @return array Messages list
154
-    */
151
+     * Returns an array of messages inside a chat session with a specific user
152
+     * @param int The ID of the user with whom the current user is chatting
153
+     * @return array Messages list
154
+     */
155 155
     public function box_session($user_id)
156 156
     {
157 157
         $items = array();
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             }
300 300
         }
301 301
          
302
-         return false;
302
+            return false;
303 303
     }
304 304
     
305 305
     public function is_chat_blocked_by_exercises()
Please login to merge, or discard this patch.
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/add_courses_to_session_functions.lib.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -6,47 +6,47 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class AddCourseToSession
8 8
 {
9
-	/**
10
-	 * Searches a course, given a search string and a type of search box
11
-	 * @param string $needle Search string
12
-	 * @param string $type Type of search box ('single' or anything else)
13
-	 * @return xajaxResponse XajaxResponse
14
-	 * @assert ('abc', 'single') !== null
15
-	 * @assert ('abc', 'multiple') !== null
16
-	 */
17
-	public static function search_courses($needle, $type)
18
-	{
19
-		global $tbl_session_rel_course, $id_session;
9
+    /**
10
+     * Searches a course, given a search string and a type of search box
11
+     * @param string $needle Search string
12
+     * @param string $type Type of search box ('single' or anything else)
13
+     * @return xajaxResponse XajaxResponse
14
+     * @assert ('abc', 'single') !== null
15
+     * @assert ('abc', 'multiple') !== null
16
+     */
17
+    public static function search_courses($needle, $type)
18
+    {
19
+        global $tbl_session_rel_course, $id_session;
20 20
         $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
21
-		$course_title = null;
22
-		$xajax_response = new xajaxResponse();
23
-		$return = '';
24
-		if(!empty($needle) && !empty($type)) {
25
-			// xajax send utf8 datas... datas in db can be non-utf8 datas
26
-			$charset = api_get_system_encoding();
27
-			$needle = api_convert_encoding($needle, $charset, 'utf-8');
21
+        $course_title = null;
22
+        $xajax_response = new xajaxResponse();
23
+        $return = '';
24
+        if(!empty($needle) && !empty($type)) {
25
+            // xajax send utf8 datas... datas in db can be non-utf8 datas
26
+            $charset = api_get_system_encoding();
27
+            $needle = api_convert_encoding($needle, $charset, 'utf-8');
28 28
 
29
-			$cond_course_code = '';
30
-			if (!empty($id_session)) {
31
-				$id_session = intval($id_session);
32
-				// check course_code from session_rel_course table
33
-				$sql = 'SELECT c_id FROM '.$tbl_session_rel_course.'
29
+            $cond_course_code = '';
30
+            if (!empty($id_session)) {
31
+                $id_session = intval($id_session);
32
+                // check course_code from session_rel_course table
33
+                $sql = 'SELECT c_id FROM '.$tbl_session_rel_course.'
34 34
 						WHERE session_id = '.$id_session;
35
-				$res = Database::query($sql);
36
-				$course_codes = '';
37
-				if (Database::num_rows($res) > 0) {
38
-					while ($row = Database::fetch_row($res)) {
39
-						$course_codes .= '\''.$row[0].'\',';
40
-					}
41
-					$course_codes = substr($course_codes,0,(strlen($course_codes)-1));
35
+                $res = Database::query($sql);
36
+                $course_codes = '';
37
+                if (Database::num_rows($res) > 0) {
38
+                    while ($row = Database::fetch_row($res)) {
39
+                        $course_codes .= '\''.$row[0].'\',';
40
+                    }
41
+                    $course_codes = substr($course_codes,0,(strlen($course_codes)-1));
42 42
 
43
-					$cond_course_code = ' AND course.id NOT IN('.$course_codes.') ';
44
-				}
45
-			}
43
+                    $cond_course_code = ' AND course.id NOT IN('.$course_codes.') ';
44
+                }
45
+            }
46 46
 
47
-			if ($type=='single') {
48
-				// search users where username or firstname or lastname begins likes $needle
49
-				$sql = 'SELECT
47
+            if ($type=='single') {
48
+                // search users where username or firstname or lastname begins likes $needle
49
+                $sql = 'SELECT
50 50
 							course.code,
51 51
 						 	course.visual_code,
52 52
 						 	course.title,
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
 						WHERE
59 59
 							course.visual_code LIKE "'.$needle.'%" OR
60 60
 							course.title LIKE "'.$needle.'%"';
61
-			} else {
62
-				$sql = 'SELECT course.code, course.visual_code, course.title
61
+            } else {
62
+                $sql = 'SELECT course.code, course.visual_code, course.title
63 63
 						FROM '.$tbl_course.' course
64 64
 						WHERE
65 65
 							course.visual_code LIKE "'.$needle.'%" '.$cond_course_code.'
66 66
 						ORDER BY course.code ';
67
-			}
67
+            }
68 68
 
69
-			if (api_is_multiple_url_enabled()) {
70
-				$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
71
-				$access_url_id = api_get_current_access_url_id();
72
-				if ($access_url_id != -1){
69
+            if (api_is_multiple_url_enabled()) {
70
+                $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
71
+                $access_url_id = api_get_current_access_url_id();
72
+                if ($access_url_id != -1){
73 73
 
74
-					if ($type=='single') {
75
-						$sql = 'SELECT
74
+                    if ($type=='single') {
75
+                        $sql = 'SELECT
76 76
 						            course.code,
77 77
 						            course.visual_code,
78 78
 						            course.title,
@@ -87,42 +87,42 @@  discard block
 block discarded – undo
87 87
 									access_url_id = '.$access_url_id.' AND
88 88
 									(course.visual_code LIKE "'.$needle.'%" OR
89 89
 									course.title LIKE "'.$needle.'%" )';
90
-					} else {
91
-						$sql = 'SELECT course.code, course.visual_code, course.title
90
+                    } else {
91
+                        $sql = 'SELECT course.code, course.visual_code, course.title
92 92
 								FROM '.$tbl_course.' course, '.$tbl_course_rel_access_url.' url_course
93 93
 								WHERE
94 94
 									url_course.c_id = course.id AND
95 95
 									access_url_id = '.$access_url_id.' AND
96 96
 									course.visual_code LIKE "'.$needle.'%" '.$cond_course_code.'
97 97
 								ORDER BY course.code ';
98
-					}
99
-				}
100
-			}
98
+                    }
99
+                }
100
+            }
101 101
 
102
-			$rs = Database::query($sql);
103
-			$course_list = array();
104
-			if ($type=='single') {
102
+            $rs = Database::query($sql);
103
+            $course_list = array();
104
+            if ($type=='single') {
105 105
 
106
-				while($course = Database :: fetch_array($rs)) {
107
-					$course_list[] = $course['code'];
108
-					$course_title=str_replace("'","\'",$course_title);
109
-					$return .= '<a href="javascript: void(0);" onclick="javascript: add_course_to_session(\''.$course['code'].'\',\''.$course_title.' ('.$course['visual_code'].')'.'\')">'.$course['title'].' ('.$course['visual_code'].')</a><br />';
110
-				}
111
-				$xajax_response -> addAssign('ajax_list_courses_single','innerHTML',api_utf8_encode($return));
112
-			} else {
113
-				$return .= '<select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:340px;">';
114
-				while($course = Database :: fetch_array($rs)) {
115
-					$course_list[] = $course['code'];
116
-					$course_title=str_replace("'","\'",$course_title);
117
-					$return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
118
-				}
119
-				$return .= '</select>';
106
+                while($course = Database :: fetch_array($rs)) {
107
+                    $course_list[] = $course['code'];
108
+                    $course_title=str_replace("'","\'",$course_title);
109
+                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_course_to_session(\''.$course['code'].'\',\''.$course_title.' ('.$course['visual_code'].')'.'\')">'.$course['title'].' ('.$course['visual_code'].')</a><br />';
110
+                }
111
+                $xajax_response -> addAssign('ajax_list_courses_single','innerHTML',api_utf8_encode($return));
112
+            } else {
113
+                $return .= '<select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:340px;">';
114
+                while($course = Database :: fetch_array($rs)) {
115
+                    $course_list[] = $course['code'];
116
+                    $course_title=str_replace("'","\'",$course_title);
117
+                    $return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
118
+                }
119
+                $return .= '</select>';
120 120
 
121
-				$xajax_response -> addAssign('ajax_list_courses_multiple','innerHTML',api_utf8_encode($return));
122
-			}
123
-		}
124
-		$_SESSION['course_list'] = $course_list;
121
+                $xajax_response -> addAssign('ajax_list_courses_multiple','innerHTML',api_utf8_encode($return));
122
+            }
123
+        }
124
+        $_SESSION['course_list'] = $course_list;
125 125
 
126
-		return $xajax_response;
127
-	}
126
+        return $xajax_response;
127
+    }
128 128
 }
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/CourseSelectForm.class.php 1 patch
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class CourseSelectForm
13 13
 {
14
-	/**
15
-	 * Display the form
16
-	 * @param array $hidden_fields Hidden fields to add to the form.
17
-	 * @param boolean the document array will be serialize. This is used in the course_copy.php file
18
-	 */
19
-	static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
14
+    /**
15
+     * Display the form
16
+     * @param array $hidden_fields Hidden fields to add to the form.
17
+     * @param boolean the document array will be serialize. This is used in the course_copy.php file
18
+     */
19
+    static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
20 20
     {
21 21
         global $charset;
22 22
         $resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
@@ -134,50 +134,50 @@  discard block
 block discarded – undo
134 134
 		</script>
135 135
 		<?php
136 136
 
137
-		//get destination course title
138
-		if (!empty($hidden_fields['destination_course'])) {
137
+        //get destination course title
138
+        if (!empty($hidden_fields['destination_course'])) {
139 139
             $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name(
140 140
                 $hidden_fields['destination_session']
141 141
             ) . ')' : null;
142 142
 
143 143
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
144
-			echo '<h3>';
145
-			echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
146
-			echo '</h3>';
147
-		}
144
+            echo '<h3>';
145
+            echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
146
+            echo '</h3>';
147
+        }
148 148
         echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
149
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
149
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
150 150
         $icon = Display::returnIconPath('myprogress_bar.gif');
151
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
152
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
151
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
152
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
153 153
 
154
-		if (!empty($hidden_fields['destination_course']) &&
154
+        if (!empty($hidden_fields['destination_course']) &&
155 155
             !empty($hidden_fields['origin_course']) &&
156 156
             !empty($hidden_fields['destination_session']) &&
157 157
             !empty($hidden_fields['origin_session'])
158 158
         ) {
159
-			echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
160
-			echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
161
-			echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
162
-			echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
163
-		}
159
+            echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
160
+            echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
161
+            echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
162
+            echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
163
+        }
164 164
 
165
-		$element_count = 0;
165
+        $element_count = 0;
166 166
         $forum_categories = array();
167 167
         $forums = array();
168 168
         $forum_topics = array();
169 169
 
170 170
         echo '<p>';
171
-		echo get_lang('SelectResources');
172
-		echo '</p>';
171
+        echo get_lang('SelectResources');
172
+        echo '</p>';
173 173
 
174 174
         Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
175 175
 
176 176
         foreach ($course->resources as $type => $resources) {
177 177
             if (count($resources) > 0) {
178
-				switch ($type) {
179
-					//Resources to avoid
180
-					case RESOURCE_FORUMCATEGORY:
178
+                switch ($type) {
179
+                    //Resources to avoid
180
+                    case RESOURCE_FORUMCATEGORY:
181 181
                         foreach ($resources as $id => $resource) {
182 182
                             $forum_categories[$id] = $resource;
183 183
                         }
@@ -196,49 +196,49 @@  discard block
 block discarded – undo
196 196
                         $element_count++;
197 197
                         break;
198 198
                     case RESOURCE_LINKCATEGORY:
199
-					case RESOURCE_FORUMPOST:
200
-					case RESOURCE_QUIZQUESTION:
201
-					case RESOURCE_SURVEYQUESTION:
202
-					case RESOURCE_SURVEYINVITATION:
203
-					case RESOURCE_SCORM:
204
-						break;
199
+                    case RESOURCE_FORUMPOST:
200
+                    case RESOURCE_QUIZQUESTION:
201
+                    case RESOURCE_SURVEYQUESTION:
202
+                    case RESOURCE_SURVEYINVITATION:
203
+                    case RESOURCE_SCORM:
204
+                        break;
205 205
                     default :
206
-						echo '<img id="img_'.$type.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$type'".');" />&nbsp;';
207
-						echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
208
-						echo '<div id="div_'.$type.'">';
209
-						if ($type == RESOURCE_LEARNPATH) {
210
-    						Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
211
-    						Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
212
-						}
213
-						if ($type == RESOURCE_DOCUMENT) {
206
+                        echo '<img id="img_'.$type.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$type'".');" />&nbsp;';
207
+                        echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
208
+                        echo '<div id="div_'.$type.'">';
209
+                        if ($type == RESOURCE_LEARNPATH) {
210
+                            Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
211
+                            Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
212
+                        }
213
+                        if ($type == RESOURCE_DOCUMENT) {
214 214
                             if (api_get_setting('show_glossary_in_documents') != 'none') {
215 215
                                 Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
216 216
                             }
217
-						}
217
+                        }
218 218
 
219
-						echo '<blockquote>';
219
+                        echo '<blockquote>';
220 220
                         echo '<div class="btn-group">';
221
-						echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
221
+                        echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
222 222
                         echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
223
-						echo '</div><br />';
223
+                        echo '</div><br />';
224 224
 
225
-						foreach ($resources as $id => $resource) {
225
+                        foreach ($resources as $id => $resource) {
226 226
                             if ($resource) {
227
-								// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
227
+                                // Event obj in 1.9.x in 1.10.x the class is CalendarEvent
228 228
                                 Coursecopy\Resource::setClassType($resource);
229 229
                                 echo '<label class="checkbox">';
230 230
                                 echo '<input type="checkbox" name="resource['.$type.']['.$id.']"  id="resource['.$type.']['.$id.']" />';
231 231
                                 $resource->show();
232 232
                                 echo '</label>';
233 233
                             }
234
-						}
235
-						echo '</blockquote>';
236
-						echo '</div>';
237
-						echo '<script language="javascript">exp('."'$type'".')</script>';
238
-						$element_count++;
234
+                        }
235
+                        echo '</blockquote>';
236
+                        echo '</div>';
237
+                        echo '<script language="javascript">exp('."'$type'".')</script>';
238
+                        $element_count++;
239 239
                 }
240
-			}
241
-		}
240
+            }
241
+        }
242 242
 
243 243
         //Fixes forum order
244 244
         if (!empty($forum_categories)) {
@@ -294,65 +294,65 @@  discard block
 block discarded – undo
294 294
             echo '<script language="javascript">exp('."'$type'".')</script>';
295 295
         }
296 296
 
297
-		if ($avoid_serialize) {
298
-			/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
297
+        if ($avoid_serialize) {
298
+            /*Documents are avoided due the huge amount of memory that the serialize php function "eats"
299 299
 			(when there are directories with hundred/thousand of files) */
300
-			// this is a known issue of serialize
301
-			$course->resources['document']= null;
302
-		}
300
+            // this is a known issue of serialize
301
+            $course->resources['document']= null;
302
+        }
303 303
 
304
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
304
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
305 305
 
306
-		if (is_array($hidden_fields)) {
307
-			foreach ($hidden_fields as $key => $value) {
308
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
309
-			}
310
-		}
306
+        if (is_array($hidden_fields)) {
307
+            foreach ($hidden_fields as $key => $value) {
308
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
309
+            }
310
+        }
311 311
 
312 312
         $recycleOption = isset($_POST['recycle_option']) ? true : false;
313 313
 
314
-		if (empty($element_count)) {
315
-		    Display::display_warning_message(get_lang('NoDataAvailable'));
316
-		} else {
317
-    		if (!empty($hidden_fields['destination_session'])) {
318
-    			echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
314
+        if (empty($element_count)) {
315
+            Display::display_warning_message(get_lang('NoDataAvailable'));
316
+        } else {
317
+            if (!empty($hidden_fields['destination_session'])) {
318
+                echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
319 319
                     get_lang('Ok').'</button>';
320
-    		} else {
320
+            } else {
321 321
                 if ($recycleOption) {
322 322
                     echo '<br /><button class="save" type="submit">'.
323 323
                         get_lang('Ok').'</button>';
324 324
                 } else {
325
-    			    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
325
+                    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
326 326
                     get_lang('Ok').'</button>';
327 327
                 }
328
-    		}
329
-		}
328
+            }
329
+        }
330 330
 
331
-		CourseSelectForm :: display_hidden_quiz_questions($course);
332
-		CourseSelectForm :: display_hidden_scorm_directories($course);
333
-		echo '</form>';
334
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
335
-	}
331
+        CourseSelectForm :: display_hidden_quiz_questions($course);
332
+        CourseSelectForm :: display_hidden_scorm_directories($course);
333
+        echo '</form>';
334
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
335
+    }
336 336
 
337 337
     /**
338 338
      * @param $course
339 339
      */
340 340
     static function display_hidden_quiz_questions($course)
341 341
     {
342
-		if(is_array($course->resources)){
343
-			foreach ($course->resources as $type => $resources) {
344
-				if (count($resources) > 0) {
345
-					switch ($type) {
346
-						case RESOURCE_QUIZQUESTION:
347
-							foreach ($resources as $id => $resource) {
348
-								echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
349
-							}
350
-							break;
351
-					}
352
-				}
353
-			}
354
-		}
355
-	}
342
+        if(is_array($course->resources)){
343
+            foreach ($course->resources as $type => $resources) {
344
+                if (count($resources) > 0) {
345
+                    switch ($type) {
346
+                        case RESOURCE_QUIZQUESTION:
347
+                            foreach ($resources as $id => $resource) {
348
+                                echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
349
+                            }
350
+                            break;
351
+                    }
352
+                }
353
+            }
354
+        }
355
+    }
356 356
 
357 357
     /**
358 358
      * @param $course
@@ -360,30 +360,30 @@  discard block
 block discarded – undo
360 360
     static function display_hidden_scorm_directories($course)
361 361
     {
362 362
         if (is_array($course->resources)){
363
-			foreach ($course->resources as $type => $resources) {
364
-				if (count($resources) > 0) {
365
-					switch($type) {
366
-						case RESOURCE_SCORM:
367
-							foreach ($resources as $id => $resource) {
368
-								echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
369
-							}
370
-							break;
371
-					}
372
-				}
373
-			}
374
-		}
375
-	}
363
+            foreach ($course->resources as $type => $resources) {
364
+                if (count($resources) > 0) {
365
+                    switch($type) {
366
+                        case RESOURCE_SCORM:
367
+                            foreach ($resources as $id => $resource) {
368
+                                echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
369
+                            }
370
+                            break;
371
+                    }
372
+                }
373
+            }
374
+        }
375
+    }
376 376
 
377
-	/**
378
-	 * Get the posted course
379
-	 * @param string $from who calls the function?
377
+    /**
378
+     * Get the posted course
379
+     * @param string $from who calls the function?
380 380
      * It can be copy_course, create_backup, import_backup or recycle_course
381 381
      * @param int $session_id
382 382
      * @param string $course_code
383
-	 * @return course The course-object with all resources selected by the user
384
-	 * in the form given by display_form(...)
385
-	 */
386
-	public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
383
+     * @return course The course-object with all resources selected by the user
384
+     * in the form given by display_form(...)
385
+     */
386
+    public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
387 387
     {
388 388
         $course = null;
389 389
 
@@ -393,30 +393,30 @@  discard block
 block discarded – undo
393 393
             return false;
394 394
         }
395 395
 
396
-		// Create the resource DOCUMENT objects
397
-		// Loading the results from the checkboxes of ethe javascript
398
-		$resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
396
+        // Create the resource DOCUMENT objects
397
+        // Loading the results from the checkboxes of ethe javascript
398
+        $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
399 399
 
400
-		$course_info = api_get_course_info($course_code);
401
-		$table_doc = Database::get_course_table(TABLE_DOCUMENT);
402
-		$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
403
-		$course_id = $course_info['real_id'];
400
+        $course_info = api_get_course_info($course_code);
401
+        $table_doc = Database::get_course_table(TABLE_DOCUMENT);
402
+        $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
403
+        $course_id = $course_info['real_id'];
404 404
 
405
-		/* Searching the documents resource that have been set to null because
405
+        /* Searching the documents resource that have been set to null because
406 406
         $avoid_serialize is true in the display_form() function*/
407
-		if ($from == 'copy_course') {
408
-			if (is_array($resource)) {
409
-				$resource = array_keys($resource);
407
+        if ($from == 'copy_course') {
408
+            if (is_array($resource)) {
409
+                $resource = array_keys($resource);
410 410
 
411
-				foreach	($resource as $resource_item) {
411
+                foreach	($resource as $resource_item) {
412 412
 
413
-					$condition_session = '';
414
-					if (!empty($session_id)) {
415
-						$session_id = intval($session_id);
416
-						$condition_session = ' AND d.session_id ='.$session_id;
417
-					}
413
+                    $condition_session = '';
414
+                    if (!empty($session_id)) {
415
+                        $session_id = intval($session_id);
416
+                        $condition_session = ' AND d.session_id ='.$session_id;
417
+                    }
418 418
 
419
-					$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
419
+                    $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
420 420
 							FROM '.$table_doc.' d, '.$table_prop.' p
421 421
 							WHERE
422 422
 							    d.c_id = '.$course_id.' AND
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
                                 p.ref = d.id AND p.visibility != 2 AND
426 426
                                 d.id = '.$resource_item.$condition_session.'
427 427
 							ORDER BY path';
428
-					$db_result = Database::query($sql);
429
-					while ($obj = Database::fetch_object($db_result)) {
428
+                    $db_result = Database::query($sql);
429
+                    while ($obj = Database::fetch_object($db_result)) {
430 430
                         $doc = new Document(
431 431
                             $obj->id,
432 432
                             $obj->path,
@@ -450,25 +450,25 @@  discard block
 block discarded – undo
450 450
                             }
451 451
                             $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
452 452
                         }
453
-					}
454
-				}
455
-			}
456
-		}
453
+                    }
454
+                }
455
+            }
456
+        }
457 457
 
458
-		if (is_array($course->resources)) {
459
-			foreach ($course->resources as $type => $resources) {
458
+        if (is_array($course->resources)) {
459
+            foreach ($course->resources as $type => $resources) {
460 460
 
461
-				switch ($type) {
462
-					case RESOURCE_SURVEYQUESTION:
463
-						foreach($resources as $id => $obj) {
464
-						    if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
461
+                switch ($type) {
462
+                    case RESOURCE_SURVEYQUESTION:
463
+                        foreach($resources as $id => $obj) {
464
+                            if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
465 465
                                 is_array($_POST['resource'][RESOURCE_SURVEY]) &&
466 466
                                 !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))
467 467
                             ) {
468
-								unset($course->resources[$type][$id]);
469
-							}
470
-						}
471
-						break;
468
+                                unset($course->resources[$type][$id]);
469
+                            }
470
+                        }
471
+                        break;
472 472
                     case RESOURCE_FORUMTOPIC:
473 473
                     case RESOURCE_FORUMPOST:
474 474
                        //Add post from topic
@@ -520,62 +520,62 @@  discard block
 block discarded – undo
520 520
                                 }
521 521
                             }
522 522
                         }
523
-					case RESOURCE_LINKCATEGORY :
524
-					case RESOURCE_FORUMCATEGORY :
525
-					case RESOURCE_QUIZQUESTION :
526
-					case RESOURCE_DOCUMENT:
527
-						// Mark folders to import which are not selected by the user to import,
528
-						// but in which a document was selected.
529
-						$documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
530
-						if (!empty($resources) && is_array($resources))
531
-							foreach ($resources as $id => $obj) {
532
-								if (isset($obj->file_type) && $obj->file_type == 'folder' &&
523
+                    case RESOURCE_LINKCATEGORY :
524
+                    case RESOURCE_FORUMCATEGORY :
525
+                    case RESOURCE_QUIZQUESTION :
526
+                    case RESOURCE_DOCUMENT:
527
+                        // Mark folders to import which are not selected by the user to import,
528
+                        // but in which a document was selected.
529
+                        $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
530
+                        if (!empty($resources) && is_array($resources))
531
+                            foreach ($resources as $id => $obj) {
532
+                                if (isset($obj->file_type) && $obj->file_type == 'folder' &&
533 533
                                     !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) &&
534 534
                                     is_array($documents)
535 535
                                 ) {
536
-									foreach ($documents as $id_to_check => $post_value) {
537
-										$obj_to_check = $resources[$id_to_check];
538
-										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
539
-										if ($id_to_check != $id && $obj->path == $shared_path_part) {
540
-											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
541
-											break;
542
-										}
543
-									}
544
-								}
545
-							}
546
-					default :
547
-						if (!empty($resources) && is_array($resources)) {
548
-							foreach ($resources as $id => $obj) {
549
-								$resource_is_used_elsewhere = $course->is_linked_resource($obj);
550
-								// check if document is in a quiz (audio/video)
551
-								if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
552
-									foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
536
+                                    foreach ($documents as $id_to_check => $post_value) {
537
+                                        $obj_to_check = $resources[$id_to_check];
538
+                                        $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
539
+                                        if ($id_to_check != $id && $obj->path == $shared_path_part) {
540
+                                            $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
541
+                                            break;
542
+                                        }
543
+                                    }
544
+                                }
545
+                            }
546
+                    default :
547
+                        if (!empty($resources) && is_array($resources)) {
548
+                            foreach ($resources as $id => $obj) {
549
+                                $resource_is_used_elsewhere = $course->is_linked_resource($obj);
550
+                                // check if document is in a quiz (audio/video)
551
+                                if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
552
+                                    foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
553 553
                                         $quiz = $quiz->obj;
554
-										if (isset($quiz->media) && $quiz->media == $id) {
555
-											$resource_is_used_elsewhere = true;
556
-										}
557
-									}
558
-								}
559
-								if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
560
-									unset($course->resources[$type][$id]);
561
-								}
562
-							}
563
-						}
564
-				}
565
-			}
566
-		}
567
-
568
-		return $course;
569
-	}
570
-
571
-	/**
572
-	 * Display the form session export
573
-	 * @param array $hidden_fields Hidden fields to add to the form.
574
-	 * @param boolean the document array will be serialize. This is used in the course_copy.php file
575
-	 */
576
-	 public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
577
-     {
578
-         ?>
554
+                                        if (isset($quiz->media) && $quiz->media == $id) {
555
+                                            $resource_is_used_elsewhere = true;
556
+                                        }
557
+                                    }
558
+                                }
559
+                                if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
560
+                                    unset($course->resources[$type][$id]);
561
+                                }
562
+                            }
563
+                        }
564
+                }
565
+            }
566
+        }
567
+
568
+        return $course;
569
+    }
570
+
571
+    /**
572
+     * Display the form session export
573
+     * @param array $hidden_fields Hidden fields to add to the form.
574
+     * @param boolean the document array will be serialize. This is used in the course_copy.php file
575
+     */
576
+        public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
577
+        {
578
+            ?>
579 579
 		<script>
580 580
 			function exp(item) {
581 581
 				el = document.getElementById('div_'+item);
@@ -617,65 +617,65 @@  discard block
 block discarded – undo
617 617
 		</script>
618 618
 		<?php
619 619
 
620
-		//get destination course title
621
-		if(!empty($hidden_fields['destination_course'])) {
622
-             if (!empty($hidden_fields['destination_session'])) {
623
-                 $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
624
-             } else {
625
-                 $sessionTitle = null;
626
-             }
620
+        //get destination course title
621
+        if(!empty($hidden_fields['destination_course'])) {
622
+                if (!empty($hidden_fields['destination_session'])) {
623
+                    $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
624
+                } else {
625
+                    $sessionTitle = null;
626
+                }
627 627
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
628
-			echo '<h3>';
629
-				echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
630
-			echo '</h3>';
631
-		}
628
+            echo '<h3>';
629
+                echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
630
+            echo '</h3>';
631
+        }
632 632
 
633
-		echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
634
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
633
+        echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
634
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
635 635
         $icon = Display::returnIconPath('progress_bar.gif');
636
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
637
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
638
-		foreach ($list_course as $course){
639
-			foreach ($course->resources as $type => $resources) {
640
-				if (count($resources) > 0) {
641
-					echo '<img id="img_'.$course->code.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$course->code'".');" />';
642
-					echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
643
-					echo '<div id="div_'.$course->code.'">';
644
-					echo '<blockquote>';
636
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
637
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
638
+        foreach ($list_course as $course){
639
+            foreach ($course->resources as $type => $resources) {
640
+                if (count($resources) > 0) {
641
+                    echo '<img id="img_'.$course->code.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$course->code'".');" />';
642
+                    echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
643
+                    echo '<div id="div_'.$course->code.'">';
644
+                    echo '<blockquote>';
645 645
 
646 646
                     echo '<div class="btn-group">';
647
-					echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
647
+                    echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
648 648
                     echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>";
649
-					echo '</div><br />';
649
+                    echo '</div><br />';
650 650
 
651
-					foreach ($resources as $id => $resource) {
652
-						echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
651
+                    foreach ($resources as $id => $resource) {
652
+                        echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
653 653
                         echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
654
-						$resource->show();
655
-						echo '</label>';
656
-					}
657
-					echo '</blockquote>';
658
-					echo '</div>';
659
-					echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
660
-				}
661
-			}
662
-		}
663
-		if ($avoid_serialize) {
664
-			//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
665
-			// this is a known issue of serialize
666
-			$course->resources['document']= null;
667
-		}
668
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
669
-		if (is_array($hidden_fields)) {
670
-			foreach ($hidden_fields as $key => $value) {
671
-				echo "\n";
672
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
673
-			}
674
-		}
675
-		echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
676
-		CourseSelectForm :: display_hidden_quiz_questions($course);
677
-		CourseSelectForm :: display_hidden_scorm_directories($course);
678
-		echo '</form>';
679
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
680
-	}
654
+                        $resource->show();
655
+                        echo '</label>';
656
+                    }
657
+                    echo '</blockquote>';
658
+                    echo '</div>';
659
+                    echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
660
+                }
661
+            }
662
+        }
663
+        if ($avoid_serialize) {
664
+            //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
665
+            // this is a known issue of serialize
666
+            $course->resources['document']= null;
667
+        }
668
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
669
+        if (is_array($hidden_fields)) {
670
+            foreach ($hidden_fields as $key => $value) {
671
+                echo "\n";
672
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
673
+            }
674
+        }
675
+        echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
676
+        CourseSelectForm :: display_hidden_quiz_questions($course);
677
+        CourseSelectForm :: display_hidden_scorm_directories($course);
678
+        echo '</form>';
679
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
680
+    }
681 681
 }
Please login to merge, or discard this patch.
main/exercice/export/aiken/aiken_classes.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 if (!function_exists('mime_content_type')) {
13 13
 
14
-	/**
15
-	 * @param string $filename
16
-	 */
17
-	function mime_content_type($filename) {
18
-		return DocumentManager::file_get_mime_type((string)$filename);
19
-	}
14
+    /**
15
+     * @param string $filename
16
+     */
17
+    function mime_content_type($filename) {
18
+        return DocumentManager::file_get_mime_type((string)$filename);
19
+    }
20 20
 }
21 21
 
22 22
 /**
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         {
34 34
             case MCUA :
35 35
                 $answer = new AikenAnswerMultipleChoice($this->id);
36
-            	return $answer;
36
+                return $answer;
37 37
             default :
38 38
                 $answer = null;
39 39
                 break;
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
     }
43 43
     function createAnswersForm($form)
44 44
     {
45
-    	return true;
45
+        return true;
46 46
     }
47 47
     function processAnswersCreation($form)
48 48
     {
49
-    	return true;
49
+        return true;
50 50
     }
51 51
 }
52 52
 
Please login to merge, or discard this patch.
main/exercice/export/qti2/qti2_export.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -34,21 +34,21 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @param Ims2Question $question Ims2Question object we want to export.
36 36
      */
37
-     function ImsAssessmentItem($question)
38
-     {
37
+        function ImsAssessmentItem($question)
38
+        {
39 39
         $this->question = $question;
40 40
         $this->answer = $this->question->setAnswer();
41 41
         $this->questionIdent = "QST_" . $question->id ;
42
-     }
43
-
44
-     /**
45
-      * Start the XML flow.
46
-      *
47
-      * This opens the <item> block, with correct attributes.
48
-      *
49
-      */
50
-      function start_item()
51
-      {
42
+        }
43
+
44
+        /**
45
+         * Start the XML flow.
46
+         *
47
+         * This opens the <item> block, with correct attributes.
48
+         *
49
+         */
50
+        function start_item()
51
+        {
52 52
         $string = '<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
53 53
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54 54
                     xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 imsqti_v2p1.xsd"
@@ -56,55 +56,55 @@  discard block
 block discarded – undo
56 56
                     title="'.htmlspecialchars(formatExerciseQtiTitle($this->question->selectTitle())).'">'."\n";
57 57
 
58 58
         return $string;
59
-      }
60
-
61
-      /**
62
-       * End the XML flow, closing the </item> tag.
63
-       *
64
-       */
65
-      function end_item()
66
-      {
59
+        }
60
+
61
+        /**
62
+         * End the XML flow, closing the </item> tag.
63
+         *
64
+         */
65
+        function end_item()
66
+        {
67 67
         return "</assessmentItem>\n";
68
-      }
69
-
70
-     /**
71
-      * Start the itemBody
72
-      *
73
-      */
74
-     function start_item_body()
75
-     {
68
+        }
69
+
70
+        /**
71
+         * Start the itemBody
72
+         *
73
+         */
74
+        function start_item_body()
75
+        {
76 76
         return '  <itemBody>' . "\n";
77
-     }
78
-
79
-     /**
80
-      * End the itemBody part.
81
-      *
82
-      */
83
-     function end_item_body()
84
-     {
77
+        }
78
+
79
+        /**
80
+         * End the itemBody part.
81
+         *
82
+         */
83
+        function end_item_body()
84
+        {
85 85
         return "  </itemBody>\n";
86
-     }
87
-
88
-     /**
89
-      * add the response processing template used.
90
-      *
91
-      */
92
-
93
-      function add_response_processing()
94
-      {
95
-          return '  <responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_correct"/>' . "\n";
96
-      }
97
-
98
-     /**
99
-      * Export the question as an IMS/QTI Item.
100
-      *
101
-      * This is a default behaviour, some classes may want to override this.
102
-      *
103
-      * @param $standalone: Boolean stating if it should be exported as a stand-alone question
104
-      * @return string string, the XML flow for an Item.
105
-      */
106
-     function export($standalone = false)
107
-     {
86
+        }
87
+
88
+        /**
89
+         * add the response processing template used.
90
+         *
91
+         */
92
+
93
+        function add_response_processing()
94
+        {
95
+            return '  <responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_correct"/>' . "\n";
96
+        }
97
+
98
+        /**
99
+         * Export the question as an IMS/QTI Item.
100
+         *
101
+         * This is a default behaviour, some classes may want to override this.
102
+         *
103
+         * @param $standalone: Boolean stating if it should be exported as a stand-alone question
104
+         * @return string string, the XML flow for an Item.
105
+         */
106
+        function export($standalone = false)
107
+        {
108 108
         $head = $foot = "";
109 109
 
110 110
         if ($standalone) {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             .$foot;
132 132
 
133 133
         return $res;
134
-     }
134
+        }
135 135
 }
136 136
 
137 137
 /**
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
     function export_presentation()
194 194
     {
195 195
         $out = "<presentation_material><flow_mat><material>\n"
196
-             . "  <mattext><![CDATA[" . formatExerciseQtiDescription($this->exercise->selectDescription()) . "]]></mattext>\n"
197
-             . "</material></flow_mat></presentation_material>\n";
196
+                . "  <mattext><![CDATA[" . formatExerciseQtiDescription($this->exercise->selectDescription()) . "]]></mattext>\n"
197
+                . "</material></flow_mat></presentation_material>\n";
198 198
         return $out;
199 199
     }
200 200
 
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
         $out = '';
209 209
         if ($n = $this->exercise->getShuffle()) {
210 210
             $out.= "<selection_ordering>"
211
-                 . "  <selection>\n"
212
-                 . "    <selection_number>" . $n . "</selection_number>\n"
213
-                 . "  </selection>\n"
214
-                 . '  <order order_type="Random" />'
215
-                 . "\n</selection_ordering>\n";
211
+                    . "  <selection>\n"
212
+                    . "    <selection_number>" . $n . "</selection_number>\n"
213
+                    . "  </selection>\n"
214
+                    . '  <order order_type="Random" />'
215
+                    . "\n</selection_ordering>\n";
216 216
         } else {
217 217
             $out.= '<selection_ordering sequence_type="Normal">' . "\n"
218
-                 . "  <selection />\n"
219
-                 . "</selection_ordering>\n";
218
+                    . "  <selection />\n"
219
+                    . "</selection_ordering>\n";
220 220
         }
221 221
 
222 222
         return $out;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     {
231 231
         $out = "";
232 232
         foreach ($this->exercise->selectQuestionList() as $q) {
233
-        	$out .= export_question_qti($q, false);
233
+            $out .= export_question_qti($q, false);
234 234
         }
235 235
         return $out;
236 236
     }
@@ -247,18 +247,18 @@  discard block
 block discarded – undo
247 247
         $head = $foot = "";
248 248
         if ($standalone) {
249 249
             $head = '<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>' . "\n"
250
-                  . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
251
-                  . "<questestinterop>\n";
250
+                    . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
251
+                    . "<questestinterop>\n";
252 252
             $foot = "</questestinterop>\n";
253 253
         }
254 254
         $out = $head
255
-             . $this->start_section()
256
-             . $this->export_duration()
257
-             . $this->export_presentation()
258
-             . $this->export_ordering()
259
-             . $this->export_questions()
260
-             . $this->end_section()
261
-             . $foot;
255
+                . $this->start_section()
256
+                . $this->export_duration()
257
+                . $this->export_presentation()
258
+                . $this->export_ordering()
259
+                . $this->export_questions()
260
+                . $this->end_section()
261
+                . $foot;
262 262
 
263 263
         return $out;
264 264
     }
@@ -304,97 +304,97 @@  discard block
 block discarded – undo
304 304
      * @param $question The Question object we want to export.
305 305
      * @author Anamd Tihon
306 306
      */
307
-     function ImsItem($question)
308
-     {
307
+        function ImsItem($question)
308
+        {
309 309
         $this->question = $question;
310 310
         $this->answer = $question->answer;
311 311
         $this->questionIdent = "QST_" . $question->selectId() ;
312
-     }
313
-
314
-     /**
315
-      * Start the XML flow.
316
-      *
317
-      * This opens the <item> block, with correct attributes.
318
-      *
319
-      * @author Amand Tihon <[email protected]>
320
-      */
321
-      function start_item()
322
-      {
312
+        }
313
+
314
+        /**
315
+         * Start the XML flow.
316
+         *
317
+         * This opens the <item> block, with correct attributes.
318
+         *
319
+         * @author Amand Tihon <[email protected]>
320
+         */
321
+        function start_item()
322
+        {
323 323
         return '<item title="' . cleanAttribute(formatExerciseQtiDescription($this->question->selectTitle())) . '" ident="' . $this->questionIdent . '">' . "\n";
324
-      }
325
-
326
-      /**
327
-       * End the XML flow, closing the </item> tag.
328
-       *
329
-       * @author Amand Tihon <[email protected]>
330
-       */
331
-      function end_item()
332
-      {
324
+        }
325
+
326
+        /**
327
+         * End the XML flow, closing the </item> tag.
328
+         *
329
+         * @author Amand Tihon <[email protected]>
330
+         */
331
+        function end_item()
332
+        {
333 333
         return "</item>\n";
334
-      }
335
-
336
-     /**
337
-      * Create the opening, with the question itself.
338
-      *
339
-      * This means it opens the <presentation> but doesn't close it, as this is the role of end_presentation().
340
-      * In between, the export_responses from the subclass should have been called.
341
-      *
342
-      * @author Amand Tihon <[email protected]>
343
-      */
344
-     function start_presentation()
345
-     {
334
+        }
335
+
336
+        /**
337
+         * Create the opening, with the question itself.
338
+         *
339
+         * This means it opens the <presentation> but doesn't close it, as this is the role of end_presentation().
340
+         * In between, the export_responses from the subclass should have been called.
341
+         *
342
+         * @author Amand Tihon <[email protected]>
343
+         */
344
+        function start_presentation()
345
+        {
346 346
         return '<presentation label="' . $this->questionIdent . '"><flow>' . "\n"
347
-             . '<material><mattext>' . formatExerciseQtiDescription($this->question->selectDescription()) . "</mattext></material>\n";
348
-     }
349
-
350
-     /**
351
-      * End the </presentation> part, opened by export_header.
352
-      *
353
-      * @author Amand Tihon <[email protected]>
354
-      */
355
-     function end_presentation()
356
-     {
347
+                . '<material><mattext>' . formatExerciseQtiDescription($this->question->selectDescription()) . "</mattext></material>\n";
348
+        }
349
+
350
+        /**
351
+         * End the </presentation> part, opened by export_header.
352
+         *
353
+         * @author Amand Tihon <[email protected]>
354
+         */
355
+        function end_presentation()
356
+        {
357 357
         return "</flow></presentation>\n";
358
-     }
359
-
360
-     /**
361
-      * Start the response processing, and declare the default variable, SCORE, at 0 in the outcomes.
362
-      *
363
-      * @author Amand Tihon <[email protected]>
364
-      */
365
-     function start_processing()
366
-     {
358
+        }
359
+
360
+        /**
361
+         * Start the response processing, and declare the default variable, SCORE, at 0 in the outcomes.
362
+         *
363
+         * @author Amand Tihon <[email protected]>
364
+         */
365
+        function start_processing()
366
+        {
367 367
         return '<resprocessing><outcomes><decvar vartype="Integer" defaultval="0" /></outcomes>' . "\n";
368
-     }
369
-
370
-     /**
371
-      * End the response processing part.
372
-      *
373
-      * @author Amand Tihon <[email protected]>
374
-      */
375
-     function end_processing()
376
-     {
368
+        }
369
+
370
+        /**
371
+         * End the response processing part.
372
+         *
373
+         * @author Amand Tihon <[email protected]>
374
+         */
375
+        function end_processing()
376
+        {
377 377
         return "</resprocessing>\n";
378
-     }
379
-
380
-     /**
381
-      * Export the question as an IMS/QTI Item.
382
-      *
383
-      * This is a default behaviour, some classes may want to override this.
384
-      *
385
-      * @param $standalone: Boolean stating if it should be exported as a stand-alone question
386
-      * @return string string, the XML flow for an Item.
387
-      * @author Amand Tihon <[email protected]>
388
-      */
389
-     function export($standalone = False)
390
-     {
378
+        }
379
+
380
+        /**
381
+         * Export the question as an IMS/QTI Item.
382
+         *
383
+         * This is a default behaviour, some classes may want to override this.
384
+         *
385
+         * @param $standalone: Boolean stating if it should be exported as a stand-alone question
386
+         * @return string string, the XML flow for an Item.
387
+         * @author Amand Tihon <[email protected]>
388
+         */
389
+        function export($standalone = False)
390
+        {
391 391
         global $charset;
392 392
         $head = $foot = "";
393 393
 
394 394
         if ($standalone) {
395 395
             $head = '<?xml version = "1.0" encoding = "'.$charset.'" standalone = "no"?>' . "\n"
396
-                  . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
397
-                  . "<questestinterop>\n";
396
+                    . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
397
+                    . "<questestinterop>\n";
398 398
             $foot = "</questestinterop>\n";
399 399
         }
400 400
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             . $this->answer->imsExportFeedback($this->questionIdent)
410 410
             . $this->end_item()
411 411
             . $foot;
412
-     }
412
+        }
413 413
 }
414 414
 
415 415
 /**
@@ -447,9 +447,9 @@  discard block
 block discarded – undo
447 447
     $question->type = $qst->type;
448 448
     $question->question = $qst->question;
449 449
     $question->description = $qst->description;
450
-	$question->weighting=$qst->weighting;
451
-	$question->position=$qst->position;
452
-	$question->picture=$qst->picture;
450
+    $question->weighting=$qst->weighting;
451
+    $question->position=$qst->position;
452
+    $question->picture=$qst->picture;
453 453
     $ims = new ImsAssessmentItem($question);
454 454
 
455 455
     return $ims->export($standalone);
Please login to merge, or discard this patch.