File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/oudlondon.nl/includes/cassette.front.php
<?php
/*
* cassette frontend
*/
class cassetteFrontend extends dbConnect{
function entries($post_section=null,$post_category=null,$uid=null,$view_page=null,$search_array=null,$limit=null,$force_view =false)
{
$this->wrapSections = isset($this->wrap) && $this->wrap == 1 ? 1 : 0;
if($uid != null)
{
if($force_view === false) $uniqids = $this->run("SELECT * FROM `unique_ids` WHERE `unique_id`='". $this->esc($uid) ."' AND status = 2 ");
else $uniqids = $this->run("SELECT * FROM `unique_ids` WHERE `unique_id`='". $this->esc($uid)."'");
}
else
{
$start = ($view_page == null) ? 0 : ($view_page-1)*$this->items_per_page;
$limit_query = ($this->items_per_page != null && $limit == null) ? " LIMIT $start,$this->items_per_page" : ($limit == null ? null: " LIMIT 0,$limit");
// get data on section
if($post_section != null)
{
if($this->lang_id != 0)
{
$translation_arr = $this->getTranslation("value",$post_section,"section");
$sectie_id = $translation_arr["element_id"];
if($translation_arr)
{
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `sectie_id` = '$sectie_id' AND `active` = '1'",false);
$post_section = $sectie_info["naam"];
}
}
if(!is_numeric($post_section)) $sectie_info = $this->run("SELECT * FROM `secties` WHERE `naam` LIKE '".preg_replace("/( |-)/","%",$this->esc($post_section))."%'",false);
else {
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `sectie_id` = '". $this->esc($post_section)."'",false);
}
// sort
$sort = $this->get("secties","sectie_id",$sectie_info["sectie_id"],"sort");
switch($sort)
{
case 1;
$sort_query = "ORDER BY `unique_ids`.`created` DESC";
break;
case 2;
$sort_query = "ORDER BY `unique_ids`.`created` ASC";
break;
default;
$sort_query = "ORDER BY `unique_ids`.`position` ASC";
break;
}
}
// post category
if($post_category == null && $uid == null)
{
$uniqids = $this->run("SELECT *,`unique_ids`.`unique_id` as `temp_uid` FROM `unique_ids` LEFT JOIN `entry_categories` ON `unique_ids`.`unique_id` = `entry_categories`.`unique_id` WHERE `unique_ids`.`sectie_id` = '". $sectie_info["sectie_id"] ."' AND `unique_ids`.`status` = 2 AND `entry_categories`.`entry_category_id` IS NULL ".$sort_query.$limit_query,true);
// d($sectie_info);
// d($uniqids);
foreach($uniqids as $i => $uid){
$uniqids[$i]["unique_id"] = $uid["temp_uid"];
}
}
// post category
elseif($post_category !== "0")
{
if(is_numeric($post_category))
{
$category_info = $this->run("SELECT * FROM `categories` WHERE `category_id` = '". $post_category ."' AND `active` = '1'",false);
}
else $category_info = $this->run("SELECT * FROM `categories` WHERE `naam` LIKE '%". preg_replace("/( |-)/","%",$this->esc($post_category)) ."%' AND `sectie_id`='". $sectie_info["sectie_id"] ."' AND `active` = '1'",false);
$uniqids = $this->run("SELECT * FROM `entry_categories`,`unique_ids` WHERE `entry_categories`.`unique_id` = `unique_ids`.`unique_id` AND `category_id` = '".$category_info["category_id"]."' AND `status`='2' ORDER BY unique_ids.position".$limit_query);
}
// post section
elseif($post_section != null)
{ $this->sectie_id = $sectie_info["sectie_id"];
$search = $uid == null ? "WHERE `status` = '2' AND `sectie_id`='$this->sectie_id' $sort_query $limit_query" : "WHERE `unique_id`='$uid'";
$this->pagination = $this->countRecords("SELECT COUNT(*) as `count` FROM `unique_ids` WHERE `sectie_id` = '$this->sectie_id'");
$uniqids = $this->run("SELECT * FROM `unique_ids` $search");
}
}
$html_arr = array();
foreach($uniqids as $i => $id)
{
// get tablename
$table = "td_".$this->get("templates","template_id",$id["template_id"],"naam");
// template fields
$fields = $this->templateFields($id["template_id"]);
// get data
$entry_data = $this->run("SELECT * FROM `$table` WHERE entry_id = ".$id["entry_id"]." ORDER BY position ASC",false);
// check for translation
if($this->lang_id != 0)
{
// search for translated item
$translation = $this->run("SELECT * FROM `unique_ids` WHERE `translation_of_uid` = '".$id["unique_id"]."' AND language_id = '". $this->lang_id ."'",false);
// hide items without translations
if($sectie_info["show_translations"] == 0 && $translation == null && $uid == null) continue;
// override master data with transalation
if($translation != null)
{
// translation data
$tranlation_data = $this->run("SELECT * FROM `$table` WHERE entry_id = ".$translation["entry_id"]." ORDER BY position ASC",false);
// fields that have translation
$trans_fields = $this->templateFields($translation["template_id"]);
foreach($trans_fields as $fld)
{
// continue if no translation has been found
if($fld["translate"] == 0) continue;
$field_user = preg_replace("/[^0-9a-zA-Z]/","_",strtolower($fld["field_user"]));
$entry_data[$field_user] = $tranlation_data[$field_user];
}
$entry_data["form_id"] = $tranlation_data["form_id"];
$entry_data["meta_title"] = $tranlation_data["meta_title"];
$entry_data["meta_description"] = $tranlation_data["meta_description"];
$entry_data["translation_uid"] = $tranlation_data["unique_id"];
}
else{
//echo "no data";
continue;
}
}
// echo $i." - ";
// new entry data object
$ed = new entryData($this->connection,$fields,$entry_data,$id["unique_id"],$id["template_id"],$id["sectie_id"],null,$this->wrapSections,$this->link_base,$this->lang_id);
//push into return array
array_push($html_arr,$ed);
}
//echo count($html_arr);
// if($uid == null) return $html_arr;
// else return $html_arr[0];
return $html_arr;
}
function getTranslation($search_column,$search_value,$type,$sectie_id=null)
{
$search_value = preg_replace("/[^0-9a-zA-Z]/","%",$this->esc($search_value));
if($type == "section" || $type == "category" && $sectie_id == null)
{
$translation_arr = $this->run("SELECT * FROM `translations` WHERE `language_id` = '$this->lang_id' AND `$search_column` LIKE '". $search_value ."' AND type='". $type ."' ",false);
}
else
{
$translation_arr = $this->run("SELECT * FROM `translations` LEFT JOIN categories ON translations.element_id = categories.category_id WHERE `language_id` = '$this->lang_id' AND `$search_column` LIKE '". $search_value ."' AND type='". $type ."' AND `sectie_id` = '".$sectie_id."'",false);
}
return ($translation_arr != null ? $translation_arr : false);
}
function countRecords($mysql)
{
$result = mysqli_query($this->connection, $mysql);
$numrows = mysqli_num_rows($result);
$page_count = ceil($numrows / $this->items_per_page);
return $pagination = ($page_count > 1) ? $page_count : false;
}
function search($table,$search_column_array,$search_values_array)
{
$search = "WHERE ";
foreach($search_column_array as $i => $post_name){
$field_value = $search_values_array[$i];
$field_name = $post_name;
if($field_value == "") continue;
$search .= "`$field_name` LIKE '%".$field_value."%' OR";
}
$search = substr($search,0,-3);
$results = $this->data($table,$search);
$html_arr = array();
foreach($results as $entry){
$fields = $this->templateFields($entry["template_id"]);
$ed = new entryData($fields,$entry,$entry["unique_id"],$entry["template_id"]);
array_push($html_arr,$ed);
}
return $html_arr;
}
function templateFields($template_id,$subof=null)
{
$sub_query = ($subof != null) ? "AND sub_of=$subof" : "AND sub_of=0";
return $this->run("SELECT * FROM template_fields LEFT JOIN field_types ON template_fields.field_id=field_types.field_id WHERE template_id = $template_id $sub_query AND active=1 ORDER BY template_fields.position ASC");
}
function entriesInCategory($category_id)
{
$html_arr = array();
$entries_in_cat = $this->run("SELECT * FROM `entry_categories`,`unique_ids` WHERE `entry_categories`.`unique_id` = `unique_ids`.`unique_id` AND category_id = $category_id");
foreach($entries_in_cat as $ec)
{
$table = "td_".$this->get("templates","template_id",$ec["template_id"],"naam");
$fields = $this->templateFields($ec["template_id"]);
$data = $this->run("SELECT * FROM `$table` WHERE entry_id = ".$ec["entry_id"]." ORDER BY position ASC");
$ed = new entryData($this->connection,$fields,$data[0],$ec["unique_id"],$ec["template_id"]);
array_push($html_arr,$ed);
}
return $html_arr;
}
function getEntryCategory($unique_id)
{
$category = $this->run(
"SELECT `naam` FROM `entry_categories`,`categories`
WHERE `categories`.`category_id` = `entry_categories`.`category_id`
AND `entry_categories`.`unique_id` = '$unique_id'"
,false
);
return $category ? $category["naam"] : null;
}
function getNavigation($positie_id,$sectie=null,$category_name=null,$show_category=false,$show_toplevel=false){
if($show_toplevel == true)
{
if($this->lang_id != 0)
{
$translation_arr = $this->getTranslation("value",$sectie,"section");
$sectie_id = $translation_arr["element_id"];
if($translation_arr)
{
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `sectie_id` = '$sectie_id' AND `active` = '1'",false);
}
}
else
{
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `naam` LIKE '". preg_replace("/( |-)/","%",$this->esc($sectie))."%'",false);
}
if(empty($sectie_info)) return false;
// categories
$cats = $this->run(
"SELECT *
FROM `categories`, `entry_categories`
WHERE `entry_categories`.`category_id` = `categories`.`category_id`
AND `categories`.`sectie_id` = ". $sectie_info["sectie_id"] ."
AND `categories`.`active`='1'
AND `zichtbaar` = '1'
GROUP BY entry_categories.category_id
ORDER BY position ASC
");
$uniqids = $this->run(
"SELECT *,`unique_ids`.`unique_id` AS `uid`
FROM `unique_ids`
LEFT JOIN `entry_posities`
ON `unique_ids`.`unique_id` = `entry_posities`.`unique_id`
LEFT JOIN `entry_categories`
ON `unique_ids`.`unique_id` = `entry_categories`.`unique_id`
WHERE `unique_ids`.`sectie_id` = '". $sectie_info["sectie_id"] ."'
AND `unique_ids`.`status` = 2
AND `entry_posities`.`positie_id` = $positie_id
AND `entry_categories`.`entry_category_id` IS NULL
ORDER BY `unique_ids`.`position`"
);
//d(array($uniqids,$cats));
return array($uniqids,$cats);
}
elseif($category_name != null)
{
//get category ID
$cat_info = $this->run("SELECT * FROM `categories` WHERE `naam` LIKE '".preg_replace("/( |-)/","%",$this->esc($category_name))."' AND `active` = '1' OR `url` LIKE '%". preg_replace("/( |-)/","%",$this->esc($category_name)) ."%' AND `active` = '1'",false);
$cats = $this->run("SELECT * FROM `categories`, `entry_categories`,`entry_posities` WHERE `entry_categories`.`category_id` = `categories`.`category_id` AND `entry_categories`.`unique_id` = `entry_posities`.`unique_id` AND `categories`.`category_id` = ".$cat_info["category_id"]." AND `categories`.`active`='1' AND `zichtbaar` = '1' AND `entry_posities`.`positie_id` = '$positie_id' ORDER BY position ASC");
return $cats;
}
elseif($show_category == true)
{
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `naam` LIKE '". preg_replace("/( |-)/","%",$this->esc($sectie))."%'",false);
if(empty($sectie_info)) return false;
$cats = $this->run("SELECT * FROM `categories`, `entry_categories` WHERE `entry_categories`.`category_id` = `categories`.`category_id` AND `categories`.`sectie_id` = ". $sectie_info["sectie_id"] ." AND `categories`.`active`='1' AND `categories`.`active`='1' AND `zichtbaar` = '1' GROUP BY entry_categories.category_id ORDER BY position ASC");
return $cats;
}
elseif($sectie == null)
{
$entries = $this->run("SELECT * FROM `unique_ids`,`entry_posities` WHERE `unique_ids`.`unique_id` = `entry_posities`.`unique_id` AND `entry_posities`.`positie_id` = '$positie_id' ORDER BY `unique_ids`.`position` ASC");
return $entries;
}
else
{
echo "hier";
// new array
$data = array();
// secion data
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `naam` LIKE '". preg_replace("/( |-)/","%",$this->esc($sectie))."%'",false);
// categories
$data[] = $this->run("SELECT * FROM `categories` WHERE `sectie_id` = '". $sectie_info["sectie_id"] ."' AND `active`='1' AND `zichtbaar` = '1' ORDER BY position ASC");
// entries
$data[] = $this->run("SELECT * FROM `unique_ids`,`entry_posities` WHERE `unique_ids`.`unique_id` = `entry_posities`.`unique_id` AND `unique_ids`.`sectie_id` = '". $sectie_info["sectie_id"] ."' AND `entry_posities`.`positie_id` = '$positie_id' AND `unique_ids`.`status` = 2 ORDER BY `unique_ids`.`position` ASC");
return $data;
}
}
function fieldHTML($element,$value,$default_html=null,$css_class=null){
if(empty($value)) return;
switch($element){
case "h1":
$html = '<div class="'.$css_class.'">';
$html .= '<header class="header-box">';
$html .= '<h1>'.stripslashes($value).'</h1>';
$html .= '</header>';
$html .= '</div>';
break;
case "text":
$html = '<div class="'.$css_class.'">';
$html .= '<h2>'.$value.'</h2>';
$html .= '</div>';
break;
case "image":
$html = '<div class="'.$css_class.'">';
$html .= '<figure class="article-image">'.$this->createImage($value[0],"h",600,220).'</figure>';
$html .= '</div>';
break;
case "cols":
if(empty($value)) return;
$count = count($value);
$width = "col".(24/count($value));
$html = "";
$html .= '<div class="col24"><div class="devider"></div></div>';
foreach($value as $link)
{
$html .= '<div class="'.$width.'">';
$html .= '<div class="dotted-box rounded">';
//$html .= '<figure>'.$this->createImage($data->foto[0],"bl",75,75).'</figure>';
$html .= '<div class="block-text float-fix">';
$html .= '<h3>'.$link[2].'</h3>';
$html .= '<p>'.$link[1].'<a class="read-more" href="'.$link[3].'">'.$bl->link_label.'</a></p>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
break;
case "link":
$html .= '<a href="'.$value[0].'" class="'.$css_class.'">'.$value[1].'</a>';
break;
case "form":
$form = new cassetteForm($value);
// form fields
$fields = $form->getFields();
$html = '<div class="'.$css_class.'">';
$html .= "<form class='form' action='handle-form' $onsubmit id='form$e->formulier' method='post' enctype='multipart/form-data'><div>";
foreach($fields as $el){
$html .= $form->cassetteFormElement($el);
}
$html .= "</div></form>";
$html .= '<div class="feedback"></div>';
$html .= '</div>';
break;
default:
$html = '<div class="'.$css_class.'">';
$html .= '<section class="article-details">';
switch($element){
case "em":
$html .= '<p><em>'.$value.'</em></p>';
break;
case "share":
$html .= '<div class="social-share">'.$default_html.'</div>';
break;
default:
$html .= $value;
break;
}
$html .= '</section>';
$html .= '</div>';
break;
}
return $html;
}
function getBezorgKosten($selected_id=null,$total=null){
$config = $this->get("instellingen","id",1);
return $config["verzendkosten"];
}
function btwBedrag($bedrag){
return ($bedrag/121)*21;
}
function iDealAmount($bedrag){
return $bedrag*100;
}
function orderTotaal($bedrag){
$_SESSION[$this->company_short]["totaalbedrag"] = $this->iDealAmount($bedrag);
}
function createImage($img_url,$prefix,$width,$height,$resize_type=1,$class=null,$alt=null){
if($img_url == ""){
//$img_url = ($override_default_img == null) ? $this->base.$this->defaultImage : $override_default_img;
$img_url = $this->base.$this->defaultImage;// : $override_default_img;
}
$prefix = preg_replace("/ /","_",$prefix);
$img_arr = explode("/",$img_url);
$img_name = end($img_arr);
// check img url op CMS URL
$pref_url = $this->base.IMAGE_DIR.$prefix."-".$img_name;
$response = get_headers($pref_url, 1);
// echo '<pre>';
// print_r($response);
// echo '</pre>';
// thumb not found
if((strpos($response[0], "404") === false) && $this->save_images == true) return '<img src="'.IMAGE_DIR.preg_replace("/ /","-",$prefix.'-'.$img_name).'" class="'.$class.'" alt="'.$alt.'" />';
else return '<img src="image.php?prefix='.$prefix.'&path='.$img_url.'&w='.$width.'&h='.$height.'&type='.$resize_type.'&d='. IMAGE_DIR .'" class="'.$class.'" alt="'.$alt.'" />';
}
function getLink($link_to_uid){
if($link_to_uid == "") return;
$r = $this->run("SELECT * FROM `unique_ids`,`secties` WHERE `unique_ids`.`sectie_id` = `secties`.`sectie_id` AND `unique_id` = '$link_to_uid'",false);
$table = "td_".$this->get("templates","template_id",$r["template_id"],"naam");
$fields = $this->templateFields($r["template_id"]);
$entry_titel = $this->get($table,"entry_id",$r["entry_id"],$fields[0]["field_naam"]);
return $r["naam"]."/".$entry_titel."-".$link_to_uid;
}
function sectieInfo($sectie)
{
if($this->lang_id != 0)
{
// get translation
$translation_arr = $this->getTranslation("value",$sectie,"section");
if($translation_arr)
{
$sectie_id = $translation_arr["element_id"];
$sectie_info = $this->run("SELECT * FROM `secties` WHERE `secties`.`sectie_id` = '". $sectie_id ."'",false);
$sectie = $sectie_info["naam"];
}
}
//echo "SELECT * FROM `secties` LEFT JOIN `stramiens` ON `secties`.`stramien` = `stramiens`.`stramien_id` WHERE `secties`.`naam` LIKE '". $this->validDBpar($sectie) ."' AND `secties`.`active` = '1'";
$sectie_info = $this->run("SELECT * FROM `secties` LEFT JOIN `stramiens` ON `secties`.`stramien` = `stramiens`.`stramien_id` WHERE `secties`.`naam` LIKE '". $this->validDBpar($sectie) ."' AND `secties`.`active` = '1'",false);
return $sectie_info;
}
function validDBpar($str)
{
return preg_replace("/( |-)/","_", $this->esc($str) );
}
function getCategories($sectie_naam)
{
// get categories
$sectie_id = $this->getSectionId($sectie_naam);
$categories = $this->run("SELECT * FROM `categories` WHERE `sectie_id`='". $sectie_id ."' AND `active` = '1' ORDER BY position");
if($this->lang_id != 0)
{
foreach($categories as $i => $c)
{
// get translation
$translation_arr = $this->getTranslation("value",$c["naam"],"category");
if($translation_arr)
{
$sectie_id = $translation_arr["element_id"];
$sectie_info = $this->run("SELECT * FROM `secties` LEFT JOIN `stramiens` ON `secties`.`stramien` = `stramiens`.`stramien_id` WHERE `secties`.`sectie_id` = '". $sectie_id ."'",false);
$sectie_naam = $sectie_info["naam"];
}
else unset($categories[$i]);
}
}
else return $categories;
}
function getSectionId($sectie_naam)
{
$sectie_arr = $this->run("SELECT `sectie_id` FROM `secties` WHERE `naam` LIKE '".preg_replace("/( |-)/","%",$this->esc($sectie_naam))."%'",false);
return $sectie_arr["sectie_id"];
}
function checkRedirect($url)
{
// $url = str_replace($this->base_str,"",$url);
$data = $this->run("SELECT * FROM `page_redirects` WHERE `old_url` LIKE '". $this->esc($url) ."'",false);
return $data["new_url"] ? $data["new_url"] : false;
}
}
class entryData extends dbConnect{
function __construct($connection,$fields,$data,$unique_id,$template_id,$sectie_id=null,$post_category=null,$wrapSections=false,$link_base=null,$lang_id=0){
$this->connection = $connection;
$this->wrapSections = $wrapSections;
$this->link_base = $link_base;
$this->entry_id = $data["entry_id"];
$this->status = $data["status"];
$this->position = $data["position"];
$this->last_edit = $data["last_edit"];
$this->unique_id = $unique_id;
$this->template_id = $template_id;
$this->template = preg_replace("/ /","_",$this->get("templates","template_id",$template_id,"naam"));
$this->form_id = $data["form_id"];
$this->meta_title = $data["meta_title"];
$this->meta_desc = $data["meta_desc"];
$this->page_redirect= $data["page_redirect"];
$this->stramien_id = $data["stramien_id"];
$this->lang_id = $lang_id;
$this->transltn_uid = isset($data["translation_uid"]) ? $data["translation_uid"] : 0;
$unique_data = $this->get("unique_ids","unique_id",$this->unique_id);
$this->sectie_id = $unique_data["sectie_id"];
$this->sectie = $this->lang_id == 0 ? $this->get("secties","sectie_id",$this->sectie_id,"naam") : $this->getSectionTranslation();
$this->entry_link = $this->link_base . vl($this->sectie."/".preg_replace("/\//","",$data[$fields[0]["field_naam"]])."-".$this->unique_id);
$this->org_url = $unique_data["url"];
$this->first_field = null;
foreach($fields as $i => $f)
{
if($f["type"] == 1)
{
$field_user = preg_replace("/[^0-9a-zA-Z]/","_",strtolower($f["field_user"]));
if($i == null) $this->first_field = $field_user;
$this->fieldHTML($f["field_naam"],$f["form_element"],$data[$f["field_naam"]]);
}
else
{
$this->fieldHTML($f["field_naam"],$f["form_element"],$f["template_field_id"]);
}
}
}
function getSectionTranslation()
{
$translation_arr = $this->run("SELECT * FROM `translations` WHERE `language_id` = '$this->lang_id' AND `element_id` = '". $this->sectie_id ."' AND type='section' ",false);
return $translation_arr["value"];
}
function fieldHtml($field_user,$element,$value){
$field_user = preg_replace("/[^0-9a-zA-Z]/","_",strtolower($field_user));
$data = array();
$value = stripslashes($value);
switch($element){
case "shop":
$staffel_array = $this->run("SELECT * FROM `prijzen_product` WHERE `unique_id` = '$this->unique_id'");
$html = '<div class="product-price">';
$html .= '<p><a class="bestellen-button rounded" href="winkelwagen?uid='.$this->unique_id.'">Bestellen</a></p>';
$html .= '</div>';
$this->$field_user = $html;
$this->prijs_voor = $staffel_array[0]["voor"];
$this->prijs_van = $staffel_array[0]["van"];
break;
case "link":
case "cols":
if(trim($value) != ""){
$files = explode("|*|",$value);
$data = array();
foreach($files as $f){
$file_data = explode("|-|",$f);
// $cassette = new cassetteFrontend();
// $entry = $cassette->entries(null,null,$file_data[0]);
// $fieldName = $entry->first_field;
// $file_data[2] = $entry->$fieldName;
// $file_data[3] = $entry->entry_link;
array_push($data,$file_data);
}
}else $data = array();
$this->$field_user = $data;
break;
case "image":
$this->$field_user = explode("|*|",$value);
break;
case "files":
$files = explode("|*|",$value);
$data = array();
foreach($files as $f){
$file_data = explode("|-|",$f);
if($file_data[0] == "") continue;
if(end($file_data) == ""){
$parts = explode("/",preg_replace("/_/"," ",$file_data[0]));
$file_data[1] = end($parts);
}
array_push($data,$file_data);
}
$this->$field_user = $data;
break;
case "dragdrop":
$this->$field_user = "";
// check for translation data id
$load_uid = $this->transltn_uid == 0 ? $this->unique_id : $this->transltn_uid;
$sections = $this->run("SELECT * FROM `page_section_content` WHERE `page_id` = '". $load_uid ."' AND `status` = '1' ORDER BY `position` ASC");
foreach($sections as $s){
$bg = $s["css"] != "" ? $s["css"].";" : "";
if($s["link_data"] != 0){
$cassette = new cassetteFrontend();
$cassette->connectDB();
// org content
$original_content = $s["html"];
// template
$link_data = $this->run("SELECT * FROM `link_data` WHERE `link_data_id` = '". $s["link_data"] ."'",false);
// field to replace in template
$template_fields = $this->run("SELECT * FROM `link_data_fields` WHERE `template_data_id` = '". $s["link_data"] ."'");
/*
<p style="text-align: center;"><img alt="" src="{image}" /></p>
<h3 style="text-align: center;">{heading}</h3>
<p style="text-align: center;">{tekst}</p>
<p style="text-align: center;"><a class="button secondary" href="{link}">{link_label}</a></p>
*/
// entries in linked category
$entries = $cassette->entries($link_data["section"],$link_data["category"]); //$link_data["category"],$link_data["entry"]
//d($entries);
//echo $link_data["category"];
$replace_total = substr_count($original_content, $link_data["find"]);
// replace all items in entry array
if($link_data["repeat_items"] == 0 && $replace_total == 1)
{
$html_str = '';
for($entry_no=0; $entry_no<count($entries); $entry_no++)
{
//echo $entry_no." - ";
// set org template
$template = $link_data["template"];
// find and replace fields in template
foreach($template_fields as $tp_fld)
{
if(!$tp_fld["field"]) continue;
$field = $tp_fld["field"];
$value = $entries[$entry_no]->$field;
if( $tp_fld["array"] == 1 ) $value = $value[$tp_fld["index"]];
$template = preg_replace("/".$tp_fld["template"]."/i", $value, $template);
}
$html_str .= $template;
}
$original_content = preg_replace("/". $link_data["find"] ."/i", $html_str,$original_content);
$s["html"] = $original_content;
}
else
{
for($i=0; $i<$replace_total; $i++)
{
// set org template
$template = $link_data["template"];
// find and replace fields in template
foreach($template_fields as $tp_fld){
if(!$tp_fld["field"]) continue;
$field = $tp_fld["field"];
$value = $entries[$i]->$field;
if( $tp_fld["array"] == 1 ) $value = $value[$tp_fld["index"]];
$template = preg_replace("/".$tp_fld["template"]."/i", $value, $template);
}
$original_content = $this->str_replace_nth($link_data["find"], $template, $original_content, $i);
}
}
$s["html"] = $original_content;
}
if($this->wrapSections == 0) $this->$field_user .= '<div id="'. $s["element_id"] .'" class="'. vl($s["element_class"]) .'" style="'. $bg .'">'. $s["html"] .'</div>';
else $this->$field_user .= preg_replace(array("/{section_htmlwrapper}/","/{style}/","/{element-id}/","/{element-class}/"),array($s["html"],$bg,$s["element_id"],$s["element_class"]),$this->section_htmlwrapper);
}
break;
default:
$this->$field_user = $value;
break;
}
}
function str_replace_nth($search, $replace, $subject, $nth)
{
$found = preg_match_all('/'.preg_quote($search).'/', $subject, $matches, PREG_OFFSET_CAPTURE);
if ($found !== false) {
return substr_replace($subject, $replace, $matches[0][0][1], strlen($search));
}
return $subject;
}
function formatPrice($str){
return "€ ".number_format($str,2,',','');
}
}
class cassetteForm extends dbConnect{
function __construct($connection,$formid){
$this->connection = $connection;
$r = $this->run("SELECT * FROM `forms` WHERE `form_id` = $formid",false);
$this->formid = $formid;
$this->unique_id = $r["unique_id"];
$this->eName = $r["form_name"];
$this->response = $r["form_response"];
$this->desc = $r["form_desc"];
$this->btn_label = $r["button_label"];
$this->handler = $r["custom_handler"] != "" ? $r["custom_handler"] : "handle-form";
$this->showMsg = false;
}
function getFields(){
$elements = array();
$form_fields = $this->run("SELECT * FROM `form_elements` WHERE `unique_id`= '$this->unique_id' ORDER BY `position` ASC ");
foreach($form_fields as $r)
{
$e = array();
$e["elementId"] = $r["form_element_id"];
$e["type"] = $r["field_id"];
$e["required"] = $r["value"];
if($e["required"] == 1) $this->showMsg = true;
$test = $this->getFormField($r['form_element_id'],$r['field_id'],$r["name"],$r["description"]);
foreach($test as $t => $v){
$e[$t] = $v;
}
array_push($elements,$e);
}
// add form id
array_push($elements,$this->addFormId());
// add a button
array_push($elements,$this->addButton());
// add required filling fields
if($this->showMsg == true) array_push($elements,$this->addMsg());
return $elements;
}
function addMsg(){
$d = array();
$d["type"] = "msg";
$d["name"] = "*) Verplicht invullen";
$d["desc"] = "";
return $d;
}
function addButton(){
$d = array();
$d["type"] = "submit";
$d["name"] = "";//$naam;
$d["desc"] = "";//$desc;
return $d;
}
function addFormId(){
$d = array();
$d["type"] = "hidden";
$d["name"] = "formid";
$d["desc"] = $this->formid;
return $d;
}
function getFormField($form_el_id,$field_id,$naam,$desc){
$d = array();
$elementName = str_replace(" ","",$form_el_id."-".$naam);
switch($field_id){
// input
case 1:
$d["type"] = "input";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
//dropdown
case 28:
$d["type"] = "select";
$d["name"] = $naam;
$d["desc"] = $desc;
$o = array();
$element_options = $this->run("SELECT * FROM form_elements_options WHERE form_element_id = $form_el_id ORDER BY form_option_id ASC");
foreach($element_options as $r)
{
array_push($o,$r['value']);
}
$d["options"] = $o;
break;
//radio
case 31:
$d["type"] = "radio";
$d["name"] = $naam;
$d["desc"] = $desc;
$o = array();
$element_options = $this->run("SELECT * FROM form_elements_options WHERE form_element_id = $form_el_id ORDER BY form_option_id ASC");
foreach($element_options as $r)
{
array_push($o,$r['value']);
}
$d["options"] = $o;
break;
//checkbox
case 24:
$d["type"] = "checkbox";
$d["name"] = $naam;
$d["desc"] = $desc;
$o = array();
$element_options = $this->run("SELECT * FROM form_elements_options WHERE form_element_id = $form_el_id");
foreach($element_options as $r){
array_push($o,$r['value']);
}
$d["options"] = $o;
break;
//multi text line
case 5:
$d["type"] = "textarea";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 15:
$d["type"] = "deactivatedfield";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 14:
$d["type"] = "datepicker";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 16:
$d["type"] = "inactiveinput";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 32:
$d["type"] = "tussenkop";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 18:
case 60:
$d["type"] = "bijlage";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 59:
$d["type"] = "geboortedatum";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
case 47:
$d["type"] = "postdata";
$d["name"] = $naam;
$d["desc"] = $desc;
break;
}
$d["valueName"] = preg_replace("/ /","_",strtolower($form_el_id."_".$naam));
return $d;
}
function cassetteFormElement($array){
$hidefieldsets = array("submit","hidden","msg");
$type = $array["type"];
$name = $array["name"];
$desc = $name. (trim($array["desc"]) != "" ? '<span class="normal">' . $array["desc"] . "</span>" : "");
$opts = (isset($array["options"])) ? $array["options"] : null ;
$eid = (isset($array["elementId"])) ? $array["elementId"] : null;
$req = (isset($array["required"]) && $array["required"] == 1) ? " required" : "";
$lbl = (isset($array["required"]) && $array["required"] == 1) ? " *" : "";
$inpName = $eid.preg_replace("/[^0-9a-zA-Z]/","",strtolower($name));
$el = "";
switch($type){
case "input":
//$el .= "<legend>$desc $lbl</legend>";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='input-wrapper'><input type='text' class='form-text$req' name='$inpName' autocomplete='off' /></div>";
break;
case "inactiveinput":
//$el .= "<legend>$desc $lbl</legend>";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<input type='text' name='$inpName' class='$req' value='#value#'disabled />";
break;
case "deactivatedfield":
$el .= "<input type='hidden' name='$inpName' value='$desc'/>";
break;
case "datepicker":
//$el .= "<legend>$desc $lbl</legend>";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='input-wrapper'><input type='text' name='$inpName' class='form-text calendar$req' autocomplete='off' /></div>";
break;
case "select":
//$el .= "<legend>$desc $lbl</legend>";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='option-wrapper'><select type='text' name='$inpName' class='select'>";
foreach($opts as $o){
$el .= "<option value='".htmlentities($o)."'>".utf8_decode($o)."</option>";
}
$el .= "</select></div>";
break;
case "radio":
$verplicht = ($array["required"] == 1) ? " required" : "";
//$el .= "<legend>$desc $lbl</legend>";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='block$verplicht' id='$inpName'>";
foreach($opts as $i => $o){
$checked = ($i == 0) ? " checked" : null;
$el .= "<span class='floatleft'><input type='radio' id='$inpName$i' name='$inpName' value='$o' $checked /> <label for='$inpName$i'>$o</label></span>";
}
$el .= "</div>";
break;
case "checkbox":
$verplicht = ($array["required"] == 1) ? " required" : "";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='block$verplicht' id='$inpName'>";
foreach($opts as $o){
$el .= "<span class='floatleft block'><input type='checkbox' name='".$inpName."[]' value='$o' /> <label>$o</label></span>";
}
$el .= "</div>";
break;
case "textarea":
//$el .= "<legend>$desc $lbl</legend>";
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='input-wrapper'><textarea class='form-text textarea$req' name='$inpName'></textarea></div>";
break;
case "submit":
$el .= "<div class='button-wrapper'><input type='submit' name='send' value='".$this->btn_label."' class='button secondary' id='".preg_replace("/[^0-9a-zA-Z]/","",strtolower($this->btn_label))."' /></div>";
break;
case "hidden":
$el .= "<input type='hidden' name='$inpName' value='$desc'/>";
break;
case "msg":
$el .= "<div class='msg-wrapper'><p>$desc</p></div>";
break;
case "tussenkop":
$el .= "<label class='group'>$name</label>";
if($array["desc"]) $el .= "<p>".$array["desc"]."</p>";
break;
case "bijlage":
$el .= "<label class='legend'>$desc $lbl</label>";
$el .= "<div class='file-wrapper'><span><input type='file' class='form-text$req' name='$inpName' accept='.doc, .docx, .pdf, .odt, application/msword, application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document,'/></span></div>";
break;
case "geboortedatum":
$el .= '<label class="legend">'.$desc.' '.$lbl.'</label>';
$el .= "<div class='block'>";
$el .= '<div class="input-wrapper date"><input type="text" name="'.$inpName.'-dd" class="form-text datum" autocomplete="off" placeholder="dd" maxlength="2" value="" /></div>';
$el .= '<div class="input-wrapper date"><input type="text" name="'.$inpName.'-mm" class="form-text datum" autocomplete="off" placeholder="mm" maxlength="2" value="" /></div>';
$el .= '<div class="input-wrapper date"><input type="text" name="'.$inpName.'-jjjj" class="form-text datum" autocomplete="off" placeholder="jjjj" maxlength="4" value="" /></div>';
$el .= '</div>';
break;
case "postdata":
$el .= "<input type='hidden' name='$inpName' value='". dp($_GET[$desc]) ."'/>";
break;
}
$data = "";
if(!in_array($type,$hidefieldsets)) $data .= '<fieldset class="'. preg_replace("/[^0-9a-zA-Z]/","",strtolower($name)) .'">';
$data .= $el;
if($type != "msg") $data .= "</fieldset>";
return $data;
}
}
class webWinkelData{
function __construct($klant_id){
$this->klant_id = $klant_id;
$this->setClientData();
}
function getBestellingTotaal($sessiondata){
$total = 0;
foreach($sessiondata as $uid => $p){
$total = $total + $p["totaal"];
}
return $total;
}
function setClientData(){
$q = mysql_query("SELECT * FROM `klanten` WHERE `klant_id` = '$this->klant_id'");
$r = mysql_fetch_assoc($q);
$this->klantData = array();
foreach($r as $column => $value){
$this->klantData[$column] = $value;
}
$this->naam_volledig = preg_replace('/\s+/', ' ',$this->klantData["voornaam"]." ".$this->klantData["tussenvoegsel"]." ".$this->klantData["achternaam"]);
$bedrijfsnaam = ($this->klantData["bedrijfsnaam"] != "") ? $this->klantData["bedrijfsnaam"]."<br />tav " : null;
$this->userDBadres = $bedrijfsnaam.$this->naam_volledig."<br />".$this->klantData["straat"]." ".$this->klantData["huisnummer"]."<br />".$this->klantData["postcode"]." ".$this->klantData["plaats"]."<br />".$this->klantData["land"]."<br /><a href='".$this->klantData["email"]."' style='".$this->css_color."'>".$this->klantData["email"]."</a>";
}
function insertKlantinfo($post){
mysql_query("INSERT INTO `klanten` (`aanhef`,`voornaam`,`bedrijfsnaam`,`telefoon`,`email`,`straat`,`huisnummer`,`postcode`,`plaats`,`land`) VALUES('".e($post["aanhef"])."','".e($post["naam"])."','".e($post["bedrijfsnaam"])."','".e($post["telefoon"])."','".e($post["email"])."','".e($post["straat"])."','".e($post["huisnummer"])."','".e($post["postcode"])."','".e($post["plaats"])."','".e($post["land"])."')") or die(mysql_error());
$this->klant_id = mysql_insert_id();
// set client data
$this->setClientData();
return $this->klant_id;
} //$$_POST['betaalwijze'],1,1,$_POST["opmerkingen"],$bericht,$bestelling_betaald
function insertBestelling($user_id,$factuur_nr,$totaal,$bezorgkosten,$betaalwijze,$halenbezorgen,$voltooid,$opmerkingen,$html_email,$bestelling_betaald){
//$totaal = str_replace(",",".",$totaal);
mysql_query("INSERT INTO `bestellingen` (`klant_id`, `order_id`, `totaal`, `bezorgkosten`, `type_betaling`, `verzending`,`opmerkingen`,`voltooid`,`betaald`,`html`)
VALUES (".esc($user_id).", '".esc($factuur_nr)."','$totaal','".esc($bezorgkosten)."','".esc($betaalwijze)."', '".esc($halenbezorgen)."', '".esc($opmerkingen)."','$voltooid','$bestelling_betaald','".esc($html_email)."')") or die(mysql_error());
return mysql_insert_id();
}
function insertBestellingProducten($bestellijst,$bestelling_id){
foreach($bestellijst as $uid => $p){
$totaal = str_replace(",",".",$p["totaal"]);
mysql_query("INSERT INTO `bestellingen_producten` (`uid`, `bestelling_id`, `aantal`, `prijs`, `totaal`) VALUES ('".esc($p["uid"])."', '".esc($bestelling_id)."', '".esc($p["aantal"])."', '".esc($p["prijs"])."', '".$totaal."')") or die(mysql_error());
}
}
function updateBezorgAdres($bestelling_id,$tav_afleveradres,$straat_afleveradres,$huisnummer_afleveradres,$postcode_afleveradres,$plaats_afleveradres,$land_afleveradres){
mysql_query("UPDATE `bestellingen` SET `tav` = '".esc($tav_afleveradres)."',`straat` = '".esc($straat_afleveradres)."',`huisnummer` = '".esc($huisnummer_afleveradres)."',`postcode` = '".esc($postcode_afleveradres)."',`plaats` = '".esc($plaats_afleveradres)."',`land` = '".esc($land_afleveradres)."' WHERE `bestelling_id` = '".esc($bestelling_id)."'") or die("update error: ".mysql_error());
}
function insertAfleveradres($user_id,$afleveradres){
mysqL_query("INSERT INTO `bestellingen_afleveradressen` (`user_id`, `adres`) VALUES (".esc($user_id).", '".esc($afleveradres)."')");
}
function updateTransactieId($bestelling_id,$transactionID){
mysql_query("UPDATE `bestellingen` SET `ideal_trans_id` = '".esc($transactionID)."',`betaald` = '1' WHERE `bestelling_id` = ".esc($bestelling_id)) or die("update error: ".mysql_error());
}
function updateIdealStatus($transactionID){
mysql_query("UPDATE `bestellingen` SET `voltooid` = 1 WHERE `ideal_trans_id` = '".esc($transactionID)."'") or die("update error: ".mysql_error());
}
function getDBFactuurNummer($transactionID){
$q = mysql_query("SELECT * FROM `bestellingen` WHERE `ideal_trans_id` = '".esc($transactionID)."'");
$r = mysql_fetch_assoc($q);
return $r["order_id"];
}
function getFactuurNummer(){
$q = mysql_query("SELECT * FROM `instellingen` LIMIT 0,1");
$r = mysql_fetch_assoc($q);
mysql_query("UPDATE `instellingen` SET `order_nummer`= ".($r["order_nummer"]+1)." WHERE `id` = ".$r["id"]) or die(mysql_error());
return $factuurnummer = $r["prefix_order_nummer"].sprintf('%05d',$r["order_nummer"]);
}
function bevestigAanmelding(){
// add email footer
$bericht .= $this->getEmailHeader();
// welkomstbericht email
$bericht .= "<tr><td colspan='4'>";
$bericht .= "<p>Beste ".$this->naam_volledig.",<br><br>";
$bericht .= "Wij heten u van harte welkom als klant bij Kidspel.</p>";
$bericht .= "<p><strong>Hieronder vindt u een overzicht van de ingevoerde gegevens op de website.</strong></p>";
$bericht .= "<p>U kunt direct beginnen met bestellen op <a href='http://www.kidsspel.nl' style='color:#D22229'>kidsspel.nl</a></p>";
$bericht .= "<p>Met vriendelijke groet,<br> Kidsspel</p>";
$bericht .= "</td></tr>";
$bericht .= "<tr><td colspan='4' style='border-bottom:solid 1px #d9d9d9;'> </td></tr>";
$bericht .= "<tr><td colspan='4' style='line-height:1px;'> </td></tr>";
$bericht .= "<tr><td colspan='4'>";
// loop registratie velden
$bericht .= "<table border='0' cellspacing='0' cellpadding='0' style='width:100%; font-size:12px;font-family:Helvetica,arial, sans-serif; color:#333;'>";
foreach($this->klantData as $column => $value){
if($column == "gebruiker_id" || $column == "datum_aanmelding") continue;
$label = ($column == "email") ? $column." (gebruikersnaam)": $column;
if($value != "") $bericht .= "<tr><td style='width:200px;height:20px;font-weight:bold;'>".ucfirst($label)."</td><td style='height:20px;'>$value</td></tr>";
}
$bericht .= "</table>";
$bericht .= "</td></tr>";
// add email footer
$bericht .= $this->getEmailFooter();
$verstuurd = $this->verstuurEmail($bericht,"Bevestiging aanmelding kidsspel.nl");
return $verstuurd;
}
function maakFactuur($emailBody){
// add email footer
$bericht = $this->getEmailHeader();
// email body toevoegen
$bericht .= "<tr><td colspan='4'>".$emailBody."</td></tr>";
// add email footer
$bericht .= $this->getEmailFooter();
return $bericht;
}
function verstuurEmail($bericht,$onderwerp,$user_email=null){
$data = $this->data("instellingen","WHERE `id`='1'");
$data = $data[0];
$d = date('l dS \of F Y h:i:s A');
$headers_consument = "From: ".$data["master_email"]."\n";
$headers_consument .= "Reply-To: ".$data["master_email"]."\n";
$headers_consument .= "Content-type: text/html; charset=UTF-8\n";
$headers_masteremail = "From: ".$data["master_email"]."\n";
$headers_masteremail .= "Reply-To: $user_email\n";
$headers_masteremail .= "Content-type: text/html; charset=UTF-8\n";
if($user_email != null) mail($user_email, $onderwerp, $bericht, $headers_consument);
if(mail($data["master_email"], $onderwerp, $bericht, $headers_masteremail)) return true;
else return false;
}
function getEmailFooter(){
$data = $this->data("instellingen","WHERE `id`='1'");
$data = $data[0];
$footer = "<tr><td colspan='4' style='border-bottom:solid 1px #d9d9d9;'> </td></tr>";
$footer .= "<tr><td colspan='4'> </td></tr>";
$footer .= "<tr><td colspan='4' style='width:260px;vertical-align:top;line-height:16px;'>";
$footer .= "<table border='0' cellspacing='0' cellpadding='0' style='width:100%; font-size:11px;font-family:Helvetica,arial, sans-serif; color:#333;'>";
$footer .= "<tr>";
$footer .= "<td style='width:300px;vertical-align:top;font-size:11px;'>
".$data["adres"]."<br />
".$data["postcode_woonplaats"]."<br />
Telefoon ".$data["telefoon"]."</td>";
$footer .= "<td style='vertical-align:top;font-size:11px;'>Bank ".$data["bank"]."<br />IBAN ".$data["bank_iban"]."<br />BIC ".$data["bank_bic"]."</td>";
$footer .= "</tr>";
$footer .= "<tr><td colspan='2' style='font-size:11px;font-family:Helvetica,arial, sans-serif; color:#333;'><br /><a href='http://www.behangoutletshop.nl' style='".$this->css_color."'>www.behangoutletshop.nl</a>, <a href='http://www.verfoutletshop.nl' style='".$this->css_color."'>www.verfoutletshop.nl</a>, <a href='http://www.goedinverf.nl' style='".$this->css_color."'>www.goedinverf.nl</a> en <a href='http://www.verfenbehangland.nl' style='".$this->css_color."'>www.verfenbehangland.nl</a><br />zijn handelsnamen van Mondriaan Trading B.V. ingeschreven bij de kamer van koophandel onder nummer 57461201</td></tr>";
$footer .= "</table>";
$footer .= "</td></tr>";
$footer .= "<tr><td colspan='4'> </td></tr>";
$footer .= "<tr><td colspan='4'> </td></tr>";
$footer .= "</table>";
$footer .= "</body></html>";
return $footer;
}
function getEmailHeader(){
// echo "<pre>";
// print_r($this);
// echo "</pre>";
$this->initialize();
$header = "<html><head></head><body>";
$header .= "<table border='0' cellspacing='0' cellpadding='5' style='width:600px; font-size:12px;font-family:Helvetica,arial, sans-serif; color:#333;' align='center'>";
$header .= "<tr><td colspan='4'> </td></tr>";
$header .= "<tr><td colspan='4' style='border-bottom:solid 1px #d9d9d9;height:124x;'><img src='".$this->base."clientdata/logo-email.png' alt='$this->company_short' /></td></tr>";
$header .= "<tr><td colspan='4'> </td></tr>";
return $header;
}
}
?>