From 55f51fee18a3055acf46b91cb2b49054020017c9 Mon Sep 17 00:00:00 2001 From: e107steved Date: Tue, 23 Sep 2008 19:31:59 +0000 Subject: [PATCH] Bugtracker #4516 - download admin fixes --- e107_admin/download.php | 350 +++++++++++------- .../shortcode/batch/download_shortcodes.php | 12 +- 2 files changed, 229 insertions(+), 133 deletions(-) diff --git a/e107_admin/download.php b/e107_admin/download.php index f1a600576..a215c30d7 100644 --- a/e107_admin/download.php +++ b/e107_admin/download.php @@ -11,13 +11,17 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/download.php,v $ -| $Revision: 1.12 $ -| $Date: 2008-06-06 19:14:20 $ +| $Revision: 1.13 $ +| $Date: 2008-09-23 19:31:50 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ + +define('DOWNLOAD_DEBUG',FALSE); + require_once("../class2.php"); -if (!getperms("R")) { +if (!getperms("R")) +{ header("location:".e_BASE."index.php"); exit; } @@ -61,12 +65,12 @@ $rs = new form; $sub_action = ''; if (e_QUERY) { - $tmp = explode(".", e_QUERY); - $action = $tmp[0]; + $tmp = explode(".", e_QUERY); + $action = $tmp[0]; $sub_action = varset($tmp[1],''); $id = varset($tmp[2],''); $from = varset($tmp[3], 0); - unset($tmp); + unset($tmp); } if(isset($_POST['delete'])) @@ -82,7 +86,7 @@ $amount = 50; if($file_array = $fl->get_files(e_DOWNLOAD, "","standard",5)) { - sort($file_array); + sort($file_array); } @@ -90,8 +94,8 @@ if($public_array = $fl->get_files(e_FILE."public/")) { foreach($public_array as $key=>$val) { - $file_array[] = str_replace(e_FILE."public/","",$val); - } + $file_array[] = str_replace(e_FILE."public/","",$val); + } } @@ -100,9 +104,9 @@ if ($sql->db_Select("rbinary")) { while ($row = $sql->db_Fetch()) { - extract($row); - $file_array[] = "Binary ".$binary_id."/".$binary_name; - } + extract($row); + $file_array[] = "Binary ".$binary_id."/".$binary_name; + } } @@ -119,19 +123,19 @@ if($thumb_array = $fl->get_files(e_FILE."downloadthumbs/", ".gif|.jpg|.png|.GIF| if(isset($_POST)) { - $e107cache->clear("download_cat"); + $e107cache->clear("download_cat"); } if (isset($_POST['add_category'])) { - $download->create_category($sub_action, $id); + $download->create_category($sub_action, $id); } if (isset($_POST['submit_download'])) { - $download->submit_download($sub_action, $id); - $action = "main"; - unset($sub_action, $id); + $download->submit_download($sub_action, $id); + $action = "main"; + unset($sub_action, $id); } @@ -240,7 +244,7 @@ if ($action == "dlm") if ($action == "create") { - $download->create_download($sub_action, $id); + $download->create_download($sub_action, $id); } @@ -248,43 +252,46 @@ 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}' "); - } + $sql->db_Delete("download_category", "download_category_parent='{$del_id}' "); + } } if ($action == "cat") { - $download->show_categories($sub_action, $id); + $download->show_categories($sub_action, $id); } if ($delete == 'main') { - $result = admin_update($sql->db_Delete("download", "download_id='$del_id' "), 'delete', DOWLAN_27." #".$del_id." ".DOWLAN_36); - if($result) - { - admin_purge_related("download", $del_id); - $e_event->trigger("dldelete", $del_id); - } - unset($sub_action, $id); + $result = admin_update($sql->db_Delete("download", "download_id='$del_id' "), 'delete', DOWLAN_27." #".$del_id." ".DOWLAN_36); + if($result) + { + admin_purge_related("download", $del_id); + $e_event->trigger("dldelete", $del_id); + } + unset($sub_action, $id); } if (isset($message)) { - $ns->tablerender("", "
".$message."
"); + $ns->tablerender("", "
".$message."
"); } if (!e_QUERY || $action == "main") { - $download->show_existing_items($action, $sub_action, $id, $from, $amount); + $download->show_existing_items($action, $sub_action, $id, $from, $amount); } -if ($action == "opt") { + + +if ($action == "opt") +{ global $pref, $ns; $agree_flag = $pref['agree_flag']; $agree_text = $pref['agree_text']; @@ -395,6 +402,8 @@ if ($action == "opt") { $ns->tablerender(DOWLAN_54, $text); } + + if($action == 'limits') { if($sql->db_Select('userclass_classes','userclass_id, userclass_name')) @@ -495,37 +504,37 @@ 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"; - $sortdirection = ($pref['download_sort']) ? strtolower($pref['download_sort']) : "desc"; - if ($sortdirection != 'desc') $sortdirection = 'asc'; - if(isset($_POST['searchdisp'])) + function show_existing_items($action, $sub_action, $id, $from, $amount) { - $pref['admin_download_disp'] = implode("|",$_POST['searchdisp']); - save_prefs(); - } + global $sql, $rs, $ns, $tp, $mySQLdefaultdb, $pref; + $text = "
"; + $sortorder = ($pref['download_order']) ? $pref['download_order'] : "download_datestamp"; + $sortdirection = ($pref['download_sort']) ? strtolower($pref['download_sort']) : "desc"; + if ($sortdirection != 'desc') $sortdirection = 'asc'; + 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']); - } + 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"; + $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']."') "; + $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 .= " OR $disp REGEXP('".$_POST['searchquery']."') "; + } $query .= " ORDER BY {$sortorder} {$sortdirection}"; } else @@ -541,7 +550,7 @@ class download ID "; -// Search Display Column header.---------- + // Search Display Column header.---------- foreach($search_display as $disp) { if($disp == "download_name") @@ -637,7 +646,7 @@ class download if ($downloads > $amount && !$_POST['searchquery']) { $parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$sub_action.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]"; - $text .= "
".$tp->parseTemplate("{NEXTPREV={$parms}}"); + $text .= "
".$tp->parseTemplate("{NEXTPREV={$parms}}"); } @@ -652,28 +661,28 @@ class download for ($i = 0; $i < $columns; $i++) { $fname[] = mysql_field_name($fields, $i); } - $m = 0; - $replacechar = array("download_","_"); + $m = 0; + $replacechar = array("download_","_"); foreach($fname as $fcol) { - $checked = (in_array($fcol,$search_display)) ? "checked='checked'" : ""; - $text .= ""; - $text .= "".str_replace($replacechar," ",$fcol) . "\n"; - $m++; + $checked = (in_array($fcol,$search_display)) ? "checked='checked'" : ""; + $text .= ""; + $text .= "".str_replace($replacechar," ",$fcol) . "\n"; + $m++; if($m == 5) { - $text .= ""; - $m = 0; - } - } + $text .= ""; + $m = 0; + } + } - $text .= "
+ $text .= "
\n
"; - $ns->tablerender(DOWLAN_7, $text); - } + $ns->tablerender(DOWLAN_7, $text); + } function show_options($action) { @@ -707,50 +716,78 @@ class download // --------------------------------------------------------------------------- + // Given the string which is stored in the DB, turns it into an array of mirror entries + // If $byID is true, the array index is the mirror ID. Otherwise its a simple array + function makeMirrorArray($source, $byID = FALSE) + { + $ret = array(); + if($source) + { + $mirrorTArray = explode(chr(1), $source); + + $count = 0; + foreach($mirrorTArray as $mirror) + { + if ($mirror) + { + list($mid, $murl, $mreq) = explode(",", $mirror); + $ret[$byID ? $mid : $count] = array('id' => $mid, 'url' => $murl, 'requests' => $mreq); + $count++; + } + } + } + return $ret; + } + + + // Turn the array into a string which can be stored in the DB + function compressMirrorArray($source) + { + if (!is_array($source) || !count($source)) return ''; + $inter = array(); + foreach ($source as $s) + { + $inter[] = $s['id'].','.$s['url'].','.$s['requests']; + } + return implode(chr(1),$inter); + } + + + function create_download($sub_action, $id) { global $cal,$tp, $sql, $fl, $rs, $ns, $file_array, $image_array, $thumb_array,$pst; require_once(e_FILE."shortcode/batch/download_shortcodes.php"); + $mirrorArray = array(); + $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")) { + 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' ")) { + 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++; - } - } - } + $mirrorArray = $this->makeMirrorArray($row['download_mirror']); } } - if ($sub_action == "dlm" && !$_POST['submit']) { - if ($sql->db_Select("upload", "*", "upload_id='$id' ")) { + if ($sub_action == "dlm" && !$_POST['submit']) + { + if ($sql->db_Select("upload", "*", "upload_id=".$id)) + { $row = $sql->db_Fetch(); $download_category = $row['upload_category']; @@ -798,34 +835,35 @@ class download $counter = 0; while (isset($file_array[$counter])) { - $fpath = str_replace(e_DOWNLOAD,"",$file_array[$counter]['path']).$file_array[$counter]['fname']; - $selected = ''; - if (stristr($fpath, $download_url) !== FALSE) - { - $selected = " selected='selected'"; - $found = 1; - } + $fpath = str_replace(e_DOWNLOAD,"",$file_array[$counter]['path']).$file_array[$counter]['fname']; + $selected = ''; + if (stristr($fpath, $download_url) !== FALSE) + { + $selected = " selected='selected'"; + $found = 1; + } - $text .= "\n"; - $counter++; + $text .= "\n"; + $counter++; } $dt = 'display:none'; if (preg_match("/http:|ftp:/", $download_url)) { - $download_url_external = $download_url; - $download_url = ''; - $dt = ''; + $download_url_external = $download_url; + $download_url = ''; + $dt = ''; } $etext = " - (".DOWLAN_68.")"; - if (file_exists(e_FILE."public/".$download_url)) { + if (file_exists(e_FILE."public/".$download_url)) + { $etext = ""; } if (!$found && $download_url) { - $text .= "\n"; + $text .= "\n"; } $text .= "
@@ -845,34 +883,49 @@ class download ".DOWLAN_128.": "; + + // See if any mirrors to display if(!$sql -> db_Select("download_mirror")) - { + { // No mirrors defined here $text .= DOWLAN_144.""; } else { - $text .= DOWLAN_132."
"; - $mirrorList = $sql -> db_getList(); + $mirrorList = $sql -> db_getList(); // Get the list of possible mirrors - $m_count = (count($mirrorArray) ? count($mirrorArray) : 1); + $m_count = (count($mirrorArray) ? count($mirrorArray) : 1); // Count of mirrors actually in use (or count of 1 if none defined yet) - for($count = 1; $count <= $m_count; $count++){ + for($count = 1; $count <= $m_count; $count++) + { $opt = ($count==1) ? "id='mirror'" : ""; - $text .=" + $text .=" "; + if (DOWNLOAD_DEBUG) + { + if ($id) + { + $text .= '('.$mirrorArray[($count-1)]['requests'].')'; + } + else + { + $text .= " + "; + } + } $text .= "
"; } @@ -889,7 +942,7 @@ class download ".DOWLAN_157." "; - } + } // End of mirror-related stuff $text .= " ".DOWLAN_15.": @@ -1107,7 +1160,8 @@ class download - function submit_download($sub_action, $id) { + function submit_download($sub_action, $id) + { global $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event; if($sub_action == 'edit') @@ -1201,33 +1255,75 @@ class download $_POST['download_datestamp'] = time(); } - if($_POST['update_datestamp']){ $_POST['download_datestamp'] = time(); } + if($_POST['update_datestamp']) + { + $_POST['download_datestamp'] = time(); + } $mirrorStr = ""; - $mirrorReq = ""; + $mirrorFlag = FALSE; - if($_POST['download_mirror_name'][0]) + // See if any mirrors defined + // Need to check all the possible mirror names - might have deleted the first one if we're in edit mode + foreach ($_POST['download_mirror_name'] as $mn) + { + if ($mn) + { + $mirrorFlag = TRUE; + break; + } + } + if($mirrorFlag) { $mirrors = count($_POST['download_mirror_name']); + $mirrorArray = array(); + $newMirrorArray = array(); + if ($id && $sql->db_Select('download','download_mirror', 'download_id = '.$id)) // Get existing download stats + { + if ($row = $sql->db_Fetch()) + { + $mirrorArray = $this->makeMirrorArray($row['download_mirror'], TRUE); + } + } 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); + $mid = trim($_POST['download_mirror_name'][$a]); + $murl = trim($_POST['download_mirror'][$a]); + if ($mid && $murl) + { + $newMirrorArray[$mid] = array('id' => $mid, 'url' => $murl, 'requests' => 0); + if (DOWNLOAD_DEBUG && !$id) + { + $newMirrorArray[$mid]['requests'] = intval($_POST['download_mirror_requests'][$a]); + } + } } + // Now copy across any existing usage figures + foreach ($newMirrorArray as $k => $m) + { + if (isset($mirrorArray[$k])) + { + $newMirrorArray[$k]['requests'] = $mirrorArray[$k]['requests']; + } + } + $mirrorStr = $this->compressMirrorArray($newMirrorArray); } if ($id) - { + { // Its an edit 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." (".$_POST['download_name'].")"); $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("dlupdate", $dlinfo); - } 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." (".$_POST['download_name'].")")) { + } + 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." (".$_POST['download_name'].")")) + { $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']) { + 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.""; @@ -1517,7 +1613,7 @@ class download 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'])); + $download_category_icon .= trim(chr(1).$tp->toDB($_POST['download_category_icon_empty'])); } if ($id) diff --git a/e107_files/shortcode/batch/download_shortcodes.php b/e107_files/shortcode/batch/download_shortcodes.php index e68787c64..7d21298c2 100644 --- a/e107_files/shortcode/batch/download_shortcodes.php +++ b/e107_files/shortcode/batch/download_shortcodes.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_files/shortcode/batch/download_shortcodes.php,v $ -| $Revision: 1.12 $ -| $Date: 2008-08-14 22:58:34 $ -| $Author: e107coders $ +| $Revision: 1.13 $ +| $Date: 2008-09-23 19:31:59 $ +| $Author: e107steved $ +----------------------------------------------------------------------------+ */ if (!defined('e107_INIT')) { exit; } @@ -454,7 +454,7 @@ SC_BEGIN DOWNLOAD_CATEGORY_SELECT // Its a structured display option - need a 2-step process to create a tree $catlist = array(); - while ($row = $sql->db_Fetch()) + while ($row = $sql->db_Fetch(MYSQL_ASSOC)) { $tmp = $row['download_category_parent']; if ($tmp == '0') @@ -484,14 +484,14 @@ SC_BEGIN DOWNLOAD_CATEGORY_SELECT { // Main categories // Could add a display class to the group, but the default looked OK - if(count($catlist)>1) + if(count($thiscat['subcats'])>0) { $boxinfo .= "\n"; $scprefix = ''; } else { - $sel = ($cdc == $sc['download_category_id']) ? " selected='selected'" : ""; + $sel = ($cdc == $thiscat['download_category_id']) ? " selected='selected'" : ""; $boxinfo .= "\n"; }