Code

Added seperate list handler for gotomasses.
[gosa.git] / plugins / admin / ogroups / class_divListOGroup.inc
1 <?php
3 class divListOGroup extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
13   /* CheckBoxes, to change default values modify $this->AddCheckBox */
14   var $UserGroups         ;
15   var $GroupGroups        ;
16   var $ApplicationGroups  ;
17   var $DepartmentGroups   ; 
18   var $ServerGroups       ;
19   var $WorkstationGroups  ;
20   var $TerminalGroups     ;
21   var $PrinterGroups      ;
22   var $PhoneGroups        ;
23   
25   /* Subsearch checkbox */
26   var $SubSearch          ;
27   var $parent             ;
28   var $ui                 ;
30   function divListOGroup (&$config,$parent)
31   {
32     MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
33     
34     $this->parent       = $parent;
35     $this->ui           = get_userinfo();
37     /* Set list strings */
38     $this->SetTitle(_("List of object groups"));
39     $this->SetSummary(_("List of object groups"));
40     $this->EnableAplhabet(true);
42     /* Result page will look like a headpage */
43     $this->SetHeadpageMode();
44     $this->SetInformation(_("This menu allows you to add, edit or remove selected groups. You may want to use the range selector on top of the group listbox, when working with  a large number of groups."));
45   
46     /* Disable buttonsm */
47     $this->EnableCloseButton(false);
48     $this->EnableSaveButton (false);
50     /* Dynamic action col, depending on snapshot icons */
51     $action_col_size = 80;
52     if($this->parent->snapshotEnabled()){
53       $action_col_size += 38; 
54     }
56     /* Toggle all selected / deselected */
57     $chk = "<input type='checkbox' id='select_all' name='select_all'
58                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
60     /* set Page header */
61     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
62     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
63     $this->AddHeader(array("string" => _("Name of object groups")." / "._("Departments"), "attach" => "style=''"));
64     $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
65     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
67     /*                  Text        ,Value    ,Name         ,Is selected */
68     $this->AddCheckBox("UserGroups" ,       _("Select to see groups containing users")       , _("Show groups containing users"), true);
69     $this->AddCheckBox("GroupGroups" ,      _("Select to see groups containing groups")      , _("Show groups containing groups"), true);
70     $this->AddCheckBox("ApplicationGroups", _("Select to see groups containing applications"), _("Show groups containing applications"), true);
71     $this->AddCheckBox("DepartmentGroups" , _("Select to see groups containing departments") , _("Show groups containing departments"), true);
72     $this->AddCheckBox("ServerGroups" ,     _("Select to see groups containing servers")     , _("Show groups containing servers"), true);
73     $this->AddCheckBox("WorkstationGroups", _("Select to see groups containing workstations"), _("Show groups containing workstations"), true);
74     $this->AddCheckBox("TerminalGroups" ,   _("Select to see groups containing terminals")   , _("Show groups containing terminals"), true);
75     $this->AddCheckBox("PrinterGroups" ,    _("Select to see groups containing printer")     , _("Show groups containing printer"), true);
76     $this->AddCheckBox("PhoneGroups" ,      _("Select to see groups containing phones")      , _("Show groups containing phones"), true);
78     /* Add SubSearch checkbox */    
79     $this->AddCheckBox(SEPERATOR);
80     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
82     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
83     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
84   }
87   function GenHeader()
88   {
89     /* Prepare departments,
90        which are shown in the listbox on top of the listbox
91      */
92     $options= "";
94     /* Get all departments within this subtree */
95     $ui= get_userinfo();
96     $first = "";
97     $found = FALSE;
98     $base = $this->config->current['BASE'];
100     /* Add base */
101     $tmp = array();
102     $tmp[] = array("dn"=>$this->config->current['BASE']);
103     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
104                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
106     $deps = array();
107     foreach($tmp as $tm){
108       $deps[$tm['dn']] = $tm['dn'];
109     }
111     /* Load possible departments */
112     $ui= get_userinfo();
113     $tdeps= $ui->get_module_departments("ogroups");
114     $ids = $this->config->idepartments;
115     $first = "";
116     $found = FALSE;
117     foreach($ids as $dep => $name){
118       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
120         /* Keep first base dn in mind, we could need this
121          *  info if no valid base was found
122          */
123         if(empty($first)) {
124           $first = $dep['dn'];
125         }
127         $value = $ids[$dep];
128         if ($this->selectedBase == $dep){
129           $found = TRUE;
130           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
131         } else {
132           $options.= "<option value='".$dep."'>$value</option>";
133         }
134       }
135     }
137     /* The currently used base is not visible with your acl setup.
138      * Set base to first useable base.
139      */
140     if(!$found){
141       $this->selectedBase = $first;
142     }
144     /* Add a seperator after displaying c&p and snapshot icons ? */
145     $add_sep = false;
146   
147     /* Get copy & paste icon */
148     $acls  = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
149     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
150     $Copy_Paste ="";
151     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
152       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
153       $add_sep = true;
154     }
156     /* Add default header */
157     $listhead = MultiSelectWindow::get_default_header();
159     /* Add snapshot restore icons */ 
160     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
161       $listhead .= $this->get_snapshot_header($this->selectedBase);
162       $add_sep = true;
163     }
165     /* Create new ogroup icon */
166     if(preg_match("/c/",$acls)) {
167       $listhead .=" <input class='center' type='image' align='middle' src='images/list_new_ogroup.png' 
168         title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>";
169       $add_sep = true;
170     }
172     /* Add copy & paste icon */
173     $listhead .=  $Copy_Paste;
174     
175     /* Should we add a seperator here ? */
176     if($add_sep){
177       $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
178     }
179   
180     /* Add department selector */
181     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
182       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
183       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
185     /* Multiple options */
186     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
187         title='"._("Remove selected object groups")."' alt='"._("Remove object groups")."' name='remove_multiple_ogroups'>&nbsp;";
189     /* Add multiple copy & cut icons */
190     if(is_object($this->parent->CopyPasteHandler)){
191       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
192         title='"._("Copy selected object group")."' alt='"._("Copy object groups")."' name='multiple_copy_ogroups'>&nbsp;";
193       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
194         title='"._("cut selected object group")."' alt='"._("Cut object groups")."' name='multiple_cut_ogroups'>&nbsp;";
195     }
196     $listhead .="</div>";
198     $this->SetListHeader($listhead);
199   }
201   function execute()
202   {
203     $this->ClearElementsList();
204     $this->GenHeader();
205   }
207   function setEntries($list)
208   {
209     /* Add Copy & Paste buttons if copy&paste is enabled
210      */
211     // Defining Links
212     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
213     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
214     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
215     $mailimg  = "<img class='center' src='images/mailto.png'             alt='M'  title='"._("Mail")   ."'>";
216     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
218     /* Dynamic action col, depending on snapshot icons */
219     $action_col_size = 80;
220     if($this->parent->snapshotEnabled()){
221       $action_col_size += 38; 
222     }
223   
224     $ui = get_userinfo();
226     // Assigning ogroups
227     foreach($list as $key => $val){
229       /* Create action icons */
230       $actions= "";
231       $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
232       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
233         $actions.= "<input class='center' type='image'
234           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
235         $actions.= "<input class='center' type='image'
236           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
237       }
239       $actions.= "<input class='center' type='image'
240         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
241     
242       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
243         $actions.= $this->GetSnapShotActions($val['dn']);
244       }
246       if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
247         $actions.= "<input class='center' type='image'
248           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
249       }else{
250         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
251           title='"._("You are not allowed to remove this entry.")."'>";
252       }
255       if(isset($val['mail'])){
256         $mail = $mailimg;
257       }else{
258         $mail = $empty;
259       }
260       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
261       if(!isset($val['description'][0])){
262         $desc = "";
263       }else{
264         $desc = " - [ ".$val['description'][0]." ]";
265       }
267       /* Cutted objects should be displayed in light grey */
268       $display = $val['cn'][0].$desc;
269       if($this->parent->CopyPasteHandler){
270         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
271           if($queue_data['dn'] == $val['dn']) {
272             $display = "<font color='#999999'>".$display."</font>";
273             break;
274           }
275         }
276       }
278       /* Create each field */
279       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
280                       "attach" => "style='width:20px;'");
281       $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
282       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
283       $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))."&nbsp;".$mail, "attach" => "style='width:136px;'");
284       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
286       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
287     }
288    
289  
290     /* Create summary string for list footer */
291     $num_deps=0;
292     if(!$this->SubSearch){
293       $num_deps = count($this->Added_Departments);
294     }
295     $num_objs = count($list);
297     $num_obj_str = _("Number of listed object groups");
298     $num_dep_str = _("Number of listed departments");
300     $str = "<img class='center' src='images/select_ogroup.png'
301               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
302     $str.= "<img class='center' src='images/folder.png'
303               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
305     $this->set_List_Bottom_Info($str);
306   }
308   function Save()
309   {
310     MultiSelectWindow :: Save();  
311   }
313   function save_object()
314   {
315     /* Save automatic created POSTs like regex, checkboxes */
316     MultiSelectWindow::save_object();   
317   }
319 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
320 ?>