blog_admin.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. *
  7. * @package chamilo.blogs
  8. */
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $current_course_tool = TOOL_BLOGS;
  11. $this_section = SECTION_COURSES;
  12. api_protect_course_script(true);
  13. // ONLY USERS REGISTERED IN THE COURSE
  14. if ((!api_is_allowed_in_course() || !api_is_allowed_in_course()) && !api_is_allowed_to_edit()) {
  15. api_not_allowed(true); //print headers/footers
  16. }
  17. $origin = api_get_origin();
  18. $action = isset($_GET['action']) ? $_GET['action'] : '';
  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 ($origin != 'learnpath') {
  25. $interbreadcrumb[] = [
  26. 'url' => 'blog_admin.php?'.api_get_cidreq(),
  27. 'name' => $nameTools,
  28. ];
  29. $my_url = '';
  30. if ($action == 'add') {
  31. $current_section = get_lang('AddBlog');
  32. $my_url = 'action=add';
  33. } elseif ($action == 'edit') {
  34. $current_section = get_lang('EditBlog');
  35. $my_url = 'action=edit&amp;blog_id='.Security::remove_XSS($_GET['blog_id']);
  36. }
  37. Display::display_header('');
  38. }
  39. echo '<div class="actions">';
  40. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add'>",
  41. Display::return_icon('new_blog.png', get_lang('AddBlog'), '', ICON_SIZE_MEDIUM)."</a>";
  42. echo '</div>';
  43. if (!empty($_POST['new_blog_submit']) && !empty($_POST['blog_name'])) {
  44. if (isset($_POST['blog_name'])) {
  45. Blog::addBlog($_POST['blog_name'], $_POST['blog_subtitle']);
  46. echo Display::return_message(get_lang('BlogStored'), 'confirmation');
  47. }
  48. }
  49. if (!empty($_POST['edit_blog_submit']) && !empty($_POST['blog_name'])) {
  50. if (strlen(trim($_POST['blog_name'])) > 0) {
  51. Blog::editBlog($_POST['blog_id'], $_POST['blog_name'], $_POST['blog_subtitle']);
  52. echo Display::return_message(get_lang('BlogEdited'), 'confirmation');
  53. }
  54. }
  55. if (isset($_GET['action']) && $_GET['action'] == 'visibility') {
  56. Blog::changeBlogVisibility(intval($_GET['blog_id']));
  57. echo Display::return_message(get_lang('VisibilityChanged'), 'confirmation');
  58. }
  59. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  60. Blog::deleteBlog(intval($_GET['blog_id']));
  61. echo Display::return_message(get_lang('BlogDeleted'), 'confirmation');
  62. }
  63. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  64. // we show the form if
  65. // 1. no post data
  66. // 2. there is post data and one of the required form elements is empty
  67. if (!$_POST || (!empty($_POST) && (empty($_POST['new_blog_submit']) || empty($_POST['blog_name'])))) {
  68. Blog::displayBlogCreateForm();
  69. }
  70. }
  71. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  72. // we show the form if
  73. // 1. no post data
  74. // 2. there is post data and one of the three form elements is empty
  75. if (!$_POST || (!empty($_POST) && (empty($_POST['edit_blog_submit']) || empty($_POST['blog_name'])))) {
  76. // if there is post data there is certainly an error in the form
  77. if ($_POST) {
  78. echo Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error');
  79. }
  80. Blog::displayBlogEditForm(intval($_GET['blog_id']));
  81. }
  82. }
  83. Blog::displayBlogsList();
  84. } else {
  85. api_not_allowed(true);
  86. }
  87. // Display the footer
  88. Display::display_footer();