Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

805 lines
26 KiB

<?php
$ConvertCommand='convert';
$ComposeCommand='composite';
// Include this function on your pages
function BEGIN_GZ(){
ob_start();
ob_implicit_flush(false);
};
function END_GZ() {
global $HTTP_ACCEPT_ENCODING;
if( headers_sent() ){
$encoding = false;
}elseif( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ){
$encoding = 'x-gzip';
}elseif( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ){
$encoding = 'gzip';
}else{
$encoding = false;
}
if( $encoding ){
$contents = ob_get_contents();
ob_end_clean();
header('Content-Encoding: '.$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$size = strlen($contents);
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $size);
print($contents);
exit();
}else{
ob_end_flush();
exit();
}
};
function handle_pereodical_jobs(){
global $DATABASE;
$QS="SELECT * FROM site_tasks WHERE DATEDIFF(CURDATE(),ts)>1 OR ts = 0";
$result=$DATABASE->Query($QS,false);
foreach($result as $CT){
switch($CT['task_id']){
case 'vip-top':{
check_vip_tops();
break;
};
case 'vip-status':{
check_vip_stat();
break;
};
case 'pic-rate':{
check_pic_rate();
break;
};
case 'user-stat':{
check_usr_stat();
break;
};
};
$QS="UPDATE site_tasks SET ts=CURDATE() WHERE id={$CT['id']}";
$DATABASE->Query($QS,false);
};
};
function GetColorOfImage($FS,$Mode=0){
$im=imagecreatefromjpeg($FS);
$P1=imagecolorat($im,0,0);
$P2=imagecolorat($im,200,0);
$P3=imagecolorat($im,200,200);
$P4=imagecolorat($im,0,200);
switch($Mode){
case 0:{
$CT=imagecolorsforindex($im,$P1);
$CI['red']=$CT['red'];$CI['green']=$CT['green'];$CI['blue']=$CT['blue'];
$CT=imagecolorsforindex($im,$P1);
$CI['red']+=$CT['red'];$CI['green']+=$CT['green'];$CI['blue']+=$CT['blue'];
$CT=imagecolorsforindex($im,$P1);
$CI['red']+=$CT['red'];$CI['green']+=$CT['green'];$CI['blue']+=$CT['blue'];
$CT=imagecolorsforindex($im,$P1);
$CI['red']+=$CT['red'];$CI['green']+=$CT['green'];$CI['blue']+=$CT['blue'];
$CI['red']=round($CI['red']/4);$CI['green']=round($CI['green']/4);$CI['blue']=round($CI['blue']/4);
$RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
break;
};
case 1:{
$CI=imagecolorsforindex($im,$P1);
$RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
break;
};
case 2:{
$CI=imagecolorsforindex($im,$P2);
$RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
break;
};
case 3:{
$CI=imagecolorsforindex($im,$P3);
$RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
break;
};
case 4:{
$CI=imagecolorsforindex($im,$P4);
$RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
break;
};
case 5:{
$CI=imagecolorsforindex($im,$P1);
$RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
$CI=imagecolorsforindex($im,$P2);
$RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
$CI=imagecolorsforindex($im,$P3);
$RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
$CI=imagecolorsforindex($im,$P4);
$RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
break;
};
};
return $RetColor;
};
function check_vip_tops(){
global $DATABASE;
$WQS="SELECT * FROM top_vips WHERE DATEDIFF(CURDATE(),ts)> (days-3)"; // Warning Query
$result=$DATABASE->Query($WQS,false);
foreach($result as $WR) top_exp3d($WR);
$CQS="DELETE FROM top_vips WHERE DATEDIFF(CURDATE(),ts)> days"; // Clearup Query
$DATABASE->Query($CQS,false);
};
function check_vip_stat(){
global $DATABASE;
$WQS="SELECT * FROM vips WHERE DATEDIFF(CURDATE(),ts)> ((month_counts*30)-3)"; // Warning Query
$result=$DATABASE->Query($WQS,false);
foreach($result as $WR) vip_exp3d($WR);
$CQS="DELETE FROM vips WHERE DATEDIFF(CURDATE(),ts)> (month_counts*30)"; // Clearup Query
$DATABASE->Query($CQS,false);
};
function check_pic_rate(){
global $DATABASE;
$QS="UPDATE photos SET views = 1";
$DATABASE->Query($QS,false);
};
function check_usr_stat(){};
function vip_exp3d($WR){
$WarnText='Your VIP status is about to expire in three (3) days.';
$user=load_profile($WR['account_id']);
DeliverAdminMessage($user['email'],'',$WarnText);
};
function top_exp3d($WR){
$WarnText='Your VIP Top Listing on folowing region '. PrintHTTP_DecorateGeoLocation($WR['city'],$WR['state'],$WR['country'],$WR['region']) .' about to expire';
$user=load_profile($WR['account_id']);
DeliverAdminMessage($user['email'],'',$WarnText);
};
function isBot(){
$BAgents=array('google','yahoo','spider','crawler','bot','msn');
$RetVal=false;
for($index=0;$index<count($BAgents);$index++)
if ( strlen(strstr(strtolower($_SERVER['HTTP_USER_AGENT']),$BAgents[$index]))>0 ) $RetVal=true;
return $RetVal;
};
function WatermarkIt($IMGName){
global $ComposeCommand,$SYSPath;
list($width, $height, $type, $attr) = getimagesize($IMGName);
if($width<400){
$MarkFile = getcwd().'/style/img/heraldic_100.png';
} else {
$MarkFile = getcwd().'/style/img/heraldic_200.png';
};
$THBName=getcwd()."/tmp/".basename($IMGName);
$runStr = $ComposeCommand . ' -gravity SouthEast "' . $MarkFile . '" "' . $IMGName . '" "' . $THBName . '"';
$RetCode =`$runStr`;
unlink($IMGName);
$MD5Code=md5_file($THBName);
copy($THBName,$IMGName);
unlink($THBName);
return $MD5Code;
};
function ResizePicIfNeeded_SYSTEM($IMGName){
global $ConvertCommand,$SYSPath;
list($width, $height, $type, $attr) = getimagesize($IMGName);
if( $width > 600 )
{
$DW = 600;
$DH = $height * 600 / $width;
$resize='-gaussian 1x1+5+5 -resize '.$DW.'x'.$DH;
} else {
$resize='';
};
$THBName=$SYSPath."tmp/".basename($IMGName);
//echo "$IMGName --> $THBName";
$runStr = $ConvertCommand .' "'.$IMGName.'" -flatten '.$resize.' -antialias -normalize -enhance -sharpen 5 "'.$THBName.'"';
$runStr = $ConvertCommand .' "'.$IMGName.'" -flatten '.$resize.' -adaptive-blur 3x3+10+10 -normalize -enhance -sharpen 1 "'.$THBName.'"';//PRiSHIKI
$runStr = $ConvertCommand .' "'.$IMGName.'" -flatten '.$resize.' -normalize -sharpen 0.2 "'.$THBName.'"';
$RetCode =`$runStr`;
unlink($IMGName);
$FileName=getcwd().'/photos/'.md5_file($THBName).'.jpg';
copy($THBName,$FileName);
unlink($THBName);
return $FileName;
};
function ImageNotTooSmall($FNAME){
global $MinimalSize;
list($width, $height, $type, $attr) = getimagesize($FNAME);
return $MinimalSize<($width*$height);
};
function SetImageSizeFromFile($ID=0,$IMGName=''){
list($width, $height, $type, $attr) = getimagesize($IMGName);
if ($ID>0) {
if($width && $height){
SetImageSize($ID,$width,$height);
} else DeleteItem($ID);
};
}
function CreateThumb200($IMGName, $THBName, $ID=0){
global $ConvertCommand,$SYSPath;
list($width, $height, $type, $attr) = getimagesize($IMGName);
if ($ID>0){
if($width && $height){
SetImageSize($ID,$width,$height);
} else return false;
};
$retcode=false;
if(is_writable (dirname(dirname($THBName)))){
if (!is_dir(dirname($THBName))){
mkdir (dirname($THBName));
$retcode=true;
};
$retcode=true;
if( $width > $height ){
$runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$height.'x'.$height.'!+0+0 -flatten -resize 200x200 "'.$THBName.'"';
} else {
$runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$width.'x'.$width.'!+0+0 -flatten -resize 200x200 "'.$THBName.'"';
}
echo $runStr."\n";
$RetCode =`$runStr`;
echo $RetCode."\n";
};
return $retcode;
};
function CreateThumb100($IMGName){
global $ConvertCommand,$SYSPath;
list($width, $height, $type, $attr) = getimagesize($IMGName);
$THBName=$SYSPath."photos/thumbs/".basename($IMGName,'.jpg').'.jpg';
if( $width > $height ){
$runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$height.'x'.$height.'!+0+0 -flatten -resize 100x100 "'.$THBName.'"';
} else {
$runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$width.'x'.$width.'!+0+0 -flatten -resize 100x100 "'.$THBName.'"';
}
$RetCode =`$runStr`;
};
function CreateThumb50($IMGName){
global $ConvertCommand,$SYSPath;
list($width, $height, $type, $attr) = getimagesize($IMGName);
$THBName=$SYSPath."photos/thumbs/".basename($IMGName,'.jpg').'_50.jpg';
if( $width > $height ){
$runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$height.'x'.$height.'!+0+0 -flatten -resize 50x50 "'.$THBName.'"';
} else {
$runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$width.'x'.$width.'!+0+0 -flatten -resize 50x50 "'.$THBName.'"';
}
$RetCode =`$runStr`;
};
function GetPicParam($PID){
global $WEBPath,$SYSPath;
$PSPath=$SYSPath.'photos/'.$PID.'.jpg';
if (file_exists($PSPath)){
$RetVal= getimagesize($PSPath);
}else {
$RetVal= array(200,200);
};
return $RetVal;
};
function PrintDATA_Picture_Path($ItemID,$PTyp=0){
global $WEBPath,$SYSPath, $ShowImagesLocal, $ShowThumbnailsLocal;
$NPPath="style/img/nopic.gif";
$ADPath="style/img/mopic.gif";
if ($ItemID){
$Data=GetItemData($ItemID);
//print_r($Data);
if(($Data['remote']=='disable') || $ShowImagesLocal || $ShowThumbnailsLocal ){
$PSPath=$SYSPath . substr($Data['fs_path'],3);
$DP=substr(dirname($Data['fs_path']),3).'/thumb';
$FN=basename($Data['fs_path']);
$CC=false;
$RetVal='';
if (file_exists($PSPath)){
switch ($PTyp){
case 0:{
$PTPath=$PSPath;
break;
};
case 1:{
if ($ShowThumbnailsLocal){
$PTPath=$SYSPath.$DP.'/'.$FN;
if(!file_exists($PTPath)){
$CC=CreateThumb200( $PSPath, $PTPath , $ItemID );
};
} else {
$RetVal=$Data['thumbnail_url'];
};
break;
};
};
if ( file_exists($PTPath)){
if ($PTyp>0){
if ($RetVal=='') $RetVal=$WEBPath.'/'.$DP.'/'.$FN;
} else {
$RetVal=$WEBPath.'/'.substr($Data['fs_path'],3);
};
} elseif(!$CC) {
$RetVal=$WEBPath.$ADPath .'" '.$PTPath ;
} else {
DeleteItem($ItemID);
$RetVal=$WEBPath.$NPPath;
};
} elseif( $PTyp==0 && !$ShowImagesLocal ){
$RetVal=$Data['url'];
} elseif( $PTyp==1 && !$ShowThumbnailsLocal){
$RetVal=$Data['thumbnail_url'];
} elseif( $PTyp==1 && $ShowThumbnailsLocal ){
$PTPath=$SYSPath.$DP.'/'.$FN;
if(file_exists($PTPath)){
$RetVal=$WEBPath.'/'.$DP.'/'.$FN;
} else $RetVal=$WEBPath.$NPPath;
};
} else {
if($PTyp>0){
$DP=substr(dirname($Data['fs_path']),3).'/thumb';
$FN=basename($Data['fs_path']);
$PTPath=$SYSPath.$DP.'/'.$FN;
if(file_exists($PTPath)===false){
$RetVal=$Data['thumbnail_url'];
} else $RetVal=$WEBPath.'/'.$DP.'/'.$FN;
} else {
$RetVal=$Data['url'];
};
};
} else {
$RetVal=$WEBPath . $NPPath;
};
return $RetVal;
};
function GetBackPath(){
if ($_SERVER['HTTP_REFERER']){
return ltrim(strrchr($_SERVER['HTTP_REFERER'],'/'),'/');
} else {
return '';
};
};
function PictureUpload(){//$SID
global $CUser;
$maxSize = 2097152; // 2 Megs by default
if( isset($_FILES['DTA']) ){
if(strstr($_FILES['DTA']['type'], 'image') === false){
$RetVal="<center><font color=Red><br><strong>The Uploaded File Isn't Image</strong><br><br></font></center>";
} elseif ($_FILES['DTA']['size'] > $maxSize ){
$RetVal="<center><font color=Red><br><strong>The Uploaded File Is Too Big</strong><br><br></font></center>";
} else {
$target_path = getcwd() . "/tmp/";
$picture_path= getcwd() . "/photos/";
$target_path .= basename( $_FILES['DTA']['tmp_name']);//$_FILES['DTA']['name']);
$srcpath=$_FILES['DTA']['tmp_name'];
//echo "Trying to move $srcpath ==> $target_path \n<br>";
if( @move_uploaded_file($srcpath, $target_path)){
list($width, $height, $type, $attr) = getimagesize($target_path);
if ( ($width/10)*($height/10)<625 ) {
@unlink($target_path);
$RetVal="<center><font color=Red><br><strong>File ". basename( $_FILES['DTA']['name'])." is too small<br>Please upload the image that is bigger then 250x250</strong><br><br></font></center>";
} else {
$picture_path.=md5_file($target_path).'.jpg';
@copy($target_path,$picture_path);
@unlink($target_path);
$picture_path=ResizePicIfNeeded_SYSTEM($picture_path);
WatermarkIt($picture_path);
$PictureName=basename($picture_path,'.jpg');
CreateThumb50($picture_path);
CreateThumb100($picture_path);
CreateThumb200($picture_path);
//echo "File Moved $srcpath ==> $target_path \n<br>";
if(isset($_POST['PIN'])) $PIPIN=1; else $PIPIN=0;
if( AddPicture($PictureName,$CUser['id'],$PIPIN,$CUser['vip']) ){ //AddBanner($_POST['TTL'],$_POST['URL'],$target_path, $SID) !== false
$RetVal="<center><br><strong>File ". basename( $_FILES['DTA']['name'])." Uploaded</strong><br><br></center>";
} else {
$RetVal="<center><font color=Red><br><strong>Error to add record into Database!</strong><br><br></font></center>";
};
};
} else {
$RetVal="<center><font color=Red><br><strong>Error to add record into Database!</strong><br><br></font></center>";
};
};
};
return $RetVal;
}
function make_300thumb($FileName){
list($width, $height, $type, $attr) = getimagesize($FileName);
#echo "IPR: $width, $height, $type, $attr\n";
if( $type == 1 ) $bim=LoadGif($FileName);
if( $type == 2 ) $bim=LoadJpeg($FileName);
if( $type == 3 ) $bim=LoadPng($FileName);
#var_dump(gd_info());
$Rim = ResizeIMG($bim,$width,$height,300);
$entry = "$FileName.987987";
$JCod=imagegif($Rim,$entry, 100);
$handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
$BytesRead=fread($handle,filesize($entry));
if ( !$BytesRead ){
echo " Read Failed Or File is Empty\n";
}
fclose($handle);
unlink($entry);
return $BytesRead;
};
function make_100thumb($FileName){
list($width, $height, $type, $attr) = getimagesize($FileName);
#echo "IPR: $width, $height, $type, $attr\n";
if( $type == 1 ) $bim=LoadGif($FileName);
if( $type == 2 ) $bim=LoadJpeg($FileName);
if( $type == 3 ) $bim=LoadPng($FileName);
#var_dump(gd_info());
$Rim = ResizeIMG($bim,$width,$height);
$entry = "$FileName.987987";
$JCod=imagegif($Rim,$entry, 100);
$handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
$BytesRead=fread($handle,filesize($entry));
if ( !$BytesRead ){
echo " Read Failed Or File is Empty\n";
}
fclose($handle);
unlink($entry);
return $BytesRead;
};
function make_40thumb($FileName){
list($width, $height, $type, $attr) = getimagesize($FileName);
#echo "IPR: $width, $height, $type, $attr\n";
if( $type == 1 ) $bim=LoadGif($FileName);
if( $type == 2 ) $bim=LoadJpeg($FileName);
if( $type == 3 ) $bim=LoadPng($FileName);
#var_dump(gd_info());
$Rim = ResizeIMG($bim,$width,$height,40);
$entry = "$FileName.987987";
$JCod=imagegif($Rim,$entry, 100);
$handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
$BytesRead=fread($handle,filesize($entry));
if ( !$BytesRead ){
echo " Read Failed Or File is Empty\n";
}
fclose($handle);
unlink($entry);
return $BytesRead;
};
function make_thumb_system($IMGName){
global $TempDir;
$THBName="$IMGName.987987";
//echo "$IMGName --> $THBName";
$RetCode =`convert "$IMGName" -sample 300x300 -flatten -resize 100x100 -normalize -enhance -sharpen 5 $THBName`;
//$RetCode =`convert "$IMGName" -sample 300x300 -flatten -median 1.8 -resize 100x100 -unsharp 3x3+30+50 -normalize -enhance -sharpen 5 $THBName`;
$handle = fopen($THBName, 'r') or die( "CreateThumbnail: Cannot open thumb/temp Image $THBName\n Rectode: $RetCode\n");
$TData=fread($handle,filesize($THBName));
fclose($handle);
unlink($THBName);
return $TData;
};
function LoadGif ($imgname)
{
$im = @imagecreatefromgif ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a blank image */
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function LoadPNG($imgname)
{
$im = @imagecreatefrompng($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function ResizePicIfNeeded_SYSTEMd($IMGName){
global $ConvertCommand,$TempDir;
list($width, $height, $type, $attr) = getimagesize($IMGName);
if( $width > 600 )
{
$DW = 600;
$DH = $height * 600 / $width;
$THBName="$IMGName.12387";
//echo "$IMGName --> $THBName";
$runStr = $ConvertCommand .' "'.$IMGName.'" -flatten -resize '.$DW.'x'.$DH.' -normalize -enhance -sharpen 5 "'.$THBName.'"';
$RetCode =`$runStr`;
//$RetCode =`convert "$IMGName" -sample 300x300 -flatten -median 1.8 -resize 100x100 -unsharp 3x3+30+50 -normalize -enhance -sharpen 5 $THBName`;
$handle = fopen($THBName, 'r') or die( "ResizeImage: Cannot open thumb/temp Image $THBName\n Rectode: $RetCode\n");
$TData=fread($handle,filesize($THBName));
fclose($handle);
unlink($THBName);
} else {
$handle = fopen($IMGName, 'r') or die( "ResizeImage: Cannot read Image $IMGName\n");
$TData=fread($handle,filesize($IMGName));
fclose($handle);
unlink($IMGName);
};
return $TData;
};
function ResizePicIfNeeded_PHP($FileName)
{
$fHandle = fopen( $FileName, 'r' );
$BytesRead = fread($fHandle,filesize($FileName));
fclose( $fHandle );
list($width, $height, $type, $attr) = getimagesize($FileName);
if( $width > 600 )
{
//echo "IPR: $width, $height, $type, $attr\n";
if( $type == 1 ) $bim=LoadGif($FileName);
if( $type == 2 ) $bim=LoadJpeg($FileName);
if( $type == 3 ) $bim=LoadPng($FileName);
$DW = 600;
$DH = $height * 600 / $width;
$Rim = @imagecreatetruecolor($DW, $DH)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocatealpha($Rim, 0, 0, 0, 175);
imagecopyresized($Rim,$bim,0,0,0,0,$DW,$DH,$width,$height);
$entry = "$FileName.456456";
$JCod=imagegif($Rim,$entry, 100);
$handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
$BytesRead=fread($handle,filesize($entry));
if ( !$BytesRead )
echo " Read Failed Or File is Empty\n";
fclose($handle);
unlink($entry);
}
return $BytesRead;
}
function ResizeIMG($image,$width,$height,$MAX=100){
$kt=$width/$height;
if( $kt > 1 ){
$DW=$MAX;
$DH=$MAX/$kt;
} else {
$DW=$MAX*$kt;
$DH=$MAX;
};
$im = @imagecreatetruecolor($DW, $DH)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
imagecopyresized($im,$image,0,0,0,0,$DW,$DH,$width,$height);
return $im;
}
$DirID=0;
function listDrives($CDrive){ //Windows Servers Only
for($i=65;$i<91;$i++){
$DLetter=chr($i);
if ( @chdir("$DLetter:\\")){
if ($DLetter!==$CDrive){
echo "<OPTION value=\"$DLetter\">$DLetter:</OPTION>\n";
} else {
echo "<OPTION selected value=\"$DLetter\">$DLetter:</OPTION>\n";
}
};
};
};
function ListDir($Path){
if (is_dir($Path)){
$CDir = opendir($Path);
while (false !== ($entry=readdir($CDir))){
if (($entry !==".")&&(is_dir($Path.$entry))){
echo "<OPTION value=\"$entry\">$entry</OPTION>\n";
};
};
closedir($CDir);
} else {
echo "Error -> Dir is not dir :(\n\n";
};
};
function ListFiles($Path){
if (is_dir($Path)){
$CDir = opendir($Path);
while (false !== ($entry=readdir($CDir))){
if (is_dir($Path.$entry)===false){
echo "<OPTION value=\"$entry\">$entry</OPTION>\n";
};
};
closedir($CDir);
} else {
echo "Error -> Dir is not dir :(\n\n";
};
};
function Scan_Dir($level, $AddToDB, $DBlink ,$ParentDirID){
global $DirParentColName,$PicDateColumn,$PicThumbColumn,$PicDataColName,$PicDescColName,$PicDirColName,$DirTitleColName,$DBName,$DBHost,$DBUser,$DBPassword,$DBTablePic,$DBTableDir,$PicThumbColName, $PicMD5KeyColName;
$DirName=getcwd();
if ($CDir=opendir($DirName)){
if ($AddToDB){
$DirName=strrchr($DirName,'/');
$DirName=mysql_escape_string($DirName);
$result = mysql_db_query ($DBName,"INSERT INTO $DBTableDir SET $DirTitleColName='$DirName',$DirParentColName='$ParentDirID'",$DBlink)
or die("Invalid query: " . mysql_error());
$result = mysql_db_query ($DBName,"Select * FROM $DBTableDir ",$DBlink)
or die("Invalid query: " . mysql_error());
$CDirID = mysql_num_rows($result);
};
echo "\nDescriptor: ".$CDir." CdirID=".$CDirID."\n";
echo "Path: ".getcwd()."\n";
while (false !== ($entry=readdir($CDir))){
if (($entry !==".") && ($entry !=="..")){
if ( ($level>0) && (is_dir($entry) )){
if (chdir($entry)){
Scan_Dir($level-1,$AddToDB,$DBlink,$CDirID);
chdir("..");
};
};
if (preg_match("/^.+\.(jpeg|jpg|gif|bmp|pcx|bmx|png)/i",$entry)){
echo "Adding File:".$entry;
if ($AddToDB) {
$MD5String=md5_file($entry);#bin2hex(md5_file($entry,true));
echo "MD5: $MD5String ";
$handle = fopen($entry, 'r') or die( "Cannot open temporary Image\n\n");
$BytesRead=fread($handle,filesize($entry));
if ( !$BytesRead ){
echo " Read Failed Or File is Empty\n";
} else {
echo " Ok\n";
};
fclose($handle);
# Altering thumbnails making
# $ThumbPic = make_thumb($entry);
$EThumbPic = "NULL";# mysql_escape_string($ThumbPic);
$EPicture = mysql_escape_string($BytesRead);
$entry=mysql_escape_string($entry);
$result = mysql_db_query ($DBName,"INSERT INTO $DBTablePic SET $PicDataColName='$EPicture', $PicDescColName='$entry', $PicDirColName='$CDirID', $PicMD5KeyColName='$MD5String' , $PicThumbColName=$EThumbPic ",$DBlink)
or die("Invalid query: " . mysql_error());
};
};
};
};
closedir($CDir);
};
};
function GenerateNewUserMail()
{
global $CUser, $Labels;
$msg = $Labels->GetLabel('_MSGHDR_');
$msg .= '<br><br>';
$msg .= $Labels->GetLabel('_MSGBDY_NEWUSR_');
$msg = nl2br( $msg );
$msg = str_replace( '%LOGIN_ID%', $CUser['id'], $msg );
$msg = str_replace( '%PASSWORD%', $CUser['password'], $msg );
SendEmail( $CUser['email'], $CUser['name'], "noreply@vicesisters.com", "Welcome to ViceSisters!", null, $msg );
}
function CountryFlagURL($CountryID){
global $DATABASE;
$QS="SELECT sign FROM countries WHERE id={$CountryID}";
$Val=$DATABASE->Query($QS,true);
$F_path='style/img/flags/'. strtolower($Val[0]['sign']).'.png';
$N_path='style/img/flags/xx.png';
if(file_exists($F_path)) return $F_path; else return $N_path;
}
function SendEmail($email,$toname,$from,$fromname,$body,$subject='ViceSisters, Message response from your profile: ', $AdminDir='', $echo_to_screen = false ){
global $MailAgent;
//$message=htmlspecialchars($body);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "To: $email\r\n";
$headers .= "From: $fromname <$from>\r\n";
$headers .= "Subject: $subject\r\n";
$msg='<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ViceSisters Mail Notification</title>
</head>
<body>
'.nl2br($body).'
<hr noshade size=1px>
This message was automatically generated by <a href="http://www.vicesisters.com/">ViceSisters.com</a> Mailer.
<br>
Please do not reply to this message.
</body></html>';
if( !$echo_to_screen )
{
if ($MailAgent=='SENDMAIL'){
//$tpl=file_get_contents("../functions/m_t.data");
$tpl=file_get_contents( $AdminDir . "../functions/mail_template.html");
$tpl=str_replace('<%MAIL_TO%>',"\"{$toname}\" <{$email}>",$tpl);
//$tpl=str_replace('<%MAIL_SUBJECT>',"\"{$subject}\"",$tpl);
$tpl=str_replace('<%MAIL_SUBJECT%>',$subject,$tpl);
$tpl=str_replace('<%MAIL_BODY%>',$body,$tpl);
@ini_set(sendmail_from, "$from"); // the INI lines are to force the From Address to be used !
//if (!@mail($email, $subject, $msg, $headers, "-f$from"))
if ( !mail($email, $subject,'',$tpl, "-f$from"))
$return = false;
else
$return = true;
@ini_restore(sendmail_from);
return $return;
} elseif ( $MailAgent=='CGP'){
return Mailer($email,$subject,$body);
} else {
echo $headers.$msg;
return true;
};
} else {
echo $headers.$msg;
return true;
};
};
function Mailer( $to, $subject, $body, $id = '' ){
global $CGP_SubmitPath;
$tpl = '../functions/mail_template.html';
if( !isset($id) || $id == '' )
$id = rand( 1, 1000000 );
$msg = file_get_contents( $tpl );
$msg = str_replace( '<%MAIL_TO%>', $to, $msg );
$msg = str_replace( '<%MAIL_SUBJECT%>', $subject, $msg );
$msg = str_replace( '<%MAIL_BODY%>', $body, $msg );
$fH = fopen( $CGP_SubmitPath . md5($to . time() . $id) . $id . '.sub', "w" );
if( !$fH )
return false;
fwrite( $fH, $msg, strlen($msg) );
fclose( $fH );
return true;
}
?>