1 <?php
3 class opengwAccount extends plugin
4 {
5 /* Definitions */
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",
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 );
29 var $serverCon = false;
30 var $handle = NULL;
31 var $is_account = false;
32 var $initialy_was_account = false;
33 var $OGWPassword = "";
34 var $ReadOnly = false;
35 var $view_logged = FALSE;
36 var $uid = "";
38 function opengwAccount ($config, $dn= NULL)
39 {
40 plugin::plugin ($config, $dn);
42 /* Setting uid to default */
43 if(isset($this->attrs['uid'][0])){
44 $this->uid = $this->attrs['uid'][0];
45 }
47 $this->info=array();
49 /* is no account and was no account */
50 $this->initialy_was_account = false;
51 $this->is_account = false;
53 /* check if datebase funktions are available, and if database configurations are available */
54 if(is_callable("pg_connect")){
56 /* Get configurations */
57 if(search_config($this->config->data,"opengwAccount","USERNAME")){
58 $atr = array();
59 $atr['LOGIN'] = search_config($this->config->data,"opengwAccount","USERNAME");
60 $atr['PASSWORD']= search_config($this->config->data,"opengwAccount","PASSWORD");
61 $atr['SERVER'] = search_config($this->config->data,"opengwAccount","DATAHOST");
62 $atr['DB'] = search_config($this->config->data,"opengwAccount","DATABASE");
63 $this->serverCon = $atr;
64 }else{
65 $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
66 }
67 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
69 /* Check if current configuration allows database connection */
70 if($this->handle->connected){
72 /* Set login name, to check if this is_account */
73 if(isset($this->attrs['uid'][0])){
74 $this->handle->info['login'] = $this->attrs['uid'][0];
75 }else{
76 $this->handle->info['login'] = "";
77 }
79 /* If this is account get data from database first */
80 if($this->handle->CheckExistence()){
81 $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
83 /* This is an account */
84 $this->initialy_was_account = true;
85 $this->is_account= true;
86 }else{
87 /* this is no account */
88 $this->initialy_was_account = false;
89 $this->is_account= false;
91 /* Selectable in GOsa */
92 $this->info['template_user_id'] = 0;
93 $this->info['is_locked'] = 0;
94 $this->info['LocationTeamID'] = 0;
95 $this->info['TeamIDis'] = array();
96 }
98 /* Set settings from ldap */
99 foreach($this->attrsToUse as $name=>$attr){
100 if(isset($this->attrs[$attr][0])){
101 $this->info[$name] = $this->attrs[$attr][0];
102 }else{
103 $this->info[$name] = false;
104 }
105 }
107 /* Description is displayed as 'Nickname' */
108 $this->info['description'] = $this->info['login'];
110 if($this->info['sex'] == "F"){
111 $this->info['sex'] = "female";
112 }else{
113 $this->info['sex'] = "male";
114 }
116 }
118 /* Transmit data back to ogw handle */
119 $this->handle->SetInfos($this->info);
120 }
121 }
123 function execute()
124 {
125 /* Log view */
126 if($this->is_account && !$this->view_logged){
127 $this->view_logged = TRUE;
128 new log("view","users/".get_class($this),$this->dn);
129 }
131 /* Show tab dialog headers */
132 $display= "";
133 $smarty= get_smarty();
135 $smarty->assign("validTeams","");
136 $smarty->assign("is_account", " ");
137 $smarty->assign("OGWstate"," disabled ");
138 $smarty->assign("validLocationTeam",array(" "));
139 $smarty->assign("validLocationTeams",array(" "));
140 $smarty->assign("LocationTeam",0);
141 $smarty->assign("validTemplateUser",array(" "));
142 $smarty->assign("validTemplateUsers",array(" "));
143 $smarty->assign("TemplateUser",0);
144 $smarty->assign("is_lockedCHK", " ");
145 $smarty->assign("is_locked", " ");
147 /* set default values */
148 $tmp = $this->plInfo();
149 foreach($tmp['plProvidedAcls'] as $acl => $desc){
150 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
151 }
153 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
154 $smarty->assign('opengwAccountACL', "");
155 }else{
156 $smarty->assign('opengwAccountACL', " disabled ");
157 }
159 /* Check database extension */
160 if(!is_callable("pg_connect")){
161 print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
162 }else
164 /* Check if config exists */
165 if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
166 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
167 }else{
169 /* Create handle */
170 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
172 /* Check if we are successfully connected to db */
173 if(!$this->handle->connected){
174 print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
175 }else{
177 /* Assign LocationTeams */
178 $tmp = array(""=>"none");
179 foreach($this->handle->validLocationTeam as $id){
180 $tmp[$id['company_id']] = $id['description'];
181 }
182 $smarty->assign("validLocationTeam",$tmp);
183 $smarty->assign("validLocationTeams",array_flip($tmp));
184 $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
186 /* Assign TemplateUsers*/
187 $tmp = array();
188 foreach($this->handle->validTemplateUser as $id){
189 $tmp[$id['company_id']] = $id['name'];
190 }
191 $smarty->assign("validTemplateUser",$tmp);
192 $smarty->assign("validTemplateUsers",array_flip($tmp));
193 $smarty->assign("TemplateUser",$this->info['template_user_id']);
195 /* Create Team membership */
196 $str = "";
197 if(($this->is_account)==""){
198 $dis = "";
199 }else{
200 $dis = " disabled ";
201 }
203 if($this->acl_is_readable("Teams")){
204 foreach($this->handle->validTeams as $id){
205 if(in_array($id['company_id'],$this->info['TeamIDis'])){
206 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
207 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
208 }else{
209 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
210 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
211 }
212 }
213 }
214 $smarty->assign("validTeams",$str);
216 /* Assign ogw checkbox */
217 if($this->is_account){
218 $smarty->assign("OGWstate","");
219 $smarty->assign("is_account", " checked ");
220 }else{
221 $smarty->assign("is_account", " ");
222 $smarty->assign("OGWstate"," disabled ");
223 }
225 /* Assign lock status */
226 if($this->info['is_locked']){
227 $smarty->assign("is_lockedCHK", " checked ");
228 }else{
229 $smarty->assign("is_lockedCHK", " ");
230 }
231 $smarty->assign("is_locked", $this->info['is_locked']);
233 }
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");
247 new log("remove","users/".get_class($this),$this->dn);
248 }
249 }
252 /* Save data to object */
253 function save_object()
254 {
255 /* get post data */
256 if($this->is_account){
258 /* Get selected team chkboxes */
259 $this->info['TeamIDis'] = array();
260 if($this->acl_is_writeable("Teams")) {
261 foreach($_POST as $name => $value ){
262 if(preg_match("/team_/i",$name)){
263 if(!in_array($value,$this->info['TeamIDis'])){
264 $this->info['TeamIDis'][]=$value;
265 }
266 }
267 }
268 }
271 /* Get location Team*/
272 if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
273 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
274 }
276 /* Get template user */
277 if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
278 $this->info['template_user_id'] = $_POST['TemplateUser'];
279 }
281 /* get lock status */
282 if($this->acl_is_writeable("Locked")){
283 if(isset($_POST['is_locked'])){
284 $this->info['is_locked'] = $_POST['is_locked'];
285 }else{
286 $this->info['is_locked'] = 0;
287 }
288 }
289 }
291 /* change account status */
292 if(isset($_POST['is_account'])){
293 if($this->acl_is_createable()){
294 $this->is_account = $_POST['is_account'];
295 }
296 }else{
297 if($this->acl_is_removeable()){
298 $this->is_account = false;//$_POST['is_account'];
299 }
300 }
301 }
304 /* Save to LDAP */
305 function save()
306 {
307 /* Save data */
308 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
309 $this->handle->SetInfos($this->info);
310 $this->handle->checkInfos();
311 if($this->initialy_was_account){
312 $this->handle->Perform("EDIT");
313 new log("modify","users/".get_class($this),$this->dn);
314 }else{
315 $this->handle->Perform("ADD");
316 new log("create","users/".get_class($this),$this->dn);
317 }
318 }
321 function PrepareForCopyPaste($src){
322 // Nothing to do, because this object can't be copied ... yet
323 }
326 /* Return plugin informations for acl handling
327 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
328 function plInfo()
329 {
330 return (array(
331 "plShortName" => _("Opengroupware"),
332 "plDescription" => _("Open groupware account settings")." : <u>"._("Connectivity addon")."</u>",
333 "plSelfModify" => TRUE,
334 "plDepends" => array("user"),
335 "plPriority" => 26, // Position in tabs
336 "plSection" => array("personal" => _("My account")),
337 "plCategory" => array("users"),
338 "plOptions" => array(),
340 "plProvidedAcls" => array(
341 "LocationTeam" => _("Location team"),
342 "TemplateUser" => _("Template user"),
343 "Locked" => _("Locked"),
344 "Teams" => _("Teams"))
345 ));
346 }
347 }
348 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
349 ?>