[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'))); |
---|
[2] | 44 | $GLOBALS['phpgw']->template->set_var('lang_change',lang('Change')); |
---|
| 45 | $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel')); |
---|
| 46 | $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/preferences/changepersonaldata.php')); |
---|
| 47 | |
---|
[578] | 48 | /* Get telephone number from ldap or from post */ |
---|
| 49 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
[3234] | 50 | $result = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], 'uid='.$GLOBALS['phpgw_info']['user']['account_lid'], array('telephonenumber','mobile')); |
---|
[578] | 51 | $entrie = ldap_get_entries($ldap_conn, $result); |
---|
[3234] | 52 | |
---|
| 53 | /* BEGIN ACL Check for Personal Data Fields.*/ |
---|
| 54 | $disabledTelephoneNumber = false; |
---|
| 55 | $disabledMobile = false; |
---|
| 56 | |
---|
| 57 | if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',1)) { |
---|
| 58 | $disabledTelephoneNumber = '"disabled=true"'; |
---|
| 59 | } |
---|
| 60 | if ($GLOBALS['phpgw']->acl->check('blockpersonaldata',2)) { |
---|
| 61 | $disabledMobile = '"disabled=true"'; |
---|
| 62 | } |
---|
| 63 | /* END ACL Check for Personal Data Fields.*/ |
---|
| 64 | |
---|
| 65 | $GLOBALS['phpgw']->template->set_var('telephonenumber',($_POST['telephonenumber'] ? $_POST['telephonenumber'] : $entrie[0]['telephonenumber'][0]).$disabledTelephoneNumber); |
---|
| 66 | $GLOBALS['phpgw']->template->set_var('mobile',($_POST['mobile'] ? $_POST['mobile'] : $entrie[0]['mobile'][0]).$disabledMobile); |
---|
| 67 | |
---|
[578] | 68 | ldap_close($ldap_conn); |
---|
| 69 | |
---|
[2] | 70 | if ($GLOBALS['phpgw_info']['server']['auth_type'] != 'ldap') |
---|
| 71 | { |
---|
| 72 | $GLOBALS['phpgw']->template->set_var('sql_message',lang('note: This feature is *exclusive* for ldap repository.')); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | if ($_POST['change']) |
---|
| 76 | { |
---|
[3234] | 77 | if ($_POST['telephonenumber'] != $GLOBALS['phpgw_info']['user']['telephonenumber'] || $_POST['mobile'] != $GLOBALS['phpgw_info']['user']['mobile']) |
---|
[2] | 78 | { |
---|
| 79 | $pattern = '/\([0-9]{2,3}\)[0-9]{4}-[0-9]{4}$/'; |
---|
[1225] | 80 | if ((strlen($_POST['telephonenumber']) != 0) && (!preg_match($pattern, $_POST['telephonenumber']))) |
---|
[2] | 81 | { |
---|
[3234] | 82 | $errors[] = lang('Format of %1 telephone number is invalid.', lang("Commercial")); |
---|
[2] | 83 | } |
---|
[3234] | 84 | if ((strlen($_POST['mobile']) != 0) && (!preg_match($pattern, $_POST['mobile']))) |
---|
[2] | 85 | { |
---|
[3234] | 86 | $errors[] = lang('Format of %1 telephone number is invalid.', lang("Mobile")); |
---|
| 87 | } |
---|
| 88 | if(!is_array($errors)) |
---|
| 89 | { |
---|
[578] | 90 | // Use LDAP Replication mode, if available |
---|
[392] | 91 | if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && |
---|
| 92 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && |
---|
| 93 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) |
---|
| 94 | { |
---|
| 95 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect( |
---|
| 96 | $GLOBALS['phpgw_info']['server']['ldap_master_host'], |
---|
| 97 | $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], |
---|
| 98 | $GLOBALS['phpgw_info']['server']['ldap_master_root_pw'] |
---|
| 99 | ); |
---|
| 100 | } |
---|
| 101 | else |
---|
| 102 | { |
---|
| 103 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 104 | } |
---|
| 105 | |
---|
[3234] | 106 | if(!$disabledTelephoneNumber && ($_POST['telephonenumber'] != $GLOBALS['phpgw_info']['user']['telephonenumber'])) { |
---|
[1225] | 107 | if (strlen($_POST['telephonenumber']) == 0) { |
---|
| 108 | $info['telephonenumber'] = $GLOBALS['phpgw_info']['user']['telephonenumber']; |
---|
| 109 | $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
| 110 | } |
---|
[3234] | 111 | elseif(strlen($GLOBALS['phpgw_info']['user']['telephonenumber']) == 0) { |
---|
| 112 | $info['telephonenumber'] = $_POST['telephonenumber']; |
---|
| 113 | $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
| 114 | } |
---|
[1225] | 115 | else { |
---|
| 116 | $info['telephonenumber'] = $_POST['telephonenumber']; |
---|
| 117 | $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
| 118 | } |
---|
[3234] | 119 | unset($info['telephonenumber']); |
---|
[2] | 120 | } |
---|
[3234] | 121 | if (!$disabledMobile && ($_POST['mobile'] != $GLOBALS['phpgw_info']['user']['mobile'])) { |
---|
| 122 | if (strlen($_POST['mobile']) == 0) { |
---|
| 123 | $info['mobile'] = $GLOBALS['phpgw_info']['user']['mobile']; |
---|
| 124 | $result = @ldap_mod_del($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
| 125 | } |
---|
| 126 | elseif(strlen($GLOBALS['phpgw_info']['user']['mobile']) == 0) { |
---|
| 127 | $info['mobile'] = $_POST['mobile']; |
---|
| 128 | $result = @ldap_mod_add($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
| 129 | } |
---|
| 130 | else { |
---|
| 131 | $info['mobile'] = $_POST['mobile']; |
---|
| 132 | $result = @ldap_mod_replace($ldap_conn, $GLOBALS['phpgw_info']['user']['account_dn'], $info); |
---|
| 133 | } |
---|
[2] | 134 | } |
---|
[3234] | 135 | ldap_close($ldap_conn); |
---|
[2] | 136 | } |
---|
| 137 | |
---|
| 138 | if(is_array($errors)) |
---|
| 139 | { |
---|
| 140 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 141 | echo parse_navbar(); |
---|
| 142 | $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors)); |
---|
| 143 | $GLOBALS['phpgw']->template->pfp('out','form'); |
---|
| 144 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | $GLOBALS['phpgw']->redirect_link('/preferences/index.php','cd=18'); |
---|
| 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
| 151 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Change your Personal Data'); |
---|
| 152 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 153 | echo parse_navbar(); |
---|
| 154 | |
---|
| 155 | $GLOBALS['phpgw']->template->pfp('out','form'); |
---|
| 156 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
| 157 | } |
---|
| 158 | ?> |
---|