]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MVC/View/views/view.quickcreate.php
Release 6.4.0
[Github/sugarcrm.git] / include / MVC / View / views / view.quickcreate.php
1 <?php
2 //FILE SUGARCRM flav=pro || flav=sales
3 if(!defined('sugarEntry') || !sugarEntry) 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
40 require_once('include/MVC/View/views/view.ajax.php');
41 require_once('include/EditView/EditView2.php');
42
43 class ViewQuickcreate extends ViewAjax
44 {
45         protected $_isDCForm = false;
46         
47         /**
48          * @var EditView object
49          */
50         protected $ev;
51
52     /**
53      * @var headerTpl String variable of the Smarty template file used to render the header portion
54      */
55     protected $headerTpl = 'include/EditView/header.tpl';
56
57     /**
58      * @var footerTpl String variable of the Smarty template file used to render the footer portion
59      */
60     protected $footerTpl = 'include/EditView/footer.tpl';
61
62
63     /**
64      * @var defaultButtons Array of default buttons assigned to the form (see function.sugar_button.php)
65      */
66     protected $defaultButtons = array('DCMENUSAVE', 'DCMENUCANCEL', 'DCMENUFULLFORM');
67
68     /**
69      * @see SugarView::preDisplay()
70      */
71     public function preDisplay() 
72     {
73         if(!empty($_REQUEST['source_module']) && $_REQUEST['source_module'] != 'undefined' && !empty($_REQUEST['record'])) {
74                         $this->bean = loadBean($_REQUEST['source_module']);
75                         if ( $this->bean instanceOf SugarBean 
76                                 && !in_array($this->bean->object_name,array('EmailMan')) ) {
77                 $this->bean->retrieve($_REQUEST['record']);
78                 if(!empty($this->bean->id))$_REQUEST['parent_id'] = $this->bean->id;
79                 if(!empty($this->bean->module_dir))$_REQUEST['parent_type'] = $this->bean->module_dir;
80                 if(!empty($this->bean->name))$_REQUEST['parent_name'] = $this->bean->name;
81                 if(!empty($this->bean->id))$_REQUEST['return_id'] = $this->bean->id;
82                 if(!empty($this->bean->module_dir))$_REQUEST['return_module'] = $this->bean->module_dir;
83                 
84                 //Now preload any related fields 
85                             if(isset($_REQUEST['module'])) {
86                         $target_bean = loadBean($_REQUEST['module']);
87                         foreach($target_bean->field_defs as $fields) {  
88                                 if($fields['type'] == 'relate' && isset($fields['module']) && $fields['module'] == $_REQUEST['source_module'] && isset($fields['rname'])) {
89                                    $rel_name = $fields['rname'];
90                                    if(isset($this->bean->$rel_name)) {
91                                           $_REQUEST[$fields['name']] = $this->bean->$rel_name;
92                                    }
93                                         if(!empty($_REQUEST['record']) && !empty($fields['id_name'])) {
94                                                 $_REQUEST[$fields['id_name']] = $_REQUEST['record'];
95                                    }
96                                 }
97                         }
98                 }               
99             }
100             $this->_isDCForm = true;
101         }
102     }    
103     
104     /**
105      * @see SugarView::display()
106      */
107     public function display()
108     {       
109         $view = (!empty($_REQUEST['target_view']))?$_REQUEST['target_view']: 'QuickCreate';
110                 $module = $_REQUEST['module'];
111                 
112                 // locate the best viewdefs to use: 1. custom/module/quickcreatedefs.php 2. module/quickcreatedefs.php 3. custom/module/editviewdefs.php 4. module/editviewdefs.php
113                 $base = 'modules/' . $module . '/metadata/';
114                 $source = 'custom/' . $base . strtolower($view) . 'defs.php';
115                 if (!file_exists( $source))
116                 {
117                         $source = $base . strtolower($view) . 'defs.php';
118                         if (!file_exists($source))
119                         {
120                                 //if our view does not exist default to EditView
121                                 $view = 'EditView';
122                                 $source = 'custom/' . $base . 'editviewdefs.php';
123                                 if (!file_exists($source))
124                                 {
125                                         $source = $base . 'editviewdefs.php';
126                                 }
127                         }
128                 }
129
130                 $this->ev = new EditView();
131                 $this->ev->view = $view;
132                 $this->ev->ss = new Sugar_Smarty();
133                 
134                 $this->ev->ss->assign('isDCForm', $this->_isDCForm);
135                 //$_REQUEST['return_action'] = 'SubPanelViewer';
136                 $this->ev->setup($module, null, $source);
137                 $this->ev->showSectionPanelsTitles = false;
138             $this->ev->defs['templateMeta']['form']['headerTpl'] = $this->headerTpl;
139                 $this->ev->defs['templateMeta']['form']['footerTpl'] = $this->footerTpl;
140                 $this->ev->defs['templateMeta']['form']['buttons'] = $this->defaultButtons;
141                 $this->ev->defs['templateMeta']['form']['button_location'] = 'bottom';
142                 $this->ev->defs['templateMeta']['form']['hidden'] = '<input type="hidden" name="is_ajax_call" value="1" />';
143                 $this->ev->defs['templateMeta']['form']['hidden'] .= '<input type="hidden" name="from_dcmenu" value="1" />';
144                 $defaultProcess = true;
145
146         //Load the parent view class if it exists.  Check for custom file first
147         loadParentView('edit');
148
149                 if(file_exists('modules/'.$module.'/views/view.edit.php')) {
150             include('modules/'.$module.'/views/view.edit.php'); 
151
152             $c = $module . 'ViewEdit';
153             
154             if(class_exists($c)) {
155                     $view = new $c;
156                     if($view->useForSubpanel) {
157                         $defaultProcess = false;
158                         
159                         //Check if we shold use the module's QuickCreate.tpl file
160                         if($view->useModuleQuickCreateTemplate && file_exists('modules/'.$module.'/tpls/QuickCreate.tpl')) {
161                            $this->ev->defs['templateMeta']['form']['headerTpl'] = 'modules/'.$module.'/tpls/QuickCreate.tpl'; 
162                         }
163                         
164                             $view->ev = & $this->ev;
165                             $view->ss = & $this->ev->ss;
166                                         $class = $GLOBALS['beanList'][$module];
167                                         if(!empty($GLOBALS['beanFiles'][$class])){
168                                                 require_once($GLOBALS['beanFiles'][$class]);
169                                                 $bean = new $class();
170                                                 $view->bean = $bean;
171                                         }
172                                         $view->ev->formName = 'form_DC'.$view->ev->view .'_'.$module;
173                                         $view->showTitle = false; // Do not show title since this is for subpanel
174                             $view->display(); 
175                     }
176             }
177                 } //if
178                 
179                 if($defaultProcess) {
180                    $form_name = 'form_DC'.$this->ev->view .'_'.$module;
181                    $this->ev->formName = $form_name;
182                    $this->ev->process(true, $form_name);
183                    echo $this->ev->display(false, true);
184                 }
185         }
186 }