index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <?php // $Id: document.php 16494 2008-10-10 22:07:36Z yannoo $
  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. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. * These files are a complete rework of the forum. The database structure is
  22. * based on phpBB but all the code is rewritten. A lot of new functionalities
  23. * are added:
  24. * - forum categories and forums can be sorted up or down, locked or made invisible
  25. * - consistent and integrated forum administration
  26. * - forum options: are students allowed to edit their post?
  27. * moderation of posts (approval)
  28. * reply only forums (students cannot create new threads)
  29. * multiple forums per group
  30. * - sticky messages
  31. * - new view option: nested view
  32. * - quoting a message
  33. *
  34. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  35. * @Copyright Ghent University
  36. * @Copyright Patrick Cool
  37. *
  38. * @package dokeos.forum
  39. */
  40. // name of the language file that needs to be included
  41. $language_file = 'forum';
  42. // including the global dokeos file
  43. require '../inc/global.inc.php';
  44. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/jquery.js" ></script>';
  45. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  46. $(document).ready(function(){ $(\'.hide-me\').slideUp() });
  47. function hidecontent(content){ $(content).slideToggle(\'normal\'); }
  48. </script>';
  49. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  50. function advanced_parameters() {
  51. if(document.getElementById(\'options\').style.display == \'none\') {
  52. document.getElementById(\'options\').style.display = \'block\';
  53. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  54. } else {
  55. document.getElementById(\'options\').style.display = \'none\';
  56. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  57. }
  58. }
  59. </script>';
  60. // the section (tabs)
  61. $this_section=SECTION_COURSES;
  62. // notice for unauthorized people.
  63. api_protect_course_script(true);
  64. // including additional library scripts
  65. require_once(api_get_path(LIBRARY_PATH).'/text.lib.php');
  66. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  67. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  68. $nameTools=get_lang('Forums');
  69. /*
  70. -----------------------------------------------------------
  71. Including necessary files
  72. -----------------------------------------------------------
  73. */
  74. require 'forumconfig.inc.php';
  75. require_once 'forumfunction.inc.php';
  76. /*
  77. ==============================================================================
  78. MAIN DISPLAY SECTION
  79. ==============================================================================
  80. */
  81. /*
  82. -----------------------------------------------------------
  83. Header
  84. -----------------------------------------------------------
  85. */
  86. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  87. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  88. $gradebook= $_SESSION['gradebook'];
  89. } elseif (empty($_GET['gradebook'])) {
  90. unset($_SESSION['gradebook']);
  91. $gradebook= '';
  92. }
  93. if (!empty($gradebook) && $gradebook=='view') {
  94. $interbreadcrumb[] = array (
  95. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  96. 'name' => get_lang('ToolGradebook')
  97. );
  98. }
  99. $search_forum=isset($_GET['search']) ? Security::remove_XSS($_GET['search']) : '';
  100. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".$search_forum,"name" => $nameTools);
  101. if (isset($_GET['action']) && $_GET['action']=='add' ) {
  102. switch ($_GET['content']) {
  103. case 'forum': $interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum', 'name' => get_lang('AddForum')); break;
  104. case 'forumcategory':$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory', 'name' => get_lang('AddForumCategory'));break;
  105. default: break;
  106. }
  107. }
  108. Display :: display_header('');
  109. // api_display_tool_title($nameTools);
  110. //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
  111. // Tool introduction
  112. Display::display_introduction_section(TOOL_FORUM);
  113. $form_count=0;
  114. /*
  115. ------------------------------------------------------------------------------------------------------
  116. ACTIONS
  117. ------------------------------------------------------------------------------------------------------
  118. */
  119. $get_actions=isset($_GET['action']) ? $_GET['action'] : '';
  120. if (api_is_allowed_to_edit(false,true)) {
  121. handle_forum_and_forumcategories();
  122. }
  123. // notification
  124. if (isset($_GET['action']) && $_GET['action'] == 'notify' AND isset($_GET['content']) AND isset($_GET['id'])) {
  125. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  126. api_not_allowed();
  127. }
  128. $return_message = set_notification($_GET['content'],$_GET['id']);
  129. Display :: display_confirmation_message($return_message,false);
  130. }
  131. get_whats_new();
  132. $whatsnew_post_info = array();
  133. $whatsnew_post_info = $_SESSION['whatsnew_post_info'];
  134. /*
  135. -----------------------------------------------------------
  136. TRACKING
  137. -----------------------------------------------------------
  138. */
  139. event_access_tool(TOOL_FORUM);
  140. /*
  141. ------------------------------------------------------------------------------------------------------
  142. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  143. ------------------------------------------------------------------------------------------------------
  144. note: we do this here just after het handling of the actions to be sure that we already incorporate the
  145. latest changes
  146. */
  147. // Step 1: We store all the forum categories in an array $forum_categories
  148. $forum_categories=array();
  149. $forum_categories_list=get_forum_categories();
  150. // step 2: we find all the forums (only the visible ones if it is a student)
  151. $forum_list=array();
  152. $forum_list=get_forums();
  153. /*
  154. ------------------------------------------------------------------------------------------------------
  155. RETRIEVING ALL GROUPS AND THOSE OF THE USER
  156. ------------------------------------------------------------------------------------------------------
  157. */
  158. // the groups of the user
  159. $groups_of_user=array();
  160. $groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  161. // all groups in the course (and sorting them as the id of the group = the key of the array
  162. if (!api_is_anonymous()) {
  163. $all_groups=GroupManager::get_group_list();
  164. if(is_array($all_groups)) {
  165. foreach ($all_groups as $group) {
  166. $all_groups[$group['id']]=$group;
  167. }
  168. }
  169. }
  170. /*
  171. ------------------------------------------------------------------------------------------------------
  172. CLEAN GROUP ID FOR AJAXFILEMANAGER
  173. ------------------------------------------------------------------------------------------------------
  174. */
  175. if(isset($_SESSION['_gid']))
  176. {
  177. unset($_SESSION['_gid']);
  178. }
  179. /*
  180. ------------------------------------------------------------------------------------------------------
  181. ACTION LINKS
  182. ------------------------------------------------------------------------------------------------------
  183. */
  184. $session_id=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : false;
  185. //if (api_is_allowed_to_edit() and !$_GET['action'])
  186. echo '<div class="actions">';
  187. echo '<span>'.search_link().'</span>';
  188. if (api_is_allowed_to_edit(false,true)) {
  189. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory"> '.Display::return_icon('forum_category_new.gif', get_lang('AddForumCategory')).' '.get_lang('AddForumCategory').'</a>';
  190. if (is_array($forum_categories_list) and !empty($forum_categories_list)) {
  191. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum"> '.Display::return_icon('forum_new.gif', get_lang('AddForum')).' '.get_lang('AddForum').'</a>';
  192. }
  193. //echo ' | <a href="forum_migration.php">'.get_lang('MigrateForum').'</a>';
  194. }
  195. echo '</div>';
  196. /*
  197. ------------------------------------------------------------------------------------------------------
  198. Display Forum Categories and the Forums in it
  199. ------------------------------------------------------------------------------------------------------
  200. */
  201. echo '<table class="data_table">'."\n";
  202. // Step 3: we display the forum_categories first
  203. if(is_array($forum_categories_list)) {
  204. foreach ($forum_categories_list as $forum_category_key => $forum_category) {
  205. //validacion when belongs to a session
  206. $session_img = api_get_session_image($forum_category['session_id'], $_user['status']);
  207. if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum_category['session_name'])) {
  208. $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
  209. } else {
  210. $session_displayed = '';
  211. }
  212. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"5\">";
  213. echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.prepare4display(Security::remove_XSS($forum_category['cat_id'])).'" '.class_visible_invisible(prepare4display($forum_category['visibility'])).'>'.prepare4display(Security::remove_XSS($forum_category['cat_title'])).$session_displayed.'</a>'. $session_img .'<br />';
  214. if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>'&nbsp;') {
  215. echo '<span class="forum_description">'.prepare4display(Security::remove_XSS($forum_category['cat_comment'],STUDENT)).'</span>';
  216. }
  217. echo "</th>\n";
  218. echo '<th style="vertical-align: top;" align="center" >';
  219. if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($session_id)!=0)) {
  220. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=edit&amp;content=forumcategory&amp;id=".prepare4display($forum_category['cat_id'])."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  221. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=delete&amp;content=forumcategory&amp;id=".prepare4display($forum_category['cat_id'])."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForumCategory"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  222. display_visible_invisible_icon('forumcategory', prepare4display($forum_category['cat_id']), prepare4display($forum_category['visibility']));
  223. display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id']), prepare4display($forum_category['locked']));
  224. display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id']), $forum_categories_list);
  225. }
  226. echo '</th>';
  227. echo "\t</tr>\n";
  228. // step 4: the interim headers (for the forum)
  229. echo "\t<tr class=\"forum_header\">\n";
  230. echo "\t\t<td colspan=\"2\">".get_lang('Forum')."</td>\n";
  231. echo "\t\t<td>".get_lang('Topics')."</td>\n";
  232. echo "\t\t<td>".get_lang('Posts')."</td>\n";
  233. echo "\t\t<td>".get_lang('LastPosts')."</td>\n";
  234. echo "\t\t<td>".get_lang('Actions')."</td>\n";
  235. echo "\t</tr>\n";
  236. // the forums in this category
  237. $forums_in_category=get_forums_in_category($forum_category['cat_id']);
  238. // step 5: we display all the forums in this category.
  239. $forum_count=0;
  240. foreach ($forum_list as $key=>$forum) {
  241. // Here we clean the whatnew_post_info array a little bit because to display the icon we
  242. // test if $whatsnew_post_info[$forum['forum_id']] is empty or not.
  243. if (!empty($whatsnew_post_info)) {
  244. if (is_array(isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null)) {
  245. foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) {
  246. if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id])) {
  247. unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]);
  248. unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]);
  249. }
  250. }
  251. }
  252. }
  253. // note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key.
  254. if (prepare4display($forum['forum_category'])==prepare4display($forum_category['cat_id'])) {
  255. // the forum has to be showed if
  256. // 1.v it is a not a group forum (teacher and student)
  257. // 2.v it is a group forum and it is public (teacher and student)
  258. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  259. // if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed
  260. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
  261. //{
  262. $show_forum=false;
  263. // SHOULD WE SHOW THIS PARTICULAR FORUM
  264. // you are teacher => show forum
  265. if (api_is_allowed_to_edit(false,true)) {
  266. //echo 'teacher';
  267. $show_forum=true;
  268. } else {// you are not a teacher
  269. //echo 'student';
  270. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  271. if ($forum['forum_of_group']=='0') {
  272. //echo '-gewoon forum';
  273. $show_forum=true;
  274. } else {
  275. // it is a group forum
  276. //echo '-groepsforum';
  277. // it is a group forum but it is public => show
  278. if ($forum['forum_group_public_private']=='public') {
  279. $show_forum=true;
  280. //echo '-publiek';
  281. } else if ($forum['forum_group_public_private']=='private') {
  282. // it is a group forum and it is private
  283. //echo '-prive';
  284. // it is a group forum and it is private but the user is member of the group
  285. if (in_array($forum['forum_of_group'],$groups_of_user)) {
  286. //echo '-is lid';
  287. $show_forum=true;
  288. } else {
  289. //echo '-is GEEN lid';
  290. $show_forum=false;
  291. }
  292. } else {
  293. $show_forum=false;
  294. }
  295. }
  296. }
  297. //echo '<hr>';
  298. if ($show_forum) {
  299. $form_count++;
  300. $mywhatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']]: null;
  301. echo "\t<tr class=\"forum\">\n";
  302. // Showing the image
  303. if(!empty($forum['forum_image'])) {
  304. $image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$forum['forum_image'];
  305. $image_size = api_getimagesize($image_path);
  306. $img_attributes = '';
  307. if (!empty($image_size)) {
  308. if ($image_size[0] > 100 || $image_size[1] > 100) {
  309. //limit display width and height to 100px
  310. $img_attributes = 'width="100" height="100"';
  311. }
  312. echo "<img src=\"$image_path\" $img_attributes>";
  313. }
  314. }
  315. echo "</td>\n";
  316. echo "\t\t<td width=\"20\">";
  317. if ($forum['forum_of_group']!=='0') {
  318. if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
  319. echo icon('../img/forumgroupnew.gif');
  320. } else {
  321. echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
  322. }
  323. } else {
  324. if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
  325. echo icon('../img/forum.gif', get_lang('Forum'));
  326. } else {
  327. echo icon('../img/forum.gif');
  328. }
  329. }
  330. echo "</td>\n";
  331. //validacion when belongs to a session
  332. $session_img = api_get_session_image($forum['session_id'], $_user['status']);
  333. if ($forum['forum_of_group'] <> '0') {
  334. $my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
  335. $my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
  336. $group_title = api_substr($my_all_groups_forum_name, 0, 30);
  337. $forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$forum['forum_of_group'].'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)' . $session_img;
  338. } else {
  339. $forum_title_group_addition = '';
  340. }
  341. if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
  342. $session_displayed = ' ('.$forum['session_name'].')';
  343. } else {
  344. $session_displayed = '';
  345. }
  346. $forum['forum_of_group']==0?$groupid='':$groupid=$forum['forum_of_group'];
  347. echo "\t\t<td><a href=\"viewforum.php?".api_get_cidreq()."&gidReq=".Security::remove_XSS($groupid)."&forum=".prepare4display($forum['forum_id'])."\" ".class_visible_invisible(prepare4display($forum['visibility'])).">".prepare4display(Security::remove_XSS($forum['forum_title'])).$session_displayed.'</a>'.$forum_title_group_addition.'<br />'.prepare4display(Security::remove_XSS($forum['forum_comment'],STUDENT))."</td>\n";
  348. //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  349. // the number of topics and posts
  350. $number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : null;
  351. $number_posts =isset($forum['number_of_posts']) ? $forum['number_of_posts'] : null;
  352. echo "\t\t<td>".$number_threads."</td>\n";
  353. echo "\t\t<td>".$number_posts."</td>\n";
  354. // the last post in the forum
  355. if ($forum['last_poster_name']<>'') {
  356. $name=$forum['last_poster_name'];
  357. $poster_id=0;
  358. } else {
  359. $name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
  360. $poster_id=$forum['last_poster_id'];
  361. }
  362. echo "\t\t<td nowrap=\"nowrap\">";
  363. if (!empty($forum['last_post_id'])) {
  364. echo api_convert_and_format_date($forum['last_post_date'], null, date_default_timezone_get())."<br /> ".get_lang('By').' '.display_user_link($poster_id, $name);
  365. }
  366. echo "</td>\n";
  367. echo "\t\t<td nowrap=\"nowrap\" align=\"center\">";
  368. if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval($session_id)!=0)) {
  369. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  370. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=delete&amp;content=forum&amp;id=".$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForum"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  371. display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility']);
  372. display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked']);
  373. display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
  374. }
  375. $iconnotify = 'send_mail.gif';
  376. $session_forum_noti=isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : false;
  377. if (is_array($session_forum_noti)) {
  378. if (in_array($forum['forum_id'],$session_forum_noti)) {
  379. $iconnotify = 'send_mail_checked.gif';
  380. }
  381. }
  382. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true) ) {
  383. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
  384. }
  385. echo "</td>\n";
  386. echo "\t</tr>";
  387. }
  388. }
  389. }
  390. if (count($forum_list)==0) {
  391. echo "\t<tr><td>".get_lang('NoForumInThisCategory')."</td>".(api_is_allowed_to_edit(false,true)?'<td colspan="6"></td>':'<td colspan="6"></td>')."</tr>\n";
  392. }
  393. }
  394. }
  395. echo "</table>\n";
  396. /*
  397. ==============================================================================
  398. FOOTER
  399. ==============================================================================
  400. */
  401. Display :: display_footer();