";
$ns->tablerender(ADLAN_24, $text);
}
// -----------------------------------------------------------------------------
function show_message($message) {
global $ns;
$ns->tablerender("", "
".$message."
");
}
// -----------------------------------------------------------------------------
// Actually save a new or edited download to the DB
function submit_download($sub_action, $id)
{
global $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event;
$dlInfo = array();
$dlMirrors = array();
if($sub_action == 'edit')
{
if($_POST['download_url_external'] == '')
{
$_POST['download_filesize_external'] = FALSE;
}
}
if ($_POST['download_url_external'] && $_POST['download_url'] == '')
{
$dlInfo['download_url'] = $tp->toDB($_POST['download_url_external']);
$filesize = intval($_POST['download_filesize_external']);
}
else
{
$dlInfo['download_url'] = $tp->toDB($_POST['download_url']);
if($_POST['download_filesize_external'])
{
$filesize = intval($_POST['download_filesize_external']);
}
else
{
if (strpos($DOWNLOADS_DIRECTORY, "/") === 0 || strpos($DOWNLOADS_DIRECTORY, ":") >= 1)
{
$filesize = filesize($DOWNLOADS_DIRECTORY.$dlInfo['download_url']);
}
else
{
$filesize = filesize(e_BASE.$DOWNLOADS_DIRECTORY.$dlInfo['download_url']);
}
}
}
if (!$filesize)
{
if($sql->db_Select("upload", "upload_filesize", "upload_file='{$dlInfo['download_url']}'"))
{
$row = $sql->db_Fetch();
$filesize = $row['upload_filesize'];
}
}
$dlInfo['download_filesize'] = $filesize;
// ---- Move Images and Files ------------
if($_POST['move_image'])
{
if($_POST['download_thumb'])
{
$oldname = e_UPLOAD.$_POST['download_thumb'];
$newname = e_FILE."downloadthumbs/".$_POST['download_thumb'];
if(!$this -> move_file($oldname,$newname))
{
return;
}
}
if($_POST['download_image'])
{
$oldname = e_UPLOAD.$_POST['download_image'];
$newname = e_FILE."downloadimages/".$_POST['download_image'];
if(!$this -> move_file($oldname,$newname))
{
return;
}
}
}
if($_POST['move_file'] && $_POST['download_url'])
{
$oldname = e_UPLOAD.$_POST['download_url'];
$newname = $_POST['move_file'].$_POST['download_url'];
if(!$this -> move_file($oldname,$newname))
{
return;
}
$dlInfo['download_url'] = str_replace(e_DOWNLOAD,"",$newname);
}
// ------------------------------------------
$dlInfo['download_description'] = $tp->toDB($_POST['download_description']);
$dlInfo['download_name'] = $tp->toDB($_POST['download_name']);
$dlInfo['download_author'] = $tp->toDB($_POST['download_author']);
$dlInfo['download_author_email'] = $tp->toDB($_POST['download_author_email']);
$dlInfo['download_author_website'] = $tp->toDB($_POST['download_author_website']);
$dlInfo['download_category'] = intval($_POST['download_category']);
$dlInfo['download_active'] = intval($_POST['download_active']);
$dlInfo['download_thumb'] = $tp->toDB($_POST['download_thumb']);
$dlInfo['download_image'] = $tp->toDB($_POST['download_image']);
$dlInfo['download_comment'] = $tp->toDB($_POST['download_comment']);
$dlInfo['download_class'] = intval($_POST['download_class']);
$dlInfo['download_visible'] =intval($_POST['download_visible']);
if (preg_match("#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#", $_POST['download_datestamp'], $matches))
{
$dlInfo['download_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
}
else
{
$dlInfo['download_datestamp'] = time();
}
if($_POST['update_datestamp'])
{
$dlInfo['download_datestamp'] = time();
}
$mirrorStr = "";
$mirrorFlag = FALSE;
// 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++)
{
$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);
}
$dlMirrors['download_mirror']=$mirrorStr;
$dlMirrors['download_mirror_type']=intval($_POST['download_mirror_type']);
if ($id)
{ // Its an edit
admin_update($sql->db_UpdateArray('download',array_merge($dlInfo,$dlMirrors),'WHERE download_id='.intval($id)), 'update', DOWLAN_2." (".$_POST['download_name'].")");
$dlInfo['download_id'] = $id;
$this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors);
$dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings
unset($dlInfo['download_class']); // Also replicating 0.7
$e_event->trigger('dlupdate', $dlInfo);
}
else
{
if (admin_update($download_id = $sql->db_Insert('download',array_merge($dlInfo,$dlMirrors)), 'insert', DOWLAN_1." (".$_POST['download_name'].")"))
{
$dlInfo['download_id'] = $download_id;
$this->downloadLog('DOWNL_05',$dlInfo,$dlMirrors);
$dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings
unset($dlInfo['download_class']); // Also replicating 0.7
$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 downloadLog($aText, &$dlInfo, &$mirrorInfo=NULL)
{
global $admin_log;
$logString = DOWLAN_9;
foreach ($dlInfo as $k => $v)
{
$logString .= '[!br!]'.$k.'=>'.$v;
}
if ($mirrorInfo != NULL)
{
foreach ($mirrorInfo as $k => $v)
{
$logString .= '[!br!]'.$k.'=>'.$v;
}
}
$admin_log->log_event($aText,$logString,E_LOG_INFORMATIVE,'');
}
// -----------------------------------------------------------------------------
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 .= "