]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Contacts/Popup_picker.php
Release 6.5.10
[Github/sugarcrm.git] / modules / Contacts / Popup_picker.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-2013 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 require_once('modules/Contacts/ContactFormBase.php');
40
41 class Popup_Picker
42 {
43         /*
44          *
45          */
46         function _get_where_clause()
47         {
48                 $where = '';
49                 if(isset($_REQUEST['query']))
50                 {
51                         $where_clauses = array();
52                         append_where_clause($where_clauses, "first_name", "contacts.first_name");
53                         append_where_clause($where_clauses, "last_name", "contacts.last_name");
54                         append_where_clause($where_clauses, "account_name", "accounts.name");
55                         append_where_clause($where_clauses, "account_id", "accounts.id");
56                         $where = generate_where_statement($where_clauses);
57                 }
58                 return $where;
59         }
60
61         /**
62          *
63          */
64         function process_page_for_address()
65         {
66                 global $theme;
67                 global $mod_strings;
68                 global $app_strings;
69                 global $currentModule;
70                 global $sugar_version, $sugar_config;
71
72                 $output_html = '';
73                 $where = '';
74
75                 $where = $this->_get_where_clause();
76
77
78                 $formBase = new ContactFormBase();
79                 if(isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save')
80                 {
81                         $formBase->handleSave('', false, true);
82                 }
83
84                 $first_name = empty($_REQUEST['first_name']) ? '' : $_REQUEST['first_name'];
85                 $last_name = empty($_REQUEST['last_name']) ? '' : $_REQUEST['last_name'];
86                 $account_name = empty($_REQUEST['account_name']) ? '' : $_REQUEST['account_name'];
87                 $request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data'];
88                 $hide_clear_button = empty($_REQUEST['hide_clear_button']) ? false : true;
89                 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
90                 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
91                 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
92
93                 // TODO: cleanup the construction of $addform
94                 $formbody = $formBase->getFormBody('','','EmailEditView');
95                 $addform = '<table><tr><td nowrap="nowrap" valign="top">'
96                         .str_replace('<br>', '</td><td nowrap="nowrap" valign="top">&nbsp;', $formbody)
97                         . '</td></tr></table>'
98                         . '<input type="hidden" name="action" value="Popup" />';
99                 $formSave = <<<EOQ
100                 <input type="submit" name="button" class="button" title="$lbl_save_button_title" value="  $lbl_save_button_label  " />
101                 <input type="button" name="button" class="button" title="{$app_strings['LBL_CANCEL_BUTTON_TITLE']}" accesskey="{$app_strings['LBL_CANCEL_BUTTON_KEY']}" value="{$app_strings['LBL_CANCEL_BUTTON_LABEL']}" onclick="toggleDisplay('addform');" />
102 EOQ;
103                 $createContact = <<<EOQ
104                 <input type="button" id="showAdd" name="showAdd" class="button" value="{$mod_strings['LNK_NEW_CONTACT']}" onclick="toggleDisplay('addform');" />
105 EOQ;
106                 $addformheader = get_form_header($mod_strings['LNK_NEW_CONTACT'], $formSave, false);
107                 $button  = "<form action='index.php' method='post' name='form' id='form'>\n";
108                 if(!$hide_clear_button)
109                 {
110                         $button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='"
111                                 .$app_strings['LBL_CLEAR_BUTTON_TITLE']."' value='  "
112                                 .$app_strings['LBL_CLEAR_BUTTON_LABEL']."  ' />\n";
113                 }
114                 $button .= "<input type='submit' name='button' class='button' onclick=\"window.close();\" title='"
115                         .$app_strings['LBL_CANCEL_BUTTON_TITLE']."' accesskey='"
116                         .$app_strings['LBL_CANCEL_BUTTON_KEY']."' value='  "
117                         .$app_strings['LBL_CANCEL_BUTTON_LABEL']."  ' />\n";
118                 $button .= "</form>\n";
119
120                 $form = new XTemplate('modules/Contacts/Address_picker.html');
121                 $form->assign('MOD', $mod_strings);
122                 $form->assign('APP', $app_strings);
123                 $form->assign('ADDFORMHEADER', $addformheader);
124                 $form->assign('ADDFORM', $addform);
125                 $form->assign('THEME', $theme);
126                 $form->assign('MODULE_NAME', $currentModule);
127                 $form->assign('FIRST_NAME', $first_name);
128                 $form->assign('LAST_NAME', $last_name);
129                 $form->assign('ACCOUNT_NAME', $account_name);
130                 $form->assign('request_data', $request_data);
131
132                 // fill in for mass update
133                 $button = "<input type='hidden' name='module' value='Contacts'>".
134                           "<input type='hidden' id='form_action' name='action' value='CloseContactAddressPopup'>".
135                           "<input type='hidden' name='massupdate' value='true'>".
136                           "<input type='hidden' name='delete' value='false'>".
137                           "<input type='hidden' name='mass' value='Array'>".
138                           "<input type='hidden' name='Update' value='Update'>";
139
140                 if(isset($_REQUEST['mass']) && is_array($_REQUEST['mass'])) {
141                         foreach(array_unique($_REQUEST['mass']) as $record) {
142                                 $button .= "<input style='display: none' checked type='checkbox' name='mass[]' value='$record'>\n";
143                         }
144                 }
145
146                 $button .= "<input type='hidden' name='query' value='true'>";
147                 $button .= "<input type='hidden' name='saved_associated_data' value=''>";
148                 $button .= "<input type='hidden' name='close_window' value='true'>";
149                 $button .= "<input type='hidden' name='html' value='change_address'>";
150                 $button .= "<input type='hidden' name='account_name' value='$account_name'>";
151         // Added ID attribute to each element to use getElementById. To give ID attribute to an element is a good practice.
152                 $button .= "<span style='display: none'><textarea name='primary_address_street' id='primary_address_street'>" . str_replace("&lt;br&gt;", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>";
153                 $button .= "<input type='hidden' name='primary_address_city' id='primary_address_city' value='". $_REQUEST["primary_address_city"] ."'>";
154                 $button .= "<input type='hidden' name='primary_address_state' id='primary_address_state' value='". $_REQUEST["primary_address_state"] ."'>";
155                 $button .= "<input type='hidden' name='primary_address_postalcode' id='primary_address_postalcode' value='". $_REQUEST["primary_address_postalcode"] ."'>";
156                 $button .= "<input type='hidden' name='primary_address_country' id='primary_address_country' value='". $_REQUEST["primary_address_country"] ."'>";
157                 // Adding an onclick event to remove address for alternate address, as user has selected copy address to primary address
158                 $button .= "<input title='".$mod_strings['LBL_COPY_ADDRESS_CHECKED_PRIMARY']."'  class='button' LANGUAGE=javascript type='submit' name='button' value='  ".$mod_strings['LBL_COPY_ADDRESS_CHECKED_PRIMARY']."  ' onclick='clearAddress(\"alt\");'>\n";
159                 // Adding a new block of code copy the address to alternate address for contacts
160                 $button .= "<span style='display: none'><textarea name='alt_address_street' id='alt_address_street'>" . str_replace("&lt;br&gt;", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>";
161                 $button .= "<input type='hidden' name='alt_address_city' id='alt_address_city' value='". $_REQUEST["primary_address_city"] ."'>";
162                 $button .= "<input type='hidden' name='alt_address_state' id='alt_address_state' value='". $_REQUEST["primary_address_state"] ."'>";
163                 $button .= "<input type='hidden' name='alt_address_postalcode' id='alt_address_postalcode' value='". $_REQUEST["primary_address_postalcode"] ."'>";
164                 $button .= "<input type='hidden' name='alt_address_country' id='alt_address_country' value='". $_REQUEST["primary_address_country"] ."'>";
165                 // Adding an onclick event to remove address for primary address, as user has selected copy address to alternate address
166                 // NOTE => You need to change the label as as per SugarCRM way..
167                 $button .= "<input title='".$mod_strings['LBL_COPY_ADDRESS_CHECKED_ALT']."'  class='button' LANGUAGE=javascript type='submit' name='button' value='  ".$mod_strings['LBL_COPY_ADDRESS_CHECKED_ALT']."  ' onclick='clearAddress(\"primary\");'>\n";
168                 $button .= "<input title='".$app_strings['LBL_CANCEL_BUTTON_TITLE']."' accessKey='".$app_strings['LBL_CANCEL_BUTTON_KEY']."' class='button' LANGUAGE=javascript onclick=\"window.close()\" type='submit' name='button' value='  ".$app_strings['LBL_CANCEL_BUTTON_LABEL']."  '>\n";
169                 ob_start();
170                 insert_popup_header($theme);
171                 $output_html .= ob_get_contents();
172                 ob_end_clean();
173
174                 // Reset the sections that are already in the page so that they do not print again later.
175                 $form->reset('main.SearchHeader');
176
177                 // create the listview
178                 $seed_bean = new Contact();
179                 $ListView = new ListView();
180                 $ListView->show_export_button = false;
181                 $ListView->process_for_popups = true;
182                 $ListView->show_delete_button = false;
183                 $ListView->show_select_menu = false;
184                 $ListView->setXTemplate($form);
185                 $ListView->setHeaderTitle($mod_strings['LBL_LIST_FORM_TITLE']);
186                 $ListView->setHeaderText($button);
187                 $ListView->setQuery($where, '', '', 'CONTACT');
188                 $ListView->setModStrings($mod_strings);
189
190                 ob_start();
191                 $ListView->processListViewMulti($seed_bean, 'main', 'CONTACT');
192                 $output_html .= ob_get_contents();
193                 ob_end_clean();
194
195         // Regular Expression to override sListView
196         $exp = '/sListView.save_checks/si';
197         $change = 'save_checks';
198         $output_html = preg_replace(array($exp), array($change), $output_html);
199
200                 $output_html .= <<<EOJS
201         <script type="text/javascript">
202         <!--
203         // Function to clear address according to the buttons clicked.
204         function clearAddress(key)
205         {
206             document.getElementById(key+"_address_street").value = "";
207             document.getElementById(key+"_address_city").value = "";
208             document.getElementById(key+"_address_state").value = "";
209             document.getElementById(key+"_address_postalcode").value = "";
210             document.getElementById(key+"_address_country").value = "";
211         }
212         checked_items = Array();
213         inputs_array = document.MassUpdate.elements;
214
215         for(wp = 0 ; wp < inputs_array.length; wp++) {
216             if(inputs_array[wp].name == "mass[]" && inputs_array[wp].style.display == "none") {
217                 checked_items.push(inputs_array[wp].value);
218             }
219         }
220         for(i in checked_items) {
221             for(wp = 0 ; wp < inputs_array.length; wp++) {
222                 if(inputs_array[wp].name == "mass[]" && inputs_array[wp].value == checked_items[i]) {
223                     inputs_array[wp].checked = true;
224                 }
225             }
226         }
227         -->
228         </script>
229 EOJS;
230
231                 $output_html .= insert_popup_footer();
232                 return $output_html;
233         }
234
235         function process_page_for_merge()
236         {
237                 global $theme;
238                 global $mod_strings;
239                 global $app_strings;
240                 global $currentModule;
241                 global $sugar_version, $sugar_config;
242
243                 $output_html = '';
244                 $where = '';
245
246                 $where = $this->_get_where_clause();
247
248                 $first_name = empty($_REQUEST['first_name']) ? '' : $_REQUEST['first_name'];
249                 $last_name = empty($_REQUEST['last_name']) ? '' : $_REQUEST['last_name'];
250                 $account_name = empty($_REQUEST['account_name']) ? '' : $_REQUEST['account_name'];
251                 $hide_clear_button = empty($_REQUEST['hide_clear_button']) ? false : true;
252                 $button  = "<form action='index.php' method='post' name='form' id='form'>\n";
253                 //START:FOR MULTI-SELECT
254                 $multi_select=false;
255                 if (!empty($_REQUEST['mode']) && strtoupper($_REQUEST['mode']) == 'MULTISELECT') {
256                         $multi_select=true;
257                         $button .= "<input type='button' name='button' class='button' onclick=\"send_back_selected('Contacts',document.MassUpdate,'mass[]','" .$app_strings['ERR_NOTHING_SELECTED']."');\" title='"
258                                 .$app_strings['LBL_SELECT_BUTTON_TITLE']."' accesskey='"
259                                 .$app_strings['LBL_SELECT_BUTTON_KEY']."' value='  "
260                                 .$app_strings['LBL_SELECT_BUTTON_LABEL']."  ' />\n";
261                 }
262                 //END:FOR MULTI-SELECT
263                 if(!$hide_clear_button)
264                 {
265                         $button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='"
266                                 .$app_strings['LBL_CLEAR_BUTTON_TITLE']."' value='  "
267                                 .$app_strings['LBL_CLEAR_BUTTON_LABEL']."  ' />\n";
268                 }
269                 $button .= "<input type='submit' name='button' class='button' onclick=\"window.close();\" title='"
270                         .$app_strings['LBL_CANCEL_BUTTON_TITLE']."' accesskey='"
271                         .$app_strings['LBL_CANCEL_BUTTON_KEY']."' value='  "
272                         .$app_strings['LBL_CANCEL_BUTTON_LABEL']."  ' />\n";
273                 $button .= "</form>\n";
274
275                 $form = new XTemplate('modules/Contacts/MailMergePicker.html');
276                 $form->assign('MOD', $mod_strings);
277                 $form->assign('APP', $app_strings);
278                 $form->assign('THEME', $theme);
279                 $form->assign('MODULE_NAME', $currentModule);
280                 $form->assign('FIRST_NAME', $first_name);
281                 $form->assign('LAST_NAME', $last_name);
282                 $form->assign('ACCOUNT_NAME', $account_name);
283                 $request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data'];
284                 $form->assign('request_data', $request_data);
285
286                 ob_start();
287                 insert_popup_header($theme);
288                 $output_html .= ob_get_contents();
289                 ob_end_clean();
290
291                 $output_html .= get_form_header($mod_strings['LBL_SEARCH_FORM_TITLE'], '', false);
292
293                 $form->parse('main.SearchHeader');
294                 $output_html .= $form->text('main.SearchHeader');
295
296                 // Reset the sections that are already in the page so that they do not print again later.
297                 $form->reset('main.SearchHeader');
298
299                 // create the listview
300                 $seed_bean = new Contact();
301                 $ListView = new ListView();
302                 $ListView->display_header_and_footer=false;
303                 $ListView->show_export_button = false;
304                 $ListView->process_for_popups = true;
305                 $ListView->setXTemplate($form);
306                 $ListView->multi_select_popup=$multi_select;
307                 if ($multi_select) $ListView->xTemplate->assign("TAG_TYPE","SPAN"); else  $ListView->xTemplate->assign("TAG_TYPE","A");
308                 $ListView->setHeaderTitle($mod_strings['LBL_LIST_FORM_TITLE']);
309                 $ListView->setQuery($where, '', 'contacts.last_name, contacts.first_name', 'CONTACT');
310                 $ListView->setModStrings($mod_strings);
311
312                 ob_start();
313                 $output_html .= get_form_header($mod_strings['LBL_LIST_FORM_TITLE'], $button, false);
314                                 //BEGIN ATHENA CUSTOMIZATION - rsmith
315         require_once('modules/MailMerge/merge_query.php');
316         $rel_module = empty($_REQUEST['rel_module'])?'': $_REQUEST['rel_module'];
317         $id = empty($_REQUEST['id'])?'': $_REQUEST['id'];
318
319                 $query = get_merge_query($seed_bean, $rel_module, $id);
320                 $result = $seed_bean->db->query($query,true,"Error retrieving $seed_bean->object_name list: ");
321
322                         $list = Array();
323                                 while(($row = $seed_bean->db->fetchByAssoc($result)) != null)
324                                 {
325                                                 $seed_bean = new Contact();
326                                                 foreach($seed_bean->field_defs as $field=>$value)
327                                                 {
328                                                         if (isset($row[$field]))
329                                                         {
330                                                                 $seed_bean->$field = $row[$field];
331                                                         }
332                                                         else if (isset($row[$seed_bean->table_name .'.'.$field]))
333                                                         {
334                                                                 $seed_bean->$field = $row[$seed_bean->table_name .'.'.$field];
335                                                         }
336                                                         else
337                                                         {
338                                                                 $seed_bean->$field = "";
339                                                         }
340                                                 }
341                                                 $seed_bean->fill_in_additional_list_fields();
342
343                                                 $list[] = $seed_bean;
344                                 }
345
346                         $ListView->processListViewTwo($list, 'main', 'CONTACT');
347
348                 //END ATHENA CUSTOMIZATION - rsmith
349                 $output_html .= ob_get_contents();
350                 ob_end_clean();
351
352                 $output_html .= insert_popup_footer();
353                 return $output_html;
354
355         }
356 }