]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/SugarFeed/views/view.adminsettings.php
Release 6.5.0
[Github/sugarcrm.git] / modules / SugarFeed / views / view.adminsettings.php
1 <?php
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-2012 SugarCRM Inc.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38
39 class ViewAdminsettings extends SugarView 
40 {       
41     /**
42          * @see SugarView::_getModuleTab()
43          */
44         protected function _getModuleTab()
45     {
46         return 'Administration';
47     }
48         
49         /**
50          * @see SugarView::_getModuleTitleParams()
51          */
52         protected function _getModuleTitleParams($browserTitle = false)
53         {
54             global $mod_strings;
55             
56         return array(
57            "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
58            $mod_strings['LBL_MODULE_NAME'],
59            );
60     }
61     
62         /** 
63      * @see SugarView::display()
64      */
65         public function display()
66     {
67         global $mod_strings, $app_strings;
68         
69         $admin = new Administration();
70         $admin->retrieveSettings();
71         
72         // Handle posts
73         if ( !empty($_REQUEST['process']) ) {
74             // Check the cleanup logic hook, make sure it is still there
75             check_logic_hook_file('Users','after_login', array(1, 'SugarFeed old feed entry remover', 'modules/SugarFeed/SugarFeedFlush.php', 'SugarFeedFlush', 'flushStaleEntries'));
76         
77             // We have data posted
78             if ( $_REQUEST['process'] == 'true' ) {
79                 // They want us to process it, the false will just fall outside of this statement
80                 if ( $_REQUEST['feed_enable'] == '1' ) {
81                     // The feed is enabled, pay attention to what categories should be enabled or disabled
82         
83                     $db = DBManagerFactory::getInstance();
84                     $ret = $db->query("SELECT * FROM config WHERE category = 'sugarfeed' AND name LIKE 'module_%'");
85                     $current_modules = array();
86                     while ( $row = $db->fetchByAssoc($ret) ) {
87                         $current_modules[$row['name']] = $row['value'];
88                     }
89                     
90                     $active_modules = $_REQUEST['modules'];
91                     if ( ! is_array($active_modules) ) { $active_modules = array(); }
92                     
93                     foreach ( $active_modules as $name => $is_active ) {
94                         $module = substr($name,7);
95                         
96                         if ( $is_active == '1' ) {
97                             // They are activating something that was disabled before
98                             SugarFeed::activateModuleFeed($module);
99                         } else {
100                             // They are disabling something that was active before
101                             SugarFeed::disableModuleFeed($module);
102                         }
103                     }
104                     
105                     $admin->saveSetting('sugarfeed','enabled','1');
106                 } else {
107                     $admin->saveSetting('sugarfeed','enabled','0');
108                     // Now we need to remove all of the logic hooks, so they don't continue to run
109                     // We also need to leave the database alone, so they can enable/disable modules with the system disabled
110                     $modulesWithFeeds = SugarFeed::getAllFeedModules();
111                     
112                     foreach ( $modulesWithFeeds as $currFeedModule ) {
113                         SugarFeed::disableModuleFeed($currFeedModule,FALSE);
114                     }
115                 }
116         
117                 $admin->retrieveSettings(FALSE,TRUE);
118                 SugarFeed::flushBackendCache();
119             } else if ( $_REQUEST['process'] == 'deleteRecords' ) {
120                 if ( ! isset($db) ) {
121                     $db = DBManagerFactory::getInstance();
122                 }
123                 $db->query("UPDATE sugarfeed SET deleted = '1'");        
124                 echo(translate('LBL_RECORDS_DELETED','SugarFeed'));
125             }
126         
127         
128         
129             if ( $_REQUEST['process'] == 'true' || $_REQUEST['process'] == 'false' ) {
130                 header('Location: index.php?module=Administration&action=index');
131                 return;
132             }
133         }
134         
135         $sugar_smarty   = new Sugar_Smarty();
136         $sugar_smarty->assign('mod', $mod_strings);
137         $sugar_smarty->assign('app', $app_strings);
138         
139         if ( isset($admin->settings['sugarfeed_enabled']) && $admin->settings['sugarfeed_enabled'] == '1' ) {
140             $sugar_smarty->assign('enabled_checkbox','checked');
141         }
142         
143         $possible_feeds = SugarFeed::getAllFeedModules();
144         $module_list = array();
145         $userFeedEnabled = 0;
146         foreach ( $possible_feeds as $module ) {
147             $currModule = array();
148             if ( isset($admin->settings['sugarfeed_module_'.$module]) && $admin->settings['sugarfeed_module_'.$module] == '1' ) {
149                 $currModule['enabled'] = 1;
150             } else {
151                 $currModule['enabled'] = 0;
152             }
153         
154             $currModule['module'] = $module;
155             if ( $module == 'UserFeed' ) {
156                 // Fake module, need to handle specially
157                 $userFeedEnabled = $currModule['enabled'];
158                 continue;
159             } else {
160                 $currModule['label'] = $GLOBALS['app_list_strings']['moduleList'][$module];
161             }
162         
163             $module_list[] = $currModule;
164         }
165         $sugar_smarty->assign('module_list',$module_list);
166         $sugar_smarty->assign('user_feed_enabled',$userFeedEnabled);
167         
168         echo getClassicModuleTitle(
169                 "Administration", 
170                 array(
171                     "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
172                    $mod_strings['LBL_MODULE_NAME'],
173                    ), 
174                 false
175                 );
176         $sugar_smarty->display('modules/SugarFeed/tpls/AdminSettings.tpl');
177     }
178 }
179