blog.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. * INIT
  10. */
  11. // name of the language file that needs to be included
  12. $language_file = "blog";
  13. require_once '../inc/global.inc.php';
  14. $blog_id = intval($_GET['blog_id']);
  15. if (empty($blog_id)) {
  16. api_not_allowed(true);
  17. }
  18. $this_section = SECTION_COURSES;
  19. $current_course_tool = TOOL_BLOGS;
  20. /* ACCESS RIGHTS */
  21. // notice for unauthorized people.
  22. api_protect_course_script(true);
  23. //session
  24. if(isset($_GET['id_session'])) {
  25. $_SESSION['id_session'] = intval($_GET['id_session']);
  26. }
  27. $lib_path = api_get_path(LIBRARY_PATH);
  28. require_once $lib_path.'blog.lib.php';
  29. require_once $lib_path.'fckeditor/fckeditor.php';
  30. $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  31. $nameTools = get_lang('Blogs');
  32. $DaysShort = api_get_week_days_short();
  33. $DaysLong = api_get_week_days_long();
  34. $MonthsLong = api_get_months_long();
  35. $current_page = $_GET['action'];
  36. /*
  37. PROCESSING
  38. */
  39. $safe_post_title = Security::remove_XSS($_POST['post_title']);
  40. $safe_post_file_comment = Security::remove_XSS($_POST['post_file_comment']);
  41. $safe_post_full_text = Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['post_full_text'])), COURSEMANAGERLOWSECURITY);
  42. $safe_comment_text = Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY);
  43. $safe_comment_title = Security::remove_XSS($_POST['comment_title']);
  44. $safe_task_name = Security::remove_XSS($_POST['task_name']);
  45. $safe_task_description = Security::remove_XSS($_POST['task_description']);
  46. if (!empty($_POST['new_post_submit']) AND !empty($_POST['post_title'])) {
  47. Blog :: create_post($safe_post_title, $safe_post_full_text, $safe_post_file_comment,$blog_id);
  48. $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogAdded'));
  49. }
  50. if (!empty($_POST['edit_post_submit']))
  51. {
  52. $safe_post_title = Security::remove_XSS($_POST['post_title']);
  53. Blog :: edit_post($_POST['post_id'], $safe_post_title, $safe_post_full_text, $blog_id);
  54. $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogEdited'));
  55. }
  56. if (!empty($_POST['new_comment_submit']))
  57. {
  58. Blog :: create_comment($safe_comment_title, $safe_comment_text, $safe_post_file_comment,$blog_id, (int)$_GET['post_id'], $_POST['comment_parent_id']);
  59. $return_message = array('type' => 'confirmation', 'message' => get_lang('CommentAdded'));
  60. }
  61. if (!empty($_POST['new_task_submit']))
  62. {
  63. Blog :: create_task($blog_id, $safe_task_name, $safe_task_description, $_POST['chkArticleDelete'], $_POST['chkArticleEdit'], $_POST['chkCommentsDelete'], $_POST['task_color']);
  64. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskCreated'));
  65. }
  66. if (isset($_POST['edit_task_submit']))
  67. {
  68. Blog :: edit_task($_POST['blog_id'], $_POST['task_id'], $safe_task_name, $safe_task_description, $_POST['chkArticleDelete'], $_POST['chkArticleEdit'],$_POST['chkCommentsDelete'], $_POST['task_color']);
  69. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskEdited'));
  70. }
  71. if (!empty($_POST['assign_task_submit']))
  72. {
  73. Blog :: assign_task($blog_id, $_POST['task_user_id'], $_POST['task_task_id'], $_POST['task_year']."-".$_POST['task_month']."-".$_POST['task_day']);
  74. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskAssigned'));
  75. }
  76. if (isset($_POST['assign_task_edit_submit']))
  77. {
  78. Blog :: edit_assigned_task($blog_id, $_POST['task_user_id'], $_POST['task_task_id'], $_POST['task_year']."-".$_POST['task_month']."-".$_POST['task_day'], $_POST['old_user_id'], $_POST['old_task_id'], $_POST['old_target_date']);
  79. $return_message = array('type' => 'confirmation', 'message' => get_lang('AssignedTaskEdited'));
  80. }
  81. if (!empty($_POST['new_task_execution_submit']))
  82. {
  83. Blog :: create_comment($safe_comment_title, $safe_comment_text, $blog_id, (int)$_GET['post_id'], $_POST['comment_parent_id'], $_POST['task_id']);
  84. $return_message = array('type' => 'confirmation', 'message' => get_lang('CommentCreated'));
  85. }
  86. if (!empty($_POST['register']))
  87. {
  88. if (is_array($_POST['user'])) {
  89. foreach ($_POST['user'] as $index => $user_id)
  90. {
  91. Blog :: set_user_subscribed((int)$_GET['blog_id'], $user_id);
  92. }
  93. }
  94. }
  95. if (!empty($_POST['unregister']))
  96. {
  97. if (is_array($_POST['user'])) {
  98. foreach ($_POST['user'] as $index => $user_id)
  99. {
  100. Blog :: set_user_unsubscribed((int)$_GET['blog_id'], $user_id);
  101. }
  102. }
  103. }
  104. if (!empty($_GET['register']))
  105. {
  106. Blog :: set_user_subscribed((int)$_GET['blog_id'], (int)$_GET['user_id']);
  107. $return_message = array('type' => 'confirmation', 'message' => get_lang('UserRegistered'));
  108. $flag = 1;
  109. }
  110. if (!empty($_GET['unregister']))
  111. {
  112. Blog :: set_user_unsubscribed((int)$_GET['blog_id'], (int)$_GET['user_id']);
  113. }
  114. if (isset($_GET['action']) && $_GET['action'] == 'manage_tasks') {
  115. if (isset($_GET['do']) && $_GET['do'] == 'delete')
  116. {
  117. Blog :: delete_task($blog_id, (int)$_GET['task_id']);
  118. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskDeleted'));
  119. }
  120. if (isset($_GET['do']) && $_GET['do'] == 'delete_assignment') {
  121. Blog :: delete_assigned_task($blog_id, intval($_GET['task_id']), intval($_GET['user_id']));
  122. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskAssignmentDeleted'));
  123. }
  124. }
  125. if (isset($_GET['action']) && $_GET['action'] == 'view_post') {
  126. $task_id = (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  127. if (isset($_GET['do']) && $_GET['do'] == 'delete_comment')
  128. {
  129. if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id))
  130. {
  131. Blog :: delete_comment($blog_id, (int)$_GET['post_id'],(int)$_GET['comment_id']);
  132. $return_message = array('type' => 'confirmation', 'message' => get_lang('CommentDeleted'));
  133. }
  134. else
  135. {
  136. $error = true;
  137. $message = get_lang('ActionNotAllowed');
  138. }
  139. }
  140. if (isset($_GET['do']) && $_GET['do'] == 'delete_article')
  141. {
  142. if (api_is_allowed('BLOG_'.$blog_id, 'article_delete', $task_id))
  143. {
  144. Blog :: delete_post($blog_id, (int)$_GET['article_id']);
  145. $current_page = ''; // Article is gone, go to blog home
  146. $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogDeleted'));
  147. }
  148. else
  149. {
  150. $error = true;
  151. $message = get_lang('ActionNotAllowed');
  152. }
  153. }
  154. if (isset($_GET['do']) && $_GET['do'] == 'rate')
  155. {
  156. if (isset($_GET['type']) && $_GET['type'] == 'post')
  157. {
  158. if (api_is_allowed('BLOG_'.$blog_id, 'article_rate'))
  159. {
  160. Blog :: add_rating('post', $blog_id, (int)$_GET['post_id'], (int)$_GET['rating']);
  161. $return_message = array('type' => 'confirmation', 'message' => get_lang('RatingAdded'));
  162. }
  163. }
  164. if (isset($_GET['type']) && $_GET['type'] == 'comment')
  165. {
  166. if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_add'))
  167. {
  168. Blog :: add_rating('comment', $blog_id, (int)$_GET['comment_id'], (int)$_GET['rating']);
  169. $return_message = array('type' => 'confirmation', 'message' => get_lang('RatingAdded'));
  170. }
  171. }
  172. }
  173. }
  174. /*
  175. DISPLAY
  176. */
  177. $htmlHeadXtra[] = '<script src="tbl_change.js" type="text/javascript"></script>';
  178. // Set bredcrumb
  179. switch ($current_page) {
  180. case 'new_post' :
  181. $nameTools = get_lang('NewPost');
  182. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  183. Display :: display_header($nameTools, 'Blogs');
  184. break;
  185. case 'manage_tasks' :
  186. $nameTools = get_lang('TaskManager');
  187. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  188. Display :: display_header($nameTools, 'Blogs');
  189. break;
  190. case 'manage_members' :
  191. $nameTools = get_lang('MemberManager');
  192. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  193. Display :: display_header($nameTools, 'Blogs');
  194. break;
  195. case 'manage_rights' :
  196. $nameTools = get_lang('RightsManager');
  197. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", 'name' => Blog :: get_blog_title($blog_id));
  198. Display :: display_header($nameTools, 'Blogs');
  199. break;
  200. case 'view_search_result' :
  201. $nameTools = get_lang('SearchResults');
  202. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", 'name' => Blog :: get_blog_title($blog_id));
  203. Display :: display_header($nameTools, 'Blogs');
  204. break;
  205. case 'execute_task' :
  206. $nameTools = get_lang('ExecuteThisTask');
  207. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", 'name' => Blog :: get_blog_title($blog_id));
  208. Display :: display_header($nameTools, 'Blogs');
  209. break;
  210. default :
  211. $nameTools = Blog :: get_blog_title($blog_id);
  212. Display :: display_header($nameTools, 'Blogs');
  213. }
  214. // feedback messages
  215. if (!empty($return_message)) {
  216. if ($return_message['type'] == 'confirmation') {
  217. Display::display_confirmation_message($return_message['message']);
  218. }
  219. if ($return_message['type'] == 'error') {
  220. Display::display_error_message($return_message['message']);
  221. }
  222. }
  223. // actions
  224. echo '<div class=actions>';
  225. ?>
  226. <a href="<?php echo api_get_self(); ?>?blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('Home') ?>"><?php echo Display::return_icon('blog.png', get_lang('Home'),'',ICON_SIZE_MEDIUM); ?></a>
  227. <?php if(api_is_allowed('BLOG_'.$blog_id, 'article_add')) { ?><a href="<?php echo api_get_self(); ?>?action=new_post&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('NewPost') ?>"><?php echo Display::return_icon('new_article.png', get_lang('NewPost'),'',ICON_SIZE_MEDIUM); ?></a><?php } ?>
  228. <?php if(api_is_allowed('BLOG_'.$blog_id, 'task_management')) { ?><a href="<?php echo api_get_self(); ?>?action=manage_tasks&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageTasks') ?>"><?php echo Display::return_icon('blog_tasks.png', get_lang('TaskManager'),'',ICON_SIZE_MEDIUM); ?></a><?php } ?>
  229. <?php if(api_is_allowed('BLOG_'.$blog_id, 'member_management')) { ?><a href="<?php echo api_get_self(); ?>?action=manage_members&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageMembers') ?>"><?php echo Display::return_icon('blog_admin_users.png', get_lang('MemberManager'),'',ICON_SIZE_MEDIUM); ?></a><?php } ?>
  230. <?php
  231. echo '</div>';
  232. // Tool introduction
  233. Display::display_introduction_section(TOOL_BLOG);
  234. //Display::display_header($nameTools,'Blogs');
  235. ?>
  236. <div class="sectiontitle"><?php echo Blog::get_blog_title($blog_id); ?></div>
  237. <div class="sectioncomment"><?php echo Blog::get_blog_subtitle($blog_id); ?></div>
  238. <table width="100%">
  239. <tr>
  240. <td width="10%" style="float;left;" class="blog_left" valign="top">
  241. <?php
  242. $month = isset($_GET['month']) ? (int)$_GET['month'] : (int) date('m');
  243. $year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
  244. Blog::display_minimonthcalendar($month, $year, $blog_id);
  245. ?>
  246. <br />
  247. <br />
  248. <table width="100%">
  249. <tr>
  250. <td class="sectiontitle"><?php echo get_lang('Search') ?></td>
  251. </tr>
  252. <tr>
  253. <td class="blog_menu">
  254. <form action="blog.php" method="get" enctype="multipart/form-data">
  255. <input type="hidden" name="blog_id" value="<?php echo $blog_id ?>" />
  256. <input type="hidden" name="action" value="view_search_result" />
  257. <input type="text" size="20" name="q" value="<?php echo isset($_GET['q']) ? Security::remove_XSS($_GET['q']) : ''; ?>" /><button class="btn search" type="submit"><?php echo get_lang('Search'); ?></button>
  258. </form>
  259. </td>
  260. </tr>
  261. </table>
  262. <br />
  263. <table width="100%">
  264. <tr>
  265. <td class="sectiontitle"><?php echo get_lang('MyTasks') ?></td>
  266. </tr>
  267. <tr>
  268. <td class="blog_menu">
  269. <?php Blog::get_personal_task_list(); ?>
  270. </td>
  271. </tr>
  272. </table>
  273. </td>
  274. <td valign="top" class="blog_right">
  275. <?php
  276. if (isset($error)) {
  277. Display :: display_error_message($message);
  278. }
  279. if (isset($flag) && $flag == '1') {
  280. $current_page = "manage_tasks";
  281. Blog :: display_assign_task_form($blog_id);
  282. }
  283. $user_task = false;
  284. $course_id = api_get_course_int_id();
  285. if (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) {
  286. $task_id = (int)$_GET['task_id'];
  287. } else {
  288. $task_id = 0;
  289. $tbl_blogs_tasks_rel_user = Database :: get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  290. $sql = "SELECT COUNT(*) as number
  291. FROM ".$tbl_blogs_tasks_rel_user."
  292. WHERE
  293. c_id = $course_id AND
  294. blog_id = ".$blog_id." AND
  295. user_id = ".api_get_user_id()." AND
  296. task_id = ".$task_id;
  297. $result = Database::query($sql);
  298. $row = Database::fetch_array($result);
  299. if ($row['number'] == 1)
  300. $user_task = true;
  301. }
  302. switch ($current_page) {
  303. case 'new_post' :
  304. if (api_is_allowed('BLOG_'.$blog_id, 'article_add', $user_task ? $task_id : 0)) {
  305. // we show the form if
  306. // 1. no post data
  307. // 2. there is post data and the required field is empty
  308. if (!$_POST OR (!empty($_POST) AND empty($_POST['post_title']))) {
  309. // if there is post data there is certainly an error in the form
  310. if ($_POST) {
  311. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  312. }
  313. Blog :: display_form_new_post($blog_id);
  314. } else {
  315. if (isset($_GET['filter']) && !empty($_GET['filter'])) {
  316. Blog :: display_day_results($blog_id, Database::escape_string($_GET['filter']));
  317. } else {
  318. Blog :: display_blog_posts($blog_id);
  319. }
  320. }
  321. } else {
  322. api_not_allowed();
  323. }
  324. break;
  325. case 'view_post' :
  326. Blog :: display_post($blog_id, intval($_GET['post_id']));
  327. break;
  328. case 'edit_post' :
  329. $task_id = (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  330. if (api_is_allowed('BLOG_'.$blog_id, 'article_edit', $task_id)) {
  331. // we show the form if
  332. // 1. no post data
  333. // 2. there is post data and the required field is empty
  334. if (!$_POST OR (!empty($_POST) AND empty($_POST['post_title']))) {
  335. // if there is post data there is certainly an error in the form
  336. if ($_POST) {
  337. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
  338. }
  339. Blog :: display_form_edit_post($blog_id, intval($_GET['post_id']));
  340. } else {
  341. if (isset ($_GET['filter']) && !empty ($_GET['filter'])) {
  342. Blog :: display_day_results($blog_id, Database::escape_string($_GET['filter']));
  343. } else {
  344. Blog :: display_blog_posts($blog_id);
  345. }
  346. }
  347. } else {
  348. api_not_allowed();
  349. }
  350. break;
  351. case 'manage_members' :
  352. if (api_is_allowed('BLOG_'.$blog_id, 'member_management')) {
  353. Blog :: display_form_user_subscribe($blog_id);
  354. echo '<br /><br />';
  355. Blog :: display_form_user_unsubscribe($blog_id);
  356. } else {
  357. api_not_allowed();
  358. }
  359. break;
  360. case 'manage_rights' :
  361. Blog :: display_form_user_rights($blog_id);
  362. break;
  363. case 'manage_tasks' :
  364. if (api_is_allowed('BLOG_'.$blog_id, 'task_management')) {
  365. if (isset($_GET['do']) && $_GET['do'] == 'add')
  366. {
  367. Blog :: display_new_task_form($blog_id);
  368. }
  369. if (isset($_GET['do']) && $_GET['do'] == 'assign')
  370. {
  371. Blog :: display_assign_task_form($blog_id);
  372. }
  373. if (isset($_GET['do']) && $_GET['do'] == 'edit')
  374. {
  375. Blog :: display_edit_task_form($blog_id, intval($_GET['task_id']));
  376. }
  377. if (isset($_GET['do']) && $_GET['do'] == 'edit_assignment')
  378. {
  379. Blog :: display_edit_assigned_task_form($blog_id, intval($_GET['task_id']), intval($_GET['user_id']));
  380. }
  381. Blog :: display_task_list($blog_id);
  382. echo '<br /><br />';
  383. Blog :: display_assigned_task_list($blog_id);
  384. echo '<br /><br />';
  385. }
  386. else
  387. api_not_allowed();
  388. break;
  389. case 'execute_task' :
  390. if (isset ($_GET['post_id']))
  391. Blog :: display_post($blog_id, intval($_GET['post_id']));
  392. else
  393. Blog :: display_select_task_post($blog_id, intval($_GET['task_id']));
  394. break;
  395. case 'view_search_result' :
  396. Blog :: display_search_results($blog_id, Database::escape_string($_GET['q']));
  397. break;
  398. case '' :
  399. default :
  400. if (isset ($_GET['filter']) && !empty ($_GET['filter'])) {
  401. Blog :: display_day_results($blog_id, Database::escape_string($_GET['filter']));
  402. } else {
  403. Blog :: display_blog_posts($blog_id);
  404. }
  405. }
  406. ?>
  407. </td>
  408. </tr>
  409. </table>
  410. <?php
  411. // Display the footer
  412. Display::display_footer();