source: branches/2.2/preferences/changepersonaldata.php @ 3299

Revision 3299, 8.2 KB checked in by niltonneto, 14 years ago (diff)

Ticket #566 - Implementada opção para editar e bloquear fone residencial (homePhone).

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]1<?php
2        /**************************************************************************\
3        * ExpressoLivre - preferences                                              *
4        * http://www.celepar.pr.gov.br                                             *
5        * Written by Joseph Engo <jengo@phpgroupware.org>                          *
6        * Modify by João Alfredo Knopik Junior <jakjr@celepar.pr.gov.br>           *
7        *                                                                                                                                                  *
8        * --------------------------------------------                             *
9        *  This program is free software; you can redistribute it and/or modify it *
10        *  under the terms of the GNU General Public License as published by the   *
11        *  Free Software Foundation; either version 2 of the License, or (at your  *
12        *  option) any later version.                                              *
13        \**************************************************************************/
14
15
16        $GLOBALS['phpgw_info']['flags'] = array(
17                'noheader'   => True,
18                'nonavbar'   => True,
19                'currentapp' => 'preferences'
20        );
21
22        include('../header.inc.php');
23
24        if($_POST['cancel'])
25        {
26                $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
27                $GLOBALS['phpgw']->common->phpgw_exit();
28        }
29
30        if(!@is_object($GLOBALS['phpgw']->js))
31        {
32                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
33        }
34        $GLOBALS['phpgw']->js->validate_file('jscode','scripts','preferences');#diretorio, arquivo.js, aplicacao
35
36        $GLOBALS['phpgw']->template->set_file(array(
37                'form' => 'changepersonaldata.tpl'
38        ));
39
[3234]40        $GLOBALS['phpgw']->template->set_var('lang_commercial_telephonenumber',lang('%1 telephone number',lang('Commercial')));
[88]41        $GLOBALS['phpgw']->template->set_var('lang_ps_commercial_telephonenumber',
[578]42        lang('Observation') . ': ' . lang('This telephone number will apear in searches for your name, and it will be visible for all ExpressoLivre Users') . '.');
[3234]43        $GLOBALS['phpgw']->template->set_var('lang_mobile_telephonenumber',lang('%1 telephone number',lang('Mobile')));
[3299]44        $GLOBALS['phpgw']->template->set_var('lang_homephone_telephonenumber',lang('%1 telephone number',lang('Home')));
[2]45        $GLOBALS['phpgw']->template->set_var('lang_change',lang('Change'));
46        $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
47        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/preferences/changepersonaldata.php'));
48
[578]49        /* Get telephone number from ldap or from post */
50        $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect();
[3299]51        $result = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], 'uid='.$GLOBALS['phpgw_info']['user']['account_lid'], array('telephonenumber','mobile','homephone'));
[578]52        $entrie = ldap_get_entries($ldap_conn, $result);
[3234]53
54        /* BEGIN ACL Check for Personal Data Fields.*/
55        $disabledTelephoneNumber = false;
56        $disabledMobile = false;
[3299]57        $disabledHomePhone = false;
[3234]58        if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',1)) {
59                $disabledTelephoneNumber = '"disabled=true"';
60        }
61        if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',2)) {
62                $disabledMobile = '"disabled=true"';
63        }
[3299]64        if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',4)) {
65                $disabledHomePhone = '"disabled=true"';
66        }
[3234]67        /* END ACL Check for Personal Data Fields.*/
68       
69        $GLOBALS['phpgw']->template->set_var('telephonenumber',($_POST['telephonenumber'] ? $_POST['telephonenumber'] : $entrie[0]['telephonenumber'][0]).$disabledTelephoneNumber);
70        $GLOBALS['phpgw']->template->set_var('mobile',($_POST['mobile'] ? $_POST['mobile'] : $entrie[0]['mobile'][0]).$disabledMobile);
[3299]71        $GLOBALS['phpgw']->template->set_var('homephone',($_POST['homephone'] ? $_POST['homephone'] : $entrie[0]['homephone'][0]).$disabledHomePhone);
72       
[3234]73
[578]74        ldap_close($ldap_conn);
75
[2]76        if ($GLOBALS['phpgw_info']['server']['auth_type'] != 'ldap')
77        {
78                $GLOBALS['phpgw']->template->set_var('sql_message',lang('note: This feature is *exclusive* for ldap repository.'));
79        }
80
81        if ($_POST['change'])
82        {
[3299]83                if ($_POST['telephonenumber'] != $GLOBALS['phpgw_info']['user']['telephonenumber'] || $_POST['mobile'] != $GLOBALS['phpgw_info']['user']['mobile']
84                 || $_POST['homephone'] != $GLOBALS['phpgw_info']['user']['homephone'])
[2]85                {
86                        $pattern = '/\([0-9]{2,3}\)[0-9]{4}-[0-9]{4}$/';
[1225]87                        if ((strlen($_POST['telephonenumber']) != 0) && (!preg_match($pattern, $_POST['telephonenumber'])))
[2]88                        {
[3234]89                                $errors[] = lang('Format of %1 telephone number is invalid.', lang("Commercial"));
[2]90                        }
[3234]91                        if ((strlen($_POST['mobile']) != 0) && (!preg_match($pattern, $_POST['mobile'])))
[2]92                        {
[3234]93                                $errors[] = lang('Format of %1 telephone number is invalid.', lang("Mobile"));
94                        }
[3299]95                        if ((strlen($_POST['homephone']) != 0) && (!preg_match($pattern, $_POST['homephone'])))
96                        {
97                                $errors[] = lang('Format of %1 telephone number is invalid.', lang("Home"));
98                        }
[3234]99                        if(!is_array($errors))
100                        {
[578]101                                // Use LDAP Replication mode, if available
[392]102                                if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
103                                         (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
104                                         (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
105                                {
106                                        $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(
107                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_host'],
108                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
109                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']
110                                                                                                   );
111                                }
112                                else
113                                {
114                                        $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect();
115                                }
116                               
[3234]117                                if(!$disabledTelephoneNumber && ($_POST['telephonenumber'] != $GLOBALS['phpgw_info']['user']['telephonenumber'])) {
[1225]118                                        if (strlen($_POST['telephonenumber']) == 0) {
119                                                $info['telephonenumber'] = $GLOBALS['phpgw_info']['user']['telephonenumber'];
120                                                $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
121                                        }
[3234]122                                        elseif(strlen($GLOBALS['phpgw_info']['user']['telephonenumber']) == 0) {
123                                                $info['telephonenumber'] = $_POST['telephonenumber'];
124                                                $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
125                                        }                                       
[1225]126                                        else {
127                                                $info['telephonenumber'] = $_POST['telephonenumber'];
128                                                $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
129                                        }
[3234]130                                        unset($info['telephonenumber']);
[2]131                                }
[3234]132                                if (!$disabledMobile && ($_POST['mobile'] != $GLOBALS['phpgw_info']['user']['mobile'])) {
133                                        if (strlen($_POST['mobile']) == 0) {
134                                                $info['mobile'] = $GLOBALS['phpgw_info']['user']['mobile'];
135                                                $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
136                                        }
137                                        elseif(strlen($GLOBALS['phpgw_info']['user']['mobile']) == 0) {
138                                                $info['mobile'] = $_POST['mobile'];
139                                                $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
140                                        }
141                                        else {
142                                                $info['mobile'] = $_POST['mobile'];
143                                                $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
144                                        }
[3299]145                                        unset($info['mobile']);
[2]146                                }
[3299]147                                if (!$disabledHomePhone && ($_POST['homephone'] != $GLOBALS['phpgw_info']['user']['homephone'])) {
148                                        if (strlen($_POST['homephone']) == 0) {
149                                                $info['homephone'] = $GLOBALS['phpgw_info']['user']['homephone'];
150                                                $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
151                                        }
152                                        elseif(strlen($GLOBALS['phpgw_info']['user']['homephone']) == 0) {
153                                                $info['homephone'] = $_POST['homephone'];
154                                                $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
155                                        }
156                                        else {
157                                                $info['homephone'] = $_POST['homephone'];
158                                                $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info);
159                                        }
160                                        unset($info['homephone']);
161                                }
[3234]162                                ldap_close($ldap_conn);
[2]163                        }
164                       
165                        if(is_array($errors))
166                        {
167                                $GLOBALS['phpgw']->common->phpgw_header();
168                                echo parse_navbar();
169                                $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors));
170                                $GLOBALS['phpgw']->template->pfp('out','form');
171                                $GLOBALS['phpgw']->common->phpgw_exit(True);
172                        }
173                }
174                $GLOBALS['phpgw']->redirect_link('/preferences/index.php','cd=18');
175        }
176        else
177        {
178                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Change your Personal Data');
179                $GLOBALS['phpgw']->common->phpgw_header();
180                echo parse_navbar();
181
182                $GLOBALS['phpgw']->template->pfp('out','form');
183                $GLOBALS['phpgw']->common->phpgw_footer();
184        }
185?>
Note: See TracBrowser for help on using the repository browser.