1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class Blog. |
6
|
|
|
* |
7
|
|
|
* Contains several functions dealing with displaying, |
8
|
|
|
* editing,... of a blog |
9
|
|
|
* |
10
|
|
|
* @package chamilo.blogs |
11
|
|
|
* |
12
|
|
|
* @author Toon Keppens <[email protected]> |
13
|
|
|
* @author Julio Montoya - Cleaning code |
14
|
|
|
*/ |
15
|
|
|
class Blog |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Get the title of a blog. |
19
|
|
|
* |
20
|
|
|
* @author Toon Keppens |
21
|
|
|
* |
22
|
|
|
* @param int $blog_id The internal ID of the blog |
23
|
|
|
* |
24
|
|
|
* @return string Blog Title |
25
|
|
|
*/ |
26
|
|
|
public static function getBlogTitle($blog_id) |
27
|
|
|
{ |
28
|
|
|
$course_id = api_get_course_int_id(); |
29
|
|
|
|
30
|
|
|
if (is_numeric($blog_id)) { |
31
|
|
|
$table = Database::get_course_table(TABLE_BLOGS); |
32
|
|
|
|
33
|
|
|
$sql = "SELECT blog_name |
34
|
|
|
FROM $table |
35
|
|
|
WHERE c_id = $course_id AND blog_id = ".intval($blog_id); |
36
|
|
|
|
37
|
|
|
$result = Database::query($sql); |
38
|
|
|
$blog = Database::fetch_array($result); |
39
|
|
|
|
40
|
|
|
return stripslashes($blog['blog_name']); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the description of a blog. |
46
|
|
|
* |
47
|
|
|
* @author Toon Keppens |
48
|
|
|
* |
49
|
|
|
* @param int $blog_id The internal ID of the blog |
50
|
|
|
* |
51
|
|
|
* @return string Blog description |
52
|
|
|
*/ |
53
|
|
|
public static function getBlogSubtitle($blog_id) |
54
|
|
|
{ |
55
|
|
|
$table = Database::get_course_table(TABLE_BLOGS); |
56
|
|
|
$course_id = api_get_course_int_id(); |
57
|
|
|
$sql = "SELECT blog_subtitle FROM $table |
58
|
|
|
WHERE c_id = $course_id AND blog_id ='".intval($blog_id)."'"; |
59
|
|
|
$result = Database::query($sql); |
60
|
|
|
$blog = Database::fetch_array($result); |
61
|
|
|
|
62
|
|
|
return stripslashes($blog['blog_subtitle']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the users of a blog. |
67
|
|
|
* |
68
|
|
|
* @author Toon Keppens |
69
|
|
|
* |
70
|
|
|
* @param int $blog_id The ID of the blog |
71
|
|
|
* |
72
|
|
|
* @return array Returns an array with [userid]=>[username] |
73
|
|
|
*/ |
74
|
|
|
public static function getBlogUsers($blog_id) |
75
|
|
|
{ |
76
|
|
|
// Database table definitions |
77
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
78
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
79
|
|
|
|
80
|
|
|
$course_id = api_get_course_int_id(); |
81
|
|
|
|
82
|
|
|
// Get blog members |
83
|
|
|
$sql = "SELECT user.user_id, user.firstname, user.lastname |
84
|
|
|
FROM $tbl_blogs_rel_user blogs_rel_user |
85
|
|
|
INNER JOIN $tbl_users user |
86
|
|
|
ON (blogs_rel_user.user_id = user.user_id) |
87
|
|
|
WHERE |
88
|
|
|
blogs_rel_user.c_id = $course_id AND |
89
|
|
|
blogs_rel_user.blog_id = '".(int) $blog_id."'"; |
90
|
|
|
$result = Database::query($sql); |
91
|
|
|
$blog_members = []; |
92
|
|
|
while ($user = Database::fetch_array($result)) { |
93
|
|
|
$blog_members[$user['user_id']] = api_get_person_name( |
94
|
|
|
$user['firstname'], |
95
|
|
|
$user['lastname'] |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $blog_members; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Creates a new blog in the given course. |
104
|
|
|
* |
105
|
|
|
* @author Toon Keppens |
106
|
|
|
* |
107
|
|
|
* @param string $title The title of the new blog |
108
|
|
|
* @param string $subtitle The description (or subtitle) of the new blog |
109
|
|
|
*/ |
110
|
|
|
public static function addBlog($title, $subtitle) |
111
|
|
|
{ |
112
|
|
|
$_user = api_get_user_info(); |
113
|
|
|
$course_id = api_get_course_int_id(); |
114
|
|
|
|
115
|
|
|
$current_date = api_get_utc_datetime(); |
116
|
|
|
$session_id = api_get_session_id(); |
117
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
118
|
|
|
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); |
119
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
120
|
|
|
|
121
|
|
|
//verified if exist blog |
122
|
|
|
$sql = "SELECT COUNT(*) as count FROM $tbl_blogs |
123
|
|
|
WHERE |
124
|
|
|
c_id = $course_id AND |
125
|
|
|
blog_name = '".Database::escape_string($title)."' AND |
126
|
|
|
blog_subtitle = '".Database::escape_string($subtitle)."' "; |
127
|
|
|
$res = Database::query($sql); |
128
|
|
|
$info_count = Database::result($res, 0, 0); |
129
|
|
|
|
130
|
|
|
if ($info_count == 0) { |
131
|
|
|
// Create the blog |
132
|
|
|
$params = [ |
133
|
|
|
'blog_id' => 0, |
134
|
|
|
'c_id' => $course_id, |
135
|
|
|
'blog_name' => $title, |
136
|
|
|
'blog_subtitle' => $subtitle, |
137
|
|
|
'date_creation' => $current_date, |
138
|
|
|
'visibility' => 1, |
139
|
|
|
'session_id' => $session_id, |
140
|
|
|
]; |
141
|
|
|
$this_blog_id = Database::insert($tbl_blogs, $params); |
142
|
|
|
|
143
|
|
|
if ($this_blog_id > 0) { |
144
|
|
|
$sql = "UPDATE $tbl_blogs SET blog_id = iid WHERE iid = $this_blog_id"; |
145
|
|
|
Database::query($sql); |
146
|
|
|
|
147
|
|
|
// insert into item_property |
148
|
|
|
api_item_property_update( |
149
|
|
|
api_get_course_info(), |
150
|
|
|
TOOL_BLOGS, |
151
|
|
|
$this_blog_id, |
152
|
|
|
'BlogAdded', |
153
|
|
|
api_get_user_id() |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// Make first post. :) |
158
|
|
|
$params = [ |
159
|
|
|
'post_id' => 0, |
160
|
|
|
'c_id' => $course_id, |
161
|
|
|
'title' => get_lang("Welcome"), |
162
|
|
|
'full_text' => get_lang('FirstPostText'), |
163
|
|
|
'date_creation' => $current_date, |
164
|
|
|
'blog_id' => $this_blog_id, |
165
|
|
|
'author_id' => $_user['user_id'], |
166
|
|
|
]; |
167
|
|
|
$postId = Database::insert($tbl_blogs_posts, $params); |
168
|
|
|
if ($postId) { |
|
|
|
|
169
|
|
|
$sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $postId"; |
170
|
|
|
Database::query($sql); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// Put it on course homepage |
174
|
|
|
$params = [ |
175
|
|
|
'c_id' => $course_id, |
176
|
|
|
'name' => $title, |
177
|
|
|
'link' => 'blog/blog.php?blog_id='.$this_blog_id, |
|
|
|
|
178
|
|
|
'image' => 'blog.gif', |
179
|
|
|
'visibility' => '1', |
180
|
|
|
'admin' => '0', |
181
|
|
|
'address' => 'pastillegris.gif', |
182
|
|
|
'added_tool' => 0, |
183
|
|
|
'session_id' => $session_id, |
184
|
|
|
'target' => '', |
185
|
|
|
]; |
186
|
|
|
$toolId = Database::insert($tbl_tool, $params); |
187
|
|
|
if ($toolId) { |
|
|
|
|
188
|
|
|
$sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $toolId"; |
189
|
|
|
Database::query($sql); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
// Subscribe the teacher to this blog |
193
|
|
|
self::subscribeUser($this_blog_id, $_user['user_id']); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Subscribes a user to a given blog. |
199
|
|
|
* |
200
|
|
|
* @author Toon Keppens |
201
|
|
|
* |
202
|
|
|
* @param int $blog_id The internal blog ID |
203
|
|
|
* @param int $user_id The internal user ID (of the user to be subscribed) |
204
|
|
|
*/ |
205
|
|
|
public static function subscribeUser($blog_id, $user_id) |
206
|
|
|
{ |
207
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
208
|
|
|
$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER); |
209
|
|
|
|
210
|
|
|
$course_id = api_get_course_int_id(); |
211
|
|
|
$blog_id = intval($blog_id); |
212
|
|
|
$user_id = intval($user_id); |
213
|
|
|
|
214
|
|
|
// Subscribe the user |
215
|
|
|
$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id ) |
216
|
|
|
VALUES ($course_id, $blog_id, $user_id)"; |
217
|
|
|
Database::query($sql); |
218
|
|
|
|
219
|
|
|
// Give this user basic rights |
220
|
|
|
$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id, tool, action) |
221
|
|
|
VALUES ($course_id, $user_id, 'BLOG_$blog_id', 'article_add')"; |
222
|
|
|
Database::query($sql); |
223
|
|
|
|
224
|
|
|
$id = Database::insert_id(); |
225
|
|
|
if ($id) { |
226
|
|
|
$sql = "UPDATE $tbl_user_permissions SET id = iid WHERE iid = $id"; |
227
|
|
|
Database::query($sql); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id, tool, action) |
231
|
|
|
VALUES ($course_id, $user_id,'BLOG_$blog_id', 'article_comments_add')"; |
232
|
|
|
Database::query($sql); |
233
|
|
|
|
234
|
|
|
$id = Database::insert_id(); |
235
|
|
|
if ($id) { |
236
|
|
|
$sql = "UPDATE $tbl_user_permissions SET id = iid WHERE iid = $id"; |
237
|
|
|
Database::query($sql); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Update title and subtitle of a blog in the given course. |
243
|
|
|
* |
244
|
|
|
* @author Toon Keppens |
245
|
|
|
* |
246
|
|
|
* @param int $blog_id The internal ID of the blog |
247
|
|
|
* @param string $title The title to be set |
248
|
|
|
* @param string $subtitle The subtitle (or description) to be set |
249
|
|
|
*/ |
250
|
|
|
public static function editBlog($blog_id, $title, $subtitle = '') |
251
|
|
|
{ |
252
|
|
|
// Table definitions |
253
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
254
|
|
|
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); |
255
|
|
|
|
256
|
|
|
$course_id = api_get_course_int_id(); |
257
|
|
|
$blog_id = intval($blog_id); |
258
|
|
|
$title = Database::escape_string($title); |
259
|
|
|
$subtitle = Database::escape_string($subtitle); |
260
|
|
|
|
261
|
|
|
// Update the blog |
262
|
|
|
$sql = "UPDATE $tbl_blogs SET |
263
|
|
|
blog_name = '$title', |
264
|
|
|
blog_subtitle = '$subtitle' |
265
|
|
|
WHERE |
266
|
|
|
c_id = $course_id AND |
267
|
|
|
blog_id = $blog_id |
268
|
|
|
LIMIT 1"; |
269
|
|
|
Database::query($sql); |
270
|
|
|
|
271
|
|
|
//update item_property (update) |
272
|
|
|
api_item_property_update( |
273
|
|
|
api_get_course_info(), |
274
|
|
|
TOOL_BLOGS, |
275
|
|
|
$blog_id, |
276
|
|
|
'BlogUpdated', |
277
|
|
|
api_get_user_id() |
278
|
|
|
); |
279
|
|
|
|
280
|
|
|
// Update course homepage link |
281
|
|
|
$sql = "UPDATE $tbl_tool SET |
282
|
|
|
name = '$title' |
283
|
|
|
WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=$blog_id' |
284
|
|
|
LIMIT 1"; |
285
|
|
|
Database::query($sql); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Deletes a blog and it's posts from the course database. |
290
|
|
|
* |
291
|
|
|
* @author Toon Keppens |
292
|
|
|
* |
293
|
|
|
* @param int $blog_id The internal blog ID |
294
|
|
|
*/ |
295
|
|
|
public static function deleteBlog($blog_id) |
296
|
|
|
{ |
297
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
298
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
299
|
|
|
$tbl_blogs_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
300
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
301
|
|
|
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); |
302
|
|
|
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); |
303
|
|
|
|
304
|
|
|
$course_id = api_get_course_int_id(); |
305
|
|
|
$blog_id = intval($blog_id); |
306
|
|
|
|
307
|
|
|
// Delete posts from DB and the attachments |
308
|
|
|
self::deleteAllBlogAttachments($blog_id); |
309
|
|
|
|
310
|
|
|
//Delete comments |
311
|
|
|
$sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id = $blog_id"; |
312
|
|
|
Database::query($sql); |
313
|
|
|
|
314
|
|
|
// Delete posts |
315
|
|
|
$sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id = $blog_id"; |
316
|
|
|
Database::query($sql); |
317
|
|
|
|
318
|
|
|
// Delete tasks |
319
|
|
|
$sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id = $blog_id"; |
320
|
|
|
Database::query($sql); |
321
|
|
|
|
322
|
|
|
// Delete ratings |
323
|
|
|
$sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id = $blog_id"; |
324
|
|
|
Database::query($sql); |
325
|
|
|
|
326
|
|
|
// Delete blog |
327
|
|
|
$sql = "DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id = $blog_id"; |
328
|
|
|
Database::query($sql); |
329
|
|
|
|
330
|
|
|
// Delete from course homepage |
331
|
|
|
$sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'"; |
332
|
|
|
Database::query($sql); |
333
|
|
|
|
334
|
|
|
//update item_property (delete) |
335
|
|
|
api_item_property_update( |
336
|
|
|
api_get_course_info(), |
337
|
|
|
TOOL_BLOGS, |
338
|
|
|
$blog_id, |
339
|
|
|
'delete', |
340
|
|
|
api_get_user_id() |
341
|
|
|
); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Creates a new post in a given blog. |
346
|
|
|
* |
347
|
|
|
* @author Toon Keppens |
348
|
|
|
* |
349
|
|
|
* @param string $title The title of the new post |
350
|
|
|
* @param string $full_text The full text of the new post |
351
|
|
|
* @param string $file_comment The text of the comment (if any) |
352
|
|
|
* @param int $blog_id The internal blog ID |
353
|
|
|
* |
354
|
|
|
* @return int |
355
|
|
|
*/ |
356
|
|
|
public static function createPost($title, $full_text, $file_comment, $blog_id) |
357
|
|
|
{ |
358
|
|
|
$_user = api_get_user_info(); |
359
|
|
|
$_course = api_get_course_info(); |
360
|
|
|
$course_id = $_course['real_id']; |
361
|
|
|
$blog_id = intval($blog_id); |
362
|
|
|
|
363
|
|
|
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); |
364
|
|
|
$upload_ok = true; |
365
|
|
|
$has_attachment = false; |
366
|
|
|
$current_date = api_get_utc_datetime(); |
367
|
|
|
|
368
|
|
|
if (!empty($_FILES['user_upload']['name'])) { |
369
|
|
|
$upload_ok = process_uploaded_file($_FILES['user_upload']); |
370
|
|
|
$has_attachment = true; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
if ($upload_ok) { |
374
|
|
|
// Table Definitions |
375
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
376
|
|
|
$title = Database::escape_string($title); |
377
|
|
|
$full_text = Database::escape_string($full_text); |
378
|
|
|
|
379
|
|
|
// Create the post |
380
|
|
|
$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id ) |
381
|
|
|
VALUES ($course_id, '$title', '$full_text', '$current_date', '$blog_id', ".$_user['user_id'].")"; |
382
|
|
|
|
383
|
|
|
Database::query($sql); |
384
|
|
|
$last_post_id = Database::insert_id(); |
385
|
|
|
|
386
|
|
|
if ($last_post_id) { |
387
|
|
|
$sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $last_post_id"; |
388
|
|
|
Database::query($sql); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
if ($has_attachment) { |
392
|
|
|
$courseDir = $_course['path'].'/upload/blog'; |
393
|
|
|
$sys_course_path = api_get_path(SYS_COURSE_PATH); |
394
|
|
|
$updir = $sys_course_path.$courseDir; |
395
|
|
|
|
396
|
|
|
// Try to add an extension to the file if it hasn't one |
397
|
|
|
$new_file_name = add_ext_on_mime( |
398
|
|
|
stripslashes($_FILES['user_upload']['name']), |
399
|
|
|
$_FILES['user_upload']['type'] |
400
|
|
|
); |
401
|
|
|
|
402
|
|
|
// user's file name |
403
|
|
|
$file_name = $_FILES['user_upload']['name']; |
404
|
|
|
|
405
|
|
|
if (!filter_extension($new_file_name)) { |
406
|
|
|
echo Display::return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'error'); |
407
|
|
|
} else { |
408
|
|
|
$new_file_name = uniqid(''); |
409
|
|
|
$new_path = $updir.'/'.$new_file_name; |
410
|
|
|
$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); |
411
|
|
|
$comment = Database::escape_string($file_comment); |
412
|
|
|
$file_name = Database::escape_string($file_name); |
413
|
|
|
$size = intval($_FILES['user_upload']['size']); |
414
|
|
|
|
415
|
|
|
// Storing the attachments if any |
416
|
|
|
if ($result) { |
417
|
|
|
$sql = "INSERT INTO $blog_table_attachment (c_id, filename,comment, path, post_id,size, blog_id,comment_id) |
418
|
|
|
VALUES ($course_id, '$file_name', '$comment', '$new_file_name', $last_post_id, $size, $blog_id, 0)"; |
419
|
|
|
Database::query($sql); |
420
|
|
|
$id = Database::insert_id(); |
421
|
|
|
if ($id) { |
422
|
|
|
$sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id"; |
423
|
|
|
Database::query($sql); |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
return $last_post_id; |
430
|
|
|
} else { |
431
|
|
|
echo Display::return_message(get_lang('UplNoFileUploaded'), 'error'); |
432
|
|
|
|
433
|
|
|
return 0; |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Edits a post in a given blog. |
439
|
|
|
* |
440
|
|
|
* @author Toon Keppens |
441
|
|
|
* |
442
|
|
|
* @param int $post_id The internal ID of the post to edit |
443
|
|
|
* @param string $title The title |
444
|
|
|
* @param string $full_text The full post text |
445
|
|
|
* @param int $blog_id The internal ID of the blog in which the post is located |
446
|
|
|
*/ |
447
|
|
|
public static function editPost($post_id, $title, $full_text, $blog_id) |
448
|
|
|
{ |
449
|
|
|
$table = Database::get_course_table(TABLE_BLOGS_POSTS); |
450
|
|
|
$course_id = api_get_course_int_id(); |
451
|
|
|
$title = Database::escape_string($title); |
452
|
|
|
$full_text = Database::escape_string($full_text); |
453
|
|
|
$post_id = intval($post_id); |
454
|
|
|
$blog_id = intval($blog_id); |
455
|
|
|
|
456
|
|
|
// Create the post |
457
|
|
|
$sql = "UPDATE $table SET |
458
|
|
|
title = '$title', |
459
|
|
|
full_text = '$full_text' |
460
|
|
|
WHERE c_id = $course_id AND post_id = $post_id AND blog_id = $blog_id |
461
|
|
|
LIMIT 1"; |
462
|
|
|
Database::query($sql); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* Deletes an article and its comments. |
467
|
|
|
* |
468
|
|
|
* @author Toon Keppens |
469
|
|
|
* |
470
|
|
|
* @param int $blog_id The internal blog ID |
471
|
|
|
* @param int $post_id The internal post ID |
472
|
|
|
*/ |
473
|
|
|
public static function deletePost($blog_id, $post_id) |
474
|
|
|
{ |
475
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
476
|
|
|
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
477
|
|
|
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); |
478
|
|
|
$blog_id = intval($blog_id); |
479
|
|
|
$post_id = intval($post_id); |
480
|
|
|
|
481
|
|
|
$course_id = api_get_course_int_id(); |
482
|
|
|
|
483
|
|
|
// Delete ratings on this comment |
484
|
|
|
$sql = "DELETE FROM $tbl_blogs_rating |
485
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id AND item_id = $post_id AND rating_type = 'post'"; |
486
|
|
|
Database::query($sql); |
487
|
|
|
|
488
|
|
|
// Delete the post |
489
|
|
|
$sql = "DELETE FROM $tbl_blogs_posts |
490
|
|
|
WHERE c_id = $course_id AND post_id = $post_id"; |
491
|
|
|
Database::query($sql); |
492
|
|
|
|
493
|
|
|
// Delete the comments |
494
|
|
|
$sql = "DELETE FROM $tbl_blogs_comments |
495
|
|
|
WHERE c_id = $course_id AND post_id = $post_id AND blog_id = $blog_id"; |
496
|
|
|
Database::query($sql); |
497
|
|
|
|
498
|
|
|
// Delete posts and attachments |
499
|
|
|
self::deleteAllBlogAttachments($blog_id, $post_id); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* Creates a comment on a post in a given blog. |
504
|
|
|
* |
505
|
|
|
* @author Toon Keppens |
506
|
|
|
* |
507
|
|
|
* @param string $title The comment title |
508
|
|
|
* @param string $full_text The full text of the comment |
509
|
|
|
* @param string $file_comment A comment on a file, if any was uploaded |
510
|
|
|
* @param int $blog_id The internal blog ID |
511
|
|
|
* @param int $post_id The internal post ID |
512
|
|
|
* @param int $parent_id The internal parent post ID |
513
|
|
|
* @param int $task_id The internal task ID (if any) |
514
|
|
|
*/ |
515
|
|
|
public static function createComment( |
516
|
|
|
$title, |
517
|
|
|
$full_text, |
518
|
|
|
$file_comment, |
519
|
|
|
$blog_id, |
520
|
|
|
$post_id, |
521
|
|
|
$parent_id, |
522
|
|
|
$task_id = null |
523
|
|
|
) { |
524
|
|
|
$_user = api_get_user_info(); |
525
|
|
|
$_course = api_get_course_info(); |
526
|
|
|
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); |
527
|
|
|
|
528
|
|
|
$upload_ok = true; |
529
|
|
|
$has_attachment = false; |
530
|
|
|
$current_date = api_get_utc_datetime(); |
531
|
|
|
$course_id = api_get_course_int_id(); |
532
|
|
|
|
533
|
|
|
if (!empty($_FILES['user_upload']['name'])) { |
534
|
|
|
$upload_ok = process_uploaded_file($_FILES['user_upload']); |
535
|
|
|
$has_attachment = true; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
if ($upload_ok) { |
539
|
|
|
// Table Definition |
540
|
|
|
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
541
|
|
|
$title = Database::escape_string($title); |
542
|
|
|
$full_text = Database::escape_string($full_text); |
543
|
|
|
$blog_id = intval($blog_id); |
544
|
|
|
$post_id = intval($post_id); |
545
|
|
|
$parent_id = intval($parent_id); |
546
|
|
|
$task_id = !empty($task_id) ? intval($task_id) : 'null'; |
547
|
|
|
|
548
|
|
|
// Create the comment |
549
|
|
|
$sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id ) |
550
|
|
|
VALUES ($course_id, '$title', '$full_text', ".$_user['user_id'].", '$current_date', $blog_id, $post_id, $parent_id, '$task_id')"; |
551
|
|
|
Database::query($sql); |
552
|
|
|
|
553
|
|
|
// Empty post values, or they are shown on the page again |
554
|
|
|
$last_id = Database::insert_id(); |
555
|
|
|
|
556
|
|
|
if ($last_id) { |
557
|
|
|
$sql = "UPDATE $tbl_blogs_comments SET comment_id = iid WHERE iid = $last_id"; |
558
|
|
|
Database::query($sql); |
559
|
|
|
|
560
|
|
|
if ($has_attachment) { |
561
|
|
|
$courseDir = $_course['path'].'/upload/blog'; |
562
|
|
|
$sys_course_path = api_get_path(SYS_COURSE_PATH); |
563
|
|
|
$updir = $sys_course_path.$courseDir; |
564
|
|
|
|
565
|
|
|
// Try to add an extension to the file if it hasn't one |
566
|
|
|
$new_file_name = add_ext_on_mime( |
567
|
|
|
stripslashes($_FILES['user_upload']['name']), |
568
|
|
|
$_FILES['user_upload']['type'] |
569
|
|
|
); |
570
|
|
|
|
571
|
|
|
// user's file name |
572
|
|
|
$file_name = Database::escape_string($_FILES['user_upload']['name']); |
573
|
|
|
|
574
|
|
|
if (!filter_extension($new_file_name)) { |
575
|
|
|
echo Display::return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'error'); |
576
|
|
|
} else { |
577
|
|
|
$new_file_name = uniqid(''); |
578
|
|
|
$new_path = $updir.'/'.$new_file_name; |
579
|
|
|
$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); |
580
|
|
|
$comment = Database::escape_string($file_comment); |
581
|
|
|
$size = intval($_FILES['user_upload']['size']); |
582
|
|
|
|
583
|
|
|
// Storing the attachments if any |
584
|
|
|
if ($result) { |
585
|
|
|
$sql = "INSERT INTO $blog_table_attachment (c_id, filename,comment, path, post_id,size,blog_id,comment_id) |
586
|
|
|
VALUES ($course_id, '$file_name', '$comment', '$new_file_name', $post_id, $size, $blog_id, $last_id)"; |
587
|
|
|
Database::query($sql); |
588
|
|
|
|
589
|
|
|
$id = Database::insert_id(); |
590
|
|
|
|
591
|
|
|
if ($id) { |
592
|
|
|
$sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id"; |
593
|
|
|
Database::query($sql); |
594
|
|
|
} |
595
|
|
|
} |
596
|
|
|
} |
597
|
|
|
} |
598
|
|
|
} |
599
|
|
|
} |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* Deletes a comment from a blogpost. |
604
|
|
|
* |
605
|
|
|
* @author Toon Keppens |
606
|
|
|
* |
607
|
|
|
* @param int $blog_id The internal blog ID |
608
|
|
|
* @param int $post_id The internal post ID |
609
|
|
|
* @param int $comment_id The internal comment ID |
610
|
|
|
*/ |
611
|
|
|
public static function deleteComment($blog_id, $post_id, $comment_id) |
612
|
|
|
{ |
613
|
|
|
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
614
|
|
|
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); |
615
|
|
|
$blog_id = intval($blog_id); |
616
|
|
|
$post_id = intval($post_id); |
617
|
|
|
$comment_id = intval($comment_id); |
618
|
|
|
$course_id = api_get_course_int_id(); |
619
|
|
|
|
620
|
|
|
self::deleteAllBlogAttachments($blog_id, $post_id, $comment_id); |
621
|
|
|
|
622
|
|
|
// Delete ratings on this comment |
623
|
|
|
$sql = "DELETE FROM $tbl_blogs_rating |
624
|
|
|
WHERE |
625
|
|
|
c_id = $course_id AND |
626
|
|
|
blog_id = $blog_id AND |
627
|
|
|
item_id = $comment_id AND |
628
|
|
|
rating_type = 'comment'"; |
629
|
|
|
Database::query($sql); |
630
|
|
|
|
631
|
|
|
// select comments that have the selected comment as their parent |
632
|
|
|
$sql = "SELECT comment_id FROM $tbl_blogs_comments |
633
|
|
|
WHERE c_id = $course_id AND parent_comment_id = $comment_id"; |
634
|
|
|
$result = Database::query($sql); |
635
|
|
|
|
636
|
|
|
// Delete them recursively |
637
|
|
|
while ($comment = Database::fetch_array($result)) { |
638
|
|
|
self::deleteComment($blog_id, $post_id, $comment['comment_id']); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
// Finally, delete the selected comment to |
642
|
|
|
$sql = "DELETE FROM $tbl_blogs_comments |
643
|
|
|
WHERE c_id = $course_id AND comment_id = $comment_id"; |
644
|
|
|
Database::query($sql); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* Creates a new task in a blog. |
649
|
|
|
* |
650
|
|
|
* @author Toon Keppens |
651
|
|
|
* |
652
|
|
|
* @param int $blog_id |
653
|
|
|
* @param string $title |
654
|
|
|
* @param string $description |
655
|
|
|
* @param string $articleDelete Set to 'on' to register as 'article_delete' in tasks_permissions |
656
|
|
|
* @param string $articleEdit Set to 'on' to register as 'article_edit' in tasks_permissions |
657
|
|
|
* @param string $commentsDelete Set to 'on' to register as 'article_comments_delete' in tasks permissions |
658
|
|
|
* @param string $color |
659
|
|
|
*/ |
660
|
|
|
public static function addTask( |
661
|
|
|
$blog_id, |
662
|
|
|
$title, |
663
|
|
|
$description, |
664
|
|
|
$articleDelete, |
665
|
|
|
$articleEdit, |
666
|
|
|
$commentsDelete, |
667
|
|
|
$color |
668
|
|
|
) { |
669
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
670
|
|
|
$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); |
671
|
|
|
|
672
|
|
|
$course_id = api_get_course_int_id(); |
673
|
|
|
$blog_id = intval($blog_id); |
674
|
|
|
$title = Database::escape_string($title); |
675
|
|
|
$description = Database::escape_string($description); |
676
|
|
|
$color = Database::escape_string($color); |
677
|
|
|
|
678
|
|
|
// Create the task |
679
|
|
|
$sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task) |
680
|
|
|
VALUES ($course_id , $blog_id, '$title', '$description', '$color', '0');"; |
681
|
|
|
Database::query($sql); |
682
|
|
|
|
683
|
|
|
$task_id = Database::insert_id(); |
684
|
|
|
|
685
|
|
|
if ($task_id) { |
686
|
|
|
$sql = "UPDATE $tbl_blogs_tasks SET task_id = iid WHERE iid = $task_id"; |
687
|
|
|
Database::query($sql); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
$tool = 'BLOG_'.$blog_id; |
691
|
|
|
|
692
|
|
|
if ($articleDelete == 'on') { |
693
|
|
|
$sql = "INSERT INTO $tbl_tasks_permissions ( c_id, task_id, tool, action) |
694
|
|
|
VALUES ($course_id, $task_id, '$tool', 'article_delete')"; |
695
|
|
|
Database::query($sql); |
696
|
|
|
|
697
|
|
|
$id = Database::insert_id(); |
698
|
|
|
|
699
|
|
|
if ($id) { |
700
|
|
|
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; |
701
|
|
|
Database::query($sql); |
702
|
|
|
} |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
if ($articleEdit == 'on') { |
706
|
|
|
$sql = " |
707
|
|
|
INSERT INTO $tbl_tasks_permissions (c_id, task_id, tool, action ) |
708
|
|
|
VALUES ($course_id, $task_id, '$tool', 'article_edit')"; |
709
|
|
|
Database::query($sql); |
710
|
|
|
$id = Database::insert_id(); |
711
|
|
|
|
712
|
|
|
if ($id) { |
713
|
|
|
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; |
714
|
|
|
Database::query($sql); |
715
|
|
|
} |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
if ($commentsDelete == 'on') { |
719
|
|
|
$sql = " |
720
|
|
|
INSERT INTO $tbl_tasks_permissions (c_id, task_id, tool, action ) |
721
|
|
|
VALUES ($course_id, $task_id, '$tool', 'article_comments_delete')"; |
722
|
|
|
Database::query($sql); |
723
|
|
|
$id = Database::insert_id(); |
724
|
|
|
|
725
|
|
|
if ($id) { |
726
|
|
|
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; |
727
|
|
|
Database::query($sql); |
728
|
|
|
} |
729
|
|
|
} |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* Edit a task in a blog. |
734
|
|
|
* |
735
|
|
|
* @author Toon Keppens |
736
|
|
|
* |
737
|
|
|
* @param int $blog_id The internal blog ID |
738
|
|
|
* @param int $task_id The internal task ID |
739
|
|
|
* @param string $title The task title |
740
|
|
|
* @param string $description The task description |
741
|
|
|
* @param string $articleDelete Set to 'on' to register as 'article_delete' in tasks_permissions |
742
|
|
|
* @param string $articleEdit Set to 'on' to register as 'article_edit' in tasks_permissions |
743
|
|
|
* @param string $commentsDelete Set to 'on' to register as 'article_comments_delete' in tasks permissions |
744
|
|
|
* @param string $color The color code |
745
|
|
|
*/ |
746
|
|
|
public static function editTask( |
747
|
|
|
$blog_id, |
748
|
|
|
$task_id, |
749
|
|
|
$title, |
750
|
|
|
$description, |
751
|
|
|
$articleDelete, |
752
|
|
|
$articleEdit, |
753
|
|
|
$commentsDelete, |
754
|
|
|
$color |
755
|
|
|
) { |
756
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
757
|
|
|
$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); |
758
|
|
|
|
759
|
|
|
$course_id = api_get_course_int_id(); |
760
|
|
|
$blog_id = intval($blog_id); |
761
|
|
|
$task_id = intval($task_id); |
762
|
|
|
$title = Database::escape_string($title); |
763
|
|
|
$description = Database::escape_string($description); |
764
|
|
|
$color = Database::escape_string($color); |
765
|
|
|
|
766
|
|
|
// Create the task |
767
|
|
|
$sql = "UPDATE $tbl_blogs_tasks SET |
768
|
|
|
title = '$title', |
769
|
|
|
description = '$description', |
770
|
|
|
color = '$color' |
771
|
|
|
WHERE c_id = $course_id AND task_id = task_id LIMIT 1"; |
772
|
|
|
Database::query($sql); |
773
|
|
|
|
774
|
|
|
$tool = 'BLOG_'.$blog_id; |
775
|
|
|
$sql = "DELETE FROM $tbl_tasks_permissions |
776
|
|
|
WHERE c_id = $course_id AND task_id = $task_id"; |
777
|
|
|
Database::query($sql); |
778
|
|
|
|
779
|
|
|
if ($articleDelete == 'on') { |
780
|
|
|
$sql = "INSERT INTO $tbl_tasks_permissions ( c_id, task_id, tool, action) |
781
|
|
|
VALUES ($course_id, $task_id, '$tool', 'article_delete')"; |
782
|
|
|
Database::query($sql); |
783
|
|
|
$id = Database::insert_id(); |
784
|
|
|
|
785
|
|
|
if ($id) { |
786
|
|
|
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; |
787
|
|
|
Database::query($sql); |
788
|
|
|
} |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
if ($articleEdit == 'on') { |
792
|
|
|
$sql = "INSERT INTO $tbl_tasks_permissions (c_id, task_id, tool, action) |
793
|
|
|
VALUES ($course_id, $task_id, '$tool', 'article_edit')"; |
794
|
|
|
Database::query($sql); |
795
|
|
|
$id = Database::insert_id(); |
796
|
|
|
|
797
|
|
|
if ($id) { |
798
|
|
|
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; |
799
|
|
|
Database::query($sql); |
800
|
|
|
} |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
if ($commentsDelete == 'on') { |
804
|
|
|
$sql = "INSERT INTO $tbl_tasks_permissions (c_id, task_id, tool, action) |
805
|
|
|
VALUES ($course_id, $task_id, '$tool', 'article_comments_delete')"; |
806
|
|
|
Database::query($sql); |
807
|
|
|
$id = Database::insert_id(); |
808
|
|
|
|
809
|
|
|
if ($id) { |
810
|
|
|
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id"; |
811
|
|
|
Database::query($sql); |
812
|
|
|
} |
813
|
|
|
} |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
/** |
817
|
|
|
* Deletes a task from a blog. |
818
|
|
|
* |
819
|
|
|
* @param int $blog_id |
820
|
|
|
* @param int $task_id |
821
|
|
|
*/ |
822
|
|
|
public static function deleteTask($blog_id, $task_id) |
823
|
|
|
{ |
824
|
|
|
$table = Database::get_course_table(TABLE_BLOGS_TASKS); |
825
|
|
|
$course_id = api_get_course_int_id(); |
826
|
|
|
$blog_id = intval($blog_id); |
827
|
|
|
$task_id = intval($task_id); |
828
|
|
|
|
829
|
|
|
// Delete posts |
830
|
|
|
$sql = "DELETE FROM $table |
831
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id AND task_id = $task_id"; |
832
|
|
|
Database::query($sql); |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* Deletes an assigned task from a blog. |
837
|
|
|
* |
838
|
|
|
* @param int $blog_id |
839
|
|
|
* @param int $task_id |
840
|
|
|
* @param int $user_id |
841
|
|
|
*/ |
842
|
|
|
public static function deleteAssignedTask($blog_id, $task_id, $user_id) |
843
|
|
|
{ |
844
|
|
|
$table = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
845
|
|
|
$course_id = api_get_course_int_id(); |
846
|
|
|
$blog_id = intval($blog_id); |
847
|
|
|
$task_id = intval($task_id); |
848
|
|
|
$user_id = intval($user_id); |
849
|
|
|
|
850
|
|
|
// Delete posts |
851
|
|
|
$sql = "DELETE FROM $table |
852
|
|
|
WHERE |
853
|
|
|
c_id = $course_id AND |
854
|
|
|
blog_id = $blog_id AND |
855
|
|
|
task_id = $task_id AND |
856
|
|
|
user_id = $user_id"; |
857
|
|
|
Database::query($sql); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* Get personal task list. |
862
|
|
|
* |
863
|
|
|
* @author Toon Keppens |
864
|
|
|
* |
865
|
|
|
* @return string Returns an unsorted list (<ul></ul>) with the users' tasks |
866
|
|
|
*/ |
867
|
|
|
public static function getPersonalTasksList() |
868
|
|
|
{ |
869
|
|
|
$_user = api_get_user_info(); |
870
|
|
|
$html = null; |
871
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
872
|
|
|
$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
873
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
874
|
|
|
|
875
|
|
|
$course_id = api_get_course_int_id(); |
876
|
|
|
$blog_id = intval($_GET['blog_id']); |
877
|
|
|
|
878
|
|
|
if ($_user['user_id']) { |
879
|
|
|
$sql = "SELECT task_rel_user.*, task.title, blog.blog_name |
880
|
|
|
FROM $tbl_blogs_tasks_rel_user task_rel_user |
881
|
|
|
INNER JOIN $tbl_blogs_tasks task |
882
|
|
|
ON task_rel_user.task_id = task.task_id |
883
|
|
|
INNER JOIN $tbl_blogs blog |
884
|
|
|
ON task_rel_user.blog_id = blog.blog_id |
885
|
|
|
AND blog.blog_id = $blog_id |
886
|
|
|
WHERE |
887
|
|
|
task.c_id = $course_id AND |
888
|
|
|
blog.c_id = $course_id AND |
889
|
|
|
task_rel_user.c_id = $course_id AND |
890
|
|
|
task_rel_user.user_id = ".$_user['user_id']." |
891
|
|
|
ORDER BY target_date ASC"; |
892
|
|
|
|
893
|
|
|
$result = Database::query($sql); |
894
|
|
|
|
895
|
|
|
if (Database::num_rows($result) > 0) { |
896
|
|
|
$html .= '<ul>'; |
897
|
|
|
while ($mytask = Database::fetch_array($result)) { |
898
|
|
|
$html .= '<li> |
899
|
|
|
<a href="blog.php?action=execute_task&blog_id='.$mytask['blog_id'].'&task_id='.intval($mytask['task_id']).'" title="[Blog: '.stripslashes($mytask['blog_name']).'] '.get_lang('ExecuteThisTask').'">'. |
900
|
|
|
stripslashes($mytask['title']).'</a></li>'; |
901
|
|
|
} |
902
|
|
|
$html .= '<ul>'; |
903
|
|
|
} else { |
904
|
|
|
$html .= get_lang('NoTasks'); |
905
|
|
|
} |
906
|
|
|
} else { |
907
|
|
|
$html .= get_lang('NoTasks'); |
908
|
|
|
} |
909
|
|
|
|
910
|
|
|
return $html; |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
/** |
914
|
|
|
* Changes the visibility of a blog. |
915
|
|
|
* |
916
|
|
|
* @author Toon Keppens |
917
|
|
|
* |
918
|
|
|
* @param int $blog_id |
919
|
|
|
*/ |
920
|
|
|
public static function changeBlogVisibility($blog_id) |
921
|
|
|
{ |
922
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
923
|
|
|
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); |
924
|
|
|
$course_id = api_get_course_int_id(); |
925
|
|
|
|
926
|
|
|
// Get blog properties |
927
|
|
|
$sql = "SELECT blog_name, visibility FROM $tbl_blogs |
928
|
|
|
WHERE c_id = $course_id AND blog_id='".(int) $blog_id."'"; |
929
|
|
|
$result = Database::query($sql); |
930
|
|
|
$blog = Database::fetch_array($result); |
931
|
|
|
$visibility = $blog['visibility']; |
932
|
|
|
$title = $blog['blog_name']; |
933
|
|
|
|
934
|
|
|
if ($visibility == 1) { |
935
|
|
|
// Change visibility state, remove from course home. |
936
|
|
|
$sql = "UPDATE $tbl_blogs SET visibility = '0' |
937
|
|
|
WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."' LIMIT 1"; |
938
|
|
|
Database::query($sql); |
939
|
|
|
|
940
|
|
|
$sql = "DELETE FROM $tbl_tool |
941
|
|
|
WHERE c_id = $course_id AND name = '".Database::escape_string($title)."' |
942
|
|
|
LIMIT 1"; |
943
|
|
|
Database::query($sql); |
944
|
|
|
} else { |
945
|
|
|
// Change visibility state, add to course home. |
946
|
|
|
$sql = "UPDATE $tbl_blogs SET visibility = '1' |
947
|
|
|
WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."' LIMIT 1"; |
948
|
|
|
Database::query($sql); |
949
|
|
|
|
950
|
|
|
$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target) |
951
|
|
|
VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int) $blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')"; |
952
|
|
|
Database::query($sql); |
953
|
|
|
$id = Database::insert_id(); |
954
|
|
|
|
955
|
|
|
if ($id) { |
956
|
|
|
$sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $id"; |
957
|
|
|
Database::query($sql); |
958
|
|
|
} |
959
|
|
|
} |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* Display the search results. |
964
|
|
|
* |
965
|
|
|
* @param int $blog_id |
966
|
|
|
* @param string $query_string |
967
|
|
|
* |
968
|
|
|
* @return string|array |
969
|
|
|
*/ |
970
|
|
|
public static function getSearchResults($blog_id, $query_string) |
971
|
|
|
{ |
972
|
|
|
$query_string_parts = explode(' ', $query_string); |
973
|
|
|
$query_string = []; |
974
|
|
|
foreach ($query_string_parts as $query_part) { |
975
|
|
|
$query_part = Database::escape_string($query_part); |
976
|
|
|
$query_string[] = " full_text LIKE '%".$query_part."%' OR title LIKE '%".$query_part."%' "; |
977
|
|
|
} |
978
|
|
|
$query_string = '('.implode('OR', $query_string).')'; |
979
|
|
|
|
980
|
|
|
// Display the posts |
981
|
|
|
return self::getPosts($blog_id, $query_string); |
982
|
|
|
} |
983
|
|
|
|
984
|
|
|
/** |
985
|
|
|
* Shows the posts of a blog. |
986
|
|
|
* |
987
|
|
|
* @author Toon Keppens |
988
|
|
|
* |
989
|
|
|
* @param int $blog_id |
990
|
|
|
* @param string $filter |
991
|
|
|
* @param int $max_number_of_posts |
992
|
|
|
* |
993
|
|
|
* @return string|array |
994
|
|
|
*/ |
995
|
|
|
public static function getPosts($blog_id, $filter = '1=1', $max_number_of_posts = 20) |
996
|
|
|
{ |
997
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
998
|
|
|
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
999
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
1000
|
|
|
|
1001
|
|
|
$course_id = api_get_course_int_id(); |
1002
|
|
|
$blog_id = intval($blog_id); |
1003
|
|
|
$max_number_of_posts = intval($max_number_of_posts); |
1004
|
|
|
// Get posts and authors |
1005
|
|
|
$sql = "SELECT post.*, user.lastname, user.firstname, user.username |
1006
|
|
|
FROM $tbl_blogs_posts post |
1007
|
|
|
INNER JOIN $tbl_users user |
1008
|
|
|
ON post.author_id = user.user_id |
1009
|
|
|
WHERE |
1010
|
|
|
post.blog_id = $blog_id AND |
1011
|
|
|
post.c_id = $course_id AND |
1012
|
|
|
$filter |
1013
|
|
|
ORDER BY post_id DESC |
1014
|
|
|
LIMIT 0, $max_number_of_posts"; |
1015
|
|
|
$result = Database::query($sql); |
1016
|
|
|
|
1017
|
|
|
// Display |
1018
|
|
|
if (Database::num_rows($result) > 0) { |
1019
|
|
|
$limit = 200; |
1020
|
|
|
$listArticle = []; |
1021
|
|
|
while ($blog_post = Database::fetch_array($result)) { |
1022
|
|
|
// Get number of comments |
1023
|
|
|
$sql = "SELECT COUNT(1) as number_of_comments |
1024
|
|
|
FROM $tbl_blogs_comments |
1025
|
|
|
WHERE |
1026
|
|
|
c_id = $course_id AND |
1027
|
|
|
blog_id = $blog_id AND |
1028
|
|
|
post_id = ".$blog_post['post_id']; |
1029
|
|
|
$tmp = Database::query($sql); |
1030
|
|
|
$blog_post_comments = Database::fetch_array($tmp); |
1031
|
|
|
|
1032
|
|
|
$fileArray = self::getBlogAttachments($blog_id, $blog_post['post_id'], 0); |
1033
|
|
|
$scoreRanking = self::displayRating( |
1034
|
|
|
'post', |
1035
|
|
|
$blog_id, |
1036
|
|
|
$blog_post['post_id'] |
1037
|
|
|
); |
1038
|
|
|
|
1039
|
|
|
// Prepare data |
1040
|
|
|
$article = [ |
1041
|
|
|
'id_blog' => $blog_post['blog_id'], |
1042
|
|
|
'c_id' => $blog_post['c_id'], |
1043
|
|
|
'id_post' => $blog_post['post_id'], |
1044
|
|
|
'id_autor' => $blog_post['author_id'], |
1045
|
|
|
'autor' => $blog_post['firstname'].' '.$blog_post['lastname'], |
1046
|
|
|
'username' => $blog_post['username'], |
1047
|
|
|
'title' => stripslashes($blog_post['title']), |
1048
|
|
|
'extract' => self::getPostExtract($blog_post['full_text'], BLOG_MAX_PREVIEW_CHARS), |
1049
|
|
|
'content' => stripslashes($blog_post['full_text']), |
1050
|
|
|
'post_date' => Display::dateToStringAgoAndLongDate($blog_post['date_creation']), |
1051
|
|
|
'n_comments' => $blog_post_comments['number_of_comments'], |
1052
|
|
|
'files' => $fileArray, |
1053
|
|
|
'score_ranking' => $scoreRanking, |
1054
|
|
|
]; |
1055
|
|
|
|
1056
|
|
|
$listArticle[] = $article; |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
|
|
return $listArticle; |
1060
|
|
|
} else { |
1061
|
|
|
if ($filter == '1=1') { |
1062
|
|
|
return get_lang('NoArticles'); |
1063
|
|
|
} else { |
1064
|
|
|
return get_lang('NoArticleMatches'); |
1065
|
|
|
} |
1066
|
|
|
} |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
/** |
1070
|
|
|
* Display posts from a certain date. |
1071
|
|
|
* |
1072
|
|
|
* @param int $blog_id |
1073
|
|
|
* @param string $query_string |
1074
|
|
|
* |
1075
|
|
|
* @return string|array |
1076
|
|
|
*/ |
1077
|
|
|
public static function getDailyResults($blog_id, $query_string) |
1078
|
|
|
{ |
1079
|
|
|
$date = explode('-', $query_string); |
1080
|
|
|
$query_string = ' |
1081
|
|
|
DAYOFMONTH(date_creation) ='.intval($date[2]).' AND |
1082
|
|
|
MONTH(date_creation) ='.intval($date[1]).' AND |
1083
|
|
|
YEAR(date_creation) ='.intval($date[0]); |
1084
|
|
|
$list = self::getPosts($blog_id, $query_string); |
1085
|
|
|
|
1086
|
|
|
return $list; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* Displays a post and his comments. |
1091
|
|
|
* |
1092
|
|
|
* @param int $blog_id |
1093
|
|
|
* @param int $post_id |
1094
|
|
|
* |
1095
|
|
|
* @return array |
1096
|
|
|
*/ |
1097
|
|
|
public static function getSinglePost($blog_id, $post_id) |
1098
|
|
|
{ |
1099
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
1100
|
|
|
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
1101
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
1102
|
|
|
$listComments = null; |
1103
|
|
|
global $charset; |
1104
|
|
|
|
1105
|
|
|
$course_id = api_get_course_int_id(); |
1106
|
|
|
$blog_id = intval($blog_id); |
1107
|
|
|
$post_id = intval($post_id); |
1108
|
|
|
|
1109
|
|
|
// Get posts and author |
1110
|
|
|
$sql = "SELECT post.*, user.lastname, user.firstname, user.username |
1111
|
|
|
FROM $tbl_blogs_posts post |
1112
|
|
|
INNER JOIN $tbl_users user |
1113
|
|
|
ON post.author_id = user.user_id |
1114
|
|
|
WHERE |
1115
|
|
|
post.c_id = $course_id AND |
1116
|
|
|
post.blog_id = $blog_id AND |
1117
|
|
|
post.post_id = $post_id |
1118
|
|
|
ORDER BY post_id DESC"; |
1119
|
|
|
$result = Database::query($sql); |
1120
|
|
|
$blog_post = Database::fetch_array($result); |
1121
|
|
|
|
1122
|
|
|
// Get number of comments |
1123
|
|
|
$sql = "SELECT COUNT(1) as number_of_comments |
1124
|
|
|
FROM $tbl_blogs_comments |
1125
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id AND post_id = $post_id"; |
1126
|
|
|
$result = Database::query($sql); |
1127
|
|
|
$blog_post_comments = Database::fetch_array($result); |
1128
|
|
|
$blogActions = null; |
1129
|
|
|
|
1130
|
|
|
$task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0; |
1131
|
|
|
|
1132
|
|
|
// Display comments if there are any |
1133
|
|
|
if ($blog_post_comments['number_of_comments'] > 0) { |
1134
|
|
|
$listComments = self::getThreadedComments(0, 0, $blog_id, $post_id, $task_id); |
1135
|
|
|
} |
1136
|
|
|
// Display comment form |
1137
|
|
|
if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_add')) { |
1138
|
|
|
$formComments = self::displayCommentCreateForm($blog_id, $post_id, $blog_post['title'], false); |
1139
|
|
|
} |
1140
|
|
|
// Prepare data |
1141
|
|
|
$fileArray = self::getBlogAttachments($blog_id, $post_id); |
1142
|
|
|
|
1143
|
|
|
$post_text = make_clickable(stripslashes($blog_post['full_text'])); |
1144
|
|
|
$post_text = stripslashes($post_text); |
1145
|
|
|
|
1146
|
|
|
if (api_is_allowed('BLOG_'.$blog_id, 'article_edit', $task_id)) { |
1147
|
|
|
$blogActions .= '<a class="btn btn-default" 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').'">'; |
1148
|
|
|
$blogActions .= Display::return_icon('edit.png', get_lang('Edit'), null, ICON_SIZE_TINY); |
1149
|
|
|
$blogActions .= '</a>'; |
1150
|
|
|
} |
1151
|
|
|
|
1152
|
|
|
if (api_is_allowed('BLOG_'.$blog_id, 'article_delete', $task_id)) { |
1153
|
|
|
$blogActions .= '<a class="btn btn-default" 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( |
1154
|
|
|
'DeleteThisArticle' |
1155
|
|
|
).'" onclick="javascript:if(!confirm(\''.addslashes( |
1156
|
|
|
api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset) |
1157
|
|
|
).'\')) return false;">'; |
1158
|
|
|
$blogActions .= Display::return_icon( |
1159
|
|
|
'delete.png', |
1160
|
|
|
get_lang('Delete'), |
1161
|
|
|
null, |
1162
|
|
|
ICON_SIZE_TINY |
1163
|
|
|
); |
1164
|
|
|
$blogActions .= '</a>'; |
1165
|
|
|
} |
1166
|
|
|
$scoreRanking = self::displayRating('post', $blog_id, $post_id); |
1167
|
|
|
$article = [ |
1168
|
|
|
'id_blog' => $blog_post['blog_id'], |
1169
|
|
|
'c_id' => $blog_post['c_id'], |
1170
|
|
|
'id_post' => $blog_post['post_id'], |
1171
|
|
|
'id_author' => $blog_post['author_id'], |
1172
|
|
|
'author' => $blog_post['firstname'].' '.$blog_post['lastname'], |
1173
|
|
|
'username' => $blog_post['username'], |
1174
|
|
|
'title' => stripslashes($blog_post['title']), |
1175
|
|
|
'extract' => api_get_short_text_from_html( |
1176
|
|
|
stripslashes($blog_post['full_text']), |
1177
|
|
|
400 |
1178
|
|
|
), |
1179
|
|
|
'content' => $post_text, |
1180
|
|
|
'post_date' => Display::dateToStringAgoAndLongDate($blog_post['date_creation']), |
1181
|
|
|
'n_comments' => $blog_post_comments['number_of_comments'], |
1182
|
|
|
'files' => $fileArray, |
1183
|
|
|
'id_task' => $task_id, |
1184
|
|
|
'comments' => $listComments, |
1185
|
|
|
'form_html' => $formComments, |
|
|
|
|
1186
|
|
|
'actions' => $blogActions, |
1187
|
|
|
'score_ranking' => (int) $scoreRanking, |
1188
|
|
|
'frm_rating' => api_is_allowed('BLOG_'.$blog_id, 'article_rate') |
1189
|
|
|
? self::displayRatingCreateForm('post', $blog_id, $post_id) |
1190
|
|
|
: null, |
1191
|
|
|
]; |
1192
|
|
|
|
1193
|
|
|
return $article; |
1194
|
|
|
} |
1195
|
|
|
|
1196
|
|
|
/** |
1197
|
|
|
* This functions gets all replies to a post, threaded. |
1198
|
|
|
* |
1199
|
|
|
* @param int $current |
1200
|
|
|
* @param int $current_level |
1201
|
|
|
* @param int $blog_id |
1202
|
|
|
* @param int $post_id |
1203
|
|
|
* @param int $task_id |
1204
|
|
|
* |
1205
|
|
|
* @return array |
1206
|
|
|
*/ |
1207
|
|
|
public static function getThreadedComments( |
1208
|
|
|
$current = 0, |
1209
|
|
|
$current_level = 0, |
1210
|
|
|
$blog_id, |
1211
|
|
|
$post_id, |
1212
|
|
|
$task_id = 0 |
1213
|
|
|
) { |
1214
|
|
|
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
1215
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
1216
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
1217
|
|
|
$charset = api_get_system_encoding(); |
1218
|
|
|
|
1219
|
|
|
$course_id = api_get_course_int_id(); |
1220
|
|
|
$blog_id = intval($blog_id); |
1221
|
|
|
$post_id = intval($post_id); |
1222
|
|
|
$task_id = intval($task_id); |
1223
|
|
|
|
1224
|
|
|
$listComments = []; |
1225
|
|
|
// Select top level comments |
1226
|
|
|
$next_level = $current_level + 1; |
1227
|
|
|
$sql = "SELECT comments.*, user.lastname, user.firstname, user.username, task.color |
1228
|
|
|
FROM $tbl_blogs_comments comments |
1229
|
|
|
INNER JOIN $tbl_users user |
1230
|
|
|
ON comments.author_id = user.user_id |
1231
|
|
|
LEFT JOIN $tbl_blogs_tasks task |
1232
|
|
|
ON comments.task_id = task.task_id AND task.c_id = $course_id |
1233
|
|
|
WHERE |
1234
|
|
|
comments.c_id = $course_id AND |
1235
|
|
|
parent_comment_id = $current AND |
1236
|
|
|
comments.blog_id = $blog_id AND |
1237
|
|
|
comments.post_id = $post_id"; |
1238
|
|
|
|
1239
|
|
|
$result = Database::query($sql); |
1240
|
|
|
$html = null; |
1241
|
|
|
while ($comment = Database::fetch_array($result)) { |
1242
|
|
|
$commentActions = null; |
1243
|
|
|
$ratingSelect = null; |
1244
|
|
|
$comment_text = make_clickable(stripslashes($comment['comment'])); |
1245
|
|
|
$comment_text = stripslashes($comment_text); |
1246
|
|
|
|
1247
|
|
|
$commentActions .= Display::toolbarButton( |
1248
|
|
|
get_lang('ReplyToThisComment'), |
1249
|
|
|
'#', |
1250
|
|
|
'reply', |
1251
|
|
|
'default', |
1252
|
|
|
['data-id' => $comment['iid'], 'role' => 'button', 'class' => 'btn-reply-to'], |
1253
|
|
|
false |
1254
|
|
|
); |
1255
|
|
|
|
1256
|
|
|
if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id)) { |
1257
|
|
|
$commentActions .= ' <a class="btn btn-default" 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( |
1258
|
|
|
'DeleteThisComment' |
1259
|
|
|
).'" onclick="javascript:if(!confirm(\''.addslashes( |
1260
|
|
|
api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset) |
1261
|
|
|
).'\')) return false;">'; |
1262
|
|
|
$commentActions .= Display::returnFontAwesomeIcon('trash'); |
1263
|
|
|
$commentActions .= '</a>'; |
1264
|
|
|
} |
1265
|
|
|
if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_rate')) { |
1266
|
|
|
$ratingSelect = self::displayRatingCreateForm( |
1267
|
|
|
'comment', |
1268
|
|
|
$blog_id, |
1269
|
|
|
$post_id, |
1270
|
|
|
$comment['comment_id'] |
1271
|
|
|
); |
1272
|
|
|
} |
1273
|
|
|
|
1274
|
|
|
$scoreRanking = self::displayRating( |
1275
|
|
|
'comment', |
1276
|
|
|
$blog_id, |
1277
|
|
|
$comment['comment_id'] |
1278
|
|
|
); |
1279
|
|
|
|
1280
|
|
|
// Files |
1281
|
|
|
$fileArray = self::getBlogAttachments( |
1282
|
|
|
$blog_id, |
1283
|
|
|
$post_id, |
1284
|
|
|
$comment['comment_id'] |
1285
|
|
|
); |
1286
|
|
|
$userInfo = api_get_user_info($comment['author_id']); |
1287
|
|
|
$comments = [ |
1288
|
|
|
'iid' => $comment['iid'], |
1289
|
|
|
'id_comment' => $comment['comment_id'], |
1290
|
|
|
'id_curso' => $comment['c_id'], |
1291
|
|
|
'title' => $comment['title'], |
1292
|
|
|
'content' => $comment_text, |
1293
|
|
|
'id_author' => $comment['author_id'], |
1294
|
|
|
'comment_date' => Display::dateToStringAgoAndLongDate($comment['date_creation']), |
1295
|
|
|
'id_blog' => $comment['blog_id'], |
1296
|
|
|
'id_post' => $comment['post_id'], |
1297
|
|
|
'id_task' => $comment['task_id'], |
1298
|
|
|
'id_parent' => $comment['parent_comment_id'], |
1299
|
|
|
'user_info' => $userInfo, |
1300
|
|
|
'color' => $comment['color'], |
1301
|
|
|
'files' => $fileArray, |
1302
|
|
|
'actions' => $commentActions, |
1303
|
|
|
'form_ranking' => $ratingSelect, |
1304
|
|
|
'score_ranking' => $scoreRanking, |
1305
|
|
|
'comments' => self::getThreadedComments( |
1306
|
|
|
$comment['iid'], |
1307
|
|
|
$next_level, |
1308
|
|
|
$blog_id, |
1309
|
|
|
$post_id |
1310
|
|
|
), |
1311
|
|
|
]; |
1312
|
|
|
|
1313
|
|
|
$listComments[] = $comments; |
1314
|
|
|
} |
1315
|
|
|
|
1316
|
|
|
return $listComments; |
1317
|
|
|
} |
1318
|
|
|
|
1319
|
|
|
/** |
1320
|
|
|
* Shows the rating form if not already rated by that user. |
1321
|
|
|
* |
1322
|
|
|
* @author Toon Keppens |
1323
|
|
|
* |
1324
|
|
|
* @param string $type |
1325
|
|
|
* @param int $blog_id |
1326
|
|
|
* @param int $post_id |
1327
|
|
|
* @param int $comment_id |
1328
|
|
|
* |
1329
|
|
|
* @return string |
1330
|
|
|
*/ |
1331
|
|
|
public static function displayRatingCreateForm($type, $blog_id, $post_id, $comment_id = null) |
1332
|
|
|
{ |
1333
|
|
|
$_user = api_get_user_info(); |
1334
|
|
|
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); |
1335
|
|
|
$course_id = api_get_course_int_id(); |
1336
|
|
|
$blog_id = intval($blog_id); |
1337
|
|
|
$post_id = intval($post_id); |
1338
|
|
|
$comment_id = isset($comment_id) ? intval($comment_id) : null; |
1339
|
|
|
$type = Database::escape_string($type); |
1340
|
|
|
$html = null; |
1341
|
|
|
|
1342
|
|
|
if ($type == 'post') { |
1343
|
|
|
// Check if the user has already rated this post |
1344
|
|
|
$sql = "SELECT rating_id FROM $tbl_blogs_rating |
1345
|
|
|
WHERE c_id = $course_id AND |
1346
|
|
|
blog_id = $blog_id |
1347
|
|
|
AND item_id = $post_id |
1348
|
|
|
AND rating_type = '$type' |
1349
|
|
|
AND user_id = ".$_user['user_id']; |
1350
|
|
|
$result = Database::query($sql); |
1351
|
|
|
// Add rating |
1352
|
|
|
if (Database::num_rows($result) == 0) { |
1353
|
|
|
$html .= '<form class="form-horizontal" method="get" action="blog.php" id="frm_rating_'.$type.'_'.$post_id.'" name="frm_rating_'.$type.'_'.$post_id.'">'; |
1354
|
|
|
$html .= '<div class="form-group">'; |
1355
|
|
|
$html .= '<label class="col-sm-3 control-label">'.get_lang('RateThis').'</label>'; |
1356
|
|
|
$html .= '<div class="col-sm-9">'; |
1357
|
|
|
$html .= '<select class="selectpicker" 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.'" />'; |
1358
|
|
|
$html .= '</div>'; |
1359
|
|
|
$html .= '</div>'; |
1360
|
|
|
$html .= '</form>'; |
1361
|
|
|
|
1362
|
|
|
return $html; |
1363
|
|
|
} else { |
1364
|
|
|
return ''; |
1365
|
|
|
} |
1366
|
|
|
} |
1367
|
|
|
|
1368
|
|
|
if ($type = 'comment') { |
1369
|
|
|
// Check if the user has already rated this comment |
1370
|
|
|
$sql = "SELECT rating_id FROM $tbl_blogs_rating |
1371
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id |
1372
|
|
|
AND item_id = $comment_id |
1373
|
|
|
AND rating_type = '$type' |
1374
|
|
|
AND user_id = ".$_user['user_id']; |
1375
|
|
|
$result = Database::query($sql); |
1376
|
|
|
if (Database::num_rows($result) == 0) { |
1377
|
|
|
$html .= '<form class="form-horizontal" method="get" action="blog.php" id="frm_rating_'.$type.'_'.$comment_id.'" name="frm_rating_'.$type.'_'.$comment_id.'">'; |
1378
|
|
|
$html .= '<div class="form-group">'; |
1379
|
|
|
$html .= '<label class="col-sm-3 control-label">'.get_lang('RateThis').'</label>'; |
1380
|
|
|
$html .= '<div class="col-sm-9">'; |
1381
|
|
|
$html .= '<select class="selectpicker" name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$comment_id.'\'].submit()">'; |
1382
|
|
|
$html .= '<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> |
1383
|
|
|
</select> |
1384
|
|
|
<input type="hidden" name="action" value="view_post" /> |
1385
|
|
|
<input type="hidden" name="type" value="'.$type.'" /> |
1386
|
|
|
<input type="hidden" name="do" value="rate" /> |
1387
|
|
|
<input type="hidden" name="blog_id" value="'.$blog_id.'" /> |
1388
|
|
|
<input type="hidden" name="post_id" value="'.$post_id.'" /> |
1389
|
|
|
<input type="hidden" name="comment_id" value="'.$comment_id.'" />'; |
1390
|
|
|
$html .= '</div>'; |
1391
|
|
|
$html .= '</div>'; |
1392
|
|
|
$html .= '</form>'; |
1393
|
|
|
|
1394
|
|
|
return $html; |
1395
|
|
|
} else { |
1396
|
|
|
return ''; |
1397
|
|
|
} |
1398
|
|
|
} |
1399
|
|
|
} |
1400
|
|
|
|
1401
|
|
|
/** |
1402
|
|
|
* Shows the rating of user. |
1403
|
|
|
* |
1404
|
|
|
* @param string $type |
1405
|
|
|
* @param int $blog_id |
1406
|
|
|
* @param int $item_id |
1407
|
|
|
* |
1408
|
|
|
* @return float |
1409
|
|
|
*/ |
1410
|
|
|
public static function displayRating($type, $blog_id, $item_id) |
1411
|
|
|
{ |
1412
|
|
|
$table = Database::get_course_table(TABLE_BLOGS_RATING); |
1413
|
|
|
$course_id = api_get_course_int_id(); |
1414
|
|
|
$blog_id = intval($blog_id); |
1415
|
|
|
$item_id = intval($item_id); |
1416
|
|
|
$type = Database::escape_string($type); |
1417
|
|
|
|
1418
|
|
|
// Calculate rating |
1419
|
|
|
$sql = "SELECT AVG(rating) as rating FROM $table |
1420
|
|
|
WHERE |
1421
|
|
|
c_id = $course_id AND |
1422
|
|
|
blog_id = $blog_id AND |
1423
|
|
|
item_id = $item_id AND |
1424
|
|
|
rating_type = '$type'"; |
1425
|
|
|
$result = Database::query($sql); |
1426
|
|
|
$result = Database::fetch_array($result); |
1427
|
|
|
|
1428
|
|
|
return round($result['rating'], 2); |
1429
|
|
|
} |
1430
|
|
|
|
1431
|
|
|
/** |
1432
|
|
|
* Displays the form to create a new post. |
1433
|
|
|
* |
1434
|
|
|
* @author Toon Keppens |
1435
|
|
|
* |
1436
|
|
|
* @param int $blog_id |
1437
|
|
|
* @param int $post_id |
1438
|
|
|
* |
1439
|
|
|
* @return string HTML form |
1440
|
|
|
*/ |
1441
|
|
|
public static function displayCommentCreateForm($blog_id, $post_id) |
1442
|
|
|
{ |
1443
|
|
|
$taskId = !empty($_GET['task_id']) ? intval($_GET['task_id']) : 0; |
1444
|
|
|
$blog_id = intval($blog_id); |
1445
|
|
|
$post_id = intval($post_id); |
1446
|
|
|
|
1447
|
|
|
$form = new FormValidator( |
1448
|
|
|
'add_post', |
1449
|
|
|
'post', |
1450
|
|
|
api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
1451
|
|
|
'action' => 'view_post', |
1452
|
|
|
'blog_id' => $blog_id, |
1453
|
|
|
'post_id' => $post_id, |
1454
|
|
|
'task_id' => $taskId, |
1455
|
|
|
]), |
1456
|
|
|
null, |
1457
|
|
|
['enctype' => 'multipart/form-data'] |
1458
|
|
|
); |
1459
|
|
|
|
1460
|
|
|
$header = $taskId ? get_lang('ExecuteThisTask') : get_lang('AddNewComment'); |
1461
|
|
|
$form->addHeader($header); |
1462
|
|
|
$form->addText('title', get_lang('Title')); |
1463
|
|
|
|
1464
|
|
|
$config = []; |
1465
|
|
|
if (!api_is_allowed_to_edit()) { |
1466
|
|
|
$config['ToolbarSet'] = 'ProjectComment'; |
1467
|
|
|
} else { |
1468
|
|
|
$config['ToolbarSet'] = 'ProjectCommentStudent'; |
1469
|
|
|
} |
1470
|
|
|
$form->addHtmlEditor( |
1471
|
|
|
'comment', |
1472
|
|
|
get_lang('Comment'), |
1473
|
|
|
false, |
1474
|
|
|
false, |
1475
|
|
|
$config |
1476
|
|
|
); |
1477
|
|
|
$form->addFile('user_upload', get_lang('AddAnAttachment')); |
1478
|
|
|
$form->addTextarea('post_file_comment', get_lang('FileComment')); |
1479
|
|
|
$form->addHidden('action', null); |
1480
|
|
|
$form->addHidden('comment_parent_id', 0); |
1481
|
|
|
$form->addHidden('task_id', $taskId); |
1482
|
|
|
$form->addButton('save', get_lang('Save')); |
1483
|
|
|
|
1484
|
|
|
if ($form->validate()) { |
1485
|
|
|
$values = $form->exportValues(); |
1486
|
|
|
|
1487
|
|
|
self::createComment( |
1488
|
|
|
$values['title'], |
1489
|
|
|
$values['comment'], |
1490
|
|
|
$values['post_file_comment'], |
1491
|
|
|
$blog_id, |
1492
|
|
|
$post_id, |
1493
|
|
|
$values['comment_parent_id'], |
1494
|
|
|
$taskId |
1495
|
|
|
); |
1496
|
|
|
|
1497
|
|
|
Display::addFlash( |
1498
|
|
|
Display::return_message(get_lang('CommentAdded'), 'success') |
1499
|
|
|
); |
1500
|
|
|
|
1501
|
|
|
header( |
1502
|
|
|
'Location: ' |
1503
|
|
|
.api_get_self() |
1504
|
|
|
.'?' |
1505
|
|
|
.api_get_cidreq() |
1506
|
|
|
.'&' |
1507
|
|
|
.http_build_query([ |
1508
|
|
|
'blog_id' => $blog_id, |
1509
|
|
|
'post_id' => $post_id, |
1510
|
|
|
'action' => 'view_post', |
1511
|
|
|
'task_id' => $taskId, |
1512
|
|
|
]) |
1513
|
|
|
); |
1514
|
|
|
exit; |
1515
|
|
|
} |
1516
|
|
|
|
1517
|
|
|
return $form->returnForm(); |
1518
|
|
|
} |
1519
|
|
|
|
1520
|
|
|
/** |
1521
|
|
|
* Adds rating to a certain post or comment. |
1522
|
|
|
* |
1523
|
|
|
* @author Toon Keppens |
1524
|
|
|
* |
1525
|
|
|
* @param string $type |
1526
|
|
|
* @param int $blog_id |
1527
|
|
|
* @param int $item_id |
1528
|
|
|
* @param int $rating |
1529
|
|
|
* |
1530
|
|
|
* @return bool success |
1531
|
|
|
*/ |
1532
|
|
|
public static function addRating($type, $blog_id, $item_id, $rating) |
1533
|
|
|
{ |
1534
|
|
|
$_user = api_get_user_info(); |
1535
|
|
|
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); |
1536
|
|
|
$course_id = api_get_course_int_id(); |
1537
|
|
|
$blog_id = intval($blog_id); |
1538
|
|
|
$item_id = intval($item_id); |
1539
|
|
|
$type = Database::escape_string($type); |
1540
|
|
|
$rating = Database::escape_string($rating); |
1541
|
|
|
|
1542
|
|
|
// Check if the user has already rated this post/comment |
1543
|
|
|
$sql = "SELECT rating_id FROM $tbl_blogs_rating |
1544
|
|
|
WHERE |
1545
|
|
|
c_id = $course_id AND |
1546
|
|
|
blog_id = $blog_id AND |
1547
|
|
|
item_id = $item_id AND |
1548
|
|
|
rating_type = '$type' AND |
1549
|
|
|
user_id = ".$_user['user_id']; |
1550
|
|
|
$result = Database::query($sql); |
1551
|
|
|
|
1552
|
|
|
// Add rating |
1553
|
|
|
if (Database::num_rows($result) == 0) { |
1554
|
|
|
$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating ) |
1555
|
|
|
VALUES ($course_id, $blog_id, '$type', $item_id, ".$_user['user_id'].", '$rating')"; |
1556
|
|
|
Database::query($sql); |
1557
|
|
|
|
1558
|
|
|
$id = Database::insert_id(); |
1559
|
|
|
if ($id) { |
1560
|
|
|
$sql = "UPDATE $tbl_blogs_rating SET rating_id = iid WHERE iid = $id"; |
1561
|
|
|
Database::query($sql); |
1562
|
|
|
} |
1563
|
|
|
|
1564
|
|
|
return true; |
1565
|
|
|
} else { |
1566
|
|
|
return false; |
1567
|
|
|
} |
1568
|
|
|
} |
1569
|
|
|
|
1570
|
|
|
/** |
1571
|
|
|
* Displays the form to create a new post. |
1572
|
|
|
* |
1573
|
|
|
* @author Toon Keppens |
1574
|
|
|
* |
1575
|
|
|
* @param int $blog_id |
1576
|
|
|
* |
1577
|
|
|
* @return string |
1578
|
|
|
*/ |
1579
|
|
|
public static function displayPostCreateForm($blog_id) |
1580
|
|
|
{ |
1581
|
|
|
$blog_id = intval($blog_id); |
1582
|
|
|
if (!api_is_allowed('BLOG_'.$blog_id, 'article_add')) { |
1583
|
|
|
api_not_allowed(); |
1584
|
|
|
} |
1585
|
|
|
|
1586
|
|
|
$form = new FormValidator( |
1587
|
|
|
'add_post', |
1588
|
|
|
'post', |
1589
|
|
|
api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=".$blog_id."&".api_get_cidreq(), |
1590
|
|
|
null, |
1591
|
|
|
['enctype' => 'multipart/form-data'] |
1592
|
|
|
); |
1593
|
|
|
$form->addHidden('post_title_edited', 'false'); |
1594
|
|
|
$form->addHeader(get_lang('NewPost')); |
1595
|
|
|
$form->addText('title', get_lang('Title')); |
1596
|
|
|
$config = []; |
1597
|
|
|
$config['ToolbarSet'] = !api_is_allowed_to_edit() ? 'ProjectStudent' : 'Project'; |
1598
|
|
|
$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config); |
1599
|
|
|
$form->addFile('user_upload', get_lang('AddAnAttachment')); |
1600
|
|
|
$form->addTextarea('post_file_comment', get_lang('FileComment')); |
1601
|
|
|
$form->addHidden('new_post_submit', 'true'); |
1602
|
|
|
$form->addButton('save', get_lang('Save')); |
1603
|
|
|
|
1604
|
|
|
if ($form->validate()) { |
1605
|
|
|
$values = $form->exportValues(); |
1606
|
|
|
|
1607
|
|
|
$postId = self::createPost( |
1608
|
|
|
$values['title'], |
1609
|
|
|
$values['full_text'], |
1610
|
|
|
$values['post_file_comment'], |
1611
|
|
|
$blog_id |
1612
|
|
|
); |
1613
|
|
|
|
1614
|
|
|
if ($postId) { |
1615
|
|
|
Display::addFlash( |
1616
|
|
|
Display::return_message(get_lang('BlogAdded'), 'success') |
1617
|
|
|
); |
1618
|
|
|
|
1619
|
|
|
header('Location: '.api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
1620
|
|
|
'action' => 'view_post', |
1621
|
|
|
'blog_id' => $blog_id, |
1622
|
|
|
'post_id' => $postId, |
1623
|
|
|
])); |
1624
|
|
|
exit; |
1625
|
|
|
} |
1626
|
|
|
} |
1627
|
|
|
|
1628
|
|
|
return $form->returnForm(); |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
|
|
/** |
1632
|
|
|
* Displays the form to edit a post. |
1633
|
|
|
* |
1634
|
|
|
* @author Toon Keppens |
1635
|
|
|
* |
1636
|
|
|
* @param int $blog_id |
1637
|
|
|
* @param int $post_id |
1638
|
|
|
* |
1639
|
|
|
* @return string |
1640
|
|
|
*/ |
1641
|
|
|
public static function displayPostEditForm($blog_id, $post_id) |
1642
|
|
|
{ |
1643
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
1644
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
1645
|
|
|
|
1646
|
|
|
$course_id = api_get_course_int_id(); |
1647
|
|
|
$blog_id = intval($blog_id); |
1648
|
|
|
$post_id = intval($post_id); |
1649
|
|
|
|
1650
|
|
|
// Get posts and author |
1651
|
|
|
$sql = "SELECT post.*, user.lastname, user.firstname |
1652
|
|
|
FROM $tbl_blogs_posts post |
1653
|
|
|
INNER JOIN $tbl_users user ON post.author_id = user.user_id |
1654
|
|
|
WHERE |
1655
|
|
|
post.c_id = $course_id AND |
1656
|
|
|
post.blog_id = $blog_id |
1657
|
|
|
AND post.post_id = $post_id |
1658
|
|
|
ORDER BY post_id DESC"; |
1659
|
|
|
$result = Database::query($sql); |
1660
|
|
|
$blog_post = Database::fetch_array($result); |
1661
|
|
|
|
1662
|
|
|
// Form |
1663
|
|
|
$form = new FormValidator( |
1664
|
|
|
'edit_post', |
1665
|
|
|
'post', |
1666
|
|
|
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']) |
1667
|
|
|
); |
1668
|
|
|
|
1669
|
|
|
$form->addHeader(get_lang('EditPost')); |
1670
|
|
|
$form->addText('title', get_lang('Title')); |
1671
|
|
|
|
1672
|
|
|
if (!api_is_allowed_to_edit()) { |
1673
|
|
|
$config['ToolbarSet'] = 'ProjectStudent'; |
|
|
|
|
1674
|
|
|
} else { |
1675
|
|
|
$config['ToolbarSet'] = 'Project'; |
1676
|
|
|
} |
1677
|
|
|
$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config); |
1678
|
|
|
|
1679
|
|
|
$form->addHidden('action', ''); |
1680
|
|
|
$form->addHidden('edit_post_submit', 'true'); |
1681
|
|
|
$form->addHidden('post_id', intval($_GET['post_id'])); |
1682
|
|
|
$form->addButton('save', get_lang('Save')); |
1683
|
|
|
$form->setDefaults($blog_post); |
1684
|
|
|
|
1685
|
|
|
return $form->returnForm(); |
1686
|
|
|
} |
1687
|
|
|
|
1688
|
|
|
/** |
1689
|
|
|
* Displays a list of tasks in this blog. |
1690
|
|
|
* |
1691
|
|
|
* @author Toon Keppens |
1692
|
|
|
* |
1693
|
|
|
* @param int $blog_id |
1694
|
|
|
* |
1695
|
|
|
* @return string |
1696
|
|
|
*/ |
1697
|
|
|
public static function displayTasksList($blog_id) |
1698
|
|
|
{ |
1699
|
|
|
global $charset; |
1700
|
|
|
$course_id = api_get_course_int_id(); |
1701
|
|
|
$blog_id = intval($blog_id); |
1702
|
|
|
$html = ''; |
1703
|
|
|
if (api_is_allowed('BLOG_'.$blog_id, 'article_add')) { |
1704
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
1705
|
|
|
$counter = 0; |
1706
|
|
|
global $color2; |
1707
|
|
|
|
1708
|
|
|
$html .= '<div class="actions">'; |
1709
|
|
|
$html .= '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$blog_id.'&do=add&'.api_get_cidreq().'">'; |
1710
|
|
|
$html .= Display::return_icon('blog_newtasks.gif', get_lang('AddTasks')); |
1711
|
|
|
$html .= get_lang('AddTasks').'</a> '; |
1712
|
|
|
$html .= '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$blog_id.'&do=assign&'.api_get_cidreq().'">'; |
1713
|
|
|
$html .= Display::return_icon('blog_task.gif', get_lang('AssignTasks')); |
1714
|
|
|
$html .= get_lang('AssignTasks').'</a>'; |
1715
|
|
|
$html .= Display::url( |
1716
|
|
|
Display::return_icon('blog_admin_users.png', get_lang('RightsManager')), |
1717
|
|
|
api_get_self().'?'.http_build_query([ |
1718
|
|
|
'action' => 'manage_rights', |
1719
|
|
|
'blog_id' => $blog_id, |
1720
|
|
|
]), |
1721
|
|
|
['title' => get_lang('ManageRights')] |
1722
|
|
|
); |
1723
|
|
|
|
1724
|
|
|
$html .= '</div>'; |
1725
|
|
|
|
1726
|
|
|
$html .= '<span class="blogpost_title">'.get_lang('TaskList').'</span><br />'; |
1727
|
|
|
$html .= "<table class=\"data_table\">"; |
1728
|
|
|
$html .= "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">" |
1729
|
|
|
."<th width='240'><b>".get_lang('Title')."</b></th>" |
1730
|
|
|
."<th><b>".get_lang('Description')."</b></th>" |
1731
|
|
|
."<th><b>".get_lang('Color')."</b></th>" |
1732
|
|
|
."<th width='50'><b>".get_lang('Modify')."</b></th></tr>"; |
1733
|
|
|
|
1734
|
|
|
$sql = " SELECT |
1735
|
|
|
blog_id, |
1736
|
|
|
task_id, |
1737
|
|
|
blog_id, |
1738
|
|
|
title, |
1739
|
|
|
description, |
1740
|
|
|
color, |
1741
|
|
|
system_task |
1742
|
|
|
FROM $tbl_blogs_tasks |
1743
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id |
1744
|
|
|
ORDER BY system_task, title"; |
1745
|
|
|
$result = Database::query($sql); |
1746
|
|
|
|
1747
|
|
|
while ($task = Database::fetch_array($result)) { |
1748
|
|
|
$counter++; |
1749
|
|
|
$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even"; |
1750
|
|
|
$delete_icon = $task['system_task'] == '1' ? "delete_na.png" : "delete.png"; |
1751
|
|
|
$delete_title = $task['system_task'] == '1' ? get_lang('DeleteSystemTask') : get_lang('DeleteTask'); |
1752
|
|
|
$delete_link = $task['system_task'] == '1' ? '#' : api_get_self().'?action=manage_tasks&blog_id='.$task['blog_id'].'&do=delete&task_id='.$task['task_id'].'&'.api_get_cidreq(); |
1753
|
|
|
$delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes( |
1754
|
|
|
api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset) |
1755
|
|
|
).'\')) return false;"'; |
1756
|
|
|
|
1757
|
|
|
$html .= '<tr class="'.$css_class.'" valign="top">'; |
1758
|
|
|
$html .= '<td width="240">'.Security::remove_XSS($task['title']).'</td>'; |
1759
|
|
|
$html .= '<td>'.Security::remove_XSS($task['description']).'</td>'; |
1760
|
|
|
$html .= '<td><span style="background-color: #'.$task['color'].'"> </span></td>'; |
1761
|
|
|
$html .= '<td width="50">'; |
1762
|
|
|
$html .= '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$task['blog_id'].'&do=edit&task_id='.$task['task_id'].'&'.api_get_cidreq().'">'; |
1763
|
|
|
$html .= Display::return_icon('edit.png', get_lang('EditTask')); |
1764
|
|
|
$html .= "</a>"; |
1765
|
|
|
$html .= '<a href="'.$delete_link.'"'; |
1766
|
|
|
$html .= $delete_confirm; |
1767
|
|
|
$html .= '>'; |
1768
|
|
|
$html .= Display::return_icon($delete_icon, $delete_title); |
1769
|
|
|
$html .= "</a>"; |
1770
|
|
|
$html .= '</td>'; |
1771
|
|
|
$html .= '</tr>'; |
1772
|
|
|
} |
1773
|
|
|
$html .= "</table>"; |
1774
|
|
|
} |
1775
|
|
|
|
1776
|
|
|
return $html; |
1777
|
|
|
} |
1778
|
|
|
|
1779
|
|
|
/** |
1780
|
|
|
* Displays a list of tasks assigned to a user in this blog. |
1781
|
|
|
* |
1782
|
|
|
* @author Toon Keppens |
1783
|
|
|
* |
1784
|
|
|
* @param int $blog_id |
1785
|
|
|
* |
1786
|
|
|
* @return string |
1787
|
|
|
*/ |
1788
|
|
|
public static function displayAssignedTasksList($blog_id) |
1789
|
|
|
{ |
1790
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
1791
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
1792
|
|
|
$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
1793
|
|
|
$counter = 0; |
1794
|
|
|
global $charset, $color2; |
1795
|
|
|
|
1796
|
|
|
$return = '<span class="blogpost_title">'.get_lang('AssignedTasks').'</span><br />'; |
1797
|
|
|
$return .= "<table class=\"data_table\">"; |
1798
|
|
|
$return .= "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">" |
1799
|
|
|
."<th width='240'><b>".get_lang('Member')."</b></th>" |
1800
|
|
|
."<th><b>".get_lang('Task')."</b></th>" |
1801
|
|
|
."<th><b>".get_lang('Description')."</b></th>" |
1802
|
|
|
."<th><b>".get_lang('TargetDate')."</b></th>" |
1803
|
|
|
."<th width='50'><b>".get_lang('Modify')."</b></th>" |
1804
|
|
|
."</tr>"; |
1805
|
|
|
|
1806
|
|
|
$course_id = api_get_course_int_id(); |
1807
|
|
|
$blog_id = intval($blog_id); |
1808
|
|
|
|
1809
|
|
|
$sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id |
1810
|
|
|
FROM $tbl_blogs_tasks_rel_user task_rel_user |
1811
|
|
|
INNER JOIN $tbl_blogs_tasks task |
1812
|
|
|
ON task_rel_user.task_id = task.task_id |
1813
|
|
|
INNER JOIN $tbl_users user |
1814
|
|
|
ON task_rel_user.user_id = user.user_id |
1815
|
|
|
WHERE |
1816
|
|
|
task_rel_user.c_id = $course_id AND |
1817
|
|
|
task.c_id = $course_id AND |
1818
|
|
|
task_rel_user.blog_id = $blog_id |
1819
|
|
|
ORDER BY target_date ASC"; |
1820
|
|
|
$result = Database::query($sql); |
1821
|
|
|
|
1822
|
|
|
while ($assignment = Database::fetch_array($result)) { |
1823
|
|
|
$counter++; |
1824
|
|
|
$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even"; |
1825
|
|
|
$delete_icon = ($assignment['system_task'] == '1') ? "delete_na.png" : "delete.png"; |
1826
|
|
|
$delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask'); |
1827
|
|
|
$delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=delete&task_id='.$assignment['task_id'].'&'.api_get_cidreq(); |
1828
|
|
|
$delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes( |
1829
|
|
|
api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset) |
1830
|
|
|
).'\')) return false;"'; |
1831
|
|
|
|
1832
|
|
|
$username = api_htmlentities(sprintf(get_lang('LoginX'), $assignment['username']), ENT_QUOTES); |
1833
|
|
|
|
1834
|
|
|
$return .= '<tr class="'.$css_class.'" valign="top">'; |
1835
|
|
|
$return .= '<td width="240">'.Display::tag( |
1836
|
|
|
'span', |
1837
|
|
|
api_get_person_name($assignment['firstname'], $assignment['lastname']), |
1838
|
|
|
['title' => $username] |
1839
|
|
|
).'</td>'; |
1840
|
|
|
$return .= '<td>'.stripslashes($assignment['title']).'</td>'; |
1841
|
|
|
$return .= '<td>'.stripslashes($assignment['description']).'</td>'; |
1842
|
|
|
$return .= '<td>'.$assignment['target_date'].'</td>'; |
1843
|
|
|
$return .= '<td width="50">'; |
1844
|
|
|
$return .= '<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'].'&'.api_get_cidreq().'">'; |
1845
|
|
|
$return .= Display::return_icon('edit.png', get_lang('EditTask')); |
1846
|
|
|
$return .= "</a>"; |
1847
|
|
|
$return .= '<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'].'&'.api_get_cidreq().'" '; |
1848
|
|
|
$return .= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"'; |
1849
|
|
|
$return .= Display::return_icon($delete_icon, $delete_title); |
1850
|
|
|
$return .= "</a>"; |
1851
|
|
|
$return .= '</td>'; |
1852
|
|
|
$return .= '</tr>'; |
1853
|
|
|
} |
1854
|
|
|
$return .= "</table>"; |
1855
|
|
|
|
1856
|
|
|
return $return; |
1857
|
|
|
} |
1858
|
|
|
|
1859
|
|
|
/** |
1860
|
|
|
* Displays new task form. |
1861
|
|
|
* |
1862
|
|
|
* @todo use FormValidator |
1863
|
|
|
* |
1864
|
|
|
* @author Toon Keppens |
1865
|
|
|
* |
1866
|
|
|
* @param int $blog_id |
1867
|
|
|
* |
1868
|
|
|
* @return string HTML form |
1869
|
|
|
*/ |
1870
|
|
|
public static function displayTaskCreateForm($blog_id) |
1871
|
|
|
{ |
1872
|
|
|
$blog_id = intval($blog_id); |
1873
|
|
|
// Init |
1874
|
|
|
$colors = [ |
1875
|
|
|
'FFFFFF', |
1876
|
|
|
'FFFF99', |
1877
|
|
|
'FFCC99', |
1878
|
|
|
'FF9933', |
1879
|
|
|
'FF6699', |
1880
|
|
|
'CCFF99', |
1881
|
|
|
'CC9966', |
1882
|
|
|
'66FF00', |
1883
|
|
|
'9966FF', |
1884
|
|
|
'CF3F3F', |
1885
|
|
|
'990033', |
1886
|
|
|
'669933', |
1887
|
|
|
'0033FF', |
1888
|
|
|
'003366', |
1889
|
|
|
'000000', |
1890
|
|
|
]; |
1891
|
|
|
|
1892
|
|
|
// form |
1893
|
|
|
$return = '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id='.$blog_id.'">'; |
1894
|
|
|
|
1895
|
|
|
// form title |
1896
|
|
|
$return .= '<legend>'.get_lang('AddTask').'</legend>'; |
1897
|
|
|
|
1898
|
|
|
// task title |
1899
|
|
|
$return .= ' <div class="control-group"> |
1900
|
|
|
<label class="control-label"> |
1901
|
|
|
<span class="form_required">*</span>'.get_lang('Title').' |
1902
|
|
|
</label> |
1903
|
|
|
<div class="controls"> |
1904
|
|
|
<input name="task_name" type="text" size="70" /> |
1905
|
|
|
</div> |
1906
|
|
|
</div>'; |
1907
|
|
|
|
1908
|
|
|
// task comment |
1909
|
|
|
$return .= ' <div class="control-group"> |
1910
|
|
|
<label class="control-label"> |
1911
|
|
|
'.get_lang('Description').' |
1912
|
|
|
</label> |
1913
|
|
|
<div class="controls"> |
1914
|
|
|
<textarea name="task_description" cols="45"></textarea> |
1915
|
|
|
</div> |
1916
|
|
|
</div>'; |
1917
|
|
|
|
1918
|
|
|
// task management |
1919
|
|
|
$return .= ' <div class="control-group"> |
1920
|
|
|
<label class="control-label"> |
1921
|
|
|
'.get_lang('TaskManager').' |
1922
|
|
|
</label> |
1923
|
|
|
<div class="controls">'; |
1924
|
|
|
$return .= '<table class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">'; |
1925
|
|
|
$return .= '<tr>'; |
1926
|
|
|
$return .= '<th colspan="2" style="width:223px;">'.get_lang('ArticleManager').'</th>'; |
1927
|
|
|
$return .= '<th width:223px;>'.get_lang('CommentManager').'</th>'; |
1928
|
|
|
$return .= '</tr>'; |
1929
|
|
|
$return .= '<tr>'; |
1930
|
|
|
$return .= '<th style="width:111px;"><label for="articleDelete">'.get_lang('Delete').'</label></th>'; |
1931
|
|
|
$return .= '<th style="width:112px;"><label for="articleEdit">'.get_lang('Edit').'</label></th>'; |
1932
|
|
|
$return .= '<th style="width:223px;"><label for="commentsDelete">'.get_lang('Delete').'</label></th>'; |
1933
|
|
|
$return .= '</tr>'; |
1934
|
|
|
$return .= '<tr>'; |
1935
|
|
|
$return .= '<td style="text-align:center;"><input id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>'; |
1936
|
|
|
$return .= '<td style="text-align:center;"><input id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>'; |
1937
|
|
|
$return .= '<td style="border:1px dotted #808080; text-align:center;"><input id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>'; |
1938
|
|
|
$return .= '</tr>'; |
1939
|
|
|
$return .= '</table>'; |
1940
|
|
|
$return .= ' </div> |
1941
|
|
|
</div>'; |
1942
|
|
|
|
1943
|
|
|
// task color |
1944
|
|
|
$return .= ' <div class="control-group"> |
1945
|
|
|
<label class="control-label"> |
1946
|
|
|
'.get_lang('Color').' |
1947
|
|
|
</label> |
1948
|
|
|
<div class="controls">'; |
1949
|
|
|
$return .= '<select name="task_color" id="color" style="width: 150px; background-color: #eeeeee" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">'; |
1950
|
|
|
foreach ($colors as $color) { |
1951
|
|
|
$style = 'style="background-color: #'.$color.'"'; |
1952
|
|
|
$return .= '<option value="'.$color.'" '.$style.'> </option>'; |
1953
|
|
|
} |
1954
|
|
|
$return .= '</select>'; |
1955
|
|
|
$return .= ' </div> |
1956
|
|
|
</div>'; |
1957
|
|
|
|
1958
|
|
|
// submit |
1959
|
|
|
$return .= ' <div class="control-group"> |
1960
|
|
|
<div class="controls"> |
1961
|
|
|
<input type="hidden" name="action" value="" /> |
1962
|
|
|
<input type="hidden" name="new_task_submit" value="true" /> |
1963
|
|
|
<button class="save" type="submit" name="Submit">'.get_lang('Save').'</button> |
1964
|
|
|
</div> |
1965
|
|
|
</div>'; |
1966
|
|
|
$return .= '</form>'; |
1967
|
|
|
|
1968
|
|
|
$return .= '<div style="clear:both; margin-bottom: 10px;"></div>'; |
1969
|
|
|
|
1970
|
|
|
return $return; |
1971
|
|
|
} |
1972
|
|
|
|
1973
|
|
|
/** |
1974
|
|
|
* Displays edit task form. |
1975
|
|
|
* |
1976
|
|
|
* @author Toon Keppens |
1977
|
|
|
* |
1978
|
|
|
* @param int $blog_id |
1979
|
|
|
* @param int $task_id |
1980
|
|
|
* |
1981
|
|
|
* @return string |
1982
|
|
|
*/ |
1983
|
|
|
public static function displayTaskEditForm($blog_id, $task_id) |
1984
|
|
|
{ |
1985
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
1986
|
|
|
$course_id = api_get_course_int_id(); |
1987
|
|
|
$blog_id = intval($blog_id); |
1988
|
|
|
$task_id = intval($task_id); |
1989
|
|
|
|
1990
|
|
|
$colors = [ |
1991
|
|
|
'FFFFFF', |
1992
|
|
|
'FFFF99', |
1993
|
|
|
'FFCC99', |
1994
|
|
|
'FF9933', |
1995
|
|
|
'FF6699', |
1996
|
|
|
'CCFF99', |
1997
|
|
|
'CC9966', |
1998
|
|
|
'66FF00', |
1999
|
|
|
'9966FF', |
2000
|
|
|
'CF3F3F', |
2001
|
|
|
'990033', |
2002
|
|
|
'669933', |
2003
|
|
|
'0033FF', |
2004
|
|
|
'003366', |
2005
|
|
|
'000000', |
2006
|
|
|
]; |
2007
|
|
|
|
2008
|
|
|
$sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks |
2009
|
|
|
WHERE c_id = $course_id AND task_id = $task_id"; |
2010
|
|
|
$result = Database::query($sql); |
2011
|
|
|
$task = Database::fetch_array($result); |
2012
|
|
|
|
2013
|
|
|
// Display |
2014
|
|
|
$return = '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id='.$blog_id.'"> |
2015
|
|
|
<legend>'.get_lang('EditTask').'</legend> |
2016
|
|
|
<table width="100%" border="0" cellspacing="2"> |
2017
|
|
|
<tr> |
2018
|
|
|
<td align="right">'.get_lang('Title').': </td> |
2019
|
|
|
<td><input name="task_name" type="text" size="70" value="'.Security::remove_XSS($task['title']).'" /></td> |
2020
|
|
|
</tr> |
2021
|
|
|
<tr> |
2022
|
|
|
<td align="right">'.get_lang('Description').': </td> |
2023
|
|
|
<td><textarea name="task_description" cols="45">'.Security::remove_XSS($task['description']).'</textarea></td> |
2024
|
|
|
</tr>'; |
2025
|
|
|
|
2026
|
|
|
/* edit by Kevin Van Den Haute ([email protected]) */ |
2027
|
|
|
$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS); |
2028
|
|
|
|
2029
|
|
|
$sql = "SELECT id, action FROM $tbl_tasks_permissions |
2030
|
|
|
WHERE c_id = $course_id AND task_id = $task_id"; |
2031
|
|
|
$result = Database::query($sql); |
2032
|
|
|
|
2033
|
|
|
$arrPermissions = []; |
2034
|
|
|
|
2035
|
|
|
while ($row = Database::fetch_array($result)) { |
2036
|
|
|
$arrPermissions[] = $row['action']; |
2037
|
|
|
} |
2038
|
|
|
|
2039
|
|
|
$return .= '<tr>'; |
2040
|
|
|
$return .= '<td style="text-align:right; vertical-align:top;">'.get_lang('TaskManager').': </td>'; |
2041
|
|
|
$return .= '<td>'; |
2042
|
|
|
$return .= '<table class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">'; |
2043
|
|
|
$return .= '<tr>'; |
2044
|
|
|
$return .= '<th colspan="2" style="width:223px;">'.get_lang('ArticleManager').'</th>'; |
2045
|
|
|
$return .= '<th width:223px;>'.get_lang('CommentManager').'</th>'; |
2046
|
|
|
$return .= '</tr>'; |
2047
|
|
|
$return .= '<tr>'; |
2048
|
|
|
$return .= '<th style="width:111px;"><label for="articleDelete">'.get_lang('Delete').'</label></th>'; |
2049
|
|
|
$return .= '<th style="width:112px;"><label for="articleEdit">'.get_lang('Edit').'</label></th>'; |
2050
|
|
|
$return .= '<th style="width:223px;"><label for="commentsDelete">'.get_lang('Delete').'</label></th>'; |
2051
|
|
|
$return .= '</tr>'; |
2052
|
|
|
$return .= '<tr>'; |
2053
|
|
|
$return .= '<td style="text-align:center;"><input '.((in_array( |
2054
|
|
|
'article_delete', |
2055
|
|
|
$arrPermissions |
2056
|
|
|
)) ? 'checked ' : '').'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>'; |
2057
|
|
|
$return .= '<td style="text-align:center;"><input '.((in_array( |
2058
|
|
|
'article_edit', |
2059
|
|
|
$arrPermissions |
2060
|
|
|
)) ? 'checked ' : '').'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>'; |
2061
|
|
|
$return .= '<td style="text-align:center;"><input '.((in_array( |
2062
|
|
|
'article_comments_delete', |
2063
|
|
|
$arrPermissions |
2064
|
|
|
)) ? 'checked ' : '').'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>'; |
2065
|
|
|
$return .= '</tr>'; |
2066
|
|
|
$return .= '</table>'; |
2067
|
|
|
$return .= '</td>'; |
2068
|
|
|
$return .= '</tr>'; |
2069
|
|
|
/* end of edit */ |
2070
|
|
|
|
2071
|
|
|
$return .= '<tr> |
2072
|
|
|
<td align="right">'.get_lang('Color').': </td> |
2073
|
|
|
<td> |
2074
|
|
|
<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">'; |
2075
|
|
|
foreach ($colors as $color) { |
2076
|
|
|
$selected = ($color == $task['color']) ? ' selected' : ''; |
2077
|
|
|
$style = 'style="background-color: #'.$color.'"'; |
2078
|
|
|
$return .= '<option value="'.$color.'" '.$style.' '.$selected.' > </option>'; |
2079
|
|
|
} |
2080
|
|
|
$return .= '</select> |
2081
|
|
|
</td> |
2082
|
|
|
</tr> |
2083
|
|
|
<tr> |
2084
|
|
|
<td align="right"> </td> |
2085
|
|
|
<td><br /><input type="hidden" name="action" value="" /> |
2086
|
|
|
<input type="hidden" name="edit_task_submit" value="true" /> |
2087
|
|
|
<input type="hidden" name="task_id" value="'.$task['task_id'].'" /> |
2088
|
|
|
<input type="hidden" name="blog_id" value="'.$task['blog_id'].'" /> |
2089
|
|
|
<button class="save" type="submit" name="Submit">'.get_lang('Save').'</button></td> |
2090
|
|
|
</tr> |
2091
|
|
|
</table> |
2092
|
|
|
</form>'; |
2093
|
|
|
|
2094
|
|
|
return $return; |
2095
|
|
|
} |
2096
|
|
|
|
2097
|
|
|
/** |
2098
|
|
|
* Displays assign task form. |
2099
|
|
|
* |
2100
|
|
|
* @author Toon Keppens |
2101
|
|
|
*/ |
2102
|
|
|
public static function displayTaskAssignmentForm($blog_id) |
2103
|
|
|
{ |
2104
|
|
|
$form = self::getTaskAssignmentForm($blog_id); |
2105
|
|
|
$form->addHidden('assign_task_submit', 'true'); |
2106
|
|
|
|
2107
|
|
|
return $form->returnForm() |
2108
|
|
|
.PHP_EOL |
2109
|
|
|
.'<div style="clear: both; margin-bottom:10px;"></div>'; |
2110
|
|
|
} |
2111
|
|
|
|
2112
|
|
|
/** |
2113
|
|
|
* Returns an HTML form to assign a task. |
2114
|
|
|
* |
2115
|
|
|
* @param $blog_id |
2116
|
|
|
* |
2117
|
|
|
* @return FormValidator |
2118
|
|
|
*/ |
2119
|
|
|
public static function getTaskAssignmentForm($blog_id) |
2120
|
|
|
{ |
2121
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
2122
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
2123
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
2124
|
|
|
$course_id = api_get_course_int_id(); |
2125
|
|
|
$blog_id = intval($blog_id); |
2126
|
|
|
|
2127
|
|
|
// Get users in this blog / make select list of it |
2128
|
|
|
$sql = "SELECT user.user_id, user.firstname, user.lastname, user.username |
2129
|
|
|
FROM $tbl_users user |
2130
|
|
|
INNER JOIN $tbl_blogs_rel_user blogs_rel_user |
2131
|
|
|
ON user.user_id = blogs_rel_user.user_id |
2132
|
|
|
WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = $blog_id"; |
2133
|
|
|
$result = Database::query($sql); |
2134
|
|
|
|
2135
|
|
|
$options = []; |
2136
|
|
|
while ($user = Database::fetch_array($result)) { |
2137
|
|
|
$options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']); |
2138
|
|
|
} |
2139
|
|
|
|
2140
|
|
|
// Get tasks in this blog / make select list of it |
2141
|
|
|
$sql = "SELECT |
2142
|
|
|
blog_id, |
2143
|
|
|
task_id, |
2144
|
|
|
blog_id, |
2145
|
|
|
title, |
2146
|
|
|
description, |
2147
|
|
|
color, |
2148
|
|
|
system_task |
2149
|
|
|
FROM $tbl_blogs_tasks |
2150
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id |
2151
|
|
|
ORDER BY system_task, title"; |
2152
|
|
|
$result = Database::query($sql); |
2153
|
|
|
|
2154
|
|
|
$taskOptions = []; |
2155
|
|
|
while ($task = Database::fetch_array($result)) { |
2156
|
|
|
$taskOptions[$task['task_id']] = stripslashes($task['title']); |
2157
|
|
|
} |
2158
|
|
|
|
2159
|
|
|
$form = new FormValidator( |
2160
|
|
|
'assign_task', |
2161
|
|
|
'post', |
2162
|
|
|
api_get_path( |
2163
|
|
|
WEB_CODE_PATH |
2164
|
|
|
).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id |
2165
|
|
|
); |
2166
|
|
|
|
2167
|
|
|
$form->addHeader(get_lang('AssignTask')); |
2168
|
|
|
$form->addSelect('task_user_id', get_lang('SelectUser'), $options); |
2169
|
|
|
$form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions); |
2170
|
|
|
$form->addDatePicker('task_day', get_lang('SelectTargetDate')); |
2171
|
|
|
|
2172
|
|
|
$form->addHidden('action', ''); |
2173
|
|
|
$form->addButtonSave(get_lang('Ok')); |
2174
|
|
|
|
2175
|
|
|
return $form; |
2176
|
|
|
} |
2177
|
|
|
|
2178
|
|
|
/** |
2179
|
|
|
* Displays assign task form. |
2180
|
|
|
* |
2181
|
|
|
* @author Toon Keppens |
2182
|
|
|
* |
2183
|
|
|
* @param int $blog_id |
2184
|
|
|
* @param int $task_id |
2185
|
|
|
* @param int $user_id |
2186
|
|
|
* |
2187
|
|
|
* @return string HTML form |
2188
|
|
|
*/ |
2189
|
|
|
public static function displayAssignedTaskEditForm($blog_id, $task_id, $user_id) |
2190
|
|
|
{ |
2191
|
|
|
$table = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
2192
|
|
|
|
2193
|
|
|
$course_id = api_get_course_int_id(); |
2194
|
|
|
$blog_id = intval($blog_id); |
2195
|
|
|
$task_id = intval($task_id); |
2196
|
|
|
$user_id = intval($user_id); |
2197
|
|
|
|
2198
|
|
|
// Get assign date; |
2199
|
|
|
$sql = " |
2200
|
|
|
SELECT target_date |
2201
|
|
|
FROM $table |
2202
|
|
|
WHERE c_id = $course_id AND |
2203
|
|
|
blog_id = $blog_id AND |
2204
|
|
|
user_id = $user_id AND |
2205
|
|
|
task_id = $task_id"; |
2206
|
|
|
$result = Database::query($sql); |
2207
|
|
|
$row = Database::fetch_assoc($result); |
2208
|
|
|
|
2209
|
|
|
$date = $row['target_date']; |
2210
|
|
|
|
2211
|
|
|
$defaults = [ |
2212
|
|
|
'task_user_id' => $user_id, |
2213
|
|
|
'task_task_id' => $task_id, |
2214
|
|
|
'task_day' => $date, |
2215
|
|
|
]; |
2216
|
|
|
$form = self::getTaskAssignmentForm($blog_id); |
2217
|
|
|
$form->addHidden('old_task_id', $task_id); |
2218
|
|
|
$form->addHidden('old_user_id', $user_id); |
2219
|
|
|
$form->addHidden('old_target_date', $date); |
2220
|
|
|
$form->addHidden('assign_task_edit_submit', 'true'); |
2221
|
|
|
$form->setDefaults($defaults); |
2222
|
|
|
|
2223
|
|
|
return $form->returnForm(); |
2224
|
|
|
} |
2225
|
|
|
|
2226
|
|
|
/** |
2227
|
|
|
* Assigns a task to a user in a blog. |
2228
|
|
|
* |
2229
|
|
|
* @param int $blog_id |
2230
|
|
|
* @param int $user_id |
2231
|
|
|
* @param int $task_id |
2232
|
|
|
* @param string $target_date date |
2233
|
|
|
*/ |
2234
|
|
|
public static function assignTask($blog_id, $user_id, $task_id, $target_date) |
2235
|
|
|
{ |
2236
|
|
|
$table = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
2237
|
|
|
$course_id = api_get_course_int_id(); |
2238
|
|
|
$blog_id = intval($blog_id); |
2239
|
|
|
$user_id = intval($user_id); |
2240
|
|
|
$task_id = intval($task_id); |
2241
|
|
|
$target_date = Database::escape_string($target_date); |
2242
|
|
|
|
2243
|
|
|
$sql = " |
2244
|
|
|
SELECT COUNT(*) as 'number' |
2245
|
|
|
FROM $table |
2246
|
|
|
WHERE c_id = $course_id |
2247
|
|
|
AND blog_id = $blog_id |
2248
|
|
|
AND user_id = $user_id |
2249
|
|
|
AND task_id = $task_id"; |
2250
|
|
|
|
2251
|
|
|
$result = Database::query($sql); |
2252
|
|
|
$row = Database::fetch_assoc($result); |
2253
|
|
|
|
2254
|
|
|
if ($row['number'] == 0) { |
2255
|
|
|
$sql = " |
2256
|
|
|
INSERT INTO ".$table." ( |
2257
|
|
|
c_id, |
2258
|
|
|
blog_id, |
2259
|
|
|
user_id, |
2260
|
|
|
task_id, |
2261
|
|
|
target_date |
2262
|
|
|
) VALUES ( |
2263
|
|
|
$course_id, |
2264
|
|
|
$blog_id, |
2265
|
|
|
$user_id, |
2266
|
|
|
$task_id, |
2267
|
|
|
'$target_date' |
2268
|
|
|
)"; |
2269
|
|
|
|
2270
|
|
|
Database::query($sql); |
2271
|
|
|
} |
2272
|
|
|
} |
2273
|
|
|
|
2274
|
|
|
/** |
2275
|
|
|
* Edit an assigned task. |
2276
|
|
|
* |
2277
|
|
|
* @param $blog_id |
2278
|
|
|
* @param $user_id |
2279
|
|
|
* @param $task_id |
2280
|
|
|
* @param $target_date |
2281
|
|
|
* @param $old_user_id |
2282
|
|
|
* @param $old_task_id |
2283
|
|
|
* @param $old_target_date |
2284
|
|
|
*/ |
2285
|
|
|
public static function updateAssignedTask( |
2286
|
|
|
$blog_id, |
2287
|
|
|
$user_id, |
2288
|
|
|
$task_id, |
2289
|
|
|
$target_date, |
2290
|
|
|
$old_user_id, |
2291
|
|
|
$old_task_id, |
2292
|
|
|
$old_target_date |
2293
|
|
|
) { |
2294
|
|
|
$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
2295
|
|
|
|
2296
|
|
|
$course_id = api_get_course_int_id(); |
2297
|
|
|
$blog_id = intval($blog_id); |
2298
|
|
|
$user_id = intval($user_id); |
2299
|
|
|
$task_id = intval($task_id); |
2300
|
|
|
$target_date = Database::escape_string($target_date); |
2301
|
|
|
$old_user_id = intval($old_user_id); |
2302
|
|
|
$old_task_id = intval($old_task_id); |
2303
|
|
|
$old_target_date = Database::escape_string($old_target_date); |
2304
|
|
|
|
2305
|
|
|
$sql = "SELECT COUNT(*) as 'number' |
2306
|
|
|
FROM $tbl_blogs_tasks_rel_user |
2307
|
|
|
WHERE |
2308
|
|
|
c_id = $course_id AND |
2309
|
|
|
blog_id = $blog_id AND |
2310
|
|
|
user_id = $user_id AND |
2311
|
|
|
task_id = $task_id"; |
2312
|
|
|
|
2313
|
|
|
$result = Database::query($sql); |
2314
|
|
|
$row = Database::fetch_assoc($result); |
2315
|
|
|
|
2316
|
|
|
if ($row['number'] == 0 || |
2317
|
|
|
($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id) |
2318
|
|
|
) { |
2319
|
|
|
$sql = "UPDATE $tbl_blogs_tasks_rel_user |
2320
|
|
|
SET |
2321
|
|
|
user_id = $user_id, |
2322
|
|
|
task_id = $task_id, |
2323
|
|
|
target_date = '$target_date' |
2324
|
|
|
WHERE |
2325
|
|
|
c_id = $course_id AND |
2326
|
|
|
blog_id = $blog_id AND |
2327
|
|
|
user_id = $old_user_id AND |
2328
|
|
|
task_id = $old_task_id AND |
2329
|
|
|
target_date = '$old_target_date' |
2330
|
|
|
"; |
2331
|
|
|
Database::query($sql); |
2332
|
|
|
} |
2333
|
|
|
} |
2334
|
|
|
|
2335
|
|
|
/** |
2336
|
|
|
* Displays a list with posts a user can select to execute his task. |
2337
|
|
|
* |
2338
|
|
|
* @param int $blog_id |
2339
|
|
|
* @param int $task_id |
2340
|
|
|
* |
2341
|
|
|
* @return string |
2342
|
|
|
*/ |
2343
|
|
|
public static function displayPostSelectionForTask($blog_id, $task_id) |
2344
|
|
|
{ |
2345
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
2346
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
2347
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
2348
|
|
|
$course_id = api_get_course_int_id(); |
2349
|
|
|
$blog_id = intval($blog_id); |
2350
|
|
|
$task_id = intval($task_id); |
2351
|
|
|
|
2352
|
|
|
$sql = "SELECT title, description FROM $tbl_blogs_tasks |
2353
|
|
|
WHERE task_id = $task_id |
2354
|
|
|
AND c_id = $course_id"; |
2355
|
|
|
$result = Database::query($sql); |
2356
|
|
|
$row = Database::fetch_assoc($result); |
2357
|
|
|
// Get posts and authors |
2358
|
|
|
$sql = "SELECT post.*, user.lastname, user.firstname, user.username |
2359
|
|
|
FROM $tbl_blogs_posts post |
2360
|
|
|
INNER JOIN $tbl_users user ON post.author_id = user.user_id |
2361
|
|
|
WHERE post.blog_id = $blog_id AND post.c_id = $course_id |
2362
|
|
|
ORDER BY post_id DESC |
2363
|
|
|
LIMIT 0, 100"; |
2364
|
|
|
$result = Database::query($sql); |
2365
|
|
|
|
2366
|
|
|
// Display |
2367
|
|
|
$return = '<span class="blogpost_title">'.get_lang('SelectTaskArticle').' "'.stripslashes($row['title']).'"</span>'; |
2368
|
|
|
$return .= '<span style="font-style: italic;"">'.stripslashes($row['description']).'</span><br><br>'; |
2369
|
|
|
|
2370
|
|
|
if (Database::num_rows($result) == 0) { |
2371
|
|
|
$return .= get_lang('NoArticles'); |
2372
|
|
|
|
2373
|
|
|
return $return; |
2374
|
|
|
} |
2375
|
|
|
|
2376
|
|
|
while ($blog_post = Database::fetch_array($result)) { |
2377
|
|
|
$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES); |
2378
|
|
|
$return .= '<a href="blog.php?action=execute_task&blog_id='.$blog_id.'&task_id='.$task_id.'&post_id='.$blog_post['post_id'].'#add_comment">'.stripslashes( |
2379
|
|
|
$blog_post['title'] |
2380
|
|
|
).'</a>, '.get_lang('WrittenBy').' '.stripslashes( |
2381
|
|
|
Display::tag( |
2382
|
|
|
'span', |
2383
|
|
|
api_get_person_name($blog_post['firstname'], $blog_post['lastname']), |
2384
|
|
|
['title' => $username] |
2385
|
|
|
) |
2386
|
|
|
).'<br />'; |
2387
|
|
|
} |
2388
|
|
|
|
2389
|
|
|
return $return; |
2390
|
|
|
} |
2391
|
|
|
|
2392
|
|
|
/** |
2393
|
|
|
* Unsubscribe a user from a given blog. |
2394
|
|
|
* |
2395
|
|
|
* @author Toon Keppens |
2396
|
|
|
* |
2397
|
|
|
* @param int $blog_id |
2398
|
|
|
* @param int $user_id |
2399
|
|
|
*/ |
2400
|
|
|
public static function unsubscribeUser($blog_id, $user_id) |
2401
|
|
|
{ |
2402
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
2403
|
|
|
$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER); |
2404
|
|
|
$blog_id = intval($blog_id); |
2405
|
|
|
$user_id = intval($user_id); |
2406
|
|
|
|
2407
|
|
|
// Unsubscribe the user |
2408
|
|
|
$sql = "DELETE FROM $tbl_blogs_rel_user |
2409
|
|
|
WHERE blog_id = $blog_id AND user_id = $user_id"; |
2410
|
|
|
Database::query($sql); |
2411
|
|
|
|
2412
|
|
|
// Remove this user's permissions. |
2413
|
|
|
$sql = "DELETE FROM $tbl_user_permissions |
2414
|
|
|
WHERE user_id = $user_id"; |
2415
|
|
|
Database::query($sql); |
2416
|
|
|
} |
2417
|
|
|
|
2418
|
|
|
/** |
2419
|
|
|
* Displays the form to register users in a blog (in a course) |
2420
|
|
|
* The listed users are users subscribed in the course. |
2421
|
|
|
* |
2422
|
|
|
* @author Toon Keppens |
2423
|
|
|
* |
2424
|
|
|
* @param int $blog_id |
2425
|
|
|
* |
2426
|
|
|
* @return string html Form with sortable table with users to subcribe in a blog, in a course |
2427
|
|
|
*/ |
2428
|
|
|
public static function displayUserSubscriptionForm($blog_id) |
2429
|
|
|
{ |
2430
|
|
|
$_course = api_get_course_info(); |
2431
|
|
|
$is_western_name_order = api_is_western_name_order(); |
2432
|
|
|
$session_id = api_get_session_id(); |
2433
|
|
|
$course_id = $_course['real_id']; |
2434
|
|
|
$blog_id = intval($blog_id); |
2435
|
|
|
|
2436
|
|
|
$currentCourse = $_course['code']; |
2437
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
2438
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
2439
|
|
|
$html = null; |
2440
|
|
|
|
2441
|
|
|
$html .= '<legend>'.get_lang('SubscribeMembers').'</legend>'; |
2442
|
|
|
|
2443
|
|
|
$properties['width'] = '100%'; |
|
|
|
|
2444
|
|
|
|
2445
|
|
|
// Get blog members' id. |
2446
|
|
|
$sql = "SELECT user.user_id FROM $tbl_users user |
2447
|
|
|
INNER JOIN $tbl_blogs_rel_user blogs_rel_user |
2448
|
|
|
ON user.user_id = blogs_rel_user.user_id |
2449
|
|
|
WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = $blog_id"; |
2450
|
|
|
$result = Database::query($sql); |
2451
|
|
|
|
2452
|
|
|
$blog_member_ids = []; |
2453
|
|
|
while ($user = Database::fetch_array($result)) { |
2454
|
|
|
$blog_member_ids[] = $user['user_id']; |
2455
|
|
|
} |
2456
|
|
|
|
2457
|
|
|
// Set table headers |
2458
|
|
|
$column_header[] = ['', false, '']; |
|
|
|
|
2459
|
|
|
if ($is_western_name_order) { |
2460
|
|
|
$column_header[] = [get_lang('FirstName'), true, '']; |
2461
|
|
|
$column_header[] = [get_lang('LastName'), true, '']; |
2462
|
|
|
} else { |
2463
|
|
|
$column_header[] = [get_lang('LastName'), true, '']; |
2464
|
|
|
$column_header[] = [get_lang('FirstName'), true, '']; |
2465
|
|
|
} |
2466
|
|
|
$column_header[] = [get_lang('Email'), false, '']; |
2467
|
|
|
$column_header[] = [get_lang('Register'), false, '']; |
2468
|
|
|
|
2469
|
|
|
$student_list = CourseManager:: get_student_list_from_course_code( |
2470
|
|
|
$currentCourse, |
2471
|
|
|
false, |
2472
|
|
|
$session_id |
2473
|
|
|
); |
2474
|
|
|
$user_data = []; |
2475
|
|
|
|
2476
|
|
|
// Add users that are not in this blog to the list. |
2477
|
|
|
foreach ($student_list as $key => $user) { |
2478
|
|
|
if (isset($user['id_user'])) { |
2479
|
|
|
$user['user_id'] = $user['id_user']; |
2480
|
|
|
} |
2481
|
|
|
if (!in_array($user['user_id'], $blog_member_ids)) { |
2482
|
|
|
$a_infosUser = api_get_user_info($user['user_id']); |
2483
|
|
|
$row = []; |
2484
|
|
|
$row[] = '<input type="checkbox" name="user[]" value="'.$a_infosUser['user_id'].'" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '').'/>'; |
2485
|
|
|
$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES); |
2486
|
|
|
if ($is_western_name_order) { |
2487
|
|
|
$row[] = $a_infosUser["firstname"]; |
2488
|
|
|
$row[] = Display::tag( |
2489
|
|
|
'span', |
2490
|
|
|
$a_infosUser["lastname"], |
2491
|
|
|
['title' => $username] |
2492
|
|
|
); |
2493
|
|
|
} else { |
2494
|
|
|
$row[] = Display::tag( |
2495
|
|
|
'span', |
2496
|
|
|
$a_infosUser["lastname"], |
2497
|
|
|
['title' => $username] |
2498
|
|
|
); |
2499
|
|
|
$row[] = $a_infosUser["firstname"]; |
2500
|
|
|
} |
2501
|
|
|
$row[] = Display::icon_mailto_link($a_infosUser['email']); |
2502
|
|
|
|
2503
|
|
|
// Link to register users |
2504
|
|
|
if ($a_infosUser['user_id'] != api_get_user_id()) { |
2505
|
|
|
$row[] = Display::url( |
2506
|
|
|
get_lang('Register'), |
2507
|
|
|
api_get_self()."?action=manage_members&blog_id=$blog_id®ister=yes&user_id=".$a_infosUser["user_id"].'&'.api_get_cidreq(), |
2508
|
|
|
['class' => 'btn btn-primary'] |
2509
|
|
|
); |
2510
|
|
|
} else { |
2511
|
|
|
$row[] = ''; |
2512
|
|
|
} |
2513
|
|
|
$user_data[] = $row; |
2514
|
|
|
} |
2515
|
|
|
} |
2516
|
|
|
|
2517
|
|
|
// Display |
2518
|
|
|
$query_vars['action'] = 'manage_members'; |
|
|
|
|
2519
|
|
|
$query_vars['blog_id'] = $blog_id; |
2520
|
|
|
$html .= '<form class="form-inline" method="post" action="blog.php?action=manage_members&blog_id='.$blog_id.'&'.api_get_cidreq().'">'; |
2521
|
|
|
$html .= Display::return_sortable_table($column_header, $user_data, null, null, $query_vars); |
2522
|
|
|
|
2523
|
|
|
$link = isset($_GET['action']) ? 'action='.Security::remove_XSS($_GET['action']).'&' : ''; |
2524
|
|
|
$link .= "blog_id=$blog_id&".api_get_cidreq(); |
2525
|
|
|
|
2526
|
|
|
$html .= '<a class="btn btn-default" href="blog.php?'.$link.'selectall=subscribe">'.get_lang('SelectAll').'</a> - '; |
2527
|
|
|
$html .= '<a class="btn btn-default" href="blog.php?'.$link.'">'.get_lang('UnSelectAll').'</a> '; |
2528
|
|
|
$html .= '<div class="form-group">'; |
2529
|
|
|
$html .= '<label>'; |
2530
|
|
|
$html .= get_lang('WithSelected').' : '; |
2531
|
|
|
$html .= '</label>'; |
2532
|
|
|
$html .= '<select class="selectpicker" name="action">'; |
2533
|
|
|
$html .= '<option value="select_subscribe">'.get_lang('Register').'</option>'; |
2534
|
|
|
$html .= '</select>'; |
2535
|
|
|
$html .= '<input type="hidden" name="register" value="true" />'; |
2536
|
|
|
$html .= '<button class="btn btn-default" type="submit">'.get_lang('Ok').'</button>'; |
2537
|
|
|
$html .= '</div>'; |
2538
|
|
|
$html .= '</form>'; |
2539
|
|
|
|
2540
|
|
|
return $html; |
2541
|
|
|
} |
2542
|
|
|
|
2543
|
|
|
/** |
2544
|
|
|
* Displays the form to register users in a blog (in a course) |
2545
|
|
|
* The listed users are users subcribed in the course. |
2546
|
|
|
* |
2547
|
|
|
* @author Toon Keppens |
2548
|
|
|
* |
2549
|
|
|
* @param int $blog_id |
2550
|
|
|
* |
2551
|
|
|
* @return false|null form with sortable table with users to unsubcribe from a blog |
2552
|
|
|
*/ |
2553
|
|
|
public static function displayUserUnsubscriptionForm($blog_id) |
2554
|
|
|
{ |
2555
|
|
|
$_user = api_get_user_info(); |
2556
|
|
|
$is_western_name_order = api_is_western_name_order(); |
2557
|
|
|
$html = null; |
2558
|
|
|
|
2559
|
|
|
// Init |
2560
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
2561
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
2562
|
|
|
$blog_id = intval($blog_id); |
2563
|
|
|
|
2564
|
|
|
$html .= '<legend>'.get_lang('UnsubscribeMembers').'</legend>'; |
2565
|
|
|
|
2566
|
|
|
$properties["width"] = "100%"; |
|
|
|
|
2567
|
|
|
//table column titles |
2568
|
|
|
$column_header[] = ['', false, '']; |
|
|
|
|
2569
|
|
|
if ($is_western_name_order) { |
2570
|
|
|
$column_header[] = [get_lang('FirstName'), true, '']; |
2571
|
|
|
$column_header[] = [get_lang('LastName'), true, '']; |
2572
|
|
|
} else { |
2573
|
|
|
$column_header[] = [get_lang('LastName'), true, '']; |
2574
|
|
|
$column_header[] = [get_lang('FirstName'), true, '']; |
2575
|
|
|
} |
2576
|
|
|
$column_header[] = [get_lang('Email'), false, '']; |
2577
|
|
|
$column_header[] = [get_lang('TaskManager'), true, '']; |
2578
|
|
|
$column_header[] = [get_lang('UnRegister'), false, '']; |
2579
|
|
|
|
2580
|
|
|
$course_id = api_get_course_int_id(); |
2581
|
|
|
|
2582
|
|
|
$sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username |
2583
|
|
|
FROM $tbl_users user |
2584
|
|
|
INNER JOIN $tbl_blogs_rel_user blogs_rel_user |
2585
|
|
|
ON user.user_id = blogs_rel_user.user_id |
2586
|
|
|
WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = $blog_id"; |
2587
|
|
|
|
2588
|
|
|
if (!($sql_result = Database::query($sql))) { |
2589
|
|
|
return false; |
2590
|
|
|
} |
2591
|
|
|
|
2592
|
|
|
$user_data = []; |
2593
|
|
|
while ($myrow = Database::fetch_array($sql_result)) { |
2594
|
|
|
$row = []; |
2595
|
|
|
$row[] = '<input type="checkbox" name="user[]" value="'.$myrow['user_id'].'" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '').'/>'; |
2596
|
|
|
$username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES); |
2597
|
|
|
if ($is_western_name_order) { |
2598
|
|
|
$row[] = $myrow["firstname"]; |
2599
|
|
|
$row[] = Display::tag( |
2600
|
|
|
'span', |
2601
|
|
|
$myrow["lastname"], |
2602
|
|
|
['title' => $username] |
2603
|
|
|
); |
2604
|
|
|
} else { |
2605
|
|
|
$row[] = Display::tag( |
2606
|
|
|
'span', |
2607
|
|
|
$myrow["lastname"], |
2608
|
|
|
['title' => $username] |
2609
|
|
|
); |
2610
|
|
|
$row[] = $myrow["firstname"]; |
2611
|
|
|
} |
2612
|
|
|
$row[] = Display::icon_mailto_link($myrow["email"]); |
2613
|
|
|
|
2614
|
|
|
$sql = "SELECT bt.title task |
2615
|
|
|
FROM ".Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER)." btu |
2616
|
|
|
INNER JOIN ".Database::get_course_table(TABLE_BLOGS_TASKS)." bt |
2617
|
|
|
ON btu.task_id = bt.task_id |
2618
|
|
|
WHERE btu.c_id = $course_id AND |
2619
|
|
|
bt.c_id = $course_id AND |
2620
|
|
|
btu.blog_id = $blog_id AND |
2621
|
|
|
btu.user_id = ".$myrow['user_id']; |
2622
|
|
|
$sql_res = Database::query($sql); |
2623
|
|
|
|
2624
|
|
|
$task = ''; |
2625
|
|
|
|
2626
|
|
|
while ($r = Database::fetch_array($sql_res)) { |
2627
|
|
|
$task .= stripslashes($r['task']).', '; |
2628
|
|
|
} |
2629
|
|
|
//echo $task; |
2630
|
|
|
$task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader'); |
2631
|
|
|
$row[] = $task; |
2632
|
|
|
//Link to register users |
2633
|
|
|
|
2634
|
|
|
if ($myrow["user_id"] != $_user['user_id']) { |
2635
|
|
|
$row[] = Display::url( |
2636
|
|
|
get_lang('UnRegister'), |
2637
|
|
|
api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=".$myrow['user_id'].'&'.api_get_cidreq(), |
2638
|
|
|
['class' => 'btn btn-primary'] |
2639
|
|
|
); |
2640
|
|
|
} else { |
2641
|
|
|
$row[] = ''; |
2642
|
|
|
} |
2643
|
|
|
$user_data[] = $row; |
2644
|
|
|
} |
2645
|
|
|
|
2646
|
|
|
$query_vars['action'] = 'manage_members'; |
|
|
|
|
2647
|
|
|
$query_vars['blog_id'] = $blog_id; |
2648
|
|
|
$html .= '<form class="form-inline" method="post" action="blog.php?action=manage_members&blog_id='.$blog_id.'&'.api_get_cidreq().'">'; |
2649
|
|
|
$html .= Display::return_sortable_table($column_header, $user_data, null, null, $query_vars); |
2650
|
|
|
|
2651
|
|
|
$link = isset($_GET['action']) ? 'action='.Security::remove_XSS($_GET['action']).'&' : ''; |
2652
|
|
|
$link .= "blog_id=$blog_id&".api_get_cidreq(); |
2653
|
|
|
|
2654
|
|
|
$html .= '<a class="btn btn-default" href="blog.php?'.$link.'selectall=unsubscribe">'.get_lang('SelectAll').'</a> - '; |
2655
|
|
|
$html .= '<a class="btn btn-default" href="blog.php?'.$link.'">'.get_lang('UnSelectAll').'</a> '; |
2656
|
|
|
$html .= '<div class="form-group">'; |
2657
|
|
|
$html .= '<label>'; |
2658
|
|
|
$html .= get_lang('WithSelected').' : '; |
2659
|
|
|
$html .= '</label>'; |
2660
|
|
|
$html .= '<select name="action" class="selectpicker">'; |
2661
|
|
|
$html .= '<option value="select_unsubscribe">'.get_lang('UnRegister').'</option>'; |
2662
|
|
|
$html .= '</select>'; |
2663
|
|
|
$html .= '<input type="hidden" name="unregister" value="true" />'; |
2664
|
|
|
$html .= '<button class="btn btn-default" type="submit">'.get_lang('Ok').'</button>'; |
2665
|
|
|
$html .= '</div>'; |
2666
|
|
|
$html .= '</form>'; |
2667
|
|
|
|
2668
|
|
|
return $html; |
2669
|
|
|
} |
2670
|
|
|
|
2671
|
|
|
/** |
2672
|
|
|
* Displays a matrix with selectboxes. On the left: users, on top: possible rights. |
2673
|
|
|
* The blog admin can thus select what a certain user can do in the current blog. |
2674
|
|
|
* |
2675
|
|
|
* @param int $blog_id |
2676
|
|
|
* |
2677
|
|
|
* @return string |
2678
|
|
|
*/ |
2679
|
|
|
public static function displayUserRightsForm($blog_id) |
2680
|
|
|
{ |
2681
|
|
|
ob_start(); |
2682
|
|
|
echo '<legend>'.get_lang('RightsManager').'</legend>'; |
2683
|
|
|
echo '<br />'; |
2684
|
|
|
|
2685
|
|
|
// Integration of patricks permissions system. |
2686
|
|
|
require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php'; |
2687
|
|
|
$content = ob_get_contents(); |
2688
|
|
|
ob_get_clean(); |
2689
|
|
|
|
2690
|
|
|
return $content; |
2691
|
|
|
} |
2692
|
|
|
|
2693
|
|
|
/** |
2694
|
|
|
* show the calender of the given month. |
2695
|
|
|
* |
2696
|
|
|
* @author Patrick Cool |
2697
|
|
|
* @author Toon Keppens |
2698
|
|
|
* |
2699
|
|
|
* @param int $month The integer value of the month we are viewing |
2700
|
|
|
* @param int $year The 4-digit year indication e.g. 2005 |
2701
|
|
|
* @param int $blog_id |
2702
|
|
|
* |
2703
|
|
|
* @return string html code |
2704
|
|
|
*/ |
2705
|
|
|
public static function displayMiniMonthCalendar($month, $year, $blog_id) |
2706
|
|
|
{ |
2707
|
|
|
// Init |
2708
|
|
|
$_user = api_get_user_info(); |
2709
|
|
|
global $DaysShort; |
2710
|
|
|
global $MonthsLong; |
2711
|
|
|
$html = null; |
2712
|
|
|
|
2713
|
|
|
$posts = []; |
2714
|
|
|
$tasks = []; |
2715
|
|
|
|
2716
|
|
|
$tbl_users = Database::get_main_table(TABLE_MAIN_USER); |
2717
|
|
|
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); |
2718
|
|
|
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); |
2719
|
|
|
$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER); |
2720
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
2721
|
|
|
|
2722
|
|
|
$course_id = api_get_course_int_id(); |
2723
|
|
|
$blog_id = intval($blog_id); |
2724
|
|
|
$month = intval($month); |
2725
|
|
|
$year = intval($year); |
2726
|
|
|
|
2727
|
|
|
//Handle leap year |
2728
|
|
|
$numberofdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; |
2729
|
|
|
|
2730
|
|
|
if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 != 0)) { |
2731
|
|
|
$numberofdays[2] = 29; |
2732
|
|
|
} |
2733
|
|
|
|
2734
|
|
|
//Get the first day of the month |
2735
|
|
|
$dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); |
2736
|
|
|
$monthName = $MonthsLong[$month - 1]; |
2737
|
|
|
|
2738
|
|
|
//Start the week on monday |
2739
|
|
|
$startdayofweek = $dayone['wday'] != 0 ? ($dayone['wday'] - 1) : 6; |
2740
|
|
|
$blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null; |
2741
|
|
|
$filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null; |
2742
|
|
|
$backwardsURL = api_get_self( |
2743
|
|
|
)."?blog_id=".$blogId."&filter=".$filter."&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year); |
2744
|
|
|
$forewardsURL = api_get_self( |
2745
|
|
|
)."?blog_id=".$blogId."&filter=".$filter."&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year); |
2746
|
|
|
|
2747
|
|
|
// Get posts for this month |
2748
|
|
|
$sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname |
2749
|
|
|
FROM $tbl_blogs_posts post |
2750
|
|
|
INNER JOIN $tbl_users user |
2751
|
|
|
ON post.author_id = user.user_id |
2752
|
|
|
WHERE |
2753
|
|
|
post.c_id = $course_id AND |
2754
|
|
|
post.blog_id = $blog_id AND |
2755
|
|
|
MONTH(date_creation) = '$month' AND |
2756
|
|
|
YEAR(date_creation) = '$year' |
2757
|
|
|
ORDER BY date_creation"; |
2758
|
|
|
$result = Database::query($sql); |
2759
|
|
|
|
2760
|
|
|
// We will create an array of days on which there are posts. |
2761
|
|
|
if (Database::num_rows($result) > 0) { |
2762
|
|
|
while ($blog_post = Database::fetch_array($result)) { |
2763
|
|
|
// If the day of this post is not yet in the array, add it. |
2764
|
|
|
if (!in_array($blog_post['post_day'], $posts)) { |
2765
|
|
|
$posts[] = $blog_post['post_day']; |
2766
|
|
|
} |
2767
|
|
|
} |
2768
|
|
|
} |
2769
|
|
|
|
2770
|
|
|
// Get tasks for this month |
2771
|
|
|
if ($_user['user_id']) { |
2772
|
|
|
$sql = "SELECT |
2773
|
|
|
task_rel_user.*, |
2774
|
|
|
DAYOFMONTH(target_date) as task_day, |
2775
|
|
|
task.title, |
2776
|
|
|
blog.blog_name |
2777
|
|
|
FROM $tbl_blogs_tasks_rel_user task_rel_user |
2778
|
|
|
INNER JOIN $tbl_blogs_tasks task |
2779
|
|
|
ON task_rel_user.task_id = task.task_id |
2780
|
|
|
INNER JOIN $tbl_blogs blog |
2781
|
|
|
ON task_rel_user.blog_id = blog.blog_id |
2782
|
|
|
WHERE |
2783
|
|
|
task_rel_user.c_id = $course_id AND |
2784
|
|
|
task.c_id = $course_id AND |
2785
|
|
|
blog.c_id = $course_id AND |
2786
|
|
|
task_rel_user.user_id = ".$_user['user_id']." AND |
2787
|
|
|
MONTH(target_date) = '$month' AND |
2788
|
|
|
YEAR(target_date) = '$year' |
2789
|
|
|
ORDER BY target_date ASC"; |
2790
|
|
|
$result = Database::query($sql); |
2791
|
|
|
|
2792
|
|
|
if (Database::num_rows($result) > 0) { |
2793
|
|
|
while ($mytask = Database::fetch_array($result)) { |
2794
|
|
|
$tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id']; |
2795
|
|
|
$tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title']; |
2796
|
|
|
$tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id']; |
2797
|
|
|
$tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name']; |
2798
|
|
|
$tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day']; |
2799
|
|
|
} |
2800
|
|
|
} |
2801
|
|
|
} |
2802
|
|
|
|
2803
|
|
|
$html .= '<table id="smallcalendar" class="table table-responsive"> |
2804
|
|
|
<tr id="title"> |
2805
|
|
|
<th width="10%"><a href="'.$backwardsURL.'">«</a></th> |
2806
|
|
|
<th align="center" width="80%" colspan="5" class="month">'.$monthName.' '.$year.'</th> |
2807
|
|
|
<th width="10%" align="right"><a href="'.$forewardsURL.'">»</a></th></tr>'; |
2808
|
|
|
|
2809
|
|
|
$html .= '<tr>'; |
2810
|
|
|
|
2811
|
|
|
for ($ii = 1; $ii < 8; $ii++) { |
2812
|
|
|
$html .= '<td class="weekdays">'.$DaysShort[$ii % 7].'</td>'; |
2813
|
|
|
} |
2814
|
|
|
|
2815
|
|
|
$html .= '</tr>'; |
2816
|
|
|
|
2817
|
|
|
$curday = -1; |
2818
|
|
|
$today = getdate(); |
2819
|
|
|
|
2820
|
|
|
while ($curday <= $numberofdays[$month]) { |
2821
|
|
|
$html .= '<tr>'; |
2822
|
|
|
for ($ii = 0; $ii < 7; $ii++) { |
2823
|
|
|
if (($curday == -1) && ($ii == $startdayofweek)) { |
2824
|
|
|
$curday = 1; |
2825
|
|
|
} |
2826
|
|
|
|
2827
|
|
|
if (($curday > 0) && ($curday <= $numberofdays[$month])) { |
2828
|
|
|
$bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\""; |
2829
|
|
|
$dayheader = "$curday"; |
2830
|
|
|
|
2831
|
|
|
if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { |
2832
|
|
|
$dayheader = "$curday"; |
2833
|
|
|
$class = "class=\"days_today\""; |
2834
|
|
|
} |
2835
|
|
|
|
2836
|
|
|
$html .= '<td '.$class.'>'; |
2837
|
|
|
|
2838
|
|
|
// If there are posts on this day, create a filter link. |
2839
|
|
|
if (in_array($curday, $posts)) { |
2840
|
|
|
$html .= '<a href="blog.php?blog_id='.$blog_id.'&filter='.$year.'-'.$month.'-'.$curday.'&month='.$month.'&year='.$year.'" title="'.get_lang( |
2841
|
|
|
'ViewPostsOfThisDay' |
2842
|
|
|
).'">'.$curday.'</a>'; |
2843
|
|
|
} else { |
2844
|
|
|
$html .= $dayheader; |
2845
|
|
|
} |
2846
|
|
|
|
2847
|
|
|
if (count($tasks) > 0) { |
2848
|
|
|
if (isset($tasks[$curday]) && is_array($tasks[$curday])) { |
2849
|
|
|
// Add tasks to calendar |
2850
|
|
|
foreach ($tasks[$curday] as $task) { |
2851
|
|
|
$html .= '<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').'">'; |
2852
|
|
|
$html .= Display::return_icon('blog_task.gif', get_lang('ExecuteThisTask')); |
2853
|
|
|
$html .= '</a>'; |
2854
|
|
|
} |
2855
|
|
|
} |
2856
|
|
|
} |
2857
|
|
|
|
2858
|
|
|
$html .= '</td>'; |
2859
|
|
|
$curday++; |
2860
|
|
|
} else { |
2861
|
|
|
$html .= '<td> </td>'; |
2862
|
|
|
} |
2863
|
|
|
} |
2864
|
|
|
$html .= '</tr>'; |
2865
|
|
|
} |
2866
|
|
|
$html .= '</table>'; |
2867
|
|
|
|
2868
|
|
|
return $html; |
2869
|
|
|
} |
2870
|
|
|
|
2871
|
|
|
/** |
2872
|
|
|
* Blog admin | Display the form to add a new blog. |
2873
|
|
|
*/ |
2874
|
|
|
public static function displayBlogCreateForm() |
2875
|
|
|
{ |
2876
|
|
|
$form = new FormValidator( |
2877
|
|
|
'add_blog', |
2878
|
|
|
'post', |
2879
|
|
|
'blog_admin.php?action=add' |
2880
|
|
|
); |
2881
|
|
|
$form->addElement('header', get_lang('AddBlog')); |
2882
|
|
|
$form->addElement('text', 'blog_name', get_lang('Title')); |
2883
|
|
|
$form->addElement('textarea', 'blog_subtitle', get_lang('SubTitle')); |
2884
|
|
|
$form->addElement('hidden', 'new_blog_submit', 'true'); |
2885
|
|
|
$form->addButtonSave(get_lang('SaveProject')); |
2886
|
|
|
|
2887
|
|
|
$defaults = [ |
2888
|
|
|
'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null, |
2889
|
|
|
'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null, |
2890
|
|
|
]; |
2891
|
|
|
$form->setDefaults($defaults); |
2892
|
|
|
$form->display(); |
2893
|
|
|
} |
2894
|
|
|
|
2895
|
|
|
/** |
2896
|
|
|
* Blog admin | Display the form to edit a blog. |
2897
|
|
|
* |
2898
|
|
|
* @param int $blog_id |
2899
|
|
|
*/ |
2900
|
|
|
public static function displayBlogEditForm($blog_id) |
2901
|
|
|
{ |
2902
|
|
|
$course_id = api_get_course_int_id(); |
2903
|
|
|
$blog_id = intval($blog_id); |
2904
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
2905
|
|
|
|
2906
|
|
|
$sql = "SELECT blog_id, blog_name, blog_subtitle |
2907
|
|
|
FROM $tbl_blogs |
2908
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id"; |
2909
|
|
|
$result = Database::query($sql); |
2910
|
|
|
$blog = Database::fetch_array($result); |
2911
|
|
|
|
2912
|
|
|
// the form contained errors but we do not want to lose the changes the user already did |
2913
|
|
|
if ($_POST) { |
2914
|
|
|
$blog['blog_name'] = Security::remove_XSS($_POST['blog_name']); |
2915
|
|
|
$blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']); |
2916
|
|
|
} |
2917
|
|
|
|
2918
|
|
|
$form = new FormValidator( |
2919
|
|
|
'edit_blog', |
2920
|
|
|
'post', |
2921
|
|
|
'blog_admin.php?action=edit&blog_id='.intval($_GET['blog_id']) |
2922
|
|
|
); |
2923
|
|
|
$form->addElement('header', get_lang('EditBlog')); |
2924
|
|
|
$form->addElement('text', 'blog_name', get_lang('Title')); |
2925
|
|
|
$form->addElement('textarea', 'blog_subtitle', get_lang('SubTitle')); |
2926
|
|
|
$form->addElement('hidden', 'edit_blog_submit', 'true'); |
2927
|
|
|
$form->addElement('hidden', 'blog_id', $blog['blog_id']); |
2928
|
|
|
$form->addButtonSave(get_lang('Save')); |
2929
|
|
|
|
2930
|
|
|
$defaults = []; |
2931
|
|
|
$defaults['blog_name'] = $blog['blog_name']; |
2932
|
|
|
$defaults['blog_subtitle'] = $blog['blog_subtitle']; |
2933
|
|
|
$form->setDefaults($defaults); |
2934
|
|
|
$form->display(); |
2935
|
|
|
} |
2936
|
|
|
|
2937
|
|
|
/** |
2938
|
|
|
* Blog admin | Returns table with blogs in this course. |
2939
|
|
|
*/ |
2940
|
|
|
public static function displayBlogsList() |
2941
|
|
|
{ |
2942
|
|
|
global $charset; |
2943
|
|
|
$_user = api_get_user_info(); |
2944
|
|
|
$course_id = api_get_course_int_id(); |
2945
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
2946
|
|
|
|
2947
|
|
|
//condition for the session |
2948
|
|
|
$session_id = api_get_session_id(); |
2949
|
|
|
|
2950
|
|
|
$sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id |
2951
|
|
|
FROM $tbl_blogs WHERE c_id = $course_id |
2952
|
|
|
ORDER BY date_creation DESC"; |
2953
|
|
|
$result = Database::query($sql); |
2954
|
|
|
$list_info = []; |
2955
|
|
|
if (Database::num_rows($result)) { |
2956
|
|
|
while ($row_project = Database::fetch_row($result)) { |
2957
|
|
|
$list_info[] = $row_project; |
2958
|
|
|
} |
2959
|
|
|
} |
2960
|
|
|
|
2961
|
|
|
$list_content_blog = []; |
2962
|
|
|
$list_body_blog = []; |
2963
|
|
|
|
2964
|
|
|
if (is_array($list_info)) { |
2965
|
|
|
foreach ($list_info as $key => $info_log) { |
2966
|
|
|
// Validation when belongs to a session |
2967
|
|
|
$session_img = api_get_session_image($info_log[4], $_user['status']); |
2968
|
|
|
|
2969
|
|
|
$url_start_blog = 'blog.php'."?"."blog_id=".$info_log[3]."&".api_get_cidreq(); |
2970
|
|
|
$title = $info_log[0]; |
2971
|
|
|
$image = Display::return_icon('blog.png', $title); |
2972
|
|
|
$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; |
2973
|
|
|
|
2974
|
|
|
$list_body_blog[] = $list_name; |
2975
|
|
|
$list_body_blog[] = $info_log[1]; |
2976
|
|
|
|
2977
|
|
|
$visibility_icon = ($info_log[2] == 0) ? 'invisible' : 'visible'; |
2978
|
|
|
$visibility_info = ($info_log[2] == 0) ? 'Visible' : 'Invisible'; |
2979
|
|
|
|
2980
|
|
|
$my_image = '<a href="'.api_get_self().'?action=visibility&blog_id='.$info_log[3].'">'; |
2981
|
|
|
$my_image .= Display::return_icon($visibility_icon.'.png', get_lang($visibility_info)); |
2982
|
|
|
$my_image .= "</a>"; |
2983
|
|
|
|
2984
|
|
|
$my_image .= '<a href="'.api_get_self().'?action=edit&blog_id='.$info_log[3].'">'; |
2985
|
|
|
$my_image .= Display::return_icon('edit.png', get_lang('EditBlog')); |
2986
|
|
|
$my_image .= "</a>"; |
2987
|
|
|
|
2988
|
|
|
$my_image .= '<a href="'.api_get_self().'?action=delete&blog_id='.$info_log[3].'" '; |
2989
|
|
|
$my_image .= 'onclick="javascript:if(!confirm(\''.addslashes( |
2990
|
|
|
api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset) |
2991
|
|
|
).'\')) return false;" >'; |
2992
|
|
|
$my_image .= Display::return_icon('delete.png', get_lang('DeleteBlog')); |
2993
|
|
|
$my_image .= "</a>"; |
2994
|
|
|
|
2995
|
|
|
$list_body_blog[] = $my_image; |
2996
|
|
|
$list_content_blog[] = $list_body_blog; |
2997
|
|
|
$list_body_blog = []; |
2998
|
|
|
} |
2999
|
|
|
|
3000
|
|
|
$table = new SortableTableFromArrayConfig( |
3001
|
|
|
$list_content_blog, |
3002
|
|
|
1, |
3003
|
|
|
20, |
3004
|
|
|
'project' |
3005
|
|
|
); |
3006
|
|
|
$table->set_header(0, get_lang('Title')); |
3007
|
|
|
$table->set_header(1, get_lang('SubTitle')); |
3008
|
|
|
$table->set_header(2, get_lang('Modify')); |
3009
|
|
|
$table->display(); |
3010
|
|
|
} |
3011
|
|
|
} |
3012
|
|
|
|
3013
|
|
|
/** |
3014
|
|
|
* Show a list with all the attachments according the parameter's. |
3015
|
|
|
* |
3016
|
|
|
* @param int $blog_id the blog's id |
3017
|
|
|
* @param int $post_id the post's id |
3018
|
|
|
* @param int $comment_id the comment's id |
3019
|
|
|
* |
3020
|
|
|
* @return array with the post info according the parameters |
3021
|
|
|
* |
3022
|
|
|
* @author Julio Montoya |
3023
|
|
|
* |
3024
|
|
|
* @version avril 2008, dokeos 1.8.5 |
3025
|
|
|
*/ |
3026
|
|
|
public static function getBlogAttachments($blog_id, $post_id = 0, $comment_id = 0) |
3027
|
|
|
{ |
3028
|
|
|
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); |
3029
|
|
|
|
3030
|
|
|
$blog_id = intval($blog_id); |
3031
|
|
|
$comment_id = intval($comment_id); |
3032
|
|
|
$post_id = intval($post_id); |
3033
|
|
|
$row = []; |
3034
|
|
|
$where = ''; |
3035
|
|
|
if (!empty($post_id) && is_numeric($post_id)) { |
3036
|
|
|
$where .= " AND post_id = $post_id "; |
3037
|
|
|
} |
3038
|
|
|
|
3039
|
|
|
if (!empty($comment_id) && is_numeric($comment_id)) { |
3040
|
|
|
if (!empty($post_id)) { |
3041
|
|
|
$where .= ' AND '; |
3042
|
|
|
} |
3043
|
|
|
$where .= " comment_id = $comment_id "; |
3044
|
|
|
} |
3045
|
|
|
|
3046
|
|
|
$course_id = api_get_course_int_id(); |
3047
|
|
|
|
3048
|
|
|
$sql = "SELECT path, filename, comment |
3049
|
|
|
FROM $blog_table_attachment |
3050
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id |
3051
|
|
|
$where"; |
3052
|
|
|
|
3053
|
|
|
$result = Database::query($sql); |
3054
|
|
|
if (Database::num_rows($result) != 0) { |
3055
|
|
|
$row = Database::fetch_array($result); |
3056
|
|
|
} |
3057
|
|
|
|
3058
|
|
|
return $row; |
3059
|
|
|
} |
3060
|
|
|
|
3061
|
|
|
/** |
3062
|
|
|
* Delete the all the attachments according the parameters. |
3063
|
|
|
* |
3064
|
|
|
* @param int $blog_id |
3065
|
|
|
* @param int $post_id post's id |
3066
|
|
|
* @param int $comment_id the comment's id |
3067
|
|
|
* |
3068
|
|
|
* @author Julio Montoya |
3069
|
|
|
* |
3070
|
|
|
* @version avril 2008, dokeos 1.8.5 |
3071
|
|
|
*/ |
3072
|
|
|
public static function deleteAllBlogAttachments( |
3073
|
|
|
$blog_id, |
3074
|
|
|
$post_id = 0, |
3075
|
|
|
$comment_id = 0 |
3076
|
|
|
) { |
3077
|
|
|
$_course = api_get_course_info(); |
3078
|
|
|
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); |
3079
|
|
|
$blog_id = intval($blog_id); |
3080
|
|
|
$comment_id = intval($comment_id); |
3081
|
|
|
$post_id = intval($post_id); |
3082
|
|
|
|
3083
|
|
|
$course_id = api_get_course_int_id(); |
3084
|
|
|
$where = null; |
3085
|
|
|
|
3086
|
|
|
// delete files in DB |
3087
|
|
|
if (!empty($post_id) && is_numeric($post_id)) { |
3088
|
|
|
$where .= " AND post_id = $post_id "; |
3089
|
|
|
} |
3090
|
|
|
|
3091
|
|
|
if (!empty($comment_id) && is_numeric($comment_id)) { |
3092
|
|
|
if (!empty($post_id)) { |
3093
|
|
|
$where .= ' AND '; |
3094
|
|
|
} |
3095
|
|
|
$where .= " comment_id = $comment_id "; |
3096
|
|
|
} |
3097
|
|
|
|
3098
|
|
|
// delete all files in directory |
3099
|
|
|
$courseDir = $_course['path'].'/upload/blog'; |
3100
|
|
|
$sys_course_path = api_get_path(SYS_COURSE_PATH); |
3101
|
|
|
$updir = $sys_course_path.$courseDir; |
3102
|
|
|
|
3103
|
|
|
$sql = "SELECT path FROM $blog_table_attachment |
3104
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id $where"; |
3105
|
|
|
$result = Database::query($sql); |
3106
|
|
|
|
3107
|
|
|
while ($row = Database::fetch_row($result)) { |
3108
|
|
|
$file = $updir.'/'.$row[0]; |
3109
|
|
|
if (Security::check_abs_path($file, $updir)) { |
3110
|
|
|
@unlink($file); |
|
|
|
|
3111
|
|
|
} |
3112
|
|
|
} |
3113
|
|
|
$sql = "DELETE FROM $blog_table_attachment |
3114
|
|
|
WHERE c_id = $course_id AND blog_id = $blog_id $where"; |
3115
|
|
|
Database::query($sql); |
3116
|
|
|
} |
3117
|
|
|
|
3118
|
|
|
/** |
3119
|
|
|
* Gets all the post from a given user id. |
3120
|
|
|
* |
3121
|
|
|
* @param int $courseId |
3122
|
|
|
* @param int $userId |
3123
|
|
|
* @param string $courseCode |
3124
|
|
|
* |
3125
|
|
|
* @return string |
3126
|
|
|
*/ |
3127
|
|
|
public static function getBlogPostFromUser($courseId, $userId, $courseCode) |
3128
|
|
|
{ |
3129
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
3130
|
|
|
$tbl_blog_post = Database::get_course_table(TABLE_BLOGS_POSTS); |
3131
|
|
|
$courseId = intval($courseId); |
3132
|
|
|
$userId = intval($userId); |
3133
|
|
|
|
3134
|
|
|
$sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation |
3135
|
|
|
FROM $tbl_blogs blog |
3136
|
|
|
INNER JOIN $tbl_blog_post post |
3137
|
|
|
ON (blog.blog_id = post.blog_id AND blog.c_id = post.c_id) |
3138
|
|
|
WHERE |
3139
|
|
|
blog.c_id = $courseId AND |
3140
|
|
|
post.c_id = $courseId AND |
3141
|
|
|
author_id = $userId AND |
3142
|
|
|
visibility = 1 |
3143
|
|
|
ORDER BY post.date_creation DESC "; |
3144
|
|
|
$result = Database::query($sql); |
3145
|
|
|
$return_data = ''; |
3146
|
|
|
|
3147
|
|
|
if (Database::num_rows($result) != 0) { |
3148
|
|
|
while ($row = Database::fetch_array($result)) { |
3149
|
|
|
$return_data .= '<div class="clear"></div><br />'; |
3150
|
|
|
$return_data .= '<div class="actions" style="margin-left:5px;margin-right:5px;">'. |
3151
|
|
|
Display::return_icon( |
3152
|
|
|
'blog_article.png', |
3153
|
|
|
get_lang('BlogPosts') |
3154
|
|
|
).' '. |
3155
|
|
|
$row['title'].' <div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$courseCode.' " >'. |
3156
|
|
|
get_lang('SeeBlog').'</a></div></div>'; |
3157
|
|
|
$return_data .= '<br / >'; |
3158
|
|
|
$return_data .= $row['full_text']; |
3159
|
|
|
$return_data .= '<br /><br />'; |
3160
|
|
|
} |
3161
|
|
|
} |
3162
|
|
|
|
3163
|
|
|
return $return_data; |
3164
|
|
|
} |
3165
|
|
|
|
3166
|
|
|
/** |
3167
|
|
|
* Gets all the post comments from a given user id. |
3168
|
|
|
* |
3169
|
|
|
* @param int $courseId |
3170
|
|
|
* @param int $userId |
3171
|
|
|
* @param string $courseCode |
3172
|
|
|
* |
3173
|
|
|
* @return string |
3174
|
|
|
*/ |
3175
|
|
|
public static function getBlogCommentsFromUser($courseId, $userId, $courseCode) |
3176
|
|
|
{ |
3177
|
|
|
$tbl_blogs = Database::get_course_table(TABLE_BLOGS); |
3178
|
|
|
$tbl_blog_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS); |
3179
|
|
|
|
3180
|
|
|
$userId = intval($userId); |
3181
|
|
|
$courseId = intval($courseId); |
3182
|
|
|
|
3183
|
|
|
$sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation |
3184
|
|
|
FROM $tbl_blogs blog |
3185
|
|
|
INNER JOIN $tbl_blog_comment comment |
3186
|
|
|
ON (blog.blog_id = comment.blog_id AND blog.c_id = comment.c_id) |
3187
|
|
|
WHERE blog.c_id = $courseId AND |
3188
|
|
|
comment.c_id = $courseId AND |
3189
|
|
|
author_id = $userId AND |
3190
|
|
|
visibility = 1 |
3191
|
|
|
ORDER BY blog_name"; |
3192
|
|
|
$result = Database::query($sql); |
3193
|
|
|
$return_data = ''; |
3194
|
|
|
if (Database::num_rows($result) != 0) { |
3195
|
|
|
while ($row = Database::fetch_array($result)) { |
3196
|
|
|
$return_data .= '<div class="clear"></div><br />'; |
3197
|
|
|
$return_data .= '<div class="actions" style="margin-left:5px;margin-right:5px;">'. |
3198
|
|
|
$row['title'].' <div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($courseCode).' " >'. |
3199
|
|
|
get_lang('SeeBlog').'</a></div></div>'; |
3200
|
|
|
$return_data .= '<br / >'; |
3201
|
|
|
$return_data .= $row['comment']; |
3202
|
|
|
$return_data .= '<br />'; |
3203
|
|
|
} |
3204
|
|
|
} |
3205
|
|
|
|
3206
|
|
|
return $return_data; |
3207
|
|
|
} |
3208
|
|
|
|
3209
|
|
|
/** |
3210
|
|
|
* Filter the post $fullText to get a extract of $length characters. |
3211
|
|
|
* |
3212
|
|
|
* @param string $fullText |
3213
|
|
|
* @param int $length |
3214
|
|
|
* |
3215
|
|
|
* @return string|null |
3216
|
|
|
*/ |
3217
|
|
|
private static function getPostExtract($fullText, $length = BLOG_MAX_PREVIEW_CHARS) |
3218
|
|
|
{ |
3219
|
|
|
$parts = explode(BLOG_PAGE_BREAK, $fullText); |
3220
|
|
|
|
3221
|
|
|
if (count($parts) > 1) { |
3222
|
|
|
return $parts[0]; |
3223
|
|
|
} |
3224
|
|
|
|
3225
|
|
|
// Remove any HTML from the string |
3226
|
|
|
$text = strip_tags($fullText); |
3227
|
|
|
$text = api_html_entity_decode($text); |
3228
|
|
|
// Replace end of lines with spaces |
3229
|
|
|
$text = preg_replace('/\s+/', ' ', $text); |
3230
|
|
|
// Count whitespaces to add to the cut() call below |
3231
|
|
|
$countBlanks = substr_count($text, ' '); |
3232
|
|
|
// Get a version of the string without spaces for comparison purposes |
3233
|
|
|
$textWithoutBlanks = str_replace(' ', '', $text); |
3234
|
|
|
// utf8_decode replaces non-ISO chars by '?' which avoids counting |
3235
|
|
|
// multi-byte characters as more than one character |
3236
|
|
|
$stringLength = strlen(utf8_decode($textWithoutBlanks)); |
3237
|
|
|
|
3238
|
|
|
if ($stringLength <= $length) { |
3239
|
|
|
return null; |
3240
|
|
|
} |
3241
|
|
|
|
3242
|
|
|
// Cut the string to the BLOG_MAX_PREVIEX_CHARS limit, adding |
3243
|
|
|
// whitespaces |
3244
|
|
|
$extract = cut($text, $length + $countBlanks); |
3245
|
|
|
|
3246
|
|
|
// Return an HTML string for printing |
3247
|
|
|
return api_htmlentities($extract); |
3248
|
|
|
} |
3249
|
|
|
} |
3250
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: