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 ********************************************************************************/
44 require_once('modules/Contacts/ContactFormBase.php');
59 function Popup_Picker()
67 function _get_where_clause()
70 if(isset($_REQUEST['query']))
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);
85 function process_page_for_address()
90 global $currentModule;
91 global $sugar_version, $sugar_config;
96 $where = $this->_get_where_clause();
99 $formBase = new ContactFormBase();
100 if(isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save')
102 $formBase->handleSave('', false, true);
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'];
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"> ', $formbody)
118 . '</td></tr></table>'
119 . '<input type="hidden" name="action" value="Popup" />';
121 <input type="submit" name="button" class="button" title="$lbl_save_button_title" 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');" />
124 $createContact = <<<EOQ
125 <input type="button" id="showAdd" name="showAdd" class="button" value="{$mod_strings['LNK_NEW_CONTACT']}" onclick="toggleDisplay('addform');" />
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)
131 $button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='"
132 .$app_strings['LBL_CLEAR_BUTTON_TITLE']."' value=' "
133 .$app_strings['LBL_CLEAR_BUTTON_LABEL']." ' />\n";
135 $button .= "<input type='submit' name='button' class='button' onclick=\"window.close();\" title='"
136 .$app_strings['LBL_CANCEL_BUTTON_TITLE']."' accesskey='"
137 .$app_strings['LBL_CANCEL_BUTTON_KEY']."' value=' "
138 .$app_strings['LBL_CANCEL_BUTTON_LABEL']." ' />\n";
139 $button .= "</form>\n";
141 $form = new XTemplate('modules/Contacts/Address_picker.html');
142 $form->assign('MOD', $mod_strings);
143 $form->assign('APP', $app_strings);
144 $form->assign('ADDFORMHEADER', $addformheader);
145 $form->assign('ADDFORM', $addform);
146 $form->assign('THEME', $theme);
147 $form->assign('MODULE_NAME', $currentModule);
148 $form->assign('FIRST_NAME', $first_name);
149 $form->assign('LAST_NAME', $last_name);
150 $form->assign('ACCOUNT_NAME', $account_name);
151 $form->assign('request_data', $request_data);
153 // fill in for mass update
154 $button = "<input type='hidden' name='module' value='Contacts'>".
155 "<input type='hidden' id='form_action' name='action' value='CloseContactAddressPopup'>".
156 "<input type='hidden' name='massupdate' value='true'>".
157 "<input type='hidden' name='delete' value='false'>".
158 "<input type='hidden' name='mass' value='Array'>".
159 "<input type='hidden' name='Update' value='Update'>";
161 if(isset($_REQUEST['mass']) && is_array($_REQUEST['mass'])) {
162 foreach(array_unique($_REQUEST['mass']) as $record) {
163 $button .= "<input style='display: none' checked type='checkbox' name='mass[]' value='$record'>\n";
167 $button .= "<input type='hidden' name='query' value='true'>";
168 $button .= "<input type='hidden' name='saved_associated_data' value=''>";
169 $button .= "<input type='hidden' name='close_window' value='true'>";
170 $button .= "<input type='hidden' name='html' value='change_address'>";
171 $button .= "<input type='hidden' name='account_name' value='$account_name'>";
172 // Added ID attribute to each element to use getElementById. To give ID attribute to an element is a good practice.
173 $button .= "<span style='display: none'><textarea name='primary_address_street' id='primary_address_street'>" . str_replace("<br>", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>";
174 $button .= "<input type='hidden' name='primary_address_city' id='primary_address_city' value='". $_REQUEST["primary_address_city"] ."'>";
175 $button .= "<input type='hidden' name='primary_address_state' id='primary_address_state' value='". $_REQUEST["primary_address_state"] ."'>";
176 $button .= "<input type='hidden' name='primary_address_postalcode' id='primary_address_postalcode' value='". $_REQUEST["primary_address_postalcode"] ."'>";
177 $button .= "<input type='hidden' name='primary_address_country' id='primary_address_country' value='". $_REQUEST["primary_address_country"] ."'>";
178 // Adding an onclick event to remove address for alternate address, as user has selected copy address to primary address
179 $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";
180 // Adding a new block of code copy the address to alternate address for contacts
181 $button .= "<span style='display: none'><textarea name='alt_address_street' id='alt_address_street'>" . str_replace("<br>", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>";
182 $button .= "<input type='hidden' name='alt_address_city' id='alt_address_city' value='". $_REQUEST["primary_address_city"] ."'>";
183 $button .= "<input type='hidden' name='alt_address_state' id='alt_address_state' value='". $_REQUEST["primary_address_state"] ."'>";
184 $button .= "<input type='hidden' name='alt_address_postalcode' id='alt_address_postalcode' value='". $_REQUEST["primary_address_postalcode"] ."'>";
185 $button .= "<input type='hidden' name='alt_address_country' id='alt_address_country' value='". $_REQUEST["primary_address_country"] ."'>";
186 // Adding an onclick event to remove address for primary address, as user has selected copy address to alternate address
187 // NOTE => You need to change the label as as per SugarCRM way..
188 $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";
189 $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";
191 insert_popup_header($theme);
192 $output_html .= ob_get_contents();
195 // Reset the sections that are already in the page so that they do not print again later.
196 $form->reset('main.SearchHeader');
198 // create the listview
199 $seed_bean = new Contact();
200 $ListView = new ListView();
201 $ListView->show_export_button = false;
202 $ListView->process_for_popups = true;
203 $ListView->show_delete_button = false;
204 $ListView->show_select_menu = false;
205 $ListView->setXTemplate($form);
206 $ListView->setHeaderTitle($mod_strings['LBL_LIST_FORM_TITLE']);
207 $ListView->setHeaderText($button);
208 $ListView->setQuery($where, '', '', 'CONTACT');
209 $ListView->setModStrings($mod_strings);
212 $ListView->processListViewMulti($seed_bean, 'main', 'CONTACT');
213 $output_html .= ob_get_contents();
216 // Regular Expression to override sListView
217 $exp = '/sListView.save_checks/si';
218 $change = 'save_checks';
219 $output_html = preg_replace(array($exp), array($change), $output_html);
221 $output_html .= <<<EOJS
222 <script type="text/javascript">
224 // Function to clear address according to the buttons clicked.
225 function clearAddress(key)
227 document.getElementById(key+"_address_street").value = "";
228 document.getElementById(key+"_address_city").value = "";
229 document.getElementById(key+"_address_state").value = "";
230 document.getElementById(key+"_address_postalcode").value = "";
231 document.getElementById(key+"_address_country").value = "";
233 checked_items = Array();
234 inputs_array = document.MassUpdate.elements;
236 for(wp = 0 ; wp < inputs_array.length; wp++) {
237 if(inputs_array[wp].name == "mass[]" && inputs_array[wp].style.display == "none") {
238 checked_items.push(inputs_array[wp].value);
241 for(i in checked_items) {
242 for(wp = 0 ; wp < inputs_array.length; wp++) {
243 if(inputs_array[wp].name == "mass[]" && inputs_array[wp].value == checked_items[i]) {
244 inputs_array[wp].checked = true;
252 $output_html .= insert_popup_footer();
256 function process_page_for_merge()
261 global $currentModule;
262 global $sugar_version, $sugar_config;
267 $where = $this->_get_where_clause();
271 $first_name = empty($_REQUEST['first_name']) ? '' : $_REQUEST['first_name'];
272 $last_name = empty($_REQUEST['last_name']) ? '' : $_REQUEST['last_name'];
273 $account_name = empty($_REQUEST['account_name']) ? '' : $_REQUEST['account_name'];
274 $hide_clear_button = empty($_REQUEST['hide_clear_button']) ? false : true;
275 $button = "<form action='index.php' method='post' name='form' id='form'>\n";
276 //START:FOR MULTI-SELECT
278 if (!empty($_REQUEST['mode']) && strtoupper($_REQUEST['mode']) == 'MULTISELECT') {
280 $button .= "<input type='button' name='button' class='button' onclick=\"send_back_selected('Contacts',document.MassUpdate,'mass[]','" .$app_strings['ERR_NOTHING_SELECTED']."');\" title='"
281 .$app_strings['LBL_SELECT_BUTTON_TITLE']."' accesskey='"
282 .$app_strings['LBL_SELECT_BUTTON_KEY']."' value=' "
283 .$app_strings['LBL_SELECT_BUTTON_LABEL']." ' />\n";
285 //END:FOR MULTI-SELECT
286 if(!$hide_clear_button)
288 $button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='"
289 .$app_strings['LBL_CLEAR_BUTTON_TITLE']."' value=' "
290 .$app_strings['LBL_CLEAR_BUTTON_LABEL']." ' />\n";
292 $button .= "<input type='submit' name='button' class='button' onclick=\"window.close();\" title='"
293 .$app_strings['LBL_CANCEL_BUTTON_TITLE']."' accesskey='"
294 .$app_strings['LBL_CANCEL_BUTTON_KEY']."' value=' "
295 .$app_strings['LBL_CANCEL_BUTTON_LABEL']." ' />\n";
296 $button .= "</form>\n";
298 $form = new XTemplate('modules/Contacts/MailMergePicker.html');
299 $form->assign('MOD', $mod_strings);
300 $form->assign('APP', $app_strings);
301 $form->assign('THEME', $theme);
302 $form->assign('MODULE_NAME', $currentModule);
303 $form->assign('FIRST_NAME', $first_name);
304 $form->assign('LAST_NAME', $last_name);
305 $form->assign('ACCOUNT_NAME', $account_name);
306 $request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data'];
307 $form->assign('request_data', $request_data);
310 insert_popup_header($theme);
311 $output_html .= ob_get_contents();
314 $output_html .= get_form_header($mod_strings['LBL_SEARCH_FORM_TITLE'], '', false);
316 $form->parse('main.SearchHeader');
317 $output_html .= $form->text('main.SearchHeader');
319 // Reset the sections that are already in the page so that they do not print again later.
320 $form->reset('main.SearchHeader');
322 // create the listview
323 $seed_bean = new Contact();
324 $ListView = new ListView();
325 $ListView->display_header_and_footer=false;
326 $ListView->show_export_button = false;
327 $ListView->process_for_popups = true;
328 $ListView->setXTemplate($form);
329 $ListView->multi_select_popup=$multi_select;
330 if ($multi_select) $ListView->xTemplate->assign("TAG_TYPE","SPAN"); else $ListView->xTemplate->assign("TAG_TYPE","A");
331 $ListView->setHeaderTitle($mod_strings['LBL_LIST_FORM_TITLE']);
332 $ListView->setQuery($where, '', 'contacts.last_name, contacts.first_name', 'CONTACT');
333 $ListView->setModStrings($mod_strings);
336 $output_html .= get_form_header($mod_strings['LBL_LIST_FORM_TITLE'], $button, false);
337 //BEGIN ATHENA CUSTOMIZATION - rsmith
338 $query = $_REQUEST['select'].' WHERE '.$_REQUEST['where']."'".$_REQUEST['id']."'";
340 //$response = $seed_bean->process_list_query($_REQUEST['select'], 0, -1, -1, $_REQUEST['where']."'".$_REQUEST['id']."'");
342 $result = $seed_bean->db->query($query,true,"Error retrieving $seed_bean->object_name list: ");
345 while(($row = $seed_bean->db->fetchByAssoc($result)) != null)
347 $seed_bean = new Contact();
348 foreach($seed_bean->field_defs as $field=>$value)
350 if (isset($row[$field]))
352 $seed_bean->$field = $row[$field];
354 else if (isset($row[$seed_bean->table_name .'.'.$field]))
356 $seed_bean->$field = $row[$seed_bean->table_name .'.'.$field];
360 $seed_bean->$field = "";
363 $seed_bean->fill_in_additional_list_fields();
365 $list[] = $seed_bean;
368 $ListView->processListViewTwo($list, 'main', 'CONTACT');
370 //END ATHENA CUSTOMIZATION - rsmith
371 $output_html .= ob_get_contents();
374 $output_html .= insert_popup_footer();