blog.php 15 KB

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