blog_admin.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. require_once __DIR__.'/../inc/global.inc.php';
  8. $current_course_tool = TOOL_BLOGS;
  9. $this_section = SECTION_COURSES;
  10. api_protect_course_script(true);
  11. // ONLY USERS REGISTERED IN THE COURSE
  12. if ((!api_is_allowed_in_course() || !api_is_allowed_in_course()) && !api_is_allowed_to_edit()) {
  13. api_not_allowed(true); //print headers/footers
  14. }
  15. $origin = api_get_origin();
  16. $action = isset($_GET['action']) ? $_GET['action'] : '';
  17. if (api_is_allowed_to_edit()) {
  18. $nameTools = get_lang('Project management');
  19. // showing the header if we are not in the learning path, if we are in
  20. // the learning path, we do not include the banner so we have to explicitly
  21. // include the stylesheet, which is normally done in the header
  22. if ($origin != 'learnpath') {
  23. $interbreadcrumb[] = [
  24. 'url' => 'blog_admin.php?'.api_get_cidreq(),
  25. 'name' => $nameTools,
  26. ];
  27. $my_url = '';
  28. if ($action == 'add') {
  29. $current_section = get_lang('Create a new project');
  30. $my_url = 'action=add';
  31. } elseif ($action == 'edit') {
  32. $current_section = get_lang('Edit a project');
  33. $my_url = 'action=edit&amp;blog_id='.Security::remove_XSS($_GET['blog_id']);
  34. }
  35. Display::display_header('');
  36. }
  37. echo '<div class="actions">';
  38. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add'>",
  39. Display::return_icon('new_blog.png', get_lang('Create a new project'), '', ICON_SIZE_MEDIUM)."</a>";
  40. echo '</div>';
  41. if (!empty($_POST['new_blog_submit']) && !empty($_POST['blog_name'])) {
  42. if (isset($_POST['blog_name'])) {
  43. Blog::addBlog($_POST['blog_name'], $_POST['blog_subtitle']);
  44. echo Display::return_message(get_lang('The project has been added.'), 'confirmation');
  45. }
  46. }
  47. if (!empty($_POST['edit_blog_submit']) && !empty($_POST['blog_name'])) {
  48. if (strlen(trim($_POST['blog_name'])) > 0) {
  49. Blog::editBlog($_POST['blog_id'], $_POST['blog_name'], $_POST['blog_subtitle']);
  50. echo Display::return_message(get_lang('The project has been edited.'), 'confirmation');
  51. }
  52. }
  53. if (isset($_GET['action']) && $_GET['action'] == 'visibility') {
  54. Blog::changeBlogVisibility(intval($_GET['blog_id']));
  55. echo Display::return_message(get_lang('The visibility has been changed.'), 'confirmation');
  56. }
  57. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  58. Blog::deleteBlog(intval($_GET['blog_id']));
  59. echo Display::return_message(get_lang('The project has been deleted.'), 'confirmation');
  60. }
  61. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  62. // we show the form if
  63. // 1. no post data
  64. // 2. there is post data and one of the required form elements is empty
  65. if (!$_POST || (!empty($_POST) && (empty($_POST['new_blog_submit']) || empty($_POST['blog_name'])))) {
  66. Blog::displayBlogCreateForm();
  67. }
  68. }
  69. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  70. // we show the form if
  71. // 1. no post data
  72. // 2. there is post data and one of the three form elements is empty
  73. if (!$_POST || (!empty($_POST) && (empty($_POST['edit_blog_submit']) || empty($_POST['blog_name'])))) {
  74. // if there is post data there is certainly an error in the form
  75. if ($_POST) {
  76. echo Display::return_message(get_lang('The form contains incorrect or incomplete data. Please check your input.'), 'error');
  77. }
  78. Blog::displayBlogEditForm(intval($_GET['blog_id']));
  79. }
  80. }
  81. Blog::displayBlogsList();
  82. } else {
  83. api_not_allowed(true);
  84. }
  85. // Display the footer
  86. Display::display_footer();