Code

Added passwort setting for opengw accounts
[gosa.git] / plugins / personal / connectivity / class_opengwAccount.inc
1 <?php
3 class opengwAccount extends plugin
4 {
5         /* Definitions */
6         var $plHeadline       = "Opengroupware account";
7         var $plDescription    = "This does something";
9         /* CLI vars */
10         var $cli_summary      = "Manage users webdav account";
11         var $cli_description  = "Some longer text\nfor help";
12         var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
14         /* attribute list for save action */
15         var $attributes       = array();
16         var $objectclasses    = array();
18   var $SetPassword   = false;
20         /* Attribute mapping opengroupware->ldap  */
21         var $attrsToUse    = array( "salutation"  =>"vocation",
22                         "name"        =>"sn",
23                         "firstname"   =>"givenName",
24                         "login"       =>"uid",
25                         "degree"      =>"academicTitle",
26                         "birthday"    =>"dateOfBirth",
27                         "sex"         =>"gender",
28                         "street"      =>"street",
29                         "zip"         =>"postalCode",
30                         "value_string"=>"mail",
31                         "number"      =>"telephoneNumber"
32                         );
34         var $serverCon            =  false;
35         var $handle               = NULL;
36         var $is_account           = false;
37         var $initialy_was_account = false;
38   var $OGWPassword          = "";
40         function opengwAccount ($config, $dn= NULL)
41         {
42                 plugin::plugin ($config, $dn);
44                 $this->info=array();
46                 /* is no account and was no account */
47                 $this->initialy_was_account = false;
48                 $this->is_account           = false;
50                 /* check if datebase funktions are available, and if database configurations are available */ 
51                 if(is_callable("pg_connect")){
53                         /* Get configurations */
54                         if(search_config($this->config->data,"opengwAccount","USERNAME")){
55                                 $atr = array();
56                                 $atr['LOGIN']   =       search_config($this->config->data,"opengwAccount","USERNAME");
57                                 $atr['PASSWORD']=       search_config($this->config->data,"opengwAccount","PASSWORD");
58                                 $atr['SERVER']  =       search_config($this->config->data,"opengwAccount","DATAHOST");
59                                 $atr['DB']              =       search_config($this->config->data,"opengwAccount","DATABASE");
60                                 $this->serverCon = $atr;
61                         }else{
62                                 $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
63                         }
64                         $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
66                         /* Check if current configuration allows database connection */
67                         if($this->handle->connected){
69                                 /* Set login name, to check if this is_account */
70                                 if(isset($this->attrs['uid'][0])){
71                                         $this->handle->info['login'] = $this->attrs['uid'][0];
72                                 }else{
73                                         $this->handle->info['login'] = ""; 
74                                 }
76                                 /* If this is account get data from database first */
77                                 if($this->handle->CheckExistence()){
78                                         $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
80                                         /* This is an account */
81                                         $this->initialy_was_account = true;
82                                         $this->is_account= true;
83                                 }else{
84                                         /* this is no account */ 
85                                         $this->initialy_was_account = false;
86                                         $this->is_account= false;
88                                         /* Selectable in GOsa */
89                                         $this->info['template_user_id']   = 0;
90                                         $this->info['is_locked']          = 0;
91                                         $this->info['LocationTeamID']     = 0;
92                                         $this->info['TeamIDis']           = array();
93                                 }
95                                 /* Set settings from ldap */
96                                 foreach($this->attrsToUse as $name=>$attr){
97                                         if(isset($this->attrs[$attr][0])){
98                                                 $this->info[$name] = $this->attrs[$attr][0];
99                                         }else{
100                                                 $this->info[$name] = false;
101                                         }
102                                 } 
104                                 /* Description is displayed as 'Nickname' */
105                                 $this->info['description']          = $this->info['login'];
107                                 if($this->info['sex'] == "F"){
108                                         $this->info['sex']                = "female";
109                                 }else{
110                                         $this->info['sex']                = "male";
111                                 }
113                         }
115                         /* Transmit data back to ogw handle */
116                         $this->handle->SetInfos($this->info);
117                 }
118         }
120         function execute()
121         {
122                 /* Show tab dialog headers */
123                 $display= "";
124                 $smarty= get_smarty();
126                 /* set default values */
127                 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
128                         $smarty->assign($ar,array());
129                 }
130                 $smarty->assign("OGWstate"," disabled ");
131                 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account","OGWPassword") as $ar){
132                         $smarty->assign($ar,"");
133                         $smarty->assign($ar."CHK","");
134                         $smarty->assign($ar."ACL"," disabled ");
135                 }
137                 /* Check database extension */    
138                 if(!is_callable("pg_connect")){
139                         print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
140                 }else
142                         /* Check if config exists */
143                         if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
144                                 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
145                         }else{
147                                 /* Create handle */
148                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
150                                 /* Check if we are successfully connected to db */
151                                 if(!$this->handle->connected){
152                                         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
153                                 }else{
155                                         /* Show main page */
156                                         $smarty->assign("OGWstate"," disabled ");
157                                         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","OGWPassword") as $ar){
158                                                 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
159                                         }
161                                         /* Assign LocationTeams */
162                                         $tmp = array(""=>"none");
163                                         foreach($this->handle->validLocationTeam as $id){
164                                                 $tmp[$id['company_id']] = $id['description']; 
165                                         }
166                                         $smarty->assign("validLocationTeam",$tmp);
167                                         $smarty->assign("validLocationTeams",array_flip($tmp));
168                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
170                                         /* Assign TemplateUsers*/
171                                         $tmp = array();
172                                         foreach($this->handle->validTemplateUser as $id){
173                                                 $tmp[$id['company_id']] = $id['name']; 
174                                         }
175                                         $smarty->assign("validTemplateUser",$tmp);
176                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
177                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
179                                         /* Create Team membership */ 
180                                         $str = "";
181                                         if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
182                                                 $dis = "";
183                                         }else{
184                                                 $dis = " disabled ";
185                                         }
187                                         foreach($this->handle->validTeams as $id){
188                                                 if(in_array($id['company_id'],$this->info['TeamIDis'])){
189                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
190                                                                 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
191                                                 }else{
192                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
193                                                                 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
194                                                 }
195                                         }
196                                         $smarty->assign("validTeams",$str);
198                                         /* Assign ogw checkbox */
199                                         if($this->is_account){
200                                                 $smarty->assign("OGWstate","");
201                                                 $smarty->assign("is_account", " checked ");
202                                         }else{
203                                                 $smarty->assign("is_account", " ");
204                                                 $smarty->assign("OGWstate"," disabled ");
205                                         }
207                                         /* Assign acls */
208                                         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
209                                                 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
210                                         }
212                                         /* Assign lock status */
213                                         if($this->info['is_locked']){
214                                                 $smarty->assign("is_lockedCHK", " checked ");
215                                         }else{
216                                                 $smarty->assign("is_lockedCHK", "  ");
217                                         }
218                                         $smarty->assign("is_locked", $this->info['is_locked']);
220                                 } 
221                         }
222       if($this->SetPassword == false){
223         if($_SESSION['js'] == 1){
224           $smarty->assign("OGWPasswordACL"," disabled ");
225         }else{
226           $smarty->assign("OGWPasswordACL","");
227         }
228         $smarty->assign("OGWPassword","");
229         $smarty->assign("OGWPasswordCHK"," ");
230       }else{
231         $smarty->assign("OGWPasswordACL","");
232         $smarty->assign("OGWPassword",$this->OGWPassword);
233         $smarty->assign("OGWPasswordCHK"," checked ");
234       }
235                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
236                 return ($display);
237         }
239         function remove_from_parent()
240         {
241                 /* remove database entries */
242                 if($this->initialy_was_account){
243                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
244                         $this->handle->SetInfos($this->info);
245                         $this->handle->Perform("REMOVE");
246                 }
247         }
250         /* Save data to object */
251         function save_object()
252         {
253                 /* get post data */
254                 if($this->is_account){
256       if(isset($_POST['SetPassword'])){
257         $this->SetPassword =true;
258       }else{
259         $this->SetPassword = false;
260       }
262       if((isset($_POST['OGWPassword']))&&($this->SetPassword)){
263         $this->OGWPassword      = $_POST['OGWPassword'];
264         $pwd = new passwordMethodCrypt($this->config);
265         
266         $this->info['password'] = preg_replace("/^{crypt}/","",$pwd->generate_hash($_POST['OGWPassword']));
267       }else{
268         if(isset($this->info['password'])){
269           unset($this->info['password']);
270         }
271       }
273                         /* Get selected team chkboxes */
274                         $this->info['TeamIDis'] = array();
275                         foreach($_POST as $name => $value ){
276                                 if(preg_match("/team_/i",$name)){
277                                         if(!in_array($value,$this->info['TeamIDis'])){
278                                                 $this->info['TeamIDis'][]=$value;
279                                         }
280                                 }
281                         }
283                         /* Get location Team*/
284                         if(isset($_POST['LocationTeam'])){
285                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
286                         }
288                         /* Get template user */
289                         if(isset($_POST['TemplateUser'])){
290                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
291                         }
293                         /* get lock status */
294                         if(isset($_POST['is_locked'])){
295                                 $this->info['is_locked'] = $_POST['is_locked'];
296                         }else{
297                                 $this->info['is_locked'] = 0;
298                         }
299                 }
301                 /* change account status */
302                 if(isset($_POST['is_account'])){
303                         $this->is_account = $_POST['is_account'];
304                 }else{
305                         $this->is_account = false;//$_POST['is_account'];
306                 }
308         }
311         /* Save to LDAP */
312         function save()
313         {
314                 /* Save data */ 
315                 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
316                 $this->handle->SetInfos($this->info);
317                 $this->handle->checkInfos();
318                 if($this->initialy_was_account){
319                         $this->handle->Perform("EDIT");
320                 }else{
321                         $this->handle->Perform("ADD");
322                 }
323         }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>