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 ********************************************************************************/
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));
106 $query = $focus->create_export_query($order_by,$where);
108 $result = $db->query($query,true,"Error mail merging {$_SESSION['MAILMERGE_MODULE']}: "."<BR>$query");
111 while($val = $db->fetchByAssoc($result,-1,false))
113 array_push($new_arr, $val['id']);
115 $_SESSION['MAILMERGE_RECORD'] = $new_arr;
117 else if(isset($_SESSION['MAILMERGE_RECORDS']))
120 $fromListView = true;
121 $_SESSION['MAILMERGE_RECORD'] = $_SESSION['MAILMERGE_RECORDS'];
122 $_SESSION['MAILMERGE_RECORDS'] = null;
125 if(isset($_SESSION['MAILMERGE_RECORD']))
127 if(!empty($_POST['return_module']) && $_POST['return_module'] != "MailMerge")
129 $rModule = $_POST['return_module'];
131 else if($fromListView)
133 $rModule = $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'];
134 $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = null;
138 $rModule = $_SESSION['MAILMERGE_MODULE'];
140 if($rModule == 'CampaignProspects'){
141 $rModule = 'Campaigns';
144 $_SESSION['MAILMERGE_MODULE'] = $rModule;
145 if(!empty($rModule) && $rModule != "MailMerge")
147 $class_name = $beanList[$rModule];
148 $includedir = $beanFiles[$class_name];
149 require_once($includedir);
150 $seed = new $class_name();
152 $selected_objects = '';
153 foreach($_SESSION['MAILMERGE_RECORD'] as $record_id)
155 if($rModule == 'Campaigns'){
157 $prospect = new Prospect();
158 $prospect_module_list = array('leads', 'contacts', 'prospects', 'users');
159 foreach($prospect_module_list as $mname){
160 $pList = $prospect->retrieveTargetList("campaigns.id = '$record_id' AND related_type = #$mname#", array('id', 'first_name', 'last_name'));
162 foreach($pList['list'] as $bean){
163 $selected_objects .= $bean->id.'='.str_replace("&", "##", $bean->name).'&';
167 $seed->retrieve($record_id);
168 $selected_objects .= $record_id.'='.str_replace("&", "##", $seed->name).'&';
173 if($rModule != 'Contacts'
174 && $rModule != 'Leads' && $rModule != 'Products' && $rModule != 'Campaigns' && $rModule != 'Projects'
177 $_SESSION['MAILMERGE_SKIP_REL'] = false;
178 $xtpl->assign("STEP", "2");
179 $xtpl->assign("SELECTED_OBJECTS", $selected_objects);
180 $_SESSION['SELECTED_OBJECTS_DEF'] = $selected_objects;
184 $_SESSION['MAILMERGE_SKIP_REL'] = true;
185 $xtpl->assign("STEP", "2");
186 $_SESSION['SELECTED_OBJECTS_DEF'] = $selected_objects;
191 $xtpl->assign("STEP", "2");
197 $xtpl->assign("STEP", "2");
199 $modules = $module_list;
201 if($rModule == 'Campaigns'){
202 $func = "disableModuleDropDown();";
204 $xtpl->assign("MAILMERGE_DISABLE_DROP_DOWN", $func);
205 $xtpl->assign("MAILMERGE_MODULE_OPTIONS", get_select_options_with_id($modules, $_SESSION['MAILMERGE_MODULE']));
206 $xtpl->assign("MAILMERGE_TEMPLATES", get_select_options_with_id(getDocumentRevisions(), '0'));
208 if(isset($_SESSION['MAILMERGE_MODULE'])){
209 $module_select_text = $mod_strings['LBL_MAILMERGE_SELECTED_MODULE'];
210 $xtpl->assign("MAILMERGE_NUM_SELECTED_OBJECTS",count($_SESSION['MAILMERGE_RECORD'])." ".$_SESSION['MAILMERGE_MODULE']." Selected");
213 $module_select_text = $mod_strings['LBL_MAILMERGE_MODULE'];
215 $xtpl->assign("MODULE_SELECT", $module_select_text);
216 if($_SESSION['MAILMERGE_MODULE'] == 'Campaigns'){
217 $_SESSION['MAILMERGE_MODULE'] = 'CampaignProspects';
220 $admin = new Administration();
221 $admin->retrieveSettings();
222 $user_merge = $current_user->getPreference('mailmerge_on');
223 if ($user_merge != 'on' || !isset($admin->settings['system_mailmerge_on']) || !$admin->settings['system_mailmerge_on']){
224 $xtpl->assign("ADDIN_NOTICE", $mod_strings['LBL_ADDIN_NOTICE']);
225 $xtpl->assign("DISABLE_NEXT_BUTTON", "disabled");
229 $xtpl->parse("main");
232 function get_user_module_list($user){
233 global $app_list_strings, $current_language;
234 $app_list_strings = return_app_list_strings_language($current_language);
235 $modules = query_module_access_list($user);
236 global $modInvisList, $modInvisListActivities;
238 if(isset($modules['Calendar']) || $modules['Activities']){
239 foreach($modInvisListActivities as $invis){
240 $modules[$invis] = $invis;
247 function getDocumentRevisions()
249 $document = new Document();
251 $currentDate = gmdate($GLOBALS['timedate']->get_db_date_time_format());
252 if ($document->db->dbType=="mysql") {
253 $empty_date=db_convert("'0000-00-00'", 'datetime');
256 $empty_date=db_convert("'1970-01-01 00:00:00'", 'datetime');
259 $query = "SELECT revision, document_name, document_revisions.id FROM document_revisions
260 LEFT JOIN documents on documents.id = document_revisions.document_id WHERE ((active_date <= ".db_convert("'".$currentDate."'", 'datetime')." AND exp_date > ".db_convert("'".$currentDate."'", 'datetime').") OR (active_date is NULL) or (active_date = ".$empty_date.") or (active_date <= ".db_convert("'".$currentDate."'", 'datetime')." AND ((exp_date = ".$empty_date.") OR (exp_date is NULL)))) AND is_template = 1 AND template_type = 'mailmerge' AND documents.deleted = 0 ORDER BY document_name";
262 $result = $document->db->query($query,true,"Error retrieving $document->object_name list: ");
265 $list['None'] = 'None';
266 while(($row = $document->db->fetchByAssoc($result)) != null)
269 $docName = $row['document_name'];
270 $revision = $row['revision'];
271 if(!empty($revision));
273 $docName .= " (rev. ".$revision.")";
275 $list[$row['id']] = $docName;