Code

Fixed deletion for ogw
[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   /* Attribute mapping opengroupware->ldap  */
19   var $attrsToUse    = array( "salutation"  =>"vocation",
20                               "name"        =>"sn",
21                               "firstname"   =>"givenName",
22                               "login"       =>"uid",
23                               "degree"      =>"academicTitle",
24                               "birthday"    =>"dateOfBirth",
25                               "sex"         =>"gender",
26                               "street"      =>"street",
27                               "zip"         =>"postalCode",
28                               "value_string"=>"mail",
29                               "number"      =>"telephoneNumber"
30                             );
32   var $serverCon            =  false;
33   var $handle               = NULL;
34   var $is_account           = false;
35   var $initialy_was_account = false;
37   function opengwAccount ($config, $dn= NULL)
38   {
39     plugin::plugin ($config, $dn);
41     $this->info=array();
43     /* is no account and was no account */
44     $this->initialy_was_account = false;
45     $this->is_account           = false;
47     /* check if datebase funktions are available, and if database configurations are available */ 
48     if((is_callable("pg_connect"))&&(isset($this->config->data['SERVERS']['OPENGROUPWARE']))){
50       /* Get configurations */
51       $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
52       $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
54       /* Check if current configuration allows database connection */
55       if($this->handle->connected){
57         /* Set login name, to check if this is_account */
58         $this->handle->info['login'] = $this->attrs['uid'][0];
60         /* If this is account get data from database first */
61         if($this->handle->CheckExistence()){
62           $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
64           /* This is an account */
65           $this->initialy_was_account = true;
66           $this->is_account= true;
67         }else{
68           /* this is no account */ 
69           $this->initialy_was_account = false;
70           $this->is_account= false;
71           
72           /* Selectable in GOsa */
73           $this->info['template_user_id']   = 0;
74           $this->info['is_locked']          = 0;
75           $this->info['LocationTeamID']     = 0;
76           $this->info['TeamIDis']           = array();
77         }
79         /* Set settings from ldap */
80         foreach($this->attrsToUse as $name=>$attr){
81           if(isset($this->attrs[$attr][0])){
82             $this->info[$name] = $this->attrs[$attr][0];
83           }else{
84             $this->info[$name] = false;
85           }
86         } 
87     
88         /* Description is displayed as 'Nickname' */
89         $this->info['description']          = $this->info['login'];
91         if($this->info['sex'] == "F"){
92           $this->info['sex']                = "female";
93         }else{
94           $this->info['sex']                = "male";
95         }
97       }
98     
99       /* Transmit data back to ogw handle */
100       $this->handle->SetInfos($this->info);
101     }
102   }
104   function execute()
105   {
106     /* Show tab dialog headers */
107     $display= "";
108     $smarty= get_smarty();
110     /* set default values */
111     foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
112       $smarty->assign($ar,array());
113     }
114     $smarty->assign("OGWstate"," disabled ");
115     foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
116       $smarty->assign($ar,"");
117       $smarty->assign($ar."CHK","");
118       $smarty->assign($ar."ACL"," disabled ");
119     }
121     /* Check database extension */    
122     if(!is_callable("pg_connect")){
123       print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
124     }else
125   
126     /* Check if config exists */
127       if(!isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
128       print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
129     }else{
131       /* Create handle */
132       $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
133       $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
135       /* Check if we are successfully connected to db */
136       if(!$this->handle->connected){
137         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
138       }else{
140         /* Show main page */
141         $smarty->assign("OGWstate"," disabled ");
142         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
143           $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
144         }
146         /* Assign LocationTeams */
147         $tmp = array(""=>"none");
148         foreach($this->handle->validLocationTeam as $id){
149           $tmp[$id['company_id']] = $id['description']; 
150         }
151         $smarty->assign("validLocationTeam",$tmp);
152         $smarty->assign("validLocationTeams",array_flip($tmp));
153         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
155         /* Assign TemplateUsers*/
156         $tmp = array();
157         foreach($this->handle->validTemplateUser as $id){
158           $tmp[$id['company_id']] = $id['name']; 
159         }
160         $smarty->assign("validTemplateUser",$tmp);
161         $smarty->assign("validTemplateUsers",array_flip($tmp));
162         $smarty->assign("TemplateUser",$this->info['template_user_id']);
163        
164         /* Create Team membership */ 
165         $str = "";
166         if($this->is_account){
167           $dis = "";
168         }else{
169           $dis = " disabled ";
170         }
172         foreach($this->handle->validTeams as $id){
173           if(in_array($id['company_id'],$this->info['TeamIDis'])){
174             $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
175                         checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
176           }else{
177             $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
178                         name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
179           }
180         }
181         $smarty->assign("validTeams",$str);
183         /* Assign ogw checkbox */
184         if($this->is_account){
185           $smarty->assign("OGWstate","");
186           $smarty->assign("is_account", " checked ");
187         }else{
188           $smarty->assign("is_account", " ");
189           $smarty->assign("OGWstate"," disabled ");
190         }
192         /* Assign acls */
193         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
194           $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
195         }
196   
197         /* Assign lock status */
198         if($this->info['is_locked']){
199           $smarty->assign("is_lockedCHK", " checked ");
200         }else{
201           $smarty->assign("is_lockedCHK", "  ");
202         }
203         $smarty->assign("is_locked", $this->info['is_locked']);
205       } 
206     }
207     $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
208     return ($display);
209   }
211   function remove_from_parent()
212   {
213     /* remove database entries */
214     if($this->initialy_was_account){
215       $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
216       $this->handle->SetInfos($this->info);
217       $this->handle->Perform("REMOVE");
218     }
219   }
222   /* Save data to object */
223   function save_object()
224   {
225     /* get post data */
226     if($this->is_account){
227     
228       /* Get selected team chkboxes */
229       $this->info['TeamIDis'] = array();
230       foreach($_POST as $name => $value ){
231         if(preg_match("/team_/i",$name)){
232           if(!in_array($value,$this->info['TeamIDis'])){
233             $this->info['TeamIDis'][]=$value;
234           }
235         }
236       }
238       /* Get location Team*/
239       if(isset($_POST['LocationTeam'])){
240         $this->info['LocationTeamID'] = $_POST['LocationTeam'];
241       }
242       
243       /* Get template user */
244       if(isset($_POST['TemplateUser'])){
245         $this->info['template_user_id'] = $_POST['TemplateUser'];
246       }
247       
248       /* get lock status */
249       if(isset($_POST['is_locked'])){
250         $this->info['is_locked'] = $_POST['is_locked'];
251       }else{
252         $this->info['is_locked'] = 0;
253       }
254     }
255  
256     /* change account status */
257     if(isset($_POST['is_account'])){
258       $this->is_account = $_POST['is_account'];
259     }else{
260       $this->is_account = false;//$_POST['is_account'];
261     }
263   }
266   /* Save to LDAP */
267   function save()
268   {
269     /* Save data */ 
270     $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
271     $this->handle->SetInfos($this->info);
272     $this->handle->checkInfos();
273     if($this->initialy_was_account){
274       $this->handle->Perform("EDIT");
275     }else{
276       $this->handle->Perform("ADD");
277     }
278   }
282 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
283 ?>