<?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_uplreply extends ajax {
public static function uplreply($hash){
parent::$CB = __FUNCTION__;
$vk = 'ajxupl_vars_'.$hash;
$fk = 'ajxupl_files_'.$hash;
if ( FALSE === sessions::isdefined($vk) ){
pagegen::add_event("Invalid Ajax Upload context, lost sessions ?");
return parent::getReply();
}
$vars = sessions::read($vk);
$files = sessions::read($fk);
if ( !isset($vars['ajxuplcb']) ){
pagegen::add_event("Context is missing cb value ???");
return parent::getReply();
}
$regs = ajax::getRegistred();
foreach($regs as $k => $func ){ if ( md5($func) === $vars['ajxuplcb']){ $cb = $func;break; } }
unset($regs);
if ( !isset($cb) ){
pagegen::add_event("Invalid Ajax Upload callback '".$vars['ajxuplcb']."' defined in context $hash");
return parent::getReply();
}
//pagegen::add_event("Upload reply called with '$hash' => <pre>".print_r($vars, TRUE).print_r($files, TRUE)."</pre>");
$func = "ajx_$func::$func";
$o = call_user_func($func, $vars, $files);
sessions::del($vk);
sessions::del($fk);
self::recur_uplfile_del($files);
return $o;
}
private static function recur_uplfile_del($file){
if ( is_array($file) ){
if ( isset($file['tmp_name']) ){
if ( isset($file['catched']) ){
$fabs = new file_abstract();
$fabs->connect();
$fabs->remove($file['tmp_name']);
}
} else {
foreach($file as $k => &$entry){ self::recur_uplfile_del($entry); }
}
}
}
}