Index: /controller/wpsg_OrderController.class.php
===================================================================
--- /controller/wpsg_OrderController.class.php	(revision 6217)
+++ /controller/wpsg_OrderController.class.php	(revision 6220)
@@ -393,4 +393,6 @@
 			$this->shop->view['data'] = array_merge($this->shop->view['data'], $arAdr);
 
+			$this->shop->callMod('wpsg_mod_orderupload', 'order_view_sidebar', array(&$_REQUEST['edit_id']));
+			
 			$this->shop->view['arSubAction'] = array(
 				'general' => array(
Index: /mods/wpsg_mod_orderupload.class.php
===================================================================
--- /mods/wpsg_mod_orderupload.class.php	(revision 6220)
+++ /mods/wpsg_mod_orderupload.class.php	(revision 6220)
@@ -0,0 +1,285 @@
+<?php
+
+	/**
+	 * Modul "Bestellupload"
+	 */
+	class wpsg_mod_orderupload extends wpsg_mod_basic 
+	{
+		
+		var $id = 1600;		
+		var $lizenz = 1;
+		var $version = "9.9.9";
+		var $hilfeURL = 'http://wpshopgermany.de/?p=5729960';
+		
+		/**
+		 * Costructor
+		 */
+		public function __construct()
+		{
+			
+			parent::__construct();
+			
+			$this->name = __('Bestellupload', 'wpsg');
+			$this->group = __('Bestellung', 'wpsg');
+			$this->desc = __('Erlaubt das hochladen von Dateien zu Bestellungen.', 'wpsg');
+						
+		} // public function __construct()
+		
+		public function install()
+		{
+			
+			$this->shop->checkDefault('wpsg_mod_orderupload_filename', '%order_onr%_%filename%');
+			$this->shop->checkDefault('wpsg_mod_orderupload_allowedext', 'jpg,jpeg');
+			$this->shop->checkDefault('wpsg_mod_orderupload_multifiles', '0');
+			$this->shop->checkDefault('wpsg_mod_orderupload_optional', '0');
+			
+		} // public function install()
+		
+		public function settings_edit()
+		{
+			
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_orderupload/settings_edit.phtml');
+			
+		} // public function settings_edit()
+		
+		public function settings_save()
+		{
+			
+			$this->shop->update_option('wpsg_mod_orderupload_filename', $_REQUEST['wpsg_mod_orderupload_filename']);
+			$this->shop->update_option('wpsg_mod_orderupload_allowedext', $_REQUEST['wpsg_mod_orderupload_allowedext']);
+			$this->shop->update_option('wpsg_mod_orderupload_multifiles', $_REQUEST['wpsg_mod_orderupload_multifiles']);
+			$this->shop->update_option('wpsg_mod_orderupload_optional', $_REQUEST['wpsg_mod_orderupload_optional']);
+			
+		} // public function settings_save()
+				
+		public function checkout_inner_prebutton(&$checkout_view) { 
+			
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_orderupload/checkout_inner_prebutton.phtml');
+			
+		} // public function checkout_inner_prebutton(&$checkout_view)
+		
+		public function checkCheckout(&$state, &$error, &$arCheckout)  
+		{
+			
+			if ($state == '1')
+			{
+				
+				if (
+					$this->shop->get_option('wpsg_mod_orderupload_optional') != '1' && 
+					sizeof($_SESSION['wpsg']['wpsg_mod_orderupload']) <= 0 &&
+					(!isset($_FILES['wpsg_mod_orderupload_file']) || !file_exists($_FILES['wpsg_mod_orderupload_file']['tmp_name']))
+					)
+				{
+					
+					// Noch keine Datei hochgeladen und es ist Pflicht !										
+					$this->shop->addFrontendError(__('Bitte eine Datei zum Upload wÃ€hlen.', 'wpsg'));
+					$error = true; return;
+					
+				}
+				
+				if (isset($_FILES['wpsg_mod_orderupload_file']) && file_exists($_FILES['wpsg_mod_orderupload_file']['tmp_name']))
+				{
+					
+					$ending = strtolower(preg_replace('/(.*)\./', '', $_FILES['wpsg_mod_orderupload_file']['name']));
+					
+					if (!in_array($ending, (array)explode(',', strtolower($this->shop->get_option('wpsg_mod_orderupload_allowedext')))))
+					{
+						
+						$this->shop->addFrontendError(__('Bitte eine gÃŒltige Dateiendung verwenden.', 'wpsg'));
+						$error = true; return;
+						
+					}
+					else
+					{
+						
+						// Upload durchfÃŒhren
+						$tmp = time().'-'.rand(1, 10000).'.'.$ending;
+						
+						move_uploaded_file($_FILES['wpsg_mod_orderupload_file']['tmp_name'], $this->getTmpFilePath().'/'.$tmp); 
+						
+						if (!is_array($_SESSION['wpsg']['wpsg_mod_orderupload'])) $_SESSION['wpsg']['wpsg_mod_orderupload'] = array();
+						else if (wpsg_isSizedArray($_SESSION['wpsg']['wpsg_mod_orderupload']) && $this->shop->get_option('wpsg_mod_orderupload_multifiles') != '1')
+						{
+							
+							// Cache sauber haltens
+							foreach ($_SESSION['wpsg']['wpsg_mod_orderupload'] as $ou)
+							{
+																
+								unlink($ou[3]);
+								
+							}
+							
+							$_SESSION['wpsg']['wpsg_mod_orderupload'] = array();
+						 							
+						}
+						
+						$_SESSION['wpsg']['wpsg_mod_orderupload'][] = wpsg_xss(array(
+							$_FILES['wpsg_mod_orderupload_file']['name'],
+							$tmp,
+							$this->getTmpFilePath(true).'/'.$tmp,
+							$this->getTmpFilePath().'/'.$tmp			
+						));
+						
+						$this->shop->addFrontendMessage(__('Datei wurde erfolgreich hochgeladen.', 'wpsg'));
+						
+						if ($this->shop->get_option('wpsg_mod_orderupload_multifiles') == '1')
+						{
+							
+							$error = true;
+							
+						}
+						
+					}
+					
+				}
+				
+			}
+			
+		} // public function checkCheckout(&$state, &$error, &$arCheckout)
+		
+		public function wp_loaded() 
+		{ 
+			
+			if ($_REQUEST['wpsg_plugin'] == 'wpsg_mod_orderupload' && $_REQUEST['wpsg_action'] == 'remove')
+			{
+				
+				unlink($_SESSION['wpsg']['wpsg_mod_orderupload'][$_REQUEST['file_index']][3]);
+				unset($_SESSION['wpsg']['wpsg_mod_orderupload'][$_REQUEST['file_index']]);
+				
+				$this->shop->addFrontendMessage(__('Dokument wurde aus der Bestellung entfernt.', 'wpsg'));
+				
+				$this->shop->redirect($this->shop->getURL(wpsg_ShopController::URL_CHECKOUT));
+				
+			}
+			
+		} // public function wp_loaded()
+
+		public function order_ajax() 
+		{ 
+			
+			if (isset($_REQUEST['wpsg_mod_orderupload_download']))
+			{
+				
+				header('Content-Disposition: attachment; filename="'.rawurldecode($_REQUEST['wpsg_mod_orderupload_download']).'"');
+				header('Content-type: application/download');
+				header('Content-Disposition: inline; filename="'.rawurldecode($_REQUEST['wpsg_mod_orderupload_download']).'"');
+				header('Expires: 0');
+				header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+				header('Pragma: public');
+				
+				die(file_get_contents($this->getSavePath($_REQUEST['edit_id']).'/'.rawurldecode($_REQUEST['wpsg_mod_orderupload_download'])));
+				
+			}
+			
+		} // public function order_ajax() 
+		
+		public function basket_save_done(&$o_id, &$k_id, &$oBasket)
+		{
+			
+			if (wpsg_isSizedArray($_SESSION['wpsg']['wpsg_mod_orderupload']))
+			{
+				
+				foreach ($_SESSION['wpsg']['wpsg_mod_orderupload'] as $k => $ou)
+				{
+					 
+					$path_target = $this->getSavePath($o_id);
+					
+					copy(
+						$ou[3], 
+						$path_target.'/'.$this->getNewName($ou[0], $o_id)
+					);
+					
+					// TemporÃ€ren Ordner sÃ€ubern
+					unlink($ou[3]);
+					
+					unset($_SESSION['wpsg']['wpsg_mod_orderupload'][$k]);
+					
+				}
+				
+			}
+			
+		} // public function basket_save_done($o_id, $k_id)
+		
+		public function order_view_sidebar(&$order_id) 
+		{ 
+	 
+			$arFiles = scandir($this->getSavePath($order_id));
+			 
+			foreach ($arFiles as $k => $v) { if (in_array($v, array('.', '..', '.htaccess', '.htpasswd'))) { unset($arFiles[$k]); } }
+			
+			if (sizeof($arFiles) <= 0) return;
+			
+			$this->shop->view['arFiles'] = $arFiles;			
+			//$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_orderupload/order_view_sidebar.phtml');
+			
+		} // public function order_view_sidebar(&$order_id)
+		
+		public function delOrder(&$order_id) 
+		{ 
+			 
+			// Hochgeladene Dateien lÃ¶schen
+			$path = $this->getSavePath($order_id);
+			
+			wpsg_rrmdir($path);
+			
+		} // public function delOrder(&$order_id)
+		
+		/* -- */
+		
+		public function getNewName($filename, $order_id)
+		{
+			
+			$arReplace = array(
+				'/%filename%/' => $filename,
+				'/%filename_clear%/' => preg_replace('/\.(.*)$/', '', $filename) 
+			);
+			
+			$filename = preg_replace(array_keys($arReplace), array_values($arReplace), $this->shop->get_option('wpsg_mod_orderupload_filename'));
+			
+			$filename = $this->shop->replaceUniversalPlatzhalter($filename, $order_id);
+			
+			return $filename;
+			
+		} // public function getNewName($filename, $order_id)
+		
+		public function getSavePath($order_id, $burl = false)
+ 		{
+ 		 
+ 			if ($this->shop->isMultiBlog())
+			{
+
+				$url = WPSG_URL_CONTENT.WPSG_MB_UPLOADS.'/wpsg/wpsg_orderupload/'.$order_id.'/';
+				$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_orderupload/'.$order_id.'/'; 
+				$htaccess = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_orderupload/.htaccess';
+				 
+			}
+			else
+			{
+				
+				$url = WPSG_URL_CONTENT.'uploads/wpsg/wpsg_orderupload/'.$order_id.'/';
+				$path = WP_CONTENT_DIR.'/uploads/wpsg/wpsg_orderupload/'.$order_id.'/';
+				$htaccess = WP_CONTENT_DIR.'/uploads/wpsg/wpsg_orderupload/.htaccess';
+								
+			}
+			 
+			if (!file_exists($path)) mkdir($path, 0777, true);
+			
+ 			if (!file_exists($htaccess))
+			{
+				 				
+				$handle = fopen($htaccess, "w+");
+				$content = "Deny from all";			
+				fwrite($handle, $content, strlen($content));
+				fclose($handle);
+				
+			}
+			
+			if ($burl) return $url;
+			else return $path;
+			
+ 		} // private function getSavePath($order_id, $url = false)
+				
+	} // class wpsg_mod_orderupload extends wpsg_mod_basic
+
+
+?>
Index: /views/mods/mod_orderupload/checkout_inner_prebutton.phtml
===================================================================
--- /views/mods/mod_orderupload/checkout_inner_prebutton.phtml	(revision 6220)
+++ /views/mods/mod_orderupload/checkout_inner_prebutton.phtml	(revision 6220)
@@ -0,0 +1,46 @@
+<?php
+
+	/**
+	 * Template fÃŒr die Integration des Bestelluploads in den Bestellprozess
+	 */
+
+?>
+<div class="wpsg_box wpsg_mod_orderupload">
+
+	<div class="wpsg_head"><?php echo __('Dateiupload', 'wpsg'); ?> 
+	
+		<?php if ($this->get_option('wpsg_mod_orderupload_optional') != '1') { ?>
+		
+			<span class="wpsg_required">*</span>
+			
+		<?php } ?>
+		
+	</div>
+	
+	<div class="wpsg_inner">
+			
+		<input class="wpsg_orderupload_checkout_button" type="file" name="wpsg_mod_orderupload_file" />
+ 
+ 		<?php /* Auflistung der bereits hochgeladenen Dokumente */ ?>
+		<?php if (wpsg_isSizedArray($_SESSION['wpsg']['wpsg_mod_orderupload'])) { ?>
+		
+			<br />
+			
+			<label class="wpsg_checkout"><?php echo __('Bisher hochgeladene Dokumente', 'wpsg'); ?>:</label><br />
+			
+			<?php foreach ($_SESSION['wpsg']['wpsg_mod_orderupload'] as $ou_index => $ou) { ?>
+			
+				<?php /* Dokument aus der Liste lÃ¶schen */ ?>
+				<a onclick="return confirm('<?php echo __('Sind Sie sich sicher, dass Sie dieses Dokument aus der Bestellung entfernen mÃ¶chten?', 'wpsg'); ?>');" href="?wpsg_plugin=wpsg_mod_orderupload&wpsg_action=remove&file_index=<?php echo $ou_index; ?>" class="wpsg_mod_orderupload_removelink">
+					<img src="<?php echo WPSG_URL; ?>views/gfx/bin_x.png" alt="<?php echo __('LÃ¶schen', 'wpsg'); ?>" />
+				</a>
+				
+				<a href="<?php echo $ou[2]; ?>"><?php echo wpsg_hspc($ou[0]); ?></a>&nbsp;<?php echo '('.wpsg_formatSize($ou[3]).')'; ?><br />	
+					
+			<?php } ?>
+			
+		<?php } ?>
+			
+	</div>
+	
+</div>
Index: /views/mods/mod_orderupload/order_view_sidebar.phtml
===================================================================
--- /views/mods/mod_orderupload/order_view_sidebar.phtml	(revision 6220)
+++ /views/mods/mod_orderupload/order_view_sidebar.phtml	(revision 6220)
@@ -0,0 +1,27 @@
+<?php
+
+	/**
+	 * Template fÃŒr die Anzeige der Bestelluploads innerhalb des Bestellbackend
+	 */
+ 
+?>
+<div class="postbox" id="wpsg_modorderupload">
+	<div title="<?php echo __('Zum Ein/Ausklappen hier klicken', 'wpsg'); ?>" class="handlediv"><br></div>
+	<h3 class="hndle">
+		<span><?php echo __('Bestelluploads', 'wpsg'); ?></span>
+	</h3> 
+	<div class="inside">
+		 <?php if (!wpsg_isSizedArray($this->view['arFiles'])) { ?>
+		 <p class="wpsg_checkout_orderupload_backend">
+		 	<?php echo __('Keine Dateien hochgeladen.', 'wpsg'); ?>
+		 </p>
+		 <?php } else { ?>
+		 <?php foreach ($this->view['arFiles'] as $f) { ?>
+		 <p class="wpsg_checkout_orderupload_backend">
+		 	<a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=view&edit_id=<?php echo $this->view['data']['id']; ?>&noheader=1&action=ajax&mod=wpsg_mod_orderupload&wpsg_mod_orderupload_download=<?php echo rawurlencode($f); ?>"><?php echo $f; ?></a><br /> 
+		 	<span class="wpsg_checkout_orderupload_backend_weight">(<?php echo wpsg_formatSize($this->callMod('wpsg_mod_orderupload', 'getSavePath', array($this->view['data']['id'])).$f); ?>)</span>
+		 </p>
+		 <?php } ?>
+		 <?php } ?>
+	</div>
+</div>
Index: /views/mods/mod_orderupload/settings_edit.phtml
===================================================================
--- /views/mods/mod_orderupload/settings_edit.phtml	(revision 6220)
+++ /views/mods/mod_orderupload/settings_edit.phtml	(revision 6220)
@@ -0,0 +1,13 @@
+<?php
+
+	/**
+	 * Template fÃŒr die Einstellungen des Bestell Upload Moduls
+	 */
+
+?>
+<br/>
+<?php echo wpsg_drawForm_Input('wpsg_mod_orderupload_filename', __('Neuer Dateiname', 'wpsg'), $this->get_option('wpsg_mod_orderupload_filename'), array('help' => 'wpsg_mod_orderupload_filename')); ?>
+<?php echo wpsg_drawForm_Input('wpsg_mod_orderupload_allowedext', __('Erlaubte Endungen (kommagetrennt)', 'wpsg'), $this->get_option('wpsg_mod_orderupload_allowedext'), array('help' => 'wpsg_mod_orderupload_allowedext')); ?>
+<br />
+<?php echo wpsg_drawForm_Checkbox('wpsg_mod_orderupload_multifiles', __('Mehr als eine Datei erlauben', 'wpsg'), $this->get_option('wpsg_mod_orderupload_multifiles'), array('help' => 'wpsg_mod_orderupload_multifiles')); ?>
+<?php echo wpsg_drawForm_Checkbox('wpsg_mod_orderupload_optional', __('Upload ist kein Pflichtfeld', 'wpsg'), $this->get_option('wpsg_mod_orderupload_optional'), array('help' => 'wpsg_mod_orderupload_optional')); ?>
Index: /views/order/view_general.phtml
===================================================================
--- /views/order/view_general.phtml	(revision 6217)
+++ /views/order/view_general.phtml	(revision 6220)
@@ -31,2 +31,21 @@
 </form>
 <?php echo wpsg_drawForm_AdminboxEnd(); ?>
+
+<?php echo wpsg_drawForm_AdminboxStart(__('Bestelluploads', 'wpsg')); ?>
+
+	<div class="inside">
+		 <?php if (!wpsg_isSizedArray($this->view['arFiles'])) { ?>
+		 <p class="wpsg_checkout_orderupload_backend">
+		 	<?php echo __('Keine Dateien hochgeladen.', 'wpsg'); ?>
+		 </p>
+		 <?php } else { ?>
+		 <?php foreach ($this->view['arFiles'] as $f) { ?>
+		 <p class="wpsg_checkout_orderupload_backend">
+		 	<a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=view&edit_id=<?php echo $this->view['data']['id']; ?>&noheader=1&action=ajax&mod=wpsg_mod_orderupload&wpsg_mod_orderupload_download=<?php echo rawurlencode($f); ?>"><?php echo $f; ?></a><br /> 
+		 	<span class="wpsg_checkout_orderupload_backend_weight">(<?php echo wpsg_formatSize($this->callMod('wpsg_mod_orderupload', 'getSavePath', array($this->view['data']['id'])).$f); ?>)</span>
+		 </p>
+		 <?php } ?>
+		 <?php } ?>
+	</div>
+
+<?php echo wpsg_drawForm_AdminboxEnd(); ?>
