]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/EditView/SubpanelQuickCreate.php
Release 6.5.1
[Github/sugarcrm.git] / include / EditView / SubpanelQuickCreate.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 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
38 require_once('include/EditView/EditView2.php');
39 /**
40  * Quick create form in the subpanel
41  * @api
42  */
43 class SubpanelQuickCreate{
44     public $defaultProcess = true;
45
46     /**
47      * The view type to use
48      *
49      * @var string
50      */
51     public $viewType = 'QuickCreate';
52
53     public function SubpanelQuickCreate($module, $view='QuickCreate', $proccessOverride = false)
54     {
55         $this->viewType = $view;
56
57         //treat quickedit and quickcreate views as the same
58         if($this->viewType == 'QuickEdit') {
59             $this->viewType = 'QuickCreate';
60         }
61
62         // Get the viewdefs source file, called here to ensure proper viewType setting
63         $source = $this->getModuleViewDefsSourceFile($module, $this->viewType);
64
65                 // locate the best viewdefs to use: 1. custom/module/quickcreatedefs.php 2. module/quickcreatedefs.php 3. custom/module/editviewdefs.php 4. module/editviewdefs.php
66                 $base = 'modules/' . $module . '/metadata/';
67                 $source = 'custom/' . $base . strtolower($view) . 'defs.php';
68                 if (!file_exists( $source))
69                 {
70                         $source = $base . strtolower($view) . 'defs.php';
71                         if (!file_exists($source))
72                         {
73                                 //if our view does not exist default to EditView
74                                 $view = 'EditView';
75                                 $source = 'custom/' . $base . 'editviewdefs.php';
76                                 if (!file_exists($source))
77                                 {
78                                         $source = $base . 'editviewdefs.php';
79                                 }
80                         }
81                 }
82
83         $this->ev = $this->getEditView();
84                 $this->ev->view = $this->viewType;
85                 $this->ev->ss = new Sugar_Smarty();
86                 //$_REQUEST['return_action'] = 'SubPanelViewer';
87
88         $class = $GLOBALS['beanList'][$module];
89         $bean = new $class();
90         if(!empty($_REQUEST['record'])) {
91             $bean->retrieve($_REQUEST['record']);
92         }
93                 $this->ev->setup($module, $bean, $source);
94                 unset($bean);
95
96
97                 // Bug 49219 - Check empty before set defaults, or the settings from viewdefs above will be overridden.
98         if (!isset($this->ev->defs['templateMeta']['form']['headerTpl']))
99         {
100             $this->ev->defs['templateMeta']['form']['headerTpl'] = 'include/EditView/header.tpl';
101         }
102
103                 if (!isset($this->ev->defs['templateMeta']['form']['footerTpl']))
104         {
105             $this->ev->defs['templateMeta']['form']['footerTpl'] = 'include/EditView/footer.tpl';
106         }
107                 // Comment below, breaks many out of the box viewdefs
108                 /*if (empty($this->ev->defs['templateMeta']['form']['buttons'])) $this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL', 'SUBPANELFULLFORM');*/
109                 $this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL', 'SUBPANELFULLFORM');
110
111         //Load the parent view class if it exists.  Check for custom file first
112         loadParentView('edit');
113
114                 $viewEditSource = 'modules/'.$module.'/views/view.edit.php';
115                 if (file_exists('custom/'. $viewEditSource)) {
116                         $viewEditSource = 'custom/'. $viewEditSource;
117                 }
118
119                 if(file_exists($viewEditSource) && !$proccessOverride) {
120             include($viewEditSource);
121             $c = $module . 'ViewEdit';
122
123             $customClass = 'Custom' . $c;
124             if(class_exists($customClass)) {
125                 $c = $customClass;
126             }
127
128             if(class_exists($c)) {
129                     $view = new $c;
130                     if($view->useForSubpanel) {
131                         $this->defaultProcess = false;
132
133                         // Check if we should use the module's QuickCreate.tpl file.
134                         if($view->useModuleQuickCreateTemplate && file_exists('modules/'.$module.'/tpls/QuickCreate.tpl')) {
135                            $this->ev->defs['templateMeta']['form']['headerTpl'] = 'modules/'.$module.'/tpls/QuickCreate.tpl';
136                         }
137
138                             $view->ev = & $this->ev;
139                             $view->ss = & $this->ev->ss;
140                                         $class = $GLOBALS['beanList'][$module];
141                                         if(!empty($GLOBALS['beanFiles'][$class])){
142                                                 require_once($GLOBALS['beanFiles'][$class]);
143                                                 $bean = new $class();
144                                                 $view->bean = $bean;
145                                         }
146                                         $this->ev->formName = 'form_Subpanel'.$this->ev->view .'_'.$module;
147                                         $view->showTitle = false; // Do not show title since this is for subpanel
148                             $view->display();
149                     }
150             }
151                 } //if
152
153                 if($this->defaultProcess && !$proccessOverride) {
154                    $this->process($module);
155                 }
156         }
157
158         function process($module){
159         if($_REQUEST['target_action'] == 'QuickCreate'){
160             $this->ev->view = 'QuickCreate';
161         }
162         $form_name = 'form_Subpanel'.$this->ev->view .'_'.$module;
163         $this->ev->formName = $form_name;
164         $this->ev->process(true, $form_name);
165                 echo $this->ev->display(false, true);
166         }
167
168     /**
169      * Get EditView object
170      * @return EditView
171      */
172     protected function getEditView()
173     {
174         return new EditView();
175     }
176
177
178     /**
179      * Finds and returns the best viewdefs to use:
180      *  1. custom/module/quickcreatedefs.php
181      *  2. module/quickcreatedefs.php
182      *  3. custom/module/editviewdefs.php
183      *  4. module/editviewdefs.php
184      *
185      * @param $module
186      * @param $view
187      * @return string The path to the viewdefs file to use
188      */
189     public function getModuleViewDefsSourceFile($module, $view) {
190         $base = 'modules/' . $module . '/metadata/';
191                 $source = 'custom/' . $base . strtolower($view) . 'defs.php';
192                 if (!file_exists($source)) {
193                         $source = $base . strtolower($view) . 'defs.php';
194                         if (!file_exists($source)) {
195                                 //if our view does not exist default to EditView
196                                 $this->viewType = 'EditView';
197                                 $source = 'custom/' . $base . 'editviewdefs.php';
198                                 if (!file_exists($source)) {
199                                         $source = $base . 'editviewdefs.php';
200                                 }
201                         }
202                 }
203
204         return $source;
205     }
206 }