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 $WindowsGroups ;
21 var $TerminalGroups ;
22 var $PrinterGroups ;
23 var $PhoneGroups ;
26 /* Subsearch checkbox */
27 var $SubSearch ;
28 var $parent ;
29 var $ui ;
31 function divListOGroup (&$config,$parent)
32 {
33 MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
35 $this->parent = $parent;
36 $this->ui = get_userinfo();
38 /* Set list strings */
39 $this->SetTitle(_("List of object groups"));
40 $this->SetSummary(_("List of object groups"));
41 $this->EnableAplhabet(true);
43 /* Result page will look like a headpage */
44 $this->SetHeadpageMode();
45 $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."));
47 /* Disable buttonsm */
48 $this->EnableCloseButton(false);
49 $this->EnableSaveButton (false);
51 /* Dynamic action col, depending on snapshot icons */
52 $action_col_size = 80;
53 if($this->parent->snapshotEnabled()){
54 $action_col_size += 38;
55 }
57 /* Toggle all selected / deselected */
58 $chk = "<input type='checkbox' id='select_all' name='select_all'
59 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
61 /* set Page header */
62 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
63 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
64 $this->AddHeader(array("string" => _("Name of object groups")." / "._("Departments"), "attach" => "style=''"));
65 $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
66 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
68 /* Text ,Value ,Name ,Is selected */
69 $this->AddCheckBox("UserGroups" , _("Select to see groups containing users") , _("Show groups containing users"), true);
70 $this->AddCheckBox("GroupGroups" , _("Select to see groups containing groups") , _("Show groups containing groups"), true);
71 $this->AddCheckBox("ApplicationGroups", _("Select to see groups containing applications"), _("Show groups containing applications"), true);
72 $this->AddCheckBox("DepartmentGroups" , _("Select to see groups containing departments") , _("Show groups containing departments"), true);
73 $this->AddCheckBox("ServerGroups" , _("Select to see groups containing servers") , _("Show groups containing servers"), true);
74 $this->AddCheckBox("WorkstationGroups", _("Select to see groups containing workstations"), _("Show groups containing workstations"), true);
75 $this->AddCheckBox("WindowsGroups", _("Select to see groups containing windows workstations"), _("Show groups containing windows workstations"), true);
76 $this->AddCheckBox("TerminalGroups" , _("Select to see groups containing terminals") , _("Show groups containing terminals"), true);
77 $this->AddCheckBox("PrinterGroups" , _("Select to see groups containing printer") , _("Show groups containing printer"), true);
78 $this->AddCheckBox("PhoneGroups" , _("Select to see groups containing phones") , _("Show groups containing phones"), true);
80 /* Add SubSearch checkbox */
81 $this->AddCheckBox(SEPERATOR);
82 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
84 /* Name ,Text ,Default , Connect with alphabet */
85 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
86 }
89 function GenHeader()
90 {
91 /* Prepare departments,
92 which are shown in the listbox on top of the listbox
93 */
94 $options= "";
96 /* Get all departments within this subtree */
97 $ui= get_userinfo();
98 $first = "";
99 $found = FALSE;
100 $base = $this->config->current['BASE'];
102 /* Add base */
103 $tmp = array();
104 $tmp[] = array("dn"=>$this->config->current['BASE']);
105 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
106 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
108 $deps = array();
109 foreach($tmp as $tm){
110 $deps[$tm['dn']] = $tm['dn'];
111 }
113 /* Load possible departments */
114 $ui= get_userinfo();
115 $tdeps= $ui->get_module_departments("ogroups");
116 $ids = $this->config->idepartments;
117 $first = "";
118 $found = FALSE;
119 foreach($ids as $dep => $name){
120 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
122 /* Keep first base dn in mind, we could need this
123 * info if no valid base was found
124 */
125 if(empty($first)) {
126 $first = $dep['dn'];
127 }
129 $value = $ids[$dep];
130 if ($this->selectedBase == $dep){
131 $found = TRUE;
132 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
133 } else {
134 $options.= "<option value='".$dep."'>$value</option>";
135 }
136 }
137 }
139 /* The currently used base is not visible with your acl setup.
140 * Set base to first useable base.
141 */
142 if(!$found){
143 $this->selectedBase = $first;
144 }
146 /* Add a seperator after displaying c&p and snapshot icons ? */
147 $add_sep = false;
149 /* Get copy & paste icon */
150 $acls = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
151 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
152 $Copy_Paste ="";
153 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
154 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
155 $add_sep = true;
156 }
158 /* Add default header */
159 $listhead = MultiSelectWindow::get_default_header();
162 /* Add department selector */
163 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
164 " <input class='center' type='image' src='images/list_submit.png' align='middle'
165 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
168 /* Create Layers menu */
169 $s = ".|"._("Actions")."|\n";
170 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
171 " "._("Create")."|\n";
173 /* Append create options */
174 if(preg_match("/c/",$acls)) {
175 $s.= "...|<input class='center' type='image' src='images/list_new_ogroup.png' alt=''>".
176 " "._("Object group")."|group_new|\n";
177 }
179 /* Multiple options */
180 $s.= "..|---|\n";
181 # $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
182 # " "._("Edit")."|"."multiple_edit|\n";
184 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
185 " "._("Remove")."|"."remove_multiple_ogroups/|\n";
187 /* Add multiple copy & cut icons */
188 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
189 $s.= "..|---|\n";
190 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
191 " "._("Copy")."|"."multiple_copy_systems|\n";
192 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
193 " "._("Cut")."|"."multiple_cut_systems|\n";
195 if($this->parent->CopyPasteHandler->entries_queued()){
196 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
197 $s.="..|".$img." "._("Paste")."|editPaste|\n";
198 }else{
199 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
200 $s.="..|".$img." "._("Paste")."\n";
201 }
202 }
204 /* Add snapshot icons */
205 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
206 $s .= "..|---|\n";
207 $s .= $this->get_snapshot_header(TRUE);
208 }
210 $this->SetDropDownHeaderMenu($s);
211 $this->SetListHeader($listhead);
212 }
214 function execute()
215 {
216 $this->ClearElementsList();
217 $this->GenHeader();
218 }
220 function setEntries($list)
221 {
222 /* Add Copy & Paste buttons if copy&paste is enabled
223 */
224 // Defining Links
225 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
226 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
227 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
228 $mailimg = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
229 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
231 /* Dynamic action col, depending on snapshot icons */
232 $action_col_size = 80;
233 if($this->parent->snapshotEnabled()){
234 $action_col_size += 38;
235 }
237 $ui = get_userinfo();
239 // Assigning ogroups
240 foreach($list as $key => $val){
242 /* Create action icons */
243 $actions= "";
244 $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
245 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
246 $actions.= "<input class='center' type='image'
247 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
248 $actions.= "<input class='center' type='image'
249 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
250 }
252 $actions.= "<input class='center' type='image'
253 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
255 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
256 $actions.= $this->GetSnapShotActions($val['dn']);
257 }
259 if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
260 $actions.= "<input class='center' type='image'
261 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
262 }else{
263 $actions.= "<img class='center' src='images/empty.png' alt=' '
264 title='"._("You are not allowed to remove this entry.")."'>";
265 }
268 if(isset($val['mail'])){
269 $mail = $mailimg;
270 }else{
271 $mail = $empty;
272 }
273 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
274 if(!isset($val['description'][0])){
275 $desc = "";
276 }else{
277 $desc = " - [ ".$val['description'][0]." ]";
278 }
280 /* Cutted objects should be displayed in light grey */
281 $display = $val['cn'][0].$desc;
282 if($this->parent->CopyPasteHandler){
283 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
284 if($queue_data['dn'] == $val['dn']) {
285 $display = "<font color='#999999'>".$display."</font>";
286 break;
287 }
288 }
289 }
291 /* Create each field */
292 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
293 "attach" => "style='width:20px;'");
294 $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
295 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
296 $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))." ".$mail, "attach" => "style='width:136px;'");
297 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
299 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
300 }
303 /* Create summary string for list footer */
304 $num_deps=0;
305 if(!$this->SubSearch){
306 $num_deps = count($this->Added_Departments);
307 }
308 $num_objs = count($list);
310 $num_obj_str = _("Number of listed object groups");
311 $num_dep_str = _("Number of listed departments");
313 $str = "<img class='center' src='images/select_ogroup.png'
314 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
315 $str.= "<img class='center' src='images/folder.png'
316 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
318 $this->set_List_Bottom_Info($str);
319 }
321 function Save()
322 {
323 MultiSelectWindow :: Save();
324 }
326 function save_object()
327 {
328 /* Save automatic created POSTs like regex, checkboxes */
329 MultiSelectWindow::save_object();
330 }
331 }
332 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
333 ?>