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.
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.
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
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
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.
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.
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 ********************************************************************************/
41 require_once('include/MVC/View/views/view.ajax.php');
42 require_once('include/EditView/EditView2.php');
45 class ViewQuickedit extends ViewAjax
48 * $var true if this form is used in the Dashlet Container
50 protected $_isDCForm = false;
53 * @var EditView object
58 * @see SugarView::preDisplay()
60 public function preDisplay()
62 if(!empty($_REQUEST['source_module']) && $_REQUEST['source_module'] != 'undefined' && !empty($_REQUEST['record'])) {
63 $this->bean = loadBean($_REQUEST['source_module']);
64 if ( $this->bean instanceOf SugarBean
65 && !in_array($this->bean->object_name,array('EmailMan')) ) {
66 $this->bean->retrieve($_REQUEST['record']);
67 if(!empty($this->bean->id))$_REQUEST['parent_id'] = $this->bean->id;
68 if(!empty($this->bean->module_dir))$_REQUEST['parent_type'] = $this->bean->module_dir;
69 if(!empty($this->bean->name))$_REQUEST['parent_name'] = $this->bean->name;
70 if(!empty($this->bean->id))$_REQUEST['return_id'] = $this->bean->id;
71 if(!empty($this->bean->module_dir))$_REQUEST['return_module'] = $this->bean->module_dir;
73 //Now preload any related fields
74 if(isset($_REQUEST['module'])) {
75 $target_bean = loadBean($_REQUEST['module']);
76 foreach($target_bean->field_defs as $fields) {
77 if($fields['type'] == 'relate' && isset($fields['module']) && $fields['module'] == $_REQUEST['source_module'] && isset($fields['rname'])) {
78 $rel_name = $fields['rname'];
79 if(isset($this->bean->$rel_name)) {
80 $_REQUEST[$fields['name']] = $this->bean->$rel_name;
82 if(!empty($_REQUEST['record']) && !empty($fields['id_name'])) {
83 $_REQUEST[$fields['id_name']] = $_REQUEST['record'];
89 $this->_isDCForm = true;
94 * @see SugarView::display()
96 public function display()
99 $view = (!empty($_REQUEST['target_view']))?$_REQUEST['target_view']: 'QuickCreate';
100 $module = $_REQUEST['module'];
102 // locate the best viewdefs to use: 1. custom/module/quickcreatedefs.php 2. module/quickcreatedefs.php 3. custom/module/editviewdefs.php 4. module/editviewdefs.php
103 $base = 'modules/' . $module . '/metadata/';
104 $source = 'custom/' . $base . strtolower($view) . 'defs.php';
105 if (!file_exists( $source))
107 $source = $base . strtolower($view) . 'defs.php';
108 if (!file_exists($source))
110 //if our view does not exist default to EditView
112 $source = 'custom/' . $base . 'editviewdefs.php';
113 if (!file_exists($source))
115 $source = $base . 'editviewdefs.php';
120 //in some cases, the source file will not exist. In these cases lets just navigate to the full form directlhy
121 if(!file_exists($source)){
124 //write out jscript that will get evaluated and redirect the browser window.
125 $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>';
127 //reports is a special case as it does not have an edit view so navigate to wizard view
128 if(strtolower($module) == 'reports'){
129 $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>';
131 //if this is not reports and there are no edit view files then go to detail view
132 elseif(!file_exists('custom/' . $base . 'editviewdefs.php') && !file_exists($base . 'editviewdefs.php')
133 && !file_exists('custom/modules/' . $module .'/EditView.php') && !file_exists('modules/' . $module .'/EditView.php')
135 $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>';
138 echo json_encode(array('scriptOnly'=> $no_defs_js));
144 $this->ev = new EditView();
145 $this->ev->view = $view;
146 $this->ev->ss = new Sugar_Smarty();
148 $this->ev->ss->assign('isDCForm', $this->_isDCForm);
149 //$_REQUEST['return_action'] = 'SubPanelViewer';
150 $this->ev->setup($module, $this->bean, $source);
151 $this->ev->showSectionPanelsTitles = false;
152 $this->ev->defs['templateMeta']['form']['headerTpl'] = 'include/EditView/header.tpl';
153 $this->ev->defs['templateMeta']['form']['footerTpl'] = 'include/EditView/footer.tpl';
154 $this->ev->defs['templateMeta']['form']['buttons'] = array('DCMENUSAVE', 'DCMENUCANCEL', 'DCMENUFULLFORM');
155 $this->ev->defs['templateMeta']['form']['button_location'] = 'bottom';
156 $this->ev->defs['templateMeta']['form']['hidden'] = '<input type="hidden" name="is_ajax_call" value="1" />';
157 $this->ev->defs['templateMeta']['form']['hidden'] .= '<input type="hidden" name="from_dcmenu" value="1" />';
158 $this->ev->defs['templateMeta']['form']['hideAudit']=true;
160 //use module level view if available
161 $editFileName = 'modules/'.$module.'/views/view.edit.php';
162 if(file_exists('custom/modules/'.$module.'/views/view.edit.php')) {
163 $editFileName = 'custom/modules/'.$module.'/views/view.edit.php';
166 $defaultProcess = true;
167 if(file_exists($editFileName)) {
168 include($editFileName);
169 $c = $module . 'ViewEdit';
171 if(class_exists($c)) {
173 if($view->useForSubpanel) {
174 $defaultProcess = false;
176 //Check if we should use the module's QuickCreate.tpl file
177 if($view->useModuleQuickCreateTemplate && file_exists('modules/'.$module.'/tpls/QuickCreate.tpl')) {
178 $this->ev->defs['templateMeta']['form']['headerTpl'] = 'modules/'.$module.'/tpls/QuickCreate.tpl';
181 $view->ev = & $this->ev;
182 $view->ss = & $this->ev->ss;
183 $class = $GLOBALS['beanList'][$module];
184 if(!empty($GLOBALS['beanFiles'][$class])){
185 require_once($GLOBALS['beanFiles'][$class]);
186 $bean = new $class();
189 $view->ev->formName = 'form_DC'.$view->ev->view .'_'.$module;
190 $view->showTitle = false; // Do not show title since this is for subpanel
193 $captured = ob_get_clean();
194 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));
199 //if defaultProcess is still true, then the default edit view was not used. Finish processing.
201 $form_name = 'form_DC'.$this->ev->view .'_'.$module;
202 $this->ev->formName = $form_name;
203 $this->ev->process(true, $form_name);
205 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));