]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/ListView/ListViewData.php
Release 6.1.4
[Github/sugarcrm.git] / include / ListView / ListViewData.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 require_once('include/EditView/SugarVCR.php');
40 class ListViewData {
41         var $additionalDetails = true;
42     var $listviewName = null;
43         var $additionalDetailsAllow = null;
44     var $additionalDetailsAjax = true; // leave this true when using filter fields
45     var $additionalDetailsFieldToAdd = 'NAME'; // where the span will be attached to
46     var $base_url = null;
47     /*
48      * If you want overwrite the query for the count of the listview set this to your query
49      * otherwise leave it empty and it will use SugarBean::create_list_count_query
50      */
51     var $count_query = '';
52
53         /**
54          * Constructor sets the limitName to look up the limit in $sugar_config
55          *
56          * @return ListViewData
57          */
58         function ListViewData() {
59                 $this->limitName = 'list_max_entries_per_page';
60                 $this->db = &DBManagerFactory::getInstance('listviews');
61         }
62
63         /**
64          * checks the request for the order by and if that is not set then it checks the session for it
65          *
66          * @return array containing the keys orderBy => field being ordered off of and sortOrder => the sort order of that field
67          */
68         function getOrderBy($orderBy = '', $direction = '') {
69                 if (!empty($orderBy) || !empty($_REQUEST[$this->var_order_by])) {
70             if(!empty($_REQUEST[$this->var_order_by])) {
71                         $direction = 'ASC';
72                         $orderBy = $_REQUEST[$this->var_order_by];
73                         if(!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0) ){
74                                 $direction = $_REQUEST['lvso'];
75
76                                     $trackerManager = TrackerManager::getInstance();
77                                         if($monitor = $trackerManager->getMonitor('tracker')){
78                                         $monitor->setValue('module_name', $GLOBALS['module']);
79                                         $monitor->setValue('item_summary', "lvso=".$direction."&".$this->var_order_by."=".$_REQUEST[$this->var_order_by]);
80                                         $monitor->setValue('action', 'listview');
81                                                 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
82                                                 $monitor->setValue('date_modified', gmdate($GLOBALS['timedate']->get_db_date_time_format()));
83                                         $monitor->save();
84                                         }
85                         }
86             }
87             $_SESSION[$this->var_order_by] = array('orderBy'=>$orderBy, 'direction'=> $direction);
88             $_SESSION['lvd']['last_ob'] = $orderBy;
89         }
90                 else {
91                         if(!empty($_SESSION[$this->var_order_by])) {
92                                 $orderBy = $_SESSION[$this->var_order_by]['orderBy'];
93                                 $direction = $_SESSION[$this->var_order_by]['direction'];
94                         }
95                         else{
96                                 $orderBy = 'date_entered';
97                                 $direction = 'DESC';
98                         }
99                 }
100                 return array('orderBy' => $orderBy, 'sortOrder' => $direction);
101         }
102
103         /**
104          * gets the reverse of the sort order for use on links to reverse a sort order from what is currently used
105          *
106          * @param STRING (ASC or DESC) $current_order
107          * @return  STRING (ASC or DESC)
108          */
109         function getReverseSortOrder($current_order){
110                 return (strcmp(strtolower($current_order), 'asc') == 0)?'DESC':'ASC';
111         }
112         /**
113          * gets the limit of how many rows to show per page
114          *
115          * @return INT (the limit)
116          */
117         function getLimit() {
118                 return $GLOBALS['sugar_config'][$this->limitName];
119         }
120
121         /**
122          * returns the current offset
123          *
124          * @return INT (current offset)
125          */
126         function getOffset() {
127                 return (!empty($_REQUEST[$this->var_offset])) ? $_REQUEST[$this->var_offset] : 0;
128         }
129
130         /**
131          * generates the base url without
132          * any files in the block variables will not be part of the url
133          *
134          *
135          * @return STRING (the base url)
136          */
137         function getBaseURL() {
138         global $beanList;
139                 if(empty($this->base_url)) {
140             $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount',$this->var_order_by, $this->var_offset, 'lvso', 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page');
141             $base_url = 'index.php?';
142             foreach($beanList as $bean) {
143                 $blockVariables[] = 'Home2_'.strtoupper($bean).'_ORDER_BY';
144             }
145             $blockVariables[] = 'Home2_CASE_ORDER_BY';
146
147             $params = array();
148             if ( isset($_POST) && is_array($_POST) ) {
149                 $params = array_merge($params,$_POST);
150             }
151             if ( isset($_GET) && is_array($_GET) ) {
152                 $params = array_merge($params,$_GET);
153             }
154             foreach($params as $name=>$value) {
155                 if(!in_array($name, $blockVariables)){ 
156                                         if(is_array($value)) {
157                                                 foreach($value as $v) {
158                             $base_url .= $name.urlencode('[]').'='.urlencode($v) . '&';
159                         }
160                     }
161                     else {
162                                                 $base_url .= $name.'='.urlencode($value) . '&';
163                     }
164                 }
165             }
166             $this->base_url = $base_url;
167         }
168                 return $this->base_url;
169         }
170         /**
171          * based off of a base name it sets base, offset, and order by variable names to retrieve them from requests and sessions
172          *
173          * @param unknown_type $baseName
174          */
175         function setVariableName($baseName, $where, $listviewName = null){
176         global $timedate;
177         $module = (!empty($listviewName)) ? $listviewName: $_REQUEST['module'];
178         $this->var_name = $module .'2_'. strtoupper($baseName);
179
180                 $this->var_order_by = $this->var_name .'_ORDER_BY';
181                 $this->var_offset = $this->var_name . '_offset';
182         $timestamp = sugar_microtime();
183         $this->stamp = $timestamp;
184
185         $_SESSION[$module .'2_QUERY_QUERY'] = $where;
186
187         $_SESSION[strtoupper($baseName) . "_FROM_LIST_VIEW"] = $timestamp;
188         $_SESSION[strtoupper($baseName) . "_DETAIL_NAV_HISTORY"] = false;
189         }
190
191         function getTotalCount($main_query){
192                 if(!empty($this->count_query)){
193                     $count_query = $this->count_query;
194                 }else{
195                 $count_query = SugarBean::create_list_count_query($main_query);
196             }
197                 $result = $this->db->query($count_query);
198                 if($row = $this->db->fetchByAssoc($result)){
199                         return $row['c'];
200                 }
201                 return 0;
202         }
203
204         /**
205          * takes in a seed and creates the list view query based off of that seed
206          * if the $limit value is set to -1 then it will use the default limit and offset values
207          *
208          * it will return an array with two key values
209          *      1. 'data'=> this is an array of row data
210          *  2. 'pageData'=> this is an array containg three values
211          *                      a.'ordering'=> array('orderBy'=> the field being ordered by , 'sortOrder'=> 'ASC' or 'DESC')
212          *                      b.'urls'=>array('baseURL'=>url used to generate other urls ,
213          *                                                      'orderBy'=> the base url for order by
214          *                                                      //the following may not be set (so check empty to see if they are set)
215          *                                                      'nextPage'=> the url for the next group of results,
216          *                                                      'prevPage'=> the url for the prev group of results,
217          *                                                      'startPage'=> the url for the start of the group,
218          *                                                      'endPage'=> the url for the last set of results in the group
219          *                      c.'offsets'=>array(
220          *                                                              'current'=>current offset
221          *                                                              'next'=> next group offset
222          *                                                              'prev'=> prev group offset
223          *                                                              'end'=> the offset of the last group
224          *                                                              'total'=> the total count (only accurate if totalCounted = true otherwise it is either the total count if less than the limit or the total count + 1 )
225          *                                                              'totalCounted'=> if a count query was used to get the total count
226          *
227          * @param SugarBean $seed
228          * @param string $where
229          * @param int:0 $offset
230          * @param int:-1 $limit
231          * @param string[]:array() $filter_fields
232          * @param array:array() $params
233          *      Potential $params are
234                 $params['distinct'] = use distinct key word
235                 $params['include_custom_fields'] = (on by default)
236         $params['custom_XXXX'] = append custom statements to query
237          * @param string:'id' $id_field
238          * @return array('data'=> row data 'pageData' => page data information
239          */
240         function getListViewData($seed, $where, $offset=-1, $limit = -1, $filter_fields=array(),$params=array(),$id_field = 'id') {
241         global $current_user;
242         SugarVCR::erase($seed->module_dir);
243         $this->seed =& $seed;
244         $totalCounted = empty($GLOBALS['sugar_config']['disable_count_query']);
245         $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = $seed->module_dir;
246         if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup'){
247             $_SESSION['MAILMERGE_MODULE'] = $seed->module_dir;
248         }
249
250         $this->setVariableName($seed->object_name, $where, $this->listviewName);
251
252                 $this->seed->id = '[SELECT_ID_LIST]';
253
254         // if $params tell us to override all ordering
255         if(!empty($params['overrideOrder']) && !empty($params['orderBy'])) {
256             $order = $this->getOrderBy(strtolower($params['orderBy']), (empty($params['sortOrder']) ? '' : $params['sortOrder'])); // retreive from $_REQUEST
257         }
258         else {
259             $order = $this->getOrderBy(); // retreive from $_REQUEST
260         }
261
262         // else use stored preference
263         $userPreferenceOrder = $current_user->getPreference('listviewOrder', $this->var_name);
264
265         if(empty($order['orderBy']) && !empty($userPreferenceOrder)) {
266             $order = $userPreferenceOrder;
267         }
268         // still empty? try to use settings passed in $param
269         if(empty($order['orderBy']) && !empty($params['orderBy'])) {
270             $order['orderBy'] = $params['orderBy'];
271             $order['sortOrder'] =  (empty($params['sortOrder']) ? '' : $params['sortOrder']);
272         }
273
274         //rrs - bug: 21788. Do not use Order by stmts with fields that are not in the query.
275         // Bug 22740 - Tweak this check to strip off the table name off the order by parameter.
276         // Samir Gandhi : Do not remove the report_cache.date_modified condition as the report list view is broken
277         $orderby = $order['orderBy'];
278         if (strpos($order['orderBy'],'.') && ($order['orderBy'] != "report_cache.date_modified"))
279             $orderby = substr($order['orderBy'],strpos($order['orderBy'],'.')+1);
280         if($orderby != 'date_entered' && !in_array($orderby, array_keys($filter_fields))){
281                 $order['orderBy'] = '';
282                 $order['sortOrder'] = '';
283         }
284
285                 if(empty($order['orderBy'])) {
286             $orderBy = '';
287         }
288                 else {
289             $orderBy = $order['orderBy'] . ' ' . $order['sortOrder'];
290             //wdong, Bug 25476, fix the sorting problem of Oracle.
291             if (isset($params['custom_order_by_override']['ori_code']) && $order['orderBy'] == $params['custom_order_by_override']['ori_code'])
292                 $orderBy = $params['custom_order_by_override']['custom_code'] . ' ' . $order['sortOrder'];
293         }
294
295         if(empty($params['skipOrderSave'])) // don't save preferences if told so
296             $current_user->setPreference('listviewOrder', $order, 0, $this->var_name); // save preference
297                 $ret_array = $seed->create_new_list_query($orderBy, $where, $filter_fields, $params, 0, '', true, $seed, true);
298         $ret_array['inner_join'] = '';
299         if(!empty($this->seed->listview_inner_join)) {
300             $ret_array['inner_join'] = ' ' . implode(' ', $this->seed->listview_inner_join) . ' ';
301         }
302
303                 if(!is_array($params)) $params = array();
304         if(!isset($params['custom_select'])) $params['custom_select'] = '';
305         if(!isset($params['custom_from'])) $params['custom_from'] = '';
306         if(!isset($params['custom_where'])) $params['custom_where'] = '';
307         if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
308                 $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
309                 //C.L. - Fix for 23461
310                 if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') {
311                    $_SESSION['export_where'] = $ret_array['where'];
312                 }
313                 if($limit < -1) {
314                         $result = $this->db->query($main_query);
315                 }
316                 else {
317                         if($limit == -1) {
318                                 $limit = $this->getLimit();
319             }
320                         $dyn_offset = $this->getOffset();
321                         if($dyn_offset > 0 || !is_int($dyn_offset))$offset = $dyn_offset;
322
323             if(strcmp($offset, 'end') == 0){
324                 $totalCount = $this->getTotalCount($main_query);
325                 $offset = (floor(($totalCount -1) / $limit)) * $limit;
326             }
327             if($this->seed->ACLAccess('ListView')) {
328                 $result = $this->db->limitQuery($main_query, $offset, $limit + 1);
329             }
330             else {
331                 $result = array();
332             }
333
334                 }
335
336                 $data = array();
337
338                 $temp = clone $seed;
339
340                 $rows = array();
341                 $count = 0;
342         $idIndex = array();
343         $id_list = '';
344                 while($row = $this->db->fetchByAssoc($result)) {
345                         if($count < $limit) {
346                                 if(!empty($id_list)) {
347                                         $id_list = '(';
348                                 }else{
349                                         $id_list .= ',';
350                                 }
351                                 $id_list .= '\''.$row[$id_field].'\'';
352                                 //handles date formating and such
353                                 $idIndex[$row[$id_field]][] = count($rows);
354                                 $rows[] = $row;
355                         }
356                         $count++;
357                 }
358                 if (!empty($id_list)) $id_list .= ')';
359
360         SugarVCR::store($this->seed->module_dir,  $main_query);
361                 if($count != 0) {
362                         //NOW HANDLE SECONDARY QUERIES
363                         if(!empty($ret_array['secondary_select'])) {
364                                 $secondary_query = $ret_array['secondary_select'] . $ret_array['secondary_from'] . ' WHERE '.$this->seed->table_name.'.id IN ' .$id_list;
365                                 $secondary_result = $this->db->query($secondary_query);
366                                 while($row = $this->db->fetchByAssoc($secondary_result)) {
367                                         foreach($row as $name=>$value) {
368                                                 //add it to every row with the given id
369                                                 foreach($idIndex[$row['ref_id']] as $index){
370                                                     $rows[$index][$name]=$value;
371                                                 }
372
373                                         }
374                                 }
375                         }
376
377             // retrieve parent names
378             if(!empty($filter_fields['parent_name']) && !empty($filter_fields['parent_id']) && !empty($filter_fields['parent_type'])) {
379                 foreach($idIndex as $id => $rowIndex) {
380                     if(!isset($post_retrieve[$rows[$rowIndex[0]]['parent_type']])) {
381                         $post_retrieve[$rows[$rowIndex[0]]['parent_type']] = array();
382                     }
383                     if(!empty($rows[$rowIndex[0]]['parent_id'])) $post_retrieve[$rows[$rowIndex[0]]['parent_type']][] = array('child_id' => $id , 'parent_id'=> $rows[$rowIndex[0]]['parent_id'], 'parent_type' => $rows[$rowIndex[0]]['parent_type'], 'type' => 'parent');
384                 }
385                 if(isset($post_retrieve)) {
386                     $parent_fields = $seed->retrieve_parent_fields($post_retrieve);
387                     foreach($parent_fields as $child_id => $parent_data) {
388                         //add it to every row with the given id
389                                                 foreach($idIndex[$child_id] as $index){
390                                                     $rows[$index]['parent_name']= $parent_data['parent_name'];
391                                                 }
392                     }
393                 }
394             }
395
396                         $pageData = array();
397
398                         $additionalDetailsAllow = $this->additionalDetails && $this->seed->ACLAccess('DetailView') && (file_exists('modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php') || file_exists('custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'));
399             if($additionalDetailsAllow) $pageData['additionalDetails'] = array();
400                         $additionalDetailsEdit = $this->seed->ACLAccess('EditView');
401             reset($rows);
402                         while($row = current($rows)){
403                 $temp = clone $seed;
404                             $dataIndex = count($data);
405
406                             $temp->setupCustomFields($temp->module_dir);
407                                 $temp->loadFromRow($row);
408                                 if($idIndex[$row[$id_field]][0] == $dataIndex){
409                                     $pageData['tag'][$dataIndex] = $temp->listviewACLHelper();
410                                 }else{
411                                     $pageData['tag'][$dataIndex] = $pageData['tag'][$idIndex[$row[$id_field]][0]];
412                                 }
413                                 $data[$dataIndex] = $temp->get_list_view_data($filter_fields);
414                             if($additionalDetailsAllow) {
415                     if($this->additionalDetailsAjax) {
416                                            $ar = $this->getAdditionalDetailsAjax($data[$dataIndex]['ID']);
417                     }
418                     else {
419                         $additionalDetailsFile = 'modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php';
420                         if(file_exists('custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php')){
421                                 $additionalDetailsFile = 'custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php';
422                         }
423                         require_once($additionalDetailsFile);
424                         $ar = $this->getAdditionalDetails($data[$dataIndex],
425                                     (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction) . $this->seed->object_name,
426                                     $additionalDetailsEdit);
427                     }
428                     $pageData['additionalDetails'][$dataIndex] = $ar['string'];
429                     $pageData['additionalDetails']['fieldToAddTo'] = $ar['fieldToAddTo'];
430                                 }
431                                 next($rows);
432                         }
433                 }
434                 $nextOffset = -1;
435                 $prevOffset = -1;
436                 $endOffset = -1;
437                 if($count > $limit) {
438                         $nextOffset = $offset + $limit;
439                 }
440
441                 if($offset > 0) {
442                         $prevOffset = $offset - $limit;
443                         if($prevOffset < 0)$prevOffset = 0;
444                 }
445                 $totalCount = $count + $offset;
446
447                 if( $count >= $limit && $totalCounted){
448                         $totalCount  = $this->getTotalCount($main_query);
449                 }
450                 SugarVCR::recordIDs($this->seed->module_dir, array_keys($idIndex), $offset, $totalCount);
451                 $endOffset = (floor(($totalCount - 1) / $limit)) * $limit;
452                 $pageData['ordering'] = $order;
453                 $pageData['ordering']['sortOrder'] = $this->getReverseSortOrder($pageData['ordering']['sortOrder']);
454                 $pageData['urls'] = $this->generateURLS($pageData['ordering']['sortOrder'], $offset, $prevOffset, $nextOffset,  $endOffset, $totalCounted);
455                 $pageData['offsets'] = array( 'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted);
456                 $pageData['bean'] = array('objectName' => $seed->object_name, 'moduleDir' => $seed->module_dir);
457         $pageData['stamp'] = $this->stamp;
458         $pageData['access'] = array('view' => $this->seed->ACLAccess('DetailView'), 'edit' => $this->seed->ACLAccess('EditView'));
459                 $pageData['idIndex'] = $idIndex;
460         if(!$this->seed->ACLAccess('ListView')) {
461             $pageData['error'] = 'ACL restricted access';
462         }
463
464                 return array('data'=>$data , 'pageData'=>$pageData);
465         }
466
467
468         /**
469          * generates urls for use by the display  layer
470          *
471          * @param int $sortOrder
472          * @param int $offset
473          * @param int $prevOffset
474          * @param int $nextOffset
475          * @param int $endOffset
476          * @param int $totalCounted
477          * @return array of urls orderBy and baseURL are always returned the others are only returned  according to values passed in.
478          */
479         function generateURLS($sortOrder, $offset, $prevOffset, $nextOffset, $endOffset, $totalCounted) {
480                 $urls = array();
481                 $urls['baseURL'] = $this->getBaseURL(). 'lvso=' . $sortOrder. '&';
482                 $urls['orderBy'] = $urls['baseURL'] .$this->var_order_by.'=';
483
484                 $dynamicUrl = '';
485                 if($nextOffset > -1) {
486                         $urls['nextPage'] = $urls['baseURL'] . $this->var_offset . '=' . $nextOffset . $dynamicUrl;
487                 }
488                 if($offset > 0) {
489                         $urls['startPage'] = $urls['baseURL'] . $this->var_offset . '=0' . $dynamicUrl;
490                 }
491                 if($prevOffset > -1) {
492                         $urls['prevPage'] = $urls['baseURL'] . $this->var_offset . '=' . $prevOffset . $dynamicUrl;
493                 }
494                 if($totalCounted) {
495                         $urls['endPage'] = $urls['baseURL'] . $this->var_offset . '=' . $endOffset . $dynamicUrl;
496                 }else{
497                         $urls['endPage'] = $urls['baseURL'] . $this->var_offset . '=end' . $dynamicUrl;
498                 }
499
500                 return $urls;
501         }
502
503         /**
504          * generates the additional details span to be retrieved via ajax
505          *
506          * @param GUID id id of the record
507          * @return array string to attach to field
508          */
509         function getAdditionalDetailsAjax($id)
510     {
511         global $app_strings;
512
513         $jscalendarImage = SugarThemeRegistry::current()->getImageURL('info_inline.gif');
514
515         $extra = "<span id='adspan_" . $id . "' onmouseout=\"return SUGAR.util.clearAdditionalDetailsCall()\" "
516                 . "onmouseover=\"lvg_dtails('$id')\" "
517                                 . "onmouseout=\"return nd(1000);\" style='position: relative;'><img vertical-align='middle' class='info' border='0' src='$jscalendarImage'></span>";
518
519         return array('fieldToAddTo' => $this->additionalDetailsFieldToAdd, 'string' => $extra);
520         }
521
522     /**
523      * generates the additional details values
524      *
525      * @param unknown_type $fields
526      * @param unknown_type $adFunction
527      * @param unknown_type $editAccess
528      * @return array string to attach to field
529      */
530     function getAdditionalDetails($fields, $adFunction, $editAccess)
531     {
532         global $app_strings;
533
534         $results = $adFunction($fields);
535         $results['string'] = str_replace(array("&#039", "'"), '\&#039', $results['string']); // no xss!
536
537         if(trim($results['string']) == '') $results['string'] = $app_strings['LBL_NONE'];
538         $extra = "<span onmouseover=\"return overlib('" .
539             str_replace(array("\rn", "\r", "\n"), array('','','<br />'), $results['string'])
540             . "', CAPTION, '<div style=\'float:left\'>{$app_strings['LBL_ADDITIONAL_DETAILS']}</div><div style=\'float: right\'>";
541         if($editAccess) $extra .= (!empty($results['editLink']) ? "<a title=\'{$app_strings['LBL_EDIT_BUTTON']}\' href={$results['editLink']}><img  border=0 src=".SugarThemeRegistry::current()->getImageURL('edit_inline.gif')."></a>" : '');
542         $extra .= (!empty($results['viewLink']) ? "<a title=\'{$app_strings['LBL_VIEW_BUTTON']}\' href={$results['viewLink']}><img style=\'margin-left: 2px;\' border=0 src=".SugarThemeRegistry::current()->getImageURL('view_inline.gif')."></a>" : '')
543             . "', DELAY, 200, STICKY, MOUSEOFF, 1000, WIDTH, "
544             . (empty($results['width']) ? '300' : $results['width'])
545             . ", CLOSETEXT, '<img border=0 style=\'margin-left:2px; margin-right: 2px;\' src='".SugarThemeRegistry::current()->getImageURL('close.gif')."'></div>', "
546             . "CLOSETITLE, '{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}', CLOSECLICK, FGCLASS, 'olFgClass', "
547             . "CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass');\" "
548             . "onmouseout=\"return nd(1000);\"><img style='padding: 0px 5px 0px 2px' border='0' src='".SugarThemeRegistry::current()->getImageURL('info_inline.png')."' ></span>";
549
550             $results = $adFunction($fields);
551             $results['string'] = str_replace(array("&#039", "'"), '\&#039', $results['string']); // no xss!
552
553             if(trim($results['string']) == '') $results['string'] = $app_strings['LBL_NONE'];
554             $extra = "<span onmouseover=\"return overlib('" .
555                 str_replace(array("\rn", "\r", "\n"), array('','','<br />'), $results['string'])
556                 . "', CAPTION, '<div style=\'float:left\'>{$app_strings['LBL_ADDITIONAL_DETAILS']}</div><div style=\'float: right\'>";
557             if($editAccess) $extra .= (!empty($results['editLink']) ? "<a title=\'{$app_strings['LBL_EDIT_BUTTON']}\' href={$results['editLink']}><img  border=0 src=".SugarThemeRegistry::current()->getImageURL('edit_inline.gif')."></a>" : '');
558             $extra .= (!empty($results['viewLink']) ? "<a title=\'{$app_strings['LBL_VIEW_BUTTON']}\' href={$results['viewLink']}><img style=\'margin-left: 2px;\' border=0 src=".SugarThemeRegistry::current()->getImageURL('view_inline.gif')."></a>" : '')
559                 . "', DELAY, 200, STICKY, MOUSEOFF, 1000, WIDTH, "
560                 . (empty($results['width']) ? '300' : $results['width'])
561                 . ", CLOSETEXT, '<img border=0 style=\'margin-left:2px; margin-right: 2px;\' src=".SugarThemeRegistry::current()->getImageURL('close.gif')."></div>', "
562                 . "CLOSETITLE, '{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}', CLOSECLICK, FGCLASS, 'olFgClass', "
563                 . "CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass');\" "
564                 . "onmouseout=\"return nd(1000);\"><img style='padding: 0px 5px 0px 2px' border='0' src='".SugarThemeRegistry::current()->getImageURL('info_inline.png')."' ></span>";
565
566             return array('fieldToAddTo' => $results['fieldToAddTo'], 'string' => $extra);
567     }
568
569 }