3 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 require_once('include/SugarWireless/SugarWirelessView.php');
41 require_once('include/DetailView/DetailView2.php');
43 class ViewGS extends SugarWirelessView
45 private $searchFields;
46 private $searchString;
48 private $matchHitStart = "<span class='searchHighlight'>";
49 private $matchHitEnd = "</span>";
51 public function ViewGS()
53 $this->searchString = empty($_REQUEST['q']) ? null : $_REQUEST['q'];
54 $this->searchRegex = '/' . $this->searchString . '/i';
55 $this->options['show_title'] = false;
56 $this->options['show_header'] = false;
57 $this->options['show_footer'] = false;
58 $this->options['show_javascript'] = false;
59 $this->options['show_subpanels'] = false;
60 $this->options['show_search'] = false;
65 private function _getGlobalSearchFields()
68 foreach ( $this->bean->field_name_map as $fieldName => $entry)
70 if( isset($entry['unified_search']) && $entry['unified_search'] )
72 if($fieldName == 'email_addresses' || $fieldName == 'emails')
73 $results[] = 'email1';
75 $results[] = $fieldName;
83 $this->searchFields = $this->_getGlobalSearchFields();
88 * @see SugarView::display()
90 public function display()
92 // no record, we should also provide a way out
93 if (empty($this->bean->id)){
94 sugar_die($GLOBALS['app_strings']['ERROR_NO_RECORD']);
97 // set up Smarty variables
98 $this->ss->assign('BEAN_ID', $this->bean->id);
99 $this->ss->assign('BEAN_NAME', $this->bean->name);
100 $this->ss->assign('MODULE', $this->module);
101 $this->ss->assign('MODULE_NAME', translate('LBL_MODULE_NAME',$this->module));
103 //Get the fields to display
104 $detailFields = $this->bean_details('WirelessDetailView');
105 $this->ss->assign('DETAILS', $detailFields);
107 //Of the fields to display, highlight text based on match
108 $matchedFields = $this->setMatchedFields($detailFields);
109 $this->ss->assign('fields', $matchedFields);
111 $this->ss->assign('ENABLE_FORM', $this->checkEditPermissions());
112 $this->ss->assign('LBL_GS_HELP', $GLOBALS['app_strings']['LBL_GS_HELP']);
114 // display the detail view
115 $file = 'include/MVC/View/tpls/gsdetail.tpl';
117 if(file_exists('custom/'.$file))
119 $this->ss->display('custom/'.$file);
121 $this->ss->display($file);
126 protected function setMatchedFields($fields)
128 if($this->searchString == null)
134 foreach ($fields as &$field)
136 if($field['value'] == '')
141 //Check if we have a search match and set the highlight flag
142 $matchReplace = $this->matchHitStart . '${0}' . $this->matchHitEnd;
144 if(isset($field['name']) && ($field['name'] == 'email1' || $field['name'] == 'email2'))
146 if(preg_match_all("/\<a.*?\>(.*?)\<\/a\>/is", $field['value'], $matches))
148 $aValue = $matches[1][0];
149 $aReplacedValue = preg_replace($this->searchRegex, $matchReplace, $aValue);
150 $newLink = preg_replace("/\<a(.*?)\>(.*?)\<\/a\>/i", "<a\${1}>{$aReplacedValue}<a>", $field['value']);
151 $field['value'] = $newLink;
153 } else if(isset($field['type']) && $field['type'] == 'phone') {
154 //Do a string replacement for phone fields since it may contain special characters
155 $matchReplace = $this->matchHitStart . $this->searchString . $this->matchHitEnd;
156 $field['value'] = str_replace($this->searchString, $matchReplace, $field['value']);
158 if (isset($field['type']) && $field['type'] == 'enum') //TODO: Handle enums since we are destroying the key.
162 $field['value'] = preg_replace($this->searchRegex, $matchReplace, $field['value']);
169 * Public function that attains the bean detail and sets up an array for
170 * Smarty consumption.
172 public function bean_details($view)
175 require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
176 global $current_user;
178 // traverse through the wirelessviewdefs metadata to get the fields and values
179 $bean_details = array();
181 foreach($this->searchFields as $field)
183 // handle empty assigned_user_name
184 if(empty($this->bean->assigned_user_name)) {
185 if(!empty($this->bean->assigned_user_id)){
186 $this->bean->assigned_user_name = get_assigned_user_name($this->bean->assigned_user_id);
188 $this->bean->assigned_user_name = $GLOBALS['current_user']->user_name;
193 $field_info = $this->setup_detail_field($field);
195 if (is_array($field_info))
197 $name = is_array($field) ? $field['name'] : $field;
199 $bean_details[$name] = $field_info;
203 return $bean_details;