Index: /changelog
===================================================================
--- /changelog	(revision 7959)
+++ /changelog	(revision 7960)
@@ -492,2 +492,3 @@
 - Bugfix: Fehler in Passwort Vergessen Funktion behoben
 - Bugfix: Reihenfolge geÃ€ndert Module werden jetzt vor dem initShop geladen!
+- Bugfix: Korrekte Filterung nach ZustÃ€nden in Gutscheinverwaltung #775
Index: /mods/mod_gutschein/wpsg_voucher.php
===================================================================
--- /mods/mod_gutschein/wpsg_voucher.php	(revision 7959)
+++ /mods/mod_gutschein/wpsg_voucher.php	(revision 7960)
@@ -51,5 +51,5 @@
         public function getUsed() {
 
-			return intval($this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDER."` WHERE `gs_id` = '".wpsg_q($this->id)."' "));
+			return intval($this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDER_VOUCHER."` WHERE `voucher_id` = '".wpsg_q($this->id)."' "));
 			
         }
@@ -197,33 +197,33 @@
         }
 
-        public function getStatus()
-        {
+		/**
+		 * 0	// Alle
+	     * 1	// Aktiv
+		 * 2	// Inaktiv
+		 * 3	// Verbraucht
+		 * 4	// Wartend
+		 * 
+		 * @return int
+		 */
+        public function getStatus() {
         	
-        	if ($this->multi === '1')
-        	{
+        	if ($this->__get('multi') === '1') {
         		
         		if (current_time('timestamp') < strtotime($this->start_date)) return 4;	// Wartend
         		
-        		if (current_time('timestamp') < strtotime($this->start_date) || current_time('timestamp') > strtotime($this->end_date))
-        		{
+        		if (current_time('timestamp') < strtotime($this->start_date) || current_time('timestamp') > strtotime($this->end_date)) {
         			
         			if ($this->getUsed() > 0) return 3;   //('Verbraucht', 'wpsg');
-        			else return 2; 	//('Inaktiv', 'wpsg');
+        			else return 2; // Inaktiv
         			
-        		}
-        		else return 1;	//__('Aktiv', 'wpsg');
+        		} else return 1; // Aktiv
         		
-        	}
-        	else
-        	{
-
-        		if (current_time('timestamp') < strtotime($this->start_date)) return 4;	// Wartend
+        	} else {
         		
-        		if ($this->getUsed() > 0) return 3;	//('Verbraucht', 'wpsg');
-        		else
-        		{
-        			
-        			if (current_time('timestamp') < strtotime($this->start_date) || current_time('timestamp') > strtotime($this->end_date)) return 2; 	//('Inaktiv', 'wpsg');
-        			else return 1; 	//('Aktiv', 'wpsg');
+        		if ($this->getUsed() > 0) return 3;	// Verbraucht
+        		else {
+					
+        			if (current_time('timestamp') < strtotime($this->start_date) || current_time('timestamp') > strtotime($this->end_date)) return 2; 	// Inaktiv
+        			else return 1; 	// Aktiv
         			
         		}
@@ -274,12 +274,7 @@
 		 * @param array $arFilter
 		 */
-		public static function find($arFilter = array())
-		{
+		public static function find($arFilter = array()) {
 
 			list($strQuerySELECT, $strQueryWHERE, $strQueryJOIN, $strQueryHAVING, $strQueryORDER) = self::getQueryParts($arFilter);
-
-			$strLimit = "";
-
-			if (wpsg_isSizedArray($arFilter['limit'])) $strLimit = "LIMIT ".wpsg_q($arFilter['limit'][0]).", ".wpsg_q($arFilter['limit'][1]);
 
 			$strQuery = "
@@ -300,5 +295,4 @@
 				
 			";
-			// ".$strLimit."
 			
 			$arID = $GLOBALS['wpsg_db']->fetchAssocField($strQuery);
@@ -306,4 +300,5 @@
 
 			$cnt = array();
+			
 			$cnt[0] = 0;	// Alle
 			$cnt[1] = 0;	// Aktiv
@@ -314,21 +309,29 @@
 			$start = 0;		// Vergleich mit $arFilter['limit'][0]
 			$cntx = 0;		// Vergleich mit $arFilter['limit'][1]
-			foreach ($arID as $id)
-			{
+			
+			foreach ($arID as $id) {
 
 				$vv = self::getInstance($id);
 				$st = $vv->getStatus();
+				
 				if (isset($arFilter['status'])) {
 					
-					$cnt[0]++;
-					$cnt[$st]++;
+					$cnt[0] ++;
+					$cnt[$st] ++;
 					
 					if (($arFilter['status'] == $st) || ($arFilter['status'] == 0)) {
+						
 						if ($start >= $arFilter['limit'][0]) {
+							
 							if ($cntx >= $arFilter['limit'][1]) continue;
+							
 							$arReturn[$id] = self::getInstance($id);
+							
 							$cntx++;
+							
 						}
+						
 						$start++;
+						
 					}
 					
Index: /mods/wpsg_mod_gutschein.class.php
===================================================================
--- /mods/wpsg_mod_gutschein.class.php	(revision 7959)
+++ /mods/wpsg_mod_gutschein.class.php	(revision 7960)
@@ -863,243 +863,5 @@
 		 * Ist fÃŒr die Ãbersicht der Gutscheine zustÃ€ndig
 		 */
-		public function indexAction()
-		{
-
-			
-			if (isset($_REQUEST['wpshopgermany-submit-gs_del']))
-			{
-
-				if (sizeof($_REQUEST['wpsg_gs_cb']) > 0)
-				{
-
-					$this->db->Query("DELETE FROM `".WPSG_TBL_GUTSCHEIN."` WHERE `id` IN (".implode(",", array_values($_REQUEST['wpsg_gs_cb'])).")");
-
-				}
-
-				$this->shop->addBackendMessage(__('Gutscheine erfolgreich gelÃ¶scht.', 'wpsg'));
-				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Voucher');
-
-			}
-
-			// Suchstring aufbauen
-			$strQueryWHERE = "";
-
-			$this->shop->view['filter'] = array(
-				'search' => ''
-			);
-
-			if (isset($_REQUEST['wpsg_search']))
-			{
-
-				$this->shop->view['filter']['search'] = $_REQUEST['wpsg_search'];
-				$strQueryWHERE .= " AND `code` LIKE '%".wpsg_q($_REQUEST['wpsg_search'])."%' ";
-
-			}
-
-			// Gefilterten Status fÃŒr das View definieren
-			if (isset($_REQUEST['wpsg_status']) && $_REQUEST['wpsg_status'] >= 0)
-			{
-				$this->shop->view['filter']['status'] = $_REQUEST['wpsg_status'];
-			}
-
-			$strQueryORDER = '';
-
-			if (!isset($_REQUEST['filter']['order']))
-			{
-
-				$this->shop->view['filter']['order'] = 'id';
-
-			}
-			else
-			{
-
-				$this->shop->view['filter']['order'] = $_REQUEST['filter']['order'];
-
-			}
-
-			switch ($this->shop->view['filter']['order'])
-			{
-
-				case 'code': $strQueryORDER = "G.`code`"; break;
-				case 'start_date': $strQueryORDER = "G.`start_date`"; break;
-				case 'end_date': $strQueryORDER = "G.`end_date`"; break;
-				case 'value': $strQueryORDER = "G.`value`"; break;
-				default: $strQueryORDER = "G.`id`"; break;
-
-			}
-
-			if (!isset($_REQUEST['filter']['ascdesc']))
-			{
-
-				$this->shop->view['filter']['ascdesc'] = 'asc';
-
-			}
-			else
-			{
-
-				$this->shop->view['filter']['ascdesc'] = $_REQUEST['filter']['ascdesc'];
-
-			}
-
-			// Alle gefilterten holen
-			$arDataAll = $this->db->fetchAssoc("
-				SELECT
-					G.*
-				FROM
-					`".WPSG_TBL_GUTSCHEIN."` AS G
-				WHERE
-					1
-					".$strQueryWHERE."
-				ORDER BY
-					".wpsg_q($strQueryORDER)." ".wpsg_q($this->shop->view['filter']['ascdesc'])."
-			");
-
-			$this->shop->view['arStatus'] = array();
-			$this->shop->view['countAll'] = sizeof($arDataAll);
-
-			foreach ($arDataAll as $k => $v)
-			{
-
-				$tStart = strtotime($v['start_date']);
-				$tEnd = strtotime($v['end_date']);
-
-				if ($tStart < wpsg_time() && $tEnd > wpsg_time())
-				{
-					$nStatus = 1; $strStatus = __('Aktiv', 'wpsg');
-				}
-				else if ($tStart > wpsg_time())
-				{
-					$nStatus = 2; $strStatus = __('Wartend', 'wpsg');
-				}
-				else if ($tEnd < wpsg_time())
-				{
-					$nStatus = 3; $strStatus = __('Ausgelaufen', 'wpsg');
-				}
-				else
-				{
-
-					// Sollte eignetlich nich auftreten
-					$nStatus = 999; $strStatus = __('UngÃŒltig', 'wpsg');
-
-				}
-
-				if ($v['multi'] == '0' && $v['o_id'] > 0)
-				{
-
-					$nStatus = 4; $strStatus = __('Verbraucht', 'wpsg');
-
-				}
-				else
-				{
-
-					$arDataAll[$k]['ordered'] = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDER."` WHERE `gs_id` = '".wpsg_q($v['id'])."'");
-
-				}
-
-				if (array_key_exists($nStatus, $this->shop->view['arStatus']))
-				{
-					$this->shop->view['arStatus'][$nStatus][1] ++;
-				}
-				else
-				{
-					$this->shop->view['arStatus'][$nStatus] = array($strStatus, 1);
-				}
-
-				if (isset($this->shop->view['filter']['status']) && $this->shop->view['filter']['status'] > 0 && $nStatus != $this->shop->view['filter']['status'])
-				{
-					unset($arDataAll[$k]);
-				}
-				else
-				{
-					$arDataAll[$k]['status'] = $strStatus;
-				}
-
-			}
-
-			//if (isset($_REQUEST['wpsg_voucher_export']) && $_REQUEST['wpsg_voucher_export'] == '1')
-			if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'export')
-				{
-
-				$strCSV  = "code;value;start_date;end_date;comment;calc_typ;multi;products";
-				if ($this->shop->hasMod('wpsg_mod_productgroups')) $strCSV .= ";productgroups";
-				$strCSV .= "\r\n";
-
-				$arData = array();
-
-
-
-				foreach ($arDataAll as $d)
-				{
-
-					$strCSV .= $d['code'].';'.$d['value'].';'.$d['start_date'].';'.$d['end_date'].';'.$d['comment'].';'.$d['calc_typ'].';'.$d['multi'].';'.$d['products'];
-					if ($this->shop->hasMod('wpsg_mod_productgroups')) $strCSV .= ';'.$d['productgroups'];
-					$strCSV .= "\r\n";
-
-				}
-
-				header("Content-Type: text/csv");
-				header("Content-Disposition: attachment; filename=gutscheine.csv");
-				header("Content-Description: csv File");
-				header("Pragma: no-cache");
-				header("Expires: 0");
-
-				die($strCSV);
-
-			}
-
-			// Anzahl an Elementen
-			$this->shop->view['count'] = sizeof($arDataAll);
-
-			// Pro Seite / Fallback auf 25 wenn was falsches eingegeben wurde
-			$perPage = ((intval($this->shop->get_option('wpsg_mod_gutschein_perPage')) > 0)?intval($this->shop->get_option('wpsg_mod_gutschein_perPage')):25);
-
-			// Anzahl an Seiten
-			$this->shop->view['pages'] = ceil($this->shop->view['count'] / $perPage);
-
-			// Seite bestimmen
-			if (isset($_REQUEST['seite']) && intval($_REQUEST['seite']) > 0) $this->shop->view['page'] = intval($_REQUEST['seite']); else $this->shop->view['page'] = 1;
-
-			// Aktuele Seite aus den DatensÃ€tzen herausnehmen
-			$this->shop->view['data'] = array_splice($arDataAll, (($this->shop->view['page'] - 1) * $perPage), $perPage);
-
-			if ($this->shop->view['filter']['order'] == 'status')
-			{
-
-				wpsg_array_csort($this->shop->view['data'], 'status');
-
-			}
-			
-
-			if (isset($_REQUEST['submit-multidelete']))
-			{
-
-				if (!wpsg_isSizedArray($_REQUEST['wpsg_multido']))
-				{
-
-					$this->shop->addBackendError(__('Bitte mindestens einen Gutschein auswÃ€hlen', 'wpsg'));
-
-				}
-				else
-				{
-
-					$nDelete = 0;
-
-					foreach ($_REQUEST['wpsg_multido'] as $k => $voucher_id)
-					{
-
-						$oVoucher = wpsg_voucher::getInstance($voucher_id);
-						$oVoucher->delete();
-
-						$nDelete ++;
-
-					}
-
-					$this->shop->addBackendMessage(wpsg_translate(__('#1# Gutschein(e) wurden gelÃ¶scht.', 'wpsg'), $nDelete));
-
-				}
-
-				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Voucher&action=index');
-
-			}
+		public function indexAction() {
 
 			$nPerPage = $this->shop->get_option('wpsg_mod_gutschein_perPage');
@@ -1117,12 +879,10 @@
 			$this->shop->view['pages'] = 1;
 
-			if (wpsg_isSizedArray($_REQUEST['filter']))
-			{
+			if (wpsg_isSizedArray($_REQUEST['filter'])) {
 
 				$this->shop->view['arFilter'] = wpsg_xss($_REQUEST['filter']);
 				$this->shop->view['hasFilter'] = true;
 
-			}
-			else if (wpsg_isSizedArray($_SESSION['wpsg']['backend']['voucher']['arFilter'])) $this->shop->view['arFilter'] = $_SESSION['wpsg']['backend']['voucher']['arFilter'];
+			} else if (wpsg_isSizedArray($_SESSION['wpsg']['backend']['voucher']['arFilter'])) $this->shop->view['arFilter'] = $_SESSION['wpsg']['backend']['voucher']['arFilter'];
 
 			$this->shop->view['countAll'] = wpsg_voucher::count($this->shop->view['arFilter']);
@@ -1151,5 +911,5 @@
 			
 			$this->shop->view['arData'] = wpsg_voucher::find($this->shop->view['arFilter']);
-
+						
 			$this->shop->view['arStatus']['0']['count'] = $this->shop->view['arData']['counts'][0];
 			$this->shop->view['arStatus']['1']['count'] = $this->shop->view['arData']['counts'][1];
@@ -1159,4 +919,77 @@
 			
 			unset($this->shop->view['arData']['counts']);
+			
+			$arDataAll = $this->shop->view['arData'];
+			
+			if (isset($_REQUEST['wpshopgermany-submit-gs_del'])) {
+
+				if (sizeof($_REQUEST['wpsg_gs_cb']) > 0) {
+
+					$this->db->Query("DELETE FROM `".WPSG_TBL_GUTSCHEIN."` WHERE `id` IN (".implode(",", array_values($_REQUEST['wpsg_gs_cb'])).")");
+
+				}
+
+				$this->shop->addBackendMessage(__('Gutscheine erfolgreich gelÃ¶scht.', 'wpsg'));
+				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Voucher');
+
+			} 
+ 
+			
+			if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'export') {
+
+				$strCSV  = "code;value;start_date;end_date;comment;calc_typ;multi;products";
+				if ($this->shop->hasMod('wpsg_mod_productgroups')) $strCSV .= ";productgroups";
+				$strCSV .= "\r\n";
+
+				$arData = array();
+
+				foreach ($arDataAll as $oVoucher) {
+
+					$d = $oVoucher->data;
+					
+					$strCSV .= $d['code'].';'.$d['value'].';'.$d['start_date'].';'.$d['end_date'].';'.$d['comment'].';'.$d['calc_typ'].';'.$d['multi'].';'.$d['products'];
+					if ($this->shop->hasMod('wpsg_mod_productgroups')) $strCSV .= ';'.$d['productgroups'];
+					$strCSV .= "\r\n";
+
+				}
+
+				header("Content-Type: text/csv");
+				header("Content-Disposition: attachment; filename=gutscheine.csv");
+				header("Content-Description: csv File");
+				header("Pragma: no-cache");
+				header("Expires: 0");
+
+				echo $strCSV;
+				exit;
+
+			} 
+ 
+			if (isset($_REQUEST['submit-multidelete'])) {
+
+				if (!wpsg_isSizedArray($_REQUEST['wpsg_multido'])) {
+
+					$this->shop->addBackendError(__('Bitte mindestens einen Gutschein auswÃ€hlen', 'wpsg'));
+
+				} else {
+
+					$nDelete = 0;
+
+					foreach ($_REQUEST['wpsg_multido'] as $k => $voucher_id) {
+
+						$oVoucher = wpsg_voucher::getInstance($voucher_id);
+						$oVoucher->delete();
+
+						$nDelete ++;
+
+					}
+
+					$this->shop->addBackendMessage(wpsg_translate(__('#1# Gutschein(e) wurden gelÃ¶scht.', 'wpsg'), $nDelete));
+
+				}
+
+				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Voucher&action=index');
+
+			}
+
 			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_gutschein/index.phtml');
 
