blog.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <?php
  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. require_once (api_get_path(LIBRARY_PATH)."/display.lib.php");
  43. require_once (api_get_path(LIBRARY_PATH)."/text.lib.php");
  44. require_once (api_get_path(LIBRARY_PATH)."/blog.lib.php");
  45. require_once (api_get_path(LIBRARY_PATH)."/fckeditor.lib.php");
  46. $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  47. $nameTools = get_lang("Blogs");
  48. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  49. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  50. $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  51. $current_page = $_GET['action'];
  52. /*
  53. ==============================================================================
  54. PROCESSING
  55. ==============================================================================
  56. */
  57. if ($_POST['new_post_submit'])
  58. {
  59. Blog :: create_post($_POST['post_title'], $_POST['post_full_text'], $_POST['post_file_comment'],$blog_id);
  60. }
  61. if ($_POST['edit_post_submit'])
  62. {
  63. Blog :: edit_post($_POST['post_id'], $_POST['post_title'], $_POST['post_full_text'], $blog_id);
  64. }
  65. if ($_POST['new_comment_submit'])
  66. {
  67. Blog :: create_comment($_POST['comment_title'], $_POST['comment_text'], $_POST['post_file_comment'],$blog_id, (int)$_GET['post_id'], $_POST['comment_parent_id']);
  68. }
  69. if ($_POST['new_task_submit'])
  70. {
  71. Blog :: create_task($blog_id, $_POST['task_name'], $_POST['task_description'], $_POST['chkArticleDelete'], $_POST['chkArticleEdit'], $_POST['chkCommentsDelete'], $_POST['task_color']);
  72. }
  73. if ($_POST['edit_task_submit'])
  74. {
  75. Blog :: edit_task($_POST['blog_id'], $_POST['task_id'], $_POST['task_name'], $_POST['task_description'], $_POST['chkArticleDelete'], $_POST['chkArticleEdit'],$_POST['chkCommentsDelete'], $_POST['task_color']);
  76. }
  77. if ($_POST['assign_task_submit'])
  78. {
  79. Blog :: assign_task($blog_id, $_POST['task_user_id'], $_POST['task_task_id'], $_POST['task_year']."-".$_POST['task_month']."-".$_POST['task_day']);
  80. }
  81. if ($_POST['assign_task_edit_submit'])
  82. {
  83. 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']);
  84. }
  85. if ($_POST['new_task_execution_submit'])
  86. {
  87. Blog :: create_comment($_POST['comment_title'], $_POST['comment_text'], $blog_id, (int)$_GET['post_id'], $_POST['comment_parent_id'], $_POST['task_id']);
  88. }
  89. if ($_POST['register'])
  90. {
  91. foreach ($_POST['user'] as $index => $user_id)
  92. {
  93. Blog :: set_user_subscribed((int)$_GET['blog_id'], $user_id);
  94. }
  95. }
  96. if ($_POST['unregister'])
  97. {
  98. foreach ($_POST['user'] as $index => $user_id)
  99. {
  100. Blog :: set_user_unsubscribed((int)$_GET['blog_id'], $user_id);
  101. }
  102. }
  103. if ($_GET['register'])
  104. {
  105. Blog :: set_user_subscribed((int)$_GET['blog_id'], (int)$_GET['user_id']);
  106. $flag = 1;
  107. }
  108. if ($_GET['unregister'])
  109. {
  110. Blog :: set_user_unsubscribed((int)$_GET['blog_id'], (int)$_GET['user_id']);
  111. }
  112. if ($_GET['action'] == 'manage_tasks')
  113. {
  114. if ($_GET['do'] == 'delete')
  115. Blog :: delete_task($blog_id, (int)$_GET['task_id']);
  116. if ($_GET['do'] == 'delete_assignment')
  117. Blog :: delete_assigned_task($blog_id, (int)$_GET['assignment_id']);
  118. }
  119. if ($_GET['action'] == 'view_post')
  120. {
  121. $task_id = (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  122. if ($_GET['do'] == 'delete_comment')
  123. {
  124. if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id))
  125. {
  126. Blog :: delete_comment($blog_id, (int)$_GET['post_id'],(int)$_GET['comment_id']);
  127. }
  128. else
  129. {
  130. $error = true;
  131. $message = get_lang('ActionNotAllowed');
  132. }
  133. }
  134. if ($_GET['do'] == 'delete_article')
  135. {
  136. if (api_is_allowed('BLOG_'.$blog_id, 'article_delete', $task_id))
  137. {
  138. Blog :: delete_post($blog_id, (int)$_GET['article_id']);
  139. $current_page = ''; // Article is gone, go to blog home
  140. }
  141. else
  142. {
  143. $error = true;
  144. $message = get_lang('ActionNotAllowed');
  145. }
  146. }
  147. if ($_GET['do'] == 'rate')
  148. {
  149. if ($_GET['type'] == 'post')
  150. {
  151. if (api_is_allowed('BLOG_'.$blog_id, 'article_rate'))
  152. {
  153. Blog :: add_rating('post', $blog_id, (int)$_GET['post_id'], (int)$_GET['rating']);
  154. }
  155. }
  156. if ($_GET['type'] == 'comment')
  157. {
  158. if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_add'))
  159. {
  160. Blog :: add_rating('comment', $blog_id, (int)$_GET['comment_id'], (int)$_GET['rating']);
  161. }
  162. }
  163. }
  164. }
  165. /*
  166. ==============================================================================
  167. DISPLAY
  168. ==============================================================================
  169. */
  170. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  171. // Set bredcrumb
  172. switch ($current_page)
  173. {
  174. case "new_post" :
  175. $nameTools = get_lang('NewPost');
  176. $interbreadcrumb[] = array ("url" => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  177. Display :: display_header($nameTools, 'blogs');
  178. break;
  179. case "manage_tasks" :
  180. $nameTools = get_lang('TaskManager');
  181. $interbreadcrumb[] = array ("url" => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  182. Display :: display_header($nameTools, 'blogs');
  183. break;
  184. case "manage_members" :
  185. $nameTools = get_lang('MemberManager');
  186. $interbreadcrumb[] = array ("url" => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  187. Display :: display_header($nameTools, 'blogs');
  188. break;
  189. case "manage_rights" :
  190. $nameTools = get_lang('RightsManager');
  191. $interbreadcrumb[] = array ("url" => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  192. Display :: display_header($nameTools, 'blogs');
  193. break;
  194. case "view_search_result" :
  195. $nameTools = get_lang('SearchResults');
  196. $interbreadcrumb[] = array ("url" => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  197. Display :: display_header($nameTools, 'blogs');
  198. break;
  199. case "execute_task" :
  200. $nameTools = get_lang('ExecuteThisTask');
  201. $interbreadcrumb[] = array ("url" => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  202. Display :: display_header($nameTools, 'blogs');
  203. break;
  204. default :
  205. $nameTools = Blog :: get_blog_title($blog_id);
  206. Display :: display_header($nameTools, 'blogs');
  207. }
  208. //Display::display_header($nameTools,'Blogs');
  209. ?>
  210. <span class="blog_title"><?php echo Blog::get_blog_title($blog_id) ?></span><br />
  211. <span class="blog_subtitle"><?php echo Blog::get_blog_subtitle($blog_id) ?></span>
  212. <br /><br />
  213. <table width="100%">
  214. <tr>
  215. <td width="220" class="blog_left" valign="top">
  216. <?php
  217. $month = (int)$_GET['month'] ? (int)$_GET['month'] : (int) date('m');
  218. $year = (int)$_GET['year'] ? (int)$_GET['year'] : date('Y');
  219. Blog :: display_minimonthcalendar($month, $year, $blog_id);
  220. ?>
  221. <br />
  222. <table width="100%">
  223. <tr>
  224. <td class="blog_menu_title"><?php echo get_lang('ThisBlog') ?></td>
  225. </tr>
  226. <tr>
  227. <td class="blog_menu">
  228. <ul>
  229. <li><a href="<?php echo api_get_self(); ?>?blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('Home') ?>"><?php echo get_lang('Home') ?></a></li>
  230. <?php if(api_is_allowed('BLOG_'.$blog_id, 'article_add')) { ?><li><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 get_lang('NewPost') ?></a></li><?php } ?>
  231. <?php if(api_is_allowed('BLOG_'.$blog_id, 'task_management')) { ?><li><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 get_lang('TaskManager') ?></a></li> <?php } ?>
  232. <?php if(api_is_allowed('BLOG_'.$blog_id, 'member_management')) { ?><li><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 get_lang('MemberManager') ?></a></li><?php } ?>
  233. </ul>
  234. </td>
  235. </tr>
  236. </table>
  237. <br />
  238. <table width="100%">
  239. <tr>
  240. <td class="blog_menu_title"><?php echo get_lang('Search') ?></td>
  241. </tr>
  242. <tr>
  243. <td class="blog_menu">
  244. <form action="blog.php" method="get" enctype="multipart/form-data">
  245. <input type="hidden" name="blog_id" value="<?php echo $blog_id ?>" />
  246. <input type="hidden" name="action" value="view_search_result" />
  247. <input type="text" size="20" name="q" value="<?php echo (isset($_GET['q']) ? $_GET['q'] : ''); ?>" /><input type="submit" value="Go" />
  248. </form>
  249. </td>
  250. </tr>
  251. </table>
  252. <br />
  253. <table width="100%">
  254. <tr>
  255. <td class="blog_menu_title"><?php echo get_lang('MyTasks') ?></td>
  256. </tr>
  257. <tr>
  258. <td class="blog_menu">
  259. <?php Blog::get_personal_task_list(); ?>
  260. </td>
  261. </tr>
  262. </table>
  263. <!--
  264. <br />
  265. <table width="100%">
  266. <tr>
  267. <td class="blog_menu_title"><?php echo get_lang('FavoriteBlogs') ?></td>
  268. </tr>
  269. <tr>
  270. <td class="blog_menu">
  271. <ul>
  272. <li>Favorite 1</li>
  273. <li>Favorite 2</li>
  274. <li>Favorite 3</li>
  275. </ul>
  276. </td>
  277. </tr>
  278. </table>
  279. <br />
  280. <table width="100%">
  281. <tr>
  282. <td class="blog_menu_title"><?php echo get_lang('TopTen') ?></td>
  283. </tr>
  284. <tr>
  285. <td class="blog_menu">
  286. <ul>
  287. <li>Blog 1</li>
  288. <li>Blog 2</li>
  289. <li>Blog 3</li>
  290. </ul>
  291. </td>
  292. </tr>
  293. </table>
  294. -->
  295. </td>
  296. <td valign="top" class="blog_right">
  297. <?php
  298. if ($error)
  299. Display :: display_error_message($message);
  300. if ($flag == '1')
  301. {
  302. $current_page = "manage_tasks";
  303. Blog :: display_assign_task_form($blog_id);
  304. }
  305. $user_task = false;
  306. if (isset ($_GET['task_id']) && is_numeric($_GET['task_id']))
  307. $task_id = (int)$_GET['task_id'];
  308. else
  309. {
  310. $task_id = 0;
  311. $tbl_blogs_tasks_rel_user = Database :: get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  312. $sql = "
  313. SELECT COUNT(*) as `number`
  314. FROM ".$tbl_blogs_tasks_rel_user."
  315. WHERE
  316. `blog_id` = ".$blog_id." AND
  317. `user_id` = ".api_get_user_id()." AND
  318. `task_id` = ".$task_id;
  319. $result = api_sql_query($sql, __LINE__, __FILE__);
  320. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  321. if ($row['number'] == 1)
  322. $user_task = true;
  323. }
  324. switch ($current_page)
  325. {
  326. case 'new_post' :
  327. if (api_is_allowed('BLOG_'.$blog_id, 'article_add', $user_task ? $task_id : 0))
  328. {
  329. Blog :: display_form_new_post($blog_id);
  330. }
  331. else
  332. {
  333. api_not_allowed();
  334. }
  335. break;
  336. case 'view_post' :
  337. Blog :: display_post($blog_id, mysql_real_escape_string((int)$_GET['post_id']));
  338. break;
  339. case 'edit_post' :
  340. $task_id = (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  341. if (api_is_allowed('BLOG_'.$blog_id, 'article_edit', $task_id))
  342. Blog :: display_form_edit_post($blog_id, mysql_real_escape_string((int)$_GET['post_id']));
  343. else
  344. api_not_allowed();
  345. break;
  346. case 'manage_members' :
  347. if (api_is_allowed('BLOG_'.$blog_id, 'member_management'))
  348. {
  349. Blog :: display_form_user_subscribe($blog_id);
  350. echo '<br /><br />';
  351. Blog :: display_form_user_unsubscribe($blog_id);
  352. }
  353. else
  354. api_not_allowed();
  355. break;
  356. case 'manage_rights' :
  357. Blog :: display_form_user_rights($blog_id);
  358. break;
  359. case 'manage_tasks' :
  360. if (api_is_allowed('BLOG_'.$blog_id, 'task_management'))
  361. {
  362. if ($_GET['do'] == 'add')
  363. {
  364. Blog :: display_new_task_form($blog_id);
  365. }
  366. if ($_GET['do'] == 'assign')
  367. {
  368. Blog :: display_assign_task_form($blog_id);
  369. }
  370. if ($_GET['do'] == 'edit')
  371. {
  372. Blog :: display_edit_task_form($blog_id, mysql_real_escape_string($_GET['task_id']));
  373. }
  374. if ($_GET['do'] == 'edit_assignment')
  375. {
  376. Blog :: display_edit_assigned_task_form($blog_id, mysql_real_escape_string((int)$_GET['assignment_id']));
  377. }
  378. Blog :: display_task_list($blog_id);
  379. echo '<br /><br />';
  380. Blog :: display_assigned_task_list($blog_id);
  381. echo '<br /><br />';
  382. if (api_is_allowed('BLOG_'.$blog_id, 'role_management'))
  383. {
  384. ?>
  385. <a href="<?php echo api_get_self(); ?>?action=manage_rights&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageRights') ?>"><?php echo get_lang('RightsManager') ?></a>
  386. <?php
  387. }
  388. }
  389. else
  390. api_not_allowed();
  391. break;
  392. case 'execute_task' :
  393. if (isset ($_GET['post_id']))
  394. Blog :: display_post($blog_id, mysql_real_escape_string((int)$_GET['post_id']));
  395. else
  396. Blog :: display_select_task_post($blog_id, mysql_real_escape_string((int)$_GET['task_id']));
  397. break;
  398. case 'view_search_result' :
  399. Blog :: display_search_results($blog_id, mysql_real_escape_string($_GET['q']));
  400. break;
  401. case '' :
  402. default :
  403. if (isset ($_GET['filter']) && !empty ($_GET['filter']))
  404. {
  405. Blog :: display_day_results($blog_id, mysql_real_escape_string($_GET['filter']));
  406. }
  407. else
  408. {
  409. Blog :: display_blog_posts($blog_id);
  410. }
  411. }
  412. ?>
  413. </td>
  414. </tr>
  415. </table>
  416. <?php
  417. // Display the footer
  418. Display::display_footer();
  419. ?>