Code

Updated strings
[gosa.git] / gosa-core / plugins / admin / ogroups / class_divListOGroup.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class divListOGroup extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
33   /* CheckBoxes, to change default values modify $this->AddCheckBox */
34   var $UserGroups         ;
35   var $GroupGroups        ;
36   var $ApplicationGroups  ;
37   var $DepartmentGroups   ; 
38   var $ServerGroups       ;
39   var $WorkstationGroups  ;
40   var $WindowsGroups  ;
41   var $TerminalGroups     ;
42   var $PrinterGroups      ;
43   var $PhoneGroups        ;
44   
46   /* Subsearch checkbox */
47   var $SubSearch          ;
48   var $parent             ;
49   var $ui                 ;
51   function divListOGroup (&$config,$parent)
52   {
53     MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
54     
55     $this->parent       = $parent;
56     $this->ui           = get_userinfo();
58     /* Set list strings */
59     $this->SetTitle(_("List of object groups"));
60     $this->SetSummary(_("List of object groups"));
61     $this->EnableAplhabet(true);
63     /* Result page will look like a headpage */
64     $this->SetHeadpageMode();
65   
66     /* Disable buttonsm */
67     $this->EnableCloseButton(false);
68     $this->EnableSaveButton (false);
70     /* Dynamic action col, depending on snapshot icons */
71     $action_col_size = 80;
72     if($this->parent->snapshotEnabled()){
73       $action_col_size += 38; 
74     }
76     /* Toggle all selected / deselected */
77     $chk = "<input type='checkbox' id='select_all' name='select_all'
78                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
80     /* set Page header */
81     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
82     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
83     $this->AddHeader(array("string" => _("Object group")." / "._("Department"), "attach" => "style=''"));
84     $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
85     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
87     /*                  Text        ,Value    ,Name         ,Is selected */
88     $str1 = _("Select to see groups containing '%s'.");
89     $str2 = _("Show groups containing '%s'");
90     $this->AddCheckBox("UserGroups" ,       sprintf($str1,  _("Users")), 
91                                             sprintf($str2,  _("Users")), true);
92     $this->AddCheckBox("GroupGroups" ,      sprintf($str1,  _("Groups")),
93                                             sprintf($str2,  _("Groups")), true);
94     $this->AddCheckBox("ApplicationGroups", sprintf($str1,  _("Applications")),
95                                             sprintf($str2,  _("Applications")), true);
96     $this->AddCheckBox("DepartmentGroups" , sprintf($str1,  _("Departments")),
97                                             sprintf($str2,  _("Departments")), true);
98     $this->AddCheckBox("ServerGroups" ,     sprintf($str1,  _("Server")),
99                                             sprintf($str2,  _("Server")), true);
100     $this->AddCheckBox("WorkstationGroups", sprintf($str1,  _("Workstations")),
101                                             sprintf($str2,  _("Workstations")), true);
102     $this->AddCheckBox("WindowsGroups",     sprintf($str1,  _("Windows workstations")),
103                                             sprintf($str2,  _("Windows workstations")), true);
104     $this->AddCheckBox("TerminalGroups" ,   sprintf($str1,  _("Terminals")),
105                                             sprintf($str2,  _("Terminals")), true);
106     $this->AddCheckBox("PrinterGroups" ,    sprintf($str1,  _("Printer")),
107                                             sprintf($str2,  _("Printer")), true);
108     $this->AddCheckBox("PhoneGroups" ,      sprintf($str1,  _("Phones")),
109                                             sprintf($str2,  _("Phones")), true);
111     /* Add SubSearch checkbox */    
112     $this->AddCheckBox(SEPERATOR);
113     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
115     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
116     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
117   }
120   function GenHeader()
121   {
122     /* Prepare departments,
123        which are shown in the listbox on top of the listbox
124      */
125     $options= "";
127     /* Get all departments within this subtree */
128     $ui= get_userinfo();
129     $first = "";
130     $found = FALSE;
131     $base = $this->config->current['BASE'];
133     /* Add base */
134     $tmp = array();
135     $tmp[] = array("dn"=>$this->config->current['BASE']);
136     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
137                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
139     $deps = array();
140     foreach($tmp as $tm){
141       $deps[$tm['dn']] = $tm['dn'];
142     }
144     /* Load possible departments */
145     $ui= get_userinfo();
146     $tdeps= $ui->get_module_departments("ogroups");
147     $ids = $this->config->idepartments;
148     $first = "";
149     $found = FALSE;
150     foreach($ids as $dep => $name){
151       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
153         /* Keep first base dn in mind, we could need this
154          *  info if no valid base was found
155          */
156         if(empty($first)) {
157           $first = $dep['dn'];
158         }
160         $value = $ids[$dep];
161         if ($this->selectedBase == $dep){
162           $found = TRUE;
163           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
164         } else {
165           $options.= "<option value='".$dep."'>$value</option>";
166         }
167       }
168     }
170     /* The currently used base is not visible with your acl setup.
171      * Set base to first useable base.
172      */
173     if(!$found){
174       $this->selectedBase = $first;
175     }
177     /* Add a seperator after displaying c&p and snapshot icons ? */
178     $add_sep = false;
179   
180     /* Get copy & paste icon */
181     $acls  = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
182     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
183     $Copy_Paste ="";
184     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
185       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
186       $add_sep = true;
187     }
189     /* Add default header */
190     $listhead = MultiSelectWindow::get_default_header();
192   
193     /* Add department selector */
194     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
195       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
196       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
199     /* Create Layers menu */
200     $s  = ".|"._("Actions")."|\n";
201     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
202       "&nbsp;"._("Create")."|\n";
204     /* Append create options */
205     if(preg_match("/c/",$acls)) {
206       $s.= "...|<input class='center' type='image' src='images/list_new_ogroup.png' alt=''>".
207         "&nbsp;"._("Object group")."|group_new|\n";
208     }
210     /* Multiple options */
211     $s.= "..|---|\n";
212 #    $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
213 #      "&nbsp;"._("Edit")."|"."multiple_edit|\n";
215     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
216       "&nbsp;"._("Remove")."|"."remove_multiple_ogroups/|\n";
218     /* Add event tag */
219     if(class_available("DaemonEvent")){
220       $events  = DaemonEvent::get_event_types(USER_EVENT);
221       if(count($events['BY_CLASS'])){
222         $s.= "..|---|\n";
223         foreach($events['BY_CLASS'] as $name => $event){
224           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
225         }
226       }
227     }
229     /* Add multiple copy & cut icons */
230     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
231       $s.= "..|---|\n";
232       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
233         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
234       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
235         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
237       if($this->parent->CopyPasteHandler->entries_queued()){
238         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
239         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
240       }else{
241         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
242         $s.="..|".$img."&nbsp;"._("Paste")."\n";
243       }
244     }
246     /* Add snapshot icons */
247     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
248       $s .= "..|---|\n";
249       $s .= $this->get_snapshot_header(TRUE);
250     }
252     $this->SetDropDownHeaderMenu($s);
253     $this->SetListHeader($listhead);
254   }
256   function execute()
257   {
258     $this->ClearElementsList();
259     $this->GenHeader();
260   }
262   function setEntries($list)
263   {
264     /* Add Copy & Paste buttons if copy&paste is enabled
265      */
266     // Defining Links
267     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
268     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
269     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
270     $mailimg  = "<img class='center' src='images/mailto.png'             alt='M'  title='"._("Mail")   ."'>";
271     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
273     /* Dynamic action col, depending on snapshot icons */
274     $action_col_size = 80;
275     if($this->parent->snapshotEnabled()){
276       $action_col_size += 38; 
277     }
278   
279     $ui = get_userinfo();
281     // Assigning ogroups
282     foreach($list as $key => $val){
284       /* Create action icons */
285       $actions= "";
286       $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
287       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
288         $actions.= "<input class='center' type='image'
289           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
290         $actions.= "<input class='center' type='image'
291           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
292       }
294       $actions.= "<input class='center' type='image'
295         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
296     
297       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
298         $actions.= $this->GetSnapShotActions($val['dn']);
299       }
301       if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
302         $actions.= "<input class='center' type='image'
303           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
304       }else{
305         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
306           title='".msgPool::permDelete()."'>";
307       }
310       if(isset($val['mail'])){
311         $mail = $mailimg;
312       }else{
313         $mail = $empty;
314       }
315       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
316       if(!isset($val['description'][0])){
317         $desc = "";
318       }else{
319         $desc = " - [ ".$val['description'][0]." ]";
320       }
322       /* Cutted objects should be displayed in light grey */
323       $display = $val['cn'][0].$desc;
324       if($this->parent->CopyPasteHandler){
325         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
326           if($queue_data['dn'] == $val['dn']) {
327             $display = "<font color='#999999'>".$display."</font>";
328             break;
329           }
330         }
331       }
333       /* Create each field */
334       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
335                       "attach" => "style='width:20px;'");
336       $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
337       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
338       $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))."&nbsp;".$mail, "attach" => "style='width:136px;'");
339       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
341       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
342     }
343    
344  
345     /* Create summary string for list footer */
346     $num_deps=0;
347     if(!$this->SubSearch){
348       $num_deps = count($this->Added_Departments);
349     }
350     $num_objs = count($list);
352     $num_obj_str = _("Number of listed object groups");
353     $num_dep_str = _("Number of listed departments");
355     $str = "<img class='center' src='images/select_ogroup.png'
356               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
357     $str.= "<img class='center' src='images/folder.png'
358               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
360     $this->set_List_Bottom_Info($str);
361   }
363   function Save()
364   {
365     MultiSelectWindow :: Save();  
366   }
368   function save_object()
369   {
370     /* Save automatic created POSTs like regex, checkboxes */
371     MultiSelectWindow::save_object();   
372   }
374 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
375 ?>