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-2011 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 $unmatchedFields = $this->get_field_defs();
98 $matchedFields = $this->setMatchedFields($unmatchedFields);
99 $this->ss->assign('fields', $matchedFields);
101 // set up Smarty variables
102 $this->ss->assign('BEAN_ID', $this->bean->id);
103 $this->ss->assign('BEAN_NAME', $this->bean->name);
104 $this->ss->assign('MODULE', $this->module);
105 $this->ss->assign('MODULE_NAME', translate('LBL_MODULE_NAME',$this->module));
106 $this->ss->assign('DETAILS', $this->bean_details('WirelessDetailView'));
107 $this->ss->assign('ENABLE_FORM', $this->checkEditPermissions());
108 $this->ss->assign('LBL_GS_HELP', $GLOBALS['app_strings']['LBL_GS_HELP']);
110 // display the detail view
111 $this->ss->display('include/MVC/View/tpls/gsdetail.tpl');
116 protected function setMatchedFields($fields)
118 if($this->searchString == null)
121 foreach ($fields as &$field)
123 //Check if we have a search match and set the highlight flag
124 $matchReplace = $this->matchHitStart . '${0}' . $this->matchHitEnd;
125 if($field['name'] == 'email1' || $field['name'] == 'email2')
127 if(preg_match_all("/\<a.*?\>(.*?)\<\/a\>/is", $field['value'], $matches))
129 $aValue = $matches[1][0];
130 $aReplacedValue = preg_replace($this->searchRegex, $matchReplace, $aValue);
131 $newLink = preg_replace("/\<a(.*?)\>(.*?)\<\/a\>/i", "<a\${1}>{$aReplacedValue}<a>", $field['value']);
132 $field['value'] = $newLink;
134 } else if(isset($field['type']) && $field['type'] == 'phone') {
135 //Do a string replacement for phone fields since it may contain special characters
136 $matchReplace = $this->matchHitStart . $this->searchString . $this->matchHitEnd;
137 $field['value'] = str_replace($this->searchString, $matchReplace, $field['value']);
139 if (isset($field['type']) && $field['type'] == 'enum') //TODO: Handle enums since we are destroying the key.
144 $field['value'] = preg_replace($this->searchRegex, $matchReplace, $field['value']);
151 * Public function that attains the bean detail and sets up an array for
152 * Smarty consumption.
154 public function bean_details($view)
157 require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
159 // traverse through the wirelessviewdefs metadata to get the fields and values
160 $bean_details = array();
162 foreach($this->searchFields as $field){
163 // handle empty assigned_user_name
164 if(empty($this->bean->assigned_user_name)) {
165 if(!empty($this->bean->assigned_user_id)){
166 $this->bean->assigned_user_name = get_assigned_user_name($this->bean->assigned_user_id);
168 $this->bean->assigned_user_name = $GLOBALS['current_user']->user_name;
171 // handle empty team_name
172 if(empty($this->bean->team_name)) {
173 if(!empty($this->bean->team_id)){
174 $this->bean->team_name = Team::getTeamName($this->bean->team_id);
176 $this->bean->team_name = $GLOBALS['current_user']->default_team_name;
180 $field_info = $this->setup_detail_field($field);
182 if (is_array($field_info)){
183 if (is_array($field)){
184 $field = $field['name'];
186 $bean_details[$field] = $field_info;
190 return $bean_details;