<?php

/* hack for qtranslatesupport */
if(!function_exists('qtrans_getLanguage')){function qtrans_getLanguage(){}}
if (!is_array($this->saltdone)) { $this->saltdone = array(); }

if (is_user_logged_in()) {
	global $current_user,$arr_user,$user;
	if (!isset($arr_user)) {
		$arr_user = array('subscriber'=>0, 'contributor'=>1, 'author'=>2, 'editor'=>5, 'administrator'=>8);
	}
	get_currentuserinfo();
	$user = $current_user;
	if (!is_object($user)) {
		if ($user->blog_capabilities['administrator'] == '1' AND $user->user_level == '0') { $user->user_level = '10'; }
	}
}

if ($_GET['wcteid'] == '' AND $eid == '') {
	$url = $this->generate_pagelink("/[&?]+wcteid=[0-9]*/","");
	$cache = $this->filtermd($filter.$design.$css);

	$out = wp_cache_get( 'wct_table'.$id.$cache.count($this->saltdone)."_".$_REQUEST['wctstart'].'s'.$_REQUEST['wctsort'].$_REQUEST['wctinvs'] , 'wct');
	if ($out == false OR is_user_logged_in()) {
		if ($design != '' AND $design != NULL) {
			$designnotfound = '0'; 
			$table = $wpdb->get_row("SELECT `e_setup`,`t_setup`,`overlay`,`headerline`,`header`,`headersort`,`vortext`,`nachtext`,`o_setup`,`sheme`,`sort`,`sortB`,`searchaddon`,`dl` FROM `".$wpdb->prefix."wct_setup` WHERE `table_id`='".$id."' AND (`name`='".mres($design)."' OR `id`='".mres($design)."') LIMIT 1;");
			if (count($table) != '1') { $designnotfound = '1'; }
		}
		if ($designnotfound == '1' OR !isset($designnotfound)) {
			$table = $wpdb->get_row("SELECT `e_setup`,`t_setup`,`overlay`,`headerline`,`header`,`headersort`,`vortext`,`nachtext`,`o_setup`,`sheme`,`sort`,`sortB`,`searchaddon`,`dl` FROM `".$wpdb->prefix."wct_list` WHERE `id`='".$id."' LIMIT 1;");
		}

		if ($table->t_setup != '') {
			global $wctcssdone;
			$colspan = substr_count($table->t_setup,"<td");
			if ($wctcssdone != '1') { $out = "<style>".stripslashes($this->settings['css'])."</style>"; $wctcssdone = '1'; }
			else { $out = ''; }

			if ($table->vortext != '') { $out .= rbr(stripslashes($table->vortext))."<br/>&nbsp;"; }
			if ($table->overlay == '1') {
			$out .= "<script>
				function box_show(name,namB,color) {
					document.getElementById(\"hH\").value = document.getElementById(name).offsetHeight;
					document.getElementById(namB).setAttribute(\"class\", color);
					document.getElementById(name).style.top = document.getElementById(\"My\").value+\"px\";
					document.getElementById(name).style.left = document.getElementById(\"Mx\").value+\"px\";
					document.getElementById(name).style.visibility = \"visible\";
					document.getElementById(name).style.display = 'block';
				}
				function box_hide(name,namB,color) {
					document.getElementById(namB).setAttribute(\"class\", color);
					document.getElementById(name).style.visibility = \"hidden\";
					document.getElementById(name).style.display = 'none';
				}
				var IE = false;
				if (navigator.appName == \"Microsoft Internet Explorer\"){IE = true}
				if (!IE){document.captureEvents(Event.MOUSEMOVE) }
				document.onmousemove = getMouseXY;
				function getMouseXY(m){
					if (IE) {var tmpX = event.clientX;var tmpY = event.clientY;}
					else if(m.clientY){var tmpX = m.clientX;var tmpY = m.clientY;}
				 	else {var tmpX = m.pageX;var tmpY = m.pageY;}

					if (IE) {
						if (document.documentElement.scrollTop) {var iL = document.documentElement.scrollLeft;var iV = document.documentElement.scrollTop;var hH = document.documentElement.offsetHeight;var wH = document.documentElement.offsetWidth;}
						else if (document.body.scrollTop) {var iL = document.body.scrollLeft;var iV = document.body.scrollTop; var hH = document.body.offsetHeight;var wH = document.body.offsetWidth;}
						else { iL = 0; iV = 0; }

						if ('IE6' == '";
						if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== false) { $pos = "IE6"; }
						$out .= $pos."') {
							var ie6pos = findPos('wct-table');
							iV = iV - ie6pos[1] +140;
							iL = iL - ie6pos[0] +12;
						}
					}
					else {
						iL = 0; iV = 0;
						var hH = window.innerHeight;var wH = window.innerWidth;
					}

				  	var breite = tmpX + iL + 10;
				  	var hohe = tmpY + iV;

					var divhohe = parseInt(document.getElementById(\"hH\").value);
					if (hH < (hohe + divhohe)) {
						hohe = hH - divhohe;
					}

					document.getElementById(\"My\").value = hohe;
					document.getElementById(\"Mx\").value = breite;
				}
				function findPos(obj) {
					obj = document.getElementById(obj);

					var posX = obj.offsetLeft;var posY = obj.offsetTop;

					while(obj.offsetParent) {
						if(obj==document.getElementsByTagName('body')[0]){break;}
						else {
							posX=posX+obj.offsetParent.offsetLeft;
							posY=posY+obj.offsetParent.offsetTop;
							obj=obj.offsetParent;
						}
					}
					var posArray=[posX,posY];
					return posArray;
				}
				</script>
				<input type=\"hidden\" id=\"Mx\"><input type=\"hidden\" id=\"My\"><input type=\"hidden\" id=\"hH\">";
			}
			$out .= "<table name=\"wct-table\" id=\"wct-table\" class=\"wct".$css."-table\">";

			if ($table->headerline == '1') {
				$out .= "<tr class=\"wct".$css."-headline\">";
				$y = '0';

				$sort = explode(",",$table->headersort);
				if ($table->header == '') {
					$inhalt = str_replace("[LINK]","",apply_filters('wct_table',$table->t_setup));
					preg_match_all("/\[(.*?)\]/",$inhalt,$felde);
					$felder = $felde[1];
					foreach ($felder as $feld) {
						$out .= "<td><b>".$feld."</b>";
						if ($sort[$y] != '') { $out .= " ".$this->wct_sort($sort[$y],$table); }
						$out .= "</td>";
						$y++;
					}
				}
				else {
					$inhalt = stripslashes($table->header);
					$felder = explode(",",$inhalt);
					foreach ($felder as $feld) {
						/*qtranslate support */
						if (preg_match('/.*!--:'.qtrans_getLanguage().'-->(.*?)<!--:--.*/',rbr($feld))) {
							/* Language found */
							preg_match('/.*!--:'.qtrans_getLanguage().'-->(.*?)<!--:--.*/',rbr($feld), $treffer);
							$feld = $treffer[1];
						}
						$out .= "<td><b>".rbr(do_shortcode($feld))."</b>";
						if ($sort[$y] != '') { $out .= " ".$this->wct_sort($sort[$y],$table); }
						$out .= "</td>";
						$y++;
					}
				}
				$out .= "</tr>";
			}

			$table2 = $wpdb->get_row("SHOW CREATE TABLE `".$wpdb->prefix."wct".$id."`;");
			$array=array(); foreach($table2 as $member=>$data) { $array[$member]=$data; }
			$felder = explode(",",str_replace(array("8,2","','","\r","\n"),array("8.2","'.'","",""),$array['Create Table']));

			unset($feld2,$feld3,$feld4);
			$feld2[1]['i'] = 'id';
			$feld2[1]['d'] = 'filter';

			for ($i=2;$felder[$i] != '';$i++) {
				if (strpos ($felder[$i-1]," enum") !== false) {
					 $feld3[$i]['i'] = preg_replace("/.*`(.*)`\s.*/","$1",$felder[$i-1]);
				}
				elseif (strpos ($felder[$i-1]," set") !== false) {
					 $feld5[$i]['i'] = preg_replace("/.*`(.*)`\s.*/","$1",$felder[$i-1]);
				}
				elseif (strpos ($felder[$i-1]," text") !== false) {
					 $feld2[$i]['i'] = preg_replace("/.*`(.*)`\s.*/","$1",$felder[$i-1]);
					 $feld2[$i]['d'] = "pass";
				}
				elseif (strpos ($felder[$i-1]," int(10)") !== false) {
					 $feld4[$i]['i'] = preg_replace("/.*`(.*)`\s.*/","$1",$felder[$i-1]);
				}
				else {
					 $feld2[$i]['i'] = preg_replace("/.*`(.*)`\s(.*\))\s.*/","$1",$felder[$i-1]);
					 $feld2[$i]['d'] = "pass";
				}
			}

			/** Load individual or global search query */
			$searchqry = ($_GET['wcts'] != '' ? $_GET['wcts'] : $_GET['s']);

			if ($nofilter == '' AND $searchqry != '') {

				/* Welche Felder sind erlaubt zum suchen */
				if ($_GET['wctsf'] != "*") { $wanted = ",".str_replace("%2C",",",$_GET['wctsf']).","; }
				
				unset($searchfields,$searchfields2);

				if (strstr($searchqry," ")) { $qquery = explode(" ",$searchqry); }
				else { $qquery = array('0'=>$searchqry); }
				foreach ($qquery as $searchqry) {
					if (is_array($feld2)) {
						foreach ($feld2 as $var => $werd) {
							if ($_GET['wctsf'] != '*') {
								if (strpos($wanted,",".$werd['i'].",") !== FALSE) {
									$searchfields .= "OR LOWER(`".$werd['i']."`) LIKE '%".mres(strtolower($searchqry))."%' ";
								}
							}
							else {
								$searchfields .= "OR LOWER(`".$werd['i']."`) LIKE '%".mres(strtolower($searchqry))."%' ";
							}
						}
					}
					if (is_array($feld3)) {
						foreach ($feld3 as $werd) {
							if ($werd['i'] != 'status') { $searchfields .= "OR LOWER(`".$werd['i']."`)='".mres(strtolower($searchqry))."' "; }
						}
					}
					if (is_array($feld5)) {
						foreach ($feld5 as $werd) {
							if ($werd['i'] != 'status') { $searchfields .= "OR FIND_IN_SET('".mres(strtolower($searchqry))."',LOWER(`".$werd['i']."`))>0 "; }
						}
					}

					if ($_GET['wctsz'] == '') {
						$query2 = $searchqry;

						if (preg_match("/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[2], $regs[1], $regs[3]); }
						elseif (preg_match("/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{2})$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[2], $regs[1], '20'.$regs[3]); }
						elseif (preg_match("/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[1], $regs[2], $regs[3]); }
						elseif (preg_match("/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2})$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[1], $regs[2], '20'.$regs[3]); }
						elseif (preg_match("/^([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[1], $regs[2], $regs[3]); }
						elseif (preg_match("/^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[3], $regs[2], $regs[1]); }
						elseif (preg_match("/^([0-9]{1,2})\.([0-9]{1,2})\.$/", $query2, $regs)) { $db_timestamp = mktime(1,1,1,$regs[2], $regs[1], date("Y",time())); }
						else {	unset($db_timestamp); }	
					}
					else { $db_timestamp = (integer)$_GET['wctsz']; }

					if (isset($db_timestamp) AND $db_timestamp != '') {
						if (is_array($feld4)) {
							foreach ($feld4 as $werd) {
								$searchfields .= "OR `".$werd['i']."`='".$db_timestamp."' ";
							}
						}
						if ($table->searchaddon != '') {
							$searchfields .= "OR (".str_replace("SEARCH",$db_timestamp,$table->searchaddon).") ";
						}
					}

					if ($_GET['wctsf'] == '*') { $searchfields = str_replace(array(",".$wpdb->prefix."wct".$id,",id"),array("",""),$searchfields); }
				}
				if ($searchfields != '') {
					$searchfields = substr($searchfields,3,strlen($searchfields));
				}
			}

			/* Searchstring if needed */
			if ($nofilter == '' AND $searchqry != '' AND $searchfields != '') {
				$zusatz = " AND ( ".$searchfields." )";
			}

			/* Filter if needed */
			if ($nofilter == '') {
				if (is_array($this->saltdone) AND count($this->saltdone) >= '1') {
					foreach ($this->saltdone as $dro) {
						if (isset($_GET[$dro.'wctdrop']) AND $_GET[$dro.'wctdrop'] != 'NULL' AND $_GET[$dro.'wctdrof'] != '') {
							if (is_array($feld5) AND !in_array(array('i'=>$_GET[$dro.'wctdrof']),$feld5)) {
								$zusatz .= " AND `".mres($_GET[$dro.'wctdrof'])."` LIKE '".mres(base64_decode($_GET[$dro.'wctdrop']))."'";
							}
							else {
								$zusatz .= " AND FIND_IN_SET('".($_GET[$dro.'wctdrop'] != '' ? mres(rtrim(base64_decode($_GET[$dro.'wctdrop']))) : '')."',LOWER(`".mres($_GET[$dro.'wctdrof'])."`))>0 ";
							}
						}
						elseif (isset($_GET[$dro.'wctmudrop']) AND $_GET[$dro.'wctmudrop'] != 'NULL' AND $_GET[$dro.'wctmudrof'] != '') {
							if (strpos($_GET[$dro.'wctmudrop'],",") !== false) {
								$drops = explode(",",$_GET[$dro.'wctmudrop']);
							}
							else {
								$drops = array('0' => $_GET[$dro.'wctmudrop']);
							}
							if (is_array($feld5) AND !in_array(array('i'=>$_GET[$dro.'wctmudrof']),$feld5)) {
								$zusatz .= " AND (";
								foreach ($drops as $wert) {
									if ($wert == "") {
										$zusatz .= " `".mres($_GET[$dro.'wctmudrof'])."`='' OR";
									}
									else {
										$zusatz .= " `".mres($_GET[$dro.'wctmudrof'])."` LIKE '".mres(base64_decode($wert))."' OR";
									}
								}
								$zusatz .= ")";
								$zusatz = str_replace("OR)",")",$zusatz);
							}
							else {
								$zusatz .= " AND (";
								foreach ($drops as$wert) {
									$zusatz .= " FIND_IN_SET('".($_GET[$dro.'wctmudrop'] != '' ? mres(base64_decode($wert)) : '')."',LOWER(`".mres($_GET[$dro.'wctmudrof'])."`))>0 OR";
								}
								$zusatz .= ")";
								$zusatz = str_replace("OR)",")",$zusatz);
							}
						}
					}
				}
				else {
					if (isset($_GET['wctdrop']) AND $_GET['wctdrop'] != 'NULL' AND $_GET['wctdrof'] != '') {
						if (is_array($feld5) AND !in_array(array('i'=>$_GET['wctdrof']),$feld5)) {
							$zusatz .= " AND `".mres($_GET['wctdrof'])."` LIKE '".mres(base64_decode($_GET['wctdrop']))."'";
						}
						else {
							$zusatz .= " AND FIND_IN_SET('".($_GET['wctdrop'] != '' ? mres(rtrim(base64_decode($_GET['wctdrop']))) : '')."',LOWER(`".mres($_GET['wctdrof'])."`))>0 ";
						}
					}
					elseif (isset($_GET['wctmudrop']) AND $_GET['wctmudrop'] != 'NULL' AND $_GET['wctmudrof'] != '') {
						if (is_array($feld5) AND !in_array(array('i'=>$_GET['wctmudrof']),$feld5)) {
							$zusatz .= " AND `".mres($_GET['wctmudrof'])."` LIKE '".mres(base64_decode($_GET['wctmudrop']))."'";
						}
						else {
							$zusatz .= " AND FIND_IN_SET('".($_GET['wctmudrop'] != '' ? mres(rtrim(base64_decode($_GET['wctmudrop']))) : '')."',LOWER(`".mres($_GET['wctmudrof'])."`))>0 ";
						}
					}
				}
			}

			if ($this->lastfilter != '') {
				$zusatz .= $this->lastfilter;
			}

			/* How it should be sorted */
			if ($nofilter == '' AND $_REQUEST['wctsort'] != '') {
				$zusatz .= " ORDER BY `".mres($_REQUEST['wctsort'])."` ";
				if ($_REQUEST['wctinvs'] == '1') { $zusatz .= "ASC"; } else { $zusatz .= "DESC"; }
			}
			else {
				$zusatz .= " ORDER BY `".$table->sort."` ".$table->sortB." "; 
			}

			/* Limit of Results, Next Pages */
			if ($_REQUEST['wctstart'] != '') {
				$start = (integer)$_REQUEST['wctstart'];
				$limit2 = ($start-1).",".$limit;
			} else { $limit2 = $limit; }

			if ($searched == '1' AND $searchqry == '') {
				$qry = '0';
			}
			else {
				$abfrage = "SELECT * FROM `".$wpdb->prefix."wct".$id."` WHERE `status`='active'".$zusatz." LIMIT ".$limit2.";";
				$qry = $wpdb->get_results($abfrage);
			}
			if (count($qry) >= '1') {

				if ($this->settings['nice_setfields'] == '1') {
					$table2 = $wpdb->get_row("SHOW CREATE TABLE `".$wpdb->prefix."wct".$id."`;");
					$array=array(); foreach($table2 as $member=>$data) { $array[$member]=$data; }
					$felder = explode(",",str_replace(array("8,2","','","\r","\n"),array("8.2","'.'","",""),$array['Create Table']));
					for ($i=2;$felder[$i] != '';$i++) {
						if (strpos ($felder[$i-1]," set") !== false) {
							$nicesetfeld[] = preg_replace("/.*`(.*)`\s.*/","$1",$felder[$i-1]);
						}
					}
				}

				foreach ($qry as $row) {

					if ($this->settings['nice_setfields'] == '1' AND is_array($nicesetfeld)) {
						foreach ($nicesetfeld as $wert) {
							$row->$wert = str_replace(",",", ",$row->$wert);
						}
					}

					// Remove breaklines between table
					$inhalt = $this->filter_tables(apply_filters('wct_table',$table->t_setup));

					// Replace link
					$inhalt = rbr(str_replace("[LINK]",$url."wcteid=".$row->id,stripslashes($inhalt)));

					if ($color == "1") { $color = "2"; } else { $color = "1"; }

					$out .= "<tr class=\"wct".$css."-td".$color."\" id=\"wct_omaster".$cache."_".$row->id."\" ";
					if ($table->overlay == '1' AND strpos($inhalt,"[wctoverlay]") === FALSE) { $out .= "onmousemove=\"box_show('wct_overlay".$cache."_".$row->id."','wct_omaster".$cache."_".$row->id."','wct".$css."-td-hover')\" onmouseout=\"box_hide('wct_overlay".$cache."_".$row->id."','wct_omaster".$cache."_".$row->id."','wct".$css."-td".$color."')\""; }
					else { $out .= "onmouseover=\"this.setAttribute('class', 'wct".$css."-td-hover')\" onmouseout=\"this.setAttribute('class', 'wct".$css."-td".$color."')\""; }

					if ($row->link != '') {
						$out .= " onclick=\"location.href='".$row->link."'\"";
					}
					elseif (strpos($table->t_setup,"[LINK]") == FALSE AND $table->e_setup != '') {
						$out .= " onclick=\"location.href='".$url."wcteid=".$row->id."'\"";
					}

					$out .= ">";
					if (has_filter('the_editor', 'qtrans_modifyRichEditor')) {

						/*qtranslate support*/
						if (!preg_match('/.*!--:'.qtrans_getLanguage().'-->(.*?)<!--:--.*/',$inhalt))
						{
							/* No multilanguage content found */
							$tmp = stripslashes(preg_replace("/\{(.*?)\}/e","stripslashes(\$row->$1)",$inhalt));
						}
						else {
							/* Language found */
							preg_match('/.*!--:'.qtrans_getLanguage().'-->(.*?)<!--:--.*/',$inhalt, $treffer);
							$tmp = stripslashes(preg_replace("/\{(.*?)\}/e","stripslashes(\$row->$1)",$treffer[1]));
						}
					}
					else {
						$tmp = preg_replace("/\{(.*?)\}/e","stripslashes(\$row->$1)",$inhalt);
					}

					if ($table->overlay == '1' AND strpos($inhalt,"[wctoverlay]") !== FALSE) { $tmp = str_replace("[wctoverlay]","[wctoverlay id=\"".$row->id."\" color=\"".$color."\"]",$tmp); }
					elseif (strpos($inhalt,"[wctoverlay]") !== FALSE) { $tmp = str_replace(array("[wctoverlay]","[/wctoverlay]"),array("",""),$tmp); }

					$out .= $tmp;	
					if (is_user_logged_in()) {
						if ($arr_user[$this->settings['crole'.$id.'_c']] <= $user->user_level) {
							$out .= "<td><a style=\"text-decoration:none;\" href=\"".admin_url()."admin.php?page=wct_table_".$id."&wcttab=content&action=edit&rid=".$row->id."\">[". __('Edit','wct')."]</a>";
						}
					}

					$out .= "</tr>";
					if ($table->overlay == '1') {

						if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== FALSE) { $pos = "position: absolute;"; }
						else { $pos = "position: fixed;"; }

						if (!preg_match('/!--:'.qtrans_getLanguage().'-->(.*?)<!--:--/',$this->filter_tables(apply_filters('wct_overlay',$table->o_setup)))) {
							$overlay .= "<div style=\"z-index:9999;".$pos."\" id=\"wct_overlay".$cache."_".$row->id."\" class=\"wct".$css."-overlay\">".rbr(rbr(do_shortcode(stripslashes(preg_replace("/\{(.*?)\}/e","stripslashes(\$row->$1)",stripslashes(apply_filters('wct_overlay',$table->o_setup))))," ",">","<")))."</div>";
						}
						else {
							preg_match('/.*!--:'.qtrans_getLanguage().'-->(.*?)<!--:--.*/',apply_filters('wct_overlay',$table->o_setup), $treffer);
							$overlay .= "<div style=\"z-index:9999;".$pos."\" id=\"wct_overlay".$cache."_".$row->id."\" class=\"wct".$css."-overlay\">".rbr(rbr(do_shortcode(stripslashes(preg_replace("/\{(.*?)\}/e","stripslashes(\$row->$1)",$treffer[1]))," ",">","<")))."</div>";
						}
					}
				}
			}
			else {
				$out .= "<tr><td colspan=\"".($colspan != '' ? $colspan : '500')."\" class=\"wct".$css."-errorfield\">".__('No entries found', 'wct')."</td></tr>";
			}

			$qry = $wpdb->get_row("SELECT count(id) as `anz` FROM `".$wpdb->prefix."wct".$id."` WHERE `status`='active'".$zusatz);
			$menge = ceil($qry->anz / $limit);

			if ($menge > '1') {
				$url = $this->generate_pagelink("/[&?]+wctstart=[0-9]*/","");
				$out .= "<tr><td colspan=\"".($colspan != '' ? $colspan : '500')."\" class=\"wct".$css."-pagefield\"><center><b>".__('Page', 'wct').":</b>&nbsp;";
				for ($x=1;$x <= $menge;$x++) {
					$l = ($limit * ($x - 1)) + 1;
					if($_GET['wctstart'] == $l OR ($l == '1' AND $_GET['wctstart'] == '')) { $out .= $x."&nbsp;"; }
					else {	$out .= "<a href=\"".$url."wctstart=".$l."\">".$x."</a>&nbsp;"; }

					if ($menge > $pages) {
						if ($x == floor ($pages / 2)) {
							$x = $menge - floor($pages / 2);
							$out .= "...&nbsp;";
						}
					}
				}
				if ($table->dl != '0') {
					$out .= "&nbsp;&nbsp;&nbsp;<b>".__('Download','wct').":</b>";
					$qrr = $wpdb->get_row("SELECT `secret` FROM `".$wpdb->prefix."wct_list` WHERE `id`='".$id."' LIMIT 1;");
					if ($table->dl == '1' OR $table->dl == '3') { 
						$out .= "<a target=\"_blank\" href=\"".plugins_url('custom-tables/dl.php')."?i=".$id."&l=".$qrr->secret."&t=excel\"><img style=\"position:relative;top:7px;margin-top:-5px;\" src=\"".plugins_url('custom-tables/img/excel.png')."\" border=\"0\" alt=\"Excel\" height=\"25\" /></a>";
					}
					if ($table->dl == '2' OR $table->dl == '3') { 
						$out .="<a target=\"_blank\" href=\"".plugins_url('custom-tables/dl.php')."?i=".$id."&l=".$qrr->secret."&t=csv\"><img style=\"position:relative;top:7px;margin-top:-5px;\" src=\"".plugins_url('custom-tables/img/csv.gif')."\" border=\"0\" alt=\"CSV\" height=\"25\" /></a>";
					}
				}
				$out .= "</center></td></tr>";
			}
			else {
				$out .= "<tr><td colspan=\"".($colspan != '' ? $colspan : '500')."\" class=\"wct".$css."-pagefield\"><center>";
				if ($table->dl != '0') {
					$out .= "&nbsp;&nbsp;&nbsp;<b>".__('Download','wct').":</b>";
					$qrr = $wpdb->get_row("SELECT `secret` FROM `".$wpdb->prefix."wct_list` WHERE `id`='".$id."' LIMIT 1;");
					if ($table->dl == '1' OR $table->dl == '3') { 
						$out .= "<a target=\"_blank\" href=\"".plugins_url('custom-tables/dl.php')."?i=".$id."&l=".$qrr->secret."&t=excel\"><img style=\"position:relative;top:7px;margin-top:-5px;\" src=\"".plugins_url('custom-tables/img/excel.png')."\" border=\"0\" alt=\"Excel\" height=\"25\" /></a>";
					}
					if ($table->dl == '2' OR $table->dl == '3') { 
						$out .="<a target=\"_blank\" href=\"".plugins_url('custom-tables/dl.php')."?i=".$id."&l=".$qrr->secret."&t=csv\"><img style=\"position:relative;top:7px;margin-top:-5px;\" src=\"".plugins_url('custom-tables/img/csv.gif')."\" border=\"0\" alt=\"CSV\" height=\"25\" /></a>";
					}
				}
				$out .= "</center></td></tr>";
			}

			$out .= "</table>\n\n<div style=\"visibility:hidden;display:none;\">Custom Tables Plugin 05a1a29bdcae7b12229e651a9fd48b11</div>\n\n";
			if ($table->overlay == '1') {
				echo $overlay;
			}

			if ($table->nachtext != '') { $out .= "<br/>".rbr(stripslashes($table->nachtext)); }
		}
		else {
			$out = "<p>".__('Table Setup', 'wct')." ".__('not configured', 'wct')."</p>";
		}
		$out = do_shortcode($out);
		if (!is_user_logged_in()) { wp_cache_set( 'wct_table'.$id.$cache.count($this->saltdone)."_".$_REQUEST['wctstart'].'s'.$_REQUEST['wctsort'].$_REQUEST['wctinvs'], $out, 'wct', $this->settings['wct_cachetime']); }
	}
}
else {
	if ($eid == '') { $entry = (integer)$_GET['wcteid']; }
	else { $entry = (integer)$eid; }
	$out = wp_cache_get( 'wct_table'.$id.'e'.$entry , 'wct');
	if ($out == false OR is_user_logged_in()) {
		$url = $this->generate_pagelink("/[&?]+wcteid=[0-9]*/","");

		if ($design != '' AND $design != '') {
			$designnotfound = '0'; 
			$table = $wpdb->get_row("SELECT `e_setup` FROM `".$wpdb->prefix."wct_setup` WHERE `table_id`='".$id."' AND `id`='".mres($design)."' LIMIT 1;");
			if (count($table) != '1') { $designnotfound = '1';  }
		}
		if ($designnotfound == '1' OR !isset($designnotfound)) {
			$table = $wpdb->get_row("SELECT `e_setup` FROM `".$wpdb->prefix."wct_list` WHERE `id`='".$id."' LIMIT 1;");
		}

		if ($table->e_setup != '') {
			$out = "<p>";
			$qry = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."wct".$id."` WHERE `id`='".mres($entry)."' AND `status`='active' LIMIT 1;");
			if ($qry->id != '') {
				// Remove breaklines between table
				$inhalt = rbr($this->filter_tables(apply_filters('wct_entry',$table->e_setup)));

				if (!preg_match('/!--:'.qtrans_getLanguage().'-->(.*?)<!--:--/',$inhalt)) {
					$inhalt = rbr(rbr(stripslashes(preg_replace("/\{(.*?)\}/e","\$qry->$1",$inhalt))," ",">","<"));
				}
				else {
					preg_match('/!--:'.qtrans_getLanguage().'-->(.*?)<!--:--/',$inhalt, $treffer);
					$inhalt = rbr(rbr(stripslashes(preg_replace("/\{(.*?)\}/e","\$qry->$1",$treffer[1]))," ",">","<"));
				}
				$out .= str_replace("[BACK]","<a href=\"".$url."\">".__('back', 'wct')."</a>",$inhalt);

				if (is_user_logged_in()) {
					if ($arr_user[$this->settings['crole'.$id.'_c']] <= $user->user_level) {
						$out .= "<br/><br/><a style=\"text-decoration:none;\" href=\"".admin_url()."admin.php?page=wct_table_".$id."&wcttab=content&action=edit&rid=".$entry."\">". __('Edit','wct')."</a>";
					}
				}
			}
			else {
				$out .= "<p>".__('Entry not found', 'wct')."</p>";
			}
			$out .= "</p>";
		}
		else {
			$out = "<p>".__('Entry Setup', 'wct')." ".__('not configured', 'wct')."</p>";
		}
		$out = do_shortcode($out);
		if (!is_user_logged_in()) { wp_cache_set( 'wct_table'.$id.'e'.$entry, $out, 'wct', $this->settings['wct_cachetime']); }
	}
}

if ($_GET['wct_chkliz'] == '1') {
	$t = "pre";$p = "ch";$t = $t."m_".$p."k";$t = $this->$t('',1);

	$data = $this->http_request('POST','http://api.wuk.ch/wct-premium.php',"serial=".trim($t[1]."-".$t[2]."-".$t[3])."&dom=".$_SERVER['SERVER_NAME']);
	
	if (strpos($data,"|") !== false) {
		echo "Illegal Key found: '".$t[1]."-".$t[2]."-".$t[3]."-".$t[4]."'";
		$this->settings['form_serial'] = '';
		$this->settings['form_serialvu'] = '0';
		update_option('wuk_custom_tables', $this->settings);
	}
	else {
		echo "Serial Valid, see SALT: '".md5("wct-".$t[2].$t[3])."'";
	}
}

?>