]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/Subscriptions.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Campaigns / Subscriptions.php
1  <?php
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.
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:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 require_once('modules/Campaigns/utils.php');
47
48 global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
49 global $import_file_name, $theme;
50
51 $focus = 0;
52 if(isset($_REQUEST['return_module'])){
53     if($_REQUEST['return_module'] == 'Contacts'){
54         
55         $focus = new Contact();
56     }
57     if($_REQUEST['return_module'] == 'Leads'){
58         
59         $focus = new Lead();
60     }
61     if($_REQUEST['return_module'] == 'Prospects'){
62         
63         $focus = new Prospect();
64     }        
65 }
66
67 if(isset($_REQUEST['record'])) {
68     $GLOBALS['log']->debug("In Subscriptions, about to retrieve record: ".$_REQUEST['record']);
69     $result = $focus->retrieve($_REQUEST['record']);
70     if($result == null)
71     {
72         sugar_die($app_strings['ERROR_NO_RECORD']);
73     }
74 }
75
76
77 //echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME']." ".$mod_strings['LBL_STEP_3_TITLE'], true);
78 $this->ss->assign("MOD", $mod_strings);
79 $this->ss->assign("APP", $app_strings);
80
81 if(isset($_REQUEST['return_module'])){$this->ss->assign("RETURN_MODULE", $_REQUEST['return_module']);}
82 if(isset($_REQUEST['return_id'])){$this->ss->assign("RETURN_ID", $_REQUEST['return_id']);}
83 if(isset($_REQUEST['return_action'])){$this->ss->assign("RETURN_ACTION", $_REQUEST['return_action']);}
84 if(isset($_REQUEST['record'])){$this->ss->assign("RECORD", $_REQUEST['record']);}
85
86 //if subsaction has been set, then process subscriptions
87 if(isset($_REQUEST['subs_action'])){manageSubscriptions($focus);}
88
89 //$title = $GLOBALS['app_strings']['LBL_MANAGE_SUBSCRIPTIONS_FOR'].$focus->name;
90 $middleText = "<a href='index.php?module={$focus->module_dir}&action=index'>{$focus->module_dir}</a><span class='pointer'>&raquo;</span><a href='index.php?module={$focus->module_dir}&action=DetailView&record={$focus->id}'>{$focus->name}</a><span class='pointer'>&raquo;</span>{$mod_strings['LBL_MANAGE_SUBSCRIPTIONS_TITLE']}";
91 $title = get_module_title($focus->module_dir, $middleText, true);
92 $orig_vals_str = printOriginalValues($focus);    
93 $orig_vals_array = constructDDSubscriptionList($focus);
94
95 $this->ss->assign('APP', $GLOBALS['app_strings']);
96 $this->ss->assign('MOD', $GLOBALS['mod_strings']);
97 $this->ss->assign('title',  $title);
98
99 $this->ss->assign('enabled_subs', $orig_vals_array[0]);
100 $this->ss->assign('disabled_subs', $orig_vals_array[1]);
101 $this->ss->assign('enabled_subs_string', $orig_vals_str[0]);
102 $this->ss->assign('disabled_subs_string', $orig_vals_str[1]);
103
104 echo $this->ss->fetch('modules/Campaigns/Subscriptions.tpl');
105
106
107
108
109 /*
110  *This function constructs Drag and Drop multiselect box of subscriptions for display in manage subscription form  
111 */
112 function constructDDSubscriptionList($focus,$classname=''){
113 require_once("include/templates/TemplateDragDropChooser.php");    
114 global $mod_strings;
115 $unsubs_arr = ''; 
116 $subs_arr =  '';
117
118 // Lets start by creating the subscription and unsubscription arrays 
119     $subscription_arrays = get_subscription_lists($focus);
120     $unsubs_arr = $subscription_arrays['unsubscribed']; 
121     $subs_arr =  $subscription_arrays['subscribed'];
122
123     $comb_array = array();
124         $comb_array [0] = array();
125         $comb_array [1] = array();
126
127     foreach ($subs_arr as $key=>$val){
128         $comb_array [0][$val] = $key;
129     }    
130
131         
132         foreach ($unsubs_arr as $key=>$val){
133         $comb_array [1][$val] = $key;
134     }
135
136     return $comb_array ;  
137        
138 }
139
140
141
142 /*
143  *This function constructs multiselect box of subscriptions for display in manage subscription form  
144 */
145 function printOriginalValues($focus){
146     global $app_strings;
147     $unsubs_arr = ''; 
148     $subs_arr =  '';
149     $return_arr =  '';
150         
151      // Lets start by creating the subscription and unsubscription arrays 
152         $subscription_arrays = get_subscription_lists($focus);
153         $unsubs_arr = $subscription_arrays['unsubscribed']; 
154         $subs_arr =  $subscription_arrays['subscribed'];
155     
156 //    ORIG_UNSUBS_VALUES
157         $unsubs_vals = ' ';
158         $subs_vals = ' ';
159         foreach($subs_arr as $name => $id){
160             $subs_vals .= ", $id";
161         }
162         $return_arr[]=$subs_vals;
163
164         foreach($unsubs_arr as $name => $id){
165             $unsubs_vals .= ", $id";
166         }
167
168         $return_arr[]=$unsubs_vals;
169
170         return $return_arr;        
171     }
172     
173
174 /*
175  * Perform Subscription management work.  This function processes selected subscriptions and calls the
176  * right methods to subscribe or unsubscribe the user
177  * */
178
179 function manageSubscriptions($focus){
180
181
182     //Process Subscription Lists first
183     //compare current list of subscriptions to original list and see if there are any additions
184     $orig_subscription_arr = array();
185     $curr_subscription_arr = array();
186     //build array of original subscriptions
187     if(isset($_REQUEST['orig_enabled_values'])  && ! empty($_REQUEST['orig_enabled_values'])){
188      $orig_subscription_arr = explode(",", $_REQUEST['orig_enabled_values']);
189      $orig_subscription_arr = process_subscriptions($orig_subscription_arr);   
190     }        
191
192     //build array of current subscriptions
193     if(isset($_REQUEST['enabled_subs'])  && ! empty($_REQUEST['enabled_subs'])){
194      $curr_subscription_arr = explode(",", $_REQUEST['enabled_subs']);
195      $curr_subscription_arr = process_subscriptions($curr_subscription_arr);   
196     }        
197
198     //compare both arrays and find differences
199     $i=0;
200     while($i<(count($curr_subscription_arr)/2)){    
201         //if current subscription existed in original subscription list, do nothing
202         if(in_array($curr_subscription_arr['campaign'.$i], $orig_subscription_arr)){
203             //nothing to process
204         }else{
205          //current subscription is new, so subscribe
206             subscribe($curr_subscription_arr['campaign'.$i], $curr_subscription_arr['prospect_list'.$i], $focus);
207         }
208         $i = $i +1;   
209     }        
210
211     //Now process UnSubscription Lists first
212     //compare current list of subscriptions to original list and see if there are any additions
213     $orig_unsubscription_arr = array();
214     $curr_unsubscription_arr = array();
215
216     //build array of original subscriptions
217     if(isset($_REQUEST['orig_disabled_values'])  && ! empty($_REQUEST['orig_disabled_values'])){
218      $orig_unsubscription_arr = explode(",", $_REQUEST['orig_disabled_values']);
219      $orig_unsubscription_arr = process_subscriptions($orig_unsubscription_arr);   
220     }        
221
222     //build array of current subscriptions
223     if(isset($_REQUEST['disabled_subs'])  && ! empty($_REQUEST['disabled_subs'])){
224      $curr_unsubscription_arr = explode(",", $_REQUEST['disabled_subs']);
225      $curr_unsubscription_arr = process_subscriptions($curr_unsubscription_arr);   
226     }        
227     //compare both arrays and find differences
228     $i=0;
229     while($i<(count($curr_unsubscription_arr)/2)){    
230         //if current subscription existed in original subscription list, do nothing
231         if(in_array($curr_unsubscription_arr['campaign'.$i], $orig_unsubscription_arr)){
232             //nothing to process
233         }else{
234          //current subscription is new, so subscribe
235             unsubscribe($curr_unsubscription_arr['campaign'.$i], $focus);
236         }
237         $i = $i +1;   
238     }
239     
240 }
241
242 ?>