]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Smarty/plugins/function.sugar_evalcolumn.php
Release 6.4.0
[Github/sugarcrm.git] / include / Smarty / plugins / function.sugar_evalcolumn.php
1 <?php
2
3 /*
4
5 Modification information for LGPL compliance
6
7 2011-09-23 16:39:38 - 0700 (Fri, 23 Sep 2011) - raagaard - Added support to place the normal field in to a customCode section by replacing @@FIELD@@
8
9 2011-08-22 12:52:36 -0700 (Mon, 22 Aug 2011) - jmertic - bug 28321: add support for rendering customCode AND normal field rendering
10
11 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
12
13 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
14
15 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
16
17 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
18
19 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
20
21 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
22
23 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
24
25 r42645 - 2008-12-18 13:41:08 -0800 (Thu, 18 Dec 2008) - awu - merging maint_5_2_0 rev41336:HEAD to trunk
26
27 r23498 - 2007-06-08 14:05:19 -0700 (Fri, 08 Jun 2007) - clee - Added support for auto generated tabindex.
28
29 r22745 - 2007-05-11 18:35:10 -0700 (Fri, 11 May 2007) - majed - fixes compiling issue
30
31 r22717 - 2007-05-11 15:02:12 -0700 (Fri, 11 May 2007) - clee - better meta data driven ui support
32
33 r22570 - 2007-05-08 16:35:23 -0700 (Tue, 08 May 2007) - clee - Latest revisions.
34
35 r22438 - 2007-05-01 18:02:10 -0700 (Tue, 01 May 2007) - clee - Updates for SDUC and developer's build.
36
37 r17559 - 2006-11-10 16:01:13 -0800 (Fri, 10 Nov 2006) - wayne - remove extra &
38
39 r17518 - 2006-11-07 14:58:53 -0800 (Tue, 07 Nov 2006) - wayne - removed extra &
40
41 r17486 - 2006-11-06 15:13:23 -0800 (Mon, 06 Nov 2006) - wayne - added array and tojson support
42
43 r17329 - 2006-10-26 15:39:17 -0700 (Thu, 26 Oct 2006) - wayne - defensive code
44
45 r12955 - 2006-04-26 18:32:25 -0700 (Wed, 26 Apr 2006) - wayne - custom code in listview smarty stuff
46
47
48 */
49
50
51 /**
52  * Smarty plugin
53  * @package Smarty
54  * @subpackage plugins
55  */
56
57
58 /**
59  * Smarty {sugar_evalcolumn} function plugin
60  *
61  * Type:     function<br>
62  * Name:     sugar_evalcolumn<br>
63  * Purpose:  evaluate a string by substituting values in the rowData parameter. Used for ListViews<br>
64  * 
65  * @author Wayne Pan {wayne at sugarcrm.com
66  * @param array
67  * @param Smarty
68  */
69 function smarty_function_sugar_evalcolumn($params, &$smarty)
70 {
71     if (!isset($params['colData']['field']) ) {
72         if(empty($params['colData']))  
73             $smarty->trigger_error("evalcolumn: missing 'colData' parameter");
74         if(!isset($params['colData']['field']))  
75             $smarty->trigger_error("evalcolumn: missing 'colData.field' parameter");
76         return;
77     }
78
79     if(empty($params['colData']['field'])) {
80         return;
81     }
82     $params['var'] = $params['colData']['field'];
83     if(isset($params['toJSON'])) {
84         $json = getJSONobj();
85         $params['var'] = $json->encode($params['var']);
86     }
87
88     if (!empty($params['var']['assign'])) {
89         return '{$' . $params['colData']['field']['name'] . '}';
90     } else {
91         $code = $params['var']['customCode'];
92         if(isset($params['tabindex']) && preg_match_all("'(<[ ]*?)(textarea|input|select)([^>]*?)(>)'si", $code, $matches, PREG_PATTERN_ORDER)) {
93            $str_replace = array();
94            $tabindex = ' tabindex="' . $params['tabindex'] . '" ';
95            foreach($matches[3] as $match) {
96                        $str_replace[$match] = $tabindex . $match;
97            }
98            $code = str_replace(array_keys($str_replace), array_values($str_replace), $code);
99         }
100         
101         // Add a string replace to swap out @@FIELD@@ for the actual field,
102         // we can't do this through customCode directly because the sugar_field smarty function returns smarty code to run on the second pass
103         if (!empty($code) && strpos($code,'@@FIELD@@') !== FALSE ) {
104             // First we need to fetch extra data about the field
105             // sfp == SugarFieldParams
106             $sfp = $params;
107             $sfp['parentFieldArray'] = 'fields';
108             $vardefs = $smarty->get_template_vars('fields');
109             $sfp['vardef'] = $vardefs[$params['colData']['field']['name']];
110             $sfp['displayType'] = 'EditView';
111             $sfp['displayParams'] = $params['colData']['field']['displayParams'];
112             $sfp['typeOverride'] = $params['colData']['field']['type'];
113             $sfp['formName'] = $smarty->get_template_vars('form_name');
114             
115             $fieldText = smarty_function_sugar_field($sfp, $smarty);
116
117             $code = str_replace('@@FIELD@@',$fieldText,$code);
118         }
119
120         //eggsurplus bug 28321: add support for rendering customCode AND normal field rendering
121         if(!empty($params['var']['displayParams']['enableConnectors']) && empty($params['var']['customCodeRenderField'])) {
122           require_once('include/connectors/utils/ConnectorUtils.php');
123           $code .= '&nbsp;' . ConnectorUtils::getConnectorButtonScript($params['var']['displayParams'], $smarty);
124         }
125         return $code;
126     }
127     
128     
129 }
130
131
132 ?>