Code

updated ogw s
[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")){
50                         /* Get configurations */
51                         if(search_config($this->config->data,"opengwAccount","USERNAME")){
52                                 $atr = array();
53                                 $atr['LOGIN']   =       search_config($this->config->data,"opengwAccount","USERNAME");
54                                 $atr['PASSWORD']=       search_config($this->config->data,"opengwAccount","PASSWORD");
55                                 $atr['SERVER']  =       search_config($this->config->data,"opengwAccount","DATAHOST");
56                                 $atr['DB']              =       search_config($this->config->data,"opengwAccount","DATABASE");
57                                 $this->serverCon = $atr;
58                         }else{
59                                 $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
60                         }
61                         $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
63                         /* Check if current configuration allows database connection */
64                         if($this->handle->connected){
66                                 /* Set login name, to check if this is_account */
67                                 $this->handle->info['login'] = $this->attrs['uid'][0];
69                                 /* If this is account get data from database first */
70                                 if($this->handle->CheckExistence()){
71                                         $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
73                                         /* This is an account */
74                                         $this->initialy_was_account = true;
75                                         $this->is_account= true;
76                                 }else{
77                                         /* this is no account */ 
78                                         $this->initialy_was_account = false;
79                                         $this->is_account= false;
81                                         /* Selectable in GOsa */
82                                         $this->info['template_user_id']   = 0;
83                                         $this->info['is_locked']          = 0;
84                                         $this->info['LocationTeamID']     = 0;
85                                         $this->info['TeamIDis']           = array();
86                                 }
88                                 /* Set settings from ldap */
89                                 foreach($this->attrsToUse as $name=>$attr){
90                                         if(isset($this->attrs[$attr][0])){
91                                                 $this->info[$name] = $this->attrs[$attr][0];
92                                         }else{
93                                                 $this->info[$name] = false;
94                                         }
95                                 } 
97                                 /* Description is displayed as 'Nickname' */
98                                 $this->info['description']          = $this->info['login'];
100                                 if($this->info['sex'] == "F"){
101                                         $this->info['sex']                = "female";
102                                 }else{
103                                         $this->info['sex']                = "male";
104                                 }
106                         }
108                         /* Transmit data back to ogw handle */
109                         $this->handle->SetInfos($this->info);
110                 }
111         }
113         function execute()
114         {
115                 /* Show tab dialog headers */
116                 $display= "";
117                 $smarty= get_smarty();
119                 /* set default values */
120                 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
121                         $smarty->assign($ar,array());
122                 }
123                 $smarty->assign("OGWstate"," disabled ");
124                 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account") as $ar){
125                         $smarty->assign($ar,"");
126                         $smarty->assign($ar."CHK","");
127                         $smarty->assign($ar."ACL"," disabled ");
128                 }
130                 /* Check database extension */    
131                 if(!is_callable("pg_connect")){
132                         print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
133                 }else
135                         /* Check if config exists */
136                         if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
137                                 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
138                         }else{
140                                 /* Create handle */
141                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
143                                 /* Check if we are successfully connected to db */
144                                 if(!$this->handle->connected){
145                                         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
146                                 }else{
148                                         /* Show main page */
149                                         $smarty->assign("OGWstate"," disabled ");
150                                         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
151                                                 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
152                                         }
154                                         /* Assign LocationTeams */
155                                         $tmp = array(""=>"none");
156                                         foreach($this->handle->validLocationTeam as $id){
157                                                 $tmp[$id['company_id']] = $id['description']; 
158                                         }
159                                         $smarty->assign("validLocationTeam",$tmp);
160                                         $smarty->assign("validLocationTeams",array_flip($tmp));
161                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
163                                         /* Assign TemplateUsers*/
164                                         $tmp = array();
165                                         foreach($this->handle->validTemplateUser as $id){
166                                                 $tmp[$id['company_id']] = $id['name']; 
167                                         }
168                                         $smarty->assign("validTemplateUser",$tmp);
169                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
170                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
172                                         /* Create Team membership */ 
173                                         $str = "";
174                                         if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
175                                                 $dis = "";
176                                         }else{
177                                                 $dis = " disabled ";
178                                         }
180                                         foreach($this->handle->validTeams as $id){
181                                                 if(in_array($id['company_id'],$this->info['TeamIDis'])){
182                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
183                                                                 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
184                                                 }else{
185                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
186                                                                 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
187                                                 }
188                                         }
189                                         $smarty->assign("validTeams",$str);
191                                         /* Assign ogw checkbox */
192                                         if($this->is_account){
193                                                 $smarty->assign("OGWstate","");
194                                                 $smarty->assign("is_account", " checked ");
195                                         }else{
196                                                 $smarty->assign("is_account", " ");
197                                                 $smarty->assign("OGWstate"," disabled ");
198                                         }
200                                         /* Assign acls */
201                                         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
202                                                 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
203                                         }
205                                         /* Assign lock status */
206                                         if($this->info['is_locked']){
207                                                 $smarty->assign("is_lockedCHK", " checked ");
208                                         }else{
209                                                 $smarty->assign("is_lockedCHK", "  ");
210                                         }
211                                         $smarty->assign("is_locked", $this->info['is_locked']);
213                                 } 
214                         }
215                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
216                 return ($display);
217         }
219         function remove_from_parent()
220         {
221                 /* remove database entries */
222                 if($this->initialy_was_account){
223                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
224                         $this->handle->SetInfos($this->info);
225                         $this->handle->Perform("REMOVE");
226                 }
227         }
230         /* Save data to object */
231         function save_object()
232         {
233                 /* get post data */
234                 if($this->is_account){
236                         /* Get selected team chkboxes */
237                         $this->info['TeamIDis'] = array();
238                         foreach($_POST as $name => $value ){
239                                 if(preg_match("/team_/i",$name)){
240                                         if(!in_array($value,$this->info['TeamIDis'])){
241                                                 $this->info['TeamIDis'][]=$value;
242                                         }
243                                 }
244                         }
246                         /* Get location Team*/
247                         if(isset($_POST['LocationTeam'])){
248                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
249                         }
251                         /* Get template user */
252                         if(isset($_POST['TemplateUser'])){
253                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
254                         }
256                         /* get lock status */
257                         if(isset($_POST['is_locked'])){
258                                 $this->info['is_locked'] = $_POST['is_locked'];
259                         }else{
260                                 $this->info['is_locked'] = 0;
261                         }
262                 }
264                 /* change account status */
265                 if(isset($_POST['is_account'])){
266                         $this->is_account = $_POST['is_account'];
267                 }else{
268                         $this->is_account = false;//$_POST['is_account'];
269                 }
271         }
274         /* Save to LDAP */
275         function save()
276         {
277                 /* Save data */ 
278                 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
279                 $this->handle->SetInfos($this->info);
280                 $this->handle->checkInfos();
281                 if($this->initialy_was_account){
282                         $this->handle->Perform("EDIT");
283                 }else{
284                         $this->handle->Perform("ADD");
285                 }
286         }
289 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>