2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
38 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
39 require_once ('modules/ModuleBuilder/Module/StudioModule.php') ;
40 require_once ('modules/ModuleBuilder/Module/StudioBrowser.php') ;
41 require_once ('modules/DynamicFields/DynamicField.php') ;
42 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
43 require_once 'modules/ModuleBuilder/parsers/views/DeployedMetaDataImplementation.php';
45 class ViewResetmodule extends SugarView
48 * @see SugarView::_getModuleTitleParams()
50 protected function _getModuleTitleParams($browserTitle = false)
55 translate('LBL_MODULE_NAME','Administration'),
56 ModuleBuilderController::getModuleTitle(),
62 $moduleName = $this->module = $_REQUEST['view_module'];
63 if (isset($_REQUEST['handle']) && $_REQUEST['handle'] == "execute") {
64 return $this->handleSave();
67 $ajax = new AjaxCompose ( ) ;
68 $ajax->addCrumb ( translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")' ) ;
69 $ajax->addCrumb ( translate($moduleName), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $moduleName . '")' ) ;
70 $ajax->addCrumb ( translate('LBL_RESET') . " " . translate($moduleName) , '') ;
72 $smarty = new Sugar_Smarty ( ) ;
73 $smarty->assign("module", $moduleName);
74 $smarty->assign("actions", array(
75 array("name" => "relationships", "label" => translate("LBL_CLEAR_RELATIONSHIPS")),
76 array("name" => "fields", "label" => translate("LBL_REMOVE_FIELDS")),
77 array("name" => "layouts", "label" => translate("LBL_RESET_LAYOUTS")),
78 array("name" => "labels", "label" => translate("LBL_RESET_LABELS")),
79 array("name" => "extensions", "label" => translate("LBL_CLEAR_EXTENSIONS")),
84 "Reset ". translate($moduleName) ,
85 $smarty->fetch('modules/ModuleBuilder/tpls/resetModule.tpl') //"This works now"
88 echo $ajax->getJavascript () ;
93 $out = "<script>ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);</script>";
95 if (!empty($_REQUEST['relationships']))
96 $out .= $this->removeCustomRelationships();
98 if (!empty($_REQUEST['fields']))
99 $out .= $this->removeCustomFields();
101 if (!empty($_REQUEST['layouts']))
102 $out .= $this->removeCustomLayouts();
104 if (!empty($_REQUEST['labels']))
105 $out .= $this->removeCustomLabels();
107 if (!empty($_REQUEST['extensions']))
108 $out .= $this->removeCustomExtensions();
113 $ajax = new AjaxCompose ( ) ;
115 $ajax->addCrumb ( translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")' ) ;
116 $ajax->addCrumb ( translate($this->module), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->module . '")' ) ;
117 $ajax->addCrumb ( "Reset ". translate($this->module) , '') ;
122 "Reset ". translate($this->module) ,
126 echo $ajax->getJavascript () ;
130 * Removes all custom fields created in studio
132 * @return html output record of the field deleted
134 function removeCustomFields()
136 $moduleName = $this->module;
137 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
138 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
139 $seed = new $class_name ( ) ;
140 $df = new DynamicField ( $moduleName ) ;
141 $df->setup ( $seed ) ;
144 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
145 $customFields = array();
146 foreach($seed->field_defs as $def) {
147 if(isset($def['source']) && $def['source'] == 'custom_fields') {
148 $field = $df->getFieldWidget($moduleName, $def['name']);
149 $field->delete ( $df ) ;
151 $module->removeFieldFromLayouts( $def['name'] );
152 $customFields[] = $def['name'];
156 foreach ($customFields as $field) {
157 $out .= "Removed field $field<br/>";
163 * Removes the metadata files for all known studio layouts.
165 * @return html output record of the files deleted
167 function removeCustomLayouts()
169 $module = StudioModuleFactory::getStudioModule( $this->module ) ;
170 $sources = $module->getViewMetadataSources();
173 foreach($sources as $view)
175 $file = DeployedMetaDataImplementation::getFileName($view['type'], $this->module);
176 if (file_exists($file)) {
178 $out .= "Removed layout {$view['type']}.php<br/>";
182 // now clear the cache
183 include_once ('include/TemplateHandler/TemplateHandler.php') ;
184 TemplateHandler::clearCache ( $this->module ) ;
190 * Removes all custom relationships containing this module
192 * @return html output record of the files deleted
194 function removeCustomRelationships()
196 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
198 $madeChanges = false;
199 $relationships = new DeployedRelationships ( $this->module ) ;
201 foreach ( $relationships->getRelationshipList () as $relationshipName )
203 $rel = $relationships->get ( $relationshipName )->getDefinition () ;
204 if ($rel [ 'is_custom' ] || (isset($rel [ 'from_studio' ]) && $rel [ 'from_studio' ])) {
205 $relationships->delete ($relationshipName);
206 $out .= "Removed relationship $relationshipName<br/>";
210 $relationships->save () ;
215 function removeCustomLabels()
218 $languageDir = "custom/modules/{$this->module}/language";
219 if (is_dir($languageDir)) {
220 $files = scandir($languageDir);
221 foreach ($files as $langFile) {
222 if (substr($langFile, 0 ,1) == '.') continue;
223 $language = substr($langFile, 0, strlen($langFile) - 9);
224 unlink($languageDir . "/" . $langFile);
226 LanguageManager::clearLanguageCache ( $this->module, $language ) ;
227 $out .= "Removed language file $langFile<br/>";
234 function removeCustomExtensions()
237 $extDir = "custom/Extension/modules/{$this->module}";
238 if (is_dir($extDir)) {
239 rmdir_recursive($extDir);
240 require_once ('modules/Administration/QuickRepairAndRebuild.php') ;
241 $rac = new RepairAndClear ( ) ;
242 $rac->repairAndClearAll ( array ( 'clearAll' ), array ( $this->module ), true, false ) ;
243 $rac->rebuildExtensions();
244 $out .= "Cleared extensions for {$this->module}<br/>";