load_files();
}
$e_sub_cat = 'download';
require_once(e_HANDLER."form_handler.php");
require_once(e_HANDLER."userclass_class.php");
require_once(e_HANDLER."file_class.php");
$fl = new e_file;
// -------- Presets. ------------
require_once(e_HANDLER."preset_class.php");
$pst = new e_preset;
$pst->form = array("myform","dlform"); // form id of the form that will have it's values saved.
$pst->page = array("download.php?create","download.php?cat"); // display preset options on which page(s).
$pst->id = array("admin_downloads","admin_dl_cat");
// -------------------------------
$download = new download;
require_once("auth.php");
$pst->save_preset(); // unique name(s) for the presets - comma separated.
/*
One form example (no arrays needed)
$pst->form = "myform"; // form id of the form that will have it's values saved.
$pst->page = "download.php?create"; // display preset options on which page.
$pst->save_preset("admin_downloads"); // unique name for the preset
*/
$rs = new form;
if (e_QUERY) {
$tmp = explode(".", e_QUERY);
$action = $tmp[0];
$sub_action = $tmp[1];
$id = $tmp[2];
$from = ($tmp[3] ? $tmp[3] : 0);
unset($tmp);
}
if(isset($_POST['delete']))
{
$tmp = array_keys($_POST['delete']);
list($delete, $del_id) = explode("_", $tmp[0]);
unset($_POST['searchquery']);
}
$from = ($from ? $from : 0);
$amount = 50;
if($file_array = $fl->get_files(e_DOWNLOAD, "","standard",2)){
sort($file_array);
}
if ($sql->db_Select("rbinary")){
while ($row = $sql->db_Fetch()) {
extract($row);
$file_array[] = "Binary ".$binary_id."/".$binary_name;
}
}
$reject = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*');
if($image_array = $fl->get_files(e_FILE."downloadimages/", "",$reject,1)){
sort($image_array);
}
if($thumb_array = $fl->get_files(e_FILE."downloadthumbs/", "",$reject,1)){
sort($thumb_array);
}
if (isset($_POST['add_category'])) {
$download->create_category($sub_action, $id);
}
if (isset($_POST['submit_download'])) {
$download->submit_download($sub_action, $id);
$action = "main";
unset($sub_action, $id);
}
if(isset($_POST['update_catorder'])){
foreach($_POST['catorder'] as $key=>$order){
if($_POST['catorder'][$key]){
$sql -> db_Update("download_category", "download_category_order='".intval($order)."' WHERE download_category_id='".intval($key)."'");
}
}
$ns->tablerender("", "
".LAN_UPDATED."
");
}
if (isset($_POST['updateoptions']))
{
$pref['download_php'] = $_POST['download_php'];
$pref['download_view'] = $_POST['download_view'];
$pref['download_sort'] = $_POST['download_sort'];
$pref['download_order'] = $_POST['download_order'];
$pref['agree_flag'] = $_POST['agree_flag'];
$pref['download_email'] = $_POST['download_email'];
$pref['agree_text'] = $tp->toDB($_POST['agree_text']);
$pref['download_denied'] = $tp->toDB($_POST['download_denied']);
save_prefs();
$message = DOWLAN_65;
}
if(isset($_POST['addlimit']))
{
if($sql->db_Select('generic','gen_id',"gen_type = 'download_limit' AND gen_datestamp = {$_POST['newlimit_class']}"))
{
$message = DOWLAN_116;
}
else
{
if($sql->db_Insert('generic',"0, 'download_limit', '".intval($_POST['newlimit_class'])."', '".intval($_POST['new_bw_num'])."', '".intval($_POST['new_bw_days'])."', '".intval($_POST['new_count_num'])."', '".intval($_POST['new_count_days'])."'"))
{
$message = DOWLAN_117;
}
else
{
$message = DOWLAN_118;
}
}
}
if(isset($_POST['updatelimits']))
{
if($pref['download_limits'] != $_POST['download_limits'])
{
$pref['download_limits'] = ($_POST['download_limits'] == 'on') ? 1 : 0;
save_prefs();
$message .= DOWLAN_126." ";
}
foreach(array_keys($_POST['count_num']) as $id)
{
if(!$_POST['count_num'][$id] && !$_POST['count_days'][$id] && !$_POST['bw_num'][$id] && !$_POST['bw_days'][$id])
{
//All entries empty - Remove record
if($sql->db_Delete('generic',"gen_id = {$id}"))
{
$message .= $id." - ".DOWLAN_119." ";
}
else
{
$message .= $id." - ".DOWLAN_120." ";
}
}
else
{
$sql->db_Update('generic',"gen_user_id = '".intval($_POST['bw_num'][$id])."', gen_ip = '".intval($_POST['bw_days'][$id])."', gen_intdata = '".intval($_POST['count_num'][$id])."', gen_chardata = '".intval($_POST['count_days'][$id])."' WHERE gen_id = {$id}");
$message .= $id." - ".DOWLAN_121." ";
}
}
}
if(isset($_POST['submit_mirror']))
{
$download->submit_mirror($sub_action, $id);
}
if($action == "mirror")
{
$download -> show_existing_mirrors();
}
if ($action == "dlm")
{
$action = "create";
$id = $sub_action;
$sub_action = "dlm";
}
if ($action == "create") {
$download->create_download($sub_action, $id);
}
if ($delete == 'category') {
if (admin_update($sql->db_Delete("download_category", "download_category_id='$del_id' "), 'delete', DOWLAN_49." #".$del_id." ".DOWLAN_36)) {
$sql->db_Delete("download_category", "download_category_parent='{$del_id}' ");
}
}
if ($action == "cat") {
$download->show_categories($sub_action, $id);
}
if ($delete == 'main') {
$result = admin_update($sql->db_Delete("download", "download_id='$del_id' "), 'delete', DOWLAN_35." #".$del_id." ".DOWLAN_36);
if($result)
{
admin_purge_related("download", $del_id);
}
unset($sub_action, $id);
}
if (isset($message)) {
$ns->tablerender("", "".$message."
");
}
if (!e_QUERY || $action == "main") {
$download->show_existing_items($action, $sub_action, $id, $from, $amount);
}
if ($action == "opt") {
global $pref, $ns;
$agree_flag = $pref['agree_flag'];
$agree_text = $pref['agree_text'];
$text = "";
$ns->tablerender(DOWLAN_54, $text);
}
if($action == 'limits')
{
if($sql->db_Select('userclass_classes','userclass_id, userclass_name'))
{
$classList = $sql->db_getList();
}
if($sql->db_Select("generic", "gen_id as limit_id, gen_datestamp as limit_classnum, gen_user_id as limit_bw_num, gen_ip as limit_bw_days, gen_intdata as limit_count_num, gen_chardata as limit_count_days", "gen_type = 'download_limit'"))
{
while($row = $sql->db_Fetch())
{
$limitList[$row['limit_classnum']] = $row;
}
}
$txt = "
";
$ns->tablerender(DOWLAN_112, $txt);
require_once(e_ADMIN.'footer.php');
exit;
}
//$download->show_options($action);
require_once("footer.php");
exit;
class download {
function show_existing_items($action, $sub_action, $id, $from, $amount) {
global $sql, $rs, $ns, $tp, $mySQLdefaultdb,$pref;
$text = "";
$sortorder = ($pref['download_order']) ? $pref['download_order'] : "download_datestamp";
if(isset($_POST['searchdisp'])){
$pref['admin_download_disp'] = implode("|",$_POST['searchdisp']);
save_prefs();
}
if(!$pref['admin_download_disp']){
$search_display = array("download_name","download_class");
}else{
$search_display = explode("|",$pref['admin_download_disp']);
}
$query = "SELECT d.*, dc.* FROM #download AS d LEFT JOIN #download_category AS dc ON dc. download_category_id = d.download_category";
if (isset($_POST['searchquery']) && $_POST['searchquery'] != "") {
$query .= " WHERE download_url REGEXP('".$_POST['searchquery']."') OR download_author REGEXP('".$_POST['searchquery']."') OR download_description REGEXP('".$_POST['searchquery']."') ";
foreach($search_display as $disp){
$query .= " OR $disp REGEXP('".$_POST['searchquery']."') ";
}
$query .= " ORDER BY ".$sortorder." DESC";
} else {
$query .= " ORDER BY ".($sub_action ? $sub_action : $sortorder)." ".($id ? $id : "DESC")." LIMIT $from, $amount";
}
if ($sql->db_Select_gen($query)) {
$text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform")."
ID
";
// Search Display Column header.----------
foreach($search_display as $disp){
if($disp == "download_name"){
$text .= "".DOWLAN_27." ";
}else{
$repl = array("download_","_");
$text .= "".ucwords(str_replace($repl," ",$disp))." ";
}
}
// ------------------------------
$text .="
".LAN_OPTIONS."
";
while ($row = $sql->db_Fetch()) {
extract($row);
$text .= "
";
// Display Chosen options -------------------------------------
$bolean_list = array("download_active","download_comment");
foreach($search_display as $disp){
$text .= "";
}
// -------------------------------------------------------------
$text .= "
";
}
$text .= "
";
} else {
$text .= "
".DOWLAN_6."
";
}
$text .= "
";
// Next-Previous. ==========================
$downloads = $sql->db_Count("download");
if ($downloads > $amount && !$_POST['searchquery']) {
$parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$sub_action.$id." : "main.download_id.desc.")."[FROM]";
$text .= "
".$tp->parseTemplate("{NEXTPREV={$parms}}");
}
// Search & display options etc. =========================.
$text .= "
\n
";
// ======================
$ns->tablerender(DOWLAN_7, $text);
}
function show_options($action) {
if ($action == "") {
$action = "main";
}
$var['main']['text'] = DOWLAN_29;
$var['main']['link'] = e_SELF;
$var['create']['text'] = DOWLAN_30;
$var['create']['link'] = e_SELF."?create";
$var['cat']['text'] = DOWLAN_31;
$var['cat']['link'] = e_SELF."?cat";
$var['cat']['perm'] = "Q";
$var['opt']['text'] = LAN_OPTIONS;
$var['opt']['link'] = e_SELF."?opt";
$var['limits']['text'] = DOWLAN_112;
$var['limits']['link'] = e_SELF."?limits";
$var['mirror']['text'] = DOWLAN_128;
$var['mirror']['link'] = e_SELF."?mirror";
show_admin_menu(DOWLAN_32, $action, $var);
}
function create_download($sub_action, $id) {
global $cal,$tp, $sql, $rs, $ns, $file_array, $image_array, $thumb_array,$pst;
$download_status[0] = DOWLAN_122;
$download_status[1] = DOWLAN_123;
$download_status[2] = DOWLAN_124;
$preset = $pst->read_preset("admin_downloads"); // read preset values into array
extract($preset);
if (!$sql->db_Select("download_category")) {
$ns->tablerender(ADLAN_24, "".DOWLAN_5."
");
return;
}
$download_active = 1;
if ($sub_action == "edit" && !$_POST['submit']) {
if ($sql->db_Select("download", "*", "download_id='$id' ")) {
$row = $sql->db_Fetch();
extract($row);
if($download_mirror)
{
$mirrorTArray = explode(chr(1), $download_mirror);
$mirrorArray = array();
$count=0;
foreach($mirrorTArray as $mirror)
{
if($mirror)
{
list($mid, $murl) = explode(",", $mirror);
$mirrorArray[$count]['id'] = $mid;
$mirrorArray[$count]['url'] = $murl;
$count++;
}
}
}
}
}
if ($sub_action == "dlm" && !$_POST['submit']) {
if ($sql->db_Select("upload", "*", "upload_id='$id' ")) {
$row = $sql->db_Fetch();
extract($row);
$download_category = $upload_category;
$download_name = $upload_name.($upload_version ? " v" . $upload_version : "");
$download_url = $upload_file;
$download_author_email = $upload_email;
$download_author_website = $upload_website;
$download_description = $upload_description;
$download_image = $upload_ss;
$download_filesize = $upload_filesize;
$image_array[] = $upload_ss;
$download_author = substr($upload_poster, (strpos($upload_poster, ".")+1));
}
}
$text = "
";
$ns->tablerender(ADLAN_24, $text);
}
function show_message($message) {
global $ns;
$ns->tablerender("", "".$message."
");
}
function submit_download($sub_action, $id) {
global $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event;
if($sub_action == 'edit')
{
if($_POST['download_url_external'] == '')
{
$_POST['download_filesize_external'] = FALSE;
}
}
if ($_POST['download_url_external'] && $_POST['download_url'] == '')
{
$durl = $_POST['download_url_external'];
$filesize = $_POST['download_filesize_external'];
}
else
{
$durl = $_POST['download_url'];
if($_POST['download_filesize_external'])
{
$filesize = $_POST['download_filesize_external'];
}
else
{
if (strpos($DOWNLOADS_DIRECTORY, "/") === 0 || strpos($DOWNLOADS_DIRECTORY, ":") >= 1)
{
$filesize = filesize($DOWNLOADS_DIRECTORY.$durl);
}
else
{
$filesize = filesize(e_BASE.$DOWNLOADS_DIRECTORY.$durl);
}
}
}
if (!$filesize)
{
if($sql->db_Select("upload", "upload_filesize", "upload_file='$durl'"))
{
$row = $sql->db_Fetch();
$filesize = $row['upload_filesize'];
}
}
$_POST['download_description'] = $tp->toDB($_POST['download_description']);
$_POST['download_name'] = $tp->toDB($_POST['download_name']);
$_POST['download_author'] = $tp->toDB($_POST['download_author']);
if (preg_match("#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#", $_POST['download_datestamp'], $matches)){
$_POST['download_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
}else{
$_POST['download_datestamp'] = time();
}
if($_POST['update_datestamp']){ $_POST['download_datestamp'] = time(); }
$mirrorStr = "";
$mirrorReq = "";
if($_POST['download_mirror_name'][0])
{
$mirrors = count($_POST['download_mirror_name']);
for($a=0; $a<$mirrors; $a++)
{
$mirror_id = $_POST['download_mirror_name'][$a];
$mirror_url = $_POST['download_mirror'][$a];
$mirrorStr .= $mirror_id.",".$mirror_url.",0".chr(1);
}
}
if ($id)
{
admin_update($sql->db_Update("download", "download_name='".$_POST['download_name']."', download_url='".$durl."', download_author='".$_POST['download_author']."', download_author_email='".$_POST['download_author_email']."', download_author_website='".$_POST['download_author_website']."', download_description='".$_POST['download_description']."', download_filesize='".$filesize."', download_category='".intval($_POST['download_category'])."', download_active='".intval($_POST['download_active'])."', download_datestamp='".intval($_POST['download_datestamp'])."', download_thumb='".$_POST['download_thumb']."', download_image='".$_POST['download_image']."', download_comment='".intval($_POST['download_comment'])."', download_class = '{$_POST['download_class']}', download_mirror='$mirrorStr', download_mirror_type='".intval($_POST['download_mirror_type'])."' , download_visible='".$_POST['download_visible']."' WHERE download_id=".intval($id)), 'update', DOWLAN_2);
} else {
if (admin_update($download_id = $sql->db_Insert("download", "0, '".$_POST['download_name']."', '".$durl."', '".$_POST['download_author']."', '".$_POST['download_author_email']."', '".$_POST['download_author_website']."', '".$_POST['download_description']."', '".$filesize."', '0', '".intval($_POST['download_category'])."', '".intval($_POST['download_active'])."', '".intval($_POST['download_datestamp'])."', '".$_POST['download_thumb']."', '".$_POST['download_image']."', '".intval($_POST['download_comment'])."', '{$_POST['download_class']}', '$mirrorStr', '".intval($_POST['download_mirror_type'])."', '".$_POST['download_visible']."' "), 'insert', DOWLAN_1)) {
$dlinfo = array("download_id" => $download_id, "download_name" => $_POST['download_name'], "download_url" => $durl, "download_author" => $_POST['download_author'], "download_author_email" => $_POST['download_author_email'], "download_author_website" => $_POST['download_author_website'], "download_description" => $_POST['download_description'], "download_filesize" => $filesize, "download_category" => $_POST['download_category'], "download_active" => $_POST['download_active'], "download_datestamp" => $time, "download_thumb" => $_POST['download_thumb'], "download_image" => $_POST['download_image'], "download_comment" => $_POST['download_comment'] );
$e_event->trigger("dlpost", $dlinfo);
if ($_POST['remove_upload']) {
$sql->db_Update("upload", "upload_active='1' WHERE upload_id='".$_POST['remove_id']."'");
$mes = " ".$_POST['download_name']." ".DOWLAN_104;
$mes .= "".DOWLAN_105." ";
$this->show_message($mes);
}
}
}
}
function show_categories($sub_action, $id)
{
global $sql, $rs, $ns, $tp, $pst;
if (!is_object($sql2)) {
$sql2 = new db;
}
$text = $rs->form_open("post", e_SELF."?".e_QUERY, "myform");
$text .= "";
$qry = "
SELECT dc.*, COUNT(d.download_id) AS filecount FROM #download_category AS dc
LEFT JOIN #download AS d ON d.download_category = dc.download_category_id
GROUP BY dc.download_category_id
ORDER BY dc.download_category_order
";
if($sql->db_Select_gen($qry))
{
$categories = $sql->db_getList();
foreach($categories as $cat)
{
$cat_array[$cat['download_category_parent']][] = $cat;
}
$text .= "
".DOWLAN_11."
".DOWLAN_52."
".LAN_ORDER."
".LAN_OPTIONS."
";
//Start displaying parent categories
foreach($cat_array[0] as $parent)
{
if(strstr($parent['download_category_icon'], chr(1)))
{
list($parent['download_category_icon'], $parent['download_category_icon_empty']) = explode(chr(1), $parent['download_category_icon']);
}
$text .= "
";
//Show main categories
if(is_array($cat_array[$parent['download_category_id']]))
{
foreach($cat_array[$parent['download_category_id']] as $main)
{
if(strstr($main['download_category_icon'], chr(1)))
{
list($main['download_category_icon'], $main['download_category_icon_empty']) = explode(chr(1), $main['download_category_icon']);
}
$text .= "
";
//Show sub categories
if(is_array($cat_array[$main['download_category_id']]))
{
foreach($cat_array[$main['download_category_id']] as $sub)
{
if(strstr($sub['download_category_icon'], chr(1)))
{
list($sub['download_category_icon'], $sub['download_category_icon_empty']) = explode(chr(1), $sub['download_category_icon']);
}
$text .= "
";
}
}
}
}
}
$text .= "
";
$text .= "
";
}
else
{
$text .= "".DOWLAN_38."
";
}
$text .= "";
$ns->tablerender(DOWLAN_37, $text);
unset($download_category_id, $download_category_name, $download_category_description, $download_category_parent, $download_category_icon, $download_category_class);
$handle = opendir(e_IMAGE."icons");
while ($file = readdir($handle)) {
if ($file != "." && $file != ".." && $file != "/" && $file != "CVS") {
$iconlist[] = $file;
}
}
closedir($handle);
if ($sub_action == "edit" && !$_POST['add_category']) {
if ($sql->db_Select("download_category", "*", "download_category_id=$id")) {
$row = $sql->db_Fetch();
extract($row);
$main_category_parent = $download_category_parent;
if(strstr($download_category_icon, chr(1)))
{
list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon);
}
else
{
$download_category_icon_empty = "";
}
}
}
$preset = $pst->read_preset("admin_dl_cat"); // read preset values into array
extract($preset);
$frm_action = (isset($_POST['add_category'])) ? e_SELF."?cat" : e_SELF."?".e_QUERY;
$text = "";
$ns->tablerender(DOWLAN_39, $text);
}
function create_category($sub_action, $id) {
global $sql, $tp;
$download_category_name = $tp->toDB($_POST['download_category_name']);
$download_category_description = $tp->toDB($_POST['download_category_description']);
$download_category_icon = $tp->toDB($_POST['download_category_icon']);
if(isset($_POST['download_category_icon_empty']) && $_POST['download_category_icon_empty'] != ""){
$download_category_icon .= trim(chr(1).$tp->toDB($_POST['download_category_icon_empty']));
}
if ($id) {
admin_update($sql->db_Update("download_category", "download_category_name='$download_category_name', download_category_description='$download_category_description', download_category_icon ='$download_category_icon', download_category_parent= '".intval($_POST['download_category_parent'])."', download_category_class='".$_POST['download_category_class']."' WHERE download_category_id='$id'"), 'update', DOWLAN_48);
} else {
admin_update($sql->db_Insert("download_category", "0, '$download_category_name', '$download_category_description', '$download_category_icon', '".intval($_POST['download_category_parent'])."', '".$_POST['download_category_class']."', 0 "), 'insert', DOWLAN_47);
}
if ($sub_action == "sn") {
$sql->db_Delete("tmp", "tmp_time='$id' ");
}
}
function show_existing_mirrors()
{
global $sql, $ns, $tp, $sub_action, $id, $delete, $del_id;
if($delete == "mirror")
{
admin_update($sql -> db_Delete("download_mirror", "mirror_id=".$del_id), delete, DOWLAN_135);
}
if(!$sql -> db_Select("download_mirror"))
{
$text = "".DOWLAN_144."
"; // No mirrors defined yet
}
else
{
$text = "";
}
$ns -> tablerender(DOWLAN_138, $text);
require_once(e_HANDLER."file_class.php");
$fl = new e_file;
$rejecthumb = array('$.','$..','/','CVS','thumbs.db','*._$',"thumb_", 'index', 'null*');
$imagelist = $fl->get_files(e_FILE."downloadimages/","",$rejecthumb);
if($sub_action == "edit" && !defined("SUBMITTED"))
{
$sql -> db_Select("download_mirror", "*", "mirror_id=".$id);
$row = $sql -> db_Fetch();
extract($mirror);
$edit = TRUE;
}
else
{
unset($mirror_name, $mirror_url, $mirror_image, $mirror_location, $mirror_description);
$edit = FALSE;
}
$text = "";
$caption = ($edit ? DOWLAN_142 : DOWLAN_143);
$ns -> tablerender($caption, $text);
}
function submit_mirror()
{
global $tp, $sql;
define("SUBMITTED", TRUE);
if(isset($_POST['mirror_name']) && isset($_POST['mirror_url']))
{
$name = $tp -> toDB($_POST['mirror_name']);
$url = $tp -> toDB($_POST['mirror_url']);
$location = $tp -> toDB($_POST['mirror_location']);
$description = $tp -> toDB($_POST['mirror_description']);
if (isset($_POST['id'])){
admin_update($sql -> db_Update("download_mirror", "mirror_name='$name', mirror_url='$url', mirror_image='".$_POST['mirror_image']."', mirror_location='$location', mirror_description='$description' WHERE mirror_id=".$_POST['id']), 'update', DOWLAN_133);
} else {
admin_update($sql -> db_Insert("download_mirror", "0, '$name', '$url', '".$_POST['mirror_image']."', '$location', '$description', 0"), 'insert', DOWLAN_134);
}
}
}
}
function download_adminmenu($parms) {
global $download;
global $action;
$download->show_options($action);
}
?>