]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MVC/View/views/view.quickedit.php
Release 6.5.0
[Github/sugarcrm.git] / include / MVC / View / views / view.quickedit.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-2012 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
41 require_once('include/MVC/View/views/view.ajax.php');
42 require_once('include/EditView/EditView2.php');
43
44
45 class ViewQuickedit extends ViewAjax
46 {
47     /**
48      * $var true if this form is used in the Dashlet Container
49      */
50         protected $_isDCForm = false;
51
52         /**
53          * @var EditView object
54          */
55         protected $ev;
56
57     /**
58      * @var headerTpl String variable of the Smarty template file used to render the header portion
59      */
60     protected $headerTpl = 'include/EditView/header.tpl';
61
62     /**
63      * @var footerTpl String variable of the Smarty template file used to render the footer portion
64      */
65     protected $footerTpl = 'include/EditView/footer.tpl';
66
67     /**
68      * @var defaultButtons Array of default buttons assigned to the form (see function.sugar_button.php)
69      */
70     protected $defaultButtons = array('DCMENUSAVE', 'DCMENUCANCEL', 'DCMENUFULLFORM');
71
72     /**
73      * @see SugarView::preDisplay()
74      */
75     public function preDisplay()
76     {
77         if(!empty($_REQUEST['source_module']) && $_REQUEST['source_module'] != 'undefined' && !empty($_REQUEST['record'])) {
78                         $this->bean = loadBean($_REQUEST['source_module']);
79                         if ( $this->bean instanceOf SugarBean
80                                 && !in_array($this->bean->object_name,array('EmailMan')) ) {
81                 $this->bean->retrieve($_REQUEST['record']);
82                 if(!empty($this->bean->id))$_REQUEST['parent_id'] = $this->bean->id;
83                 if(!empty($this->bean->module_dir))$_REQUEST['parent_type'] = $this->bean->module_dir;
84                 if(!empty($this->bean->name))$_REQUEST['parent_name'] = $this->bean->name;
85                 if(!empty($this->bean->id))$_REQUEST['return_id'] = $this->bean->id;
86                 if(!empty($this->bean->module_dir))$_REQUEST['return_module'] = $this->bean->module_dir;
87
88                 //Now preload any related fields
89                             if(isset($_REQUEST['module'])) {
90                         $target_bean = loadBean($_REQUEST['module']);
91                         foreach($target_bean->field_defs as $fields) {
92                                 if($fields['type'] == 'relate' && isset($fields['module']) && $fields['module'] == $_REQUEST['source_module'] && isset($fields['rname'])) {
93                                    $rel_name = $fields['rname'];
94                                    if(isset($this->bean->$rel_name)) {
95                                           $_REQUEST[$fields['name']] = $this->bean->$rel_name;
96                                    }
97                                         if(!empty($_REQUEST['record']) && !empty($fields['id_name'])) {
98                                                 $_REQUEST[$fields['id_name']] = $_REQUEST['record'];
99                                    }
100                                 }
101                         }
102                 }
103             }
104             $this->_isDCForm = true;
105         }
106     }
107
108     /**
109      * @see SugarView::display()
110      */
111     public function display()
112     {       
113         if(($this->bean instanceOf SugarBean) && !$this->bean->ACLAccess('edit')){
114             $no_defs_js = '<script>SUGAR.ajaxUI.loadContent("index.php?module=' . $this->bean->module_dir . '&action=Noaccess&record=' . $this->bean->id.'")</script>';
115             echo json_encode(array('scriptOnly'=> $no_defs_js));
116             return;
117         }
118
119         $view = (!empty($_REQUEST['target_view']))?$_REQUEST['target_view']: 'QuickCreate';
120                 $module = $_REQUEST['module'];
121
122                 // locate the best viewdefs to use: 1. custom/module/quickcreatedefs.php 2. module/quickcreatedefs.php 3. custom/module/editviewdefs.php 4. module/editviewdefs.php
123                 $base = 'modules/' . $module . '/metadata/';
124                 $source = 'custom/' . $base . strtolower($view) . 'defs.php';
125                 if (!file_exists( $source))
126                 {
127                         $source = $base . strtolower($view) . 'defs.php';
128                         if (!file_exists($source))
129                         {
130                                 //if our view does not exist default to EditView
131                                 $view = 'EditView';
132                                 $source = 'custom/' . $base . 'editviewdefs.php';
133                                 if (!file_exists($source))
134                                 {
135                                         $source = $base . 'editviewdefs.php';
136                                 }
137                         }
138                 }
139
140         // In some cases, the source file will not exist. In these cases, just navigate to the full form directly.
141         if(!file_exists($source)){
142             global $app_strings;
143
144             //write out jscript that will get evaluated and redirect the browser window.
145             $no_defs_js = '<script>SUGAR.ajaxUI.loadContent("index.php?return_module='.$this->bean->module_dir.'&module=' . $this->bean->module_dir . '&action=EditView&record=' . $this->bean->id.'")</script>';
146
147             //reports is a special case as it does not have an edit view so navigate to wizard view
148             if(strtolower($module) == 'reports'){
149                 $no_defs_js = '<script>SUGAR.ajaxUI.loadContent("index.php?return_module='.$this->bean->module_dir.'&module=' . $this->bean->module_dir . '&action=ReportsWizard&record=' . $this->bean->id.'")</script>';
150             }
151             //if this is not reports and there are no edit view files then go to detail view
152             elseif(!file_exists('custom/' . $base . 'editviewdefs.php') && !file_exists($base . 'editviewdefs.php')
153             && !file_exists('custom/modules/' . $module .'/EditView.php') && !file_exists('modules/' . $module .'/EditView.php')
154             ){
155                 $no_defs_js = '<script>SUGAR.ajaxUI.loadContent("index.php?return_module='.$this->bean->module_dir.'&module=' . $this->bean->module_dir . '&action=DetailView&record=' . $this->bean->id.'")</script>';
156             }
157
158             echo json_encode(array('scriptOnly'=> $no_defs_js));
159
160           return;
161
162         }
163
164         $this->ev = $this->getEditView();
165                 $this->ev->view = $view;
166                 $this->ev->ss = new Sugar_Smarty();
167
168                 $this->ev->ss->assign('isDCForm', $this->_isDCForm);
169                 //$_REQUEST['return_action'] = 'SubPanelViewer';
170                 $this->ev->setup($module, $this->bean, $source);
171                 $this->ev->showSectionPanelsTitles = false;
172             $this->ev->defs['templateMeta']['form']['headerTpl'] = $this->headerTpl;
173                 $this->ev->defs['templateMeta']['form']['footerTpl'] = $this->footerTpl;
174                 $this->ev->defs['templateMeta']['form']['buttons'] = $this->defaultButtons;
175                 $this->ev->defs['templateMeta']['form']['button_location'] = 'bottom';
176                 $this->ev->defs['templateMeta']['form']['hidden'] = '<input type="hidden" name="is_ajax_call" value="1" />';
177                 $this->ev->defs['templateMeta']['form']['hidden'] .= '<input type="hidden" name="from_dcmenu" value="1" />';
178         $this->ev->defs['templateMeta']['form']['hideAudit']=true;
179
180         //use module level view if available
181         $editFileName = 'modules/'.$module.'/views/view.edit.php';
182         if(file_exists('custom/modules/'.$module.'/views/view.edit.php')) {
183             $editFileName = 'custom/modules/'.$module.'/views/view.edit.php';
184         }
185
186         $defaultProcess = true;
187         if(file_exists($editFileName)) {
188            include($editFileName);
189            $c = $module . 'ViewEdit';
190
191            if(class_exists($c)) {
192                $view = new $c;
193                if($view->useForSubpanel) {
194                         $defaultProcess = false;
195
196                    //Check if we should use the module's QuickCreate.tpl file
197                    if($view->useModuleQuickCreateTemplate && file_exists('modules/'.$module.'/tpls/QuickCreate.tpl')) {
198                       $this->ev->defs['templateMeta']['form']['headerTpl'] = 'modules/'.$module.'/tpls/QuickCreate.tpl';
199                    }
200
201                    $view->ev = & $this->ev;
202                    $view->ss = & $this->ev->ss;
203                    $class = $GLOBALS['beanList'][$module];
204                    if(!empty($GLOBALS['beanFiles'][$class])){
205                        require_once($GLOBALS['beanFiles'][$class]);
206                        $bean = new $class();
207                        if (isset($_REQUEST['record']) && $_REQUEST['record'] != false)
208                        {
209                            $bean->retrieve($_REQUEST['record']);
210                        }
211                        $view->bean = $bean;
212                    }
213                    $view->ev->formName = 'form_DC'.$view->ev->view .'_'.$module;
214                    $view->showTitle = false; // Do not show title since this is for subpanel
215                    ob_start();
216                    $view->display();
217                    $captured =  ob_get_clean();
218                    echo json_encode(array('title'=> $this->bean->name, 'url'=>'index.php?module=' . $this->bean->module_dir . '&action=DetailView&record=' . $this->bean->id ,'html'=> $captured, 'eval'=>true));
219                }
220            }
221        }
222
223         //if defaultProcess is still true, then the default edit view was not used.  Finish processing.
224         if($defaultProcess){
225                    $form_name = 'form_DC'.$this->ev->view .'_'.$module;
226                    $this->ev->formName = $form_name;
227                    $this->ev->process(true, $form_name);
228                         ob_clean();
229             echo json_encode(array('title'=> $this->bean->name, 'url'=>'index.php?module=' . $this->bean->module_dir . '&action=DetailView&record=' . $this->bean->id ,'html'=> $this->ev->display(false, true), 'eval'=>true));
230                 }
231         }
232
233
234     /**
235      * Get EditView object
236      * @return EditView
237      */
238     protected function getEditView()
239     {
240         return new EditView();
241     }
242 }