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