Location: PHPKode > projects > @1 File Store > pf.php
<?
$MustLogin=2|4;
require_once("libs/header.php");
require_once(LIBPATH."multipage.php");

$pager=new multipage("page");
$pager->setpagesize(10);

$userlevel=$CurUser->getlevel();
if($userlevel==-1 || $userlevel==0) {
	$smarty->assign("IsAdmin", "1");
}
function currentLocation( $fid ) {
	global $smarty, $fpath ;
	$SQL = mysql_query("SELECT folder_name, id, parent FROM fstore_folders WHERE id=$fid ");
	$row = mysql_fetch_array( $SQL );
	if( $row['parent'] == 0 ) 
		$location = " {$row['folder_name']} /";
	else {
		$location = " {$row['folder_name']} /";
		currentLocation( $row['parent'] );
	}
	$fpath .= $location ;
}
function currentLocationA( $fid ){
	global $smarty_subscription, $breadcrumbs ;
	
	$SQL = mysql_query("SELECT folder_name, id, parent FROM fstore_folders WHERE id=$fid ");
	$row = mysql_fetch_array( $SQL );
	if( $row['parent'] == 0 )
		$location = "  >>  <a href=\"folder.php?id={$row['id']}\">{$row['folder_name']}</a>";
	else
	{
		$location = "  >>  <a href=\"folder.php?id={$row['id']}\">{$row['folder_name']}</a>";
		currentLocationA( $row['parent'] );
	}
	$breadcrumbs .= $location ;
}

if (isset($_GET['confirmall']) and $_GET['confirmall']=='yes') {
	$file_list=array();
	$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
	$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
	$SQL.=" WHERE `".DB_PREFIX."file_list`.`confirm`='N'";
	$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."` ".ORDERREC;

//	if(!$mysql->query($SQL)) {
//		exit($mysql->error);
//	}
//	$pager->setrec($mysql->num);
//	$SQL.=$pager->limit();

	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	$smarty->assign("PAGES", $pager->smarty());
	$file_list=array();
	while(!$mysql->EOF) {
		$file_list[]=$mysql->arr;
		$mysql->movenext();
	}
	$smarty_subscription=new Smarty;
	foreach ($file_list as $kfile_list => $vfile_list) {
		$val = $vfile_list['id'];
		$SQL="UPDATE `".DB_PREFIX."file_list` SET `confirm`='Y' WHERE id='".$val."'";
		 if(!$mysql->query($SQL)) {
			 exit($mysql->error);
		}
		
		// *start**************************************************************************
		// -- send email notification to users who subscribe -- added by niotech
		if((defined("PUBLIC_APPROVED")) &&  PUBLIC_APPROVED==1){
			$smarty_subscription->template_dir=$RootDir."templates";
			$smarty_subscription->compile_dir=$RootDir."templates_c";	
				
			//----------[build breadcrumbs]--------------	
			$breadcrumbs = "<a href=\"main.php?\">".$lang['index']."</a>";
			
				
			//---------------[end build breadcrumbs]---------------
			$file_id=$val;
			
			$table_suffix="file_list";
			$SQL="SELECT filename,download,folder_id,descript,file_type,user_id,filesize,dateadd FROM `".DB_PREFIX.$table_suffix."` WHERE `".DB_PREFIX.$table_suffix."`.id=$file_id";
			if(!$mysql->query($SQL)) {
				exit($mysql->error);
			}
			
			// create file signature (md5)
			if(!($f=fopen(UPLOAD_DIR.$mysql->field("download"),"r"))){
				exit("Failed reading uploaded file");
			}
		  
			$buff=fread($f,$mysql->field("filesize"));
			fclose($f);
			$sig=md5($buff);
			
			// create direct download link
			$ddl=$site_config["SITE_URL"]; 
			if(substr($ddl,strlen($ddl)-1,1)!="/")
				$ddl.="/";
			$ddl.="download.php?id=".$file_id."&sig=".$sig;
			
			currentLocationA( $mysql->field("folder_id") );
			$smarty_subscription->assign("siteurl", $site_config["SITE_URL"]);	
			$smarty_subscription->assign("breadcrumbs", $breadcrumbs);
			$smarty_subscription->assign("filedescription", $mysql->field("descript"));
			$smarty_subscription->assign("uploaddate", $mysql->field("dateadd"));	
			$smarty_subscription->assign("filesize", $mysql->field("filesize"));
			$smarty_subscription->assign("filetype", $mysql->field("file_type"));
			$smarty_subscription->assign("ddl", $ddl);
			
			$table_suffix="users";
			$SQL="SELECT real_name,login,level FROM `".DB_PREFIX.$table_suffix."` WHERE `".DB_PREFIX.$table_suffix."`.id=".$mysql->field("user_id");	
			if(!$mysql->query($SQL)) {
				exit($mysql->error);
			}	
			$smarty_subscription->assign("uploader", $mysql->field("real_name"));
			$smarty_subscription->assign("uploaderlogin", $mysql->field("login"));	
			$email_content=$smarty_subscription->fetch("subscription_email.tpl");
		
			// grab users email
			if($mysql->field("level")==0 || $mysql->field("level")==-1){
				$SQL="SELECT `".DB_PREFIX."users`.email FROM `".DB_PREFIX."users` WHERE `".DB_PREFIX."users`.level=-1 OR `".DB_PREFIX."users`.level=0 ";
			}else{
				$SQL="SELECT `".DB_PREFIX."users`.email FROM `".DB_PREFIX."users`,`".DB_PREFIX."access_list`,`".DB_PREFIX."file_list` WHERE `".DB_PREFIX."file_list`.id=$file_id AND `".DB_PREFIX."users`.subscription='Y' AND `".DB_PREFIX."file_list`.folder_id=`".DB_PREFIX."access_list`.folder_id AND `".DB_PREFIX."access_list`.group_id=`".DB_PREFIX."users`.level ORDER BY `".DB_PREFIX."users`.id ";
			}
			if(!$mysql->query($SQL)) {
				exit($mysql->error);
			}
			$email_list=array();
			while(!$mysql->EOF) {
				$email_list[]=$mysql->arr[0];
				$mysql->movenext();
			}					
			
			// email users
			if(count($email_list)){
				$bodycontent=SUBSCRIPTION_EMAIL_ADDITIONAL_HEADER.$email_content.SUBSCRIPTION_EMAIL_ADDITIONAL_FOOTER;
				foreach($email_list as $email){			
					mail(trim($email), SUBSCRIPTION_EMAIL_SUBJECT, $bodycontent, "From:".SUBSCRIPTION_EMAIL_ADMIN_EMAIL); 
				}
			}
			
			// grab admins/subadmins email
			$SQL="SELECT `".DB_PREFIX."users`.email FROM `".DB_PREFIX."users` WHERE `".DB_PREFIX."users`.subscription='Y' AND `".DB_PREFIX."users`.level<1 ORDER BY `".DB_PREFIX."users`.id ";
			
			if(!$mysql->query($SQL)) {
				exit($mysql->error);
			}
			$email_list=array();
			while(!$mysql->EOF) {
				$email_list[]=$mysql->arr[0];
				$mysql->movenext();
			}	
				
			// email admins/subadmins
			if(count($email_list)){
				$bodycontent=SUBSCRIPTION_EMAIL_ADDITIONAL_HEADER.$email_content.SUBSCRIPTION_EMAIL_ADDITIONAL_FOOTER;
				foreach($email_list as $email){			
					mail(trim($email), SUBSCRIPTION_EMAIL_SUBJECT, $bodycontent, "From:".SUBSCRIPTION_EMAIL_ADMIN_EMAIL); 
				}
			}
		}
		// *end**************************************************************************		
	}
	Header("Location:main.php");
	exit();
} else {
	$file_list=array();
	$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
	$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
	$SQL.=" WHERE `".DB_PREFIX."file_list`.`confirm`='N'";
	$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."` ".ORDERREC;
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	$pager->setrec($mysql->num);
	$SQL.=$pager->limit();

	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	$smarty->assign("PAGES", $pager->smarty());
	$file_list=array();
	while(!$mysql->EOF) {
		$file_list[]=$mysql->arr;
		$mysql->movenext();
	}
	$testfile_list = $file_list;
	$testfile_list2 = $file_list;

foreach ($testfile_list as $ktestfile_list => $vtestfile_list) {
	$fpath = " Index /";
	$mffid = $vtestfile_list['folder_id'];
	currentLocation( $mffid );
	$file_list[$ktestfile_list]['loc']= strval($fpath).' '.strval($vtestfile_list['filename']);
}
$smarty->assign("filelist", $file_list);
$smarty->display("pf.tpl");
}
?>
Return current item: @1 File Store