@ -56,10 +56,10 @@ class Blog
WHERE c_id = $course_id AND blog_id ='".intval($blog_id)."'";
$result = Database::query($sql);
$blog = Database::fetch_array($result);
return stripslashes($blog['blog_subtitle']);
}
/**
* Get the users of a blog
* @author Toon Keppens
@ -68,7 +68,8 @@ class Blog
*
* @return Array Returns an array with [userid]=>[username]
*/
public static function get_blog_users ($blog_id) {
public static function get_blog_users($blog_id)
{
// Database table definitions
$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
@ -78,8 +79,10 @@ class Blog
// Get blog members
$sql = "SELECT user.user_id, user.firstname, user.lastname
FROM " . $tbl_blogs_rel_user . " blogs_rel_user
INNER JOIN " . $tbl_users . " user ON blogs_rel_user.user_id = user.user_id
WHERE blogs_rel_user.c_id = $course_id AND
INNER JOIN " . $tbl_users . " user
ON blogs_rel_user.user_id = user.user_id
WHERE
blogs_rel_user.c_id = $course_id AND
blogs_rel_user.blog_id = '" . (int)$blog_id."'";
$result = Database::query($sql);
$blog_members = array ();
@ -97,9 +100,9 @@ class Blog
* @param String $title
* @param Text $description
*/
public static function create_blog ($title, $subtitle) {
global $_user;
public static function create_blog($title, $subtitle)
{
$_user = api_get_user_info();
$course_id = api_get_course_int_id();
$current_date=date('Y-m-d H:i:s',time());
@ -112,7 +115,10 @@ class Blog
//verified if exist blog
$sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
WHERE c_id = '.$course_id.' AND blog_name="'.Database::escape_string($title).'" AND blog_subtitle="'.Database::escape_string($subtitle).'";';
WHERE
c_id = '.$course_id.' AND
blog_name="'.Database::escape_string($title).'" AND
blog_subtitle="'.Database::escape_string($subtitle).'"';
$res = Database::query($sql);
$info_count = Database::result($res, 0, 0);
@ -124,22 +130,44 @@ class Blog
$this_blog_id = Database::insert_id();
if ($this_blog_id > 0) {
$sql = "UPDATE $tbl_blogs SET blog_id = iid WHERE iid = $this_blog_id";
Database::query($sql);
//insert into item_property
api_item_property_update(api_get_course_info(), TOOL_BLOGS, $this_blog_id, 'BlogAdded', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_BLOGS,
$this_blog_id,
'BlogAdded',
api_get_user_id()
);
}
// Make first post. :)
$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id)
VALUES ($course_id, '".get_lang("Welcome")."', '" . get_lang('FirstPostText')."','".$current_date."', '".Database::escape_string((int)$this_blog_id)."', '".Database::escape_string((int)$_user['user_id'])."');";
Database::query($sql);
$postId = Database::insert_id();
if ($postId) {
$sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $postId";
Database::query($sql);
}
// Put it on course homepage
$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id)
VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id')";
Database::query($sql);
$toolId = Database::insert_id();
if ($toolId) {
$sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $toolId";
Database::query($sql);
}
// Subscribe the teacher to this blog
Blog::set_user_subscribed((int)$this_blog_id,(int)$_user['user_id']);
Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
}
}
@ -161,16 +189,29 @@ class Blog
$course_id = api_get_course_int_id();
// Update the blog
$sql = "UPDATE $tbl_blogs SET blog_name = '".Database::escape_string($title)."', blog_subtitle = '".Database::escape_string($subtitle)."'
WHERE c_id = $course_id AND blog_id ='".Database::escape_string((int)$blog_id)."' LIMIT 1";
$sql = "UPDATE $tbl_blogs SET
blog_name = '".Database::escape_string($title)."',
blog_subtitle = '".Database::escape_string($subtitle)."'
WHERE
c_id = $course_id AND
blog_id ='".Database::escape_string((int)$blog_id)."'
LIMIT 1";
Database::query($sql);
$this_blog_id = Database::insert_id();
//update item_property (update)
api_item_property_update(api_get_course_info(), TOOL_BLOGS, intval($blog_id), 'BlogUpdated', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_BLOGS,
intval($blog_id),
'BlogUpdated',
api_get_user_id()
);
// Update course homepage link
$sql = "UPDATE $tbl_tool SET name = '".Database::escape_string($title)."' WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".Database::escape_string((int)$blog_id)."' LIMIT 1";
$sql = "UPDATE $tbl_tool SET
name = '".Database::escape_string($title)."'
WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".Database::escape_string((int)$blog_id)."' LIMIT 1";
Database::query($sql);
}
@ -191,36 +232,43 @@ class Blog
$tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$course_id = api_get_course_int_id();
$blog_id = intval($blog_id);
// Delete posts from DB and the attachments
delete_all_blog_attachment($blog_id);
//Delete comments
$sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."'";
$sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
Database::query($sql);
// Delete posts
$sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."'";
$sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
Database::query($sql);
// Delete tasks
$sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."'";
$sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
Database::query($sql);
// Delete ratings
$sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."'";
$sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
Database::query($sql);
// Delete blog
$sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."'";
$sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
Database::query($sql);
// Delete from course homepage
$sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int) $blog_id."'";
$sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
Database::query($sql);
//update item_property (delete)
api_item_property_update(api_get_course_info(), TOOL_BLOGS, intval($blog_id), 'delete', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_BLOGS,
$blog_id,
'delete',
api_get_user_id()
);
}
/**
@ -257,6 +305,11 @@ class Blog
Database::query($sql);
$last_post_id = Database::insert_id();
if ($last_post_id) {
$sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $last_post_id";
Database::query($sql);
}
if ($has_attachment) {
$courseDir = $_course['path'].'/upload/blog';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
@ -281,6 +334,11 @@ class Blog
$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
"VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."', '".$blog_id."', '0' )";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
}
}
@ -304,8 +362,11 @@ class Blog
$course_id = api_get_course_int_id();
// Create the post
$sql = "UPDATE $tbl_blogs_posts SET title = '" . Database::escape_string($title)."', full_text = '" . Database::escape_string($full_text)."'
WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."' LIMIT 1 ;";
$sql = "UPDATE $tbl_blogs_posts SET
title = '" . Database::escape_string($title)."',
full_text = '" . Database::escape_string($full_text)."'
WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."'
LIMIT 1 ";
Database::query($sql);
}
@ -355,7 +416,7 @@ class Blog
{
$_user = api_get_user_info();
$_course = api_get_course_info();
global $blog_table_attachment ;
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT) ;
$upload_ok = true;
$has_attachment = false;
@ -379,6 +440,11 @@ class Blog
// Empty post values, or they are shown on the page again
$last_id = Database::insert_id();
if ($last_id) {
$sql = "UPDATE $tbl_blogs_comments SET comment_id = iid WHERE iid = $last_id";
Database::query($sql);
}
if ($has_attachment) {
$courseDir = $_course['path'].'/upload/blog';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
@ -406,6 +472,13 @@ class Blog
$sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
"VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."', '".$blog_id."', '".$last_id."' )";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
}
}
@ -415,8 +488,8 @@ class Blog
/**
* Deletes a comment from a blogpost
* @author Toon Keppens
* @param Integer $blog_id
* @param Integer $comment_id
* @param int $blog_id
* @param int $comment_id
*/
public static function delete_comment($blog_id, $post_id, $comment_id)
{
@ -431,7 +504,11 @@ class Blog
// Delete ratings on this comment
$sql = "DELETE FROM $tbl_blogs_rating
WHERE c_id = $course_id AND blog_id = '".$blog_id."' AND item_id = '".$comment_id."' AND rating_type = 'comment'";
WHERE
c_id = $course_id AND
blog_id = '".$blog_id."' AND
item_id = '".$comment_id."' AND
rating_type = 'comment'";
Database::query($sql);
// select comments that have the selected comment as their parent
@ -472,6 +549,12 @@ class Blog
Database::query($sql);
$task_id = Database::insert_id();
if ($task_id) {
$sql = "UPDATE $tbl_blogs_tasks SET task_id = iid WHERE iid = $task_id";
Database::query($sql);
}
$tool = 'BLOG_' . $blog_id;
if ($articleDelete == 'on') {
@ -482,6 +565,13 @@ class Blog
'article_delete'
)";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
if ($articleEdit == 'on') {
@ -493,6 +583,12 @@ class Blog
'article_edit'
)";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
if ($commentsDelete == 'on') {
@ -503,10 +599,15 @@ class Blog
'" . Database::escape_string($tool) . "',
'article_comments_delete'
)";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
}
/**
* Edit a task in a blog
@ -544,8 +645,13 @@ class Blog
'" . Database::escape_string($tool) . "',
'article_delete'
)";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
if ($articleEdit == 'on') {
@ -556,6 +662,12 @@ class Blog
'article_edit'
)";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
if ($commentsDelete == 'on') {
@ -566,6 +678,12 @@ class Blog
'article_comments_delete'
)";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
}
@ -597,7 +715,11 @@ class Blog
// Delete posts
$sql = "DELETE FROM $tbl_blogs_tasks_rel_user
WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."' AND user_id = '".(int)$user_id."'";
WHERE
c_id = $course_id AND
blog_id = '".(int)$blog_id."' AND
task_id = '".(int)$task_id."' AND
user_id = '".(int)$user_id."'";
Database::query($sql);
}
@ -665,8 +787,7 @@ class Blog
$visibility = $blog['visibility'];
$title = $blog['blog_name'];
if($visibility == 1)
{
if ($visibility == 1) {
// Change visibility state, remove from course home.
$sql = "UPDATE $tbl_blogs SET visibility = '0'
WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
@ -675,9 +796,7 @@ class Blog
$sql = "DELETE FROM $tbl_tool
WHERE c_id = $course_id AND name = '".Database::escape_string($title)."' LIMIT 1";
$result = Database::query($sql);
}
else
{
} else {
// Change visibility state, add to course home.
$sql = "UPDATE $tbl_blogs SET visibility = '1'
WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
@ -686,6 +805,12 @@ class Blog
$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
}
@ -695,7 +820,8 @@ class Blog
*
* @param Integer $blog_id
*/
public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20) {
public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
{
// Init
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
@ -705,8 +831,10 @@ class Blog
$course_id = api_get_course_int_id();
// Get posts and authors
$sql = "SELECT post.*, user.lastname, user.firstname, user.username FROM $tbl_blogs_posts post
INNER JOIN $tbl_users user ON post.author_id = user.user_id
$sql = "SELECT post.*, user.lastname, user.firstname, user.username
FROM $tbl_blogs_posts post
INNER JOIN $tbl_users user
ON post.author_id = user.user_id
WHERE post.blog_id = '".(int)$blog_id."' AND
post.c_id = $course_id AND
$filter
@ -761,7 +889,7 @@ class Blog
echo '< / span > ';
}
$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
echo '< span class = "blogpost_info" > ' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - < a href = "blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title = "' . get_lang('ReadPost') . '" > ' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '< / a > < / span > '."\n" ;
echo '< span class = "blogpost_info" > ' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - < a href = "blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title = "' . get_lang('ReadPost') . '" > ' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '< / a > < / span > ';
echo '< / div > ';
}
} else {
@ -877,8 +1005,7 @@ class Blog
$file_name_array = get_blog_attachment($blog_id, $post_id);
if (!empty($file_name_array))
{
if (!empty($file_name_array)) {
echo ' < br / > ';
echo Display::return_icon('attachment.gif',get_lang('Attachment'));
echo '< a href = "download.php?file=';
@ -904,8 +1031,7 @@ class Blog
}
// Display comment form
if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_add'))
{
if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
}
}
@ -938,15 +1064,20 @@ class Blog
AND user_id = '".(int)$_user['user_id']."'";
$result = Database::query($sql);
if(Database::num_rows($result) == 0) // Add rating
{
// Add rating
if (Database::num_rows($result) == 0) {
$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".Database::escape_string($rating)."')";
$result = Database::query($sql);
return true;
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_blogs_rating SET rating_id = iid WHERE iid = $id";
Database::query($sql);
}
else // Return
{
return true;
} else {
return false;
}
}
@ -967,7 +1098,11 @@ class Blog
// Calculate rating
$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$item_id."' AND rating_type = '".Database::escape_string($type)."' ";
WHERE
c_id = $course_id AND
blog_id = '".(int)$blog_id."' AND
item_id = '".(int)$item_id."' AND
rating_type = '".Database::escape_string($type)."' ";
$result = Database::query($sql);
$result = Database::fetch_array($result);
return round($result['rating'], 2);
@ -989,8 +1124,7 @@ class Blog
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
$course_id = api_get_course_int_id();
if($type == 'post')
{
if ($type == 'post') {
// Check if the user has already rated this post
$sql = "SELECT rating_id FROM $tbl_blogs_rating
WHERE c_id = $course_id AND
@ -999,18 +1133,15 @@ class Blog
AND rating_type = '".Database::escape_string($type)."'
AND user_id = '".(int)$_user['user_id']."'";
$result = Database::query($sql);
if(Database::num_rows($result) == 0) // Add rating
{
// Add rating
if (Database::num_rows($result) == 0) {
return ' - ' . get_lang('RateThis') . ': < form method = "get" action = "blog.php" style = "display: inline" id = "frm_rating_' . $type . '_' . $post_id . '" name = "frm_rating_' . $type . '_' . $post_id . '" > < select name = "rating" onchange = "document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()" > < option value = "" > -< / option > < option value = "1" > 1< / option > < option value = "2" > 2< / option > < option value = "3" > 3< / option > < option value = "4" > 4< / option > < option value = "5" > 5< / option > < option value = "6" > 6< / option > < option value = "7" > 7< / option > < option value = "8" > 8< / option > < option value = "9" > 9< / option > < option value = "10" > 10< / option > < / select > < input type = "hidden" name = "action" value = "view_post" / > < input type = "hidden" name = "type" value = "' . $type . '" / > < input type = "hidden" name = "do" value = "rate" / > < input type = "hidden" name = "blog_id" value = "' . $blog_id . '" / > < input type = "hidden" name = "post_id" value = "' . $post_id . '" / > < / form > ';
}
else // Return
{
} else {
return '';
}
}
if($type = 'comment')
{
if ($type = 'comment') {
// Check if the user has already rated this comment
$sql = "SELECT rating_id FROM $tbl_blogs_rating
WHERE c_id = $course_id AND blog_id = '".(int)$blog_id ."'
@ -1019,12 +1150,9 @@ class Blog
AND user_id = '".(int)$_user['user_id']."'";
$result = Database::query($sql);
if(Database::num_rows($result) == 0) // Add rating
{
if (Database::num_rows($result) == 0) {
return ' - ' . get_lang('RateThis') . ': < form method = "get" action = "blog.php" style = "display: inline" id = "frm_rating_' . $type . '_' . $comment_id . '" name = "frm_rating_' . $type . '_' . $comment_id . '" > < select name = "rating" onchange = "document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()" > < option value = "" > -< / option > < option value = "1" > 1< / option > < option value = "2" > 2< / option > < option value = "3" > 3< / option > < option value = "4" > 4< / option > < option value = "5" > 5< / option > < option value = "6" > 6< / option > < option value = "7" > 7< / option > < option value = "8" > 8< / option > < option value = "9" > 9< / option > < option value = "10" > 10< / option > < / select > < input type = "hidden" name = "action" value = "view_post" / > < input type = "hidden" name = "type" value = "' . $type . '" / > < input type = "hidden" name = "do" value = "rate" / > < input type = "hidden" name = "blog_id" value = "' . $blog_id . '" / > < input type = "hidden" name = "post_id" value = "' . $post_id . '" / > < input type = "hidden" name = "comment_id" value = "' . $comment_id . '" / > < / form > ';
}
else // Return
{
} else {
return '';
}
}
@ -1095,8 +1223,7 @@ class Blog
echo '< span class = "blogpost_text" > ' . $comment_text . '< / span > ';
$file_name_array=get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
if (!empty($file_name_array))
{
if (!empty($file_name_array)) {
echo '< br / > < br / > ';
echo Display::return_icon('attachment.gif',get_lang('Attachment'));
echo '< a href = "download.php?file=';
@ -1210,7 +1337,8 @@ class Blog
*
* @param Integer $blog_id
*/
public static function display_task_list ($blog_id) {
public static function display_task_list($blog_id)
{
global $charset;
$course_id = api_get_course_int_id();
@ -1252,8 +1380,7 @@ class Blog
$result = Database::query($sql);
while($task = Database::fetch_array($result))
{
while($task = Database::fetch_array($result)) {
$counter++;
$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
$delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
@ -1286,7 +1413,8 @@ class Blog
*
* @param Integer $blog_id
*/
public static function display_assigned_task_list ($blog_id) {
public static function display_assigned_task_list ($blog_id)
{
// Init
$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
@ -1353,7 +1481,23 @@ class Blog
public static function display_new_task_form ($blog_id)
{
// Init
$colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
$colors = array(
'FFFFFF',
'FFFF99',
'FFCC99',
'FF9933',
'FF6699',
'CCFF99',
'CC9966',
'66FF00',
'9966FF',
'CF3F3F',
'990033',
'669933',
'0033FF',
'003366',
'000000'
);
// form
echo '< form name = "add_task" method = "post" action = "blog.php?action=manage_tasks&blog_id=' . $blog_id . '" > ';
@ -1388,21 +1532,21 @@ class Blog
< / label >
< div class = "controls" > ';
echo "\t\t\t" . '< table class = "data_table" cellspacing = "0" style = "border-collapse:collapse; width:446px;" > ';
echo "\t\t\t\t" . '< tr > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th colspan = "2" style = "width:223px;" > ' . get_lang('ArticleManager') . '< / th > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th width:223px ; > ' . get_lang('CommentManager') . '< / th > ' . "\n" ;
echo "\t\t\t\t" . '< / tr > ' . "\n" ;
echo "\t\t\t\t" . '< tr > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th style = "width:111px;" > < label for = "articleDelete" > ' . get_lang('Delete') . '< / label > < / th > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th style = "width:112px;" > < label for = "articleEdit" > ' . get_lang('Edit') . '< / label > < / th > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th style = "width:223px;" > < label for = "commentsDelete" > ' . get_lang('Delete') . '< / label > < / th > ' . "\n" ;
echo "\t\t\t\t" . '< / tr > ' . "\n" ;
echo "\t\t\t\t" . '< tr > ' . "\n" ;
echo "\t\t\t\t\t" . ' < td style = "text-align:center;" > < input id = "articleDelete" name = "chkArticleDelete" type = "checkbox" / > < / td > ' . "\n" ;
echo "\t\t\t\t\t" . ' < td style = "text-align:center;" > < input id = "articleEdit" name = "chkArticleEdit" type = "checkbox" / > < / td > ' . "\n" ;
echo "\t\t\t\t\t" . ' < td style = "border:1px dotted #808080; text-align:center;" > < input id = "commentsDelete" name = "chkCommentsDelete" type = "checkbox" / > < / td > ' . "\n" ;
echo "\t\t\t\t" . '< / tr > ' . "\n" ;
echo "\t\t\t" . '< / table > ' . "\n" ;
echo "\t\t\t\t" . '< tr > ';
echo ' < th colspan = "2" style = "width:223px;" > ' . get_lang('ArticleManager') . '< / th > ' ;
echo ' < th width:223px ; > ' . get_lang('CommentManager') . '< / th > ' ;
echo "\t\t\t\t" . '< / tr > ';
echo "\t\t\t\t" . '< tr > ';
echo ' < th style = "width:111px;" > < label for = "articleDelete" > ' . get_lang('Delete') . '< / label > < / th > ' ;
echo ' < th style = "width:112px;" > < label for = "articleEdit" > ' . get_lang('Edit') . '< / label > < / th > ' ;
echo ' < th style = "width:223px;" > < label for = "commentsDelete" > ' . get_lang('Delete') . '< / label > < / th > ' ;
echo "\t\t\t\t" . '< / tr > ';
echo "\t\t\t\t" . '< tr > ';
echo ' < td style = "text-align:center;" > < input id = "articleDelete" name = "chkArticleDelete" type = "checkbox" / > < / td > ' ;
echo ' < td style = "text-align:center;" > < input id = "articleEdit" name = "chkArticleEdit" type = "checkbox" / > < / td > ' ;
echo ' < td style = "border:1px dotted #808080; text-align:center;" > < input id = "commentsDelete" name = "chkCommentsDelete" type = "checkbox" / > < / td > ' ;
echo "\t\t\t\t" . '< / tr > ';
echo "\t\t\t" . '< / table > ';
echo ' < / div >
< / div > ';
@ -1478,27 +1622,27 @@ class Blog
while ($row = Database::fetch_array($result))
$arrPermissions[] = $row['action'];
echo "\t" . '< tr > ' . "\n" ;
echo "\t\t" . '< td style = "text-align:right; vertical-align:top;" > ' . get_lang('TaskManager') . ': < / td > ' . "\n" ;
echo "\t\t" . '< td > ' . "\n" ;
echo "\t" . '< tr > ' ;
echo "\t\t" . '< td style = "text-align:right; vertical-align:top;" > ' . get_lang('TaskManager') . ': < / td > ';
echo "\t\t" . '< td > ';
echo "\t\t\t" . '< table class = "data_table" cellspacing = "0" style = "border-collapse:collapse; width:446px;" > ';
echo "\t\t\t\t" . '< tr > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th colspan = "2" style = "width:223px;" > ' . get_lang('ArticleManager') . '< / th > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th width:223px ; > ' . get_lang('CommentManager') . '< / th > ' . "\n" ;
echo "\t\t\t\t" . '< / tr > ' . "\n" ;
echo "\t\t\t\t" . '< tr > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th style = "width:111px;" > < label for = "articleDelete" > ' . get_lang('Delete') . '< / label > < / th > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th style = "width:112px;" > < label for = "articleEdit" > ' . get_lang('Edit') . '< / label > < / th > ' . "\n" ;
echo "\t\t\t\t\t" . ' < th style = "width:223px;" > < label for = "commentsDelete" > ' . get_lang('Delete') . '< / label > < / th > ' . "\n" ;
echo "\t\t\t\t" . '< / tr > ' . "\n" ;
echo "\t\t\t\t" . '< tr > ' . "\n" ;
echo "\t\t\t\t\t" . ' < td style = "text-align:center;" > < input ' . ( ( in_array ( ' article_delete ' , $ arrPermissions ) ) ? ' checked ' : ' ' ) . ' id = "articleDelete" name = "chkArticleDelete" type = "checkbox" / > < / td > ' . "\n" ;
echo "\t\t\t\t\t" . ' < td style = "text-align:center;" > < input ' . ( ( in_array ( ' article_edit ' , $ arrPermissions ) ) ? ' checked ' : ' ' ) . ' id = "articleEdit" name = "chkArticleEdit" type = "checkbox" / > < / td > ' . "\n" ;
echo "\t\t\t\t\t" . ' < td style = "text-align:center;" > < input ' . ( ( in_array ( ' article_comments_delete ' , $ arrPermissions ) ) ? ' checked ' : ' ' ) . ' id = "commentsDelete" name = "chkCommentsDelete" type = "checkbox" / > < / td > ' . "\n" ;
echo "\t\t\t\t" . '< / tr > ' . "\n" ;
echo "\t\t\t" . '< / table > ' . "\n" ;
echo "\t\t" . '< / td > ' . "\n" ;
echo "\t" . '< / tr > ' . "\n" ;
echo "\t\t\t\t" . '< tr > ';
echo ' < th colspan = "2" style = "width:223px;" > ' . get_lang('ArticleManager') . '< / th > ' ;
echo ' < th width:223px ; > ' . get_lang('CommentManager') . '< / th > ' ;
echo "\t\t\t\t" . '< / tr > ';
echo "\t\t\t\t" . '< tr > ';
echo ' < th style = "width:111px;" > < label for = "articleDelete" > ' . get_lang('Delete') . '< / label > < / th > ' ;
echo ' < th style = "width:112px;" > < label for = "articleEdit" > ' . get_lang('Edit') . '< / label > < / th > ' ;
echo ' < th style = "width:223px;" > < label for = "commentsDelete" > ' . get_lang('Delete') . '< / label > < / th > ' ;
echo "\t\t\t\t" . '< / tr > ';
echo "\t\t\t\t" . '< tr > ';
echo ' < td style = "text-align:center;" > < input ' . ( ( in_array ( ' article_delete ' , $ arrPermissions ) ) ? ' checked ' : ' ' ) . ' id = "articleDelete" name = "chkArticleDelete" type = "checkbox" / > < / td > ' ;
echo ' < td style = "text-align:center;" > < input ' . ( ( in_array ( ' article_edit ' , $ arrPermissions ) ) ? ' checked ' : ' ' ) . ' id = "articleEdit" name = "chkArticleEdit" type = "checkbox" / > < / td > ' ;
echo ' < td style = "text-align:center;" > < input ' . ( ( in_array ( ' article_comments_delete ' , $ arrPermissions ) ) ? ' checked ' : ' ' ) . ' id = "commentsDelete" name = "chkCommentsDelete" type = "checkbox" / > < / td > ' ;
echo "\t\t\t\t" . '< / tr > ';
echo "\t\t\t" . '< / table > ';
echo "\t\t" . '< / td > ';
echo "\t" . '< / tr > ';
/* end of edit */
echo '< tr >
@ -1689,9 +1833,24 @@ class Blog
}
}
public static function edit_assigned_task ($blog_id, $user_id, $task_id, $target_date, $old_user_id, $old_task_id, $old_target_date)
{
/**
* @param $blog_id
* @param $user_id
* @param $task_id
* @param $target_date
* @param $old_user_id
* @param $old_task_id
* @param $old_target_date
*/
public static function edit_assigned_task(
$blog_id,
$user_id,
$task_id,
$target_date,
$old_user_id,
$old_task_id,
$old_target_date
) {
$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
$course_id = api_get_course_int_id();
@ -1705,7 +1864,7 @@ class Blog
task_id = " . (int)$task_id . "
";
$result = @ Database::query($sql);
$result = Database::query($sql);
$row = Database::fetch_assoc($result);
if ($row['number'] == 0 || ($row['number'] != 0 & & $task_id == $old_task_id & & $user_id == $old_user_id)) {
@ -1733,7 +1892,8 @@ class Blog
* @param Integer $blog_id
* @param unknown_type $task_id
*/
public static function display_select_task_post ($blog_id, $task_id) {
public static function display_select_task_post($blog_id, $task_id)
{
// Init
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
@ -1764,9 +1924,10 @@ class Blog
$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
echo '< a href = "blog.php?action=execute_task&blog_id=' . $blog_id . '&task_id=' . $task_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" > '.stripslashes($blog_post['title']) . '< / a > , ' . get_lang('WrittenBy') . ' ' . stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))) . '< br / > ';
}
} else
} else {
echo get_lang('NoArticles');
}
}
/**
* Subscribes a user to a given blog
@ -1775,7 +1936,8 @@ class Blog
* @param Integer $blog_id
* @param Integer $user_id
*/
public static function set_user_subscribed ($blog_id,$user_id) {
public static function set_user_subscribed($blog_id, $user_id)
{
// Init
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
@ -1783,14 +1945,31 @@ class Blog
$course_id = api_get_course_int_id();
// Subscribe the user
$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id ) VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
$result = Database::query($sql);
// Give this user basic rights
$sql="INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action) VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
$result = Database::query($sql);
$sql="INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action) VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_user_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
$result = Database::query($sql);
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $tbl_user_permissions SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
/**
@ -1800,17 +1979,20 @@ class Blog
* @param Integer $blog_id
* @param Integer $user_id
*/
public static function set_user_unsubscribed ($blog_id, $user_id) {
public static function set_user_unsubscribed($blog_id, $user_id)
{
// Init
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
// Unsubscribe the user
$sql = "DELETE FROM $tbl_blogs_rel_user WHERE blog_id = '".(int)$blog_id."' AND user_id = '".(int)$user_id."'";
$result = @Database::query($sql);
$sql = "DELETE FROM $tbl_blogs_rel_user
WHERE blog_id = '".(int)$blog_id."' AND user_id = '".(int)$user_id."'";
$result = Database::query($sql);
// Remove this user's permissions.
$sql = "DELETE FROM $tbl_user_permissions WHERE user_id = '".(int)$user_id."'";
$sql = "DELETE FROM $tbl_user_permissions
WHERE user_id = '".(int)$user_id."'";
$result = Database::query($sql);
}
@ -1862,7 +2044,11 @@ class Blog
$column_header[] = array(get_lang('Email'), false, '');
$column_header[] = array(get_lang('Register'), false, '');
$student_list = CourseManager :: get_student_list_from_course_code($currentCourse, false, $session_id);
$student_list = CourseManager:: get_student_list_from_course_code(
$currentCourse,
false,
$session_id
);
$user_data = array();
// Add users that are not in this blog to the list.
@ -1950,12 +2136,12 @@ class Blog
$course_id = api_get_course_int_id();
$sql_query = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
$sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
FROM $tbl_users user INNER JOIN $tbl_blogs_rel_user blogs_rel_user
ON user.user_id = blogs_rel_user.user_id
WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
if (!($sql_result = Database::query($sql_query ))) {
if (!($sql_result = Database::query($sql))) {
return false;
}
@ -2339,8 +2525,8 @@ class Blog
$url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "& ".api_get_cidreq();
$title = $info_log[0];
$image = '< img src = "../img/blog.gif" border = "0" align = "absmiddle" alt = "' . $title . '" > '."\n" ;
$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 . "\n" ;
$image = '< img src = "../img/blog.gif" border = "0" align = "absmiddle" alt = "' . $title . '" > ';
$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;
$list_body_blog[] = $list_name;
$list_body_blog[] = $info_log[1];
@ -2462,11 +2648,11 @@ function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null)
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path.$courseDir;
$sql= 'SELECT path FROM '.$blog_table_attachment.' WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'" '.$where;
$sql = 'SELECT path FROM '.$blog_table_attachment.'
WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'" '.$where;
$result=Database::query($sql);
while ($row=Database::fetch_row($result))
{
while ($row=Database::fetch_row($result)) {
$file=$updir.'/'.$row[0];
if (Security::check_abs_path($file,$updir) )
{
@ -2517,7 +2703,8 @@ function get_blog_post_from_user($course_code, $user_id)
* @param string db course name
* @param int user id
*/
function get_blog_comment_from_user($course_code, $user_id) {
function get_blog_comment_from_user($course_code, $user_id)
{
$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
$tbl_blog_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS);
$user_id = intval($user_id);