<?php
require("incs/include.php");
?>
<?php echo add_head('FavLinks Favorties Manager', 'FavLinks Favorties Manager'); ?>
<?php
$p_title = '';
$p_url = '';
$p_desc = '';
$p_category = '--other--';
$p_other = 'If other, please specify';
$p_rating = 0;
if (isset($_POST['submit']) && $_POST['submit'] == "Add to FavLinks") {
// to fill up the feilds in the form
$p_title = htmlspecialchars(slashtod($_POST['title']));
$p_url = htmlspecialchars(slashtod($_POST['url']));
$p_desc = htmlspecialchars(slashtod($_POST['desc']));
$p_category = htmlspecialchars(slashtod($_POST['category']));
$p_other = htmlspecialchars(slashtod($_POST['other']));
$p_rating = ((int) $_POST['rating']) % 6;
if ($_POST['title'] == '' || $_POST['url'] == '') {
echo draw_box('Error!', 'Either the \'Title\' or the \'URL\' field is empty.');
} else if ($_POST['category'] == '--other--' && $_POST['other'] == 'If other, please specify') {
echo draw_box('Error!', 'Please specify a valid category.');
} else if ($_POST['category'] == 'any') {
echo draw_box('Error!', 'Please specify a valid category (\'any\' is a reserved word).');
} else {
$p_title = slashdot(htmlspecialchars($_POST['title']));
$p_url = slashdot(htmlspecialchars($_POST['url']));
$p_desc = slashdot(htmlspecialchars($_POST['desc']));
$p_category = slashdot(htmlspecialchars($_POST['category'] == '--other--' ? $_POST['other'] : $_POST['category'] ));
$p_rating = abs((int) $_POST['rating']) % 6;
if (strpos($p_url, "://") === false) {
$p_url = "http://".$p_url;
}
$a_query = "INSERT INTO `favlinks` (`id`, `title`, `url`, `desc`, `category`, `rating`, `date`) VALUES('', '$p_title', '$p_url', '$p_desc', '$p_category', '$p_rating', CURDATE( ));";
$a_result = mysql_query($a_query);
if (mysql_error() == '') {
echo draw_box('Success', 'Entry added to the database successfully!');
$p_title = '';
$p_url = '';
$p_desc = '';
$p_category = '--other--';
$p_other = 'If other, please specify';
$p_rating = 0;
} else {
echo draw_box('Error!', 'There was some problem in adding entry to the database.');
echo "<!-- ".mysql_error()." -->";
}
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="add">
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1" class=table>
<tr><td colspan="2" class="t_head">Add a favorite link</td></tr>
<tr><td width="20%" class=dark>Title:</td><td class=light><input name="title" type="text" value="<?php echo $p_title; ?>" class="width100"></td></tr>
<tr><td class=dark>URL:</td><td class=light><input name="url" type="text" value="<?php echo $p_url; ?>" class="width100"></td></tr>
<tr><td valign="top" class=dark>Description:</td><td class=light><textarea name="desc" rows="3" class=width100><?php echo $p_desc; ?></textarea></td></tr>
<tr><td class=dark>Category:</td><td class=light><select name="category" id="category">
<option value='--other--'>-- Other --</option>
<?php
$c_query = "SELECT DISTINCT `category` FROM `favlinks` ORDER BY `category` ASC;";
$c_result = mysql_query($c_query);
while ($c_values = mysql_fetch_array($c_result)) {
echo "\n<option".($c_values['category'] == $p_category ? ' selected' : '').">".$c_values['category']."</option>";
}
?>
</select> <input name="other" type="text" value="<?php echo $p_other; ?>" size=30></td></tr>
<tr><td class=dark>Rating:</td><td class=light><select name="rating">
<option value='0'>Unrated</option>
<?php
for ($i=1;$i<6;$i++) {
echo "<option value='$i'".($p_rating == $i ? ' selected' : '').">$i star".($i > 1 ? 's' : '')."</option>\n";
}
?></select> </td></tr>
<tr><td colspan=2 class=dark align=center><input name="submit" type="submit" id="submit" value="Add to FavLinks"></td></tr>
</table>
</form>
<br><br>
<?php searchbox(); ?>
<?php echo add_foot(); ?>