Code

Updated repository template
[gosa.git] / gosa-plugins / gofon / gofon / phoneaccount / main.inc
1 <?php
2 /*
3   This code is part of GOsa (https://gosa.gonicus.de)
4   Copyright (C) 2004  Cajus Pollmeier
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2 of the License, or
9   (at your option) any later version.
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
21 /* Remove locks created by this plugin
22 */
23 $lock_msg ="";
24 if ($remove_lock || isset($_POST['edit_cancel'])){
25   if(session::is_set('phoneAccount') && session::is_set('edit')){
26     del_lock($ui->dn);
27   }
28 }
30 /* Remove this plugin from session
31 */
32 if ( $cleanup ){
33   session::un_set('phoneAccount');
34   session::un_set('edit');
36 }else{
38         /* Reset requested? */
39         if (isset($_POST['edit_cancel'])){
40                 session::un_set ('edit');
41                 session::un_set ('phoneAccount');
42         }
44         /* Create phoneAccount object on demand */
45         if (!session::is_set('phoneAccount') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
46                 $phoneAccount= new phoneAccount ($config, $ui->dn);
47                 $phoneAccount->set_acl_base($ui->dn);
48                 $phoneAccount->set_acl_category("users");
49                 session::set('phoneAccount',$phoneAccount);
50         }
51         $phoneAccount = session::get('phoneAccount');
53         /* save changes back to object */
54         if (session::is_set('edit')){
55                 $phoneAccount->save_object ();
56         }
58         /* Enter edit mode? */
59         if (isset($_POST['edit']) && !session::is_set('edit')){
61                 /* Check locking */
62                 if (($username= get_lock($ui->dn)) != ""){
63                         session::set('back_plugin',$plug);
64                         session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
65                         $lock_msg =  gen_locked_message ($username, $ui->dn);
67                 }else{
69                         /* Lock the current entry */
70                         add_lock ($ui->dn, $ui->dn);
71                         session::set('edit',TRUE);
72                 }
74         }
76         /* save changes to LDAP and disable edit mode */
77         if (isset($_POST['edit_finish'])){
79                 /* Perform checks */
80                 $message= $phoneAccount->check ();
82                 /* No errors, save object */
83                 if (count ($message) == 0){
84                         $phoneAccount->save ();
86                         del_lock ($ui->dn);
87                         session::un_set ('edit');
89                         /* Write back to session */
90                         session::set('phoneAccount',$phoneAccount);
91                 } else {
92                         /* Errors found, show message */
93                         msg_dialog::displayChecks($message);
94                 }
95         }
97         /* Execute formular */
98         if($lock_msg){
99                 $display.= $lock_msg;
100         }else{
101                 $display.= $phoneAccount->execute ();
102         }
104         /* Store changes  in session */
105         if (session::is_set('edit')){
106                 session::set('phoneAccount',$phoneAccount);
107         }
109         $info= "";
110         if ($phoneAccount->is_account && empty($lock_msg)){
111                 $display.= "<p class=\"plugbottom\">";
113                 /* Are we in edit mode? */
114                 if (session::is_set('edit')){
115                         $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
116                         $display.= "&nbsp;";
117                         $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
118                         $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png')."\"> ".$ui->dn."&nbsp;";
119                 } else {
120                         $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png')."\"> ".$ui->dn."&nbsp;";
122                         if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/phoneAccount"))){
123                                 $info.= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png')."\">"._("Click the 'Edit' button below to change informations in this dialog");
124                                 $display.= "<input type=submit name=\"edit\" value=\"".msgPool::editButton()."\">\n";
125                         }
126                         $display.= "<input type=\"hidden\" name=\"ignore\">\n";
127                 }
128                 $display.= "</p>\n";
129                 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
130         }
132         /* Page header*/
133         $display= print_header(get_template_path('plugins/gofon/images/phoneAccount.png'), _("Phone settings"), $info).$display;
136 ?>