<?php require_once('../Connections/sjarm.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $mydb, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($mydb, $theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO nieuws (type, sub, last_change, kop, intro, bericht, bron, datum, einddatum) VALUES (%s, %s,  %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['type'], "text", $sjarm),
                       GetSQLValueString($_POST['sub'], "text", $sjarm),
                       GetSQLValueString($_POST['last_change'], "text", $sjarm),					   
                       GetSQLValueString($_POST['koptekst'], "text", $sjarm),
                       GetSQLValueString($_POST['intro'], "text", $sjarm),
                       GetSQLValueString($_POST['tekst'], "text", $sjarm),
                       GetSQLValueString($_POST['bron'], "text", $sjarm),
                       GetSQLValueString($_POST['datum'], "text", $sjarm),
                       GetSQLValueString($_POST['einddatum'], "text", $sjarm));

  mysqli_select_db($sjarm, $database_sjarm);
  $Result1 = mysqli_query($sjarm, $insertSQL) or die(mysqli_error($sjarm));

  $insertGoTo = "nieuws.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$colname_rs_nieuws = "-1";
if (isset($_GET['id'])) {
  $colname_rs_nieuws = $_GET['id'];
}
mysqli_select_db($sjarm, $database_sjarm);
$query_rs_nieuws = sprintf("SELECT * FROM nieuws WHERE id = %s", GetSQLValueString($colname_rs_nieuws, "int", $sjarm));
$rs_nieuws = mysqli_query($sjarm, $query_rs_nieuws) or die(mysql_error($sjarm));
$row_rs_nieuws = mysqli_fetch_assoc($rs_nieuws);
?>
<?php include('include_whitelist.php');?>
<?php include('include_tinymce_standaard.php');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Content Management Website</title>
<link href="sjarm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="calendarDateInput.js">

/***********************************************
* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
* Script featured on and available at http://www.dynamicdrive.com
* Keep this notice intact for use.
***********************************************/

</script>
</head>

<body>
<div id="main1">
<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" background="../images/achtergrond_main.png">
<tr>
		<td align="center"><img src="../images/beheer/sjarm_cms_250.gif" alt="sjarm" width="250" height="76" />
          <div id="table_main">
		  <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="25" align="left" bgcolor="#FDC040" class="small">type</td>
                <td align="left" bgcolor="#FFFFFF"><label>
                  <select name="type" id="type">
                    <option value="algemeen">algemeen</option>
                  </select>
                  <input name="last_change" type="hidden" id="last_change" value="<?php echo $_COOKIE["user"]; ?>" />
                </label></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" bgcolor="#FDC040" class="small">Kop</td>
                <td align="left" bgcolor="#FFFFFF"><label>
                  <input name="koptekst" type="text" class="field_form" id="koptekst" size="70" />
                </label></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" bgcolor="#FDC040" class="small">Intro</td>
                <td align="left" bgcolor="#FFFFFF"><textarea name="intro" cols="90" class="field_form" id="intro"></textarea>
                <br />
                <span class="small">LET OP !! Niet meer dan 2 regels, check na plaatsen het item op juistheid !!</span></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" valign="top" bgcolor="#FDC040" class="small">Bericht</td>
                <td align="left" bgcolor="#FFFFFF"><textarea name="tekst" cols="91" rows="25" id="tekst" class="standaard"></textarea></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" bgcolor="#FDC040" class="small">Bron</td>
                <td align="left" bgcolor="#FFFFFF"><input name="bron" type="text" class="field_form" id="bron" size="40" /></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" bgcolor="#FDC040" class="small">Datum</td>
                <td align="left" bgcolor="#FFFFFF"><script>DateInput('datum', true, 'YYYY-MM-DD', '<?php echo date('Y-m-d'); ?>')</script></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" bgcolor="#FDC040" class="small">Einddatum</td>
                <td align="left" bgcolor="#FFFFFF"><script>DateInput('einddatum', true, 'YYYY-MM-DD', '<?php echo date('Y-m-d', strtotime ('+1 month')); ?>')</script>
                <input name="sub" type="hidden" id="sub" value="nieuws" /></td>
              </tr>
              <tr>
                <td width="150" height="25" align="left" bgcolor="#FDC040">&nbsp;</td>
                <td align="right" bgcolor="#FFFFFF"><input name="ok" type="submit" class="button_form" id="ok" value="Aanpassen" /></td>
              </tr>
            </table>
            <input type="hidden" name="MM_insert" value="form1" />
          </form>
          </div>
		  <p>
		    <input name="" type="button" class="button_form" 
onclick="location.href='nieuws.php'" value="Terug" />
	  </p></td></tr>
</table>
</div>

</body>
</html>