<?php
// $Id: submit.php,v 1.4 2004/07/14 13:45:19 Farsus Exp $
// -------------------------------------------------------------------------//
//                                         RUNCMS                           //
//                                                                          //
//         Relaible - Unique - Nocost &  Simplicity & ease off use          //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once("header.php");
include_once(XOOPS_ROOT_PATH."/class/module.errorhandler.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formdhtmltextarea.php");

$eh     = new ErrorHandler();
$mytree = new XoopsTree($db->prefix("mylinks_cat"), "cid", "pid");

if ( !empty($HTTP_POST_VARS['submit']) ) {
        if ( !$xoopsUser && empty($mylinksConfig['anon_add']) ) {
                redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
                exit();
        }

if ( empty($HTTP_POST_VARS['submitter']) ) {
        if (!$xoopsUser) {
                $submitter = 0;
                } else {
                        $submitter = $xoopsUser->uid();
                }
        }

$cid         = intval($HTTP_POST_VARS['cid']);
$url         = formatURL($myts->makeTboxData4Save($HTTP_POST_VARS['url']));
$title       = $myts->makeTboxData4Save($HTTP_POST_VARS['title']);
$email       = $myts->makeTboxData4Save($HTTP_POST_VARS['email']);
$description = $myts->makeTboxData4Save($HTTP_POST_VARS['linkdesc']);
$date        = time();

// Check if Title exist
if ( empty($title) ) {
        $eh->show("1001");
}

// Check if URL exist
if ( empty($url) ) {
        $eh->show("1016");
}

// Check if Description exist
if ( empty($description) ) {
        $eh->show("1008");
}
$newid = $db->genId($db->prefix("mylinks_links")."_lid_seq");
$sql   = "INSERT INTO ".$db->prefix("mylinks_links")." VALUES (
        ".intval($newid).",
        ".intval($cid).",
        '$title',
        '$description',
        '$url',
        '$email',
        '$url',
        ".intval($submitter).",
        0,
        ".time().",
        0,
        0,
        0,
        0)";


$db->query($sql) or $eh->show("0013");
redirect_header("index.php", 2, _MD_RECEIVED."<br />"._MD_WHENAPPROVED."");
exit();

} else {
        if ( !$xoopsUser && empty($mylinksConfig['anon_add']) ) {
                redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
                exit();
        }

include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
mainheader();

if (!$xoopsUser) {
        $uid   = 0;
        $email = '';
        $lock  = 'text';
        } else {
                $uid   = $xoopsUser->uid();
                $email = $xoopsUser->getVar("email");
                $lock  = 'hidden';
        }

$disclaimer = join('', file("./cache/disclaimer.php"));
$myts->setType('admin');
echo $myts->makeTareaData4Show($disclaimer, 1, 1, 1)."<br /><br />";
OpenTable();
?>

<h3><?php echo _MD_ADDNEWLINK;?></h3>
<form action="submit.php" method="post">
<table width="80%"><tr>
<td align="right" nowrap>*<b><?php echo _MD_SITETITLE;?></b></td>
<td><input type="text" class="text" name="title" size="50" maxlength="100" /></td>
</tr><tr>
<td align="right" nowrap>*<b><?php echo _MD_SITEURL;?></b></td>
<td><input type="text" class="text" name="url" size="50" maxlength="255" value="http://" /></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_CATEGORYC;?></b></td>
<td><?php echo $mytree->makeMySelBox("title", "title");?></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_CONTACTEMAIL;?></b></td>
<td><input type="<?php echo $lock;?>" name="email" value="<?php echo $email;?>" size="50" maxlength="60" /><?php echo $email;?></td>
</tr><tr>
<td align="right" valign="top" nowrap>*<b><?php echo _MD_DESCRIPTIONC;?></b></td>
<td>
<?php
$desc = new XoopsFormDhtmlTextArea('', 'linkdesc', '', 10, 50);
echo $desc->render();
?>
</td>
</tr>
</table>
<div align="center">
<input type="hidden" name="submitter" value="<?php echo $uid;?>" />
<input type="submit" class="button" name="submit" value="<?php echo _SUBMIT;?>" />
<input type="button" class="button" value="<?php echo _CANCEL;?>" onclick="javascript:history.go(-1)" />
</div>
</form>

<?php
CloseTable();
CloseTable();
}

include_once("footer.php");
?>