blog_admin.php 4.2 KB

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