<?php
class SITExportManagerFunctions {

	/**
	 * 
	 */
	function sampleLimitFunction($ISITDatabaseController, $limitFunctionAddition) {

	    $limitIdArray = arraY();

        // For database checks use
 		$resultArray = $ISITDatabaseController->readQuery(
 		    "SELECT oxid FROM oxuser WHERE oxid IN ( SELECT oxuserid FROM oxorder WHERE oxid IN (SELECT oxorderid FROM oxorderarticles WHERE oxartid = '8ea18f8863d7c2550a66668743d97330') )"
        );
 		foreach ($resultArray as $key => $resultRow) {
            $limitIdArray[] = $resultRow["id"];
 		}
		
		return $limitIdArray;
	}


	/**
	 * 
	 */ 
	function stripHtmlTags($headerDataArray, $rowDataArray, $currentHeader, $currentValue, $ISITDatabaseController, $functionCondition, $functionValue) {
	
		return strip_tags($currentValue);
	}

	/**
	 * 
	 */ 
	function getCountryName($headerDataArray, $rowDataArray, $currentHeader, $currentValue, $ISITDatabaseController, $functionCondition, $functionValue) {
	
		$countryName = $currentValue;
		
		$resultArray = $ISITDatabaseController->readQuery("SELECT oxtitle FROM oxcountry WHERE oxid = '" . $currentValue . "'");
 		foreach ($resultArray as $key => $resultRow) {
			$countryName = $resultRow["oxtitle"];
 		}
		
		return $countryName;
	}

    function formatPrice($headerDataArray, $rowDataArray, $currentHeader, $currentValue, $ISITDatabaseController, $functionCondition, $functionValue) {

        $sPrice = str_replace(".", ",", $currentValue);
        return $sPrice;
    }

	function formatDate($headerDataArray, $rowDataArray, $currentHeader, $currentValue, $ISITDatabaseController, $functionCondition, $functionValue) {
		
		$date = DateTime::createFromFormat('Y-m-d H:i:s', str_replace('"', '', $currentValue));
		return $date->format('d.m.Y');
	}
	
	/**
	 *
	 */
	function checkRemark($headerDataArray, $rowDataArray, $currentHeader, $currentValue, $ISITDatabaseController, $functionCondition, $functionValue) {
	
		if ($currentValue != '"Hier können Sie uns noch etwas mitteilen."') {
			return $currentValue;
		}
	
		return '';
	}
	
	function finishExport($headerDataArray, $rowDataArray, $currentHeader, $currentValue, $ISITDatabaseController) {

        $orderNr = $rowDataArray["BLG_Belegnr"];

        $articles = "";
        $resultArray = $ISITDatabaseController->readQuery( 'SELECT oxartnum, oxamount, oxbrutprice FROM oxorderarticles WHERE oxorderid = (SELECT oxid FROM oxorder WHERE oxordernr = ' . $orderNr . ')' );
        foreach ( $resultArray as $key => $resultRow ) {

            $articles .=
                "\n" .
                "#ORDERPOS;" .
                '"' . $resultRow["oxartnum"] . '";' .
                '"' . $resultRow["oxamount"] . '";' .
                '"' . $resultRow["oxbrutprice"] . '";' .
                '""';
        }

        return $currentValue . $articles;
    }
}