<?
include "mysqlcon.php";
include "header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "upload"; }
if(isset($_POST['f_id'])) { $f_id = $_POST['f_id']; } elseif(isset($_GET['f_id'])) { $f_id = $_GET['f_id']; } else { exit(); }
if(isset($_POST['page'])) { $page = $_POST['page']; } elseif(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; }

$getfolders = mysql_query("SELECT * FROM ims_folders WHERE u_id='$user_info[u_id]' AND f_id='$f_id'");
if(mysql_num_rows($getfolders) == 0) { exit(); }
$folder_info = mysql_fetch_assoc($getfolders);

if($task == "upload_do") {
$title1 = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST[title1])));
  $checkforblank = str_replace(" ", "", $title1);
  if($checkforblank == "") { $title1 = $_FILES['file1']['name']; }
$title2 = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST[title2])));
  $checkforblank = str_replace(" ", "", $title2);
  if($checkforblank == "") { $title2 = $_FILES['file2']['name']; }
$title3 = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST[title3])));
  $checkforblank = str_replace(" ", "", $title3);
  if($checkforblank == "") { $title3 = $_FILES['file3']['name']; }

$descr1 = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST['descr1'])));
$descr2 = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST['descr2'])));
$descr3 = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST['descr3'])));

$ext1 = str_replace(".", "", strtolower(strrchr($_FILES['file1']['name'], ".")));
$ext2 = str_replace(".", "", strtolower(strrchr($_FILES['file2']['name'], ".")));
$ext3 = str_replace(".", "", strtolower(strrchr($_FILES['file3']['name'], ".")));

$allowed_exts = explode(",", $user_info[ext_list]);
$ext_list_spaced = str_replace(",", ", ", $user_info[ext_list]);
$badfiles = "";
$badfilescount = $badfilescount + 0;

if($_FILES['file1']['name'] == "") { $file1 = "none"; } else { $file1 = "good"; }
if($_FILES['file2']['name'] == "") { $file2 = "none"; } else { $file2 = "good"; }
if($_FILES['file3']['name'] == "") { $file3 = "none"; } else { $file3 = "good"; }

if($file1 != "none" OR $file2 != "none" OR $file3 != "none") {
$file1_image_type = "good";
$file2_image_type = "good";
$file3_image_type = "good";

$allowed_types = array();
$s = 0;
for($i=0;$i<count($allowed_exts);$i++) {
if($allowed_exts[$i] == "jpeg" | $allowed_exts[$i] == "jpg") {
$allowed_types[$s] = "pjpeg";
$s = $s + 1;
$allowed_types[$s] = "jpeg";
$s = $s + 1;
} elseif($allowed_exts[$i] == "png") {
$allowed_types[$s] = "x-png";
$s = $s + 1;
}
$allowed_types[$s] = $allowed_exts[$i];
$s = $s + 1;
}

if($file1 != "none") {
$file1_image_type = "bad";
for($i=0;$i<count($allowed_types);$i++) {
if($_FILES['file1']['type'] == "image/$allowed_types[$i]" | $_FILES['file1']['type'] == "application/$allowed_types[$i]") {
$file1_image_type = "good";
}}}

if($file2 != "none") {
$file2_image_type = "bad";
for($i=0;$i<count($allowed_types);$i++) {
if($_FILES['file2']['type'] == "image/$allowed_types[$i]" | $_FILES['file2']['type'] == "application/$allowed_types[$i]") {
$file2_image_type = "good";
}}}

if($file3 != "none") {
$file3_image_type = "bad";
for($i=0;$i<count($allowed_types);$i++) {
if($_FILES['file3']['type'] == "image/$allowed_types[$i]" | $_FILES['file3']['type'] == "application/$allowed_types[$i]") {
$file3_image_type = "good";

}}}

// FILENAME MAXLENGTH
   if($file1 != "none" AND strlen($title1) > 40) {
   $badfiletrue = "yes";
   $badfile1 = "yes";
   $longname1 = "yes";
   $reasons1 = "filename exceeds maxlength";
   }

   if($file2 != "none" AND strlen($title2) > 40) {
   $badfiletrue = "yes";
   $badfile2 = "yes";
   $longname2 = "yes";
   $reasons2 = "filename exceeds maxlength";
   }

   if($file3 != "none" AND strlen($title3) > 40) {
   $badfiletrue = "yes";
   $badfile3 = "yes";
   $longname3 = "yes";
   $reasons3 = "filename exceeds maxlength";
   }

// INVALID FORMATS
   if($file1 != "none" AND (!in_array($ext1, $allowed_exts) OR $file1_image_type != "good")) {
   $badfiletrue = "yes";
   $wrongformat1 = "yes";
   $badfile1 = "yes";
   $reasons1 = "invalid format";
   }

   if($file2 != "none" AND (!in_array($ext2, $allowed_exts) OR $file2_image_type != "good")) {
   $badfiletrue = "yes";
   $wrongformat2 = "yes";
   $badfile2 = "yes";
   $reasons2 = "invalid format";
   }

   if($file3 != "none" AND (!in_array($ext3, $allowed_exts) OR $file3_image_type != "good")) {
   $badfiletrue = "yes";
   $wrongformat3 = "yes";
   $badfile3 = "yes";
   $reasons3 = "invalid format";
   }

// FILES NOT SUBMITTED
   if($file1 == "none") { $badfile1 = "yes"; }
   if($file2 == "none") { $badfile2 = "yes"; }
   if($file3 == "none") { $badfile3 = "yes"; }

// FILES EXCEED THE MAX FILE SIZE
   if($file1 != "none") {
   $size = $_FILES['file1']['size'] / 1024;
   $size = round($size, 0);
   if($size > $user_info[max_filesize]) {
   $badfiletrue = "yes";
   $exceedmax1 = "yes";
   $badfile1 = "yes";
   if(isset($reasons1)) {$reasons1 .= ", "; }
   $reasons1 .= "file size too large";
   }}

   if($file2 != "none") {
   $size = $_FILES['file2']['size'] / 1024;
   $size = round($size, 0);
   if($size > $user_info[max_filesize]) {
   $badfiletrue = "yes";
   $exceedmax2 = "yes";
   $badfile2 = "yes";
   if(isset($reasons2)) {$reasons2 .= ", "; }
   $reasons2 .= "file size too large";
   }}

   if($file3 != "none") {
   $size = $_FILES['file3']['size'] / 1024;
   $size = round($size, 0);
   if($size > $user_info[max_filesize]) {
   $badfiletrue = "yes";
   $exceedmax3 = "yes";
   $badfile3 = "yes";
   if(isset($reasons3)) {$reasons3 .= ", "; }
   $reasons3 .= "file size too large";
   }}

// UPLOAD FILES, UNLESS THEY ARE TOO BIG OR DESTINATION FOLDERS HAVE TOO MANY FILES
$images_inside = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE f_id='$f_id' AND u_id='$user_info[u_id]'"));

        if($file1 != "none") {
        $space_used = mysql_fetch_assoc(mysql_query("SELECT sum(size) AS size FROM ims_image WHERE u_id='$user_info[u_id]'"));
        if($space_used[size] == NULL) { $space_used[size] = 0; }
        $space_avail = $user_info[space_avail] * (1024 * 1024);
        $space_left = (int)$space_avail - (int)$space_used[size];
        if($_FILES['file1']['size'] >= $space_left) {
        $badfiletrue = "yes";
        $toobig1 = "yes";
        $badfile1 = "yes";
        if(isset($reasons1)) {$reasons1 .= ", "; }
        $reasons1 .= "insufficient space available";
        }
        if($images_inside == 100) {
        $badfiletrue = "yes";
        $filelim1 = "yes";
        $badfile1 = "yes";
        if(isset($reasons1)) {$reasons1 .= ", "; }
        $reasons1 .= "destination folder already contains maximum allowed images (100)";
        }}

   if($badfile1 != "yes") {
   $file1_tmp_name = $_FILES['file1']['tmp_name'];
   $file1_name = $_FILES['file1']['name'];
   $file1_size = $_FILES['file1']['size'];

   mysql_query("INSERT INTO ims_image (u_id, f_id, title, description, ext, size) VALUES ('$user_info[u_id]', '$f_id', '$title1', '$descr1', '$ext1', '$file1_size')");
   $i_id = mysql_fetch_assoc(mysql_query("SELECT max(i_id) AS i_id FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id' AND title='$title1' AND description='$descr1' AND ext='$ext1' AND size='$file1_size' AND views=''"));
   $image_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_image WHERE i_id='$i_id[i_id]'"));

   if(move_uploaded_file($file1_tmp_name, "./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext])) {
    $thumb_sql = "$image_info[i_id].$image_info[ext]";
  if($ext1 == "gif") {
    copy("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext], "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
  } elseif($ext1 == "bmp") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefrombmp("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagejpeg($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);

      $newimage = imagecreatetruecolor($size[0], $size[1]);
      $oldimage = imagecreatefrombmp("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
      imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $size[0], $size[1], $size[0], $size[1]);
      imagejpeg($newimage, "./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
      ImageDestroy($newimage);
      ImageDestroy($oldimage);

  } elseif($ext1 == "jpeg" | $ext1 == "jpg") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefromjpeg("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagejpeg($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);
  } elseif($ext1 == "png") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefrompng("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagepng($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);
  } else {
    $thumb_sql = "none";
  }
    mysql_query("UPDATE ims_image SET thumb='$thumb_sql' WHERE i_id='$image_info[i_id]'");
   } else {
    mysql_query("DELETE * FROM ims_image WHERE i_id='$image_info[i_id]'");
   }

   $filepassed1 = "yes";
   $images_inside = $images_inside + 1;
   }


        if($file2 != "none") {
        $space_used = mysql_fetch_assoc(mysql_query("SELECT sum(size) AS size FROM ims_image WHERE u_id='$user_info[u_id]'"));
        if($space_used[size] == NULL) { $space_used[size] = 0; }
        $space_avail = $user_info[space_avail] * (1024 * 1024);
        $space_left = $space_avail - $space_used[size];
        if($_FILES['file2']['size'] >= $space_left) {
        $badfiletrue = "yes";
        $toobig2 = "yes";
        $badfile2 = "yes";
        if(isset($reasons2)) {$reasons2 .= ", "; }
        $reasons2 .= "insufficient space available";
        }
        if($images_inside == 100) {
        $badfiletrue = "yes";
        $filelim2 = "yes";
        $badfile2 = "yes";
        if(isset($reasons2)) {$reasons2 .= ", "; }
        $reasons2 .= "destination folder already contains maximum allowed images (100)";
        }}

   if($badfile2 != "yes") {
   $file2_tmp_name = $_FILES['file2']['tmp_name'];
   $file2_name = $_FILES['file2']['name'];
   $file2_size = $_FILES['file2']['size'];

   mysql_query("INSERT INTO ims_image (u_id, f_id, title, description, ext, size) VALUES ('$user_info[u_id]', '$f_id', '$title2', '$descr2', '$ext2', '$file2_size')");
   $i_id = mysql_fetch_assoc(mysql_query("SELECT max(i_id) AS i_id FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id' AND title='$title2' AND description='$descr2' AND ext='$ext2' AND size='$file2_size' AND views=''"));
   $image_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_image WHERE i_id='$i_id[i_id]'"));

   if(move_uploaded_file($file2_tmp_name, "./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext])) {
    $thumb_sql = "$image_info[i_id].$image_info[ext]";
    if($ext2 == "gif") {
    copy("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext], "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
  } elseif($ext2 == "bmp") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefrombmp("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagejpeg($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);

      $newimage = imagecreatetruecolor($size[0], $size[1]);
      $oldimage = imagecreatefrombmp("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
      imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $size[0], $size[1], $size[0], $size[1]);
      imagejpeg($newimage, "./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
      ImageDestroy($newimage);
      ImageDestroy($oldimage);

    } elseif($ext2 == "jpeg" | $ext2 == "jpg") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefromjpeg("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagejpeg($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);
    } elseif($ext2 == "png") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefrompng("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
         for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagepng($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);
    } else {
    $thumb_sql = "none";
    }
    mysql_query("UPDATE ims_image SET thumb='$thumb_sql' WHERE i_id='$image_info[i_id]'");
   } else {
    mysql_query("DELETE * FROM ims_image WHERE i_id='$image_info[i_id]'");
   }

   $filepassed2 = "yes";
   $images_inside = $images_inside + 1;
   }


        if($file3 != "none") {
        $space_used = mysql_fetch_assoc(mysql_query("SELECT sum(size) AS size FROM ims_image WHERE u_id='$user_info[u_id]'"));
        if($space_used[size] == NULL) { $space_used[size] = 0; }
        $space_avail = $user_info[space_avail] * (1024 * 1024);
        $space_left = $space_avail - $space_used[size];
        if($_FILES['file3']['size'] >= $space_left) {
        $badfiletrue = "yes";
        $toobig3 = "yes";
        $badfile3 = "yes";
        if(isset($reasons3)) {$reasons3 .= ", "; }
        $reasons3 .= "insufficient space available";
        }
        if($images_inside == 100) {
        $badfiletrue = "yes";
        $filelim3 = "yes";
        $badfile3 = "yes";
        if(isset($reasons3)) {$reasons3 .= ", "; }
        $reasons3 .= "destination folder already contains maximum allowed images (100)";
        }}

   if($badfile3 != "yes") {
   $file3_tmp_name = $_FILES['file3']['tmp_name'];
   $file3_name = $_FILES['file3']['name'];
   $file3_size = $_FILES['file3']['size'];

   mysql_query("INSERT INTO ims_image (u_id, f_id, title, description, ext, size) VALUES ('$user_info[u_id]', '$f_id', '$title3', '$descr3', '$ext3', '$file3_size')");
   $i_id = mysql_fetch_assoc(mysql_query("SELECT max(i_id) AS i_id FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id' AND title='$title3' AND description='$descr3' AND ext='$ext3' AND size='$file3_size' AND views=''"));
   $image_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_image WHERE i_id='$i_id[i_id]'"));

   if(move_uploaded_file($file3_tmp_name, "./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext])) {
    $thumb_sql = "$image_info[i_id].$image_info[ext]";
    if($ext3 == "gif") {
    copy("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext], "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
  } elseif($ext3 == "bmp") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefrombmp("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
        for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagejpeg($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);

      $newimage = imagecreatetruecolor($size[0], $size[1]);
      $oldimage = imagecreatefrombmp("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
      imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $size[0], $size[1], $size[0], $size[1]);
      imagejpeg($newimage, "./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
      ImageDestroy($newimage);
      ImageDestroy($oldimage);

    } elseif($ext3 == "jpeg" | $ext3 == "jpg") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefromjpeg("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
         for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagejpeg($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);
    } elseif($ext3 == "png") {
    $thumb = imagecreatetruecolor(60, 60);
    $new = imagecreatefrompng("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
         for($i=0; $i<256; $i++) {
        imagecolorallocate($thumb, $i, $i, $i);
        }
    $size = getimagesize("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
    imagecopyresampled($thumb, $new, 0, 0, 0, 0, 60, 60, $size[0], $size[1]);
    imagepng($thumb, "./u/$user_info[u_id]/$folder_info[f_id]/thumbs/".$image_info[i_id].".".$image_info[ext]);
    ImageDestroy($new);
    ImageDestroy($thumb);
    } else {
    $thumb_sql = "none";
    }
    mysql_query("UPDATE ims_image SET thumb='$thumb_sql' WHERE i_id='$image_info[i_id]'");
   } else {
    mysql_query("DELETE * FROM ims_image WHERE i_id='$image_info[i_id]'");
   }

   $filepassed3 = "yes";
   $images_inside = $images_inside + 1;
   }
}




include "vars.php";
$images_inside = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id'"));
if(($images_inside % $user_info[prefs_images_per_page]) != 0) {
$maxpage = ($images_inside) / $user_info[prefs_images_per_page] + 1;
} else {
$maxpage = ($images_inside) / $user_info[prefs_images_per_page];
}
$maxpage = (int) $maxpage;

if($user_info[prefs_listby] == "oldest") { 
$page = $maxpage; 
} elseif($user_info[prefs_listby] == "newest") {
$page = 1;
} elseif($user_info[prefs_listby] == "alpha") {
$page = $page;
}


echo $header;
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr><form action='upload_images.php?f_id=$f_id' method='POST'>
<td class='comments'>";

    // NO FILES SPECIFIED
    if($file1 == "none" AND $file2 == "none" AND $file3 == "none") {
    echo "<b>Error</b><br><font class='csmall'>You did not specify any images to upload.</font><br><br>";
    $skip2 = "yes";
    $tryagain = "yes";
    }

    // SUCCESSFUL UPLOADS 
    echo "<b>Successful Uploads:</b><br><font class='csmall'>";
    if($filepassed1 != "yes" AND $filepassed2 != "yes" AND $filepassed3 != "yes") {
    echo "<i>None</i><br><br>";
    }

$title1_stripped = stripslashes($title1);
$title2_stripped = stripslashes($title2);
$title3_stripped = stripslashes($title3);

    if($filepassed1 == "yes" OR $filepassed2 == "yes" OR $filepassed3 == "yes" ) {
    if($filepassed1 == "yes") {
    echo $title1_stripped."<br>";
    }
    if($filepassed2 == "yes") {
    echo $title2_stripped."<br>";
    }
    if($filepassed3 == "yes") {
    echo $title3_stripped."<br>";
    }
    echo "<br>";
    $uploadmore = "yes";
    }

    // INVALID FILES SUBMITTED
    if($skip2 != "yes") {
    echo "</font><b>Unsuccessful Uploads:</b><br><font class='csmall'>";
    if($badfiletrue != "yes") {
    echo "<i>None</i><br>";
    } else {

    if($badfile1 == "yes" AND $file1 != "none") {
    echo $title1_stripped." - ($reasons1) <br>";
    }
    if($badfile2 == "yes" AND $file2 != "none") {
    echo $title2_stripped." - ($reasons2) <br>";
    }
    if($badfile3 == "yes" AND $file3 != "none") {
    echo $title3_stripped." - ($reasons3) <br>";
    }
    }

    echo "<br>";

    if($wrongformat1 == "yes" OR $wrongformat2 == "yes" OR $wrongformat3 == "yes") {
    echo "Only images of the following types are accepted: $ext_list_spaced.<br>";
    $tryagain = "no";
    $uploadmore = "yes";
    }

    if($longname1 == "yes" OR $longname2 == "yes" OR $longname3 == "yes") {
    echo "Uploaded file names may not be longer than 40 characters.<br>";
    $tryagain = "no";
    $uploadmore = "yes";
    }

    if($badletters1 == "yes" OR $badletters2 == "yes" OR $badletters3 == "yes") {
    echo "Uploaded file names may only contain alpha-numeric characters, spaces, hyphens, and underscores.<br>";
    $tryagain = "no";
    $uploadmore = "yes";
    }

    if($toobig1 == "yes" OR $toobig2 == "yes" OR $toobig3 == "yes") {
    echo "You have reached your allocated space limit.<br>";
    $tryagain = "yes";
    $uploadmore = "no";
    }

    if($filelim1 == "yes" OR $filelim2 == "yes" OR $filelim3 == "yes") {
    echo "Destination folders may contain up to 100 files.<br>";
    $tryagain = "yes";
    $uploadmore = "no";
    }
  
    if($exceedmax1 == "yes" OR $exceedmax2 == "yes" OR $exceedmax3 == "yes") {
    echo "Uploaded files must not be larger than $user_info[max_filesize] KB.<br>";
    $tryagain = "yes";
    $uploadmore = "no";
    }

    if($duplicate1 == "yes" OR $duplicate2 == "yes" OR $duplicate3 == "yes") {
    echo "Uploaded files must not have the same filename as an image currently in the folder.<br>";
    $tryagain = "yes";
    $uploadmore = "no";
    }

    echo "</font><br>";
    }

    // SHOW APPROPRIATE BUTTONS
    if($tryagain == "yes") {
    echo "
    <input type='button' class='button' value='Done' onClick=\"gofolder('$f_id&page=$page')\">
    <input type='submit' class='button' value='Upload More'>
    <input type='hidden' name='task' value='upload'>
    ";
    }

    if($uploadmore == "yes") {
    echo "
    <input type='button' class='button' value='Done' onClick=\"gofolder('$f_id&page=$page')\">
    <input type='submit' class='button' value='Upload More'>
    <input type='hidden' name='task' value='upload'>
    ";
    }

echo "
</td>
</tr>
</form>
</table>";
echo $footer;
}




if($task == "upload") {
$allowed_exts = explode(",", $user_info[ext_list]);
$ext_list_spaced = str_replace(",", ", ", $user_info[ext_list]);

echo $header;
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr>
<td>
<b>Upload Images to \"$folder_info[name]\"</b><br><font class='csmall'>
&nbsp;&nbsp; - You may upload up to 3 images at once.<br>
&nbsp;&nbsp; - Each image cannot exceed "; echo $user_info[max_filesize]; echo " Kb in size.<br>
&nbsp;&nbsp; - Image titles and descriptions are optional"; if($admin_info[photo_album] == "yes") { echo " - they are displayed in your photo album."; } echo "<br>
&nbsp;&nbsp; - You may upload images of the following types: <b>$ext_list_spaced</b>.</font>
</td>
</tr>
</table>

<br>

<script language='JavaScript'>
<!--
function doMsg() {
document.upload.msg.value = 'Uploading ';
doMsg1();
}
function doMsg1() {
if(document.upload.msg.value == 'Uploading ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||') { document.upload.msg.value = 'Uploading '; }
document.upload.msg.value = document.upload.msg.value + '|';
window.setTimeout(\"doMsg1()\", 250);
}
// -->
</script>

<table cellpadding='0' cellspacing='0'>
<form name='upload' action='upload_images.php' enctype='multipart/form-data' method='POST'> 
<tr>
<td>
<input type='hidden' name='MAX_FILE_SIZE' value='1000000'>

<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;'>
<tr>
<td style='padding: 5px;'>
<font class='small'>Title</font><br>
<input class='text' type='text' name='title1' size='30' maxlength='40'><br>
<font class='small'>Description</font><br>
<input class='text' type='text' name='descr1' size='74' maxlength='300'><br>
<font class='small'>Image</font><br>
<input class='text' type='file' name='file1' size='60'>
</td>
</tr>
</table>

<br>

<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;'>
<tr>
<td style='padding: 5px;'>
<font class='small'>Title</font><br>
<input class='text' type='text' name='title2' size='30' maxlength='40'><br>
<font class='small'>Description</font><br>
<input class='text' type='text' name='descr2' size='74' maxlength='300'><br>
<font class='small'>Image</font><br>
<input class='text' type='file' name='file2' size='60'>
</td>
</tr>
</table>

<br>

<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;'>
<tr>
<td style='padding: 5px;'>
<font class='small'>Title</font><br>
<input class='text' type='text' name='title3' size='30' maxlength='40'><br>
<font class='small'>Description</font><br>
<input class='text' type='text' name='descr3' size='74' maxlength='300'><br>
<font class='small'>Image</font><br>
<input class='text' type='file' name='file3' size='60'>
</td>
</tr>
</table>

<br>

<input type='hidden' name='task' value='upload_do'>
<input type='hidden' name='f_id' value='$f_id'>
<input type='hidden' name='page' value='$page'>
<input class='button' type='submit' value='Upload Images' onClick=\"doMsg()\">
<input type='button' class='button' value='Cancel' onClick=\"gofolder('$f_id&page=$page')\">
&nbsp;<input type='text' name='msg' size='55' style='border: none; background: none; font-size: 9pt; margin-bottom: 2px;' value='Please be patient - larger files require longer uploads.' READONLY>

</td>
</tr>
</form>
</table>";

echo $footer;
}

?>