<?php
// $Id: modlink.php,v 1.4 2004/09/08 20:49:24 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) {
                redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
                exit();
                } else {
                        $modifysubmitter = $xoopsUser->uid();
                }

$lid         = intval($HTTP_POST_VARS["lid"]);
$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"]);

// 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_mod")."_requestid_seq");
$sql   = "
INSERT INTO 
	".$db->prefix("mylinks_mod")." 
	SET 
	requestid=$newid,
        lid=$lid,
        cid=$cid,
        title='$title',
        url='$url',
        email='$email',
        description='$description',
        modifysubmitter=$modifysubmitter";

$db->query($sql) or $eh->show("0013");
redirect_header("index.php", 2, _MD_THANKSFORINFO);
exit();

} else {

$lid = intval($HTTP_GET_VARS['lid']);

if (!$xoopsUser) {
        redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
        exit();
}

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

echo "<table align='center'>";
$result = $db->query("SELECT cid, title, description, url, email FROM ".$db->prefix("mylinks_links")." WHERE lid=$lid AND status>0");
echo "<h4>"._MD_REQUESTMOD."</h4>";
list($cid, $title, $description, $url, $email) = $db->fetch_row($result);

$title       = $myts->makeTboxData4Edit($title);
$url         = $myts->makeTboxData4Edit($url);
$email       = $myts->makeTboxData4Edit($email);
$description = $myts->makeTboxData4Edit($description);

?>
<form action="modlink.php" method="post">
<table width="80%"><tr>
<td align="right"><?php echo _MD_LINKID;?></td>
<td><b><?php echo $lid;?></b></td>
</tr><tr>
<td align="right"><?php echo _MD_SITETITLE;?></td>
<td><input type="text" class="text" name="title" size="50" maxlength="100" value="<?php echo $title;?>" /></td>
</tr><tr>
<td align="right"><?php echo _MD_SITEURL;?></td>
<td><input type="text" class="text" name="url" size="50" maxlength="255" value="<?php echo $url;?>" /></td>
</tr><tr>
<td align="right"><?php echo _MD_CATEGORYC;?></td>
<td><?php $mytree->makeMySelBox("title", "title", $cid);?></td>
</tr><tr>
<td align="right"><?php echo _MD_CONTACTEMAIL;?></td>
<td><input type="text" class="text" name="email" size="50" maxlength="60" value="<?php echo $email;?>" /></td>
</tr><tr>
<td align="right" valign="top"><?php echo _MD_DESCRIPTIONC;?></td>
<td>
<?php
$desc = new XoopsFormDhtmlTextArea('', 'linkdesc', $description, 10, 50);
echo $desc->render();
?>
</td>
</tr><tr>
<td colspan="2" align="center"><br />
<input type="hidden" name="lid" value="<?php echo $lid;?>" />
<input type="hidden" name="modifysubmitter" value="<?php echo $xoopsUser->uid();?>" />
<input type="submit" class="button" name="submit" value="<?php echo _MD_SENDREQUEST;?>" />
<input type="button" class="button" value="<?php echo _CANCEL;?>" onclick="javascript:history.go(-1)" />
</form>
</td></tr></table>
<?php

CloseTable();
}

include_once("footer.php");
?>