HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rooymans.komma-mediadesign.nl/wwwroot/kms/portfolio_toevoegen.php
	<?php

include_once('resizer.inc.php');
include("ckeditor/ckeditor.php");

if(isset($_POST['verzenden'])){
	$verzenden = true;
}
if(isset($_POST['naam'])){
	$naam = $_POST['naam'];
	$naam = trim($naam);
	$lengte_naam = strlen($naam);
	if(($lengte_naam > 1) && ($lengte_naam < 100)){
		$valid_naam = true;
		$te_lang_naam = false;
	}else{
		$valid_naam = false;
		if($lengte_naam != 0){
			$te_lang_naam = true;
		}
	}
}else{
	$valid_naam = false;
}
//check if al bestaat

if($verzenden && $valid_naam){

	$test_url = friendlyURL($naam);
	
	$q_cases = sprintf("SELECT kms_portfolio.url FROM kms_portfolio WHERE kms_portfolio.url='%s'", $test_url);
	$r_cases = mysql_query($q_cases);
	$rec_cases = mysql_fetch_assoc($r_cases);
	
	$uitkomst = $rec_cases['url'];
	
	if($test_url == $uitkomst){
		$bestaat_niet = false;	
	}else{
		$bestaat_niet = true;		
	}	
}

if(isset($_POST['categorie'])){
	$categorie = $_POST['categorie'];
}
if(isset($_POST['labelTitel'])){
	$labelTitel = $_POST['labelTitel'];
	$labelTitel = trim($labelTitel);
	$lengte_labelTitel = strlen($labelTitel);
	if($lengte_labelTitel < 150){
		$valid_labelTitel = true;
		$te_lang_labelTitel = false;
	}else{
		$valid_labelTitel = false;
		if($lengte_labelTitel != 0){
			$te_lang_labelTitel = true;
		}
	}
}else{
	$valid_labelTitel = false;
}
if(isset($_POST['labelOmschrijving'])){
	$labelOmschrijving = $_POST['labelOmschrijving'];
	$labelOmschrijving = trim($labelOmschrijving);
	$lengte_labelOmschrijving = strlen($labelOmschrijving);
	if($lengte_labelOmschrijving < 250){
		$valid_labelOmschrijving = true;
		$te_lang_labelOmschrijving = false;
	}else{
		$valid_labelOmschrijving = false;
		if($lengte_labelOmschrijving != 0){
			$te_lang_labelOmschrijving = true;
		}
	}
}else{
	$valid_labelOmschrijving = false;
}
if(isset($_POST['omschrijvingLinks'])){
	$omschrijvingLinks = $_POST['omschrijvingLinks'];
	$omschrijvingLinks = trim($omschrijvingLinks);
	$lengte_omschrijvingLinks = strlen($omschrijvingLinks);
	if(($lengte_omschrijvingLinks > 1)){
		$valid_omschrijvingLinks = true;
	}else{
		$valid_omschrijvingLinks = false;
	}
}else{
	$valid_omschrijvingLinks = false;
}
if(isset($_POST['omschrijvingRechts'])){
	$omschrijvingRechts = $_POST['omschrijvingRechts'];
	$omschrijvingRechts = trim($omschrijvingRechts);
	$lengte_omschrijvingRechts = strlen($omschrijvingRechts);
	$valid_omschrijvingRechts = true;
}else{
	$valid_omschrijvingRechts = true;
}
if(isset($_POST['cta'])){
	$cta = $_POST['cta'];
	$cta = trim($cta);
	$lengte_cta = strlen($cta);
	if($lengte_cta < 250){
		$valid_cta = true;
		$te_lang_cta = false;
	}else{
		$valid_cta = false;
		if($lengte_cta != 0){
			$te_lang_cta = true;
		}
	}
}else{
	$valid_cta = false;
}
if(isset($_POST['homepagina'])){
	$homepagina = $_POST['homepagina'];
		
	$q_homepagina = "SELECT COUNT(homepagina) AS totaal_homepagina FROM kms_portfolio WHERE kms_portfolio.homepagina = 'yes'";
	$r_homepagina = mysql_query($q_homepagina);
	$rec_homepagina = mysql_fetch_assoc($r_homepagina);
		
	$totaal_homepagina = $rec_homepagina['totaal_homepagina'];
		
	if($totaal_homepagina > 5){	
		$homepagina = "no";
		$teveel_homepagina = true;
	}else{
		$teveel_homepagina = false;
	}
}
if(isset($_POST['productpagina'])){
	$productpagina = $_POST['productpagina'];
		
	if($productpagina == "yes" && !empty($categorie)){
			
		$q_productpagina = sprintf("SELECT COUNT(productpagina) AS totaal_productpagina FROM kms_portfolio WHERE kms_portfolio.productpagina = 'yes' AND kms_portfolio.categorie_id = '%s'", $categorie);
		$r_productpagina = mysql_query($q_productpagina);
		$rec_productpagina = mysql_fetch_assoc($r_productpagina);
			
		$totaal_productpagina = $rec_productpagina['totaal_productpagina'];
			
		if($totaal_productpagina > 5){	
			$productpagina = "no";
			$teveel_productpagina = true;
		}else{
			$teveel_productpagina = false;
		}
	}
}

if($_FILES['image_file']['tmp_name']){
	
	$file_tegroot = false;
	$valid_file = true;
	$extensions = array("image/jpg", "image/jpeg", "image/pjpeg");
	
	if(in_array($_FILES['image_file']['type'], $extensions)) { 
	   $valid_type = true; 
	}else{	
		$valid_type = false;
	}
	
}else{
	$valid_file = false;
	$valid_type = false;
}


if($verzenden && $valid_naam && $bestaat_niet && $valid_labelTitel && $valid_labelOmschrijving && $valid_cta && $valid_omschrijvingLinks && $valid_omschrijvingRechts
&& $valid_type && !$file_tegroot && !empty($categorie) && $teveel_homepagina == false && $teveel_productpagina == false){
	
	$root = $_SERVER['DOCUMENT_ROOT']."/";
	
	if($valid_file && $_FILES['image_file']['tmp_name']){
		
		$dirname = time();
		
		$extensions = array("image/jpg", "image/jpeg", "image/pjpeg");
		
		if(in_array($_FILES['image_file']['type'], $extensions)) 
		{ 
			if($_FILES['image_file']['type'] == "image/jpg"){
				$ext = ".jpg";
			}else if($_FILES['image_file']['type'] == "image/jpeg"){
				$ext = ".jpg"; 
			}else if($_FILES['image_file']['type'] == "image/pjpeg"){
				$ext = ".jpg";
			}
		   
		   mkdir ($root . '/portfolio_images/' . $dirname);

		   $picture = $_FILES['image_file']['tmp_name'];
		   
		   list($width, $height) = getimagesize($picture);
		   $objResize = new RVJ_ImageResize($_FILES['image_file']['tmp_name'], $root . '/portfolio_images/'. $dirname . '/thumb_groot.jpg', 'W', '118');
		}
	}
	
	$url = friendlyURL($naam);
	
	$naam = htmlentities($naam);
	$labelTitel = htmlentities($labelTitel);
	$labelOmschrijving = htmlentities($labelOmschrijving);
	$cta = htmlentities($cta);
	
	
	$naam = checkData($naam);
	$categorie = checkData($categorie);
	$labelTitel = checkData($labelTitel);
	$labelOmschrijving = checkData($labelOmschrijving);
	$omschrijvingLinks = checkData($_POST['omschrijvingLinks']);
	$omschrijvingRechts = checkData($_POST['omschrijvingRechts']);
	$cta = checkData($cta);
	$homepagina = checkData($homepagina);
	$productpagina = checkData($productpagina);
	
	$image = $dirname;
	
	if($homepagina != "yes"){ $homepagina = "no"; }
	if($productpagina != "yes"){ $productpagina = "no"; }
	
	$sort_order = 1;

	$q_nieuws = sprintf("INSERT INTO kms_portfolio (naam, categorie_id, labelTitel, labelOmschrijving, descriptionLeft, descriptionRight, cta, homepagina, productpagina, image_dir, url, sort_order) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", 
	$naam,
	$categorie,
	$labelTitel,
	$labelOmschrijving,
	$omschrijvingLinks,
	$omschrijvingRechts,
	$cta,
	$homepagina,
	$productpagina,
	$image,
	$url,
	$sort_order);

	$r_nieuws = mysql_query($q_nieuws);
	
	if($r_nieuws){	
	
		$q_portfolio_id = sprintf("SELECT kms_portfolio.portfolio_id FROM kms_portfolio WHERE url='%s'", $url);
		$r_portfolio_id = mysql_query($q_portfolio_id);
		$rec_portfolio_id = mysql_fetch_assoc($r_portfolio_id);
	
		$query = "SELECT kms_portfolio.portfolio_id FROM kms_portfolio WHERE kms_portfolio.portfolio_id != '".$rec_portfolio_id['portfolio_id']."' ORDER BY kms_portfolio.sort_order ASC";
		$result = mysql_query($query);
		
		if(mysql_num_rows($result)) {
			$order = array();
			while($item = mysql_fetch_assoc($result)) {
			  $order[] = $item['portfolio_id'];
			}
		}
		foreach($order as $index=>$id) {
			$id = (int) $id;
			if($id != '') {
				$query = 'UPDATE kms_portfolio SET sort_order = '.($index + 2).' WHERE kms_portfolio.portfolio_id = '.$id;
				$result = mysql_query($query) or die(mysql_error().': '.$query);
			}
		}

        $targ_w = 118;
        $targ_h = 70;
        $jpeg_quality = 90;
        $map = "portfolio_images";
        $image_dir = $image;

        $src = $_SERVER['DOCUMENT_ROOT'].'/'.$map.'/'.$image_dir.'/thumb_groot.jpg';
        $img_r = imagecreatefromjpeg($src);
        $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

        imagecopyresampled($dst_r,$img_r,0,0,0,0,$targ_w,$targ_h,118,70);

        $imageKleur = $dst_r;

        class image {
            var $in;
            var $out;
            var $table;
            var $w,$h;
            var $converted = false;

            function image($filename, $width, $height) {
                $this->in = $filename;
                $this->w = $width;
                $this->h = $height;
                $this->clear();
            }

            function clear() {
                $this->converted=false;
                if(isset($this->out)) imagedestroy($this->out);
                $this->out = imagecreatetruecolor($this->w,$this->h);
            }

            /**
             *  Set output to greyscale, using grey as the center duotone
             */
            function setGrey() {
                $this->setDuotone(196,196,196); //rgb 196 is de maximale grijswaarde
            }
            /**
             *  Set output to duotone, using a simpler algorith resulting in a duller image
             */
            function setDull($r,$g,$b) {
                $this->clear();
                $this->table = array();
                for($i=0;$i<255;$i++) {
                    $this->table[$i] = imagecolorallocate($this->out,($i+$r)/2,($i+$g)/2,($i+$b)/2);
                }
            }
            /**
             *  Set output to duotone, using a fixed center color
             */
            function setFix($r,$g,$b) {
                $this->setDuotone($r,$g,$b,255);
            }
            /**
             *  Set output to duotone
             */
            function setDuotone($r,$g,$b,$center=false,$min=196,$max=255) {  //rgb 196 is de maximale grijswaarde
                $this->clear();
                $this->table = array();
                if($center === false) $center = ($r+$g+$b)/9; //origineel is het delen door 3
                for($i=0;$i<256;$i++) {
                    if($this->_duotone($i,$r,$center,$min,$max) == $this->_duotone($i,$g,$center,$min,$max) && $this->_duotone($i,$g,$center,$min,$max) == $this->_duotone($i,$b,$center,$min,$max)){
                        $waarde_r = $this->_duotone($i,$r,$center,$min,$max);
                        $waarde_g = $this->_duotone($i,$g,$center,$min,$max);
                        $waarde_b = $this->_duotone($i,$b,$center,$min,$max);
                        if($waarde_r < 196){ $waarde_r = 196; $waarde_g = 196; $waarde_b = 196; } //rgb 196 is de maximale grijswaarde
                    }else{
                        $waarde_r = $this->_duotone($i,$r,$center,$min,$max);
                        $waarde_g = $this->_duotone($i,$g,$center,$min,$max);
                        $waarde_b = $this->_duotone($i,$b,$center,$min,$max);
                        echo($waarde_r);
                    }
                    $this->table[$i] = imagecolorallocate($this->out, $waarde_r, $waarde_g, $waarde_b);
                }
            }
            /**
             *  Calculates the appropriate duotone color per channel
             */
            function _duotone($black,$color,$center,$min=196,$max=255) {  //rgb 196 is de maximale grijswaarde
                if($black <= $center) {
                    return ($black / $center) * $color;
                } else {
                    return $max - (($max - $black) / ($max - $center) * ($max - $color));
                }
            }
            /**
             *  Something I discoverd while trying to come up with a duotone algorithm
             */
            function setFun($r,$g,$b) {
                $this->clear();
                $this->table = array();
                for($i=0;$i<255;$i++) {
                    $this->table[$i] = imagecolorallocate($this->out,(((255-$i)/255)*$i)+((($i)/255)*$r),(((255-$i)/255)*$i)+((($i)/255)*$g),(((255-$i)/255)*$i)+((($i)/255)*$b));
                }
            }
            /**
             *  Convert the image and save it in the object.
             */
            function convert() {
                if(!isset($this->table)) $this->setGrey();
                for($x=0;$x < $this->w;$x++) {
                    for($y=0;$y < $this->h;$y++) {
                        list($r,$g,$b,$bw) = $this->_colors($x,$y);
                        imagesetpixel($this->out,$x,$y,$this->table[$bw]);
                    }
                }
                $this->converted=true;
            }
            /**
             *  Helper function to get color information in an array/list
             */
            function _colors($x,$y) {
                $rgb = ImageColorAt($this->in,$x,$y);
                $r = ($rgb >> 16) & 0xFF;
                $g = ($rgb >> 8) & 0xFF;
                $b = $rgb & 0xFF;
                $bw = ($r+$g+$b)/3; // simple B/W value
                return array($r,$g,$b,$bw);
            }
            function saveJPG($filename,$qual=90) {
                if(!$this->converted) $this->convert();
                return imagejpeg($this->out,$filename,$qual);
            }
        }

        $img = new image($imageKleur, $targ_w, $targ_h);
        $img->setDuotone(190,190,190); // rgb 185 is de duotone kleur

        $srcKleur = $_SERVER['DOCUMENT_ROOT'].'/'.$map.'/'.$image_dir.'/thumbKleur.jpg';

        $img->saveJPG($srcKleur);

        $imbottom = $dst_r;
        $imtop = imagecreatefromjpeg($srcKleur);;

        $spriteImage=imagecreatetruecolor(imagesx($imtop),imagesy($imtop)+imagesy($imbottom));
        imagecopy($spriteImage,$imtop,0,0,0,0,imagesx($imtop),imagesy($imtop));
        imagecopy($spriteImage,$imbottom,0,imagesy($imtop),0,0,imagesx($imbottom),imagesy($imbottom));

        $file_loc= $_SERVER['DOCUMENT_ROOT'].'/'.$map.'/'.$image_dir.'/thumb.jpg';
        $img_file = imagejpeg($spriteImage,$file_loc,$jpeg_quality);

        unlink($srcKleur);

        echo("<h1>Resultaat:</h1>");
        echo("<img src=\"/".$map."/".$image_dir."/thumb.jpg\"/><br /><br />");
        echo("Portfolio succesvol toegevoegd!<br /><br />");
        echo("<a href=\"index.php?p=portfoliofoto_overzicht&amp;portfolio_id=".$rec_portfolio_id['portfolio_id']."\" title=\"Foto's beheren\">Klik hier om de foto's van dit portfolio item te beheren</a>");
        echo("&nbsp;|&nbsp;<a href=\"index.php?p=portfolio_overzicht\" title=\"Terug naar het overzicht\">Terug naar het portfolio overzicht</a>");

	}else{
		echo("Er is iets fout gegaan.");
	}
}else{
?>

<h1>Portfolio toevoegen</h1>
<p>Vul onderstaande gegevens in om een portfolio item toe te voegen.</p>
<span class="label">* = verplicht</span><br /><br />
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>" id="aanmelden" name="aanmelden" method="post">
    	    
	<div>
        <label>Naam / titel *</label>
		<input name="naam" type="text" value="<?php echo(htmlspecialchars($naam)); ?>" />
        <?php if(!$valid_naam && $verzenden){ print("<span class=\"error\"> (foutieve invoer)</span>"); }?>
        <?php if(!$valid_naam && $verzenden && $te_lang_naam){ print("<span class=\"error\"><br />(invoer te lang)</span>"); }?>
        <?php if($valid_naam && $verzenden && !$bestaat_niet){ print("<span class=\"error\"><br />(de naam met artikelnummer bestaat al)</span>"); }?><br />
        
        <br />
        
        <label>Categorie:*</label>
        <select name="categorie" >
        	<option></option>
            <?php
            	$q_categorieen = "SELECT kms_categories.categorie_id, kms_categories.categorie_name FROM kms_categories ORDER BY categorie_name ASC";
				$r_categorieen = mysql_query($q_categorieen);
				
				while($rec_categorieen = mysql_fetch_assoc($r_categorieen)){ ?>
	                <option value="<?php echo($rec_categorieen['categorie_id']); ?>" <?php if ($categorie == $rec_categorieen['categorie_id']) { echo("selected=\"selected\"");}  ?>><?php echo(html_entity_decode($rec_categorieen['categorie_name'])); ?></option>
                <?php } ?>
           	
        </select>
        <?php if(empty($categorie) && $verzenden){ echo("<span class=\"error\"> (selecteer een categorie)</span>"); }?>
        
       <br /><br />
        
        <label>Label titel</label>
		<input name="labelTitel" type="text" value="<?php echo(htmlspecialchars($labelTitel)); ?>" />
        <?php if(!$valid_labelTitel && $verzenden){ print("<span class=\"error\"> (foutieve invoer)</span>"); }?>
        <?php if(!$valid_labelTitel && $verzenden && $te_lang_labelTitel){ print("<span class=\"error\"><br />(invoer te lang)</span>"); }?><br />
        
        <br />
        
        <label>Label omschrijving</label>
		<textarea name="labelOmschrijving"><?php echo(htmlspecialchars($labelOmschrijving)); ?></textarea>
                
        <?php if(!$valid_labelOmschrijving && $verzenden){ print("<span class=\"error\"> (foutieve invoer)</span>"); }?>
        <?php if(!$valid_labelOmschrijving && $verzenden && $te_lang_labelOmschrijving){ print("<span class=\"error\"><br />(invoer te lang)</span>"); }?><br />

        <br /><br />
            
        <label>Omschrijving linkse kolom* <?php if(!$valid_omschrijvingLinks && $verzenden){ echo("<span class=\"error\"> (foutieve invoer)</span>"); }?></label><br /><br />
<?php
// Create class instance.
$CKEditor = new CKEditor();

// Do not print the code directly to the browser, return it instead
$CKEditor->returnOutput = true;

// Path to CKEditor directory, ideally instead of relative dir, use an absolute path:
//   $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';

// Set global configuration (will be used by all instances of CKEditor).
$CKEditor->config['width'] = 600;
$CKEditor->config['toolbar'] = 'Basic';

// Change default textarea attributes
$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);

// The initial value to be displayed in the editor.
$initialValueLinks = $omschrijvingLinks;


// Create first instance.
$codeLinks = $CKEditor->editor("omschrijvingLinks", $initialValueLinks);

echo $codeLinks;
			?>
            
        <br />
        
        <p style="width:560px;"><em><strong>Opmerkingen:</strong> Door in de editor op "enter" te drukken wordt een nieuwe paragraaf gestart.
        Wanneer u een "normale enter" wilt zetten kan dit via de combinatie "shift" + "enter".</em></p>
        
        <br /><br />
            
        <label>Omschrijving rechtse kolom <?php if(!$valid_omschrijvingRechts && $verzenden){ echo("<span class=\"error\"> (foutieve invoer)</span>"); }?></label><br /><br />
<?php
// Create class instance.
$CKEditor = new CKEditor();

// Do not print the code directly to the browser, return it instead
$CKEditor->returnOutput = true;

// Path to CKEditor directory, ideally instead of relative dir, use an absolute path:
//   $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';

// Set global configuration (will be used by all instances of CKEditor).
$CKEditor->config['width'] = 600;
$CKEditor->config['toolbar'] = 'Basic';

// Change default textarea attributes
$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);

// The initial value to be displayed in the editor.
$initialValueRechts = $omschrijvingRechts;


// Create first instance.
$codeRechts = $CKEditor->editor("omschrijvingRechts", $initialValueRechts);

echo $codeRechts;
			?>
            
        <br />
        
        <p style="width:560px;"><em><strong>Opmerkingen:</strong> Door in de editor op "enter" te drukken wordt een nieuwe paragraaf gestart.
        Wanneer u een "normale enter" wilt zetten kan dit via de combinatie "shift" + "enter".</em></p>
        
        <br />
        
        <label>Call to action tekst</label>
		<input name="cta" type="text" value="<?php echo(htmlspecialchars($cta)); ?>" />
        <?php if(!$valid_cta && $verzenden){ print("<span class=\"error\"> (foutieve invoer)</span>"); }?>
        <?php if(!$valid_cta && $verzenden && $te_lang_cta){ print("<span class=\"error\"><br />(invoer te lang)</span>"); }?><br />
        
        <br /><br />
             
       	<label>Logo selecteren <br />(.jpg)</label>
     	<input class="file_input" type="file" name="image_file" />
       	
        <br />
		<?php if(!$valid_type && !$valid_file && $verzenden && !$file_tegroot){ print("<span class=\"error\"><br />(Selecteer een afbeelding)</span>"); }?>
        <?php if(!$valid_type && $valid_file && $verzenden && !$file_tegroot){ print("<span class=\"error\"><br />(Alleen jpg bestanden)</span>"); }?>
		<?php if($file_tegroot && $verzenden){ print("<span class=\"error\"><br />(Uw bestand is te groot. Max 1 MB)</span>"); }?><br />
        
        <br />
        
        <label>Op homepagina</label>
        <input type="checkbox" name="homepagina" value="yes" <?php if ($homepagina == "yes") { echo("checked=\"checked\"");}  ?>     /><br />
		<?php if($teveel_homepagina && $verzenden){ echo("<span class=\"error\"> (er staan al 6 items op de homepagina)</span>"); }?>
        
        <br />
        
        <label>Op portfolio pagina</label>
        <input type="checkbox" name="productpagina" value="yes" <?php if ($productpagina == "yes") { echo("checked=\"checked\"");}  ?>     />
        <?php if($teveel_productpagina && $verzenden){ echo("<span class=\"error\"> (er staan al 6 items op de portfolio pagina)</span>"); }?>
        
        <br /><br />
        
        <input name="verzenden" type="submit" value="Toevoegen" class="submit" />
        <a class="submit_annuleren" href="index.php?p=portfolio_overzicht" title="Annuleren">Annuleren</a>
	</div>
</form>

<?php
}
?>