<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($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 run_text (berita, kode) VALUES (%s, %s)",
                       GetSQLValueString($_POST['berita'], "text"),
                       GetSQLValueString($_POST['kode'], "text"));

  mysql_select_db($database_sistem, $sistem);
  $Result1 = mysql_query($insertSQL, $sistem) or die(mysql_error());
}

mysql_select_db($database_sistem, $sistem);
$query_unit = "SELECT * FROM user_tb";
$unit = mysql_query($query_unit, $sistem) or die(mysql_error());
$row_unit = mysql_fetch_assoc($unit);
$totalRows_unit = mysql_num_rows($unit);

mysql_select_db($database_sistem, $sistem);
$query_runtext = "SELECT * FROM run_text";
$runtext = mysql_query($query_runtext, $sistem) or die(mysql_error());
$row_runtext = mysql_fetch_assoc($runtext);
$totalRows_runtext = mysql_num_rows($runtext);
?>


<p>&nbsp;</p>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td><form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table width="100%" align="left">
        <tr valign="baseline">
          <td colspan="2" align="left" nowrap="nowrap"><h3 style="color:#033">Form Running Text</h3></td>
        </tr>
        <tr valign="baseline">
          <td colspan="2" align="left" valign="top" nowrap="nowrap"><hr></td>
          </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap">Berita</td>
          <td><label for="berita3"></label>
            <textarea name="berita" id="berita3" cols="45" rows="5"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="left">Kode</td>
          <td valign="baseline"><label for="berita4"></label>
            <select name="kode" id="berita4">
              <option value="All" <?php if (!(strcmp("All", $row_unit['kode_unit']))) {echo "selected=\"selected\"";} ?>>Semua Unit</option>
              <?php
do {  
?>
              <option value="<?php echo $row_unit['kode_unit']?>"<?php if (!(strcmp($row_unit['kode_unit'], $row_unit['kode_unit']))) {echo "selected=\"selected\"";} ?>><?php echo $row_unit['nama_unit']?></option>
              <?php
} while ($row_unit = mysql_fetch_assoc($unit));
  $rows = mysql_num_rows($unit);
  if($rows > 0) {
      mysql_data_seek($unit, 0);
	  $row_unit = mysql_fetch_assoc($unit);
  }
?>
            </select></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">&nbsp;</td>
          <td><input type="submit" value="Input Data Running Text"  /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1" />
    </form></td>
  </tr>
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="2" cellspacing="2">
        <tr align="center">
          <td colspan="4" align="left"><h3 style="color:#033">Daftar Running Text</h3></td>
        </tr>
        <tr align="center" class="form_body">
          <td colspan="4" align="left"><hr></td>
        </tr>
        <tr height="35" align="center" class="form_body" style="background:url(images/bg1.png)">
          <td width="10%">id</td>
          <td>berita</td>
          <td width="10%">kode</td>
          <td width="10%">Proses</td>
        </tr>
        <tr align="center" class="form_body">
          <td colspan="4"><hr></td>
        </tr>
        <?php do { ?>
          <tr class="isi_tabel">
            <td align="center"><?php echo $row_runtext['id']; ?></td>
            <td><?php echo $row_runtext['berita']; ?></td>
            <td align="center"><?php echo $row_runtext['kode']; ?></td>
            <td align="center"><a href="?section=Setting&module=hapus_rtext&reg=<?php echo $row_runtext['id'];?>"><img src="images/cross.png" width="16" height="16" /></a></td>
          </tr>
          <?php } while ($row_runtext = mysql_fetch_assoc($runtext)); ?>
    </table></td>
  </tr>
</table>
<p>&nbsp;</p>

<?php
mysql_free_result($unit);

mysql_free_result($runtext);
?>
