2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
41 ********************************************************************************/
43 if(!is_admin($current_user)) sugar_die("Unauthorized access to administration.");
45 $_REQUEST['edit']='true';
50 global $app_list_strings;
57 /* Start standard EditView setup logic */
58 $mod_strings = return_module_language($current_language, 'Schedulers');
59 $focus = new Scheduler();
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']);
66 sugar_die($app_strings['ERROR_NO_RECORD']);
69 if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
70 $GLOBALS['log']->debug("isDuplicate found - duplicating record of id: ".$focus->id);
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'];
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'];
84 echo getClassicModuleTitle("Schedulers", $params, true);
86 $GLOBALS['log']->info("Scheduler Edit View");
87 /* End standard EditView setup logic */
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('day_of_month', 'alpha', 'Days of Month', true, $prefix='');
97 $javascript->addFieldGeneric('months', 'alpha', 'Months', true, $prefix='');
98 $javascript->addFieldGeneric('day_of_week', 'alpha', 'Days of Week', true, $prefix='');
99 $javascript->addFieldGeneric('date_start', 'date', 'Start Date', true, $prefix='');
100 //$javascript->addFieldDateBeforeAllowBlank('date_start', 'date', 'Date End', 'false', $prefix='', 'date_end', 'true'); // cn: disabled because it does not handle user-pref date format
101 $javascript->addToValidateBinaryDependency('time_hour_from', 'alpha', 'Active From (hr) must be set with Active To (hr) ', 'false', $prefix='', 'time_hour_to');
102 $javascript->addToValidateBinaryDependency('time_minute_from', 'alpha', 'Active From (min) must be set with Active To (min) ', 'false', $prefix='', 'time_minute_to');
103 //($field, $type,$displayName, $required, $prefix='',$compareTo)
105 // split the date/time of start/end
106 $dtStart = $focus->date_time_start;
107 $dtEnd = $focus->date_time_end;
108 if(!empty($dtStart)) {
109 $exStart = explode(" ",$dtStart);
110 $date_start = $exStart[0];
111 $time_start = $exStart[1];
113 $prefDate = $current_user->getUserDateTimePreferences();
114 $date_start = $timedate->asUserDate($timedate->fromString('2005-01-01'));
118 if(!empty($dtEnd) && $dtEnd != '2020-12-31 23:59') {
119 $exEnd = explode(" ",$dtEnd);
120 $date_end = $exEnd[0];
121 $time_end = $exEnd[1];
127 // setup calendar dropdowns
128 $time_format = $timedate->get_user_time_format();
129 $time_meridiem_start = $timedate->AMPMMenu('time_start_', $time_start, '');
130 $time_meridiem_end = $timedate->AMPMMenu('time_end_', $time_end, '');
131 $time_meridiem_from = $timedate->AMPMMenu('time_from_', $focus->time_from, '');
132 $time_meridiem_to = $timedate->AMPMMenu('time_to_', $focus->time_to, '');
133 $time_start_hour = intval(substr($time_start, 0, 2));
134 $time_start_minutes = substr($time_start, 3, 5);
135 $time_end_hour = intval(substr($time_end, 0, 2));
136 $time_end_minutes = substr($time_end, 3, 5);
137 $time_from_hour = intval(substr($focus->time_from, 0, 2));
138 $time_from_min = substr($focus->time_from, 3, 5);
139 $time_to_hour = intval(substr($focus->time_to, 0, 2));
140 $time_to_min = substr($focus->time_to, 3, 5);
141 $hours_arr = array ();
146 // setup function drop down
147 include_once('modules/Schedulers/_AddJobsHere.php');
149 if(is_array($job_strings) && !empty($job_strings)) {
150 $job_function = "<option value=''>--</option>";
151 foreach($job_strings as $k => $function) {
152 $job_function .= "<option value='function::".$function."'";
153 if($focus->job == "function::".$function) {
154 $job_function .= " SELECTED ";
156 $job_function .= ">".$mod_strings['LBL_'.strtoupper($function)]."</option>";
160 if (empty ($time_meridiem_start)) {
165 for ($i = $start_at; $i < $num_of_hours; $i ++) {
167 if (strlen($i) == 1) {
173 for($j=0; $j<60; $j++) {
174 $mins_arr[$j] = str_pad($j, 2, 0, STR_PAD_LEFT);
177 // make two more array with "nulls"
178 $hours_arr_unreq = $hours_arr;
179 $mins_arr_unreq = $mins_arr;
180 $hours_arr_unreq[''] = '--';
181 $mins_arr_unreq[''] = '--';
183 // explode crontab notation
184 if(!empty($focus->job_interval)) {
185 $exInterval = explode("::", $focus->job_interval);
187 $exInterval = array('*','*','*','*','*');
192 // TEMPLATE ASSIGNMENTS
193 $xtpl = new XTemplate('modules/Schedulers/EditView.html');
195 ///////////////////////////////////////////////////////////////////////////////
196 //// PARSING FOR BASIC SETUP
198 $xtpl->assign('USE_ADV_BOOL', 'false');
199 $xtDays = array(1 => 'MON',
207 if($exInterval[4] == '*') {
208 $xtpl->assign('ALL', "CHECKED");
209 $xtpl->assign('MON', "CHECKED");
210 $xtpl->assign('TUE', "CHECKED");
211 $xtpl->assign('WED', "CHECKED");
212 $xtpl->assign('THU', "CHECKED");
213 $xtpl->assign('FRI', "CHECKED");
214 $xtpl->assign('SAT', "CHECKED");
215 $xtpl->assign('SUN', "CHECKED");
216 } elseif(strpos($exInterval[4], ',')) {
218 $exDays = explode(',', trim($exInterval[4]));
219 foreach($exDays as $k => $days) {
220 if(strpos($days, '-')) {
221 $exDaysRange = explode('-', $days);
222 for($i=$exDaysRange[0]; $i<=$exDaysRange[1]; $i++) {
223 $xtpl->assign($xtDays[$days], "CHECKED");
226 $xtpl->assign($xtDays[$days], "CHECKED");
229 } elseif(strpos($exInterval[4], '-')) {
230 $exDaysRange = explode('-', $exInterval[4]);
231 for($i=$exDaysRange[0]; $i<=$exDaysRange[1]; $i++) {
232 $xtpl->assign($xtDays[$i], "CHECKED");
235 $xtpl->assign($xtDays[$exInterval[4]], "CHECKED");
239 for($i=1; $i<=30; $i++) {
243 if($exInterval[0] == '*' && $exInterval[1] == '*') {
244 $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, '1'));
245 $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'min'));
247 } elseif(strpos($exInterval[1], '*/') !== false && $exInterval[0] == '0') {
248 // we have a "BASIC" type of hour setting
249 $exHours = explode('/', $exInterval[1]);
250 $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, $exHours[1]));
251 $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'hour'));
253 } elseif(strpos($exInterval[0], '*/') !== false && $exInterval[1] == '*' ) {
254 // we have a "BASIC" type of min setting
255 $exMins = explode('/', $exInterval[0]);
256 $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, $exMins[1]));
257 $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'min'));
258 // we've got an advanced time setting
260 $xtpl->assign('BASIC_PERIOD', get_select_options_with_id($app_list_strings['scheduler_period_dom'], 'hour'));
261 $xtpl->assign('BASIC_INTERVAL', get_select_options_with_id($ints, 10));
262 $xtpl->assign('ONLY_ADV', 'DISABLED');
263 $xtpl->assign('USE_ADV_BOOL', 'true');
269 //// END PARSING FOR BASIC
270 ///////////////////////////////////////////////////////////////////////////////
275 // calendar assignments
276 $xtpl->assign('DATE_START', $date_start);
277 $xtpl->assign('TIME_START', $time_start);
278 $xtpl->assign('DATE_END', $date_end);
279 $xtpl->assign('TIME_END', $time_end);
280 $xtpl->assign('TIME_START_HOUR_OPTIONS', get_select_options_with_id($hours_arr, $time_start_hour));
281 $xtpl->assign('TIME_START_MINUTE_OPTIONS', get_select_options_with_id($mins_arr, $time_start_minutes));
282 $xtpl->assign('TIME_END_HOUR_OPTIONS', get_select_options_with_id($hours_arr_unreq, $time_end_hour));
283 $xtpl->assign('TIME_END_MINUTE_OPTIONS', get_select_options_with_id($mins_arr_unreq, $time_end_minutes));
284 $xtpl->assign('TIME_TO_HOUR_OPTIONS', get_select_options_with_id($hours_arr_unreq, $time_to_hour));
285 $xtpl->assign('TIME_TO_MIN_OPTIONS', get_select_options_with_id($mins_arr_unreq, $time_to_min));
286 $xtpl->assign('TIME_FROM_HOUR_OPTIONS', get_select_options_with_id($hours_arr_unreq, $time_from_hour));
287 $xtpl->assign('TIME_FROM_MIN_OPTIONS', get_select_options_with_id($mins_arr_unreq, $time_from_min));
288 $xtpl->assign('TIME_MERIDIEM_START', $time_meridiem_start);
289 $xtpl->assign('TIME_MERIDIEM_END', $time_meridiem_end);
290 $xtpl->assign('TIME_MERIDIEM_FROM', $time_meridiem_from);
291 $xtpl->assign('TIME_MERIDIEM_TO', $time_meridiem_to);
292 if (preg_match('/\d([^\d])\d/', $time_format, $match)) {
293 $xtpl->assign('TIME_SEPARATOR', $match[1]);
295 $xtpl->assign('TIME_SEPARATOR', ':');
297 $xtpl->assign('TIME_FORMAT', '('.$time_format.')');
298 $xtpl->assign('USER_DATEFORMAT', '('.$timedate->get_user_date_format().')');
299 $xtpl->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
301 $xtpl->assign('MOD', $mod_strings);
302 $xtpl->assign('APP', $app_strings);
303 $xtpl->assign('THEME', SugarThemeRegistry::current()->__toString());
304 $xtpl->assign('GRIDLINE', $gridline);
306 $javascript->script .= 'toggleAdv();';
307 $xtpl->assign('JAVASCRIPT', get_set_focus_js().$javascript->getScript());
309 $xtpl->assign('JAVASCRIPT', get_set_focus_js().$javascript->getScript());
311 $xtpl->assign('RETURN_MODULE', 'Schedulers');
312 $xtpl->assign('RETURN_ID', $focus->id);
313 $xtpl->assign('RETURN_ACTION', 'DetailView');
315 $xtpl->assign('ID', $focus->id);
316 $xtpl->assign('NAME', $focus->name);
317 if($focus->catch_up == 1) {
318 $xtpl->assign('CATCH_UP_CHECKED', 'CHECKED');
321 if(strstr($focus->job, 'url::')) {
322 $job_url = str_replace('url::','', $focus->job);
324 $job_url = 'http://';
327 $xtpl->assign('JOB_FUNCTION', $job_function);
328 $xtpl->assign('JOB_URL', $job_url);
329 $xtpl->assign('JOB_INTERVAL', $focus->job_interval);
332 $xtpl->assign('TIME_FROM', $focus->time_from);
333 $xtpl->assign('TIME_TO', $focus->time_to);
334 $xtpl->assign('STATUS_OPTIONS', get_select_options_with_id($app_list_strings['scheduler_status_dom'], $focus->status));
335 $xtpl->assign('MINS', $exInterval[0]);
336 $xtpl->assign('HOURS', $exInterval[1]);
337 $xtpl->assign('DAY_OF_MONTH', $exInterval[2]);
338 $xtpl->assign('MONTHS', $exInterval[3]);
339 $xtpl->assign('DAY_OF_WEEK', $exInterval[4]);
340 $xtpl->assign('ROLLOVER', $email->rolloverStyle);
342 $xtpl->assign('SERVER_TIMEZONE', date("T"));
343 $xtpl->assign('SERVER_OFFSET', date("O"));
345 $xtpl->parse("main");
348 //$focus->displayCronInstructions();