PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/include/generic/SugarWidgets/SugarWidgetSubPanelTopButtonQuickCreate.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 192 lines | 147 code | 10 blank | 35 comment | 6 complexity | e7982b2e1db4ec5bd1d3544e0da26a0c 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. class SugarWidgetSubPanelTopButtonQuickCreate extends SugarWidgetSubPanelTopButton
  39. {
  40. function &_get_form($defines, $additionalFormFields = null)
  41. {
  42. global $app_strings;
  43. global $currentModule;
  44. // Create the additional form fields with real values if they were not passed in
  45. if(empty($additionalFormFields) && $this->additional_form_fields)
  46. {
  47. foreach($this->additional_form_fields as $key=>$value)
  48. {
  49. if(!empty($defines['focus']->$value))
  50. {
  51. $additionalFormFields[$key] = $defines['focus']->$value;
  52. }
  53. else
  54. {
  55. $additionalFormFields[$key] = '';
  56. }
  57. }
  58. }
  59. if(!empty($this->module))
  60. {
  61. $defines['child_module_name'] = $this->module;
  62. }
  63. else
  64. {
  65. $defines['child_module_name'] = $defines['module'];
  66. }
  67. $defines['parent_bean_name'] = get_class( $defines['focus']);
  68. $relationship_name = $this->get_subpanel_relationship_name($defines);
  69. $form = 'form' . $relationship_name;
  70. $button = '<form onsubmit="return SUGAR.subpanelUtils.sendAndRetrieve(this.id, \'subpanel_' . $defines['subpanel_definition']->name . '\', \'' . addslashes($app_strings['LBL_LOADING']) . '\');" action="index.php" method="post" name="form" id="form' . $form . "\">\n";
  71. //module_button is used to override the value of module name
  72. $button .= "<input type='hidden' name='target_module' value='".$defines['child_module_name']."'>\n";
  73. $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_id' value='".$defines['focus']->id."'>\n";
  74. if(isset($defines['focus']->name))
  75. {
  76. $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_name' value='".$defines['focus']->name."'>";
  77. #26451,add these fields for custom one-to-many relate field.
  78. if(!empty($defines['child_module_name'])){
  79. $button .= "<input type='hidden' name='". $relationship_name ."_name' value='".$defines['focus']->name."'>";
  80. $childFocusName = !empty($GLOBALS['beanList'][$defines['child_module_name']]) ? $GLOBALS['beanList'][$defines['child_module_name']] : "";
  81. if(!empty($GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name'])){
  82. $button .= "<input type='hidden' name='". $GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name'] ."' value='".$defines['focus']->id."'>";
  83. }
  84. }
  85. }
  86. if(!empty($defines['view']))
  87. $button .= '<input type="hidden" name="target_view" value="'. $defines['view'] . '" />';
  88. $button .= '<input type="hidden" name="to_pdf" value="true" />';
  89. $button .= '<input type="hidden" name="tpl" value="QuickCreate.tpl" />';
  90. $button .= '<input type="hidden" name="return_module" value="' . $currentModule . "\" />\n";
  91. $button .= '<input type="hidden" name="return_action" value="' . $defines['action'] . "\" />\n";
  92. $button .= '<input type="hidden" name="return_id" value="' . $defines['focus']->id . "\" />\n";
  93. $button .= '<input type="hidden" name="return_relationship" value="' . $relationship_name . "\" />\n";
  94. // TODO: move this out and get $additionalFormFields working properly
  95. if(empty($additionalFormFields['parent_type']))
  96. {
  97. if($defines['focus']->object_name=='Contact') {
  98. $additionalFormFields['parent_type'] = 'Accounts';
  99. }
  100. else {
  101. $additionalFormFields['parent_type'] = $defines['focus']->module_dir;
  102. }
  103. }
  104. if(empty($additionalFormFields['parent_name']))
  105. {
  106. if($defines['focus']->object_name=='Contact') {
  107. $additionalFormFields['parent_name'] = $defines['focus']->account_name;
  108. $additionalFormFields['account_name'] = $defines['focus']->account_name;
  109. }
  110. else {
  111. $additionalFormFields['parent_name'] = $defines['focus']->name;
  112. }
  113. }
  114. if(empty($additionalFormFields['parent_id']))
  115. {
  116. if($defines['focus']->object_name=='Contact') {
  117. $additionalFormFields['parent_id'] = $defines['focus']->account_id;
  118. $additionalFormFields['account_id'] = $defines['focus']->account_id;
  119. }
  120. else {
  121. $additionalFormFields['parent_id'] = $defines['focus']->id;
  122. }
  123. }
  124. if(strtolower($defines['child_module_name']) =='contracts') {
  125. //set variables to account name, or parent account name
  126. if(strtolower($defines['parent_bean_name']) == 'account' ){
  127. //if account is parent bean, then get focus id/focus name
  128. if(isset($defines['focus']->id))$additionalFormFields['account_id'] = $defines['focus']->id;
  129. if(isset($defines['focus']->name))$additionalFormFields['account_name'] = $defines['focus']->name;
  130. }elseif(strtolower($defines['parent_bean_name']) == 'quote' ){
  131. //if quote is parent bean, then get billing_account_id/billing_account_name
  132. if(isset($defines['focus']->billing_account_id))$additionalFormFields['account_id'] = $defines['focus']->billing_account_id;
  133. if(isset($defines['focus']->billing_account_name))$additionalFormFields['account_name'] = $defines['focus']->billing_account_name;
  134. }else{
  135. if(isset($defines['focus']->account_id))$additionalFormFields['account_id'] = $defines['focus']->account_id;
  136. if(isset($defines['focus']->account_name))$additionalFormFields['account_name'] = $defines['focus']->account_name;
  137. }
  138. }
  139. $button .= '<input type="hidden" name="action" value="SubpanelCreates" />' . "\n";
  140. $button .= '<input type="hidden" name="module" value="Home" />' . "\n";
  141. $button .= '<input type="hidden" name="target_action" value="QuickCreate" />' . "\n";
  142. // fill in additional form fields for all but action
  143. foreach($additionalFormFields as $key => $value)
  144. {
  145. if($key != 'action')
  146. {
  147. $button .= '<input type="hidden" name="' . $key . '" value=\'' . $value . '\' />' . "\n";
  148. }
  149. }
  150. return $button;
  151. }
  152. /**
  153. * get_subpanel_relationship_name
  154. * Get the relationship name based on the subapnel definition
  155. * @param mixed $defines The subpanel definition
  156. */
  157. function get_subpanel_relationship_name($defines) {
  158. $relationship_name = '';
  159. if(!empty($defines)) {
  160. $relationship_name = isset($defines['module']) ? $defines['module'] : '';
  161. $dataSource = $defines['subpanel_definition']->get_data_source_name(true);
  162. if (!empty($dataSource)) {
  163. $relationship_name = $dataSource;
  164. //Try to set the relationship name to the real relationship, not the link.
  165. if (!empty($defines['subpanel_definition']->parent_bean->field_defs[$dataSource])
  166. && !empty($defines['subpanel_definition']->parent_bean->field_defs[$dataSource]['relationship']))
  167. {
  168. $relationship_name = $defines['subpanel_definition']->parent_bean->field_defs[$dataSource]['relationship'];
  169. }
  170. }
  171. }
  172. return $relationship_name;
  173. }
  174. }
  175. ?>