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