ACC SHELL

Path : /srv/www/vhosts/marevva/nadaciakrizovatka/admin/
File Upload :
Current File : /srv/www/vhosts/marevva/nadaciakrizovatka/admin/admin-xml-export.php

<h2>XML export</h2>
<div class="cleaner20"></div>
<div class="cleaner20"></div>

<?php
	
	//include( 'init-path.php' );
	//include( 'functions.php' );
	include_once( '../class.crProduct.php' );
					
					
	//echo print_r( $_POST, true );
	
	// update
	if ( isset( $_POST['ID'] ) && isset( $_POST['type'] ) && ( $_POST['type'] == 'update' ) )
	{
		$fileName = $_POST['fileName'];
		if ( $fileName == '' )
			$fileName = $xmlExportDBitem['fileName'];
		
		$xmlExportDBitems = $db->getAllItems( 'xmlExport' );
		
		foreach( $xmlExportDBitems as $xmlExportDBitem )
		{
			if ( $_POST['ID'] == $xmlExportDBitem['ID'] )
			{
				// generate feed - zbozi.cz
				if ( $xmlExportDBitem['ID'] == 1 )
				{
					echo 'Generujem '.$fileName.'...<br/>';
					
					$xml = simplexml_load_file( $serverFullPath . 'feed-base.xml' );
					
					$products = $db->getAllItems( 'product', " WHERE `visibility`=1 " );
					if ( count( $products ) > 0 )
					{
						foreach ( $products as $product )
						{
							$_product = new crProduct( $db );
							$_product->loadByID( $product['ID'] );
	
							// category
							$category = array();
							$productCategories = $db->getAllItems( 'productCategory', " WHERE `productID`=" . $product['ID'] );
							foreach ( $productCategories as $productCategory )
							{
								if ( !isset( $category['ID'] ) )
									$category = $db->getItem( 'category', $productCategory['categoryID'] );
							}
							if ( !isset( $category['ID'] ) )
							{
								continue;
							}
							
							// name
							$productName = fuckOffHTMLspecialChars( $product['title'] );
							
							$seo = $db->getItemWhere( 'seo', " WHERE `url`='/" . $category['url'] . '/' . $product['url'] . "' " );
							if ( isset( $seo['title'] ) )
								$productName = $productName . ' ' . fuckOffHTMLspecialChars( $seo['title'] );
							
							// description
							$productDescription = ($product['text']);
							$productDescription = fuckOffHTMLspecialChars( strip_tags($productDescription) );
							$productDescription = str_replace( "\n", '', $productDescription );
							$productDescription = str_replace( '&nbsp;', ' ', $productDescription );
							
							// price
							$productPrice_sDPH = $_product->getPriceInVAT();
							$productPrice_bezDPH = $_product->getPriceExVAT();
							
							// manufacturer
							$productManufacturer = '';
							$manufacturer = $db->getItem( 'manufacturer', $product['manufacturerID'] );
							if ( isset( $manufacturer['ID'] ) )
								$productManufacturer = trim( $manufacturer['title'] );
							
							// url (product, image)
							$product_url = 'http://'.$_SERVER['HTTP_HOST'].'/' . $category['url'] . '/' . $product['url'];
							$productImg_url = 'http://'.$_SERVER['HTTP_HOST'].$productImageDir.'/medium/' . $product['image'];
								$productImg_url = str_replace( ' ', '%20', $productImg_url );
								$productImg_url = str_replace( ',', '%2c', $productImg_url );
							$productImg_url_ = '.'.$productImageDir.'/medium/' . $product['image'];
							
							// url (product, other_image)
							$images = $db->getAllItems( 'mediaItem', " WHERE `ownerID`=" . $product['ID'] . " ORDER BY `position` ASC " );
							$imagesCount = count( $images );
							$productImgS_url = array();
							for ( $i = 0; $i < $imagesCount; $i++ )
							{
								$image = $images[ $i ];
								
								$productImgS_url_ = 'http://'.$_SERVER['HTTP_HOST'] . $productImagesDir . '/' . $product['ID'] . '/' . $image['fileName'];
								$productImgS_url_ = str_replace( ' ', '%20', $productImgS_url_ );
								$productImgS_url_ = str_replace( ',', '%2c', $productImgS_url_ );
								
								$productImgS_url[] = $productImgS_url_;
							}
							
							if ( ($productPrice_sDPH > 0) && ($productPrice_bezDPH > 0) && (file_exists($serverFullPath . $productImg_url_)) &&
							     ( $product['cenaTyp'] != 'vyprodano' ) )
							{
								$productNode = $xml->addChild( 'SHOPITEM' );
								
								$productNode->addChild( 'PRODUCTNAME', $category['title'] . ' - ' . $productName );
								$productNode->addChild( 'PRODUCT', $productName );
								$productNode->addChild( 'CATEGORYTEXT', $category['title'] );
								if ( $productDescription != '' ) $productNode->addChild( 'DESCRIPTION', $productDescription );
								if ( $productManufacturer != '' ) $productNode->addChild( 'MANUFACTURER', $productManufacturer );
								$productNode->addChild( 'URL', $product_url );
								$productNode->addChild( 'IMGURL', $productImg_url );
								for ( $i = 0; $i < $imagesCount; $i++ )
								{
									$productImgS_url_ = $productImgS_url[ $i ];
									$productNode->addChild( 'OTHER_IMG', $productImgS_url_ );
								}
								$productNode->addChild( 'PRICE', number_format( $productPrice_bezDPH, 0, '', '' ) );
								$productNode->addChild( 'PRICE_VAT',  number_format( $productPrice_sDPH, 0, '', '' ) );
								
								$dd = $product['deliveryDate'];
								if ( $dd == '' )
									$dd = -1;
								$productNode->addChild( 'DELIVERY_DATE', $dd );
							}
						}
					}		
					
					unlink( $serverFullPath . $xmlExportDBitem['fileName'] );
					
					$xml->asXML( $serverFullPath . $fileName );	
					
					echo 'OK <div class="cleaner20"></div>';

					
				}
				// generate feed - zbozi.cz - end
				
				// generate feed - Heureka
				if ( $xmlExportDBitem['ID'] == 2 )
				{
					echo 'Generujem '.$fileName.'...<br/>';
					
					$xml = simplexml_load_file( $serverFullPath . 'feed-base.xml' );
					
					$products = $db->getAllItems( 'product', " WHERE `visibility`=1 " );
					if ( count( $products ) > 0 )
					{
						foreach ( $products as $product )
						{
							$_product = new crProduct( $db );
							$_product->loadByID( $product['ID'] );
							
							// category
							$category = array();
							$productCategories = $db->getAllItems( 'productCategory', " WHERE `productID`=" . $product['ID'] );
							foreach ( $productCategories as $productCategory )
							{
								if ( !isset( $category['ID'] ) )
									$category = $db->getItem( 'category', $productCategory['categoryID'] );
							}
							if ( !isset( $category['ID'] ) )
							{
								continue;
							}
							
							// name
							$productName = fuckOffHTMLspecialChars( $product['title'] );
							
							$seo = $db->getItemWhere( 'seo', " WHERE `url`='/" . $category['url'] . '/' . $product['url'] . "' " );
							if ( isset( $seo['title'] ) )
								$productName = $productName . ' ' . fuckOffHTMLspecialChars( $seo['title'] );
							
							// description
							$productDescription = ($product['text']);
							$productDescription = fuckOffHTMLspecialChars( strip_tags($productDescription) );
							$productDescription = str_replace( "\n", '', $productDescription );
							$productDescription = str_replace( '&nbsp;', ' ', $productDescription );
							
							// price
							$productPrice_sDPH = $_product->getPriceInVAT();
							$productPrice_bezDPH = $_product->getPriceExVAT();
							
							// manufacturer
							$productManufacturer = '';
							$manufacturer = $db->getItem( 'manufacturer', $product['manufacturerID'] );
							if ( isset( $manufacturer['ID'] ) )
								$productManufacturer = trim( $manufacturer['title'] );
							
							// url (product, image)
							$product_url = 'http://'.$_SERVER['HTTP_HOST'].'/' . $category['url'] . '/' . $product['url'];
							$productImg_url = 'http://'.$_SERVER['HTTP_HOST'].'/data/product/mainImages/medium/' . $product['image'];
								$productImg_url = str_replace( ' ', '%20', $productImg_url );
								$productImg_url = str_replace( ',', '%2c', $productImg_url );
							$productImg_url_ = './data/product/mainImages/medium/' . $product['image'];
							
							// url (product, other_image)
							$images = $db->getAllItems( 'mediaItem', " WHERE `ownerID`=" . $product['ID'] . " ORDER BY `position` ASC " );
							$imagesCount = count( $images );
							$productImgS_url = array();
							for ( $i = 0; $i < $imagesCount; $i++ )
							{
								$image = $images[ $i ];
								$productImgS_url[] = 'http://'.$_SERVER['HTTP_HOST'].'' . $productImagesDir . '/' . $product['ID'] . '/' . $image['fileName'];
							}
							
							if ( ($productPrice_sDPH > 0) && ($productPrice_bezDPH > 0) && (file_exists($serverFullPath . $productImg_url_)) &&
							     ( $product['cenaTyp'] != 'vyprodano' ) )
							{
								$productNode = $xml->addChild( 'SHOPITEM' );
								
								$productNode->addChild( 'PRODUCTNAME', $category['title'] . ' - ' . $productName );
								
								$productNode->addChild( 'PRODUCT', $productName );
								$productNode->addChild( 'CATEGORYTEXT', $category['title'] );
								$productNode->addChild( 'DESCRIPTION', $productDescription );
								$productNode->addChild( 'MANUFACTURER', $productManufacturer );
								$productNode->addChild( 'URL', $product_url );
								$productNode->addChild( 'IMGURL', $productImg_url );
								for ( $i = 0; $i < $imagesCount; $i++ )
								{
									$productImgS_url_ = $productImgS_url[ $i ];
									$productNode->addChild( 'IMGURL_ALTERNATIVE', $productImgS_url_ );
								}
								for ( $i = 1; $i <= 3; $i++ )
								{
									if ( $product['videoURL'.$i] != '')
										$productNode->addChild( 'VIDEO_URL', $product['videoURL'.$i] );
								}
								$productNode->addChild( 'PRICE', number_format( $productPrice_bezDPH, 0, '', '' ) );
								$productNode->addChild( 'PRICE_VAT',  number_format( $productPrice_sDPH, 0, '', '' ) );
								
								$productNode->addChild( 'HEUREKA_CPC', 1 );
								
								$dd = $product['deliveryDate'];
								if ( $dd == '' )
									$dd = -1;
								$productNode->addChild( 'DELIVERY_DATE', $dd );
								$productNode->addChild( 'DELIVERY_ID', 'CESKA_POSTA_NA_POSTU' );
							}
							
						}
					}		
					
					unlink( $serverFullPath . $xmlExportDBitem['fileName'] );
					
					$xml->asXML( $serverFullPath . $fileName );	
					
					echo 'OK <div class="cleaner20"></div>';
				}
				// generate feed - Heureka - end
				
				$db->setItem( 'xmlExport', $xmlExportDBitem['ID'], array( 'fileName' => $fileName, 'lastExport' => 'CURRENT_TIMESTAMP' ) );
			}
		}
	}
	
	// upload
	if ( isset( $_POST['ID'] ) && isset( $_POST['type'] ) && ( $_POST['type'] == 'upload' ) )
	{
		
		$xmlExportDBitems = $db->getAllItems( 'xmlExport' );
		
		foreach( $xmlExportDBitems as $xmlExportDBitem )
		{
			if ( $_POST['ID'] == $xmlExportDBitem['ID'] )
			{
				foreach ( $_FILES as $file )
				{
					$fileName = basename( $file['name'] );
					if ( $fileName != '' )
					{
						if ( move_uploaded_file( $file['tmp_name'], $serverFullPath . $fileName ) )
						{
							if ( $xmlExportDBitem[ 'fileName' ] != $fileName )
								@unlink( $serverFullPath . $xmlExportDBitem[ 'fileName' ] );
								
							$db->setItem( 'xmlExport', $xmlExportDBitem['ID'], array( 'fileName' => $fileName, 'lastExport' => 'CURRENT_TIMESTAMP' ) );
							
							echo $fileName . ' - OK <div class="cleaner20"></div>';
						}
						else
						{
							echo $fileName . ' - Chyba! <div class="cleaner20"></div>';
						}
								
					}
					break;
				}	
			}
		}
	}
	
	// vypis
	$xmlExportDBitems = $db->getAllItems( 'xmlExport' );
	
	foreach( $xmlExportDBitems as $xmlExportDBitem )
	{
		$datetime = date_create( $xmlExportDBitem['lastExport'] );
		$datetime = date_format( $datetime, "d.m.Y, H:i:s" );
		
		?>
		
		<h3><?= $xmlExportDBitem['title'] ?></h3>
		
		<a href="/<?= $xmlExportDBitem['fileName'] ?>" title="Ke stažení: <?= $xmlExportDBitem['fileName'] ?>" target="_blank">&darr; <?= $xmlExportDBitem['fileName'] ?></a>
		<div class="cleaner5"></div>
		Poslední export: <?= $datetime ?>
		<div class="cleaner10"></div>
		
		<?php 
			if ( $xmlExportDBitem['ID'] != 3 )
			{
		?>
		<form action="" method="post" name="xmlExportForm<?= $xmlExportDBitem['ID']; ?>">
			
			<div class="admin-user-label border" style="width: 114px;" >Název souboru</div>
			<input type="text" class="admin-user-edit-value" style="width: 250px;" name="fileName" id="fileName" value="<?= $xmlExportDBitem['fileName'] ?>" />
								
			<input type="hidden" value="<?= $xmlExportDBitem['ID'] ?>" name="ID" id="ID" />
			<input type="hidden" value="update" name="type" id="type" />				
			
			<input type="submit" value="Aktualizovat" name="xmlExportFormSubmit<?= $xmlExportDBitem['ID'] ?>" id="xmlExportFormSubmit<?= $xmlExportDBitem['ID'] ?>" class="admin-button-green" style="margin-left:10px;" />
			
		</form>
		
		<div class="cleaner10"></div>
		<?php
			}
		?>
		
		<form action="" method="post" name="xmlUploadForm<?= $xmlExportDBitem['ID'] ?>" enctype="multipart/form-data">
			
			<div class="admin-user-label border" style="width: 114px;" >Soubor</div>
			<input type="file"  style="width: 250px;" name="fileName" id="fileName" accept="text/xml"/>
								
			<input type="hidden" value="<?= $xmlExportDBitem['ID'] ?>" name="ID" id="ID" />
			<input type="hidden" value="upload" name="type" id="type" />				
			
			<input type="submit" value="Nahrát" name="xmlUploadFormSubmit<?= $xmlExportDBitem['ID'] ?>" id="xmlUploadFormSubmit<?= $xmlExportDBitem['ID'] ?>" class="admin-button" style="margin-left:10px;" />
			
		</form>
		
		<div class="cleaner20"></div>
		<div class="cleaner20"></div>
		
		<?php
		
	}
	
	
?>

ACC SHELL 2018