All pastes #550507 Raw Edit

Something

public text v1 · immutable
·published 2007-06-08 13:05 UTC
rendered paste body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<?php include("dict.php"); ?>
<html>
<head>
<title>PAD Submittal</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>

<!-- No modifications are required in this file -->

<?php

  // added in v2.00.03 (OG)
  function _GetParam($Name, $Default = "") {
    if ( isset($_GET[$Name]) )
      return $_GET[$Name];
    else if ( isset($_POST[$Name]) )
      return $_POST[$Name];
    else
      return $Default;
  }
  $padurl = _GetParam("padurl");
  $padcat = _GetParam("padcat");

  //if (empty($psubmit)) die("Invalid page access");

  if (substr(strtolower($padurl),0,7) <> "http://")
    die ("<b>Error:</b> PAD URL must begin with http://<br>Press the Back button.<br>");

  if (strtolower($padurl) == "http://")
    die ("<b>Error:</b> No PAD URL submitted. Press the Back button.<br>");

  if (trim($padcat) == "")
    die("<b>Error:</b> No program category selected. Press the Back button.<br>");

include("header.php");

$catary = file($catfile);

$isvalidcat = 0;

//$padcat=urldecode($padcat);  // changed in v2.00.03 (OG)
for ($i=0; $i<count($catary); $i++) {
 $cdisp = rtrim($catary[$i]);
 $cmach = rawurlencode($cdisp);
 $cdisp2 = explode("::", $cdisp);
 $cmach2 = explode("%3A%3A", $cmach);

 $cdispwsc=htmlspecialchars($cdisp); // added in v2.00.01 (DV)
// $cdisp=urldecode($cdisp);
// echo "<br>$i - $cdisp";
 if ($padcat == $cdisp || $padcat == $cdispwsc) { //a pre-defined category?
   $isvalidcat = 1;
   break; // added in v2.00.01 (DV)
 }
}

if ($isvalidcat == 0)
    die("<b>Error:</b> Unrecognized category $padcat. Press the Back button.<br>");

  function GetStartTag($parser,$element_name,$element_attribs)
  {
    global $tagstack;
    $tagstack .= "<" . $element_name . ">";
  }

  function GetData($parser,$data)
  {
    global $tagstack, $tagarray, $lasttag;
    if ($lasttag == $tagstack) $tagarray["$tagstack"] .= $data; else $tagarray["$tagstack"] = $data;
    $lasttag = $tagstack;
  }

  function GetEndTag($parser,$element_name)
  {
    global $tagstack;
    $x = "<" . $element_name . ">";
    if (strrchr($tagstack,$x) == $x) $tagstack = substr($tagstack,0,strrpos($tagstack,$x));
    else
    {
      echo "Error: no corresponding start tag for end tag",htmlspecialchars($x),"<br><br>";
      exit;
    }
  }

  $tagstack = "";
  $lasttag = "?";

  if (!$data = @file($padurl)) die("Error opening $padurl . Press back button and check URL");
  $data = implode("",$data);  // changed in v2.00.02 (OG)
  $data = substr($data, strpos($data,"<?xml"));  // remove any http headers

  // Look up the XML encoding  // added in v2.00.02 (OG)
  if ( preg_match("/<\?xml [^>]*encoding=['\"](.*?)['\"][^>]*>.*/", $data, $m) )
    $encoding = strtoupper($m[1]);
  else
    $encoding = "UTF-8";

  // If the encoding is not natively supported by the PHP XML parser, try to
  // decode on our own (to UTF-8), if decoding is not possible, assume UTF-8,
  // which is the XML default.  // added in v2.00.02 (OG)
  if ( ($encoding != "UTF-8") && ($encoding != "US-ASCII") && ($encoding != "ISO-8859-1") )
  {
    $encoding = "";
    if ( function_exists("mb_convert_encoding") )
    {
      $encoded_source = @mb_convert_encoding($data, "UTF-8", $encoding);
      if ( $encoded_source != NULL )
      {
        $data = str_replace($m[0], "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", $encoded_source);
        $encoding = "UTF-8";
      }
    }
  }

  if (!($xml_parser = xml_parser_create($encoding))) die ("Error creating XML parser");  // changed in v2.00.02 (OG)

  xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");  // added in v2.00.02 (OG)
  xml_set_element_handler($xml_parser,"GetStartTag","GetEndTag");
  xml_set_character_data_handler($xml_parser,"GetData");
  xml_parse($xml_parser,$data,true);
  xml_parser_free($xml_parser);

  echo "<b>Results for $padurl</b>:<br><br>";

  $reqtags = array("<XML_DIZ_INFO><COMPANY_INFO><COMPANY_NAME>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_NAME>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_VERSION>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_MONTH>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_DAY>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_YEAR>",
                   "<XML_DIZ_INFO><COMPANY_INFO><COMPANY_WEBSITE_URL>",
                   "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_EMAIL>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_COST_DOLLARS>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_TYPE>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_OS_SUPPORT>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><FILE_INFO><FILE_SIZE_K>",
                   "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><KEYWORDS>",
                   "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><CHAR_DESC_450>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_INFO_URL>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_SCREENSHOT_URL>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_XML_FILE_URL>",
                   "<XML_DIZ_INFO><WEB_INFO><DOWNLOAD_URLS><PRIMARY_DOWNLOAD_URL>",
                   "<XML_DIZ_INFO><ASP><ASP_MEMBER_NUMBER>");

  // set defaults for cost, screenshot, and ASP number if blank

  $tag = "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_COST_DOLLARS>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "0.00";
  $tag = "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_SCREENSHOT_URL>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";

  $tag = "<XML_DIZ_INFO><ASP><ASP_MEMBER_NUMBER>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";


  // check for missing/empty tags

  $paderr = false;

  foreach ($reqtags as $tag)
  {
    if (empty($tagarray["$tag"]))
    {
      echo "Required tag not found in PAD file: ",htmlspecialchars($tag),"<br>";
      $paderr = true;
    }
    else
    {
      $tagarray["$tag"] = trim($tagarray["$tag"]);
      if  ($tagarray["$tag"] == "")
      {
        echo "Required data not found in tag: ",htmlspecialchars($tag),"<br>";
        $paderr = true;
      }
    }
  }

  if ($paderr) die("<br><b>PAD file rejected</b><br>");

  $tag = $reqtags[0];  $company =     substr($tagarray["$tag"], 0, 50);
  $tag = $reqtags[1];  $title =       substr($tagarray["$tag"], 0, 50);
  $tag = $reqtags[2];  $version =     substr($tagarray["$tag"], 0, 10);   // modified in v2.00.03 (OG)
  $tag = $reqtags[3];  $pmonth =      $tagarray["$tag"];
  $tag = $reqtags[4];  $pday =        $tagarray["$tag"];
  $tag = $reqtags[5];  $pyear =       $tagarray["$tag"];
  $tag = $reqtags[6];  $website =     substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[7];  $email =       substr($tagarray["$tag"], 0, 50);   // modified in v2.00.03 (OG)
  $tag = $reqtags[8];  $cost =        $tagarray["$tag"];
  $tag = $reqtags[9];  $ptype =       substr($tagarray["$tag"], 0, 15);   // modified in v2.00.03 (OG)
  $tag = $reqtags[10]; $os =          substr($tagarray["$tag"], 0, 80);   // modified in v2.00.03 (OG)
  $tag = $reqtags[11]; $ksize =       $tagarray["$tag"];
  $tag = $reqtags[12]; $keywords =    substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[13]; $description = $tagarray["$tag"];
  $tag = $reqtags[14]; $homepage =    substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[15]; $screenshot =  substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[16]; $padfile =     substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[17]; $download =    substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[18]; $aspnumber =   substr($tagarray["$tag"], 0, 5);    // modified in v2.00.03 (OG)

  // added in v2.00.08 (OG)
  // prepend protocol if not provided
  if ((trim($website) != "") && (strstr($website, "://") === FALSE))
    $website = "http://" . $website;
  if ((trim($homepage) != "") && (strstr($homepage, "://") === FALSE))
    $homepage = "http://" . $homepage;
  if ((trim($screenshot) != "") && (strstr($screenshot, "://") === FALSE))
    $screenshot = "http://" . $screenshot;
  if ((trim($download) != "") && (strstr($download, "://") === FALSE))
    $download = "http://" . $download;

  if (strlen($pmonth) == 1) $pmonth = "0" . $pmonth;
  if (strlen($pday) == 1) $pday = "0" . $pday;
  $pdate = $pyear . "-" . $pmonth . "-" . $pday;
  $ksize = str_replace(",","",$ksize);  // remove any commas

  // count chars in description minus html encodings

  $desc2 = str_replace("&lt;","x",strtolower($description));
  $desc2 = str_replace("&gt;","x",$desc2);
  $desc2 = str_replace("&amp;","x",$desc2);
  $desc2 = str_replace("&quot;","x",$desc2);
  if (strlen($desc2) > 450)
    die("Error: CHAR_DESC_450 field exceeds 450 character limit.<br>");

//  if (strcasecmp($padurl,$padfile) <> 0) // removed in v2.00.01 (DV)
//    die("Error: submitted url ($padurl) does not match url inside PAD file ($padfile). Click back button and correct the URL"); // removed in v2.00.01 (DV)

  $tomorrow = date("Y-m-d",time()+86400);
  if ($pdate > $tomorrow)
    die("Error: Forward dating not allowed. Release date ($pdate) is greater than tomorrow's date ($tomorrow)<br>");

  // connect to database

  $link_id = mysql_connect($dbhost, $userid, $userpassword) or die ("Error connecting to the database server.");  // changed in v2.00.05 (OG)
  mysql_select_db ($dbname);

  $company = addslashes($company);
  $keywords = addslashes($keywords);
  $title = addslashes($title);
  $description = addslashes($description);
  $download = addslashes($download); // added in v1.50.03 (DV)
  $poll = 0;

  // see if company/title already in paddata table

  $result = mysql_query("select * from paddata where (company = '$company' and title = '$title') or (padfile = '$padfile')", $link_id);  // modified in v2.00.03 (OG)
  $replace = (mysql_num_rows($result) <> 0);

  // insert (replace) fields into paddata table

  if (!mysql_query("replace into paddata (company, title, version, pdate, website, email, cost, ptype, os, ksize, category, keywords, description, homepage, screenshot, padfile, download, aspnumber, poll) values('$company', '$title', '$version', '$pdate', '$website', '$email', '$cost', '$ptype', '$os', '$ksize', '$padcat', '$keywords', '$description', '$homepage', '$screenshot', '$padfile', '$download', '$aspnumber', '$poll')", $link_id)) die("Error updating paddata table");

  // update activity log

  $ipaddr = getenv("REMOTE_ADDR");
  mysql_query("insert into editlog(logtime,aspnumber,ipaddr,action) values(now(), '$aspnumber', '$ipaddr', 'Add PAD: $company - $title')", $link_id);

  // disconnect from database

  mysql_close($link_id);

  // display messages

  if ($replace) echo "Existing program record successfully updated<br>";
  else echo "New program successfully added<br>";

  echo "Click your browser's Back button to add another program<br><br>";

  $company = htmlspecialchars(stripslashes($company));
  $title = htmlspecialchars(stripslashes($title));
  $keywords = htmlspecialchars(stripslashes($keywords));
  $description = htmlspecialchars(stripslashes($description));
  $download = htmlspecialchars(stripslashes($download),ENT_QUOTES); // added in v1.50.03 (DV)
  $cost = sprintf("%01.2f",$cost);

  echo
  "
    <Table class='tableborder' border='0' width='100%' align='center' cellspacing='0' cellpadding='0'>
      <TR>
        <TD>
          <Table border='0' width='100%' cellspacing='1' cellpadding='4'>
            <TR>
              <TD class='tablehead' width='50%' colspan='2'>
                <b>$title $version</b>
              </TD>
              <TH class='tablehead' align='center' colspan='2'>
                <a class='head' href='$website'>[$company]</a>
              </TH>
            </TR>
            <TR>
              <TD class='tablebody' colspan='4'>
                <b>Description:</b> $description<br>
                <a class='nu' href='$homepage'>[app home page]</a>&nbsp;
  ";
                if ($screenshot <> "none") echo "<a class='nu' href='$screenshot'>[app screenshot]</a>";
  echo
  "
              </TD>
            </TR>
            <TR>
              <TD class='tablebody' width='75%' colspan='3'>
                <b>Platform:</b> $os
              </TD>
              <TD class='tablebody'>
                <b>Category:</b> $padcat
              </TD>
            </TR>
            <TR>
              <TD class='tablebody'>
                <b>Type:</b> $ptype
              </TD>
              <TD class='tablebody'>
                <b>Cost:</b> \$$cost US
              </TD>
              <TD class='tablebody'>
                <b>Size:</b> $ksize K
              </TD>
              <TD class='tablebody'>
                <b>Released:</b> $pdate
              </TD>
            </TR>
            <TR>
              <TD class='tablebody' colspan='4'>
                <b>Download:</b> <a class='nu' href='$download'>$download</a>
              </TD>
            </TR>
          </Table>
        </TD>
      </TR>
    </Table>
    <p>
    <b>Non-Displayed Fields:</b><br><br>
    <b>Email: </b>$email<br>
    <b>Keywords: </b>$keywords<br>
    <b>PAD File: </b>$padfile<br>
    <b>ASP Number: </b>$aspnumber<br><br>
    </p>
  ";

?>

<?php include("footer.php") ?>

</body>
</html>