
PK 
<?php
class common
{
var $min_logout_time;
var $prefix;
var $realpath;
var $httppath;
//===================================================================================
function common() // constructor
{
$this->min_logout_time=20;
$this->prefix="jeff_";
$this->realpath="";
$this->httppath="";
}
//====================================================================================
//====================================================================================
function prefix_table($tablename)
{
$prefix=$this->prefix;
$tablename=$prefix.$tablename;
return $tablename;
}
//====================================================================================
//=====================================================================================
/* function will open a existing file and return its contents */
function return_file_content($db_domain,$xpath)
{
$fp=fopen("$xpath","r");
$fullcontent=fread($fp,filesize("$xpath"));
fclose($fp);
return $fullcontent;
}
//=====================================================================================
//=====================================================================================
/*to generate a secure unique sessionkey*/
function hashgen()
{
$hash = md5(uniqid(rand(),1));
return $hash;
}//function hashgen()
//=====================================================================================
//=====================================================================================
/*checks if the site was last accessed before 20min and if so prompts user to relogin*/
function check_admin_session($hash,$db_domain)
{
$adminsession=$this->prefix_table("admin_session");
$qry="Select admin_id,timestamp from $adminsession where hash='$hash'";
$line = $db_domain->get_a_line($qry);
$adminid=$line[0];
$min_logout_time=$this->min_logout_time;
$min=$min_logout_time*60;
if( (time() - $line[1] ) > $min )
{
//echo("$session_timed_out");
return 0;
}
else
{
$timestmp=time();
$qry="Update $adminsession set timestamp='$timestmp' where hash='$hash'";
if (! ($result = mysql_query ("$qry")))
{
$men = mysql_errno();
$mem = mysql_error();
echo ("<h4>$qry $men $mem</h4>");
exit;
}
else
{
return $adminid;
}
}
}
//=====================================================================================
//=====================================================================================
/*checks if the site was last accessed before 20min and if so prompts user to relogin*/
function check_member_session($hash,$db_domain)
{
$membersession=$this->prefix_table("member_session");
$qry="Select member_id,timestamp from $membersession where hash='$hash'";
$line = $db_domain->get_a_line($qry);
$memberid=$line[0];
$min_logout_time=$this->min_logout_time;
$min=$min_logout_time*60;
if( (time() - $line[1] ) > $min )
{
//echo("$session_timed_out");
return 0;
}
else
{
$timestmp=time();
$qry="Update $membersession set timestamp='$timestmp' where hash='$hash'";
if (! ($result = mysql_query ("$qry")))
{
$men = mysql_errno();
$mem = mysql_error();
echo ("<h4>$qry $men $mem</h4>");
exit;
}
else
{
return $memberid;
}
}
}
//=====================================================================================
//=====================================================================================
/*checks if the site was last accessed before 20min and if so prompts user to relogin*/
function check_viewer_session($hash,$db_domain)
{
$membersession=$this->prefix_table("viewers_session");
$qry="Select viewer_id,timestamp from $membersession where hash='$hash'";
$line = $db_domain->get_a_line($qry);
$memberid=$line[0];
$min_logout_time=$this->min_logout_time;
$min=$min_logout_time*60;
if( (time() - $line[1] ) > $min )
{
//echo("$session_timed_out");
return 0;
}
else
{
$timestmp=time();
$qry="Update $membersession set timestamp='$timestmp' where hash='$hash'";
if (! ($result = mysql_query ("$qry")))
{
$men = mysql_errno();
$mem = mysql_error();
echo ("<h4>$qry $men $mem</h4>");
exit;
}
else
{
return $memberid;
}
}
}
//=====================================================================================
//=====================================================================================
function check_url($url)
{
$url=ereg_replace("http://","",$url);
$url=ereg_replace("www\.","",$url);
if(ereg("[0-9a-zA-Z-]",$url))
{
//echo("url=$url");
}
else
{
$r=1;
}
if($r!=1)
{
$r=$this->check_count($url);
$furl=$r;
}
if($r==1)
{
return $r;
}
}
//====================================================================================
//=====================================================================================
function check_for_http($url)
{
if(preg_match("/http:\/\//",$url)) // if url contains http
{
return $url;
}
elseif(preg_match("/https:\/\//",$url)) // if url contains https
{
return $url;
}
else
{
$url="http://".$url;
return $url;
}
}
//=====================================================================================
//=====================================================================================
function check_email($email)
{
if (! (preg_match ("/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/", "$email") || preg_match("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/" , "$email") && $email != ""))
{
return 0;
}
else
{
return 1;
}
}
//====================================================================================
//====================================================================================
function print_page_break($db_object,$return_content,$count,$records,$links,$fPage)
{
$pages=ceil($count/$records);
$pattern="/<{page_loopstart}>(.*?)<{page_loopend}>/s";
preg_match($pattern,$return_content,$out);
$myvar=$out[1];
$str="";
for($i=1;$i<=$pages;$i++)
{
$link=$links."page=$i";
$page=$i;
if ($page == $fPage)
{
$page = $i;
$str.=preg_replace("/<{(.*?)}>/e","$$1",$myvar);
}
else
{
$page = "<a href=\"$link\">$page</a>";
$str.=preg_replace("/<{(.*?)}>/e","$$1",$myvar);
}
}
$return_content=preg_replace($pattern,$str,$return_content);
return $return_content;
}
//=====================================================================================
//======================================================================================
function storepic($imagefile,$imageid,$type,$ext,$flag)
{
$orgfile=$imageid."_image".$ext;
$dir=$this->photopath;
if($flag=="t")
{
$dir.="thumbnail";
}
else
{
$dir.="zoom";
}
@move_uploaded_file ("$imagefile" , "$dir/$orgfile");
}
//======================================================================================
//======================================================================================
function create_thumbnail($orgfilename,$orgfilepath,$new_width,$new_height)
{
$imagefile = $orgfilepath;
$tmbimagefile = $this->realpath."performers";
//$nw=120; //The Width Of The Thumbnails
//$nh=100; //The Height Of The Thumbnails
$nw=$new_width; //The Width Of The Thumbnails
$nh=$new_height; //The Height Of The Thumbnails
$ipath = $imagefile;
$tpath = $tmbimagefile;
$ipath = trim($ipath);
$l = strlen($ipath);
$ipath = substr($ipath,0,$l);
$tpath = trim($tpath);
$l = strlen($tpath);
$tpath = substr($tpath,0,$l);
$img = $imagefile;
$img_name = $orgfilename;
$thumb = $orgfilename;
$dimensions = GetImageSize($img);
$thname = "$tpath/$img_name";
$w=$dimensions[0];
$h=$dimensions[1];
$img2 = @ImageCreateFromJpeg($img);
$thumb= @ImageCreateTrueColor($nw,$nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w > $h)
{
$adjusted_width = $w / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
@ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
@ImageJPEG($thumb,$thname,95);
}
elseif(($w < $h) || ($w == $h))
{
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
@ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
@ImageJPEG($thumb,$thname,95);
}
else
{
@ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);
@ImageJPEG($thumb,$thname,95);
}
@imagedestroy($img2);
}
//======================================================================================
//======================================================================================
function create_zoom($orgfilename,$orgfilepath)
{
$imagefile = $orgfilepath;
$tmbimagefile = $this->photopath;
$tmbimagefile.="zoom";
$nw=500; //The Width Of The zoom img
$nh=500; //The Height Of The zoom img
$ipath = $imagefile;
$tpath = $tmbimagefile;
$ipath = trim($ipath);
$l = strlen($ipath);
$ipath = substr($ipath,0,$l);
$tpath = trim($tpath);
$l = strlen($tpath);
$tpath = substr($tpath,0,$l);
$img = $orgfilepath."/".$orgfilename;
$img_name = $orgfilename;
$thumb = $orgfilename;
$dimensions = GetImageSize($img);
$thname = "$tpath/$img_name";
$w=$dimensions[0];
$h=$dimensions[1];
$img2 = ImageCreateFromJpeg($img);
$thumb=ImageCreateTrueColor($nw,$nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w > $h)
{
$adjusted_width = $w / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
ImageJPEG($thumb,$thname,95);
}
elseif(($w < $h) || ($w == $h))
{
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
ImageJPEG($thumb,$thname,95);
}
else
{
ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);
ImageJPEG($thumb,$thname,95);
}
imagedestroy($img2);
}
//======================================================================================
//======================================================================================
function resizepicture($imagefile,$imageid,$type,$f,$suf)
{
$imgdir=$this->root_path;
$imgdir.="/photos";
$orgfile=$imgdir."/".$imagefile;
$size=getImageSize($orgfile);
$orgwidth=$size[0];
$orgheight=$size[1];
if($f=="t")
{
$newwidth=$this->thumb_width;
$newheight=$this->thumb_height;
$file=$imageid."_t".$suf;
}
elseif($f=="r")
{
$newwidth=$this->resize_width;
$newheight=$this->resize_height;
$file=$imageid."_r".$suf;
}
$blankimg=ImageCreate($newwidth,$newheight); // a blank image
if($suf==".jpg")
{
$img = ImageCreateFromJpeg("$orgfile");
}
elseif($suf==".png")
{
$img = ImageCreateFromPng("$orgfile");
}
elseif($suf==".gif")
{
$img = ImageCreateFromGif("$orgfile");
}
$newpath=$imgdir."/".$file;
//echo "new: $newwidth:$newheight,Org : $orgwidth:$orgheight";
imagecopyresized ($blankimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $orgwidth, $orgheight);// reduce the image sizes
if($suf==".png")
{
ImagePng($blankimg,$newpath); // output my image
}
elseif($suf==".jpg")
{
ImageJPEG($blankimg,$newpath); // output my image
}
else
{
ImageGIF($blankimg,$newpath); // output my image
}
ImageDestroy($blankimg);
}
//======================================================================================
/*
//======================================================================================
function sendmail ($from_name, $from_email, $to_name, $to_email, $subject, $text_message="", $html_message, $attachment="")
{
$from = "$from_name <$from_email>";
$to = "$to_name <$to_email>";
$main_boundary = "----=_NextPart_".md5(rand());
$text_boundary = "----=_NextPart_".md5(rand());
$html_boundary = "----=_NextPart_".md5(rand());
$headers = "From: $fromn";
$headers .= "Reply-To: $fromn";
$headers .= "X-Mailer: Hermawan Haryanto (http://hermawan.com)n";
$headers .= "MIME-Version: 1.0n";
$headers .= "Content-Type: multipart/mixed;ntboundary="$main_boundary"n";
$message .= "n--$main_boundaryn";
$message .= "Content-Type: multipart/alternative;ntboundary="$text_boundary"n";
$message .= "n--$text_boundaryn";
$message .= "Content-Type: text/plain; charset="ISO-8859-1"n";
$message .= "Content-Transfer-Encoding: 7bitnn";
$message .= ($text_message!="")?"$text_message":"Text portion of HTML Email";
$message .= "n--$text_boundaryn";
$message .= "Content-Type: multipart/related;ntboundary="$html_boundary"n";
$message .= "n--$html_boundaryn";
$message .= "Content-Type: text/html; charset="ISO-8859-1"n";
$message .= "Content-Transfer-Encoding: quoted-printablenn";
$message .= str_replace ("=", "=3D", $html_message)."n";
if (isset ($attachment) && $attachment != "" && count ($attachment) >= 1)
{
for ($i=0; $i<count ($attachment); $i++)
{
$attfile = $attachment[$i];
$file_name = basename ($attfile);
$fp = fopen ($attfile, "r");
$fcontent = "";
while (!feof ($fp))
{
$fcontent .= fgets ($fp, 1024);
}
$fcontent = chunk_split (base64_encode($fcontent));
@fclose ($fp);
$message .= "n--$html_boundaryn";
$message .= "Content-Type: application/octetstreamn";
$message .= "Content-Transfer-Encoding: base64n";
$message .= "Content-Disposition: inline; filename="$file_name"n";
$message .= "Content-ID: <$file_name>nn";
$message .= $fcontent;
}
}
$message .= "n--$html_boundary--n";
$message .= "n--$text_boundary--n";
$message .= "n--$main_boundary--n";
@mail ($to, $subject, $message, $headers);
}
//======================================================================================
*/
}//end class
######################################################
# for paginaton
######################################################
function pagination($url, $total_items, $per_page, $start, $range = 5, $pages = 'total', $prevnext = TRUE, $prevnext_always = FALSE, $firstlast = TRUE, $firstlast_always = FALSE) {
// Here you can edit the looks of the pagination, make sure you keep all instances
// of %s intact, they will be replaced by text by the script. Read
// http://www.php.net/sprintf for more information on how to change the order of
// these format 'tags'.
// The links themselves, for these goes: first %s is the url, the second the text for the link
$str_links = " <a href='%s'>%s</a> ";
$str_selected = " <a href='%s'>[%s]</a> ";
$str_prevnext = " <a href='%s'>%s</a> ";
$str_firstlast = " <a href='%s'>%s</a> ";
// The pages text, has only one %s: the text
$str_pages = "%s ";
// The text on previous, next, first, and last links. One %s: a (optional) number
$prev_txt = '<<%s';
$next_txt = '%s>>';
$first_txt = '««%s';
$last_txt = '%s»»';
// Pretty self explanatory now..
$pages_txt_total = '%s Pages';
$pages_txt_page = 'Page %s';
$pages_txt_pageoftotal = 'Page %s of %s';
/*******************************Start of the code**************************/
$str = '';
// First, check on a few parameters to see if they're ok, we don't want negatives
$total_items = ($total_items < 0) ? 0 : $total_items;
$per_page = ($per_page < 1) ? 1 : $per_page;
$range = ($range < 1) ? 1 : $range;
$sel_page = 1;
// Remove the start argument from the url, if it's there, then add the arguments to the url
$args = (isset($_SERVER['argv'][0])) ? preg_replace('/(start=)(\d+)(&|)/i', '', $_SERVER['argv'][0]) : '';
$url .= $args . ((substr($args, -1) == '&') ? '' : '&') . 'start=';
$total_pages = ceil($total_items / $per_page);
// Are there more than one pages to show? If not, this section will be skipped,
// and only the pages_text will be shown
if ($total_pages > 1) {
// The page we are on
$sel_page = floor($start / $per_page) + 1;
// The ranges indicate how many pages should be displayed before and after
// the selected one. Here, it will check if the range is an even number,
// and adjust the ranges appropriately. It will behave best on non-even numbers
$range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
$range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
$page_min = $sel_page - $range_min;
$page_max = $sel_page + $range_max;
// This parts checks whether the ranges are 'out of bounds'. If we're at or near
// the 'edge' of the pagination, we will start or end there, not at the range
$page_min = ($page_min < 1) ? 1 : $page_min;
$page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
if ($page_max > $total_pages) {
$page_min = ($page_min > 1) ? $total_pages - $range + 1 : 1;
$page_max = $total_pages;
}
// Build the links
for ($i = $page_min;$i <= $page_max;$i++) {
$str .= sprintf((($i == $sel_page) ? $str_selected : $str_links), $url . (($i - 1) * $per_page), $i);
}
// Do we got previous and next links to display?
if (($prevnext) || (($prevnext) && ($prevnext_always))) {
// Aye we do, set what they will look like
$prev_num = (($prevnext === 'num') || ($prevnext === 'nump')) ? $sel_page - 1 : '';
$next_num = (($prevnext === 'num') || ($prevnext === 'numn')) ? $sel_page + 1 : '';
$prev_txt = sprintf($prev_txt, $prev_num);
$next_txt = sprintf($next_txt, $next_num);
// Display previous link?
if (($sel_page > 1) || ($prevnext_always)) {
$start_at = ($sel_page - 2) * $per_page;
$start_at = ($start_at < 0) ? 0 : $start_at;
$str = sprintf($str_prevnext, $url . $start_at, $prev_txt).$str;
}
// Next link?
if (($sel_page < $total_pages) || ($prevnext_always)) {
$start_at = $sel_page * $per_page;
$start_at = ($start_at >= $total_items) ? $total_items - $per_page : $start_at;
$str .= sprintf($str_prevnext, $url . $start_at, $next_txt);
}
}
// This part is just about identical to the prevnext links, just a few minor
// value differences
if (($firstlast) || (($firstlast) && ($firstlast_always))) {
$first_num = (($firstlast === 'num') || ($firstlast === 'numf')) ? 1 : '';
$last_num = (($firstlast === 'num') || ($firstlast === 'numl')) ? $total_pages : '';
$first_txt = sprintf($first_txt, $first_num);
$last_txt = sprintf($last_txt, $last_num);
if ((($sel_page > ($range - $range_min)) && ($total_pages > $range)) || ($firstlast_always)) {
$str = sprintf($str_firstlast, $url . '0', $first_txt).$str;
}
if ((($sel_page < ($total_pages - $range_max)) && ($total_pages > $range)) || ($firstlast_always)) {
$str .= sprintf($str_firstlast, $url . ($total_items - $per_page), $last_txt);
}
}
}
// Display pages text?
if ($pages) {
// Decide what to show
switch ($pages) {
case 'total':
$pages_txt = sprintf($pages_txt_total, $total_pages);
break;
case 'page':
$pages_txt = sprintf($pages_txt_page, $sel_page);
break;
case 'pageoftotal':
$pages_txt = sprintf($pages_txt_pageoftotal, $sel_page, $total_pages);
break;
}
// Replace it
$str = sprintf($str_pages, $pages_txt) .": ". $str;
}
// Done, return the pagination
return $str;
}
@extract($_POST);
@extract($_GET);
?>


PK 99