]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Tasks/Save.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Tasks / 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 /*********************************************************************************
39
40  * Description:  Saves an Account record and then redirects the browser to the
41  * defined return URL.
42  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43  * All Rights Reserved.
44  * Contributor(s): ______________________________________..
45  ********************************************************************************/
46
47
48
49 $focus = new Task();
50 if (!isset($prefix)) $prefix='';
51
52 global $timedate;
53 $time_format = $timedate->get_user_time_format();
54 $time_separator = ":";
55 if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
56    $time_separator = $match[1];
57 }
58
59 if(!empty($_POST[$prefix.'due_meridiem'])) {
60         $_POST[$prefix.'time_due'] = $timedate->merge_time_meridiem($_POST[$prefix.'time_due'],$timedate->get_time_format(), $_POST[$prefix.'due_meridiem']);
61 }
62
63 if(!empty($_POST[$prefix.'start_meridiem'])) {
64         $_POST[$prefix.'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix.'time_start'],$timedate->get_time_format(), $_POST[$prefix.'start_meridiem']);
65 }
66
67 if(isset($_POST[$prefix.'time_due']) && !empty($_POST[$prefix.'time_due'])) {
68    $_POST[$prefix.'date_due'] = $_POST[$prefix.'date_due'] . ' ' . $_POST[$prefix.'time_due'];
69 }
70
71 if(isset($_POST[$prefix.'time_start']) && !empty($_POST[$prefix.'time_start'])) {
72    $_POST[$prefix.'date_start'] = $_POST[$prefix.'date_start'] . ' ' . $_POST[$prefix.'time_start'];
73 }
74
75 require_once('include/formbase.php');
76 $focus = populateFromPost('', $focus);
77
78 if(!$focus->ACLAccess('Save')){
79                 ACLController::displayNoAccess(true);
80                 sugar_cleanup(true);
81 }
82
83 if (isCloseAndCreateNewPressed()) $focus->status = 'Completed';
84 if (!isset($_POST['date_due_flag'])) $focus->date_due_flag = 0;
85 if (!isset($_POST['date_start_flag'])) $focus->date_start_flag = 0;
86 if($focus->date_due_flag != 'off' && $focus->date_due_flag != 1) {
87    $focus->date_due = '';
88    $focus->time_due = '';
89 }
90
91 //if only the time is passed in, without a date, then string length will be 7
92 if (isset($_REQUEST['date_due']) && strlen(trim($_REQUEST['date_due']))<8 ){
93     //no date set, so clear out field, and set the rest flag to true
94     $focus->date_due_flag = 1;
95     $focus->date_due = '';    
96 }
97
98 //if only the time is passed in, without a date, then string length will be 7
99 if (isset($_REQUEST['date_start']) && strlen(trim($_REQUEST['date_start']))<8){
100     //no date set, so clear out field, and set the rest flag to true
101     $focus->date_start_flag = 1;
102     $focus->date_start = '';
103 }
104
105
106
107 ///////////////////////////////////////////////////////////////////////////////
108 ////    INBOUND EMAIL HANDLING
109 ///////////////////////////////////////////////////////////////////////////////
110 if(isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
111         // fake this case like it's already saved.
112         $focus->save();
113         
114         $email = new Email();
115         $email->retrieve($_REQUEST['inbound_email_id']);
116         $email->parent_type = 'Tasks';
117         $email->parent_id = $focus->id;
118         $email->assigned_user_id = $current_user->id;
119         $email->status = 'read';
120         $email->save();
121         $email->load_relationship('tasks');
122         $email->tasks->add($focus->id);
123         
124         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=".$_REQUEST['inbound_email_id']."&parent_id=".$email->parent_id."&parent_type=".$email->parent_type.'&start='.$_REQUEST['start'].'&assigned_user_id='.$current_user->id);
125         exit();
126 }
127 ////    END INBOUND EMAIL HANDLING
128 /////////////////////////////////////////////////////////////////////////////// 
129
130 // CCL - Bugs 41103 and 43751.  41103 address the issue where the parent_id is set, but
131 // the relate_id field overrides the relationship.  43751 fixes the problem where the relate_id and
132 // parent_id are the same value (in which case it should just use relate_id) by adding the != check
133 if ((!empty($_REQUEST['relate_id']) && !empty($_REQUEST['parent_id'])) && ($_REQUEST['relate_id'] != $_REQUEST['parent_id']))
134 {
135         $_REQUEST['relate_id'] = false;
136 }
137
138 // avoid undefined index
139 if (!isset($GLOBALS['check_notify'])) {
140         $GLOBALS['check_notify'] = false;
141 }
142 $focus->save($GLOBALS['check_notify']);
143 $return_id = $focus->id;
144
145 handleRedirect($return_id,'Tasks');
146 ?>