dokeos-forum
[ class tree: dokeos-forum ] [ index: dokeos-forum ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2006 Dokeos S.A.
  7.     Copyright (c) 2006 Ghent University (UGent)
  8.  
  9.     For a full list of contributors, see "credits.txt".
  10.     The full license can be read in "license.txt".
  11.  
  12.     This program is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU General Public License
  14.     as published by the Free Software Foundation; either version 2
  15.     of the License, or (at your option) any later version.
  16.  
  17.     See the GNU General Public License for more details.
  18.  
  19.     Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  20.     Mail: info@dokeos.com
  21. ==============================================================================
  22. */
  23.  
  24. /**
  25. *    These files are a complete rework of the forum. The database structure is
  26. *    based on phpBB but all the code is rewritten. A lot of new functionalities
  27. *    are added:
  28. *     - forum categories and forums can be sorted up or down, locked or made invisible
  29. *    - consistent and integrated forum administration
  30. *     - forum options:     are students allowed to edit their post?
  31. *                         moderation of posts (approval)
  32. *                         reply only forums (students cannot create new threads)
  33. *                         multiple forums per group
  34. *    - sticky messages
  35. *     - new view option: nested view
  36. *     - quoting a message
  37. *
  38. *    @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  39. *    @Copyright Ghent University
  40. *    @Copyright Patrick Cool
  41. *
  42. *     @package dokeos.forum
  43. */
  44.  
  45. // name of the language file that needs to be included
  46. $language_file 'forum';
  47.  
  48. // including the global dokeos file
  49. require ('../inc/global.inc.php');
  50.  
  51. // the section (tabs)
  52. $this_section=SECTION_COURSES;
  53.  
  54. // notice for unauthorized people.
  55.  
  56. // including additional library scripts
  57. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  58. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  59. $nameTools=get_lang('Forum');
  60.  
  61. /*
  62. -----------------------------------------------------------
  63.     Including necessary files
  64. -----------------------------------------------------------
  65. */
  66. include('forumconfig.inc.php');
  67. include('forumfunction.inc.php');
  68.  
  69. $fck_attribute['Width''100%';
  70. $fck_attribute['Height''175';
  71. $fck_attribute['ToolbarSet''Middle';
  72. $fck_attribute['Config']['IMUploadPath''upload/forum/';
  73. $fck_attribute['Config']['FlashUploadPath''upload/forum/';
  74. if(!api_is_allowed_to_edit()) $fck_attribute['Config']['UserStatus''student';
  75.  
  76. //error_reporting(E_ALL);
  77. /*
  78. ==============================================================================
  79.         MAIN DISPLAY SECTION
  80. ==============================================================================
  81. */
  82. /*
  83. -----------------------------------------------------------
  84.     Header
  85. -----------------------------------------------------------
  86. */
  87. $interbreadcrumb[]=array("url" => "index.php?search=".Security::remove_XSS($_GET['search']),"name" => $nameTools);
  88.  
  89. if ($_GET['action']=='add' {
  90.         
  91.     switch ($_GET['content']){    
  92.         case 'forum':    $interbreadcrumb[array ("url" => api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum''name' => get_lang('AddForum'))break;
  93.         case 'forumcategory':$interbreadcrumb[array ("url" => api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forumcategory''name' => get_lang('AddForumCategory'));break;
  94.         defaultbreak;  
  95.     }
  96. }
  97.  
  98.  
  99. //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
  100.  
  101. // tool introduction
  102.  
  103. /*
  104. ------------------------------------------------------------------------------------------------------
  105.     ACTIONS
  106. ------------------------------------------------------------------------------------------------------
  107. */
  108. {
  109.     $fck_attribute['ToolbarSet''ForumLight';
  110. }
  111.  
  112. // notification
  113. if ($_GET['action'== 'notify' AND isset($_GET['content']AND isset($_GET['id']))
  114. {
  115.     $return_message set_notification($_GET['content'],$_GET['id']);
  116.     Display :: display_confirmation_message($return_message,false);
  117. }
  118.  
  119. if ($_GET['action']!='add' && $_GET['action']!='edit' )
  120. {
  121.     get_whats_new();
  122.     $whatsnew_post_info array();
  123.     $whatsnew_post_info $_SESSION['whatsnew_post_info'];
  124.         
  125.     /*
  126.     -----------------------------------------------------------
  127.                   TRACKING
  128.     -----------------------------------------------------------
  129.     */
  130.     
  131.     include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  132.     
  133.     
  134.     /*
  135.     ------------------------------------------------------------------------------------------------------
  136.         RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  137.     ------------------------------------------------------------------------------------------------------
  138.     note: we do this here just after het handling of the actions to be sure that we already incorporate the
  139.     latest changes
  140.     */
  141.     // Step 1: We store all the forum categories in an array $forum_categories
  142.     $forum_categories=array();
  143.     $forum_categories_list=get_forum_categories();
  144.     
  145.     // step 2: we find all the forums (only the visible ones if it is a student)
  146.     $forum_list=array();
  147.     $forum_list=get_forums();
  148.     
  149.     /*
  150.     ------------------------------------------------------------------------------------------------------
  151.         RETRIEVING ALL GROUPS AND THOSE OF THE USER
  152.     ------------------------------------------------------------------------------------------------------
  153.     */
  154.     // the groups of the user
  155.     $groups_of_user=array();
  156.     $groups_of_user=GroupManager::get_group_ids($_course['dbName']$_user['user_id']);
  157.     // all groups in the course (and sorting them as the id of the group = the key of the array
  158.     $all_groups=GroupManager::get_group_list();
  159.     if(is_array($all_groups))
  160.     {
  161.         foreach ($all_groups as $group)
  162.         {
  163.             $all_groups[$group['id']]=$group;
  164.         }
  165.     }
  166.     
  167.     /*
  168.     ------------------------------------------------------------------------------------------------------
  169.         ACTION LINKS
  170.     ------------------------------------------------------------------------------------------------------
  171.     */
  172.     //if (api_is_allowed_to_edit() and !$_GET['action'])
  173.     echo '<span style="float:right;">'.search_link().'</span>';
  174.     if (api_is_allowed_to_edit())
  175.     {
  176.         echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forumcategory"> '.Display::return_icon('forum_category_new.gif').' '.get_lang('AddForumCategory').'</a> ';
  177.         if (is_array($forum_categories_list))
  178.         {
  179.             echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum"> '.Display::return_icon('forum_new.gif').' '.get_lang('AddForum').'</a>';
  180.         }
  181.         //echo ' | <a href="forum_migration.php">'.get_lang('MigrateForum').'</a>';
  182.     }
  183.     
  184.     /*
  185.     ------------------------------------------------------------------------------------------------------
  186.         Display Forum Categories and the Forums in it
  187.     ------------------------------------------------------------------------------------------------------
  188.     */
  189.     echo '<table class="data_table" width="100%">'."\n";
  190.     // Step 3: we display the forum_categories first
  191.     if(is_array($forum_categories_list))
  192.     {
  193.         foreach ($forum_categories_list as $forum_category_key => $forum_category)
  194.         {
  195.             echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"5\">";
  196.             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']).'</a><br />';
  197.             
  198.             if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>'&nbsp;')
  199.             {  
  200.                 echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
  201.             }            
  202.             echo "</th>\n";
  203.             
  204.             echo '<th style="padding: 5px; vertical-align: top;" align="center" >';
  205.             if (api_is_allowed_to_edit())
  206.             {
  207.                 echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=edit&amp;content=forumcategory&amp;id=".prepare4display($forum_category['cat_id'])."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  208.                 echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&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>";
  209.                 display_visible_invisible_icon('forumcategory'prepare4display($forum_category['cat_id'])prepare4display($forum_category['visibility']));
  210.                 display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id'])prepare4display($forum_category['locked']));
  211.                 display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id'])$forum_categories_list);
  212.             }
  213.             echo '</th>';                
  214.             echo "\t</tr>\n";
  215.         
  216.             // step 4: the interim headers (for the forum)
  217.             echo "\t<tr class=\"forum_header\">\n";
  218.             echo "\t\t<td colspan='2'>".get_lang('Forum')."</td>\n";
  219.             echo "\t\t<td>".get_lang('Topics')."</td>\n";
  220.             echo "\t\t<td>".get_lang('Posts')."</td>\n";
  221.             echo "\t\t<td>".get_lang('LastPosts')."</td>\n";
  222.                 echo "\t\t<td>".get_lang('Actions')."</td>\n";
  223.             echo "\t</tr>\n";
  224.         
  225.             // the forums in this category
  226.             $forums_in_category=get_forums_in_category($forum_category['cat_id']);
  227.         
  228.             // step 5: we display all the forums in this category.
  229.             $forum_count=0;            
  230.             
  231.             foreach ($forum_list as $key=>$forum)
  232.             {
  233.                 // Here we clean the whatnew_post_info array a little bit because to display the icon we
  234.                 // test if $whatsnew_post_info[$forum['forum_id']] is empty or not.
  235.                 if(is_array($whatsnew_post_info[$forum['forum_id']]))
  236.                 {
  237.                     foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array)
  238.                     {
  239.                         if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id]))
  240.                         {
  241.                             unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]);
  242.                             unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]);
  243.                         }
  244.                     }
  245.                 }
  246.                                         
  247.                 // note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key.
  248.                 if (prepare4display($forum['forum_category'])==prepare4display($forum_category['cat_id']))
  249.                 
  250.                     // the forum has to be showed if
  251.                     // 1.v it is a not a group forum (teacher and student)
  252.                     // 2.v it is a group forum and it is public (teacher and student)
  253.                     // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  254.                     // 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
  255.                     //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
  256.                     //{
  257.                     $show_forum=false;
  258.         
  259.                     // SHOULD WE SHOW THIS PARTICULAR FORUM
  260.                     // you are teacher => show forum
  261.         
  262.                     if (api_is_allowed_to_edit())
  263.                     {
  264.                         //echo 'teacher';
  265.                         $show_forum=true;
  266.                     }
  267.                     // you are not a teacher
  268.                     else
  269.                     {
  270.                         //echo 'student';
  271.                         // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  272.                         if ($forum['forum_of_group']=='0')
  273.                         {
  274.                             //echo '-gewoon forum';
  275.                             $show_forum=true;
  276.                         }
  277.                         // it is a group forum
  278.                         else
  279.                         {
  280.                             //echo '-groepsforum';
  281.                             // it is a group forum but it is public => show
  282.                             if ($forum['forum_group_public_private']=='public')
  283.                             {
  284.                                 $show_forum=true;
  285.                                 //echo '-publiek';
  286.                             }
  287.                             // it is a group forum and it is private
  288.                             else
  289.                             {
  290.                                 //echo '-prive';
  291.                                 // it is a group forum and it is private but the user is member of the group
  292.                                 if (in_array($forum['forum_of_group'],$groups_of_user))
  293.                                 {
  294.                                     //echo '-is lid';
  295.                                     $show_forum=true;
  296.                                 }
  297.                                 else
  298.                                 {
  299.                                     //echo '-is GEEN lid';
  300.                                     $show_forum=false;
  301.                                 }
  302.                             }
  303.         
  304.                         }
  305.                     }
  306.                 
  307.                     
  308.                     //echo '<hr>';
  309.         
  310.                     if ($show_forum)
  311.                     {
  312.                         $form_count++;
  313.                         echo "\t<tr class=\"forum\">\n";
  314.                         echo "\t\t<td width=\"20\">";
  315.                         if ($forum['forum_of_group']!=='0')
  316.                         {
  317.                             if (is_array($whatsnew_post_info[$forum['forum_id']]and !empty($whatsnew_post_info[$forum['forum_id']]))
  318.                             {
  319.                                 echo icon('../img/forumgroupnew.gif');
  320.                             }
  321.                             else
  322.                             {
  323.                                 echo icon('../img/forumgroup.gif');
  324.                             }
  325.                         }
  326.                         else
  327.                         {
  328.                             if (is_array($whatsnew_post_info[$forum['forum_id']]and !empty($whatsnew_post_info[$forum['forum_id']]))
  329.                             {
  330.                                 echo icon('../img/forum.gif');
  331.                             }
  332.                             else
  333.                             {
  334.                                 echo icon('../img/forum.gif');
  335.                             }
  336.         
  337.                         }
  338.                         echo "</td>\n";
  339.                         if ($forum['forum_of_group']<>'0')
  340.                         {
  341.                             $group_title=substr($all_groups[$forum['forum_of_group']]['name'],0,30);
  342.                             $forum_title_group_addition=' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$all_groups[$forum['forum_of_group']]['id'].'" class="forum_group_link">'.$group_title.'</a>)';
  343.                         }
  344.                         else
  345.                         {
  346.                             $forum_title_group_addition='';
  347.                         }
  348.         
  349.                         echo "\t\t<td><a href=\"viewforum.php?".api_get_cidreq()."&forum=".prepare4display($forum['forum_id'])."\" ".class_visible_invisible(prepare4display($forum['visibility'])).">".prepare4display($forum['forum_title']).'</a>'.$forum_title_group_addition.'<br />'.prepare4display($forum['forum_comment'])."</td>\n";
  350.                         //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  351.                         // the number of topics and posts
  352.                         echo "\t\t<td>".$forum['number_of_threads']."</td>\n";
  353.                         echo "\t\t<td>".$forum['number_of_posts']."</td>\n";
  354.                         // the last post in the forum
  355.                         if ($forum['last_poster_name']<>'')
  356.                         {
  357.                             $name=$forum['last_poster_name'];
  358.                             $poster_id=0;
  359.                         }
  360.                         else
  361.                         {
  362.                             $name=$forum['last_poster_firstname'].' '.$forum['last_poster_lastname'];
  363.                             $poster_id=$forum['last_poster_id'];
  364.                         }
  365.                         echo "\t\t<td NOWRAP>";
  366.                         
  367.                         if (!empty($forum['last_post_id']))
  368.                         {
  369.                             echo $forum['last_post_date']."<br /> ".get_lang('By').' '.display_user_link($poster_id$name);
  370.                         }
  371.                         echo "</td>\n";
  372.         
  373.         
  374.                         echo "\t\t<td NOWRAP align='center'>";
  375.                         if (api_is_allowed_to_edit())
  376.                         {
  377.                             echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  378.                             echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&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>";
  379.                             display_visible_invisible_icon('forum',$forum['forum_id']$forum['visibility']);
  380.                             display_lock_unlock_icon('forum',$forum['forum_id']$forum['locked']);
  381.                             display_up_down_icon('forum',$forum['forum_id']$forums_in_category);
  382.                             
  383.                         }
  384.                         $iconnotify 'send_mail.gif';
  385.                         if (is_array($_SESSION['forum_notification']['forum']))
  386.                         {
  387.                             if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum']))
  388.                             {
  389.                                 $iconnotify 'send_mail_checked.gif';
  390.                             }
  391.                         }
  392.                         echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
  393.                         echo "</td>\n";
  394.                         echo "\t</tr>";
  395.                     }
  396.                 }                    
  397.             }
  398.             
  399.             if (count($forum_list)==0)
  400.             {
  401.                 echo "\t<tr><td>".get_lang('NoForumInThisCategory')."</td>".(api_is_allowed_to_edit()?'<td colspan="5"></td>':'<td colspan="4"></td>')."</tr>\n";
  402.             }
  403.         }
  404.     }
  405.     echo "</table>\n";
  406. }
  407. /*
  408. ==============================================================================
  409.         FOOTER
  410. ==============================================================================
  411. */
  412.  
  413. ?>

Documentation generated on Thu, 12 Jun 2008 13:48:56 -0500 by phpDocumentor 1.4.1