'; $r = mysql_query($sql); $s = mysql_error(); if ($s > " ") { echo "

\n$s\n

SQL:
\n$sql\n

"; die; } return $r; } function mysql_encode($s) { $s = str_replace('\\', '\\\\', $s); $s = str_replace('\'', '\\\'', $s); return $s; } class DataReader { var $sql = null; var $r = null; var $a = null; function Execute() // for internal use { $this->r = ExecSQL($this->sql); return $this->r; } function DataReader($_sql) { $this->sql = $_sql; } function fetch() { if (!$this->r) $this->Execute(); $temp = mysql_fetch_array($this->r, MYSQL_ASSOC); if (is_array($temp)) { reset($temp); while (list($key, $val) = each($temp)) { $temp[$key]=stripslashes($val); } } $this->a=$temp; return $this->a; } function get_array() { $this->Execute(); $this->a = ''; $res = array(); while ($a = $this->fetch()) $res[] = $a; return $res; } function get_single_array() { $this->Execute(); $this->a = ''; $res = array(); while ($a = $this->fetch()) $res = $a; return $res; } function get_assoc_array($key = '', $value = '') { $this->Execute(); $this->a = ''; $res = array(); if ($key > '') { while ($a = mysql_fetch_array($this->r)) { $res[$a[$key]] = $a[$value]; } } else { while ($a = mysql_fetch_row($this->r)) { $res[$a[0]] = $a[1]; } } return $res; } function get_values() { $this->Execute(); $this->a = ''; $res = array(); while ($a = mysql_fetch_row($this->r)) $res[] = $a[0]; return $res; } function get_scalar() { $this->Execute(); $this->a = mysql_fetch_row($this->r); return $this->a[0]; } } class DataTable { var $TableName = ""; var $ID_name = ""; var $Fields = array(); var $FieldByName = array(); var $sqlWhereSelect = ""; // empty or starts with 'and' var $sqlWhereDelete = ""; // empty or starts with 'and' var $sqlWhereUpdate = ""; // empty or starts with 'and' var $language = ""; // empty or language (ro,en,it) var $LanguageFielad = ""; var $LangCondition = ""; function LoadFields() { global $db_Database, $db_Connection; $this->Fields = array(); $fld = mysql_list_fields($db_Database, $this->TableName, $db_Connection); $fieldsCount = mysql_num_fields($fld); for ($i = 0; $i < $fieldsCount; $i++) { $fi = array(); $fi['Name'] = mysql_field_name($fld, $i); $fi['Length'] = mysql_field_len($fld, $i); $fi['Type'] = mysql_field_type($fld, $i); $fi['Flags'] = mysql_field_flags($fld, $i); $fi['CanSelect'] = 1; $fi['CanInsert'] = 1; $fi['CanUpdate'] = 1; $this->Fields[$i] = $fi; $this->FieldByName[$fi['Name']] = &$this->Fields[$i]; } } function DataTable($_TableName,$_LangField) { $this->TableName = $_TableName; $this->LoadFields(); $this->ID_name = $this->Fields[0]['Name']; $this->LanguageFielad = $_LangField; if($_SESSION['LANGUAGE'] != '' && $this->LanguageFielad != '') { $this->language = $_SESSION['LANGUAGE']; $this->LangCondition = " AND ".$this->LanguageFielad." = '".$this->language."' "; } } function create_reader($condition = '', $order = '') // condition must start with 'and' { //if ($this->Fields[$i]['CanSelect'] > 0) $s = ''; for ($i = 0; $i < count($this->Fields); $i++) $s .= "," . $this->Fields[$i]['Name']; $s = substr($s, 1); //$id = mysql_encode($id); $d = new DataReader("select $s from {$this->TableName} where 1=1 {$condition} {$this->sqlWhereSelect} {$this->LangCondition} $order"); return $d; } function CreateReader($condition = '', $order = '') { return $this->create_reader($condition, $order); } function read($id) { $id = mysql_encode($id); $d = $this->create_reader("and {$this->ID_name}='{$id}'"); return $d->fetch(); } function delete($id) { $id = mysql_encode($id); if (!$this->trigger_before_delete($id)) return; ExecSQL("delete from {$this->TableName} where {$this->ID_name}='{$id}' {$this->sqlWhereDelete}"); $this->trigger_after_delete($id); } function insert($set) { if (!$this->trigger_before_insert($set)) return false; $a = ''; $b = ''; reset($this->Fields); while (list(, $field) = each($this->Fields)) if ($field['CanInsert']) { $ok = true; if ($field['Name'] == $this->ID_name) { if ($set[$field['Name']] > ""); else $ok = false; } if ($ok) { $a .= ',' . mysql_encode($field['Name']); $b .= ',\'' . mysql_encode($set[$field['Name']]) . '\''; } } $a = substr($a,1); $b = substr($b,1); //echo "insert into {$this->TableName}($a) values($b)"; ExecSQL("insert into {$this->TableName}($a) values($b)"); $id = mysql_insert_id(); $this->trigger_after_insert($set, $id); return $id; } function update($set, $id) { $id = mysql_encode($id); $old = $this->read($id); if (!$this->trigger_before_update($set, $old, $id)) return false; $a = ''; reset($this->Fields); while (list(, $field) = each($this->Fields)) if ($field['CanUpdate']) { $ok = true; if ($field['Name'] == $this->ID_name) { if ($set[$field['Name']] > "") $ok = true; else $ok = false; }else { if ($set[$field['Name']] > "" || $set[$field['Name']] == "NULL") $ok = true; else $ok = false; if ($set[$field['Name']] == "NULL") $set[$field['Name']] = ''; } if ($ok) $a .= ',' . mysql_encode($field['Name']) . '=\'' . mysql_encode($set[$field['Name']]) . '\''; } $a = substr($a,1); //echo "update {$this->TableName} set $a where {$this->ID_name}='$id' {$this->sqlWhereUpdate}"; ExecSQL ("update {$this->TableName} set $a where {$this->ID_name}='$id' {$this->sqlWhereUpdate}"); $this->trigger_after_update($set, $old, $id); return $id; } function save($set, $id = 0) { if ($id > '') if ($this->read($id)) return $this->update($set, $id); return $this->insert($set); } function trigger_before_insert(&$new) { return true; } // works as validation function trigger_after_insert(&$new, $id) { } function trigger_before_update(&$new, &$old, $id) { return true; } // works as validation function trigger_after_update(&$new, &$old, $id) { } function trigger_before_delete($id) { return true; } // works as validation function trigger_after_delete($id) { } } //======================================================================================================================= //================================================== FILE UPLOAD ====================================================== //======================================================================================================================= class FileUpload { var $field_name; var $valid; var $type; var $size; var $tmp_name; var $original_name; function FileUpload($field_name, $valid_extensions = '') { $this->field_name = $field_name; $this->valid = 0; if (is_uploaded_file($_FILES[$field_name]['tmp_name'])) { $of = $_FILES[$field_name]['name']; $this->valid = 1; if ($valid_extensions > '') { $tmp = split(',', $valid_extensions); $ok = false; $found = false; foreach ($tmp as $s) { $s = trim($s); if ($s > '') { $found = true; if (ereg("$s\$", $of)) $ok = true; } } $this->valid = (!$found) || $ok; } if ($this->valid) { $this->tmp_name = $_FILES[$field_name]['tmp_name']; $this->size = $_FILES[$field_name]['size']; $this->original_name = $_FILES[$field_name]['name']; $this->type = $_FILES[$field_name]['type']; } } } /** * $overwrite_rule: -1 = ignore new version; 0 = overwrite ; 1 = sequential * * returns false if failed or filename on success **/ function Save($folder, $filename = '', $ext = '', $overwrite_rule = 0) { if ($this->valid) { if (ereg('^(.*)\.([A-Za-z0-9]+)$', $this->original_name, $rtmp)) { $_fn = ''; $_ext = ''; if ($filename > '') $_fn = $filename; else $_fn = $rtmp[1]; if ($ext > '') $_ext = $ext; else $_ext = $rtmp[2]; $fn = "$folder/$_fn.$_ext"; if (file_exists($fn)) { if ($overwrite_rule == -1) return false; if ($overwrite_rule == 1) { $i = 0; while (++$i) { $fn = "$folder/$_fn($i).$_ext"; if (!file_exists($fn)) break; if ($i >= 1000) return false; } } } if (move_uploaded_file($this->tmp_name, $fn)) { chmod($fn,0777); return $fn; }else return false; } } } } class FileOnDisk { function guess_filename($folder, $fn, $valid_extensions = '') { $valid = 1; $extensions_found = array(); $extensions_found_bn = array(); if ($handle = opendir($folder)) { while (false !== ($file = readdir($handle))) { if (ereg("^$fn\\.([A-Za-z0-9]+)\$", $file, $rtmp)) { $extensions_found[] = $rtmp[1]; $extensions_found_bn[$rtmp[1]] = true; } } } $found = false; if ($valid_extensions > '') { $tmp = split(',', $valid_extensions); foreach ($tmp as $s) { $s = trim($s); if ($s > '') { $found = true; if ($extensions_found_bn[$s]) return $fn . "." . $s; } } } if (!$found) { if (count($extensions_found) > 0) return $fn . "." . $extensions_found[0]; } return false; } function delete_guess_filename($folder, $fn, $valid_extensions = '') { $i = 0; while ($s = guess_filename($folder, $fn, $valid_extensions)) { $i++; unlink($s); if ($i > 1000) return false; } return i; } } function anyfile($s) { exec("ls {$s}.*",$r); if (count($r >= 1)) return $r[0]; return ""; } function pic($s) { echo ("$s.gif"); if (file_exists("$s.gif")) return "$s.gif"; if (file_exists("$s.jpg")) return "$s.jpg"; return ""; } /***************************************************************************/ /***** *****/ /***** DATE CLASS *****/ /***** *****/ /***************************************************************************/ class Date { var $date; var $regexps; var $get_formats; var $regexps_ord; var $default_get_format; var $default_set_format; function Date($date = '', $format = '') { $this->regexps = array(); $this->regexps['mysql'] = '^([0-9]{4})[-\./]?([0-9]{1,2})[-\./]?([0-9]{1,2})'; $this->regexps['date'] = '^([0-9]{1,2})[-\./]?([0-9]{1,2})[-\./]?([0-9]{4})'; $this->regexps['date_us'] = '^([0-9]{1,2})[-\./]?([0-9]{1,2})[-\./]?([0-9]{4})'; $this->regexps_ord = array(); $this->regexps_ord['mysql'][0] = 0; $this->regexps_ord['mysql'][1] = 1; $this->regexps_ord['mysql'][2] = 2; $this->regexps_ord['date'][0] = 2; $this->regexps_ord['date'][1] = 1; $this->regexps_ord['date'][2] = 0; $this->regexps_ord['date_us'][0] = 2; $this->regexps_ord['date_us'][1] = 0; $this->regexps_ord['date_us'][2] = 1; $this->get_formats = array(); $this->get_formats['mysql'] = "%Y-%m-%d"; $this->get_formats['date'] = "%d.%m.%Y"; $this->get_formats['date_we'] = "%d/%m/%Y"; $this->get_formats['date_us'] = "%m/%d/%Y"; global $default_input_date_format; global $default_print_date_format; $this->default_get_format = $default_input_date_format > '' ? $default_input_date_format : 'date'; $this->default_set_format = $default_print_date_format > '' ? $default_print_date_format : 'date'; if ($date == '') $this->date = mktime(); else if ($date == 'null') $this->date = null; else $this->Set($date, $format); } function Set($date, $format = '') { if ($format == '') $format = $this->default_set_format; if (ereg($this->regexps[$format], $date, $r)) { $y = $r[$this->regexps_ord[$format][0] + 1]; $m = $r[$this->regexps_ord[$format][1] + 1]; $d = $r[$this->regexps_ord[$format][2] + 1]; $this->date = mktime(0, 0, 0, $m, $d, $y); } else $this->date = null; } function Get($format = '') { if (!$this->date) return ""; if ($format == '') $format = $this->default_get_format; return strftime($this->get_formats[$format], $this->date); } } function transform_date_array (&$a, $f1 = 'mysql', $f2 = 'date', $name = 'Date') { for ($i = 0; $i< count ($a); $i++) { $d = new Date ($a[$i][$name], $f1); $a[$i][$name] = $d->Get ($f2); } } /***************************************************************************/ /***** *****/ /***** URL and FORM FUNCTIONS *****/ /***** *****/ /***************************************************************************/ function js_validate_s($field, $message, $rule, $rule_parameter = '') { if (($rule == 'required')|| ($rule == 'req')) $rule = "f.elements['$field'].value > ''"; if (($rule == 'integer') || ($rule == 'int')) $rule = "f.elements['$field'].value.match(/^\d*$/)"; if (($rule == 'regexp')|| ($rule == 'regex')) $rule = "f.elements['$field'].value.match($rule_parameter)"; if (($rule == 'float') || ($rule == 'real') || ($rule == 'decimal')) $rule = "f.elements['$field'].value.match(/^\d*(\.\d+)?$/)"; if (($rule == 'password')) $rule = "f.elements['$field'].value == f.elements['password_check'].value"; if (($rule == 'checked')) $rule = "f.elements['$field'].checked"; if (($rule == 'min_selected_index')) $rule = "f.elements['$field'].selectedIndex >= $rule_parameter"; if (($rule == 'max_selected_index')) $rule = "f.elements['$field'].selectedIndex <= $rule_parameter"; if (($rule == 'min')) $rule = "parseFloat(f.elements['$field'].value) >= $rule_parameter"; if (($rule == 'min_')) $rule = "parseFloat(f.elements['$field'].value) > $rule_parameter"; if (($rule == 'max')) $rule = "parseFloat(f.elements['$field'].value) <= $rule_parameter"; if (($rule == 'max_')) $rule = "parseFloat(f.elements['$field'].value) < $rule_parameter"; if (($rule == 'mail')) $rule = "f.elements['$field'].value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/)"; if (($rule == 'date')) $rule = "f.elements['$field'].value.match(/^(3[01]|[1-9]|0[1-9]|[12]\d)[\/-\\\.]([1-9]|0[1-9]|1[012])[\/-\\\.]\d{4}$/)"; if (($rule == 'date_mdy')) $rule = "f.elements['$field'].value.match(/^([1-9]|0[1-9]|1[012])[\/-\\\.](3[01]|[1-9]|0[1-9]|[12]\d)[\/-\\\.]\d{4}$/)"; if ($rule) return "if (!($rule)) { alert('$message'); try{ f.elements['$field'].focus(); } catch(e) { } return false; }"; else return ""; } function php_validate_field($field, $rule, $rule_parameter = '') { return true; } function js_validate($field, $message, $rule, $rule_parameter = '') { return js_validate_s($field, $message, $rule, $rule_parameter); } class FormElement { var $name; var $rules; function FormElement($_name) { $this->name = $_name; $this->rules = array(); } function AddRule($rule, $rule_param, $message) { $this->rules[] = array($rule, $rule_param, $message); } } class Form { var $elements; var $js_custom_rules; function php_custom_validate() { return true; } function Form() { $this->elements = array(); } // adauga o referinta !!!!!! function AddElement(&$element) { $this->elements[] = &$element; } // exemplu: $x = &$f->NewElement(); $x->AddRule(...); function &NewElement($name) { $element = new FormElement($name); $this->AddElement($element); return $element; } function js_generate() { $s = ""; for( $i = 0; $i<= count ($this->elements); $i++) { $k = $this->elements[$i]; $kr = $k->rules; for ($j = 0; $jname, $kr[$j][2], $kr[$j][0], $kr[$j][1]) . "\n"; } $s .= $js_custom_rules; return $s; } function validate() { return php_custom_validate(); } } /***************************************************************************/ /***** *****/ /***** SMARTY LAYOUTS AND STUFF *****/ /***** *****/ /***************************************************************************/ function GetLayoutImage($template, $screen, $layout = '') { global $default_layout, $AuthKey; if ($layout > ''); else { if (function_exists(get_layout)) $layout = get_layout($screen); if ($layout > ''); else $layout = $default_layout; } //if (function_exists(set_layout_vars)) //set_layout_vars($template, $screen, $layout); include "seo/$layout.php"; include "seo/$layout.$screen.php"; include "pages/$layout.php"; include "pages/$layout.$screen.php"; $replace= array(''); for($i=0;$iassign('keywords', implode(",",array_diff($keywords, $replace))); $template->assign("description", $page_description.$default_description); $template->assign('screen', $screen); $x = $template->fetch("$layout.$screen.tpl"); $template->assign('page_content', $x); return $template->fetch("layout.$layout.tpl"); } function DisplayLayout($template, $screen, $layout = '') { echo GetLayoutImage($template, $screen, $layout); } ?> '; if (is_array($message)) print_r($message); else echo $message; echo ""; } } function arrayUnique ( $rArray ){ $rReturn = array (); while ( list( $key, $val ) = each ( $rArray ) ){ if ( !in_array( $val, $rReturn ) ) array_push( $rReturn, $val ); } return $rReturn; } /** * @return array with text wrapped * @param name ARG string and length size of tab * @desc wrap text */ function wrap_text($arg,$length) { $text_return=''; $poz=-1; while (strlen($arg)>$length) { $temp=substr($arg,0,$length); $arg=substr($arg,$length,strlen($arg)); $poz++;$text_return[$poz]=$temp; } $poz++; $text_return[$poz]=$arg; return $text_return; } /** * @return true or false * @param name ARG string and lenght length * @desc Validate length of a string */ function Valid_len($arg,$length){ if (strlen($arg)>=$length) return true; else return false; } /** * @return true or false * @param name email * @desc Validate an email address */ function Valid_email($arg){ return eregi( "^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$", $arg); } /** * @return String * @param name GET or POST name * @desc Get value from GET or POST */ function has_access($type = "") { if (isset($_SESSION["userType"])) { if ($_SESSION["userType"]==$type && $_SESSION["userID"]>0) return true; else return false; } else return false; } function get_value($name, $method = "") { if(!empty($method)) { if($method == "POST" && array_key_exists($name, $_POST)) { return trim($_POST[$name]); } if($method == "GET" && array_key_exists($name, $_GET)) { return trim($_GET[$name]); } return null; } if(array_key_exists($name, $_POST) && !empty($_POST[$name])) { return trim($_POST[$name]); } if(array_key_exists($name, $_GET) && !empty($_GET[$name])) { return trim($_GET[$name]); } return null; } function to_mysql_date($data,$inc = 0) { if(strpos($data,"/")) { $my_date=explode("/",$data); } else if(strpos($data,"\\")) { $my_date=explode("\\",$data); } if(strpos($data,"-")) { $my_date=explode("-",$data); } if(strpos($data,":")) { $my_date=explode(":",$data); } if(!isset($my_date)) return null; $day = $my_date[0]+$inc; $month = $my_date[1]; $year = $my_date[2]; if(strlen($day)==1) $day="0".$day; if(strlen($month)==1) $month="0".$month; return $year."-".$month."-".$day; } /** * @return zz/ll/aaaa * @param data yyyy-mm-dd * @desc Romanian date from MySQL date */ function from_mysql_date($data) { if(strpos($data,"/")) { $my_date=explode("/",$data); } else if(strpos($data,"\\")) { $my_date=explode("\\",$data); } if(strpos($data,"-")) { $my_date=explode("-",$data); } if(strpos($data,":")) { $my_date=explode(":",$data); } $day = $my_date[2]; $month = $my_date[1]; $year = $my_date[0]; if(strlen($day)==1) $day="0".$day; if(strlen($month)==1) $month="0".$month; return $day."/".$month."/".$year; } function from_mysql_to_fox_date($data) { $d = explode(" ",$data); $data = $d[0]; if(strpos($data,"/")) { $my_date=explode("/",$data); } else if(strpos($data,"\\")) { $my_date=explode("\\",$data); } if(strpos($data,"-")) { $my_date=explode("-",$data); } if(strpos($data,":")) { $my_date=explode(":",$data); } $day = $my_date[2]; $month = $my_date[1]; //$year = substr($my_date[0], 2, 2); $year = $my_date[0]; if(strlen($day)==1) $day="0".$day; if(strlen($month)==1) $month="0".$month; return $year.$month.$day; } /** * @return UNIXTIMESTAMP * @param strDate romanian data * @desc get UNIXTIMESTAMP from romanian date */ function unixTimeStampRomanianDate($strDate){ $date = explode("/", $strDate); return mktime(0,0,0,$date[1],$date[0],$date[2]); } function unixTimeStampFromSQLDateTime($strSQLDateTime){ $arrDateTime = explode(" ", $strSQLDateTime); $arrDate = explode("-", $arrDateTime[0]); if(!isset($arrDateTime[1])) { $arrTime = array(0, 0, 0); } else { $arrTime = explode(":", $arrDateTime[1]); } return mktime($arrTime[0], $arrTime[1], $arrTime[2], $arrDate[1], $arrDate[2], $arrDate[0]); } /** * @return String * @param name Int to Format * @desc Format money for easy reading */ function niceint($int = 0) { if(substr($int,0,1) == '-') { $minus = "-"; $int = substr($int, 1, strlen($int)-1); } else { $minus = ""; } $dec = $int - floor($int); $int = floor($int); if($dec != 0) { $dec = substr($dec, 2); $decimal = ".".niceint($dec); } else { $decimal = ""; } $bottom = (strlen($int) % 3 == 0) ? 1:0; $newint = ''; for($i = strlen($int); $i >= $bottom; $i-=3) { $start = ($i>3) ? $i-3: 0; $count = ($i>=3) ? 3: $i; $newint= substr($int, $start, $count).",".$newint; } return $minus.substr($newint, 0, strlen($newint)-1).$decimal; } function Valid_date($arg){ return eregi( "^[0-3]{0,1}[0-9]{1}/[0-1]{1}[0-9]{1}/[1-9]{1}[0-9]{3}$", $arg); } function Valid_mysql_date($arg){ return eregi( "^[1-9]{1}[0-9]{3}-([0-1]{0,1}[1-9]{1})-([1-31]{1})$", $arg); } function Valid_number($arg){ return eregi( "^[0-9]+$", $arg); } function Valid_numberminus($arg){ return eregi( "^-{0,1}[0-9]+$", $arg); } function Valid_float($arg){ return eregi( "^[0-9]{1}(\\.[0-9]{0,2})?$", $arg); } function Valid_symbol($arg){ return eregi( "^[A-Z]{3,6}[1-9]{0,1}$", $arg); } function is_alpha($input) { return (("a" <= $input && $input <= "z") || ("A" <= $input && $input <= "Z"))?true:false; } function encrypt($to_encrypt) { /* Open the cipher */ $td = mcrypt_module_open ('rijndael-256', '', 'ofb', ''); /* Create the IV and determine the keysize length */ $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM); $ks = mcrypt_enc_get_key_size ($td); /* Create key */ include("configure.php"); $key = substr (md5 ($CRYPT_KEY), 0, $ks); /* Intialize encryption */ mcrypt_generic_init ($td, $key, $iv); /* Encrypt data */ $encrypted = mcrypt_generic ($td, $to_encrypt); /* Terminate encryption handler */ mcrypt_generic_deinit ($td); mcrypt_module_close ($td); $_SESSION["iv"] = serialize($iv); return $encrypted; } function decrypt($encrypted) { /* Open the cipher */ $td = mcrypt_module_open ('rijndael-256', '', 'ofb', ''); /* Create the IV and determine the keysize length */ $iv = unserialize($_SESSION["iv"]); $ks = mcrypt_enc_get_key_size ($td); /* Create key */ include("configure.php"); $key = substr (md5 ($CRYPT_KEY), 0, $ks); /* Initialize encryption module for decryption */ mcrypt_generic_init ($td, $key, $iv); /* Decrypt encrypted string */ $decrypted = mdecrypt_generic ($td, $encrypted); /* Terminate decryption handle and close module */ mcrypt_generic_deinit ($td); mcrypt_module_close ($td); return trim ($decrypted); } /** * @return IP * @desc Get user IP / Proxy transparent */ function fetchip() { //get useful vars: if (isset($_SERVER['HTTP_CLIENT_IP'])) $client_ip = $_SERVER['HTTP_CLIENT_IP']; else $client_ip=""; if (isset( $_SERVER['HTTP_X_FORWARDED_FOR'])) $x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR']; else $x_forwarded_for=""; if (isset($_SERVER['REMOTE_ADDR'])) $remote_addr = $_SERVER['REMOTE_ADDR']; else $remote_addr=""; // then the script itself if (!empty ($client_ip) ) { $ip_expl = explode('.',$client_ip); $referer = explode('.',$remote_addr); if($referer[0] != $ip_expl[0]) { $ip=array_reverse($ip_expl); $return=implode('.',$ip); } else { $return = $client_ip; }; } elseif (!empty($x_forwarded_for) ) { if(strstr($x_forwarded_for,',')) { $ip_expl = explode(',',$x_forwarded_for); $return = end($ip_expl); } else { $return = $x_forwarded_for; }; } else { $return = $remote_addr; }; unset ($client_ip,$x_forwarded_for,$remote_addr,$ip_expl); return $return; } function displayPageSmart($page, $rec_count, $page_size, $layout) { $str = ""; $page_nr = 5; $page_count=ceil($rec_count/$page_size); $page_start = (0 > $page - $page_nr -1 ?0 : $page-$page_nr-1); $page_stop = ($page_count > $page + 5 ? $page + 5 : $page_count); $page_back=$page>0?$page-1:$page; $page_back_back=$page - $page_nr>1?$page - $page_nr:1; $page_next = $page < $page_count ? $page + 1:$page; $page_next_next = $page + $page_nr <= $page_count ? $page + $page_nr : $page_count; if ($page_count > 1) { $k = 0; for ($i = $page_start; $i <$page_stop; $i++) { $page_array [$k][Name] = $i; $page_array [$k][Value] = $i+1; $k++; } $tpl = new Smarty(); $tpl->assign('rec_count', $rec_count); $tpl->assign('page', $page); $tpl->assign('page_back', $page_back); $tpl->assign('page_back_back', $page_back_back); $tpl->assign('page_count', $page_count); $tpl->assign('page_array', $page_array); $tpl->assign('page_next', $page_next); $tpl->assign('page_next_next', $page_next_next); $str = $tpl->fetch("page.$layout.tpl"); } return $str; } function prepareListCheck ($s, $a) { $sa = split (",",$s); $rez = $a; $rez [Checked] = $sa; return $rez; } function _readdir($dir, $id) { $files = array(); if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $poz=strpos($file,$id); if ($poz===0) array_push($files, $file); } } } sort($files, SORT_ASC); if (!empty($files[0])) return $filename=$files[0]; else return '' ; } function array_filter_multi($input, $filter="", $keepMatches=true) { if (!is_array($input)) return ($input==$filter xor $keepMatches==false) ? $input : false; while (list ($key,$value) = @each($input)){ $res = array_filter_multi($value, $filter,$keepMatches); if ($res !== false) $out[$key] = $res; } return $out; } function session_default() { $language = $_SESSION['LANGUAGE']; $last_page = $_SESSION['last_page']; session_destroy(); session_start(); $_SESSION['LANGUAGE'] = $language; $page = $last_page; return $page; } function validateURL($URL) { $domain = "([[:alpha:]][-[:alnum:]]*[[:alnum:]])(\.[[:alpha:]][-[:alnum:]]*[[:alpha:]])+"; $dir = "(/[[:alpha:]][-[:alnum:]]*[[:alnum:]])*"; $page = "(/[[:alpha:]][-[:alnum:]]*\.[[:alpha:]]{3,5})?"; $getstring = "(\?([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+)(&([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+))*)?"; $pattern = "^".$domain.$dir.$page.$getstring."$"; return eregi($pattern, $URL); } function distance($lat1, $lon1, $lat2, $lon2) { // Formula for calculating distances // from latitude and longitude. $dist = acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2))); $dist = rad2deg($dist); $miles = (float) $dist * 69; // To get kilometers, multiply miles by 1.61 $km = (float) $miles * 1.61; // This is all displaying functionality // $display = sprintf("%0.2f",$miles).' miles' ; // $display .= ' ('.sprintf("%0.2f",$km).' kilometers)' ; return $miles ; } function copy_file_url($from_url,$to_path) { $fis = file($from_url); $fis = implode("",$fis); //var_dump($fis); //die(); if($fis) { $to = fopen($to_path,'w'); fwrite($to,$fis); fclose($to); return true; }else return false; } function fill_sort_table($new_row) { $old_sort = $_GET['sort']; $new_sort = $old_sort; if(strpos($old_sort,$new_row) === false) $new_sort .= ','.$new_row.' ASC'; else { $start_p = strpos($new_sort,$new_row)+strlen($new_row); $type = substr($new_sort,$start_p+1,3); if($type == 'ASC') { $first = substr($new_sort,0,$start_p); $last = substr($new_sort,$start_p+4,strlen($new_sort)); $new_sort = $first.' DESC'.$last; }elseif($type == 'DES') { $end_p = $start_p-strlen($new_row); $first = substr($new_sort,0,$end_p-1); $last = substr($new_sort,$start_p+5,strlen($new_sort)); if($end_p == 0) $new_sort = $last; else $new_sort = $first.$last; } } if (substr($new_sort,0,1)== ',') $new_sort = substr($new_sort,1,strlen($new_sort)); return $new_sort; } function set_arrows($sort_str) { $arr = explode(',',$sort_str); for($i=0;$i 0 || $valoare_lei != '') { setlocale(LC_MONETARY, 'ro_RO'); $lei = money_format("%i",$valoare_lei); }else $lei = ''; return $lei; } function parse_dir($mydir) { $dir = opendir($mydir); $k=0; while((false!==($file=readdir($dir)))) { if($file!="." and $file !="..") { $files[$k] = $mydir.$file; $k++; } } closedir($dir); return $files; } function clean_pict_products() { $no_del = 0; $files = parse_dir("../produse/"); for($i=0;$icreate_reader("AND pict_url = '".$pict[$i]."'","limit 1"); $row_pict = $res_pict->get_single_array(); if(!$row_pict) { @unlink($files[$i]); $no_del++; } } return $no_del; } function rec_newsletter($email) { $obj_nclient = new DbTableNClients(); $res_check = $obj_nclient->create_reader("AND nclient_email = '".$email."' ","LIMIT 1"); $row_check = $res_check->get_single_array(); if($row_check) { $_SESSION['system_msg'] = " Esti inregistrat pentru newsletter !"; }else { $res_new = $obj_nclient->create_reader("","ORDER BY nclient_id DESC LIMIT 1"); $row_new = $res_new->get_single_array(); if($row_new) $new_id = $row_new['nclient_id']+1; else $new_id = 1; $rec['nclient_id'] = $new_id; $rec['nclient_email'] = $email; $rec['nclient_numbs'] = 0; $rec['nclient_time'] = time(); $obj_nclient->save($rec); $_SESSION['system_msg'] = "Ai fost inregistrar cu succes !"; } } function out_newsletter($email) { ExecSQL("DELETE FROM news_clients WHERE nclient_email = '".$email."' ; "); $ok = mysql_affected_rows(); if($ok) $_SESSION['system_msg'] = "Abonamentul tau pentru newsletter a fost anulat ."; else $_SESSION['system_msg'] = "Adresa de email nu a fost iregistrata pentru newsletter !"; } function clean_pict_magazin() { $no_del = 0; $files = parse_dir("../pict_magazine/"); for($i=0;$icreate_reader(" AND magazin_pict = '".$pict[$i]."'","limit 1"); $row_pict1 = $res_pict1->get_single_array(); if(!$row_pict1) { echo $pict[$i]."
"; @unlink("../pict_magazine/".$pict[$i]); @unlink("../pict_magazine/big_".$pict[$i]); @unlink("../pict_magazine/small_".$pict[$i]); $no_del++; } } } return $no_del; } function users_login($email,$pass) { $error_login = ''; if($email == "" || !$email) $error_login = 1; if($pass == "" || !$pass) $error_login = 1; if(!$error_login) { $obj_users = new DbTableUsers(); if ($_SERVER['REMOTE_ADDR']=='83.166.220.142' || $_SERVER['REMOTE_ADDR']=='80.97.71.202') { # de la sediul SNS nu e nevoie de parola, pentru teste $res_check = $obj_users->CreateReader("AND user_name = '".$email."' AND user_valid = '1'" ,"LIMIT 1"); } else { $res_check = $obj_users->CreateReader("AND user_name = '".$email."' AND user_pass = '".sha1($pass)."' AND user_valid = '1'" ,"LIMIT 1"); } $row_check = $res_check->get_single_array(); if(!$row_check) $error_login = 1; } if(!$error_login) { $_SESSION['U_INFO'] = $row_check; header("location: send.html"); } return $error_login; } function bliss_users_login($surname,$name,$card,$pass) { $error_login = ''; //echo $surname." ".$name." ".$card; if($surname == "" || !$surname) $error_login = 1; if($name == "" || !$name) $error_login = 1; if($pass == "" || !$pass) $error_login = 1; if($card == "" || !$card) $error_login = 1; if(!$error_login) { $obj_users = new DbTableUsers(); $res_check = $obj_users->CreateReader(" AND user_nume = '".$name."' AND user_prenume = '".$surname."' AND user_card = ".$card." AND user_pass = '".sha1($pass)."' AND user_bliss='1'" ," LIMIT 1"); $row_check = $res_check->get_single_array(); if(!$row_check) $error_login = 1; } if(!$error_login) { $_SESSION['U_INFO'] = $row_check; header("location: send.html"); } return $error_login; } function bnr() { $file = @file("http://www.bnro.ro/Ro/Info/", "r"); if(!$file) { return null; } $tmp = TRUE; for ($i=0; $i')) if ($tmp) { $dolar = substr ($file[$i], 18, 6); $tmp = FALSE; } else { $euro = substr ($file[$i], 18, 6); break; } $ret = array ($dolar, $euro); return $ret; } function bnr_valute() { $pozitie_data = 8; $valuta = array(); $simbol = array(); $data_curs = ""; $file = @file("http://www.bnro.ro/ro/info/curs_ext.asp"); if(!$file) return null; $k = 0; $h = 1; for ($i=0; $i')) array_push($valuta,str_replace(",",".",str_replace(" ","",str_replace("/T","",str_replace("<","",substr($file[$i], 18, 6)))))); if (strstr ($file[$i], '')) array_push($simbol,str_replace("TD>","",substr ($file[$i], strlen($file[$i])-13, 6))); //92, 6 if(strstr ($file[$i], '')) { $h++; if($h == $pozitie_data) $data_curs = substr(strip_tags($file[$i]),1,11); } } return array($data_curs,$simbol,$valuta); } function gw_send_sms($mobile_sender,$sms_to,$sms_msg,$uid="",$smslog_id="",$flash=false) { $ok = false; $sms_from = $mobile_sender; // set failed first $p_status = 2; //setsmsdeliverystatus($smslog_id,$uid,$p_status); $sms_type = 2; // text if ($flash) { $sms_type = 0; //flash } $URL = "/cgi-bin/sendsms?username=".urlencode('test')."&password=".urlencode('foobar'); $URL .= "&from=".urlencode($sms_from)."&to=".urlencode($sms_to)."&text=".urlencode($sms_msg); $URL .= "&dlr-mask=31&dlr-url=".urlencode('http://localhost'."/index.php?page=status&type=%d&slid=$smslog_id&uid=$uid"); $connection = @fsockopen('localhost',13131,$error_number,$error_description,60); if($connection) { socket_set_blocking($connection, false); fputs($connection, "GET $URL HTTP/1.0\r\n\r\n"); while (!feof($connection)) { $myline = fgets($connection, 128); if ($myline == "Sent.") { $ok = true; // set pending $p_status = 0; } } } @fclose ($connection); return $p_status; } function Valid_mobile($number) { $tmp_numar = str_replace("+","",str_replace(" ","",$number)); return (is_numeric($tmp_numar) && strlen($tmp_numar)>9); } function valid_phone($number,$errors, &$tmp_pret, &$tmp_numar, &$tmp_operator, &$tmp_tara) { $tmp_numar = str_replace("+","",str_replace(" ","",$number)); if (!is_numeric($tmp_numar) && strlen($tmp_numar)<10) return "
  • ($tmp_numar)".$errors[2][$_SESSION['LANGUAGE']]; $row = mysql_fetch_assoc(mysql_query(" select operatori_prefixe.prefix operator, operatori_tari.prefix tara, operatori.pret pret from operatori_prefixe, operatori_tari,operatori where operatori.id=operatori_prefixe.operator and operatori.tara=operatori_tari.id and '$tmp_numar' like concat(cache,'%');")); snsdebug ($row?'ok':'bad'); if ($row) { $tmp_tara= $row[tara]; $tmp_pret= $row[pret]; $tmp_operator = $row[operator]; } else { $f = fopen ("/var/log/wrong_numbers.log","a"); fwrite ($f, date("Y-m-d H:i:s : ") . $tmp_numar . "\n"); fclose($f); return "
  • ($tmp_numar)".$errors[0][$_SESSION['LANGUAGE']]; } } function send_sms($rec,$user_id) { $errors[0]['ro']='Pentru tara in care doriti sa trimiteti nu exista inca tarife in vigoare'; $errors[0]['en']='There are no active fees for this country'; $errors[1]['ro']='Pentru acest operator nu exista inca tarife in vigoare'; $errors[1]['en']='There are no active fees for this service'; $errors[2]['ro']='Numarul nu este valid.'; $errors[2]['en']='This phone number isn\'t valid.'; $errors[3]['ro']='Nu ati introdus un mesaj.'; $errors[3]['en']='You need to fill in a message.'; $errors[4]['ro']='
  • Credite insuficiente !'; $errors[4]['en']='
  • Not enough credits !'; $error = ''; $error.=valid_phone($rec['sms_number'], $errors, $tmp_pret, $tmp_numar, $tmp_operator, $tmp_tara); $tmp_text = $rec['sms_text']; if(!$tmp_text) $error.="
  • ($tmp_numar)".$errors[3][$_SESSION['LANGUAGE']]; if (!$error) { $obj = new DbTableUa(); $res = $obj->CreateReader(" AND ua_user='$user_id'"); $row = $res->get_single_array(); $ua_id=$row['ua_id']; if(strlen($tmp_text)>160) { if($row['ua_credite_ramase']>=($tmp_pret*ceil(strlen($tmp_text)/154))) $ins_user['ua_credite_ramase']=$row['ua_credite_ramase']-($tmp_pret*ceil(strlen($tmp_text)/154)); elseif($row['ua_abonament']==1) $ins_user['ua_suplimentar']=$row['ua_suplimentar']+($tmp_pret*ceil(strlen($tmp_text)/154)); else $error.=$errors[4][$_SESSION['LANGUAGE']]; } else { if($row['ua_credite_ramase']>=$tmp_pret) $ins_user['ua_credite_ramase']=$row['ua_credite_ramase']-$tmp_pret; elseif($row['ua_abonament']==1) $ins_user['ua_suplimentar']=$row['ua_suplimentar']+$tmp_pret; else $error.=$errors[4][$_SESSION['LANGUAGE']]; } } if (!$error) { if (strlen($tmp_text)>160) { for($i=0;$isave($ins[$i]); $sms_id = mysql_insert_id(); if($rec['sms_now']==0) { $tmp_date = explode("-",$rec['sms_month']); $rec['sms_month'] = $tmp_date[0]; $rec['sms_year'] = $tmp_date[1]; //print_r($rec); $tmp_time=mktime($rec['sms_hour'],$rec['sms_min'],0,$rec['sms_month'],$rec['sms_day'],$rec['sms_year']); $ins[$i]['sms_time']=$tmp_time; $ins[$i]['sms_status']='10'; } else { if (substr($rec['sms_number'],0,4)=='4078') { $rec['sms_number']=substr($rec['sms_number'],1); $rec['sms_eticheta'] = 1866; } $ins[$i]['sms_status'] = gw_send_sms($rec['sms_eticheta'],$rec['sms_number'],$ins[$i]['sms_text'],$user_id,$sms_id,false); } $ins[$i]['sms_text']=addslashes($ins[$i]['sms_text']); $obj->update($ins[$i],$sms_id); } $obj = new DbTableUa(); $obj->update($ins_user,$ua_id); } return $error; } function generatePassword ($length = 8) { // start with a blank password $password = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } // done! return $password; } function language($id) { $obj_text = new DbTableText(); $res_text = $obj_text->create_reader("AND text_sid = ".$id,"LIMIT 1"); $row_text = $res_text->get_single_array(); return stripslashes($row_text['text_text']); } ?>