]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Schedulers/EditView.php
Release 6.1.5
[Github/sugarcrm.git] / modules / Schedulers / EditView.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  
41  ********************************************************************************/
42 global $current_user;
43 if(!is_admin($current_user)) sugar_die("Unauthorized access to administration.");
44
45 $_REQUEST['edit']='true';
46
47
48 $header_text = '';
49 global $mod_strings;
50 global $app_list_strings;
51 global $app_strings;
52 global $current_user;
53 global $timedate;
54
55 $email = new Email();
56
57 /* Start standard EditView setup logic */
58 $mod_strings = return_module_language($current_language, 'Schedulers');
59 $focus = new Scheduler();
60 $focus->checkCurl();
61 if(isset($_REQUEST['record'])) {
62         $GLOBALS['log']->debug("In Scheduler edit view, about to retrieve record: ".$_REQUEST['record']);
63         $result = $focus->retrieve($_REQUEST['record']);
64     if($result == null)
65     {
66         sugar_die($app_strings['ERROR_NO_RECORD']);
67     }
68 }
69 if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
70         $GLOBALS['log']->debug("isDuplicate found - duplicating record of id: ".$focus->id);
71         $focus->id = "";
72 }
73
74
75
76 $params = array();
77 $params[] = "<a href='index.php?module=Schedulers&action=index'>{$mod_strings['LBL_MODULE_TITLE']}</a>";
78 if(empty($focus->id)){
79         $params[] = $GLOBALS['app_strings']['LBL_CREATE_BUTTON_LABEL'];
80 }else{
81         $params[] = "<a href='index.php?module=Schedulers&action=DetailView&record={$focus->id}'>{$focus->name}</a>";
82         $params[] = $GLOBALS['app_strings']['LBL_EDIT_BUTTON_LABEL'];
83 }
84 echo getClassicModuleTitle("Schedulers", $params, true);
85
86 $GLOBALS['log']->info("Scheduler Edit View");
87 /* End standard EditView setup logic */
88
89 // javascript calls
90
91 $javascript = new javascript();
92 $javascript->setSugarBean($focus);
93 $javascript->setFormName('EditView');
94 $javascript->addAllFields('');
95 $javascript->addFieldGeneric('mins', 'alpha', 'Mins', true, $prefix='');
96 $javascript->addFieldGeneric('hours', 'alpha', 'Hours', true, $prefix='');
97 $javascript->addFieldGeneric('day_of_month', 'alpha', 'Days of Month', true, $prefix='');
98 $javascript->addFieldGeneric('months', 'alpha', 'Months', true, $prefix='');
99 $javascript->addFieldGeneric('day_of_week', 'alpha', 'Days of Week', true, $prefix='');
100 $javascript->addFieldGeneric('date_start', 'date', 'Start Date', true, $prefix='');
101 //$javascript->addFieldDateBeforeAllowBlank('date_start', 'date', 'Date End', 'false', $prefix='', 'date_end', 'true'); // cn: disabled because it does not handle user-pref date format
102 $javascript->addToValidateBinaryDependency('time_hour_from', 'alpha', 'Active From (hr) must be set with Active To (hr) ', 'false', $prefix='', 'time_hour_to');
103 $javascript->addToValidateBinaryDependency('time_minute_from', 'alpha', 'Active From (min) must be set with Active To (min) ', 'false', $prefix='', 'time_minute_to');
104 //($field, $type,$displayName, $required, $prefix='',$compareTo)
105
106 // split the date/time of start/end
107 $dtStart = $focus->date_time_start;
108 $dtEnd = $focus->date_time_end;
109 if(!empty($dtStart)) {
110         $exStart = explode(" ",$dtStart);
111         $date_start = $exStart[0];
112         $time_start = $exStart[1];
113 } else {
114         $prefDate = $current_user->getUserDateTimePreferences();
115         $date_start = date($prefDate['date'], strtotime('2005-01-01'));
116         $time_start = '';
117 }
118
119 if(!empty($dtEnd) && $dtEnd != '2020-12-31 23:59') {
120         $exEnd = explode(" ",$dtEnd);
121         $date_end = $exEnd[0];
122         $time_end = $exEnd[1];
123 } else {
124         $date_end = '';
125         $time_end = ''; 
126 }
127
128 // setup calendar dropdowns
129 $time_format = $timedate->get_user_time_format();
130 $time_meridiem_start = $timedate->AMPMMenu('time_start_', $time_start, '');
131 $time_meridiem_end = $timedate->AMPMMenu('time_end_', $time_end, '');
132 $time_meridiem_from = $timedate->AMPMMenu('time_from_', $focus->time_from, '');
133 $time_meridiem_to = $timedate->AMPMMenu('time_to_', $focus->time_to, '');
134 $time_start_hour = intval(substr($time_start, 0, 2));
135 $time_start_minutes = substr($time_start, 3, 5);
136 $time_end_hour = intval(substr($time_end, 0, 2));
137 $time_end_minutes = substr($time_end, 3, 5);
138 $time_from_hour = intval(substr($focus->time_from, 0, 2));
139 $time_from_min = substr($focus->time_from, 3, 5);
140 $time_to_hour = intval(substr($focus->time_to, 0, 2));
141 $time_to_min = substr($focus->time_to, 3, 5);
142 $hours_arr = array ();
143 $mins_arr = array();
144 $num_of_hours = 13;
145 $start_at = 1;
146
147 // setup function drop down
148 include_once('modules/Schedulers/_AddJobsHere.php');
149
150 if(is_array($job_strings) && !empty($job_strings)) {
151         $job_function = "<option value=''>--</option>"; 
152         foreach($job_strings as $k => $function) {
153                 $job_function .= "<option value='function::".$function."'";
154                 if($focus->job == "function::".$function) {
155                         $job_function .= " SELECTED ";
156                 }
157                 $job_function .= ">".$mod_strings['LBL_'.strtoupper($function)]."</option>";
158         }       
159 }
160
161 if (empty ($time_meridiem_start)) {
162         $num_of_hours = 24;
163         $start_at = 0;
164 }
165
166 for ($i = $start_at; $i < $num_of_hours; $i ++) {
167         $i = $i."";
168         if (strlen($i) == 1) {
169                 $i = "0".$i;
170         }
171         $hours_arr[$i] = $i;
172 }
173
174 for($j=0; $j<60; $j++) {
175         $mins_arr[$j] = str_pad($j, 2, 0, STR_PAD_LEFT);        
176 }
177
178 // make two more array with "nulls"
179 $hours_arr_unreq = $hours_arr;
180 $mins_arr_unreq = $mins_arr;
181 $hours_arr_unreq[''] = '--';
182 $mins_arr_unreq[''] = '--';
183
184 // explode crontab notation 
185 if(!empty($focus->job_interval)) {
186         $exInterval = explode("::", $focus->job_interval);
187 } else {
188         $exInterval = array('*','*','*','*','*');       
189 }
190
191
192
193 // TEMPLATE ASSIGNMENTS
194 $xtpl = new XTemplate('modules/Schedulers/EditView.html');
195
196 ///////////////////////////////////////////////////////////////////////////////
197 ////    PARSING FOR BASIC SETUP
198 // Days of the week
199 $xtpl->assign('USE_ADV_BOOL', 'false');
200 $xtDays = array(0 => 'MON',
201                                 1 => 'TUE',
202                                 2 => 'WED',
203                                 3 => 'THU',
204                                 4 => 'FRI',
205                                 5 => 'SAT',
206                                 6 => 'SUN');
207
208 if($exInterval[4] == '*') {
209         $xtpl->assign('ALL', "CHECKED");
210         $xtpl->assign('MON', "CHECKED");
211         $xtpl->assign('TUE', "CHECKED");
212         $xtpl->assign('WED', "CHECKED");
213         $xtpl->assign('THU', "CHECKED");
214         $xtpl->assign('FRI', "CHECKED");
215         $xtpl->assign('SAT', "CHECKED");
216         $xtpl->assign('SUN', "CHECKED");
217 } elseif(strpos($exInterval[4], ',')) {
218         $daysRun = array();
219         $exDays = explode(',', trim($exInterval[4]));
220         foreach($exDays as $k => $days) {
221                 if(strpos($days, '-')) {
222                         $exDaysRange = explode('-', $days);
223                         for($i=$exDaysRange[0]; $i<=$exDaysRange[1]; $i++) {
224                                 $xtpl->assign($xtDays[$days], "CHECKED");       
225                         }       
226                 } else {
227                         $xtpl->assign($xtDays[$days], "CHECKED");
228                 }
229         }
230 } elseif(strpos($exInterval[4], '-')) {
231         $exDaysRange = explode('-', $exInterval[4]);
232         for($i=$exDaysRange[0]; $i<=$exDaysRange[1]; $i++) {
233                 $xtpl->assign($xtDays[$i], "CHECKED");  
234         }       
235 } else {
236         $xtpl->assign($xtDays[$exInterval[4]], "CHECKED");
237 }
238
239 // Hours
240 for($i=1; $i<=30; $i++) {
241         $ints[$i] = $i;
242 }
243 $use_adv = false;
244 if($exInterval[0] == '*' && $exInterval[1] == '*') {
245         $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, '1'));
246         $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'min'));
247 // hours
248 } elseif(strpos($exInterval[1], '*/') !== false && $exInterval[0] == '0') {
249         // we have a "BASIC" type of hour setting
250         $exHours = explode('/', $exInterval[1]);
251         $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, $exHours[1]));
252         $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'hour'));
253 // Minutes
254 } elseif(strpos($exInterval[0], '*/') !== false && $exInterval[1] == '*' ) {
255         // we have a "BASIC" type of min setting
256         $exMins = explode('/', $exInterval[0]);
257         $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, $exMins[1]));
258         $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'min'));
259 // we've got an advanced time setting
260 } else {
261         $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'hour'));
262         $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, 10));
263         $xtpl->assign('ONLY_ADV', 'DISABLED');
264         $xtpl->assign('USE_ADV_BOOL', 'true');
265         $use_adv = true;
266 }
267
268
269
270 ////    END PARSING FOR BASIC
271 ///////////////////////////////////////////////////////////////////////////////
272
273
274
275
276 // calendar assignments
277 $xtpl->assign('DATE_START', $date_start);
278 $xtpl->assign('TIME_START', $time_start);
279 $xtpl->assign('DATE_END', $date_end);
280 $xtpl->assign('TIME_END', $time_end);
281 $xtpl->assign('TIME_START_HOUR_OPTIONS', get_select_options_with_id($hours_arr, $time_start_hour));
282 $xtpl->assign('TIME_START_MINUTE_OPTIONS', get_select_options_with_id($mins_arr, $time_start_minutes));
283 $xtpl->assign('TIME_END_HOUR_OPTIONS', get_select_options_with_id($hours_arr_unreq, $time_end_hour));
284 $xtpl->assign('TIME_END_MINUTE_OPTIONS', get_select_options_with_id($mins_arr_unreq, $time_end_minutes));
285 $xtpl->assign('TIME_TO_HOUR_OPTIONS', get_select_options_with_id($hours_arr_unreq, $time_to_hour));
286 $xtpl->assign('TIME_TO_MIN_OPTIONS', get_select_options_with_id($mins_arr_unreq, $time_to_min));
287 $xtpl->assign('TIME_FROM_HOUR_OPTIONS', get_select_options_with_id($hours_arr_unreq, $time_from_hour));
288 $xtpl->assign('TIME_FROM_MIN_OPTIONS', get_select_options_with_id($mins_arr_unreq, $time_from_min));
289 $xtpl->assign('TIME_MERIDIEM_START', $time_meridiem_start);
290 $xtpl->assign('TIME_MERIDIEM_END', $time_meridiem_end);
291 $xtpl->assign('TIME_MERIDIEM_FROM', $time_meridiem_from);
292 $xtpl->assign('TIME_MERIDIEM_TO', $time_meridiem_to);
293 if (preg_match('/\d([^\d])\d/', $time_format, $match)) {
294         $xtpl->assign('TIME_SEPARATOR', $match[1]);
295 } else {
296         $xtpl->assign('TIME_SEPARATOR', ':');
297 }
298 $xtpl->assign('TIME_FORMAT', '('.$time_format.')');
299 $xtpl->assign('USER_DATEFORMAT', '('.$timedate->get_user_date_format().')');
300 $xtpl->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
301 // standard assigns
302 $xtpl->assign('MOD', $mod_strings);
303 $xtpl->assign('APP', $app_strings);
304 $xtpl->assign('THEME', SugarThemeRegistry::current()->__toString());
305 $xtpl->assign('GRIDLINE', $gridline);
306 if($use_adv) {
307         $javascript->script .= 'toggleAdv();';
308         $xtpl->assign('JAVASCRIPT', get_set_focus_js().$javascript->getScript());
309 } else {
310         $xtpl->assign('JAVASCRIPT', get_set_focus_js().$javascript->getScript());
311 }
312 $xtpl->assign('RETURN_MODULE', 'Schedulers');
313 $xtpl->assign('RETURN_ID', $focus->id);
314 $xtpl->assign('RETURN_ACTION', 'DetailView');
315 // module specific
316 $xtpl->assign('ID', $focus->id);
317 $xtpl->assign('NAME', $focus->name);
318 if($focus->catch_up == 1) {
319         $xtpl->assign('CATCH_UP_CHECKED', 'CHECKED');
320 }
321 // job
322 if(strstr($focus->job, 'url::')) {
323         $job_url = str_replace('url::','', $focus->job);
324 } else {
325         $job_url = 'http://';
326 }
327         
328 $xtpl->assign('JOB_FUNCTION', $job_function);
329 $xtpl->assign('JOB_URL', $job_url);
330 $xtpl->assign('JOB_INTERVAL', $focus->job_interval);
331
332
333 $xtpl->assign('TIME_FROM', $focus->time_from);
334 $xtpl->assign('TIME_TO', $focus->time_to);
335 $xtpl->assign('STATUS_OPTIONS', get_select_options_with_id($app_list_strings['scheduler_status_dom'], $focus->status));
336 $xtpl->assign('MINS', $exInterval[0]);
337 $xtpl->assign('HOURS', $exInterval[1]);
338 $xtpl->assign('DAY_OF_MONTH', $exInterval[2]);
339 $xtpl->assign('MONTHS', $exInterval[3]);
340 $xtpl->assign('DAY_OF_WEEK', $exInterval[4]);
341 $xtpl->assign('ROLLOVER', $email->rolloverStyle);
342
343 $xtpl->assign('SERVER_TIMEZONE', date("T"));
344 $xtpl->assign('SERVER_OFFSET', date("O"));
345
346 $xtpl->parse("main");
347 $xtpl->out("main");
348
349 //$focus->displayCronInstructions();
350 ?>