Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        WBCore
5
 * @package         WBCore_addons
6
 * @author          Werner v.d.Decken
7
 * @copyright       Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @revision        $Revision: 1669 $
11
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/addons/reload.php $
12
 * @lastmodified    $Date: 2012-04-17 15:14:20 +0200 (Tue, 17 Apr 2012) $
13
 */
14

    
15
/**
16
 * loop through all resource directories of one type and reload the resources
17
 * @param string $sType type of resource ( module / template / language )
18
 * @return bool
19
 */
20
	function ReloadAddonLoop($sType)
21
	{
22
		global $database;
23
		$sql = 'DELETE FROM `'.TABLE_PREFIX.'addons` WHERE `type`=\''.$sType.'\'';
24
		try{
25
			if(!$database->query($sql)) {
26
				throw new Exception('database error');
27
			}
28
			$oIterator = new DirectoryIterator(WB_PATH.'/'.$sType.'s');
29
			$_Function = 'load_'.$sType;
30
			foreach ($oIterator as $oFileinfo) {
31
				if( ( $oFileinfo->isFile() &&
32
					   $sType == 'language' &&
33
					   preg_match('/^([A-Z]{2}.php)/', $oFileinfo->getBasename())
34
					) ||
35
				    ($oFileinfo->isDir() && $sType != 'language')
36
				  )
37
				{
38
					if(substr($oFileinfo->getBasename(), 0,1) != '.') {
39
						$_Function($oFileinfo->getPathname());
40
					}
41
				}
42
			}
43
		}catch(Exception $e) {
44
			return false;
45
		}
46
		return true;
47
	}
48
/**
49
 * check if user has permissions to access this file
50
 */
51
// include all needed core files and check permission
52
	require_once('../../config.php');
53
	require_once('../../framework/class.admin.php');
54
	$aMsg = array();
55
	$aErrors = array();
56
// check user permissions for admintools (redirect users with wrong permissions)
57
	$admin = new admin('Admintools', 'admintools', false, false);
58
	if ($admin->get_permission('admintools'))
59
	{
60
		require_once(WB_PATH . '/framework/functions.php');
61
		require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
62
	// recreate Admin object without admin header
63
		$admin = new admin('Addons', '', false, false);
64
		$js_back = ADMIN_URL . '/addons/index.php?advanced';
65
	// check transaction
66
		if ($admin->checkFTAN())
67
		{
68
		// start the selected action
69
			if(isset($_POST['cmdCopyTheme']))
70
			{
71
				$sNewTheme = (isset($_POST['ThNewTheme']) ? $_POST['ThNewTheme'] : '');
72
				require(dirname(__FILE__).'/CopyTheme.php');
73
				$ct = new CopyTheme();
74
				$ct->execute(THEME_PATH, $sNewTheme);
75
				if($ct->isError()) {
76
					$aErrors[] = $ct->getError();
77
				}else {
78
					$aMsg[] = $TEXT['THEME_COPY_CURRENT'].' :: '.$MESSAGE['GENERIC_COMPARE'];
79
				}
80
				unset($ct);
81
		// ---------------------------
82
			}elseif(isset($_POST['cmdCopyTemplate']))
83
			{
84
				$aFileList = (isset($_POST['ThTemplate']) ? $_POST['ThTemplate'] : array());
85
				require(dirname(__FILE__).'/CopyThemeHtt.php');
86
				$x = CopyThemeHtt::doImport($aFileList);
87
				if(is_null($x)) {
88
					$aMsg[] = $TEXT['THEME_IMPORT_HTT'].' :: '.$MESSAGE['GENERIC_COMPARE'];
89
				}else {
90
					$aErrors = array_merge($aErrors, $x);
91
				}
92
		// ---------------------------
93
			}elseif(isset($_POST['cmdReload']))
94
			{
95
				$aReloadType = (isset($_POST['reload']) && is_array($_POST['reload'])) ? $_POST['reload'] : array();
96
				foreach($aReloadType as $sType) {
97
					$sType = rtrim($sType, 's');
98
					switch($sType) {
99
						case 'module':
100
						case 'template':
101
						case 'language':
102
						// reload all addons from given type
103
							if(ReloadAddonLoop($sType)) {
104
								$aMsg[] = $MESSAGE['ADDON_'.strtoupper($sType).'S_RELOADED'];
105
							}else {
106
								$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
107
							}
108
							break;
109
						default:
110
							$aErrors[] = $MESSAGE['GENERIC_NOT_COMPARE'].' ['.$sType.']';
111
							break;
112
					}
113
				}
114
			}else {
115
		// ---------------------------
116
				$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
117
			}
118
		}else { // invalid FTAN
119
			$aErrors[] = $MESSAGE['GENERIC_SECURITY_ACCESS'];
120
		}
121
	}else { // no permission
122
		$aErrors[] = $MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES'];
123
	}
124
	if(sizeof($aErrors) > 0)  {
125
// output error message
126
		$admin->print_header();
127
		$admin->print_error(implode('<br />', $aErrors), $js_back);
128
	}else {
129
// output success message
130
		$admin->print_header();
131
		$admin->print_success(implode('<br />', $aMsg), $js_back);
132
		$admin->print_footer();
133
	}
(4-4/4)