Location: PHPKode > projects > Simple Way to Usenet > libs/swun/ajax/ajx_n_upload.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_n_upload extends ajax {

	public static function n_upload($vars, $files){
		parent::$CB = __FUNCTION__;
		if ( !isset($vars['nzbcatid']) ){
			pagegen::add_event(langs::translate('nzbnocatid', NULL, 'search'));
			return parent::getReply();
		} elseif( !isset(search_nzbid::$cats[$vars['nzbcatid']]) ){
			pagegen::add_event(langs::translate('nzbadcatid', NULL, 'search'));
			return parent::getReply();
		} elseif ( !isset($files['nzb']) ){
			pagegen::add_event('Missing Argument : nzb, abording');
			return parent::getReply();
		} elseif ( !isset($files['nzb']['catched']) ){
			pagegen::add_event(langs::translate('nzbbadfile', NULL, 'search'));
			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('/'.$files['nzb']['name']) ){
			pagegen::add_event(langs::translate('nzbsamename', NULL, 'search'));
			return parent::getReply();
		} elseif ( FALSE === nzb::isnzb($files['nzb']['tmp_name']) ){
			pagegen::add_event(langs::translate('nzbbadnzb', Array('file'=>$files['nzb']['name']), 'search'));
			return parent::getReply();
		} elseif ( FALSE === $repo->move(NULL, $files['nzb']['tmp_name'], 'NZB', '/'.$files['nzb']['name']) ){
			pagegen::add_event(langs::translate('nzbnofsimport', Array('file'=>$files['nzb']['name']), 'search'));
			return parent::getReply();
		} elseif( FALSE === $db->import_nzb($files['nzb']['name'], $vars['nzbcatid']) ){
			$repo->remove($files['nzb']['name']);
			pagegen::add_event(langs::translate('nzbnodbimport', Array('file'=>$files['nzb']['name']), 'search'));
			return parent::getReply();
		}
		$l['cat'] = langs::translate('cat_'.search_nzbid::$cats[$vars['nzbcatid']], NULL, 'search');
		$l['id'] = $db->get_idbyfile($files['nzb']['name']);
		$l['file'] = $files['nzb']['name'];
		pagegen::add_event(langs::translate('nzbimported', $l, 'search'));
		return parent::getReply();
	}

}
Return current item: Simple Way to Usenet