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 ;
25 /* Subsearch checkbox */
26 var $SubSearch ;
27 var $parent ;
28 var $ui ;
30 function divListOGroup ($config,$parent)
31 {
32 MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
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."));
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" => " ", "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"), _("Ignore 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 $base = $this->config->current['BASE'];
96 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
97 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
99 /* Load possible departments */
100 $ui= get_userinfo();
101 $tdeps= $ui->get_module_departments("ogroups");
103 $ids = $this->config->idepartments;
105 foreach($deps as $dep){
106 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
108 $value = $ids[$dep['dn']];
109 if ($this->selectedBase == $dep['dn']){
110 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
111 } else {
112 $options.= "<option value='".$dep['dn']."'>$value</option>";
113 }
114 }
115 }
117 /* Add a seperator after displaying c&p and snapshot icons ? */
118 $add_sep = false;
120 /* Get copy & paste icon */
121 $acls = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
122 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
123 $Copy_Paste ="";
124 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
125 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
126 $add_sep = true;
127 }
129 /* Add default header */
130 $listhead = MultiSelectWindow::get_default_header();
132 /* Add snapshot restore icons */
133 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
134 $listhead .= $this->get_snapshot_header($this->selectedBase);
135 $add_sep = true;
136 }
138 /* Create new ogroup icon */
139 if(preg_match("/c/",$acls)) {
140 $listhead .=" <input class='center' type='image' align='middle' src='images/list_new_ogroup.png'
141 title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>";
142 $add_sep = true;
143 }
145 /* Add copy & paste icon */
146 $listhead .= $Copy_Paste;
148 /* Should we add a seperator here ? */
149 if($add_sep){
150 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
151 }
153 /* Add department selector */
154 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
155 " <input class='center' type='image' src='images/list_submit.png' align='middle'
156 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
158 /* Multiple options */
159 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
160 title='"._("Remove selected object groups")."' alt='"._("Remove object groups")."' name='remove_multiple_ogroups'> ";
162 $listhead .="</div>";
164 $this->SetListHeader($listhead);
165 }
167 function execute()
168 {
169 $this->ClearElementsList();
170 $this->GenHeader();
171 }
173 function setEntries($list)
174 {
175 /* Add Copy & Paste buttons if copy&paste is enabled
176 */
177 // Defining Links
178 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
179 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
180 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
181 $mailimg = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
182 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
184 /* Dynamic action col, depending on snapshot icons */
185 $action_col_size = 80;
186 if($this->parent->snapshotEnabled()){
187 $action_col_size += 38;
188 }
190 $ui = get_userinfo();
192 // Assigning ogroups
193 foreach($list as $key => $val){
195 /* Create action icons */
196 $actions= "";
197 $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
198 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
199 $actions.= "<input class='center' type='image'
200 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
201 $actions.= "<input class='center' type='image'
202 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
203 }
205 $actions.= "<input class='center' type='image'
206 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
208 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
209 $actions.= $this->GetSnapShotActions($val['dn']);
210 }
212 if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
213 $actions.= "<input class='center' type='image'
214 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
215 }else{
216 $actions.= "<img class='center' src='images/empty.png' alt=' '
217 title='"._("You are not allowed to remove this entry.")."'>";
218 }
221 if(isset($val['mail'])){
222 $mail = $mailimg;
223 }else{
224 $mail = $empty;
225 }
226 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
227 if(!isset($val['description'][0])){
228 $desc = "";
229 }else{
230 $desc = " - [ ".$val['description'][0]." ]";
231 }
232 /* Create each field */
233 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
234 "attach" => "style='width:20px;'");
235 $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
236 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
237 $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))." ".$mail, "attach" => "style='width:136px;'");
238 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
240 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
241 }
242 }
244 function Save()
245 {
246 MultiSelectWindow :: Save();
247 }
249 function save_object()
250 {
251 /* Save automatic created POSTs like regex, checkboxes */
252 MultiSelectWindow::save_object();
253 }
254 }
255 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
256 ?>