<?php
include("connect.php");
include("includes/func_download.php");
$folder=$folderdownload;
$action = $_GET['action'];
if(!isset($action)) $action = "home";

IF ($action=="home"){
$m1=$d6;
$m2=$k6;
tpl_header($LANGAUGE[62]);
bar($namelinks1,$LANGAUGE[62],"","");

table($LANGAUGE[62],downloadcats(),1);

tpl_footer();

}ELSEIF ($action=="cat"){
$id = intval($_GET["id"]);

$sql = @mysql_query("select * from download_cat where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}
$Row['name_cat'] = text(3,$Row['name_cat']);

tpl_header($Row['name_cat']);
bar($namelinks1,$namelinks12,$Row['name_cat'],"");

table($Row['name_cat'],download(),1);

tpl_footer();

}ELSEIF ($action=="show"){

$id = intval($_GET["id"]);

$sql = @mysql_query("select * from download where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}

$name = text(3,$Row['name']);
$url = text(3,$Row['url']);
$url2 = text(3,$Row['url2']);
$vis = $Row['vis'];
$dow = $Row['downloads'];
$cat = $Row['cat'];
$text = text(2,$Row['text']);
$image = text(3,$Row['image']);
$d = date("j/n/Y",$Row['date']);
$namepro = text(3,$Row['namepro']);

if($image == ""){
$iii = "";
}else{
$iii = "<tr>
    <td colspan='2' class='xtd' align='center'><img src='$image' alt='$name' border='0' /></td>
</tr>";
}

if($text == ""){
$ttt = "";
}else{
$ttt = "<tr>
    <td colspan='2' class='xtd'>".$text."</td>
</tr>";
}


if($url2 == ""){
$uuu = "";
}else{
$uuu = "<tr>
      <td width='30%' class='xtr'>".$LANGAUGE[104]." :</td>
      <td width='70%' class='xtd'><a target='_blank' href='$url2'>$url2</a></td>
</tr>";
}

if($namepro == ""){
$nnn = "";
}else{
$nnn = "<tr>
      <td width='30%' class='xtr'>".$LANGAUGE[105]." :</td>
      <td width='70%' class='xtd'>$namepro</td>
</tr>";
}

$sql2 = @mysql_query("SELECT * FROM download_cat where id='$cat'") or die ("Query failed3");
$cats = @mysql_fetch_array($sql2);
$catnamef = text(3,$cats['name_cat']);
if ($htmlorphp=="1"){
$xxx = "<a href='downloadcat-$cat.html'>$catnamef</a>";
$ddd = "downloadfile-$id.html";
}else{
$xxx = "<a href='download.php?action=cat&id=$cat'>$catnamef</a>";
$ddd = "download.php?action=download&id=$id";
}

$sql3 = @mysql_query("update download set vis=vis+1 where id='$id'") or die ("Query failed4");

$F = "<table class='xtable' width='100%' id='Auber1f5'>

$ttt
$iii
$uuu
$nnn

    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[106]." :</td>
      <td width='70%' class='xtd'><a target='_blank' href='$ddd'><img src='$folder/icons/save.png' alt='$name' border='0' /></a></td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[107]." :</td>
      <td width='70%' class='xtd'>".$xxx."</td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[84]." :</td>
      <td width='70%' class='xtd'>$vis</td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[108]." :</td>
      <td width='70%' class='xtd'>$dow</td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[83]." :</td>
      <td width='70%' class='xtd'>$d</td>
    </tr>
  </table>";

tpl_header($name);
bar($namelinks1,$namelinks12,$xxx,$name);

table($name,$F,1);

tpl_footer();

}ELSEIF ($action=="download"){

$id = intval($_GET["id"]);
$id = clean_value($id);

$sql = @mysql_query("select * from download where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}

$Row['name'] = text(3,$Row['name']);
$Row['url'] = text(3,$Row['url']);

$sql2 = @mysql_query("update download set downloads=downloads+1 where id='$id'") or die ("Query failed4");

$name = str_replace(" ","_",$Row['name']);
$fileName = $Row['url'];

$file_data = explode("/", $fileName);
$file_name_only = $name."_".$file_data[count($file_data)-1];

if (file_exists($fileName))
{
 header('Content-type: application/force-download');
 header('Content-Transfer-Encoding: Binary');
 header('Content-length: '.filesize($fileName));
 header('Content-disposition: attachment; filename='.$file_name_only.'');
 readfile($fileName);

}else{
echo "<meta http-equiv='Refresh' content='0;URL=$fileName' />";

}

}
?>