]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MVC/View/views/view.gs.php
Release 6.4.0
[Github/sugarcrm.git] / include / MVC / View / views / view.gs.php
1 <?php
2
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.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39
40 require_once('include/SugarWireless/SugarWirelessView.php');
41 require_once('include/DetailView/DetailView2.php');
42
43 class ViewGS extends SugarWirelessView
44 {
45     private $searchFields;
46     private $searchString;
47     private $searchRegex;
48     private $matchHitStart = "<span class='searchHighlight'>";
49     private $matchHitEnd = "</span>";
50
51     public function ViewGS()
52     {
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; 
61                 parent::SugarView();
62     }
63     
64     
65      private function _getGlobalSearchFields()
66      {
67          $results = array();
68          foreach ( $this->bean->field_name_map as $fieldName => $entry)
69          {
70              if( isset($entry['unified_search']) && $entry['unified_search'] )
71              {
72                  if($fieldName == 'email_addresses' || $fieldName == 'emails')
73                     $results[] = 'email1';
74                  else   
75                     $results[] = $fieldName;
76              }
77          }
78          return $results;     
79      }
80      
81      function preDisplay()
82      {
83         $this->searchFields = $this->_getGlobalSearchFields();
84                 
85         } 
86         
87     /**
88      * @see SugarView::display()
89      */
90     public function display()
91     {
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']);
95             }       
96
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));
102
103         //Get the fields to display
104         $detailFields = $this->bean_details('WirelessDetailView');
105                 $this->ss->assign('DETAILS', $detailFields);
106
107         //Of the fields to display, highlight text based on match
108             $matchedFields = $this->setMatchedFields($detailFields);
109                 $this->ss->assign('fields', $matchedFields);
110
111                 $this->ss->assign('ENABLE_FORM', $this->checkEditPermissions());
112                 $this->ss->assign('LBL_GS_HELP', $GLOBALS['app_strings']['LBL_GS_HELP']);
113                 
114                 // display the detail view
115         $file = 'include/MVC/View/tpls/gsdetail.tpl';
116
117         if(file_exists('custom/'.$file))
118         {
119             $this->ss->display('custom/'.$file);
120         } else {
121                     $this->ss->display($file);
122         }
123
124     }
125     
126     protected function setMatchedFields($fields)
127     {
128         if($this->searchString == null)
129         {
130             return $fields;
131         }
132
133
134         foreach ($fields as &$field)
135         {
136             if($field['value'] == '')
137             {
138                 continue;
139             }
140
141             //Check if we have a search match and set the highlight flag
142             $matchReplace = $this->matchHitStart . '${0}' . $this->matchHitEnd;
143
144             if(isset($field['name']) && ($field['name'] == 'email1' || $field['name'] == 'email2'))
145             {
146                 if(preg_match_all("/\<a.*?\>(.*?)\<\/a\>/is", $field['value'], $matches))
147                 {
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;
152                 }
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']);
157             } else {
158                 if (isset($field['type']) && $field['type'] == 'enum') //TODO: Handle enums since we are destroying the key.
159                 {
160                     continue;
161                 }
162                 $field['value'] = preg_replace($this->searchRegex, $matchReplace, $field['value']);
163             }
164         }
165
166         return $fields;
167     }
168    /**
169          * Public function that attains the bean detail and sets up an array for
170          * Smarty consumption.
171          */
172         public function bean_details($view)
173         {
174
175             require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
176         global $current_user;
177
178                 // traverse through the wirelessviewdefs metadata to get the fields and values
179                 $bean_details = array();
180
181                 foreach($this->searchFields as $field)
182             {
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);
187                                    }else{
188                        $this->bean->assigned_user_name = $GLOBALS['current_user']->user_name;
189                                    }
190                                 }
191
192                                 
193                                 $field_info = $this->setup_detail_field($field);
194
195                                 if (is_array($field_info))
196                 {
197                     $name = is_array($field) ? $field['name'] : $field;
198
199                                         $bean_details[$name] = $field_info;
200                                 }                               
201                 }
202         
203         return $bean_details;
204         }
205 }