<?php
/*******************************************************************************
* IKBIN (http://ikbin.sourceforge.net)
* Copyright (C) 2007 ikbin project administrators
*
*************************************************************************************/
require_once('config.frontend.php');
//check if nzb generation is allowed.
if(!($GLOBALS['CONF_allownzb'])){?>
Sorry, NZB generation is disabled. <br/>
Why not <a href="http://www.sourceforge.net/projects/ikbin">download</a> the source and start your own USENET index.<br/>
<br/>
<b>Don't know how? Need some help? Want to support open source software?</b><br/>
Do you need to index newsgroups used by your organization, but don't know where to start?<br/>
We can install ikbin on your host and add custom features.<br/>
<br/>
Write us: <i>hide@address.com</i><br/>
<?php exit;}
//make an nzb
$i=0;
$j=0;
$fid='';
$cid='';
foreach($_POST as $key => $value){
if($value=='cid'){
$cid[$i]=$key;
$i++;
}
if($value=='fid'){
$fid[$j]=$key;
$j++;
}
}
//check get vars if there are no posts
if(($i+$j)<1){
foreach($_GET as $key => $value){
if($value=='cid'){
$cid[$i]=$key;
$i++;
}
if($value=='fid'){
$fid[$j]=$key;
$j++;
}
}
}
//if there is still nothing, give an error and exit
if(($i+$j)<1){
echo "Nothing Selected!";
exit;
}
$db=new User_db;
$db->connect();
//$sql=new sqluser;
//$sql->db=&$db;
$db2=new User_db;
$db2->connect();
require_once('class/nzb.class.php');
$nzb=new parseNZB;
if($_GET['nn']){
$nzbname=$_GET['nn'];
}elseif($_POST['nn']){
$nzbname=$_POST['nn'];
}elseif($cid[0]){
$nzbname=$cid[0];
}elseif($fid[0]){
$nzbname=$fid[0];
}else{
$nzbname='ikbin.info';
}
header('Content-Type: application/x-nzb');
header('content-disposition: attachment; filename="'.$nzbname.'.nzb"');
//compress output?
if($GLOBALS['CONF_nzbgzip']){ob_start('ob_gzhandler');}
//start NZB output
echo $nzb->startNZB();
//process each file
if($fid){
foreach($fid as $key=>$value){
$q="SELECT f.sender,f.subject,f.totalparts,f.date,g.group
FROM `files` as f, `groups` as g
WHERE f.`key`='".mysql_real_escape_string($value)."'
AND f.`group`=g.`key`";
$db->query($q);
$db->next_record();
//$group=array();
$group[0]=$db->Record['group'];
//for each file that matches the collection ID
//start a file block
//my new reader REQUIRES a (1/parts) in the subject or it assumes a single part
//thats pretty dumb considering its an XML format with details inside each chunk, but...
//so we fake it here because the only header we save is the stem (without this info!)
echo $nzb->startfile($db->Record['sender'],
$group,
$db->Record['subject'].' (1/'.$db->Record['totalparts'].')',
$db->Record['date']);
//add all segments that match the file ID
$q='SELECT *
FROM `headers`
WHERE `fileid`=\''.mysql_real_escape_string($value).'\'';// ORDER BY `part` ASC";
//$sql->nzbfileheaders(mysql_real_escape_string($value));
$db->query($q);
while($db->next_record()){
echo $nzb->addsegment($db->Record['bytes'],$db->Record['part'],$db->Record['messageid']);
}
echo $nzb->endfile();
}
}//if fid...
//process all collections:
if($cid){
foreach($cid as $key=>$value){//for each marked collection
//find all files that go with it
$q="SELECT c.`poster`,g.`group`,c.`altgroup1`,c.`altgroup2`
FROM `collections` as c, `groups` as g
WHERE c.`key`='".mysql_real_escape_string($value)."
AND c.`group`=g.`key`'
LIMIT 1";
$db->query($q);
$db->next_record();
$poster=$db->Record['poster'];
//$group=array();
$group[0]=$db->Record['group'];
//needs to be adapted for new XREF
//if(!empty($db->Record['altgroup1'])){$group[1]=$db->Record['altgroup1'];}
//if(!empty($db->Record['altgroup2'])){$group[2]=$db->Record['altgroup2'];}
$q="SELECT `key`,`subject`,`date`,`totalparts`
FROM `files`
WHERE `collid`='".mysql_real_escape_string($value)."'";
$db->query($q);
//for each file that matches the collection ID
while($db->next_record()){
//start a file block
//my new reader REQUIRES a (1/parts) in the subject or it assumes a single part
//thats pretty dumb considering its an XML format with details inside each chunk, but...
//so we fake it here because the only header we save is the stem (without this info!)
echo $nzb->startfile($poster,
$group,
$db->Record['subject'].' (1/'.$db->Record['totalparts'].')',
$db->Record['date']); //make propper date format
//add all segments that match the file ID
$q='SELECT *
FROM `headers`
WHERE `fileid`=\''.$db->Record['key'].'\'';// ORDER BY `part` ASC";
//$q=$sql->nzbfileheaders($db->Record['key']);
$db2->query($q);
while($db2->next_record()){
echo $nzb->addsegment($db2->Record['bytes'],$db2->Record['part'],$db2->Record['messageid']);
}
echo $nzb->endfile();
}//while loop
}//for each collection
}//if cid
echo $nzb->endNZB();
if($GLOBALS['CONF_nzbgzip']){ob_end_flush();}
//collection tracking
if($GLOBALS['CONF_logdownloads']){
$db=new Tracker_db;
$db->connect();
$q="INSERT INTO `tracker` (`type`,`id`, `date`)
VALUES";
if($cid){
foreach($cid as $key=>$collection){
if($key>0){$q.=',';}
$q.="('c','".mysql_real_escape_string($collection)."',NOW())";
}
}
if($fid){
foreach($fid as $key=>$file){
if($key>0){$q.=',';}
$q.="('f','".mysql_real_escape_string($file)."',NOW())";
}
}
$db->query($q);
}
?>