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-2013 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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
47 $focus = new Campaign();
49 $focus->retrieve($_POST['record']);
50 if(!$focus->ACLAccess('Save')){
51 ACLController::displayNoAccess(true);
54 if (!empty($_POST['assigned_user_id']) && ($focus->assigned_user_id != $_POST['assigned_user_id']) && ($_POST['assigned_user_id'] != $current_user->id)) {
58 $check_notify = FALSE;
61 require_once('include/formbase.php');
62 $focus = populateFromPost('', $focus);
64 //store preformatted dates for 2nd save
65 $preformat_start_date = $focus->start_date;
66 $preformat_end_date = $focus->end_date;
67 //_ppd($preformat_end_date);
69 $focus->save($check_notify);
70 $return_id = $focus->id;
72 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
75 //copy compaign targets on duplicate
76 if( !empty($_REQUEST['duplicateSave']) && !empty($_REQUEST['duplicateId']) ){
77 $copyFromCompaign = new Campaign();
78 $copyFromCompaign->retrieve($_REQUEST['duplicateId']);
79 $copyFromCompaign->load_relationship('prospectlists');
81 $focus->load_relationship('prospectlists');
82 $target_lists = $copyFromCompaign->prospectlists->get();
83 if(count($target_lists)>0){
84 foreach ($target_lists as $prospect_list_id){
85 $focus->prospectlists->add($prospect_list_id);
93 //if type is set to newsletter then make sure there are prospect lists attached
94 if($focus->campaign_type =='NewsLetter'){
95 //if this is a duplicate, and the "relate_to" and "relate_id" elements are not cleared out,
96 //then prospect lists will get related to the original campaign on save of the prospect list, and then
97 //will get related to the new newsletter campaign, meaning the same (un)subscription list will belong to
98 //two campaigns, which is wrong
99 if((isset($_REQUEST['duplicateSave']) && $_REQUEST['duplicateSave']) || (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate']) ){
100 $_REQUEST['relate_to'] = '';
101 $_REQUEST['relate_id'] = '';
105 //add preformatted dates for 2nd save, to avoid formatting conversion errors
106 $focus->start_date = $preformat_start_date ;
107 $focus->end_date = $preformat_end_date ;
109 $focus->load_relationship('prospectlists');
110 $target_lists = $focus->prospectlists->get();
111 if(count($target_lists)<1){
112 global $current_user;
114 //if no prospect lists are attached, then lets create a subscription and unsubscription
115 //default prospect lists as these are required for newsletters.
117 //create subscription list
118 $subs = new ProspectList();
119 $subs->name = $focus->name.' '.$mod_strings['LBL_SUBSCRIPTION_LIST'];
120 $subs->assigned_user_id= $current_user->id;
121 $subs->list_type = "default";
123 $focus->prospectlists->add($subs->id);
125 //create unsubscription list
126 $unsubs = new ProspectList();
127 $unsubs->name = $focus->name.' '.$mod_strings['LBL_UNSUBSCRIPTION_LIST'];
128 $unsubs->assigned_user_id= $current_user->id;
129 $unsubs->list_type = "exempt";
131 $focus->prospectlists->add($unsubs->id);
133 //create unsubscription list
134 $test_subs = new ProspectList();
135 $test_subs->name = $focus->name.' '.$mod_strings['LBL_TEST_LIST'];
136 $test_subs->assigned_user_id= $current_user->id;
137 $test_subs->list_type = "test";
139 $focus->prospectlists->add($test_subs->id);
141 //save new relationships
144 }//finish newsletter processing
146 handleRedirect($focus->id, 'Campaigns');