PageRenderTime 47ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/ModuleBuilder/parsers/parser.modifysubpanel.php

https://github.com/jacknicole/sugarcrm_dev
PHP | 257 lines | 171 code | 25 blank | 61 comment | 62 complexity | b26c368fe0ded3b67f1d83f33795454b MD5 | raw file
  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-2011 SugarCRM Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under
  9. * the terms of the GNU Affero General Public License version 3 as published by the
  10. * Free Software Foundation with the addition of the following permission added
  11. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  12. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  13. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  14. *
  15. * This program is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  18. * details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License along with
  21. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  22. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  23. * 02110-1301 USA.
  24. *
  25. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  26. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  27. *
  28. * The interactive user interfaces in modified source and object code versions
  29. * of this program must display Appropriate Legal Notices, as required under
  30. * Section 5 of the GNU Affero General Public License version 3.
  31. *
  32. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  33. * these Appropriate Legal Notices must retain the display of the "Powered by
  34. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  35. * technical reasons, the Appropriate Legal Notices must display the words
  36. * "Powered by SugarCRM".
  37. ********************************************************************************/
  38. /*
  39. * Modify an exising Subpanel
  40. * Typically called from Studio for a deployed (OOB or installed custom module)
  41. *
  42. * Uses the listview editor to modify the subpanel
  43. * Uses SubPanelDefinitions to load the definitions for the subpanel, and SubPanel to save them, using the unique SubPanel override mechanism
  44. * There are two relevant modules for every subpanel - the module whose detailview this subpanel will appear in ($module_name), and the module that is the source of the data for the subpanel ($subPanelParentModule)
  45. */
  46. require_once ('modules/ModuleBuilder/parsers/parser.modifylistview.php') ;
  47. class ParserModifySubPanel extends ParserModifyListView
  48. {
  49. var $listViewDefs = false ;
  50. var $defaults = array ( ) ;
  51. var $additional = array ( ) ;
  52. var $available = array ( ) ;
  53. var $columns = array ( 'LBL_DEFAULT' => 'getDefaultFields' , 'LBL_HIDDEN' => 'getAvailableFields' ) ;
  54. function init ($module_name , $subPanelName)
  55. {
  56. $GLOBALS [ 'log' ]->debug ( "in ParserModifySubPanel: module_name={$module_name} child_module={$subPanelName}" ) ;
  57. $this->moduleName = $module_name ;
  58. $this->subPanelName = $subPanelName ;
  59. global $beanList, $beanFiles ;
  60. // Sometimes we receive a module name which is not in the correct CamelCase, so shift to lower case for all beanList lookups
  61. $beanListLower = array_change_key_case ( $beanList ) ;
  62. // Retrieve the definitions for all the available subpanels for this module
  63. $class = $beanListLower [ strtolower ( $this->moduleName ) ] ;
  64. require_once ($beanFiles [ $class ]) ;
  65. $module = new $class ( ) ;
  66. require_once ('include/SubPanel/SubPanelDefinitions.php') ;
  67. $spd = new SubPanelDefinitions ( $module ) ;
  68. // Get the lists of fields already in the subpanel and those that can be added in
  69. // Get the fields lists from an aSubPanel object describing this subpanel from the SubPanelDefinitions object
  70. $this->originalListViewDefs = array ( ) ;
  71. if (array_key_exists ( strtolower ( $this->subPanelName ), $spd->layout_defs [ 'subpanel_setup' ] ))
  72. {
  73. $originalPanel = $spd->load_subpanel ( $this->subPanelName, true ) ;
  74. $this->originalListViewDefs = $originalPanel->get_list_fields () ;
  75. $this->panel = $spd->load_subpanel ( $subPanelName, false ) ;
  76. $this->listViewDefs = $this->panel->get_list_fields () ;
  77. // Retrieve a copy of the bean for the parent module of this subpanel - so we can find additional fields for the layout
  78. $subPanelParentModuleName = $this->panel->get_module_name () ;
  79. $this->subPanelParentModule = null ;
  80. if (! empty ( $subPanelParentModuleName ) && isset($beanListLower[strtolower($subPanelParentModuleName)]))
  81. {
  82. $class = $beanListLower[strtolower($subPanelParentModuleName)];
  83. if (isset($beanFiles [ $class ]))
  84. {
  85. require_once ($beanFiles [ $class ]) ;
  86. $this->subPanelParentModule = new $class ( ) ;
  87. }
  88. }
  89. }
  90. $this->language_module = $this->panel->template_instance->module_dir ;
  91. }
  92. /**
  93. * Return a list of the fields that will be displayed in the subpanel
  94. */
  95. function getDefaultFields ()
  96. {
  97. $this->defaults = array ( ) ;
  98. foreach ( $this->listViewDefs as $key => $def )
  99. {
  100. if (! empty ( $def [ 'usage' ] ) && strcmp ( $def [ 'usage' ], 'query_only' ) == 0)
  101. continue ;
  102. if (! empty ( $def [ 'vname' ] ))
  103. $def [ 'label' ] = $def [ 'vname' ] ;
  104. $this->defaults [ $key ] = $def ;
  105. }
  106. return $this->defaults ;
  107. }
  108. /**
  109. * Return a list of fields that are not currently included in the subpanel but that are available for use
  110. */
  111. function getAvailableFields ()
  112. {
  113. $this->availableFields = array ( ) ;
  114. if ($this->subPanelParentModule != null)
  115. {
  116. $lowerFieldList = array_change_key_case ( $this->listViewDefs ) ;
  117. foreach ( $this->originalListViewDefs as $key => $def )
  118. {
  119. $key = strtolower ( $key ) ;
  120. if (! isset ( $lowerFieldList [ $key ] ))
  121. {
  122. $this->availableFields [ $key ] = $def ;
  123. }
  124. }
  125. $GLOBALS [ 'log' ]->debug ( 'parser.modifylistview.php->getAvailableFields(): field_defs=' . print_r ( $this->availableFields, true ) ) ;
  126. foreach ( $this->subPanelParentModule->field_defs as $key => $fieldDefinition )
  127. {
  128. $fieldName = strtolower ( $key ) ;
  129. if (! isset ( $lowerFieldList [ $fieldName ] )) // bug 16728 - check this first, so that other conditions (e.g., studio == visible) can't override and add duplicate entries
  130. {
  131. if ((empty ( $fieldDefinition [ 'source' ] ) || $fieldDefinition [ 'source' ] == 'db' || $fieldDefinition [ 'source' ] == 'custom_fields') && $fieldDefinition [ 'type' ] != 'id' && strcmp ( $fieldName, 'deleted' ) != 0 || (isset ( $def [ 'name' ] ) && strpos ( $def [ 'name' ], "_name" ) != false) || ! empty ( $def [ 'custom_type' ] ) && (empty ( $fieldDefinition [ 'dbType' ] ) || $fieldDefinition [ 'dbType' ] != 'id') && (empty ( $fieldDefinition [ 'dbtype' ] ) || $fieldDefinition [ 'dbtype' ] != 'id') || (! empty ( $fieldDefinition [ 'studio' ] ) && $fieldDefinition [ 'studio' ] == 'visible'))
  132. {
  133. $label = (isset ( $fieldDefinition [ 'vname' ] )) ? $fieldDefinition [ 'vname' ] : (isset ( $fieldDefinition [ 'label' ] ) ? $fieldDefinition [ 'label' ] : $fieldDefinition [ 'name' ]) ;
  134. $this->availableFields [ $fieldName ] = array ( 'width' => '10' , 'label' => $label ) ;
  135. }
  136. }
  137. }
  138. }
  139. return $this->availableFields ;
  140. }
  141. function getField ($fieldName)
  142. {
  143. foreach ( $this->listViewDefs as $key => $def )
  144. {
  145. $key = strtolower ( $key ) ;
  146. if ($key == $fieldName)
  147. {
  148. return $def ;
  149. }
  150. }
  151. foreach ( $this->originalListViewDefs as $key => $def )
  152. {
  153. $key = strtolower ( $key ) ;
  154. if ($key == $fieldName)
  155. {
  156. return $def ;
  157. }
  158. }
  159. foreach ( $this->panel->template_instance->field_defs as $key => $def )
  160. {
  161. $key = strtolower ( $key ) ;
  162. if ($key == $fieldName)
  163. {
  164. return $def ;
  165. }
  166. }
  167. return array ( ) ;
  168. }
  169. /*
  170. * Save the modified definitions for a subpanel
  171. * Obtains the field definitions from a _REQUEST array, and merges them with the other fields from the original definitions
  172. * Uses the subpanel override mechanism from SubPanel to save them
  173. */
  174. function handleSave ()
  175. {
  176. $GLOBALS [ 'log' ]->debug ( "in ParserModifySubPanel->handleSave()" ) ;
  177. require_once ('include/SubPanel/SubPanel.php') ;
  178. $subpanel = new SubPanel ( $this->moduleName, 'fab4', $this->subPanelName, $this->panel ) ;
  179. $newFields = array ( ) ;
  180. foreach ( $this->listViewDefs as $name => $field )
  181. {
  182. if (! isset ( $field [ 'usage' ] ) || $field [ 'usage' ] != 'query_only')
  183. {
  184. $existingFields [ $name ] = $field ;
  185. } else
  186. {
  187. $newFields [ $name ] = $field ;
  188. }
  189. }
  190. // Loop through all of the fields defined in the 'Default' group of the ListView data in $_REQUEST
  191. // Replace the field specification in the originalListViewDef with this new updated specification
  192. foreach ( $_REQUEST [ 'group_0' ] as $field )
  193. {
  194. if (! empty ( $this->originalListViewDefs [ $field ] ))
  195. {
  196. $newFields [ $field ] = $this->originalListViewDefs [ $field ] ;
  197. } else
  198. {
  199. $vname = '' ;
  200. if (isset ( $this->panel->template_instance->field_defs [ $field ] ))
  201. {
  202. $vname = $this->panel->template_instance->field_defs [ $field ] [ 'vname' ] ;
  203. }
  204. if (($this->subPanelParentModule != null) && (isset ( $this->subPanelParentModule->field_name_map [ $field ] ) && ($this->subPanelParentModule->field_name_map [ $field ] [ 'type' ] == 'bool' || (isset ( $this->subPanelParentModule->field_name_map [ $field ] [ 'custom_type' ] ) && $this->subPanelParentModule->field_name_map [ $field ] [ 'custom_type' ] == 'bool'))))
  205. {
  206. $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname , 'widget_type' => 'checkbox' ) ;
  207. } else
  208. {
  209. $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname ) ;
  210. }
  211. }
  212. // Now set the field width if specified in the $_REQUEST data
  213. if (isset ( $_REQUEST [ strtolower ( $field ) . 'width' ] ))
  214. {
  215. $width = substr ( $_REQUEST [ strtolower ( $field ) . 'width' ], 6, 3 ) ;
  216. if (strpos ( $width, "%" ) != false)
  217. {
  218. $width = substr ( $width, 0, 2 ) ;
  219. }
  220. if ($width < 101 && $width > 0)
  221. {
  222. $newFields [ $field ] [ 'width' ] = $width ;
  223. }
  224. } else if (isset ( $this->listViewDefs [ $field ] [ 'width' ] ))
  225. {
  226. $newFields [ $field ] [ 'width' ] = $this->listViewDefs [ $field ] [ 'width' ] ;
  227. }
  228. }
  229. $subpanel->saveSubPanelDefOverride ( $this->panel, 'list_fields', $newFields ) ;
  230. }
  231. }
  232. ?>