]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MailMerge/Step2.php
Release 6.4.0
[Github/sugarcrm.git] / modules / MailMerge / Step2.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-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
41 /*
42  * Created on Oct 4, 2005
43  *
44  * To change the template for this generated file go to
45  * Window - Preferences - PHPeclipse - PHP - Code Templates
46  */
47
48
49
50 //require_once('include/utils.php');
51 require_once('include/json_config.php');
52 $json_config = new json_config();
53
54 global $app_strings;
55 global $app_list_strings;
56 global $mod_strings;
57 global $current_user;
58 global $theme;
59 global $sugar_version, $sugar_config;
60
61
62
63 $xtpl = new XTemplate('modules/MailMerge/Step2.html');
64 $xtpl->assign("MOD", $mod_strings);
65 $xtpl->assign("APP", $app_strings);
66 $xtpl->assign('JSON_CONFIG_JAVASCRIPT', $json_config->get_static_json_server(false, true));
67
68 if(isset($_POST['mailmerge_module']))
69 {
70         $_SESSION['MAILMERGE_MODULE'] = $_POST['mailmerge_module'];     
71     if($_SESSION['MAILMERGE_MODULE'] == 'Campaigns'){
72         $_SESSION['MAILMERGE_MODULE'] = 'CampaignProspects';
73     }
74         if($_SESSION['MAILMERGE_MODULE'] == 'Contacts' || $_SESSION['MAILMERGE_MODULE'] == 'Leads'|| $_SESSION['MAILMERGE_MODULE'] == 'CampaignProspects')
75         {
76                 
77                 $_SESSION['MAILMERGE_SKIP_REL'] = true;
78         }
79 }
80
81 $step_txt = "Step 2: ";
82 if(!empty($_SESSION['SELECTED_OBJECTS_DEF'])){
83         $selObjs = $_SESSION['SELECTED_OBJECTS_DEF'];
84         $sel_obj = array();
85         parse_str($selObjs,$sel_obj);
86         $idArray = array();
87         $_SESSION['MAILMERGE_WHERE'] = "";
88         foreach($sel_obj as $key => $value){
89                 $value = str_replace("##", "&", $value);
90                 $idArray[$key] = $value;
91         if($_SESSION['MAILMERGE_MODULE'] == 'CampaignProspects'){
92             if(isset($_POST['mailmerge_module']) && $_POST['mailmerge_module'] == 'Campaigns'){
93                 $where = "campaigns.id = '$key'";
94                 $_SESSION['MAILMERGE_WHERE'] = $where;
95                 $_SESSION['MAILMERGE_CAMPAIGN_ID'] = $key;
96                 $idArray = array();
97                 break; 
98             }   
99         }
100         }
101                    
102     $xtpl->assign("MAILMERGE_WHERE", $_SESSION['MAILMERGE_WHERE']); 
103         $xtpl->assign("MAILMERGE_PRESELECTED_OBJECTS", get_select_options_with_id($idArray, '0'));
104         $step_txt .= "Refine list of ".$_SESSION['MAILMERGE_MODULE']." to merge.";
105         $xtpl->assign("MAILMERGE_GET_OBJECTS", 0);
106 }
107 else
108 {
109         $step_txt .= "Select list of ".$_SESSION['MAILMERGE_MODULE']." to merge.";
110         $xtpl->assign("MAILMERGE_GET_OBJECTS", 1);
111 }
112
113 if(isset($_SESSION['MAILMERGE_SKIP_REL']) && $_SESSION['MAILMERGE_SKIP_REL'])
114 {
115         $xtpl->assign("STEP", "4");     
116         
117 }
118 else
119 {
120
121         $selected = '';
122         if(isset($_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO']) && $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO']){
123                 $selected = $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'];       
124         }
125         $xtpl->assign("STEP", "3");     
126         //$xtpl->assign("MAIL_MERGE_CONTAINS_CONTACT_INFO", '<table><tr><td><input id="contains_contact_info" name="contains_contact_info" class="checkbox" type="checkbox" '.$checked.'/></td><td>'.$mod_strings['LBL_CONTAINS_CONTACT_INFO'].'</td></tr></table>');
127         $rel_options = array(""=>"--None--");
128         $seed = loadBean($_SESSION['MAILMERGE_MODULE']);
129         if($seed->load_relationship('contacts')){
130                 $rel_options["Contacts"] = "Contacts";
131         }
132         if($_SESSION['MAILMERGE_MODULE'] == "Accounts"){
133                 $rel_options["Opportunities"] = "Opportunities";
134         }
135         elseif($_SESSION['MAILMERGE_MODULE'] == "Opportunities"){
136                 $rel_options["Accounts"] = "Accounts";
137         }
138         $xtpl->assign("MAIL_MERGE_CONTAINS_CONTACT_INFO", '<table><tr><td>'.$mod_strings['LBL_CONTAINS_CONTACT_INFO'].'</td><td><select id="contains_contact_info" name="contains_contact_info">'.get_select_options_with_id($rel_options, $selected).'</select></td></tr></table>');
139 }
140
141 $xtpl->assign("MAILMERGE_MODULE", $_SESSION['MAILMERGE_MODULE']);
142 $xtpl->assign("MAILMERGE_PREV", SugarThemeRegistry::current()->getImage('previous','border="0" style="margin-left: 1px;" id="prevItems" onClick="decreaseOffset();getObjects();"',null,null,'.gif',$mod_strings['LBL_BACK']));
143 $xtpl->assign("MAILMERGE_NEXT", SugarThemeRegistry::current()->getImage('next','border="0" style="margin-left: 1px;" alt="Next" id="nextItems" onClick="increaseOffset();getObjects();"',null,null,'.gif',$mod_strings['LBL_NEXT']));
144 $xtpl->assign("MAILMERGE_RIGHT_TO_LEFT", SugarThemeRegistry::current()->getImage('leftarrow_big','border="0" style="margin-left: 1px;"  onClick="moveLeft();"',null,null,'.gif',$mod_strings['LBL_REMOVE']));
145 $xtpl->assign("MAILMERGE_LEFT_TO_RIGHT", SugarThemeRegistry::current()->getImage('rightarrow_big','border="0" style="margin-left: 1px;" onClick="moveRight();"',null,null,'.gif',$mod_strings['LBL_ADD']));
146 $xtpl->assign("MAIL_MERGE_HEADER_STEP_2", $step_txt);
147 if($_SESSION['MAILMERGE_MODULE'] == 'CampaignProspects'){
148     $rel_options = array("Contacts"=>"Contacts", "Leads" => "Leads", "Prospects" => "Prospects", "Users"=>"Users");
149     $xtpl->assign("MAIL_MERGE_CAMPAIGN_PROSPECT_SELECTOR", '<select id="campaign_prospect_type" name="campaign_prospect_type">'.get_select_options_with_id($rel_options, 'Prospects').'</select>');
150         
151 }
152
153 if(!empty($_POST['document_id']))
154 {
155         $_SESSION['MAILMERGE_DOCUMENT_ID'] = $_POST['document_id'];
156 }
157
158
159 $xtpl->parse("main");
160 $xtpl->out("main");
161
162 function displaySelectionBox($objectList)
163 {
164         $html = '<select id="display_objs" name="display_objs[]" size="10" multiple="multiple" size="10" >';
165         foreach($objectList as $key=>$value)
166         {
167                 $html .= '<option value="'.$key.'">'.$value.'</option>';
168         }
169         $html .= '</select>';
170         return $html;
171 }
172
173 ?>