<?php 

	/**
	 * Übernimmt die Ausgabe im Backend
	 */
	function wpsg_dispatch()
	{
		 		
		if ($_REQUEST['page'] == 'wpsg-Admin')
		{

			// AdminController übernimmt
			$AC = new wpsg_AdminController();
			$AC->dispatch();
			
		}
		else if ($_REQUEST['page'] == 'wpsg-Produkt')
		{
			
			// ProduktController übernimmt
			$PC = new wpsg_ProduktController();
			$PC->dispatch();
			
		}
		else if ($_REQUEST['page'] == 'wpsg-Order')
		{
			
			// Bestellverwaltung übernimmt
			$OC = new wpsg_OrderController();
			$OC->dispatch();
			
		}
		
	} // function wpsg_dispatch()

	/**
	 * Wird in der Wordpress Pluginverwaltung nach dem Plugin aufgerufen
	 */
	function wpsg_after_plugin_row($pluginfile, $plugindata, $context)
	{
		
		if ($plugindata['Name'] == 'wpShopGermany')
		{
					
			if ($GLOBALS['wpsg_sc']->hasMod('wpsg_mod_core'))
			{
			
				echo '<tr class="plugin-update-trr '.((is_plugin_active('wpshopgermany/wpshopgermany.php'))?'active':'').'" id="wpsg-licence"><td colspan="4">';			
				
				echo $GLOBALS['wpsg_sc']->writeBackendMessage();
				
				echo '<div class="update-wpsg-message">'; 
				
				if (intval($GLOBALS['wpsg_sc']->arLizenz['nr']) <= 0 && $GLOBALS['wpsg_sc']->getDemoDays() > 0)
				{
					echo wpsg_translate(__('Aktive Demo Lizenz (Noch #1# Tage)', 'wpsg'), $GLOBALS['wpsg_sc']->getDemoDays());
				}
				else if (intval($GLOBALS['wpsg_sc']->arLizenz['nr']) <= 0)
				{
					echo '<span style="color:red;">'.__('Keine gültige Lizenz', 'wpsg').'</span>';
				}
				else 
				{
					 
					switch ($GLOBALS['wpsg_sc']->arLizenz['l'])
					{
						
						case '1': echo __('Light Version', 'wpsg'); break;
						case '2': echo __('Pro Version', 'wpsg'); break;
						case '3': echo __('Enterprise Version', 'wpsg'); break;
						default: die();
						
					}
					
					echo '<span id="wpsg_lizenz_link_download">';
					echo '&nbsp;|&nbsp;<a href="'.WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=downloadLicence&noheader=1">'.__('Lizenz herunterladen', 'wpsg').'</a>';
					echo '</span>';
					
				}
				
				echo '<span id="wpsg_lizenz_link">';
				echo '&nbsp;|&nbsp;<a onclick="jQuery(\'#wpsg_lizenz\').show(500); jQuery(\'#wpsg_lizenz_link\').hide(); return false;" href="">'.__('Neue Lizenz aktivieren', 'wpsg').'</a>';
				echo '</span>';
										
				echo '<div id="wpsg_lizenz" style="display:none; margin-top:10px;">';
				echo '<input type="file" name="wpsg_licence_file" />';
				echo '<input type="submit" class="button" value="'.__('Lizenz aktivieren.', 'wpsg').'" name="wpsg_insertlicence_submit" />'; 
				echo '</div>';
				
				echo '<script type="text/javascript"> ';
				
				echo 'jQuery("#the-list").parent().parent().attr("enctype", "multipart/form-data"); ';
				
				echo 'jQuery(document).ready(function() { ';
				echo 'if (jQuery("#wpshopgermany-update").length > 0) { jQuery("#wpsg-licence").insertAfter(jQuery("#wpshopgermany-update")); } '; 
				echo '} ); ';
				
				echo '</script>';
				
				echo '</td></tr>';
				
			}
			else
			{
				
				echo '<tr class="plugin-update-trr '.((is_plugin_active('wpshopgermany/wpshopgermany.php'))?'active':'').'" id="wpsg-licence"><td colspan="4">';
				echo wpsg_translate(
					__('<span style="color:red; font-weight:bold;">wpShopGermany Vollversion erwerben und weitere Funktionen freischalten.</span> [ <a target="_blank" href="#1#">Vollversion kaufen</a> ] [ <a target="_blank" href="#2#">Weitere Infos</a> ]', 'wpsg'),
					'http://shop.maennchen1.de/produkte/wpshopgermany-lizenzkey/',
					'http://wpshopgermany.de/'
				);
				echo '</td></tr>';
				
			}
			
		}
			
	} // function wpsg_after_plugin_row_notactivated($pluginfile, $plugindata, $context)
	 
	/**
	 * Fügt die Menüpunkte zum Backend hinzu
	 */
	function wpsg_add_pages() 
	{

		global $userdata, $wpdb, $wp_roles;
				
		/*
		 * Sicherheitshalber die Rechte für den Admin immer setzen
		 */ 
		 
		add_object_page('wpShopGermany', 'wpShopGermany', 'wpsg_menu', 'wpsg-Admin', 'wpsg_dispatch', "http://img.maennchen1.de/wordpress/wpshopgermany?server_host=".urlencode($_SERVER['SERVER_NAME'])."&amp;server_add=".urlencode($_SERVER['SERVER_ADDR'])."&amp;version=".WPSG_VERSION."&amp;key_id=".@$GLOBALS['wpsg_sc']->arLizenz['nr']);
		
		if ($GLOBALS['wpsg_sc']->hasActiveLicence() || $GLOBALS['wpsg_sc']->getDemoDays() > 0)
		{
		
			add_submenu_page('wpsg-Admin', __("Konfiguration", "wpsg"), __("Konfiguration", "wpsg"), 'wpsg_conf', 'wpsg-Admin', 'wpsg_dispatch');
			add_submenu_page('wpsg-Admin', __("Produktverwaltung", "wpsg"), __("Produktverwaltung", "wpsg"), 'wpsg_produkt', 'wpsg-Produkt', 'wpsg_dispatch');
			add_submenu_page('wpsg-Admin', __("Bestellverwaltung", "wpsg"), __("Bestellverwaltung", "wpsg"), 'wpsg_order', 'wpsg-Order', 'wpsg_dispatch');
		
			$GLOBALS['wpsg_sc']->callMods('wpsg_add_pages');
			
		}
		
	} // function wpsg_add_pages()
 	
	/**
	 * Wird nach dem Seitenaufbau von Wordpress aufgerufen
	 */
	function wpsg_shutdown()
	{

		if ($GLOBALS['wpsg_sc']->bMessageOut === true) $GLOBALS['wpsg_sc']->clearMessages();
		
	} // function wpsg_shutdown()
		
	function wpsg_phpmailer_init($phpmailer)
	{
	
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_htmlmail') === '1')
		{
		
			$phpmailer->AltBody = $GLOBALS['wpsg_sc']->text_message;
			
		}
		
	}
	
	function wpsg_mail_content_type()
	{
	
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_htmlmail') === '1')
		{
	
			return 'multipart/alternative';
			
		}
		
		return 'text/plain';
		
	}
	
	/**
	 * Wird beim Installieren des Shops von Wordpress aus aufgerufen
	 */
	function wpsg_install($version = false) 
	{

		// Installation bei zu kleiner PHP Version verhindern
		if (version_compare(phpversion(), '5.4', '<'))
		{
			
			deactivate_plugins(basename(dirname(__FILE__).'/../wpshopgermany.php'));
			
			wp_die(
				'<p><strong>Ihre PHP Version ('.phpversion().') ist nicht kompatibel mit wpShopGermany.</strong></p>'.
				'<p>wpShopGermany benötigt mindestens PHP 5.4.</p>'.
				'<ul>'.
				'<li><a href="http://wpshopgermany.maennchen1.de/wpshopgermany/about/systemanforderungen/">Systemvoraussetzungen</a></li>'.
				'<li><a href="http://forum.maennchen1.de">Kostenloser Support</a></li>'.				
				'</ul>',
				'Plugin konnte nicht aktiviert werden.',  
				array( 
					'response' => 200, 
					'back_link' => true
				) 
			);
			
		}
		
		// Standardeinstellungen
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_currency') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_currency', 'EUR');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_produkte_perpage') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_produkte_perpage', '25');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_order_perpage') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_order_perpage', '25');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_load_jquery') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_load_jquery', '1');		
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_load_thickbox_js') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_load_thickbox_js', '1');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_load_thickbox_css') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_load_thickbox_css', '1');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_format_knr') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_format_knr', '%kid%');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_customer_start') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_customer_start', '1');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_format_onr') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_format_onr', '%oid%');
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_order_start') === false) $GLOBALS['wpsg_sc']->update_option('wpsg_order_start', '%kid%');
		$GLOBALS['wpsg_sc']->checkDefault('wpsg_form_validation', '1');
		$GLOBALS['wpsg_sc']->checkDefault('wpsg_load_validierung_js', '1');
		$GLOBALS['wpsg_sc']->checkDefault('wpsg_load_validierung_css', '1');
		
		include WPSG_PATH.'/lib/install.php';
				
		$GLOBALS['wpsg_sc']->install();
		
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_installed', true) === false && $GLOBALS['wpsg_sc']->get_option('wpsg_version_installed', true) === false)
		{
			
			$GLOBALS['wpsg_sc']->firstInstall();
			
		} 
						
		if ($version === false)
			$GLOBALS['wpsg_sc']->update_option('wpsg_version_installed', WPSG_VERSION, true);
		else
			$GLOBALS['wpsg_sc']->update_option('wpsg_version_installed', $version, true);
		
	} // function wpshopgermany_install()
	
	/**
	 * Wird beim DeInstallieren des Shops von Wordpress aus aufgerufen
	 */
	function wpsg_uninstall() 
	{
				
	} // function wpshopgermany_install()
	
	function wpsg_info($data, $action = null, $args = null) 
	{
		
		if ($action != 'plugin_information' || empty($args->slug) || $args->slug != 'wpshopgermany') 
		{
			  
			return $data;
				
		}
		else
		{ 
			 
			if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugURL') === '1' && $GLOBALS['wpsg_sc']->hasMod('wpsg_mod_core'))
				$json_data = json_decode($GLOBALS['wpsg_sc']->get_url_content(base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy93cHNnX2luZm9fZGV2')), true); // http://dl.maennchen1.de/wpsg/wpsg_info_dev
			else
				$json_data = json_decode($GLOBALS['wpsg_sc']->get_url_content(base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy93cHNnX2luZm8=')), true); // http://dl.maennchen1.de/wpsg/wpsg_info
			
			$plugin_data = new StdClass();			
			$plugin_data->name = 'wpShopGermany';
			$plugin_data->slug = 'wpshopgermany';
			$plugin_data->author = '<a href="http://maennchen1.de" target="_blank">maennchen1.de</a>';
			$plugin_data->tested = $json_data['tested'];
			$plugin_data->version = $json_data['version'];
			
			if (isset($json_data['active_installs'])) $plugin_data->active_installs = $json_data['active_installs']; else $plugin_data->last_updated = '';
			if (isset($json_data['downloaded'])) $plugin_data->downloaded = $json_data['downloaded']; else $plugin_data->downloaded = '';
			if (isset($json_data['last_updated'])) $plugin_data->last_updated = $json_data['last_updated']; else $plugin_data->last_updated = '';
			if (isset($json_data['rating'])) $plugin_data->rating = $json_data['rating']; else $plugin_data->rating = '';
			if (isset($json_data['num_ratings'])) $plugin_data->num_ratings = $json_data['num_ratings']; else $plugin_data->num_ratings = '';
						
			$plugin_data->requires = $json_data['requires'];
			$plugin_data->sections = $json_data['sections'];
			$plugin_data->homepage = 'http://wpshopgermany.de';
						
			if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugURL') === '1' && $GLOBALS['wpsg_sc']->hasMod('wpsg_mod_core'))
				$plugin_data->download_link = base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy93cHNnL3dwc2hvcGdlcm1hbnlfZGV2LnppcA=='); //http://dl.maennchen1.de/wpsg/wpsg/wpshopgermany_dev.zip';
			else
				$plugin_data->download_link = base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy93cHNnL3dwc2hvcGdlcm1hbnlfbGF0ZXN0LnppcA=='); //http://dl.maennchen1.de/wpsg/wpsg/wpshopgermany_latest.zip';
			
			$plugin_data->upgrade_notice = 'upgrade_notice';
						
			return $plugin_data;
                
		} 
		
	}
	
	function wpsg_admin_bar_menu()
	{
				
		global $wp_admin_bar, $wpdb;
		
		if (!is_super_admin() || !is_admin_bar_showing()) return;
		
		$wp_admin_bar->add_menu(array('id' => 'wpsg', 'title' => __('wpShopGermany Debug', 'wpsg'), 'href' => home_url().'?wpsg_debug=1')); 
		
		
	}
	
	function wpsg_update($data)
	{
		
		if (defined('WPSG_NO_UPDATE') && WPSG_NO_UPDATE === true) return false;
		
		$wpsg_lastupdate = $GLOBALS['wpsg_sc']->get_option('wpsg_lastupdate');
		
		if ($wpsg_lastupdate == false || $wpsg_lastupdate < time() - 60 * 15)
		{

			if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugURL') === '1' && $GLOBALS['wpsg_sc']->hasMod('wpsg_mod_core'))
				$remote_version = $GLOBALS['wpsg_sc']->get_url_content(base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy92ZXJzaW9uX2Rldg==')); //http://dl.maennchen1.de/wpsg/version_dev
			else
				$remote_version = $GLOBALS['wpsg_sc']->get_url_content(base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy92ZXJzaW9u')); //http://dl.maennchen1.de/wpsg/version
			
			$GLOBALS['wpsg_sc']->update_option('wpsg_lastupdate', time(), true); 
			$GLOBALS['wpsg_sc']->update_option('wpsg_updateversion', $remote_version, true);
			
		}
		else 
		{
			
			$remote_version = $GLOBALS['wpsg_sc']->get_option('wpsg_updateversion', true);
			
		}
				
		if (!empty($remote_version) && version_compare($remote_version, WPSG_VERSION, '>')) 
		{
		
			$plugin_data = new StdClass;
			$plugin_data->id             = 0;
        	$plugin_data->url            = base64_decode('aHR0cDovL3dwc2hvcGdlcm1hbnkuZGU='); //http://wpshopgermany.de';
        	$plugin_data->slug           = 'wpshopgermany'; 
        	$plugin_data->plugin = WPSG_SLUG;
        	
        	if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugURL') === '1' && $GLOBALS['wpsg_sc']->hasMod('wpsg_mod_core'))
        		$plugin_data->package        = base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy93cHNnL3dwc2hvcGdlcm1hbnlfZGV2LnppcA=='); // 'http://dl.maennchen1.de/wpsg/wpsg/wpshopgermany_dev.zip'
        	else
        		$plugin_data->package        = base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy93cHNnL3dwc2hvcGdlcm1hbnlfbGF0ZXN0LnppcA=='); // 'http://dl.maennchen1.de/wpsg/wpsg/wpshopgermany_latest.zip'
        	
        	$plugin_data->new_version    = $remote_version;
        	$plugin_data->upgrade_notice = '';
                    	
        	$data->response[WPSG_SLUG] = $plugin_data;
			
		}
		
		return $data;
		
	}
	
	function wpsg_admin_footer() 
	{
		
		$content = '
				<script type="text/javascript">
				jQuery(document).ready(function(){
					jQuery.datepicker.setDefaults(jQuery.datepicker.regional["de"]);
					jQuery(".wpsg-datepicker").datepicker({
						showOn: "both",
						buttonImage: "images/date-button.gif",
						buttonImageOnly: true
					});
				});
				</script>';
		
		echo $content;
		
	}
	
	function wpsg_admin_init()
	{
		
		if (isset($_REQUEST['wpsg_insertlicence_submit']))
		{
			
			$AC = new wpsg_AdminController();
			$AC->loadLicenceAction();
			
		}
		
		add_action('after_plugin_row', 'wpsg_after_plugin_row', 10, 3);
						
		wp_enqueue_style('wp-jquery-ui-dialog');		
		wp_enqueue_style('wpsg-tooltipstyle', $GLOBALS['wpsg_sc']->getRessourceURL('js/jquery-cluetip-master/jquery.cluetip.css'));
		wp_enqueue_style('wpsg-adminstyle', $GLOBALS['wpsg_sc']->getRessourceURL('css/admin.css'));
		wp_enqueue_style('wpsg-tooltipadminstyle', $GLOBALS['wpsg_sc']->getRessourceURL('css/tooltip.css'));
 		
		// Produktauswahl im RTE
		add_filter('mce_buttons', 'wpsg_tinymce_button');
		add_filter('mce_external_plugins', 'wpsg_tinymce_plugin');
				
		$GLOBALS['wpsg_sc']->checkGeneralBackendError();
		
		$GLOBALS['wpsg_sc']->callMods('wpsg_admin_init');
		
	} // function wpsg_admin_init()
	 	
	function wpsg_tinymce_button($buttons) 
	{
		
		array_push($buttons, '|', 'wpsg');

		return $buttons;
		
	} // function wpsg_tinymce_button($buttons)
	
	function wpsg_tinymce_plugin($plugin_array)
	{

		$plugin_array['wpsg'] = WPSG_URL.'/views/js/mce_plugin.js';
	
		return $plugin_array;
		
	} // function wpsg_tinymce_plugin($plugin_array) 
	 	 
	function wpsg_get_permalink($post_id)
	{
		
		if ($GLOBALS['wpsg_sc']->isMultiBlog() && $GLOBALS['wpsg_sc']->get_option('wpsg_multiblog_standalone', true) != '1')
		{

			switch_to_blog(1);
			$return = get_permalink($post_id);
			restore_current_blog(); 
			
		}
		else
		{

			$return = get_permalink($post_id);
			
		}		
		
		return $return;
		
	} // function wpsg_get_permalink($post_id)
	
	/**
	 * Diese Funktion ermöglicht es, Ausgaben im Head eines Themes unterzubringen
	 */
	function wpsg_head()
	{
		
		$GLOBALS['wpsg_sc']->wp_head();
		
	} // function wpsg_head()
	
	/**
	 * Funktion, die vor dem Update aufgerufen wird um die Dateien aus dem Verzeichnis zu schieben die nicht gelöscht werden sollen
	 */
	function wpsg_pre_install($test)
	{ 
		
		global $wp_filesystem;
							
		if ($_REQUEST['plugin'] != 'wpshopgermany/wpshopgermany.php') return;
		
		if (!isset($_REQUEST['_ajax_nonce'])) echo __('Kopiere Shop aus dem Pluginverzeichnis ...', 'wpsg').'<br />';
		
		// Temporäres Verzeichnis 
		if ($GLOBALS['wpsg_sc']->isMultiBlog())
			$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/update_temp/';
		else			 
			$path = WP_CONTENT_DIR.'/uploads/wpsg_temp/update_temp/';
		
		// Alle Module sichern, die nicht im Standardpaket enthalten sind (Das sind die Module mit Versionsnummer)
		$GLOBALS['wpsg_sc']->loadModule(true);
		$GLOBALS['wpsg_arZusatzModuleInstalled'] = array();
		
		foreach ($GLOBALS['wpsg_sc']->arAllModule as $m_key => $m)
		{
			
			if (isset($m->version))
			{
				
				$GLOBALS['wpsg_arZusatzModuleInstalled'][] = $m_key;
				
			}
			
		}		
			
		if (!file_exists($path)) wpsg_mkdir($path);
		//if (!file_exists($path)) die(__('Fehler beim Anlegen des Backupverzeichnisses.', 'wpsg'));
		
		// Translation rauskopieren
		if (file_exists(WPSG_PATH.'/lib/translation.phtml'))
		{
		
			if (!file_exists($path.'/lib/')) wpsg_mkdir($path.'/lib/');
			//if (!file_exists($path.'/lib/')) die(__('Fehler beim Anlegen des Backupverzeichnisses.', 'wpsg'));
		
			wpsg_copy(WPSG_PATH.'/lib/translation.phtml', $path.'/lib/translation.phtml');
			//if (!file_exists($path.'/lib/translation.phtml')) die(__('Übersetzungsdatei wurde nicht kopiert.', 'wpsg'));
			
		}
		
		// Übersetzungsdatei rauskopieren
		if (file_exists(WPSG_PATH.'/lang/'))
		{
			
			@wpsg_mkdir($path.'/lang/', 0777, true);
			wpsg_copy(WPSG_PATH.'/lang/', $path.'/lang/');
			
			//if (!file_exists($path.'/lang/')) die(__('Übersetzung konnte nicht kopiert werden.', 'wpsg'));
			
		}
		
		// User_views kopieren
		if (file_exists(WPSG_PATH.'/user_views/'))
		{
			
			@wpsg_mkdir($path.'/user_views/', 0777, true);
			wpsg_copy(WPSG_PATH.'/user_views/', $path.'/user_views');
			
			//if (!file_exists($path.'/user_views/')) die(__('Userviews wurden nicht kopiert.', 'wpsg'));    
			
		}
		
	} // function wpsg_pre_install()
	
	/**
	 * Funktion, die nach dem Update aufgerufen wird um die Dateien wieder an die richtige Stelle zu schieben
	 */
	function wpsg_post_install()
	{
		
		global $wp_filesystem;
		
		if ($_REQUEST['plugin'] != 'wpshopgermany/wpshopgermany.php') return;
		
		if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugURL') === '1' && $GLOBALS['wpsg_sc']->hasMod('wpsg_mod_core'))
			$remote_version = $GLOBALS['wpsg_sc']->get_url_content(base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy92ZXJzaW9uX2Rldg==')); // http://dl.maennchen1.de/wpsg/version_dev
		else
			$remote_version = $GLOBALS['wpsg_sc']->get_url_content(base64_decode('aHR0cDovL2RsLm1hZW5uY2hlbjEuZGUvd3BzZy92ZXJzaW9u')); // http://dl.maennchen1.de/wpsg/version
		
		if (!isset($_REQUEST['_ajax_nonce'])) echo __('Kopiere Shop zurück ...', 'wpsg').'<br />';
		
		// Temporäres Verzeichnis 
		if ($GLOBALS['wpsg_sc']->isMultiBlog())
			$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/update_temp/';
		else			 
			$path = WP_CONTENT_DIR.'/uploads/wpsg_temp/update_temp/';
			
		//if (file_exists($path.'/lib/translation.phtml')) copy($path.'/lib/translation.phtml', WPSG_PATH.'/lib/translation.phtml');
		//if (file_exists($path.'/user_views/')) wpsg_copy($path.'/user_views/', WPSG_PATH.'/user_views/');	
		//if (file_exists($path.'/lang/')) wpsg_copy($path.'/lang/', WPSG_PATH.'/lang/');
		
		if (file_exists($path.'/lib/translation.phtml'))
		{
			
			$source_file = $path.'lib/translation.phtml';
			$target_file = WPSG_PATH.'lib/translation.phtml';
			
			wpsg_copy($source_file, $target_file);			
						
		}
		
		if (file_exists($path.'/user_views/'))
		{
			
			$source_file = $path.'user_views';
			$target_file = WPSG_PATH.'user_views';
			
			wpsg_copy($source_file, $target_file);
			
		}
		
		if (file_exists($path.'/lang'))
		{
			
			$source_file = $path.'lang';
			$target_file = WPSG_PATH.'lang';
			    
			wpsg_copy($source_file, $target_file);
						
		}
		
		wpsg_chmod($path.'/lib/translation.phtml', 0777);
		wpsg_chmod($path.'/lang', 0777);
		
		$AC = new wpsg_AdminController();
		
		// Module nachinstallieren
		foreach ((array)$GLOBALS['wpsg_arZusatzModuleInstalled'] as $m_key)
		{
			
			$AC->installModul($m_key);
			
		}
		
		// Aufräumen
		//if (file_exists($path)) wpsg_rrmdir($path);
				 
		// Datenbank aktualisieren
		if (!isset($_REQUEST['_ajax_nonce'])) echo '<br />'.__('Aktualisiere Shop Datenbank ...', 'wpsg').'<br />';
		
		// Einmalige Meldungen zurücksetzen
		$GLOBALS['wpsg_sc']->db->Query("DELETE FROM `".$GLOBALS['wpsg_sc']->prefix."options` WHERE `option_name` LIKE 'wpsg_message_%' ");		
		
		$GLOBALS['wpsg_sc']->clearMessages();
		$GLOBALS['wpsg_sc']->loadModule();
		
		wpsg_install(trim($remote_version));
		
	} // function wpsg_post_install()
	
?>