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;
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 }
122 /* Log view */
123 if($this->is_account){
124 @log::log("view","users/".get_class($this),$this->dn);
125 }
127 }
129 function execute()
130 {
131 /* Show tab dialog headers */
132 $display= "";
133 $smarty= get_smarty();
135 /* set default values */
136 $tmp = $this->plInfo();
137 foreach($tmp['plProvidedAcls'] as $acl => $desc){
138 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
139 }
141 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
142 $smarty->assign('opengwAccountACL', "");
143 }else{
144 $smarty->assign('opengwAccountACL', " disabled ");
145 }
147 /* Check database extension */
148 if(!is_callable("pg_connect")){
149 print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
150 }else
152 /* Check if config exists */
153 if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
154 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
155 }else{
157 /* Create handle */
158 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
160 /* Check if we are successfully connected to db */
161 if(!$this->handle->connected){
162 print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
163 }else{
165 /* Assign LocationTeams */
166 $tmp = array(""=>"none");
167 foreach($this->handle->validLocationTeam as $id){
168 $tmp[$id['company_id']] = $id['description'];
169 }
170 $smarty->assign("validLocationTeam",$tmp);
171 $smarty->assign("validLocationTeams",array_flip($tmp));
172 $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
174 /* Assign TemplateUsers*/
175 $tmp = array();
176 foreach($this->handle->validTemplateUser as $id){
177 $tmp[$id['company_id']] = $id['name'];
178 }
179 $smarty->assign("validTemplateUser",$tmp);
180 $smarty->assign("validTemplateUsers",array_flip($tmp));
181 $smarty->assign("TemplateUser",$this->info['template_user_id']);
183 /* Create Team membership */
184 $str = "";
185 if(($this->is_account)==""){
186 $dis = "";
187 }else{
188 $dis = " disabled ";
189 }
191 if($this->acl_is_readable("Teams")){
192 foreach($this->handle->validTeams as $id){
193 if(in_array($id['company_id'],$this->info['TeamIDis'])){
194 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
195 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
196 }else{
197 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
198 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
199 }
200 }
201 }
202 $smarty->assign("validTeams",$str);
204 /* Assign ogw checkbox */
205 if($this->is_account){
206 $smarty->assign("OGWstate","");
207 $smarty->assign("is_account", " checked ");
208 }else{
209 $smarty->assign("is_account", " ");
210 $smarty->assign("OGWstate"," disabled ");
211 }
213 /* Assign lock status */
214 if($this->info['is_locked']){
215 $smarty->assign("is_lockedCHK", " checked ");
216 }else{
217 $smarty->assign("is_lockedCHK", " ");
218 }
219 $smarty->assign("is_locked", $this->info['is_locked']);
221 }
222 }
223 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
224 return ($display);
225 }
227 function remove_from_parent()
228 {
229 /* remove database entries */
230 if($this->initialy_was_account){
231 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
232 $this->handle->SetInfos($this->info);
233 $this->handle->Perform("REMOVE");
235 @log::log("remove","users/".get_class($this),$this->dn);
236 }
237 }
240 /* Save data to object */
241 function save_object()
242 {
243 /* get post data */
244 if($this->is_account){
246 /* Get selected team chkboxes */
247 $this->info['TeamIDis'] = array();
248 if($this->acl_is_writeable("Teams")) {
249 foreach($_POST as $name => $value ){
250 if(preg_match("/team_/i",$name)){
251 if(!in_array($value,$this->info['TeamIDis'])){
252 $this->info['TeamIDis'][]=$value;
253 }
254 }
255 }
256 }
259 /* Get location Team*/
260 if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
261 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
262 }
264 /* Get template user */
265 if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
266 $this->info['template_user_id'] = $_POST['TemplateUser'];
267 }
269 /* get lock status */
270 if($this->acl_is_writeable("Locked")){
271 if(isset($_POST['is_locked'])){
272 $this->info['is_locked'] = $_POST['is_locked'];
273 }else{
274 $this->info['is_locked'] = 0;
275 }
276 }
277 }
279 /* change account status */
280 if(isset($_POST['is_account'])){
281 if($this->acl_is_createable()){
282 $this->is_account = $_POST['is_account'];
283 }
284 }else{
285 if($this->acl_is_removeable()){
286 $this->is_account = false;//$_POST['is_account'];
287 }
288 }
289 }
292 /* Save to LDAP */
293 function save()
294 {
295 /* Save data */
296 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
297 $this->handle->SetInfos($this->info);
298 $this->handle->checkInfos();
299 if($this->initialy_was_account){
300 $this->handle->Perform("EDIT");
301 @log::log("modify","users/".get_class($this),$this->dn);
302 }else{
303 $this->handle->Perform("ADD");
304 @log::log("create","users/".get_class($this),$this->dn);
305 }
306 }
309 function PrepareForCopyPaste($src){
310 // Nothing to do, because this object can't be copied ... yet
311 }
314 /* Return plugin informations for acl handling
315 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
316 function plInfo()
317 {
318 return (array(
319 "plShortName" => _("Opengroupware"),
320 "plDescription" => _("Open groupware account settings")." : <u>"._("Connectivity addon")."</u>",
321 "plSelfModify" => TRUE,
322 "plDepends" => array("user"),
323 "plPriority" => 26, // Position in tabs
324 "plSection" => array("personal" => _("My account")),
325 "plCategory" => array("users"),
326 "plOptions" => array(),
328 "plProvidedAcls" => array(
329 "LocationTeam" => _("Location team"),
330 "TemplateUser" => _("Template user"),
331 "Locked" => _("Locked"),
332 "Teams" => _("Teams"))
333 ));
334 }
335 }
336 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
337 ?>