blog_admin.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php //$Id: announcements.php 16702 2008-11-10 13:02:30Z elixir_inter $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. info@dokeos.com
  18. ==============================================================================
  19. BLOG HOMEPAGE
  20. This file takes care of all blog navigation and displaying.
  21. @package dokeos.blogs
  22. ==============================================================================
  23. */
  24. // name of the language file that needs to be included
  25. $language_file = "blog";
  26. require_once('../inc/global.inc.php');
  27. $this_section=SECTION_COURSES;
  28. $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  29. /* ------------ ACCESS RIGHTS ------------ */
  30. // notice for unauthorized people.
  31. api_protect_course_script(true);
  32. //------------ ONLY USERS REGISTERED IN THE COURSE----------------------
  33. if((!$is_allowed_in_course || !$is_courseMember) && !api_is_allowed_to_edit())
  34. {
  35. api_not_allowed(true);//print headers/footers
  36. }
  37. if (api_is_allowed_to_edit())
  38. {
  39. require_once(api_get_path(LIBRARY_PATH) . "blog.lib.php");
  40. $nameTools = get_lang("blog_management");
  41. // showing the header if we are not in the learning path, if we are in
  42. // the learning path, we do not include the banner so we have to explicitly
  43. // include the stylesheet, which is normally done in the header
  44. if ($_GET['origin'] != 'learnpath') {
  45. $interbreadcrumb[]= array (
  46. 'url' => 'blog_admin.php?',
  47. 'name' => $nameTools
  48. );
  49. $my_url='';
  50. if (isset($_GET['action']) && $_GET['action']=='add') {
  51. $current_section=get_lang('AddBlog');
  52. $my_url='action=add';
  53. } elseif (isset($_GET['action']) && $_GET['action']=='edit') {
  54. $current_section=get_lang('EditBlog');
  55. $my_url='action=edit&amp;blog_id='.Security::remove_XSS($_GET['blog_id']);
  56. }
  57. $interbreadcrumb[]= array (
  58. 'url' => 'blog_admin.php?'.$my_url,
  59. 'name' => $current_section
  60. );
  61. Display::display_header('');
  62. } else {
  63. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  64. }
  65. /*
  66. ==============================================================================
  67. PROCESSING..
  68. ==============================================================================
  69. */
  70. $get_blog_name = Security::remove_XSS($_POST['blog_name']);
  71. $get_blog_subtitle = Security::remove_XSS($_POST['blog_subtitle']);
  72. $get_blog_id = Security::remove_XSS($_POST['blog_id']);
  73. if (!empty($_POST['new_blog_submit']) AND !empty($_POST['blog_name'])) {
  74. if (strlen(trim($_POST['blog_name']))>0) {
  75. Blog::create_blog($get_blog_name,$get_blog_subtitle);
  76. Display::display_confirmation_message(get_lang('BlogStored'));
  77. }
  78. }
  79. if (!empty($_POST['edit_blog_submit']) AND !empty($_POST['blog_name'])) {
  80. if (strlen(trim($_POST['blog_name']))>0) {
  81. Blog::edit_blog($get_blog_id,$get_blog_name,$get_blog_subtitle);
  82. Display::display_confirmation_message(get_lang('BlogEdited'));
  83. }
  84. }
  85. if (isset($_GET['action']) && $_GET['action'] == 'visibility') {
  86. Blog::change_blog_visibility(Database::escape_string((int)$_GET['blog_id']));
  87. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  88. }
  89. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  90. Blog::delete_blog(Database::escape_string((int)$_GET['blog_id']));
  91. Display::display_confirmation_message(get_lang('BlogDeleted'));
  92. }
  93. /*
  94. ==============================================================================
  95. DISPLAY
  96. ==============================================================================
  97. */
  98. //api_display_tool_title($nameTools);
  99. //api_introductionsection(TOOL_BLOG);
  100. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  101. // we show the form if
  102. // 1. no post data
  103. // 2. there is post data and one of the required form elements is empty
  104. if (!$_POST OR (!empty($_POST) AND (empty($_POST['new_blog_submit']) OR empty($_POST['blog_name'])))) {
  105. // if there is post data there is certainly an error in the form
  106. /*if ($_POST){
  107. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  108. }*/
  109. if (strlen($_POST['blog_name'])==0) {
  110. if (count($_POST)>0) {
  111. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  112. }
  113. }
  114. Blog::display_new_blog_form();
  115. }
  116. }
  117. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  118. // we show the form if
  119. // 1. no post data
  120. // 2. there is post data and one of the three form elements is empty
  121. if (!$_POST OR (!empty($_POST) AND (empty($_POST['edit_blog_submit']) OR empty($_POST['blog_name']) )))
  122. {
  123. // if there is post data there is certainly an error in the form
  124. if ($_POST) {
  125. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  126. }
  127. Blog::display_edit_blog_form(Database::escape_string((int)$_GET['blog_id']));
  128. }
  129. }
  130. echo '<div class="actions">';
  131. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add'>",Display::return_icon('blog_new.gif',get_lang('AddBlog')),get_lang('AddBlog')."</a>";
  132. echo '</div>';
  133. /*echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" class='data_table'>";
  134. echo "<tr>",
  135. "<th>",get_lang('Title'),"</th>\n",
  136. "<th>",get_lang('Subtitle'),"</th>\n",
  137. "<th>",get_lang('Modify'),"</th>\n",
  138. "</tr>\n";
  139. echo "</table>";*/
  140. Blog::display_blog_list();
  141. } else {
  142. api_not_allowed(true);
  143. }
  144. // Display the footer
  145. Display::display_footer();
  146. ?>