blog_admin.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * BLOG HOMEPAGE
  5. * This file takes care of all blog navigation and displaying.
  6. * @package chamilo.blogs
  7. */
  8. require_once '../inc/global.inc.php';
  9. $current_course_tool = TOOL_BLOGS;
  10. $this_section = SECTION_COURSES;
  11. $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  12. /* ACCESS RIGHTS */
  13. // notice for unauthorized people.
  14. api_protect_course_script(true);
  15. // ONLY USERS REGISTERED IN THE COURSE
  16. if ((!$is_allowed_in_course || !$is_courseMember) && !api_is_allowed_to_edit()) {
  17. api_not_allowed(true);//print headers/footers
  18. }
  19. if (api_is_allowed_to_edit()) {
  20. $nameTools = get_lang("blog_management");
  21. // showing the header if we are not in the learning path, if we are in
  22. // the learning path, we do not include the banner so we have to explicitly
  23. // include the stylesheet, which is normally done in the header
  24. if ($_GET['origin'] != 'learnpath') {
  25. $interbreadcrumb[]= array ('url' => 'blog_admin.php?','name' => $nameTools);
  26. $my_url='';
  27. if (isset($_GET['action']) && $_GET['action']=='add') {
  28. $current_section=get_lang('AddBlog');
  29. $my_url='action=add';
  30. } elseif (isset($_GET['action']) && $_GET['action']=='edit') {
  31. $current_section=get_lang('EditBlog');
  32. $my_url='action=edit&amp;blog_id='.Security::remove_XSS($_GET['blog_id']);
  33. }
  34. Display::display_header('');
  35. }
  36. echo '<div class="actions">';
  37. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add'>",
  38. Display::return_icon('new_blog.png',get_lang('AddBlog'),'',ICON_SIZE_MEDIUM)."</a>";
  39. echo '</div>';
  40. if (!empty($_POST['new_blog_submit']) AND !empty($_POST['blog_name'])) {
  41. if (isset($_POST['blog_name'])) {
  42. Blog::create_blog($_POST['blog_name'], $_POST['blog_subtitle']);
  43. Display::display_confirmation_message(get_lang('BlogStored'));
  44. }
  45. }
  46. if (!empty($_POST['edit_blog_submit']) AND !empty($_POST['blog_name'])) {
  47. if (strlen(trim($_POST['blog_name']))>0) {
  48. Blog::edit_blog($_POST['blog_id'], $_POST['blog_name'], $_POST['blog_subtitle']);
  49. Display::display_confirmation_message(get_lang('BlogEdited'));
  50. }
  51. }
  52. if (isset($_GET['action']) && $_GET['action'] == 'visibility') {
  53. Blog::change_blog_visibility(intval($_GET['blog_id']));
  54. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  55. }
  56. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  57. Blog::delete_blog(intval($_GET['blog_id']));
  58. Display::display_confirmation_message(get_lang('BlogDeleted'));
  59. }
  60. /*
  61. DISPLAY
  62. */
  63. //api_display_tool_title($nameTools);
  64. //api_introductionsection(TOOL_BLOG);
  65. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  66. // we show the form if
  67. // 1. no post data
  68. // 2. there is post data and one of the required form elements is empty
  69. if (!$_POST OR (!empty($_POST) AND (empty($_POST['new_blog_submit']) OR empty($_POST['blog_name'])))) {
  70. // if there is post data there is certainly an error in the form
  71. /*if ($_POST){
  72. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  73. }*/
  74. /*if (strlen($_POST['blog_name'])==0) {
  75. if (count($_POST)>0) {
  76. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  77. }
  78. }*/
  79. Blog::display_new_blog_form();
  80. }
  81. }
  82. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  83. // we show the form if
  84. // 1. no post data
  85. // 2. there is post data and one of the three form elements is empty
  86. if (!$_POST OR (!empty($_POST) AND (empty($_POST['edit_blog_submit']) OR empty($_POST['blog_name']) ))) {
  87. // if there is post data there is certainly an error in the form
  88. if ($_POST) {
  89. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  90. }
  91. Blog::display_edit_blog_form(intval($_GET['blog_id']));
  92. }
  93. }
  94. Blog::display_blog_list();
  95. } else {
  96. api_not_allowed(true);
  97. }
  98. // Display the footer
  99. Display::display_footer();