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 divListUsers extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
33 /* CheckBoxes */
34 var $ShowTemplates ;
35 var $ShowFunctionalUsers;
36 var $ShowUnixUsers;
37 var $ShowMailUsers;
38 var $ShowSambaUsers;
39 var $ShowProxyUsers;
41 /* Subsearch checkbox */
42 var $SubSearch = false;
44 var $parent ;
45 var $ui ;
47 function divListUsers (&$config,$parent)
48 {
49 MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
51 $this->parent = $parent;
52 $this->ui = get_userinfo();
54 /* Set list strings */
55 $this->SetTitle(_("List of users"));
56 $this->SetSummary(_("List of users"));
58 /* Result page will look like a headpage */
59 $this->SetHeadpageMode();
61 $this->EnableAplhabet (true);
63 /* Disable buttonsm */
64 $this->EnableCloseButton(false);
65 $this->EnableSaveButton (false);
67 /* Dynamic action col, depending on snapshot icons */
68 $action_col_size = 122;
69 if($this->parent->snapshotEnabled()){
70 $action_col_size += 38;
71 }
73 /* Toggle all selected / deselected */
74 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
75 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
77 /* set Page header */
78 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
79 $this->AddHeader(array("string"=> " ", "attach"=>"style='width:20px;'"));
80 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
81 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:166px;'"));
82 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
84 $this->AddCheckBox("ShowTemplates" ,msgPool::selectToView(_("Template")) ,sprintf(_("Show %s"),_("templates")), false);
85 $this->AddCheckBox("ShowFunctionalUsers",msgPool::selectToView(_("GOsa object"),"enabled"),sprintf(_("Show %s"),_("functional users")), true);
86 $this->AddCheckBox("ShowUnixUsers" ,msgPool::selectToView(_("Posix"),"enabled") ,sprintf(_("Show %s"),_("POSIX users")), true);
87 $this->AddCheckBox("ShowMailUsers" ,msgPool::selectToView(_("Mail"),"enabled") ,sprintf(_("Show %s"),_("mail users")), true);
88 $this->AddCheckBox("ShowSambaUsers" ,msgPool::selectToView(_("Samba"),"enabled") ,sprintf(_("Show %s"),_("samba users")), true);
89 $this->AddCheckBox("ShowProxyUsers" ,msgPool::selectToView(_("Proxy"),"enabled") ,sprintf(_("Show %s"),_("proxy users")), true);
91 /* Add SubSearch checkbox */
92 $this->AddCheckBox(SEPERATOR);
93 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
95 /* Name ,Text ,Default , Connect with alphabet */
96 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
97 }
100 function GenHeader()
101 {
102 /* Prepare departments,
103 which are shown in the listbox on top of the listbox
104 */
105 $options= "";
107 /* Get all departments within this subtree */
108 $base = $this->config->current['BASE'];
110 /* Add base */
111 $tmp = array();
112 $tmp[] = array("dn"=>$this->config->current['BASE']);
113 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
114 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
116 $deps = array();
117 foreach($tmp as $tm){
118 $deps[$tm['dn']] = $tm['dn'];
119 }
122 /* Load possible departments */
123 $ui= get_userinfo();
124 $tdeps= $ui->get_module_departments("users");
125 $ids = $this->config->idepartments;
126 $first = "";
127 $found = FALSE;
128 foreach($ids as $dep => $name){
129 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
131 /* Keep first base dn in mind, we could need this
132 * info if no valid base was found
133 */
134 if(empty($first)) {
135 $first = $dep['dn'];
136 }
138 $value = $ids[$dep];
139 if ($this->selectedBase == $dep){
140 $found = TRUE;
141 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
142 } else {
143 $options.= "<option value='".$dep."'>$value</option>";
144 }
145 }
146 }
148 /* The currently used base is not visible with your acl setup.
149 * Set base to first useable base.
150 */
151 if(!$found){
152 $this->selectedBase = $first;
153 }
155 /* Get copy & paste icon */
156 $acl = $ui->get_permissions($this->selectedBase,"users/user");
158 /* Add default header */
159 $listhead = MultiSelectWindow::get_default_header();
160 $listhead .=
161 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
162 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
163 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
166 /* Create Layers menu */
167 $s = ".|"._("Actions")."|\n";
169 /* Append create options */
170 if(preg_match("/c/",$acl)) {
171 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
172 " "._("Create")."|\n";
173 $s.= "...|<input class='center' type='image' src='images/list_new_user.png' alt=''>".
174 " "._("User")."|user_new|\n";
175 $s.= "...|<input class='center' type='image' src='images/lists/new.png' alt=''>".
176 " "._("Template")."|user_tplnew|\n";
177 }
179 /* Multiple options */
180 $s.= "..|---|\n";
181 $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
182 " "._("Edit")."|"."multiple_edit|\n";
183 $s.= "..|<img src='images/list_password.png' alt='' border='0' class='center'>".
184 " "._("Change password")."|"."multiple_password_change|\n";
185 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
186 " "._("Remove")."|"."remove_multiple|\n";
187 $s.= "..|<img src='images/wizard.png' alt='' border='0' class='center'>".
188 " "._("Apply template")."|"."templatize_multiple|\n";
190 /* Add event tag */
191 if(class_available("DaemonEvent")){
192 $events = DaemonEvent::get_event_types(USER_EVENT);
193 if(count($events['BY_CLASS'])){
194 $s.= "..|---|\n";
195 foreach($events['BY_CLASS'] as $name => $event){
196 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
197 }
198 }
199 }
201 /* Add multiple copy & cut icons */
202 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users");
204 if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
205 $s.= "..|---|\n";
206 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
207 " "._("Copy")."|"."multiple_copy_systems|\n";
208 }
209 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(r.*d|d.*r)/",$acl_all)){
210 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
211 " "._("Cut")."|"."multiple_cut_systems|\n";
212 }
214 /* Copy & paste icons */
215 if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
216 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
217 $s.="..|".$img." "._("Paste")."|editPaste|\n";
218 }else{
219 $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
220 $s.="..|".$img." "._("Paste")."\n";
221 }
223 /* Add snapshot icons */
224 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
225 $s .= "..|---|\n";
226 $s .= $this->get_snapshot_header(TRUE);
227 }
229 $this->SetDropDownHeaderMenu($s);
230 $this->SetListHeader($listhead);
231 }
233 /* so some basic settings */
234 function execute()
235 {
236 $this->ClearElementsList();
237 $this->GenHeader();
238 }
240 function setEntries($list)
241 {
242 /********************
243 Variable init
244 ********************/
246 $num_users = 0;
247 $num_templates = 0;
249 /* Variable initialation */
250 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
251 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
252 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
253 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
254 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
256 /* Dynamic action col, depending on snapshot icons */
257 $action_col_size = 122;
258 if($this->parent->snapshotEnabled()){
259 $action_col_size += 38;
260 }
262 /* Possilbe objectClass image combinations */
263 $possibleAccounts = array(
264 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
265 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
266 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
267 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
268 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
269 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
271 /* Pictures for Extensions */
272 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
273 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
274 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
275 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
276 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
277 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
278 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
279 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
280 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
281 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
282 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
283 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
284 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
285 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
286 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
287 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
288 $tplcreateuserimg = "<input type='image' class='center' src='images/lists/new.png' alt='"._("Create user from template")."'
289 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
291 /********************
292 END :: Variable init
293 ********************/
296 /********************
297 Append entries to divlist
298 ********************/
300 $ui = get_userinfo();
302 // Test Every Entry and generate divlist Array
303 foreach($list as $key => $val){
305 /* Create action icons */
306 $action= "";
308 /* Add copy & cut icons */
309 $acl = $ui->get_permissions($val['dn'],"users/user");
310 if(preg_match("/(r.*d|r.*d)/",$acl) && $this->parent->CopyPasteHandler){
311 $action .= "<input class='center' type='image'
312 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
313 }else{
314 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
315 }
317 if(preg_match("/r/",$acl) && $this->parent->CopyPasteHandler){
318 $action.= "<input class='center' type='image'
319 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
320 }else{
321 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
322 }
324 /* Add deactivate status */
325 $lock_status = "";
327 if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
328 if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
329 $lock_status = "<input class='center' type='image' src='images/lists/locked.png'
330 alt='"._("inactive")."' name='toggle_lock_status_%KEY%'>";
331 }else{
332 $lock_status = "<input class='center' type='image' src='images/lists/unlocked.png'
333 alt='"._("active")."' name='toggle_lock_status_%KEY%'>";
334 }
335 }else{
336 $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
337 }
339 /* Generate edit icon */
340 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
341 name='user_edit_%KEY%' title='".msgPool::editButton(_("user"))."'>";
343 /* Add deactivate status if we are allowed to */
344 if (preg_match("/w/",$acl)){
345 $action.= $lock_status;
346 }else{
347 $action.="<img src='images/empty.png' alt=' ' class='center'>";
348 }
350 /* Add Password change icon, if we are able to write users/password */
351 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
352 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
353 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
354 }else{
355 $action.= "<img class='center' src='images/empty.png' alt=' '
356 title='"._("Not allowed")."'>";
357 }
359 /* Add snapshot icon */
360 if(preg_match("/(r.*w|w.*r)/",$acl)){
361 $action.= $this->GetSnapShotActions($val['dn']);
362 }else{
363 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
364 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
365 }
367 /* Add remove icon, if we are allowed to remove the current user */
368 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
369 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
370 name='user_del_%KEY%' title='"._("Delete user")."'>";
371 }else{
372 $action.= "<img class='center' src='images/empty.png' alt=' '
373 title='"._("Not allowed")."'>";
374 }
376 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
377 if((in_array("goFonAccount" ,$val['objectClass']))){
379 /* Set defaults */
380 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
381 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
382 $fonac = preg_replace("/%title%/", "", $fonac);
384 }else{
385 $fonac=$empty;
386 }
388 /* Set images for different types of objectClasses */
389 foreach($possibleAccounts as $objectClass => $Settigns){
390 if(in_array($objectClass ,$val['objectClass'])){
391 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
392 }else{
393 $$Settigns['VAR'] = $empty;
394 }
395 }
397 /* Create userimg */
398 if(in_array("gosaUserTemplate",$val['objectClass'])){
399 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
400 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
401 $num_templates ++;
402 }else{
403 $s_img_create_from_template = "";
404 $tpl = $userimg;
405 $num_users ++;
406 }
408 /* Insert key into userimg */
409 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
411 // Generate caption for rows
412 if (isset($val["sn"]) && isset($val["givenName"])){
413 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
414 } else {
415 $display= "[".$val["uid"][0]."]";
416 }
418 /* Connect all images */
419 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
421 /* Cutted objects should be displayed in light grey */
422 if($this->parent->CopyPasteHandler){
423 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
424 if($queue_data['dn'] == $val['dn']) {
425 $display = "<font color='#999999'>".$display."</font>";
426 break;
427 }
428 }
429 }
431 /* Create each field */
432 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
433 "attach" => "style='width:20px;'");
434 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
435 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
436 $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
437 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
438 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
439 /* Add to list */
440 $add = array($field0,$field1,$field2,$field3,$field4);
441 $this->AddElement($add);
443 // Template or User
444 if(in_array("gosaUserTemplate",$val['objectClass'])){
445 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
446 }else{
447 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
448 }
449 }
452 /* Create summary string for list footer */
453 $num_deps=0;
454 if(!$this->SubSearch){
455 $num_deps = count($this->Added_Departments);
456 }
457 $num_users = count($list);
459 $num_user_str = _("Number of listed users");
460 $num_dep_str = _("Number of listed departments");
462 $str = "<img class='center' src='images/select_user.png'
463 title='".$num_user_str."' alt='".$num_user_str."'> ".$num_users." ";
464 $str.= "<img class='center' src='images/lists/folder.png'
465 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
467 $this->set_List_Bottom_Info($str);
468 }
470 function Save()
471 {
472 MultiSelectWindow :: Save();
473 }
475 function save_object()
476 {
477 /* Save automatic created POSTs like regex, checkboxes */
478 MultiSelectWindow::save_object();
479 }
480 }
481 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
482 ?>