3
class opengwAccount extends plugin
6
var $plHeadline = "Opengroupware account";
7
var $plDescription = "This does something";
9
/* attribute list for save action */
10
var $attributes = array();
11
var $objectclasses = array();
13
var $SetPassword = false;
15
/* Attribute mapping opengroupware->ldap */
16
var $attrsToUse = array( "salutation" =>"vocation",
18
"firstname" =>"givenName",
20
"degree" =>"academicTitle",
21
"birthday" =>"dateOfBirth",
25
"value_string"=>"mail",
26
"number" =>"telephoneNumber"
29
var $serverCon = false;
31
var $is_account = false;
32
var $initialy_was_account = false;
33
var $OGWPassword = "";
36
function opengwAccount ($config, $dn= NULL, $parent= NULL)
38
plugin::plugin ($config, $dn, $parent);
40
/* Setting uid to default */
41
if(isset($this->attrs['uid'][0])){
42
$this->uid = $this->attrs['uid'][0];
47
/* is no account and was no account */
48
$this->initialy_was_account = false;
49
$this->is_account = false;
51
/* check if datebase funktions are available, and if database configurations are available */
52
if(is_callable("pg_connect")){
54
/* Get configurations */
55
if(search_config($this->config->data,"opengwAccount","USERNAME")){
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;
63
$this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
65
$this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
67
/* Check if current configuration allows database connection */
68
if($this->handle->connected){
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];
74
$this->handle->info['login'] = "";
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]);
81
/* This is an account */
82
$this->initialy_was_account = true;
83
$this->is_account= true;
85
/* this is no account */
86
$this->initialy_was_account = false;
87
$this->is_account= false;
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();
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];
101
$this->info[$name] = false;
105
/* Description is displayed as 'Nickname' */
106
$this->info['description'] = $this->info['login'];
108
if($this->info['sex'] == "F"){
109
$this->info['sex'] = "female";
111
$this->info['sex'] = "male";
116
/* Transmit data back to ogw handle */
117
$this->handle->SetInfos($this->info);
123
/* Show tab dialog headers */
125
$smarty= get_smarty();
127
/* set default values */
128
foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
129
$smarty->assign($ar,array());
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 ");
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", "");
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."));
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."));
157
$this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
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."));
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));
170
/* Assign LocationTeams */
171
$tmp = array(""=>"none");
172
foreach($this->handle->validLocationTeam as $id){
173
$tmp[$id['company_id']] = $id['description'];
175
$smarty->assign("validLocationTeam",$tmp);
176
$smarty->assign("validLocationTeams",array_flip($tmp));
177
$smarty->assign("LocationTeam",$this->info['LocationTeamID']);
179
/* Assign TemplateUsers*/
181
foreach($this->handle->validTemplateUser as $id){
182
$tmp[$id['company_id']] = $id['name'];
184
$smarty->assign("validTemplateUser",$tmp);
185
$smarty->assign("validTemplateUsers",array_flip($tmp));
186
$smarty->assign("TemplateUser",$this->info['template_user_id']);
188
/* Create Team membership */
190
if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
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>";
201
$str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
202
name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
205
$smarty->assign("validTeams",$str);
207
/* Assign ogw checkbox */
208
if($this->is_account){
209
$smarty->assign("OGWstate","");
210
$smarty->assign("is_account", " checked ");
212
$smarty->assign("is_account", " ");
213
$smarty->assign("OGWstate"," disabled ");
217
foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
218
$smarty->assign($atr."ACL",chkacl($this->acl,$atr));
221
/* Assign lock status */
222
if($this->info['is_locked']){
223
$smarty->assign("is_lockedCHK", " checked ");
225
$smarty->assign("is_lockedCHK", " ");
227
$smarty->assign("is_locked", $this->info['is_locked']);
232
if($this->SetPassword == false){
233
if($_SESSION['js'] == 1){
234
$smarty->assign("OGWPasswordACL"," disabled ");
236
$smarty->assign("OGWPasswordACL","");
238
$smarty->assign("OGWPassword","");
239
$smarty->assign("OGWPasswordCHK"," ");
241
$smarty->assign("OGWPasswordACL","");
242
$smarty->assign("OGWPassword",$this->OGWPassword);
243
$smarty->assign("OGWPasswordCHK"," checked ");
246
$display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
250
function remove_from_parent()
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");
261
/* Save data to object */
262
function save_object()
265
if($this->is_account){
268
if(isset($_POST['SetPassword'])){
269
$this->SetPassword =true;
271
$this->SetPassword = false;
274
if((isset($_POST['OGWPassword']))&&($this->SetPassword)){
275
$this->OGWPassword = $_POST['OGWPassword'];
276
$pwd = new passwordMethodCrypt($this->config);
278
$this->info['password'] = preg_replace("/^{crypt}/","",$pwd->generate_hash($_POST['OGWPassword']));
280
if(isset($this->info['password'])){
281
unset($this->info['password']);
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;
296
/* Get location Team*/
297
if(isset($_POST['LocationTeam'])){
298
$this->info['LocationTeamID'] = $_POST['LocationTeam'];
301
/* Get template user */
302
if(isset($_POST['TemplateUser'])){
303
$this->info['template_user_id'] = $_POST['TemplateUser'];
306
/* get lock status */
307
if(isset($_POST['is_locked'])){
308
$this->info['is_locked'] = $_POST['is_locked'];
310
$this->info['is_locked'] = 0;
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;
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");
333
$this->handle->Perform("ADD");
338
function PrepareForCopyPaste($src){
339
// Nothing to do, because this object can't be copied ... yet
343
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: