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 function opengwAccount ($config, $dn= NULL)
37 {
38 plugin::plugin ($config, $dn);
40 $this->info=array();
42 /* is no account and was no account */
43 $this->initialy_was_account = false;
44 $this->is_account = false;
46 /* check if datebase funktions are available, and if database configurations are available */
47 if(is_callable("pg_connect")){
49 /* Get configurations */
50 if(search_config($this->config->data,"opengwAccount","USERNAME")){
51 $atr = array();
52 $atr['LOGIN'] = search_config($this->config->data,"opengwAccount","USERNAME");
53 $atr['PASSWORD']= search_config($this->config->data,"opengwAccount","PASSWORD");
54 $atr['SERVER'] = search_config($this->config->data,"opengwAccount","DATAHOST");
55 $atr['DB'] = search_config($this->config->data,"opengwAccount","DATABASE");
56 $this->serverCon = $atr;
57 }else{
58 $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
59 }
60 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
62 /* Check if current configuration allows database connection */
63 if($this->handle->connected){
65 /* Set login name, to check if this is_account */
66 if(isset($this->attrs['uid'][0])){
67 $this->handle->info['login'] = $this->attrs['uid'][0];
68 }else{
69 $this->handle->info['login'] = "";
70 }
72 /* If this is account get data from database first */
73 if($this->handle->CheckExistence()){
74 $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
76 /* This is an account */
77 $this->initialy_was_account = true;
78 $this->is_account= true;
79 }else{
80 /* this is no account */
81 $this->initialy_was_account = false;
82 $this->is_account= false;
84 /* Selectable in GOsa */
85 $this->info['template_user_id'] = 0;
86 $this->info['is_locked'] = 0;
87 $this->info['LocationTeamID'] = 0;
88 $this->info['TeamIDis'] = array();
89 }
91 /* Set settings from ldap */
92 foreach($this->attrsToUse as $name=>$attr){
93 if(isset($this->attrs[$attr][0])){
94 $this->info[$name] = $this->attrs[$attr][0];
95 }else{
96 $this->info[$name] = false;
97 }
98 }
100 /* Description is displayed as 'Nickname' */
101 $this->info['description'] = $this->info['login'];
103 if($this->info['sex'] == "F"){
104 $this->info['sex'] = "female";
105 }else{
106 $this->info['sex'] = "male";
107 }
109 }
111 /* Transmit data back to ogw handle */
112 $this->handle->SetInfos($this->info);
113 }
114 }
116 function execute()
117 {
118 /* Show tab dialog headers */
119 $display= "";
120 $smarty= get_smarty();
121 print_red(_("New ACLs are not implemeneted yet."));
123 /* set default values */
124 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
125 $smarty->assign($ar,array());
126 }
127 $smarty->assign("OGWstate"," disabled ");
128 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account"/*,"OGWPassword"*/) as $ar){
129 $smarty->assign($ar,"");
130 $smarty->assign($ar."CHK","");
131 $smarty->assign($ar."ACL"," disabled ");
132 }
134 /* Check database extension */
135 if(!is_callable("pg_connect")){
136 print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
137 }else
139 /* Check if config exists */
140 if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
141 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
142 }else{
144 /* Create handle */
145 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
147 /* Check if we are successfully connected to db */
148 if(!$this->handle->connected){
149 print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
150 }else{
152 /* Show main page */
153 $smarty->assign("OGWstate"," disabled ");
154 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount"/*,"OGWPassword"*/) as $ar){
155 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
156 }
158 /* Assign LocationTeams */
159 $tmp = array(""=>"none");
160 foreach($this->handle->validLocationTeam as $id){
161 $tmp[$id['company_id']] = $id['description'];
162 }
163 $smarty->assign("validLocationTeam",$tmp);
164 $smarty->assign("validLocationTeams",array_flip($tmp));
165 $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
167 /* Assign TemplateUsers*/
168 $tmp = array();
169 foreach($this->handle->validTemplateUser as $id){
170 $tmp[$id['company_id']] = $id['name'];
171 }
172 $smarty->assign("validTemplateUser",$tmp);
173 $smarty->assign("validTemplateUsers",array_flip($tmp));
174 $smarty->assign("TemplateUser",$this->info['template_user_id']);
176 /* Create Team membership */
177 $str = "";
178 if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
179 $dis = "";
180 }else{
181 $dis = " disabled ";
182 }
184 foreach($this->handle->validTeams as $id){
185 if(in_array($id['company_id'],$this->info['TeamIDis'])){
186 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
187 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
188 }else{
189 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
190 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
191 }
192 }
193 $smarty->assign("validTeams",$str);
195 /* Assign ogw checkbox */
196 if($this->is_account){
197 $smarty->assign("OGWstate","");
198 $smarty->assign("is_account", " checked ");
199 }else{
200 $smarty->assign("is_account", " ");
201 $smarty->assign("OGWstate"," disabled ");
202 }
204 /* Assign acls */
205 foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
206 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
207 }
209 /* Assign lock status */
210 if($this->info['is_locked']){
211 $smarty->assign("is_lockedCHK", " checked ");
212 }else{
213 $smarty->assign("is_lockedCHK", " ");
214 }
215 $smarty->assign("is_locked", $this->info['is_locked']);
217 }
218 }
219 /*
220 if($this->SetPassword == false){
221 if($_SESSION['js'] == 1){
222 $smarty->assign("OGWPasswordACL"," disabled ");
223 }else{
224 $smarty->assign("OGWPasswordACL","");
225 }
226 $smarty->assign("OGWPassword","");
227 $smarty->assign("OGWPasswordCHK"," ");
228 }else{
229 $smarty->assign("OGWPasswordACL","");
230 $smarty->assign("OGWPassword",$this->OGWPassword);
231 $smarty->assign("OGWPasswordCHK"," checked ");
232 }
233 */
234 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
235 return ($display);
236 }
238 function remove_from_parent()
239 {
240 /* remove database entries */
241 if($this->initialy_was_account){
242 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
243 $this->handle->SetInfos($this->info);
244 $this->handle->Perform("REMOVE");
245 }
246 }
249 /* Save data to object */
250 function save_object()
251 {
252 /* get post data */
253 if($this->is_account){
255 /*
256 if(isset($_POST['SetPassword'])){
257 $this->SetPassword =true;
258 }else{
259 $this->SetPassword = false;
260 }
262 if((isset($_POST['OGWPassword']))&&($this->SetPassword)){
263 $this->OGWPassword = $_POST['OGWPassword'];
264 $pwd = new passwordMethodCrypt($this->config);
266 $this->info['password'] = preg_replace("/^{crypt}/","",$pwd->generate_hash($_POST['OGWPassword']));
267 }else{
268 if(isset($this->info['password'])){
269 unset($this->info['password']);
270 }
271 }
272 */
274 /* Get selected team chkboxes */
275 $this->info['TeamIDis'] = array();
276 foreach($_POST as $name => $value ){
277 if(preg_match("/team_/i",$name)){
278 if(!in_array($value,$this->info['TeamIDis'])){
279 $this->info['TeamIDis'][]=$value;
280 }
281 }
282 }
284 /* Get location Team*/
285 if(isset($_POST['LocationTeam'])){
286 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
287 }
289 /* Get template user */
290 if(isset($_POST['TemplateUser'])){
291 $this->info['template_user_id'] = $_POST['TemplateUser'];
292 }
294 /* get lock status */
295 if(isset($_POST['is_locked'])){
296 $this->info['is_locked'] = $_POST['is_locked'];
297 }else{
298 $this->info['is_locked'] = 0;
299 }
300 }
302 /* change account status */
303 if(isset($_POST['is_account'])){
304 $this->is_account = $_POST['is_account'];
305 }else{
306 $this->is_account = false;//$_POST['is_account'];
307 }
309 }
312 /* Save to LDAP */
313 function save()
314 {
315 /* Save data */
316 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
317 $this->handle->SetInfos($this->info);
318 $this->handle->checkInfos();
319 if($this->initialy_was_account){
320 $this->handle->Perform("EDIT");
321 }else{
322 $this->handle->Perform("ADD");
323 }
324 }
327 function PrepareForCopyPaste($src){
328 // Nothing to do, because this object can't be copied ... yet
329 }
332 /* Return plugin informations for acl handling
333 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
334 function plInfo()
335 {
336 return (array(
337 "plShortName" => _("Opengroupware"),
338 "plDescription" => _("Open groupware account settings"),
339 "plSelfModify" => TRUE,
340 "plDepends" => array("user"),
341 "plPriority" => 3, // Position in tabs
342 "plSection" => "personal", // This belongs to personal
343 "plCategory" => array("users"),
344 "plOptions" => array(),
346 "plProvidedAcls" => array(
347 "opengwAccount" => "!!! FIXME "._("Open groupware account"))
348 ));
349 }
350 }
351 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
352 ?>