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

Source for file group.php

Documentation is available at group.php

  1. <?php
  2. /*
  3. ===============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
  10.     Copyright (c) Bart Mollet
  11.  
  12.     For a full list of contributors, see "credits.txt".
  13.     The full license can be read in "license.txt".
  14.  
  15.     This program is free software; you can redistribute it and/or
  16.     modify it under the terms of the GNU General Public License
  17.     as published by the Free Software Foundation; either version 2
  18.     of the License, or (at your option) any later version.
  19.  
  20.     See the GNU General Public License for more details.
  21.  
  22.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  23.     
  24. ===============================================================================
  25. */
  26. /**
  27. ==============================================================================
  28. *    Main page for the group module.
  29. *    This script displays the general group settings,
  30. *    and a list of groups with buttons to view, edit...
  31. *
  32. *    @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
  33. *    @author Bert Vanderkimpen, improved self-unsubscribe for cvs
  34. *    @author Patrick Cool, show group comment under the group name
  35. *    @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
  36. *    @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
  37. *    @package dokeos.group
  38. ==============================================================================
  39. */
  40. /*
  41. ==============================================================================
  42.         INIT SECTION
  43. ==============================================================================
  44. */
  45. // name of the language file that needs to be included
  46. $language_file 'group';
  47. include ('../inc/global.inc.php');
  48. $this_section=SECTION_COURSES;
  49.  
  50. // notice for unauthorized people.
  51.  
  52. $nameTools get_lang('GroupManagement');
  53.  
  54. /*
  55. -----------------------------------------------------------
  56.     Libraries
  57. -----------------------------------------------------------
  58. */
  59. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  60. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  61. require_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  62.  
  63. //Create default category if it doesn't exist when group categories aren't allowed
  64. ifapi_get_setting('allow_group_categories'== 'false')
  65. {
  66.     $sql "SELECT * FROM $cat_table WHERE id = '".DEFAULT_GROUP_CATEGORY."'";
  67.     $res api_sql_query($sql,__FILE__,__LINE__);
  68.     $num Database::num_rows($res);
  69.     if($num == 0)
  70.     {
  71.         api_sql_query("INSERT INTO ".$cat_table." ( id , title , description , forum_state , max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order ) VALUES ('2', '".lang2db($DefaultGroupCategory)."', '', '1', '8', '0', '0', '0', '0');");
  72.     }
  73. }
  74.  
  75. /*
  76. -----------------------------------------------------------
  77.     Header
  78. -----------------------------------------------------------
  79. */
  80. if (!isset ($_GET['origin']|| $_GET['origin'!= 'learnpath')
  81. //so we are not in learnpath tool
  82.     if ($is_allowed_in_courseapi_not_allowed(true);
  83. }
  84.  
  85. /*
  86. -----------------------------------------------------------
  87.     Introduction section
  88.     (editable by course admins)
  89. -----------------------------------------------------------
  90. */
  91.  
  92. /*
  93.  * Self-registration and unregistration
  94.  */
  95. if (isset ($_GET['action']))
  96. {
  97.     switch ($_GET['action'])
  98.     {
  99.         case 'self_reg' :
  100.             if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id']$_GET['group_id']))
  101.             {
  102.                 GroupManager :: subscribe_users($_SESSION['_user']['user_id']$_GET['group_id']);
  103.                 Display :: display_normal_message(get_lang('GroupNowMember'));
  104.             }
  105.             break;
  106.         case 'self_unreg' :
  107.             if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id']$_GET['group_id']))
  108.             {
  109.                 GroupManager :: unsubscribe_users($_SESSION['_user']['user_id']$_GET['group_id']);
  110.                 Display :: display_normal_message(get_lang('StudentDeletesHimself'));
  111.             }
  112.             break;
  113.         case 'show_msg' :
  114.             Display :: display_normal_message($_GET['msg']);
  115.             break;
  116.     }
  117. }
  118. /*
  119.  * Group-admin functions
  120.  */
  121. {
  122.  
  123.     // Post-actions
  124.     if (isset ($_POST['action']))
  125.     {
  126.         switch ($_POST['action'])
  127.         {
  128.             case 'delete_selected' :
  129.                 ifis_array($_POST['group']))
  130.                 {
  131.                     GroupManager :: delete_groups($_POST['group']);
  132.                     Display :: display_normal_message(get_lang('SelectedGroupsDeleted'));
  133.                 }
  134.                 break;
  135.             case 'empty_selected' :
  136.                 ifis_array($_POST['group']))
  137.                 {
  138.                     GroupManager :: unsubscribe_all_users($_POST['group']);
  139.                     Display :: display_normal_message(get_lang('SelectedGroupsEmptied'));
  140.                 }
  141.                 break;
  142.             case 'fill_selected' :
  143.                 ifis_array($_POST['group']))
  144.                 {
  145.                     GroupManager :: fill_groups($_POST['group']);
  146.                     Display :: display_normal_message(get_lang('SelectedGroupsFilled'));
  147.                 }
  148.                 break;
  149.         }
  150.     }
  151.     // Get-actions
  152.     if (isset ($_GET['action']))
  153.     {
  154.         switch ($_GET['action'])
  155.         {
  156.             case 'swap_cat_order' :
  157.                 GroupManager :: swap_category_order($_GET['id1']$_GET['id2']);
  158.                 Display :: display_normal_message(get_lang('CategoryOrderChanged'));
  159.                 break;
  160.             case 'delete_one' :
  161.                 GroupManager :: delete_groups($_GET['id']);
  162.                 Display :: display_normal_message(get_lang('GroupDel'));
  163.                 break;
  164.             case 'empty_one' :
  165.                 GroupManager :: unsubscribe_all_users($_GET['id']);
  166.                 Display :: display_normal_message(get_lang('GroupEmptied'));
  167.                 break;
  168.             case 'fill_one' :
  169.                 GroupManager :: fill_groups($_GET['id']);
  170.                 Display :: display_normal_message(get_lang('GroupFilledGroups'));
  171.                 break;
  172.             case 'delete_category' :
  173.                 GroupManager :: delete_category($_GET['id']);
  174.                 Display :: display_normal_message(get_lang('CategoryDeleted'));
  175.                 break;
  176.         }
  177.     }
  178.     // Show admin-panel
  179.     echo '<div id="actions">';
  180.     echo '<ul id="groupItems">';
  181.     if (get_setting('allow_group_categories'== 'true')
  182.     {
  183.         echo '<li><a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.get_lang('AddCategory').'</a>&nbsp;</li>';
  184.     }
  185.     else
  186.     {
  187.         //echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('edit_group.gif').'&nbsp;'.get_lang('PropModify').'</a>&nbsp;';
  188.         echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.get_lang('PropModify').'</a>&nbsp;';
  189.     }
  190.     //echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('group_add_big.gif').'&nbsp;'.get_lang('NewGroupCreate').'</a>&nbsp;';
  191.     echo '<li><a href="group_creation.php?'.api_get_cidreq().'">'.get_lang('NewGroupCreate').'</a>&nbsp;</li>';
  192.     {
  193.         //echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_view.gif').'&nbsp;'.get_lang('GroupOverview').'</a>&nbsp;';
  194.         echo '<li><a href="group_overview.php?'.api_get_cidreq().'">'.get_lang('GroupOverview').'</a>&nbsp;</li>';
  195.     }
  196. }
  197. $group_cats GroupManager :: get_categories();
  198. if (get_setting('allow_group_categories'== 'true' && count($group_cats1)
  199. {
  200.     //echo '<p><a href="?'.api_get_cidreq().'&show_all=1">'.get_lang('ShowAll').'</a></p>';
  201.     echo '<li><a href="?'.api_get_cidreq().'&show_all=1">'.get_lang('ShowAll').'</a></li>';
  202. }
  203. echo '</ul>';
  204. /*
  205.  * List all categories
  206.  */
  207. foreach ($group_cats as $index => $category)
  208. {
  209.     $group_list array ();
  210.     $in_category false;
  211.     if (get_setting('allow_group_categories'== 'true')
  212.     {
  213.         if (isset ($_GET['show_all']|| (isset ($_GET['category']&& $_GET['category'== $category['id']))
  214.         {
  215.             echo '<img src="../img/opendir.gif" alt=""/>';
  216.             echo ' <a href="group.php?'.api_get_cidreq().'&origin='.$_GET['origin'].'">'.$category['title'].'</a>';
  217.             $in_category true;
  218.         }
  219.         else
  220.         {
  221.             echo '<img src="../img/file.gif" alt=""/>';
  222.             echo ' <a href="group.php?'.api_get_cidreq().'&origin='.$_GET['origin'].'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
  223.         }
  224.         $group_list GroupManager :: get_group_list($category['id']);
  225.         echo ' ('.count($group_list).' '.get_lang('ExistingGroups').')';
  226.         if (api_is_allowed_to_edit())
  227.         {
  228.             echo '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'"  title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang('Edit').'"/></a> ';
  229.             echo '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'"  onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif"  alt="'.get_lang('Delete').'"/></a> ';
  230.             if ($index != 0)
  231.             {
  232.                 echo ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'"><img src="../img/up.gif" alt=""/></a>';
  233.             }
  234.             if ($index != count($group_cats1)
  235.             {
  236.                 echo ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'"><img src="../img/down.gif" alt=""/></a>';
  237.             }
  238.         }
  239.         echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
  240.     }
  241.     else
  242.     {
  243.         $group_list GroupManager :: get_group_list();
  244.         $in_category true;
  245.     }
  246.     echo '<div style="margin: 0px;margin-left: 50px;">';
  247.     //if (count($group_list) > 0 && $in_category)
  248.     if ($in_category)
  249.     {
  250.         $totalRegistered 0;
  251.         // Determine wether current user is tutor for this course
  252.         $user_is_tutor GroupManager :: is_tutor($_user['user_id']);
  253.         $group_data array ();
  254.         foreach ($group_list as $index => $this_group)
  255.         {
  256.             // all the tutors of this group
  257.             $tutorsids_of_group=GroupManager::get_subscribed_tutors($this_group['id'],true);
  258.  
  259.             // create a new table-row
  260.             $row array ();
  261.             // checkbox
  262.             if (api_is_allowed_to_edit(&& count($group_list1)
  263.             {
  264.                 $row[$this_group['id'];
  265.             }
  266.  
  267.             // group name
  268.             if (api_is_allowed_to_edit(|| 
  269.                     in_array($_user['user_id'],$tutorsids_of_group|| 
  270.                     $this_group['is_member'|| 
  271.                     GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_DOCUMENTS||
  272.                     GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_CALENDAR||
  273.                     GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_ANNOUNCEMENT||
  274.                     GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_WORK))
  275.             {
  276.                 $group_name '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;gidReq='.$this_group['id'].'">'.stripslashes($this_group['name']).'</a>';
  277.                 if ($_SESSION['_user']['user_id'&& $_SESSION['_user']['user_id'== $this_group['id_tutor'])
  278.                 {
  279.                     $group_name .= ' ('.get_lang('OneMyGroups').')';
  280.                 }
  281.                 elseif ($this_group['is_member'])
  282.                 {
  283.                     $group_name .= ' ('.get_lang('MyGroup').')';
  284.                 }
  285.                 $row[$group_name.'<br/>'.stripslashes(trim($this_group['description']));
  286.             }
  287.             else
  288.             {
  289.                 $row[$this_group['name'].'<br/>'.stripslashes(trim($this_group['description']));
  290.             }
  291.             // self-registration / unregistration
  292.             if (!api_is_allowed_to_edit())
  293.             {
  294.                 if (GroupManager :: is_self_registration_allowed($_user['user_id']$this_group['id']))
  295.                 {
  296.                     $row['<a href="group.php?'.api_get_cidreq().'&category='.$category['id'].'&amp;action=self_reg&amp;group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;">'.get_lang('GroupSelfRegInf').'</a>';
  297.                 }
  298.                 elseif (GroupManager :: is_self_unregistration_allowed($_user['user_id']$this_group['id']))
  299.                 {
  300.                     $row['<a href="group.php?'.api_get_cidreq().'&category='.$category['id'].'&amp;action=self_unreg&amp;group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;">'.get_lang('GroupSelfUnRegInf').'</a>';
  301.                 }
  302.                 else
  303.                 {
  304.                     $row['-';
  305.                 }
  306.             }
  307.             // number of members in group
  308.             $row[$this_group['number_of_members'];
  309.             // max number of members in group
  310.             $row[($this_group['maximum_number_of_members'== MEMBER_PER_GROUP_NO_LIMIT '-' $this_group['maximum_number_of_members']);
  311.             // tutor name
  312.             $tutor_info '';
  313.  
  314.             if(count($tutorsids_of_group)>0)
  315.             {
  316.                 foreach($tutorsids_of_group as $tutor_id){
  317.                     $tutor api_get_user_info($tutor_id);
  318.                     $tutor_info .= Display::encrypted_mailto_link($tutor['mail'],$tutor['firstName'].' '.$tutor['lastName']).', ';
  319.                 }
  320.             }
  321.             $tutor_info substr($tutor_info,0,strlen($tutor_info)-2);
  322.             $row[$tutor_info;
  323.             // edit-links
  324.             if (api_is_allowed_to_edit())
  325.             {
  326.                 $edit_actions '<a href="group_edit.php?'.api_get_cidreq().'&gidReq='.$this_group['id'].'"  title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang('Edit').'"/></a>&nbsp;';
  327.                 $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&category='.$category['id'].'&amp;action=delete_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif" alt="'.get_lang('Delete').'"/></a>&nbsp;';
  328.                 $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&category='.$category['id'].'&amp;action=empty_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;" title="'.get_lang('EmptyGroup').'"><img src="../img/group_delete.gif" alt="'.get_lang('EmptyGroup').'"/></a>&nbsp;';
  329.                 $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&category='.$category['id'].'&amp;action=fill_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;" title="'.get_lang('FillGroup').'"><img src="../img/add_user.gif" alt="'.get_lang('FillGroup').'"/></a>';
  330.                 $row[$edit_actions;
  331.             }
  332.             $totalRegistered $totalRegistered $this_group['nbMember'];
  333.             $group_data[$row;
  334.         // while loop
  335.         if (isset ($_GET['show_all']))
  336.         {
  337.             $paging_options array ('per_page' => count($group_data));
  338.         }
  339.         else
  340.         {
  341.             $paging_options array ();
  342.         }
  343.         $table new SortableTableFromArray($group_data1);
  344.         $table->set_additional_parameters(array('category'=>$_GET['category']));
  345.         $column 0;
  346.         if (api_is_allowed_to_edit(and count($group_list1)
  347.         {
  348.             $table->set_header($column++,''false);
  349.         }
  350.         $table->set_header($column++,get_lang('ExistingGroups'));
  351.         if (!api_is_allowed_to_edit()) // If self-registration allowed
  352.         {
  353.             $table->set_header($column++,get_lang('GroupSelfRegistration'));
  354.         }
  355.         $table->set_header($column++,get_lang('Registered'));
  356.         $table->set_header($column++,get_lang('Max'));
  357.         $table->set_header($column++,get_lang('GroupTutor'));
  358.         if (api_is_allowed_to_edit()) // only for course administrator
  359.         {
  360.             $table->set_header($column++,get_lang('Modify')false);
  361.             $form_actions array();
  362.             $form_actions['delete_selected'get_lang('Delete');
  363.             $form_actions['fill_selected'get_lang('FillGroup');
  364.             $form_actions['empty_selected'get_lang('EmptyGroup');
  365.             if (count($group_list1)
  366.             {
  367.                 $table->set_form_actions($form_actions,'group');
  368.             }
  369.         }
  370.         $table->display();
  371.     }
  372.     /*
  373.     elseif ($in_category)
  374.     {
  375.         echo get_lang('NoGroupsAvailable');
  376.     }
  377.     */
  378.     echo '</div>';
  379. }
  380. /*
  381. ==============================================================================
  382.         FOOTER
  383. ==============================================================================
  384. */
  385. if (!isset ($_GET['origin']|| $_GET['origin'!= 'learnpath')
  386. {
  387. }
  388. ?>

Documentation generated on Thu, 12 Jun 2008 13:35:52 -0500 by phpDocumentor 1.4.1