]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Project/Save.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Project / 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
41
42
43 require_once('include/formbase.php');
44
45 global $current_user;
46
47 $sugarbean = new Project();
48 $sugarbean = populateFromPost('', $sugarbean);
49
50 $projectTasks = array();
51 if (isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true"){
52     $base_project_id = $_REQUEST['relate_id'];
53 }
54 else{
55     $base_project_id = $sugarbean->id;
56 }
57 if(isset($_REQUEST['save_type']) || isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true") {
58     $query = "SELECT id FROM project_task WHERE project_id = '" . $base_project_id . "' AND deleted = 0";
59     $result = $sugarbean->db->query($query,true,"Error retrieving project tasks");
60     $row = $sugarbean->db->fetchByAssoc($result);
61
62     while ($row != null){
63         $projectTaskBean = new ProjectTask();
64         $projectTaskBean->id = $row['id'];
65         $projectTaskBean->retrieve();
66         $projectTaskBean->date_entered = '';
67         $projectTaskBean->date_modified = '';
68         array_push($projectTasks, $projectTaskBean);
69         $row = $sugarbean->db->fetchByAssoc($result);
70     }
71 }
72 if (isset($_REQUEST['save_type'])){
73     $sugarbean->id = '';
74     $sugarbean->assigned_user_id = $current_user->id;
75
76     if ($_REQUEST['save_type'] == 'TemplateToProject'){
77         $sugarbean->name = $_REQUEST['project_name'];
78         $sugarbean->is_template = 0;
79     }
80     else if ($_REQUEST['save_type'] == 'ProjectToTemplate'){
81         $sugarbean->name = $_REQUEST['template_name'];
82         $sugarbean->is_template = true;
83     }
84 }
85 else{
86     if (isset($_REQUEST['is_template']) && $_REQUEST['is_template'] == '1'){
87         $sugarbean->is_template = true;
88     }
89     else{
90         $sugarbean->is_template = 0;
91     }
92 }
93
94 if(isset($_REQUEST['email_id'])) $sugarbean->email_id = $_REQUEST['email_id'];
95
96 if(!$sugarbean->ACLAccess('Save')){
97         ACLController::displayNoAccess(true);
98         sugar_cleanup(true);
99 }
100
101 if (isset($GLOBALS['check_notify'])) {
102     $check_notify = $GLOBALS['check_notify'];
103 }
104 else {
105     $check_notify = FALSE;
106 }
107 $sugarbean->save($check_notify);
108 $return_id = $sugarbean->id;
109
110 if(isset($_REQUEST['save_type']) || isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true") {
111     for ($i = 0; $i < count($projectTasks); $i++){
112         if (isset($_REQUEST['save_type']) || (isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true")){
113             $projectTasks[$i]->id = '';
114             $projectTasks[$i]->project_id = $sugarbean->id;
115         }
116         if ($sugarbean->is_template){
117             $projectTasks[$i]->assigned_user_id = '';
118         }
119         $projectTasks[$i]->team_id = $sugarbean->team_id;
120         if(empty( $projectTasks[$i]->duration_unit)) $projectTasks[$i]->duration_unit = " "; //Since duration_unit cannot be null.
121         $projectTasks[$i]->save(false);
122     }
123 }
124
125 if ($sugarbean->is_template){
126     header("Location: index.php?action=ProjectTemplatesDetailView&module=Project&record=$return_id&return_module=Project&return_action=ProjectTemplatesEditView");
127 }
128 else{
129     handleRedirect($return_id,'Project');
130 }
131 ?>