blog_admin.php 4.3 KB

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