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.
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 ********************************************************************************/
39 * Created on Oct 4, 2005
41 * To change the template for this generated file go to
42 * Window - Preferences - PHPeclipse - PHP - Code Templates
48 require_once('modules/MailMerge/modules_array.php');
51 require_once('include/json_config.php');
52 $json_config = new json_config();
55 global $app_list_strings;
58 global $beanList, $beanFiles;
59 global $sugar_version, $sugar_config, $db;
61 $xtpl = new XTemplate('modules/MailMerge/Step1.html');
62 $xtpl->assign("MOD", $mod_strings);
63 $xtpl->assign("APP", $app_strings);
64 $xtpl->assign('JSON_CONFIG_JAVASCRIPT', $json_config->get_static_json_server(false, true));
66 if($_SESSION['MAILMERGE_MODULE'] == 'Campaigns' || $_SESSION['MAILMERGE_MODULE'] == 'CampaignProspects'){
67 $modules_array['Campaigns'] = 'Campaigns';
69 $module_list = $modules_array;
71 if(isset($_REQUEST['reset']) && $_REQUEST['reset'])
73 $_SESSION['MAILMERGE_MODULE'] = null;
74 $_SESSION['MAILMERGE_DOCUMENT_ID'] = null;
75 $_SESSION['SELECTED_OBJECTS_DEF'] = null;
76 $_SESSION['MAILMERGE_SKIP_REL'] = null;
77 $_SESSION['MAILMERGE_RECORD'] = null;
78 $_SESSION['MAILMERGE_RECORDS'] = null;
79 $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'] = null;
81 $fromListView = false;
82 if(!empty($_REQUEST['record']))
84 $_SESSION['MAILMERGE_RECORD'] = $_REQUEST['record'];
86 else if(isset($_REQUEST['uid'])) {
87 $_SESSION['MAILMERGE_RECORD'] = explode(',', $_REQUEST['uid']);
90 else if(isset($_REQUEST['entire']) && $_REQUEST['entire'] == 'true') {
94 $bean = $beanList[ $_SESSION['MAILMERGE_MODULE']];
95 require_once($beanFiles[$bean]);
98 if(isset($_SESSION['export_where']) && !empty($_SESSION['export_where'])) { // bug 4679
99 $where = $_SESSION['export_where'];
103 $beginWhere = substr(trim($where), 0, 5);
104 if ($beginWhere == "where")
105 $where = substr(trim($where), 5, strlen($where));
107 $query = $focus->create_export_query($orderBy,$where);
109 $result = $db->query($query,true,"Error mail merging {$_SESSION['MAILMERGE_MODULE']}: "."<BR>$query");
112 while($val = $db->fetchByAssoc($result,false))
114 array_push($new_arr, $val['id']);
116 $_SESSION['MAILMERGE_RECORD'] = $new_arr;
118 else if(isset($_SESSION['MAILMERGE_RECORDS']))
121 $fromListView = true;
122 $_SESSION['MAILMERGE_RECORD'] = $_SESSION['MAILMERGE_RECORDS'];
123 $_SESSION['MAILMERGE_RECORDS'] = null;
126 if(isset($_SESSION['MAILMERGE_RECORD']))
128 if(!empty($_POST['return_module']) && $_POST['return_module'] != "MailMerge")
130 $rModule = $_POST['return_module'];
132 else if($fromListView)
134 $rModule = $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'];
135 $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = null;
139 $rModule = $_SESSION['MAILMERGE_MODULE'];
141 if($rModule == 'CampaignProspects'){
142 $rModule = 'Campaigns';
145 $_SESSION['MAILMERGE_MODULE'] = $rModule;
146 if(!empty($rModule) && $rModule != "MailMerge")
148 $class_name = $beanList[$rModule];
149 $includedir = $beanFiles[$class_name];
150 require_once($includedir);
151 $seed = new $class_name();
153 $selected_objects = '';
154 foreach($_SESSION['MAILMERGE_RECORD'] as $record_id)
156 if($rModule == 'Campaigns'){
158 $prospect = new Prospect();
159 $prospect_module_list = array('leads', 'contacts', 'prospects', 'users');
160 foreach($prospect_module_list as $mname){
161 $pList = $prospect->retrieveTargetList("campaigns.id = '$record_id' AND related_type = #$mname#", array('id', 'first_name', 'last_name'));
163 foreach($pList['list'] as $bean){
164 $selected_objects .= $bean->id.'='.str_replace("&", "##", $bean->name).'&';
168 $seed->retrieve($record_id);
169 $selected_objects .= $record_id.'='.str_replace("&", "##", $seed->name).'&';
174 if($rModule != 'Contacts'
175 && $rModule != 'Leads' && $rModule != 'Products' && $rModule != 'Campaigns' && $rModule != 'Projects'
178 $_SESSION['MAILMERGE_SKIP_REL'] = false;
179 $xtpl->assign("STEP", "2");
180 $xtpl->assign("SELECTED_OBJECTS", $selected_objects);
181 $_SESSION['SELECTED_OBJECTS_DEF'] = $selected_objects;
185 $_SESSION['MAILMERGE_SKIP_REL'] = true;
186 $xtpl->assign("STEP", "2");
187 $_SESSION['SELECTED_OBJECTS_DEF'] = $selected_objects;
192 $xtpl->assign("STEP", "2");
198 $xtpl->assign("STEP", "2");
200 $modules = $module_list;
202 if($rModule == 'Campaigns'){
203 $func = "disableModuleDropDown();";
205 $xtpl->assign("MAILMERGE_DISABLE_DROP_DOWN", $func);
206 $xtpl->assign("MAILMERGE_MODULE_OPTIONS", get_select_options_with_id($modules, $_SESSION['MAILMERGE_MODULE']));
207 $xtpl->assign("MAILMERGE_TEMPLATES", get_select_options_with_id(getDocumentRevisions(), '0'));
209 if(isset($_SESSION['MAILMERGE_MODULE'])){
210 $module_select_text = $mod_strings['LBL_MAILMERGE_SELECTED_MODULE'];
211 $xtpl->assign("MAILMERGE_NUM_SELECTED_OBJECTS",count($_SESSION['MAILMERGE_RECORD'])." ".$_SESSION['MAILMERGE_MODULE']." Selected");
214 $module_select_text = $mod_strings['LBL_MAILMERGE_MODULE'];
216 $xtpl->assign("MODULE_SELECT", $module_select_text);
217 if($_SESSION['MAILMERGE_MODULE'] == 'Campaigns'){
218 $_SESSION['MAILMERGE_MODULE'] = 'CampaignProspects';
221 $admin = new Administration();
222 $admin->retrieveSettings();
223 $user_merge = $current_user->getPreference('mailmerge_on');
224 if ($user_merge != 'on' || !isset($admin->settings['system_mailmerge_on']) || !$admin->settings['system_mailmerge_on']){
225 $xtpl->assign("ADDIN_NOTICE", $mod_strings['LBL_ADDIN_NOTICE']);
226 $xtpl->assign("DISABLE_NEXT_BUTTON", "disabled");
230 $xtpl->parse("main");
233 /*function get_user_module_list($user){
234 global $app_list_strings, $current_language;
235 $app_list_strings = return_app_list_strings_language($current_language);
236 $modules = query_module_access_list($user);
237 global $modInvisList;
242 function getDocumentRevisions()
244 $document = new Document();
246 $currentDate = $document->db->now();
247 $empty_date = $document->db->emptyValue("date");
249 $query = "SELECT revision, document_name, document_revisions.id FROM document_revisions
250 LEFT JOIN documents on documents.id = document_revisions.document_id
251 WHERE ((active_date <= $currentDate AND exp_date > $currentDate)
252 OR (active_date is NULL) or (active_date = ".$empty_date.")
253 OR (active_date <= $currentDate AND ((exp_date = $empty_date OR (exp_date is NULL)))))
254 AND is_template = 1 AND template_type = 'mailmerge' AND documents.deleted = 0 ORDER BY document_name";
256 $result = $document->db->query($query,true,"Error retrieving $document->object_name list: ");
259 $list['None'] = 'None';
260 while(($row = $document->db->fetchByAssoc($result)) != null)
263 $docName = $row['document_name'];
264 $revision = $row['revision'];
265 if(!empty($revision));
267 $docName .= " (rev. ".$revision.")";
269 $list[$row['id']] = $docName;