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