Location: PHPKode > projects > Simple Way to Usenet > libs/swun/ajax/ajx_unfidimport.class.php
<?php
/**
 *  
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */
class ajx_unfidimport extends ajax {

	public static function unfidimport($inQ, $rpc, $cat, $title, $ids){
		parent::$CB = __FUNCTION__;
		//check title for filename validity;
		if( !isset(search_nzbid::$cats[$cat]) ){
			pagegen::add_event(langs::translate('nzbadcatid', NULL, 'search'));
			return parent::getReply();
		} elseif ( !hellarpcs::gotfree_slot() ){
			pagegen::add_event("NZB Generation from usenet failed, no free slot available, please retry later.");
			return parent::getReply();
		}
		$repo = new file_abstract('NZB');
		$db = new nzbdb();
		if ( FALSE === $repo->connect() ){
			pagegen::add_event(langs::translate('nzbreponoconn', NULL, 'search'));
			return parent::getReply();
		} elseif ( $repo->isfile("/$title.nzb") ){
			pagegen::add_event(langs::translate('nzbsamename', NULL, 'search'));
			return parent::getReply();
		} elseif ( !hellarpcs::lock_slot('Import', $ids) ){
			pagegen::add_event("NZB Generation from usenet failed, slot could not be locked");
			return parent::getReply();
		}
		$ids = split(';', $ids);
		foreach($ids as $k => $id){ if ( empty($id) ){ unset($ids[$k]); } }
		$nzb = nb_fetch::get_nzb(NULL, $ids);
		if ( FALSE === $nzb ){
			pagegen::add_event('NZB Could not be generated using newzbin DirectID');
			return parent::getReply();
		} elseif ( FALSE === $repo->move(NULL, $nzb, 'NZB', "$title.nzb") ){
			pagegen::add_event('NZB File "'.$title.'.nzb" could not be imported to collection folder');
			return parent::getReply();
		} elseif ( FALSE === $db->import_nzb("$title.nzb", $cat) ){
			pagegen::add_event(langs::translate('nzbnodbimport', Array('file'=>"$title.nzb"), 'search'));
			return parent::getReply();
		}
		$l['cat'] = langs::translate('cat_'.search_nzbid::$cats[$cat], NULL, 'search');
		$l['id'] = $db->get_idbyfile("$title.nzb");
		$l['file'] = "$title.nzb";
		pagegen::add_event(langs::translate('nzbimported', $l, 'search'));
		if ( $inQ ){ return ajx_didenqueue::didenqueue($rpc, 'nzbid', $l['id']); }
		ajx_didenqueue::did_redraw();
		return parent::getReply();
	}
	
}
Return current item: Simple Way to Usenet