viewforumcategory.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 init 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/nolines_minus.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/nolines_plus.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
  57. }
  58. }
  59. </script>';
  60. // including the global dokeos file
  61. require '../inc/global.inc.php';
  62. // the section (tabs)
  63. $this_section=SECTION_COURSES;
  64. // notice for unauthorized people.
  65. api_protect_course_script(true);
  66. // including additional library scripts
  67. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  68. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  69. $nameTools=get_lang('Forum');
  70. /*
  71. -----------------------------------------------------------
  72. Including necessary files
  73. -----------------------------------------------------------
  74. */
  75. require 'forumconfig.inc.php';
  76. require_once 'forumfunction.inc.php';
  77. /*
  78. ==============================================================================
  79. MAIN DISPLAY SECTION
  80. ==============================================================================
  81. */
  82. $fck_attribute['Width'] = '100%';
  83. $fck_attribute['Height'] = '300';
  84. $fck_attribute['ToolbarSet'] = 'Middle';
  85. $fck_attribute['Config']['IMUploadPath'] = 'upload/forum/';
  86. $fck_attribute['Config']['FlashUploadPath'] = 'upload/forum/';
  87. if(!api_is_allowed_to_edit(false,true)) {
  88. $fck_attribute['Config']['UserStatus'] = 'student';
  89. }
  90. /*
  91. -----------------------------------------------------------
  92. Header and Breadcrumbs
  93. -----------------------------------------------------------
  94. */
  95. $current_forum_category=get_forum_categories($_GET['forumcategory']);
  96. $interbreadcrumb[]=array("url" => "index.php?search=".Security::remove_XSS(urlencode(isset($_GET['search'])?$_GET['search']:'')),"name" => $nameTools);
  97. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode(isset($_GET['search'])?$_GET['search']:'')),"name" => prepare4display($current_forum_category['cat_title']));
  98. if (!empty($_GET['action']) && !empty($_GET['content'])) {
  99. if ($_GET['action']=='add' && $_GET['content']=='forum' ) {
  100. $interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum', 'name' => get_lang('AddForum'));
  101. }
  102. }
  103. //are we in a lp ?
  104. $origin = '';
  105. if (isset($_GET['origin'])) {
  106. $origin = Security::remove_XSS($_GET['origin']);
  107. }
  108. if ($origin=='learnpath') {
  109. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  110. } else {
  111. Display :: display_header(null);
  112. api_display_tool_title($nameTools);
  113. }
  114. /*
  115. ------------------------------------------------------------------------------------------------------
  116. ACTIONS
  117. ------------------------------------------------------------------------------------------------------
  118. */
  119. $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
  120. /*
  121. -----------------------------------------------------------
  122. Is the user allowed here?
  123. -----------------------------------------------------------
  124. */
  125. // if the user is not a course administrator and the forum is hidden
  126. // then the user is not allowed here.
  127. if (!api_is_allowed_to_edit(false,true) AND $current_forum_category['visibility']==0) {
  128. forum_not_allowed_here();
  129. }
  130. /*
  131. ------------------------------------------------------------------------------------------------------
  132. ACTIONS
  133. ------------------------------------------------------------------------------------------------------
  134. */
  135. $action_forums=isset($_GET['action']) ? $_GET['action'] : '';
  136. if (api_is_allowed_to_edit(false,true)) {
  137. handle_forum_and_forumcategories();
  138. }
  139. // notification
  140. if ($action_forums == 'notify' AND isset($_GET['content']) AND isset($_GET['id'])) {
  141. $return_message = set_notification($_GET['content'],$_GET['id']);
  142. Display :: display_confirmation_message($return_message,false);
  143. }
  144. if ($action_forums!='add') {
  145. /*
  146. ------------------------------------------------------------------------------------------------------
  147. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  148. ------------------------------------------------------------------------------------------------------
  149. note: we do this here just after het handling of the actions to be sure that we already incorporate the
  150. latest changes
  151. */
  152. // Step 1: We store all the forum categories in an array $forum_categories
  153. $forum_categories=array();
  154. $forum_category=get_forum_categories($_GET['forumcategory']);
  155. // step 2: we find all the forums
  156. $forum_list=array();
  157. $forum_list=get_forums();
  158. /*
  159. ------------------------------------------------------------------------------------------------------
  160. RETRIEVING ALL GROUPS AND THOSE OF THE USER
  161. ------------------------------------------------------------------------------------------------------
  162. */
  163. // the groups of the user
  164. $groups_of_user=array();
  165. $groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  166. // all groups in the course (and sorting them as the id of the group = the key of the array
  167. $all_groups=GroupManager::get_group_list();
  168. if(is_array($all_groups)) {
  169. foreach ($all_groups as $group) {
  170. $all_groups[$group['id']]=$group;
  171. }
  172. }
  173. /*
  174. ------------------------------------------------------------------------------------------------------
  175. CLEAN GROUP ID FOR AJAXFILEMANAGER
  176. ------------------------------------------------------------------------------------------------------
  177. */
  178. if(isset($_SESSION['_gid']))
  179. {
  180. unset($_SESSION['_gid']);
  181. }
  182. /*
  183. -----------------------------------------------------------
  184. Action Links
  185. -----------------------------------------------------------
  186. */
  187. echo '<div class="actions">';
  188. echo '<span style="float:right;">'.search_link().'</span>';
  189. if (api_is_allowed_to_edit(false,true)) {
  190. //echo '<a href="'.api_get_self().'?forumcategory='.$_GET['forumcategory'].'&amp;action=add&amp;content=forumcategory">'.get_lang('AddForumCategory').'</a> | ';
  191. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum"> '.Display::return_icon('forum_new.gif', get_lang('AddForum')).' '.get_lang('AddForum').'</a>';
  192. //echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=add&amp;content=forum">'.Display::return_icon('forum_new.gif', get_lang('AddForum')).' '.get_lang('AddForum').'</a>';
  193. }
  194. echo '</div>';
  195. /*
  196. -----------------------------------------------------------
  197. Display Forum Categories and the Forums in it
  198. -----------------------------------------------------------
  199. */
  200. echo "<table class=\"data_table\" width='100%'>\n";
  201. $my_session=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null;
  202. $forum_categories_list='';
  203. echo "\t<tr>\n\t\t<th align=\"left\" colspan=\"5\">";
  204. echo '<span class="forum_title">'.prepare4display($forum_category['cat_title']).'</span><br />';
  205. echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
  206. echo "</th>\n";
  207. if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($my_session)!=0)) {
  208. echo '<th style="vertical-align: top;" align="center" >';
  209. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=edit&amp;content=forumcategory&amp;id=".$forum_category['cat_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  210. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=delete&amp;content=forumcategory&amp;amp;id=".$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>";
  211. display_visible_invisible_icon('forumcategory', $forum_category['cat_id'], $forum_category['visibility'], array("forumcategory"=>$_GET['forumcategory']));
  212. display_lock_unlock_icon('forumcategory',$forum_category['cat_id'], $forum_category['locked'], array("forumcategory"=>$_GET['forumcategory']));
  213. display_up_down_icon('forumcategory',$forum_category['cat_id'], $forum_categories_list);
  214. echo "</th>\n";
  215. }
  216. echo "\t</tr>\n";
  217. // step 3: the interim headers (for the forum)
  218. echo "\t<tr class=\"forum_header\">\n";
  219. echo "\t\t<td colspan='2'>".get_lang('Forum')."</td>\n";
  220. echo "\t\t<td>".get_lang('Topics')."</td>\n";
  221. echo "\t\t<td>".get_lang('Posts')."</td>\n";
  222. echo "\t\t<td>".get_lang('LastPosts')."</td>\n";
  223. echo "\t\t<td>".get_lang('Actions')."</td>\n";
  224. echo "\t</tr>\n";
  225. // the forums in this category
  226. $forums_in_category=get_forums_in_category($forum_category['cat_id']);
  227. // step 4: we display all the forums in this category.
  228. $forum_count=0;
  229. foreach ($forum_list as $key=>$forum) {
  230. if ($forum['forum_category']==$forum_category['cat_id']) {
  231. // the forum has to be showed if
  232. // 1.v it is a not a group forum (teacher and student)
  233. // 2.v it is a group forum and it is public (teacher and student)
  234. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  235. // 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
  236. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
  237. //{
  238. $show_forum=false;
  239. // SHOULD WE SHOW THIS PARTICULAR FORUM
  240. // you are teacher => show forum
  241. if (api_is_allowed_to_edit(false,true)) {
  242. //echo 'teacher';
  243. $show_forum=true;
  244. } else {
  245. // you are not a teacher
  246. //echo 'student';
  247. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  248. if ($forum['forum_of_group']=='0') {
  249. //echo '-gewoon forum';
  250. $show_forum=true;
  251. } else {
  252. // it is a group forum
  253. //echo '-groepsforum';
  254. // it is a group forum but it is public => show
  255. if ($forum['forum_group_public_private']=='public') {
  256. $show_forum=true;
  257. //echo '-publiek';
  258. } else {
  259. // it is a group forum and it is private
  260. //echo '-prive';
  261. // it is a group forum and it is private but the user is member of the group
  262. if (in_array($forum['forum_of_group'],$groups_of_user)) {
  263. //echo '-is lid';
  264. $show_forum=true;
  265. } else {
  266. //echo '-is GEEN lid';
  267. $show_forum=false;
  268. }
  269. }
  270. }
  271. }
  272. //echo '<hr>';
  273. $form_count=isset($form_count)?$form_count:0;
  274. if ($show_forum === true) {
  275. $form_count++;
  276. echo "\t<tr class=\"forum\">\n";
  277. echo "\t\t<td width=\"20\">";
  278. $my_whatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null;
  279. if ($forum['forum_of_group']!=='0') {
  280. if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
  281. echo icon('../img/forumgroupnew.gif');
  282. } else {
  283. echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
  284. }
  285. } else {
  286. if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
  287. echo icon('../img/forum.gif', get_lang('Forum'));
  288. } else {
  289. echo icon('../img/forum.gif');
  290. }
  291. }
  292. echo "</td>\n";
  293. if ($forum['forum_of_group']<>'0')
  294. {
  295. $my_all_groups_forum_name=isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
  296. $my_all_groups_forum_id=isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
  297. $group_title=substr($my_all_groups_forum_name,0,30);
  298. $forum_title_group_addition=' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$my_all_groups_forum_id.'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)';
  299. }
  300. else
  301. {
  302. $forum_title_group_addition='';
  303. }
  304. if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
  305. $session_displayed = ' ('.$forum['session_name'].')';
  306. } else {
  307. $session_displayed = '';
  308. }
  309. echo "\t\t<td><a href=\"viewforum.php?".api_get_cidreq()."&forum=".$forum['forum_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode(isset($_GET['search'])?$_GET['search']:''))."\" ".class_visible_invisible($forum['visibility']).">".prepare4display($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />'.prepare4display($forum['forum_comment'])."</td>\n";
  310. //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  311. // the number of topics and posts
  312. $my_number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : '';
  313. $my_number_posts=isset($forum['number_of_posts']) ? $forum['number_of_posts'] : '';
  314. echo "\t\t<td>".$my_number_threads."</td>\n";
  315. echo "\t\t<td>".$my_number_posts."</td>\n";
  316. // the last post in the forum
  317. if ($forum['last_poster_name']<>'') {
  318. $name=$forum['last_poster_name'];
  319. $poster_id=0;
  320. } else {
  321. $name=$forum['last_poster_firstname'].' '.$forum['last_poster_lastname'];
  322. $poster_id=$forum['last_poster_id'];
  323. }
  324. echo "\t\t<td>";
  325. if (!empty($forum['last_post_id'])) {
  326. echo $forum['last_post_date']." ".get_lang('By').' '.display_user_link($poster_id, $name);
  327. }
  328. echo "</td>\n";
  329. echo "\t\t<td NOWRAP align='center'>";
  330. if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval(isset($_SESSION['id_session'])?$_SESSION['id_session']:null)!=0)) {
  331. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  332. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;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>";
  333. display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility'], array("forumcategory"=>$_GET['forumcategory']));
  334. display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked'], array("forumcategory"=>$_GET['forumcategory']));
  335. display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
  336. }
  337. $iconnotify = 'send_mail.gif';
  338. if (is_array(isset($_SESSION['forum_notification']['forum'])?$_SESSION['forum_notification']['forum']:null)) {
  339. if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum'])) {
  340. $iconnotify = 'send_mail_checked.gif';
  341. }
  342. }
  343. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
  344. echo "</td>\n";
  345. echo "\t</tr>";
  346. }
  347. }
  348. }
  349. if (count($forum_list) == 0) {
  350. echo "\t<tr><td>".get_lang('NoForumInThisCategory')."</td></tr>\n";
  351. }
  352. echo "</table>\n";
  353. }
  354. /*
  355. ==============================================================================
  356. FOOTER
  357. ==============================================================================
  358. */
  359. // footer
  360. if ($origin!='learnpath') {
  361. Display :: display_footer();
  362. }