2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
43 require_once('include/formbase.php');
47 $sugarbean = new Project();
48 $sugarbean = populateFromPost('', $sugarbean);
50 $projectTasks = array();
51 if (isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true"){
52 $base_project_id = $_REQUEST['relate_id'];
55 $base_project_id = $sugarbean->id;
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);
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);
72 if (isset($_REQUEST['save_type'])){
74 $sugarbean->assigned_user_id = $current_user->id;
76 if ($_REQUEST['save_type'] == 'TemplateToProject'){
77 $sugarbean->name = $_REQUEST['project_name'];
78 $sugarbean->is_template = 0;
80 else if ($_REQUEST['save_type'] == 'ProjectToTemplate'){
81 $sugarbean->name = $_REQUEST['template_name'];
82 $sugarbean->is_template = true;
86 if (isset($_REQUEST['is_template']) && $_REQUEST['is_template'] == '1'){
87 $sugarbean->is_template = true;
90 $sugarbean->is_template = 0;
94 if(isset($_REQUEST['email_id'])) $sugarbean->email_id = $_REQUEST['email_id'];
96 if(!$sugarbean->ACLAccess('Save')){
97 ACLController::displayNoAccess(true);
101 $sugarbean->save(false);
102 $return_id = $sugarbean->id;
104 if(isset($_REQUEST['save_type']) || isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true") {
105 for ($i = 0; $i < count($projectTasks); $i++){
106 if (isset($_REQUEST['save_type']) || (isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave'] === "true")){
107 $projectTasks[$i]->id = '';
108 $projectTasks[$i]->project_id = $sugarbean->id;
110 if ($sugarbean->is_template){
111 $projectTasks[$i]->assigned_user_id = '';
113 $projectTasks[$i]->team_id = $sugarbean->team_id;
114 if(empty( $projectTasks[$i]->duration_unit)) $projectTasks[$i]->duration_unit = " "; //Since duration_unit cannot be null.
115 $projectTasks[$i]->save(false);
119 if ($sugarbean->is_template){
120 header("Location: index.php?action=ProjectTemplatesDetailView&module=Project&record=$return_id&return_module=Project&return_action=ProjectTemplatesEditView");
123 handleRedirect($return_id,'Project');