Code

Fixed w3c compatibility
[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= "";
82 #print_a($this->config->idepartments);
83 #$ui= get_userinfo();
84 #$t= $ui->get_module_departments("users");
85 #print_a($t);
86     foreach ($this->config->idepartments as $key => $value){
87       if ($this->selectedBase == $key){
88         $options.= "<option selected='selected' value='$key'>$value</option>";
89       } else {
90         $options.= "<option value='$key'>$value</option>";
91       }
92     }
94     /* Get copy & paste icon */ 
95     if($this->parent->CopyPasteHandler){
96       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
97     }else{
98       $Copy_Paste ="";
99     }
101     /* Create header with selected base */
102     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
103       " <input class='center' type='image' src='images/list_root.png' align='middle' 
104       title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
105       " <input class='center' type='image' align='middle' src='images/list_back.png' 
106       title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;".
107       " <input class='center' type='image' align='middle' src='images/list_home.png' 
108       title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;".
109       " <input class='center' type='image' src='images/list_reload.png' align='middle' 
110       title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
111       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
112     $listhead .= $this->get_snapshot_header($this->selectedBase);
113     $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
114       title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
115       " <input class='center' type='image' align='middle' src='images/list_new.png' 
116       title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
117       $Copy_Paste.
118       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
119       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
120       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
121       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
122       "</div>";
124     $this->SetListHeader($listhead);
125   }
127   /* so some basic settings */
128   function execute()
129   {
130     $this->ClearElementsList();
131     $this->GenHeader();
132   }
134   function setEntries($list)
135   {
136     /********************
137       Variable init
138      ********************/
140     /* Variable initialation */
141     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
142     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
143     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
144     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
145     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
147     /* Dynamic action col, depending on snapshot icons */
148     $action_col_size = 104;
149     if($this->parent->snapshotEnabled()){
150       $action_col_size += 38;
151     }
153     /* Possilbe objectClass image combinations */  
154     $possibleAccounts = array(
155             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
156             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
157             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
158             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
159             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
160             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
162      /* Pictures for Extensions */
163     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
164                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
165     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
166                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
167     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
168                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
169     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
170                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
171     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
172                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
173     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
174                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
175     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
176                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
177     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
178                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
179     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
180                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
182     /********************
183       END :: Variable init
184      ********************/
186     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
187      * Read Sip Table for specified account (for each user with phoneAccount).
188      * Check the attributes ip port and regseconds.
189      * If regseconds is set and >0 , the phone is logged in.
190      * Else the phone is currently not logged.
191      * If we can't read any Data from the DB or there is no goFon DB specified
192      * show old style without status icons.
193      */
194     $r_db   =false;
195     $r_con  =false;
196     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
197       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
198       $r_con = false;
199       $r_db  = false;
200       if(is_callable("mysql_pconnect")){
201         $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
202         // Check if we are  connected correctly
203         if($r_con){
204           $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
205         }
206       }
207     }
208    
209  
210     /********************
211       Append entries to divlist 
212      ********************/
213  
214     // Test Every Entry and generate divlist Array
215     foreach($list as $key => $val){
217       /* Create action icons */
218       $action= "";
219       if($this->parent->CopyPasteHandler){
220         $action .= "<input class='center' type='image'
221           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
222         $action.= "<input class='center' type='image'
223           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
224       }
225       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
226         name='user_edit_%KEY%' title='"._("Edit user")."'>";
227       $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
228         name='user_chgpw_%KEY%' title='"._("Change password")."'>";
229       $action.= $this->GetSnapShotActions($val['dn']);
230       $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
231         name='user_del_%KEY%' title='"._("Delete user")."'>";
234       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
235       $connected  = ""; // This string represents timestamp or offline status
236       $ip_port    = ""; // String that will represent ip : port of the connected phone
237       if((in_array("goFonAccount"    ,$val['objectClass']))){
239         /* Set defaults */
240         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
241         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
242         $fonac = preg_replace("/%title%/", "", $fonac);
244         /* Database connection is ok ?*/
245         if(($r_db)&&(is_callable("mysql_query"))){
246           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
247           $mysql_entry = @mysql_fetch_row($res);
248           if(is_array($mysql_entry)){
249             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
250               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
251               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
252               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
253               $fonac = preg_replace("/%title%/", $connected, $fonac);
254               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
255             }
256             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
257               $connected = " | "._("Offline");
258               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
259               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
260               $fonac = preg_replace("/%title%/", $connected, $fonac);
261             }
262           }
263         }
264       }else{
265         $fonac=$empty;
266       }
268       /* Set images for different types of objectClasses */
269       foreach($possibleAccounts as $objectClass => $Settigns){ 
270         if(in_array($objectClass ,$val['objectClass'])){
271           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
272         }else{
273           $$Settigns['VAR'] = $empty;
274         }
275       }
277       /* Create userimg */
278       if(in_array("gosaUserTemplate",$val['objectClass'])){
279         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
280         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
281       }else{
282         $s_img_create_from_template   = "";
283         $tpl                          = $userimg;
284       }
286       /* Insert key into userimg */
287       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
289       // Generate caption for rows
290       if (isset($val["sn"]) && isset($val["givenName"])){
291         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
292       } else {
293         $display= "[".$val["uid"][0]."]";
294       }
296       /* Connect all images */
297       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
299       /* Create each field */
300       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
301       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
302       $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
303       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
304                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
305       /* Add to list */
306       $add = array($field1,$field2,$field3,$field4);
307       $this->AddElement($add);
309       // Template or User
310       if(in_array("gosaUserTemplate",$val['objectClass'])){
311         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
312       }else{
313         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
314       }
315     }
316     
317     /* close database connection, if it was opened */
318     if(isset($r_con)){
319       if((is_callable("mysql_close"))&&($r_con)){
320         @mysql_close($r_con);
321       }
322     }
324   }
326   function Save()
327   {
328     MultiSelectWindow :: Save();  
329   }
331   function save_object()
332   {
333     /* Save automatic created POSTs like regex, checkboxes */
334     MultiSelectWindow::save_object();   
335   }
337 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
338 ?>