<?php 

	/*
	 * Prepare all data for edit
	 */
	 	 
	$sShowPreData = true;
	if($_SERVER['REMOTE_ADDR'] != '95.170.68.38'){
	}
		$sShowPreData = false;
	
	if($sPage == 'add'){	
		$bIsAllowed = $oMijnOVIS->checkLimits();	
	}
	
	if($bIsAllowed){	
		$oMijnOVIS->parseDataSet();	
	}	
	
	if(!empty($sShowPreData)){
		
		//echo '<meta charset="UTF-8">';
		
		print_R('<pre>');
		//print_R($oMijnOVIS);
		//print_R('oMijnOVIS->_oDetailsData<br><br>');
		//print_R($oMijnOVIS->_oDetailsData);
		print_R('<br><br>');
		print_R('oMijnOVIS->parsedDetails');
		print_R($oMijnOVIS->parsedDetails);
		//print_R(mb_detect_encoding($oMijnOVIS->_oDetailsData->specifications->titleSuffix));
			
		$titleSuffixValueEN = $oMijnOVIS->_oDetailsData->specifications->titleSuffix;
		
		//var_dump($titleSuffixValueEN);
				
		$sEuroISO = chr(128);
		$sSpaceISO = chr(194);
		$titleSuffixValueEN = str_replace($sEuroISO, '&euro;', (trim($titleSuffixValueEN)));
		$titleSuffixValueEN = str_replace($sSpaceISO, '', (trim($titleSuffixValueEN)));
		//$titleSuffixValueEN = html_entity_decode($titleSuffixValueEN);
		//$titleSuffixValueEN = htmlentities($titleSuffixValueEN);
		//$titleSuffixValueEN = mb_convert_encoding($titleSuffixValueEN, 'UTF-8', 'Windows-1252');
		//$titleSuffixValueEN = mb_convert_encoding($titleSuffixValueEN, 'UTF-8', 'ISO-8859-15');
		//$titleSuffixValueEN = mb_convert_encoding($titleSuffixValueEN, 'UTF-8', 'HTML-ENTITIES');
			
		//$titleSuffixValueEN = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $titleSuffixValueEN);
		//print_R('<br><br>');
		//var_dump(trim($titleSuffixValueEN));
		
		/*
		//print_R('<br><br>');
		//print_R(mb_convert_encoding($oMijnOVIS->_oDetailsData->specifications->titleSuffix, 'UTF-8', 'Windows-1252'));
		///print_R('<br><br>');
		//print_R(mb_convert_encoding($oMijnOVIS->_oDetailsData->specifications->titleSuffix, 'UTF-8', 'ISO-8859-15'));
		
		print_R('<br><br>');
		print_R($titleSuffixValueEN_1);
		print_R('<br><br>');
		print_R($titleSuffixValueEN_2);
		
		print_R('<br><br>');
		print_R(utf8_encode($titleSuffixValueEN));
		print_R('<br><br>');
		print_R(utf8_decode($titleSuffixValueEN));
		print_R('<br><br>');
		
		print_R('<br><br>titleSuffixValueEN: ');
		print_R($titleSuffixValueEN);
		print_R('<br>');
		print_R(preg_replace('/[[:^print:]]/', '', $titleSuffixValueEN));
		print_R('<br>');
		var_dump($titleSuffixValueEN);
		
		print_R(utf8_encode($titleSuffixValueEN_1));
		print_R('<br><br>');
		print_R(utf8_decode($titleSuffixValueEN_2));
		print_R('<br><br>');
		print_R(html_entity_decode($titleSuffixValueEN_1, ENT_COMPAT, 'ISO-8859-15'));
		print_R('<br><br>');
		print_R(html_entity_decode($titleSuffixValueEN_2, ENT_COMPAT, 'WINDOWS-1252'));
		print_R('<br><br>');
		print_R(htmlentities($titleSuffixValueEN_1, ENT_COMPAT, 'ISO-8859-15'));
		print_R('<br><br>');
		print_R(htmlentities($titleSuffixValueEN_2, ENT_COMPAT, 'WINDOWS-1252'));
		
		//print_R($bIsAllowed);
		//print_R($oMijnOVIS->_oUserLimits);
		//print_R($oMijnOVIS->_oUserData->id);
		//print_R('oMijnOVIS->parsedDetails');
		//print_R($oMijnOVIS->parsedDetails);
		*/
		print_R('</pre>');
		exit;
	}
	
	/*
	 * Header
	 */
	
	require_once dirname(__FILE__) .  '/../include/inc.header.php'; 	
	
	/*
	 * Page
	 */
	
	$sHTML = '';
	
	if(!$bIsAllowed){
		
		$sHTML .= '<div class="list-loading"><span></span></div>';
		
		$sHTML .= 
		'<section class="content" id="main-content">';
			
			$sHTML .= '<div class="center">';
				$sHTML .= '<div class="article-form">
					<div id="limit-container">
						<div class="limit-exceded">U kunt momenteel geen advertenties toevoegen, limiet is bereikt.</div>
					</div>				
				</div>';
			$sHTML .= '</div>';
		
		$sHTML .= '</section>';
		
	} else {
	
		$sHTML .= '<div class="list-loading"><span></span></div>';
		
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.hiddenfields.php';	
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.preview.php';	
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.category.php';	
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.photos.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.features.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.price.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.descriptions.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.description.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.comment.php';
		
		if($_SERVER['REMOTE_ADDR'] == '95.170.68.38'){
			$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.memo.php';
		}
		
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.marktplaats.php';
		
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.status.php';
		//$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.kenteken.php';	
		
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.brand.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.sleep.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.dates.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.accessories.php';
		$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.sizes.php';
		
		if($oMijnOVIS->_oUserData->realm == 'boat'){
			
			$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.type_boat.php';
			$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.motoren.php';
			
		} else {
			
			if($_SERVER['REMOTE_ADDR'] == '95.170.68.38' || $_SERVER['REMOTE_ADDR'] == '2a01:7c8:bb09:1d:5054:ff:fefe:ce4d'){
				$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.version.php';
			}
			
			$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.model.php';
			$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.type.php';
			$sHTML .= require_once dirname(__FILE__) .  '/../include/inc.divisions.php';
			
		}	
			
		$sHTML .= 
		'<section class="content add-edit" id="main-content">';
			
			$sHTML .= '<div class="center">';
								
				/*
				 * Articles
				 */		
				 
				
				$sHTML .= 
				'<div class="article-form">
				
					<div class="article-input-group-container">	
						<div class="article-input-group first" data-group="photos">Foto\'s</div>	
						<div class="pictures-container">
							<div class="pictures">
								<div class="pictures-row">';
									
									$iImages = !empty($oMijnOVIS->parsedDetails->images) ? count($oMijnOVIS->parsedDetails->images) : 0;
															
									for($i=1; $i<=24; $i++){
										
										$iArrayKey = $i-1;
										
										${'sPicture'.$i} = !empty($oMijnOVIS->parsedDetails->images[$iArrayKey]) ? $oMijnOVIS->parsedDetails->images[$iArrayKey]->traditional->default->clean->url : false;									
										${'sPicture'.$i.'_path'} = !empty(${'sPicture'.$i}) ? array_values(array_filter(explode('/',${'sPicture'.$i}))) : false;																		
										${'sPicture'.$i.'_id'} = $i;									
									}	

									$aPictureOrder = array(1,2,4,6,8,10,12,14,16,18,20,22,24,3,5,7,9,11,13,15,17,19,21,23);

									foreach($aPictureOrder as $aPictureOrderId){
										
										
										if($aPictureOrderId == $iImages+1){
											$bShowAddBackground = true;										
										} else {
											$bShowAddBackground = false;	
										}										
											
										$sHTML .= '<div class="picture-block'.($aPictureOrderId == 1 ? ' main-picture' : ' sub-picture').(!empty($bShowAddBackground) ? ' add-picture add-new-image' : false).'" id="picture-'.${'sPicture'.$aPictureOrderId.'_id'}.'"'.(!empty(${'sPicture'.$aPictureOrderId}) ? ' style="background-image:url('.${'sPicture'.$aPictureOrderId}.');"' : false).'></div>';
										
									}								
									
									$sHTML .= '			
								</div>
							</div>
						</div>
					</div>
					<div class="article-input-group-container">						
						<div class="article-input-group first status'.(!empty($oMijnOVIS->parsedDetails->statusSynopsis) ? ' active' : false).'" data-group="status">Status<span id="status-set-value" class="set-value">'.ucfirst($oMijnOVIS->parsedDetails->statusSynopsis).'</span></div>
					</div>
				
					<div class="article-input-group-container">	
						<div class="article-input-group'.(!empty($oMijnOVIS->parsedDetails->category) ? '-fixed' : false).' first category'.(!empty($oMijnOVIS->parsedDetails->category) ? ' active' : false).'" data-group="category">Categorie<span id="category-set-value" class="set-value">'.(!empty($oMijnOVIS->parsedDetails->category) ? (!empty($oReturn->condition) ? 'Nieuw ' : 'Gebruikte ') : false).strtolower($oMijnOVIS->parsedDetails->category).'</span></div>
						<div class="article-input-group features'.(!empty($oMijnOVIS->parsedDetails->featuresSynopsis) ? ' active' : false).'" data-group="features">Kenmerken<span id="features-set-value" class="set-value">'.ucfirst($oMijnOVIS->parsedDetails->featuresSynopsis).'</span></div>
						<div class="article-input-group description'.(!empty($oMijnOVIS->parsedDetails->memoSynopsis) ? ' active' : false).'" data-group="description">Beschrijving<span id="description-set-value" class="set-value">'.ucfirst($oMijnOVIS->parsedDetails->memoSynopsis).'</span></div>
					</div>
					
					<div class="article-input-group-container">	
						<div class="article-input-group price'.(!empty($oMijnOVIS->parsedDetails->pricesSynopsis) ? ' active' : false).' first" data-group="prices">Prijs<span id="price-set-value" class="set-value">'.($oMijnOVIS->parsedDetails->pricesSynopsis).'</span></div>
					</div>
					
					<div class="article-input-group-container">	
						<div class="article-input-group marktplaats'.(!empty($oMijnOVIS->parsedDetails->marktplaatsSynopsis) ? ' active' : false).' first" data-group="marktplaats">Marktplaats<span id="marktplaats-set-value" class="set-value">'.($oMijnOVIS->parsedDetails->marktplaatsSynopsis).'</span></div>
					</div>
					
					<div class="article-input-group-container">	
						<div class="article-input-group preview first" data-group="preview">Preview<span id="preview-set-value" class="set-value"></span></div>
					</div>
				
				</div>';
		
			$sHTML .= '</div>';

			$sHTML .= '<div id="userNaw" class="userNaw">';
			
			
				$oNawGegevens = new stdClass();
				$oNawGegevens->bedrijfsnaam = !empty($oMijnOVIS->_oUserData->companyName) ? $oMijnOVIS->_oUserData->companyName.'<br>' : '';
				
				$oNawGegevens->address = '';
				$oNawGegevens->address .= !empty($oMijnOVIS->_oUserData->address) ? htmlentities($oMijnOVIS->_oUserData->address).' ' : '';
				$oNawGegevens->address .= !empty($oMijnOVIS->_oUserData->houseNumber) ? $oMijnOVIS->_oUserData->houseNumber.' ' : '';
				$oNawGegevens->address .= !empty($oMijnOVIS->_oUserData->houseNumberExt1) ? $oMijnOVIS->_oUserData->houseNumberExt1.' ' : '';
				$oNawGegevens->address .= !empty($oMijnOVIS->_oUserData->houseNumberExt2) ? $oMijnOVIS->_oUserData->houseNumberExt2.' ' : '';
				
				$oNawGegevens->postcode = !empty($oMijnOVIS->_oUserData->postalCode) ? $oMijnOVIS->_oUserData->postalCode : '';
				$oNawGegevens->plaats = !empty($oMijnOVIS->_oUserData->city) ?$oMijnOVIS->_oUserData->city : '';
				
				$oNawGegevens->postbus = !empty($oMijnOVIS->_oUserData->poBox) ? $oMijnOVIS->_oUserData->poBox : '';
				$oNawGegevens->postbus_pc = !empty($oMijnOVIS->_oUserData->poBoxPostalCode) ? $oMijnOVIS->_oUserData->poBoxPostalCode : '';
				$oNawGegevens->postbus_plaats = !empty($oMijnOVIS->_oUserData->poBoxCity) ? $oMijnOVIS->_oUserData->poBoxCity : '';
				
				$oNawGegevens->telefoon = !empty($oMijnOVIS->_oUserData->email) ? $oMijnOVIS->_oUserData->email : '';
				$oNawGegevens->email = !empty($oMijnOVIS->_oUserData->phone) ? $oMijnOVIS->_oUserData->phone : '';
				$oNawGegevens->website = !empty($oMijnOVIS->_oUserData->website) ? $oMijnOVIS->_oUserData->website : '';
		
				$sHTML .= $oNawGegevens->bedrijfsnaam;
				$sHTML .= !empty($oMijnOVIS->_oUserData->displaySettings->address) ? trim($oNawGegevens->address).'<br>' : false;
							
				$sPostalCode = !empty($oMijnOVIS->_oUserData->displaySettings->postalCode) ? $oNawGegevens->postcode : false;
				$sCity = !empty($oMijnOVIS->_oUserData->displaySettings->city) ? $oNawGegevens->plaats : false;
				
				$sHTML .= !empty($sPostalCode) || !empty($sCity) ? trim($sPostalCode.' '.$sCity).'<br>' : false;
				
				$sPostBox = !empty($oMijnOVIS->_oUserData->displaySettings->poBox) ? $oNawGegevens->postbus : false;
				$sPostBoxPostalCode = !empty($oMijnOVIS->_oUserData->displaySettings->poBoxPostalCode) ? $oNawGegevens->postbus_pc : false;
				$sPostBoxCity = !empty($oMijnOVIS->_oUserData->displaySettings->poBoxCity) ? $oNawGegevens->postbus_plaats : false;
				
				$sHTML .= !empty($sPostBox) ? trim($sPostBox).'<br>' : false;
				$sHTML .= !empty($sPostBoxPostalCode) || !empty($sPostBoxCity) ? trim($sPostBoxPostalCode.' '.$sPostBoxCity).'<br>' : false;
				
				$sHTML .= !empty($oMijnOVIS->_oUserData->displaySettings->phone) ? 'Telefoon: '.$oNawGegevens->telefoon.'<br>' : false;
				$sHTML .= !empty($oMijnOVIS->_oUserData->displaySettings->email) ? 'E-mail: '.$oNawGegevens->email.'<br>' : false;
				$sHTML .= !empty($oMijnOVIS->_oUserData->displaySettings->website) ? 'Internet: '.$oNawGegevens->website.'<br>' : false;		
			
			$sHTML .= '</div>';
		
		$sHTML .= '</section>';
	}
	
	echo $sHTML;
	
	/*
	 * Footer
	 */
		
	require_once dirname(__FILE__) .  '/../include/inc.footer.php';