All pastes #160020 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-03 19:49 UTC
rendered paste body
<?
//error_reporting(E_ALL);

$item = null;

if (!isset($offset)){
$offset = 0;
}

  if ($handle = opendir("download/")) {

    while (false !== ($file = readdir($handle))) {

      if ( $file != "." && $file != ".." && !is_file($file) ) {

$filename  = $file;

$extention = explode(".", $filename);

if ( $extention[1] != "gif" && $extention[1] != "zip" ){

        $item = $item . "$file ";

}

      }

    }

    closedir($handle);

  }

  $item = explode(" ", $item);

  $delete = array_pop($item);

  $numrows = count($item);

  $page = $_GET['offset'];

  $id = $_GET['id'];

  // ************** pager **************************

  $limit = 12;



  if (!$page){

    $page = 0;

  }



  $pages = intval($numrows/$limit);



  if($numrows%$limit){ $pages++;

  $current = ($_GET['offset']/$limit);

}

  if(($pages < 1) || ($pages == 0)){

  $total = 1;

  }

  else {

  $total = $pages;



  $first = $_GET['offset'];

}

  if(((($_GET['offset'] + $limit) / $limit) >= $pages) && $pages != 1){

  $last = $_GET['offset'] + $limit;

	}

  else{

	  $last = $numrows;

	  }



  // ************** end of pager **************************

  if (!$page){

    $page = 0;

  }

  $pagelimit = $page+$limit;

  $columns = 3;

  $counter = 0;



  for ($i = $page; $i < $pagelimit; $i++) {

    if ($i < $numrows){

$filename  = $item[$i];

$extention = explode(".", $filename);

if ( $extention[1] != "gif" && $extention[1] != "zip" ){



      $templatedisplay .= "<div class=\"templates\" style=\"float:left; margin: 8px;\">
";

      $templatedisplay .= "<div class=\"screenshot\">
";

      $templatedisplay .= "<img alt=\"" . $item[$i] . "\" src=\"download/" . $item[$i] . ".gif\" height=\"78\" width=\"104\" />
";

      $templatedisplay .= "</div>
";

      $templatedisplay .= "<div class=\"view\"><a href=\"download/" . $item[$i] . "/\">View</a></div>
";

      $templatedisplay .= "<div class=\"download\"><a href=\"download/" . $item[$i] . ".zip\">Download</a></div>
";

      $templatedisplay .= "</div>
";



}

      ++$counter;

      if($counter == $columns)

      {


        $counter = 0;

      }

    }

  }


	$templatedisplay .= "<div align=\"center\" style=\"clear:both;\">
";

	$ptot = (count($item)/$limit);

	$pnum = ($page/$limit+1);

        $ptot = ceil($ptot);

$templatedisplay .= "Page $pnum of $ptot<br />";

  // ************** bottom pager  **************************



  if (!empty($_GET['offset']) && $_GET['offset'] > 0)

  {

    $back_page = $_GET['offset'] - $limit;

    $url = "templates.html?offset=$back_page";

    $templatedisplay .= "<a href=\"$url\">&laquo; Back </a>
";

  }

  if($pages > 1)

  {

    for ($i=1; $i <= $pages; $i++)

    {

      $ppage = $limit*($i - 1);

      if ($ppage == $_GET['offset'])

      $templatedisplay .= "<i>$i</i>
";

      else

      {

        $url = "templates.html?offset=$ppage";

        $templatedisplay .= "<a href=\"$url\">$i</a>
";

      }

    }

  }



  if(((($_GET['offset']+$limit) / $limit) < $pages) && $pages != 1)

  {

    $next_page = $_GET['offset'] + $limit;

    $url = "templates.html?offset=$next_page";

    $templatedisplay .= "<a href=\"$url\"> Next &raquo;</a>
";

  }

  // ************** end of bottom pager **************************

  $templatedisplay .= "</div>
";

echo $templatedisplay;

?>