PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/include/generic/SugarWidgets/SugarWidgetFieldname.php

https://github.com/jacknicole/sugarcrm_dev
PHP | 310 lines | 231 code | 36 blank | 43 comment | 51 complexity | 9efe843670aed09679879a66d10fcb27 MD5 | raw file
  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. require_once('include/generic/SugarWidgets/SugarWidgetFieldvarchar.php');
  38. class SugarWidgetFieldName extends SugarWidgetFieldVarchar
  39. {
  40. function SugarWidgetFieldName(&$layout_manager) {
  41. parent::SugarWidgetFieldVarchar($layout_manager);
  42. $this->reporter = $this->layout_manager->getAttribute('reporter');
  43. }
  44. function displayList(&$layout_def)
  45. {
  46. if(empty($layout_def['column_key']))
  47. {
  48. return $this->displayListPlain($layout_def);
  49. }
  50. $module = $this->reporter->all_fields[$layout_def['column_key']]['module'];
  51. $name = $layout_def['name'];
  52. $layout_def['name'] = 'id';
  53. $key = $this->_get_column_alias($layout_def);
  54. $key = strtoupper($key);
  55. if(empty($layout_def['fields'][$key]))
  56. {
  57. $layout_def['name'] = $name;
  58. return $this->displayListPlain($layout_def);
  59. }
  60. $record = $layout_def['fields'][$key];
  61. $layout_def['name'] = $name;
  62. global $current_user;
  63. if ($module == 'Users' && !is_admin($current_user))
  64. $module = 'Employees';
  65. $str = "<a target='_blank' href=\"index.php?action=DetailView&module=$module&record=$record\">";
  66. $str .= $this->displayListPlain($layout_def);
  67. $str .= "</a>";
  68. return $str;
  69. }
  70. function _get_normal_column_select($layout_def)
  71. {
  72. global $sugar_config;
  73. // if $this->db->dbytpe is empty, then grab dbtype value from global array "$sugar_config[dbconfig]"
  74. if(empty($this->db->dbType)){
  75. $this->db->dbType = $sugar_config['dbconfig']['db_type'];
  76. }
  77. if ( isset($this->reporter->all_fields) ) {
  78. $field_def = $this->reporter->all_fields[$layout_def['column_key']];
  79. } else {
  80. $field_def = array();
  81. }
  82. if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
  83. {
  84. return parent::_get_column_select($layout_def);
  85. }
  86. // 'fields' are the two fields to concat to create the name
  87. $alias = '';
  88. $endalias = '';
  89. if ( ! empty($layout_def['table_alias']))
  90. {
  91. if ($this->db->dbType == 'mysql')
  92. {
  93. $alias .= "CONCAT(CONCAT(IFNULL("
  94. .$layout_def['table_alias']."."
  95. .$field_def['fields'][0].",''),' '),"
  96. .$layout_def['table_alias']."."
  97. .$field_def['fields'][1].")";
  98. }
  99. elseif ( $this->db->dbType == 'mssql' )
  100. {
  101. $alias .= $layout_def['table_alias'] . '.' . $field_def['fields'][0] . " + ' ' + "
  102. . $layout_def['table_alias'] . '.' . $field_def['fields'][1]."";
  103. }
  104. }
  105. elseif (! empty($layout_def['name']))
  106. {
  107. $alias = $layout_def['name'];
  108. }
  109. else
  110. {
  111. $alias .= "*";
  112. }
  113. $alias .= $endalias;
  114. return $alias;
  115. }
  116. function _get_column_select($layout_def)
  117. {
  118. global $sugar_config;
  119. global $locale, $current_user;
  120. // if $this->db->dbytpe is empty, then grab dbtype value from global array "$sugar_config[dbconfig]"
  121. if(empty($this->db->dbType)){
  122. $this->db->dbType = $sugar_config['dbconfig']['db_type'];
  123. }
  124. if ( isset($this->reporter->all_fields) ) {
  125. $field_def = $this->reporter->all_fields[$layout_def['column_key']];
  126. } else {
  127. $field_def = array();
  128. }
  129. // 'fields' are the two fields to concat to create the name
  130. $alias = '';
  131. $endalias = '';
  132. if(!isset($field_def['fields']))
  133. {
  134. $alias = $this->_get_normal_column_select($layout_def);
  135. return $alias;
  136. }
  137. $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
  138. $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
  139. $names = array();
  140. $names['f'] = db_convert($layout_def['table_alias'].'.'.$field_def['fields'][0].",''","IFNULL");
  141. $names['l'] = $layout_def['table_alias'].'.'.$field_def['fields'][1];
  142. if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
  143. {
  144. return parent::_get_column_select($layout_def);
  145. }
  146. if ( ! empty($layout_def['table_alias']))
  147. {
  148. if ($this->db->dbType == 'mysql')
  149. {
  150. for($i=0; $i<strlen($localeNameFormat); $i++) {
  151. $alias .= array_key_exists($localeNameFormat{$i}, $names) ? $names[$localeNameFormat{$i}] : '\''.$localeNameFormat{$i}.'\'';
  152. if($i<strlen($localeNameFormat)-1) $alias .= ',';
  153. }
  154. if(strlen($localeNameFormat)>1)
  155. $alias = 'concat('.$alias.')';
  156. }
  157. elseif ( $this->db->dbType == 'mssql' )
  158. {
  159. for($i=0; $i<strlen($localeNameFormat); $i++) {
  160. $alias .= array_key_exists($localeNameFormat{$i}, $names) ? $names[$localeNameFormat{$i}] : '\''.$localeNameFormat{$i}.'\'';
  161. if($i<strlen($localeNameFormat)-1) $alias .= ' + ';
  162. }
  163. }
  164. }
  165. elseif (! empty($layout_def['name']))
  166. {
  167. $alias = $layout_def['name'];
  168. }
  169. else
  170. {
  171. $alias .= "*";
  172. }
  173. $alias .= $endalias;
  174. return $alias;
  175. }
  176. function queryFilterIs($layout_def)
  177. {
  178. require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
  179. $layout_def['name'] = 'id';
  180. $layout_def['type'] = 'id';
  181. $input_name0 = $layout_def['input_name0'];
  182. if ( is_array($layout_def['input_name0']))
  183. {
  184. $input_name0 = $layout_def['input_name0'][0];
  185. }
  186. if ($input_name0 == 'Current User') {
  187. global $current_user;
  188. $input_name0 = $current_user->id;
  189. }
  190. return SugarWidgetFieldid::_get_column_select($layout_def)."='"
  191. .$GLOBALS['db']->quote($input_name0)."'\n";
  192. }
  193. function queryFilteris_not($layout_def)
  194. {
  195. require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
  196. $layout_def['name'] = 'id';
  197. $layout_def['type'] = 'id';
  198. $input_name0 = $layout_def['input_name0'];
  199. if ( is_array($layout_def['input_name0']))
  200. {
  201. $input_name0 = $layout_def['input_name0'][0];
  202. }
  203. if ($input_name0 == 'Current User') {
  204. global $current_user;
  205. $input_name0 = $current_user->id;
  206. }
  207. return SugarWidgetFieldid::_get_column_select($layout_def)."<>'"
  208. .$GLOBALS['db']->quote($input_name0)."'\n";
  209. }
  210. // $rename_columns, if true then you're coming from reports
  211. function queryFilterone_of(&$layout_def, $rename_columns = true)
  212. {
  213. require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
  214. if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
  215. $layout_def['name'] = 'id';
  216. $layout_def['type'] = 'id';
  217. }
  218. $arr = array();
  219. foreach($layout_def['input_name0'] as $value)
  220. {
  221. if ($value == 'Current User') {
  222. global $current_user;
  223. array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
  224. }
  225. else
  226. array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
  227. }
  228. $str = implode(",",$arr);
  229. return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
  230. }
  231. // $rename_columns, if true then you're coming from reports
  232. function queryFilternot_one_of(&$layout_def, $rename_columns = true)
  233. {
  234. require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
  235. if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
  236. $layout_def['name'] = 'id';
  237. $layout_def['type'] = 'id';
  238. }
  239. $arr = array();
  240. foreach($layout_def['input_name0'] as $value)
  241. {
  242. if ($value == 'Current User') {
  243. global $current_user;
  244. array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
  245. }
  246. else
  247. array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
  248. }
  249. $str = implode(",",$arr);
  250. return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
  251. }
  252. function &queryGroupBy($layout_def)
  253. {
  254. if( $this->reporter->db->dbType == 'mysql') {
  255. if($layout_def['name'] == 'full_name') {
  256. $layout_def['name'] = 'id';
  257. $layout_def['type'] = 'id';
  258. require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
  259. $group_by = SugarWidgetFieldid::_get_column_select($layout_def)."\n";
  260. }
  261. else {
  262. // group by clause for user name passes through here.
  263. // $layout_def['name'] = 'name';
  264. // $layout_def['type'] = 'name';
  265. $group_by = $this->_get_column_select($layout_def)."\n";
  266. }
  267. }
  268. elseif( $this->reporter->db->dbType == 'mssql') {
  269. $group_by = $this->_get_column_select($layout_def);
  270. }
  271. return $group_by;
  272. }
  273. }
  274. ?>