1 <?php
3 class divListGroup extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
12 var $UserRegex = "*";
14 /* CheckBoxes, to change default values modify $this->AddCheckBox */
15 var $ShowPrimaryGroups;
16 var $ShowSambaGroups;
17 var $ShowApplicationGroups;
18 var $ShowMailGroups;
19 var $ShowFunctionalGroups;
21 /* Subsearch checkbox */
22 var $SubSearch = false;
24 var $parent ;
25 var $ui ;
27 function divListGroup ($config,$parent)
28 {
29 MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
31 $this->parent = $parent;
32 $this->ui = get_userinfo();
34 /* Set list strings */
35 $this->SetTitle(_("List of groups"));
36 $this->SetSummary(_("List of groups"));
37 $this->EnableAplhabet (true);
39 /* Result page will look like a headpage */
40 $this->SetHeadpageMode();
41 $this->SetInformation(_("This menu allows you to add, edit and 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."));
43 /* Disable buttonsm */
44 $this->EnableCloseButton(false);
45 $this->EnableSaveButton (false);
47 /* Dynamic action col, depending on snapshot icons */
48 $action_col_size = 70;
49 if($this->parent->snapshotEnabled()){
50 $action_col_size += 38;
51 }
53 /* set Page header */
54 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
55 $this->AddHeader(array("string"=>_("Groupname / Department")));
56 $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
57 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
59 /* Text ,Value ,Name ,Is selected */
60 $this->AddCheckBox("ShowPrimaryGroups", _("Select to see groups that are primary groups of users"), _("Show primary groups"), true);
61 $this->AddCheckBox("ShowSambaGroups", _("Select to see groups that have samba groups mappings"), _("Show samba groups"), true);
62 $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"), _("Show application groups"),true);
63 $this->AddCheckBox("ShowMailGroups", _("Select to see groups that have mail settings"), _("Show mail groups"), true);
64 $this->AddCheckBox("ShowFunctionalGroups", _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
65 $this->AddCheckBox(SEPERATOR);
67 /* Add SubSearch checkbox */
68 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
70 /* Name ,Text ,Default , Connect with alphabet */
71 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
72 $this->AddRegex ("UserRegex", _("User name of which groups are shown"), "*" , false, "images/search_user.png");
73 }
76 function GenHeader()
77 {
78 /* Prepare departments,
79 which are shown in the listbox on top of the listbox
80 */
81 $options= "";
85 /* Get all departments within this subtree */
86 $base = $this->config->current['BASE'];
87 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
88 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
90 /* Load possible departments */
91 $ui= get_userinfo();
92 $tdeps= $ui->get_module_departments("groups");
94 $ids = $this->config->idepartments;
96 foreach($deps as $dep){
97 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
99 $value = $ids[$dep['dn']];
100 if ($this->selectedBase == $dep['dn']){
101 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
102 } else {
103 $options.= "<option value='".$dep['dn']."'>$value</option>";
104 }
105 }
106 }
108 /* Get acls */
109 $acls = $ui->get_permissions($this->selectedBase,"groups/group");
110 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
112 /* If this is true add a seperator after added c&p and snapshot icons to header */
113 $addsep = false;
115 /* Get copy & paste icon */
116 $Copy_Paste ="";
117 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
118 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
119 $addsep = true;
120 }
122 // Managment
123 $listhead = "
124 <div style='background:#F0F0F9;padding:5px;'>".
125 " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
126 " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
127 " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
128 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='". _("Submit")."'> ".
129 " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'> ";
131 /* Add snapshot restore icon and force a following seperator */
132 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
133 $listhead .= $this->get_snapshot_header($this->selectedBase);
134 $addsep = true;
135 }
137 /* Add Create group icon */
138 if(preg_match("/c/",$acls)) {
139 $listhead.=" <input type='image' class='center' src='images/list_new_group.png'
140 title='"._("Create new group")."' alt='"._("New")."' name='group_new'> ";
141 $addsep = true;
142 }
144 /* Assign copy & paste icons */
145 $listhead.= $Copy_Paste;
147 /* Append an additional seperator */
148 if($addsep){
149 $listhead.=" <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'> ";
150 }
152 /* Add department selection */
153 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
154 " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
155 "'> ".
156 "</div>";
158 $this->SetListHeader($listhead);
159 }
161 function execute()
162 {
163 $this->ClearElementsList();
164 $this->GenHeader();
165 }
167 function setEntries($groups)
168 {
169 // Defining Links
170 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
172 // image Buttons
173 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
174 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
176 /* Dynamic action col, depending on snapshot icons */
177 $action_col_size = 70;
178 if($this->parent->snapshotEnabled()){
179 $action_col_size += 38;
180 }
182 /* Assign extension images */
183 $posiximg = "<input type='image' class='center' src='images/select_groups.png'
184 name='group_group_edit_%KEY%' alt='P' title='"._("Posix") ."'>";
185 $mailimg = "<input type='image' class='center' src='images/mailto.png'
186 name='mailgroup_group_edit_%KEY%' alt='M' title='"._("Mail") ."'>";
187 $sambaimg = "<input type='image' class='center' src='images/select_winstation.png'
188 name='group_group_edit_%KEY%' alt='S' title='"._("Samba") ."'>";
189 $applimg = "<input type='image' class='center' src='images/select_application.png'
190 name='appgroup_group_edit_%KEY%' alt='A' title='"._("Application")."'>";
191 $phoneimg = "<input type='image' class='center' src='images/select_phone.png'
192 name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone") ."'>";
193 $envimg = "<input type='image' class='center' src='images/smallenv.png'
194 name='environment_group_edit_%KEY%' alt='E' title='"._("Environment") ."'>";
196 // Space
197 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
199 // User and Template Images
200 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
202 $ui = get_userinfo();
204 // Test Every Entry and generate divlist Array
205 foreach($groups as $key => $val){
207 /* Create action icons - copy & paste icons */
208 $acl = $ui->get_permissions($val['dn'],"groups/group");
209 $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
211 $actions= "";
212 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
213 $actions.= "<input class='center' type='image'
214 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
215 $actions.= "<input class='center' type='image'
216 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
217 }
219 /* Add edit icon */
220 $actions.= "<input class='center' type='image'
221 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
223 /* Add snapshot functionality */
224 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
225 $actions.= $this->GetSnapShotActions($val['dn']);
226 }
228 if(preg_match("/d/",$acl)){
229 $actions.= "<input class='center' type='image'
230 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
231 }
234 $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
236 if(isset($val['objectClass'])){
237 if(in_array("posixGroup", $val['objectClass'])) $posix = $posiximg;
238 if(in_array("gosaMailAccount", $val['objectClass'])) $mail = $mailimg;
239 if(in_array("sambaGroupMapping", $val['objectClass'])) $samba = $sambaimg;
240 if(in_array("gosaApplicationGroup", $val['objectClass'])) $appl = $applimg;
241 if(in_array("goFonPickupGroup", $val['objectClass'])) $phone = $phoneimg;
242 if(in_array("gotoEnvironment", $val['objectClass'])) $enviro= $envimg;
243 }
245 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
247 if(!isset($val['description'][0])){
248 $desc = "";
249 }else{
250 $desc = " - [ ".$val['description'][0]." ]";
251 }
253 /* FAIrelease tag from groupApplications */
254 if(isset($val['FAIrelease'][0])){
255 $desc .= " (".$val['FAIrelease'][0].")";
256 }
258 $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
259 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
260 $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix." ".$enviro." ".$mail." ".$samba." ".$appl." ".$phone), "attach" => "style='width:136px;'");
261 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
263 $this->AddElement(array($field1,$field2,$field3,$field4));
264 }
265 }
267 function Save()
268 {
269 MultiSelectWindow :: Save();
270 }
272 function save_object()
273 {
274 /* Save automatic created POSTs like regex, checkboxes */
275 MultiSelectWindow::save_object();
276 }
277 }
278 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
279 ?>