blog_admin.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php //$Id: announcements.php 16702 2008-11-10 13:02:30Z elixir_inter $
  2. /*
  3. /* For licensing terms, see /chamilo_license.txt */
  4. /**
  5. ==============================================================================
  6. BLOG HOMEPAGE
  7. This file takes care of all blog navigation and displaying.
  8. @package dokeos.blogs
  9. ==============================================================================
  10. */
  11. // name of the language file that needs to be included
  12. $language_file = "blog";
  13. require_once '../inc/global.inc.php';
  14. $this_section=SECTION_COURSES;
  15. $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  16. /* ------------ ACCESS RIGHTS ------------ */
  17. // notice for unauthorized people.
  18. api_protect_course_script(true);
  19. //------------ ONLY USERS REGISTERED IN THE COURSE----------------------
  20. if((!$is_allowed_in_course || !$is_courseMember) && !api_is_allowed_to_edit())
  21. {
  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 (
  32. 'url' => 'blog_admin.php?',
  33. 'name' => $nameTools
  34. );
  35. $my_url='';
  36. if (isset($_GET['action']) && $_GET['action']=='add') {
  37. $current_section=get_lang('AddBlog');
  38. $my_url='action=add';
  39. } elseif (isset($_GET['action']) && $_GET['action']=='edit') {
  40. $current_section=get_lang('EditBlog');
  41. $my_url='action=edit&amp;blog_id='.Security::remove_XSS($_GET['blog_id']);
  42. }
  43. $interbreadcrumb[]= array (
  44. 'url' => 'blog_admin.php?'.$my_url,
  45. 'name' => $current_section
  46. );
  47. Display::display_header('');
  48. } else {
  49. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  50. }
  51. echo '<div class="actions">';
  52. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add'>",Display::return_icon('blog_new.gif',get_lang('AddBlog')),get_lang('AddBlog')."</a>";
  53. echo '</div>';
  54. /*
  55. ==============================================================================
  56. PROCESSING..
  57. ==============================================================================
  58. */
  59. $get_blog_name = Security::remove_XSS($_POST['blog_name']);
  60. $get_blog_subtitle = Security::remove_XSS($_POST['blog_subtitle']);
  61. $get_blog_id = Security::remove_XSS($_POST['blog_id']);
  62. if (!empty($_POST['new_blog_submit']) AND !empty($_POST['blog_name'])) {
  63. if (strlen(trim($_POST['blog_name']))>0) {
  64. Blog::create_blog($get_blog_name,$get_blog_subtitle);
  65. Display::display_confirmation_message(get_lang('BlogStored'));
  66. }
  67. }
  68. if (!empty($_POST['edit_blog_submit']) AND !empty($_POST['blog_name'])) {
  69. if (strlen(trim($_POST['blog_name']))>0) {
  70. Blog::edit_blog($get_blog_id,$get_blog_name,$get_blog_subtitle);
  71. Display::display_confirmation_message(get_lang('BlogEdited'));
  72. }
  73. }
  74. if (isset($_GET['action']) && $_GET['action'] == 'visibility') {
  75. Blog::change_blog_visibility(Database::escape_string((int)$_GET['blog_id']));
  76. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  77. }
  78. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  79. Blog::delete_blog(Database::escape_string((int)$_GET['blog_id']));
  80. Display::display_confirmation_message(get_lang('BlogDeleted'));
  81. }
  82. /*
  83. ==============================================================================
  84. DISPLAY
  85. ==============================================================================
  86. */
  87. //api_display_tool_title($nameTools);
  88. //api_introductionsection(TOOL_BLOG);
  89. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  90. // we show the form if
  91. // 1. no post data
  92. // 2. there is post data and one of the required form elements is empty
  93. if (!$_POST OR (!empty($_POST) AND (empty($_POST['new_blog_submit']) OR empty($_POST['blog_name'])))) {
  94. // if there is post data there is certainly an error in the form
  95. /*if ($_POST){
  96. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  97. }*/
  98. if (strlen($_POST['blog_name'])==0) {
  99. if (count($_POST)>0) {
  100. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  101. }
  102. }
  103. Blog::display_new_blog_form();
  104. }
  105. }
  106. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  107. // we show the form if
  108. // 1. no post data
  109. // 2. there is post data and one of the three form elements is empty
  110. if (!$_POST OR (!empty($_POST) AND (empty($_POST['edit_blog_submit']) OR empty($_POST['blog_name']) )))
  111. {
  112. // if there is post data there is certainly an error in the form
  113. if ($_POST) {
  114. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  115. }
  116. Blog::display_edit_blog_form(Database::escape_string((int)$_GET['blog_id']));
  117. }
  118. }
  119. Blog::display_blog_list();
  120. } else {
  121. api_not_allowed(true);
  122. }
  123. // Display the footer
  124. Display::display_footer();
  125. ?>