<?
	session_start();
	ob_start();
	if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
		{
			header("location:login.php");
		}
	include("../include/db.inc.php");
	include("../include/pager.php");	
	include("../include/functions.php");
	$db1=new db;
    $db1->open();mysql_query("SET NAMES 'utf8'");mysql_query("SET NAMES 'utf8'");
	
if(isset($_POST['add_news']))
	{
				$title=$_POST['news_title'];
				
				$desc=$_POST['description'];
				$news_value=$_POST['news_value'];
				$news_time=$_POST['news_date'];
				$record=$_REQUEST["record"];
				if(is_uploaded_file($_FILES['image']['tmp_name'])){
					$copy=copy($_FILES['image']['tmp_name'],'../images/product/'.$_FILES['image']['name']);
					 $image=$_FILES['image']['name'];
			}else 
			$image=$_POST['image1'];
				if ($record==0)
				   {
						$sql="insert into t123go_productnews values('','$title','$desc','$news_value','$news_time',now(),'$image','0')";
						$x=@mysql_query($sql);
						if($x)
								{
								?>
									<script language="javascript">
										alert("News added successfully!");
										window.location.href="add_productnews.php?record=0";
									</script>
								<?
								}
								else
								{
								?>
									<script language="javascript">
										alert("News could not be added!\nPlease try again!");
										window.location.href="add_productnews.php?record=0");
									</script>
								<?
								}
					}
				else
				    {
							$sql="update t123go_productnews set title='$title',description='$desc',news_value='$news_value',news_date='$news_time',image='$image' where id='$record'";
							$x=@mysql_query($sql);
							if($x)
									{
									?>
										<script language="javascript">
											alert("News Updated successfully!");
											window.location.href="add_productnews.php?record=<? echo $record ; ?>";
										</script>
									<?
									}
									else
									{
									?>
										<script language="javascript">
											alert("News could not be added!\nPlease try again!");
											window.location.href="add_productnews.php?record=<? echo $record ; ?>");
										</script>
									<?
									}
					
					}			
				
	}
$record=$_REQUEST["record"];	
$sql="SELECT * FROM t123go_productnews where id='$record'";
$res=mysql_query($sql);
$data=mysql_fetch_array($res);
?>

<!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>

<title>Add News </title>
<link type="text/css" rel="stylesheet" href="../css/dhtmlgoodies_calendar.css?random=20051112" media="screen" />
<script language="JavaScript" src="../js/common.js"></script>
<script language="javascript" src="../js/dhtmlgoodies_calendar.js?random=20060118"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.a1{color:#000000}
a:hover {text-decoration: none; color:#000000}
.style3 {
	font-family: "Times New Roman", Times, serif;
	font-size: 24px;
	font-style: italic;
	color: #FFFFFF;
}
</style>

<script src="../../telebid/include/validation.js"></script>
<link href="index.css" rel="stylesheet" type="text/css"></link>
<script language="JavaScript">
function trim(str)
  {
     s = str.replace(/^(\s)*/, '');
     s = s.replace(/(\s)*$/, '');
     return s;
   }
function checkform()
  {document.form1.description.value=tinyMCE.getContent();
      if (trim(document.getElementById("news_title").value)=="")
	    {
				  alert ("Please Enter News Title");
				  document.getElementById("news_title").focus();
				  return false;
		}
	
	 else if (trim(document.getElementById("description").value)=="")
	    {
				  alert ("Please Enter News Description");
				  document.getElementById("description").focus();
				  return false;
		}
	 else
	    {
		   return true;
		}
  }


</script>
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "spellchecker,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable",
		theme_advanced_buttons1_add_before : "save,newdocument,separator",
		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,spellchecker",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_path_location : "bottom",
		content_css : "/example_data/example_full.css",
	    plugin_insertdate_dateFormat : "%Y-%m-%d",
	    plugin_insertdate_timeFormat : "%H:%M:%S",
		extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
		external_link_list_url : "example_data/example_link_list.js",
		external_image_list_url : "example_data/example_image_list.js",
		flash_external_list_url : "example_data/example_flash_list.js",
		file_browser_callback : "mcFileManager.filebrowserCallBack",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : true,
		apply_source_formatting : true,
		spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
	});
	
</script>
</head>
<body >

<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum">

<!-- ImageReady Slices (NEWADMIN.psd) -->
<table id="Table_01" width="100%" border="0" cellpadding="0" cellspacing="0" align="center">

    <tr>
		
	   <td width="80%" bgcolor="#FFFFFF" valign="top">
        <form name="form1" method="post" action="" enctype="multipart/form-data" onSubmit="return checkform();">
		<input type="hidden" name="record" value="<?php echo $_REQUEST["record"]; ?>">
		<input type="hidden" name="image1" value="<?php echo $data['image'];  ?>">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
                <td background="img/bg01.gif"><strong>&nbsp;<? if ($record==0) { echo "Add News"; } else { echo "Edit News"; }   ?></strong></td>
                <td width="35"><img src="img/04.gif" width="35" height="23"></td>
              </tr>
            </table>

                  <table width="86%" align="center">
                    
                    <tr>
                      <td width="42%" class="normaltextnotbold"  >Enter News Title </td>
                      <td width="58%" class="normaltextnotbold" ><input type="text"  name="news_title" id="news_title" value="<?php echo $data['title']; ?>" size="100" maxlength="255"   /></td>
                    </tr>
					<tr>
                      <td class="normaltextnotbold" >Description</td>
                      <td >
          	<textarea name="description" style="width:600px" id="description" ><?php echo $data['description']; ?></textarea>
          </td>
                    </tr>
					 <tr>
                      <td width="32%" class="normaltextnotbold"  >Product Value </td>
                      <td width="68%" class="normaltextnotbold" ><input type="text"  name="news_value" id="news_title" value="<?php echo $data['news_value']; ?>" size="100" maxlength="255"   /></td>
                    </tr>
					 <tr>
                      <td width="32%" class="normaltextnotbold"  >Launch Date </td>
                      <td width="68%" class="normaltextnotbold" ><input type="text"  name="news_date" id="news_title" value="<?php echo $data['news_date']; ?>" size="100" maxlength="255"   /><small>
                                <input type="button" value="Cal" onClick="displayCalendar(document.form1.news_date,'yyyy/mm/dd hh:ii',this,true)">
                                </small>
					  </td>
                    </tr>
					<tr>
                      <td class="normaltextnotbold" >Image</td>
                      <td >
          	 <input name="image" type="file"   size="35">
          </td>
                    </tr>
					
                   
          </table>
		   <br>
		  <table width="80%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" align="center">
                      <tr>
                        <td align="center" bgcolor="#EDEDED"> 
                          <input type="submit"   name="add_news" value="<? if ($record==0) { echo "Add News"; } else { echo "Save News"; }   ?>" />
                          &nbsp;
                          <input name="back" type="button"  onClick="window.location.href='product_news.php'" value="Back To List"> </td>
                      </tr>
                  </table>

<br/>
		 
          </form>
        </td>
    </tr>
   
</table>
<!-- End ImageReady Slices -->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>

</html>
</div>
</body>
</html>
