blog.php 16 KB

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