]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Schedulers/Save.php
Release 6.5.0
[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-2012 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 require_once('include/formbase.php');
39
40 $focus = new Scheduler();
41 $focus = populateFromPost('', $focus);
42
43 ///////////////////////////////////////////////////////////////////////////////
44 ////    USE_ADV override
45 if(!isset($_REQUEST['adv_interval']) || $_REQUEST['adv_interval'] == 'false' || $_REQUEST['adv_interval'] == '0') {
46         // days of week
47         $xtDays = array(1 => 'mon',
48                                         2 => 'tue',
49                                         3 => 'wed',
50                                         4 => 'thu',
51                                         5 => 'fri',
52                                         6 => 'sat',
53                                         0 => 'sun');
54                                         
55         if(     (isset($_REQUEST['mon']) && $_REQUEST['mon'] == 'true') &&
56                 (isset($_REQUEST['tue']) && $_REQUEST['tue'] == 'true') &&
57                 (isset($_REQUEST['wed']) && $_REQUEST['wed'] == 'true') &&
58                 (isset($_REQUEST['thu']) && $_REQUEST['thu'] == 'true') &&
59                 (isset($_REQUEST['fri']) && $_REQUEST['fri'] == 'true') &&
60                 (isset($_REQUEST['sat']) && $_REQUEST['sat'] == 'true') &&
61                 (isset($_REQUEST['sun']) && $_REQUEST['sun'] == 'true') ) {
62                 $_REQUEST['day_of_week'] = '*';
63         } else {
64                 $day_string = '';
65                 foreach($xtDays as $k => $day) {
66                         if(isset($_REQUEST[$day]) && $_REQUEST[$day] == 'true') {
67                                 if($day_string != '') {
68                                         $day_string .= ',';
69                                 }
70                                 $day_string .= $k;
71                         }
72                 }
73                 $_REQUEST['day_of_week'] = $day_string;
74         }
75
76
77         if($_REQUEST['basic_period'] == 'min') {
78                 $_REQUEST['mins'] = '*/'.$_REQUEST['basic_interval'];
79                 $_REQUEST['hours'] = '*';
80         } else {
81         // Bug # 44933 - hours cannot be greater than 23
82         if ($_REQUEST['basic_interval'] < 24) {
83                     $_REQUEST['hours'] = '*/'.$_REQUEST['basic_interval'];
84         } else {
85            $_REQUEST['hours'] = '0'; // setting it to run midnight every 24 hours
86         }
87         $_REQUEST['mins'] = '0';    // on top of the hours
88         } 
89 }
90
91 ////    END USE_ADV override
92 ///////////////////////////////////////////////////////////////////////////////
93 $focus->job_interval = $_REQUEST['mins']."::".$_REQUEST['hours']."::".$_REQUEST['day_of_month']."::".$_REQUEST['months']."::".$_REQUEST['day_of_week'];
94 // deal with job types
95 // neither
96 if ( ($_REQUEST['job_function'] == 'url::') && ($_REQUEST['job_url'] == '' || $_REQUEST['job_url'] == 'http://') ) {
97         $GLOBALS['log']->fatal('Scheduler save did not get a job_url or job_function');
98 } elseif ( ($_REQUEST['job_function'] != 'url::') && ($_REQUEST['job_url'] != '' && $_REQUEST['job_url'] != 'http://') ) {
99         $GLOBALS['log']->fatal('Scheduler got both a job_url and job_function');
100 }
101 //function
102 if ( ($_REQUEST['job_function'] != 'url::')) {
103         $focus->job = $_REQUEST['job_function'];
104 } elseif ( $_REQUEST['job_url'] != '' && $_REQUEST['job_url'] != 'http://') { // url
105         $focus->job = 'url::'.$_REQUEST['job_url'];
106 } // url wins if both passed
107
108 // save should refresh ALL jobs
109 $focus->save();
110 $return_id = $focus->id;
111
112 $edit='';
113 if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") $return_module = $_REQUEST['return_module'];
114 else $return_module = "Schedulers";
115 if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") $return_action = $_REQUEST['return_action'];
116 else $return_action = "DetailView";
117 if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") $return_id = $_REQUEST['return_id'];
118 if(!empty($_REQUEST['edit'])) {
119         $return_id='';
120         $edit='edit=true';
121 }
122
123 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
124
125 header("Location: index.php?action=$return_action&module=$return_module&record=$return_id&$edit");
126 ?>