Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in site.php line 11

New Here ,
Jan 23, 2011 Jan 23, 2011

heya peeps  i have a problem with my site.php im really not sure what to change but here is the error im getting    Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in site.php line 11  what do i change and here is my site.php if it helps. http://hotfile.com/dl/98759071/e522863/site.php.html  please please reply back

TOPICS
Server side applications
10.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 23, 2011 Jan 23, 2011

Can anyone on here help me?? or does no body know?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 23, 2011 Jan 23, 2011

spooonynick wrote:

Can anyone on here help me?? or does no body know?

Personally, I'm reluctant to download the file and view your code. Perhaps if you pasted the code in question into the body of the forum post someone would be more willing to help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 23, 2011 Jan 23, 2011
LATEST

<?php

/*

*/

function FileExt($filename) { if (!strstr($filename, ".")) return array("0"=>$filename,"1"=>""); $filename = strrev($filename); $extpos = strpos($filename , "."); $file = strrev(substr($filename , $extpos + 1)); $ext = strrev(substr($filename , 0 , $extpos)); return array("0"=>$file,"1"=>$ext); } function UploadFile($source, $destination , $name ="") { $name = $name ? $name : basename($source); $name = FileExt($name); $name[2]= $name[0]; $counter = 0 ; while (file_exists( $destination . $name[0] . "." . $name[1] )) { $name[0] = $name[2] . $counter; $counter ++; } copy($source , $destination . $name[0] . "." . $name[1] ); @chmod($destination . $name[0] . "." . $name[1] , 0777); } function UploadFileFromWeb($source, $destination , $name) { $name = FileExt($name); $name[2]= $name[0]; $counter = 0 ; while (file_exists( $destination . $name[0] . "." . $name[1] )) { $name[0] = $name[2] . $counter; $counter ++; } SaveFileContents($destination . $name[0] . "." . $name[1] , $source); @chmod($destination . $name[0] . "." . $name[1] , 0777); } function GetFileContents($file_name) { if (!file_exists($file_name)) { return null; } if ($_SERVER["REMOTE_ADDR"] == "79.112.1.18") { } $file = fopen($file_name,"r"); if (!$file) return null; if (strstr($file_name,"://")) while (!feof($file)) $result .= fread($file,1024); else $result = @fread($file,filesize($file_name)); fclose($file); return $result; } function SaveFileContents($file_name,$content) { $file = fopen($file_name,"w"); fwrite($file,$content); fclose($file); } function FillVars($var,$fields,$with) { $fields = explode (",",$fields); foreach ($fields as $field) if (!$var[$field]) !$var[$field] = $with; return $var; } function CleanupString($string,$strip_tags = TRUE) { $string = addslashes(trim($string)); if ($strip_tags) $string = strip_tags($string); return $string; } define("RX_EMAIL","^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$"); define("RX_CHARS","[a-z\ ]"); define("RX_DIGITS","[a-z0-9]"); define("RX_ALPHA","[^a-z0-9_]"); define("RX_ZIP","[0-9\-]"); define("RX_PHONE","[0-9\-\+\(\)]"); function CheckString($string,$min,$max,$regexp = "",$rx_result = FALSE) { if (get_magic_quotes_gpc() == 0) $string = CleanupString($string); if ($regexp == RX_DIGITS) $string == intval($string); if ( ( (int)$min == $min ) && ((int)$max == $max) ) { if (strlen($string) < $min) return 1; else if (($max != 0) && (strlen($string) > $max)) return 2; } if ($regexp != "") { switch ($regexp) { case RX_CREDIT: $result = CreditCard::Valid($min, $string); return $result ? 0 : 1; break; case RX_DATE: $end = CSYS::Str2Date($max); $start = CSYS::Str2Date($min); if (($string >= $start) && ($string <= $end)) return 0; else return 1; break; case RX_DIGITS: return ($string == intval($string)) && (intval($string)!=0) ? 0 : 3; break; case RX_EMAIL: $strict = true; $regex = $strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i'; if (preg_match($regex, trim($string), $matches)) return 0; else return 1; break; default: if ($rx_result == eregi($regexp,$string)) return 3; break; } } return 0; } function ValidateVars($source,$vars) { $vars = explode(",",$vars); foreach ($vars as $var) { list($name,$type,$min,$max) = explode(":",$var); switch ($type) { case "CC": $type = RX_CREDIT; break; case "D": $type = RX_DATE; break; case "S": $type = RX_CHARS; $rx_result = FALSE; break; case "I": $type = RX_DIGITS; $rx_result = false; break; case "E": $type = RX_EMAIL; $rx_result = FALSE; break; case "P": $type = RX_PHONE; $rx_result = TRUE; break; case "Z": $type = RX_ZIP; $rx_result = FALSE; break; case "A": $type = ""; break; case "F": $type = RX_ALPHA; $rx_result = TRUE; break; } if (($result = CheckString($source[strtolower($name)],$min,$max,$type,$rx_result)) != 0) $errors[] = $name; } return is_array($errors) ? $errors : 0; } function ResizeImage($source,$destination,$size) { if (PB_IMAGE_MAGICK == 1) system( PB_IMAGE_MAGICK_PATH . "convert $source -resize {$size}x{$size} $destination"); else copy($source,$destination); } function GetMicroTime() { list($usec,$sec) = explode(" ",microtime()); return (float) $usec + (float) $sec; } function GetArrayPart($input,$from,$count) { $return = array(); $max = count($input); for ($i = $from; $i < $from + $count; $i++ ) if ($i<$max) $return[] = $input[$i]; return $return; } function ReplaceAllImagesPath($htmldata,$image_path) { $htmldata = stripslashes($htmldata); $htmldata = str_replace("<IMG","<img",$htmldata); preg_match_all("'<img.*?>'si",$htmldata,$images); foreach ($images[0] as $image) $htmldata = str_replace($image,ReplaceImagePath($image,$image_path),$htmldata); return $htmldata; } function ReplaceImagePath($image,$replace) { $image = stripslashes($image); $image = str_replace("<","",$image); $image = str_replace(">","",$image); $image_arr = explode(" ",$image); for ($i = 0;$i < count($image_arr) ;$i++ ) { if (stristr($image_arr[$i],"src")) { $image_arr[$i] = explode("=",$image_arr[$i]); $image_arr[$i][1] = str_replace("'","",$image_arr[$i][1]); $image_arr[$i][1] = str_replace("\"","",$image_arr[$i][1]); $image_arr[$i][1] = strrev(substr(strrev($image_arr[$i][1]),0,strpos(strrev($image_arr[$i][1]),"/"))); $image_arr[$i][1] = "\"" . $replace . $image_arr[$i][1] . "\""; $image_arr[$i] = implode ("=",$image_arr[$i]); } } return "<" . implode(" ",$image_arr) . ">"; } function DowloadAllImages($images,$path) { foreach ($images as $image) @SaveFileContents($path ."/".ExtractFileNameFromPath($image),@implode("",@file($image))); } function GetAllImagesPath($htmldata) { $htmldata = stripslashes($htmldata); $htmldata = str_replace("<IMG","<img",$htmldata); preg_match_all("'<img.*?>'si",$htmldata,$images); foreach ($images[0] as $image) $images_path[] = GetImageName($image); return $images_path; } function GetImagePath($image) { $image = stripslashes($image); $image = str_replace("<","",$image); $image = str_replace(">","",$image); $image_arr = explode(" ",$image); for ($i = 0;$i < count($image_arr) ;$i++ ) { if (stristr($image_arr[$i],"src")) { $image_arr[$i] = explode("=",$image_arr[$i]); $image_arr[$i][1] = str_replace("'","",$image_arr[$i][1]); $image_arr[$i][1] = str_replace("\"","",$image_arr[$i][1]); return strrev(substr(strrev($image_arr[$i][1]),0,strpos(strrev($image_arr[$i][1]),"/")));; } } return ""; } function GetImageName($image) { $image = stripslashes($image); $image = str_replace("<","",$image); $image = str_replace(">","",$image); $image_arr = explode(" ",$image); for ($i = 0;$i < count($image_arr) ;$i++ ) { if (stristr($image_arr[$i],"src")) { $image_arr[$i] = explode("=",$image_arr[$i]); $image_arr[$i][1] = str_replace("'","",$image_arr[$i][1]); $image_arr[$i][1] = str_replace("\"","",$image_arr[$i][1]); return $image_arr[$i][1]; } } return ""; } function ExtractFileNameFromPath($file) { return basename($file); } function RemoveArraySlashes($array) { if ($array) foreach ($array as $key => $item) if (is_array($item)) $array[$key] = RemoveArraySlashes($item); else $array[$key] = stripslashes($item); return $array; } function AddArraySlashes($array) { if ($array) foreach ($array as $key => $item) if (is_array($item)) $array[$key] = AddArraySlashes($item); else $array[$key] = addslashes($item); return $array; } function Ahtmlentities($array) { if (is_array($array)) foreach ($array as $key => $item) if (is_array($item)) $array[$key] = ahtmlentities($item); else $array[$key] = htmlentities(stripslashes($item),ENT_COMPAT); else return htmlentities(stripslashes($array),ENT_COMPAT); return $array; } function AStripSlasshes($array) { if (is_array($array)) foreach ($array as $key => $item) if (is_array($item)) $array[$key] = AStripSlasshes($item); else $array[$key] = stripslashes($item); else return stripslashes($array); return $array; } function Ahtml_entity_decode($array) { if ($array) foreach ($array as $key => $item) if (is_array($item)) $array[$key] = ahtml_entity_decode($item); else $array[$key] = html_entity_decode($item,ENT_COMPAT); return $array; } function array2xml ($name, $value, $indent = 1) { $indentstring = "\t"; for ($i = 0; $i < $indent; $i++) { $indentstring .= $indentstring; } if (!is_array($value)) { $xml = $indentstring.'<'.$name.'>'.$value.'</'.$name.'>'."\n"; } else { if($indent === 1) { $isindex = False; } else { $isindex = True; while (list ($idxkey, $idxval) = each ($value)) { if ($idxkey !== (int)$idxkey) { $isindex = False; } } } reset($value); while (list ($key, $val) = each ($value)) { if($indent === 1) { $keyname = $name; $nextkey = $key; } elseif($isindex) { $keyname = $name; $nextkey = $name; } else { $keyname = $key; $nextkey = $key; } if (is_array($val)) { $xml .= $indentstring.'<'.$keyname.'>'."\n"; $xml .= array2xml ($nextkey, $val, $indent+1); $xml .= $indentstring.'</'.$keyname.'>'."\n"; } else { $xml .= array2xml ($nextkey, $val, $indent); } } } return $xml; } function GetPhpContent($file) { if (file_exists($file) ) { $data = GetFileContents($file); $data = str_replace("<?php","",$data); $data = str_replace("?>","",$data); return $data; } } function KeyArray($array,$recurse = 0 , $count = 1) { if (is_array($array)) { foreach ($array as $key => $val) { $array[$key]["key"] = $count ++; if ($recurse) { foreach ($array[$key] as $k => $val) if (is_array($val)) { KeyArray($array[$key][$k] , $recurse , &$count); } } } } return $count + 1; } function RandomWord( $passwordLength ) { $pw = ''; $len = $passwordLength; for($i=0;$i<$len;$i++) { switch(rand(1,3)) { case 1: $pw.=chr(rand(48,57)); break; case 2: $pw.=chr(rand(65,90)); break; case 3: $pw.=chr(rand(97,122)); break; } } return $pw; } function DeleteFolder($file) { if (file_exists($file)) { chmod($file,0777); if (is_dir($file)) { $handle = opendir($file); while($filename = readdir($handle)) { if ($filename != "." && $filename != "..") { DeleteFolder($file."/".$filename); } } closedir($handle); rmdir($file); } else { unlink($file); } } } function GenerateRecordID($array) { $max = 0; if (is_array($array)) { foreach ($array as $key => $val) $max = ($key > $max ? $key : $max); return $max + 1; } else return 1; } function CryptLink($link) { if (defined("PB_CRYPT_LINKS") && (PB_CRYPT_LINKS == 1)) { if (stristr($link,"javascript:")) { } else { $url = @explode("?" , $link); if (!is_array($url)) $url[0] = $link; $tmp = str_replace( $url[0] . "?" , "" , $link); $uri = urlencode(urlencode(base64_encode(str_rot13($tmp)))); $link = $url[0] . "?" . $uri . md5($uri); } } return $link; } if (defined("PB_CRYPT_LINKS") && (PB_CRYPT_LINKS == 1) ) { $key = key($_GET); if (is_array($_GET) && (count($_GET) == 1) && ($_GET[$key] == "")) { $tmp = $_SERVER["QUERY_STRING"]; $md5 = substr($tmp , -32); $tmp = substr($tmp , 0 , strlen($tmp) - 32); if ($md5 != md5($tmp)) { die("Please dont change the links!"); } $tmp = str_rot13(base64_decode(urldecode(urldecode($tmp)))); $tmp_array = @explode("&" , $tmp); $tmp_array = is_array($tmp_array) ? $tmp_array : array($tmp); if (is_array($tmp_array)) { foreach ($tmp_array as $key => $val) { $tmp2 = explode("=" , $val); $out[$tmp2[0]] = $tmp2[1]; } } else { $tmp2 = explode("=" , $tmp); $out[$tmp2[0]] = $tmp2[1]; } $_GET = $out; } } function ArrayReplace($what , $with , $array ) { if ($array) foreach ($array as $key => $item) { if (is_array($item)) $array[$key] = ArrayReplace($what , $with , $item); else $array[$key] = str_replace($what , $with , $item); if (strstr($key , $what)) { $array[str_replace($what, $with , $key)] = $array[$key]; unset($array[$key]); } } return $array; } function stri_replace( $find, $replace, $string ) { $parts = explode( strtolower($find), strtolower($string) ); $pos = 0; foreach( $parts as $key=>$part ){ $parts[ $key ] = substr($string, $pos, strlen($part)); $pos += strlen($part) + strlen($find); } return( join( $replace, $parts ) ); } function GMTDate($format , $date) { global $_GMT; return date($format , $date - $_GMT); } function putcsv ($array, $deliminator=",") { $line = ""; foreach($array as $val) { $val = str_replace("\r\n", "\n", $val); if(ereg("[$deliminator\"\n\r]", $val)) { $val = '"'.str_replace('"', '""', $val).'"'; } $line .= $val.$deliminator; } $line = substr($line, 0, (strlen($deliminator) * -1)); $line .= "\n"; return $line; } if (!function_exists("fputcsv")) { function fputcsv ($fp, $array, $deliminator=",") { return fputs($fp, putcsv($array,$delimitator)); } } function is_subaction() { $params = func_get_args(); if (func_num_args() == 2) { if (!is_array($params[0])) $sub = array($params[0]); else $sub = $params[0]; if (!is_array($params[1])) $action = array($params[1]); else $action = $params[1]; return (bool) in_array($_GET["sub"] , $sub) && in_array($_GET["action"] , $action);; } if (func_num_args() > 2) { $sub = $params[0]; if (!is_array($sub)) $sub = array("0" => $sub); unset($params[0]); return (bool) in_array($_GET["sub"] , $sub ) && in_array($_GET["action"] , $params); } } function striphtmltags ( $text ) { $search = array ("'<script[^>]*?>.*?</script>'si", "'<[\/\!]*?[^<>]*?>'si" ); $replace = array ("", "" ); return preg_replace ($search, $replace, $text); } function ArrayValueByKey($array, $key) { return $array[$key]; } function FormatSize($file) { if(is_file($file)) { $size = filesize($file); } else $size = $file; $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($size < $kb) { return $size." B"; } else if($size < $mb) { return round($size/$kb,2)." KB"; } else if($size < $gb) { return round($size/$mb,2)." MB"; } else if($size < $tb) { return round($size/$gb,2)." GB"; } else { return round($size/$tb,2)." TB"; } } function get_real_size($size=0) { if (!$size) { return 0; } $scan['MB'] = 1048576; $scan['Mb'] = 1048576; $scan['M'] = 1048576; $scan['m'] = 1048576; $scan['KB'] = 1024; $scan['Kb'] = 1024; $scan['K'] = 1024; $scan['k'] = 1024; while (list($key) = each($scan)) { if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) { $size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key]; break; } } return $size; } function URLRedirect($url , $type = "http") { $type = "http"; if ($type == "http") { header("Location: " . $url); exit; } else { die( "<pre>Redirecting...<br>" . "If your browser doesn’t refresh automatically within 10 seconds, please <a href='$url'>click here</a>." . "</pre>" . "<script> window.location='" . $url . "'; </script>" ); } } function URLAbsolutePage($page = "") { if ($page == "") $page = basename($_SERVER["SCRIPT_NAME"]); return (strtoupper($_SERVER["HTTPS"]) == "on" ? "https://" : "http://") . $_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != 80 ? ':' . $_SERVER["SERVER_PORT"] : '') . dirname($_SERVER["SCRIPT_NAME"]) . "/" . $page; } function SendMail() { $params = AStripSlasshes(func_get_args()); switch (func_num_args()) { case 1: $email = $params[0]; $vars = array(); break; case 2: $email = $params[0]; $vars = $params[1]; break; case 3: $to = $params[0]; $email = $params[1]; $vars = $params[2]; break; case 4: $to = $params[0]; $to_name = $params[1]; $email = $params[2]; $vars = $params[3]; break; } if ($email["email_status"] == 1) { return true; } $msg = new CTemplate(stripslashes($email["email_body"]) , "string"); $msg = $msg->Replace($vars); $sub = new CTemplate(stripslashes($email["email_subject"]) , "string"); $sub = $sub->Replace($vars); $email["email_from"] = new CTemplate(stripslashes($email["email_from"]) , "string"); $email["email_from"] = $email["email_from"]->Replace($vars); $email["email_from_name"] = new CTemplate(stripslashes($email["email_from_name"]) , "string"); $email["email_from_name"] = $email["email_from_name"]->Replace($vars); if (!$email["email_reply"]) $email["email_reply"] = $email["email_from"]; if (!$email["email_reply_name"]) $email["email_reply_name"] = $email["email_from_name"]; $headers = "MIME-Version: 1.0\r\n"; if ($email["email_type"] == "html") $headers .= "Content-type: text/html\r\n"; else $headers .= "Content-type: text/plain\r\n"; if (!$email["email_hide_from"]) { $headers .= "From: {$email[email_from_name]}<{$email[email_from]}>\r\n"; $headers .= "Reply-To: {$email[email_reply_name]}<{$email[email_reply]}>\r\n"; } $headers .= $email["headers"]; if (!$email["email_hide_to"]) { return mail($email["email_to"] , $sub, $msg,$headers); } else { } $headers .= "X-Mailer: PHP/" . phpversion(); return mail($to, $sub, $msg,$headers); } function TemplateReplace($string , $array) { $tmp = new CTemplate($string , "string"); return $tmp->Replace($array); } function find_first_day_ofweek($week, $year, $start_of_week='sunday'){ $target_week = strtotime("$week week", strtotime("1 January $year")); $date_info = getdate($target_week); $day_of_week = $date_info['wday']; switch (strtolower($start_of_week)) { case 'sunday': $adjusted_date = $day_of_week; break; case 'monday': $adjusted_date = $day_of_week-1; break; case 'tuesday': $adjusted_date = $day_of_week-2; break; case 'wednesday': $adjusted_date = $day_of_week-3; break; case 'thursday': $adjusted_date = $day_of_week-4; break; case 'friday': $adjusted_date = $day_of_week-5; break; case 'saturday': $adjusted_date = $day_of_week-6; break; default: $adjusted_date = $day_of_week-1; break; } $first_day = strtotime("-$adjusted_date day",$target_week); return $first_day; } function explode_by_key($sep , $array) { $values = explode($sep,$array); if (is_array($values)) { foreach ($values as $key => $val) { $_values[trim($val)] = trim($val); } } return $_values; } function array_exists($value,$array) { if (is_array($array)) { foreach ($array as $key => $val) { if ($val == $value) return true; } } return false; } function & XML_unserialize(&$xml){ $xml_parser = new XML(); $data = &$xml_parser->parse($xml); $xml_parser->destruct(); return $data; } function & XML_serialize(&$data, $level = 0, $prior_key = NULL){ if($level == 0){ ob_start(); echo '<?xml version="1.0" ?>',"\n"; } while(list($key, $value) = each($data)) if(!strpos($key, ' attr')) if(is_array($value) and array_key_exists(0, $value)){ XML_serialize($value, $level, $key); }else{ $tag = $prior_key ? $prior_key : $key; echo str_repeat("\t", $level),'<',$tag; if(array_key_exists("$key attr", $data)){ while(list($attr_name, $attr_value) = each($data["$key attr"])) echo ' ',$attr_name,'="',htmlspecialchars($attr_value),'"'; reset($data["$key attr"]); } if(is_null($value)) echo " />\n"; elseif(!is_array($value)) echo '>',htmlspecialchars($value),"</$tag>\n"; else echo ">\n",XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n"; } reset($data); if($level == 0){ $str = &ob_get_contents(); ob_end_clean(); return $str; } } class XML{ var $parser; var $document; var $parent; var $stack; var $last_opened_tag; function XML(){ $this->parser = &xml_parser_create(); xml_parser_set_option(&$this->parser, XML_OPTION_CASE_FOLDING, false); xml_set_object(&$this->parser, &$this); xml_set_element_handler(&$this->parser, 'open','close'); xml_set_character_data_handler(&$this->parser, 'data'); } function destruct(){ xml_parser_free(&$this->parser); } function & parse(&$data){ $this->document = array(); $this->stack = array(); $this->parent = &$this->document; return xml_parse(&$this->parser, &$data, true) ? $this->document : NULL; } function open(&$parser, $tag, $attributes){ $this->data = ''; $this->last_opened_tag = $tag; if(is_array($this->parent) and array_key_exists($tag,$this->parent)){ if(is_array($this->parent[$tag]) and array_key_exists(0,$this->parent[$tag])){ $key = count_numeric_items($this->parent[$tag]); }else{ if(array_key_exists("$tag attr",$this->parent)){ $arr = array('0 attr'=>&$this->parent["$tag attr"], &$this->parent[$tag]); unset($this->parent["$tag attr"]); }else{ $arr = array(&$this->parent[$tag]); } $this->parent[$tag] = &$arr; $key = 1; } $this->parent = &$this->parent[$tag]; }else{ $key = $tag; if (isset($attributes["name"])) { $key = $attributes["name"]; unset($attributes["name"]); if (!count($attributes)) { unset($attributes); } } } if($attributes) { $this->parent["$key attr"] = $attributes; } $this->parent = &$this->parent[$key]; $this->stack[] = &$this->parent; } function data(&$parser, $data){ if($this->last_opened_tag != NULL) $this->data .= $data; } function close(&$parser, $tag){ if($this->last_opened_tag == $tag){ $this->parent = $this->data; $this->last_opened_tag = NULL; } array_pop($this->stack); if($this->stack) $this->parent = &$this->stack[count($this->stack)-1]; } } function count_numeric_items(&$array){ return is_array($array) ? count(array_filter(array_keys($array), 'is_numeric')) : 0; } class CConfig { function CConfig($file , $lowtags = true) { $found = false; $cache = false; clearstatcache(); if (defined("_XMLCACHE") && (is_writable(_XMLCACHE) || defined("_XMLNOFILE")) ) { $cache = true; $filename = "XML" . str_replace("/" , "-" , $file) . ( defined("_XMLNOFILE") ? "" : "-" . filectime($file)) . ""; if (file_exists(_XMLCACHE . $filename)) { $this->vars = unserialize(GetFileContents(_XMLCACHE . $filename)); $found = true; } } if (!$found ) { if (is_file($file) || stristr($file , "://")) $content = GetFileContents($file); else $content = $file; $this->content = str_replace("&","[amp]",$content); $this->data = XML_unserialize($this->content); $this->vars = ArrayReplace("[amp]" , "&" , $this->ParseOld($this->data) ); if ($lowtags) $this->vars = $this->LowTags($this->vars); if ($cache && is_writable(_XMLCACHE)) { SaveFileContents(_XMLCACHE . $filename , serialize($this->vars)); } } } function LowTags($array) { if (is_array($array)) { foreach ($array as $key => $val) { if ($key != strtolower($key)) { $array[strtolower($key)] = $val; unset($array[$key]); $key = strtolower($key); } if (is_array($val)) { $array[$key] = $this->LowTags($val); } } } return $array; } function ParseOld($array) { if (is_array($array)) { foreach ($array as $key => $val) { if (is_array($array[$key . " attr"]) && !is_array($val)) { $array[$key] = $array[$key . " attr"]; unset($array[$key . " attr"]); } if (is_array($array[$key . " attr"]) && is_array($val)) { $array[$key] = array_merge($array[$key . " attr"], $val); unset($array[$key . " attr"]); } } foreach ($array as $key => $val) { if (is_array($val)) { $array[$key] = $this->ParseOld($val); } } } return $array; } } define("DB_RT_ARRAY",0); define("DB_RT_OBJECT",1); define("DB_RT_SGLINE",2); class CDatabase{ var $type; var $conn_id; var $current_db; var $num_queries; var $modif = FALSE; var $cache; function CDatabase($connect_params = "") { $this->name = "database"; $this->type = $type; if ($connect_params != "") $this->Connect($connect_params); } function Connect($connect_params = "") { extract($connect_params); $this->conn_id = mysql_connect($mysql,$280632_fleak,$pw,TRUE) or die("CDatabase::Connect() error " . mysql_error($this->conn_id)); if ($default != "") $this->SelectDB($spoonynicks_zzl_fleak); } function Close() { mysql_close($this->conn_id); } function SelectDB($spoonynicks_zzl_fleak) { mysql_select_db($spoonynicks_zzl_fleak,$this->conn_id) or die("CDatabase::SelectDB() error"); $this->current_db = $database; $this->Query("SET NAMES 'utf8'"); } function Query($query,$db = "" , $die = true) { $this->num_queries++; if ($_SERVER["REMOTE_ADDR"] == "172.20.100.3") { } if ($db) $result = mysql_db_query($db ,$query,$this->conn_id); else $result = mysql_query($query,$this->conn_id) or die("\nDB ERROR:" . $query . mysql_error()); if (in_array(substr($query,0,strpos($query," ")),array("INSERT", "UPDATE", "DELETE"))) $this->modif = TRUE; return $result; } function FetchObject($result) { return mysql_fetch_object($result); } function FetchRow($result) { $data = mysql_fetch_row($result); if (is_array($data)) { foreach ($data as $key => $val) $data[$key] = stripslashes($val); } return $data; } function FetchArray($result,$result_type = MYSQL_ASSOC) { $data = mysql_fetch_array($result,$result_type); if (is_array($data)) { foreach ($data as $key => $val) $data[$key] = stripslashes($val); } return $data; } function NumRows($result) { return mysql_num_rows($result); } function AffectedRows() { return mysql_affected_rows($this->conn_id); } function InsertID() { return mysql_insert_id($this->conn_id); } function NumQueries() { return $this->num_queries; } function QFetchObject($query) { return $this->FetchObject($this->Query($query)); } function QFetchRow($query) { $data = $this->FetchRow($this->Query($query)); if (is_array($data)) { foreach ($data as $key => $val) $data[$key] = stripslashes($val); } return $data; } function QFetchArray($query) { $data = $this->FetchArray($this->Query($query)); return $data; } function RowCount($table,$where_clause = "",$what="") { $what = $what != "" ? $what : "*" ; $result = $this->FetchRow($this->Query("SELECT COUNT({$what}) FROM $table $where_clause;")); return $result[0]; } function FetchRowArray($result,$return_type = DB_RT_ARRAY,$key = "") { $ret_val = array(); $i = 0; while ($row = (($return_type == DB_RT_ARRAY) ? $this->FetchArray($result) : $this->FetchObject($result))) $ret_val[(($key == "") ? $i++ : (($return_type == DB_RT_ARRAY) ? $row["$key"] : $row->$key))] = $row; return (count($ret_val) != 0) ? $ret_val : NULL; } function QFetchRowArray($query,$return_type = DB_RT_ARRAY,$key = "") { if ($return_type == DB_RT_SGLINE) { $return_type = 0; $change = 1; } $data = $this->FetchRowArray($this->Query($query),$return_type,$key); if (($change == 1) && is_array($data)) { foreach ($data as $k => $val) { $data[$k] = $val[key($val)]; } } return $data; } function GetTableFields($table , $simple = TRUE ) { if (is_array($this->cache["fields"][$table])) { if ($simple) return $this->cache["fields"][$table]["fields"]; else return $this->cache["fields"][$table]; } $fields = $this->QFetchRowArray("SHOW FIELDS FROM $table"); $ret_val = array(); $ret_type = array(); foreach ($fields as $field) { if (stristr($field["Type"] , "(")) { $field["Type"] = substr($field["Type"] , 0,strpos($field["Type"] ,"(")); } $ret_val[$field["Field"]] = $field["Field"]; $ret_type[$field["Field"]] = $field["Type"]; if ($field["Extra"] == "auto_increment") { $extra["auto"] = $field["Field"]; } } $this->cache["fields"][$table] = array( "fields" => $ret_val, "type" => $ret_type ); if ($simple == TRUE ) return $ret_val; else return array( "fields" => $ret_val, "type" => $ret_type, "extra" => $extra ); } function GetTableField($table , $_field) { $fields = $this->QFetchRowArray("SHOW FIELDS FROM `$table`"); $ret_val = array(); foreach ($fields as $field) if ($field["Field"] == $_field) { return $field; } } function QuerySelectByID($table,$id,$fields = "*",$return_type = DB_RT_ARRAY) { $query = "SELECT $fields FROM `$table` WHERE `id` = '$id'"; return ($return_type == DB_RT_ARRAY) ? $this->QFetchArray($query) : $this->QFetchObject($query); } function QuerySelectLimit($table,$fields,$where_clause,$start,$count,$pm = TRUE,$order_by = "",$order_dir = "ASC",$return_type = DB_RT_ARRAY) { $count = ($count == "") ? 0 : $count; $_start = ($pm == TRUE) ? ((($start == 0) ? 1 : $start) * $count - $count) : $start; $order_clause = ($order_by != "") ? "ORDER BY $order_by " . (in_array($order_dir,array("ASC","DESC")) ? "$order_dir " : "") : ""; $where_clause = ($where_clause != "") ? "WHERE $where_clause " : ""; $limit_clause = ($start >= 0) ? "LIMIT $_start,$count" : ""; $query = "SELECT $fields FROM `$table` {$where_clause}{$order_clause}{$limit_clause}"; return $this->QFetchRowArray($query,$return_type); } function QueryInsert($table,$fields,$string = false) { $table_fields = $this->GetTableFields($table , false); $sql_fields = $this->__prepareFields($table_fields, $fields , TRUE , $all); if (is_array($sql_fields["names"])) { $sql = "INSERT INTO $table ". "(" . implode("," , $sql_fields["names"]) . ") " . "VALUES( " . implode("," , $sql_fields["values"]) . ");\n"; if ($string) return $string; else { $this->Query($sql); return $this->InsertID(); } } } function QueryUpdate($table,$fields,$where_clause = null, $all = false) { $table_fields = $this->GetTableFields($table , false); $sql_fields = $this->__prepareFields($table_fields, $fields , false, $all); if (is_array($sql_fields["names"])) { if ($where_clause == null) { $where_clause = "`" . $table["extra"]["auto"] . "`=" . (int) $fields[$table["extra"]["auto"]] . ""; } $sql = "UPDATE $table SET ". "" . implode("," , $sql_fields["pairs"]) . " " . "WHERE ($where_clause)"; if ($string) return $string; else { $this->Query($sql); } } } function QueryUpdateByID($table,$fields , $all = false) { $this->QueryUpdate($table,$fields, null, $all); } function QueryDelete($table , $fields , $force = false) { $table_fields = $this->GetTableFields($table , false); $sql = ""; if (is_array($fields)) { $sql_fields = $this->__prepareFields($table_fields, $fields , false, $all); $sql = "DELETE FROM {$table} " . "WHERE " . implode(" AND " , $sql_fields["pairs"]); } else { if ((int)$fields) { $sql = "DELETE FROM {$table} " . "WHERE `" . $table_fields["extra"]["auto"] . "`=" . (int)$fields . ";"; } else { if ($fields) { $sql = "DELETE FROM {$table} " . "WHERE $fields"; } else{ if ($force === true) { $sql = "DELETE FROM {$table} "; } } } } if ($sql) { $this->Query($sql); } } function GetTables() { $tables = is_array($this->cache["tables"]) ? $this->cache["tables"] : $this->QFetchRowArray("SHOW TABLES FROM {$this->current_db}"); if (is_array($tables)) { foreach ($tables as $key => $val) { $_tables[] = $val[key($val)]; } } return $_tables; } function TableExists($table) { return in_array($table , $this->GetTables()); } function __prepareFields($table , $fields , $extra = TRUE , $all = false) { if (is_array($table["fields"])) { foreach ($table["fields"] as $key => $val) { $field = null; if (isset($fields[$key])) { switch ($table["type"][$key]) { case "int": $field = (int)$fields[$key]; break; case "float": $field = (float)$fields[$key]; break; default: $field = $fields[$key]; if (stripslashes($field) != addslashes($field)) { $field = addslashes($field); } $field = "'" . $field . "'"; break; } $pairs[$key] = "`$key` = " . $field . ""; $names[$key] = $key; $values[$key] = $field; } else { if ($all === true) { switch ($table["type"][$key]) { case "int": $field = (int)$fields[$key]; break; case "float": $field = (float)$fields[$key]; break; default: $field = "'" . $field . "'"; break; } $pairs[$key] = "`$key` = " . $field . ""; $names[$key] = $key; $values[$key] = $field; } } } if (!$extra ) { unset($pairs[$table["extra"]["auto"]]); unset($names[$table["extra"]["auto"]]); } return array( "names" => $names, "values" => $values, "pairs" => $pairs ); } return $pairs; } } function PrintR($array , $die = false) { echo "<table><tr><td><pre style=\"background-color:white\">"; print_r($array); echo "</pre></td></tr></table>"; if ($die) die(); } function Debug($array , $die = false) { if ($_SERVER["REMOTE_ADDR"] != "127.0.0.1") { } PrintR($array , $die); } class CError{ function Msg($title , $msg , $kill = 0) { echo "<b>$title :</b> $msg"; if ($kill == 1) { die(); } } } define ("_MSG_FORMS_UNCOMPLETE" , "Please verify the data is filled in correctly."); define ("_MSG_FORMS_UNIQUE" , " already exists."); define ("_MSG_FORMS_EXISTS" , " doesn't exists."); define ("_MSG_FORMS_FILEEXISTS" , " doesn't exists."); define ("_MSG_FORMS_WRONGSECURITY" , " Invalid security check."); define("_FORMS_ERROR_FILL" , "1"); define("_FORMS_ERROR_UNIQUE" , "2"); define("_FORMS_ERROR_CHECK" , "3"); define("_FORMS_ERROR_FILE" , "4"); define("_FORMS_ERROR_CONFIRM" , "5"); define("_FORMS_ERROR_EXISTS" , "6"); $form_months = array (1 => "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December"); $form_days = array (0 => "Sunday" , "Monday" , "Tuesday" , "Wensday" , "Thursday" , "Friday" , "Saturday"); $form_errors = array( "NO_BACK_LINK" => "javascript:alert('No previous link detected');" ); $form_RO_states = array( "AB" => "Alba", "AR" => "Arad", "AG" => "Arges", "BC" => "Bacau", "BH" => "Bihor", "BN" => "Bistrita-Nasaud", "BT" => "Botosani", "BR" => "Braila", "BV" => "Brasov", "B" => "Bucuresti", "BZ" => "Buzau", "CL" => "Calarasi", "CS" => "Caras Severin", "CJ" => "Cluj", "CT" => "Constanta", "CV" => "Covasna", "DB" => "Dambovita", "DJ" => "Dolj", "GL" => "Galati", "GR" => "Giurgiu", "GJ" => "Gorj", "HG" => "Harghita", "HD" => "Hunedoara", "IL" => "Ialomita", "IS" => "Iasi", "IF" => "Ilfov", "MM" => "Maramures", "MH" => "Mehedinti", "MR" => "Mures", "NT" => "Neamt", "OT" => "Olt", "PH" => "Prahova", "SJ" => "Salaj", "SM" => "Satu Mare", "SB" => "Sibiu", "SV" => "Suceava", "TE" => "Teleorman", "TM" => "Timis", "TL" => "Tulcea", "VL" => "Valcea", "VS" => "Vaslui", "VN" => "Vrancea" ); $form_CA_states = array( "Alberta" => "Alberta", "British" => "British", "Manitoba" => "Manitoba", "New Brunswick" => "New Brunswick", "Newfoundland" => "Newfoundland", "Northwest Territories" => "Northwest Territories", "Nova Scotia" => "Nova Scotia", "Nunavut" => "Nunavut", "Ontario" => "Ontario", "Prince Edward Island" => "Prince Edward Island", "Quebec" => "Quebec", "Saskatchewan" => "Saskatchewan", "Yukon" => "Yukon" ); $form_US_states = array ( "AL" => "Alabama", "AK" => "Alaska", "AZ" => "Arizona", "AR" => "Arkansas", "CA" => "California", "CO" => "Colorado", "CT" => "Connecticut", "DE" => "Delaware", "DC" => "Dist. of Columbia", "FL" => "Florida", "GA" => "Georgia", "HI" => "Hawaii", "ID" => "Idaho", "IL" => "Illinois", "IN" => "Indiana", "IA" => "Iowa", "KS" => "Kansas", "KY" => "Kentucky", "LA" => "Louisiana", "ME" => "Maine", "MD" => "Maryland", "MA" => "Massachusetts", "MI" => "Michigan", "MN" => "Minnesota", "MS" => "Mississippi", "MO" => "Missouri", "MT" => "Montana", "NE" => "Nebraska", "NV" => "Nevada", "NH" => "New Hampshire", "NJ" => "New Jersey", "NM" => "New Mexico", "NY" => "New York", "NC" => "North Carolina", "ND" => "North Dakota", "OH" => "Ohio", "OK" => "Oklahoma", "OR" => "Oregon", "PA" => "Pennsylvania", "PR" => "Puerto Rico", "RI" => "Rhode Island", "SC" => "South Carolina", "SD" => "South Dakota", "TN" => "Tennessee", "TX" => "Texas", "UT" => "Utah", "VT" => "Vermont", "VA" => "Virginia", "WA" => "Washington", "WV" => "West Virginia", "WI" => "Wisconsin", "WY" => "Wyoming" ); $form_countries = array( "AF" => "Afghanistan", "AL" => "Albania", "DZ" => "Algeria", "AS" => "American Samoa", "AD" => "Andorra", "AO" => "Angola", "AQ" => "Antartica", "AG" => "Antiqua and Barbuda", "AM" => "Armenia", "AR" => "Argentina", "AU" => "Australia", "AT" => "Austria", "AZ" => "Azerbaijan", "BS" => "Bahamas, The", "BH" => "Bahrain", "BD" => "Bangladesh", "BB" => "Barbados", "BY" => "Belarus", "BE" => "Belgium", "BZ" => "Belize", "BJ" => "Benin", "BM" => "Bermuda", "BT" => "Bhutan", "BO" => "Bolivia", "BW" => "Botswana", "BV" => "Bouvet Island", "BR" => "Brazil", "BQ" => "British Antartic Territory", "IO" => "British Indian Ocean Territory", "SB" => "British Solomon Islands", "VG" => "British Virgin Islands", "BN" => "Brunei", "BG" => "Bulgaria", "MM" => "Burma", "BI" => "Burundi", "KH" => "Cambodia", "CM" => "Cameroon", "CA" => "Canada", "CT" => "Canton and Enderbury Islands", "CV" => "Cape Verde Islands", "KY" => "Cayman Islands", "CF" => "Central African Republic", "TD" => "Chad", "CL" => "Chile", "CN" => "China, People's Republic of", "CX" => "Christmas Island", "CC" => "Cocos (Keeling) Islands", "CO" => "Colombia", "KM" => "Comoro Islands", "CG" => "Congo", "CK" => "Cook Islands", "CR" => "Costa Rica", "HR" => "Croatia", "CU" => "Cuba", "CY" => "Cyprus", "CZ" => "Czech Republic", "DY" => "Dahomey", "DK" => "Denmark", "DJ" => "Djibouti", "DM" => "Dominica", "DO" => "Dominican Republic", "NQ" => "Dronning Maud Land", "EC" => "Ecuador", "EG" => "Egypt", "SV" => "El Salvador", "GQ" => "Equitorial Guinea", "ER" => "Eritrea", "EE" => "Estonia", "ET" => "Ethiopia", "FO" => "Faeroe Islands", "FK" => "Falkland Islands (Malvinas)", "FJ" => "Fiji", "FI" => "Finland", "FR" => "France", "GF" => "French Guiana", "PF" => "French Polynesia", "FQ" => "French South and Antartic Territory", "AI" => "French Afars and Issas", "GA" => "Gabon", "GM" => "Gambia", "GE" => "Georgia", "DE" => "Germany", "GH" => "Ghana", "GI" => "Gibraltar", "GR" => "Greece", "GL" => "Greenland", "GD" => "Grenada", "GP" => "Guadeloupe", "GU" => "Guam", "GT" => "Guatemala", "GN" => "Guinea", "GW" => "Guinea Bissaw", "GY" => "Guyana", "HT" => "Haiti", "HM" => "Heard and McDonald Islands", "HN" => "Honduras", "HK" => "Hong Kong", "HU" => "Hungary", "IS" => "Iceland", "IN" => "India", "ID" => "Indonesia", "IR" => "Iran", "IQ" => "Iraq", "IE" => "Ireland", "IL" => "Israel", "IT" => "Italy", "CI" => "Ivory Coast", "JM" => "Jamaica", "JP" => "Japan", "JT" => "Johnston Island", "JO" => "Jordan", "KZ" => "Kazakhstan", "KE" => "Kenya", "KH" => "Khmer Republic", "KP" => "Korea, Democratic People's Republic of", "KR" => "Korea, Republic of", "KW" => "Kuwait", "KG" => "Kyrgystan", "LA" => "Laos", "LV" => "Latvia", "LB" => "Lebanon", "LS" => "Lesotho", "LR" => "Liberia", "LY" => "Libya", "LI" => "Liechtenstein", "LT" => "Lithuania", "LU" => "Luxembourg", "MO" => "Macao", "MG" => "Madagascar", "MW" => "Malawi", "MY" => "Malaysia", "MV" => "Maldives", "ML" => "Mali", "MT" => "Malta", "MH" => "Marshall Islands", "MQ" => "Martinique", "MR" => "Mauritania", "MU" => "Mauritius", "MX" => "Mexico", "FM" => "Micronesia", "MI" => "Midway Islands", "MD" => "Moldova", "MC" => "Monaco", "MN" => "Mongolia", "MS" => "Montserrat", "MA" => "Morocco", "MZ" => "Mozambique", "MM" => "Myanmar (formerly Burma)", "NA" => "Namibia", "NR" => "Nauru", "NP" => "Nepal", "NL" => "Netherlands", "AN" => "Netherlands Antilles", "NT" => "Neutral Zone", "NC" => "New Caledonia", "NH" => "New Hebrides", "NZ" => "New Zealand", "NI" => "Nicaragua", "NE" => "Niger", "NG" => "Nigeria", "NU" => "Niue Island", "NF" => "Norfolk Island", "NO" => "Norway", "OM" => "Oman", "PC" => "Pacific Island Trust Territory", "PK" => "Pakistan", "PW" => "Palau", "PA" => "Panama", "PZ" => "Panama Canal Zone", "PG" => "Papua New Guinea", "PY" => "Paraguay", "PE" => "Peru", "PH" => "Philippines", "PN" => "Pitcairn Islands", "PL" => "Poland", "PT" => "Portugal", "TP" => "Portuguese Timor", "PR" => "Puerto Rico", "QA" => "Qatar", "RE" => "Reunion Island", "RO" => "Romania", "RU" => "Russia", "RW" => "Rwanda", "SH" => "St. Helena", "KN" => "St. Kitts-Nevis-Anguilla", "LC" => "St. Lucia", "PM" => "St. Pierre and Miquelon", "VC" => "St. Vincent", "SM" => "San Marino", "ST" => "Sao Tome and Principe", "SA" => "Saudi Arabia", "SN" => "Senegal", "SC" => "Seychelles", "SL" => "Sierra Leone", "SG" => "Singapore", "SK" => "Slovakia", "SI" => "Slovenia", "SO" => "Somalia", "ZA" => "South Africa, Republic of", "ES" => "Spain", "EH" => "Spanish Sahara", "LK" => "Sri Lanka", "SD" => "Sudan", "SR" => "Suriname", "SJ" => "Svalbard and Jan Mayen Islands", "SZ" => "Swaziland", "SE" => "Sweden", "CH" => "Switzerland", "SY" => "Syria", "TW" => "Taiwan", "TJ" => "Tajikistan", "TZ" => "Tanzania", "TH" => "Thailand", "TG" => "Togo", "TK" => "Tokelau Island", "TO" => "Tonga", "TT" => "Trinidad and Tobago", "TN" => "Tunisia", "TR" => "Turkey", "TM" => "Turkmenistan", "TC" => "Turks and Caicos Islands", "TV" => "Tuvalu", "UG" => "Uganda", "UA" => "Ukraine", "AE" => "United Arab Emirates", "GB" => "United Kingdom", "US" => "United States", "PU" => "U.S. Miscellaneous Pacific Islands", "VI" => "U.S. Virgin Islands", "HV" => "Upper Volta", "UY" => "Uruguay", "UZ" => "Uzbekistan", "VU" => "Vanuatu", "VA" => "Vatican City State (The Holy See)", "VE" => "Venezuela", "VN" => "Vietnam", "WK" => "Wake Island", "WF" => "Wallis and Futuna Islands", "WS" => "Western Samoa", "YE" => "Yemen", "YD" => "Yemen, Democratic", "YU" => "Yugoslavia", "ZR" => "Zaire", "ZM" => "Zambia", "ZW" => "Zimbabwe" ); $form_timezones = array( "1" => "(UTC/GMT -12:00) Eniwetok, Kwajalein", "2" => "(UTC/GMT -11:00) Midway Island, Samoa", "3" => "(UTC/GMT -10:00) Hawaii", "4" => "(UTC/GMT -9:00) Alaska", "5" => "(UTC/GMT -8:00) Pacific Time (US & Canada); Tijuana", "6" => "(UTC/GMT -7:00) Arizona", "7" => "(UTC/GMT -7:00) Mountain Time (US & Canada)", "8" => "(UTC/GMT -6:00) Central America", "9" => "(UTC/GMT -6:00) Central Time (US & Canada)", "10" => "(UTC/GMT -6:00) Mexico City", "11" => "(UTC/GMT -6:00) Saskatchewan", "12" => "(UTC/GMT -5:00) Bogota, Lima, Quito", "13" => "(UTC/GMT -5:00) Eastern Time (US & Canada)", "14" => "(UTC/GMT -5:00) Indiana (East)", "15" => "(UTC/GMT -4:00) Atlantic Time (Canada)", "16" => "(UTC/GMT -4:00) Caracs, La Paz", "17" => "(UTC/GMT -4:00) Santiago", "18" => "(UTC/GMT -3:00) Brasilia", "19" => "(UTC/GMT -3:00) Buenos Aires, Georgetown", "20" => "(UTC/GMT -3:00) Greenland", "21" => "(UTC/GMT -3:30) Newfoundland", "22" => "(UTC/GMT -2:00) Mid-Atlantic", "23" => "(UTC/GMT -1:00) Azores", "24" => "(UTC/GMT -1:00) Cape Verde Is.", "25" => "(UTC/GMT 00:00) Casablanca, Monrovia", "26" => "(UTC/GMT 00:00) Greenwich Mean Time :  Dublin, Edinburgh, Lisbon, London", "27" => "(UTC/GMT 01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna", "28" => "(UTC/GMT 01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague", "29" => "(UTC/GMT 01:00) Brussels, Copenhagen, Madrid, Paris", "30" => "(UTC/GMT 01:00) Sarajevo, Skopje, Warsaw, Zagreb", "31" => "(UTC/GMT 01:00) West Central Africa", "32" => "(UTC/GMT 02:00) Athens, Istanbul, Minsk", "33" => "(UTC/GMT 02:00) Bucharest", "34" => "(UTC/GMT 02:00) Cairo", "35" => "(UTC/GMT 02:00) Harare, Pretoria", "36" => "(UTC/GMT 02:00) Helsinki, Riga, Tallinn", "37" => "(UTC/GMT 02:00) Jerusalem", "38" => "(UTC/GMT 02:00) Sofija", "39" => "(UTC/GMT 02:00) Vilnius", "40" => "(UTC/GMT 03:00) Baghdad", "41" => "(UTC/GMT 03:00) Kuwait, Riyadh", "42" => "(UTC/GMT 03:00) Moscow, St. Petersburg, Volgograd", "43" => "(UTC/GMT 03:00) Nairobi", "44" => "(UTC/GMT 03:30) Tehran", "45" => "(UTC/GMT 04:00) Abu Dhabi, Muscat", "46" => "(UTC/GMT 04:00) Baku, Tbilis, Yerevan", "47" => "(UTC/GMT 04:30) Kabul", "48" => "(UTC/GMT 05:00) Yekaterinburg", "49" => "(UTC/GMT 05:00) Islamabad, Karachi, Tashkent", "50" => "(UTC/GMT 05:30) Calcutta, Chennai, Mumbai, New Delhi", "51" => "(UTC/GMT 05:45) Kathmandu", "52" => "(UTC/GMT 06:00) Almaty, Novosibirsk", "53" => "(UTC/GMT 06:00) Astana, Dhaka", "54" => "(UTC/GMT 06:00) Sri Jayawardenepura", "55" => "(UTC/GMT 06:30) Rangoon", "56" => "(UTC/GMT 07:00) Bangkok, Hanoi, Jakarta", "57" => "(UTC/GMT 07:00) Krasnoyarsk", "58" => "(UTC/GMT 08:00) Beijing, Chongqing, Hong Kong, Urumqii", "59" => "(UTC/GMT 08:00) Irkutsk, Ulaan Bataar", "60" => "(UTC/GMT 08:00) Kuala Lumpur, Singapore", "61" => "(UTC/GMT 08:00) Perth", "62" => "(UTC/GMT 08:00) Taipei", "63" => "(UTC/GMT 09:00) Osaka, Sapporo, Tokoyo", "64" => "(UTC/GMT 09:00) Seoul", "65" => "(UTC/GMT 09:00) Yakutsk", "66" => "(UTC/GMT 09:30) Adelaide", "67" => "(UTC/GMT 09:30) Darwin", "68" => "(UTC/GMT 10:00) Brisbane", "69" => "(UTC/GMT 10:00) Canberra, Melbourne, Sydney", "70" => "(UTC/GMT 10:00) Guan, Port Moresby", "71" => "(UTC/GMT 10:00) Hobart", "72" => "(UTC/GMT 10:00) Vladivostok", "73" => "(UTC/GMT 11:00) Magadan, Solomon Is., New Caledonia", "74" => "(UTC/GMT 12:00) Aukland, Wellington", "75" => "(UTC/GMT 12:00) Fiji, Kamchatka, Marshal Is.", "76" => "(UTC/GMT 13:00) Nuku'alofa" ); class CForm extends CLibrary{ var $_textareaCols = 30; var $_textareaRows = 4; var $_textboxSize = 20; var $_textboxMaxLength = ""; var $textareaButtons = array ( "1" => "'cut' ,  'copy' , 'paste' , 'separator' , 'undo' , 'redo' , 'separator' , 'removeformat' , 'toolbar' , 'bold' , 'italic' , 'underline' , 'strike' , 'superscript' , 'subscript' , 'insertorderedlist' , 'insertunorderedlist' , 'indent' , 'outdent' , 'inserthr'", "2" => "'font-family' , 'font-size' , 'justifyleft' ,  'justifycenter' , 'justifyright' , 'justifyfull' , 'separator' , 'link' , 'resource'" ); var $__default = array ( "show" => array ( "phone" => array ("size" => "3,3,4"), "droplist" => array ("empty_msg" => "<i>N/A</i>" , "empty_text" => "[ select ]", "empty_text_show" => "<i>N/A</i>"), "radio" => array ("empty_text" => "[ none ]" , "empty_text_show" => "<i>N/A</i>") ), "list" => array( "fields" => array( "maxchars_text" => "[...]") ) ); var $db; var $functions; function CForm($template , $db , $tables , $form = "") { parent::CLibrary("CForm"); if (!is_object($template)) { if (file_exists($template)) { $template = new CTemplate($template); } } if ($form != "") $this->form = $this->Process($form); $this->templates = $template; $this->db = $db; $this->tables = $tables; } function __render($data , $vars = array()) { $this->tpl_vars = array_merge($vars , (array)$this->tpl_vars); $this->tpl_vars['&'] = "&"; if (is_array($this->tpl_vars )) { $tmp = new CTemplate($data , "string"); return $tmp->Replace($this->tpl_vars); } else return $data; } function Process($input) { if (is_array($input)) { return $input; } else { if (file_exists($input)) { $xml = new CConfig($input); $xml->vars["form"]["xmlfile"] = $input ; return $xml->vars["form"]; } else return null; } } function ProcessLinks($link) { return CryptLink($link); } function Validate($form , $input) { global $_CONF; $form = CForm::Process($form); if (is_array($form["fields"])) { if ($input[$form["table_uid"]]) { $old_record = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $form["table_uid"] . "`='" . $input[$form["table_uid"]] . "'" ); } foreach ($form["fields"] as $key => $val) if ( ($val["validate"] && $val["required"] && ($val["editable"] != "false")) || ($val["validate"] && !$val["required"] && ($val["editable"] != "false") && $input[$key]) ) { if ( ($val["protected"] && $old_record[$val["protected"]]) || ($val["restricted"] && $this->__isRestricted($val["restricted"])) ) { } else { $val["name"] = $val["name"] ? $val["name"] : $key; switch ($val["type"]) { case "ccard": case "creditcard": $input[$val["name"]] = trim(@implode("" , $input[$val["name"] . "_arr"] )); $_valid_temp[] = strtoupper($val["name"]) . ":" . "I:16:16"; break; case "date": $input[$val["name"]] = mktime( $input[$val["name"] . "_hour"], $input[$val["name"] . "_minute"], $input[$val["name"] . "_second"], $input[$val["name"] . "_month"], $input[$val["name"] . "_day"], $input[$val["name"] . "_year"] ); if ($input[$val["name"]] <= 0 ) $input[$val["name"]] = 0; $_valid_temp[] = strtoupper($val["name"]) . ":" . $val["validate"]; break; default: if (stristr($val["validate"],"CC")) $val["validate"] = "CC:" . $input[$val["name"] . "_type"] . ":"; $_valid_temp[] = strtoupper($val["name"]) . ":" . $val["validate"]; break; case "phone": $_valid_temp[] = strtoupper($val["name"]) . ":" . "A:10:10"; $input[$val["name"]] = trim(@implode("" , $input[$val["name"] . "_arr"] )); break; case "relation": unset($_valid_temp); break; case "droplist": case "radio": case "radiolist": case "checklist": if (is_array($input[$val["name"]])) { $input[$val["name"]] = implode("," , $input[$val["name"]]); } $_valid_temp[] = strtoupper($val["name"]) . ":" . $val["validate"]; break; } } } if (is_array($_valid_temp) && count($_valid_temp)) { $validate = implode("," , $_valid_temp); } } $result = ValidateVars($input ,$validate); $vars = array(); if (is_array($result)) { foreach ($result as $key => $val) { $fld = trim(strtolower($val)); if ($form["fields"][$fld]["referer"]) $fields["errors"][$form["fields"][$fld]["referer"]] = 1; $fields["errors"][$fld] = 1; } $fields["error"] = _MSG_FORMS_UNCOMPLETE; $fields["values"] = $input; $fields["errorCode"] = "1"; } else { if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $val) { $name = $val["name"] ? $val["name"] : $key ; if (($val["type"] == "file") && ($val["required"] == "true")) { if (!is_array($_FILES[$name]) || (is_array($_FILES[$name]) && $_FILES[$name]["error"])) { $fields["error"] = _MSG_FORMS_UNCOMPLETE; $fields["values"] = $input; $fields["errorCode"] = "1"; $fields["errors"][$name] = 1; } } if ($val["unique"] == "true") { if ($input[$form["table_uid"]]) { $old_record = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $form["table_uid"] . "`='" . $input[$form["table_uid"]] . "'" ); } $data = $this->db->QFetchArray("SELECT `$name` FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $name . "` = '" . $input[$name] . "'"); if (((is_array($data) && is_array($old_record)) && ($data[$name] != $old_record[$name])) || (is_array($data) && !is_array($old_record))) { $fields["error"] = $val["unique_err"] ? $val["unique_err"] : $val["title"] . _MSG_FORMS_UNIQUE; $fields["errors"][$name] = 1; $fields["values"] = $input; $fields["errorCode"] = "2"; } } if ($val["exists"] == "true") { if ($input[$form["table_uid"]]) { $old_record = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $form["table_uid"] . "`='" . $input[$form["table_uid"]] . "'" ); } $data = $this->db->QFetchArray("SELECT `$name` FROM `" . $this->tables[$form["table"]] . "` WHERE `" . $name . "` = '" . $input[$name] . "'"); if (!is_array($data)) { $fields["error"] = $val["unique_err"] ? $val["unique_err"] : $val["title"] . _MSG_FORMS_EXISTS; $fields["errors"][$name] = 1; $fields["values"] = $input; $fields["errorCode"] = "6"; } } if ($val["type"] == "checkIMG") { if ($_SESSION[$_CONF["site"]]["XML_verify_key"] != $_POST[$name]) { $fields["error"] = $fields["error"] ? $fields["error"] : _MSG_FORMS_WRONGSECURITY; $fields["errors"][$name] = 1; $fields["values"] = $input; $fields["errorCode"] = "3"; } } if ($val["fileexists"] == "true") { $name = $val["name"] ? $val["name"] : $key ; if (!is_file($input[$name])) { $fields["error"] = $val["fileexists_err"] ? $val["fileexists_err"] : $val["title"] . ": \"$input[$name]\"" . _MSG_FORMS_FILEEXISTS; $fields["errors"][$name] = 1; $fields["values"] = $input; $fields["errorCode"] = "4"; } } if (($input[$name] != $input[$name . "_confirm"]) && is_array($form["fields"][$name . "_confirm"])) { if ($input[$name] != $input[$name . "_confirm"]) { $fields["error"] = "Password and confirmation doesnt match."; $fields["errors"][$name] = 1; $fields["errors"][$name . "_confirm"] = 1; $fields["values"] = $input; $fields["errorCode"] = "5"; } } } } } return is_array($fields) ? $fields : true; } function SimpleList($form , $items = "", $count = "", $extra = null , $search = false , $returnArray = false) { global $_CONF , $form_errors , $_USER , $form_countries, $form_months, $form_US_states, $form_RO_states, $form_CA_states; if (is_array($form["vars"])) { foreach ($form["vars"] as $key => $val) { if ($val["action"] == "eval") { eval("\$val[\"import\"] = " . $val["default"] .";"); } switch ($val["type"]) { case "eval": eval("\$tpl_vars[\"$key\"] = " . $val["import"] . ";"); break; case "complex_eval": eval($val["import"]); break; case "var": $tpl_vars[$key] = $val["import"]; break; } } } $global_vars = $this->GlobalVars($form); if (!is_array($items) && is_object($this->db) && count($this->tables)) { if (!is_array($form["sql"])) { $form["sql"] = array( "vars" => array( "table" => array("type" => "table"), "page" => array("type" => "page"), "items" => array("type" => "form" , "var" => "items"), "order" => array("type" => "var" , "import" => $_GET["order"]), "order_mode" => array("type" => "var" , "import" => $_GET["order_mode"] && array_exists($_GET["order_mode"] , array("ASC" , "DESC" )) ? $_GET["order_mode"] : "ASC") ) ); $form["sql"]["query"] = "SELECT * FROM {TABLE} " . ($_GET["order"] ? "ORDER BY {ORDER} {ORDER_MODE}" : "") . " LIMIT {PAGE} , {ITEMS} "; $form["sql"]["count"] = array("table" => "{TABLE}" , "condition" => ""); } else { if ($form["sql"]["vars"]["order"] && $_GET["order"]) $form["sql"]["vars"]["order"]["import"] = $_GET["order"]; if ($form["sql"]["vars"]["order_mode"] && $_GET["order_mode"]) $form["sql"]["vars"]["order_mode"]["import"] = $_GET["order_mode"]; } if (is_array($form["sql"])) { if (is_array($form["sql"]["vars"])) { foreach ($form["sql"]["vars"] as $key => $val) { if ($val["action"] == "eval") { eval("\$val[\"import\"] = " . $val["default"] .";"); } switch ($val["type"]) { case "eval": eval("\$sql_vars[\"$key\"] = " . $val["import"] . ";"); break; case "var": $sql_vars[$key] = $val["import"]; break; case "table": $sql_vars[$key] = $val["import"] ? $this->tables[$val["import"]] : $this->tables[$form["table"]]; $__tables[] = $key; break; case "page": $sql_vars[$key] = ($_GET[($val["code"] ? $val["code"] : 'page')] -1 )* $form['items']; break; case "form": $sql_vars[$key] = $form[$val["var"]]; break; } } foreach ($sql_vars as $key => $val) { $this->templates->blocks["Temp"]->input = $val; $sql_vars[$key] = $this->templates->blocks["Temp"]->Replace($sql_vars); $sql_vars[$key] = str_replace("]" , ">" , str_replace("[" , "<" , $sql_vars[$key])); } $this->templates->blocks["Temp"]->input = $form["sql"]["query"]; $sql = $this->templates->blocks["Temp"]->Replace($sql_vars); $sql = str_replace("]" , ">" , str_replace("[" , "<" , $sql)); $items = $this->db->QFetchRowArray($sql); if (is_array($form["sql"]["count"])) { $form["sql"]["count"]["table"] = $form["sql"]["count"]["table"] ? $form["sql"]["count"]["table"] : $form["table"]; foreach ($form["sql"]["count"] as $key => $val) { $this->templates->blocks["Temp"]->input = $val; $form["sql"]["count"][$key] = $this->templates->blocks["Temp"]->Replace($sql_vars); } $count = $this->db->RowCount($form["sql"]["count"]["table"] , $form["sql"]["count"]["condition"] , $form["sql"]["count"]["select"] , $form["sql"]["count"]["fields"] ); } } } } if ($returnArray == true) { return array( "items" => $items, "count" => $count ); } $_GET["page"] = $_GET["page"] ? $_GET["page"] : 1; $start = $form["items"] * ($_GET["page"] ? $_GET["page"] - 1 : 0); $_old_count = $start + 1; if (is_array($items)) { foreach ($items as $key => $val) { $items[$key]["_count"] = ++$start; $items[$key]["original_count"] = $items[$key]["_count"] ; } } $_new_count = $start; $html = new CHtml(); $form = $this->Process($form); $template = &$this->templates; if (is_array($form["fields"])) { if ($form["sql"]["vars"]["fields"] != "") $__fields = explode("," , $form["sql"]["vars"]["fields"]); else { if (is_array($__tables) && is_object($this->db)) { $__fields = array(); foreach ($__tables as $_k => $_v) { $__fields = array_merge((array)$__fields , (array)$this->db->GetTableFields($sql_vars[$_v])); } } } $tmp_count = 0; foreach ($form["fields"] as $key => $val) { if (!($val["restricted"] && $this->__isRestricted($val["restricted"]))) { $tmp_count ++; $cell = array ( "width" => $val["width"], "align" => $val["align"], "value" => "{" . strtoupper($key) . "}", "valign" => $val["valign"] ? $val["valign"] : "middle", "final" => !is_array($form["buttons"]) && ($tmp_count == count($form["fields"])) ? "Final" : "", "first" => $tmp_count == 1 ? "First" : "", ); if ($form["valternance"] == "true") { $cell["_valternance"] = $this->_tmpVAlternance ? "2" : ""; $this->_tmpVAlternance = $this->_tmpVAlternance ? 0 : 1; } else $cell["_valternance"] = ""; $data .= $template->blocks["ListCell"]->Replace ( $cell ); if ($val["type"] == "multiple") $val["header"] = $template->blocks["SimpleListMultipleHeader"]->Replace(array( "name" => $val["field"], "start" => $_old_count, "end" => $_new_count )); $__title = ($val["header"] ? $val["header"] : "<img width=0 height=1 border=0/>"); if ($sql_vars["order"] == $key) $__sorting_mode = $_GET["order_mode"] == "ASC" ? "DESC" : "ASC"; else $__sorting_mode = "ASC"; if ($form["header"]["nolinks"] == "true") { $__template = "ListTitle"; } else { if (is_array($__fields) && in_array($key , $__fields)) $__template = "ListTitleLink"; else $__template = "ListTitle"; } $__tmp_title = array( "title" => $__title, "width" => $val["width"] ? " width=\"{$val[width]}\" " : "", "final" => !is_array($form["buttons"]) && ($tmp_count == count($form["fields"])) ? "Final" : "", "first" => $tmp_count == 1 ? "First" : "", "link" => CSYS::_GetVar( array( "order" => $key , "order_mode"=> $__sorting_mode ) ), "order" => $sql_vars["order"] == $key ? $template->blocks["ListTitleLinkOrder"]->Replace( array( "order" => strtolower($__sorting_mode) ) ) : "" ); if ($form["valternance"] == "true") { $__tmp_title["_valternance"] = $this->_tmpVAlternanceHeader ? "2" : ""; $this->_tmpVAlternanceHeader = $this->_tmpVAlternanceHeader ? 0 : 1; } else $__tmp_title["_valternance"] = ""; $titles .= $template->blocks[$__template]->Replace ( $__tmp_title ); } } if (is_array($form["buttons"])) { $titles .= $template->blocks["ListTitle"]->Replace ( array( "title" => "&nbsp" , "final" => "Final" , "width" => $val["width"] ? " width=\"{$val[width]}\" " : "" )); $row = $data . $template->blocks["ButtonsCell"]->output; } else $row = $data; $template->blocks["ListElement"]->input = $template->blocks["ListRow"]->Replace(array( "ROW"=> $row, "class" => "FormSimpleListRow" )); $titles = $template->blocks["ListRow"]->Replace(array( "ROW"=> $titles , "CLASS" => "FormSimpleListTitle" )); if ($form["header"]["titles"] == "false") { $titles = ""; } } if (is_array($form["header"]["buttons"])) { foreach ($form["header"]["buttons"] as $key => $val) { $val = array_merge($_GET , $val); $this->templates->blocks["Temp"]->input = $val["location"]; $val["location"] = $this->templates->blocks["Temp"]->Replace($val); $val["location"] = CryptLink($val["location"]); $val["title"] = $val["title"]; $val["onmouseout"] = $val["onmouseout"]; $val["onmouseover"] = $val["onmouseover"]; $val["onclick"] = $val["onclick"]; $val["target"] = $val["target"]; $header["buttons"] .= $template->blocks["Button"]->Replace($val); } } if (is_array($form["header"]["search"])) { $form_search = $form["header"]["search"]; if (is_array($form_search["options"])) { foreach ($form_search["options"] as $key => $val) { $search_form[$key]["label"] = $val; $search_form[$key]["checked"] = $_GET[$form_search["variable"]] == $key ? " selected " : ""; $search_form[$key]["tag"] = is_array($val) && $val["type"] == "group" ? "optgroup" : "option"; } $search["droplist"] = $html->FormSelect( "what" , $search_form , $template, "Select" , $_GET["what"], $search_form , array( "width" => "" , "onchange" => "" ) ); if (is_array($_GET)) { $temp = $_GET; $temp[$this->forms["uridata"]["action"]] = $this->forms["uridata"]["search"]; foreach ($temp as $key => $val) { if (!in_array($key , array( "page" , "what" , "search"))) { $search["fields"] .= $template->blocks["SearchField"]->Replace(array("name" => $key , "value" => $val)); } } } $search["action"] = $_SERVER["PHP_SELF"]; $search["value"] = $_GET["search"]; $header["search"] = $template->blocks["SearchForm"]->Replace($search); } } if (is_array($form["header"])) { if (($form["collapse"]["automatic"] == "true")&&($form["border"] == "true")) { unset($form["collapse"]); } if (is_array($form["collapse"]) && is_object($this->templates->blocks["ListCollapse"])) { $header["collapse"] = $this->templates->blocks["ListCollapse"]->Replace($form["collapse"]); } else $header["collapse"] = ""; $header["buttons"] = $header["buttons"] ? $header["buttons"] : ""; $header["search"] = $header["search"] ? $header["search"] : ""; $header["subtitle"] = $form["subtitle"]; $header = $template->blocks["ListHeader"]->Replace($header); } else $header = ""; $template->blocks["ListGroup"]->input = $template->blocks["ListGroup"]->Replace(array( "_HEADER" => $header , "_TITLES" => $titles , "_HTML_PRE" => (is_array($form["html"]["pre"]) && ($form["html"]["pre"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["pre"]["file"]) : html_entity_decode($form["html"]["pre"]), "_HTML_MIDDLE" => (is_array($form["html"]["middle"]) && ($form["html"]["middle"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["middle"]["file"]) : html_entity_decode($form["html"]["middle"]), "_PRE_TABS" => $this->DrawTabs($form["tabs"]), "_HTML_AFTER" => (is_array($form["html"]["after"]) && ($form["html"]["after"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["after"]["file"]) : html_entity_decode($form["html"]["after"]), "PRE" => $extra["pre"], "AFTER" => $extra["after"], "COLLAPSE_ID" => $form["collapse"]["id"], "COLLAPSE_INIT" => is_array($form["collapse"]) && is_object($this->templates->blocks["ListCollapseInit"]) ? $this->templates->blocks["ListCollapseInit"]->Replace($form["collapse"]) : "" )); $template->blocks["ListGroup"]->input = $template->blocks["ListGroup"]->Replace($form); if (is_array($global_vars)) { $template->blocks["ListElement"]->input = $template->blocks["ListElement"]->Replace($global_vars); $template->blocks["Button"]->input = $template->blocks["Button"]->Replace($global_vars); } if (is_array($_GET)) { foreach ($_GET as $key => $val) { if ($key != "page") { if (is_array($val)) { foreach ($val as $k => $v) $url[] = $key . "[$k]" . "=" . $v; } else { if ($key == "returnurl") { $url[] = $key . "=" . urlencode($val); } else { $url[] = $key . "=" . $val; } } } } $url = $_SERVER["SCRIPT_NAME"] . "?" . @implode("&" , $url) . "&"; } $template->blocks["Page"]->input = $template->blocks["Page"]->Replace(array("BASE" => $url)); $_GET["page"] = ($_GET["page"] ? $_GET["page"] : "1"); if (is_array($items)) { foreach ($items as $key => $val) { if (is_array($form["fields"])) { foreach ($form["fields"] as $k => $v) { if (!$v["name"]) $v["name"] = $k; $items[$key][$k] = html_entity_decode($items[$key][$k] , ENT_QUOTES); switch ($v["type"]) { case "phone": if (!$v["size"]) $v["size"] = $this->__default["show"]["phone"]["size"]; $size = explode("," , $v["size"]); $items[$key]["original_" . $k] = $items[$key][$k]; if (strlen($items[$key][$k]) <2) $items[$key][$k] = "<i>N/A</i>"; else $items[$key][$k] = substr($items[$key][$k],0,$size["0"]) . "-" . substr($items[$key][$k],$size["0"],$size["1"]) . "-" . substr($items[$key][$k],$size["1"],$size["2"]); break; case "rostates": $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = $form_RO_states[$items[$key][$k]]; break; case "states": case "usstates": $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = $form_US_states[$items[$key][$k]]; break; case "castates": $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = $form_CA_states[$items[$key][$k]]; break; case "countries": $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = $form_countries[$items[$key][$k]]; break; case "date": $items[$key]["original_" . $k] = $items[$key][$k]; if (isset($v["fields"])) { $supp_fields = array("month" , "year" , "month_str", "day"); $_tmp_v = ""; foreach ($supp_fields as $__k => $__v) { switch ($__v) { case "month_str": $_tmp_v[$__v] = $form_months[$val[$k . "_month" ]]; break; case "day": $_tmp_v[$__v] = sprintf("%02d" ,$val[$k . "_day" ]); break; } } $items[$key][$k] = $v["fields"]; foreach ($_tmp_v as $__k => $__v) { $items[$key][$k] = str_replace($__k , $__v , $items[$key][$k]); } } else { if (isset($val[$k . "_day" ]) && isset($val[$k . "_month" ]) && isset($val[$k . "_year" ])) { $items[$key][$k] = ( $val[$k . "_month" ] ? sprintf("%02d" ,$val[$k . "_month" ]) : "--" ). "/" . ( $val[$k . "_day" ] ? sprintf("%02d" ,$val[$k . "_day" ]) : "--" ) . "/" . ( $val[$k . "_year" ] ? $val[$k . "_year" ] : "----" ) ; } else $items[$key][$k] = $items[$key][$k] > 0 ? @date($v["params"] , ($v["now"] == "true" ? time() : $items[$key][$k])) : "N/A"; } break; case "price": $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = number_format($items[$key][$k],2); break; case "int": $items[$key][$k] = (int)$items[$key][$k]; break; case "image": if (isset($items[$key][$k]) && $items[$key][$k]) { $items[$key][$k] = $template->blocks[$v["nolink"] == "true" ? "imageshownolink" : "imageshow"]->Replace( array( "width" => $v["width"], "border" => $v["border"] ? $v["border"] : 0, "height" => $v["height"] ? "height='{$v[height]}' " : "", "src" => $v["link"] ? $v["link"] : (($v["absolute"] == "true" ? "" : $_CONF["url"] . $_CONF["upload"]) . $v["path"] . CTemplateStatic::Replace($v["file"]["default"] , $items[$key]) . ($v["file"]["field"] ? $items[$key][$v["file"]["field"]] : "") . $v["file"]["ext"]), "title" => $v["title"] ) ); } else { if ($v["default"]) { $items[$key][$k] = $template->blocks["imageshownolink"]->Replace( array( "width" => $v["width"], "border" => $v["border"] ? $v["border"] : 0, "height" => $v["height"] ? "height='{$v[height]}' " : "", "src" => $_CONF["url"] . $_CONF["upload"] . $v["path"] . $v["default"], "title" => $v["title"] ) ); } else $items[$key][$k] = " "; } break; case "relation": $items[$key]["original_" . $k] = $items[$key][$k]; if (is_array($v["options"])) { if (($v["multi"] == "true" )) { $_tmp = explode("," , $items[$key][$k]); $items[$key][$k] = array(); foreach ($_tmp as $__k => $__v) $items[$key][$k][] = $v["options"][$__v]; if (count($items[$key][$k])) $items[$key][$k] = implode($v["sep"] ? $v["sep"] : ", " , $items[$key][$k]); else $items[$key][$k] = ""; } else $items[$key][$k] = $v["options"][$items[$key][$k]] ? $v["options"][$items[$key][$k]] : " "; } if (is_array($v["relation"])) { $tmp_table= explode("," , $v["relation"]["table"]); $rel_table = array(); if (count($tmp_table)) { foreach ($tmp_table as $__k => $__table) { $rel_table[] = $this->tables[$__table]; } $rel_table = implode(" , " , $rel_table); } else $rel_table = $this->tables[$v["relation"]["table"]]; if ($v["multi"] == "true") { $record = ""; $_tmp = explode("," , $items[$key][$k]); if (is_array($_tmp)) { foreach ($_tmp as $__key => $__val) { if (!is_array($this->cache["list"][$v["name"]][$__val])) { $record[] = $this->cache["list"][$v["name"]][$__val] = $this->db->QFetchArray( "SELECT * FROM " . $rel_table . " WHERE `" . $v["relation"]["id"] . "`='" . $__val . "'" ); } else $record[] = $this->cache["list"][$v["name"]][$__val]; } } } else { if (!is_array($record = $this->cache["list"][$v["name"]][$items[$key][$k]])) { $sql = "SELECT * FROM " . $rel_table . " WHERE `" . $v["relation"]["id"] . "`='" . $items[$key][$k] . "'"; $record =$this->db->QFetchArray( $sql ); if (!is_array($record)) { $this->cache["list"][$v["name"]][$items[$key][$k]] = array(); } else $this->cache["list"][$v["name"]][$items[$key][$k]] = $record; } } if (is_array($v["relation"]["text"])) { $_tmp_text = ""; foreach ($v["relation"]["text"] as $kkey => $vval) if (is_array($vval)) $_tmp_text[] = $vval["preffix"] . $record[$vval["field"]] . $vval["suffix"]; else $_tmp_text[] = $record[$vval]; $items[$key][$k] = implode($v["relation"]["separator"] ? $v["relation"]["separator"] : " " , $_tmp_text); } else if (($v["multi"] == "true" ) && is_array($record)) { foreach ($record as $__k => $__v) $record[$__k] = $record[$__k][$v["relation"]["text"]]; $items[$key][$k] = implode($v["sep"] ? $v["sep"] : ", " , $record); } else $items[$key][$k] = $record[$v["relation"]["text"]]; } if ($items[$key][$k] == "") $items[$key][$k] = "N/A"; break; case "sql": $items[$key]["original_" . $k] = $items[$key][$k]; if (is_array($v["sql"])) { $form_sql_vars = array(); if (is_array($v["sql"]["vars"])) { foreach ($v["sql"]["vars"] as $_key => $_val) { if ($_val["action"] == "eval") { eval("\$_val[\"import\"] = " . $_val["default"] .";"); } switch ($_val["type"]) { case "eval": eval("\$form_sql_vars[\"$_key\"] = " . $_val["import"] . ";"); break; case "var": $form_sql_vars[$_key] = $_val["import"]; break; case "page": $form_sql_vars[$_key] = ($_GET[($_val["code"] ? $_val["code"] : 'page')] -1 )* $form['items']; break; case "form": eval("\$form_sql_vars[\"$_key\"] = " . $form[$_val["var"]] . ";"); break; case "table": $form_sql_vars[$_key] = $_val["import"] ? $this->tables[$_val["import"]] : $this->tables[$form["table"]]; break; case "field": $form_sql_vars[$_key] = $items[$key][$_val["import"]]; break; } } foreach ($form_sql_vars as $_key => $_val) { $this->templates->blocks["Temp"]->input = $_val; $form_sql_vars[$_key] = $this->templates->blocks["Temp"]->Replace($form_sql_vars); } $this->templates->blocks["Temp"]->input = $v["sql"]["query"]; $sql = $this->templates->blocks["Temp"]->Replace($form_sql_vars); $sql = str_replace("]" , ">" , str_replace("[" , "<" , $sql)); $record = $this->db->QFetchArray($sql); $items[$key][$k] = $record[$v["sql"]["field"]] ? $record[$v["sql"]["field"]] : "N/A"; $items[$key][$k] = $record[$v["sql"]["field"]] ? $record[$v["sql"]["field"]] : (isset($v["empty_msg"]) ? $v["empty_msg"] : "N/A"); } } else $items[$key][$k] = isset($v["empty_msg"]) ? $v["empty_msg"] : "N/A"; break; case "button": $v["nolink"] = "true"; if ($v["protected"] && $items[$key][$v["protected"]]) { $items[$key][$k] = " "; } else { $tmp = $v; $tmp["onmouseout"] = $tmp["onmouseout"] ? $tmp["onmouseout"] : ""; $tmp["onmouseover"] = $tmp["onmouseover"] ? $tmp["onmouseover"] : ""; $tmp["onclick"] = $tmp["onclick"] ? $tmp["onclick"] : ""; $tmp["title"] = $tmp["title"] ? $tmp["title"] : ""; $tmp["target"] = $tmp["target"] ? $tmp["target"] : ""; $button = new CTemplate($template->blocks["Button"]->Replace($tmp),"string"); $button->input = $button->Replace($global_vars); $items[$key][$k] = $button->Replace($items[$key]); } break; case "multiple": $items[$key]["original_" . $k] = $items[$key][$k]; $found_multiple = true; $_tmp_data = array(); if ($v["checked"]) { if ($v["checked"] == "exact") { $_tmp_data["value"] = $v["value"]; if ($items[$key][$v["field"]] == $v["value"]) $_tmp_data["checked"] = "checked"; else $_tmp_data["checked"] = ""; } else { $_tmp_data["value"] = $items[$key][$v["value"]]; if ($items[$key][$v["field"]]) $_tmp_data["checked"] = "checked"; else $_tmp_data["checked"] = ""; } } else { $_tmp_data["value"] = $items[$key][$v["value"]]; } $items[$key][$k] = $template->blocks["SimpleListMultiple"]->Replace(array( "value" => $_tmp_data["value"], "checked" => $_tmp_data["checked"], "field" => $v["field"] , "subfield" => $items[$key][$v["subfield"]], "name" => $v["field"], "_count" => $items[$key]["original_count"] )); break; case "field": $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = $template->blocks["SimpleListFieldInput"]->Replace(array( "value" => $items[$key][$v["field-value"]] , "field" => $v["field-id"] , "_count" => $items[$key]["original_count"], "size" => $v["field-size"], "align" => $v["field-align"] ? "align=\"{$v['field-align']}\"" : "", "id" => $items[$key][$v["field-id"]], "field-type" => $v["field-type"], "field-sub" => $v["field-sub"] ? "[" . $v["field-sub"] . "]" : "" )); break; case "eval": eval("\$items[\"\$key\"][\"\$k\"] = " . $v["value"]); break; default: $items[$key][$k] = $items[$key][$k] ? $items[$key][$k] : ($v["default"] ? $v["default"] : " "); break; } $items[$key][$k] = str_replace("&","&",$items[$key][$k]); if ($v["maxchars"]) { $items[$key][$k] = substr($items[$key][$k],0,$v["maxchars"]) . (strlen($items[$key][$k]) > $v["maxchars"] ? ($v["maxchars_text"] ? $v["maxchars_text"] : $this->__default["list"]["fields"]["maxchars_text"]) : ""); } if ($v["protected"] && $items[$key][$v["protected"]]) { $items[$key][$k] = " "; } if (($v["html"] != "true") && !$v["link"]) { if ($v["bbcode"] == "true") { $items[$key][$k] = CBBCode::Convert($items[$key][$k],""); } else { if ($v["nolink"] != "true") { $items[$key][$k] = eregi_replace("([_a-z0-9\-\.]+)@([a-z0-9\-\.]+)\." . "(net|com|gov|mil|org|edu|int|biz|asia|info|name|pro|[A-Z]{2})". "($|[^a-z]{1})", "<a title=\"Click to open the mail client.\" href=\"mailto:\\1@\\2.\\3\">\\1@\\2.\\3</a>\\4", $items[$key][$k]); $items[$key][$k] = eregi_replace("(http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href=\"\\1://\\2\" title=\"Click to open in new window.\" target=\"_blank\">\\2</a>", $items[$key][$k]); } } } $items[$key][$k] = $v["preffix"] . ( strtoupper($v["allownl"]) == "TRUE" ? nl2br($items[$key][$k]) : $items[$key][$k] ). $v["suffix"]; if ($v["link"]) { $tmp = new CTemplate( $this->templates->blocks["ListLink"]->Replace(array( "link" => $v["link"], "title" => $items[$key][$k] )) , "string"); $tmp->input = $tmp->Replace($global_vars); if (!$items[$key]["original_" . $k]) $items[$key]["original_" . $k] = $items[$key][$k]; $items[$key][$k] = $tmp->Replace($items[$key]); } if ($v["nobr"] == "true") { $items[$key][$k] = "<nobr>" . $items[$key][$k] . "</nobr>"; } if ($v["font"]) { $__fonts = @explode("," , $v["font"]); if (is_array($__fonts)) { $font__pre = ""; $font__after = ""; foreach ($__fonts as $__font) { $font__pre = $font__pre . "<$__font>"; $font__after = "</$__font>" . $font__pre; } $items[$key][$k] = $font__pre . $items[$key][$k] . $font__after; } } if ($v["color"]) { $colors = @explode(":" , $v["color"]); if (count($colors) == 1) $style = "color: {$colors[0]}"; else $style = "color: {$colors[0]};backgrond: {$colors[1]}"; $items[$key][$k] = "<span style=\"{$style}\">" . $items[$key][$k] . "</span>"; } } } if (is_array($form["buttons"])) { foreach ($form["buttons"] as $key2 => $val2) { if ($key2 != "set") { if ($val2["protected"] && $items[$key][$val2["protected"]]) { } else { $this->templates->blocks["Temp"]->input = $val2["location"]; $this->templates->blocks["Temp"]->input = $this->templates->blocks["Temp"]->Replace($global_vars); $val2["location"] = $this->ProcessLinks($this->templates->blocks["Temp"]->Replace(array_merge($items[$key],$global_vars))); $val2["location"] = str_replace(" ","%20" , $val2["location"]); $val2["title"] = $val2["title"]; $val2["onmouseout"] = $val2["onmouseout"]; $val2["onmouseover"] = $val2["onmouseover"]; $val2["onclick"] = $val2["onclick"]; $val2["target"] = $val2["target"]; $items[$key]["buttons"] .= ($form["buttons"]["set"]["buttonsvert"] == "true" ? "<tr><td height=3></td></tr><tr>" : "" ). $template->blocks["Button"]->Replace($val2) . ($form["buttons"]["set"]["buttonsvert"] == "true" ? "</tr>" : "" ); } } } if ( $items[$key]["buttons"] == "") { $items[$key]["buttons"] = " "; } } else { $items[$key]["buttons"] = ""; } if ($form["alternance"] == "true") { $items[$key]["_alternance"] = $this->_tmpAlternance ? "Alt" : ""; $this->_tmpAlternance = $this->_tmpAlternance ? 0 : 1; } else $items[$key]["_alternance"] = ""; } } if ($form["items"]) { $return = CTemplateStatic::Replace( $html->Table( $template , "List" , $items), array( "paging" => CHTML::CustomPaging( $template , "Paging", 10 , ceil($count / $form["items"]) , $_GET["page"] , $url . "&page={PAGE}" ), ) ); } else { $return = $html->Table( $template , "List" , $items ); } if (is_array($this->functions["list"]["after"])) call_user_func($this->functions["list"]["after"],&$append); if (!$append) { $append = ""; } if ($form["border"] != "true") { $border = new CTemplate($return , "string"); } else { $border = &$this->templates->blocks["Border"]; } $return = $border->Replace( array( "_TEMPLATE_DATA" => $return , "WIDTH" => $form["width"], "TITLE" => $form["title"] , "EXTRA" => $append )); $this->templates->blocks["Temp"]->input = $return; if ($form["formtag"] == "true") { $form["id"] = $form["id"] ? " id=\"" . $form["id"] . "\" " : ""; $form["encoding"] = $form["encoding"] ? $form["encoding"] : ""; $form["method"] = $form["method"] ? $form["method"] : "post"; $form["_template_data"] = $this->templates->blocks["Temp"]->input; $this->templates->blocks["Temp"]->input = $this->templates->blocks["Action"]->Replace( $form ); } return $this->__render($this->templates->blocks["Temp"]->input , array_merge((array)$global_vars,(array)$tpl_vars)); } function InsertField( $params ) { $form["fields"]["temp"] = $params; $values["values"][$params["name"]] = $params["value"] ; return $this->DrawElement ( $form , "temp" , $values ); } function DrawElement( $form , $_field , $values , $draw_referer = 0 ) { global $_SESS , $_CONF, $form_RO_states, $form_US_states, $form_CA_states, $form_countries , $form_timezones , $_VARS , $_USER , $base , $_TSM , $_SESS , $form_months; $field = $form["fields"][$_field]; $field["_end_char"] = $field["title"] ? ":" : ""; if ($field["type"] == "after_save") { $form["fields"][$_field] = $field = array( "type" => "droplist", "name" => "after_save", "default" => "\$_GET[after_save];", "action" => "eval", "title" => "After save", "options" => array( "0" => "return to previous page", "1" => "add a new record" ) ); } if (!is_array($field)) return ""; if (!$field["type"]) { return ""; } if (substr($field["default"],0,5) == "eval:") { $field["action"] = "eval"; $field["default"] = substr($field["default"],5); } $field["name"] = $_field; if (!isset($values["values"][$field["name"]])) { switch ($field["action"]) { case "eval": if (isset($field["default"])) eval("\$field[\"value\"] = " . $field["default"] . ";"); break; case "complex_eval": if (isset($field["default"])) eval($field["default"]); break; case "value": $field["value"] = $values["values"][$field["default"]]; break; default: $field["value"] = $field["default"]; break; } } else { $field["value"] = $values["values"][$field["name"]]; } if (isset($field["forcevalue"])) { switch ($field["action"]) { case "eval": eval("\$field[\"value\"] = " . $field["forcevalue"] . ";"); break; default: $field["value"] = $field["forcevalue"]; break; } } if ((($field["type"] != "image")&&($field["type"] != "upload")) && is_array($field["file"]) && !($values["values"][$field["name"]]) && file_exists($_CONF["path"] . $_CONF["upload"] . $field["file"]["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"])) { $field["value"] = GetFileContents($_CONF["path"] . $_CONF["upload"] . $field["file"]["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"]); } if (is_array($field["description"])) { switch ($field["description"]["type"]) { case "file": $_description = GetFileContents(dirname($form["xmlfile"]) . "/" . $field["description"]["file"]); if ($field["description"]["html"] != "true") { $_description = htmlspecialchars($_description); } break; } $field["description"] = $_description; } else { if (isset($field["description"])) $field["description"] = nl2br(html_entity_decode(str_replace("]" , ">" , str_replace("[" , "<" , $field["description"])))); } if (! $draw_referer && (($field["referer"]) || ($field["multiple"] == "true"))) return ""; $this->__private__handlers(&$field); if ($field["editable"] == "false") { switch ($field["type"]) { case "textbox": case "textarea": $field["type"] = "text"; $field["required"] = $field["unique"] = $field["validate"]; unset($field["description"]); break; } } switch ($field["type"]) { case "checkIMG" : $field["required"] = "true"; $field["validate"] = "A:8:8"; $current_field = $this->templates->blocks["imgCheck"]->Replace($field); break; case "phone": $current_field = $this->__field__phone( &$field , &$values ) ; break; case "textarea": $current_field = $this->__field__textarea(&$field , &$values ); break; case "file": $current_field = $this->__field__file(&$field , &$values); break; case "password": case "textbox": $current_field = $this->__field__textbox(&$field , &$values); break; case "sql": $this->__field__sql(&$field , &$values ); case "text": $current_field = $this->__field__text(&$field , &$values); break; case "hidden": $current_field = $this->__field__hidden(&$field , &$values ); $current_field_extra = ""; break; case "button": $current_field = $this->__field__button(&$field , &$values); break; case "checkbox": $current_field = $this->__field__checkbox(&$field , &$values); break; case "radiolist": case "radio": $field["radio"] = "true"; $field["type"] = "radio"; if (!isset($field["empty_text"])) $field["empty_text"] = $this->__default["show"]["radio"]["empty_text" . ($field["editable"] == "false" ? "_show" : "")]; case "checklist": if ($field["type"] == "checklist") { $field["checkbox"] = "true"; $field["radio"] = ""; $field["empty"] = ""; $field["multi"] = "true"; } case "relation": if ($field["type"] == "relation") $field["editable"] = "false"; case "double": case "doubleselect": if ( ($field["type"] == "doubleselect") || ($field["type"] == "double")) { $field["double"] = "true"; $field["multi"] = "true"; } case "USstates": case "usstates": case "droplist": case "countries": case "CAstates": case "castates": case "ROstates": case "timezone": case "timezones": case "rostates": $current_field = $this->__field__droplist(&$field , &$values ); break; case "upload": case "image": $current_field = $this->__field__image(&$field , &$values ); break; case "comment": $current_field = $this->__field__comment(&$field , &$values); break; case "date": $current_field = $this->__field__date(&$field , &$values ); break; case "multiple": if (is_array($field["multiple"])) { foreach ($field["multiple"] as $key => $val) { $current_field .= $this->DrawElement($form , $key , $values , 1); } } break; case "ccard": case "creditcard": $current_field = $this->__field__creditcard(&$field , &$values); break; case "namesort": $current_field = $this->__field__namesort(&$field , &$values ); break; case "calendar": $current_field = $this->__field__calendar(&$field , &$values); break; } $current_field_extra = $field["valign"] && !$field["hidden"]? $this->templates->blocks["TopAlign"]->output : ""; if ($field["link"]) { $tmp_tpl = new Ctemplate( '<a href="' . $field["link"] . '">' . $current_field . '</a>' , "string"); $current_field = $tmp_tpl->Replace($values["values"]); } if ($field["hidden"] != "true") { if (is_array($field["help"])) { $element["_helptopic"] = $this->templates->blocks["ElementHelpTopic"]->Replace(array( "location" => ($field["help"]["location"] == "module" ? dirname($form["xmlfile"]) . "/" : "") . $field["help"]["file"] )); } else $element["_helptopic"] = ""; if (!isset($field["referer"])) { $element["title"] = $field["title"]; $element["name"] = str_replace("[]" , "" , $field["name"]); $element["_end_char"] = $field["title"] ? ":" : ""; $element["align"] = $field["align"] ? $field["align"] : "left"; $field["description"] = $field["description"]; $element["_description"] = $field["description"] ? $this->templates->blocks["Description"]->Replace($field) : ""; $element["_description_rowspan"] = $field["description"] ? $this->templates->blocks["DescriptionRowspan"]->output : ""; $element["_element"] = $current_field; if (!is_array($field["referers"]) && isset($field["referers"])) { $tmp = explode("," , $field["referers"]); if (is_array($tmp)) { $field["referers"] = array(); foreach ($tmp as $_tmp => $referer) { $field["referers"][$referer] = "true"; $form["fields"][$field["name"]]["referers"][$referer] = "true"; } } } if (is_array($field["referers"])) { $_cnt = 0; foreach ($field["referers"] as $key => $val) { if (is_array($form["fields"][$key])) { $form["fields"][$key]["referer"] = $field["name"]; } $element["_element"] .= ($_cnt == 0 ? "" : '<td width="5"><img width=5 height=0></td>') . '<td>' . $this->DrawElement($form , $key , $values , 1) . "</td>"; $_cnt ++; } $element["_element"] = '<table cellspacing="0" cellpadding="0"><tr><td>' . $element["_element"] . "</tr></table>"; } $element["_suffix"] = $field["suffix"]; $element["_preffix"] = $field["preffix"]; $element["_extra"] = $current_field_extra; $element["_extra_code"] = $field["_extra_code"]; $element["_required"] = $field["required"] == "true" ? trim($this->templates->blocks["RequiredMark"]->output) : ""; $element["_required_error"] = $values["errors"][str_replace("[]" , "" , $field["name"])] ? trim($this->templates->blocks["Required"]->output) : ""; if ($form["alternance"] == "true") { $this->_tmpAlternance = $this->_tmpAlternance ? 0 : 1; $element["_alternance"] = $this->_tmpAlternance ? "Alt" : ""; } else $element["_alternance"] = ""; if (($form["alternance_comment"]=="false") && ($field["type"] == "comment")) { $this->_tmpAlternance = $this->_tmpAlternance ? 0 : 1; $element["_alternance"] = $this->_tmpAlternance ? "Alt" : ""; } if (($field["multiple"] == "true") && $draw_referer ){ return $this->templates->blocks["ElementMultipleBody"]->Replace($element); } if ($field["type"] == "multiple") { if ($form["alternance"] == "true") { $this->_tmpAlternance = $this->_tmpAlternance ? 0 : 1; $vars["_alternance"] = $this->templates->blocks["Alternance" . $this->_tmpAlternance]->output; $this->templates->blocks["Temp"]->input = $this->templates->blocks["ElementMultiple"]->Replace($element); return $this->templates->blocks["Temp"]->Replace($vars); } else return $this->templates->blocks["ElementMultiple"]->Replace($element); } if ($field["extend"] != "true") { switch ($field["type"]) { case "subtitle": return $this->templates->blocks["Subtitle"]->Replace($element); break; case "comment": return $current_field; break; default: return $this->templates->blocks["Element"]->Replace($element); break; } } else { if (is_object($this->templates->blocks["ExtendElementTitle"])) { if ($element["title"]) $element["element_title"] = $this->templates->blocks["ExtendElementTitle"]->Replace($element); else $element["element_title"] = ""; } else { $element["element_title"] = ""; } return $this->templates->blocks["ExtendElement"]->Replace($element); } } else { $element["_suffix"] = $field["suffix"]; $element["_preffix"] = $field["preffix"]; $element["_element"] = $current_field; return $draw_referer ? $this->templates->blocks["ElementReferer"]->Replace($element): ""; } } else { return $current_field; } } function DrawTabsRow($tabs , $first = 0) { global $base; if (is_array($tabs)) { $count = 1; $active = false; foreach ($tabs as $key => $val) { if ($val["restricted"] && $this->__isRestricted($val["restricted"])) { unset($tabs[$key]); } } foreach ($tabs as $key => $val) { if ($active == true) { $active = false; $tabs[$key]["afteractive"] = "true"; } else $tabs[$key]["afteractive"] = "false"; $tabs[$key]["last"] = ($count == count($tabs) ? "true" : "false"); $tabs[$key]["active"] = $val["active"] == "true" ? "true" : "false"; $tabs[$key]["width"] = $val["width"] ? $val["width"] : "50"; $tabs[$key]["icon"] = $val["icon"]; $tabs[$key]["onmouseover"] = $val["onmouseover"]; $tabs[$key]["onmouseout"] = $val["onmouseout"]; $tabs[$key]["id"] = $key; $tabs[$key]["link"] = $val["link"]; $tabs[$key]["firstrow"] = $first == 0 ? "true" : "false"; if ($val["active"] == "true") $active = true; $count ++; } return $base->html->Table($this->templates,"Tabs",$tabs); } else return ""; } function DrawTabs($tabs) { global $base; if (is_array($tabs)) { if (is_array($tabs["groups"])) { $count = 0; foreach ($tabs["groups"] as $key => $val) { $return .= $this->DrawTabsRow($val , $count); $count ++; } return $return; } else return $this->DrawTabsRow($tabs); } else return ""; } function Show($form = array(), $values = array() , $extra = array()) { global $_CONF , $_USER, $_SESS, $form_errors; if (is_array($form)) $form = $this->Process($form); else $form = $this->form; if (is_array($form["vars"])) { foreach ($form["vars"] as $key => $val) { if ($val["action"] == "eval") { eval("\$val[\"import\"] = " . $val["default"] .";"); } switch ($val["type"]) { case "eval": eval("\$tpl_vars[\"$key\"] = " . $val["import"] . ";"); break; case "value": $tpl_vars[$key] = $values["values"][$val["import"]]; break; case "complex_eval": eval($val["import"]); break; case "var": $tpl_vars[$key] = $val["import"]; break; } } } $tpl_vars = array_merge((array)$tpl_vars , $globalvars = $this->GlobalVars($form)); if (!is_array($form["fields"]["returnurl"]) && ($tpl_vars["self.previous"] != "")) $form["fields"]["returnurl"] = array( "type" => "hidden", "default" => $globalvars["self.previous_enc"] ); if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $field) { if (!$field["name"]) $form["fields"][$key]["name"] = $key; if ($field["protected"] && $values["values"][$field["protected"]] && ($field["showprotected"] == "true")) { $form["fields"][$key]["type"] = "text"; $form["fields"][$key]["validate"] = ""; $form["fields"][$key]["required"] = ""; $form["fields"][$key]["unique"] = ""; $form["fields"][$key]["description"] = ""; unset($field["protected"]); } if ($field["protected"] && $values["values"][$field["protected"]] || ($field["restricted"] && $this->__isRestricted($field["restricted"]))) { } else { $element = array(); $current_field_extra = ""; $current_field = ""; if (!@isset($values["values"][$field["name"]]) && @isset($GLOBALS[$field["get"]][$field["name"]])) { $values["values"][$field["name"]] = $GLOBALS[$field["get"]][$field["name"]]; } if (isset($extra["fields"][$key])) $form["fields"][$key]["_extra_code"] = $extra["fields"][$key]; else $form["fields"][$key]["_extra_code"] = ""; $form["_template_data"] .= $this->DrawElement($form , $key, &$values); } } } else $form["_template_data"] = ""; if (is_array($form["buttons"])) { foreach ($form["buttons"] as $key => $val) if (($key != "set") && (!($val["protected"] && $values["values"][$val["protected"]]))) { $this->templates->blocks["Temp"]->input = $val["location"]; $this->templates->blocks["Temp"]->input = $this->templates->blocks["Temp"]->Replace($tpl_vars); $val["location"] = $this->templates->blocks["Temp"]->Replace($values["values"]); $val["location"] = CryptLink($val["location"]); $val["onmouseout"] = $val["onmouseout"]; $val["onmouseover"] = $val["onmouseover"]; $val["onclick"] = $val["onclick"]; $val["title"] = $val["title"]; $val["target"] = $val["target"]; $buttons .= $this->templates->blocks["Button"]->Replace($val); } if ( (($form["buttons"]["set"]["header"] == "true") && (count($form["buttons"])>1) ) || $form["subtitle"]) { $form["_header_buttons"] = $this->templates->blocks["HeaderButtons"]->Replace(array( "SUBTITLE" => ($form["subtitle"] ? $form["subtitle"] : " ") , "BUTTONS" => $form["buttons"]["set"]["header"] == "true" ? $buttons : "&nbsp" ) ); } else $form["_header_buttons"] = ""; $form["_footer_buttons"] = $form["buttons"]["set"]["footer"] == "true" ? $this->templates->blocks["FooterButtons"]->Replace(array("BUTTONS" => $buttons)) : ""; } else { $form["_header_buttons"] = $form["_footer_buttons"] = ""; if (strlen($form["subtitle"])) { $form["_header_buttons"] = $this->templates->blocks["HeaderButtons"]->Replace(array( "SUBTITLE" => ($form["subtitle"] ? $form["subtitle"] : " ") , "BUTTONS" => "&nbsp" )); } } if ($values["error"]) $form["_error"] = $this->templates->blocks["Error"]->Replace(array("error" => $values["error"] )); else $form["_error"] = ""; $form["_pre_javascript"] = $form["javascript"]["pre"] ? "<script language=\"Javascript\">" . $form["javascript"]["pre"] . "</script>" : ""; $form["_after_javascript"] = $form["javascript"]["after"] ? "<script language=\"Javascript\">" . $form["javascript"]["after"] . "</script>" : ""; $form["_pre_tabs"] = $this->DrawTabs($form["tabs"]); $form["_pre_html"] = (is_array($form["html"]["pre"]) && ($form["html"]["pre"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["pre"]["file"]) : html_entity_decode($form["html"]["pre"]); $form["_middle_html"] = (is_array($form["html"]["middle"]) && ($form["html"]["middle"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["middle"]["file"]) : html_entity_decode($form["html"]["middle"]); $form["_after_html"] = (is_array($form["html"]["after"]) && ($form["html"]["after"]["type"] == "extern")) ? GetFileContents(dirname($form["xmlfile"]) . "/" . $form["html"]["after"]["file"]) : html_entity_decode($form["html"]["after"]); $form["_pre_form"] = $extra["pre"]; $form["_after_form"] = $extra["after"]; $this->templates->blocks["Temp"]->input = $form["action"]; $form["action"] = CryptLink($this->templates->blocks["Temp"]->Replace($tpl_vars)); $form["_template_data"] = $form["_template_data"] == "" ? "" : $form["_template_data"]; $form["_template_data"] = $this->templates->blocks["Form"]->Replace($form); if ($form["border"] == "true") { $form["_template_data"] = $this->templates->blocks["Border"]->Replace( $form ); } $this->templates->blocks["Temp"]->input = $form["_template_data"]; $form["_template_data"] = $this->templates->blocks["Temp"]->Replace($tpl_vars); if ($form["formtag"] == "true") { $form["id"] = $form["id"] ? " id=\"" . $form["id"] . "\" " : ""; $form["encoding"] = $form["encoding"] ? $form["encoding"] : ""; $form["method"] = $form["method"] ? $form["method"] : "post"; $form["_template_data"] = $this->templates->blocks["Action"]->Replace( $form ); } return $this->__render($form["_template_data"] , $tpl_vars); } function GlobalVars($form = array(), $_FROM = array()) { global $_CONF; if (!count($_FROM)) $_FROM = &$_GET; if ($_GET["returnurl"]) $private_return = $_GET["returnurl"]; if ($_GET["returnURL"]) $private_return = $_GET["returnURL"]; if ($_POST["returnurl"]) $private_return = $_POST["returnurl"]; $return_enc = urlencode($private_return); $return_dec = urldecode($private_return); $repl_count = 1; if ((substr($return_dec,0,1) != "/") && (strlen($return_dec) > 3)) while ( (substr($return_dec,0,1) != "/") && ($repl_count < 10 )) { $return_dec = urldecode($return_dec); $repl_count ++; } if (strstr($return_enc , '/')) $return_enc = urlencode($return_enc); $return = array ( "self.conf.url" => $_CONF["url"], "self.file" => $_SERVER["PHP_SELF"], "self.mod" => $_FROM['mod'] ? 'mod=' . $_FROM['mod'] . '&' : '', "self.sub" => $_FROM['sub'] ? 'sub=' . $_FROM['sub'] . '' : '', "self.action" => $_FROM['action'] ? 'action=' . $_FROM['action'] . '' : '', "self.var.mod" => $_FROM['mod'], "self.var.sub" => $_FROM['sub'], "self.var.action" => $_FROM['action'], "self.uid" => $form["table_uid"], "self.uidvar" => '{' . strtoupper($form["table_uid"]) . '}', "self.link" => $_SERVER["PHP_SELF"] . "?" . ($_FROM['mod'] ? 'mod=' . $_FROM['mod'] . '&' : '') . ($_FROM['sub'] ? 'sub=' . $_FROM['sub'] . '&' : ''), "self.linkuid" => $_SERVER["PHP_SELF"] . "?" . ($_FROM['mod'] ? 'mod=' . $_FROM['mod'] . '&' : '') . ($_FROM['sub'] ? 'sub=' . $_FROM['sub'] . '&' : '') . $form["table_uid"] . "=" . '{' . strtoupper($form["table_uid"]) . '}', "self.location" => urlencode(urlencode($_SERVER["REQUEST_URI"])), "self.title" => !$_FROM[$form["table_uid"]] || $_POST[$form["table_uid"]] ? "Add New " : "Edit ", "self.previous" => $private_return ? $return_dec : $form_errors["NO_BACK_LINK"], "self.previous_enc" => $private_return ? $return_enc : $form_errors["NO_BACK_LINK"], "private.get_mod" => $_FROM["mod"], "private.get_sub" => $_FROM["sub"], "private.get_action" => $_FROM["action"], "private.table_uid" => $form["table_uid"], "private.value_uid" => '{' . strtoupper($form["table_uid"]) . "}", "private.form_action_title" => !$_FROM[$form["table_uid"]] || $_POST[$form["table_uid"]] ? "Add New " : "Edit ", "private.form_previous_page" => $private_return ? $return_dec : $form_errors["NO_BACK_LINK"], "private.form_previous_page_enc" => $private_return ? $return_enc : $form_errors["NO_BACK_LINK"], "current_page" => urlencode(urlencode($_SERVER["REQUEST_URI"])) ); if (is_array($_GET)) { foreach ($_GET as $key => $val) { $return["global.get." . strtolower($key)] = $val; } } if (is_array($form["urilinks"])) { foreach ($form["urilinks"] as $key => $val) { $return["self.uri.$key"] = $val; } } if (is_array($form["uridata"])) { foreach ($form["uridata"] as $key => $val) { $return["self.action.$key"] = $form["uridata"]["action"] . "=" . $val; $return["self.linkuid.$key"] = $return["self.linkuid"] . "&" . $return["self.action.$key"]; $return["self.link.$key"] = $return["self.link"] . "&" . $return["self.action.$key"]; } } $tmp = new CTemplate(""); foreach ($return as $key => $val) { $tmp->input = $val; $return[$key] = $tmp->Replace($return); } return $return; } function __private__handlers($field) { $events = array( "tabindex" , "accesskey" , "onfocus" , "onblur" , "onselect" , "onchange" , "onclick" , "ondblclick" , "onmousedown" , "onmouseup" , "onmouseover" , "onmousemove" , "onmouseout" , "onkeypress" , "onkeydown" , "onkeyup" ); foreach ($events as $key => $val) { if (array_key_exists($val , $field)) $final[] = " {$val}=\"" . $field[$val] ."\" "; } if (is_array($final)) $field["handlers"] = implode("" , $final); else $field["handlers"] = ""; } function __private__showonly( $form = array(), $set = array ( "description" => TRUE, "comments" => TRUE ) ) { $form = CForm::Process($form); if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $val) { unset($form["fields"][$key]["required"]); unset($form["fields"][$key]["validate"]); if (($set["description"] == TRUE) && ($val["type"] != "comment" )) unset($form["fields"][$key]["description"]); $form["fields"][$key]["editable"] = "false"; switch ($val["type"]) { case "textbox": case "textarea": $form["fields"][$key]["type"] = "text"; break; case "password": $form["fields"][$key]["type"] = "text"; $form["fields"][$key]["forcevalue"] = "**********"; break; case "comment": if ($set["comments"] == TRUE) unset($form["fields"][$key]); break; case "after_save": unset($form["fields"][$key]); break; } } } return $form; } function __private_generate_field($val) { return array( "type" => $val["item_type"], "title" => $val["item_set_title"] ? "" : $val["item_title"], "description" => $val["item_description"], "size" => $val["item_type"] == "textbox" ? $val["item_size_cols"] : ($val["item_type"] == "textarea" ? $val["item_size_cols"] . ":" . $val["item_size_rows"] : ""), "options" => $val["options"], "padding" => $val["item_type"] == "comment" ? "20" : "", "empty" => $val["item_type"] == in_array($val["item_type"] , array("droplist" , "radiolist" , "checklist" , "usstates" , "rostates" , "castates")) ? "true" : "", "required" => $val["item_required"] ? "true" : "", "validate" => strtoupper($val["item_required_type"]) . ":" . $val["item_required_size_min"] . ":" . $val["item_required_size_max"], "preffix" => $val["item_set_preffix"], "suffix" => $val["item_set_suffix"], "checked" => $val["item_type"] == "checkbox" ? "1" : "", "label" => $val["item_set_label"], "empty" => $val["item_set_radio_empty"] ? "true" : "", "newline" => $val["item_set_radio_line"] ? "true" : "false" ); } function __private_tree($records , $parent , $record_id , $parent_field , $separator , $level = 0 , $full = array() , $location = array()) { if ($level && ($full["full"]!="true")) { for ($i = 1; $i<= $level; $i++) { $sep .= $separator; } } if (is_array($records)) { foreach ($records as $key => $val) { if ($val[$parent_field] == $parent) { $val["separator"] = $sep; if ($full["full"] == "true") { $tmp = $location; $tmp[] = $val[$full["field"]]; $val[$full["field"]] = implode($separator , $tmp); } $_records[] = $val; $_records = array_merge((array)$_records , (array)CForm::__private_tree($records , $val[$record_id] ,$record_id , $parent_field , $separator , $level+1 , $full , $tmp)); } } } if ($level == 0) { } return $_records; } function ProcessVariables($form , $input) { $form = CForm::Process($form); if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $val) { switch ($val["type"]) { case "ccard": case "creditcard": case "phone": if (is_array($input[$key . "_arr"])) { $input[$key] = trim(implode("" , $input[$key . "_arr"] )); } break; case "checkbox": $input[$key] = $input[$key] ? $input[$key] : "0"; break; case "date": $__date = mktime($input[$key . "_hour"] , $input[$key . "_min"] , $input[$key . "_sec"] , $input[$key . "_month"] , $input[$key . "_day"] , $input[$key . "_year"]); if ($__date > 1000) { $input[$key] = $__date; } else $input[$key] = 0; break; case "checklist": $val["multi"] = "true"; if (is_array($input[$key])) $input[$key] = implode("," , $input[$key]); else $input[$key] = ""; break; case "droplist": case "radiolist": case "double": case "doubleselect": case "countries": case "usstates": case "states": case "rostates": case "castates": if (is_array($input[$key])) $input[$key] = implode("," , $input[$key]); break; case "calendar": if ((strlen($input[$key]) == 10) && (((int)$input[$key] == $input[$key]) && ($input[$key] > 1000))) { } else { if (isset($input[$key])) { if (strlen($input[$key]) == 10) { $tmp["m"] = substr($input[$key],0,2); $tmp["d"] = substr($input[$key],3,2); $tmp["y"] = substr($input[$key],6,4); } if ((strlen($input[$key]) == 16) && ($val["calendar"]["time"] == "true")) { $tmp["m"] = substr($input[$key],0,2); $tmp["d"] = substr($input[$key],3,2); $tmp["y"] = substr($input[$key],6,4); $tmp["h"] = substr($input[$key],11,2); $tmp["i"] = substr($input[$key],14,2); } if (is_array($tmp) && count($tmp)) { if ($_CONF["settings"]["locale"] == "eu"){ $tmp["_"] = $tmp["m"]; $tmp["m"] = $tmp["d"]; $tmp["d"] = $tmp["_"]; } if (count($tmp) == 3) { $input[$key] = mktime(0 , 0 , 0 , $tmp["m"] , $tmp["d"] , $tmp["y"]); } if (count($tmp) == 5) { $input[$key] = mktime($tmp["h"] , $tmp["i"] , 0 , $tmp["m"] , $tmp["d"] , $tmp["y"]); } } } } if ($input[$key] < 1000) $input[$key] = 0; if ($input[$key]) { $input[$key . "_hour"] = date("H" , $input[$key]); $input[$key . "_min"] = date("i" , $input[$key]); $input[$key . "_sec"] = date("s" , $input[$key]); $input[$key . "_month"] = date("m" , $input[$key]); $input[$key . "_day"] = date("d" , $input[$key]); $input[$key . "_year"] = date("Y" , $input[$key]); } break; } } } return $input; } function __isRestricted($data) { global $_MODULES; if (strpos($data , "eval:") === 0) { eval("\$result = " . substr($data , 5) ); return $result; } } function ProcessItems($items , $relations) { if (is_array($items)) { foreach ($items as $key => $val) { $items[$key] = CForm::ProcessItem($val , $relations); } } return $items; } function ProcessItem($item , $relations) { if (is_array($item)) { foreach ($item as $k => $v) { if ($relations[$k]) { $relation = $relations[$k]; switch ($relation["type"]) { case "date": if ($v) $item[$k] = date($relation["params"] , $v); else $item[$k] = $relation["default"] ? $relation["default"] : "N/A"; break; case "price": $item[$k] = number_format($item[$k],2); break; case "options": $item[$k] = $relation["options"][$v]; break; case "bbcode": $bbc = new CBBCode(); if ($relation["tpl"]) { $bbc->language_tpl = $relation["tpl"]; } $item[$k] = $bbc->Convert($v , $relation["lang"]["default"]); break; } if ($relation["maxchars"]) { if (strlen($item[$k]) > $relation["maxchars"]) { $item[$k] = substr($item[$k] , 0 , $relation["maxchars"] ) . "..."; } } } } } return $item; } function __field__droplist($field , $values) { global $form_US_states, $form_RO_states, $form_CA_states, $form_countries, $form_timezones; if ($field["newline"] == "false") { $field["line_bottom"] = ""; $field["line_top"] = ""; } else { $field["line_bottom"] = $this->templates->blocks["CheckBoxOption_line_bottom"]->output; $field["line_top"] = $this->templates->blocks["CheckBoxOption_line_top"]->output; } if (!isset($field["emptymsg"])) $field["emptymsg"] = $this->__default["show"]["droplist"]["empty_text" . ($field["editable"] == "false" ? "_show" : "")]; if (!isset($field["empty_text"])) $field["empty_text"] = $this->__default["show"]["droplist"]["empty_text" . ($field["editable"] == "false" ? "_show" : "") ]; if (($field["multi"]||$field["double"]) && !is_array($field["value"])) $field["value"] = explode("," , $field["value"]); $values["values"]["original_" . $field["name"]] = $field["value"]; switch ($field["type"]) { case "USstates": case "states": case "usstates": $field["options"] = $form_US_states; break; case "ROstates": case "rostates": $field["options"] = $form_RO_states; break; case "CAstates": case "castates": $field["options"] = $form_CA_states; break; case "countries": $field["options"] = $form_countries; break; case "relation": $field["editable"] = "false"; break; case "timezones": case "timezone": $field["options"] = $form_timezones; break; } if (($field["usetext"] == "true") && (is_array($field["options"]))) { foreach ($field["options"] as $key => $val){ unset($field["options"][$key]); $field["options"][$val] = $val; } } if ($field["editable"] == "false") $field["type"] = "relation"; $temp_options = ""; if (is_array($field["dynamic"])) { if ($field["dynamic"]["from_type"] == "eval") { eval( "\$field[\"dynamic\"][\"from\"] = " . $field["dynamic"]["from"] . ";"); } if ($field["dynamic"]["from"] > $field["dynamic"]["to"]) for ($i = $field["dynamic"]["from"]; $i>= $field["dynamic"]["to"]; $i-- ) { $field["options"][$i] = $field["dynamic"]["width"] ? sprintf("%0" . $field["dynamic"]["width"] . "d", $i) : $i; } else for ($i = $field["dynamic"]["from"]; $i<=$field["dynamic"]["to"]; $i++ ) { $field["options"][$i] = $field["dynamic"]["width"] ? sprintf("%0" . $field["dynamic"]["width"] . "d", $i) : $i; } } if (is_array($field["relation"])) { if (is_array($field["relation"]["sql"])) { if (is_array($field["relation"]["sql"]["vars"])) { $form_sql_vars = array(); foreach ($field["relation"]["sql"]["vars"] as $key => $val) { if ($val["action"] == "eval") { eval("\$val[\"import\"] = " . $val["default"] .";"); } switch ($val["type"]) { case "eval": eval("\$form_sql_vars[\"$key\"] = " . $val["import"] . ";"); break; case "var": $form_sql_vars[$key] = $val["import"]; break; case "table": $form_sql_vars[$key] = $val["import"] ? $this->tables[$val["import"]] : $this->tables[$form["table"]]; break; case "page": $form_sql_vars[$key] = ($_GET[($val["code"] ? $val["code"] : 'page')] -1 )* $form['items']; break; case "form": eval("\$form_sql_vars[\"$key\"] = " . $form[$val["var"]] . ";"); break; } } foreach ($form_sql_vars as $key => $val) { $this->templates->blocks["Temp"]->input = $val; $form_sql_vars[$key] = $this->templates->blocks["Temp"]->Replace($form_sql_vars); } $this->templates->blocks["Temp"]->input = $field["relation"]["sql"]["query"]; $sql = $this->templates->blocks["Temp"]->Replace($form_sql_vars); $sql = str_replace("]" , ">" , str_replace("[" , "<" , $sql)); $records = $this->db->QFetchRowArray($sql); } else { $records = $this->db->QFetchRowArray($field["relation"]["sql"]["query"]); } } else { if (is_array($field["relation"]["condition"]) && ($field["relation"]["condition"]["eval"] == "true")) { eval("\$field[\"relation\"][\"condition\"] = " . $field["relation"]["condition"]["import"]); } $tmp_table= explode("," , $field["relation"]["table"]); if (count($tmp_table)) { foreach ($tmp_table as $__k => $__table) { $rel_table[] = $this->tables[$__table]; } $rel_table = implode(" , " , $rel_table); } else $rel_table = $this->tables[$field["relation"]["table"]]; $sql = "SELECT * FROM " . $rel_table . " " . ($field["relation"]["condition"] ? " WHERE (" . $field["relation"]["condition"] . ") " : "" ) . ($field["relation"]["order"] ? " ORDER BY " . $field["relation"]["order"] . " " . ($field["relation"]["ordermode"] ? $field["relation"]["ordermode"] : "") : "" ); $records =$this->db->QFetchRowArray( $sql ); } if (is_array($records)) { if (($field["editable"] != "false") && is_array($records) && is_array($field["tree"])) { $records = CForm::__private_tree( $records , $field["tree"]["first"] ? $field["tree"]["first"] : 0 , $field["relation"]["id"] , $field["tree"]["parent"] , $field["tree"]["separator"] , 0, array ( "full" => $field["tree"]["full"] , "field" => $field["tree"]["field"] ) ); } if (is_array($records)) { foreach ($records as $key => $val) { if (is_array($field["relation"]["text"])) { $_tmp_text = array(); foreach ($field["relation"]["text"] as $kkey => $vval) if (is_array($vval)) $_tmp_text[] = $vval["preffix"] . $val[$vval["field"]] . $vval["suffix"]; else $_tmp_text[] = $val[$vval]; $field["options"][$val[$field["relation"]["id"]]] = $val["separator"] . implode($field["relation"]["separator"] ? $field["relation"]["separator"] : " " , $_tmp_text); } else $field["options"][$val[$field["relation"]["id"]]] = $val["separator"] . $val[$field["relation"]["text"]]; } } } } if ($field["radio"] == "true") { $template = "Radio"; $checked = " checked=\"checked\" "; } else { if ($field["checkbox"] == "true") { $template = "CheckBox"; $checked = " checked=\"checked\" "; } else { if ($field["double"] == "true") { if ($field["small"] == "true") { $template = "DoubleSmall"; $checked = true; } else { $template = "Double"; $checked = true; } } else { $template = "Select"; $checked = " selected=\"selected\" "; } } } if ($field["empty"] == "true") { if ($field["editable"] == "false") $__empty = $field["empty_text"] ? $field["empty_text"] : "<i>N/A</i>"; else $__empty = $field["empty_text"] ? $field["empty_text"] : " [ select ] "; $field["options"] = array("" => $__empty) + (is_array($field["options"]) ? $field["options"] : array() ); } if (is_array($field["options"])) { if ($field["multi"] && ($field["editable"] != "false")) $field["name"] .= "[]"; foreach ($field["options"] as $key => $val) { if ($field["editable"] == "false") { if ($field["multi"]) { if (in_array($key , $values["values"]["original_" . $field["name"]] )) $current_field[] = $val; } else { if (($key == $values["values"][$field["name"]]) && (strlen($key) == strlen($values["values"][$field["name"]])) ) { $found = 1; $field["value"] = $val; $this->templates->blocks["text"]->Replace($field , false); $current_field = $this->templates->blocks["text"]->EmptyVars(); } } } else { if (is_array($val)) { $label = $val["value"]; $disabled = $val["disabled"] == "true" ? " disabled " : ""; } else { $label = $val; $disabled = ""; } if (is_array($field["value"])) $selected = in_array($key , $field["value"]) ? $checked : "" ? $checked : ""; else { $selected = (($key == $field["value"]) && (strlen($key) == strlen($field["value"])) ? $checked : ""); } if (($field["double"] == "true") && $selected) { $temp_options2 .= $this->templates->blocks["{$template}Option" . (is_array($val) && $val["type"] == "group" ? "Group" : "")]->Replace( array( "value" => $key, "label" => $label, "checked" => $selected, "disabled" => $disabled, "name" => $field["name"], "line_top" => $field["line_top"], "line_bottom" => $field["line_bottom"] ) ); $temp_options3[] = $key; } $temp_options .= $this->templates->blocks["{$template}Option" . (is_array($val) && $val["type"] == "group" ? "Group" : "")]->Replace( array( "value" => $key, "label" => $label, "checked" => $selected, "disabled" => $disabled, "name" => $field["name"], "line_top" => $field["line_top"], "line_bottom" => $field["line_bottom"] ) ); } } if (is_array($current_field)) { $current_field = implode(", " , $current_field ); $found = 1; } } if ($field["editable"] != "false") { if (!isset($field["emptymsg"])) $field["emptymsg"] = $this->__default["show"]["droplist"]["emptytext"]; $field["options"] = $temp_options; if (($field["double"] == "true")) { $field["options2"] = $temp_options2; $field["values"] = is_array($temp_options3) ? implode("," , $temp_options3) : ""; } $field["size"] = $field["size"] ? $field["size"] : "1"; $field["multiple"] = $field["multi"] ? " multiple=\"multiple\" " : ""; $field["width"] = $field["width"] ? "style=\"width:{$field[width]}px\";" : ""; $field["disabled"] = $field["disabled"] == "true" ? " disabled " : ""; if ($temp_options != "") $current_field = $this->templates->blocks[$template]->Replace($field); else $current_field = $field["emptymsg"]; } else { if (!(($current_field != "")&& $found)) { $current_field = $field["emptymsg"]; } } return $current_field; } function __field__image($field , $values) { global $_CONF; if ($field["type"] == "upload") { $file = true; } if ($field["force_values"]) { $values["values"][$field["name"] . "_file"] = $field["force_values"]["file"]; $values["values"][$field["file"]["field"]] = $field["force_values"]["field"]; $values["values"][$field["name"]] = $field["force_values"]["value"]; } if ($field["editable"] != "false") { $field["web_checked"] = $values["values"][$field["name"] . "_radio_type"] ? "checked" : ""; $field["client_checked"] = $values["values"][$field["name"] . "_radio_type"] ? "" : "checked"; $field["web_link"] = $values["values"][$field["name"] . "_upload_web"] ? $values["values"][$field["name"] . "_upload_web"] : "http://"; $field["file_name"] = $values["values"][$field["name"] . "_file"]; $field["target"] = $field["target"] == "self" ? "" : "target=\"_new\"" ; $field["rem_disabled"] = $values["values"][$field["name"] . "_temp"] || $values["values"][$field["name"] . "_temp"] || $values["values"][$field["name"]] ? "" : "disabled"; $image["editable"] = $this->templates->blocks[$file ? "uploadedit" : "imageedit"]->Replace($field); } if ($file) { if (is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"])) { $image["preview"] = $this->templates->blocks["fileshow"]->Replace( array( "name" => $_CONF["url"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_file"], "src" => $_CONF["url"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"] , "target" => $field["target"] == "self" ? "" : "target=\"_new\"" ) ); } else { $file_name = $_CONF["path"] . $_CONF["upload"] . ($field["path"] ? $field["path"] : $field["file"]["path"]) . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"]; $file_url = $_CONF["url"] . $_CONF["upload"] . ($field["path"] ? $field["path"] : $field["file"]["path"]) . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"]; if (file_exists($file_name)) { $image["preview"] = $this->templates->blocks["fileshow"]->Replace( array( "name" => $values["values"][$field["name"] . "_file"] ? $values["values"][$field["name"] . "_file"] : $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"], "src" => $file_url, "target" => $field["target"] == "self" ? "" : "target=\"_new\"" ) ); } else $image["preview"] = $field["error"] ? $field["error"] : "No file uploaded."; } } else { if (is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"])) { $image["preview"] = $this->templates->blocks["imageshow"]->Replace( array( "width" => $field["adminwidth"], "height" => $field["adminheight"] ? ' height="' . $field["adminheight"] . '"' : "", "border" => $field["border"] ? $field["border"] : 0, "src" => $_CONF["url"] . $_CONF["upload"] . "tmp/" . $values["values"][$field["name"] . "_temp"] ) ); } else { if ($values["values"][$field["name"]] && file_exists($_CONF["path"] . $_CONF["upload"] . $field["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"])) { $image["preview"] = $this->templates->blocks["imageshow"]->Replace( array( "width" => $field["adminwidth"], "height" => $field["adminheight"] ? ' height="' . $field["adminheight"] . '"' : "", "border" => $field["border"] ? $field["border"] : 0, "src" => $_CONF["url"] . $_CONF["upload"] . $field["path"] . $field["file"]["default"] . $values["values"][$field["file"]["field"]] . $field["file"]["ext"] ) ); } else { if ($field["default"]) { $image["preview"] = $this->templates->blocks["imageshownolink"]->Replace( array( "width" => $field["adminwidth"], "height" => $field["adminheight"] ? ' height="' . $field["adminheight"] . '"' : "", "border" => $field["border"] ? $field["border"] : 0, "src" => $_CONF["url"] . $_CONF["upload"] . $field["path"] . $field["default"] ) ); } else $image["preview"] = $field["error"] ? $field["error"] : "No image curently available."; } } } $image["temp"] = $values["values"][$field["name"] . "_temp"]; $image["error"] = $field["error"]; $image["name"] = $field["name"]; if (($file == FALSE) && ($field["editable"] == "true") && is_object($this->templates->blocks["image2"])) { $this->templates->blocks["image2"]->Replace($image , false); $current_field = $this->templates->blocks["image2"]->EmptyVars(); } else { $this->templates->blocks["image"]->Replace($image , false); $current_field = $this->templates->blocks["image"]->EmptyVars(); } return $current_field; } function __field__phone($field , $values) { if (!$field["size"]) $field["size"] = $this->__default["show"]["phone"]["size"]; $size = explode("," , $field["size"]); $field["size_1"] = (int) $size[0]; $field["size_2"] = (int) $size[1]; $field["size_3"] = (int) $size[2]; if (is_array($values["values"][$field["name"] . "_arr"])) { $_val = &$values["values"][$field["name"] . "_arr"]; $field["value_1"] = $_val[0]; $field["value_2"] = $_val[1]; $field["value_3"] = $_val[2]; } else { $field["value_1"] = $field["value"] ? substr($field["value"],0,$field["size_1"]) : ""; $field["value_2"] = $field["value"] ? substr($field["value"],$field["size_1"],$field["size_2"]) : ""; $field["value_3"] = $field["value"] ? substr($field["value"],(int)($field["size_1"] + $field["size_2"])) : ""; } $current_field = $this->templates->blocks[$field["editable"] == "false" ? "phoneshow" : "phone"]->Replace($field); return $current_field; } function __field__textarea( $field , $values) { global $_TSM; if (is_array($temp = @explode(":" , $field["size"]))) { $field["_cols"] = $temp["0"]; $field["_rows"] = $temp["1"]; } else { $field["_cols"] = $this->_textareaCols; $field["_rows"] = $this->_textareaRows; } if ($field["readonly"] == "true") $field["readonly"] = " readonly "; else $field["readonly"] = ""; if ($field["html"] == "true") { if ($_GLOBALS["cform_editor_loaded"] != true) { $current_field = $this->templates->blocks["htmlareainit"]->output; $_GLOBALS["cform_editor_loaded"] = true; } $field["value"] = stripslashes($field["value"]); $_TSM["FORMS.PRIVATE.ONLOAD"] .= $this->templates->blocks["htmlareaonload"]->Replace($field); $current_field .= $this->templates->blocks["htmlarea"]->Replace($field); } else { if ($field["width"]) { $field["style"] = " style=\"width:{$field[width]}\" "; } $current_field = $this->templates->blocks["textarea"]->Replace($field); } return $current_field; } function __field__textbox( $field , $values) { if ($field["size"]) { if (is_array($temp = @explode(":" , $field["size"]))) { $field["_size"] = $temp["0"]; $field["_maxlength"] = $temp["1"]; } else { $field["_size"] = $field["size"]; $field["_maxlength"] = $this->_textboxMaxLength; } } else { if ($field["width"]) { } else { $field["_size"] = $this->_textboxSize; $field["_maxlength"] = $this->_textboxMaxLength; } } if ($field["html"] != "true") if (!isset($values["values"][$field["name"] . "_confirm"])) $values["values"][$field["name"] . "_confirm"] = $field["value"]; if ($field["align"]) $field["style"][] = "text-align:{$field[align]}"; if ($field["readonly"] == "true") $field["readonly"] = " readonly "; else $field["readonly"] = ""; if ($field["type"] == "password") { if ($field["show"] == "true") $field["show"] = is_object($this->templates->blocks["password_show"]) ? $this->templates->blocks["password_show"]->Replace($field) : ""; else $field["show"] = ""; } if (is_array($field["style"])) $field["style"] = ' style="' . implode(";" , $field["style"]) . '" '; else $field["style"] = ""; $field["value"] = str_replace("\"" , "&quot;" , $field["value"]); $current_field = $this->templates->blocks[$field["type"]]->Replace($field); return $current_field; } function __field__file($field , $values) { $field["file"] = $values["values"][$field["name"]]; $this->templates->blocks["file"]->Replace($field , false); $current_field = $this->templates->blocks["file"]->EmptyVars(); return $current_field; } function __field__sql($field , $values) { if (is_array($field["sql"])) { $form_sql_vars = array(); if (is_array($field["sql"]["vars"])) { foreach ($field["sql"]["vars"] as $_key => $_val) { if ($_val["action"] == "eval") { eval("\$_val[\"import\"] = " . $_val["default"] .";"); } switch ($_val["type"]) { case "eval": eval("\$form_sql_vars[\"$_key\"] = " . $_val["import"] . ";"); break; case "var": $form_sql_vars[$_key] = $_val["import"]; break; case "page": $form_sql_vars[$_key] = ($_GET[($_val["code"] ? $_val["code"] : 'page')] -1 )* $form['items']; break; case "form": eval("\$form_sql_vars[\"$_key\"] = " . $form[$_val["var"]] . ";"); break; case "field": $form_sql_vars[$_key] = $items[$key][$_val["import"]]; break; } } foreach ($form_sql_vars as $_key => $_val) { $this->templates->blocks["Temp"]->input = $_val; $form_sql_vars[$_key] = $this->templates->blocks["Temp"]->Replace($form_sql_vars); } $this->templates->blocks["Temp"]->input = $field["sql"]["query"]; $sql = $this->templates->blocks["Temp"]->Replace($form_sql_vars); $sql = str_replace("]" , ">" , str_replace("[" , "<" , $sql)); $record = $this->db->QFetchArray($sql); $field["value"] = $record[$field["sql"]["field"]]; } } } function __field__text($field , $values) { if ($field["html"] != "true") { $field["value"] = eregi_replace("([_a-z0-9\-\.]+)@([a-z0-9\-\.]+)\." . "(net|com|gov|mil|org|edu|int|biz|info|name|pro|[A-Z]{2})". "($|[^a-z]{1})", "<a title=\"Click to open the mail client.\" href=\"mailto:\\1@\\2.\\3\">\\1@\\2.\\3</a>\\4", $field["value"]); $field["value"] = eregi_replace("(http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href=\"\\1://\\2\" title=\"Click to open in new window.\" target=\"_blank\">\\2</a>", $field["value"]); $field["value"] = nl2br($field["value"]); } if ($field["html"] != "true") { } if ($field["html_entities_decode"] == "true") $field["value"] = html_entity_decode($field["value"]); if ($field["maxchars"]) { $field["value"] = substr($field["value"],0,$field["maxchars"]) . (strlen($field["value"]) > $field["maxchars"] ? ($field["maxchars_text"] ? $field["maxchars_text"] : $this->__default["list"]["fields"]["maxchars_text"]) : ""); } $field["action"] = $field["subtype"] ? $field["subtype"] : $field["action"]; switch ($field["action"]) { case "date": if (isset($values["values"][$field["name"] . "_day" ]) && isset($values["values"][$field["name"] . "_month" ]) && isset($values["values"][$field["name"] . "_year" ])) $field["value"] = ( $values["values"][$field["name"] . "_month" ] ? sprintf("%02d" ,$values["values"][$field["name"] . "_month" ]) : "--" ). "." . ( $values["values"][$field["name"] . "_day" ] ? sprintf("%02d" ,$values["values"][$field["name"] . "_day" ]) : "--" ) . "." . ( $values["values"][$field["name"] . "_year" ] ? $values["values"][$field["name"] . "_year" ] : "----" ) ; else $field["value"] = $field["value"] > 0 ? @date($field["params"] , $field["value"]) : "not available"; break; case "price": $field["value"] = number_format($field["value"] , 2); break; } switch ($field["font"]) { case "normal": break; default: $field["value"] = "" . $field["value"] . ""; break; } if ($field["nobr"] == "true") $field["value"] = "<nobr>{$field[value]}</nobr>"; $current_field = $this->templates->blocks["text"]->Replace($field , false); return $current_field; } function __field__hidden($field , $values) { $field["hidden"] = "true"; $current_field = $this->templates->blocks["hidden"]->Replace($field , false); return $current_field; } function __field__button($field , $values) { $field["target"] = $field["target"]; $field["title"] = $field["title"]; $field["onmouseover"] = $field["onmouseover"]; $field["onmouseout"] = $field["onmouseout"]; $field["onclick"] = $field["onclick"]; $field["id"] = $field["id"]; $current_field = $this->templates->blocks["button"]->Replace($field , false); return $current_field; } function __field__checkbox($field , $values) { $_value = $field["checked"]; $field["checked"] = $field["value"] == $field["checked"] ? " checked=\"checked\" " : ""; $field["value"] = $_value; $field["check"] = $field["checked"] ? "on" : "off"; if (strstr($field["label"] , "|")) { $tmp = explode("|" , $field["label"]); $field["label"] = $tmp[0]; if ($field["editable"] == "false") $new = true; } if ($new == true) { if ($field["editable"] == "false") { $field["value"] = $field["check"] == "on" ? $tmp[0] : $tmp[1]; $current_field = $this->templates->blocks["text"]->Replace($field , false); } } else { $this->templates->blocks["checkbox" . ($field["editable"] == "false" ? "_show" : "")]->Replace($field , false); $current_field = $this->templates->blocks["checkbox" . ($field["editable"] == "false" ? "_show" : "")]->EmptyVars(); } return $current_field; } function __field__comment($field , $values) { if ($field["value"]) { $field["description"] = nl2br($field["value"]); } if ($field["subtype"] == "extern") { $field["description"] = GetFileContents(dirname($form["xmlfile"]) . "/" . $field["file"]); } else { $field["description"] = preg_replace( array( '(\[)' , '(\])' ), array( "<" , ">" ), $field["description"] ); } $old = $this->templates->blocks["Comment"]->input ; $this->templates->blocks["Comment"]->input = $this->templates->blocks["Comment"]->Replace(array( "COMMENT" => $field["description"], "PADDING" => $field["padding"] ? $field["padding"] : "0", "ALIGN" => $field["align"] )); $this->templates->blocks["Comment"]->input = $this->templates->blocks["Comment"]->Replace($values["values"]); $this->templates->blocks["Comment"]->input = $this->templates->blocks["Comment"]->Replace($_GET); $current_field = $this->templates->blocks["Comment"]->Replace($_POST); $this->templates->blocks["Comment"]->input = $old; return $current_field; } function __field__date($field , $values) { if (($field["now"] == "true") && !$field["value"]) { $field["value"] = time(); } if ($field["editable"] == "false") { $val = &$values["values"]; $k = $field["name"]; if (!isset($val[$k])) { $val[$k] = $field["value"]; } if (is_string($field["fields"])) { $supp_fields = array("month" , "year" , "month_str", "day"); $_tmp_v = ""; foreach ($supp_fields as $__k => $__v) { switch ($__v) { case "month_str": $_tmp_v[$__v] = $form_months[$val[$k . "_month" ]]; break; case "day": $_tmp_v[$__v] = sprintf("%02d" ,$val[$k . "_day" ]); break; case "year": $_tmp_v[$__v] = sprintf("%02d" ,$val[$k . "_year" ]); break; } } $current_field = $field["fields"]; foreach ($_tmp_v as $__k => $__v) { $current_field = str_replace($__k , $__v , $current_field); } } else { if (isset($val[$k . "_month" ]) && isset($val[$k . "_day" ]) && isset($val[$k . "_year" ])) { $current_field = ( $val[$k . "_month" ] ? sprintf("%02d" ,$val[$k . "_month" ]) : "--" ). "/" . ( $val[$k . "_day" ] ? sprintf("%02d" ,$val[$k . "_day" ]) : "--" ) . "/" . ( $val[$k . "_year" ] ? $val[$k . "_year" ] : "----" ) . "  " . ($val[$k . "_hour"] && $val[$k . "_minute"] ? $val[$k . "_hour"] . ":" . $val[$k . "_minute"] : ""); } else { $current_field = $val[$k] > 1000 ? date(($field["params"] ? $field["params"] : "m/d/Y") , $val[$k]) : "not available"; } } } else { if (is_array($field["fields"])) { $html = new CHtml; if (is_array($years)) unset($years); if (is_array($days)) unset($days); if (is_array($months)) unset($months); $date_vals = &$values["values"][$field["name"]]; if (($date_vals < 1000) && isset($field["value"])) { $date_vals = $field["value"]; } if (($date_vals > 1000) || (isset($values["values"][$field["name"] ."_year"]) || isset($values["values"][$field["name"] ."_month"]) || isset($values["values"][$field["name"] ."_day"]))) { $year_selected = isset($values["values"][$field["name"] ."_year"]) ? $values["values"][$field["name"] ."_year"] : @date("Y" , $date_vals ); $month_selected = isset($values["values"][$field["name"] ."_month"]) ? $values["values"][$field["name"] ."_month"] : @date("n" , $date_vals ); $day_selected = isset($values["values"][$field["name"] ."_day"]) ? $values["values"][$field["name"] ."_day"] : @date("j" , $date_vals ); $hour_selected = isset($values["values"][$field["name"] ."_hour"]) ? $values["values"][$field["name"] ."_hour"] : @date("G" , $date_vals ); $minute_selected = isset($values["values"][$field["name"] ."_minute"]) ? $values["values"][$field["name"] ."_minute"] : @date("i" , $date_vals ); $second_selected = isset($values["values"][$field["name"] ."_second"]) ? $values["values"][$field["name"] ."_second"] : @date("s" , $date_vals ); } else { $fld = $field["fields"]; $year_selected = $fld["year"]["default"] == "now" ? date("Y") : $fld["year"]["default"]; $month_selected = $fld["month"]["default"] == "now" ? date("n") : $fld["month"]["default"]; $day_selected = $fld["day"]["default"] == "now" ? date("j") : $fld["day"]["default"]; $hour_selected = $fld["hour"]["default"] == "now" ? date("G") : $fld["hour"]["default"]; $minute_selected = $fld["minute"]["default"] == "now" ? date("i") : $fld["minute"]["default"]; $second_selected = $fld["second"]["default"] == "now" ? date("s") : $fld["second"]["default"]; } if ($field["calendar"] == true) { $current_field = $this->templates->blocks["Calendar"]->Replace(array( "name" => $field["name"], "value" => mktime(1,1,1,$month_selected, $day_selected , $year_selected), "value_day" => $day_selected, "value_month" => $month_selected, "value_year" => $year_selected, "form" => $form["name"] )); } else { foreach ($field["fields"] as $key => $val) { switch ($key) { case "year": if ($field["fields"]["year"]["empty"] == "true") { $years[0] = "--" ; } for ($i = $field["fields"]["year"]["from"] ; $i <= $field["fields"]["year"]["to"] ; $i++ ) $years[$i] = $i; $current_field .= $html->FormSelect( $field["name"]."_year" , $years , $this->templates , "DateSelect", $year_selected , array() , array("DISABLED" => ($field["fields"]["year"]["editable"] == "false") ? "DISABLED" : "") ); $current_field .= $val["separator"]; break; case "day": if ($field["fields"]["day"]["empty"] == "true") { $days[0] = "--" ; } for ($i = 1 ; $i <= 31 ; $i++ ) $days[$i] = sprintf("%02d",$i); $current_field .= $html->FormSelect( $field["name"]."_day" , $days , $this->templates , "DateSelect", $day_selected, array() , array("DISABLED" => ($field["fields"]["day"]["editable"] == "false") ? "DISABLED" : "") ); $current_field .= $val["separator"]; break; case "month": if (($field["fields"]["month"]["empty"] == "true")) { $months[0] = "--" ; } global $form_months; if (is_array($months)) $formmonths = array_merge($months, $form_months); else $formmonths = $form_months; $current_field .= $html->FormSelect( $field["name"]."_month" , $formmonths, $this->templates , "DateSelect", $month_selected, array() , array("DISABLED" => ($field["fields"]["month"]["editable"] == "false") ? "DISABLED" : "") ); $current_field .= $val["separator"]; break; case "hour": for ($i = 0; $i <= 23; $i++ ) $hours[$i] = sprintf("%02d",$i);; $current_field .= $html->FormSelect( $field["name"]."_hour" , $hours , $this->templates , "DateSelect", $hour_selected , array() , array("DISABLED" => ($field["fields"]["hour"]["editable"] == "false") ? "DISABLED" : "") ); $current_field .= $val["separator"]; break; case "minute": for ($i = 0; $i <= 59; $i++ ) $minutes[$i] = sprintf("%02d",$i);; $current_field .= $html->FormSelect( $field["name"]."_minute" , $minutes , $this->templates , "DateSelect", $minute_selected , array() , array("DISABLED" => ($field["fields"]["minute"]["editable"] == "false") ? "DISABLED" : "") ); $current_field .= $val["separator"]; break; case "second": for ($i = 0; $i <= 59; $i++ ) $seconds[$i] = sprintf("%02d",$i);; $current_field .= $html->FormSelect( $field["name"]."_second" , $seconds , $this->templates , "DateSelect", $second_selected , array() , array("DISABLED" => ($field["fields"]["minute"]["editable"] == "false") ? "DISABLED" : "") ); $current_field .= $val["separator"]; break; } } } } } return $current_field; } function __field__creditcard($field , $values) { if (is_array($values["values"][$field["name"] . "_arr"])) { $field["value_group_1"] = $values["values"][$field["name"] . "_arr"]["1"]; $field["value_group_2"] = $values["values"][$field["name"] . "_arr"]["2"]; $field["value_group_3"] = $values["values"][$field["name"] . "_arr"]["3"]; $field["value_group_4"] = $values["values"][$field["name"] . "_arr"]["4"]; } else { switch ($field["show"]) { case "blank": $field["value_group_1"] = ""; $field["value_group_2"] = ""; $field["value_group_3"] = ""; $field["value_group_4"] = ""; break; case "none": $field["value_group_1"] = $field["editable"] == "false" ? "xxxx" : ""; $field["value_group_2"] = $field["editable"] == "false" ? "xxxx" : ""; $field["value_group_3"] = $field["editable"] == "false" ? "xxxx" : ""; $field["value_group_4"] = $field["editable"] == "false" ? "xxxx" : ""; break; case "last": $field["value_group_1"] = $field["editable"] == "false" ? "xxxx" : ""; $field["value_group_2"] = $field["editable"] == "false" ? "xxxx" : ""; $field["value_group_3"] = $field["editable"] == "false" ? "xxxx" : ""; $field["value_group_4"] = substr($field["value"],12,4); break; default: $field["value_group_1"] = substr($field["value"],0,4) ; $field["value_group_2"] = substr($field["value"],4,4); $field["value_group_3"] = substr($field["value"],8,4); $field["value_group_4"] = substr($field["value"],12,4); break; } } $this->templates->blocks[$field["editable"] == "false" ? "cc_show" : "cc"]->Replace($field , false); $current_field = $this->templates->blocks[$field["editable"] == "false" ? "cc_show" : "cc"]->EmptyVars(); return $current_field; } function __field__namesort(&$field , &$values) { global $base; switch ($field["content"]) { case "alphanumeric": case "digits": for ($i = 0; $i<= 9; $i++) { $content[] = array("name" => $i , "link" => "javascript:document.forms[" . ($form["name"] ? "'" .$form["name"] . "'": '0') . "].{$field[name]}.value='" . $i. "'"); } if ($field["content"] == "digits") break; case "letters": for ($i = 65; $i<= 90; $i++) { $content[] = array("name" => chr($i) , "link" => "javascript:document.forms[" . ($form["name"] ? "'" .$form["name"] . "'": '0') . "].{$field[name]}.value='" . chr($i). "'"); } break; } if (is_array($content)) { $current_field = $base->html->table( $this->templates, "namesort", $content ); } return $current_field; } function __field__calendar($field , $values) { $calendar_fields = array( "inputField" => '"field_' . $field["name"] . '"', "ifFormat" => '"{DATE}"' , "date" => '{DATE}' , "button" => '"field_' . $field["name"] . '_trigger"', "align" => '"Br"', "singleClick" => 'true', "range" => "[" . date("Y") . "," . (date("Y") + 10). "]", "boxsize" => "10" ); if ($field["calendar"]["time"] == "true") { $calendar_fields["showsTime"] = "true"; $calendar_fields["ifFormat"] = "'{DATE} %H:%M'"; $calendar_fields["date"] = "{DATE} H:i"; $calendar_fields["boxsize"] = 16; } if ($field["calendar"]["range"]) { $tmp = explode(":" , $field["calendar"]["range"]); $calendar_fields["range"] = "[" . trim($tmp[0]) . "," . trim($tmp[1]) . "]"; } if ($_CONF["settings"]["locale"] == "eu"){ $calendar_fields["ifFormat"] = str_replace("{DATE}" , '%d/%m/%Y' , $calendar_fields["ifFormat"]); $calendar_fields["date"] = str_replace("{DATE}" , 'd/m/Y' , $calendar_fields["date"]); } else { $calendar_fields["ifFormat"] = str_replace("{DATE}" , '%m/%d/%Y' , $calendar_fields["ifFormat"]); $calendar_fields["date"] = str_replace("{DATE}" , 'm/d/Y' , $calendar_fields["date"]); } if ($field["calendar"]["style"]) $calendar_fields["style"] = $field["calendar"]["style"]; if ($field["value"] > 1000) $field["value"] = date($calendar_fields["date"] , $field["value"]); else $field["value"] = ""; if ($field["editable"] == "false") { $current_field = $this->templates->blocks["text"]->Replace($field); } else { $size = $calendar_fields["boxsize"]; unset($calendar_fields["boxsize"]); unset($calendar_fields["date"]); $tmp = array(); foreach ($calendar_fields as $c_key => $c_val) { $tmp[] = "\t\t" . $c_key . ":" . $c_val; } $current_field = $this->templates->blocks["calendar"]->Replace( array_merge( $field , array( "_params" => implode(",\n" , $tmp), "boxsize" => $size ) ), FALSE ); } return $current_field; } function __private_uploads_pre($field , $_fields = array()) { global $_CONF , $base; $key = $field["name"]; $val = $field; switch ($_POST[$key . "_radio_type"]) { case 0: if (is_array($_FILES[$key . "_upload_client"]) && is_uploaded_file($_FILES[$key . "_upload_client"]["tmp_name"])) { $img = &$_FILES[$key . "_upload_client"]; $name = $_POST[$key . "_temp"] != "" ? $_POST[$key . "_temp"] : $key . $val["file"]["default"] . time() . $val["file"]["ext"]; if ($val["process"]) { $base->image->Resize( $img["tmp_name"] , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name, $val["process"]["width"], strtoupper($val["process"]["force"]) , null , null , null, null , $val["process"]["quality"] ? $val["process"]["quality"] : null , null, $val["process"]["watermark"], $val["process"]["height"] ); } else @copy($img["tmp_name"] , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name ); $_file_name = $img["tmp_name"]; if ($val["tn"]["generate"] == "true") { $base->image->Resize( $img["tmp_name"] , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $name , $val["tn"]["width"] ); $_POST["tn_" . $key] = "1"; } chmod ($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , 0777); $_fields["values"][$key . "_temp"] = $name; $_POST[$key . "_temp"] = $name; $_POST[$key . "_file"] = $_FILES[$key . "_upload_client"]["name"]; $_POST[$key] = "1"; @$size = getimagesize($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name); if (is_array($size)) { $_POST[$key . "_width"] = $size[0]; $_POST[$key . "_height"] = $size[1]; } } break; case "1": if ($_POST[$key . "_upload_web"] != "http://") { $image = @GetFileContents($_POST[$key . "_upload_web"]); $name = $_POST[$key . "_temp"] != "" ? $_POST[$key . "_temp"] : $key . $val["file"]["default"] . time() . $val["file"]["ext"]; SaveFileContents( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , $image); chmod ($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , 0777); if ($val["process"]) { $base->image->Resize( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name . "resize" , $val["process"]["width"], strtoupper($val["process"]["force"]) ); unlink($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name); rename($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name . "resize" , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name); } $_file_name = $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name ; if ($val["tn"]["generate"] == "true") { @$base->image->Resize( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $name , $val["tn"]["width"] ); $_POST["tn_" . $key] = "1"; } $_fields["values"][$key . "_temp"] = $name; $_POST[$key . "_temp"] = $name; $_POST[$key . "_file"] = basename($_POST[$key . "_upload_web"]); $_POST[$key] = "1"; @$size = getimagesize($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name); if (is_array($size)) { $_POST[$key . "_width"] = $size[0]; $_POST[$key . "_height"] = $size[1]; } } break; case "-1": if (file_exists($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]) && is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"])) @unlink($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]); else @unlink($_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"]); $_fields["values"][$key . "_radio_type"] = 0; $_POST[$key] = 0; $_fields["values"][$key . "_temp"] = ""; $_POST[$key . "_temp"] = ""; $_POST[$key . "_file"] = ""; break; } if ($field["type"] == "image") { if ($_POST[$key . "_temp"] && !$file) { $img = @GetImageSize($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]); if (!is_array($img)) { @unlink($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]); $_POST[$key . "_temp"] = ""; $_POST[$key] = 0; } } } } function __private_uploads_after($field) { global $base, $_CONF; $val = $field; $key = $field["name"]; $source = $_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]; $destination = $_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"]; if (!is_file($source)) return false; if (is_file($destination)) { @unlink($destination); } @copy( $source , $destination ); @chmod ($destination , 0777); if ($val["tn"]["generate"] == "true") { @rename( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $_POST[$key . "_temp"] , $_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["tn"]["preffix"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"] ); } if (is_array($val["thumbnails"])) { foreach ($val["thumbnails"] as $__k => $__thumbnail) { @unlink($_CONF["path"] . $_CONF["upload"] . $val["path"] . $__thumbnail["preffix"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"]); if ($__thumbnail["crop"] == "true") @$base->image->Crop( $source, $_CONF["path"] . $_CONF["upload"] . $val["path"] . $__thumbnail["preffix"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"], $__thumbnail["width"], null, null, null, null, null, null, $__thumbnail["quality"] ? $__thumbnail["quality"] : null , $__thumbnail["watermark"], $__thumbnail["height"] ); else @$base->image->Resize( $source , $_CONF["path"] . $_CONF["upload"] . $val["path"] . $__thumbnail["preffix"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"], $__thumbnail["width"], null, null, null, null, null, null, $__thumbnail["quality"] ? $__thumbnail["quality"] : null , $__thumbnail["watermark"], $__thumbnail["height"] ); chmod($_CONF["path"] . $_CONF["upload"] . $val["path"] . $__thumbnail["preffix"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"] , 0777); } } @unlink($source); return true; } } class CFormSettings extends CForm{ function CFormSettings($xml , $templates , $db , $tables) { parent::CForm($templates, $db , $tables,$xml); $this->name = "formsettings"; $this->method = strtoupper($this->form["method"] ? $this->form["method"] : "post"); } function Show($values , $extra = array()) { if (is_array($this->_errors)) { $edit = true; } else { if ($_SERVER["REQUEST_METHOD"] == "POST") { $location = new CTemplate($this->form["redirect"] , "string"); URLRedirect($location->Replace(parent::GlobalVars($this->form)) , "js"); } else $edit = $_GET["action"] == "edit" || $_GET["action"] == "store" ? true : false; } if ($edit == false) { if (is_array($this->form["fields"])) { parent::__private__showonly(&$this->form); } if (!$_GET["returnurl"]) unset($this->form["buttons"]["back"]); unset($this->form["buttons"]["save"]); unset($this->form["action"]); } else { unset($this->form["buttons"]["edit"]); } return parent::Show( $this->form , is_array($this->_errors) ? $this->_errors : array( "values" => $values, "error" => $this->error ), $extra ); } function Validate() { if ($_SERVER["REQUEST_METHOD"] != $this->method) return 1; if ($this->method == "GET" ) $data = &$_GET ; else $data = &$_POST; CForm::ProcessVariables($this->form, $data); $this->_errors = parent::Validate($this->form , $data); $this->valid = !(int)is_array($this->_errors); } function Done() { $this->Validate(); $this->Uploads(); if ($this->valid) { if ($_SERVER["REQUEST_METHOD"] == "POST") { $this->DoUploads(); return true; } } return false; } function Uploads() { if (is_array($this->form["fields"])) { foreach ($this->form["fields"] as $key => $val) { if (!$val["name"]) $val["name"] = $key; switch ($val["type"]) { case "upload": case "image": $this->__private_uploads_pre($val); break; } } } } function DoUploads() { if (is_array($this->form["fields"])) { foreach ($this->form["fields"] as $key => $val) { if (!$val["name"]) $val["name"] = $key; switch ($val["type"]) { case "upload": case "image": $this->__private_uploads_after($val); unset($_POST["portfolio_img_temp"]); unset($_POST["portfolio_img_radio_type"]); unset($_POST["portfolio_img_upload_web"]); break; } } } } function DoEvents(){ } } class CHTML { function CustomPaging($template , $preffix = "" , $show = 10 , $pages , $current , $link , $jump = true) { if ($pages <= 1) { return ""; } $tpl = &$template; $adjacents = 3; $limit = 1; $page = $current; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($pages / $limit); $lpm1 = $lastpage - 1; if (is_array($link)) { $link0 = $link["first"]; $link1 = $link["all"]; $link2 = $link["last"] ? $link["last"] : $link["all"]; $link3 = $link["jump"]; } else $link0 = $link1 = $link2 = $link; if($lastpage > 1) { if ($page > 1) { $html.= $tpl->blockReplace( $preffix . "Back" , array( "url" => CTemplateStatic::Replace( $current == 2 ? $link0 : $link1 , array("page" => $prev )), "page" => $prev ) ); } else { $html.= $tpl->blockReplace( $preffix . "BackDisabled" , array( "page" => $prev ) ); } if ($lastpage < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == 1) { $tmp_link = $link0; } else { if ($counter == $lastpage) $tmp_link = $link2; else $tmp_link = $link1; } if ($counter == $page) $html .= $tpl->blockReplace( $preffix . "PageCurrent" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); else $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); } } elseif($lastpage >= 7 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 3)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == 1) { $tmp_link = $link0; } else { if ($counter == $lastpage) $tmp_link = $link2; else $tmp_link = $link1; } if ($counter == $page) $html .= $tpl->blockReplace( $preffix . "PageCurrent" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); else $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); } $html .= $tpl->blockReplace( $preffix . "Dots" , array() ); $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => $lpm1 )), "page" => $lpm1 ) ); $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => $lastpage )), "page" => $lastpage ) ); } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link0 , array("page" => 1 )), "page" => 1 ) ); $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => 2 )), "page" => 2 ) ); $html .= $tpl->blockReplace( $preffix . "Dots" , array() ); for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == 1) { $tmp_link = $link0; } else { if ($counter == $lastpage) $tmp_link = $link2; else $tmp_link = $link1; } if ($counter == $page) $html .= $tpl->blockReplace( $preffix . "PageCurrent" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); else $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); } $html .= $tpl->blockReplace( $preffix . "Dots" , array() ); $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => $lpm1 )), "page" => $lpm1 ) ); $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => $lastpage )), "page" => $lastpage ) ); } else { $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link0 , array("page" => 1 )), "page" => 1 ) ); $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => 2 )), "page" => 2 ) ); $html .= $tpl->blockReplace( $preffix . "Dots" , array() ); for ($counter = $lastpage - (1 + ($adjacents * 3)); $counter <= $lastpage; $counter++) { if ($counter == 1) { $tmp_link = $link0; } else { if ($counter == $lastpage) $tmp_link = $link2; else $tmp_link = $link1; } if ($counter == $page) $html .= $tpl->blockReplace( $preffix . "PageCurrent" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); else $html .= $tpl->blockReplace( $preffix . "Page" , array( "url" => CTemplateStatic::Replace( $tmp_link , array("page" => $counter )), "page" => $counter ) ); } } } if ($page < $lastpage) { $html.= $tpl->blockReplace( $preffix . "Next" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => $next )), "page" => $next ) ); } else { $html.= $tpl->blockReplace( $preffix . "NextDisabled" , array( "url" => CTemplateStatic::Replace( $link1 , array("page" => $next )), "page" => $next ) ); } } return $tpl->blockReplace( $preffix . "Main" , array( "data" => $html, "jump" => $jump ? $tpl->blockReplace( $preffix . "Jump" , array( "url" => $link1, ) ) : "" ) ); } function Paging($template,$ic,$ipp,$cp,$vars,$pn = TRUE) { if ($ipp == 0) return ""; if ($ic > $ipp) { $result = ""; if (!is_object($template)) { $template = new CTemplate($template); } $tpl_normal = $template->blocks["Page"]; $tpl_active = $template->blocks["PageActive"]; $pc = round(ceil($ic / $ipp)); if ($cp < 1) $cp = 1; elseif ($cp > $pc) $cp = $pc; for ($i = 0; $i < $pc; $i++) { $pn = $i + 1; $tpl = ($pn == $cp) ? $tpl_active : $tpl_normal; $vars["PAGE"] = $pn; $vars["FACE"] = $pn; $result .= $tpl->Replace($vars); } if ($pn == TRUE) { if ($cp > 1) { $vars["PAGE"] = $cp - 1; $vars["FACE"] = $template->blocks["Prev"]->output; $result = $tpl_normal->Replace($vars) . $result; } if ($cp < $pc) { $vars["PAGE"] = $cp + 1; $vars["FACE"] = $template->blocks["Next"]->output; $result .= $tpl_normal->Replace($vars); } } $return["ITEM_COUNT"] = $ic; $return["CURRENT_PAGE"] = $cp; $return["PAGE_COUNT"] = $pc; $return["PAGES"] = $result; return $template->blocks["Main"]->Replace($return); } else return ""; } function FormSelect($name,$vars,$template,$block,$selected = "",$extra_vars = array(), $global_vars = array()) { if (is_array($vars)) foreach ($vars as $key => $val) { $replace = array( "VALUE" => $key, "NAME" => $val, "SELECTED" => (($key == $selected) ? " selected=\"selected\"" : "") ); if (is_array($extra_vars[$key])) $replace = array_merge($replace,$extra_vars[$key]); $options .= $template->blocks["{$block}Option"]->Replace($replace); } if (count($global_vars) != 0) $select = $global_vars; $select["NAME"] = $name; $select["OPTIONS"] = $options; return $template->blocks["$block"]->Replace($select); } function Select( $template, $block, $values , $selected = "", $extra = array() ) { if (is_array($values)) { $_values = array(); if ($values["fields"]) { $__field__title = $values["fields"]["title"]; $__field__value = $values["fields"]["value"]; $values = $values["items"]; unset($values["fields"]); } else { $__field__title = "title"; $__field__value = "value"; } if (!$template->blockExists($block . "OptionSelected")) $__selected = $block . "Option"; else $__selected = $block . "OptionSelected"; $__normal = $block . "Option"; $__main = $block ; if (is_array($values)){ foreach ($values as $key => $val) { if (!is_array($val)) $_values[] = array($__field__title =>$val , $__field__value => $key); else $_values[] = $val; } $values = $_values; foreach ($values as $key => $val) $output .= $template->BlockReplace( ($selected == $val[$__field__value] ? $__selected : $__normal) , array( "title" => $val[$__field__title], "value" => $val[$__field__value] ) ); } $return = $template->blockReplace($__main , array ("options" => $output ) ); if (is_array($extra) && count($extra)) return CTemplateStatic::Replace($return , $extra); else return $return; } return ""; } function Table($template,$template_block,$data,$has_paging = FALSE,$element_count = 0,$elements_per_page = 0,$page = 0,$paging_template = NULL,$paging_vars = array()) { if (is_array($data) && count($data)) { foreach ($data as $element) $return .= $template->BlockReplace($template_block . "Element",$element); $group = "Group"; } else { $return = $template->BlockReplace($template_block . "Empty" , array()); $group = "Group" . ( $template->blockExists($template_block . "GroupEmpty") ? "Empty" : ""); } if ($has_paging == TRUE) { $paging = $this->Paging($paging_template,$element_count,$elements_per_page,$page,$paging_vars); return $template->BlockReplace( $template_block . $group, array( "DATA" => $return, "PAGING" => $paging ) ); } else { return $template->BlockReplace( $template_block . $group, array( "DATA" => $return, ) ); } } function TableSimple($template,$block,$items,$vars = array(),$filler_func = NULL,$paging = NULL,$page = 0,$tic = 0,$paging_vars = array()) { $item_count = count($items); if (is_array($items)) { foreach ($items as $item) { if (is_array($filler_func) && is_array($item)) call_user_func($filler_func,&$item); if ($template->dynamic) $rows .= $template->BlockReplace("{$block}Row",$item); else $rows .= $template->blocks["{$block}Row"]->Replace($item); } } else if ($template->dynamic) $rows .= $template->BlockReplace("{$block}Row",$item); else $rows = $template->blocks["{$block}Empty"]->output; $_paging = ($paging != NULL) ? $this->Paging($paging,$tic,$item_count,$page,$paging_vars) : ""; return $template->blocks[$block]->Replace(array_merge(array("ROWS" => $rows, "PAGING" => $_paging),$vars)); } function TableLight($template,$block,$data) { if ($data == "") return ""; else { foreach ($data as $item) $rows .= $template->blocks["{$block}Row"]->Replace($item); return $template->blocks[$block]->Replace(array("ROWS" => $rows)); } } function TableComplex($template,$block,$items,$rc,$cc,$vars = array(),$filler_func = NULL,$paging = NULL,$page = 0,$tic = 0,$paging_vars = array()) { $item_count = count($items); if (is_array($items)) { $row_count = ceil(count($items) / $cc); $column_count = $cc ; $columns = ""; $rows = ""; $key = 0; for ($i = 0; $i < $row_count; $i++) { for ($j = 0; $j < $column_count; $j++) { $item = $items[$key]; if (is_array($filler_func) && is_array($item)) call_user_func($filler_func,&$item); $columns .= (is_array($item)) ? $template->blocks["Column"]->Replace($item) : $template->blocks["ColumnEmpty"]->output; $key++; } $rows .= $template->blocks["Row"]->Replace(array("COLUMNS" => $columns)); $columns = ""; } } else $rows = $template->blocks["Empty"]->output; $_paging = ($paging != NULL) ? $this->Paging($paging,$tic,$rc*$cc,$page,$paging_vars) : ""; return $template->blocks[$block]->Replace(array_merge(array("ROWS" => $rows, "PAGING" => $_paging),$vars)); } function error($template,$id) { return $template->blocks[$id]->output; } function FormRadio($template,$block,$name,$vars) { if (is_array($vars)) { foreach ($vars as $key => $val) { $vars[$key]["name"] = $name; } return $this->Table($template, $block , $vars); } return ""; } } class CImage { var $name; var $types; function CImage() { $this->name = "image"; $this->types = array ( "0" => "unknown", "1" => "gif", "2" => "jpg", "3" => "png", "4" => "swf", "5" => "psd", "6" => "bmp", "7" => "tiff", "8" => "tiff", "9" => "jpc", "10" => "jp2", "11" => "jpx", "12" => "jb2", "13" => "swc", "14" => "iff", "15" => "wbmp" ); } function GetType($image,$return_type = 1) { $data = GetImageSize($image); return ($return_type == 1 ? $this->types[$data["2"]] : ($data ? $data["2"] : 0)); } function GetData($filename) { if (defined("PB_IMAGE_MAGICK")) { $file_name = md5(uniqid($filename)); exec ( PB_IMAGE_MAGICK_PATH . "convert.exe -quality 100 " . $filename . " " . PB_IMAGE_MAGICK_TMP . $file_name . ".jpg" , $out); if (file_exists(PB_IMAGE_MAGICK_TMP . $file_name . ".jpg")) { $image = ImageCreateFromJPEG(PB_IMAGE_MAGICK_TMP . $file_name . ".jpg"); unlink (PB_IMAGE_MAGICK_TMP . $file_name . ".jpg"); return $image; } else { $count = 0; while (!file_exists(PB_IMAGE_MAGICK_TMP . $file_name . ".jpg." . $count) && ($count < 20 )) $count ++; if (file_exists(PB_IMAGE_MAGICK_TMP . $file_name . ".jpg." . $count)) { $image = ImageCreateFromJPEG(PB_IMAGE_MAGICK_TMP . $file_name . ".jpg." . $count ); $count = 0; while (file_exists(PB_IMAGE_MAGICK_TMP . $file_name . ".jpg." . $count) && ($count < 100 )) { unlink (PB_IMAGE_MAGICK_TMP . $file_name . ".jpg." . $count); $count ++; } return $image; } else { } } return ""; } $type = $this->GetType($filename); switch ($type) { case "gif": return ImageCreateFromGIF($filename); break; case "jpg": return ImageCreateFromJPEG($filename); break; case "png": return ImageCreateFromPNG($filename); break; case "bmp": return ImageCreateFromBMP($filename); break; case "wbmp": return ImageCreateFromWBMP($filename); break; case "bmp": break; } return false; } function Crop( $source , $destination , $resize_width , $resize_force = NULL, $border = NULL , $shadow = NULL , $texture = NULL , $texture_tile = NULL , $background = NULL , $quality = NULL , $watermark = array (), $resize_height = NULL ) { $resize = true; if (!(int) $quality) $quality = 90; if (extension_loaded("gd")) { if (!$resize_height) $resize_height = $resize_width; $size = max($resize_width , $resize_height); if (file_exists($source)) { $src_img = $this->GetData($source); if ($src_img === false) return false; if ($resize == true) { $width = ImageSX($src_img); $height = ImageSY($src_img); $oRatio = $width / $height; $nRatio = $resize_width / $resize_height; if ($oRatio > $nRatio) { $nWidth = (int)$resize_width * ( $oRatio / $nRatio ); $nHeight = $resize_height; } else { $nHeight = (int)$resize_height * ( $nRatio / $oRatio ); $nWidth = $resize_width; } $im = ImageCreateTrueColor ($nWidth,$nHeight); ImageCopyResampled($im,$src_img,0,0,0,0,$nWidth,$nHeight,$width,$height); @ImageDestroy($src_img); $src_img = $im; } $im = ImageCreateTrueColor ($resize_width,$resize_height); ImageCopy($im,$src_img,0,0,0,0,$resize_width,$resize_height); Imagejpeg($im,$destination,$quality); @ImageDestroy($src_img); @ImageDestroy($im); return true; } } return false; } function CropSquare( $source, $destination, $size, $resize = true, $quality = 90 ) { if (!(int) $quality) $quality = 100; if (extension_loaded("gd")) { if (file_exists($source)) { $src_img = $this->GetData($source); if ($src_img === false) return false; if ($resize == true) { $width = ImageSX($src_img); $height = ImageSY($src_img); if ($width > $height) { $nheight = $size; $nwidth = (int) ( $size * ( $width / $height )); } else { $nwidth = $size; $nheight = (int) ($size * ($height / $width )); } $im = ImageCreateTrueColor ($nwidth,$nheight); ImageCopyResampled($im,$src_img,0,0,0,0,$nwidth,$nheight,$width,$height); @ImageDestroy($src_img); $src_img = $im; } $im = ImageCreateTrueColor ($size,$size); ImageCopy($im,$src_img,0,0,0,0,$size,$size); Imagejpeg($im,$destination,$quality); chmod($destination, 0777); @ImageDestroy($src_img); @ImageDestroy($im); return true; } } return false; } function ResizePro( $source , $destination , $resize_width , $resize_force = NULL, $border = NULL , $shadow = NULL , $texture = NULL , $texture_tile = NULL , $background = NULL , $quality = NULL , $watermark = array (), $resize_height = 0 ) { $resize_force = (($resize_force == "FALSE") || ($resize_force == "TRUE")) ? $resize_force : "FALSE"; $quality = (is_numeric($quality) && ($quality >= 0) && ($guality <= 100)) ? $quality : 90; if (extension_loaded("gd")) { if (!file_exists($source)) { $src_img = ImageCreate($resize_width,$resize_height ? $resize_height : $resize_width); imagestring ( $src_img, 4, 5, ($resize_height / 2), "Error Loading Image", ImageColorAllocate ($src_ig, 0 ,0, 0 )); } else { $src_img= $this->GetData( $source ); if ($scr_img === "") return null; } $src_width = ImageSX($src_img); $src_height = ImageSY($src_img); $ratio = imagesx($src_img) / imagesy($src_img); $new_width = $resize_width; $new_height = $resize_width / $ratio; if ($new_height > $resize_height) { $new_height = $resize_height; $new_width = $resize_height * $ratio; } $new_width = min(round($new_width) , $resize_width); $new_height = min(round($new_height) , $resize_height); $im = ImageCreateTrueColor ($new_width,$new_height); if (function_exists("imageantialias")) { imageantialias($im,true); } (int) ImageCopyResampled( $im, $src_img, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height ); Imagejpeg($im,$destination,$quality); @ImageDestroy($src_img); @ImageDestroy($im); @ImageDestroy($txt_img); } return NULL; } function Resize( $source , $destination , $resize_width , $resize_force = NULL, $border = NULL , $shadow = NULL , $texture = NULL , $texture_tile = NULL , $background = NULL , $quality = NULL , $watermark = array (), $resize_height = 0 ) { $resize_force = (($resize_force == "FALSE") || ($resize_force == "TRUE")) ? $resize_force : "FALSE"; $border = is_numeric($border) ? $border : 0; $shadow = is_numeric($shadow) ? $shadow : 0; $texture = file_exists($texture) ? $texture : NULL; $texture_tile = (($texture_tile == "FALSE") || ($texture_tile == "TRUE")) ? $texture_tile : "FALSE"; $background = (is_array($background) && (count($background) == 3)) ? $background : array("255","255","255"); $quality = (is_numeric($quality) && ($quality >= 0) && ($guality <= 100)) ? $quality : 90; if (extension_loaded("gd")) { if (!file_exists($source)) { $src_img = ImageCreate($resize_width,$resize_width); imagestring ( $src_img, 4, 5, ($resize_height / 2), "Error Loading Image", ImageColorAllocate ($src_ig, 0 ,0, 0 )); } else { $src_img= $this->GetData( $source ); if ($scr_img === "") return null; } if ((ImageSX($src_img) > $resize_width) || ($resize_force == "TRUE")) { $width = $resize_width; if ($height == 0) $height = ImageSY($src_img) * ($resize_width / ImageSX($src_img) ); } else { $width = ImageSX($src_img); $height = ImageSY($src_img); } $im = ImageCreateTrueColor ($width,$height); if (function_exists("imageantialias")) { imageantialias($im,true); } if ($texture&&file_exists($texture)) { $txt_img = $this->GetData($texture); if ($texture_tile == "TRUE") { } else ImageCopyResampled($im,$txt_img,0,0,0,0,$width+1,$height,ImageSX($txt_img),ImageSY($txt_img)); } else ImageFilledRectangle ($im, 0, 0, $width, $height, ImageColorAllocate ($im, $background["0"], $background["1"], $background["2"])); if ($shadow) { $new_width = $width - $shadow + 1; $new_height = $height - $shadow + 1; } else { $new_width = $width - $shadow; $new_height = $height - $shadow; } ImageCopyResampled($im,$src_img,0,0,0,0,$new_width,$new_height,ImageSX($src_img),ImageSY($src_img)); if ($shadow) for ($i = 0 ; $i<$shadow ; $i++ ) { $factor = 0; $color = ImageColorAllocate ($im, 0+($i*$factor), 0+($i*$factor), 0+($i*$factor)); ImageLine ($im,$shadow,$height-$shadow+$i,$width-$shadow+$i,$height-$shadow+$i,$color); ImageLine ($im,$width-$shadow+$i,$shadow,$width-$shadow+$i,$height-$shadow+$i,$color); } if ($border) { ImageSetThickness ($im , $border); $position = round(ceil($border/2)) ; ImageRectangle ($im,$position - 1,$position - 1,$new_width - $position,$new_height - $position,ImageColorAllocate($im,0,0,0)); } if (count($watermark)) { if (file_exists($watermark["file"])) { $watermark["pos_y"] = in_array($watermark["pos_y"], array("bottom" , "top" , "middle" , "random")) ? $watermark["pos_y"] : "bottom"; $watermark["pos_x"] = in_array($watermark["pos_x"], array("left" , "right" , "center" , "random")) ? $watermark["pos_x"] : "right"; $wmImg = imagecreatefrompng($watermark["file"]); imageAlphaBlending($wmImg, false); imageSaveAlpha($wmImg, true); switch ($watermark["pos_y"]) { case "bottom": $wmY = imageSY($im) - imageSY($wmImg); break; case "top": $wmY = 0; break; case "middle": $wmY = (int) ((imageSY($im) - imageSY($wmImg)) / 2); break; case "random": $wmY = (bool)rand(0,1) ? $margin : (imageSY($im) - imageSY($wmImg)); break; } switch ($watermark["pos_x"]) { case "left": $wmX = 0; break; case "center": $wmX = (int) ((imageSX($im) - imageSX($wmImg)) / 2); break; case "right": $wmX = imageSX($im) - imageSX($wmImg) ; break; case "random": $wmX = (bool)rand(0,1) ? $margin : (imageSX($im) - imageSX($wmImg)); break; } imageCopy($im, $wmImg, $wmX, $wmY, 0, 0, imageSX($wmImg), imageSY($wmImg)); } } Imagejpeg($im,$destination,$quality); @ImageDestroy($src_img); @ImageDestroy($im); @ImageDestroy($txt_img); } else { if (PB_IMAGE_MAGICK) { $image_data = GetImageSize($source); $border_cmd = $border ? " -bordercolor black -border " . $border . "x" . $border . " " : " "; $resize_cmd = (($image_data[0] > $resize_width) || ($resize_force == "TRUE")) ? " -resize " . $resize_width ." " : ($border ? " -resize " . ($image_data[0] - ($border * 2)) ." " : ""); $tmp_file = PB_MAGE_MAGICK_TMP . md5(uniqid($source)) . ".jpg"; $comand_line = PB_IMAGE_MAGICK_PATH . "convert " . $resize_cmd . " " . $source . " " . $border_cmd . " " . $tmp_file; if ($border_cmd || $resize_cmd) { exec ($command_line); $source = $tmp_file; } if ($shadow) { } } else @copy ($source, $destination); } return NULL; } function imageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { $scaleX = ($src_w - 1) / $dst_w; $scaleY = ($src_h - 1) / $dst_h; $scaleX2 = $scaleX / 2.0; $scaleY2 = $scaleY / 2.0; $tc = imageistruecolor($src_img); for ($y = $src_y; $y < $src_y + $dst_h; $y++) { $sY = $y * $scaleY; $siY = (int) $sY; $siY2 = (int) $sY + $scaleY2; for ($x = $src_x; $x < $src_x + $dst_w; $x++) { $sX = $x * $scaleX; $siX = (int) $sX; $siX2 = (int) $sX + $scaleX2; if ($tc) { $c1 = imagecolorat($src_img, $siX, $siY2); $c2 = imagecolorat($src_img, $siX, $siY); $c3 = imagecolorat($src_img, $siX2, $siY2); $c4 = imagecolorat($src_img, $siX2, $siY); $r = (($c1 + $c2 + $c3 + $c4) >> 2) & 0xFF0000; $g = ((($c1 & 0xFF00) + ($c2 & 0xFF00) + ($c3 & 0xFF00) + ($c4 & 0xFF00)) >> 2) & 0xFF00; $b = ((($c1 & 0xFF) + ($c2 & 0xFF) + ($c3 & 0xFF) + ($c4 & 0xFF)) >> 2); imagesetpixel($dst_img, $dst_x + $x - $src_x, $dst_y + $y - $src_y, $r+$g+$b); } else { $c1 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX, $siY2)); $c2 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX, $siY)); $c3 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX2, $siY2)); $c4 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX2, $siY)); $r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red'] ) << 14; $g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) << 6; $b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue'] ) >> 2; imagesetpixel($dst_img, $dst_x + $x - $src_x, $dst_y + $y - $src_y, $r+$g+$b); } } } } } if(!function_exists('imagecreatefrombmp')){ function ConvertBMP2GD($src, $dest = false) { if(!($src_f = fopen($src, "rb"))) { trigger_error("Can't open $src", E_WARNING); return false; } if(!($dest_f = fopen($dest, "wb"))) { trigger_error("Can't open $dest", E_WARNING); return false; } $header = unpack("vtype/Vsize/v2reserved/Voffset", fread($src_f, 14)); $info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyr

es/Vncolor/Vimportant", fread($src_f, 40)); extract($info); extract($header); if($type != 0x4D42) { return false; } $palette_size = $offset - 54; $ncolor = $palette_size / 4; $gd_header = ""; $gd_header .= ($palette_size == 0) ? "\xFF\xFE" : "\xFF\xFF"; $gd_header .= pack("n2", $width, $height); $gd_header .= ($palette_size == 0) ? "\x01" : "\x00"; if($palette_size) { $gd_header .= pack("n", $ncolor); } $gd_header .= "\xFF\xFF\xFF\xFF"; fwrite($dest_f, $gd_header); if($palette_size) { $palette = fread($src_f, $palette_size); $gd_palette = ""; $j = 0; while($j < $palette_size) { $b = $palette{$j++}; $g = $palette{$j++}; $r = $palette{$j++}; $a = $palette{$j++}; $gd_palette .= "$r$g$b$a"; } $gd_palette .= str_repeat("\x00\x00\x00\x00", 256 - $ncolor); fwrite($dest_f, $gd_palette); } $scan_line_size = (($bits * $width) + 7) >> 3; $scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size & 0x03) : 0; for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) { fseek($src_f, $offset + (($scan_line_size + $scan_line_align) * $l)); $scan_line = fread($src_f, $scan_line_size); if($bits == 24) { $gd_scan_line = ""; $j = 0; while($j < $scan_line_size) { $b = $scan_line{$j++}; $g = $scan_line{$j++}; $r = $scan_line{$j++}; $gd_scan_line .= "\xFF$r$g$b"; } } else if($bits == 32) { $gd_scan_line = ""; $j = 0; while($j < $scan_line_size) { $b = $scan_line{$j++}; $g = $scan_line{$j++}; $r = $scan_line{$j++}; $a = chr(255 - ord($scan_line{$j++})); $gd_scan_line .= "$a$r$g$b"; } } else if($bits == 8) { $gd_scan_line = $scan_line; } else if($bits == 4) { $gd_scan_line = ""; $j = 0; while($j < $scan_line_size) { $byte = ord($scan_line{$j++}); $p1 = chr($byte >> 4); $p2 = chr($byte & 0x0F); $gd_scan_line .= "$p1$p2"; } $gd_scan_line = substr($gd_scan_line, 0, $width); } else if($bits == 1) { $gd_scan_line = ""; $j = 0; while($j < $scan_line_size) { $byte = ord($scan_line{$j++}); $p1 = chr((int) (($byte & 0x80) != 0)); $p2 = chr((int) (($byte & 0x40) != 0)); $p3 = chr((int) (($byte & 0x20) != 0)); $p4 = chr((int) (($byte & 0x10) != 0)); $p5 = chr((int) (($byte & 0x08) != 0)); $p6 = chr((int) (($byte & 0x04) != 0)); $p7 = chr((int) (($byte & 0x02) != 0)); $p8 = chr((int) (($byte & 0x01) != 0)); $gd_scan_line .= "$p1$p2$p3$p4$p5$p6$p7$p8"; } $gd_scan_line = substr($gd_scan_line, 0, $width); } fwrite($dest_f, $gd_scan_line); } fclose($src_f); fclose($dest_f); return true; } class MemoryStream { var $position; var $varname; var $buffer; function stream_open($path, $mode, $options, &$opened_path) { $url = parse_url($path); $this->varname = $url["host"]; $this->position = 0; $this->buffer = @$GLOBALS[$this->varname]; return true; } function stream_close() { $GLOBALS[$this->varname] = $this->buffer; } function stream_read($count) { $ret = substr($this->buffer, $this->position, $count); $this->position += strlen($ret); return $ret; } function stream_write($data) { $this->buffer .= $data; $this->position += strlen($data); return strlen($data); } function stream_tell() { return $this->position; } function stream_eof() { return $this->position >= strlen($this->buffer); } function stream_stat() { return array( 'size' => strlen($this->buffer) ); } } function imagecreatefrombmp($filename) { if(function_exists('stream_wrapper_register') && stream_wrapper_register("mem", "MemoryStream")) { $tmp_name = "mem://GD_TMP_FILE"; $del_tmp = false; } else { $tmp_name = tempnam("/tmp", "GD"); $del_tmp = true; } if(ConvertBMP2GD($filename, $tmp_name)) { $img = imagecreatefromgd($tmp_name); if($del_tmp) { unlink($tmp_name); } return $img; } return false; } } if(!function_exists('imagebmp')){ function imagebmp($im,$dir="") { $pix = ""; for($y=imagesy($im)-1;$y>=0;$y--) { for($x=0;$x<imagesx($im);$x++) { $rgb = ImageColorAt($im, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $pix .= pack("C3",$b,$g,$r); } } $header = pack("Vv2VVVVvvVVVVVV",strlen($pix)+54,0,0,54,40,imagesx($im),imagesy($im),1,24,0,strlen($pix),0,0,0,0); if ($dir != "") { $inF = fopen($dir,"w"); fwrite($inF,"BM".$header.$pix); fclose($inF); } else echo "BM".$header.$pix; } } class CLibrary { var $name; function CLibrary($name) { $this->name = $name; } } class CMenu extends CXMLParser { var $data; var $src; var $state_base; var $item_base; var $states; var $items; var $body; function CMenu($file = "",$active = "") { parent::CXMLParser(); if ($file != "") { $this->Load($file); $this->Build($active); } } function HNDTagOpen($parser,$tag,$attr) { parent::HNDTagOpen($parser,$tag,$attr); switch ($tag) { case "MENU": $this->src = $attr["SRC"]; break; case "STATES": $this->state_base = $attr["BASE"]; break; case "ITEMS": $this->item_base = $attr["BASE"]; break; } } function HNDCData($parser,$cdata) { switch ($this->tag) { case "NORMAL": case "OVER": case "ACTIVE": $this->states[$this->tag] = $cdata; break; case "ITEM": $this->items[$cdata]["alt"] = $this->attr["ALT"]; $this->items[$cdata]["href"] = $this->attr["HREF"]; break; } } function Load($file) { parent::Parse($this->data = GetFileContents($file)); } function Build($active) { $this->body = ""; $tpl = new CTemplate($this->src); $tpl_normal = new CTemplate($this->state_base . $this->states["NORMAL"]); $tpl_active = new CTemplate($this->state_base . $this->states["ACTIVE"]); foreach ($this->items as $key => $item) { if ($key == $active) $tpl_item = $tpl_active; else $tpl_item = $tpl_normal; $vars = array ( "HREF" => $item["href"], "NAME" => $key, "ALT" => $item["alt"] ); $this->body .= $tpl_item->Replace($vars); } $this->body = $tpl->ReplaceSingle("ITEMS",$this->body); } } class CModule { var $tplvars; var $templates; var $tables; var $vars; var $db; var $messages; var $admin; function CModule($name) { $this->name = $name; } function __init() { $this->path = _MODPATH . $this->name . "/" ; $_CONF["forms"]["adminpath"] = _MODPATH . $_MOD . "/forms/"; if (file_exists( $this->path . "/" . "module.xml")) { $this->config = new CConfig($this->path . "module.xml"); $this->_CONF = $this->config->vars["module"]; if ($this->admin) $this->config->vars["module"]["templates"] = is_array($this->config->vars["module"]["admin"]["templates"]) ? $this->config->vars["module"]["admin"]["templates"] : $this->config->vars["module"]["templates"]; else $this->config->vars["module"]["templates"] = is_array($this->config->vars["module"]["site"]["templates"]) ? $this->config->vars["module"]["site"]["templates"] : $this->config->vars["module"]["templates"]; if (is_array($this->config->vars["module"]["templates"])) { if ($perm = strtolower($this->config->vars["module"]["templates"]["perm"])) { unset($this->config->vars["module"]["templates"]["perm"]); } foreach ($this->config->vars["module"]["templates"] as $key => $val) { if (($key != "path") && ($key != "perm")) { $template = isset($this->config->vars["module"]["templates"]["path"]) ? $this->config->vars["module"]["templates"]["path"] . $val : $this->path . "/templates/" . $val ; if ($perm == "false") $this->private->templates[$key] = new CTemplateDynamic( $template); else $this->private->templates[$key] = new CTemplate( $template); } } } if (is_array($this->config->vars["module"]["database"])) { $this->private->db = new CDatabase($this->config->vars["module"]["database"]); } if ($this->admin) $this->private->tables = is_array($this->config->vars["module"]["admin"]["tables"]) ? $this->config->vars["module"]["admin"]["tables"] : $this->config->vars["module"]["tables"]; else $this->private->tables = is_array($this->config->vars["module"]["site"]["tables"]) ? $this->config->vars["module"]["site"]["tables"] : $this->config->vars["module"]["tables"]; if (is_array($this->config->vars["module"]["tables"])) { $this->private->tables = is_array($this->config->vars["module"]["admin"]["tables"]) ? $this->config->vars["module"]["admin"]["tables"] : $this->config->vars["module"]["tables"]; foreach ($this->private->tables as $key => $val) { if ($key == "vars") $this->private->vars = new CVars($this->db , $val); if ($key == "messages") { $this->private->messages = new CMessages($this->db , $val); } } } } if (file_exists( $this->path . "/" . "menu.xml") && $this->admin) { $menu = new CConfig ($this->path . "/" . "menu.xml"); if (is_array($menu->vars["menu"]["level_" . $_SESS["minibase"]["raw"]["user_level"] ] )) $menu = $menu->vars["menu"]["level_" . $_SESS["minibase"]["raw"]["user_level"] ]; else $menu = $menu->vars["menu"]; $this->private->menu = $menu; } $this->start = true; } function __adminMenu() { global $_SESS , $_TSM , $_USER; $__template_blocks = array( "Menu" , "MenuGroup", "LinksGroup", "LinksElement", "TitleLink", "TitleNoCollapse", "Collapse" ); $__template = "menus"; if (!is_object($this->templates["menus"])) return false; if (is_array($__template_blocks)) { foreach ($__template_blocks as $k => $block) { if (!is_object($this->templates[$__template]->blocks[$block])) { return false; } } } if (file_exists( $this->path . "/" . "menu.xml") && $this->admin) { $menu = $this->private->menu; if (is_array($menu)) { $tmp_menu = ""; foreach ($menu as $key => $val) { $_links = ""; $_links2 = ""; if ((isset($val["level"]) && $_USER["user_level"] == $val["level"]) || (!isset($val["level"]))) { if (is_array($val["links"])) { foreach ($val["links"] as $k => $v) { $_links[] = array( "title" => is_array($v) ? $v["title"] : ucwords($k), "link" => is_array($v) ? $v["link"] : $v ); $_links2[] = array( "title" => is_array($v) ? $v["title"] : ucwords($k), "link" => is_array($v) ? $v["link"] : $v ); } } $val["title"] = $val["title"] ? $val["title"] : ucwords ($key); $val["id"] = str_replace(" ", "_" , $key); $sublinks = ""; if (is_array($_links2)) { foreach ($_links2 as $k => $_link) { if (is_array($_link["link"])) { switch ($_link["link"]["type"]) { case "var": $sublinks .= $_link["link"]["value"]; break; } } else { $sublinks .= is_object($this->templates["menus"]->blocks["LinksElement"]) ? $this->templates["menus"]->blocks["LinksElement"]->Replace($_link) : ""; } } } if ($GLOBALS["_TMP"]["module"]["alternance"]) { $GLOBALS["_TMP"]["module"]["alternance"] = 0; $alternance = "Alt"; } else { $GLOBALS["_TMP"]["module"]["alternance"] = 1; $alternance = ""; } $tmp_menu .= is_object($this->templates["menus"]->blocks["MenuGroup"]) ? $this->templates["menus"]->blocks["MenuGroup"]->Replace(array( "title_data" => $this->templates["menus"]->blocks[$val["link"] ? "TitleLink" : "Title"]->Replace($val) , "data" => $sublinks ? $this->templates["menus"]->blocks["LinksGroup"]->Replace(array("DATA" => $sublinks)) : "", "id" => $val["id"], "alternance" => $alternance, "collapse" =>is_array($_links) ? $this->templates["menus"]->blocks["Collapse"]->Replace($val) : "" )) : ""; } } $menus .= $tmp_menu; $output = $tmp_menu; } } else { if (file_exists(_MODPATH . $_MOD . "/" . "menu.htm") && $this->admin) { $tmp_menu = new CTemplate(_MODPATH . $_MOD . "/" . "menu.htm"); if (is_object($tmp_menu->blocks["MenuLevel" . (int)$_SESS["minibase"]["raw"]["user_level"]])) $_menu .= $tmp_menu->blocks["MenuLevel" . (int)$_SESS["minibase"]["raw"]["user_level"]]->output; else $_menu .= !count($tmp_menu->blocks) ? $tmp_menu->output : ""; $menus .= $_menu; $output = $_menu; } else { } } $_TSM["MINIBASE.MENU." . $this->name] = $output; return $output; } function __render($data , $vars = array()) { $vars = array_merge($vars , (array)$this->tpl_vars); if (is_array($vars )) { $tmp = new CTemplate($data , "string"); return $tmp->Replace($vars); } else return $data; } function __loadvars() { if (is_object($this->private->messages)) { $this->tpl_vars = array_merge((array)$this->tplvars , $this->private->messages->LoadVars($this->name)); } if (is_array($this->_CONF["conf"])) { foreach ($this->_CONF["conf"] as $key => $val) $this->tpl_vars["MODULE::" . strtoupper($this->name) . "::CONF." . strtoupper($key)] = $val; } } function DoEvents(){ global $base, $_CONF, $_TSM , $_VARS , $_USER , $_BASE; $this->__loadvars(); } function __protect() { if ($this->name != $_GET["mod"]) { return false; } } function __page($title , $body ) { global $_TSM; $_TSM["CPAGE::TITLE"] = $title; if ($this->templates["page"]) { return $this->templates["page"]->Replace(array( "CPAGE::TITLE" => $title, "CPAGE::BODY" => $body )); } else return $body; } function __title($title) { global $_TSM; $_TSM["CPAGE::TITLE"] = $title; } } class CPlugin{ var $tplvars; function CPlugin($db, $tables, $templates) { $this->db = $db; $this->tables = $tables; $this->templates = $templates; } function __init() { $this->_xmlFile = dirname(__FILE__) . basename(__FILE__ , ".php") . ".xml"; $this->_xmlPath = dirname(__FILE__) ; if (file_exists($this->_xmlFile)) { $conf = new CConfig($this->_xmlFile); $this->conf = $conf->vars["plugin"]; if (is_array($this->conf["tables"])) { foreach ($this->conf["tables"] as $key => $val) { $this->private->tables[$key] = $val; } } if (is_array($this->conf["templates"])) { foreach ($this->conf["tables"] as $key => $val) { $this->private->templates[$key] = new CTemplateDyn($val); } } } } function DoEvents() { global $_CONF; } } if (!isset($_SERVER["REQUEST_URI"])) { $_SERVER["REQUEST_URI"] = (strtoupper($_SERVER["HTTPS"]) == "on" ? "https://" : "http://") . $_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != 80 ? ':' . $_SERVER["SERVER_PORT"] : '') . $_SERVER["SCRIPT_NAME"] . ( $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : '' ); } if (!defined("_3RDPATH")) { define("_3RDPATH" , "3rdparty/"); } if (!defined("_MODPATH")) { define("_MODPATH" , "modules/"); } if (!defined("_TPLPATH")) { define("_TPLPATH" , "templates/"); } if (!defined("_LANGPATH")) { define("_LANGPATH" , "lang/"); } if (!defined("_LOCALPATH")) { define("_LOCALPATH" , "local/"); } if (!defined("_LIBPATH")) { define("_LIBPATH" , "lib/"); } if (!defined("_XMLCACHE")) { } if (!defined("_TPLCACHE")) { define("_TPLCACHE" , "./tmp/tplcache/"); } session_start(); class CBase { var $html; } class CSite { var $admin; var $html; function CSite($xml , $admin = false , $preload_modules = true) { global $_CONF , $base , $_VARS; $this->admin = $admin; $this->preload = $preload_modules; $tmp_config = new CConfig($xml); $_CONF = $tmp_config->vars["config"]; if (($this->admin) && is_array($_CONF["paths"])){ $_CONF["upload"] = $_CONF["paths"]["admin"]["upload"]; $_CONF["path"] = $_CONF["paths"]["admin"]["path"]; $_CONF["url"] = $_CONF["paths"]["admin"]["url"]; } else { $_CONF["upload"] = $_CONF["paths"]["site"]["upload"]; $_CONF["path"] = $_CONF["paths"]["site"]["path"]; $_CONF["url"] = $_CONF["paths"]["site"]["url"]; } $GLOBALS["_SESS"] = &$_SESSION[$_CONF["site"]]; if ($this->admin) { if ($_CONF["admin"]["template"] != "") { $tpl = is_array($_CONF["admin"]["template"]) ? $_CONF["admin"]["template"]["tpl"] : $_CONF["admin"]["template"]; $current_template = $GLOBALS["_SESS"]["current"]["template"] ? $GLOBALS["_SESS"]["current"]["template"] : $tpl; if (!file_exists(_TPLPATH . $current_template . "/template.xml")) $current_template = $_CONF["admin"]["template"]; $template = new CConfig(_TPLPATH . $current_template . "/template.xml"); $conf = $template->vars["template"]; if (is_array($conf["templates"])) { foreach ($conf["templates"] as $key =>$tpl) { if ($key != "path") $this->templates[$key] = new CTemplate(_TPLPATH . $current_template . $conf["templates"]["path"] . $tpl); } } } if (is_array($_CONF["templates"]["admin"])) { foreach ($_CONF["templates"]["admin"] as $key => $val) { if ($key != "path") $this->templates[$key] = new CTemplate($_CONF["templates"]["admin"]["path"] .$val); } } } else { if (is_array($_CONF["templates"]["site"])) $_CONF["templates"] = $_CONF["templates"]["site"]; if (is_array($_CONF["templates"])) { foreach ($_CONF["templates"] as $key => $val) { if (($key != "path" ) && ($key != "admin")) $this->templates[$key] = new CTemplate($_CONF["templates"]["path"] . $_CONF["templates"][$key]); } } } $base = new CBase(); $base->html = new CHtml(); $base->image = new CImage(); $this->html = &$base->html; $this->image = &$base->image; if (file_exists(_LIBPATH . "../mysql.php")) { require(_LIBPATH . "../mysql.php"); } if (is_array($_CONF["database"])) { $this->db = new CDatabase($_CONF["database"]); if ($_CONF["tables"]["vars"]) { $this->vars = new CVars($this->db , $_CONF["tables"]["vars"]); $base->vars = &$this->vars; $_VARS = $this->vars->data; } $this->tables = &$_CONF["tables"]; } } function TableFiller($item) { if (file_exists("pb_tf.php")) { include("pb_tf.php"); } } function Run() { global $_TSM , $_SITE_IDENTITY_CODE, $_CONF , $_USER , $_VARS , $_PAGE , $base , $_SESS , $_MODULES; $_USER = $_SESS["minibase"]["raw"]; if ($this->admin) { $_CONF["modules"] = $_CONF["modules"]["admin"]; unset($_CONF["modules"]["admin"]); } else { $_CONF["modules"] = $_CONF["modules"]["site"]; unset($_CONF["modules"]["admin"]); } if (!$this->preload) { foreach ($_CONF["modules"] as $key => $val) { if ($_GET["mod"] != $val) { unset($_CONF["modules"][$key]); } } } if (is_dir(_LOCALPATH)) { $locals = dir(_LOCALPATH); while (false !== ($entry = $locals->read())) { if (strstr($entry , "pre.")) { include_once(_LOCALPATH . $entry); } } $locals->close(); } if (is_array($_CONF["vars"])) { foreach ($_CONF["vars"] as $key => $var) { $_TSM["MINIBASE." . strtoupper($key)] = $var; } } if ($this->admin) { $_TSM["MINIBASE.POSTMENU"] = file_exists("templates/menu.post.htm") ? GetFileContents("templates/menu.post.htm") : ""; $_TSM["MINIBASE.PREMENU"] = file_exists("templates/menu.pre.htm") ? GetFileContents("templates/menu.pre.htm") : ""; if (!$_SESS["minibase"]["user"]) { $_GET["mod"] = "auth"; $_CONF["modules_back"] = $_CONF["modules"]; unset($_CONF["modules"]); $_CONF["modules"]["auth"] = "auth"; $_GET["sub"] = ($_GET["sub"] == "ajax") || ($_GET["sub"] == "recover") || ($_GET["sub"] == "verify") ? $_GET["sub"] : ""; } else { if ($_GET["redirect"]) { die("error"); header("Location: " . urldecode($_GET["redirect"])); exit; } } } if (is_array($_CONF["modules"])) { foreach ($_CONF["modules"] as $_KMOD => $_MOD) { $file = _MODPATH . $_MOD . "/" . ($this->admin ? "admin.php" : "site.php"); $found = false; $cache = false; if (file_exists($file) && !$found) { require_once $file; eval("\$_MODULES[\"". $_MOD. "\"] = new c{$_MOD}();"); $_MODULES[$_MOD]->templates = $this->templates; $_MODULES[$_MOD]->tables = &$this->tables; $_MODULES[$_MOD]->vars = $this->vars; $_MODULES[$_MOD]->db = &$this->db; $_MODULES[$_MOD]->admin = $this->admin; $_MODULES[$_MOD]->__init(); $_CONF["forms"]["adminpath"] = _MODPATH . $_MOD . "/forms/"; if ($_GET["mod"] == $_MOD) { $_TSM[strtoupper($_MOD)] = $_TSM["PB_EVENTS"] = $_MODULES[$_MOD]->DoEvents(); $executed_module = true; } else { $_TSM[strtoupper($_MOD)] = $_MODULES[$_MOD]->DoEvents(); } } $menus .= $_TSM["MINIBASE.MENU." . $_MOD] = method_exists($_MODULES[$_MOD], "__adminMenu") ? $_MODULES[$_MOD]->__adminMenu() : ""; } } if (is_object($this->templates["menus"]) && $this->admin) { $menus = new CTemplate($menus,"string"); $_TSM["MINIBASE.MENU"] = $_SESS["minibase"]["user"] ? $this->templates["menus"]->blocks["Menu"]->Replace(array("MENUS.CONTENT"=>$menus->Replace($_TSM))) : ""; } else { $_TSM["MINIBASE.MENU"] = ""; } if (file_exists("pb_events.php") && !$executed_module) { include("pb_events.php"); $_TSM["PB_EVENTS"] = @DoEvents(&$this); } if (!$_TSM["PB_EVENTS"]) { $_TSM["PB_EVENTS"] = ""; } if ($_GET["devel"] == "phpinfo") { ob_start(); phpinfo(); $phpinfo .= ob_get_contents(); ob_end_clean(); $search = array ("'<style[^>]*?>.*?</style>'si" ); $replace = array ("" ); $phpinfo = preg_replace ($search, $replace, $phpinfo); $phpinfo = str_replace( array( 'class="e"', 'class="v"', 'class="h"' ), array( 'style=" border: 1px solid #000000; font-size: 75%; vertical-align: baseline;background-color: #ccccff; font-weight: bold; color: #000000;"', 'style=" border: 1px solid #000000; font-size: 75%; vertical-align: baseline;background-color: #cccccc; color: #000000;"', 'style=" border: 1px solid #000000; font-size: 75%; vertical-align: baseline;background-color: #9999cc; font-weight: bold; color: #000000;"' ), $phpinfo ); $_TSM["PB_EVENTS"] = "<script>draw_box ( '550' , 1 , 'Php Info' );</script> <div style='width:589;height:600;overflow:auto'>$phpinfo</div><script>draw_box ( '' , 2 , 'Php Info' );</script>"; } if (is_dir(_LOCALPATH)) { $locals = dir(_LOCALPATH); while (false !== ($entry = $locals->read())) { if ((substr($entry , 0 , 6) == "after.") && (strstr($entry , ".php"))) { include_once(_LOCALPATH . $entry); } } $locals->close(); } if (isset($_PAGE)) { $this->layout = new CLayout(($_CONF["template_path"] ? $_CONF["template_path"] : $_CONF["path"]). "templates/$_PAGE/layout.xml"); $this->layout->Build(); $this->layout->Show(); } else { if (is_object($this->templates["layout"])) { echo $this->templates["layout"]->Replace($_TSM) . $_SITE_IDENTITY_CODE ; } } } } class CSQLAdmin extends CLibrary { var $form; var $functions; function CSQLAdmin($section , $templates , $db , $tables , $extra = "") { global $_CONF; if (!$_GET["page"]) $_GET["page"] = 1; parent::CLibrary("SQLAdmin"); if (!is_array($templates)) $this->templates = array("generic_form" => new CTemplate($templates)); else $this->templates = $templates; $this->db = $db; $this->tables = $tables; $this->extra = $extra; if (is_array($section)) { $this->forms = $section; } else { $path = ($_CONF["forms"]["adminpath"] ? $_CONF["forms"]["adminpath"] : $_CONF["formspath"] ); if (dirname($section)) { $path .= dirname($section) . "/" ; $section = basename($section); } if (defined("PB_DEBUG") && (PB_DEBUG == "1")) echo "<br>FILE:SQLADMIN:MAIN:{$path}{$section}.xml"; $conf = new CConfig( $path . $section . ".xml"); $this->forms = $conf->vars["form"]; if (is_array($this->forms["forms"])) { foreach ($this->forms["forms"] as $key => $val) { if (is_array($val)) { $form = CForm::Process($path . $val["file"]); $this->forms["forms"][$key] = $form; $this->forms["forms"][$key]["type"] = $val["type"]; } if (strstr($val,"SHOW::")) { $tmp = explode("::" , $val); $form = is_array($this->forms["forms"][$tmp[1]]) ? $this->forms["forms"][$tmp[1]] : CForm::Process($path . $this->forms["forms"][$tmp[1]]); CForm::__private__showonly(&$form); } else if (file_exists($path . $val)){ $form = CForm::Process($path . $val); } if (is_array($form)) { $this->forms["forms"][$key] = array_merge( $form , array( "table" => &$this->forms["table"], "table_uid" => &$this->forms["table_uid"], "urilinks" => &$this->forms["urilinks"], "uridata" => &$this->forms["uridata"] ) ); if (in_array($key , array("store" , "add" , "edit" , "details" , "search")) && !isset($this->forms["forms"][$key]["type"])) { $this->forms["forms"][$key]["type"] = "FORM"; } else { if (in_array($key , array("list" , "search")) && !isset($this->forms["forms"][$key]["type"])) { $this->forms["forms"][$key]["type"] = "LIST"; } } } } foreach ($this->forms["forms"] as $key => $val) { if ((($key == "edit")||($key == "add")) && isset($this->forms["forms"][$key]["buttons"]["button_edit"])) unset($this->forms["forms"][$key]["buttons"]["button_edit"]); if (($key == "details") && isset($this->forms["forms"][$key]["buttons"]["button_save"])) unset($this->forms["forms"][$key]["buttons"]["button_save"]); if (!($_GET["returnurl"] || $_POST["returnurl"]) && isset($this->forms["forms"][$key]["buttons"]["button_back"])) if (is_array($this->forms["forms"][$key]["buttons"]["button_back"])) { unset($this->forms["forms"][$key]["buttons"]["button_back"]); } } if (is_array($this->forms["forms"]["search"])) { $search = &$this->forms["forms"]["search"]; if (is_array($search["search"]["simple"]) && is_array($search["search"]["advanced"])) $search["search"] = $search["search"][$_GET["advanced"] ? "advanced" : "simple"]; if (is_array($search["search"])) { $search_type = &$search["search"]; $search["fields"] = array_merge($search["fields"] , $search_type["fields"] ); if (is_array($search_type["fields"]["fields"])) { if (is_array($_GET["fields"])) { $fields_list = $_GET["fields"]; } else { $fields_list = explode("," , strlen($_GET["fields"]) ? $_GET["fields"] : $search_type["fields"]["fields"]["default"]); } if (!is_array($_GET["fields"])) $_GET["fields"] = $fields_list; if (is_array($_GET["fields"])) { foreach ($_GET["fields"] as $__key => $__val) { $_GET["fields"][$__val] = $__val; unset($_GET["fields"][$__key]); } } if (is_array($search_type["header"]) && is_array($_GET["fields"]) ) { foreach ($search_type["header"] as $key => $val) { if (!array_exists($key , $fields_list )) { unset($search_type["header"][$key]); } } } } else { if (is_array($search_type["header"]) && count($search_type["header"])) $this->forms["forms"]["list"]["fields"] = array_merge($search_type["header"],$this->forms["forms"]["list"]["fields"]); } } } } } $this->form = new CForm($this->templates["generic_form"], &$db , &$tables); } function FormList($items = "") { global $base; $found_search = true; if (is_array($this->forms["forms"]["search"])) { if ($this->forms["forms"]["search"]["search"]["required"] == "true") $found_search = false; } else $found_search = true; if (is_array($this->items)) { $items = $this->items; $items_count = count($items); } else { if (is_array($items)) $items_count = count($items); } if (is_array($this->forms["forms"]["search"])) { $search = &$this->forms["forms"]["search"]; if (($_GET["hidesearch"] != "true")) { $this->forms["forms"]["list"]["border"] = ""; $this->forms["forms"]["list"]["subtitle"] = $this->forms["forms"]["list"]["title"]; } if ($_GET["advanced"]) { unset($search["buttons"]["butt_advanced"]); unset($search["buttons"]["button_advanced"]); } else { if (isset($search)) { if (is_array($search["buttons"]["butt_simple"])) unset($search["buttons"]["butt_simple"]); if (is_array($search["buttons"]["button_simple"])) unset($search["buttons"]["button_simple"]); } } if (is_array($search["search"])) { $search_type = &$search["search"]; if (is_array($search_type["header"])) { $this->forms["forms"]["list"]["fields"] = array_merge($search_type["header"],$this->forms["forms"]["list"]["fields"]); } if (!$_GET["returnurl"] && is_array($search["buttons"]["button_back"])) unset($search["buttons"]["button_back"]); if (is_array($search_type["sql_fields"])) { if (is_array($search_type["sql_fields"])) { CForm::ProcessVariables($search, &$_GET); foreach ($search_type["sql_fields"] as $key => $val) { switch (strtolower($val)) { case "=": if (isset($_GET[$key]) && strlen($_GET[$key])) $query[] = " `$key`='{$_GET[$key]}'"; break; case "int": $query[] = " `$key`=" . ((int)$_GET[$key]) . ""; break; case "%": if (isset($_GET[$key]) && strlen($_GET[$key])) $query[] = " `$key` LIKE '%{$_GET[$key]}%'"; break; case "?%": if (isset($_GET[$key]) && strlen($_GET[$key])) $query[] = " `$key` LIKE '{$_GET[$key]}%'"; break; case "%?": if (isset($_GET[$key]) && strlen($_GET[$key])) $query[] = " `$key` LIKE '%{$_GET[$key]}'"; break; case "range": $start = ""; $end = ""; if ($_GET[$key . "_start"]) $start = $_GET[$key . "_start"]; if ($_GET[$key . "_end"]) $end = $_GET[$key . "_end"]; if ($start && $end) $query[] = " ((`$key` <= '$end') AND (`$key` >= '$start')) "; else if ($start) $query[] = " `$key` >= '$start' "; else if ($end) $query[] = " `$key` <= '$end' "; break; case "in_set": if ($_GET["$key"]) { $query[] = " FIND_IN_SET('" . $_GET[$key] . "' , `{$key}`) "; } break; case "in": if (strlen($_GET[$key])) { $__tmp = implode("','" , explode("," , $_GET[$key])); $query[] = " `{$key}` IN ( '{$__tmp}' ) "; } break; } $__fields[] = $key; } if (is_array($query)) { if (count($query) > 1) { $this->forms["forms"]["list"]["sql"]["vars"]["condition"]["import"] = implode(" " . (array_exists($_GET["relation"] , array("and" , "or")) ? $_GET["relation"] : "and") . " " , $query); } else $this->forms["forms"]["list"]["sql"]["vars"]["condition"]["import"] = $query[0]; if (!$this->forms["forms"]["list"]["sql"]["vars"]["req_condition"]["import"]) $this->forms["forms"]["list"]["sql"]["vars"]["condition"]["import"] = " WHERE " . $this->forms["forms"]["list"]["sql"]["vars"]["condition"]["import"]; else $this->forms["forms"]["list"]["sql"]["vars"]["condition"]["import"] = $this->forms["forms"]["list"]["sql"]["vars"]["req_condition"]["import"] . " AND " . $this->forms["forms"]["list"]["sql"]["vars"]["condition"]["import"]; $found_search = true; } else { if ($this->forms["forms"]["list"]["sql"]["vars"]["req_condition"]) $this->forms["forms"]["list"]["sql"]["vars"]["condition"] = $this->forms["forms"]["list"]["sql"]["vars"]["req_condition"]; } } if ($_GET["order"] && array_key_exists($_GET["order"] , $search_type["sql_fields"])) $this->forms["forms"]["list"]["sql"]["vars"]["order"]["import"] = $_GET["order"]; if ($_GET["order_mode"] && array_exists($_GET["order_mode"] , array("ASC" , "DESC" ))) $this->forms["forms"]["list"]["sql"]["vars"]["order_mode"]["import"] = $_GET["order_mode"]; if ((int)$_GET["items"]) $this->forms["forms"]["list"]["items"] = $this->forms["forms"]["list"]["sql"]["vars"]["items"]["import"] = (int)$_GET["items"]; else $this->forms["forms"]["list"]["sql"]["vars"]["items"]["import"] = $this->forms["forms"]["list"]["items"]; } } else { $this->forms["forms"]["list"]["sql"]["vars"]["condition"] = $this->forms["forms"]["list"]["sql"]["vars"]["req_condition"]; } } if ($found_search || ($_GET["search"])) { if (is_array($this->functions["list"]["pre"])) call_user_func($this->functions["list"]["pre"], &$items , &$items_count); $_GET["page"] = $_GET["page"] ? $_GET["page"] : 1; $start = $this->forms["forms"]["list"]["items"] * ($_GET["page"] - 1 ); if (is_array($items)) { foreach ($items as $key => $val) { $items[$key]["_count"] = ++$start; } } $return = $this->form->SimpleList($this->forms["forms"]["list"] , $items , $count , $this->extra["list"]); } unset($search["search"]); if (is_array($search) && ($_GET["hidesearch"] != "true")) { $search_form = new CForm($this->templates["generic_form"], &$this->db , &$this->tables); return $search_form->Show($search , array("values"=>$_GET) , array("after" => $return)); } else return $return; } function SetFunction( $form , $event , $function) { $this->functions[$form][$event] = $function; } function ListProcess($pre = "" , $after = "" ) { $this->functions["list"]["pre"] = $pre; $this->functions["list"]["after"] = $after; } function StoreRecord($redirect = true) { global $base, $_CONF; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!isset($_GET["type"])) { if ($_POST[$this->forms["table_uid"]]) $_GET["type"] = "edit"; else $_GET["type"] = "add"; } $form = $this->forms["forms"][$_GET["type"]]; if (is_array($form["fields"])) { $_POST = CForm::ProcessVariables($form , $_POST); foreach ($form["fields"] as $key => $val) { if (!$val["name"]) $val["name"] = $key; switch ($val["type"]) { case "checkbox": if ($this->_set_store_nochecks != true) { if (!isset($_POST[$key])) { $_POST[$key] = "0"; } } break; case "upload": $file = true; case "image": unset($_POST[$key]); CForm::__private_uploads_pre($val , &$_fields); break; } } } if ($_GET["FORMvalidate"] == "false") $fields = ""; else $fields = $this->form->Validate($this->forms["forms"][$_GET["type"]] , $_POST); if (!is_array($fields)) { if ($this->functions["onstore_prepare"]) call_user_func($this->functions["onstore_prepare"] , $_POST ); if ($_POST[$this->forms["table_uid"]] && is_array($this->db->QFetchArray("SELECT * FROM " . $this->tables[$this->forms["table"]] . " WHERE {$this->forms[table_uid]}='" . $_POST[$this->forms["table_uid"]] . "'"))) { $this->db->QueryUpdate($this->tables[$this->forms["table"]] , $_POST , "`" . $this->forms["table_uid"] . "`='" . $_POST[$this->forms["table_uid"]] . "'" ); $id = $_POST[$this->forms["table_uid"]]; $was_added = false; } else { $id = $this->db->QueryInsert($this->tables[$this->forms["table"]] , $_POST); $_POST[$this->forms["table_uid"]] = $id; $was_added = true; } if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $val) { if (!$val["name"]) $val["name"] = $key; switch ($val["type"]) { case "upload": case "image": if (CForm::__private_uploads_after($val)) { $_POST[$key] = 1; $this->db->QueryUpdate($this->tables[$this->forms["table"]] , $_POST , "`" . $this->forms["table_uid"] . "`='" . $_POST[$this->forms["table_uid"]] . "'" ); } break; default: if (is_array($val["file"])) SaveFileContents($_CONF["path"] . $_CONF["upload"] . $val["file"]["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"] , stripslashes($_POST[$key])); break; } } } if (!$_GET["type"]) { $_GET["type"] = $_POST[$this->forms["table_uid"]] ? "edit" : "add"; } if ($this->functions["onstore"]) call_user_func($this->functions["onstore"] , $_POST , $_GET["type"]); $this->templates["generic_form"]->blocks["Temp"]->input = $this->forms["forms"][$_GET["type"]]["redirect"]; if ($_POST["_after_save"]) { $_POST["after_save"] = $_POST["_after_save"]; } if ($_POST["after_save"]) { $vars = $this->form->GlobalVars($this->forms["forms"]["add"] , array_merge($_GET , $_POST)); $location = new CTemplate($vars["self.uri.add"] . "&after_save={$_POST[after_save]}&returnurl=" . $_POST["returnurl"] , "string"); UrlRedirect($location->Replace(array_merge($_GET , $_POST))); } if ($_GET["returnURL"]) { header("Location:" . urldecode($_GET["returnURL"])); exit; } if ($_POST["returnurl"]) { switch ($_GET["storeredirect"]) { case "STOREDETAILS": header("Location:" . basename($_SERVER["SCRIPT_NAME"]) . "?mod={$_GET[mod]}&sub={$_GET[sub]}&action={$this->forms[uridata][details]}&{$this->forms[table_uid]}={$_POST[$this->forms[table_uid]]}&returnurl={$_POST[returnurl]}"); exit; break; case "ADDDETAILS": if ($was_added) { $vars = $this->form->GlobalVars($this->forms["forms"]["details"]); $vars["self.location"] = $_POST["returnurl"]; $url = CTemplateStatic::Replace( CTemplateStatic::Replace( $this->forms["forms"]["details"]["urilinks"]["details"], $vars ), array_merge( $_POST, $_GET ) ); header("Location:" . $url); exit; }  default: $count = 1; while ($count < 10 ) { $_POST["returnurl"] = urldecode($_POST["returnurl"]); if (substr($_POST["returnurl"],0,1) == "/") break; $count ++; } $this->templates["generic_form"]->blocks["Temp"]->input = $_POST["returnurl"]; header("Location:" . $this->templates["generic_form"]->blocks["Temp"]->Replace(array_merge($_GET,$_POST))); exit; break; } } if ($redirect == true) { header("Location: " . CryptLink($this->templates["generic_form"]->blocks["Temp"]->Replace(array_merge($_GET,$_POST)))); exit; } else { return true; } } } else { die("ARGH!!!"); header("Location:" . str_replace("&action=store" , "" , $_SERVER["REQUEST_URI"])); exit; } if (is_array($_fields["values"])) $fields["values"] = array_merge($fields["values"], $_fields["values"]); if ($_POST[$this->forms["table_uid"]]) { $data = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["table"]] . "` WHERE `" . $this->forms["table_uid"] . "`='" . $_POST[$this->forms["table_uid"]] . "'" ); $fields["values"] = array_merge($data , $fields["values"]); } return $this->form->Show($this->forms["forms"][$_GET["type"]] , $fields , $this->extra[$_GET["type"]]); } function RestoreURI($section) { if (is_array($_GET)) { foreach ($_GET as $key => $val) { $out[$key] = $key . "=" . $val; } $out[$this->forms["uridata"]["action"]] = $this->forms["uridata"]["action"] . "=" . $this->forms["uridata"][$section]; unset($out[$this->forms["table_uid"]]); return CryptLink($_SERVER["SCRIPT_NAME"] . "?" . implode("&" , $out)); } } function DoEvents($section = "" , $extra = "" , $values = "") { global $base , $_CONF; if (is_array($extra)) { $this->extra = array_merge($this->extra , $extra); } switch ($_GET[$this->forms["uridata"]["action"]]) { case $this->forms["uridata"]["delete"]: if (($_GET["rconfirm"] == "true")&&($_GET["confirmed"] != "true")) { return $this->templates["generic_form"]->blocks["DeleteItem"]->Replace(array( "title" => $_GET["title"] ? urldecode($_GET["title"]) : "Delete Item", "description" => $_GET["description"] ? urldecode($_GET["description"]) : "Are you sure you want to delete this record?", "return" => urldecode($_GET["returnURL"]), "cancel_location" => urldecode($_GET["returnURL"]), "delete_location" => $_SERVER["REQUEST_URI"] . "&confirmed=true" )); } if ($_SERVER["REQUEST_METHOD"] == "POST") { if (is_array($_POST[$this->forms["table_uid"]])) { foreach ($_POST[$this->forms["table_uid"]] as $key => $val) { $this->db->Query("DELETE FROM `" . $this->tables[$this->forms["table"]] . "` WHERE `" . $this->forms["table_uid"] . "`='" . $val . "'" ); } } if ($_GET["returnURL"]) { header("Location: " . CryptLink(urldecode($_GET["returnurl"]))); exit; } else { header("Location:" . $_SERVER["HTTP_REFERER"]); exit; } } else { $data = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["table"]] . "` WHERE `" . $this->forms["table_uid"] . "`='" . $_GET[$this->forms["table_uid"]] . "'" ); if (is_array($data)) { $this->db->Query("DELETE FROM `" . $this->tables[$this->forms["table"]] . "` WHERE `" . $this->forms["table_uid"] . "`='" . $_GET[$this->forms["table_uid"]] . "'" ); if ($this->functions["ondelete"]) call_user_func($this->functions["ondelete"] , $data); } if ($_GET["returnURL"]) { header("Location: " . CryptLink(urldecode($_GET["returnURL"]))); exit; } else { header("Location:" . $_SERVER["HTTP_REFERER"]); exit; } } break; case $this->forms["uridata"]["store"]: return $this->StoreRecord(); break; case $this->forms["uridata"]["add"]: $fields["values"] = $values["add"]; return $this->form->Show($this->forms["forms"]["add"] , $fields , $this->extra["add"]); break; case $this->forms["uridata"]["edit"]: $data = $values["edit"] ? $values["edit"] : $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["table"]] . "` WHERE `" . $this->forms["table_uid"] . "`='" . $_GET[$this->forms["table_uid"]] . "'" ); if ($this->functions["onedit"]) call_user_func($this->functions["onedit"] , &$data); if (is_array($data)) { $fields["values"] = $data; return $this->form->Show($this->forms["forms"]["edit"] , $fields , $this->extra["edit"]); } header("Location:" . $this->RestoreURI("list")); exit; break; case $this->forms["uridata"]["details"]: $data = $values["details"] ? $values["details"] : $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["table"]] . "` WHERE `" . $this->forms["table_uid"] . "`='" . $_GET[$this->forms["table_uid"]] . "'" ); if ($this->functions["ondetails"]) call_user_func($this->functions["ondetails"] , &$data); if (is_array($data)) { $fields["values"] = $data; return $this->form->Show($this->forms["forms"]["details"] , $fields, $this->extra["details"]); } header("Location:" . $this->RestoreURI("list")); exit; break; case $this->forms["uridata"]["search"]: case $this->forms["uridata"]["list"]: default: return $this->FormList($values["list"]); break; } } } class CTemplateDynamic{ function CTemplateDynamic($source , $source_type = "file") { $this->source = array( "file" => $source , "type" => $source_type ); $this->dynamic = true; } function Replace($vars , $clear) { $this->__checkObject(); return $this->template->Replace($vars , $clear); } function EmptyVars($vars = array()) { if (count($vars)) $this->template->Replace($vars , false); return $this->template->EmptyVars(); } function SwapIO() { $this->__checkObject(); $this->template->input = $this->template->output; } function Block($block) { $this->__checkObject(); if (!is_object($this->template->blocks[$block])) { $this->error($block); return NULL; } else { return $this->template->blocks[$block]->output; } } function BlockSetInput($block , $data) { $this->__checkObject(); if (!is_object($this->template->blocks[$block])) { $this->error($block); return NULL; } else { return $this->template->blocks[$block]->input = $data; } } function BlockReplace($block , $vars = array(), $clear = true) { $this->__checkObject(); if (!is_object($this->template->blocks[$block])) { $this->error($block); return NULL; } else { return $this->template->blocks[$block]->Replace($vars , $clear); } } function BlockEmptyVars($block , $vars , $clear = true) { $this->__checkObject(); if (!is_object($this->template->blocks[$block])) { $this->error($block); return NULL; } else { $this->template->blocks[$block]->Replace($vars , false); return $this->template->blocks[$block]->EmptyVars(); } } function BlockSwapIO($block) { $this->__checkObject(); if (!is_object($this->template->blocks[$block])) { $this->error($block); return NULL; } else { $this->template->blocks[$block]->input = $this->template->blocks[$block]->output; } } function __checkObject() { if (!is_object($this->template)) { $this->template = new CTemplate( $this->source["file"], $this->source["type"] ); } } function BlockExists() { $this->__checkObject(); if (func_num_args() > 0) { $blocks = func_get_args(); $error = true; for ($i = 0; $i < count($blocks); $i++) { if (!is_object($this->template->blocks[$blocks[$i]])) { return false; } } } return $error; } function Error($block) { CError::Msg("

            <pre>

                CTemplateDynamic::BlockSwapIO::_invalid object

                    - block: {$block} doesnt exist

                    - template: {$this->source[file]}

            </pre>

        "); } } class CLayout extends CXMLParser { var $data; var $version; var $name; var $base; var $body; var $blocks; var $loaded = FALSE; function CLayout($file_name = "") { parent::CXMLParser(); if ($file_name != "") $this->Load($file_name); } function HNDTagOpen($parser,$tag,$attr) { global $base; switch ($tag) { case "LAYOUT": $this->version = ($attr["VERSION"] == "") ? "1.0" : $attr["VERSION"]; $this->base = $attr["BASE"]; $this->name = $attr["NAME"]; $this->body = new CTemplate($GLOBALS["_TEMPLATES_PATH"] . $this->base . $attr["SRC"]); break; case "BLOCK": $this->blocks[$attr["NAME"]] = new CTemplate($GLOBALS["_TEMPLATES_PATH"] . $this->base . $attr["SRC"]); break; case "ASSIGN": switch ($attr["TYPE"]) { case "var": if ($attr["BLOCK"] == $this->name) $this->body->ReplaceSingle($attr["VAR"],$attr["VAL"],TRUE); else $this->blocks[$attr["BLOCK"]]->ReplaceSingle($attr["VAR"],$attr["VAL"]); break; case "tpl": $parse = TRUE; if ($attr["REQUIRES"] != "") if ($GLOBALS["_TSM"][$attr["REQUIRES"]] == "") $parse = FALSE; if ($parse) $val = GetFileContents($this->base . $attr["VAL"],TRUE); else $val = $attr["DEFAULT"]; if ($attr["BLOCK"] == $this->name) $this->body->ReplaceSingle($attr["VAR"],$val,TRUE); else $this->blocks[$attr["BLOCK"]]->ReplaceSingle($attr["VAR"],$val,TRUE); break; case "call": if ($attr["BLOCK"] == $this->name) $this->body->ReplaceSingle($attr["VAR"],call_user_func($attr["VAL"]),TRUE); else $this->blocks[$attr["BLOCK"]]->ReplaceSingle($attr["VAR"],call_user_func($attr["VAL"])); break; case "module": if (strstr($attr["PARAMS"],",")) { $params = "," . $attr["PARAMS"]; $call = "\$result = call_user_func(array(&\$base->modules[\$attr[\"MODULE\"]],\$attr[\"METHOD\"])$params);"; echo $call; eval($call); } else { $call = "\$result = \$base->modules[$attr[MODULE]]->$attr[METHOD]($attr[PARAMS]);"; eval($call); } if ($attr["BLOCK"] == $this->name) $this->body->ReplaceSingle($attr["VAR"],$result,TRUE); else $this->blocks[$attr["BLOCK"]]->ReplaceSingle($attr["VAR"],$result,TRUE); break; } break; } } function Load($file_name) { if (file_exists($file_name)) { parent::Parse($this->data = GetFileContents($file_name)); $this->loaded = TRUE; } else $this->loaded = FALSE; } function Replace($vars) { $this->body->Replace($vars,FALSE); } function BlockReplace($block,$vars) { $this->blocks[$block]->Replace($vars,FALSE); } function BlockExists($block) { if (isset($this->blocks[$block])) return TRUE; else return FALSE; } function Build() { global $_TSM; if ($this->loaded == FALSE) return; $vars = array(); if (is_array($this->blocks)) { foreach ($this->blocks as $key => $block) { if ($_TSM[$key]) $this->BlockReplace($key,$_TSM[$key]); $vars[$key] = $block->output; } foreach ($_TSM as $k => $v) if (!$this->BlockExists($k)) $vars[$k] = $v; if (is_array($_TSM["_PERM"])) $vars = array_merge($vars,$_TSM["_PERM"]); $this->body->Replace($vars,FALSE); } else $this->body->Replace($_TSM,FALSE); $this->body->input = $this->body->output; $this->body->Replace($_TSM , FALSE); } function Show() { print($this->body->output); } } $_TSM = array(); class CTemplate { var $input; var $output; var $blocks; function CTemplate($source,$source_type = "file") { $this->Load($source,$source_type); } function Load($source,$source_type = "file") { switch ($source_type) { case "file": $this->template_file = $source; $data = GetFileContents($source); break; case "rsl": case "string": $data = $source; break; } preg_match_all("'<!--S\:.*?-->.*?<!--E\:.*?-->'si",$data,$matches); if (count($matches[0]) != 0) foreach ($matches[0] as $block) { $name = substr($block,strpos($block,"S:") + 2,strpos($block,"-->") - 6); $block = substr($block,9 + strlen($name),strlen($block) - 18 - strlen($name) * 2); $this->blocks["$name"] = new CTemplate($block,"string"); } $this->input = $this->output = preg_replace(array("'<!--S\:.*?-->(\r\n|\n|\n\r)'si","'<!--E\:.*?-->(\r\n|\n|\n\r)'si"),"",$data); } function Replace($vars,$clear = TRUE) { if (is_array($vars)) { foreach ($vars as $key => $var) { if (is_array($var)) { unset($vars[$key]); } } } $patterns = array(); $replacements = array(); if (is_array($vars)) foreach ($vars as $key => $val) { $patterns[] = "/\{" . strtoupper($key) . "\}/"; $replacements[] = str_replace('$','\$',$val); } $result = $this->output = @preg_replace($patterns,$replacements,$this->input); if ($clear == TRUE) $this->Clear(); return $result; } function SepReplace($ssep , $esep , $vars,$clear = TRUE) { if (is_array($vars)) { foreach ($vars as $key => $var) { if (is_array($var)) { unset($vars[$key]); } } } $patterns = array(); $replacements = array(); if (is_array($vars)) foreach ($vars as $key => $val) { $patterns[] = $ssep . strtoupper($key) . $esep; $replacements[] = str_replace('$','\$',$val); } $result = $this->output = @preg_replace($patterns,$replacements,$this->input); if ($clear == TRUE) $this->Clear(); return $result; } function ReplaceSingle($var,$value,$perm = FALSE) { if ($perm) $this->input = $this->Replace(array("$var" => $value)); else return $this->Replace(array("$var" => $value)); } function Clear() { $this->output = $this->input; } function EmptyVars() { global $_TSM; return $this->output = preg_replace("'{[A-Z_\-0-9]*?}'si","",$this->output); } function BlockExists($block_name) { return isset($this->blocks[$block_name]) && is_object($this->blocks[$block_name])? TRUE : FALSE; } function BlockReplace($block , $vars = array(), $clear = true){ if (!is_object($this->blocks[$block])) echo "CTemplate::{$this->template_file}::$block Doesnt exists.<br>"; return $this->blocks[$block]->Replace($vars , $clear); } function BlockEmptyVars($block , $vars = array(), $clear = true) { if (!is_object($this->blocks[$block])) echo "CTemplate::{$this->template_file}::$block Doesnt exists.<br>"; if (is_array($vars) && count($vars)) $this->blocks[$block]->Replace($vars , false); return $this->blocks[$block]->EmptyVars(); } function Block($block) { if (!is_object($this->blocks[$block])) echo "CTemplate::{$this->template_file}::$block Doesnt exists.<br>"; return $this->blocks[$block]->output; } } class CTemplateStatic{     function ReplaceSingle($tmp , $key , $val) {$template = new CTemplate($tmp , "string");return $template->replace(array($key => $val ));}
function Replace($tmp , $data = array()) { $template = new CTemplate($tmp , "string"); return $template->replace($data); } function EmptyVars($tmp , $data = array()) { $template = new CTemplate($tmp , "string"); if (count($data)) { $template->replace($data , false); } return $template->emptyvars(); } } class CVars { var $database; var $table; var $data = array(); var $modif = FALSE; function CVars($database,$table) { if (is_object($database)) $this->database = &$database; else $this->database = new CDatabase($database); $this->table = $table; return $this->Load(); } function Load() { global $_USER; $vars = $this->database->QFetchRowArray("SELECT * FROM `$this->table`"); if (is_array($vars)) foreach ($vars as $key => $var) { if (strtolower($var["name"]) != "retrunurl") { if (isset($var["base_user"]) && ($var["base_user"] != $_USER["user_id"])) { unset($vars[$key]); } else $this->data[$var["name"]] = stripslashes($var["value"]); } } } function SetAll($var) { $this->data = array_merge ($this->data ,$var); $this->modif = TRUE; } function Set($name,$value,$force = FALSE) { $value = addslashes($value); if ($force == TRUE) { $this->database->Query("UPDATE `$this->table` SET `value` = '$value' WHERE (`name` = '$name')"); if ($this->database->AffectedRows() == 0) { $this->database->Query("INSERT INTO `$this->table` (`name`,`value`) VALUES ('$name','$value')"); } } $this->data["$name"] = $value; $this->modif = TRUE; } function Get($name) { return $this->data["$name"]; } function Save() { global $_USER; $table_fields = $this->database->GetTableFields($this->table); if ($this->modif == TRUE) { foreach ($this->data as $name => $val) { if (strtolower($name) != "returnurl") { $val = addslashes($val); $values[] = "('$name','$val'" . (in_array("base_user",$table_fields) ? ",'{$_USER[user_id]}'" : '') . ")"; } } $values = implode(", ",$values); $this->database->Query("DELETE FROM `$this->table` " . (in_array("base_user",$table_fields) ? " WHERE `base_user`='{$_USER[user_id]}'" : '')); $this->database->Query("INSERT INTO `$this->table` (`name`,`value`" . (in_array("base_user",$table_fields) ? ",`base_user`" : '') . ") VALUES $values"); } } } class CXMLParser { var $parser; var $namespace; var $attr_namespace = FALSE; var $tag; var $attr; function CXMLParser() { } function InitParser() { $this->parser = xml_parser_create(); xml_set_object($this->parser,&$this); xml_set_element_handler($this->parser,"HNDTagOpen","HNDTagClose"); xml_set_character_data_handler($this->parser,"HNDCData"); } function HNDTagOpen($parser,$tag,$attr) { if (strpos($tag,":")) { list($namespace,$tag) = explode(":",$tag); $this->namespace = $namespace; } $attr_namespace = FALSE; foreach ($attr as $key => $val) { if (strpos($key,":")) { $attr_namespace = TRUE; list($namespace,$name) = explode(":",$key); $_attr["$namespace"]["$name"] = $val; } else $_attr["$key"] = $val; } if ($attr_namespace == TRUE) { $attr = $_attr; $this->attr_namespace = TRUE; } else $this->attr_namespace = FALSE; $this->tag = $tag; $this->attr = $attr; } function HNDTagClose($parser,$tag) { $this->tag = ""; $this->attr = ""; } function HNDCData($parser,$cdata) { } function Parse($data) { $this->namespace = ""; $this->attr_namespace = FALSE; $this->tag = ""; $this->attr = array(); $this->InitParser(); xml_parse($this->parser,$data); xml_parser_free($this->parser); } } class CreditCard { function Valid($type , $nr) { $nr = CreditCard::Strip($nr); $supported = array( "visa" => true, "mc" => true, "discovery" => true, "jcb" => true, "amex" => true, ); if (array_key_exists($type,$supported)) { switch ($type) { case "visa": $size = array( 13, 16 ); $preffix = "4"; break; case "mc": $size = 16; $preffix = array( 51, 52, 53, 54, 55 ); break; case "discovery": $size = 16; $preffix = "6011"; break; case "jcb": $size = array( 15, 16 ); $preffix = array( "3", "2131", "1800" ); break; case "amex": $size = array( 34, 37 ); $preffix = 15; break; } if (isset($size) && isset($preffix)) { $valid = false; if (is_array($size)) { foreach ($size as $key => $val) { if ($val == strlen($nr)) { $valid = true; break; } } } else $valid = (bool) $size == strlen($nr); if (!$valid) return false; $valid = false; if (is_array($preffix)) { foreach ($preffix as $key => $val) { if ($val == substr($nr,0,strlen($val)) ) { $valid = true; break; } } } else $valid = (bool) $preffix == substr($nr , 0 , strlen ($preffix)); if (!$valid) return false; } } return CreditCard::__luhn($nr) ? $nr : false; } function Strip($nr) { if (strlen($nr)) { for ($i = 0 ; $i<strlen($nr) ; $i++) { if (array_key_exists($nr[$i], array (0,1,2,3,4,5,6,7,8,9) )) { $_nr .= $nr[$i]; } } $nr = $_nr; } return $nr; } function Protect($nr , $last = 4) { if (strlen($nr) > 1) { $count = 1; for ($i = strlen($nr); $i > 0 ; $i-- ) { if (array_key_exists($nr[$i - 1], array (0,1,2,3,4,5,6,7,8,9) )) { if ($count > $last) { $nr[$i - 1] = "X"; } $count ++; } } } return $nr; } function __luhn($number) { $l = strlen($number); for ($i=0; $i<$l; $i++) { $q = substr($number,$l-$i-1,1)*($i%2+1); $r += ($q%10)+(int)($q/10); } return !($r%10); } } class CDir{ var $tplvars; function CDir( $path , $ext = "", $recursive = false ) { $this->path = $path; $this->ext = $ext; $this->recursive = $recursive; $this->__readDir($path); return $this->_files; } function __readDir($path) { $d = dir($path); while (false !== ($entry = $d->read())) { if ($this->recursive && is_dir($path . "/" . $entry)) $this->__readDir($path . "/" . $entry); if (!is_dir($path . "/" . $entry)) { if ((($this->ext != "") && strstr($entry , $this->ext)) || ($this->ext == "")) { $this->_files[] = $path . "/" . $entry; } } } $d->close(); } function GetFiles($dir , $ext = false) { return CDir::__getfiles($dir , false , $ext) ; } function GetFilesRec($dir , $ext = false) { return CDir::__getfiles($dir , TRUE , $ext) ; } function __getfiles($dir , $rec = TRUE , $ext) { $array = array(); $d = dir($dir); while (false !== ($entry = $d->read())) { if($entry!='.' && $entry!='..') { $entry = $dir.'/'.$entry; if(is_dir($entry)) { if ($rec == true) $array = array_merge($array, CDir::__getfiles($entry , $rec , $ext)); } else { if (($ext && stristr($entry , $ext )) || !$ext) { $array[] = $entry; } } } } $d->close(); return $array; } } class CFile { function GetContent($file_name) { if (!file_exists($file_name)) { return null; } $file = fopen($file_name,"r"); if (!$file) return null; if (strstr($file_name,"://")) while (!feof($file)) $result .= fread($file,1024); else $result = @fread($file,filesize($file_name)); fclose($file); return $result; } function SaveContents($file_name , $content) { $file = fopen($file_name,"w"); fwrite($file,$content); fclose($file); } function Extension($file_name) { $tmp = explode("." , $file_name); return $tmp[count($tmp) - 1]; } function Name2Url($filename) { $replace = array( " " => "-", "&" => "-and-", "?" => "", "'" => "-", "/" => "-", "!" => "", "," => "-", "\"" => "", "'" => "", ":" => "-", "_" => "-", "--" => "-" ); foreach ($replace as $key => $val) { $filename = str_replace($key , $val , $filename); } return strtolower($filename); } } define('STR_HIGHLIGHT_SIMPLE', 1); define('STR_HIGHLIGHT_WHOLEWD', 2); define('STR_HIGHLIGHT_CASESENS', 4); define('STR_HIGHLIGHT_STRIPLINKS', 8); function str_highlight($text, $needle, $options = null, $highlight = null) { if ($highlight === null) { $highlight = '<strong>\1</strong>'; } if ($options & STR_HIGHLIGHT_SIMPLE) { $pattern = '#(%s)#'; $sl_pattern = '#(%s)#'; } else { $pattern = '#(?!<.*?)(%s)(?![^<>]*?>)#'; $sl_pattern = '#<a\s(?:.*?)>(%s)</a>#'; } if (!($options & STR_HIGHLIGHT_CASESENS)) { $pattern .= 'i'; $sl_pattern .= 'i'; } $needle = (array) $needle; foreach ($needle as $needle_s) { $needle_s = preg_quote($needle_s); if ($options & STR_HIGHLIGHT_WHOLEWD) { $needle_s = '\b' . $needle_s . '\b'; } if ($options & STR_HIGHLIGHT_STRIPLINKS) { $sl_regex = sprintf($sl_pattern, $needle_s); $text = preg_replace($sl_regex, '\1', $text); } $regex = sprintf($pattern, $needle_s); $text = preg_replace($regex, $highlight, $text); } return $text; } function stripos_words($haystack,$needles='',$pos_as_key=true) { $idx=0; $haystack = strtolower($haystack); foreach ( preg_split('/[^\w]/',strtolower($needles)) as $needle ){ $i=0; $pos_cur=0; $pos_found=0; while ( $pos_found !== false && $needles !== '') { $pos_found = strpos(substr($haystack,$pos_cur),$needle); if ( $pos_found !== false ) { $index = $pos_as_key ? $pos_found+$pos_cur : $idx++; $data = array( "start" => $pos_found+$pos_cur, "end" =>$pos_cur, "word" => $needle ); $positions[] = $data; $i++; } } } } class CMime { function CMime($file = null) { if ($file == null) { $file = _LIBPATH . "include/mime.xml"; } $tmp = new CConfig($file); $this->types = $tmp->data["content-type"]; } function Set($ext) { header("Content-type: " . $this->types[$ext]); } function GetByExt($file) { $tmp = explode("." , $file); krsort($tmp); reset($tmp); $ext = $tmp[key($tmp)]; return $this->types[strtolower($ext)] ? $this->types[strtolower($ext)] : $this->types["unknown"]; } function Filename($file) { header('Content-Disposition: attachment; filename="' . str_replace("%20" , " " , $file) . '"'); } } if (!function_exists("str_ireplace")) { function str_Ireplace($search, $replace, $subject) { if (is_array($search)) { foreach ($search as $word) { $words[] = "/".$word."/i"; } } else { $words = "/".$search."/i"; } return preg_replace($words, $replace, $subject); } } if(!defined('UNZIP_CMD')) define('UNZIP_CMD','unzip -o @_SRC_@ -x -d  @_DST_@'); class CSYS{ function _GetVar($data) { $__get = $_GET; if (is_array($data)) { foreach ($data as $k => $v) { $__get[$k] = $v; } } if (is_array($__get)) { foreach ($__get as $k => $v) { if (is_array($v)) { foreach ($v as $key => $val) { $vars[] = "{$k}[]={$val}"; } } else { if ((strtolower($k) == "returnurl") && strstr($v,"=")) { while (strstr($v,"=")) $v = urlencode($v); $v = urlencode($v); } $vars[] = "$k=$v"; } } } return $_SERVER["PHP_SELF"] . "?" . @implode("&" , $vars); } function Str2Date($data , $format = "us" , $sep = "/") { switch ($data) { case "now_month": $date = time(); return mktime(0,0,0,date("m"), 1, date("Y")); break; case "now_month_end": return mktime(0,0,0,date("m"), 0, date("Y")); break; case "now": return time(); break; default: if (strstr($data , $sep)) { $elements = explode($sep , $data); return $format == "us" ? mktime(0,0,0, $elements[0],$elements[1],$elements[2]) : mktime(0,0,0, $elements[1],$elements[0],$elements[2]) ; } if ((int)$data >= 1970) return mktime(0,0,0,0,0,$data); break; } } function VarRequire($field) { return $_GET[$field] ? $_GET[$field] : $_POST[$field]; } function InRange($val , $min, $max) { return ($val >= $min) && ($val <= $max); } function ExtractVars($data) { $vars = @explode("?" , $data); $vars = @explode("&" , $vars[1]); if (is_array($vars)) { foreach ($vars as $key => $val) { $tmp = explode("=" , $val); $_vars[$tmp[0]] = $tmp[1]; } } return $_vars; } function ProcessDate($data , $dates) { if (is_array($data)) { $count = true; foreach ($data as $key => $val) { $count = !$count; $data[$key]["__alternance"] = (int)$count; foreach ($dates as $k => $v) { if ($val[$k] > 1000) $data[$key][$k] = date($v , $val[$k]); else $data[$key][$k] = "N/A"; } } } return $data; } function ProcessNotes($records , $field , $max , $stars) { if (is_array($records)) { foreach ($records as $key => $val) { CSYS::ProcessNote ( &$records[$key] , $field , $max , $stars); } } return $records; } function ProcessNote($val , $field , $max , $stars) { $stars_note = ($val[$field] * $stars) / $max; $int = number_format($stars_note , 1); $dec = number_format(($stars_note - $stars_note % 10) * 10 , 0); $i = 1; if ($int > 0) { for ($i = 1 ; $i <= $int ; $i++) { $val[$field. "_" . $i] = "2"; } } if ($dec < 2) $val[$field . "_" . $i] = "0"; else if ($dec >= 7) $val[$field . "_" . $i] = "2"; else $val[$field . "_" . $i] = "1"; $i++; if ($i <= $stars) { for ($j = $i; $j <= $stars ; $j++ ) $val[$field. "_" . $j] = "0"; } return $val; } function nl2p($data) { $tmp = explode("\n" , $data); if (is_array($tmp)) { foreach ($tmp as $key => $val) { $tmp[$key] = "<p>" . trim($val) . "</p>"; } return implode("" , $tmp); } return "<p>{$data}</p>"; } function rmDir($path) { if (substr($path, -1, 1) != "/") { $path .= "/"; } $normal_files = glob($path . "*"); $hidden_files = glob($path . "\.?*"); $all_files = array_merge($normal_files, $hidden_files); foreach ($all_files as $file) { if (preg_match("/(\.|\.\.)$/", $file)) { continue; } if (is_file($file) === TRUE) { unlink($file); } else if (is_dir($file) === TRUE) { CSYS::rmDir($file); } } if (is_dir($path) === TRUE) { rmdir($path); } } function Unzip($zipFile,$zipDir) { $unzipCmd=UNZIP_CMD; $unzipCmd=str_replace('@_SRC_@',$zipFile,$unzipCmd); $unzipCmd=str_replace('@_DST_@',$zipDir,$unzipCmd); $res=-1; $UnusedArrayResult=array(); $UnusedStringResult=exec($unzipCmd,$UnusedArrayResult,$res); return ($res==0); } } ?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines