index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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;<img src="../img/div_hide.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
  54. } else {
  55. document.getElementById(\'options\').style.display = \'none\';
  56. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;<img src="../img/div_show.gif" alt="" />&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. $fck_attribute['Width'] = '100%';
  77. $fck_attribute['Height'] = '400';
  78. $fck_attribute['Config']['IMUploadPath'] = 'upload/forum/';
  79. $fck_attribute['Config']['FlashUploadPath'] = 'upload/forum/';
  80. $fck_attribute['Config']['InDocument'] = false;
  81. $fck_attribute['Config']['CreateDocumentDir'] = '../../courses/'.api_get_course_path().'/document/';
  82. if(!api_is_allowed_to_edit(false,true)) {
  83. $fck_attribute['Config']['UserStatus'] = 'student';
  84. $fck_attribute['ToolbarSet'] = 'Forum_Student';
  85. }
  86. else
  87. {
  88. $fck_attribute['ToolbarSet'] = 'Forum';
  89. }
  90. /*
  91. ==============================================================================
  92. MAIN DISPLAY SECTION
  93. ==============================================================================
  94. */
  95. /*
  96. -----------------------------------------------------------
  97. Header
  98. -----------------------------------------------------------
  99. */
  100. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  101. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  102. $gradebook= $_SESSION['gradebook'];
  103. } elseif (empty($_GET['gradebook'])) {
  104. unset($_SESSION['gradebook']);
  105. $gradebook= '';
  106. }
  107. if (!empty($gradebook) && $gradebook=='view') {
  108. $interbreadcrumb[] = array (
  109. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  110. 'name' => get_lang('Gradebook')
  111. );
  112. }
  113. $search_forum=isset($_GET['search']) ? Security::remove_XSS($_GET['search']) : '';
  114. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".$search_forum,"name" => $nameTools);
  115. if (isset($_GET['action']) && $_GET['action']=='add' ) {
  116. switch ($_GET['content']) {
  117. case 'forum': $interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum', 'name' => get_lang('AddForum')); break;
  118. case 'forumcategory':$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory', 'name' => get_lang('AddForumCategory'));break;
  119. default: break;
  120. }
  121. }
  122. Display :: display_header('');
  123. // api_display_tool_title($nameTools);
  124. //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
  125. // Tool introduction
  126. $fck_attribute['Width'] = '100%';
  127. $fck_attribute['Height'] = '300';
  128. $fck_attribute['ToolbarSet'] = 'Introduction';
  129. Display::display_introduction_section(TOOL_FORUM,'left');
  130. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  131. $form_count=0;
  132. /*
  133. ------------------------------------------------------------------------------------------------------
  134. ACTIONS
  135. ------------------------------------------------------------------------------------------------------
  136. */
  137. $get_actions=isset($_GET['action']) ? $_GET['action'] : '';
  138. if (api_is_allowed_to_edit(false,true)) {
  139. $fck_attribute['Width'] = '98%';
  140. $fck_attribute['Height'] = '200';
  141. $fck_attribute['ToolbarSet'] = 'Forum';
  142. handle_forum_and_forumcategories();
  143. }
  144. // notification
  145. if (isset($_GET['action']) && $_GET['action'] == 'notify' AND isset($_GET['content']) AND isset($_GET['id'])) {
  146. $return_message = set_notification($_GET['content'],$_GET['id']);
  147. Display :: display_confirmation_message($return_message,false);
  148. }
  149. get_whats_new();
  150. $whatsnew_post_info = array();
  151. $whatsnew_post_info = $_SESSION['whatsnew_post_info'];
  152. /*
  153. -----------------------------------------------------------
  154. TRACKING
  155. -----------------------------------------------------------
  156. */
  157. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  158. event_access_tool(TOOL_FORUM);
  159. /*
  160. ------------------------------------------------------------------------------------------------------
  161. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  162. ------------------------------------------------------------------------------------------------------
  163. note: we do this here just after het handling of the actions to be sure that we already incorporate the
  164. latest changes
  165. */
  166. // Step 1: We store all the forum categories in an array $forum_categories
  167. $forum_categories=array();
  168. $forum_categories_list=get_forum_categories();
  169. // step 2: we find all the forums (only the visible ones if it is a student)
  170. $forum_list=array();
  171. $forum_list=get_forums();
  172. /*
  173. ------------------------------------------------------------------------------------------------------
  174. RETRIEVING ALL GROUPS AND THOSE OF THE USER
  175. ------------------------------------------------------------------------------------------------------
  176. */
  177. // the groups of the user
  178. $groups_of_user=array();
  179. $groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  180. // all groups in the course (and sorting them as the id of the group = the key of the array
  181. $all_groups=GroupManager::get_group_list();
  182. if(is_array($all_groups)) {
  183. foreach ($all_groups as $group) {
  184. $all_groups[$group['id']]=$group;
  185. }
  186. }
  187. /*
  188. ------------------------------------------------------------------------------------------------------
  189. CLEAN GROUP ID FOR AJAXFILEMANAGER
  190. ------------------------------------------------------------------------------------------------------
  191. */
  192. if(isset($_SESSION['_gid']))
  193. {
  194. unset($_SESSION['_gid']);
  195. }
  196. /*
  197. ------------------------------------------------------------------------------------------------------
  198. ACTION LINKS
  199. ------------------------------------------------------------------------------------------------------
  200. */
  201. $session_id=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : false;
  202. //if (api_is_allowed_to_edit() and !$_GET['action'])
  203. echo '<div class="actions">';
  204. echo '<span style="float:right;">'.search_link().'</span>';
  205. if (api_is_allowed_to_edit(false,true)) {
  206. 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>';
  207. if (is_array($forum_categories_list) and !empty($forum_categories_list)) {
  208. 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>';
  209. }
  210. //echo ' | <a href="forum_migration.php">'.get_lang('MigrateForum').'</a>';
  211. }
  212. echo '</div>';
  213. /*
  214. ------------------------------------------------------------------------------------------------------
  215. Display Forum Categories and the Forums in it
  216. ------------------------------------------------------------------------------------------------------
  217. */
  218. echo '<table class="data_table">'."\n";
  219. // Step 3: we display the forum_categories first
  220. if(is_array($forum_categories_list)) {
  221. foreach ($forum_categories_list as $forum_category_key => $forum_category) {
  222. if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum_category['session_name'])) {
  223. $session_displayed = ' ('.$forum_category['session_name'].')';
  224. } else {
  225. $session_displayed = '';
  226. }
  227. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
  228. echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.prepare4display($forum_category['cat_id']).'" '.class_visible_invisible(prepare4display($forum_category['visibility'])).'>'.prepare4display($forum_category['cat_title']).$session_displayed.'</a><br />';
  229. if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>'&nbsp;') {
  230. echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
  231. }
  232. echo "</th>\n";
  233. echo '<th style="vertical-align: top;" align="center" >';
  234. if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($session_id)!=0)) {
  235. 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>";
  236. 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(htmlentities(get_lang("DeleteForumCategory"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  237. display_visible_invisible_icon('forumcategory', prepare4display($forum_category['cat_id']), prepare4display($forum_category['visibility']));
  238. display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id']), prepare4display($forum_category['locked']));
  239. display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id']), $forum_categories_list);
  240. }
  241. echo '</th>';
  242. echo "\t</tr>\n";
  243. // step 4: the interim headers (for the forum)
  244. echo "\t<tr class=\"forum_header\">\n";
  245. echo "\t\t<td colspan=\"3\">".get_lang('Forum')."</td>\n";
  246. echo "\t\t<td>".get_lang('Topics')."</td>\n";
  247. echo "\t\t<td>".get_lang('Posts')."</td>\n";
  248. echo "\t\t<td>".get_lang('LastPosts')."</td>\n";
  249. echo "\t\t<td>".get_lang('Actions')."</td>\n";
  250. echo "\t</tr>\n";
  251. // the forums in this category
  252. $forums_in_category=get_forums_in_category($forum_category['cat_id']);
  253. // step 5: we display all the forums in this category.
  254. $forum_count=0;
  255. foreach ($forum_list as $key=>$forum) {
  256. // Here we clean the whatnew_post_info array a little bit because to display the icon we
  257. // test if $whatsnew_post_info[$forum['forum_id']] is empty or not.
  258. if (!empty($whatsnew_post_info)) {
  259. if (is_array(isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null)) {
  260. foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) {
  261. if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id])) {
  262. unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]);
  263. unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]);
  264. }
  265. }
  266. }
  267. }
  268. // note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key.
  269. if (prepare4display($forum['forum_category'])==prepare4display($forum_category['cat_id'])) {
  270. // the forum has to be showed if
  271. // 1.v it is a not a group forum (teacher and student)
  272. // 2.v it is a group forum and it is public (teacher and student)
  273. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  274. // 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
  275. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
  276. //{
  277. $show_forum=false;
  278. // SHOULD WE SHOW THIS PARTICULAR FORUM
  279. // you are teacher => show forum
  280. if (api_is_allowed_to_edit(false,true)) {
  281. //echo 'teacher';
  282. $show_forum=true;
  283. } else {// you are not a teacher
  284. //echo 'student';
  285. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  286. if ($forum['forum_of_group']=='0') {
  287. //echo '-gewoon forum';
  288. $show_forum=true;
  289. } else {
  290. // it is a group forum
  291. //echo '-groepsforum';
  292. // it is a group forum but it is public => show
  293. if ($forum['forum_group_public_private']=='public') {
  294. $show_forum=true;
  295. //echo '-publiek';
  296. } else if ($forum['forum_group_public_private']=='private') {
  297. // it is a group forum and it is private
  298. //echo '-prive';
  299. // it is a group forum and it is private but the user is member of the group
  300. if (in_array($forum['forum_of_group'],$groups_of_user)) {
  301. //echo '-is lid';
  302. $show_forum=true;
  303. } else {
  304. //echo '-is GEEN lid';
  305. $show_forum=false;
  306. }
  307. } else {
  308. $show_forum=false;
  309. }
  310. }
  311. }
  312. //echo '<hr>';
  313. if ($show_forum) {
  314. $form_count++;
  315. $mywhatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']]: null;
  316. echo "\t<tr class=\"forum\">\n";
  317. // Showing the image
  318. echo "\t\t<td width=\"50\">";
  319. if(!empty($forum['forum_image'])) {
  320. $image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$forum['forum_image'];
  321. $image_size = @getimagesize($image_path);
  322. $img_attributes = '';
  323. if (!empty($image_size)) {
  324. if ($image_size[0] > 100 || $image_size[1] > 100) {
  325. //limit display width and height to 100px
  326. $img_attributes = 'width="100" height="100"';
  327. }
  328. echo "<img src=\"$image_path\" $img_attributes>";
  329. }
  330. }
  331. echo "</td>\n";
  332. echo "\t\t<td width=\"20\">";
  333. if ($forum['forum_of_group']!=='0') {
  334. if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
  335. echo icon('../img/forumgroupnew.gif');
  336. } else {
  337. echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
  338. }
  339. } else {
  340. if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
  341. echo icon('../img/forum.gif', get_lang('Forum'));
  342. } else {
  343. echo icon('../img/forum.gif');
  344. }
  345. }
  346. echo "</td>\n";
  347. if ($forum['forum_of_group']<>'0') {
  348. $my_all_groups_forum_name=isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
  349. $my_all_groups_forum_id=isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
  350. $group_title=substr($my_all_groups_forum_name,0,30);
  351. $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>)';
  352. } else {
  353. $forum_title_group_addition='';
  354. }
  355. if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
  356. $session_displayed = ' ('.$forum['session_name'].')';
  357. } else {
  358. $session_displayed = '';
  359. }
  360. $forum['forum_of_group']==0?$groupid='':$groupid=$forum['forum_of_group'];
  361. 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($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />'.prepare4display($forum['forum_comment'])."</td>\n";
  362. //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  363. // the number of topics and posts
  364. $number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : null;
  365. $number_posts =isset($forum['number_of_posts']) ? $forum['number_of_posts'] : null;
  366. echo "\t\t<td>".$number_threads."</td>\n";
  367. echo "\t\t<td>".$number_posts."</td>\n";
  368. // the last post in the forum
  369. if ($forum['last_poster_name']<>'') {
  370. $name=$forum['last_poster_name'];
  371. $poster_id=0;
  372. } else {
  373. $name=$forum['last_poster_firstname'].' '.$forum['last_poster_lastname'];
  374. $poster_id=$forum['last_poster_id'];
  375. }
  376. echo "\t\t<td nowrap=\"nowrap\">";
  377. if (!empty($forum['last_post_id'])) {
  378. echo $forum['last_post_date']."<br /> ".get_lang('By').' '.display_user_link($poster_id, $name);
  379. }
  380. echo "</td>\n";
  381. echo "\t\t<td nowrap=\"nowrap\" align=\"center\">";
  382. if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval($session_id)!=0)) {
  383. 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>";
  384. 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(htmlentities(get_lang("DeleteForum"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  385. display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility']);
  386. display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked']);
  387. display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
  388. }
  389. $iconnotify = 'send_mail.gif';
  390. $session_forum_noti=isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : false;
  391. if (is_array($session_forum_noti)) {
  392. if (in_array($forum['forum_id'],$session_forum_noti)) {
  393. $iconnotify = 'send_mail_checked.gif';
  394. }
  395. }
  396. 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>";
  397. echo "</td>\n";
  398. echo "\t</tr>";
  399. }
  400. }
  401. }
  402. if (count($forum_list)==0) {
  403. 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";
  404. }
  405. }
  406. }
  407. echo "</table>\n";
  408. /*
  409. ==============================================================================
  410. FOOTER
  411. ==============================================================================
  412. */
  413. Display :: display_footer();