<?php
// Master Autoindex
// ionutvmi@gmail.com 
// Sep 2012
// master-land.net

include "inc/init.php";

$plugins->run_hook("file_top");


$fid = (int)$_GET['id'];

$file = $db->get_row("SELECT * FROM `". MAI_PREFIX ."files` WHERE `id`='$fid'");

if(!$file) {
	header("Location: $set->url");
	exit;
}
$title = $file->name;

if(isset($_GET["download"])) {
	$plugins->run_hook("download",null);
	
	$db->query("UPDATE `". MAI_PREFIX ."files` SET `dcount` = dcount+1 WHERE `id` = '$fid'");
	
	if(isset($_GET['jad'])) {
		include 'lib/pclzip.lib.php';
		$l = ".".$file->path;
		$zip = new PclZip($l);
		$content = $zip->extract(PCLZIP_OPT_BY_NAME,'META-INF/MANIFEST.MF',PCLZIP_OPT_EXTRACT_AS_STRING);
		$filesize=filesize($l);
		header('Content-type: text/vnd.sun.j2me.app-descriptor');
		header('Content-Disposition: attachment; filename="'.basename($l).'.jad";');

		echo $content[0]['content']."\n".'MIDlet-Jar-Size: '.$filesize."\n".'MIDlet-Jar-URL: '.$set->url.$file->path;
		exit;
	
	}else {
		
		if (file_exists(".".$file->path)) {
            header("Location: $set->url".$file->path);
			exit;
		}
	}
}
$db->query("UPDATE `". MAI_PREFIX ."files` SET `views` = views+1 WHERE `id` = '$fid'");
$name = $lang->name." : ".$file->name;
$description = $lang->description." : ".$file->description;
$time = $lang->uploaded_on." : ".date("D, d M Y",$file->time);
$size = $lang->size." : ".convert($file->size);
$dloads = $lang->downloads." : ".$file->dcount;
$views = $lang->views." : ".$file->views;

$ext = (object)pathinfo($file->path);
$ext->extension = strtolower($ext->extension);


if(in_array($ext->extension,array('png','jpg','jpeg','gif','jar'))) {
	if($ext->extension == 'jar') 
		$icon = "/icon.php?s=".base64_encode($file->path);
	else{
		$icon = "/thumb.php?w=128&src=".base64_encode($file->path);
		$extra_img = "<div>
		$lang->width : 
		<a href='$set->url/thumb.php?w=16&src=".base64_encode($file->path)."' class='touch'>16px</a>
		<a href='$set->url/thumb.php?w=32&src=".base64_encode($file->path)."' class='touch'>32px</a>
		<a href='$set->url/thumb.php?w=64&src=".base64_encode($file->path)."' class='touch'>64px</a>
		<a href='$set->url/thumb.php?w=128&src=".base64_encode($file->path)."' class='touch'>128px</a>
		<a href='$set->url/thumb.php?w=256&src=".base64_encode($file->path)."' class='touch'>256px</a>
		<a href='$set->url/thumb.php?w=512&src=".base64_encode($file->path)."' class='touch'>512px</a>
		<br/>
		<form action='$set->url/thumb.php'>
		<input type='text' size='3' name='w'>x<input type='text' size='3' name='h'><input type='submit' value='$lang->ok'>
		<input type='hidden' name='src' value='".base64_encode($file->path)."'>
		</form>
		</div>";
	}
}else{
	$all_icons = str_replace(".png","",array_map("basename",glob(MAI_TPL."style/png/*.png")));
	if(!in_array($ext->extension,$all_icons))
		$icon = "/". MAI_TPL ."style/png/file.png";
	else
		$icon = "/". MAI_TPL ."style/png/$ext->extension.png";
}

if($file->icon != '')
	$icon = "/thumb.php?ext&w=128&src=".urlencode($file->icon);

	$plugins->run_hook("file_mid");
	
	
$show_icon = "<img src='$set->url".$icon."' width='128'>";


$download = "
<b><u><font color='red'>Disclaimer :</font></u></b></br></br>

<b>Copyright Disclaimer Under Section 107 of the Copyright Act 1976. All the songs, applications, tones at Zmobi.In are for listening purposes only. Making duplicate Audio CD's from MP3 files is illegal. Allowance is made for 'fair use'. Therefore please kindly support us by buying original version of Audio CD's from your local retailer , Applications For Your App Market , From google, or etc. All the rights are reserved to the audio company. The owner of this website cannot held liability for any illegal usage of the contents. Any disclaimer can contact by Email : admin@zmobi.in </b>
</br></br>
<b><font color='green'>Thanks regards,</font></b></br>
<b>Zmobi.In Administration.</b>


<div><div class='menuhead'>Download Here With Options</div>
</div> 
<div><a href='http://waptrack.net/vote/78476' class='touch'><img src='http://zmobi.in/icons/download.png'> $lang->download $ext->extension -<b>(3G Speed)</b></a> </div>
<!-- Please paste the below code in your body of your HTML wherever you want to display AdIQuity ads in your page. If you want to display AdIQuity ads at multiple places on the same page, Please make sure you use unique div ids from the below code. For Ex: my-ad-slot-top, my-ad-slot-bottom. Do not forget to replace all values of div ids everywhere. -->
<div id = 'my-ad-slot'></div>
<script type='text/javascript' src='http://us-ads.adiquity.com/scripts/adiquity.js'></script>
<script type='text/javascript'>

    /*
    * Configuration Parameters
    *
        pazid: 'pazid',
        app: 'app',
        hwid: 'hwid',
        hwid_md5: 'hwid_md5',
        hwid_sha1: 'hwid_sha1',
        odin: 'odin',
        plat: 'plat',
        app_pkg: 'app_pkg',
        app_name: 'app_name',
        adunit: 'adunit',
        dob: 'dob',
        age: 'age',
        gender: gender',
        loc: 'loc',
        zip: 'zip',
        city: 'city',
        state: 'state',
        tags: 'tags',
        test: 'test',
    *
    */
    var adiquity_conf = {
        pazid : 'adq5akn2-14eml1mj-7c6tv',
        test: false,

        //Below Callback method gets triggered when Adiquity is not returning any ad.
        onAdsNotAvailable: function() {
            document.getElementById('my-ad-slot').style.display = 'none';
            //Please have your own logic to handle this case.
        }
    };

try {
    _adiquity.getAd(document.getElementById('my-ad-slot'), adiquity_conf);
} catch (err) { 
//Please use this block to catch exception (only incase of errors)
}
</script>
<div><a href='?download' class='touch'><img src='http://zmobi.in/icons/download.png'> $lang->download $ext->extension -<b>(Server 1 Normal)</b></a> </div>
<!-- Please paste the below code in your body of your HTML wherever you want to display AdIQuity ads in your page. If you want to display AdIQuity ads at multiple places on the same page, Please make sure you use unique div ids from the below code. For Ex: my-ad-slot-top, my-ad-slot-bottom. Do not forget to replace all values of div ids everywhere. -->
<div id = 'my-ad-slot'></div>
<script type='text/javascript' src='http://us-ads.adiquity.com/scripts/adiquity.js'></script>
<script type='text/javascript'>

    /*
    * Configuration Parameters
    *
        pazid: 'pazid',
        app: 'app',
        hwid: 'hwid',
        hwid_md5: 'hwid_md5',
        hwid_sha1: 'hwid_sha1',
        odin: 'odin',
        plat: 'plat',
        app_pkg: 'app_pkg',
        app_name: 'app_name',
        adunit: 'adunit',
        dob: 'dob',
        age: 'age',
        gender: gender',
        loc: 'loc',
        zip: 'zip',
        city: 'city',
        state: 'state',
        tags: 'tags',
        test: 'test',
    *
    */
    var adiquity_conf = {
        pazid : 'adq5akn2-14eml1mj-7c6tv',
        test: false,

        //Below Callback method gets triggered when Adiquity is not returning any ad.
        onAdsNotAvailable: function() {
            document.getElementById('my-ad-slot').style.display = 'none';
            //Please have your own logic to handle this case.
        }
    };

try {
    _adiquity.getAd(document.getElementById('my-ad-slot'), adiquity_conf);
} catch (err) { 
//Please use this block to catch exception (only incase of errors)
}
</script>
<div><a href='http://besttop.mobi/in.php?id=81561' class='touch'><img src='http://zmobi.in/icons/download.png'> $lang->download $ext->extension -<b>(Server 2 - (Mirror)</b></a> </div>
<!-- Please paste the below code in your body of your HTML wherever you want to display AdIQuity ads in your page. If you want to display AdIQuity ads at multiple places on the same page, Please make sure you use unique div ids from the below code. For Ex: my-ad-slot-top, my-ad-slot-bottom. Do not forget to replace all values of div ids everywhere. -->
<div id = 'my-ad-slot'></div>
<script type='text/javascript' src='http://us-ads.adiquity.com/scripts/adiquity.js'></script>
<script type='text/javascript'>

    /*
    * Configuration Parameters
    *
        pazid: 'pazid',
        app: 'app',
        hwid: 'hwid',
        hwid_md5: 'hwid_md5',
        hwid_sha1: 'hwid_sha1',
        odin: 'odin',
        plat: 'plat',
        app_pkg: 'app_pkg',
        app_name: 'app_name',
        adunit: 'adunit',
        dob: 'dob',
        age: 'age',
        gender: gender',
        loc: 'loc',
        zip: 'zip',
        city: 'city',
        state: 'state',
        tags: 'tags',
        test: 'test',
    *
    */
    var adiquity_conf = {
        pazid : 'adq5akn2-14eml1mj-7c6tv',
        test: false,

        //Below Callback method gets triggered when Adiquity is not returning any ad.
        onAdsNotAvailable: function() {
            document.getElementById('my-ad-slot').style.display = 'none';
            //Please have your own logic to handle this case.
        }
    };

try {
    _adiquity.getAd(document.getElementById('my-ad-slot'), adiquity_conf);
} catch (err) { 
//Please use this block to catch exception (only incase of errors)
}
</script>
<div><a href='http://waptoplist.net/welcome/4727' class='touch'><img src='http://zmobi.in/icons/download.png'> $lang->download $ext->extension -<b>(Server 3 - (4G Speed)</b></a> </div>
<!-- Please paste the below code in your body of your HTML wherever you want to display AdIQuity ads in your page. If you want to display AdIQuity ads at multiple places on the same page, Please make sure you use unique div ids from the below code. For Ex: my-ad-slot-top, my-ad-slot-bottom. Do not forget to replace all values of div ids everywhere. -->
<div id = 'my-ad-slot'></div>
<script type='text/javascript' src='http://us-ads.adiquity.com/scripts/adiquity.js'></script>
<script type='text/javascript'>

    /*
    * Configuration Parameters
    *
        pazid: 'pazid',
        app: 'app',
        hwid: 'hwid',
        hwid_md5: 'hwid_md5',
        hwid_sha1: 'hwid_sha1',
        odin: 'odin',
        plat: 'plat',
        app_pkg: 'app_pkg',
        app_name: 'app_name',
        adunit: 'adunit',
        dob: 'dob',
        age: 'age',
        gender: gender',
        loc: 'loc',
        zip: 'zip',
        city: 'city',
        state: 'state',
        tags: 'tags',
        test: 'test',
    *
    */
    var adiquity_conf = {
        pazid : 'adq5akn2-14eml1mj-7c6tv',
        test: false,

        //Below Callback method gets triggered when Adiquity is not returning any ad.
        onAdsNotAvailable: function() {
            document.getElementById('my-ad-slot').style.display = 'none';
            //Please have your own logic to handle this case.
        }
    };

try {
    _adiquity.getAd(document.getElementById('my-ad-slot'), adiquity_conf);
} catch (err) { 
//Please use this block to catch exception (only incase of errors)
}
</script></div></a>";
if($ext->extension == 'jar') 
	$download .= "<a href='?download&jad'><div class='download'> $lang->download JAD</div></a>";

foreach(explode('/',substr($file->path,7)) as $dr){
	if(trim($dr != "")) {
	$_dr .="/".$dr;
	$id = $db->get_row("SELECT `id`,`name` FROM `". MAI_PREFIX ."files` WHERE `path` = '/files".$db->escape($_dr)."'");
	$links[] = mai_img("arr.gif")."&nbsp;<a href='$set->url/data/".($file->id == $id->id ? "file/" : "").$id->id."/".mai_converturl($id->name).".html'>$id->name</a>";
	}
}
	if(is_admin()){
		$_admin = "<div align='center'><div class='menuhead' align='center'><a href='$set->url/admincp/actions.php?act=edit&id=$file->id'>$lang->edit</a> |
		<a href='$set->url/admincp/actions.php?act=delete&id=$file->id'>$lang->delete</a></center></div></div>";
	}

include "header.php";
$tpl->grab("file.tpl",'file');
$tpl->assign('name',$name);
$tpl->assign('description',$description);
$tpl->assign('size',$size);
$tpl->assign('dloads',$dloads);
$tpl->assign('views',$views);
$tpl->assign('show_icon',$show_icon);
$tpl->assign('time',$time);
$tpl->assign('download',$download);
$tpl->assign('extra_img',$extra_img);
$tpl->assign('_admin',$_admin);
$tpl->display();

$plugins->run_hook("file_end");
include "footer.php";