"Extension","T"=>"Theme");
$typename = $typearray[$_GET["type"]];
?>
Add New
\n";
//------------------
// Construct $manifestdata[] array from install.rdf info.
//-------------------
$manifestdata = parse_install_manifest($buf);
if(is_null($manifestdata)) {
echo"Errors were encountered during install.rdf parsing...
\n";
die("Aborting...");
}
// this is a temporary function
// until we support multiple locales for
// name / description
function default_l10n($array)
{
if($array["en-US"]) {
return $array["en-US"];
}
else {
foreach($array as $val) {
return $val;
}
}
return "";
}
//echo"Adding Extension... Checking file...
\n";
//echo""; print_r($manifestdata); echo"
\n";
//Populate Form Variables from manifestdata.
$id = $manifestdata["id"];
$version = $manifestdata["version"];
$homepage = $manifestdata["homepageURL"];
// $names, $descriptions are arrays keyed by locale
$names = $manifestdata["name"];
$descriptions = $manifestdata["description"];
//TODO: support multiple locale names/descriptions
// right now we just use en-US or the first one
$name = default_l10n($names);
$description = default_l10n($descriptions);
//Check GUID for validity/existance, if it exists, check the logged in author for permission
$sql = "SELECT ID, GUID from `main` WHERE `GUID` = '".escape_string($manifestdata[id])."' LIMIT 1";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
if (mysql_num_rows($sql_result)=="1") {
// echo"This is a updated extension... Checking author data...
\n";
$mode = "update";
$row = mysql_fetch_array($sql_result);
$item_id = $row["ID"];
if ($_POST["legacy"]=="TRUE") {
if ($_POST["mode"]=="update") {
$item_id = escape_string($_POST["existingitems"]);
} else {
$item_id="";
}
}
$sql = "SELECT `UserID` from `authorxref` WHERE `ID`='$item_id' AND `UserID` = '$_SESSION[uid]' LIMIT 1";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
if (mysql_num_rows($sql_result)=="1" or ($_SESSION["level"]=="admin" or $_SESSION["level"]=="editor")) {
// echo"This extension belongs to the author logged in
\n";
} else {
echo"ERROR!! This extension does NOT belong to the author logged in.
\n";
die("Terminating...");
}
} else {
$mode = "new";
// echo"This is a new extension...
\n";
}
//Verify MinAppVer and MaxAppVer per app for validity, if they're invalid, reject the file.
if ($_POST["legacy"]=="TRUE" AND !$manifestdata["targetApplication"]) {$manifestdata["targetApplication"]=array(); }
foreach ($manifestdata["targetApplication"] as $key=>$val) {
$esckey = escape_string($key);
$i=0;
$sql = "SELECT `AppName`, `major`, `minor`, `release`, `SubVer` FROM `applications` WHERE `GUID`='$esckey' ORDER BY `major` DESC, `minor` DESC, `release` DESC, `SubVer` DESC";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
while ($row = mysql_fetch_array($sql_result)) {
$i++;
$appname = $row["AppName"];
$subver = $row["SubVer"];
$release = $row["major"] . "." . $row["minor"];
if ($row["release"]) {$release = "$release." . $row["release"];}
if ($subver !=="final") {$release="$release$subver";}
if ($release == $val["minVersion"]) { $versioncheck[$key]["minVersion_valid"] = "true"; }
if ($release == $val["maxVersion"]) { $versioncheck[$key]["maxVersion_valid"] = "true"; }
}
if (!$versioncheck[$key]["minVersion_valid"]) {
$versioncheck[$key]["minVersion_valid"]="false";
echo"Error! The MinAppVer for $appname of " . $val["minVersion"] . " in install.rdf is invalid.
\n";
$versioncheck["errors"]="true";
}
if (!$versioncheck[$key]["maxVersion_valid"]) {
$versioncheck[$key]["maxVersion_valid"]="false";
echo"Error! The MaxAppVer for $appname of ". $val["maxVersion"] . " in install.rdf is invalid.
\n";
$versioncheck["errors"]="true";
}
}
if ($versioncheck["errors"]=="true") {
echo"Errors were encountered during install.rdf checking...
\n";
die("Aborting...");
} else {
// echo"install.rdf minAppVer and maxAppVer valid...
\n";
}
} else {
echo"Add Step 1b: Legacy Item Data Entry: ($filename)
\n";
?>
"Extension","T"=>"Theme");
$type = escape_string($_POST["type"]);
$typename = $typearray[$type];
if ($mode=="update") {
$sql = "SELECT `Name`, `Homepage`, `Description` FROM `main` WHERE `ID` = '$item_id' LIMIT 1";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
$row = mysql_fetch_array($sql_result);
if (!$name) { $name=$row["Name"]; }
$homepage = $row["Homepage"];
$description = $row["Description"];
$authors = ""; $i="";
$sql = "SELECT TU.UserEmail FROM `authorxref` TAX INNER JOIN userprofiles TU ON TAX.UserID = TU.UserID WHERE `ID` = '$item_id'";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
$numresults = mysql_num_rows($sql_result);
while ($row = mysql_fetch_array($sql_result)) {
$i++;
$email = $row["UserEmail"];
$authors .= "$email";
if ($i < $numresults) { $authors .=", "; }
}
//Get Currently Set Categories for this Object...
$sql = "SELECT TCX.CategoryID, TC.CatName FROM `categoryxref` TCX
INNER JOIN categories TC ON TCX.CategoryID = TC.CategoryID
WHERE TCX.ID = '$item_id'
ORDER BY `CatName` ASC ";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
while ($row = mysql_fetch_array($sql_result)) {
$n++;
$catid = $row["CategoryID"];
$categories[$n] = $catid;
}
unset($n);
}
if (!$categories) {$categories = array(); }
?>
Add New »» Step 2:
1) {
//Too many e-mails match, store individual data for error block.
$r++;
$emailerrors[$a]["foundemails"][$r] = $useremail;
}
$authorids[] = $userid;
$authoremails[] = $useremail;
}
if ($numresults !="1") {
//No Valid Entry Found for this E-Mail or too many, kill and store data for error block.
$emailerrors[$a]["author"] = "$author";
$updateauthors = "false"; // Just takes one of these to kill the author update.
}
}
unset($a,$r);
if ($_POST["name"] AND $_POST["type"] AND $_POST["authors"] AND $updateauthors !="false" AND $_POST["version"] AND $_POST["osid"] AND $_POST["filename"] AND $_POST["filesize"] AND $_POST["description"] AND $minappver AND $maxappver) {
//All Needed Info is in the arrays, procceed with inserting...
//Create DIV for Box around the output...
echo"Adding Item... Please Wait...
\n";
echo"\n";
//Phase One, Main Data
$name = escape_string($_POST["name"]);
$homepage = escape_string($_POST["homepage"]);
$description = escape_string($_POST["description"]);
$item_id = escape_string($_POST["item_id"]);
$guid = escape_string($_POST["guid"]);
$type = escape_string($_POST["type"]);
//Check to ensure tha the name isn't already taken, if it is, throw an error and halt.
$sql = "SELECT `Name` from `main` WHERE `Name`='$name' and `GUID` != '$guid'";
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
if (mysql_num_rows($sql_result)=="0") {
if ($_POST["mode"]=="update") {
$sql = "UPDATE `main` SET `Name`='$name', `Homepage`='$homepage', `Description`='$description', `DateUpdated`=NOW(NULL) WHERE `ID`='$item_id' LIMIT 1";
} else {
$sql = "INSERT INTO `main` (`GUID`, `Name`, `Type`, `Homepage`,`Description`,`DateAdded`,`DateUpdated`) VALUES ('$guid', '$name', '$type', '$homepage', '$description', NOW(NULL), NOW(NULL));";
}
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
if ($sql_result) {echo"Updating/Adding record for $name...
\n";
} else {
//Handle Error Case and Abort
$failure = "true";
echo"Failure to successfully add/update main record. Unrecoverable Error, aborting.
\n";
include"$page_footer";
echo"