Code

Reworked list management for groups
[gosa.git] / plugins / admin / groups / class_divListGroup.inc
1 <?php
3 class divListGroup extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
12   var $UserRegex          = "*";
14   /* CheckBoxes */
15   var $ShowPrimaryGroups      = true;
16   var $ShowSambaGroups        = true;  
17   var $ShowApplicationGroups  = true;
18   var $ShowMailGroups         = true;
19   var $ShowFunctionalGroups   = true;
21   /* Subsearch checkbox */
22   var $SubSearch              = false;
24   var $parent             ;
25   var $ui                 ;
27   function divListGroup ($config,$parent)
28   {
29     MultiSelectWindow::MultiSelectWindow($config,"System");
30     
31     $this->parent       = $parent;
32     $this->ui           = get_userinfo();
34     /* Set default base */
35     if(!isset($_SESSION['CurrentMainBase'])){
36       $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
37     }
38     $this->selectedBase = $_SESSION['CurrentMainBase'];
40     /* Set list strings */
41     $this->SetTitle(_("List of groups"));
42     $this->SetSummary(_("List of groups"));
43     $this->EnableAplhabet   (true);
45     /* Result page will look like a headpage */
46     $this->SetHeadpageMode();
47     $this->SetInformation(_("This menu allows you to add, edit and remove selected groups. ".
48                             "You may want to use the range selector on top of the group listbox, when working with a large number of groups."));
49   
50     /* Disable buttonsm */
51     $this->EnableCloseButton(false);
52     $this->EnableSaveButton (false);
54     /* set Page header */
55     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
56     $this->AddHeader(array("string"=>_("Groupname / Department")));
57     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
58     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:80px;border-right:0px;'"));
60     /*                  Text        ,Value    ,Name         ,Is selected */
61     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"),          _("Show primary groups"),      true);
62     $this->AddCheckBox("ShowSambaGroups",       _("Select to see groups that have samba groups mappings"),          _("Show samba groups"),      true);
63     $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"),        _("Show application groups"),true);
64     $this->AddCheckBox("ShowMailGroups",        _("Select to see groups that have mail settings"),                  _("Show mail groups"),       true);
65     $this->AddCheckBox("ShowFunctionalGroups",  _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
66     $this->AddCheckBox(SEPERATOR);
68     /* Add SubSearch checkbox */    
69     $this->AddCheckBox("SubSearch",  _("Select to search search within subtres"), _("Subsearch"), true);
71     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
72     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
73     $this->AddRegex   ("UserRegex", _("User name of which groups are shown"),         "*" , false, "images/search_user.png");
74   }
77   function GenHeader()
78   {
79     /* Prepare departments,
80        which are shown in the listbox on top of the listbox
81      */
82     $options= "";
83     foreach ($this->config->idepartments as $key => $value){
84       if ($this->selectedBase == $key){
85         $options.= "<option selected='selected' value='$key'>$value</option>";
86       } else {
87         $options.= "<option value='$key'>$value</option>";
88       }
89     }
91     if($this->parent->CopyPasteHandler){
92       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
93     }else{
94       $Copy_Paste ="";
95     }
97     // Managment
98     $listhead = "
99       <div style='background:#F0F0F9;padding:5px;'>".
100       " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
101       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
102       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
103       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
104       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
105       " <input type='image' class='center' src='images/list_new_group.png' title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;".
106       $Copy_Paste.
107       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
108       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
109        " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
110 "'>&nbsp;".
111       "</div>";
113     $this->SetListHeader($listhead);
114   }
116   function execute()
117   {
118     $this->ClearElementsList();
119     $this->GenHeader();
120   }
122   function setEntries($groups)
123   {
124     // Defining Links
125     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
127     // image Buttons
128     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
129     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
131     /* Assign extension images */
132     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
133                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
134     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
135                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
136     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
137                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
138     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
139                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
140     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
141                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
142     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
143                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
145     // Space
146     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
148     /* Create action icons - copy & paste icons */
149     $actions = "";
150     if($this->parent->CopyPasteHandler){
151       $actions.= "<input class='center' type='image'
152         src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
153       $actions.= "<input class='center' type='image'
154         src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
155     }
156     $actions.= "<input class='center' type='image'
157       src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
158     $actions.= "<input class='center' type='image'
159       src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
162     // User and Template  Images
163     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
165     // Test Every Entry and generate divlist Array
166     foreach($groups as $key => $val){
168       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
170       if(isset($val['objectClass'])){
171         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
172         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
173         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
174         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
175         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
176         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
177       }
179       $title = "title='dn:&nbsp;".@LDAP::fix($val['dn'])."'";
181       if(!isset($val['description'][0])){
182         $desc = "";
183       }else{
184         $desc = " - [ ".$val['description'][0]." ]";
185       }
187       /* FAIrelease tag from groupApplications */
188       if(isset($val['FAIrelease'][0])){
189         $desc .= " (".$val['FAIrelease'][0].")";
190       }
192       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
193       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
194       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
195       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
197       $this->AddElement(array($field1,$field2,$field3,$field4));
198     }
199   }
201   function Save()
202   {
203     MultiSelectWindow :: Save();  
204   }
206   function save_object()
207   {
208     /* Save automatic created POSTs like regex, checkboxes */
209     MultiSelectWindow::save_object();   
211     $s_action ="";
212     foreach($_POST as $key => $value){
213       if(preg_match("/^dep_back.*/i",$key)){
214         $s_action="back";
215       }elseif(preg_match("/^dep_root.*/",$key)){
216         $s_action="root";
217       }elseif(preg_match("/^dep_home.*/i",$key)){
218         $s_action="home";
219       }
220     }
221    
222     /* Save base selection from headpage selectbox*/ 
223     if(isset($_POST['CurrentMainBase'])){
224       $this->selectedBase = $_POST['CurrentMainBase'];
225     }
227     /* Homebutton is posted */
228     if($s_action=="home"){
229       $ui= get_userinfo();
230       $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
231       $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
232     }
234     /* Open selected department 
235        this is posted by the parent class MultiSelectWindow */
236     if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
237       $s_entry = base64_decode($_GET['dep_id']);
238       $this->selectedBase = $this->config->departments[trim($s_entry)];
239     }
241     /* back to the roots ^^ */
242     if($s_action=="root"){
243       $this->selectedBase=($this->config->current['BASE']);
244     }
246     /* If Backbutton is Posted */
247     if($s_action=="back"){
248       $base_back          = preg_replace("/^[^,]+,/","",$this->selectedBase);
249       $base_back          = convert_department_dn($base_back);
250       if(isset($this->config->departments[trim($base_back)])){
251         $this->selectedBase= $this->config->departments[trim($base_back)];
252       }else{
253         $this->selectedBase= $this->config->departments["/"];
254       }
255     }
257     $_SESSION['CurrentMainBase']  = $this->selectedBase;
258   }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>