<?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_didenqueue extends ajax {
public static function didenqueue($rpc, $type, $dids){
parent::$CB = __FUNCTION__;
$multi = ereg(';', $dids);
if ( $multi ){ $dids = split(';', $dids); }
if ( FALSE === hellarpcs::isrpc($rpc) ){
pagegen::add_event('Invalid Argument : RPC, unknown RPC');
return parent::getReply();
}
$REALM = new realm(pages::get_realm(browsing::get_active()));
if ( FALSE === $REALM->checks('rpc', 'use', $rpc) ){
pagegen::add_event('Invalid Argument : RPC, you are NOT allowed to use that RPC');
return parent::getReply();
}
unset($REALM);
hellarpcs::load($rpc);
if ( FALSE === $multi ){
$ID=trim($dids);
if ( empty($ID) ){
pagegen::add_event("Empty ID after trim");
return parent::getReply();
} elseif ( ! is_numeric($ID) ){
pagegen::add_event("ID is not numeric");
return parent::getReply();
}
$did = hellarpcs::gendid($type, $ID);
if ( $type == 'nbrid' ){
if ( hellarpcs::gotfree_slot() ){
if ( FALSE === hellarpcs::lock_slot('DirectID', $did) ){
pagegen::add_event("Newzbin DirectID Rate slot could not be locked !, abording");
return parent::getReply();
}
if ( FALSE === hellarpcs::enqueue($rpc, $did) ){
pagegen::add_event("Newzbin Report ID $did could not be enqueued on RPC $rpc !");
return parent::getReply();
}
} else {
if ( FALSE === hellarpcs::delayed_enqueue($rpc, $did) ){
pagegen::add_event("Enqueue could not be delayed !");
} else {
pagegen::add_event("DirectID $type:$ID enqueue on RPC $rpc has been delayed.");
}
self::did_redraw();
return parent::getReply();
}
} elseif ( FALSE === hellarpcs::enqueue($rpc, $did) ){
pagegen::add_event("Report ID $did could not be enqueued on RPC $rpc !");
return parent::getReply();
}
$rpc = hellarpcs::getname($rpc);
pagegen::add_event("DirectID $type:$ID has been enqueued on RPC $rpc");
if ( $type == 'nbrid' ){ self::did_redraw(); }
return parent::getReply();
}
$t=0;$e=0;$d=0;$f=0;
foreach($dids as $k => &$ID){
$ID=trim($ID);
if ( !empty($ID) ){
$did = hellarpcs::gendid($type, $ID);
if ( $type == 'nbrid' ){
if ( hellarpcs::gotfree_slot() ){
if ( FALSE === hellarpcs::lock_slot('Search', $ID) ){
errors::raise("Newzbin DirectID Rate slot could not be locked !, abording", CORE_LOG_ERROR, 'RPC');
$f++;
} elseif ( FALSE === hellarpcs::enqueue($rpc, $did) ){ $f++; } else { $e++; }
} elseif ( FALSE === hellarpcs::delayed_enqueue($rpc, $did) ){ $f++; } else { $d++; }
} elseif ( FALSE === hellarpcs::enqueue($rpc, $did) ){ $f++; } else { $e++; }
$t++;
}
}
$rpc = hellarpcs::getname($rpc);
pagegen::add_event(langs::translate('multididenqueue', Array('rpc'=>$rpc,'e'=>$e, 'd'=>$d, 'f'=>$f, 't'=>$t), 'hellarpcs'));
if ( $type == 'nbrid' ){ self::did_redraw(); }
return parent::getReply();
}
public static function did_redraw(){
$tpl = new template();
if ( FALSE === $tpl->load_file('leftmenu/didrate.tpl') ){ return FALSE; }
$data = hellarpcs::list_slot();
for($i=4;$i>=0;$i--){
if ( !isset($data[$i]) ){
$buf['nbslots'][$i] = Array('why'=>'-','freein'=>'-');
} else {
$buf['nbslots'][$i] = $data[$i];
}
$buf['nbslots'][$i]['unic'] = CORE::hash(NULL, 5);
parent::addScript("rate_countdown('".$buf['nbslots'][$i]['unic']."')");
}
$tpl->setdata( $buf );
parent::addAssign('block_leftmenu_didrate', 'innerHTML', $tpl->parse(TRUE) );
foreach($buf['nbslots'] as $k => $data ){
parent::addScript("rate_countdown('".$data['unic']."')");
}
unset($tpl);
}
}