<?
$page = "uploads.php";
include "manager_header.php";

if($group_info[allow_album] != 1 AND $group_info[allow_podcastfiles] != 1 AND $group_info[allow_uploads] != 1) { exit(); }

if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
if(isset($_POST['page'])) { $page = $_POST['page']; } elseif(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = "1"; }
$files_per_page = 10;




// SET ERROR VARS
$errormsg = "";


// CALCULATE SPACE ALLOWED
$space_allowed = $group_info[uploads_space];
if($space_allowed >= 1024) { 
$space_allowed = $space_allowed / 1024;
$space_allowed = round($space_allowed, 2); 
$unit2 = "MB"; 
} else { 
$space_allowed = round($space_allowed, 0); 
$unit2 = "KB"; 
}

// CALCULATE SPACE USED
$files = mysql_fetch_assoc(mysql_query("SELECT sum(filesize) AS size FROM bhost_uploads WHERE u_id='$user_info[u_id]'"));
$space_used = $files[size];
$space_used = $space_used / 1024;
if($unit2 == "MB") {
$space_used = $space_used / 1024;
$space_used = round($space_used, 2);
$unit1 = "MB";
} elseif($unit2 == "KB") {
$space_used = round($space_used, 0);
$unit1 = "KB";
}
if($space_used >= $space_allowed) {
$redfont1 = "<font color='#FF0000'>";
$redfont2 = "</font>";
}

$space = "<br>$uploads14 $redfont1<b>$space_used $unit1 </b>/<b> $space_allowed $unit2</b>$redfont2";











if($task == "cancel") {
if(isset($_GET['up_id'])) { $up_id = $_GET['up_id']; } elseif(isset($_POST['up_id'])) { $up_id = $_POST['up_id']; } else { $up_id = ""; }
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { exit(); }
$file_info = mysql_fetch_assoc($file);
if($file_info[f_id] != 0) {
 $location = "uploads.php?task=viewfolder&f_id=$file_info[f_id]";
} else {
 if($file_info[location] == "podcast") {
  $location = "uploads.php?task=viewpodcasts";
 } elseif($file_info[location] == "album") {
  $location = "uploads.php?task=viewalbum";
 } else {
  $location = "uploads.php";
 }
}

header("Location: $location");
exit();
}




if($task == "delete") {
if(isset($_GET[up_id])) { $up_id = $_GET[up_id]; } else { header("Location: uploads.php"); exit(); }

// CHECK THAT USER OWNS THIS FILE
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { header("Location: uploads.php"); exit(); }
$file_info = mysql_fetch_assoc($file);

mysql_query("DELETE FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND up_id='$file_info[up_id]'");
$letter = strtolower(substr($user_info[username], 0, 1));
@unlink("../uploads/$letter/$user_info[username]/$file_info[up_id].$file_info[ext]");
if(file_exists("../uploads/$letter/$user_info[username]/$file_info[up_id]"."_thumb.$file_info[ext]")) {
 @unlink("../uploads/$letter/$user_info[username]/$file_info[up_id]"."_thumb.$file_info[ext]");
}
if($file_info[f_id] == "0" & $file_info[location] == "album") {
 header("Location: uploads.php?task=viewalbum");
 exit();
} elseif($file_info[f_id] == "0" & $file_info[location] == "podcast") {
 header("Location: uploads.php?task=viewpodcasts");
 exit();
} else {
 header("Location: uploads.php?task=viewfolder&f_id=$file_info[f_id]");
 exit;
}
}













if($task == "modify_do") {
$up_id = $_POST['up_id'];
$name = htmlspecialchars(stripslashes($_POST['name']), ENT_QUOTES);
$description = htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES);
$folder = $_POST['folder'];
$submit = $_POST['submit'];

// CHECK THAT USER OWNS FILE
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { header("Location: uploads.php"); exit(); }
$file_info = mysql_fetch_assoc($file);
if($file_info[f_id] != 0) { $folder_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_folders WHERE f_id='$file_info[f_id]' AND u_id='$user_info[u_id]'")); }

if(htmlentities($submit, ENT_QUOTES) != htmlentities(html_entity_decode($uploads6, ENT_QUOTES), ENT_QUOTES)) {

// IF DESTINATION FOLDER IS ALBUM
if($folder == "album") {

	// CHECK IF CURRENT FOLDER IS ALBUM
	if($file_info[location] != "album") {
	mysql_query("UPDATE bhost_uploads SET f_id='0', location='album' WHERE up_id='$file_info[up_id]' AND u_id='$user_info[u_id]'");
	}

// IF DESTINATION FOLDER IS PODCASTS
} elseif($folder == "podcasts") {

	// CHECK IF CURRENT FOLDER IS PODCAST
	if($file_info[location] != "podcast") {
	mysql_query("UPDATE bhost_uploads SET f_id='0', location='podcasts' WHERE up_id='$file_info[up_id]' AND u_id='$user_info[u_id]'");
	}

} else {

	// MOVE FILE TO NEW FOLDER, IF OWNED BY USER
	$newfolder = mysql_query("SELECT f_id, folder FROM bhost_folders WHERE f_id='$folder' AND u_id='$user_info[u_id]'");
	if(mysql_num_rows($newfolder) != 1) { header("Location: uploads.php"); exit; }
	$newfolder = mysql_fetch_assoc($newfolder);
	if($newfolder[f_id] != $file_info[f_id]) {
	mysql_query("UPDATE bhost_uploads SET f_id='$newfolder[f_id]', location='folder' WHERE up_id='$file_info[up_id]' AND u_id='$user_info[u_id]'");
	}

}


if(str_replace(" ", "", $name) == "") { $name = "Untitled"; }
mysql_query("UPDATE bhost_uploads SET name='$name', description='$description' WHERE up_id='$file_info[up_id]' AND u_id='$user_info[u_id]'");

}

if($file_info[f_id] == "0" & $file_info[location] == "album") {
 header("Location: uploads.php?task=viewalbum");
 exit();
} elseif($file_info[f_id] == "0" & $file_info[location] == "podcast") {
 header("Location: uploads.php?task=viewpodcasts");
 exit();
} else {
 header("Location: uploads.php?task=viewfolder&f_id=$file_info[f_id]");
 exit();
}
}







if($task == "modify") {
$up_id = $_GET['up_id'];
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { header("Location: uploads.php"); exit(); }
$file_info = mysql_fetch_assoc($file);
if($file_info[f_id] != 0) { $folder_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_folders WHERE f_id='$file_info[f_id]' AND u_id='$user_info[u_id]'")); }

if($file_info[f_id] != 0) {
 if($folder_info[in_album] == "1") {
  $path = "<a href='uploads.php?task=viewalbum'>$uploads21</a> &#187; <a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a>";
 } else {
  $path = "<a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a>";
 }
} else {
 if($file_info[location] == "album") {
  $path = "<a href='uploads.php?task=viewalbum'>$uploads21</a>";
 } elseif($file_info[location] == "podcast") {
  $path = "<a href='uploads.php?task=viewpodcasts'>$uploads22</a>";
 }
}

$letter = strtolower(substr($user_info[username], 0, 1));
$fileurl = "../uploads/$letter/$user_info[username]/$file_info[up_id].$file_info[ext]";

// CREATE FOLDER LIST
$folders_list = "
<tr>
<td class='form1'>$uploads7</td>
<td class='form2'>
<select name='folder'>
";

	// ADD FOLDERS IN ALBUM TO LIST
	if($group_info[allow_album] == 1) {
	$folders_inalbum = mysql_query("SELECT f_id, folder FROM bhost_folders WHERE in_album='1' AND u_id='$user_info[u_id]' ORDER BY folder");
	$folders_list .= "<option value='album'>$uploads21</option>";
	while($folder_inalbum = mysql_fetch_assoc($folders_inalbum)) {
	$folders_list .= "<option value='$folder_inalbum[f_id]'"; if($folder_inalbum[f_id] == $file_info[f_id]) { $folders_list .= " SELECTED"; } $folders_list .= ">&nbsp;&nbsp; $folder_inalbum[folder]</option>";
	}}

	// ADD OTHER FOLDERS TO LIST
	$folders = mysql_query("SELECT f_id, folder FROM bhost_folders WHERE in_album='0' AND u_id='$user_info[u_id]' ORDER BY folder");
	while($folder = mysql_fetch_assoc($folders)) {
	$folders_list .= "<option value='$folder[f_id]'"; if($folder[f_id] == $file_info[f_id]) { $folders_list .= " SELECTED"; } $folders_list .= ">$folder[folder]</option>";
	}

$folders_list .= "
</select>
</tr>
";

// IF THERE ARE NO OTHER FOLDERS, HIDE LIST
$totalfolders = mysql_num_rows($folders_inalbum) + mysql_num_rows($folders);
if($group_info[allow_album] == 1) { $totalfolders++; }
if($totalfolders == 0) { 
$folders_list = "<input type='hidden' name='folder' value='$file[f_id]'>";
}

echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> &#187; $path &#187; $uploads8</h2>
$uploads9
<br><br>
<table cellpadding='0' cellspacing='0' class='form'>
<form action='uploads.php' method='POST'>
<tr>
<td class='form1'>$uploads10&nbsp;</td>
<td class='form2'><input type='text' class='text' name='name' value='$file_info[name]' maxlength='30'>&nbsp;</td>
</tr>
<tr>
<td class='form1' valign='top'>$uploads17&nbsp;</td>
<td class='form2'><textarea name='description' rows='5' cols='60'>$file_info[description]</textarea>&nbsp;</td>
</tr>
$folders_list
</table>

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='submit' class='button' name='submit' value='$uploads18'>&nbsp;</td>
<td><input type='submit' class='button' name='submit' value='$uploads6'></td>
</tr>
<input type='hidden' name='task' value='modify_do'>
<input type='hidden' name='up_id' value='$file_info[up_id]'>
</form>
</table>
";

echo $foot;
exit;
}













if($task == "upload_do") {
$f_id = $_POST['f_id'];
$location = $_POST['location'];
if($f_id != 0) {
 $folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
 if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
 $folder_info = mysql_fetch_assoc($folder);
 if($folder_info[in_album] == "1" & $group_info[allow_album] != "1") { header("Location: uploads.php"); exit(); }
 if($folder_info[in_album] == "0" & $group_info[allow_uploads] != "1") { header("Location: uploads.php"); exit(); }
 if($folder_info[in_album] == "1") {
  $extensions = $group_info[album_extensions];
 } else {
  $extensions = $group_info[uploads_extensions];
 }
} else {
 if($location == "album") {
  if($group_info[allow_album] != "1") { header("Location: uploads.php"); exit(); }
  $extensions = $group_info[album_extensions];
 } elseif($location == "podcast") {
  if($group_info[allow_podcastfiles] != "1") { header("Location: uploads.php"); exit(); }
  $extensions = $group_info[podcast_extensions];
 } else {
  header("Location: uploads.php");
  exit();
 }
}

$name = htmlspecialchars(stripslashes($_POST['name']), ENT_QUOTES);
$description = htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES);
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$file_tempname = $_FILES['file']['tmp_name'];
$file_error = $_FILES['file']['error'];

// REPLACE SPACES, STRIP OTHER BAD CHARS
$file_name = str_replace(" ", "_", $file_name);
$file_name = str_replace("?", "", $file_name);
$file_name = str_replace("&", "", $file_name);
$file_name = str_replace("=", "", $file_name);
$file_name = str_replace("#", "", $file_name);
$file_name = str_replace("%", "", $file_name);
$file_name = str_replace("'", "", $file_name);
$file_name = str_replace("\"", "", $file_name);
$file_name = stripslashes($file_name);

// GET NEW FILE EXTENSION
$ext = strtolower(strrchr($file_name, "."));
$ext = str_replace(".", "", $ext);

// CHECK THAT FIELD IS NOT EMPTY
if(!isset($file_name) OR $file_name == "") {
$errormsg = "$uploads1";
}

// GET EXTENSION LIST
if($errormsg == "") {
$extlist = str_replace(" ", "", $extensions);
$extlist = str_replace(",", ", ", $extlist);
$extensions_case = strtolower($extensions);
$extensions = explode(",", $extensions_case);

// SEARCH FOR NEW FILE EXTENSION IN THE EXTENSION LIST
if(!in_array($ext, $extensions)) {
$errormsg = "$uploads2 $extlist";
}
}


// CHECK COMMON FILES FOR CORRECT MIME TYPES
if($errormsg == "") {
$type = strtolower($file_type);

if($ext == "jpg" OR $ext == "jpeg" OR $ext == "jpe") { 
if($type != "image/jpeg" AND $type != "image/jpg" AND $type != "image/jpe" AND $type != "image/pjpeg" AND $type != "image/pjpg" AND $type != "image/x-jpeg" AND $type != "image/x-jpg") {
$errormsg = $uploads27;
}}

elseif($ext == "gif") { 
if($type != "image/gif" AND $type != "image/x-gif") {
$errormsg = $uploads27;
}}

elseif($ext == "png") { 
if($type != "image/png" AND $type != "image/x-png") {
$errormsg = $uploads27;
}}

elseif($ext == "tiff") { 
if($type != "image/tif" AND $type != "image/tiff") {
$errormsg = $uploads27;
}}

elseif($ext == "bmp") { 
if($type != "image/bmp" AND $type != "image/x-bmp") {
$errormsg = $uploads27;
}}

elseif($ext == "html" OR $ext == "htm") { 
if($type != "text/html") {
$errormsg = $uploads27;
}}

elseif($ext == "css") { 
if($type != "text/css") {
$errormsg = $uploads27;
}}

elseif($ext == "txt") { 
if($type != "text/plain") {
$errormsg = $uploads27;
}}

elseif($ext == "xml") { 
if($type != "text/xml") {
$errormsg = $uploads27;
}}

elseif($ext == "mpeg" OR $ext == "mpg" OR $ext == "mpe") { 
if($type != "video/mpeg" AND $type != "video/x-mpeg") {
$errormsg = $uploads27;
}}

elseif($ext == "mp3" OR $ext == "mp2" OR $ext == "mpga") { 
if($type != "audio/mpeg" AND $type != "audio/x-mpeg") {
$errormsg = $uploads27;
}}

elseif($ext == "kar" OR $ext == "mid" OR $ext == "midi") { 
if($type != "audio/midi" AND $type != "audio/mid") {
$errormsg = $uploads27;
}}

elseif($ext == "aif" OR $ext == "aifc" OR $ext == "aiff") { 
if($type != "audio/x-aiff") {
$errormsg = $uploads27;
}}

elseif($ext == "wav") { 
if($type != "audio/x-wav" AND $type != "audio/wav") {
$errormsg = $uploads27;
}}

elseif($ext == "ram" OR $ext == "ra") { 
if($type != "audio/x-pn-realaudio") {
$errormsg = $uploads27;
}}

elseif($ext == "zip") { 
if($type != "application/zip" AND $type != "application/x-zip" AND $type != "application/x-zip-compressed") {
$errormsg = $uploads27;
}}

elseif($ext == "pdf") { 
if($type != "application/pdf") {
$errormsg = $uploads27;
}}

elseif($ext == "doc") { 
if($type != "application/msword") {
$errormsg = $uploads27;
}}

elseif($ext == "rtf") { 
if($type != "application/rtf") {
$errormsg = $uploads27;
}}

elseif($ext == "rtx") { 
if($type != "application/richtext") {
$errormsg = $uploads27;
}}

elseif($ext == "xls") { 
if($type != "application/x-excel") {
$errormsg = $uploads27;
}}

elseif($ext == "gz") { 
if($type != "application/x-gzip") {
$errormsg = $uploads27;
}}

elseif($ext == "js") { 
if($type != "application/x-javascript") {
$errormsg = $uploads27;
}}

elseif($ext == "pps" OR $ext == "ppt" OR $ext == "ppz") { 
if($type != "application/x-javascript") {
$errormsg = $uploads27;
}}

elseif($ext == "sit") { 
if($type != "application/x-stuffit") {
$errormsg = $uploads27;
}}

elseif($ext == "tar") { 
if($type != "application/x-tar") {
$errormsg = $uploads27;
}}

}

// CALCULATE SPACE ALLOWED
if($errormsg == "") {
$space_allowed = $group_info[uploads_space] * 1024;

// CALCULATE SPACE USED, PLUS NEW FILE
$files = mysql_fetch_assoc(mysql_query("SELECT sum(filesize) AS size FROM bhost_uploads WHERE u_id='$user_info[u_id]'"));
$space_used = $files[size]+$file_size;

// SHOW ERROR IF OUT OF SPACE, OTHERWISE DO UPLOAD
if($space_used > $space_allowed) {
$errormsg = "$uploads3";
}
}


if($errormsg == "") {

 if($name == "") { $name = "$file_name"; }

 // GET DIMENSIONS IF FILE IS IMAGE
 $dimension = @getimagesize($file_tempname);
 if($dimension[0] != "" AND $dimension[1] != "") { $dimensions = "$dimension[0]x$dimension[1]"; }

 // INSERT IMAGE INTO DATABASE
 mysql_query("INSERT INTO bhost_uploads (u_id, f_id, location, ext, filesize, name, description, dimensions) VALUES ('$user_info[u_id]', '$f_id', '$location', '$ext', '$file_size', '$name', '$description', '$dimensions')") or die(mysql_error());
 $image_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='$f_id' AND location='$location' AND filesize='$file_size' AND name='$name' AND description='$description' ORDER BY up_id DESC LIMIT 1"));

 // RENAME FILE
 $newfilename = "$image_info[up_id].$ext";
 $letter = strtolower(substr($user_info[username], 0, 1));
 $path = "../uploads/$letter/$user_info[username]/$newfilename";

 // UPLOAD FILE
 if(!move_uploaded_file($file_tempname, $path)) {
  // FILE FAILED TO UPLOAD
  mysql_query("DELETE FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='$f_id' AND location='$location' AND filesize='$file_size' AND name='$name' AND description='$description'");
  $errormsg = "$uploads20";
 } else {


  //CREATE THUMBNAILS

	// GET FILE DIMENSIONS
	$dimension = explode("x", $image_info[dimensions]);
	$width = $dimension[0];
	$height = $dimension[1];

	// MAKE THUMBNAILS
	while($width > 150 OR $height > 150) {
		$width = $width * .95;
		$height = $height * .95;
	}
	$width = (int)$width;
	$height = (int)$height;


  if(function_exists('gd_info')) {
  $thumbpath = "../uploads/$letter/$user_info[username]/$image_info[up_id]"."_thumb.$ext";
  if($ext == "gif") {
    $thumb = imagecreatetruecolor($width, $height);
    $new = imagecreatefromgif("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
     $size = getimagesize("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
     imagecopyresampled($thumb, $new, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
     imagejpeg($thumb, $thumbpath);
     ImageDestroy($new);
     ImageDestroy($thumb);
  } elseif($ext == "bmp") {
    $thumb = imagecreatetruecolor($width, $height);
    $new = imagecreatefrombmp("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
     $size = getimagesize("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
     imagecopyresampled($thumb, $new, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
     imagejpeg($thumb, $thumbpath);
     ImageDestroy($new);
     ImageDestroy($thumb);
  } elseif($ext == "jpeg" | $ext == "jpg") {
    $thumb = imagecreatetruecolor($width, $height);
    $new = imagecreatefromjpeg("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
     $size = getimagesize("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
     imagecopyresampled($thumb, $new, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
     imagejpeg($thumb, $thumbpath);
     ImageDestroy($new);
     ImageDestroy($thumb);
  } elseif($ext == "png") {
    $thumb = imagecreatetruecolor($width, $height);
    $new = imagecreatefrompng("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
     $size = getimagesize("../uploads/$letter/$user_info[username]/$image_info[up_id].$ext");
     imagecopyresampled($thumb, $new, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
     imagepng($thumb, $thumbpath);
     ImageDestroy($new);
     ImageDestroy($thumb);
  } 
  }  
  
  
  // GIVE FILE FULL PERMISSIONS
  @chmod($path, 0777);
 }
 if($f_id != 0) {
  header("Location: uploads.php?task=viewfolder&f_id=$f_id");
  exit();
 } else {
  if($location == "album") {
   if($group_info[allow_album] != "1") { header("Location: uploads.php"); exit(); }
    header("Location: uploads.php?task=viewalbum");
    exit();
  } elseif($location == "podcast") {
   if($group_info[allow_podcastfiles] != "1") { header("Location: uploads.php"); exit(); }
    header("Location: uploads.php?task=viewpodcasts");
    exit();
  } else {
   $task = "main";
  }
 }
}

if($errormsg != "") { $task = "upload"; }
}















if($task == "upload") {
 if($errormsg == "") {
  $file = "";
  $name = "";
  $description = "";
 }
$f_id = $_POST['f_id'];
$location = $_POST['location'];
if($f_id != 0) {
 $folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
 if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
 $folder_info = mysql_fetch_assoc($folder);
 if($folder_info[in_album] == "1" & $group_info[allow_album] != "1") { header("Location: uploads.php"); exit(); }
 if($folder_info[in_album] == "0" & $group_info[allow_uploads] != "1") { header("Location: uploads.php"); exit(); }
 if($folder_info[in_album] == "1") {
  $extensions = $group_info[album_extensions];
 } else {
  $extensions = $group_info[uploads_extensions];
 }
} else {
 if($location == "album") {
  if($group_info[allow_album] != "1") { header("Location: uploads.php"); exit(); }
  $extensions = $group_info[album_extensions];
 } elseif($location == "podcast") {
  if($group_info[allow_podcastfiles] != "1") { header("Location: uploads.php"); exit(); }
  $extensions = $group_info[podcast_extensions];
 } else {
  header("Location: uploads.php");
  exit();
 }
}


// GET EXTENSION LIST
$ext_list = str_replace(",", ", ", $extensions);

if($f_id != 0) {
 if($folder_info[in_album] == "1") {
  $path = "<a href='uploads.php?task=viewalbum'>$uploads21</a> &#187; <a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a>";
 } else {
  $path = "<a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a>";
 }
} else {
 if($location == "album") {
  $path = "<a href='uploads.php?task=viewalbum'>$uploads21</a>";
 } elseif($location == "podcast") {
  $path = "<a href='uploads.php?task=viewpodcasts'>$uploads22</a>";
 }
}

echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> &#187; $path &#187; $uploads23</h2>
$uploads13 <i>$ext_list</i>
$space
<br><br>
<table cellpadding='0' cellspacing='0' class='form'>
<form action='uploads.php' method='POST' onSubmit='doupload()' name='uploadform' enctype='multipart/form-data'>
<tr>
<td class='form1"; if($errormsg != "") { echo "error"; } echo "'>$uploads15&nbsp;</td>
<td class='form2'><input type='file' name='file' size='40'>&nbsp;"; show_error($errormsg); echo "</td>
</tr>
<tr>
<td class='form1'>$uploads10&nbsp;</td>
<td class='form2'><input type='text' class='text' name='name' value='$name' maxlength='30'>&nbsp;</td>
</tr>
<tr>
<td class='form1' valign='top'>$uploads17&nbsp;</td>
<td class='form2'><textarea name='description' rows='5' cols='60'>$description</textarea>&nbsp;</td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='submit' class='button' name='submit' value='$uploads16'>&nbsp;</td>
<td><input type='button' class='button' value='$uploads6' onClick='history.go(-1);'>&nbsp;&nbsp;</td>
<td><input type='text' name='status' class='upload_status' value=''></td>
</tr>
<input type='hidden' name='task' value='upload_do'>
<input type='hidden' name='f_id' value='$f_id'>
<input type='hidden' name='location' value='$location'>
<input type='hidden' name='MAX_FILE_SIZE' value='5000000'>
</form>
</table>

<script lang='JavaScript'>
<!--
function doupload() {
document.uploadform.submit.disabled = true;
document.uploadform.status.value = \"UPLOADING\";
window.setTimeout(\"doMsg1()\", 400);
}
function doMsg1() {
document.uploadform.status.value  = document.uploadform.status.value + '.';
if(document.uploadform.status.value == 'UPLOADING....') { document.uploadform.status.value = '$uploads24'; }
window.setTimeout(\"doMsg1()\", 400);
}
// -->
</script>
";

echo $foot;
exit;
}







if($task == "post_do") {
$up_id = $_POST['up_id'];

// CHECK THAT USER OWNS THIS FILE
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { exit(); }
$file_info = mysql_fetch_assoc($file);

$w_id = $_POST['w_id'];
$weblogs = mysql_query("SELECT w_id FROM bhost_weblogs WHERE w_id='$w_id' AND (u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%')");
if(mysql_num_rows($weblogs) != 1) { exit(); }
$weblog_info = mysql_fetch_assoc($weblogs);

header("Location: weblog_cookies.php?w_id=$weblog_info[w_id]&t=post&up_id=$up_id");
exit;
}










if($task == "post") {

// CHECK THAT USER OWNS THIS FILE
$up_id = $_GET['up_id'];
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { exit(); }
$file_info = mysql_fetch_assoc($file);
if($file_info[f_id] != 0) {
 $folder_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_folders WHERE u_id='$user_info[u_id]' AND f_id='$file_info[f_id]'"));
} else {
 if($file_info[location] == "podcast") { header("Location: uploads.php?task=podcast&up_id=$up_id"); exit(); }
 $folder_info[in_album] = "";
}

$weblogs = mysql_query("SELECT w_id, title FROM bhost_weblogs WHERE u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%'");
$weblogs_total = mysql_num_rows($weblogs);

// IF THE USER IS ASSOCIATED WITH 1 BLOG, POST IMMEDIATELY
if($weblogs_total == 1) { 

	$weblog_info = mysql_fetch_assoc($weblogs);
	header("Location: weblog_cookies.php?w_id=$weblog_info[w_id]&t=post&up_id=$up_id");
	exit;

// IF USER HAS IS ASSOCIATED WITH 0 BLOGS, EXIT
} elseif($weblogs_total == 0) {

	header("Location: uploads.php");
	exit;

// IF USER HAS IS ASSOCIATED WITH MORE THAN 1 BLOG, GIVE POST OPTIONS
} elseif($weblogs_total > 1) {

	echo $head;
	echo "
        <h2><a href='uploads.php'>$uploads11</a> 
        "; 
        if(($file_info[f_id] == "0" & $file_info[location] == "album") | $folder_info[in_album] == "1") { 
         echo "&#187; <a href='uploads.php?task=viewalbum'>$uploads21</a> ";
         if($folder_info[in_album] == "1") { echo "&#187; <a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a> "; }
        } else {
         echo "&#187; <a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a> ";
        }
        echo "
        &#187; $uploads25</h2>
	$uploads26
	<br><br>
	<table cellpadding='0' cellspacing='0'>
	<form action='uploads.php' method='POST'>
	";
	$c = 0;
	while($weblog = mysql_fetch_assoc($weblogs)) {
	$c++;
	echo "
	<tr><td><input type='radio' name='w_id' id='blog$c' value='$weblog[w_id]'"; if($c == 1) { echo " CHECKED"; } echo ">&nbsp;</td><td><font class='bold'><label for='blog$c'>$weblog[title]</label></font></td></tr>
	";
	}
	echo "
	</table>
	<br>
	<table cellpadding='0' cellspacing='0'>
	<tr>
	<td><input type='submit' class='button' name='submit' value='$uploads28'>&nbsp;</td>
	<input type='hidden' name='task' value='post_do'>
	<input type='hidden' name='up_id' value='$file_info[up_id]'>
	</form>
	<form action='uploads.php' method='POST'>
	<td><input type='submit' class='button' name='submit' value='$uploads6'></td>
	<input type='hidden' name='task' value='cancel'>
	<input type='hidden' name='up_id' value='$file_info[up_id]'>
	</form>
	</tr>
	</table>
	";
	echo $foot;
	exit;

}


exit;
}








if($task == "podcast_do") {
$up_id = $_POST['up_id'];
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { exit(); }
$file_info = mysql_fetch_assoc($file);

$w_id = $_POST['w_id'];
$weblogs = mysql_query("SELECT w_id FROM bhost_weblogs WHERE w_id='$w_id' AND (u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%')");
if(mysql_num_rows($weblogs) != 1) { exit(); }
$weblog_info = mysql_fetch_assoc($weblogs);

header("Location: weblog_cookies.php?w_id=$weblog_info[w_id]&t=podcast&up_id=$up_id");
exit;
}










if($task == "podcast") {

// CHECK THAT USER OWNS THIS FILE
$up_id = $_GET['up_id'];
$file = mysql_query("SELECT * FROM bhost_uploads WHERE up_id='$up_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($file) != 1) { exit(); }
$file_info = mysql_fetch_assoc($file);
if($file_info[f_id] != 0 & $file_info[location] != "podcast") { exit(); }

$weblogs = mysql_query("SELECT w_id, weblog, title FROM bhost_weblogs WHERE u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%'");
$weblogs_total = mysql_num_rows($weblogs);

// IF THE USER IS ASSOCIATED WITH 1 BLOG, POST IMMEDIATELY
if($weblogs_total == 1) { 

	$weblog_info = mysql_fetch_assoc($weblogs);
	header("Location: weblog_cookies.php?w_id=$weblog_info[w_id]&t=podcast&up_id=$up_id");
	exit;

// IF USER HAS IS ASSOCIATED WITH 0 BLOGS, EXIT
} elseif($weblogs_total == 0) {

	header("Location: uploads.php");
	exit;

// IF USER HAS IS ASSOCIATED WITH MORE THAN 1 BLOG, GIVE POST OPTIONS
} elseif($weblogs_total > 1) {

	echo $head;
	echo "
        <h2><a href='uploads.php'>$uploads11</a> &#187; <a href='uploads.php?task=viewpodcasts'>$uploads22</a> &#187; $uploads25</h2>
	$uploads29
	<br><br>
	<table cellpadding='0' cellspacing='0'>
	<form action='uploads.php' method='POST'>
	";
	$c = 0;
	while($weblog = mysql_fetch_assoc($weblogs)) {
	$c++;
	echo "
	<tr><td><input type='radio' name='w_id' id='blog$c' value='$weblog[w_id]'"; if($c == 1) { echo " CHECKED"; } echo ">&nbsp;</td><td><font class='bold'><label for='blog$c'>$weblog[weblog]</label></font></td></tr>
	";
	}
	echo "
	</table>
	<br>
	<table cellpadding='0' cellspacing='0'>
	<tr>
	<td><input type='submit' class='button' name='submit' value='$uploads30'>&nbsp;</td>
	<input type='hidden' name='task' value='podcast_do'>
	<input type='hidden' name='up_id' value='$file_info[up_id]'>
	</form>
	<form action='uploads.php' method='POST'>
	<td><input type='submit' class='button' name='submit' value='$uploads6'></td>
	<input type='hidden' name='task' value='cancel'>
	<input type='hidden' name='up_id' value='$file_info[up_id]'>
	</form>
	</tr>
	</table>
	";
	echo $foot;
	exit;

}


exit;
}









if($task == "deletefolder_do") {

if(isset($_POST['f_id'])) { $f_id = $_POST['f_id']; } else { header("Location: uploads.php"); exit(); }
$folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
$folder_info = mysql_fetch_assoc($folder);
if($group_info[allow_uploads] != 1 & $folder_info[in_album] == 0) { exit(); }
if($group_info[allow_album] != 1 & $folder_info[in_album] == 1) { exit(); }
$submit = $_POST['submit'];

if(htmlentities($submit, ENT_QUOTES) == htmlentities(html_entity_decode($uploads6, ENT_QUOTES), ENT_QUOTES)) {
 if($folder_info[in_album] == "1") {
  header("Location: uploads.php?task=viewalbum");
  exit();
 } else {
  header("Location: uploads.php");
  exit();
 }
}

$letter = strtolower(substr($user_info[username], 0, 1));
$files = mysql_query("SELECT * FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='$folder_info[f_id]'");
while($file = mysql_fetch_assoc($files)) {
  @unlink("../uploads/$letter/$user_info[username]/$file[up_id].$file[ext]");
  mysql_query("DELETE FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND up_id='$file[up_id]'");
}
mysql_query("DELETE FROM bhost_folders WHERE u_id='$user_info[u_id]' AND f_id='$folder_info[f_id]'");
if($folder_info[in_album] == "1") {
 header("Location: uploads.php?task=viewalbum");
 exit;
} else {
 header("Location: uploads.php");
 exit;
}
}










if($task == "deletefolder") {
if(isset($_GET['f_id'])) { $f_id = $_GET['f_id']; } else { header("Location: uploads.php"); exit(); }

// CHECK THAT USER OWNS THIS FOLDER
$folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
$folder_info = mysql_fetch_assoc($folder);
if($group_info[allow_uploads] != 1 & $folder_info[in_album] == 0) { exit(); }
if($group_info[allow_album] != 1 & $folder_info[in_album] == 1) { exit(); }


echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> "; if($folder_info[in_album] == "1") { echo "&#187; <a href='uploads.php?task=viewalbum'>$uploads21</a> "; } echo " &#187; $uploads31</h2>
$uploads58
<br><br>
<form action='uploads.php' method='POST'>
<input type='submit' name='submit' class='button' value='$uploads31'>
<input type='submit' name='submit' class='button' value='$uploads6'>
<input type='hidden' name='task' value='deletefolder_do'>
<input type='hidden' name='f_id' value='$folder_info[f_id]'>
</form>
";
echo $foot;
exit;
}











if($task == "modifyfolder_do") {
if(isset($_POST['f_id'])) { $f_id = $_POST['f_id']; } else { header("Location: uploads.php"); exit(); }

// CHECK THAT USER OWNS THIS FOLDER
$folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
$folder_info = mysql_fetch_assoc($folder);
if($group_info[allow_uploads] != 1 & $folder_info[in_album] == 0) { exit(); }
if($group_info[allow_album] != 1 & $folder_info[in_album] == 1) { exit(); }
$submit = $_POST['submit'];
$folder = htmlspecialchars(stripslashes($_POST['folder']), ENT_QUOTES);
$description = htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES);

if(htmlentities($submit, ENT_QUOTES) == htmlentities(html_entity_decode($uploads6, ENT_QUOTES), ENT_QUOTES)) {
 if($folder_info[in_album] == "1") {
  header("Location: uploads.php?task=viewalbum");
  exit();
 } else {
  header("Location: uploads.php");
  exit();
 }
}

if($folder == "") {
$errormsg = "$uploads32";
}

if($errormsg == "") {
mysql_query("UPDATE bhost_folders SET folder='$folder', description='$description' WHERE u_id='$user_info[u_id]' AND f_id='$folder_info[f_id]'");
 if($folder_info[in_album] == "1") {
  header("Location: uploads.php?task=viewalbum");
  exit;
 } else {
  header("Location: uploads.php");
  exit;
 }
}
$task = "modifyfolder";
}










if($task == "modifyfolder") {
if(isset($_GET['f_id'])) { $f_id = $_GET['f_id']; } elseif(isset($_POST['f_id'])) { $f_id = $_POST['f_id']; } else { header("Location: uploads.php"); exit(); }
$folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
$folder_info = mysql_fetch_assoc($folder);
if($group_info[allow_uploads] != 1 & $folder_info[in_album] == 0) { exit(); }
if($group_info[allow_album] != 1 & $folder_info[in_album] == 1) { exit(); }


echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> "; if($folder_info[in_album] == "1") { echo "&#187; <a href='uploads.php?task=viewalbum'>$uploads21</a> "; } echo "&#187; $uploads33</h2>
$uploads34
<br><br>
<table cellpadding='0' cellspacing='0' class='form'>
<form action='uploads.php' method='POST'>
<tr>
<td class='form1'>$uploads35</td>
<td class='form2'><input type='text' class='text' name='folder' value='$folder_info[folder]' size='25' maxlength='40'>"; show_error($errormsg); echo "</td>
</tr>
<tr>
<td class='form1' valign='top'>$uploads17</td>
<td class='form2'><textarea name='description' rows='4' cols='60'>$folder_info[description]</textarea></td>
</tr>
</table>
<br>
<input type='submit' name='submit' class='button' value='$uploads33'>
<input type='submit' name='submit' class='button' value='$uploads6'>
<input type='hidden' name='task' value='modifyfolder_do'>
<input type='hidden' name='f_id' value='$folder_info[f_id]'>
</form>
";
echo $foot;
exit;
}










// DO CREATE FOLDER
if($task == "createfolder_do") {
$submit = $_POST['submit'];
$folder = htmlspecialchars(stripslashes($_POST['folder']), ENT_QUOTES);
$description = htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES);
$in_album = $_POST['in_album'];
if($in_album != "1" & $in_album != "0") { $in_album = 0; }

 if($in_album == "1" & mysql_num_rows(mysql_query("SELECT f_id FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='$in_album'")) >= 20) {
  header("Location: uploads.php?task=viewalbum");
  exit();
 } elseif($in_album == "0" & mysql_num_rows(mysql_query("SELECT f_id FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='$in_album'")) >= 20) {
  header("Location: uploads.php");
  exit();
 }

if(htmlentities($submit, ENT_QUOTES) == htmlentities(html_entity_decode($uploads6, ENT_QUOTES), ENT_QUOTES)) {
 if($in_album == "1") {
  header("Location: uploads.php?task=viewalbum");
  exit();
 } else {
  header("Location: uploads.php");
  exit();
 }
}

if($folder == "") {
$errormsg = "$uploads32";
}

if($errormsg == "") {
mysql_query("INSERT INTO bhost_folders (u_id, in_album, folder, description) VALUES ('$user_info[u_id]', '$in_album', '$folder', '$description')");
 if($in_album == "1") {
  header("Location: uploads.php?task=viewalbum");
  exit;
 } else {
  header("Location: uploads.php");
  exit;
 }
}
$task = "createfolder";
}









// CREATE FOLDER
if($task == "createfolder") {
if(isset($_POST['in_album'])) { $in_album = $_POST['in_album']; } else { $in_album = 0; }

if($in_album == 1) { $path = "&#187; <a href='uploads.php?task=viewalbum'>$uploads21</a>"; }

echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> $path &#187; $uploads36</h2>
";

if($in_album == "1" & mysql_num_rows(mysql_query("SELECT f_id FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='$in_album'")) >= 20) {
 echo "
  $uploads37<br><br>
  <form action='uploads.php' method='POST'>
  <input type='submit' name='submit' value='$uploads38' class='button'>
  <input type='hidden' name='task' value='viewalbum'>
  </form>
 ";
 echo $foot;
 exit();
 } elseif($in_album == "0" & mysql_num_rows(mysql_query("SELECT f_id FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='$in_album'")) >= 20) {
 echo "
  $uploads37<br><br>
  <form action='uploads.php' method='POST'>
  <input type='submit' name='submit' value='$uploads38' class='button'>
  <input type='hidden' name='task' value='main'>
  </form>
 ";
 echo $foot;
 exit();
 }


echo "
$uploads39
<br><br>
<table cellpadding='0' cellspacing='0' class='form'>
<form action='uploads.php' method='POST'>
<tr>
<td class='form1'>$uploads35</td>
<td class='form2'><input type='text' class='text' name='folder' size='25' maxlength='40'>"; show_error($errormsg); echo "</td>
</tr>
<tr>
<td class='form1' valign='top'>$uploads17</td>
<td class='form2'><textarea name='description' rows='4' cols='60'></textarea></td>
</tr>
</table>
<br>
<input type='submit' name='submit' class='button' value='$uploads36'>
<input type='submit' name='submit' class='button' value='$uploads6'>
<input type='hidden' name='task' value='createfolder_do'>
<input type='hidden' name='in_album' value='$in_album'>
</form>
";
echo $foot;
exit;
}











if($task == "viewfolder") {
if($group_info[allow_uploads] != 1) { exit(); }
if(isset($_GET['f_id'])) { $f_id = $_GET['f_id']; } else { header("Location: uploads.php"); exit(); }
$folder = mysql_query("SELECT * FROM bhost_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'");
if(mysql_num_rows($folder) != 1) { header("Location: uploads.php"); exit(); }
$folder_info = mysql_fetch_assoc($folder);

$total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='$folder_info[f_id]'"));

if(($total_files % $files_per_page) != 0) {
 $maxpage = ($total_files) / $files_per_page + 1;
} else {
 $maxpage = ($total_files) / $files_per_page;
}
$maxpage = (int) $maxpage;
if($page > $maxpage) { $page = $maxpage; } elseif($page < 1) { $page = 1; }
$start = ($page - 1) * $files_per_page;

if($page - 1 > 0 & $maxpage != 1) {  
 $prev = $page - 1;  
 $pp = "<a href='uploads.php?task=viewfolder&page=$prev&f_id=$f_id'>$uploads45</a>";  
} else {
 $pp = "<font class='gray'>$uploads45</font>";  
}
if($page + 1 <= $maxpage & $maxpage != 1) {  
 $next = $page + 1;  
 $np = "<a href='uploads.php?task=viewfolder&page=$next&f_id=$f_id'>$uploads46</a>";  
} else {
 $np = "<font class='gray'>$uploads46</font>";  
}



$files = mysql_query("SELECT * FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='$folder_info[f_id]' ORDER BY up_id DESC LIMIT $start, $files_per_page");


if($total_files != 0 & $maxpage != 1) {
 $begin = $start+1;
 $end = $start+$files_per_page;
 if($end > $total_files) { $end = $total_files; }
 if($begin == $end) { $listing_files = "$uploads44 $begin $uploads47 $total_files."; } else { $listing_files = "$uploads43 $begin-$end $uploads47 $total_files."; }
 $pages = "<br>$listing_files <font class='gray'>[</font> $pp <font class='gray'>]</font> <font class='gray'>[</font> $np <font class='gray'>]</font><br>";
}



echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> "; if($folder_info[in_album] == "1") { echo "&#187; <a href='uploads.php?task=viewalbum'>$uploads21</a> "; } echo "&#187; $folder_info[folder]</h2>
$uploads40
$space
<br><br>

<table cellpadding='0' cellspacing='0'>
<form action='uploads.php' method='POST'>
<tr>
<td><input type='submit' class='button' name='submit' value='"; if($folder_info[in_album] == "1") { echo "$uploads41"; } else { echo "$uploads42"; } echo "'></td>
<input type='hidden' name='task' value='upload'>
<input type='hidden' name='f_id' value='$f_id'>
<input type='hidden' name='location' value='folder'>
</form>
</tr>
</table>

$pages

<br>

<table cellpadding='0' cellspacing='0' class='files'>
";

while($file = mysql_fetch_assoc($files)) {
$letter = strtolower(substr($user_info[username], 0, 1));
$fileurl = "../uploads/$letter/$user_info[username]/$file[up_id].$file[ext]";
$size = round($file[filesize]/1024, 2);
switch($file[ext]) {
 case "jpg":
 case "jpeg":
 case "png":
 case "gif":
 case "bmp":
  if(file_exists("../uploads/$letter/$user_info[username]/$file[up_id]"."_thumb.$file[ext]")) {
   $thumburl = "../uploads/$letter/$user_info[username]/$file[up_id]"."_thumb.$file[ext]";
  } else {
   $thumburl = $fileurl;
  }
  $thumbtype = "pic";
  break;
 case "mp3":
 case "au":
 case "wav":
 case "ram":
 case "rm":
 case "wma":
 case "ogg":
 case "midi":
 case "aif":
 case "aifc":
 case "aiff":
 case "mid":
  $thumburl = "../images/icon_audio.gif";
  break;
 default:
  $thumburl = "../images/icon_file.gif";
  break;
}
 

if($file[description] == "") { $file[description] .= "<br>"; }


// IF USER HAS ANY BLOG ASSOCIATIONS SHOW POST POTION
$weblogs = mysql_query("SELECT w_id, title FROM bhost_weblogs WHERE u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%'");
if(mysql_num_rows($weblogs) != 0) {
$post = "<a href='uploads.php?task=post&up_id=$file[up_id]'>$uploads48</a> <font class='gray'>|</font>";
}

echo "
<tr>
<td class='file'>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td class='file1' width='60' height='60' align='center'><a href='$fileurl' target='_blank'><img src='$thumburl'"; if($thumbtype == "pic") { echo "width='60' height='60'"; } echo " border='0'></a></td>
  <td class='file1'>
  <font class='bold'><a href='$fileurl' target='_blank'>$file[name]</a></font> ($size Kb)
  <br>$file[description]
  <div class='fileoptions'>$post <a href='uploads.php?task=modify&up_id=$file[up_id]'>$uploads50</a> <font class='gray'>|</font> <a href='uploads.php?task=delete&up_id=$file[up_id]'>$uploads49</a></div>
  </td>
  </tr>
  </table>
</td>
</tr>
";
}

echo "
</table>
";



echo "$pages";

if(mysql_num_rows($files) == 0) {
echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td class='empty' colspan='4'>
$uploads51
</td>
</tr>
</table>
";
}

echo $foot;
exit;
}















// VIEW PHOTO ALBUM
if($task == "viewalbum") {
if($group_info[allow_album] != 1) { exit; }

$total_folders = mysql_num_rows(mysql_query("SELECT f_id FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='1'"));
$total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='0' AND location='album'"));
$total_objects = $total_files+$total_folders;

if(($total_objects % $files_per_page) != 0) {
 $maxpage = ($total_objects) / $files_per_page + 1;
} else {
 $maxpage = ($total_objects) / $files_per_page;
}
$maxpage = (int) $maxpage;
if($page > $maxpage) { $page = $maxpage; } elseif($page < 1) { $page = 1; }
$start = ($page - 1) * $files_per_page;

if($page - 1 > 0 & $maxpage != 1) {  
 $prev = $page - 1;  
 $pp = "<a href='uploads.php?task=viewalbum&page=$prev'>$uploads45</a>";  
} else {
 $pp = "<font class='gray'>$uploads45</font>";  
}
if($page + 1 <= $maxpage & $maxpage != 1) {  
 $next = $page + 1;  
 $np = "<a href='uploads.php?task=viewalbum&page=$next'>$uploads46</a>";  
} else {
 $np = "<font class='gray'>$uploads46</font>";  
}


if($total_folders < $start) {
 $folders_start = 0;
 $folders_end = 0;
 $files_start = $start-$total_folders;
 $files_end = $start-$total_folders+$files_per_page;
} elseif($total_folders < $start+$files_per_page) {
 $folders_start = $start;
 $folders_end = $total_folders-$start;
 $files_start = 0;
 $files_end = $files_per_page-($total_folders-$start-$start);
} else {
 $folders_start = $start;
 $folders_end = $files_per_page;
 $files_start = 0;
 $files_end = 0;
}
$folders = mysql_query("SELECT * FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='1' ORDER BY folder LIMIT $folders_start, $folders_end");
$files = mysql_query("SELECT * FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='0' AND location='album' ORDER BY up_id DESC LIMIT $files_start, $files_end");


$album_url = url("album", "", "$user_info[username]");

echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> &#187; $uploads21 <font class='url'>( <a href='$album_url' target='_blank'>$album_url</a> )</font></h2>
$uploads52
$space
<br><br>

<table cellpadding='0' cellspacing='0'>
<tr>
<form action='uploads.php' method='POST'>
<td><input type='submit' class='button' name='submit' value='$uploads36'>&nbsp;</td>
<input type='hidden' name='task' value='createfolder'>
<input type='hidden' name='in_album' value='1'>
</form>
<form action='uploads.php' method='POST'>
<td><input type='submit' class='button' name='submit' value='$uploads41'>&nbsp;</td>
<input type='hidden' name='task' value='upload'>
<input type='hidden' name='f_id' value='0'>
<input type='hidden' name='location' value='album'>
</form>
<form action='../album.php' method='GET' target='_blank'>
<td><input type='submit' class='button' name='submit' value='$uploads59'></td>
<input type='hidden' name='u' value='$user_info[username]'>
</form>
</tr>
</table>
";


// LIST PAGES
$pages = "";
if($total_objects != 0 & $maxpage != 1) {
 $begin = $start+1;
 $end = $start+$files_per_page;
 if($end > $total_objects) { $end = $total_objects; }
 if($begin == $end) { $listing_files = "$uploads44 $begin $uploads47 $total_objects"; } else { $listing_files = "$uploads43 $begin-$end $uploads47 $total_objects"; }
 $pages = "<br>$listing_files <font class='gray'>[</font> $pp <font class='gray'>]</font> <font class='gray'>[</font> $np <font class='gray'>]</font><br>";
}
echo $pages;


// LIST FOLDERS
if(mysql_num_rows($folders) != 0) {
echo "<br><table cellpadding='0' cellspacing='0' class='files'>";
while($folder_info = mysql_fetch_assoc($folders)) {
 $total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE f_id='$folder_info[f_id]' AND location='folder' AND u_id='$user_info[u_id]'"));
 echo "
 <tr>
 <td class='file'>
   <table cellpadding='0' cellspacing='0'>
   <tr>
   <td class='file1' width='60' height='60' align='center'><a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'><img src='../images/folder_files.gif' border='0'></a></td>
   <td class='file1'>
   <font class='bold'><a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a></font> ($total_files image"; if($total_files != "1") { echo "s"; } echo ")<br>
   $folder_info[description]<br>
   <a href='uploads.php?task=modifyfolder&f_id=$folder_info[f_id]'>$uploads50</a> <font class='gray'>|</font> <a href='uploads.php?task=deletefolder&f_id=$folder_info[f_id]'>$uploads49</a>
   </td>
   </tr>
   </table>
 </td>
 </tr>
 ";
}
echo "</table>";
}

// LIST FILES
if(mysql_num_rows($files) != 0) {
echo "<br><table cellpadding='0' cellspacing='0' class='files'>";
while($file = mysql_fetch_assoc($files)) {
$letter = strtolower(substr($user_info[username], 0, 1));
$fileurl = "../uploads/$letter/$user_info[username]/$file[up_id].$file[ext]";
$size = round($file[filesize]/1024, 2);
switch($file[ext]) {
 case "jpg":
 case "jpeg":
 case "png":
 case "gif":
 case "bmp":
  if(file_exists("../uploads/$letter/$user_info[username]/$file[up_id]"."_thumb.$file[ext]")) {
   $thumburl = "../uploads/$letter/$user_info[username]/$file[up_id]"."_thumb.$file[ext]";
  } else {
   $thumburl = $fileurl;
  }
  $thumbtype = "pic";
  break;
 case "mp3":
 case "au":
 case "wav":
 case "ram":
 case "rm":
 case "wma":
 case "ogg":
 case "midi":
 case "aif":
 case "aifc":
 case "aiff":
 case "mid":
  $thumburl = "../images/icon_audio.gif";
  break;
 default:
  $thumburl = "../images/icon_file.gif";
  break;
}

// IF USER HAS ANY BLOG ASSOCIATIONS SHOW POST OPTION
$weblogs = mysql_query("SELECT w_id, title FROM bhost_weblogs WHERE u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%'");
if(mysql_num_rows($weblogs) != 0) {
$post = "<a href='uploads.php?task=post&up_id=$file[up_id]'>$uploads48</a> <font class='gray'>|</font>";
}

if($file[description] == "") { $file[description] .= "<br>"; }
echo "
<tr>
<td class='file'>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td class='file1' valign='top'><a href='$fileurl' target='_blank'><img src='$thumburl'"; if($thumbtype == "pic") { echo " width='60' height='60'"; } echo " class='thumb' border='0'></a></td>
  <td class='file1'>
  <font class='bold'><a href='$fileurl' target='_blank'>$file[name]</a></font> ($size Kb)
  <br>$file[description]
  <div class='fileoptions'>$post <a href='uploads.php?task=modify&up_id=$file[up_id]'>$uploads50</a> <font class='gray'>|</font> <a href='uploads.php?task=delete&up_id=$file[up_id]'>$uploads49</a></div>
  </td>
  </tr>
  </table>
</td>
</tr>
";
}}

echo "
</table>

$pages
";

if($total_objects == 0) {
echo "
<br>
<table cellpadding='0' cellspacing='0'>
<tr><td class='empty'>$uploads53</td></tr>
</table>
";
}

echo $foot;
exit;
}














if($task == "viewpodcasts") {
if($group_info[allow_podcastfiles] != 1) { exit; }

$total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='0' AND location='podcast'"));

if(($total_files % $files_per_page) != 0) {
 $maxpage = ($total_files) / $files_per_page + 1;
} else {
 $maxpage = ($total_files) / $files_per_page;
}
$maxpage = (int) $maxpage;
if($page > $maxpage) { $page = $maxpage; } elseif($page < 1) { $page = 1; }
$start = ($page - 1) * $files_per_page;

if($page - 1 > 0 & $maxpage != 1) {  
 $prev = $page - 1;  
 $pp = "<a href='uploads.php?task=viewpodcasts&page=$prev'>$uploads45</a>";  
} else {
 $pp = "<font class='gray'>$uploads45</font>";  
}
if($page + 1 <= $maxpage & $maxpage != 1) {  
 $next = $page + 1;  
 $np = "<a href='uploads.php?task=viewpodcasts&page=$next'>$uploads46</a>";  
} else {
 $np = "<font class='gray'>$uploads46</font>";  
}



$files = mysql_query("SELECT * FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND f_id='0' AND location='podcast' ORDER BY up_id DESC LIMIT $start, $files_per_page");


echo $head;
echo "
<h2><a href='uploads.php'>$uploads11</a> &#187; $uploads22</h2>
$uploads54
$space
<br><br>

<table cellpadding='0' cellspacing='0'>
<form action='uploads.php' method='POST'>
<tr>
<td>
<input type='submit' class='button' name='submit' value='$uploads42'>
<input type='hidden' name='task' value='upload'>
<input type='hidden' name='f_id' value='0'>
<input type='hidden' name='location' value='podcast'>
</td>
</tr>
</form>
</table>
";

if($total_files != 0 & $maxpage != 1) {
 $begin = $start+1;
 $end = $start+$files_per_page;
 if($end > $total_files) { $end = $total_files; }
 if($begin == $end) { $listing_files = "$uploads44 $begin $uploads47 $total_files"; } else { $listing_files = "$uploads43 $begin-$end $uploads47 $total_files"; }
 $pages = "<br>$listing_files <font class='gray'>[</font> $pp <font class='gray'>]</font> <font class='gray'>[</font> $np <font class='gray'>]</font><br>";
}

echo "
$pages

<br>

<table cellpadding='0' cellspacing='0' class='files'>
";

while($file = mysql_fetch_assoc($files)) {
$letter = strtolower(substr($user_info[username], 0, 1));
$fileurl = "../uploads/$letter/$user_info[username]/$file[up_id].$file[ext]";
$size = round($file[filesize]/1024, 2);
switch($file[ext]) {
 case "jpg":
 case "jpeg":
 case "png":
 case "gif":
 case "bmp":
  if(file_exists("../uploads/$letter/$user_info[username]/$file[up_id]"."_thumb.$file[ext]")) {
   $thumburl = "../uploads/$letter/$user_info[username]/$file[up_id]"."_thumb.$file[ext]";
  } else {
   $thumburl = $fileurl;
  }
  $thumbtype = "pic";
  break;
 case "mp3":
 case "au":
 case "wav":
 case "ram":
 case "rm":
 case "wma":
 case "ogg":
 case "midi":
 case "aif":
 case "aifc":
 case "aiff":
 case "mid":
  $thumburl = "../images/icon_audio.gif";
  break;
 default:
  $thumburl = "../images/icon_file.gif";
  break;
}

if($file[description] == "") { $file[description] .= "<br>"; }

// IF USER HAS ANY BLOG ASSOCIATIONS SHOW PODCAST POTION
$weblogs = mysql_query("SELECT w_id, title FROM bhost_weblogs WHERE u_id='$user_info[u_id]' OR level1 LIKE '%,$user_info[u_id],%' OR level2 LIKE '%,$user_info[u_id],%'");
if(mysql_num_rows($weblogs) != 0) {
$pod = "<a href='uploads.php?task=podcast&up_id=$file[up_id]'>$uploads55</a> <font class='gray'>|</font> ";
}

echo "
<tr>
<td class='file'>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td class='file1' align='center'><a href='$fileurl' target='_blank'><img src='$thumburl' border='0'"; if($thumbtype == "pic") { echo " width='60' height='60'"; } echo "></a></td>
  <td class='file1'>
  <font class='bold'><a href='$fileurl' target='_blank'>$file[name]</a></font> ($size Kb)
  <br>$file[description]
  <br>$pod<a href='uploads.php?task=modify&up_id=$file[up_id]'>$uploads50</a> <font class='gray'>|</font> <a href='uploads.php?task=delete&up_id=$file[up_id]'>$uploads49</a>
  </td>
  </tr>
  </table>
</td>
</tr>
";
}

echo "
</table>

$pages
";

if(mysql_num_rows($files) == 0) {
echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td class='empty' colspan='4'>
$uploads51
</td>
</tr>
</table>
";
}

echo $foot;
exit;
}

















if($task == "main") {
echo $head;
echo "
<h2>$uploads11</h2>
$uploads12
$space

<br><br>

<table cellpadding='0' cellspacing='0' class='files'>
";

if($group_info[allow_album] == 1) {
 $album_folders = mysql_query("SELECT f_id, in_album FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='1'");
 $where = "";
 while($folder_info = mysql_fetch_assoc($album_folders)) {
  $where .= " OR f_id='$folder_info[f_id]'";
 }
$total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE u_id='$user_info[u_id]' AND ((f_id='0' AND location='album')$where)"));
echo "
<tr>
<td class='file'>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td class='file1'><a href='uploads.php?task=viewalbum'><img src='../images/folder_album.gif' border='0'></a></td>
  <td class='file1'>
  <font class='bold'><a href='uploads.php?task=viewalbum'>$uploads21</a></font> ($total_files images)<br>
  $uploads56
  </td>
  </tr>
  </table>
</td>
</tr>
";
}

if($group_info[allow_podcastfiles] == 1) {
$total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE f_id='0' AND location='podcast' AND u_id='$user_info[u_id]'"));
echo "
<tr>
<td class='file'>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td class='file1'><a href='uploads.php?task=viewpodcasts'><img src='../images/folder_sound.gif' border='0'></a></td>
  <td class='file1'>
  <font class='bold'><a href='uploads.php?task=viewpodcasts'>$uploads22</a></font> ($total_files files)<br>
  $uploads57
  </td>
  </tr>
  </table>
</td>
</tr>
";
}

if($group_info[allow_uploads] == 1) {
 $folders = mysql_query("SELECT * FROM bhost_folders WHERE u_id='$user_info[u_id]' AND in_album='0' ORDER BY folder");
 while($folder_info = mysql_fetch_assoc($folders)) {
  $total_files = mysql_num_rows(mysql_query("SELECT up_id FROM bhost_uploads WHERE f_id='$folder_info[f_id]' AND location='folder' AND u_id='$user_info[u_id]'"));
  echo "
  <tr>
  <td class='file'>
    <table cellpadding='0' cellspacing='0'>
    <tr>
    <td class='file1'><a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'><img src='../images/folder_files.gif' border='0'></a></td>
    <td class='file1'>
    <font class='bold'><a href='uploads.php?task=viewfolder&f_id=$folder_info[f_id]'>$folder_info[folder]</a></font> ($total_files file"; if($total_files != "1") { echo "s"; } echo ")<br>
    $folder_info[description]<br>
    <a href='uploads.php?task=modifyfolder&f_id=$folder_info[f_id]'>$uploads50</a> <font class='gray'>|</font> <a href='uploads.php?task=deletefolder&f_id=$folder_info[f_id]'>$uploads49</a>
    </td>
    </tr>
    </table>
  </td>
  </tr>
  ";
 }
}

echo "
<form action='uploads.php' method='POST'>
</table>

<br>

<input type='submit' class='button' name='submit' value='$uploads36'>
<input type='hidden' name='task' value='createfolder'>
<input type='hidden' name='in_album' value='0'>
</form>
";

echo $foot;
}

?>