viewforumcategory.php 18 KB

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