PageRenderTime 32ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/include/generic/SugarWidgets/SugarWidgetField.php

https://bitbucket.org/allexblacker/suitecrm
PHP | 232 lines | 145 code | 44 blank | 43 comment | 35 complexity | f36d47c0a461604cae827fbd40865872 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry)
  3. 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-2013 SugarCRM Inc.
  7. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  8. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU Affero General Public License version 3 as published by the
  12. * Free Software Foundation with the addition of the following permission added
  13. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  14. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  15. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  16. *
  17. * This program is distributed in the hope that it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  19. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License along with
  23. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  24. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  25. * 02110-1301 USA.
  26. *
  27. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  28. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  29. *
  30. * The interactive user interfaces in modified source and object code versions
  31. * of this program must display Appropriate Legal Notices, as required under
  32. * Section 5 of the GNU Affero General Public License version 3.
  33. *
  34. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  35. * these Appropriate Legal Notices must retain the display of the "Powered by
  36. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  37. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  38. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  39. ********************************************************************************/
  40. class SugarWidgetField extends SugarWidget {
  41. function __construct(&$layout_manager) {
  42. parent::__construct($layout_manager);
  43. }
  44. /**
  45. * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
  46. */
  47. function SugarWidgetField(&$layout_manager){
  48. $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
  49. if(isset($GLOBALS['log'])) {
  50. $GLOBALS['log']->deprecated($deprecatedMessage);
  51. }
  52. else {
  53. trigger_error($deprecatedMessage, E_USER_DEPRECATED);
  54. }
  55. self::__construct($layout_manager);
  56. }
  57. function display($layout_def) {
  58. //print $layout_def['start_link_wrapper']."===";
  59. $context = $this->layout_manager->getAttribute('context'); //_ppd($context);
  60. $func_name = 'display'.$context;
  61. if (!empty ($context) && method_exists($this, $func_name)) {
  62. return $this-> $func_name ($layout_def);
  63. } else {
  64. return 'display not found:'.$func_name;
  65. }
  66. }
  67. function _get_column_alias($layout_def) {
  68. $alias_arr = array ();
  69. if (!empty ($layout_def['name']) && $layout_def['name'] == 'count') {
  70. return 'count';
  71. }
  72. if (!empty ($layout_def['table_alias'])) {
  73. array_push($alias_arr, $layout_def['table_alias']);
  74. }
  75. if (!empty ($layout_def['name'])) {
  76. array_push($alias_arr, $layout_def['name']);
  77. }
  78. return $this->getTruncatedColumnAlias(implode("_", $alias_arr));
  79. }
  80. function & displayDetailLabel(& $layout_def) {
  81. return '';
  82. }
  83. function & displayDetail($layout_def) {
  84. $layout_def = '';
  85. return $layout_def;
  86. }
  87. function displayHeaderCellPlain($layout_def)
  88. {
  89. if (!empty ($layout_def['label'])) {
  90. return $layout_def['label'];
  91. }
  92. if (!empty ($layout_def['vname'])) {
  93. return translate($layout_def['vname'], $this->layout_manager->getAttribute('module_name'));
  94. }
  95. return '';
  96. }
  97. function displayHeaderCell($layout_def) {
  98. $module_name = $this->layout_manager->getAttribute('module_name');
  99. $this->local_current_module = $_REQUEST['module'];
  100. $this->is_dynamic = true;
  101. // don't show sort links if name isn't defined
  102. if (empty ($layout_def['name']) || (isset ($layout_def['sortable']) && !$layout_def['sortable'])) {
  103. return $this->displayHeaderCellPlain($layout_def);
  104. }
  105. $header_cell_text = $this->displayHeaderCellPlain($layout_def);
  106. $subpanel_module = $layout_def['subpanel_module'];
  107. $html_var = $subpanel_module . "_CELL";
  108. if (empty ($this->base_URL)) {
  109. $objListView = new ListView();
  110. $this->base_URL = $objListView -> getBaseURL($html_var);
  111. $split_url = explode('&to_pdf=true&action=SubPanelViewer&subpanel=', $this->base_URL);
  112. $this->base_URL = $split_url[0];
  113. $this->base_URL .= '&inline=true&to_pdf=true&action=SubPanelViewer&subpanel=';
  114. }
  115. $sort_by_name = $layout_def['name'];
  116. if (isset ($layout_def['sort_by'])) {
  117. $sort_by_name = $layout_def['sort_by'];
  118. }
  119. $objListView = new ListView();
  120. $sort_by = $objListView->getSessionVariableName($html_var, "ORDER_BY").'='.$sort_by_name;
  121. $start = (empty ($layout_def['start_link_wrapper'])) ? '' : $layout_def['start_link_wrapper'];
  122. $end = (empty ($layout_def['end_link_wrapper'])) ? '' : $layout_def['end_link_wrapper'];
  123. $header_cell = "<a class=\"listViewThLinkS1\" href=\"".$start.$this->base_URL.$subpanel_module.'&'.$sort_by.$end."\">";
  124. $header_cell .= $header_cell_text;
  125. $imgArrow = '';
  126. if (isset ($layout_def['sort'])) {
  127. $imgArrow = $layout_def['sort'];
  128. }
  129. $arrow_start = $objListView->getArrowUpDownStart($imgArrow);
  130. $arrow_end = $objListView->getArrowUpDownEnd($imgArrow);
  131. $header_cell .= " ".$arrow_start.$arrow_end."</a>";
  132. return $header_cell;
  133. }
  134. function displayList($layout_def) {
  135. return $this->displayListPlain($layout_def);
  136. }
  137. function displayListPlain($layout_def) {
  138. $value= $this->_get_list_value($layout_def);
  139. if (isset($layout_def['widget_type']) && $layout_def['widget_type'] =='checkbox') {
  140. if ($value != '' && ($value == 'on' || intval($value) == 1 || $value == 'yes'))
  141. {
  142. return "<input name='checkbox_display' class='checkbox' type='checkbox' disabled='true' checked>";
  143. }
  144. return "<input name='checkbox_display' class='checkbox' type='checkbox' disabled='true'>";
  145. }
  146. return $value;
  147. }
  148. function _get_list_value(& $layout_def)
  149. {
  150. $key = '';
  151. if ( isset($layout_def['varname']) ) {
  152. $key = strtoupper($layout_def['varname']);
  153. }
  154. else {
  155. $key = strtoupper($this->_get_column_alias($layout_def));
  156. }
  157. if ( isset($layout_def['fields'][$key]) ) {
  158. return $layout_def['fields'][$key];
  159. }
  160. return '';
  161. }
  162. function & displayEditLabel($layout_def) {
  163. return '';
  164. }
  165. function & displayEdit($layout_def) {
  166. return '';
  167. }
  168. function & displaySearchLabel($layout_def) {
  169. return '';
  170. }
  171. function & displaySearch($layout_def) {
  172. return '';
  173. }
  174. function displayInput($layout_def) {
  175. return ' -- Not Implemented --';
  176. }
  177. function getVardef($layout_def) {
  178. $myName = $layout_def['column_key'];
  179. $vardef = $this->layout_manager->defs['reporter']->all_fields[$myName];
  180. if ( !isset($vardef) ) {
  181. // No vardef, return an empty array
  182. return array();
  183. } else {
  184. return $vardef;
  185. }
  186. }
  187. }