blog_admin.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 (empty($_GET['origin']) || $_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']) && !empty($_POST['blog_name'])) {
  41. if (isset($_POST['blog_name'])) {
  42. Blog::addBlog($_POST['blog_name'], $_POST['blog_subtitle']);
  43. Display::display_confirmation_message(get_lang('BlogStored'));
  44. }
  45. }
  46. if (!empty($_POST['edit_blog_submit']) && !empty($_POST['blog_name'])) {
  47. if (strlen(trim($_POST['blog_name']))>0) {
  48. Blog::editBlog($_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::changeBlogVisibility(intval($_GET['blog_id']));
  54. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  55. }
  56. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  57. Blog::deleteBlog(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 || (!empty($_POST) && (empty($_POST['new_blog_submit']) || empty($_POST['blog_name'])))) {
  70. Blog::displayBlogCreateForm();
  71. }
  72. }
  73. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  74. // we show the form if
  75. // 1. no post data
  76. // 2. there is post data and one of the three form elements is empty
  77. if (!$_POST || (!empty($_POST) && (empty($_POST['edit_blog_submit']) || empty($_POST['blog_name']) ))) {
  78. // if there is post data there is certainly an error in the form
  79. if ($_POST) {
  80. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  81. }
  82. Blog::displayBlogEditForm(intval($_GET['blog_id']));
  83. }
  84. }
  85. Blog::displayBlogsList();
  86. } else {
  87. api_not_allowed(true);
  88. }
  89. // Display the footer
  90. Display::display_footer();