]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/updateTimezonePrefs.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Administration / updateTimezonePrefs.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 ?>
38 <form action='index.php' method="POST">
39 <input type='hidden' name='action' value='updateTimezonePrefs'>
40 <input type='hidden' name='module' value='Administration'>
41
42 <table>
43 <?php
44 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
45 $prompt_users = 'checked';
46 if(isset($_POST['preview']) && !isset($_POST['prompt_users'])){
47         $prompt_users = '';
48 }
49
50
51 $result = $db->query("SELECT id, user_preferences, user_name FROM users");
52 $execute = false;
53 // loop through user preferences and check for "bad" elements; rebuild preferences array and update database
54 if(isset($_POST['execute'])){
55         $execute = true;
56 }
57 $serverTimeZone = lookupTimezone(0);
58 while ($row = $db->fetchByAssoc($result)) {
59         $adjustment = 'none';
60
61         if(isset($_POST[$row['id'].'adjust'])){
62                 $adjustment = $_POST[$row['id'].'adjust'];
63         }
64         
65                 $string = "Preview";
66                 if($execute)$string = "Updating";
67         echo "<tr><td> $string timezone preferences for user <b>{$row['user_name']}</b>...</td><td>";
68                 
69         
70         $prefs = array();
71         $newprefs = array();
72         
73         $prefs = unserialize(base64_decode($row['user_preferences']));
74         $setTo = '';
75         $alreadySet = '';
76                 if(!empty($prefs)){
77                         
78                 foreach ($prefs as $key => $val) {
79                        if ($key == 'timez') {
80                                 if(empty($prefs['timezone']) && $val != ''){
81                                         $hourAdjust = $adjustment;
82                                         if($hourAdjust == 'none'){
83                                                                 $hourAdjust = 0;
84                                                         }
85                                         $selectedZone = lookupTimezone($prefs['timez'] + $hourAdjust);
86                                 
87                                 if(!empty($selectedZone)){
88                                         $newprefs['timezone'] = $selectedZone;   
89                                         $newprefs['timez']  = $val;
90                                         $setTo = $selectedZone;
91                                         if(empty($prompt_users)){
92                                                 $newprefs['ut']=1;
93                                         }else{
94                                                 $newprefs['ut']=0;
95                                         }
96                                 }else{
97                                         $newprefs['timezone'] = $serverTimeZone;   
98                                         $newprefs['timez']  = $val;
99                                         $setTo = $serverTimeZone;
100                                         if(empty($prompt_users)){
101                                                 $newprefs['ut']=1;
102                                         }else{
103                                                 $newprefs['ut']=0;
104                                         }
105                                 }
106                         }else{
107                                 $newprefs[$key] = $val;
108                                 if(!empty($prefs['timezone'])){
109                                         $alreadySet = 'Previously Set - '. $prefs['timezone'];  
110                                 }
111                         }
112                         
113                  
114                         }else{
115                                 $newprefs[$key] = $val;
116                         }
117                 }
118                         if($execute){
119                                 $newstr = mysql_real_escape_string(base64_encode(serialize($newprefs)));
120                                 $db->query("UPDATE users SET user_preferences = '{$newstr}' WHERE id = '{$row['id']}'");
121                         }
122                 }
123                 if(!empty($setTo)){
124                         echo $setTo;
125                 }else{
126                         if(!empty($alreadySet)){
127                                 echo $alreadySet;
128                         }else{
129                                 echo $serverTimeZone;
130                                 $prefs['timezone'] = $serverTimeZone;
131                         }
132                 }
133         echo "</td><td>";
134         if(!empty($setTo)){
135                 echo "Adjust: ";
136         if($execute){
137                         if(isset($_POST[$row['id'].'adjust'])){
138                                 echo  $adjustment;
139                         }
140                 }else{
141                         echo "<select name='{$row['id']}adjust'>";
142                         
143                         echo get_select_options_with_id(array('-1'=>'-1', 'none'=>'0', '1'=>'+1'), $adjustment.'');
144                         echo '</select>';
145
146                 }
147                 echo ' hour';
148         }
149                 echo ' </td><td>';
150         echo "</tr>";
151
152                 $the_old_prefs[] = $prefs;
153                 $the_new_prefs[] = $newprefs;
154
155         unset($prefs);
156         unset($newprefs);
157         unset($newstr);
158 }
159
160 echo "</table>";
161
162 if($execute){
163         echo "<br>All timezone preferences updated!<br><br>";
164         
165 }else{
166         echo "Prompt users on login to confirm:<input type='checkbox' name='prompt_users' value='1' $prompt_users><br>";
167         echo "<input class='button' type='submit' name='execute' value='Execute'>&nbsp; <input class='button' type='submit' name='preview' value='Preview'>";
168         
169 }
170 echo "&nbsp;<input class='button' type='button' name='Done' value='Done' onclick='document.location.href=\"index.php?action=DstFix&module=Administration\"'>";
171 ?>
172 </form>