PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/include/generic/SugarWidgets/SugarWidgetSubPanelTopCreateTaskButton.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 161 lines | 106 code | 18 blank | 37 comment | 19 complexity | ffea8c95fa8a3aaa35ab5392245515a8 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/SugarWidgetSubPanelTopButtonQuickCreate.php');
  38. class SugarWidgetSubPanelTopCreateTaskButton extends SugarWidgetSubPanelTopButtonQuickCreate
  39. {
  40. function &_get_form($defines, $additionalFormFields = null)
  41. {
  42. global $app_strings;
  43. global $currentModule;
  44. $this->module="Tasks";
  45. $this->subpanelDiv = "activities";
  46. // Create the additional form fields with real values if they were not passed in
  47. if(empty($additionalFormFields) && $this->additional_form_fields)
  48. {
  49. foreach($this->additional_form_fields as $key=>$value)
  50. {
  51. if(!empty($defines['focus']->$value))
  52. {
  53. $additionalFormFields[$key] = $defines['focus']->$value;
  54. }
  55. else
  56. {
  57. $additionalFormFields[$key] = '';
  58. }
  59. }
  60. }
  61. if(!empty($this->module))
  62. {
  63. $defines['child_module_name'] = $this->module;
  64. }
  65. else
  66. {
  67. $defines['child_module_name'] = $defines['module'];
  68. }
  69. if(!empty($this->subpanelDiv))
  70. {
  71. $defines['subpanelDiv'] = $this->subpanelDiv;
  72. }
  73. $defines['parent_bean_name'] = get_class( $defines['focus']);
  74. $form = 'form' . $defines['child_module_name'];
  75. $button = '<form onsubmit="return SUGAR.subpanelUtils.sendAndRetrieve(this.id, \'subpanel_' . strtolower($defines['subpanelDiv']) . '\', \'' . addslashes($app_strings['LBL_LOADING']) . '\');" action="index.php" method="post" name="form" id="form' . $form . "\">\n";
  76. //module_button is used to override the value of module name
  77. $button .= "<input type='hidden' name='target_module' value='".$defines['child_module_name']."'>\n";
  78. $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_id' value='".$defines['focus']->id."'>\n";
  79. if(isset($defines['focus']->name))
  80. {
  81. $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_name' value='".$defines['focus']->name."'>";
  82. }
  83. $button .= '<input type="hidden" name="to_pdf" value="true" />';
  84. $button .= '<input type="hidden" name="tpl" value="QuickCreate.tpl" />';
  85. $button .= '<input type="hidden" name="return_module" value="' . $currentModule . "\" />\n";
  86. $button .= '<input type="hidden" name="return_action" value="' . $defines['action'] . "\" />\n";
  87. $button .= '<input type="hidden" name="return_id" value="' . $defines['focus']->id . "\" />\n";
  88. // TODO: move this out and get $additionalFormFields working properly
  89. if(empty($additionalFormFields['parent_type']))
  90. {
  91. if($defines['focus']->object_name=='Contact') {
  92. $additionalFormFields['parent_type'] = 'Accounts';
  93. }
  94. else {
  95. $additionalFormFields['parent_type'] = $defines['focus']->module_dir;
  96. }
  97. }
  98. if(empty($additionalFormFields['parent_name']))
  99. {
  100. if($defines['focus']->object_name=='Contact') {
  101. $additionalFormFields['parent_name'] = $defines['focus']->account_name;
  102. $additionalFormFields['account_name'] = $defines['focus']->account_name;
  103. }
  104. else {
  105. $additionalFormFields['parent_name'] = $defines['focus']->name;
  106. }
  107. }
  108. if(empty($additionalFormFields['parent_id']))
  109. {
  110. if($defines['focus']->object_name=='Contact') {
  111. $additionalFormFields['parent_id'] = $defines['focus']->account_id;
  112. $additionalFormFields['account_id'] = $defines['focus']->account_id;
  113. }
  114. else {
  115. $additionalFormFields['parent_id'] = $defines['focus']->id;
  116. }
  117. }
  118. $button .= '<input type="hidden" name="action" value="SubpanelCreates" />' . "\n";
  119. $button .= '<input type="hidden" name="module" value="Home" />' . "\n";
  120. $button .= '<input type="hidden" name="target_action" value="QuickCreate" />' . "\n";
  121. // fill in additional form fields for all but action
  122. foreach($additionalFormFields as $key => $value)
  123. {
  124. if($key != 'action')
  125. {
  126. $button .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />' . "\n";
  127. }
  128. }
  129. return $button;
  130. }
  131. function display($defines, $additionalFormFields = null)
  132. {
  133. $focus = new Task;
  134. if ( !$focus->ACLAccess('EditView') ) {
  135. return '';
  136. }
  137. return parent::display($defines, $additionalFormFields);
  138. }
  139. }
  140. ?>