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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 * Changes to AbstractSubpanelImplementation for DeployedSubpanels
40 * The main differences are in the load and save of the definitions
41 * For subpanels we must make use of the SubPanelDefinitions class to do this; this also means that the history mechanism,
42 * which tracks files, not objects, needs us to create an intermediate file representation of the definition that it can manage and restore
45 require_once 'modules/ModuleBuilder/parsers/views/MetaDataImplementationInterface.php' ;
46 require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataImplementation.php' ;
47 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
49 class UndeployedSubpanelImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
52 const HISTORYFILENAME = 'restored.php' ;
53 const HISTORYVARIABLENAME = 'layout_defs' ;
57 * @param string subpanelName The name of this subpanel
58 * @param string moduleName The name of the module to which this subpanel belongs
59 * @param string packageName If not empty, the name of the package to which this subpanel belongs
61 function __construct ($subpanelName , $moduleName , $packageName)
63 $this->_subpanelName = $subpanelName ;
64 $this->_moduleName = $moduleName ;
67 $this->historyPathname = 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . self::HISTORYFILENAME ;
68 $this->_history = new History ( $this->historyPathname ) ;
70 //get the bean from ModuleBuilder
71 $mb = new ModuleBuilder ( ) ;
72 $this->module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
73 $this->module->mbvardefs->updateVardefs () ;
74 $this->_fielddefs = & $this->module->mbvardefs->vardefs [ 'fields' ] ;
76 $templates = & $this->module->config['templates'];
78 foreach ( $templates as $template => $a ){
79 if($a===1) $template_def = $template;
81 $template_subpanel_def = 'include/SugarObjects/templates/'.$template_def. '/metadata/subpanels/default.php';
82 if (file_exists($template_subpanel_def)){
83 include($template_subpanel_def);
84 if (!empty($subpanel_layout['list_fields']))
85 $this->_mergeFielddefs($this->_fielddefs, $subpanel_layout['list_fields']);
88 $subpanel_layout = $this->module->getAvailibleSubpanelDef ( $this->_subpanelName ) ;
89 $this->_viewdefs = & $subpanel_layout [ 'list_fields' ] ;
90 $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
92 // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
93 $selected_lang = 'en_us';
94 if(isset($GLOBALS['current_language']) &&!empty($GLOBALS['current_language'])) {
95 $selected_lang = $GLOBALS['current_language'];
97 $GLOBALS [ 'mod_strings' ] = array_merge ( $GLOBALS [ 'mod_strings' ], $this->module->getModStrings ($selected_lang) ) ;
100 function getLanguage ()
102 return "" ; // '' is the signal to translate() to use the global mod_strings
107 * @param array defs Layout definition in the same format as received by the constructor
108 * @param string type The location for the file - for example, MB_BASEMETADATALOCATION for a location in the OOB metadata directory
110 function deploy ($defs)
112 $outputDefs = $this->module->getAvailibleSubpanelDef ( $this->_subpanelName ) ;
113 // first sort out the historical record...
114 // copy the definition to a temporary file then let the history object add it
115 write_array_to_file ( self::HISTORYVARIABLENAME, $outputDefs, $this->historyPathname, 'w', '' ) ;
116 $this->_history->append ( $this->historyPathname ) ;
117 // no need to unlink the temporary file as being handled by in history->append()
118 //unlink ( $this->historyPathname ) ;
120 $outputDefs [ 'list_fields' ] = $defs ;
121 $this->_viewdefs = $defs ;
122 $this->module->saveAvailibleSubpanelDef ( $this->_subpanelName, $outputDefs ) ;