~ubuntu-branches/ubuntu/vivid/gosa/vivid

« back to all changes in this revision

Viewing changes to plugins/personal/connectivity/class_opengwAccount.inc

Tags: 2.7.1-1
* New upstream release
* Updated packaging to not include smarty (Closes: #620489)
* Fixed case of POSIX (Closes: #620486)

Show diffs side-by-side

added added

removed removed

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