Code

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