]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Schedulers/Save.php
Release 6.2.2
[Github/sugarcrm.git] / modules / Schedulers / Save.php
1 <?php
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-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
43
44
45
46 $focus = new Scheduler();
47 $focus->retrieve($_REQUEST['record']);
48
49
50 // deal with empty values
51 if(!empty($_REQUEST['date_end']) && !empty($_REQUEST['time_hour_end']) && !empty($_REQUEST['time_minute_end']) ) {
52         $date_time_end = $_REQUEST['date_end']." ".str_pad($_REQUEST['time_hour_end'],2,'0',STR_PAD_LEFT).":".str_pad($_REQUEST['time_minute_end'],2,'0',STR_PAD_LEFT).$_REQUEST['time_end_meridiem'];
53 } else {
54         $date_time_end = '';
55 }
56 if( (!empty($_REQUEST['time_hour_from']) || $_REQUEST['time_hour_from'] == '0' ) && (!empty($_REQUEST['time_minute_from']) || $_REQUEST['time_minute_from'] == '0' ) ) {
57         $time_from = str_pad($_REQUEST['time_hour_from'],2,'0',STR_PAD_LEFT).":".str_pad($_REQUEST['time_minute_from'],2,'0',STR_PAD_LEFT);
58         if(!empty($_REQUEST['time_from_meridiem'])) {
59                 $time_from .= $_REQUEST['time_from_meridiem'];
60         }
61 } else {
62         $time_from = '';
63 }
64 if( (!empty($_REQUEST['time_hour_to']) || $_REQUEST['time_hour_to'] == '0') && (!empty($_REQUEST['time_minute_to']) || $_REQUEST['time_minute_to'] == '0') ) {
65         $time_to = str_pad($_REQUEST['time_hour_to'],2,'0',STR_PAD_LEFT).":".str_pad($_REQUEST['time_minute_to'],2,'0',STR_PAD_LEFT);
66         if(!empty($_REQUEST['time_to_meridiem'])) {
67                 $time_to .= $_REQUEST['time_to_meridiem'];      
68         }
69 } else {
70         $time_to = '';
71 }
72 $date_time_start = $_REQUEST['date_start']." ".str_pad($_REQUEST['time_hour_start'],2,'0',STR_PAD_LEFT).":".str_pad($_REQUEST['time_minute_start'],2,'0',STR_PAD_LEFT);
73 if(!empty($_REQUEST['time_start_meridiem'])) {
74         $date_time_start .= $_REQUEST['time_start_meridiem'];
75 }
76 if(empty($_REQUEST['catch_up'])) {
77         $focus->catch_up = 0;
78 } else {
79         $focus->catch_up = 1;
80 }
81
82 $focus->date_time_start = $date_time_start;
83 $focus->date_time_end = $date_time_end;
84 $focus->time_from = $time_from;
85 $focus->time_to = $time_to;
86 $focus->status = $_REQUEST['status'];
87 $focus->name = $_REQUEST['name'];
88
89 ///////////////////////////////////////////////////////////////////////////////
90 ////    USE_ADV override
91 if($_REQUEST['use_adv'] == 'false') {
92         // days of week
93         $xtDays = array(0 => 'mon',
94                                         1 => 'tue',
95                                         2 => 'wed',
96                                         3 => 'thu',
97                                         4 => 'fri',
98                                         5 => 'sat',
99                                         6 => 'sun');
100                                         
101         if(     (isset($_REQUEST['mon']) && $_REQUEST['mon'] == 'true') && 
102                 (isset($_REQUEST['tue']) && $_REQUEST['tue'] == 'true') &&
103                 (isset($_REQUEST['wed']) && $_REQUEST['wed'] == 'true') &&
104                 (isset($_REQUEST['thu']) && $_REQUEST['thu'] == 'true') &&
105                 (isset($_REQUEST['fri']) && $_REQUEST['fri'] == 'true') &&
106                 (isset($_REQUEST['sat']) && $_REQUEST['sat'] == 'true') &&
107                 (isset($_REQUEST['sun']) && $_REQUEST['sun'] == 'true') ) {
108                 $_REQUEST['day_of_week'] = '*';
109         } else {
110                 $day_string = '';
111                 foreach($xtDays as $k => $day) {
112                         if(isset($_REQUEST[$day]) && $_REQUEST[$day] == 'true') {
113                                 if($day_string != '') {
114                                         $day_string .= ',';
115                                 }
116                                 $day_string .= $k;
117                         }
118                 }
119                 $_REQUEST['day_of_week'] = $day_string;
120         }
121                 
122         
123         if($_REQUEST['basic_period'] == 'min') {
124                 $_REQUEST['mins'] = '*/'.$_REQUEST['basic_interval'];
125                 $_REQUEST['hours'] = '*';       
126         } else {
127         // Bug # 44933 - hours cannot be greater than 23
128         if ($_REQUEST['basic_interval'] < 24) {
129                     $_REQUEST['hours'] = '*/'.$_REQUEST['basic_interval'];
130         } else {
131            $_REQUEST['hours'] = '0'; // setting it to run midnight every 24 hours
132         }
133         $_REQUEST['mins'] = '0';    // on top of the hours
134         } 
135 }
136
137 ////    END USE_ADV override
138 ///////////////////////////////////////////////////////////////////////////////
139 //_ppd($_REQUEST);
140 $focus->job_interval = $_REQUEST['mins']."::".$_REQUEST['hours']."::".$_REQUEST['day_of_month']."::".$_REQUEST['months']."::".$_REQUEST['day_of_week'];
141
142
143
144
145 // deal with job types
146 // neither 
147 if ( ($_REQUEST['job_function'] == '') && ($_REQUEST['job_url'] == '' || $_REQUEST['job_url'] == 'http://') ) {
148         $GLOBALS['log']->fatal('Scheduler save did not get a job_url or job_function');
149 } elseif ( ($_REQUEST['job_function'] != '') && ($_REQUEST['job_url'] != '' && $_REQUEST['job_url'] != 'http://') ) {
150         $GLOBALS['log']->fatal('Scheduler got both a job_url and job_function');
151 }
152 //function 
153 if ( ($_REQUEST['job_function'] != '') && ($_REQUEST['job_url'] == '' || $_REQUEST['job_url'] == 'http://') ) {
154         $focus->job = $_REQUEST['job_function'];
155 } elseif ( ($_REQUEST['job_function'] == '') && ($_REQUEST['job_url'] != '' && $_REQUEST['job_url'] != 'http://') ) { // url
156         $focus->job = 'url::'.$_REQUEST['job_url'];
157 } // url wins if both passed
158
159 // save should refresh ALL jobs
160 $focus->save();
161 $return_id = $focus->id;
162
163 $edit='';
164 if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") $return_module = $_REQUEST['return_module'];
165 else $return_module = "Schedulers";
166 if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") $return_action = $_REQUEST['return_action'];
167 else $return_action = "DetailView";
168 if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") $return_id = $_REQUEST['return_id'];
169 if(!empty($_REQUEST['edit'])) {
170         $return_id='';
171         $edit='edit=true';
172 }
173
174 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
175
176 header("Location: index.php?action=$return_action&module=$return_module&record=$return_id&$edit");
177 ?>