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.'display.lib.php';
  25. require_once $lib_path.'blog.lib.php';
  26. require_once $lib_path.'fckeditor/fckeditor.php';
  27. $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  28. $nameTools = get_lang('Blogs');
  29. $DaysShort = api_get_week_days_short();
  30. $DaysLong = api_get_week_days_long();
  31. $MonthsLong = api_get_months_long();
  32. $current_page = $_GET['action'];
  33. /*
  34. PROCESSING
  35. */
  36. $safe_post_title = Security::remove_XSS($_POST['post_title']);
  37. $safe_post_file_comment = Security::remove_XSS($_POST['post_file_comment']);
  38. $safe_post_full_text = Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['post_full_text'])), COURSEMANAGERLOWSECURITY);
  39. $safe_comment_text = Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY);
  40. $safe_comment_title = Security::remove_XSS($_POST['comment_title']);
  41. $safe_task_name = Security::remove_XSS($_POST['task_name']);
  42. $safe_task_description = Security::remove_XSS($_POST['task_description']);
  43. if (!empty($_POST['new_post_submit']) AND !empty($_POST['post_title']))
  44. {
  45. Blog :: create_post($safe_post_title, $safe_post_full_text, $safe_post_file_comment,$blog_id);
  46. $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogAdded'));
  47. }
  48. if (!empty($_POST['edit_post_submit']))
  49. {
  50. $safe_post_title = Security::remove_XSS($_POST['post_title']);
  51. Blog :: edit_post($_POST['post_id'], $safe_post_title, $safe_post_full_text, $blog_id);
  52. $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogEdited'));
  53. }
  54. if (!empty($_POST['new_comment_submit']))
  55. {
  56. Blog :: create_comment($safe_comment_title, $safe_comment_text, $safe_post_file_comment,$blog_id, (int)$_GET['post_id'], $_POST['comment_parent_id']);
  57. $return_message = array('type' => 'confirmation', 'message' => get_lang('CommentAdded'));
  58. }
  59. if (!empty($_POST['new_task_submit']))
  60. {
  61. Blog :: create_task($blog_id, $safe_task_name, $safe_task_description, $_POST['chkArticleDelete'], $_POST['chkArticleEdit'], $_POST['chkCommentsDelete'], $_POST['task_color']);
  62. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskCreated'));
  63. }
  64. if (isset($_POST['edit_task_submit']))
  65. {
  66. Blog :: edit_task($_POST['blog_id'], $_POST['task_id'], $safe_task_name, $safe_task_description, $_POST['chkArticleDelete'], $_POST['chkArticleEdit'],$_POST['chkCommentsDelete'], $_POST['task_color']);
  67. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskEdited'));
  68. }
  69. if (!empty($_POST['assign_task_submit']))
  70. {
  71. Blog :: assign_task($blog_id, $_POST['task_user_id'], $_POST['task_task_id'], $_POST['task_year']."-".$_POST['task_month']."-".$_POST['task_day']);
  72. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskAssigned'));
  73. }
  74. if (isset($_POST['assign_task_edit_submit']))
  75. {
  76. 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']);
  77. $return_message = array('type' => 'confirmation', 'message' => get_lang('AssignedTaskEdited'));
  78. }
  79. if (!empty($_POST['new_task_execution_submit']))
  80. {
  81. Blog :: create_comment($safe_comment_title, $safe_comment_text, $blog_id, (int)$_GET['post_id'], $_POST['comment_parent_id'], $_POST['task_id']);
  82. $return_message = array('type' => 'confirmation', 'message' => get_lang('CommentCreated'));
  83. }
  84. if (!empty($_POST['register']))
  85. {
  86. if (is_array($_POST['user'])) {
  87. foreach ($_POST['user'] as $index => $user_id)
  88. {
  89. Blog :: set_user_subscribed((int)$_GET['blog_id'], $user_id);
  90. }
  91. }
  92. }
  93. if (!empty($_POST['unregister']))
  94. {
  95. if (is_array($_POST['user'])) {
  96. foreach ($_POST['user'] as $index => $user_id)
  97. {
  98. Blog :: set_user_unsubscribed((int)$_GET['blog_id'], $user_id);
  99. }
  100. }
  101. }
  102. if (!empty($_GET['register']))
  103. {
  104. Blog :: set_user_subscribed((int)$_GET['blog_id'], (int)$_GET['user_id']);
  105. $return_message = array('type' => 'confirmation', 'message' => get_lang('UserRegistered'));
  106. $flag = 1;
  107. }
  108. if (!empty($_GET['unregister']))
  109. {
  110. Blog :: set_user_unsubscribed((int)$_GET['blog_id'], (int)$_GET['user_id']);
  111. }
  112. if (isset($_GET['action']) && $_GET['action'] == 'manage_tasks')
  113. {
  114. if (isset($_GET['do']) && $_GET['do'] == 'delete')
  115. {
  116. Blog :: delete_task($blog_id, (int)$_GET['task_id']);
  117. $return_message = array('type' => 'confirmation', 'message' => get_lang('TaskDeleted'));
  118. }
  119. if (isset($_GET['do']) && $_GET['do'] == 'delete_assignment')
  120. {
  121. Blog :: delete_assigned_task($blog_id, Database::escape_string((int)$_GET['task_id']), Database::escape_string((int)$_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. {
  127. $task_id = (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  128. if (isset($_GET['do']) && $_GET['do'] == 'delete_comment')
  129. {
  130. if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id))
  131. {
  132. Blog :: delete_comment($blog_id, (int)$_GET['post_id'],(int)$_GET['comment_id']);
  133. $return_message = array('type' => 'confirmation', 'message' => get_lang('CommentDeleted'));
  134. }
  135. else
  136. {
  137. $error = true;
  138. $message = get_lang('ActionNotAllowed');
  139. }
  140. }
  141. if (isset($_GET['do']) && $_GET['do'] == 'delete_article')
  142. {
  143. if (api_is_allowed('BLOG_'.$blog_id, 'article_delete', $task_id))
  144. {
  145. Blog :: delete_post($blog_id, (int)$_GET['article_id']);
  146. $current_page = ''; // Article is gone, go to blog home
  147. $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogDeleted'));
  148. }
  149. else
  150. {
  151. $error = true;
  152. $message = get_lang('ActionNotAllowed');
  153. }
  154. }
  155. if (isset($_GET['do']) && $_GET['do'] == 'rate')
  156. {
  157. if (isset($_GET['type']) && $_GET['type'] == 'post')
  158. {
  159. if (api_is_allowed('BLOG_'.$blog_id, 'article_rate'))
  160. {
  161. Blog :: add_rating('post', $blog_id, (int)$_GET['post_id'], (int)$_GET['rating']);
  162. $return_message = array('type' => 'confirmation', 'message' => get_lang('RatingAdded'));
  163. }
  164. }
  165. if (isset($_GET['type']) && $_GET['type'] == 'comment')
  166. {
  167. if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_add'))
  168. {
  169. Blog :: add_rating('comment', $blog_id, (int)$_GET['comment_id'], (int)$_GET['rating']);
  170. $return_message = array('type' => 'confirmation', 'message' => get_lang('RatingAdded'));
  171. }
  172. }
  173. }
  174. }
  175. /*
  176. DISPLAY
  177. */
  178. $htmlHeadXtra[] = '<script src="tbl_change.js" type="text/javascript" language="javascript"></script>';
  179. // Set bredcrumb
  180. switch ($current_page)
  181. {
  182. case 'new_post' :
  183. $nameTools = get_lang('NewPost');
  184. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  185. Display :: display_header($nameTools, 'Blogs');
  186. break;
  187. case 'manage_tasks' :
  188. $nameTools = get_lang('TaskManager');
  189. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  190. Display :: display_header($nameTools, 'Blogs');
  191. break;
  192. case 'manage_members' :
  193. $nameTools = get_lang('MemberManager');
  194. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", "name" => Blog :: get_blog_title($blog_id));
  195. Display :: display_header($nameTools, 'Blogs');
  196. break;
  197. case 'manage_rights' :
  198. $nameTools = get_lang('RightsManager');
  199. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", 'name' => Blog :: get_blog_title($blog_id));
  200. Display :: display_header($nameTools, 'Blogs');
  201. break;
  202. case 'view_search_result' :
  203. $nameTools = get_lang('SearchResults');
  204. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", 'name' => Blog :: get_blog_title($blog_id));
  205. Display :: display_header($nameTools, 'Blogs');
  206. break;
  207. case 'execute_task' :
  208. $nameTools = get_lang('ExecuteThisTask');
  209. $interbreadcrumb[] = array ('url' => "blog.php?blog_id=$blog_id", 'name' => Blog :: get_blog_title($blog_id));
  210. Display :: display_header($nameTools, 'Blogs');
  211. break;
  212. default :
  213. $nameTools = Blog :: get_blog_title($blog_id);
  214. Display :: display_header($nameTools, 'Blogs');
  215. }
  216. // feedback messages
  217. if (!empty($return_message))
  218. {
  219. if ($return_message['type'] == 'confirmation')
  220. {
  221. Display::display_confirmation_message($return_message['message']);
  222. }
  223. if ($return_message['type'] == 'error')
  224. {
  225. Display::display_error_message($return_message['message']);
  226. }
  227. }
  228. // actions
  229. echo '<div class=actions>';
  230. ?>
  231. <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'),'','32'); ?></a>
  232. <?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'),'','32'); ?></a><?php } ?>
  233. <?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'),'','32'); ?></a><?php } ?>
  234. <?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'),'','32'); ?></a><?php } ?>
  235. <?php
  236. echo '</div>';
  237. // Tool introduction
  238. Display::display_introduction_section(TOOL_BLOG);
  239. //Display::display_header($nameTools,'Blogs');
  240. ?>
  241. <div class="sectiontitle"><?php echo Blog::get_blog_title($blog_id); ?></div>
  242. <div class="sectioncomment"><?php echo Blog::get_blog_subtitle($blog_id); ?></div>
  243. <table width="100%">
  244. <tr>
  245. <td width="10%" style="float;left;" class="blog_left" valign="top">
  246. <?php
  247. $month = (int)$_GET['month'] ? (int)$_GET['month'] : (int) date('m');
  248. $year = (int)$_GET['year'] ? (int)$_GET['year'] : date('Y');
  249. Blog :: display_minimonthcalendar($month, $year, $blog_id);
  250. ?>
  251. <br />
  252. <br />
  253. <table width="100%">
  254. <tr>
  255. <td class="sectiontitle"><?php echo get_lang('Search') ?></td>
  256. </tr>
  257. <tr>
  258. <td class="blog_menu">
  259. <form action="blog.php" method="get" enctype="multipart/form-data">
  260. <input type="hidden" name="blog_id" value="<?php echo $blog_id ?>" />
  261. <input type="hidden" name="action" value="view_search_result" />
  262. <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>
  263. </form>
  264. </td>
  265. </tr>
  266. </table>
  267. <br />
  268. <table width="100%">
  269. <tr>
  270. <td class="sectiontitle"><?php echo get_lang('MyTasks') ?></td>
  271. </tr>
  272. <tr>
  273. <td class="blog_menu">
  274. <?php Blog::get_personal_task_list(); ?>
  275. </td>
  276. </tr>
  277. </table>
  278. <!--
  279. <br />
  280. <table width="100%">
  281. <tr>
  282. <td class="blog_menu_title"><?php echo get_lang('FavoriteBlogs') ?></td>
  283. </tr>
  284. <tr>
  285. <td class="blog_menu">
  286. <ul>
  287. <li>Favorite 1</li>
  288. <li>Favorite 2</li>
  289. <li>Favorite 3</li>
  290. </ul>
  291. </td>
  292. </tr>
  293. </table>
  294. <br />
  295. <table width="100%">
  296. <tr>
  297. <td class="blog_menu_title"><?php echo get_lang('TopTen') ?></td>
  298. </tr>
  299. <tr>
  300. <td class="blog_menu">
  301. <ul>
  302. <li>Blog 1</li>
  303. <li>Blog 2</li>
  304. <li>Blog 3</li>
  305. </ul>
  306. </td>
  307. </tr>
  308. </table>
  309. -->
  310. </td>
  311. <td valign="top" class="blog_right">
  312. <?php
  313. if ($error)
  314. Display :: display_error_message($message);
  315. if ($flag == '1')
  316. {
  317. $current_page = "manage_tasks";
  318. Blog :: display_assign_task_form($blog_id);
  319. }
  320. $user_task = false;
  321. if (isset ($_GET['task_id']) && is_numeric($_GET['task_id'])) {
  322. $task_id = (int)$_GET['task_id'];
  323. } else {
  324. $task_id = 0;
  325. $tbl_blogs_tasks_rel_user = Database :: get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  326. $sql = "SELECT COUNT(*) as number
  327. FROM ".$tbl_blogs_tasks_rel_user."
  328. WHERE
  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();