]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MailMerge/Step4.php
Release 6.5.0
[Github/sugarcrm.git] / modules / MailMerge / Step4.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-2012 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  * Created on Oct 4, 2005
40  *
41  * To change the template for this generated file go to
42  * Window - Preferences - PHPeclipse - PHP - Code Templates
43  */
44
45
46
47
48
49
50
51
52 global $app_strings;
53 global $app_list_strings;
54 global $mod_strings;
55 global $current_user;
56 global $locale;
57
58 $xtpl = new XTemplate('modules/MailMerge/Step4.html');
59 $xtpl->assign("MOD", $mod_strings);
60 $xtpl->assign("APP", $app_strings);
61
62 if(!empty($_POST['document_id']))
63 {
64         $_SESSION['MAILMERGE_DOCUMENT_ID'] = $_POST['document_id'];
65 }
66 $document_id = $_SESSION['MAILMERGE_DOCUMENT_ID'];
67 $revision = new DocumentRevision();
68 $revision->retrieve($document_id);
69 //$document = new Document();
70 //$document->retrieve($document_id);
71
72 if(!empty($_POST['selected_objects']))
73 {
74         $selObjs = urldecode($_POST['selected_objects']);
75         $_SESSION['SELECTED_OBJECTS_DEF'] = $selObjs;
76 }
77 $selObjs = $_SESSION['SELECTED_OBJECTS_DEF'];
78 $sel_obj = array();
79
80 parse_str(stripslashes(html_entity_decode($selObjs, ENT_QUOTES)),$sel_obj);
81 foreach($sel_obj as $key=>$value)
82 {
83         $sel_obj[$key] = stripslashes($value);
84 }
85 $relArray = array();
86 //build relationship array
87 foreach($sel_obj as $key=>$value)
88 {
89         $id = 'rel_id_'.str_replace('-', '', $key);     
90         if(isset($_POST[$id]) && !empty($_POST[$id]))
91         {
92                 $relArray[$key] = $_POST[$id];  
93         }
94 }
95
96
97 $builtArray = array();
98 if(count($relArray) > 0)
99 {
100 $_SESSION['MAILMERGE_RELATED_CONTACTS'] = $relArray;
101
102 $relModule = $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'];
103 global $beanList, $beanFiles;
104 $class_name = $beanList[$relModule ];
105 require_once($beanFiles[$class_name]);
106
107         $seed = new $class_name();
108         foreach($sel_obj as $key=>$value)
109         {       
110                 $builtArray[$key] = $value;
111                 if(isset($relArray[$key]))
112                 {
113                         $seed->retrieve($relArray[$key]);
114                         $name = "";
115                         if($relModule  == "Contacts"){
116                                 $name = $locale->getLocaleFormattedName($seed->first_name,$seed->last_name);
117                         }
118                         else{
119                                 $name = $seed->name;
120                         }
121                                 $builtArray[$key] = str_replace('##', '&', $value)." (".$name.")";
122                 }
123         }
124
125 }
126 else
127 {
128         $builtArray = $sel_obj; 
129 }
130
131 $xtpl->assign("MAILMERGE_MODULE", $_SESSION['MAILMERGE_MODULE']);
132 $xtpl->assign("MAILMERGE_DOCUMENT_ID", $document_id);
133 $xtpl->assign("MAILMERGE_TEMPLATE", $revision->filename." (rev. ".$revision->revision.")");
134 $xtpl->assign("MAILMERGE_SELECTED_OBJECTS", get_select_options_with_id($builtArray,'0'));
135 $xtpl->assign("MAILMERGE_SELECTED_OBJECTS_DEF", urlencode($selObjs));
136 $step_num = 4;
137
138 if(isset($_SESSION['MAILMERGE_SKIP_REL']) && $_SESSION['MAILMERGE_SKIP_REL'] || !isset($_SESSION['MAILMERGE_RELATED_CONTACTS']) || empty($_SESSION['MAILMERGE_RELATED_CONTACTS']))
139 {
140         $xtpl->assign("PREV_STEP", "2");
141         $step_num = 3;
142 }
143 else
144 {
145         $xtpl->assign("PREV_STEP", "3");
146 }
147         
148 $xtpl->assign("STEP_NUM", "Step ".$step_num.":");
149
150 $xtpl->parse("main");
151 $xtpl->out("main");
152
153 ?>