<?php
function my_magic_quotes($var) {
foreach ($var AS $key => $value) {
if (is_array($value))
$var[$key] = my_magic_quotes($value);
else
$var[$key] = addslashes($value);
}
return $var;
}
function redirect($strUrl) {
if (!empty($strUrl)) {
closedb();
header("Location:" . $strUrl);
//echo $strUrl;
exit;
}
}
function closedb() {
global $connect;
mysql_close($connect);
}
function setErr($strErrMsg) {
$_SESSION["errorMessage"] = $strErrMsg;
}
function getErr($intColspan) {
if (!empty($_SESSION["errorMessage"])) {
echo("<tr><td align=\"center\" colspan=\"" . $intColspan ."\" class=\"err\">" . $_SESSION["errorMessage"] . "</td></tr>");
$_SESSION["errorMessage"] = "";
}
}
function showErr() {
echo($_SESSION["errorMessage"]);
$_SESSION["errorMessage"] = "";
}
function setusererr($strErrMsg) {
$_SESSION["setusererr"] = $strErrMsg;
}
function showusererr() {
echo("<br><font color=red size=2><B>".$_SESSION["setusererr"]);
$_SESSION["setusererr"] = "";
}
function gotoerror($strErrMsg) {
setErr($strErrMsg);
redirect("error.php");
}
function selfx($strComp1, $strComp2) {
if (!strcasecmp($strComp1, $strComp2))
return(" selected");
}
function chkfx($strChkValue) {
if (trim($strChkValue) != "")
return (1);
else
return (0);
}
function cbfx($strCbValue) {
if (trim($strCbValue) == "1")
echo(" checked");
elseif (trim($strCbValue) == "true")
echo(" checked");
elseif (trim($strCbValue) == "True")
echo(" checked");
}
function getfx($key) {
if (get_magic_quotes_gpc())
return stripslashes($_GET[$key]);
else
return $_GET[$key];
}
function postfx($key) {
if (get_magic_quotes_gpc())
return stripslashes($_POST[$key]);
else
return $_POST[$key];
}
function dbfx($strVal) {
return addslashes(trim($strVal));
}
function pdbfx($strVal) {
if (get_magic_quotes_gpc())
return trim($_POST[$strVal]);
else
return addslashes(trim($_POST[$strVal]));
}
function gdbfx($strVal) {
if (get_magic_quotes_gpc())
return trim($_GET[$strVal]);
else
return addslashes(trim($_GET[$strVal]));
}
function stsfx($strStatusValue) {
//echo $strStatusValue;
//die;
if (trim($strStatusValue) == 1)
echo("<img src=\"../images/icons/+.gif\" border=\"0\">");
elseif (trim($strStatusValue) == 2)
echo("<img src=\"../images/icons/+.gif\" border=\"0\">");
else
echo("<img src=\"../images/icons/-.gif\" border=\"0\">");
}
function stsfxroot($strStatusValue) {
//echo $strStatusValue;
//die;
if (trim($strStatusValue) == 1)
echo("<img src=\"images/icons/+.gif\" border=\"0\">");
elseif (trim($strStatusValue) == 2)
echo("<img src=\"images/icons/+.gif\" border=\"0\">");
else
echo("<img src=\"images/icons/-.gif\" border=\"0\">");
}
function stsfx2($strStatusValue) {
//echo $strStatusValue;
//die;
if (trim($strStatusValue) == 1)
echo("<img src=\"images/icons/+.gif\" border=\"0\">");
elseif (trim($strStatusValue) == 2)
echo("<img src=\"images/icons/+.gif\" border=\"0\">");
else
echo("<img src=\"images/icons/-.gif\" border=\"0\">");
}
function stsfx1($strStatusValue, $strTrue) {
if (cmpfx($strStatusValue, $strTrue))
echo("<img src=\"../images/icons/-.gif\" border=\"0\">");
else
echo("<img src=\"../images/icons/+.gif\" border=\"0\">");
}
function cmpfx($str1, $str2) {
if (!strcasecmp($str1, $str2))
return (1);
else
return (0);
}
function sendmail($strTo, $strFrom, $strCC, $strBCC, $strSubject, $strBody, $htmlMail) {
$strHeaders = "";
if ($htmlMail) {
$strHeaders .= "MIME-Version: 1.0\r\n";
$strHeaders .= "Content-type: text/html; charset=iso-8859-1\r\n";
}
if (strcmp($strTo, "") != 0)
$strHeaders .= "To: " . $strTo . "\r\n";
if (strcmp($strFrom, "") != 0)
$strHeaders .= "From: " . $strFrom . "\r\n";
if (strcmp($strCC, "") != 0) {
$strHeaders .= "Cc: " . $strCC . "\r\n";
if (strcmp($strTo, "") != 0)
$strTo .= "," . $strCC;
else
$strTo .= $strCC;
}
if (strcmp($strBCC, "") != 0) {
$strHeaders .= "Bcc: " . $strBCC . "\r\n";
if (strcmp($strBcc, "") != 0)
$strTo .= "," . $strBcc;
else
$strTo .= $strBcc;
}
return @mail($strTo, $strSubject, $strBody, $strHeaders);
}
function clearsql() {
global $_where;
$_where = "";
}
function appsql($strCond) {
global $_where;
if (!empty($strCond) && strcmp($strCond, "") != 0) {
if (!empty($_where) && strcmp($_where, "") != 0)
$_where .= " AND " . $strCond;
else
$_where = " WHERE " . $strCond;
}
}
function getsql() {
global $_where;
return ($_where);
}
function iff($prmStr, $strTrue, $strFalse) {
if ($prmStr)
return $strTrue;
else
return $strFalse;
}
function cint($str) {
return (round($str, 0));
}
function cdbl($str) {
return (round($str, 2));
}
class paging {
var $ps; //Pagesize
var $pss; //Page scroll size
var $pg; //Current page
var $tr; //Total rows
var $tp; //Total pages
var $rec; //Start row for limit
var $cps;
var $sp; //Start page
var $ep; //End page
var $tps; //Total page sets
var $pps; //Previous page set
var $nps; //Next page set
var $i; //Counter
function paging() {
$this->pss = 5;
if (!empty($_GET["ps"]))
$this->ps = (int) $_GET["ps"];
else
$this->ps = 10;
if (empty($this->ps))
$this->ps = 10;
if (!empty($_GET["pg"]))
$this->pg = (int) $_GET["pg"];
else
$this->pg = 1;
if (empty($this->pg))
$this->pg = 1;
$this->i = 1;
}
function setpages($sql) {
$rs = mysql_fetch_row(mysql_query($sql));
$this->tr = $rs[0];
//$this->tp = round($this->tr/$this->ps, 0)+1;
$this->tp = round($this->tr/$this->ps, 0);
if ($this->tp < 1) $this->tp = 1;
if ($this->tr > $this->ps)
if (($this->tr%$this->ps) != 0)
$this->tp++;
//echo $this->tr%$this->ps;
if (!empty($this->pg)) {
if ($this->pg > $this->tp)
$this->pg = $this->tp;
}
else
$this->pg = 1;
$this->rec = ($this->pg*$this->ps)-$this->ps;
}
function getlimit() {
return " limit " . $this->rec . ", " . $this->ps;
}
function showPagingw($url, $qs) {
$this->cps = cint( ($this->pg / $this->pss) + .49 );
$this->tps = ((cint( ($this->tp / $this->pss) + .49 )-1)*$this->pss)+1;
$this->sp = (($this->cps-1)*$this->pss)+1;
$this->ep = $this->sp + 5;
if ($this->ep > $this->tp)
$this->ep = $this->tp;
$this->pps = $this->sp - 5;
$this->nps = $this->sp + 5;
echo "<span class=\"paging\">";
//if ($this->pg == 1)
//echo "<< <";
//else {
//if ($this->pps > 0)
// echo "<a href=\"" . $url . "?pg=" . ($this->pps+4) . "&" . $qs . "\" class=botlinks><<</a>";
//else
// echo "<<";
//echo " <a href=\"" . $url . "?pg=" . ($this->pg-1) . "&" . $qs . "\" //class=botlinks><</a>";
//}
echo " ";
//$this->ep=($this->ep;
for ($this->i=$this->sp; $this->i<=$this->ep; $this->i++) {
if ($this->i == $this->pg)
echo "[" . $this->i . "]";
else
echo "<a href=\"" . $url . "?pg=" . $this->i . "&" . $qs . "\" class=botlinks>" . $this->i . "</a>";
echo " ";
}
echo " ";
//if ($this->pg == $this->tp)
//echo "> >>";
//else {
//echo "<a href=\"" . $url . "?pg=" . ($this->pg+1) . "&" . $qs . "\" class=botlinks>></a> ";
//if ($this->nps <= $this->tps)
// echo "<a href=\"" . $url . "?pg=" . $this->nps . "&" . $qs . "\" class=botlinks>>></a>";
//else
// echo ">>";
//}
}
function showPaging($url, $qs) {
$this->cps = cint( ($this->pg / $this->pss) + .49 );
$this->tps = ((cint( ($this->tp / $this->pss) + .49 )-1)*$this->pss)+1;
$this->sp = (($this->cps-1)*$this->pss)+1;
$this->ep = $this->sp + 5;
if ($this->ep > $this->tp)
$this->ep = $this->tp;
$this->pps = $this->sp - 5;
$this->nps = $this->sp + 5;
if ($this->pg !=1 && $this->pg!='' )
echo "<a href='".$url."?pg=".($this->pg-1).$qs."'></a>";
//echo "Page: ";
echo " ";
for ($this->i=$this->sp; $this->i<=$this->ep; $this->i++) {
//$url="Listing".$this->i.".html";
$url1=$url."?pg=".$this->i.$qs;
if ($this->i == $this->pg)
{
echo "[" . $this->i . "]";
$nextpage= $url."?pg=".($this->i+1).$qs;
//echo $nextpage;
}
else
echo "<a href=\"" . $url1 . "\" class=bodylinks><strong>" . $this->i . "</strong></a>";
echo " ";
$url1='';
}
echo " ";
}
}
function alert($str) {
echo "<script language=\"javascript\" type=\"text/javascript\">" . chr(13);
echo " alert(\"" . $str . "\");" . chr(13);
echo "</script>";
}
function getqs($nm) {
$strqs = "";
foreach ($_GET as $key=>$val) {
if (!strpos("," . $nm . ",", $key))
if ($strqs == "") {
if (is_array($val))
$strqs = $key . "[]=" . implode("&" . $key . "[]=", $val);
else
$strqs = $key . "=" . $val;
}
else {
if (is_array($val))
$strqs .= "&" . $key . "[]=" . implode("&" . $key . "[]=", $val);
else
$strqs .= "&" . $key . "=" . $val;
}
}
return $strqs;
}
function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
/*
$interval can be:
yyyy - Number of full years
q - Number of full quarters
m - Number of full months
y - Difference between day numbers
(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
d - Number of full days
w - Number of full weekdays
ww - Number of full weeks
h - Number of full hours
n - Number of full minutes
s - Number of full seconds (default)
*/
if (!$using_timestamps) {
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
}
$difference = $dateto - $datefrom; // Difference in seconds
switch($interval) {
case 'yyyy': // Number of full years
$years_difference = floor($difference / 31536000);
if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
$years_difference--;
}
if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
$years_difference++;
}
$datediff = $years_difference;
break;
case "q": // Number of full quarters
$quarters_difference = floor($difference / 8035200);
while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
$months_difference++;
}
$quarters_difference--;
$datediff = $quarters_difference;
break;
case "m": // Number of full months
$months_difference = floor($difference / 2678400);
while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
$months_difference++;
}
$months_difference--;
$datediff = $months_difference;
break;
case 'y': // Difference between day numbers
$datediff = date("z", $dateto) - date("z", $datefrom);
break;
case "d": // Number of full days
$datediff = floor($difference / 86400);
break;
case "w": // Number of full weekdays
$days_difference = floor($difference / 86400);
$weeks_difference = floor($days_difference / 7); // Complete weeks
$first_day = date("w", $datefrom);
$days_remainder = floor($days_difference % 7);
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
if ($odd_days > 7) { // Sunday
$days_remainder--;
}
if ($odd_days > 6) { // Saturday
$days_remainder--;
}
$datediff = ($weeks_difference * 5) + $days_remainder;
break;
case "ww": // Number of full weeks
$datediff = floor($difference / 604800);
break;
case "h": // Number of full hours
$datediff = floor($difference / 3600);
break;
case "n": // Number of full minutes
$datediff = floor($difference / 60);
break;
default: // Number of full seconds (default)
$datediff = $difference;
break;
}
return $datediff;
}
function str_contains($haystack, $needle, $ignoreCase = false) {
if ($ignoreCase) {
$haystack = strtolower($haystack);
$needle = strtolower($needle);
}
$needlePos = strpos($haystack, $needle);
return ($needlePos === false ? false : ($needlePos+1));
}
function genpasswordalpha($length){
srand((double)microtime()*1000000);
$vowels = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "p","q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
$cons = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
$num_vowels = count($vowels);
$num_cons = count($cons);
for($i = 0; $i < $length; $i++){
$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
}
return strtoupper(substr($password, 0, $length));
}
function genpasswordnum($length){
srand((double)microtime()*1000000);
$vowels = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
$cons = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
$num_vowels = count($vowels);
$num_cons = count($cons);
for($i = 0; $i < $length; $i++){
$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
}
return substr($password, 0, $length);
}
function GetRecortarTexto ($vTxt, $Car) {
if (strlen($vTxt) > $Car) {
return substr($vTxt, 0, $Car) . "...";
} else return $vTxt;
}
function GetIP()
{
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
//$ip=str_replace(".","-",$ip);
//$ip2=split("-",$ip);
//$ip1=str_replace("-".$ip2[3],"-XXX",$ip);
//$ip1=str_replace("-",".",$ip1);
return($ip);
}/*-------GetIP()-------*/
function PrepareName($s)
{
$abc = "1234567890abcdefghijklmnopqrstuvwxyz";
$s = strtolower($s);
$r = "";
for($i=0;$i<strlen($s);$i++)
{
if (strpos($abc,$s[$i])!==false)
$r .= $s[$i];
if (($s[$i]==' ')&&($r[strlen($r)-1]!=' '))
$r .= ' ';
}
$r = trim($r);
return str_replace(' ','-',$r);
}
function getsettings($variable_id,$selected,$returntype=1,$default=1,$multiple=1) {
$sql="select * from settings where variable_id=".$variable_id;
$cmd = mysql_query($sql);
mysql_query($sql);
while ($rs = mysql_fetch_array($cmd))
{
if ($returntype==1)
{
$temp=split(",",$rs[1]);
if ($default==2)
if ($multiple==2 && $selected=='')
echo "<option value='' selected>----Any----</option>";
else
echo "<option value=''>----Any----</option>";
for($i=0;$i<count($temp);$i++)
{
if ($temp[$i]==$selected)
echo "<option value='".$temp[$i]."' selected>".$temp[$i]."</option>";
else
if ($multiple==2 && str_contains($selected,$temp[$i]))
echo "<option value='".$temp[$i]."' selected>".$temp[$i]."</option>";
else
echo "<option value='".$temp[$i]."'>".$temp[$i]."</option>";
}
}
else
return $rs[1];
}
}
function getsettingssingle($variable_id) {
$sql="select * from settings where variable_id=".$variable_id;
$cmd = mysql_query($sql);
mysql_query($sql);
while ($rs = mysql_fetch_array($cmd))
{
return $rs[1];
}
}
function categorypath($cat)
{
$ret="";
while($cat>0)
{
$sql="select category_id,category_name,category_parent_id from category_master where category_id=$cat ";
$cmd = mysql_query($sql);
$rs = mysql_fetch_array($cmd);
if($rs!=0)
{
$catnameis = $rs[1];
$catnameis = str_replace("/","-",$catnameis);
$catnameis = str_replace(" ","-",$catnameis);
$catnameis = str_replace("?","-",$catnameis);
$catnameis = str_replace(":","-",$catnameis);
$ret=($cat==1?"":" » ").$catnameis.$ret;
$cat=$rs[2];
}
else
$cat=0;
}
return $ret;
}
function categorypathlink($cat,$default=0)
{
$ret="";
while($cat>0)
{
$sql="select category_id,category_name,category_parent_id from category_master where category_id=$cat";
$cmd = mysql_query($sql);
$rs = mysql_fetch_array($cmd);
if($rs!=0)
{
$catnameis = $rs[1];
$catnameis = str_replace("/","-",$catnameis);
$catnameis = str_replace(" ","-",$catnameis);
$catnameis = str_replace("?","-",$catnameis);
$catnameis = str_replace(":","-",$catnameis);
if ($cat!=1)
if ($default!=$cat)
$ret=($cat==1?"":" » ")."<a href='category".$rs[0].".html' class=bodylinks>".$catnameis."</a>".$ret;
else
$ret=($cat==1?"":" » ").$catnameis.$ret;
else
$ret=($cat==1?"":" » ")."<a href='index.php' class=bodylinks>".$catnameis."</a>".$ret;
$cat=$rs[2];
}
else
$cat=0;
}
return $ret;
}
function DateAdd($v,$d=null , $f="Y-m-d"){
$d=($d?$d:date("Y-m-d"));
return date($f,strtotime($v." days",strtotime($d)));
}
function DateMinus($v,$d=null , $f="Y-m-d"){
$d=($d?$d:date("Y-m-d"));
return date($f,strtotime(-$v." days",strtotime($d)));
}
function generateCategories($cat,$lev,$default)
{
if ($cat!=1)
echo "<option value=$cat ".(isset($default)&&$default==$cat?"selected":"").">";
for($x=0;$x<$lev;$x++)
echo "- ";
$result=mysql_query("select category_name from category_master where category_id=$cat");
$rscat = mysql_fetch_array($result);
echo $rscat["category_name"];
$result=mysql_query("select category_id from category_master where category_parent_id=$cat order by category_name");
while ($rscat = mysql_fetch_array($result))
{
generateCategories($rscat["category_id"],$lev+1,$default);
}
mysql_free_result($result);
}
function generateCategoriesroot($cat,$lev,$default)
{
echo "<option value=$cat ".(isset($default)&&$default==$cat?"selected":"").">";
for($x=0;$x<$lev;$x++)
echo "- ";
$result=mysql_query("select category_name from category_master where category_id=$cat");
$rscat = mysql_fetch_array($result);
echo $rscat["category_name"];
$result=mysql_query("select category_id from category_master where category_parent_id=$cat order by category_name");
while ($rscat = mysql_fetch_array($result))
{
generateCategories($rscat["category_id"],$lev+1,$default);
}
mysql_free_result($result);
}
function makeClickableLinks($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1" target=_blank>\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
return $text;
}
?>