Code

Updated Listing for serveral Management lists.
[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 = 90;
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' title='"._("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     $str2 = _("Show %s");
89     $this->AddCheckBox("UserGroups" ,       sprintf($str2,  _("user groups")), 
90                                             sprintf($str2,  _("user groups")), true);
91     $this->AddCheckBox("GroupGroups" ,      sprintf($str2,  _("nested groups")),
92                                             sprintf($str2,  _("nested groups")), true);
93     $this->AddCheckBox("ApplicationGroups", sprintf($str2,  _("application groups")),
94                                             sprintf($str2,  _("application groups")), true);
95     $this->AddCheckBox("DepartmentGroups" , sprintf($str2,  _("department groups")),
96                                             sprintf($str2,  _("department groups")), true);
97     $this->AddCheckBox("ServerGroups" ,     sprintf($str2,  _("server groups")),
98                                             sprintf($str2,  _("server groups")), true);
99     $this->AddCheckBox("WorkstationGroups", sprintf($str2,  _("workstation groups")),
100                                             sprintf($str2,  _("workstation groups")), true);
101     $this->AddCheckBox("WindowsGroups",     sprintf($str2,  _("windows workstation groups")),
102                                             sprintf($str2,  _("windows workstation groups")), true);
103     $this->AddCheckBox("TerminalGroups" ,   sprintf($str2,  _("terminal groups")),
104                                             sprintf($str2,  _("terminal groups")), true);
105     $this->AddCheckBox("PrinterGroups" ,    sprintf($str2,  _("printer groups")),
106                                             sprintf($str2,  _("printer groups")), true);
107     $this->AddCheckBox("PhoneGroups" ,      sprintf($str2,  _("phone groups")),
108                                             sprintf($str2,  _("phone groups")), true);
110     /* Add SubSearch checkbox */    
111     $this->AddCheckBox(SEPERATOR);
112     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
114     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
115     $this->AddRegex   ("Regex", _("Regular expression for matching group names"), "*" , true);
116   }
119   function GenHeader()
120   {
121     /* Get all departments within this subtree */
122     $ui= get_userinfo();
123     $first = "";
124     $found = FALSE;
125     $base = $this->config->current['BASE'];
126     $options  = $this->create_department_list($this->module);
128     /* Add base */
129     $tmp = array();
130     $tmp[] = array("dn"=>$this->config->current['BASE']);
131     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
132                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
134     /* Add a seperator after displaying c&p and snapshot icons ? */
135     $add_sep = false;
136   
137     /* Get copy & paste icon */
138     $acls  = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
139     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
142     /* Add default header */
143     $listhead = MultiSelectWindow::get_default_header();
144   
145     /* Add department selector */
146     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
147       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
148       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
151     /* Create Layers menu */
152     $s  = ".|"._("Actions")."|\n";
154     /* Append create options */
155     if(preg_match("/c/",$acls)) {
156       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
157         "&nbsp;"._("Create")."|\n";
158       $s.= "...|<input class='center' type='image' src='plugins/ogroups/images/new.png' alt=''>".
159         "&nbsp;"._("Object group")."|group_new|\n";
160     }
162     /* Multiple options */
163     $s.= "..|---|\n";
164 #   $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
165 #     "&nbsp;"._("Edit")."|"."multiple_edit|\n";
166     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
167       "&nbsp;"._("Remove")."|"."remove_multiple_ogroups/|\n";
169     /* Add event tag */
170     if(class_available("DaemonEvent")){
171       $events  = DaemonEvent::get_event_types(USER_EVENT);
172       if(count($events['BY_CLASS'])){
173         $s.= "..|---|\n";
174         foreach($events['BY_CLASS'] as $name => $event){
175           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
176         }
177       }
178     }
180     /* Add Copy & Paste header */
181     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
183     /* Add snapshot icons */
184     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);    
186     $this->SetDropDownHeaderMenu($s);
187     $this->SetListHeader($listhead);
188   }
191   function execute()
192   {
193     $this->ClearElementsList();
194     $this->GenHeader();
195   }
197   function setEntries($list)
198   {
199     /* Add Copy & Paste buttons if copy&paste is enabled
200      */
201     // Defining Links
202     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
203     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
204     $mailimg  = "<img class='center' src='plugins/ogroups/images/mail.png'             alt='M'  title='"._("Mail")   ."'>";
205     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
207     /* Dynamic action col, depending on snapshot icons */
208     $action_col_size = 90;
209     if($this->parent->snapshotEnabled()){
210       $action_col_size += 38; 
211     }
212   
213     $ui = get_userinfo();
215     // Assigning ogroups
216     foreach($list as $key => $val){
218       $actions = "";
219       
220       /* Create action icons */
221       $acl    = $ui->get_permissions($val['dn'],"ogroups/ogroup");
222       $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
224       /* Add copy & cut functionality */
225       $actions.= $this->parent->get_copypaste_action($val['dn'],"ogroups","ogroup");
227       $actions.= "<input class='center' type='image'
228         src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
229     
230       $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
232       if(preg_match("/d/",$acl)){
233         $actions.= "<input class='center' type='image'
234           src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
235       }else{
236         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
237           title='".msgPool::permDelete()."'>";
238       }
240       if(isset($val['mail'])){
241         $mail = $mailimg;
242       }else{
243         $mail = $empty;
244       }
245       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
246       if(!isset($val['description'][0])){
247         $desc = "";
248       }else{
249         $desc = " - [ ".$val['description'][0]." ]";
250       }
252       /* Cutted objects should be displayed in light grey */
253       $display = $val['cn'][0].$desc;
254       if($this->parent->CopyPasteHandler){
255         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
256           if($queue_data['dn'] == $val['dn']) {
257             $display = "<font color='#999999'>".$display."</font>";
258             break;
259           }
260         }
261       }
263       /* Create each field */
264       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
265                       "attach" => "style='width:20px;'");
266       $field1 = array("string" => "<img src='plugins/ogroups/images/ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
267       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
268       $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))."&nbsp;".$mail, "attach" => "style='width:136px;'");
269       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
271       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
272     }
273    
274  
275     /* Create summary string for list footer */
276     $num_deps=0;
277     if(!$this->SubSearch){
278       $num_deps = count($this->Added_Departments);
279     }
280     $num_objs = count($list);
282     $num_obj_str = _("Number of listed object groups");
283     $num_dep_str = _("Number of listed departments");
285     $str = "<img class='center' src='plugins/ogroups/images/ogroup.png'
286               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
287     $str.= "<img class='center' src='images/lists/folder.png'
288               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
290     $this->set_List_Bottom_Info($str);
291   }
293   function Save()
294   {
295     MultiSelectWindow :: Save();  
296   }
298   function save_object()
299   {
300     /* Save automatic created POSTs like regex, checkboxes */
301     MultiSelectWindow::save_object();   
302   }
304 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
305 ?>