blog.php 18 KB

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