diff --git a/main/blog/blog_admin.php b/main/blog/blog_admin.php index ba35fbd1af..49b688a69f 100644 --- a/main/blog/blog_admin.php +++ b/main/blog/blog_admin.php @@ -59,12 +59,25 @@ if (api_is_allowed_to_edit()) // showing the header if we are not in the learning path, if we are in // the learning path, we do not include the banner so we have to explicitly // include the stylesheet, which is normally done in the header - if ($_GET['origin'] != 'learnpath') - { - Display::display_header($nameTools,'Blogs'); - } - else - { + if ($_GET['origin'] != 'learnpath') { + $interbreadcrumb[]= array ( + 'url' => 'blog_admin.php?', + 'name' => $nameTools + ); + $my_url=''; + if (isset($_GET['action']) && $_GET['action']=='add') { + $current_section=get_lang('AddBlog'); + $my_url='action=add'; + } elseif (isset($_GET['action']) && $_GET['action']=='edit') { + $current_section=get_lang('EditBlog'); + $my_url='action=edit&blog_id='.Security::remove_XSS($_GET['blog_id']); + } + $interbreadcrumb[]= array ( + 'url' => 'blog_admin.php?'.$my_url, + 'name' => $current_section + ); + Display::display_header(''); + } else { echo ""; } /* @@ -107,32 +120,35 @@ if (api_is_allowed_to_edit()) //api_introductionsection(TOOL_BLOG); - if (isset($_GET['action']) && $_GET['action'] == 'add') - { + if (isset($_GET['action']) && $_GET['action'] == 'add') { // we show the form if // 1. no post data // 2. there is post data and one of the three form elements is empty - if (!$_POST OR (!empty($_POST) AND (empty($_POST['Submit']) OR empty($_POST['blog_name']) OR empty($_POST['blog_subtitle'])))) - { + if (!$_POST OR (!empty($_POST) AND (empty($_POST['Submit']) OR empty($_POST['blog_name']) OR empty($_POST['blog_subtitle'])))) { // if there is post data there is certainly an error in the form - if ($_POST) - { + /*if ($_POST){ + Display::display_error_message(get_lang('FormHasErrorsPleaseComplete')); + }*/ + + if (strlen($_POST['blog_name'])==0 || strlen($_POST['blog_subtitle'])==0 ) { + if (count($_POST)>0) { Display::display_error_message(get_lang('FormHasErrorsPleaseComplete')); } + + + } Blog::display_new_blog_form(); } } - if (isset($_GET['action']) && $_GET['action'] == 'edit') - { + if (isset($_GET['action']) && $_GET['action'] == 'edit') { // we show the form if // 1. no post data // 2. there is post data and one of the three form elements is empty if (!$_POST OR (!empty($_POST) AND (empty($_POST['edit_blog_submit']) OR empty($_POST['blog_name']) OR empty($_POST['blog_subtitle'])))) { // if there is post data there is certainly an error in the form - if ($_POST) - { + if ($_POST) { Display::display_error_message(get_lang('FormHasErrorsPleaseComplete')); } Blog::display_edit_blog_form(Database::escape_string((int)$_GET['blog_id'])); @@ -142,17 +158,17 @@ if (api_is_allowed_to_edit()) echo '
'; echo "",Display::return_icon('blog_new.gif',get_lang('AddBlog')),get_lang('AddBlog').""; echo '
'; - echo ""; + /*echo "
"; echo "", "\n", "\n", "\n", "\n"; - Blog::display_blog_list(); - echo "
",get_lang('Title'),"",get_lang('Subtitle'),"",get_lang('Modify'),"
"; - } - else - { + + echo "";*/ + Blog::display_blog_list(); + + } else { api_not_allowed(true); } diff --git a/main/inc/lib/blog.lib.php b/main/inc/lib/blog.lib.php index acff8f8809..b0155bdb1a 100644 --- a/main/inc/lib/blog.lib.php +++ b/main/inc/lib/blog.lib.php @@ -133,33 +133,39 @@ class Blog function create_blog($title, $subtitle) { global $_user; - + $current_date=date('Y-m-d H:i:s',time()); // Tabel definitions $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); - // Create the blog - $sql = "INSERT INTO $tbl_blogs (`blog_name`, `blog_subtitle`, `date_creation`, `visibility` ) - VALUES ('".Database::escape_string($title)."', '".Database::escape_string($subtitle)."', NOW(), '1');"; - api_sql_query($sql, __FILE__, __LINE__); - $this_blog_id = Database::get_last_insert_id(); - - // Make first post. :) - $sql = "INSERT INTO $tbl_blogs_posts (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` ) - VALUES ('".get_lang("Welcome")."', '" . get_lang('FirstPostText')."', NOW(), '".Database::escape_string((int)$this_blog_id)."', '".Database::escape_string((int)$_user['user_id'])."');"; - api_sql_query($sql, __FILE__, __LINE__); - - // Put it on course homepage - $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) - VALUES ('".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0)"; - api_sql_query($sql, __FILE__, __LINE__); - - // Subscribe the teacher to this blog - Blog::set_user_subscribed((int)$this_blog_id,(int)$_user['user_id']); - - return void; + //verified if exist blog + $sql='SELECT COUNT(*) as count FROM '.$tbl_blogs.' WHERE blog_name="'.$title.'" AND blog_subtitle="'.$subtitle.'";'; + $res=Database::query($sql,__FILE__,__LINE__); + $info_count=Database::result($res,0,0); + if ($info_count==0) { + // Create the blog + $sql = "INSERT INTO $tbl_blogs (`blog_name`, `blog_subtitle`, `date_creation`, `visibility` ) + VALUES ('".Database::escape_string($title)."', '".Database::escape_string($subtitle)."', '".$current_date."', '1');"; + api_sql_query($sql, __FILE__, __LINE__); + $this_blog_id = Database::get_last_insert_id(); + + // Make first post. :) + $sql = "INSERT INTO $tbl_blogs_posts (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` ) + VALUES ('".get_lang("Welcome")."', '" . get_lang('FirstPostText')."','".$current_date."', '".Database::escape_string((int)$this_blog_id)."', '".Database::escape_string((int)$_user['user_id'])."');"; + api_sql_query($sql, __FILE__, __LINE__); + + // Put it on course homepage + $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) + VALUES ('".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0)"; + api_sql_query($sql, __FILE__, __LINE__); + + // Subscribe the teacher to this blog + Blog::set_user_subscribed((int)$this_blog_id,(int)$_user['user_id']); + + return void; + } } /** @@ -259,7 +265,8 @@ class Blog $upload_ok=true; $has_attachment=false; - + $current_date=date('Y-m-d H:i:s',time()); + if(!empty($_FILES['user_upload']['name'])) { require_once('fileUpload.lib.php'); @@ -274,7 +281,7 @@ class Blog // Create the post $sql = "INSERT INTO " . $tbl_blogs_posts." (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` ) - VALUES ('".Database::escape_string($title)."', '".Database::escape_string($full_text)."', NOW(), '".(int)$blog_id."', '".(int)$_user['user_id']."');"; + VALUES ('".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');"; api_sql_query($sql, __FILE__, __LINE__); $last_post_id=Database::insert_id(); @@ -398,7 +405,8 @@ class Blog $upload_ok=true; $has_attachment=false; - + $current_date=date('Y-m-d H:i:s',time()); + if(!empty($_FILES['user_upload']['name'])) { require_once('fileUpload.lib.php'); @@ -413,7 +421,7 @@ class Blog // Create the comment $sql = "INSERT INTO $tbl_blogs_comments (`title`, `comment`, `author_id`, `date_creation`, `blog_id`, `post_id`, `parent_comment_id`, `task_id` ) - VALUES ('".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."', NOW(), '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')"; + VALUES ('".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')"; api_sql_query($sql, __FILE__, __LINE__); // Empty post values, or they are shown on the page again @@ -2854,10 +2862,52 @@ class Blog global $charset; // Init $counter = 0; + $tbl_blogs = Database::get_course_table(TABLE_BLOGS); + $sql = 'SELECT blog_name,blog_subtitle,visibility,blog_id FROM '.$tbl_blogs.' ORDER BY date_creation DESC '; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row_project=Database::fetch_row($result)) { + $list_info[]=$row_project; + } + $list_content_blog=array(); + $list_body_blog=array(); - $sql = "SELECT `blog_id`, `blog_name`, `blog_subtitle`, `visibility` FROM $tbl_blogs ORDER BY `blog_name`"; + foreach($list_info as $key => $info_log) { + + $list_body_blog[]=$info_log[0]; + $list_body_blog[]=$info_log[1]; + + $visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible'; + $visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible'; + $my_image.=''; + $my_image.=''; + $my_image.="\n"; + $my_image.=''; + $my_image.=''; + $my_image.="\n"; + $my_image.=''; + $my_image.=''; + $my_image.="\n"; + + $list_body_blog[]=$my_image; + $my_image=''; + + $list_content_blog[]=$list_body_blog; + $list_body_blog=array(); + } + $parameters=''; + //$parameters=array('action'=>Security::remove_XSS($_GET['action'])); + + $table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project'); + $table->set_additional_parameters($parameters); + $table->set_header(0, get_lang('Title')); + $table->set_header(1, get_lang('Subtitle')); + $table->set_header(2, get_lang('Modify')); + $table->display(); + $list_content_blog=array(); + /*$sql = "SELECT `blog_id`, `blog_name`, `blog_subtitle`, `visibility` FROM $tbl_blogs ORDER BY `blog_name`"; $result = api_sql_query($sql, __FILE__, __LINE__); while($blog = Database::fetch_array($result)) @@ -2884,8 +2934,9 @@ class Blog "\n", '', ''; - } + }*/ } + }