PageRenderTime 63ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/include/generic/LayoutManager.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 343 lines | 263 code | 32 blank | 48 comment | 39 complexity | f683d0982c048f6ba6c1bd0386dcf746 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, AGPL-3.0, LGPL-2.1
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM 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/SugarWidgetSubPanelTopButton.php');
  38. require_once('include/generic/SugarWidgets/SugarWidgetReportField.php');
  39. require_once('include/database/DBHelper.php');
  40. class LayoutManager
  41. {
  42. var $defs = array();
  43. var $widget_prefix = 'SugarWidget';
  44. var $default_widget_name = 'Field';
  45. var $DBHelper;
  46. function LayoutManager()
  47. {
  48. // set a sane default for context
  49. $this->defs['context'] = 'Detail';
  50. $this->DBHelper = $GLOBALS['db']->getHelper();
  51. }
  52. function setAttribute($key,$value)
  53. {
  54. $this->defs[$key] = $value;
  55. }
  56. function setAttributePtr($key,&$value)
  57. {
  58. $this->defs[$key] = $value;
  59. }
  60. function getAttribute($key)
  61. {
  62. if ( isset($this->defs[$key]))
  63. {
  64. return $this->defs[$key];
  65. } else {
  66. return null;
  67. }
  68. }
  69. // Take the class name from the widget definition and use the class to look it up
  70. // $use_default will default classes to SugarWidgetFieldxxxxx
  71. function getClassFromWidgetDef($widget_def, $use_default = false)
  72. {
  73. static $class_map = array(
  74. 'SugarWidgetSubPanelTopCreateButton' => array(
  75. 'widget_class'=>'SugarWidgetSubPanelTopButton',
  76. 'title'=>'LBL_NEW_BUTTON_TITLE',
  77. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  78. 'form_value'=>'LBL_NEW_BUTTON_LABEL',
  79. 'ACL'=>'edit',
  80. ),
  81. 'SugarWidgetSubPanelTopButtonQuickCreate' => array(
  82. 'widget_class'=>'SugarWidgetSubPanelTopButtonQuickCreate',
  83. 'title'=>'LBL_NEW_BUTTON_TITLE',
  84. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  85. 'form_value'=>'LBL_NEW_BUTTON_LABEL',
  86. 'ACL'=>'edit',
  87. ),
  88. 'SugarWidgetSubPanelTopScheduleMeetingButton' => array(
  89. 'widget_class'=>'SugarWidgetSubPanelTopScheduleMeetingButton',
  90. 'module'=>'Meetings',
  91. 'title'=>'LBL_NEW_BUTTON_TITLE',
  92. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  93. 'form_value'=>'LNK_NEW_MEETING',
  94. 'ACL'=>'edit',
  95. ),
  96. 'SugarWidgetSubPanelTopScheduleCallButton' => array(
  97. 'widget_class'=>'SugarWidgetSubPanelTopScheduleCallButton',
  98. 'module'=>'Calls',
  99. 'title'=>'LBL_NEW_BUTTON_TITLE',
  100. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  101. 'form_value'=>'LNK_NEW_CALL',
  102. 'ACL'=>'edit',
  103. ),
  104. 'SugarWidgetSubPanelTopCreateTaskButton' => array(
  105. 'widget_class'=>'SugarWidgetSubPanelTopCreateTaskButton',
  106. 'module'=>'Tasks',
  107. 'title'=>'LBL_NEW_BUTTON_TITLE',
  108. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  109. 'form_value'=>'LNK_NEW_TASK',
  110. 'ACL'=>'edit',
  111. ),
  112. 'SugarWidgetSubPanelTopCreateNoteButton' => array(
  113. 'widget_class'=>'SugarWidgetSubPanelTopCreateNoteButton',
  114. 'module'=>'Notes',
  115. 'title'=>'LBL_NEW_BUTTON_TITLE',
  116. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  117. 'form_value'=>'LNK_NEW_NOTE',
  118. 'ACL'=>'edit',
  119. ),
  120. 'SugarWidgetSubPanelTopCreateContactAccountButton' => array(
  121. 'widget_class'=>'SugarWidgetSubPanelTopButton',
  122. 'module'=>'Contacts',
  123. 'title'=>'LBL_NEW_BUTTON_TITLE',
  124. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  125. 'form_value'=>'LBL_NEW_BUTTON_LABEL',
  126. 'additional_form_fields' => array(
  127. 'primary_address_street' => 'shipping_address_street',
  128. 'primary_address_city' => 'shipping_address_city',
  129. 'primary_address_state' => 'shipping_address_state',
  130. 'primary_address_country' => 'shipping_address_country',
  131. 'primary_address_postalcode' => 'shipping_address_postalcode',
  132. 'to_email_addrs' => 'email1'
  133. ),
  134. 'ACL'=>'edit',
  135. ),
  136. 'SugarWidgetSubPanelTopCreateContact' => array(
  137. 'widget_class'=>'SugarWidgetSubPanelTopButton',
  138. 'module'=>'Contacts',
  139. 'title'=>'LBL_NEW_BUTTON_TITLE',
  140. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  141. 'form_value'=>'LBL_NEW_BUTTON_LABEL',
  142. 'additional_form_fields' => array(
  143. 'account_id' => 'account_id',
  144. 'account_name' => 'account_name',
  145. ),
  146. 'ACL'=>'edit',
  147. ),
  148. 'SugarWidgetSubPanelTopCreateRevisionButton'=> array(
  149. 'widget_class'=>'SugarWidgetSubPanelTopButton',
  150. 'module'=>'DocumentRevisions',
  151. 'title'=>'LBL_NEW_BUTTON_TITLE',
  152. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  153. 'form_value'=>'LBL_NEW_BUTTON_LABEL',
  154. 'additional_form_fields' => array(
  155. 'parent_name'=>'document_name',
  156. 'document_name' => 'document_name',
  157. 'document_revision' => 'latest_revision',
  158. 'document_filename' => 'filename',
  159. 'document_revision_id' => 'document_revision_id',
  160. ),
  161. 'ACL'=>'edit',
  162. ),
  163. 'SugarWidgetSubPanelTopCreateDirectReport' => array(
  164. 'widget_class'=>'SugarWidgetSubPanelTopButton',
  165. 'module'=>'Contacts',
  166. 'title'=>'LBL_NEW_BUTTON_TITLE',
  167. 'access_key'=>'LBL_NEW_BUTTON_KEY',
  168. 'form_value'=>'LBL_NEW_BUTTON_LABEL',
  169. 'additional_form_fields' => array(
  170. 'reports_to_name' => 'name',
  171. 'reports_to_id' => 'id',
  172. ),
  173. 'ACL'=>'edit',
  174. ),
  175. 'SugarWidgetSubPanelTopSelectFromReportButton' => array(
  176. 'widget_class'=>'SugarWidgetSubPanelTopSelectButton',
  177. 'module'=>'Reports',
  178. 'title'=>'LBL_SELECT_REPORTS_BUTTON_LABEL',
  179. 'access_key'=>'LBL_SELECT_BUTTON_KEY',
  180. 'form_value'=>'LBL_SELECT_REPORTS_BUTTON_LABEL',
  181. 'ACL'=>'edit',
  182. 'add_to_passthru_data'=>array (
  183. 'return_type'=>'report',
  184. )
  185. ),
  186. 'SugarWidgetSubPanelAddToProspectListButton' => array(
  187. 'widget_class'=>'SugarWidgetSubPanelTopSelectButton',
  188. 'module'=>'ProspectLists',
  189. 'title'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL',
  190. 'access_key'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_KEY',
  191. 'form_value'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL',
  192. 'ACL'=>'edit',
  193. 'add_to_passthru_data'=>array (
  194. 'return_type'=>'addtoprospectlist',
  195. 'parent_module'=>'ProspectLists',
  196. 'parent_type'=>'ProspectList',
  197. 'child_id'=>'target_id',
  198. 'link_attribute'=>'target_type',
  199. 'link_type'=>'polymorphic', //polymorphic or default
  200. )
  201. ),
  202. );
  203. $fieldDef = $this->getFieldDef($widget_def);
  204. if(!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'multienum'){
  205. $widget_def['widget_class'] = 'Fieldmultienum';
  206. }
  207. if(!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'bool'){
  208. $widget_def['widget_class'] = 'Fieldbool';
  209. }
  210. if($use_default) {
  211. switch($widget_def['name']) {
  212. case 'assigned_user_id':
  213. $widget_def['widget_class'] = 'Fielduser_name';
  214. break;
  215. default:
  216. if ( isset($widget_def['type']) ) {
  217. $widget_def['widget_class'] = 'Field' . $widget_def['type'];
  218. }
  219. else {
  220. $widget_def['widget_class'] = 'Field' . $this->DBHelper->getFieldType($widget_def);
  221. }
  222. }
  223. }
  224. if(!empty($widget_def['name']) && $widget_def['name'] == 'team_set_id'){
  225. $widget_def['widget_class'] = 'Fieldteam_set_id';
  226. }
  227. if(empty($widget_def['widget_class']))
  228. {
  229. // Default the class to SugarWidgetField
  230. $class_name = $this->widget_prefix.$this->default_widget_name;
  231. }
  232. else
  233. {
  234. $class_name = $this->widget_prefix.$widget_def['widget_class'];
  235. }
  236. // Check to see if this is one of the known class mappings.
  237. if(!empty($class_map[$class_name]))
  238. {
  239. if (empty($class_map[$class_name]['widget_class'])) {
  240. $widget = new SugarWidgetSubPanelTopButton($class_map[$class_name]);
  241. } else {
  242. if (!class_exists($class_map[$class_name]['widget_class'])) {
  243. require_once('include/generic/SugarWidgets/'.$class_map[$class_name]['widget_class'].'.php');
  244. }
  245. $widget = new $class_map[$class_name]['widget_class']($class_map[$class_name]);
  246. }
  247. return $widget;
  248. }
  249. // At this point, we have a class name and we do not have a valid class defined.
  250. if(!class_exists($class_name))
  251. {
  252. // The class does not exist. Try including it.
  253. if (file_exists('custom/include/generic/SugarWidgets/'.$class_name.'.php'))
  254. require_once('custom/include/generic/SugarWidgets/'.$class_name.'.php');
  255. else if (file_exists('include/generic/SugarWidgets/'.$class_name.'.php'))
  256. require_once('include/generic/SugarWidgets/'.$class_name.'.php');
  257. if(!class_exists($class_name))
  258. {
  259. // If we still do not have a class, oops....
  260. die("LayoutManager: Class not found:".$class_name);
  261. }
  262. }
  263. $widget = new $class_name($this); // cache disabled $this->getClassFromCache($class_name);
  264. return $widget;
  265. }
  266. // 27426
  267. function getFieldDef($widget_def){
  268. static $beanCache;
  269. if(!empty($widget_def['module']) &&!empty($GLOBALS['beanList'][$widget_def['module']]) && !empty($GLOBALS['beanFiles'][$GLOBALS['beanList'][$widget_def['module']]])){
  270. if (!isset($beanCache[$widget_def['module']])){
  271. $beanCache[$widget_def['module']] = new $GLOBALS['beanList'][$widget_def['module']]();
  272. }
  273. $bean = $beanCache[$widget_def['module']];
  274. if(!empty($widget_def['name']) && !empty($bean->field_name_map) &&!empty($bean->field_name_map[$widget_def['name']]) ){
  275. return $bean->field_name_map[$widget_def['name']];
  276. }
  277. }
  278. return null;
  279. }
  280. function widgetDisplay($widget_def, $use_default = false)
  281. {
  282. $theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
  283. $label = isset($widget_def['module']) ? $widget_def['module'] : '';
  284. if (is_subclass_of($theclass, 'SugarWidgetSubPanelTopButton')) {
  285. $label = $theclass->get_subpanel_relationship_name($widget_def);
  286. }
  287. $theclass->setWidgetId($label);
  288. //#27426
  289. $fieldDef = $this->getFieldDef($widget_def);
  290. if(!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'multienum'){
  291. $widget_def['fields'] = sugarArrayMerge($widget_def['fields'] , $fieldDef);
  292. $widget_def['fields']['module'] = $label;
  293. }
  294. //end
  295. return $theclass->display($widget_def);
  296. }
  297. function widgetQuery($widget_def, $use_default = false)
  298. {
  299. $theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
  300. // _pp($theclass);
  301. return $theclass->query($widget_def);
  302. }
  303. // display an input field
  304. // module is the parent module of the def
  305. function widgetDisplayInput($widget_def, $use_default = false)
  306. {
  307. $theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
  308. return $theclass->displayInput($widget_def);
  309. }
  310. }
  311. ?>