<?php
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');
$obj = new DBClass();
$dat = date('Y-m-d');
$headin = 'Add Hindi News';
$buton = 'Add Hindi News';
?>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">


<?php 
if(isset($_GET['msg'])){
	if($_GET['msg'] == add){
		$info[] = 'News Added Successfully';
	}
}
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_hi');

mysql_select_db('anyphpwo_coaldb',$link);

$sql1 = "SELECT * FROM news_hindi";
$rs1 = $obj->executeQry($sql1,$link);
$row1 = $obj->fetchrow();	 

$cupage = 'news';
if(isset($_GET['action']) && $_GET['action'] == 'edit'){
	$headin = 'Edit Hindi News';
	$buton = 'Edit Hindi News';
	$obj2 = new DBClass();
	$sql = "SELECT * FROM news_hindi WHERE id = '".$_GET['id']."' ";
	$rs = $obj2->executeQry($sql,$link);
	$row = $obj2->fetchrow();
}

if(isset($_POST['submit'])){
        $valid = validmess($_POST['title'], "Title"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
	$valid = validmess($_POST['news'], "News"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
	if($error == ''){
		if($_POST['submit'] == 'Add Hindi News'){
			$sql1 = "SELECT * FROM news_hindi WHERE title = '".$_POST['title']."'";
			$rs1 = $obj->executeQry($sql1,$link);
			$row1 = $obj->fetchrow();	
			if($row1['title'] == $_POST['title']){
				$error[] = 'News with same title already exist...';
			} else {
				$sqll = "INSERT INTO news_hindi (title,added_date,news) VALUES ('".trim($_POST['title'])."','".trim($_POST['added_date'])."','".trim($_POST['news'])."') ";
				$rs2 = $obj->executeQry($sqll,$link);
				if($rs2){
					if($_POST['last'] == 'yes') {
						@header('Location: news_hindi.php?msg=add');
					} else {
					@header('Location: add_hindi_news.php?msg=add');
					}
				}
			}
		}
	
		if($_POST['submit'] == 'Edit Hindi News'){
			$sqll = "UPDATE news_hindi SET title = '".trim($_POST['title'])."',added_date = '".trim($_POST['added_date'])."', news = '".trim($_POST['news'])."' WHERE id = '".$_GET['id']."'";
			$rs2 = $obj->executeQry($sqll,$link);
			if($rs2){
				@header('Location: news_hindi.php?msg=edit');
			}
		}
	}	
}

require_once(INCLUDES_DIR.ADMHEADER); 
include_once(ABS_ROOT_PATH."fckeditor/fckeditor.php") ;
?>
<link href="<?=EDITOR_DIR;?>sample.css" rel="stylesheet" type="text/css" />
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" align="center" class="submenu"><a href="news_hindi.php">Manage News</a></td>
    <td align="center" class="submenu">Add HIndi News</td>
  </tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="17"></td>
  </tr>
  <tr>
    <td><table width="910" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="pagehead"><table width="900" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="315" height="35"><?php echo $headin;?></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#FFFFFF" class="innermain"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25"><?php ShowError($error); ShowInfo($info);?></td>
          </tr>
	<form name="pageform" id="pageform" method="post" enctype="multipart/form-data" action="<?php echo $cpage;?>">
          <tr>
            <td valign="top" class="bdr4"><table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td bgcolor="#990066" class="form_head">News Title</td>
                </tr>
              <tr>
                <td valign="top" class="form_bg"><table width="500" border="0" cellpadding="0" cellspacing="0" class="form_txt1">
                  <tr>
                    <td align="left" width="20%">News Title: </td>
                    <td align="left" width="80%"><input type="text" name="title" id="title" value="<?php echo ($_POST['title'] == '') ? $row['title'] : $_POST['title']; ?>" /></td>
                    </tr>
					 <tr>
                    <td align="left" width="20%">News Date: </td>
                    <td align="left" width="80%"><input type="text" name="added_date" id="added_date" value="<?php if(isset($row['added_date']) && ($row['added_date'] != '')) { echo $row['added_date']; } else {  echo date('Y-m-d'); } ?>" /></td>
                    </tr>
					 <tr>
                    <td align="left" width="20%">Last News: </td>
                    <td align="left" width="80%"><input type="checkbox" name="last" id="last" value="yes"/></td>
                    </tr>
                        </table></td>
              </tr>
              <tr>
                <td bgcolor="#990066" class="form_head">News</td>
              </tr>
              <tr>
                <td valign="top" class="form_bg"><table width="500" border="0" cellpadding="0" cellspacing="0" class="form_txt1">
                  <tr>
                    <td colspan="2" align="center">
				<?php
				$oFCKeditor = new FCKeditor('news') ;
				$oFCKeditor->BasePath =  SITE_URL.'fckeditor/' ;
				$oFCKeditor->Width = 600;
				$oFCKeditor->Height = 400;
				$oFCKeditor->Value = ($_POST['news'] == '') ? html_entity_decode(stripslashes($row['news'])) : $_POST['news'];
				$oFCKeditor->Create() ;
				?>				
			</td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td align="right" valign="top" class="form_bg"><table width="500" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td align="center"><input name="submit" type="submit" class="bg_bt" id="button" value="<?php echo $buton;?>" /></td>
                  </tr>
                  </table></td>
              </tr>
</form>
              </table></td>
          </tr>
          </table></td>
      </tr>
      </table></td>
  </tr>
  <tr>
    <td height="40">&nbsp;</td>
  </tr>
</table>

<?php require_once(INCLUDES_DIR.ADMFOOTER); ?>