Passed
Push — 1.10.x ( 7dd9ca...040b8d )
by
unknown
59:07
created
main/inc/lib/blog.lib.php 1 patch
Indentation   +1836 added lines, -1837 removed lines patch added patch discarded remove patch
@@ -6,115 +6,114 @@  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
-			// init
30
-			$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
31
-
32
-			$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
+            // init
29
+            $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
30
+
31
+            $sql = "SELECT blog_name
33 32
 					FROM " . $tbl_blogs . "
34 33
 					WHERE c_id = $course_id AND blog_id = " . intval($blog_id);
35 34
 
36
-			$result = Database::query($sql);
37
-			$blog = Database::fetch_array($result);
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
35
+            $result = Database::query($sql);
36
+            $blog = Database::fetch_array($result);
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 Integer $course_id Id
100
-	 * @param String $title
101
-	 * @param Text $description
102
-	 */
103
-	public static function create_blog($title, $subtitle)
104
-	{
105
-		$_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 Integer $course_id Id
99
+     * @param String $title
100
+     * @param Text $description
101
+     */
102
+    public static function create_blog($title, $subtitle)
103
+    {
104
+        $_user = api_get_user_info();
106 105
         $course_id = api_get_course_int_id();
107 106
 
108
-		$current_date=date('Y-m-d H:i:s',time());
109
-		$session_id = api_get_session_id();
110
-		// Tabel definitions
107
+        $current_date=date('Y-m-d H:i:s',time());
108
+        $session_id = api_get_session_id();
109
+        // Tabel definitions
111 110
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
112 111
         $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
113 112
         $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
114 113
         $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
115 114
 
116
-		//verified if exist blog
117
-		$sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
115
+        //verified if exist blog
116
+        $sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
118 117
 			  	WHERE
119 118
 			  	    c_id = '.$course_id.' AND
120 119
 			  	    blog_name="'.Database::escape_string($title).'" AND
@@ -123,9 +122,9 @@  discard block
 block discarded – undo
123 122
         $info_count = Database::result($res, 0, 0);
124 123
 
125 124
         if ($info_count == 0) {
126
-			// Create the blog
125
+            // Create the blog
127 126
             $params = [
128
-				'blog_id' => 0,
127
+                'blog_id' => 0,
129 128
                 'c_id' => $course_id,
130 129
                 'blog_name' => $title,
131 130
                 'blog_subtitle' =>  $subtitle,
@@ -133,14 +132,14 @@  discard block
 block discarded – undo
133 132
                 'visibility' => 1 ,
134 133
                 'session_id' => $session_id,
135 134
             ];
136
-			$this_blog_id = Database::insert($tbl_blogs, $params);
135
+            $this_blog_id = Database::insert($tbl_blogs, $params);
137 136
 
138
-			if ($this_blog_id > 0) {
137
+            if ($this_blog_id > 0) {
139 138
 
140 139
                 $sql = "UPDATE $tbl_blogs SET blog_id = iid WHERE iid = $this_blog_id";
141 140
                 Database::query($sql);
142 141
 
143
-				// insert into item_property
142
+                // insert into item_property
144 143
                 api_item_property_update(
145 144
                     api_get_course_info(),
146 145
                     TOOL_BLOGS,
@@ -148,12 +147,12 @@  discard block
 block discarded – undo
148 147
                     'BlogAdded',
149 148
                     api_get_user_id()
150 149
                 );
151
-			}
150
+            }
152 151
 
153
-			// Make first post. :)
152
+            // Make first post. :)
154 153
 
155 154
             $params = [
156
-				'post_id' => 0,
155
+                'post_id' => 0,
157 156
                 'c_id' => $course_id,
158 157
                 'title' => get_lang("Welcome"),
159 158
                 'full_text' => get_lang('FirstPostText'),
@@ -167,10 +166,10 @@  discard block
 block discarded – undo
167 166
                 Database::query($sql);
168 167
             }
169 168
 
170
-			// Put it on course homepage
171
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id)
169
+            // Put it on course homepage
170
+            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id)
172 171
 					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')";
173
-			Database::query($sql);
172
+            Database::query($sql);
174 173
 
175 174
             $toolId = Database::insert_id();
176 175
             if ($toolId) {
@@ -178,37 +177,37 @@  discard block
 block discarded – undo
178 177
                 Database::query($sql);
179 178
             }
180 179
 
181
-			// Subscribe the teacher to this blog
182
-			Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
183
-		}
184
-	}
185
-
186
-	/**
187
-	 * Update title and subtitle of a blog in the given course
188
-	 * @author Toon Keppens
189
-	 * @param Integer $course_id Id
190
-	 * @param String $title
191
-	 * @param Text $description
192
-	 */
193
-	public static function edit_blog($blog_id, $title, $subtitle)
194
-	{
195
-		// Table definitions
196
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
197
-		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
180
+            // Subscribe the teacher to this blog
181
+            Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
182
+        }
183
+    }
184
+
185
+    /**
186
+     * Update title and subtitle of a blog in the given course
187
+     * @author Toon Keppens
188
+     * @param Integer $course_id Id
189
+     * @param String $title
190
+     * @param Text $description
191
+     */
192
+    public static function edit_blog($blog_id, $title, $subtitle)
193
+    {
194
+        // Table definitions
195
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
196
+        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
198 197
 
199 198
         $course_id = api_get_course_int_id();
200 199
 
201
-		// Update the blog
202
-		$sql = "UPDATE $tbl_blogs SET
200
+        // Update the blog
201
+        $sql = "UPDATE $tbl_blogs SET
203 202
 		        blog_name = '".Database::escape_string($title)."',
204 203
 		        blog_subtitle = '".Database::escape_string($subtitle)."'
205 204
 		        WHERE
206 205
 		            c_id = $course_id AND
207 206
 		            blog_id ='".Database::escape_string((int)$blog_id)."'
208 207
                 LIMIT 1";
209
-		Database::query($sql);
208
+        Database::query($sql);
210 209
 
211
-		//update item_property (update)
210
+        //update item_property (update)
212 211
         api_item_property_update(
213 212
             api_get_course_info(),
214 213
             TOOL_BLOGS,
@@ -217,60 +216,60 @@  discard block
 block discarded – undo
217 216
             api_get_user_id()
218 217
         );
219 218
 
220
-		// Update course homepage link
221
-		$sql = "UPDATE $tbl_tool SET
219
+        // Update course homepage link
220
+        $sql = "UPDATE $tbl_tool SET
222 221
 		        name = '".Database::escape_string($title)."'
223 222
 		        WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int)$blog_id."' LIMIT 1";
224
-		Database::query($sql);
225
-	}
226
-
227
-	/**
228
-	 * Deletes a blog and it's posts from the course database
229
-	 * @author Toon Keppens
230
-	 * @param Integer $blog_id
231
-	 */
232
-	public static function delete_blog($blog_id)
233
-	{
234
-		// Init
223
+        Database::query($sql);
224
+    }
225
+
226
+    /**
227
+     * Deletes a blog and it's posts from the course database
228
+     * @author Toon Keppens
229
+     * @param Integer $blog_id
230
+     */
231
+    public static function delete_blog($blog_id)
232
+    {
233
+        // Init
235 234
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
236 235
         $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
237 236
         $tbl_blogs_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS);
238 237
         $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
239 238
         $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
240 239
         $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
241
-		$tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
240
+        $tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
242 241
 
243 242
         $course_id = api_get_course_int_id();
244 243
         $blog_id = intval($blog_id);
245 244
 
246
-		// Delete posts from DB and the attachments
247
-		delete_all_blog_attachment($blog_id);
245
+        // Delete posts from DB and the attachments
246
+        delete_all_blog_attachment($blog_id);
248 247
 
249
-		//Delete comments
250
-		$sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
251
-   		Database::query($sql);
248
+        //Delete comments
249
+        $sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
250
+            Database::query($sql);
252 251
 
253
-		// Delete posts
254
-   		$sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
255
-   		Database::query($sql);
252
+        // Delete posts
253
+            $sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
254
+            Database::query($sql);
256 255
 
257
-		// Delete tasks
258
-		$sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
259
-		Database::query($sql);
256
+        // Delete tasks
257
+        $sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
258
+        Database::query($sql);
260 259
 
261
-		// Delete ratings
262
-		$sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
263
-		Database::query($sql);
260
+        // Delete ratings
261
+        $sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
262
+        Database::query($sql);
264 263
 
265
-		// Delete blog
266
-		$sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
267
-		Database::query($sql);
264
+        // Delete blog
265
+        $sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
266
+        Database::query($sql);
268 267
 
269
-		// Delete from course homepage
270
-		$sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
271
-		Database::query($sql);
268
+        // Delete from course homepage
269
+        $sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
270
+        Database::query($sql);
272 271
 
273
-		//update item_property (delete)
272
+        //update item_property (delete)
274 273
         api_item_property_update(
275 274
             api_get_course_info(),
276 275
             TOOL_BLOGS,
@@ -278,152 +277,152 @@  discard block
 block discarded – undo
278 277
             'delete',
279 278
             api_get_user_id()
280 279
         );
281
-	}
282
-
283
-	/**
284
-	 * Creates a new post in a given blog
285
-	 * @author Toon Keppens
286
-	 * @param String $title
287
-	 * @param String $full_text
288
-	 * @param Integer $blog_id
289
-	 */
290
-	public static function create_post($title, $full_text, $file_comment, $blog_id)
291
-	{
292
-		$_user = api_get_user_info();
293
-		$_course = api_get_course_info();
294
-		$course_id = $_course['real_id'];
295
-
296
-		$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
297
-		$upload_ok=true;
298
-		$has_attachment=false;
299
-		$current_date = api_get_utc_datetime();
300
-
301
-		if (!empty($_FILES['user_upload']['name'])) {
302
-			$upload_ok = process_uploaded_file($_FILES['user_upload']);
303
-			$has_attachment=true;
304
-		}
305
-
306
-		if ($upload_ok) {
307
-			// Table Definitions
308
-			$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
309
-
310
-			// Create the post
311
-			$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
280
+    }
281
+
282
+    /**
283
+     * Creates a new post in a given blog
284
+     * @author Toon Keppens
285
+     * @param String $title
286
+     * @param String $full_text
287
+     * @param Integer $blog_id
288
+     */
289
+    public static function create_post($title, $full_text, $file_comment, $blog_id)
290
+    {
291
+        $_user = api_get_user_info();
292
+        $_course = api_get_course_info();
293
+        $course_id = $_course['real_id'];
294
+
295
+        $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
296
+        $upload_ok=true;
297
+        $has_attachment=false;
298
+        $current_date = api_get_utc_datetime();
299
+
300
+        if (!empty($_FILES['user_upload']['name'])) {
301
+            $upload_ok = process_uploaded_file($_FILES['user_upload']);
302
+            $has_attachment=true;
303
+        }
304
+
305
+        if ($upload_ok) {
306
+            // Table Definitions
307
+            $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
308
+
309
+            // Create the post
310
+            $sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
312 311
 					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');";
313 312
 
314
-			Database::query($sql);
315
-			$last_post_id = Database::insert_id();
313
+            Database::query($sql);
314
+            $last_post_id = Database::insert_id();
316 315
 
317 316
             if ($last_post_id) {
318 317
                 $sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $last_post_id";
319 318
                 Database::query($sql);
320 319
             }
321 320
 
322
-			if ($has_attachment) {
323
-				$courseDir   = $_course['path'].'/upload/blog';
324
-				$sys_course_path = api_get_path(SYS_COURSE_PATH);
325
-				$updir = $sys_course_path.$courseDir;
326
-
327
-				// Try to add an extension to the file if it hasn't one
328
-				$new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
329
-
330
-				// user's file name
331
-				$file_name = $_FILES['user_upload']['name'];
332
-
333
-				if (!filter_extension($new_file_name)) {
334
-					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
335
-				} else {
336
-					$new_file_name = uniqid('');
337
-					$new_path = $updir.'/'.$new_file_name;
338
-					$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
339
-					$comment = Database::escape_string($file_comment);
340
-
341
-					// Storing the attachments if any
342
-					if ($result) {
343
-						$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
344
-							   "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' )";
345
-						Database::query($sql);
321
+            if ($has_attachment) {
322
+                $courseDir   = $_course['path'].'/upload/blog';
323
+                $sys_course_path = api_get_path(SYS_COURSE_PATH);
324
+                $updir = $sys_course_path.$courseDir;
325
+
326
+                // Try to add an extension to the file if it hasn't one
327
+                $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
328
+
329
+                // user's file name
330
+                $file_name = $_FILES['user_upload']['name'];
331
+
332
+                if (!filter_extension($new_file_name)) {
333
+                    Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
334
+                } else {
335
+                    $new_file_name = uniqid('');
336
+                    $new_path = $updir.'/'.$new_file_name;
337
+                    $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
338
+                    $comment = Database::escape_string($file_comment);
339
+
340
+                    // Storing the attachments if any
341
+                    if ($result) {
342
+                        $sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
343
+                                "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' )";
344
+                        Database::query($sql);
346 345
                         $id = Database::insert_id();
347 346
                         if ($id) {
348 347
                             $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
349 348
                             Database::query($sql);
350 349
                         }
351
-					}
352
-				}
353
-			}
354
-		} else {
355
-			Display::display_error_message(get_lang('UplNoFileUploaded'));
356
-		}
357
-	}
358
-
359
-	/**
360
-	 * Edits a post in a given blog
361
-	 * @author Toon Keppens
362
-	 * @param Integer $blog_id
363
-	 * @param String $title
364
-	 * @param String $full_text
365
-	 * @param Integer $blog_id
366
-	 */
367
-	public static function edit_post($post_id, $title, $full_text, $blog_id)
368
-	{
369
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
350
+                    }
351
+                }
352
+            }
353
+        } else {
354
+            Display::display_error_message(get_lang('UplNoFileUploaded'));
355
+        }
356
+    }
357
+
358
+    /**
359
+     * Edits a post in a given blog
360
+     * @author Toon Keppens
361
+     * @param Integer $blog_id
362
+     * @param String $title
363
+     * @param String $full_text
364
+     * @param Integer $blog_id
365
+     */
366
+    public static function edit_post($post_id, $title, $full_text, $blog_id)
367
+    {
368
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
370 369
         $course_id = api_get_course_int_id();
371 370
 
372
-		// Create the post
373
-		$sql = "UPDATE $tbl_blogs_posts SET
371
+        // Create the post
372
+        $sql = "UPDATE $tbl_blogs_posts SET
374 373
 		        title = '" . Database::escape_string($title)."',
375 374
 		        full_text = '" . Database::escape_string($full_text)."'
376 375
 		        WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."'
377 376
 		        LIMIT 1 ";
378
-		Database::query($sql);
379
-	}
380
-
381
-	/**
382
-	 * Deletes an article and it's comments
383
-	 * @author Toon Keppens
384
-	 * @param int $blog_id
385
-	 * @param int $post_id
386
-	 */
387
-	public static function delete_post($blog_id, $post_id)
388
-	{
389
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
390
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
391
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
377
+        Database::query($sql);
378
+    }
379
+
380
+    /**
381
+     * Deletes an article and it's comments
382
+     * @author Toon Keppens
383
+     * @param int $blog_id
384
+     * @param int $post_id
385
+     */
386
+    public static function delete_post($blog_id, $post_id)
387
+    {
388
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
389
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
390
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
392 391
 
393 392
         $course_id = api_get_course_int_id();
394 393
 
395
-		// Delete ratings on this comment
396
-		$sql = "DELETE FROM $tbl_blogs_rating
394
+        // Delete ratings on this comment
395
+        $sql = "DELETE FROM $tbl_blogs_rating
397 396
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'";
398
-		Database::query($sql);
397
+        Database::query($sql);
399 398
 
400
-		// Delete the post
401
-		$sql = "DELETE FROM $tbl_blogs_posts
399
+        // Delete the post
400
+        $sql = "DELETE FROM $tbl_blogs_posts
402 401
 				WHERE c_id = $course_id AND post_id = '".(int)$post_id."'";
403
-		Database::query($sql);
402
+        Database::query($sql);
404 403
 
405
-		// Delete the comments
406
-		$sql = "DELETE FROM $tbl_blogs_comments
404
+        // Delete the comments
405
+        $sql = "DELETE FROM $tbl_blogs_comments
407 406
 				WHERE c_id = $course_id AND post_id = '".(int)$post_id."' AND blog_id = '".(int)$blog_id."'";
408
-		Database::query($sql);
409
-
410
-		// Delete posts and attachments
411
-		delete_all_blog_attachment($blog_id,$post_id);
412
-	}
413
-
414
-	/**
415
-	 * Creates a comment on a post in a given blog
416
-	 * @author Toon Keppens
417
-	 * @param String $title
418
-	 * @param String $full_text
419
-	 * @param Integer $blog_id
420
-	 * @param Integer $post_id
421
-	 * @param Integer $parent_id
422
-	 */
423
-	public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
424
-	{
425
-		$_user = api_get_user_info();
426
-		$_course = api_get_course_info();
407
+        Database::query($sql);
408
+
409
+        // Delete posts and attachments
410
+        delete_all_blog_attachment($blog_id,$post_id);
411
+    }
412
+
413
+    /**
414
+     * Creates a comment on a post in a given blog
415
+     * @author Toon Keppens
416
+     * @param String $title
417
+     * @param String $full_text
418
+     * @param Integer $blog_id
419
+     * @param Integer $post_id
420
+     * @param Integer $parent_id
421
+     */
422
+    public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
423
+    {
424
+        $_user = api_get_user_info();
425
+        $_course = api_get_course_info();
427 426
         $blog_table_attachment 	= Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
428 427
 
429 428
         $upload_ok = true;
@@ -431,55 +430,55 @@  discard block
 block discarded – undo
431 430
         $current_date = api_get_utc_datetime();
432 431
         $course_id = api_get_course_int_id();
433 432
 
434
-		if (!empty($_FILES['user_upload']['name'])) {
435
-			$upload_ok = process_uploaded_file($_FILES['user_upload']);
436
-			$has_attachment=true;
437
-		}
433
+        if (!empty($_FILES['user_upload']['name'])) {
434
+            $upload_ok = process_uploaded_file($_FILES['user_upload']);
435
+            $has_attachment=true;
436
+        }
438 437
 
439
-		if ($upload_ok) {
440
-			// Table Definition
441
-			$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
438
+        if ($upload_ok) {
439
+            // Table Definition
440
+            $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
442 441
 
443
-			// Create the comment
444
-			$sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
442
+            // Create the comment
443
+            $sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
445 444
 					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."')";
446
-			Database::query($sql);
445
+            Database::query($sql);
447 446
 
448
-			// Empty post values, or they are shown on the page again
449
-			$last_id = Database::insert_id();
447
+            // Empty post values, or they are shown on the page again
448
+            $last_id = Database::insert_id();
450 449
 
451 450
             if ($last_id) {
452 451
                 $sql = "UPDATE $tbl_blogs_comments SET comment_id = iid WHERE iid = $last_id";
453 452
                 Database::query($sql);
454 453
             }
455 454
 
456
-			if ($has_attachment) {
457
-				$courseDir   = $_course['path'].'/upload/blog';
458
-				$sys_course_path = api_get_path(SYS_COURSE_PATH);
459
-				$updir = $sys_course_path.$courseDir;
460
-
461
-				// Try to add an extension to the file if it hasn't one
462
-				$new_file_name = add_ext_on_mime(
463
-					stripslashes($_FILES['user_upload']['name']),
464
-					$_FILES['user_upload']['type']
465
-				);
466
-
467
-				// user's file name
468
-				$file_name =$_FILES['user_upload']['name'];
469
-
470
-				if (!filter_extension($new_file_name)) {
471
-					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
472
-				} else {
473
-					$new_file_name = uniqid('');
474
-					$new_path=$updir.'/'.$new_file_name;
475
-					$result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
476
-					$comment = Database::escape_string($file_comment);
477
-
478
-					// Storing the attachments if any
479
-					if ($result) {
480
-						$sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
481
-							 "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."'  )";
482
-						Database::query($sql);
455
+            if ($has_attachment) {
456
+                $courseDir   = $_course['path'].'/upload/blog';
457
+                $sys_course_path = api_get_path(SYS_COURSE_PATH);
458
+                $updir = $sys_course_path.$courseDir;
459
+
460
+                // Try to add an extension to the file if it hasn't one
461
+                $new_file_name = add_ext_on_mime(
462
+                    stripslashes($_FILES['user_upload']['name']),
463
+                    $_FILES['user_upload']['type']
464
+                );
465
+
466
+                // user's file name
467
+                $file_name =$_FILES['user_upload']['name'];
468
+
469
+                if (!filter_extension($new_file_name)) {
470
+                    Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
471
+                } else {
472
+                    $new_file_name = uniqid('');
473
+                    $new_path=$updir.'/'.$new_file_name;
474
+                    $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
475
+                    $comment = Database::escape_string($file_comment);
476
+
477
+                    // Storing the attachments if any
478
+                    if ($result) {
479
+                        $sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
480
+                                "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."'  )";
481
+                        Database::query($sql);
483 482
 
484 483
                         $id = Database::insert_id();
485 484
 
@@ -487,92 +486,92 @@  discard block
 block discarded – undo
487 486
                             $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
488 487
                             Database::query($sql);
489 488
                         }
490
-					}
491
-				}
492
-			}
493
-		}
494
-	}
495
-
496
-	/**
497
-	 * Deletes a comment from a blogpost
498
-	 * @author Toon Keppens
499
-	 * @param int $blog_id
500
-	 * @param int $comment_id
501
-	 */
502
-	public static function delete_comment($blog_id, $post_id, $comment_id)
503
-	{
504
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
505
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
506
-		$blog_id = intval($blog_id);
507
-		$post_id = intval($post_id);
508
-		$comment_id = intval($comment_id);
489
+                    }
490
+                }
491
+            }
492
+        }
493
+    }
494
+
495
+    /**
496
+     * Deletes a comment from a blogpost
497
+     * @author Toon Keppens
498
+     * @param int $blog_id
499
+     * @param int $comment_id
500
+     */
501
+    public static function delete_comment($blog_id, $post_id, $comment_id)
502
+    {
503
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
504
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
505
+        $blog_id = intval($blog_id);
506
+        $post_id = intval($post_id);
507
+        $comment_id = intval($comment_id);
509 508
         $course_id = api_get_course_int_id();
510 509
 
511
-		delete_all_blog_attachment($blog_id, $post_id, $comment_id);
510
+        delete_all_blog_attachment($blog_id, $post_id, $comment_id);
512 511
 
513
-		// Delete ratings on this comment
514
-		$sql = "DELETE FROM $tbl_blogs_rating
512
+        // Delete ratings on this comment
513
+        $sql = "DELETE FROM $tbl_blogs_rating
515 514
 				WHERE
516 515
 				    c_id = $course_id AND
517 516
 				    blog_id = '".$blog_id."' AND
518 517
 				    item_id = '".$comment_id."' AND
519 518
 				    rating_type = 'comment'";
520
-		Database::query($sql);
519
+        Database::query($sql);
521 520
 
522
-		// select comments that have the selected comment as their parent
523
-		$sql = "SELECT comment_id FROM $tbl_blogs_comments
521
+        // select comments that have the selected comment as their parent
522
+        $sql = "SELECT comment_id FROM $tbl_blogs_comments
524 523
 				WHERE c_id = $course_id AND parent_comment_id = '".$comment_id."'";
525
-		$result = Database::query($sql);
524
+        $result = Database::query($sql);
526 525
 
527
-		// Delete them recursively
528
-		while ($comment = Database::fetch_array($result)) {
529
-			Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
530
-		}
526
+        // Delete them recursively
527
+        while ($comment = Database::fetch_array($result)) {
528
+            Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
529
+        }
531 530
 
532
-		// Finally, delete the selected comment to
533
-		$sql = "DELETE FROM $tbl_blogs_comments
531
+        // Finally, delete the selected comment to
532
+        $sql = "DELETE FROM $tbl_blogs_comments
534 533
 				WHERE c_id = $course_id AND comment_id = '".$comment_id."'";
535
-		Database::query($sql);
536
-	}
537
-
538
-	/**
539
-	 * Creates a new task in a blog
540
-	 * @author Toon Keppens
541
-	 * @param Integer $blog_id
542
-	 * @param String $title
543
-	 * @param String $description
544
-	 * @param String $color
545
-	 */
546
-	public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
547
-	{
548
-		// Init
549
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
550
-		$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
551
-
552
-		$course_id = api_get_course_int_id();
553
-
554
-		// Create the task
555
-		$sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
534
+        Database::query($sql);
535
+    }
536
+
537
+    /**
538
+     * Creates a new task in a blog
539
+     * @author Toon Keppens
540
+     * @param Integer $blog_id
541
+     * @param String $title
542
+     * @param String $description
543
+     * @param String $color
544
+     */
545
+    public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
546
+    {
547
+        // Init
548
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
549
+        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
550
+
551
+        $course_id = api_get_course_int_id();
552
+
553
+        // Create the task
554
+        $sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
556 555
 				VALUES ($course_id , '".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');";
557
-		Database::query($sql);
556
+        Database::query($sql);
558 557
 
559
-		$task_id = Database::insert_id();
558
+        $task_id = Database::insert_id();
560 559
 
561 560
         if ($task_id) {
562 561
             $sql = "UPDATE $tbl_blogs_tasks SET task_id = iid WHERE iid = $task_id";
563 562
             Database::query($sql);
564 563
         }
565 564
 
566
-		$tool = 'BLOG_' . $blog_id;
565
+        $tool = 'BLOG_' . $blog_id;
567 566
 
568
-		if ($articleDelete == 'on') {
569
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
567
+        if ($articleDelete == 'on') {
568
+            $sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
570 569
 					'" . (int)$course_id . "',
571 570
 					'" . (int)$task_id . "',
572 571
 					'" . Database::escape_string($tool) . "',
573 572
 					'article_delete'
574 573
 				)";
575
-			Database::query($sql);
574
+            Database::query($sql);
576 575
 
577 576
             $id = Database::insert_id();
578 577
 
@@ -582,172 +581,172 @@  discard block
 block discarded – undo
582 581
             }
583 582
         }
584 583
 
585
-		if ($articleEdit == 'on') {
586
-			$sql = "
584
+        if ($articleEdit == 'on') {
585
+            $sql = "
587 586
 				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
588 587
 					'" . (int)$course_id . "',
589 588
 					'" . (int)$task_id . "',
590 589
 					'" . Database::escape_string($tool) . "',
591 590
 					'article_edit'
592 591
 				)";
593
-			Database::query($sql);
592
+            Database::query($sql);
594 593
             $id = Database::insert_id();
595 594
 
596 595
             if ($id) {
597 596
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
598 597
                 Database::query($sql);
599 598
             }
600
-		}
599
+        }
601 600
 
602
-		if ($commentsDelete == 'on') {
603
-			$sql = "
601
+        if ($commentsDelete == 'on') {
602
+            $sql = "
604 603
 				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
605 604
 					'" . (int)$course_id . "',
606 605
 					'" . (int)$task_id . "',
607 606
 					'" . Database::escape_string($tool) . "',
608 607
 					'article_comments_delete'
609 608
 				)";
610
-			Database::query($sql);
609
+            Database::query($sql);
611 610
             $id = Database::insert_id();
612 611
 
613 612
             if ($id) {
614 613
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
615 614
                 Database::query($sql);
616 615
             }
617
-		}
618
-	}
619
-
620
-	/**
621
-	 * Edit a task in a blog
622
-	 * @author Toon Keppens
623
-	 * @param Integer $task_id
624
-	 * @param String $title
625
-	 * @param String $description
626
-	 * @param String $color
627
-	 */
628
-	public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
629
-	{
630
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
631
-		$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
616
+        }
617
+    }
618
+
619
+    /**
620
+     * Edit a task in a blog
621
+     * @author Toon Keppens
622
+     * @param Integer $task_id
623
+     * @param String $title
624
+     * @param String $description
625
+     * @param String $color
626
+     */
627
+    public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
628
+    {
629
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
630
+        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
632 631
 
633 632
         $course_id = api_get_course_int_id();
634 633
 
635
-		// Create the task
636
-		$sql = "UPDATE $tbl_blogs_tasks SET
634
+        // Create the task
635
+        $sql = "UPDATE $tbl_blogs_tasks SET
637 636
 					title = '".Database::escape_string($title)."',
638 637
 					description = '".Database::escape_string($description)."',
639 638
 					color = '".Database::escape_string($color)."'
640 639
 				WHERE c_id = $course_id AND task_id ='".(int)$task_id."' LIMIT 1";
641
-		Database::query($sql);
640
+        Database::query($sql);
642 641
 
643
-		$tool = 'BLOG_' . $blog_id;
642
+        $tool = 'BLOG_' . $blog_id;
644 643
 
645
-		$sql = "DELETE FROM " . $tbl_tasks_permissions . "
644
+        $sql = "DELETE FROM " . $tbl_tasks_permissions . "
646 645
 				WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
647
-		Database::query($sql);
646
+        Database::query($sql);
648 647
 
649
-		if ($articleDelete == 'on') {
650
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
648
+        if ($articleDelete == 'on') {
649
+            $sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
651 650
 					'" . (int)$course_id . "',
652 651
 					'" . (int)$task_id . "',
653 652
 					'" . Database::escape_string($tool) . "',
654 653
 					'article_delete'
655 654
 				)";
656
-			Database::query($sql);
655
+            Database::query($sql);
657 656
             $id = Database::insert_id();
658 657
 
659 658
             if ($id) {
660 659
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
661 660
                 Database::query($sql);
662 661
             }
663
-		}
662
+        }
664 663
 
665
-		if ($articleEdit == 'on') {
666
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
664
+        if ($articleEdit == 'on') {
665
+            $sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
667 666
 					'" . (int)$course_id . "',
668 667
 					'" . (int)$task_id . "',
669 668
 					'" . Database::escape_string($tool) . "',
670 669
 					'article_edit'
671 670
 				)";
672
-			Database::query($sql);
671
+            Database::query($sql);
673 672
             $id = Database::insert_id();
674 673
 
675 674
             if ($id) {
676 675
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
677 676
                 Database::query($sql);
678 677
             }
679
-		}
678
+        }
680 679
 
681
-		if ($commentsDelete == 'on') {
682
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
680
+        if ($commentsDelete == 'on') {
681
+            $sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
683 682
 					'" . (int)$course_id . "',
684 683
 					'" . (int)$task_id . "',
685 684
 					'" . Database::escape_string($tool) . "',
686 685
 					'article_comments_delete'
687 686
 				)";
688
-			Database::query($sql);
687
+            Database::query($sql);
689 688
             $id = Database::insert_id();
690 689
 
691 690
             if ($id) {
692 691
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
693 692
                 Database::query($sql);
694 693
             }
695
-		}
696
-	}
697
-
698
-	/**
699
-	 * Deletes a task from a blog
700
-	 * @param Integer $blog_id
701
-	 * @param Integer $task_id
702
-	 */
703
-	public static function delete_task($blog_id, $task_id)
704
-	{
705
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
706
-		$course_id = api_get_course_int_id();
707
-
708
-		// Delete posts
709
-		$sql = "DELETE FROM $tbl_blogs_tasks
694
+        }
695
+    }
696
+
697
+    /**
698
+     * Deletes a task from a blog
699
+     * @param Integer $blog_id
700
+     * @param Integer $task_id
701
+     */
702
+    public static function delete_task($blog_id, $task_id)
703
+    {
704
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
705
+        $course_id = api_get_course_int_id();
706
+
707
+        // Delete posts
708
+        $sql = "DELETE FROM $tbl_blogs_tasks
710 709
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."'";
711
-		Database::query($sql);
712
-	}
713
-
714
-	/**
715
-	 * Deletes an assigned task from a blog
716
-	 * @param Integer $blog_id
717
-	 * @param Integer $assignment_id
718
-	 */
719
-	public static function delete_assigned_task($blog_id, $task_id, $user_id)
720
-	{
721
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
710
+        Database::query($sql);
711
+    }
712
+
713
+    /**
714
+     * Deletes an assigned task from a blog
715
+     * @param Integer $blog_id
716
+     * @param Integer $assignment_id
717
+     */
718
+    public static function delete_assigned_task($blog_id, $task_id, $user_id)
719
+    {
720
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
722 721
         $course_id = api_get_course_int_id();
723 722
 
724
-		// Delete posts
725
-		$sql = "DELETE FROM $tbl_blogs_tasks_rel_user
723
+        // Delete posts
724
+        $sql = "DELETE FROM $tbl_blogs_tasks_rel_user
726 725
 				WHERE
727 726
 				    c_id = $course_id AND
728 727
 				    blog_id = '".(int)$blog_id."' AND
729 728
 				    task_id = '".(int)$task_id."' AND
730 729
 				    user_id = '".(int)$user_id."'";
731
-		Database::query($sql);
732
-	}
733
-
734
-	/**
735
-	 * Get personal task list
736
-	 * @author Toon Keppens
737
-	 * @return Returns an unsorted list (<ul></ul>) with the users' tasks
738
-	 */
739
-	public static function get_personal_task_list()
740
-	{
741
-		$_user = api_get_user_info();
742
-
743
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
744
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
745
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
746
-
747
-		$course_id = api_get_course_int_id();
748
-
749
-		if ($_user['user_id']) {
750
-			$sql = "SELECT task_rel_user.*, task.title, blog.blog_name
730
+        Database::query($sql);
731
+    }
732
+
733
+    /**
734
+     * Get personal task list
735
+     * @author Toon Keppens
736
+     * @return Returns an unsorted list (<ul></ul>) with the users' tasks
737
+     */
738
+    public static function get_personal_task_list()
739
+    {
740
+        $_user = api_get_user_info();
741
+
742
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
743
+        $tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
744
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
745
+
746
+        $course_id = api_get_course_int_id();
747
+
748
+        if ($_user['user_id']) {
749
+            $sql = "SELECT task_rel_user.*, task.title, blog.blog_name
751 750
                     FROM $tbl_blogs_tasks_rel_user task_rel_user
752 751
                     INNER JOIN $tbl_blogs_tasks task
753 752
                     ON task_rel_user.task_id = task.task_id
@@ -761,85 +760,85 @@  discard block
 block discarded – undo
761 760
                         task_rel_user.user_id = ".(int)$_user['user_id']."
762 761
                     ORDER BY target_date ASC";
763 762
 
764
-			$result = Database::query($sql);
765
-
766
-			if (Database::num_rows($result) > 0) {
767
-				echo '<ul>';
768
-				while ($mytask = Database::fetch_array($result)) {
769
-					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>';
770
-				}
771
-				echo '<ul>';
772
-			} else {
773
-				echo get_lang('NoTasks');
774
-			}
775
-		} else {
776
-			echo get_lang('NoTasks');
777
-		}
778
-	}
779
-
780
-	/**
781
-	 * Changes the visibility of a blog
782
-	 * @author Toon Keppens
783
-	 * @param Integer $blog_id
784
-	 */
785
-	public static function change_blog_visibility($blog_id)
786
-	{
787
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
788
-		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
789
-		$course_id = api_get_course_int_id();
790
-
791
-		// Get blog properties
792
-		$sql = "SELECT blog_name, visibility FROM $tbl_blogs
763
+            $result = Database::query($sql);
764
+
765
+            if (Database::num_rows($result) > 0) {
766
+                echo '<ul>';
767
+                while ($mytask = Database::fetch_array($result)) {
768
+                    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>';
769
+                }
770
+                echo '<ul>';
771
+            } else {
772
+                echo get_lang('NoTasks');
773
+            }
774
+        } else {
775
+            echo get_lang('NoTasks');
776
+        }
777
+    }
778
+
779
+    /**
780
+     * Changes the visibility of a blog
781
+     * @author Toon Keppens
782
+     * @param Integer $blog_id
783
+     */
784
+    public static function change_blog_visibility($blog_id)
785
+    {
786
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
787
+        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
788
+        $course_id = api_get_course_int_id();
789
+
790
+        // Get blog properties
791
+        $sql = "SELECT blog_name, visibility FROM $tbl_blogs
793 792
 				WHERE c_id = $course_id AND blog_id='".(int)$blog_id."'";
794
-		$result = Database::query($sql);
795
-		$blog = Database::fetch_array($result);
796
-		$visibility = $blog['visibility'];
797
-		$title = $blog['blog_name'];
798
-
799
-		if ($visibility == 1) {
800
-			// Change visibility state, remove from course home.
801
-			$sql = "UPDATE $tbl_blogs SET visibility = '0'
793
+        $result = Database::query($sql);
794
+        $blog = Database::fetch_array($result);
795
+        $visibility = $blog['visibility'];
796
+        $title = $blog['blog_name'];
797
+
798
+        if ($visibility == 1) {
799
+            // Change visibility state, remove from course home.
800
+            $sql = "UPDATE $tbl_blogs SET visibility = '0'
802 801
 					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
803
-			Database::query($sql);
802
+            Database::query($sql);
804 803
 
805
-			$sql = "DELETE FROM $tbl_tool
804
+            $sql = "DELETE FROM $tbl_tool
806 805
 					WHERE c_id = $course_id AND name = '".Database::escape_string($title)."' LIMIT 1";
807
-			Database::query($sql);
808
-		} else {
809
-			// Change visibility state, add to course home.
810
-			$sql = "UPDATE $tbl_blogs SET visibility = '1'
806
+            Database::query($sql);
807
+        } else {
808
+            // Change visibility state, add to course home.
809
+            $sql = "UPDATE $tbl_blogs SET visibility = '1'
811 810
 					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
812
-			Database::query($sql);
811
+            Database::query($sql);
813 812
 
814
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
813
+            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
815 814
 					VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
816
-			Database::query($sql);
815
+            Database::query($sql);
817 816
             $id = Database::insert_id();
818 817
 
819 818
             if ($id) {
820 819
                 $sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $id";
821 820
                 Database::query($sql);
822 821
             }
823
-		}
824
-	}
825
-
826
-	/**
827
-	 * Shows the posts of a blog
828
-	 * @author Toon Keppens
829
-	 *
830
-	 * @param Integer $blog_id
831
-	 */
832
-	public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
822
+        }
823
+    }
824
+
825
+    /**
826
+     * Shows the posts of a blog
827
+     * @author Toon Keppens
828
+     *
829
+     * @param Integer $blog_id
830
+     */
831
+    public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
833 832
     {
834
-		// Init
835
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
836
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
837
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
833
+        // Init
834
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
835
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
836
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
838 837
 
839
-		$course_id = api_get_course_int_id();
838
+        $course_id = api_get_course_int_id();
840 839
 
841
-		// Get posts and authors
842
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
840
+        // Get posts and authors
841
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
843 842
 		        FROM $tbl_blogs_posts post
844 843
                 INNER JOIN $tbl_users user
845 844
                 ON post.author_id = user.user_id
@@ -847,131 +846,131 @@  discard block
 block discarded – undo
847 846
 						post.c_id = $course_id AND
848 847
 						$filter
849 848
 				ORDER BY post_id DESC LIMIT 0,".(int)$max_number_of_posts;
850
-		$result = Database::query($sql);
851
-
852
-		// Display
853
-		if(Database::num_rows($result) > 0) {
854
-		    $limit = 200;
855
-			while ($blog_post = Database::fetch_array($result)) {
856
-				// Get number of comments
857
-				$sql = "SELECT COUNT(1) as number_of_comments
849
+        $result = Database::query($sql);
850
+
851
+        // Display
852
+        if(Database::num_rows($result) > 0) {
853
+            $limit = 200;
854
+            while ($blog_post = Database::fetch_array($result)) {
855
+                // Get number of comments
856
+                $sql = "SELECT COUNT(1) as number_of_comments
858 857
 						FROM $tbl_blogs_comments
859 858
 						WHERE
860 859
 						    c_id = $course_id AND
861 860
 						    blog_id = '".(int)$blog_id."' AND
862 861
 						    post_id = '" . (int)$blog_post['post_id']."'";
863
-				$tmp = Database::query($sql);
864
-				$blog_post_comments = Database::fetch_array($tmp);
865
-
866
-				// Prepare data
867
-				$blog_post_id = $blog_post['post_id'];
868
-				$blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
869
-				$blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
870
-
871
-				// Create an introduction text (but keep FULL sentences)
872
-				$words = 0;
873
-				$blog_post_text_cut = cut($blog_post_text, $limit) ;
874
-				$words = strlen($blog_post_text);
875
-
876
-				if ($words >= $limit) {
877
-					$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>';
878
-					$introduction_text = $blog_post_text_cut;
879
-				} else {
880
-				    $introduction_text = $blog_post_text;
881
-					$readMoreLink = '';
882
-				}
883
-
884
-				$introduction_text = stripslashes($introduction_text);
885
-
886
-				echo '<div class="blogpost">';
887
-				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>';
888
-				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>';
889
-				echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
890
-				echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
891
-
892
-				$file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
893
-
894
-				if (!empty($file_name_array)) {
895
-					echo '<br /><br />';
896
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
897
-					echo '<a href="download.php?file=';
898
-					echo $file_name_array['path'];
899
-					echo ' "> '.$file_name_array['filename'].' </a><br />';
900
-					echo '</span>';
901
-				}
902
-				$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
903
-				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>';
904
-				echo '</div>';
905
-			}
906
-		} else {
907
-			if($filter == '1=1') {
908
-				echo get_lang('NoArticles');
909
-			} else {
910
-				echo get_lang('NoArticleMatches');
911
-			}
912
-		}
862
+                $tmp = Database::query($sql);
863
+                $blog_post_comments = Database::fetch_array($tmp);
864
+
865
+                // Prepare data
866
+                $blog_post_id = $blog_post['post_id'];
867
+                $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
868
+                $blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
869
+
870
+                // Create an introduction text (but keep FULL sentences)
871
+                $words = 0;
872
+                $blog_post_text_cut = cut($blog_post_text, $limit) ;
873
+                $words = strlen($blog_post_text);
874
+
875
+                if ($words >= $limit) {
876
+                    $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>';
877
+                    $introduction_text = $blog_post_text_cut;
878
+                } else {
879
+                    $introduction_text = $blog_post_text;
880
+                    $readMoreLink = '';
881
+                }
882
+
883
+                $introduction_text = stripslashes($introduction_text);
884
+
885
+                echo '<div class="blogpost">';
886
+                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>';
887
+                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>';
888
+                echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
889
+                echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
890
+
891
+                $file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
892
+
893
+                if (!empty($file_name_array)) {
894
+                    echo '<br /><br />';
895
+                    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
896
+                    echo '<a href="download.php?file=';
897
+                    echo $file_name_array['path'];
898
+                    echo ' "> '.$file_name_array['filename'].' </a><br />';
899
+                    echo '</span>';
900
+                }
901
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
902
+                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>';
903
+                echo '</div>';
904
+            }
905
+        } else {
906
+            if($filter == '1=1') {
907
+                echo get_lang('NoArticles');
908
+            } else {
909
+                echo get_lang('NoArticleMatches');
910
+            }
911
+        }
913 912
 }
914 913
 
915
-	/**
916
-	 * Display the search results
917
-	 *
918
-	 * @param Integer $blog_id
919
-	 * @param String $query_string
920
-	 */
921
-	public static function display_search_results ($blog_id, $query_string)
922
-	{
923
-		// Init
924
-		$query_string = Database::escape_string($query_string);
925
-		$query_string_parts = explode(' ',$query_string);
926
-		$query_string = array();
927
-		foreach ($query_string_parts as $query_part) {
928
-			$query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
929
-		}
930
-		$query_string = '('.implode('OR',$query_string) . ')';
931
-
932
-		// Display the posts
933
-		echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
934
-		Blog::display_blog_posts($blog_id, $query_string);
935
-	}
936
-
937
-	/**
938
-	 * Display posts from a certain date
939
-	 *
940
-	 * @param Integer $blog_id
941
-	 * @param String $query_string
942
-	 */
943
-	public static function display_day_results($blog_id, $query_string)
944
-	{
945
-		$date_output = $query_string;
946
-		$date = explode('-',$query_string);
947
-		$query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
948
-
949
-		// Put date in correct output format
950
-		$date_output = api_format_date($date_output, DATE_FORMAT_LONG);
951
-
952
-		// Display the posts
953
-		echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
954
-		Blog::display_blog_posts($blog_id, $query_string);
955
-	}
956
-
957
-	/**
958
-	 * Displays a post and his comments
959
-	 *
960
-	 * @param Integer $blog_id
961
-	 * @param Integer $post_id
962
-	 */
963
-	public static function display_post($blog_id, $post_id)
964
-	{
965
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
966
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
967
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
968
-
969
-		global $charset, $dateFormatLong;
970
-
971
-		$course_id = api_get_course_int_id();
972
-
973
-		// Get posts and author
974
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
914
+    /**
915
+     * Display the search results
916
+     *
917
+     * @param Integer $blog_id
918
+     * @param String $query_string
919
+     */
920
+    public static function display_search_results ($blog_id, $query_string)
921
+    {
922
+        // Init
923
+        $query_string = Database::escape_string($query_string);
924
+        $query_string_parts = explode(' ',$query_string);
925
+        $query_string = array();
926
+        foreach ($query_string_parts as $query_part) {
927
+            $query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
928
+        }
929
+        $query_string = '('.implode('OR',$query_string) . ')';
930
+
931
+        // Display the posts
932
+        echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
933
+        Blog::display_blog_posts($blog_id, $query_string);
934
+    }
935
+
936
+    /**
937
+     * Display posts from a certain date
938
+     *
939
+     * @param Integer $blog_id
940
+     * @param String $query_string
941
+     */
942
+    public static function display_day_results($blog_id, $query_string)
943
+    {
944
+        $date_output = $query_string;
945
+        $date = explode('-',$query_string);
946
+        $query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
947
+
948
+        // Put date in correct output format
949
+        $date_output = api_format_date($date_output, DATE_FORMAT_LONG);
950
+
951
+        // Display the posts
952
+        echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
953
+        Blog::display_blog_posts($blog_id, $query_string);
954
+    }
955
+
956
+    /**
957
+     * Displays a post and his comments
958
+     *
959
+     * @param Integer $blog_id
960
+     * @param Integer $post_id
961
+     */
962
+    public static function display_post($blog_id, $post_id)
963
+    {
964
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
965
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
966
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
967
+
968
+        global $charset, $dateFormatLong;
969
+
970
+        $course_id = api_get_course_int_id();
971
+
972
+        // Get posts and author
973
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
975 974
 		        FROM $tbl_blogs_posts post
976 975
 					INNER JOIN $tbl_users user
977 976
 					ON post.author_id = user.user_id
@@ -980,113 +979,113 @@  discard block
 block discarded – undo
980 979
                     post.blog_id = '".(int)$blog_id."' AND
981 980
                     post.post_id = '".(int)$post_id."'
982 981
                 ORDER BY post_id DESC";
983
-		$result = Database::query($sql);
984
-		$blog_post = Database::fetch_array($result);
982
+        $result = Database::query($sql);
983
+        $blog_post = Database::fetch_array($result);
985 984
 
986
-		// Get number of comments
987
-		$sql = "SELECT COUNT(1) as number_of_comments
985
+        // Get number of comments
986
+        $sql = "SELECT COUNT(1) as number_of_comments
988 987
 		        FROM $tbl_blogs_comments
989 988
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND post_id = '".(int)$post_id."'";
990
-		$result = Database::query($sql);
991
-		$blog_post_comments = Database::fetch_array($result);
989
+        $result = Database::query($sql);
990
+        $blog_post_comments = Database::fetch_array($result);
992 991
 
993
-		// Prepare data
994
-		$blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
995
-		$blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
996
-		$blog_post_actions = "";
992
+        // Prepare data
993
+        $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
994
+        $blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
995
+        $blog_post_actions = "";
997 996
 
998
-		$task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
997
+        $task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
999 998
 
1000
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
1001
-			$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') . '">';
1002
-			$blog_post_actions .=  Display::return_icon('edit.png');
1003
-			$blog_post_actions .= '</a>';
999
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
1000
+            $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') . '">';
1001
+            $blog_post_actions .=  Display::return_icon('edit.png');
1002
+            $blog_post_actions .= '</a>';
1004 1003
         }
1005 1004
 
1006
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
1007
-			$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;">';
1005
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
1006
+            $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;">';
1008 1007
             $blog_post_actions .= Display::return_icon('delete.png');
1009 1008
             $blog_post_actions .= '</a>';
1010 1009
         }
1011 1010
 
1012
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1013
-			$rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1011
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1012
+            $rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1014 1013
 
1015
-		$blog_post_text=stripslashes($blog_post_text);
1014
+        $blog_post_text=stripslashes($blog_post_text);
1016 1015
 
1017
-		// Display post
1018
-		echo '<div class="blogpost">';
1019
-		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>';
1020
-		echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1021
-		echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1016
+        // Display post
1017
+        echo '<div class="blogpost">';
1018
+        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>';
1019
+        echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1020
+        echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1022 1021
 
1023
-		$file_name_array = get_blog_attachment($blog_id, $post_id);
1022
+        $file_name_array = get_blog_attachment($blog_id, $post_id);
1024 1023
 
1025 1024
         if (!empty($file_name_array)) {
1026
-			echo ' <br />';
1027
-			echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1028
-			echo '<a href="download.php?file=';
1029
-			echo $file_name_array['path'];
1030
-			echo ' "> '.$file_name_array['filename'].' </a>';
1031
-			echo '</span>';
1032
-			echo '<span class="attachment_comment">';
1033
-			echo $file_name_array['comment'];
1034
-			echo '</span>';
1035
-			echo '<br />';
1036
-		}
1025
+            echo ' <br />';
1026
+            echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1027
+            echo '<a href="download.php?file=';
1028
+            echo $file_name_array['path'];
1029
+            echo ' "> '.$file_name_array['filename'].' </a>';
1030
+            echo '</span>';
1031
+            echo '<span class="attachment_comment">';
1032
+            echo $file_name_array['comment'];
1033
+            echo '</span>';
1034
+            echo '<br />';
1035
+        }
1037 1036
         $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1038
-		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>';
1039
-		echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1040
-		echo '</div>';
1041
-
1042
-		// Display comments if there are any
1043
-		if($blog_post_comments['number_of_comments'] > 0) {
1044
-			echo '<div class="comments">';
1045
-				echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1046
-				Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1047
-			echo '</div>';
1048
-		}
1049
-
1050
-		// Display comment form
1051
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1052
-			Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1053
-		}
1054
-	}
1055
-
1056
-	/**
1057
-	 * Adds rating to a certain post or comment
1058
-	 * @author Toon Keppens
1059
-	 *
1060
-	 * @param String $type
1061
-	 * @param Integer $blog_id
1062
-	 * @param Integer $item_id
1063
-	 * @param Integer $rating
1064
-	 *
1065
-	 * @return Boolean success
1066
-	 */
1067
-	public static function add_rating($type, $blog_id, $item_id, $rating)
1068
-	{
1069
-		$_user = api_get_user_info();
1070
-
1071
-		// Init
1072
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1073
-		$course_id = api_get_course_int_id();
1074
-
1075
-		// Check if the user has already rated this post/comment
1076
-		$sql = "SELECT rating_id FROM $tbl_blogs_rating
1037
+        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>';
1038
+        echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1039
+        echo '</div>';
1040
+
1041
+        // Display comments if there are any
1042
+        if($blog_post_comments['number_of_comments'] > 0) {
1043
+            echo '<div class="comments">';
1044
+                echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1045
+                Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1046
+            echo '</div>';
1047
+        }
1048
+
1049
+        // Display comment form
1050
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1051
+            Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1052
+        }
1053
+    }
1054
+
1055
+    /**
1056
+     * Adds rating to a certain post or comment
1057
+     * @author Toon Keppens
1058
+     *
1059
+     * @param String $type
1060
+     * @param Integer $blog_id
1061
+     * @param Integer $item_id
1062
+     * @param Integer $rating
1063
+     *
1064
+     * @return Boolean success
1065
+     */
1066
+    public static function add_rating($type, $blog_id, $item_id, $rating)
1067
+    {
1068
+        $_user = api_get_user_info();
1069
+
1070
+        // Init
1071
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1072
+        $course_id = api_get_course_int_id();
1073
+
1074
+        // Check if the user has already rated this post/comment
1075
+        $sql = "SELECT rating_id FROM $tbl_blogs_rating
1077 1076
                 WHERE
1078 1077
                     c_id = $course_id AND
1079 1078
                     blog_id = '".(int)$blog_id."' AND
1080 1079
                     item_id = '".(int)$item_id."' AND
1081 1080
                     rating_type = '".Database::escape_string($type)."' AND
1082 1081
                     user_id = '".(int)$_user['user_id']."'";
1083
-		$result = Database::query($sql);
1082
+        $result = Database::query($sql);
1084 1083
 
1085 1084
         // Add rating
1086
-		if (Database::num_rows($result) == 0) {
1087
-			$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1085
+        if (Database::num_rows($result) == 0) {
1086
+            $sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1088 1087
 					VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".Database::escape_string($rating)."')";
1089
-			Database::query($sql);
1088
+            Database::query($sql);
1090 1089
 
1091 1090
             $id = Database::insert_id();
1092 1091
             if ($id) {
@@ -1094,107 +1093,107 @@  discard block
 block discarded – undo
1094 1093
                 Database::query($sql);
1095 1094
             }
1096 1095
 
1097
-			return true;
1096
+            return true;
1098 1097
         } else {
1099
-			return false;
1100
-		}
1101
-	}
1102
-
1103
-	/**
1104
-	 * Shows the rating of user
1105
-	 *
1106
-	 * @param String $type
1107
-	 * @param Integer $blog_id
1108
-	 * @param Integer $item_id
1109
-	 *
1110
-	 * @return array()
1111
-	 */
1112
-	public static function display_rating($type, $blog_id, $item_id)
1113
-	{
1114
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1115
-		$course_id = api_get_course_int_id();
1116
-
1117
-		// Calculate rating
1118
-		$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1098
+            return false;
1099
+        }
1100
+    }
1101
+
1102
+    /**
1103
+     * Shows the rating of user
1104
+     *
1105
+     * @param String $type
1106
+     * @param Integer $blog_id
1107
+     * @param Integer $item_id
1108
+     *
1109
+     * @return array()
1110
+     */
1111
+    public static function display_rating($type, $blog_id, $item_id)
1112
+    {
1113
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1114
+        $course_id = api_get_course_int_id();
1115
+
1116
+        // Calculate rating
1117
+        $sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1119 1118
 				WHERE
1120 1119
 				    c_id = $course_id AND
1121 1120
 				    blog_id = '".(int)$blog_id."' AND
1122 1121
 				    item_id = '".(int)$item_id."' AND
1123 1122
 				    rating_type = '".Database::escape_string($type)."' ";
1124
-		$result = Database::query($sql);
1125
-		$result = Database::fetch_array($result);
1126
-		return round($result['rating'], 2);
1127
-	}
1128
-
1129
-	/**
1130
-	 * Shows the rating form if not already rated by that user
1131
-	 * @author Toon Keppens
1132
-	 *
1133
-	 * @param String $type
1134
-	 * @param Integer $blog_id
1135
-	 * @param Integer $item_id
1136
-	 *
1137
-	 *@return String
1138
-	 */
1139
-	public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1140
-	{
1141
-		$_user = api_get_user_info();
1142
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1123
+        $result = Database::query($sql);
1124
+        $result = Database::fetch_array($result);
1125
+        return round($result['rating'], 2);
1126
+    }
1127
+
1128
+    /**
1129
+     * Shows the rating form if not already rated by that user
1130
+     * @author Toon Keppens
1131
+     *
1132
+     * @param String $type
1133
+     * @param Integer $blog_id
1134
+     * @param Integer $item_id
1135
+     *
1136
+     *@return String
1137
+     */
1138
+    public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1139
+    {
1140
+        $_user = api_get_user_info();
1141
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1143 1142
         $course_id = api_get_course_int_id();
1144 1143
 
1145 1144
         if ($type == 'post') {
1146
-			// Check if the user has already rated this post
1147
-			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1145
+            // Check if the user has already rated this post
1146
+            $sql = "SELECT rating_id FROM $tbl_blogs_rating
1148 1147
 					WHERE c_id = $course_id AND
1149 1148
 					blog_id = '".(int)$blog_id."'
1150 1149
 					AND item_id = '".(int)$post_id."'
1151 1150
 					AND rating_type = '".Database::escape_string($type)."'
1152 1151
 					AND user_id = '".(int)$_user['user_id']."'";
1153
-			$result = Database::query($sql);
1152
+            $result = Database::query($sql);
1154 1153
             // Add rating
1155 1154
             if (Database::num_rows($result) == 0) {
1156
-				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>';
1155
+                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>';
1157 1156
             } else {
1158
-				return '';
1159
-			}
1160
-		}
1157
+                return '';
1158
+            }
1159
+        }
1161 1160
 
1162 1161
         if ($type = 'comment') {
1163
-			// Check if the user has already rated this comment
1164
-			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1162
+            // Check if the user has already rated this comment
1163
+            $sql = "SELECT rating_id FROM $tbl_blogs_rating
1165 1164
 					WHERE c_id = $course_id AND blog_id = '".(int)$blog_id ."'
1166 1165
 					AND item_id = '".(int)$comment_id."'
1167 1166
 					AND rating_type = '".Database::escape_string($type)."'
1168 1167
 					AND user_id = '".(int)$_user['user_id']."'";
1169
-			$result = Database::query($sql);
1168
+            $result = Database::query($sql);
1170 1169
 
1171 1170
             if (Database::num_rows($result) == 0) {
1172
-				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>';
1171
+                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>';
1173 1172
             } else {
1174
-				return '';
1175
-			}
1176
-		}
1177
-	}
1178
-
1179
-	/**
1180
-	 * This functions gets all replys to a post, threaded.
1181
-	 *
1182
-	 * @param Integer $current
1183
-	 * @param Integer $current_level
1184
-	 * @param Integer $blog_id
1185
-	 * @param Integer $post_id
1186
-	 */
1187
-	public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
1188
-	{
1189
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
1190
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1191
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1192
-		global $charset;
1193
-
1194
-		$course_id = api_get_course_int_id();
1195
-
1196
-		// Select top level comments
1197
-		$next_level = $current_level + 1;
1173
+                return '';
1174
+            }
1175
+        }
1176
+    }
1177
+
1178
+    /**
1179
+     * This functions gets all replys to a post, threaded.
1180
+     *
1181
+     * @param Integer $current
1182
+     * @param Integer $current_level
1183
+     * @param Integer $blog_id
1184
+     * @param Integer $post_id
1185
+     */
1186
+    public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
1187
+    {
1188
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
1189
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1190
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1191
+        global $charset;
1192
+
1193
+        $course_id = api_get_course_int_id();
1194
+
1195
+        // Select top level comments
1196
+        $next_level = $current_level + 1;
1198 1197
         $sql = "SELECT comments.*, user.lastname, user.firstname, user.username, task.color
1199 1198
                 FROM $tbl_blogs_comments comments
1200 1199
                 INNER JOIN $tbl_users user
@@ -1206,11 +1205,11 @@  discard block
 block discarded – undo
1206 1205
                     parent_comment_id = $current AND
1207 1206
                     comments.blog_id = '".(int)$blog_id."' AND
1208 1207
                     comments.post_id = '".(int)$post_id."'";
1209
-		$result = Database::query($sql);
1208
+        $result = Database::query($sql);
1210 1209
 
1211
-		while($comment = Database::fetch_array($result)) {
1212
-			// Select the children recursivly
1213
-			$tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1210
+        while($comment = Database::fetch_array($result)) {
1211
+            // Select the children recursivly
1212
+            $tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1214 1213
 			        FROM $tbl_blogs_comments comments
1215 1214
 					INNER JOIN $tbl_users user
1216 1215
 					ON comments.author_id = user.user_id
@@ -1219,15 +1218,15 @@  discard block
 block discarded – undo
1219 1218
 						comment_id = $current
1220 1219
 						AND blog_id = '".(int)$blog_id."'
1221 1220
 						AND post_id = '".(int)$post_id."'";
1222
-			$tmp = Database::query($tmp);
1223
-			$tmp = Database::fetch_array($tmp);
1224
-			$parent_cat = $tmp['parent_comment_id'];
1225
-			$border_color = '';
1226
-
1227
-			// Prepare data
1228
-			$comment_text = make_clickable(stripslashes($comment['comment']));
1229
-			$blog_comment_date = api_convert_and_format_date($comment['date_creation'], null, date_default_timezone_get());
1230
-			$blog_comment_actions = "";
1221
+            $tmp = Database::query($tmp);
1222
+            $tmp = Database::fetch_array($tmp);
1223
+            $parent_cat = $tmp['parent_comment_id'];
1224
+            $border_color = '';
1225
+
1226
+            // Prepare data
1227
+            $comment_text = make_clickable(stripslashes($comment['comment']));
1228
+            $blog_comment_date = api_convert_and_format_date($comment['date_creation'], null, date_default_timezone_get());
1229
+            $blog_comment_actions = "";
1231 1230
             if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id)) {
1232 1231
                 $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(
1233 1232
                         'DeleteThisComment'
@@ -1242,92 +1241,92 @@  discard block
 block discarded – undo
1242 1241
                 $rating_select = Blog::display_rating_form('comment', $blog_id, $post_id, $comment['comment_id']);
1243 1242
             }
1244 1243
 
1245
-			if (!is_null($comment['task_id'])) {
1246
-				$border_color = ' border-left: 3px solid #' . $comment['color'];
1247
-			}
1248
-
1249
-			$comment_text = stripslashes($comment_text);
1250
-
1251
-			// Output...
1252
-			$margin = $current_level * 30;
1253
-			echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1254
-				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>';
1255
-				echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1256
-				echo '<span class="blogpost_text">' . $comment_text . '</span>';
1257
-
1258
-				$file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1259
-				if (!empty($file_name_array)) {
1260
-					echo '<br /><br />';
1261
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1262
-					echo '<a href="download.php?file=';
1263
-					echo $file_name_array['path'];
1264
-					echo ' "> '.$file_name_array['filename'].' </a>';
1265
-					echo '<span class="attachment_comment">';
1266
-					echo $file_name_array['comment'];
1267
-					echo '</span><br />';
1268
-				}
1244
+            if (!is_null($comment['task_id'])) {
1245
+                $border_color = ' border-left: 3px solid #' . $comment['color'];
1246
+            }
1247
+
1248
+            $comment_text = stripslashes($comment_text);
1249
+
1250
+            // Output...
1251
+            $margin = $current_level * 30;
1252
+            echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1253
+                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>';
1254
+                echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1255
+                echo '<span class="blogpost_text">' . $comment_text . '</span>';
1256
+
1257
+                $file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1258
+                if (!empty($file_name_array)) {
1259
+                    echo '<br /><br />';
1260
+                    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1261
+                    echo '<a href="download.php?file=';
1262
+                    echo $file_name_array['path'];
1263
+                    echo ' "> '.$file_name_array['filename'].' </a>';
1264
+                    echo '<span class="attachment_comment">';
1265
+                    echo $file_name_array['comment'];
1266
+                    echo '</span><br />';
1267
+                }
1269 1268
                 $username = api_htmlentities(sprintf(get_lang('LoginX'), $comment['username']), ENT_QUOTES);
1270
-				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>';
1271
-				echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1272
-			echo '</div>';
1273
-
1274
-			// Go further down the tree.
1275
-			Blog::get_threaded_comments($comment['comment_id'], $next_level, $blog_id, $post_id);
1276
-		}
1277
-	}
1278
-
1279
-	/**
1280
-	 * Displays the form to create a new post
1281
-	 * @author Toon Keppens
1282
-	 *
1283
-	 * @param Integer $blog_id
1284
-	 */
1285
-	public static function display_form_new_post($blog_id)
1286
-	{
1287
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1288
-			$form = new FormValidator(
1289
-				'add_post',
1290
-				'post',
1291
-				api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1292
-				null,
1293
-				array('enctype' => 'multipart/form-data')
1294
-			);
1295
-			$form->addHidden('post_title_edited', 'false');
1296
-			$form->addHeader(get_lang('NewPost'));
1297
-			$form->addText('title', get_lang('Title'));
1298
-			$config = array();
1299
-			if (!api_is_allowed_to_edit()) {
1300
-				$config['ToolbarSet'] = 'ProjectStudent';
1301
-			} else {
1302
-				$config['ToolbarSet'] = 'Project';
1303
-			}
1304
-			$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1305
-			$form->addFile('user_upload', get_lang('AddAnAttachment'));
1306
-			$form->addTextarea('post_file_comment', get_lang('FileComment'));
1307
-			$form->addHidden('new_post_submit', 'true');
1308
-			$form->addButton('save', get_lang('Save'));
1309
-
1310
-			$form->display();
1311
-		} else {
1312
-			api_not_allowed();
1313
-		}
1314
-	}
1315
-
1316
-	/**
1317
-	 * Displays the form to edit a post
1318
-	 * @author Toon Keppens
1319
-	 *
1320
-	 * @param Integer $blog_id
1321
-	 */
1322
-	public static function display_form_edit_post($blog_id, $post_id)
1323
-	{
1324
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1325
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1326
-
1327
-		$course_id = api_get_course_int_id();
1328
-
1329
-		// Get posts and author
1330
-		$sql = "SELECT post.*, user.lastname, user.firstname
1269
+                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>';
1270
+                echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1271
+            echo '</div>';
1272
+
1273
+            // Go further down the tree.
1274
+            Blog::get_threaded_comments($comment['comment_id'], $next_level, $blog_id, $post_id);
1275
+        }
1276
+    }
1277
+
1278
+    /**
1279
+     * Displays the form to create a new post
1280
+     * @author Toon Keppens
1281
+     *
1282
+     * @param Integer $blog_id
1283
+     */
1284
+    public static function display_form_new_post($blog_id)
1285
+    {
1286
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1287
+            $form = new FormValidator(
1288
+                'add_post',
1289
+                'post',
1290
+                api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1291
+                null,
1292
+                array('enctype' => 'multipart/form-data')
1293
+            );
1294
+            $form->addHidden('post_title_edited', 'false');
1295
+            $form->addHeader(get_lang('NewPost'));
1296
+            $form->addText('title', get_lang('Title'));
1297
+            $config = array();
1298
+            if (!api_is_allowed_to_edit()) {
1299
+                $config['ToolbarSet'] = 'ProjectStudent';
1300
+            } else {
1301
+                $config['ToolbarSet'] = 'Project';
1302
+            }
1303
+            $form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1304
+            $form->addFile('user_upload', get_lang('AddAnAttachment'));
1305
+            $form->addTextarea('post_file_comment', get_lang('FileComment'));
1306
+            $form->addHidden('new_post_submit', 'true');
1307
+            $form->addButton('save', get_lang('Save'));
1308
+
1309
+            $form->display();
1310
+        } else {
1311
+            api_not_allowed();
1312
+        }
1313
+    }
1314
+
1315
+    /**
1316
+     * Displays the form to edit a post
1317
+     * @author Toon Keppens
1318
+     *
1319
+     * @param Integer $blog_id
1320
+     */
1321
+    public static function display_form_edit_post($blog_id, $post_id)
1322
+    {
1323
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1324
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1325
+
1326
+        $course_id = api_get_course_int_id();
1327
+
1328
+        // Get posts and author
1329
+        $sql = "SELECT post.*, user.lastname, user.firstname
1331 1330
 				FROM $tbl_blogs_posts post
1332 1331
 				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1333 1332
 				WHERE
@@ -1335,74 +1334,74 @@  discard block
 block discarded – undo
1335 1334
 				post.blog_id 		= '".(int)$blog_id ."'
1336 1335
 				AND post.post_id	= '".(int)$post_id."'
1337 1336
 				ORDER BY post_id DESC";
1338
-		$result = Database::query($sql);
1339
-		$blog_post = Database::fetch_array($result);
1340
-
1341
-		// Form
1342
-		$form = new FormValidator(
1343
-			'edit_post',
1344
-			'post',
1345
-			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'])
1346
-		);
1347
-
1348
-		$form->addHeader(get_lang('EditPost'));
1349
-		$form->addText('title', get_lang('Title'));
1350
-
1351
-		if (!api_is_allowed_to_edit()) {
1352
-			$config['ToolbarSet'] = 'ProjectStudent';
1353
-		} else {
1354
-			$config['ToolbarSet'] = 'Project';
1355
-		}
1356
-		$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1357
-
1358
-		$form->addHidden('action', '');
1359
-		$form->addHidden('edit_post_submit', 'true');
1360
-		$form->addHidden('post_id', intval($_GET['post_id']));
1361
-		$form->addButton('save', get_lang('Save'));
1362
-		$form->setDefaults($blog_post);
1363
-		$form->display();
1364
-	}
1365
-
1366
-	/**
1367
-	 * Displays a list of tasks in this blog
1368
-	 * @author Toon Keppens
1369
-	 *
1370
-	 * @param Integer $blog_id
1371
-	 */
1372
-	public static function display_task_list($blog_id)
1337
+        $result = Database::query($sql);
1338
+        $blog_post = Database::fetch_array($result);
1339
+
1340
+        // Form
1341
+        $form = new FormValidator(
1342
+            'edit_post',
1343
+            'post',
1344
+            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'])
1345
+        );
1346
+
1347
+        $form->addHeader(get_lang('EditPost'));
1348
+        $form->addText('title', get_lang('Title'));
1349
+
1350
+        if (!api_is_allowed_to_edit()) {
1351
+            $config['ToolbarSet'] = 'ProjectStudent';
1352
+        } else {
1353
+            $config['ToolbarSet'] = 'Project';
1354
+        }
1355
+        $form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1356
+
1357
+        $form->addHidden('action', '');
1358
+        $form->addHidden('edit_post_submit', 'true');
1359
+        $form->addHidden('post_id', intval($_GET['post_id']));
1360
+        $form->addButton('save', get_lang('Save'));
1361
+        $form->setDefaults($blog_post);
1362
+        $form->display();
1363
+    }
1364
+
1365
+    /**
1366
+     * Displays a list of tasks in this blog
1367
+     * @author Toon Keppens
1368
+     *
1369
+     * @param Integer $blog_id
1370
+     */
1371
+    public static function display_task_list($blog_id)
1373 1372
     {
1374
-		global $charset;
1373
+        global $charset;
1375 1374
         $course_id = api_get_course_int_id();
1376 1375
 
1377
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1378
-			$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1379
-			$counter = 0;
1380
-			global $color2;
1376
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1377
+            $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1378
+            $counter = 0;
1379
+            global $color2;
1381 1380
 
1382
-			echo '<div class="actions">';
1383
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1381
+            echo '<div class="actions">';
1382
+            echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1384 1383
             echo Display::return_icon('blog_newtasks.gif', get_lang('AddTasks'));
1385 1384
             echo get_lang('AddTasks') . '</a> ';
1386
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1385
+            echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1387 1386
             echo Display::return_icon('blog_task.gif', get_lang('AssignTasks'));
1388 1387
             echo get_lang('AssignTasks') . '</a>';
1389
-			?>
1388
+            ?>
1390 1389
 				<a href="<?php echo api_get_self(); ?>?action=manage_rights&blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageRights') ?>">
1391 1390
                     <?php echo Display::return_icon('blog_admin_users.png', get_lang('RightsManager'),'',ICON_SIZE_SMALL). get_lang('RightsManager') ?></a>
1392 1391
 			<?php
1393
-			echo '</div>';
1392
+            echo '</div>';
1394 1393
 
1395
-			echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1396
-			echo "<table class=\"data_table\">";
1397
-			echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1398
-					 "<th width='240'><b>",get_lang('Title'),"</b></th>\n",
1399
-					 "<th><b>",get_lang('Description'),"</b></th>\n",
1400
-					 "<th><b>",get_lang('Color'),"</b></th>\n",
1401
-					 "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
1402
-				"</tr>\n";
1394
+            echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1395
+            echo "<table class=\"data_table\">";
1396
+            echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1397
+                        "<th width='240'><b>",get_lang('Title'),"</b></th>\n",
1398
+                        "<th><b>",get_lang('Description'),"</b></th>\n",
1399
+                        "<th><b>",get_lang('Color'),"</b></th>\n",
1400
+                        "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
1401
+                "</tr>\n";
1403 1402
 
1404 1403
 
1405
-			$sql = " SELECT
1404
+            $sql = " SELECT
1406 1405
                         blog_id,
1407 1406
                         task_id,
1408 1407
                         blog_id,
@@ -1413,22 +1412,22 @@  discard block
 block discarded – undo
1413 1412
                     FROM " . $tbl_blogs_tasks . "
1414 1413
                     WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1415 1414
                     ORDER BY system_task, title";
1416
-			$result = Database::query($sql);
1417
-
1418
-
1419
-			while($task = Database::fetch_array($result)) {
1420
-				$counter++;
1421
-				$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1422
-				$delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
1423
-				$delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1424
-				$delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1425
-				$delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1426
-
1427
-				echo	'<tr class="' . $css_class . '" valign="top">',
1428
-                         '<td width="240">' . Security::remove_XSS($task['title']) . '</td>',
1429
-                         '<td>' . Security::remove_XSS($task['description']) . '</td>',
1430
-                         '<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>',
1431
-                         '<td width="50">',
1415
+            $result = Database::query($sql);
1416
+
1417
+
1418
+            while($task = Database::fetch_array($result)) {
1419
+                $counter++;
1420
+                $css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1421
+                $delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
1422
+                $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1423
+                $delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1424
+                $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1425
+
1426
+                echo	'<tr class="' . $css_class . '" valign="top">',
1427
+                            '<td width="240">' . Security::remove_XSS($task['title']) . '</td>',
1428
+                            '<td>' . Security::remove_XSS($task['description']) . '</td>',
1429
+                            '<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>',
1430
+                            '<td width="50">',
1432 1431
                             '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=edit&task_id=' . $task['task_id'] . '">',
1433 1432
                             '<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
1434 1433
                             "</a>\n",
@@ -1436,41 +1435,41 @@  discard block
 block discarded – undo
1436 1435
                             $delete_confirm,
1437 1436
                             '><img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
1438 1437
                             "</a>\n",
1439
-                         '</td>',
1438
+                            '</td>',
1440 1439
                     '</tr>';
1441
-			}
1442
-			echo "</table>";
1443
-		}
1444
-	}
1445
-
1446
-	/**
1447
-	 * Displays a list of tasks assigned to a user in this blog
1448
-	 * @author Toon Keppens
1449
-	 *
1450
-	 * @param Integer $blog_id
1451
-	 */
1452
-	public static function display_assigned_task_list ($blog_id)
1440
+            }
1441
+            echo "</table>";
1442
+        }
1443
+    }
1444
+
1445
+    /**
1446
+     * Displays a list of tasks assigned to a user in this blog
1447
+     * @author Toon Keppens
1448
+     *
1449
+     * @param Integer $blog_id
1450
+     */
1451
+    public static function display_assigned_task_list ($blog_id)
1453 1452
     {
1454
-		// Init
1455
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1456
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1457
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1458
-		$counter = 0;
1459
-		global $charset,$color2;
1460
-
1461
-		echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1462
-		echo "<table class=\"data_table\">";
1463
-		echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1464
-				 "<th width='240'><b>",get_lang('Member'),"</b></th>\n",
1465
-				 "<th><b>",get_lang('Task'),"</b></th>\n",
1466
-				 "<th><b>",get_lang('Description'),"</b></th>\n",
1467
-				 "<th><b>",get_lang('TargetDate'),"</b></th>\n",
1468
-				 "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
1469
-			"</tr>";
1470
-
1471
-		$course_id = api_get_course_int_id();
1472
-
1473
-		$sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id
1453
+        // Init
1454
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1455
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1456
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1457
+        $counter = 0;
1458
+        global $charset,$color2;
1459
+
1460
+        echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1461
+        echo "<table class=\"data_table\">";
1462
+        echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1463
+                    "<th width='240'><b>",get_lang('Member'),"</b></th>\n",
1464
+                    "<th><b>",get_lang('Task'),"</b></th>\n",
1465
+                    "<th><b>",get_lang('Description'),"</b></th>\n",
1466
+                    "<th><b>",get_lang('TargetDate'),"</b></th>\n",
1467
+                    "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
1468
+            "</tr>";
1469
+
1470
+        $course_id = api_get_course_int_id();
1471
+
1472
+        $sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id
1474 1473
 				FROM $tbl_blogs_tasks_rel_user task_rel_user
1475 1474
 				INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
1476 1475
 				INNER JOIN $tbl_users user ON task_rel_user.user_id = user.user_id
@@ -1479,45 +1478,45 @@  discard block
 block discarded – undo
1479 1478
 					task.c_id = $course_id AND
1480 1479
 					task_rel_user.blog_id = '".(int)$blog_id."'
1481 1480
 				ORDER BY target_date ASC";
1482
-		$result = Database::query($sql);
1481
+        $result = Database::query($sql);
1483 1482
 
1484
-		while ($assignment = Database::fetch_array($result)) {
1485
-			$counter++;
1486
-			$css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1487
-			$delete_icon = ($assignment['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
1488
-			$delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1489
-			$delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1490
-			$delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1483
+        while ($assignment = Database::fetch_array($result)) {
1484
+            $counter++;
1485
+            $css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1486
+            $delete_icon = ($assignment['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
1487
+            $delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1488
+            $delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1489
+            $delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1491 1490
 
1492 1491
             $username = api_htmlentities(sprintf(get_lang('LoginX'), $assignment['username']), ENT_QUOTES);
1493 1492
 
1494
-			echo	'<tr class="' . $css_class . '" valign="top">',
1495
-						 '<td width="240">' . Display::tag('span', api_get_person_name($assignment['firstname'], $assignment['lastname']), array('title'=>$username)) . '</td>',
1496
-						 '<td>'.stripslashes($assignment['title']) . '</td>',
1497
-						 '<td>'.stripslashes($assignment['description']) . '</td>',
1498
-						 '<td>' . $assignment['target_date'] . '</td>',
1499
-						 '<td width="50">',
1500
-						 	'<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'] . '">',
1501
-							'<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
1502
-							"</a>\n",
1503
-							'<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'] . '" ',
1504
-							'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"',
1505
-							'<img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
1506
-							"</a>\n",
1507
-						 '</td>',
1508
-					'</tr>';
1509
-		}
1510
-		echo "</table>";
1511
-	}
1512
-
1513
-	/**
1514
-	 * Displays new task form
1515
-	 * @author Toon Keppens
1516
-	 *
1517
-	 */
1518
-	public static function display_new_task_form ($blog_id)
1519
-	{
1520
-		// Init
1493
+            echo	'<tr class="' . $css_class . '" valign="top">',
1494
+                            '<td width="240">' . Display::tag('span', api_get_person_name($assignment['firstname'], $assignment['lastname']), array('title'=>$username)) . '</td>',
1495
+                            '<td>'.stripslashes($assignment['title']) . '</td>',
1496
+                            '<td>'.stripslashes($assignment['description']) . '</td>',
1497
+                            '<td>' . $assignment['target_date'] . '</td>',
1498
+                            '<td width="50">',
1499
+                                '<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'] . '">',
1500
+                            '<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
1501
+                            "</a>\n",
1502
+                            '<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'] . '" ',
1503
+                            'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"',
1504
+                            '<img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
1505
+                            "</a>\n",
1506
+                            '</td>',
1507
+                    '</tr>';
1508
+        }
1509
+        echo "</table>";
1510
+    }
1511
+
1512
+    /**
1513
+     * Displays new task form
1514
+     * @author Toon Keppens
1515
+     *
1516
+     */
1517
+    public static function display_new_task_form ($blog_id)
1518
+    {
1519
+        // Init
1521 1520
         $colors = array(
1522 1521
             'FFFFFF',
1523 1522
             'FFFF99',
@@ -1536,14 +1535,14 @@  discard block
 block discarded – undo
1536 1535
             '000000'
1537 1536
         );
1538 1537
 
1539
-		// form
1540
-		echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1538
+        // form
1539
+        echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1541 1540
 
1542
-		// form title
1543
-		echo '<legend>'.get_lang('AddTask').'</legend>';
1541
+        // form title
1542
+        echo '<legend>'.get_lang('AddTask').'</legend>';
1544 1543
 
1545
-		// task title
1546
-		echo '	<div class="control-group">
1544
+        // task title
1545
+        echo '	<div class="control-group">
1547 1546
 					<label class="control-label">
1548 1547
 						<span class="form_required">*</span>' . get_lang('Title') . '
1549 1548
 					</label>
@@ -1552,8 +1551,8 @@  discard block
 block discarded – undo
1552 1551
 					</div>
1553 1552
 				</div>';
1554 1553
 
1555
-		// task comment
1556
-		echo '	<div class="control-group">
1554
+        // task comment
1555
+        echo '	<div class="control-group">
1557 1556
 					<label class="control-label">
1558 1557
 						' . get_lang('Description') . '
1559 1558
 					</label>
@@ -1562,8 +1561,8 @@  discard block
 block discarded – undo
1562 1561
 					</div>
1563 1562
 				</div>';
1564 1563
 
1565
-		// task management
1566
-		echo '	<div class="control-group">
1564
+        // task management
1565
+        echo '	<div class="control-group">
1567 1566
 					<label class="control-label">
1568 1567
 						' . get_lang('TaskManager') . '
1569 1568
 					</label>
@@ -1584,12 +1583,12 @@  discard block
 block discarded – undo
1584 1583
                         echo '<td style="border:1px dotted #808080; text-align:center;"><input id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1585 1584
                     echo '</tr>';
1586 1585
                 echo '</table>';
1587
-		echo '		</div>
1586
+        echo '		</div>
1588 1587
 				</div>';
1589 1588
 
1590 1589
 
1591
-		// task color
1592
-		echo '	<div class="control-group">
1590
+        // task color
1591
+        echo '	<div class="control-group">
1593 1592
 					<label class="control-label">
1594 1593
 						' . get_lang('Color') . '
1595 1594
 					</label>
@@ -1600,40 +1599,40 @@  discard block
 block discarded – undo
1600 1599
                     echo '<option value="' . $color . '" ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1601 1600
                 }
1602 1601
         echo '</select>';
1603
-		echo '		</div>
1602
+        echo '		</div>
1604 1603
 				</div>';
1605 1604
 
1606
-		// submit
1607
-		echo '	<div class="control-group">
1605
+        // submit
1606
+        echo '	<div class="control-group">
1608 1607
 					<div class="controls">
1609 1608
 							<input type="hidden" name="action" value="" />
1610 1609
 							<input type="hidden" name="new_task_submit" value="true" />
1611 1610
 						<button class="save" type="submit" name="Submit">' . get_lang('Save') . '</button>
1612 1611
 					</div>
1613 1612
 				</div>';
1614
-		echo '</form>';
1613
+        echo '</form>';
1615 1614
 
1616
-		echo '<div style="clear:both; margin-bottom: 10px;"></div>';
1617
-	}
1615
+        echo '<div style="clear:both; margin-bottom: 10px;"></div>';
1616
+    }
1618 1617
 
1619 1618
 
1620
-	/**
1621
-	 * Displays edit task form
1622
-	 * @author Toon Keppens
1623
-	 *
1624
-	 */
1625
-	public static function display_edit_task_form ($blog_id, $task_id) {
1626
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1619
+    /**
1620
+     * Displays edit task form
1621
+     * @author Toon Keppens
1622
+     *
1623
+     */
1624
+    public static function display_edit_task_form ($blog_id, $task_id) {
1625
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1627 1626
         $course_id = api_get_course_int_id();
1628 1627
 
1629
-		$colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1628
+        $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1630 1629
 
1631
-		$sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1632
-		$result = Database::query($sql);
1633
-		$task = Database::fetch_array($result);
1630
+        $sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1631
+        $result = Database::query($sql);
1632
+        $task = Database::fetch_array($result);
1634 1633
 
1635
-		// Display
1636
-		echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1634
+        // Display
1635
+        echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1637 1636
 					<legend>' . get_lang('EditTask') . '</legend>
1638 1637
 					<table width="100%" border="0" cellspacing="2">
1639 1638
 						<tr>
@@ -1645,42 +1644,42 @@  discard block
 block discarded – undo
1645 1644
 					   <td><textarea name="task_description" cols="45">'.Security::remove_XSS($task['description']).'</textarea></td>
1646 1645
 						</tr>';
1647 1646
 
1648
-						/* edit by Kevin Van Den Haute ([email protected]) */
1649
-						$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1647
+                        /* edit by Kevin Van Den Haute ([email protected]) */
1648
+                        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1650 1649
 
1651
-						$sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1650
+                        $sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1652 1651
 							     WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
1653
-						$result = Database::query($sql);
1654
-
1655
-						$arrPermissions = array();
1656
-
1657
-						while ($row = Database::fetch_array($result))
1658
-							$arrPermissions[] = $row['action'];
1659
-
1660
-						    echo '<tr>';
1661
-							echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1662
-							echo '<td>';
1663
-								echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1664
-									echo '<tr>';
1665
-										echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1666
-										echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1667
-									echo '</tr>';
1668
-									echo '<tr>';
1669
-										echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1670
-										echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1671
-										echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1672
-									echo '</tr>';
1673
-									echo '<tr>';
1674
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1675
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1676
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1677
-									echo '</tr>';
1678
-								echo '</table>';
1679
-							echo '</td>';
1680
-						echo '</tr>';
1681
-						/* end of edit */
1682
-
1683
-						echo '<tr>
1652
+                        $result = Database::query($sql);
1653
+
1654
+                        $arrPermissions = array();
1655
+
1656
+                        while ($row = Database::fetch_array($result))
1657
+                            $arrPermissions[] = $row['action'];
1658
+
1659
+                            echo '<tr>';
1660
+                            echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1661
+                            echo '<td>';
1662
+                                echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1663
+                                    echo '<tr>';
1664
+                                        echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1665
+                                        echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1666
+                                    echo '</tr>';
1667
+                                    echo '<tr>';
1668
+                                        echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1669
+                                        echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1670
+                                        echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1671
+                                    echo '</tr>';
1672
+                                    echo '<tr>';
1673
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1674
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1675
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1676
+                                    echo '</tr>';
1677
+                                echo '</table>';
1678
+                            echo '</td>';
1679
+                        echo '</tr>';
1680
+                        /* end of edit */
1681
+
1682
+                        echo '<tr>
1684 1683
 					   <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
1685 1684
 					   <td>
1686 1685
 					   	<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">';
@@ -1689,7 +1688,7 @@  discard block
 block discarded – undo
1689 1688
                                 $style = 'style="background-color: #' . $color . '"';
1690 1689
                                 echo '<option value="' . $color . '" ' . $style . ' ' . $selected . ' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1691 1690
                             }
1692
-		echo '			   </select>
1691
+        echo '			   </select>
1693 1692
 						  </td>
1694 1693
 						</tr>
1695 1694
 						<tr>
@@ -1702,34 +1701,34 @@  discard block
 block discarded – undo
1702 1701
 						</tr>
1703 1702
 					</table>
1704 1703
 				</form>';
1705
-	}
1706
-
1707
-	/**
1708
-	 * @param $blog_id
1709
-	 * @return FormValidator
1710
-	 */
1711
-	public static function getTaskForm($blog_id)
1712
-	{
1713
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1714
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1715
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1716
-		$course_id = api_get_course_int_id();
1717
-
1718
-		// Get users in this blog / make select list of it
1719
-		$sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
1704
+    }
1705
+
1706
+    /**
1707
+     * @param $blog_id
1708
+     * @return FormValidator
1709
+     */
1710
+    public static function getTaskForm($blog_id)
1711
+    {
1712
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1713
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1714
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1715
+        $course_id = api_get_course_int_id();
1716
+
1717
+        // Get users in this blog / make select list of it
1718
+        $sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
1720 1719
 				FROM $tbl_users user
1721 1720
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
1722 1721
 				ON user.user_id = blogs_rel_user.user_id
1723 1722
 				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
1724
-		$result = Database::query($sql);
1723
+        $result = Database::query($sql);
1725 1724
 
1726
-		$options = array();
1727
-		while ($user = Database::fetch_array($result)) {
1728
-			$options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
1729
-		}
1725
+        $options = array();
1726
+        while ($user = Database::fetch_array($result)) {
1727
+            $options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
1728
+        }
1730 1729
 
1731
-		// Get tasks in this blog / make select list of it
1732
-		$sql = "
1730
+        // Get tasks in this blog / make select list of it
1731
+        $sql = "
1733 1732
 			SELECT
1734 1733
 				blog_id,
1735 1734
 				task_id,
@@ -1741,97 +1740,97 @@  discard block
 block discarded – undo
1741 1740
 			FROM $tbl_blogs_tasks
1742 1741
 			WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1743 1742
 			ORDER BY system_task, title";
1744
-		$result = Database::query($sql);
1745
-
1746
-		$taskOptions = array();
1747
-		while ($task = Database::fetch_array($result)) {
1748
-			$taskOptions[$task['task_id']] = stripslashes($task['title']);
1749
-		}
1750
-
1751
-		$form = new FormValidator(
1752
-			'assign_task',
1753
-			'post',
1754
-			api_get_path(
1755
-				WEB_CODE_PATH
1756
-			).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id
1757
-		);
1758
-
1759
-		$form->addHeader(get_lang('AssignTask'));
1760
-		$form->addSelect('task_user_id', get_lang('SelectUser'), $options);
1761
-		$form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions);
1762
-		$form->addDatePicker('task_day', get_lang('SelectTargetDate'));
1763
-
1764
-		$form->addHidden('action', '');
1765
-		$form->addButtonSave(get_lang('Ok'));
1766
-
1767
-		return $form;
1768
-	}
1769
-
1770
-	/**
1771
-	 * Displays assign task form
1772
-	 * @author Toon Keppens
1773
-	 *
1774
-	 */
1775
-	public static function display_assign_task_form($blog_id)
1776
-	{
1777
-		$form = self::getTaskForm($blog_id);
1778
-		$form->addHidden('assign_task_submit', 'true');
1779
-		$form->display();
1780
-		echo '<div style="clear: both; margin-bottom:10px;"></div>';
1781
-	}
1782
-
1783
-	/**
1784
-	 * Displays assign task form
1785
-	 * @author Toon Keppens
1786
-	 *
1787
-	 */
1788
-	public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1789
-	{
1790
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1791
-
1792
-		$course_id = api_get_course_int_id();
1793
-
1794
-		// Get assignd date;
1795
-		$sql = "
1743
+        $result = Database::query($sql);
1744
+
1745
+        $taskOptions = array();
1746
+        while ($task = Database::fetch_array($result)) {
1747
+            $taskOptions[$task['task_id']] = stripslashes($task['title']);
1748
+        }
1749
+
1750
+        $form = new FormValidator(
1751
+            'assign_task',
1752
+            'post',
1753
+            api_get_path(
1754
+                WEB_CODE_PATH
1755
+            ).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id
1756
+        );
1757
+
1758
+        $form->addHeader(get_lang('AssignTask'));
1759
+        $form->addSelect('task_user_id', get_lang('SelectUser'), $options);
1760
+        $form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions);
1761
+        $form->addDatePicker('task_day', get_lang('SelectTargetDate'));
1762
+
1763
+        $form->addHidden('action', '');
1764
+        $form->addButtonSave(get_lang('Ok'));
1765
+
1766
+        return $form;
1767
+    }
1768
+
1769
+    /**
1770
+     * Displays assign task form
1771
+     * @author Toon Keppens
1772
+     *
1773
+     */
1774
+    public static function display_assign_task_form($blog_id)
1775
+    {
1776
+        $form = self::getTaskForm($blog_id);
1777
+        $form->addHidden('assign_task_submit', 'true');
1778
+        $form->display();
1779
+        echo '<div style="clear: both; margin-bottom:10px;"></div>';
1780
+    }
1781
+
1782
+    /**
1783
+     * Displays assign task form
1784
+     * @author Toon Keppens
1785
+     *
1786
+     */
1787
+    public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1788
+    {
1789
+        $tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1790
+
1791
+        $course_id = api_get_course_int_id();
1792
+
1793
+        // Get assignd date;
1794
+        $sql = "
1796 1795
 			SELECT target_date
1797 1796
 			FROM $tbl_blogs_tasks_rel_user
1798 1797
 			WHERE c_id = $course_id AND
1799 1798
 			      blog_id = '".(int)$blog_id."' AND
1800 1799
 			      user_id = '".(int)$user_id."' AND
1801 1800
 			      task_id = '".(int)$task_id."'";
1802
-		$result = Database::query($sql);
1803
-		$row = Database::fetch_assoc($result);
1804
-
1805
-		$date = $row['target_date'];
1806
-
1807
-		$defaults = [
1808
-			'task_user_id' => $user_id,
1809
-			'task_task_id' => $task_id,
1810
-			'task_day' => $date
1811
-		];
1812
-		$form = self::getTaskForm($blog_id);
1813
-		$form->addHidden('old_task_id', $task_id);
1814
-		$form->addHidden('old_user_id', $user_id);
1815
-		$form->addHidden('old_target_date', $date);
1816
-		$form->addHidden('assign_task_edit_submit', 'true');
1817
-		$form->setDefaults($defaults);
1818
-		$form->display();
1819
-	}
1820
-
1821
-	/**
1822
-	 * Assigns a task to a user in a blog
1823
-	 *
1824
-	 * @param Integer $blog_id
1825
-	 * @param Integer $user_id
1826
-	 * @param Integer $task_id
1827
-	 * @param Date $target_date
1828
-	 */
1829
-	public static function assign_task($blog_id, $user_id, $task_id, $target_date)
1830
-	{
1831
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1832
-		$course_id = api_get_course_int_id();
1833
-
1834
-		$sql = "
1801
+        $result = Database::query($sql);
1802
+        $row = Database::fetch_assoc($result);
1803
+
1804
+        $date = $row['target_date'];
1805
+
1806
+        $defaults = [
1807
+            'task_user_id' => $user_id,
1808
+            'task_task_id' => $task_id,
1809
+            'task_day' => $date
1810
+        ];
1811
+        $form = self::getTaskForm($blog_id);
1812
+        $form->addHidden('old_task_id', $task_id);
1813
+        $form->addHidden('old_user_id', $user_id);
1814
+        $form->addHidden('old_target_date', $date);
1815
+        $form->addHidden('assign_task_edit_submit', 'true');
1816
+        $form->setDefaults($defaults);
1817
+        $form->display();
1818
+    }
1819
+
1820
+    /**
1821
+     * Assigns a task to a user in a blog
1822
+     *
1823
+     * @param Integer $blog_id
1824
+     * @param Integer $user_id
1825
+     * @param Integer $task_id
1826
+     * @param Date $target_date
1827
+     */
1828
+    public static function assign_task($blog_id, $user_id, $task_id, $target_date)
1829
+    {
1830
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1831
+        $course_id = api_get_course_int_id();
1832
+
1833
+        $sql = "
1835 1834
 			SELECT COUNT(*) as 'number'
1836 1835
 			FROM " . $tbl_blogs_tasks_rel_user . "
1837 1836
 			WHERE c_id = $course_id AND
@@ -1840,11 +1839,11 @@  discard block
 block discarded – undo
1840 1839
 			AND	task_id = " . (int)$task_id . "
1841 1840
 		";
1842 1841
 
1843
-		$result = Database::query($sql);
1844
-		$row = Database::fetch_assoc($result);
1842
+        $result = Database::query($sql);
1843
+        $row = Database::fetch_assoc($result);
1845 1844
 
1846
-		if ($row['number'] == 0) {
1847
-			$sql = "
1845
+        if ($row['number'] == 0) {
1846
+            $sql = "
1848 1847
 				INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
1849 1848
 					c_id,
1850 1849
 					blog_id,
@@ -1859,9 +1858,9 @@  discard block
 block discarded – undo
1859 1858
 					'" . Database::escape_string($target_date) . "'
1860 1859
 				)";
1861 1860
 
1862
-			Database::query($sql);
1863
-		}
1864
-	}
1861
+            Database::query($sql);
1862
+        }
1863
+    }
1865 1864
 
1866 1865
     /**
1867 1866
      * @param $blog_id
@@ -1881,11 +1880,11 @@  discard block
 block discarded – undo
1881 1880
         $old_task_id,
1882 1881
         $old_target_date
1883 1882
     ) {
1884
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1883
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1885 1884
 
1886
-		$course_id = api_get_course_int_id();
1885
+        $course_id = api_get_course_int_id();
1887 1886
 
1888
-		$sql = "SELECT COUNT(*) as 'number'
1887
+        $sql = "SELECT COUNT(*) as 'number'
1889 1888
                 FROM " . $tbl_blogs_tasks_rel_user . "
1890 1889
                 WHERE
1891 1890
                     c_id = $course_id AND
@@ -1894,11 +1893,11 @@  discard block
 block discarded – undo
1894 1893
                     task_id = " . (int)$task_id . "
1895 1894
             ";
1896 1895
 
1897
-		$result = Database::query($sql);
1898
-		$row = Database::fetch_assoc($result);
1896
+        $result = Database::query($sql);
1897
+        $row = Database::fetch_assoc($result);
1899 1898
 
1900
-		if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1901
-			$sql = "
1899
+        if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1900
+            $sql = "
1902 1901
 				UPDATE " . $tbl_blogs_tasks_rel_user . "
1903 1902
 				SET
1904 1903
 					user_id = " . (int)$user_id . ",
@@ -1911,76 +1910,76 @@  discard block
 block discarded – undo
1911 1910
 					task_id = " . (int)$old_task_id . " AND
1912 1911
 					target_date = '" . Database::escape_string($old_target_date) . "'
1913 1912
 			";
1914
-			Database::query($sql);
1915
-		}
1916
-	}
1917
-
1918
-	/**
1919
-	 * Displays a list with posts a user can select to execute his task.
1920
-	 *
1921
-	 * @param Integer $blog_id
1922
-	 * @param unknown_type $task_id
1923
-	 */
1924
-	public static function display_select_task_post($blog_id, $task_id)
1913
+            Database::query($sql);
1914
+        }
1915
+    }
1916
+
1917
+    /**
1918
+     * Displays a list with posts a user can select to execute his task.
1919
+     *
1920
+     * @param Integer $blog_id
1921
+     * @param unknown_type $task_id
1922
+     */
1923
+    public static function display_select_task_post($blog_id, $task_id)
1925 1924
     {
1926
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1927
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1928
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1929
-		$course_id = api_get_course_int_id();
1925
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1926
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1927
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1928
+        $course_id = api_get_course_int_id();
1930 1929
 
1931 1930
 
1932
-		$sql = "SELECT title, description FROM $tbl_blogs_tasks
1931
+        $sql = "SELECT title, description FROM $tbl_blogs_tasks
1933 1932
 				WHERE task_id = '".(int)$task_id."'
1934 1933
 				AND c_id = $course_id";
1935
-		$result = Database::query($sql);
1936
-		$row = Database::fetch_assoc($result);
1937
-		// Get posts and authors
1938
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
1934
+        $result = Database::query($sql);
1935
+        $row = Database::fetch_assoc($result);
1936
+        // Get posts and authors
1937
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
1939 1938
 				FROM $tbl_blogs_posts post
1940 1939
 				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1941 1940
 				WHERE post.blog_id = '".(int)$blog_id."' AND post.c_id = $course_id
1942 1941
 				ORDER BY post_id DESC
1943 1942
 				LIMIT 0, 100";
1944
-		$result = Database::query($sql);
1943
+        $result = Database::query($sql);
1945 1944
 
1946
-		// Display
1947
-		echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1948
-		echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1945
+        // Display
1946
+        echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1947
+        echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1949 1948
 
1950
-		if (Database::num_rows($result) > 0) {
1951
-			while($blog_post = Database::fetch_array($result)) {
1952
-			    $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1953
-				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 />';
1954
-			}
1949
+        if (Database::num_rows($result) > 0) {
1950
+            while($blog_post = Database::fetch_array($result)) {
1951
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1952
+                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 />';
1953
+            }
1955 1954
         } else {
1956 1955
             echo get_lang('NoArticles');
1957 1956
         }
1958
-	}
1959
-
1960
-	/**
1961
-	 * Subscribes a user to a given blog
1962
-	 * @author Toon Keppens
1963
-	 *
1964
-	 * @param Integer $blog_id
1965
-	 * @param Integer $user_id
1966
-	 */
1967
-	public static function set_user_subscribed($blog_id, $user_id)
1957
+    }
1958
+
1959
+    /**
1960
+     * Subscribes a user to a given blog
1961
+     * @author Toon Keppens
1962
+     *
1963
+     * @param Integer $blog_id
1964
+     * @param Integer $user_id
1965
+     */
1966
+    public static function set_user_subscribed($blog_id, $user_id)
1968 1967
     {
1969
-		// Init
1970
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1971
-		$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
1968
+        // Init
1969
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1970
+        $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
1972 1971
 
1973
-		$course_id = api_get_course_int_id();
1972
+        $course_id = api_get_course_int_id();
1974 1973
 
1975
-		// Subscribe the user
1976
-		$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1974
+        // Subscribe the user
1975
+        $sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1977 1976
 		        VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
1978
-		Database::query($sql);
1977
+        Database::query($sql);
1979 1978
 
1980
-		// Give this user basic rights
1981
-		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1979
+        // Give this user basic rights
1980
+        $sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1982 1981
 		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
1983
-		Database::query($sql);
1982
+        Database::query($sql);
1984 1983
 
1985 1984
         $id = Database::insert_id();
1986 1985
         if ($id) {
@@ -1988,9 +1987,9 @@  discard block
 block discarded – undo
1988 1987
             Database::query($sql);
1989 1988
         }
1990 1989
 
1991
-		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1990
+        $sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1992 1991
 		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
1993
-		Database::query($sql);
1992
+        Database::query($sql);
1994 1993
 
1995 1994
         $id = Database::insert_id();
1996 1995
         if ($id) {
@@ -1998,197 +1997,197 @@  discard block
 block discarded – undo
1998 1997
             Database::query($sql);
1999 1998
         }
2000 1999
 
2001
-	}
2000
+    }
2002 2001
 
2003
-	/**
2004
-	 * Unsubscribe a user from a given blog
2005
-	 * @author Toon Keppens
2006
-	 *
2007
-	 * @param Integer $blog_id
2008
-	 * @param Integer $user_id
2009
-	 */
2010
-	public static function set_user_unsubscribed($blog_id, $user_id)
2002
+    /**
2003
+     * Unsubscribe a user from a given blog
2004
+     * @author Toon Keppens
2005
+     *
2006
+     * @param Integer $blog_id
2007
+     * @param Integer $user_id
2008
+     */
2009
+    public static function set_user_unsubscribed($blog_id, $user_id)
2011 2010
     {
2012
-		// Init
2011
+        // Init
2013 2012
         $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2014 2013
         $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
2015 2014
 
2016
-		// Unsubscribe the user
2017
-		$sql = "DELETE FROM $tbl_blogs_rel_user
2015
+        // Unsubscribe the user
2016
+        $sql = "DELETE FROM $tbl_blogs_rel_user
2018 2017
 		        WHERE blog_id = '".(int)$blog_id."' AND user_id = '".(int)$user_id."'";
2019
-		Database::query($sql);
2018
+        Database::query($sql);
2020 2019
 
2021
-		// Remove this user's permissions.
2022
-		$sql = "DELETE FROM $tbl_user_permissions
2020
+        // Remove this user's permissions.
2021
+        $sql = "DELETE FROM $tbl_user_permissions
2023 2022
 		        WHERE user_id = '".(int)$user_id."'";
2024
-		Database::query($sql);
2025
-	}
2026
-
2027
-	/**
2028
-	 * Displays the form to register users in a blog (in a course)
2029
-	 * The listed users are users subcribed in the course.
2030
-	 * @author Toon Keppens
2031
-	 *
2032
-	 * @param Integer $blog_id
2033
-	 *
2034
-	 * @return Html Form with sortable table with users to subcribe in a blog, in a course.
2035
-	 */
2036
-	public static function display_form_user_subscribe($blog_id)
2037
-	{
2038
-		$_course = api_get_course_info();
2039
-		$is_western_name_order = api_is_western_name_order();
2040
-		$session_id = api_get_session_id();
2041
-		$course_id = $_course['real_id'];
2042
-
2043
-		$currentCourse = $_course['code'];
2044
-		$tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2045
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2046
-
2047
-		echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
2048
-
2049
-		$properties["width"] = "100%";
2050
-
2051
-		// Get blog members' id.
2052
-		$sql = "SELECT user.user_id FROM $tbl_users user
2023
+        Database::query($sql);
2024
+    }
2025
+
2026
+    /**
2027
+     * Displays the form to register users in a blog (in a course)
2028
+     * The listed users are users subcribed in the course.
2029
+     * @author Toon Keppens
2030
+     *
2031
+     * @param Integer $blog_id
2032
+     *
2033
+     * @return Html Form with sortable table with users to subcribe in a blog, in a course.
2034
+     */
2035
+    public static function display_form_user_subscribe($blog_id)
2036
+    {
2037
+        $_course = api_get_course_info();
2038
+        $is_western_name_order = api_is_western_name_order();
2039
+        $session_id = api_get_session_id();
2040
+        $course_id = $_course['real_id'];
2041
+
2042
+        $currentCourse = $_course['code'];
2043
+        $tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2044
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2045
+
2046
+        echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
2047
+
2048
+        $properties["width"] = "100%";
2049
+
2050
+        // Get blog members' id.
2051
+        $sql = "SELECT user.user_id FROM $tbl_users user
2053 2052
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2054 2053
 				ON user.user_id = blogs_rel_user.user_id
2055 2054
 				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".intval($blog_id)."'";
2056
-		$result = Database::query($sql);
2057
-
2058
-		$blog_member_ids = array();
2059
-		while($user = Database::fetch_array($result)) {
2060
-			$blog_member_ids[] = $user['user_id'];
2061
-		}
2062
-
2063
-		// Set table headers
2064
-		$column_header[] = array ('', false, '');
2065
-		if ($is_western_name_order) {
2066
-			$column_header[] = array(get_lang('FirstName'), true, '');
2067
-			$column_header[] = array(get_lang('LastName'), true, '');
2068
-		} else {
2069
-			$column_header[] = array(get_lang('LastName'), true, '');
2070
-			$column_header[] = array(get_lang('FirstName'), true, '');
2071
-		}
2072
-		$column_header[] = array(get_lang('Email'), false, '');
2073
-		$column_header[] = array(get_lang('Register'), false, '');
2055
+        $result = Database::query($sql);
2056
+
2057
+        $blog_member_ids = array();
2058
+        while($user = Database::fetch_array($result)) {
2059
+            $blog_member_ids[] = $user['user_id'];
2060
+        }
2061
+
2062
+        // Set table headers
2063
+        $column_header[] = array ('', false, '');
2064
+        if ($is_western_name_order) {
2065
+            $column_header[] = array(get_lang('FirstName'), true, '');
2066
+            $column_header[] = array(get_lang('LastName'), true, '');
2067
+        } else {
2068
+            $column_header[] = array(get_lang('LastName'), true, '');
2069
+            $column_header[] = array(get_lang('FirstName'), true, '');
2070
+        }
2071
+        $column_header[] = array(get_lang('Email'), false, '');
2072
+        $column_header[] = array(get_lang('Register'), false, '');
2074 2073
 
2075 2074
         $student_list = CourseManager:: get_student_list_from_course_code(
2076 2075
             $currentCourse,
2077 2076
             false,
2078 2077
             $session_id
2079 2078
         );
2080
-		$user_data = array();
2081
-
2082
-		// Add users that are not in this blog to the list.
2083
-		foreach ($student_list as $key=>$user) {
2084
-			if(isset($user['id_user'])) {
2085
-				$user['user_id'] = $user['id_user'];
2086
-			}
2087
-			if(!in_array($user['user_id'],$blog_member_ids)) {
2088
-				$a_infosUser = api_get_user_info($user['user_id']);
2089
-				$row = array ();
2090
-				$row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2091
-				$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2092
-				if ($is_western_name_order) {
2093
-					$row[] = $a_infosUser["firstname"];
2094
-					$row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2095
-				} else {
2096
-					$row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2097
-					$row[] = $a_infosUser["firstname"];
2098
-				}
2099
-				$row[] = Display::icon_mailto_link($a_infosUser["email"]);
2100
-
2101
-				//Link to register users
2102
-				if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2103
-					$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>";
2104
-				} else {
2105
-					$row[] = '';
2106
-				}
2107
-				$user_data[] = $row;
2108
-			}
2109
-		}
2110
-
2111
-		// Display
2112
-		$query_vars['action'] = 'manage_members';
2113
-		$query_vars['blog_id'] = $blog_id;
2114
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2115
-			Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2116
-			$link = '';
2117
-			$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2118
-			$link .= "blog_id=$blog_id&";
2119
-
2120
-			echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2121
-			echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2122
-			echo get_lang('WithSelected') . ' : ';
2123
-			echo '<select name="action">';
2124
-			echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2125
-			echo '</select>';
2126
-			echo '<input type="hidden" name="register" value="true" />';
2127
-			echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2128
-		echo '</form>';
2129
-	}
2130
-
2131
-	/**
2132
-	 * Displays the form to register users in a blog (in a course)
2133
-	 * The listed users are users subcribed in the course.
2134
-	 * @author Toon Keppens
2135
-	 *
2136
-	 * @param Integer $blog_id
2137
-	 *
2138
-	 * @return Html Form with sortable table with users to unsubcribe from a blog.
2139
-	 */
2140
-	public static function display_form_user_unsubscribe ($blog_id)
2141
-	{
2142
-		$_user = api_get_user_info();
2143
-		$is_western_name_order = api_is_western_name_order();
2144
-
2145
-		// Init
2146
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2147
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2148
-
2149
-		echo '<legend>'.get_lang('UnsubscribeMembers').'</legend>';
2150
-
2151
-		$properties["width"] = "100%";
2152
-		//table column titles
2153
-		$column_header[] = array ('', false, '');
2154
-		if ($is_western_name_order) {
2155
-			$column_header[] = array (get_lang('FirstName'), true, '');
2156
-			$column_header[] = array (get_lang('LastName'), true, '');
2157
-		} else {
2158
-			$column_header[] = array (get_lang('LastName'), true, '');
2159
-			$column_header[] = array (get_lang('FirstName'), true, '');
2160
-		}
2161
-		$column_header[] = array (get_lang('Email'), false, '');
2162
-		$column_header[] = array (get_lang('TaskManager'), true, '');
2163
-		$column_header[] = array (get_lang('UnRegister'), false, '');
2164
-
2165
-		$course_id = api_get_course_int_id();
2166
-
2167
-		$sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2079
+        $user_data = array();
2080
+
2081
+        // Add users that are not in this blog to the list.
2082
+        foreach ($student_list as $key=>$user) {
2083
+            if(isset($user['id_user'])) {
2084
+                $user['user_id'] = $user['id_user'];
2085
+            }
2086
+            if(!in_array($user['user_id'],$blog_member_ids)) {
2087
+                $a_infosUser = api_get_user_info($user['user_id']);
2088
+                $row = array ();
2089
+                $row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2090
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2091
+                if ($is_western_name_order) {
2092
+                    $row[] = $a_infosUser["firstname"];
2093
+                    $row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2094
+                } else {
2095
+                    $row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2096
+                    $row[] = $a_infosUser["firstname"];
2097
+                }
2098
+                $row[] = Display::icon_mailto_link($a_infosUser["email"]);
2099
+
2100
+                //Link to register users
2101
+                if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2102
+                    $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>";
2103
+                } else {
2104
+                    $row[] = '';
2105
+                }
2106
+                $user_data[] = $row;
2107
+            }
2108
+        }
2109
+
2110
+        // Display
2111
+        $query_vars['action'] = 'manage_members';
2112
+        $query_vars['blog_id'] = $blog_id;
2113
+        echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2114
+            Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2115
+            $link = '';
2116
+            $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2117
+            $link .= "blog_id=$blog_id&";
2118
+
2119
+            echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2120
+            echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2121
+            echo get_lang('WithSelected') . ' : ';
2122
+            echo '<select name="action">';
2123
+            echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2124
+            echo '</select>';
2125
+            echo '<input type="hidden" name="register" value="true" />';
2126
+            echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2127
+        echo '</form>';
2128
+    }
2129
+
2130
+    /**
2131
+     * Displays the form to register users in a blog (in a course)
2132
+     * The listed users are users subcribed in the course.
2133
+     * @author Toon Keppens
2134
+     *
2135
+     * @param Integer $blog_id
2136
+     *
2137
+     * @return Html Form with sortable table with users to unsubcribe from a blog.
2138
+     */
2139
+    public static function display_form_user_unsubscribe ($blog_id)
2140
+    {
2141
+        $_user = api_get_user_info();
2142
+        $is_western_name_order = api_is_western_name_order();
2143
+
2144
+        // Init
2145
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2146
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2147
+
2148
+        echo '<legend>'.get_lang('UnsubscribeMembers').'</legend>';
2149
+
2150
+        $properties["width"] = "100%";
2151
+        //table column titles
2152
+        $column_header[] = array ('', false, '');
2153
+        if ($is_western_name_order) {
2154
+            $column_header[] = array (get_lang('FirstName'), true, '');
2155
+            $column_header[] = array (get_lang('LastName'), true, '');
2156
+        } else {
2157
+            $column_header[] = array (get_lang('LastName'), true, '');
2158
+            $column_header[] = array (get_lang('FirstName'), true, '');
2159
+        }
2160
+        $column_header[] = array (get_lang('Email'), false, '');
2161
+        $column_header[] = array (get_lang('TaskManager'), true, '');
2162
+        $column_header[] = array (get_lang('UnRegister'), false, '');
2163
+
2164
+        $course_id = api_get_course_int_id();
2165
+
2166
+        $sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2168 2167
                 FROM $tbl_users user INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2169 2168
                 ON user.user_id = blogs_rel_user.user_id
2170 2169
                 WHERE blogs_rel_user.c_id = $course_id AND  blogs_rel_user.blog_id = '".(int)$blog_id."'";
2171 2170
 
2172
-		if (!($sql_result = Database::query($sql))) {
2173
-			return false;
2174
-		}
2175
-
2176
-		$user_data = array ();
2177
-
2178
-		while ($myrow = Database::fetch_array($sql_result)) {
2179
-			$row = array ();
2180
-			$row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2181
-			$username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2182
-			if ($is_western_name_order) {
2183
-				$row[] = $myrow["firstname"];
2184
-				$row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2185
-			} else {
2186
-				$row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2187
-				$row[] = $myrow["firstname"];
2188
-			}
2189
-			$row[] = Display::icon_mailto_link($myrow["email"]);
2190
-
2191
-			$sql = "SELECT bt.title task
2171
+        if (!($sql_result = Database::query($sql))) {
2172
+            return false;
2173
+        }
2174
+
2175
+        $user_data = array ();
2176
+
2177
+        while ($myrow = Database::fetch_array($sql_result)) {
2178
+            $row = array ();
2179
+            $row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2180
+            $username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2181
+            if ($is_western_name_order) {
2182
+                $row[] = $myrow["firstname"];
2183
+                $row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2184
+            } else {
2185
+                $row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2186
+                $row[] = $myrow["firstname"];
2187
+            }
2188
+            $row[] = Display::icon_mailto_link($myrow["email"]);
2189
+
2190
+            $sql = "SELECT bt.title task
2192 2191
 					FROM " . Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER) . " btu
2193 2192
 					INNER JOIN " . Database::get_course_table(TABLE_BLOGS_TASKS) . " bt
2194 2193
 					ON btu.task_id = bt.task_id
@@ -2196,158 +2195,158 @@  discard block
 block discarded – undo
2196 2195
 							bt.c_id 	= $course_id  AND
2197 2196
 							btu.blog_id = $blog_id AND
2198 2197
 							btu.user_id = " . $myrow['user_id'];
2199
-			$sql_res = Database::query($sql);
2200
-
2201
-			$task = '';
2202
-
2203
-			while($r = Database::fetch_array($sql_res)) {
2204
-				$task .= stripslashes($r['task']) . ', ';
2205
-			}
2206
-			//echo $task;
2207
-			$task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
2208
-			$row[] = $task;
2209
-			//Link to register users
2210
-
2211
-			if ($myrow["user_id"] != $_user['user_id']) {
2212
-				$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>";
2213
-			} else {
2214
-				$row[] = '';
2215
-			}
2216
-
2217
-			$user_data[] = $row;
2218
-		}
2219
-
2220
-		$query_vars['action'] = 'manage_members';
2221
-		$query_vars['blog_id'] = $blog_id;
2222
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2223
-		Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2224
-		$link = '';
2225
-		$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2226
-		$link .= "blog_id=$blog_id&";
2227
-
2228
-		echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2229
-		echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2230
-		echo get_lang('WithSelected') . ' : ';
2231
-		echo '<select name="action">';
2232
-		echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2233
-		echo '</select>';
2234
-		echo '<input type="hidden" name="unregister" value="true" />';
2235
-		echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2236
-		echo '</form>';
2237
-	}
2238
-
2239
-	/**
2240
-	 * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
2241
-	 * The blog admin can thus select what a certain user can do in the current blog
2242
-	 *
2243
-	 * @param Integer $blog_id
2244
-	 */
2245
-	public static function display_form_user_rights ($blog_id)
2198
+            $sql_res = Database::query($sql);
2199
+
2200
+            $task = '';
2201
+
2202
+            while($r = Database::fetch_array($sql_res)) {
2203
+                $task .= stripslashes($r['task']) . ', ';
2204
+            }
2205
+            //echo $task;
2206
+            $task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
2207
+            $row[] = $task;
2208
+            //Link to register users
2209
+
2210
+            if ($myrow["user_id"] != $_user['user_id']) {
2211
+                $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>";
2212
+            } else {
2213
+                $row[] = '';
2214
+            }
2215
+
2216
+            $user_data[] = $row;
2217
+        }
2218
+
2219
+        $query_vars['action'] = 'manage_members';
2220
+        $query_vars['blog_id'] = $blog_id;
2221
+        echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2222
+        Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2223
+        $link = '';
2224
+        $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2225
+        $link .= "blog_id=$blog_id&";
2226
+
2227
+        echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2228
+        echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2229
+        echo get_lang('WithSelected') . ' : ';
2230
+        echo '<select name="action">';
2231
+        echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2232
+        echo '</select>';
2233
+        echo '<input type="hidden" name="unregister" value="true" />';
2234
+        echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2235
+        echo '</form>';
2236
+    }
2237
+
2238
+    /**
2239
+     * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
2240
+     * The blog admin can thus select what a certain user can do in the current blog
2241
+     *
2242
+     * @param Integer $blog_id
2243
+     */
2244
+    public static function display_form_user_rights ($blog_id)
2245
+    {
2246
+        echo '<legend>'.get_lang('RightsManager').'</legend>';
2247
+        echo '<br />';
2248
+
2249
+        // Integration of patricks permissions system.
2250
+        require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php';
2251
+    }
2252
+
2253
+    /**
2254
+     * Displays the form to create a new post
2255
+     * @author Toon Keppens
2256
+     *
2257
+     * @param Integer $blog_id
2258
+     */
2259
+    public static function display_new_comment_form($blog_id, $post_id, $title)
2260
+    {
2261
+        $form = new FormValidator(
2262
+            'add_post',
2263
+            'post',
2264
+            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(),
2265
+            null,
2266
+            array('enctype' => 'multipart/form-data')
2267
+        );
2268
+
2269
+        $header = get_lang('AddNewComment');
2270
+        if (isset($_GET['task_id'])) {
2271
+            $header = get_lang('ExecuteThisTask');
2272
+        }
2273
+        $form->addHeader($header);
2274
+        $form->addText('title', get_lang('Title'));
2275
+
2276
+        $config = array();
2277
+        if (!api_is_allowed_to_edit()) {
2278
+            $config['ToolbarSet'] = 'ProjectComment';
2279
+        } else {
2280
+            $config['ToolbarSet'] = 'ProjectCommentStudent';
2281
+        }
2282
+        $form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
2283
+        $form->addFile('user_upload', get_lang('AddAnAttachment'));
2284
+
2285
+        $form->addTextarea('post_file_comment', get_lang('FileComment'));
2286
+
2287
+        $form->addHidden('action', null);
2288
+        $form->addHidden('comment_parent_id', 0);
2289
+
2290
+        if (isset($_GET['task_id'])) {
2291
+            $form->addHidden('new_task_execution_submit', 'true');
2292
+            $form->addHidden('task_id', intval($_GET['task_id']));
2293
+        } else {
2294
+            $form->addHidden('new_comment_submit', 'true');
2295
+        }
2296
+        $form->addButton('save', get_lang('Save'));
2297
+        $form->display();
2298
+    }
2299
+
2300
+
2301
+    /**
2302
+     * show the calender of the given month
2303
+     * @author Patrick Cool
2304
+     * @author Toon Keppens
2305
+     *
2306
+     * @param Array $blogitems an array containing all the blog items for the given month
2307
+     * @param Integer $month: the integer value of the month we are viewing
2308
+     * @param Integer $year: the 4-digit year indication e.g. 2005
2309
+     * @param String $monthName: the language variable for the mont name
2310
+     *
2311
+     * @return html code
2312
+     */
2313
+    public static function display_minimonthcalendar($month, $year, $blog_id)
2246 2314
     {
2247
-		echo '<legend>'.get_lang('RightsManager').'</legend>';
2248
-		echo '<br />';
2249
-
2250
-		// Integration of patricks permissions system.
2251
-		require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php';
2252
-	}
2253
-
2254
-	/**
2255
-	 * Displays the form to create a new post
2256
-	 * @author Toon Keppens
2257
-	 *
2258
-	 * @param Integer $blog_id
2259
-	 */
2260
-	public static function display_new_comment_form($blog_id, $post_id, $title)
2261
-	{
2262
-		$form = new FormValidator(
2263
-			'add_post',
2264
-			'post',
2265
-			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(),
2266
-			null,
2267
-			array('enctype' => 'multipart/form-data')
2268
-		);
2269
-
2270
-		$header = get_lang('AddNewComment');
2271
-		if (isset($_GET['task_id'])) {
2272
-			$header = get_lang('ExecuteThisTask');
2273
-		}
2274
-		$form->addHeader($header);
2275
-		$form->addText('title', get_lang('Title'));
2276
-
2277
-		$config = array();
2278
-		if (!api_is_allowed_to_edit()) {
2279
-			$config['ToolbarSet'] = 'ProjectComment';
2280
-		} else {
2281
-			$config['ToolbarSet'] = 'ProjectCommentStudent';
2282
-		}
2283
-		$form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
2284
-		$form->addFile('user_upload', get_lang('AddAnAttachment'));
2285
-
2286
-		$form->addTextarea('post_file_comment', get_lang('FileComment'));
2287
-
2288
-		$form->addHidden('action', null);
2289
-		$form->addHidden('comment_parent_id', 0);
2290
-
2291
-		if (isset($_GET['task_id'])) {
2292
-			$form->addHidden('new_task_execution_submit', 'true');
2293
-			$form->addHidden('task_id', intval($_GET['task_id']));
2294
-		} else {
2295
-			$form->addHidden('new_comment_submit', 'true');
2296
-		}
2297
-		$form->addButton('save', get_lang('Save'));
2298
-		$form->display();
2299
-	}
2300
-
2301
-
2302
-	/**
2303
-	 * show the calender of the given month
2304
-	 * @author Patrick Cool
2305
-	 * @author Toon Keppens
2306
-	 *
2307
-	 * @param Array $blogitems an array containing all the blog items for the given month
2308
-	 * @param Integer $month: the integer value of the month we are viewing
2309
-	 * @param Integer $year: the 4-digit year indication e.g. 2005
2310
-	 * @param String $monthName: the language variable for the mont name
2311
-	 *
2312
-	 * @return html code
2313
-	*/
2314
-	public static function display_minimonthcalendar($month, $year, $blog_id)
2315
-	{
2316
-		// Init
2317
-		$_user = api_get_user_info();
2318
-		global $DaysShort;
2319
-		global $MonthsLong;
2320
-
2321
-		$posts = array();
2322
-		$tasks = array();
2323
-
2324
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2325
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
2326
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
2327
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
2328
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2329
-
2330
-		$course_id = api_get_course_int_id();
2331
-
2332
-		//Handle leap year
2333
-		$numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2334
-
2335
-		if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2336
-			$numberofdays[2] = 29;
2337
-
2338
-		//Get the first day of the month
2339
-		$dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2340
-		$monthName = $MonthsLong[$month-1];
2341
-
2342
-		//Start the week on monday
2343
-		$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2344
-		$blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2345
-		$filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2346
-		$backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2347
-		$forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2348
-
2349
-		// Get posts for this month
2350
-		$sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
2315
+        // Init
2316
+        $_user = api_get_user_info();
2317
+        global $DaysShort;
2318
+        global $MonthsLong;
2319
+
2320
+        $posts = array();
2321
+        $tasks = array();
2322
+
2323
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2324
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
2325
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
2326
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
2327
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2328
+
2329
+        $course_id = api_get_course_int_id();
2330
+
2331
+        //Handle leap year
2332
+        $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2333
+
2334
+        if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2335
+            $numberofdays[2] = 29;
2336
+
2337
+        //Get the first day of the month
2338
+        $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2339
+        $monthName = $MonthsLong[$month-1];
2340
+
2341
+        //Start the week on monday
2342
+        $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2343
+        $blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2344
+        $filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2345
+        $backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2346
+        $forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2347
+
2348
+        // Get posts for this month
2349
+        $sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
2351 2350
 				FROM $tbl_blogs_posts post
2352 2351
 				INNER JOIN $tbl_users user
2353 2352
 				ON post.author_id = user.user_id
@@ -2357,20 +2356,20 @@  discard block
 block discarded – undo
2357 2356
 					MONTH(date_creation) = '".(int)$month."' AND
2358 2357
 					YEAR(date_creation) = '".(int)$year."'
2359 2358
 				ORDER BY date_creation";
2360
-		$result = Database::query($sql);
2361
-
2362
-		// We will create an array of days on which there are posts.
2363
-		if( Database::num_rows($result) > 0) {
2364
-			while($blog_post = Database::fetch_array($result)) {
2365
-				// If the day of this post is not yet in the array, add it.
2366
-				if (!in_array($blog_post['post_day'], $posts))
2367
-					$posts[] = $blog_post['post_day'];
2368
-			}
2369
-		}
2370
-
2371
-		// Get tasks for this month
2372
-		if ($_user['user_id']) {
2373
-			$sql = " SELECT task_rel_user.*,  DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
2359
+        $result = Database::query($sql);
2360
+
2361
+        // We will create an array of days on which there are posts.
2362
+        if( Database::num_rows($result) > 0) {
2363
+            while($blog_post = Database::fetch_array($result)) {
2364
+                // If the day of this post is not yet in the array, add it.
2365
+                if (!in_array($blog_post['post_day'], $posts))
2366
+                    $posts[] = $blog_post['post_day'];
2367
+            }
2368
+        }
2369
+
2370
+        // Get tasks for this month
2371
+        if ($_user['user_id']) {
2372
+            $sql = " SELECT task_rel_user.*,  DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
2374 2373
 				FROM $tbl_blogs_tasks_rel_user task_rel_user
2375 2374
 				INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
2376 2375
 				INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
@@ -2382,84 +2381,84 @@  discard block
 block discarded – undo
2382 2381
 					MONTH(target_date) = '".(int)$month."' AND
2383 2382
 					YEAR(target_date) = '".(int)$year."'
2384 2383
 				ORDER BY target_date ASC";
2385
-			$result = Database::query($sql);
2386
-
2387
-			if (Database::num_rows($result) > 0) {
2388
-				while ($mytask = Database::fetch_array($result)) {
2389
-					$tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
2390
-					$tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
2391
-					$tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
2392
-					$tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
2393
-					$tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
2394
-				}
2395
-			}
2396
-		}
2397
-
2398
-		echo 	'<table id="smallcalendar" class="table table-responsive">',
2399
-				"<tr id=\"title\">\n",
2400
-				"<th width=\"10%\"><a href=\"", $backwardsURL, "\">&laquo;</a></th>\n",
2401
-				"<th align=\"center\" width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n",
2402
-				"<th width=\"10%\" align=\"right\"><a href=\"", $forewardsURL, "\">&raquo;</a></th>\n", "</tr>";
2403
-
2404
-		echo "<tr>\n";
2405
-
2406
-		for($ii = 1; $ii < 8; $ii ++)
2407
-			echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2408
-
2409
-		echo "</tr>";
2410
-
2411
-		$curday = -1;
2412
-		$today = getdate();
2413
-
2414
-		while ($curday <= $numberofdays[$month]) {
2415
-			echo "<tr>";
2416
-			for ($ii = 0; $ii < 7; $ii ++) {
2417
-				if (($curday == -1) && ($ii == $startdayofweek))
2418
-					$curday = 1;
2419
-
2420
-			 	if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2421
-					$bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2422
-					$dayheader = "$curday";
2423
-
2424
-					if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2425
-						$dayheader = "$curday";
2426
-						$class = "class=\"days_today\"";
2427
-					}
2428
-
2429
-					echo "<td " . $class.">";
2430
-
2431
-					// If there are posts on this day, create a filter link.
2432
-					if(in_array($curday, $posts))
2433
-						echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2434
-					else
2435
-						echo $dayheader;
2436
-
2437
-					if (count($tasks) > 0) {
2438
-						if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2439
-							// Add tasks to calendar
2440
-							foreach ($tasks[$curday] as $task) {
2441
-								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') . '">
2384
+            $result = Database::query($sql);
2385
+
2386
+            if (Database::num_rows($result) > 0) {
2387
+                while ($mytask = Database::fetch_array($result)) {
2388
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
2389
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
2390
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
2391
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
2392
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
2393
+                }
2394
+            }
2395
+        }
2396
+
2397
+        echo 	'<table id="smallcalendar" class="table table-responsive">',
2398
+                "<tr id=\"title\">\n",
2399
+                "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&laquo;</a></th>\n",
2400
+                "<th align=\"center\" width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n",
2401
+                "<th width=\"10%\" align=\"right\"><a href=\"", $forewardsURL, "\">&raquo;</a></th>\n", "</tr>";
2402
+
2403
+        echo "<tr>\n";
2404
+
2405
+        for($ii = 1; $ii < 8; $ii ++)
2406
+            echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2407
+
2408
+        echo "</tr>";
2409
+
2410
+        $curday = -1;
2411
+        $today = getdate();
2412
+
2413
+        while ($curday <= $numberofdays[$month]) {
2414
+            echo "<tr>";
2415
+            for ($ii = 0; $ii < 7; $ii ++) {
2416
+                if (($curday == -1) && ($ii == $startdayofweek))
2417
+                    $curday = 1;
2418
+
2419
+                    if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2420
+                    $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2421
+                    $dayheader = "$curday";
2422
+
2423
+                    if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2424
+                        $dayheader = "$curday";
2425
+                        $class = "class=\"days_today\"";
2426
+                    }
2427
+
2428
+                    echo "<td " . $class.">";
2429
+
2430
+                    // If there are posts on this day, create a filter link.
2431
+                    if(in_array($curday, $posts))
2432
+                        echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2433
+                    else
2434
+                        echo $dayheader;
2435
+
2436
+                    if (count($tasks) > 0) {
2437
+                        if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2438
+                            // Add tasks to calendar
2439
+                            foreach ($tasks[$curday] as $task) {
2440
+                                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') . '">
2442 2441
 								<img src="../img/blog_task.gif" alt="Task" title="' . get_lang('ExecuteThisTask') . '" /></a>';
2443
-							}
2444
-						}
2445
-					}
2446
-
2447
-					echo "</td>";
2448
-					$curday ++;
2449
-				} else
2450
-					echo "<td>&nbsp;</td>";
2451
-			}
2452
-			echo "</tr>";
2453
-		}
2454
-		echo "</table>";
2455
-	}
2456
-
2457
-	/**
2458
-	 * Blog admin | Display the form to add a new blog.
2459
-	 *
2460
-	 */
2461
-	public static function display_new_blog_form()
2462
-	{
2442
+                            }
2443
+                        }
2444
+                    }
2445
+
2446
+                    echo "</td>";
2447
+                    $curday ++;
2448
+                } else
2449
+                    echo "<td>&nbsp;</td>";
2450
+            }
2451
+            echo "</tr>";
2452
+        }
2453
+        echo "</table>";
2454
+    }
2455
+
2456
+    /**
2457
+     * Blog admin | Display the form to add a new blog.
2458
+     *
2459
+     */
2460
+    public static function display_new_blog_form()
2461
+    {
2463 2462
         $form = new FormValidator('add_blog', 'post', 'blog_admin.php?action=add');
2464 2463
         $form->addElement('header', get_lang('AddBlog'));
2465 2464
         $form->addElement('text', 'blog_name', get_lang('Title'));
@@ -2469,34 +2468,34 @@  discard block
 block discarded – undo
2469 2468
         $form->addButtonSave(get_lang('SaveProject'));
2470 2469
 
2471 2470
         $defaults = array(
2472
-			'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null,
2473
-        	'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null
2474
-		);
2471
+            'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null,
2472
+            'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null
2473
+        );
2475 2474
         $form->setDefaults($defaults);
2476 2475
         $form->display();
2477
-	}
2478
-
2479
-	/**
2480
-	 * Blog admin | Display the form to edit a blog.
2481
-	 *
2482
-	 */
2483
-	public static function display_edit_blog_form($blog_id)
2484
-	{
2485
-	    $course_id = api_get_course_int_id();
2486
-		$blog_id= intval($blog_id);
2487
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2488
-
2489
-		$sql = "SELECT blog_id, blog_name, blog_subtitle
2476
+    }
2477
+
2478
+    /**
2479
+     * Blog admin | Display the form to edit a blog.
2480
+     *
2481
+     */
2482
+    public static function display_edit_blog_form($blog_id)
2483
+    {
2484
+        $course_id = api_get_course_int_id();
2485
+        $blog_id= intval($blog_id);
2486
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2487
+
2488
+        $sql = "SELECT blog_id, blog_name, blog_subtitle
2490 2489
 		        FROM $tbl_blogs
2491 2490
 		        WHERE c_id = $course_id AND blog_id = '".$blog_id."'";
2492
-		$result = Database::query($sql);
2493
-		$blog = Database::fetch_array($result);
2491
+        $result = Database::query($sql);
2492
+        $blog = Database::fetch_array($result);
2494 2493
 
2495
-		// the form contained errors but we do not want to lose the changes the user already did
2496
-		if ($_POST) {
2497
-			$blog['blog_name'] = Security::remove_XSS($_POST['blog_name']);
2498
-			$blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2499
-		}
2494
+        // the form contained errors but we do not want to lose the changes the user already did
2495
+        if ($_POST) {
2496
+            $blog['blog_name'] = Security::remove_XSS($_POST['blog_name']);
2497
+            $blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2498
+        }
2500 2499
 
2501 2500
         $form = new FormValidator('edit_blog', 'post','blog_admin.php?action=edit&blog_id='.intval($_GET['blog_id']));
2502 2501
         $form->addElement('header', get_lang('EditBlog'));
@@ -2512,82 +2511,82 @@  discard block
 block discarded – undo
2512 2511
         $defaults['blog_subtitle'] = $blog['blog_subtitle'];
2513 2512
         $form->setDefaults($defaults);
2514 2513
         $form->display();
2515
-	}
2514
+    }
2516 2515
 
2517
-	/**
2518
-	 * Blog admin | Returns table with blogs in this course
2519
-	 */
2520
-	public static function display_blog_list()
2516
+    /**
2517
+     * Blog admin | Returns table with blogs in this course
2518
+     */
2519
+    public static function display_blog_list()
2521 2520
     {
2522
-		global $charset;
2523
-		$_user = api_get_user_info();
2521
+        global $charset;
2522
+        $_user = api_get_user_info();
2524 2523
         $course_id = api_get_course_int_id();
2525 2524
 
2526
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2525
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2527 2526
 
2528
-		//condition for the session
2529
-		$session_id = api_get_session_id();
2530
-		$condition_session = api_get_session_condition($session_id, false);
2527
+        //condition for the session
2528
+        $session_id = api_get_session_id();
2529
+        $condition_session = api_get_session_condition($session_id, false);
2531 2530
 
2532
-		$sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id
2531
+        $sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id
2533 2532
 				FROM $tbl_blogs WHERE c_id = $course_id
2534 2533
 				ORDER BY date_creation DESC";
2535
-		$result = Database::query($sql);
2536
-		$list_info = array();
2537
-		if (Database::num_rows($result)) {
2538
-			while ($row_project=Database::fetch_row($result)) {
2539
-				$list_info[]=$row_project;
2540
-			}
2541
-		}
2542
-
2543
-		$list_content_blog = array();
2544
-		$list_body_blog = array();
2545
-
2546
-		if (is_array($list_info)) {
2547
-			foreach ($list_info as $key => $info_log) {
2548
-				// Validation when belongs to a session
2549
-				$session_img = api_get_session_image($info_log[4], $_user['status']);
2550
-
2551
-				$url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2552
-				$title = $info_log[0];
2534
+        $result = Database::query($sql);
2535
+        $list_info = array();
2536
+        if (Database::num_rows($result)) {
2537
+            while ($row_project=Database::fetch_row($result)) {
2538
+                $list_info[]=$row_project;
2539
+            }
2540
+        }
2541
+
2542
+        $list_content_blog = array();
2543
+        $list_body_blog = array();
2544
+
2545
+        if (is_array($list_info)) {
2546
+            foreach ($list_info as $key => $info_log) {
2547
+                // Validation when belongs to a session
2548
+                $session_img = api_get_session_image($info_log[4], $_user['status']);
2549
+
2550
+                $url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2551
+                $title = $info_log[0];
2553 2552
                         $image = Display::return_icon('blog.png', $title);
2554
-    			$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;
2553
+                $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;
2555 2554
 
2556
-				$list_body_blog[] = $list_name;
2557
-				$list_body_blog[] = $info_log[1];
2555
+                $list_body_blog[] = $list_name;
2556
+                $list_body_blog[] = $info_log[1];
2558 2557
 
2559
-				$visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2560
-				$visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2561
-			 	$my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2558
+                $visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2559
+                $visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2560
+                    $my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2562 2561
                                 $my_image.= Display::return_icon('edit.png', get_lang('EditBlog'));
2563 2562
 
2564
-				$my_image.= "</a>\n";
2565
-				$my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2566
-				$my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2563
+                $my_image.= "</a>\n";
2564
+                $my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2565
+                $my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2567 2566
                                 $my_image.= Display::return_icon('delete.png', get_lang('DeleteBlog'));
2568 2567
 
2569
-				$my_image.= "</a>\n";
2570
-				$my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2568
+                $my_image.= "</a>\n";
2569
+                $my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2571 2570
                                 $my_image.= Display::return_icon($visibility_icon . '.gif', get_lang($visibility_info));
2572 2571
 
2573
-				$my_image.= "</a>\n";
2572
+                $my_image.= "</a>\n";
2574 2573
 
2575
-				$list_body_blog[]=$my_image;
2574
+                $list_body_blog[]=$my_image;
2576 2575
 
2577
-				$list_content_blog[]=$list_body_blog;
2578
-				$list_body_blog = array();
2576
+                $list_content_blog[]=$list_body_blog;
2577
+                $list_body_blog = array();
2579 2578
 
2580
-			}
2581
-			$parameters='';
2582
-			//$parameters=array('action'=>Security::remove_XSS($_GET['action']));
2583
-			$table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2584
-			//$table->set_additional_parameters($parameters);
2585
-			$table->set_header(0, get_lang('Title'));
2586
-			$table->set_header(1, get_lang('SubTitle'));
2587
-			$table->set_header(2, get_lang('Modify'));
2588
-			$table->display();
2589
-		}
2590
-	}
2579
+            }
2580
+            $parameters='';
2581
+            //$parameters=array('action'=>Security::remove_XSS($_GET['action']));
2582
+            $table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2583
+            //$table->set_additional_parameters($parameters);
2584
+            $table->set_header(0, get_lang('Title'));
2585
+            $table->set_header(1, get_lang('SubTitle'));
2586
+            $table->set_header(2, get_lang('Modify'));
2587
+            $table->display();
2588
+        }
2589
+    }
2591 2590
 }
2592 2591
 
2593 2592
 /**
@@ -2607,34 +2606,34 @@  discard block
 block discarded – undo
2607 2606
  */
2608 2607
 function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
2609 2608
 {
2610
-	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2611
-
2612
-	$blog_id = intval($blog_id);
2613
-	$comment_id = intval($comment_id);
2614
-	$post_id = intval($post_id);
2615
-	$row=array();
2616
-	$where='';
2617
-	if (!empty ($post_id) && is_numeric($post_id)) {
2618
-		$where.=' AND post_id ="'.$post_id.'" ';
2619
-	}
2620
-
2621
-	if (!empty ($comment_id) && is_numeric($comment_id)) {
2622
-		if (!empty ($post_id)) {
2623
-			$where.= ' AND ';
2624
-		}
2625
-		$where.=' comment_id ="'.$comment_id.'" ';
2626
-	}
2609
+    $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2610
+
2611
+    $blog_id = intval($blog_id);
2612
+    $comment_id = intval($comment_id);
2613
+    $post_id = intval($post_id);
2614
+    $row=array();
2615
+    $where='';
2616
+    if (!empty ($post_id) && is_numeric($post_id)) {
2617
+        $where.=' AND post_id ="'.$post_id.'" ';
2618
+    }
2619
+
2620
+    if (!empty ($comment_id) && is_numeric($comment_id)) {
2621
+        if (!empty ($post_id)) {
2622
+            $where.= ' AND ';
2623
+        }
2624
+        $where.=' comment_id ="'.$comment_id.'" ';
2625
+    }
2627 2626
 
2628 2627
     $course_id = api_get_course_int_id();
2629 2628
 
2630
-	$sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2629
+    $sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2631 2630
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2632 2631
 
2633
-	$result=Database::query($sql);
2634
-	if (Database::num_rows($result)!=0) {
2635
-		$row=Database::fetch_array($result);
2636
-	}
2637
-	return $row;
2632
+    $result=Database::query($sql);
2633
+    if (Database::num_rows($result)!=0) {
2634
+        $row=Database::fetch_array($result);
2635
+    }
2636
+    return $row;
2638 2637
 }
2639 2638
 
2640 2639
 /**
@@ -2648,16 +2647,16 @@  discard block
 block discarded – undo
2648 2647
 
2649 2648
 function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null)
2650 2649
 {
2651
-	$_course = api_get_course_info();
2652
-	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2653
-	$blog_id = intval($blog_id);
2654
-	$comment_id = intval($comment_id);
2655
-	$post_id = intval($post_id);
2650
+    $_course = api_get_course_info();
2651
+    $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2652
+    $blog_id = intval($blog_id);
2653
+    $comment_id = intval($comment_id);
2654
+    $post_id = intval($post_id);
2656 2655
 
2657 2656
     $course_id = api_get_course_int_id();
2658
-	$where = null;
2657
+    $where = null;
2659 2658
 
2660
-	// delete files in DB
2659
+    // delete files in DB
2661 2660
     if (!empty ($post_id) && is_numeric($post_id)) {
2662 2661
         $where .= ' AND post_id ="'.$post_id.'" ';
2663 2662
     }
@@ -2669,25 +2668,25 @@  discard block
 block discarded – undo
2669 2668
         $where .= ' comment_id ="'.$comment_id.'" ';
2670 2669
     }
2671 2670
 
2672
-	// delete all files in directory
2673
-	$courseDir   = $_course['path'].'/upload/blog';
2674
-	$sys_course_path = api_get_path(SYS_COURSE_PATH);
2675
-	$updir = $sys_course_path.$courseDir;
2671
+    // delete all files in directory
2672
+    $courseDir   = $_course['path'].'/upload/blog';
2673
+    $sys_course_path = api_get_path(SYS_COURSE_PATH);
2674
+    $updir = $sys_course_path.$courseDir;
2676 2675
 
2677
-	$sql = 'SELECT path FROM '.$blog_table_attachment.'
2676
+    $sql = 'SELECT path FROM '.$blog_table_attachment.'
2678 2677
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2679
-	$result=Database::query($sql);
2680
-
2681
-	while ($row=Database::fetch_row($result)) {
2682
-		$file=$updir.'/'.$row[0];
2683
-		if (Security::check_abs_path($file,$updir) )
2684
-		{
2685
-			@ unlink($file);
2686
-		}
2687
-	}
2688
-	$sql = 'DELETE FROM '. $blog_table_attachment.'
2678
+    $result=Database::query($sql);
2679
+
2680
+    while ($row=Database::fetch_row($result)) {
2681
+        $file=$updir.'/'.$row[0];
2682
+        if (Security::check_abs_path($file,$updir) )
2683
+        {
2684
+            @ unlink($file);
2685
+        }
2686
+    }
2687
+    $sql = 'DELETE FROM '. $blog_table_attachment.'
2689 2688
 	        WHERE c_id = '.$course_id.' AND  blog_id ="'.intval($blog_id).'"  '.$where;
2690
-	Database::query($sql);
2689
+    Database::query($sql);
2691 2690
 }
2692 2691
 
2693 2692
 /**
@@ -2697,12 +2696,12 @@  discard block
 block discarded – undo
2697 2696
  */
2698 2697
 function get_blog_post_from_user($course_code, $user_id)
2699 2698
 {
2700
-	$tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2701
-	$tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2702
-	$course_info 	= api_get_course_info($course_code);
2703
-	$course_id 		= $course_info['real_id'];
2699
+    $tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2700
+    $tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2701
+    $course_info 	= api_get_course_info($course_code);
2702
+    $course_id 		= $course_info['real_id'];
2704 2703
 
2705
-	$sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
2704
+    $sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
2706 2705
 			FROM $tbl_blogs blog
2707 2706
 			INNER JOIN  $tbl_blog_post post
2708 2707
 			ON (blog.blog_id = post.blog_id)
@@ -2711,19 +2710,19 @@  discard block
 block discarded – undo
2711 2710
 				post.c_id = $course_id AND
2712 2711
 				author_id =  $user_id AND visibility = 1
2713 2712
 			ORDER BY post.date_creation DESC ";
2714
-	$result = Database::query($sql);
2715
-	$return_data = '';
2716
-
2717
-	if (Database::num_rows($result)!=0) {
2718
-		while ($row=Database::fetch_array($result)) {
2719
-			$return_data.=  '<div class="clear"></div><br />';
2720
-			$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>';
2721
-			$return_data.=  '<br / >';
2722
-			$return_data.= $row['full_text'];
2723
-			$return_data.= '<br /><br />';
2724
-		}
2725
-	}
2726
-	return $return_data;
2713
+    $result = Database::query($sql);
2714
+    $return_data = '';
2715
+
2716
+    if (Database::num_rows($result)!=0) {
2717
+        while ($row=Database::fetch_array($result)) {
2718
+            $return_data.=  '<div class="clear"></div><br />';
2719
+            $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>';
2720
+            $return_data.=  '<br / >';
2721
+            $return_data.= $row['full_text'];
2722
+            $return_data.= '<br /><br />';
2723
+        }
2724
+    }
2725
+    return $return_data;
2727 2726
 }
2728 2727
 
2729 2728
 /**
@@ -2740,7 +2739,7 @@  discard block
 block discarded – undo
2740 2739
     $course_info = api_get_course_info($course_code);
2741 2740
     $course_id = $course_info['real_id'];
2742 2741
 
2743
-	$sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation
2742
+    $sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation
2744 2743
 			FROM $tbl_blogs blog INNER JOIN  $tbl_blog_comment comment
2745 2744
 			ON (blog.blog_id = comment.blog_id)
2746 2745
 			WHERE 	blog.c_id = $course_id AND
@@ -2748,18 +2747,18 @@  discard block
 block discarded – undo
2748 2747
 					author_id =  $user_id AND
2749 2748
 					visibility = 1
2750 2749
 			ORDER BY blog_name";
2751
-	$result = Database::query($sql);
2752
-	$return_data = '';
2753
-	if (Database::num_rows($result)!=0) {
2754
-		while ($row=Database::fetch_array($result)) {
2755
-			$return_data.=  '<div class="clear"></div><br />';
2756
-			$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>';
2757
-			$return_data.=  '<br / >';
2758
-			//$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2759
-			$return_data.=  $row['comment'];
2760
-			$return_data.=  '<br />';
2761
-		}
2762
-	}
2763
-	return $return_data;
2750
+    $result = Database::query($sql);
2751
+    $return_data = '';
2752
+    if (Database::num_rows($result)!=0) {
2753
+        while ($row=Database::fetch_array($result)) {
2754
+            $return_data.=  '<div class="clear"></div><br />';
2755
+            $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>';
2756
+            $return_data.=  '<br / >';
2757
+            //$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2758
+            $return_data.=  $row['comment'];
2759
+            $return_data.=  '<br />';
2760
+        }
2761
+    }
2762
+    return $return_data;
2764 2763
 }
2765 2764
 
Please login to merge, or discard this patch.