\n");
html_start_links();
html_link("Submit New Category", "$PHP_SELF?UC+P$parent_id$options");
html_end_links();
db_free($result);
// Then show the listings...
if ($query != "")
$result = db_query("SELECT * FROM link "
."WHERE ${is_published}is_category = 0 AND "
."($query) "
."ORDER BY name");
else if ($parent_id >= 0)
$result = db_query("SELECT * FROM link "
."WHERE ${is_published}is_category = 0 AND "
."parent_id = $parent_id "
."ORDER BY name");
else
$result = db_query("SELECT * FROM link "
."WHERE ${is_published}is_category = 0 "
."ORDER BY name");
if ($parent_id < 0)
print("
$name $version");
if ($search != "")
{
$category = get_category($row['parent_id'], 1);
print(" in $category");
}
if (!$row["is_published"])
print(" ");
if ($age == 1)
print(", Updated 1 day ago");
else if ($age < 30)
print(", Updated $age days ago");
if ($LOGIN_LEVEL >= AUTH_DEVEL || $LOGIN_USER == $row["create_user"])
{
print(" [ Edit"
." | Delete ]\n");
}
print("$description
\n");
}
print("
\n");
html_start_links();
html_link("Submit New Listing", "$PHP_SELF?UL+P$parent_id$options");
html_end_links();
db_free($result);
html_footer();
break;
case 'U' : // Add or update category or listing...
if ($id > 0)
{
// Get current link data from database...
$result = db_query("SELECT * FROM link WHERE id = $id");
if (db_count($result) != 1)
{
// Link doesn't exist!
db_free($result);
header("Location: $PHP_SELF");
exit();
}
$row = db_next($result);
if ($LOGIN_LEVEL < AUTH_DEVEL && $LOGIN_USER != $row["create_user"])
{
// No permission!
db_free($result);
header("Location: $PHP_SELF");
exit();
}
$is_category = $row['is_category'];
$is_published = $row['is_published'];
$name = $row['name'];
$version = $row['version'];
$license = $row['license'];
$author = $row['author'];
$email = $row['email'];
$homepage_url = $row['homepage_url'];
$download_url = $row['download_url'];
$description = $row['description'];
db_free($result);
}
else
{
// Use default information for type...
if ($type == 'C')
$is_category = 1;
else
$is_category = 0;
if ($LOGIN_LEVEL >= AUTH_DEVEL)
$is_published = 1;
else
$is_published = 0;
$name = "";
$version = "";
$license = "";
$author = "";
$email = "";
$homepage_url = "http://";
$download_url = "ftp://";
$description = "";
}
$announcement = "";
if ($REQUEST_METHOD == "POST")
{
if (array_key_exists("PARENT_ID", $_POST))
$parent_id = (int)$_POST["PARENT_ID"];
if ($LOGIN_LEVEL >= AUTH_DEVEL &&
array_key_exists("IS_PUBLISHED", $_POST))
$is_published = (int)$_POST["IS_PUBLISHED"];
if (array_key_exists("NAME", $_POST))
$name = $_POST["NAME"];
if (array_key_exists("VERSION", $_POST))
$version = $_POST["VERSION"];
if (array_key_exists("LICENSE", $_POST))
$license = $_POST["LICENSE"];
if (array_key_exists("AUTHOR", $_POST))
$author = $_POST["AUTHOR"];
if (array_key_exists("EMAIL", $_POST))
$email = $_POST["EMAIL"];
if (array_key_exists("HOMEPAGE_URL", $_POST))
$homepage_url = $_POST["HOMEPAGE_URL"];
if (array_key_exists("DOWNLOAD_URL", $_POST))
$download_url = $_POST["DOWNLOAD_URL"];
if (array_key_exists("DESCRIPTION", $_POST))
$description = $_POST["DESCRIPTION"];
if (array_key_exists("ANNOUNCEMENT", $_POST) && $type == 'L')
$announcement = $_POST["ANNOUNCEMENT"];
if ($name != "" &&
($is_category ||
($version != "" && $license != "" &&
$author != "" && $description != "" &&
$homepage_url != "http://" && $download_url != "ftp://")))
$havedata = 1;
else
$havedata = 0;
}
else
$havedata = 0;
if ($type == 'C')
$typename = 'Category';
else
$typename = 'Listing';
if ($id > 0)
$opname = 'Update';
else
$opname = 'Create';
if ($havedata)
$heading = htmlspecialchars("${opname}d $typename $name");
else
$heading = htmlspecialchars("$opname $typename $name");
html_header($heading);
html_start_links(1);
html_link("Show All Listings", "$PHP_SELF?LA$options");
html_link("Show Listings By Category", "$PHP_SELF?LC$options");
if ($LOGIN_LEVEL >= AUTH_DEVEL)
html_link("Show Unpublished Listings", "$PHP_SELF?LU$options");
html_end_links();
print("
$heading
\n");
if ($havedata)
{
$name = db_escape($name);
$version = db_escape($version);
$license = db_escape($license);
$author = db_escape($author);
$email = db_escape($email);
$homepage_url = db_escape($homepage_url);
$download_url = db_escape($download_url);
$user = db_escape($LOGIN_USER);
$date = time();
$what = strtolower("${opname}d");
if ($id == 0)
{
// Insert a new record...
db_query("INSERT INTO link VALUES(NULL,$parent_id,"
."$is_category,$is_published,"
."'$name','$version','$license',"
."'$author','$email','$homepage_url','$download_url',"
."'$description',5,1,0,0,$date,'$user',$date,'$user')");
$id = db_insert_id();
}
else
{
// Modify the existing record...
db_query("UPDATE link SET is_published=$is_published,"
."parent_id=$parent_id,"
."name='$name',version='$version',license='$license',"
."author='$author',email='$email',"
."homepage_url='$homepage_url',download_url='$download_url',"
."description='$description',modify_date=$date,"
."modify_user='$user' "
."WHERE id=$id");
}
if ($announcement != "")
{
$links = "
[ More Info";
if ($homepage_url != "")
$links .= " | Home Page";
if ($download_url != "")
$links .= " | Download";
$links .= " ]
\n";
$abstract = db_escape(abbreviate($announcement, 80));
$announcement = db_escape($links . $announcement);
db_query("INSERT INTO article VALUES(NULL,0,"
."'$name $version','$abstract','$announcement',$date,"
."'$user',$date,'$user')");
$article_id = db_insert_id();
// Notify the admin about the new article...
mail($PROJECT_EMAIL, "$PROJECT_NAME Article #$article_id created",
wordwrap("$user has created an article titled, "
."'$name $version' with the following abstract:\n\n"
." $abstract\n\n"
."Please approve or delete this article via the following "
."page:\n\n"
." $PHP_URL?L$article_id\n"),
"From: $PROJECT_EMAIL\r\n");
}
if ($is_published == 0)
{
// Send email to moderators...
$message = wordwrap("'$name' has been $what on the $PROJECT_NAME "
."links page and requires your approval before "
."it will be made visible on the $PROJECT_NAME "
."site. Please go to the following link to "
."process the submission:\n\n"
." $PHP_URL?U$type$id\n");
mail($PROJECT_EMAIL, "$PROJECT_NAME $typename ${opname}d",
$message, "From: $PROJECT_EMAIL\r\n");
// Let the user know that the moderator must approve it...
print("
Your submission will be made visible as soon as one of "
."moderators approves it.
\n");
}
else
{
print("
Thank you, your submission is now visible on the site.
\n");
if ($announcement != "")
print("
Your news announcement will be made visible as soon as "
."one of moderators approves it.
\n");
}
html_start_links();
html_link("Return to Listing", "$PHP_SELF?L+P$parent_id");
html_end_links();
}
else
{
if ($REQUEST_METHOD == "POST")
{
$what = strtolower($typename);
print("
Error: Please fill in the fields marked in "
."bold red below and resubmit "
."your $what.