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");
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);
44 /* Disable buttonsm */
45 $this->EnableCloseButton(false);
46 $this->EnableSaveButton (false);
48 /* set Page header */
49 $this->AddHeader(array("string"=>" ", "attach"=>"style='width:20px;'"));
50 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
51 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:152px;'"));
52 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:102px;border-right:0px;text-align:right;'"));
54 $this->AddCheckBox("ShowTemplates" ,_("Select to see template pseudo users") ,_("Show templates") , false);
55 $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
56 $this->AddCheckBox("ShowUnixUsers" ,_("Select to see users that have posix settings") ,_("Show unix users") , true);
57 $this->AddCheckBox("ShowMailUsers" ,_("Select to see users that have mail settings") ,_("Show mail users") , true);
58 $this->AddCheckBox("ShowSambaUsers" ,_("Select to see users that have samba settings") ,_("Show samba users") , true);
59 $this->AddCheckBox("ShowProxyUsers" ,_("Select to see users that have proxy settings") ,_("Show proxy users") , true);
61 /* Add SubSearch checkbox */
62 $this->AddCheckBox(SEPERATOR);
63 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
65 /* Name ,Text ,Default , Connect with alphabet */
66 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
67 }
69 function GenHeader()
70 {
71 /* Prepare departments,
72 which are shown in the listbox on top of the listbox
73 */
74 $options= "";
75 foreach ($this->config->idepartments as $key => $value){
76 if ($this->selectedBase == $key){
77 $options.= "<option selected='selected' value='$key'>$value</option>";
78 } else {
79 $options.= "<option value='$key'>$value</option>";
80 }
81 }
83 /* Get copy & paste icon */
84 if($this->parent->CopyPasteHandler){
85 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
86 }else{
87 $Copy_Paste ="";
88 }
90 /* Add default header */
91 $listhead = MultiSelectWindow::get_default_header();
93 $listhead.= " <input class='center' type='image' align='middle' src='images/list_new_user.png'
94 title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
95 " <input class='center' type='image' align='middle' src='images/list_new.png'
96 title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
97 $Copy_Paste.
98 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
99 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
100 " <input class='center' type='image' src='images/list_submit.png' align='middle'
101 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
102 "</div>";
104 $this->SetListHeader($listhead);
105 }
107 /* so some basic settings */
108 function execute()
109 {
110 $this->ClearElementsList();
111 $this->GenHeader();
112 }
114 function setEntries($list)
115 {
116 /********************
117 Variable init
118 ********************/
120 /* Variable initialation */
121 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
122 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
123 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
124 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
125 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
127 /* Create action icons */
128 $action = "";
129 if($this->parent->CopyPasteHandler){
130 $action .= "<input class='center' type='image'
131 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
132 $action.= "<input class='center' type='image'
133 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
134 }
135 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
136 name='user_edit_%KEY%' title='"._("Edit user")."'>";
137 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
138 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
139 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
140 name='user_del_%KEY%' title='"._("Delete user")."'>";
142 /* Possilbe objectClass image combinations */
143 $possibleAccounts = array(
144 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
145 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
146 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
147 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
148 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
149 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
151 /* Pictures for Extensions */
152 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
153 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
154 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
155 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
156 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
157 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
158 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
159 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
160 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
161 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
162 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
163 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
164 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
165 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
166 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
167 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
168 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
169 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
171 /********************
172 END :: Variable init
173 ********************/
175 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
176 * Read Sip Table for specified account (for each user with phoneAccount).
177 * Check the attributes ip port and regseconds.
178 * If regseconds is set and >0 , the phone is logged in.
179 * Else the phone is currently not logged.
180 * If we can't read any Data from the DB or there is no goFon DB specified
181 * show old style without status icons.
182 */
183 $r_db =false;
184 $r_con =false;
185 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
186 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
187 $r_con = false;
188 $r_db = false;
189 if(is_callable("mysql_pconnect")){
190 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
191 // Check if we are connected correctly
192 if($r_con){
193 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
194 }
195 }
196 }
199 /********************
200 Append entries to divlist
201 ********************/
203 // Test Every Entry and generate divlist Array
204 foreach($list as $key => $val){
206 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
207 $connected = ""; // This string represents timestamp or offline status
208 $ip_port = ""; // String that will represent ip : port of the connected phone
209 if((in_array("goFonAccount" ,$val['objectClass']))){
211 /* Set defaults */
212 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
213 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
214 $fonac = preg_replace("/%title%/", "", $fonac);
216 /* Database connection is ok ?*/
217 if(($r_db)&&(is_callable("mysql_query"))){
218 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
219 $mysql_entry = @mysql_fetch_row($res);
220 if(is_array($mysql_entry)){
221 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
222 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
223 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
224 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
225 $fonac = preg_replace("/%title%/", $connected, $fonac);
226 #$ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
227 }
228 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
229 $connected = " | "._("Offline");
230 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
231 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
232 $fonac = preg_replace("/%title%/", $connected, $fonac);
233 }
234 }
235 }
236 }else{
237 $fonac=$empty;
238 }
240 /* Set images for different types of objectClasses */
241 foreach($possibleAccounts as $objectClass => $Settigns){
242 if(in_array($objectClass ,$val['objectClass'])){
243 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
244 }else{
245 $$Settigns['VAR'] = $empty;
246 }
247 }
249 /* Create userimg */
250 if(in_array("gosaUserTemplate",$val['objectClass'])){
251 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
252 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
253 }else{
254 $s_img_create_from_template = "";
255 $tpl = $userimg;
256 }
258 /* Insert key into userimg */
259 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
261 // Generate caption for rows
262 if (isset($val["sn"]) && isset($val["givenName"])){
263 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
264 } else {
265 $display= "[".$val["uid"][0]."]";
266 }
268 /* Connect all images */
269 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
271 /* Create each field */
272 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
273 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
274 $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
275 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
276 "attach" => "style='width:102px;border-right:0px; text-align:right;'");
277 /* Add to list */
278 $add = array($field1,$field2,$field3,$field4);
279 $this->AddElement($add);
281 // Template or User
282 if(in_array("gosaUserTemplate",$val['objectClass'])){
283 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
284 }else{
285 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
286 }
287 }
289 /* close database connection, if it was opened */
290 if(isset($r_con)){
291 if((is_callable("mysql_close"))&&($r_con)){
292 @mysql_close($r_con);
293 }
294 }
296 }
298 function Save()
299 {
300 MultiSelectWindow :: Save();
301 }
303 function save_object()
304 {
305 /* Save automatic created POSTs like regex, checkboxes */
306 MultiSelectWindow::save_object();
307 }
308 }
309 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
310 ?>