blog.php 17 KB

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