Code

Set of fixes for users/acl
[gosa.git] / plugins / admin / users / class_divListUsers.inc
1 <?php
3 class divListUsers extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
13   /* CheckBoxes */
14   var $ShowTemplates ;
15   var $ShowFunctionalUsers;
16   var $ShowUnixUsers;
17   var $ShowMailUsers;
18   var $ShowSambaUsers;
19   var $ShowProxyUsers;
21   /* Subsearch checkbox */
22   var $SubSearch              = false;
24   var $parent             ;
25   var $ui                 ;
27   function divListUsers ($config,$parent)
28   {
29     MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
30     
31     $this->parent       = $parent;
32     $this->ui           = get_userinfo();
34     /* Set list strings */
35     $this->SetTitle(_("List of users"));
36     $this->SetSummary(_("List of users"));
38     /* Result page will look like a headpage */
39     $this->SetHeadpageMode();
40     $this->SetInformation(_("This menu allows you to create, edit and delete selected users. Having a great number of users, you may want to use the range selectors on top of the user list."));
42     $this->EnableAplhabet   (true);
43   
44     /* Disable buttonsm */
45     $this->EnableCloseButton(false);
46     $this->EnableSaveButton (false);
48     /* Dynamic action col, depending on snapshot icons */
49     $action_col_size = 104;
50     if($this->parent->snapshotEnabled()){
51       $action_col_size += 38;
52     }
54     /* set Page header */
55     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
56     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
57     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:152px;'"));
58     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
59     
60     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
61     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
62     $this->AddCheckBox("ShowUnixUsers"      ,_("Select to see users that have posix settings")      ,_("Show unix users")       , true);
63     $this->AddCheckBox("ShowMailUsers"      ,_("Select to see users that have mail settings")       ,_("Show mail users")       , true);
64     $this->AddCheckBox("ShowSambaUsers"     ,_("Select to see users that have samba settings")      ,_("Show samba users")      , true);
65     $this->AddCheckBox("ShowProxyUsers"     ,_("Select to see users that have proxy settings")      ,_("Show proxy users")      , true);
67     /* Add SubSearch checkbox */
68     $this->AddCheckBox(SEPERATOR);
69     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
71     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
72     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
73   }
76   function GenHeader()
77   {
78     /* Prepare departments,
79        which are shown in the listbox on top of the listbox
80      */
81     $options= "";
83     /* Get all departments within this subtree */ 
84     $base = $this->config->current['BASE'];
85     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
86                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
88 $ui= get_userinfo();
89 $t= $ui->get_module_departments("users");
90 print_a($t);
92     $ids = $this->config->idepartments;
93  
94 print_a($ids);
96     foreach($deps as $dep){
97       if(isset($ids[$dep['dn']])){
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 copy & paste icon */ 
109     if($this->parent->CopyPasteHandler){
110       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
111     }else{
112       $Copy_Paste ="";
113     }
115     /* Create header with selected base */
116     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
117       " <input class='center' type='image' src='images/list_root.png' align='middle' 
118       title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
119       " <input class='center' type='image' align='middle' src='images/list_back.png' 
120       title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;".
121       " <input class='center' type='image' align='middle' src='images/list_home.png' 
122       title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;".
123       " <input class='center' type='image' src='images/list_reload.png' align='middle' 
124       title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
125       " <img   class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'>&nbsp;";
126     $listhead .= $this->get_snapshot_header($this->selectedBase);
127     $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
128       title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
129       " <input class='center' type='image' align='middle' src='images/list_new.png' 
130       title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
131       $Copy_Paste.
132       " <img   class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'>&nbsp;".
133       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
134       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
135       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
136       "</div>";
138     $this->SetListHeader($listhead);
139   }
141   /* so some basic settings */
142   function execute()
143   {
144     $this->ClearElementsList();
145     $this->GenHeader();
146   }
148   function setEntries($list)
149   {
150     /********************
151       Variable init
152      ********************/
154     /* Variable initialation */
155     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
156     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
157     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
158     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
159     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
161     /* Dynamic action col, depending on snapshot icons */
162     $action_col_size = 104;
163     if($this->parent->snapshotEnabled()){
164       $action_col_size += 38;
165     }
167     /* Possilbe objectClass image combinations */  
168     $possibleAccounts = array(
169             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
170             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
171             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
172             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
173             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
174             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
176      /* Pictures for Extensions */
177     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
178                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
179     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
180                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
181     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
182                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
183     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
184                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
185     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
186                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
187     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
188                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
189     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
190                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
191     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
192                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
193     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
194                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
196     /********************
197       END :: Variable init
198      ********************/
200     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
201      * Read Sip Table for specified account (for each user with phoneAccount).
202      * Check the attributes ip port and regseconds.
203      * If regseconds is set and >0 , the phone is logged in.
204      * Else the phone is currently not logged.
205      * If we can't read any Data from the DB or there is no goFon DB specified
206      * show old style without status icons.
207      */
208     $r_db   =false;
209     $r_con  =false;
210     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
211       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
212       $r_con = false;
213       $r_db  = false;
214       if(is_callable("mysql_pconnect")){
215         $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
216         // Check if we are  connected correctly
217         if($r_con){
218           $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
219         }
220       }
221     }
222    
223  
224     /********************
225       Append entries to divlist 
226      ********************/
227  
228     // Test Every Entry and generate divlist Array
229     foreach($list as $key => $val){
231       /* Create action icons */
232       $action= "";
233       if($this->parent->CopyPasteHandler){
234         $action .= "<input class='center' type='image'
235           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
236         $action.= "<input class='center' type='image'
237           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
238       }
239       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
240         name='user_edit_%KEY%' title='"._("Edit user")."'>";
241       $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
242         name='user_chgpw_%KEY%' title='"._("Change password")."'>";
243       $action.= $this->GetSnapShotActions($val['dn']);
244       $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
245         name='user_del_%KEY%' title='"._("Delete user")."'>";
248       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
249       $connected  = ""; // This string represents timestamp or offline status
250       $ip_port    = ""; // String that will represent ip : port of the connected phone
251       if((in_array("goFonAccount"    ,$val['objectClass']))){
253         /* Set defaults */
254         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
255         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
256         $fonac = preg_replace("/%title%/", "", $fonac);
258         /* Database connection is ok ?*/
259         if(($r_db)&&(is_callable("mysql_query"))){
260           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
261           $mysql_entry = @mysql_fetch_row($res);
262           if(is_array($mysql_entry)){
263             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
264               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
265               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
266               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
267               $fonac = preg_replace("/%title%/", $connected, $fonac);
268               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
269             }
270             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
271               $connected = " | "._("Offline");
272               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
273               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
274               $fonac = preg_replace("/%title%/", $connected, $fonac);
275             }
276           }
277         }
278       }else{
279         $fonac=$empty;
280       }
282       /* Set images for different types of objectClasses */
283       foreach($possibleAccounts as $objectClass => $Settigns){ 
284         if(in_array($objectClass ,$val['objectClass'])){
285           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
286         }else{
287           $$Settigns['VAR'] = $empty;
288         }
289       }
291       /* Create userimg */
292       if(in_array("gosaUserTemplate",$val['objectClass'])){
293         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
294         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
295       }else{
296         $s_img_create_from_template   = "";
297         $tpl                          = $userimg;
298       }
300       /* Insert key into userimg */
301       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
303       // Generate caption for rows
304       if (isset($val["sn"]) && isset($val["givenName"])){
305         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
306       } else {
307         $display= "[".$val["uid"][0]."]";
308       }
310       /* Connect all images */
311       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
313       /* Create each field */
314       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
315       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
316       $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
317       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
318                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
319       /* Add to list */
320       $add = array($field1,$field2,$field3,$field4);
321       $this->AddElement($add);
323       // Template or User
324       if(in_array("gosaUserTemplate",$val['objectClass'])){
325         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
326       }else{
327         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
328       }
329     }
330     
331     /* close database connection, if it was opened */
332     if(isset($r_con)){
333       if((is_callable("mysql_close"))&&($r_con)){
334         @mysql_close($r_con);
335       }
336     }
338   }
340   function Save()
341   {
342     MultiSelectWindow :: Save();  
343   }
345   function save_object()
346   {
347     /* Save automatic created POSTs like regex, checkboxes */
348     MultiSelectWindow::save_object();   
349   }
351 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
352 ?>