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 | |
---|
40 | $GLOBALS['phpgw']->template->set_var('lang_commercial_telephonenumber',lang('%1 telephone number',lang('Commercial'))); |
---|
41 | $GLOBALS['phpgw']->template->set_var('lang_birthday',lang('Birthday')); |
---|
42 | $GLOBALS['phpgw']->template->set_var('lang_ps_commercial_telephonenumber', |
---|
43 | lang('Observation') . ': ' . lang('This telephone number will apear in searches for your name, and it will be visible for all ExpressoLivre Users') . '.'); |
---|
44 | $GLOBALS['phpgw']->template->set_var('lang_mobile_telephonenumber',lang('%1 telephone number',lang('Mobile'))); |
---|
45 | $GLOBALS['phpgw']->template->set_var('lang_homephone_telephonenumber',lang('%1 telephone number',lang('Home'))); |
---|
46 | $GLOBALS['phpgw']->template->set_var('lang_change',lang('Change')); |
---|
47 | $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel')); |
---|
48 | $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/preferences/changepersonaldata.php')); |
---|
49 | |
---|
50 | /* Get telephone number from ldap or from post */ |
---|
51 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
52 | $result = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], 'uid='.$GLOBALS['phpgw_info']['user']['account_lid'], array('telephonenumber','mobile','homephone','datanascimento')); |
---|
53 | $entrie = ldap_get_entries($ldap_conn, $result); |
---|
54 | |
---|
55 | /* BEGIN ACL Check for Personal Data Fields.*/ |
---|
56 | $disabledTelephoneNumber = false; |
---|
57 | $disabledMobile = false; |
---|
58 | $disabledHomePhone = false; |
---|
59 | $disableBirthday = false; |
---|
60 | if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',1)) { |
---|
61 | $disabledTelephoneNumber = '"disabled=true"'; |
---|
62 | } |
---|
63 | if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',2)) { |
---|
64 | $disabledMobile = '"disabled=true"'; |
---|
65 | } |
---|
66 | if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',4)) { |
---|
67 | $disabledHomePhone = '"disabled=true"'; |
---|
68 | } |
---|
69 | if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',8)) { |
---|
70 | $disableBirthday = '"disabled=true"'; |
---|
71 | } |
---|
72 | /* END ACL Check for Personal Data Fields.*/ |
---|
73 | |
---|
74 | $GLOBALS['phpgw']->template->set_var('telephonenumber',($_POST['telephonenumber'] ? $_POST['telephonenumber'] : $entrie[0]['telephonenumber'][0]).$disabledTelephoneNumber); |
---|
75 | $GLOBALS['phpgw']->template->set_var('mobile',($_POST['mobile'] ? $_POST['mobile'] : $entrie[0]['mobile'][0]).$disabledMobile); |
---|
76 | $GLOBALS['phpgw']->template->set_var('homephone',($_POST['homephone'] ? $_POST['homephone'] : $entrie[0]['homephone'][0]).$disabledHomePhone); |
---|
77 | $GLOBALS['phpgw']->template->set_var('datanascimento',$_POST['datanascimento'] ? $_POST['datanascimento'] : $entrie[0]['datanascimento'][0] != '' ? $entrie[0]['datanascimento'][0] : ''); |
---|
78 | |
---|
79 | |
---|
80 | ldap_close($ldap_conn); |
---|
81 | |
---|
82 | if ($GLOBALS['phpgw_info']['server']['auth_type'] != 'ldap') |
---|
83 | { |
---|
84 | $GLOBALS['phpgw']->template->set_var('sql_message',lang('note: This feature is *exclusive* for ldap repository.')); |
---|
85 | } |
---|
86 | |
---|
87 | if ($_POST['change']) |
---|
88 | { |
---|
89 | if ($_POST['telephonenumber'] != $GLOBALS['phpgw_info']['user']['telephonenumber'] || $_POST['mobile'] != $GLOBALS['phpgw_info']['user']['mobile'] |
---|
90 | || $_POST['homephone'] != $GLOBALS['phpgw_info']['user']['homephone'] || $_POST['datanascimento'] != $GLOBALS['phpgw_info']['user']['datanascimento']) |
---|
91 | { |
---|
92 | $pattern = '/\([0-9]{2,3}\)[0-9]{4}-[0-9]{4}$/'; |
---|
93 | if ((strlen($_POST['telephonenumber']) != 0) && (!preg_match($pattern, $_POST['telephonenumber']))) |
---|
94 | { |
---|
95 | $errors[] = lang('Format of %1 telephone number is invalid.', lang("Commercial")); |
---|
96 | } |
---|
97 | if ((strlen($_POST['mobile']) != 0) && (!preg_match($pattern, $_POST['mobile']))) |
---|
98 | { |
---|
99 | $errors[] = lang('Format of %1 telephone number is invalid.', lang("Mobile")); |
---|
100 | } |
---|
101 | if ((strlen($_POST['homephone']) != 0) && (!preg_match($pattern, $_POST['homephone']))) |
---|
102 | { |
---|
103 | $errors[] = lang('Format of %1 telephone number is invalid.', lang("Home")); |
---|
104 | } |
---|
105 | |
---|
106 | if(!(checkdate(substr($_POST['datanascimento'],3,2),substr($_POST['datanascimento'],0,2),substr($_POST['datanascimento'],6,4)) == 1 |
---|
107 | || ($_POST['datanascimento'] == ''))) |
---|
108 | { |
---|
109 | $errors[] = lang('invalid date'); |
---|
110 | } |
---|
111 | if(!is_array($errors)) |
---|
112 | { |
---|
113 | // Use LDAP Replication mode, if available |
---|
114 | if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && |
---|
115 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && |
---|
116 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) |
---|
117 | { |
---|
118 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect( |
---|
119 | $GLOBALS['phpgw_info']['server']['ldap_master_host'], |
---|
120 | $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], |
---|
121 | $GLOBALS['phpgw_info']['server']['ldap_master_root_pw'] |
---|
122 | ); |
---|
123 | } |
---|
124 | else |
---|
125 | { |
---|
126 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
127 | } |
---|
128 | |
---|
129 | if(!$disabledTelephoneNumber && ($_POST['telephonenumber'] != $GLOBALS['phpgw_info']['user']['telephonenumber'])) { |
---|
130 | if (strlen($_POST['telephonenumber']) == 0) { |
---|
131 | $info['telephonenumber'] = $GLOBALS['phpgw_info']['user']['telephonenumber']; |
---|
132 | $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
133 | } |
---|
134 | elseif(strlen($GLOBALS['phpgw_info']['user']['telephonenumber']) == 0) { |
---|
135 | $info['telephonenumber'] = $_POST['telephonenumber']; |
---|
136 | $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
137 | } |
---|
138 | else { |
---|
139 | $info['telephonenumber'] = $_POST['telephonenumber']; |
---|
140 | $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
141 | } |
---|
142 | unset($info['telephonenumber']); |
---|
143 | } |
---|
144 | if (!$disabledMobile && ($_POST['mobile'] != $GLOBALS['phpgw_info']['user']['mobile'])) { |
---|
145 | if (strlen($_POST['mobile']) == 0) { |
---|
146 | $info['mobile'] = $GLOBALS['phpgw_info']['user']['mobile']; |
---|
147 | $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
148 | } |
---|
149 | elseif(strlen($GLOBALS['phpgw_info']['user']['mobile']) == 0) { |
---|
150 | $info['mobile'] = $_POST['mobile']; |
---|
151 | $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
152 | } |
---|
153 | else { |
---|
154 | $info['mobile'] = $_POST['mobile']; |
---|
155 | $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
156 | } |
---|
157 | unset($info['mobile']); |
---|
158 | } |
---|
159 | if (!$disabledHomePhone && ($_POST['homephone'] != $GLOBALS['phpgw_info']['user']['homephone'])) { |
---|
160 | if (strlen($_POST['homephone']) == 0) { |
---|
161 | $info['homephone'] = $GLOBALS['phpgw_info']['user']['homephone']; |
---|
162 | $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
163 | } |
---|
164 | elseif(strlen($GLOBALS['phpgw_info']['user']['homephone']) == 0) { |
---|
165 | $info['homephone'] = $_POST['homephone']; |
---|
166 | $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
167 | } |
---|
168 | else { |
---|
169 | $info['homephone'] = $_POST['homephone']; |
---|
170 | $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
171 | } |
---|
172 | unset($info['homephone']); |
---|
173 | } |
---|
174 | if (!$disableBirthday && ($_POST['datanascimento'] != $GLOBALS['phpgw_info']['user']['datanascimento'])) { |
---|
175 | if (strlen($_POST['datanascimento']) == 0) { |
---|
176 | $info['datanascimento'] = $GLOBALS['phpgw_info']['user']['datanascimento']; |
---|
177 | $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
178 | } |
---|
179 | elseif(strlen($GLOBALS['phpgw_info']['user']['datanascimento']) == 0) { |
---|
180 | $info['datanascimento'] = $_POST['datanascimento']; |
---|
181 | $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
182 | } |
---|
183 | else { |
---|
184 | $info['datanascimento'] = $_POST['datanascimento']; |
---|
185 | $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
186 | } |
---|
187 | unset($info['datanascimento']); |
---|
188 | } |
---|
189 | ldap_close($ldap_conn); |
---|
190 | } |
---|
191 | |
---|
192 | if(is_array($errors)) |
---|
193 | { |
---|
194 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
195 | echo parse_navbar(); |
---|
196 | $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors)); |
---|
197 | $GLOBALS['phpgw']->template->pfp('out','form'); |
---|
198 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
199 | } |
---|
200 | } |
---|
201 | $GLOBALS['phpgw']->redirect_link('/preferences/index.php','cd=18'); |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Change your Personal Data'); |
---|
206 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
207 | echo parse_navbar(); |
---|
208 | |
---|
209 | $GLOBALS['phpgw']->template->pfp('out','form'); |
---|
210 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
211 | } |
---|
212 | ?> |
---|