Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/new_newsitem.php
<?php
    /*******************************************************************************
     **  File          :  new_newsitem.php                                        **
     **  Author        :  R.Balaji                                                **
     **  Description   :  New news item overview of language wise.                **
  	 **  Date          :  26/07/2005                                              **
     **  Last Modified :  03/08/2005 by Ramkumar.G                                **
     **                                                                           **
     **  PHP Version   :  5.0.3                                                   **
     *******************************************************************************/

session_start();
$_SESSION['member'];
$_SESSION['usertype'];

if(!empty($_SESSION['member'])){

	include("header.php");

	//***** For Error Message****
	$err_qry="select * from events where parent='34'";
	$err_res=$pg_sql->query_pass($err_qry,"4");

	for($e=0;$e<count($err_res);$e++)
	{
	 if(trim($err_res[$e]['name'])=='delete')
       $errD=$err_res[$e][description];

    }

	//Language settings
	if($_REQUEST['lang']=='al'){
		$lang_condition = "";
		$lang = "al";
	}elseif(empty($_REQUEST['lang'])){
		$lang_condition = " where  language='".$_SESSION['lang']."'";
		$lang = $_SESSION['lang'];
	}else{
		$lang_condition = " where language='".$_REQUEST['lang']."'";
		$lang = $_REQUEST['lang'];
	}

	if($_REQUEST['id__']!="")
	{
	 $delid=$_REQUEST['id__'];

	  if(file_exists("tmp/attachments/".$delid.".jpg"))
	      unlink("tmp/attachments/".$delid.".jpg");

	  if(file_exists("tmp/attachments/".$delid.".gif"))
          unlink("tmp/attachments/".$delid.".gif");

	 $delqry="Delete from new_newsitem where newsitem_id='$delid'";
	 $del_res=$pg_sql->query_pass($delqry,"4");

	 $del_catqry="Delete from newsitem_category where newsitem_id='$delid'";
	 $del_cat_res=$pg_sql->query_pass($del_catqry,"4");

	}


?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  <tr>
    <td width="170" align="left" valign="top"><?php include("side_menu.php");?></td>
    <td valign="top" height="20"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="border">
        <tr>
          <td bgcolor="8AC4FF" height="19" class="head1">New News Item Overview</td>
        </tr>
        <tr>
          <td><form name="language" method="post">
              <table width="40%"  border="0" align="left">
                <tr>
                  <td class="contbold" nowrap>Select Language</td>
                  <td valign="middle">&nbsp;&nbsp;<select name="lang" class="cont" onChange="getlanguage()">
				  <?php
					$get_lang = "select * from public.language order by language_name";
					$lang_result = $pg_sql->query_pass($get_lang,"4");
					$lang_num = count($lang_result);
					for($i=0;$i<$lang_num;$i++){
					   if($lang_result[$i]['lang_id']==$lang){
					      $select = "Selected";
					   }else{
				   		  $select = "";
					   }
                       echo "<option value='".$lang_result[$i]['lang_id']."' ".$select.">".$lang_result[$i]['language_name']."</option>";
					}
				  ?>
                    </select></td>

                </tr>
              </table>
            </form></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
	      <td colspan="5" height="1" bgcolor="#8AC4FF"></td>
	   </tr>
        <tr>
          <td><?php

          	       if(isset($_SESSION['Keyword'])!="")
          	       {
          	                $search_id=$_SESSION['newsitem_id'];
          	                if($search_id!="")
          	                {
								$total_catqry = "select * from new_newsitem where newsitem_id in ($search_id)";
								$total_result = $pg_sql->query_pass($total_catqry,"4");
								$total_num = count($total_result);
								$limit = 30; // Set limit display news item per page
								$offset = 0;
								if($_REQUEST['offset']>0){
								   $offset = $_REQUEST['offset'];
								}
							//Order by Query build by obclick the label "channel short name" and "title"
								if($_REQUEST['orderby']=='channel_name_'){ // order asc && desce added on 01/08/2005 Ramkumar.G
								  $order="asc";
								  $orderby = "order by channel_short_name,pubdate $order";
								}elseif($_REQUEST['orderby']=='title_'){
								  $order="asc";
								  $orderby = "order by title,pubdate $order";
								}else{
								  $orderby = "order by pubdate desc";
								}

						   $news_catqry = "select * from new_newsitem where newsitem_id in ($search_id) $orderby limit $limit offset $offset";
						   $news_catres = $pg_sql->query_pass($news_catqry,"4");
						 }
						   $news_catnum = count($news_catres);
						   if($news_catnum==0)
						   {
						    $msg="No search results found for '".$_SESSION['Keyword']. "'";
						   }


          	       }
          	       else{
          	           $total_catqry = "select * from new_newsitem  $lang_condition";
					   $total_result = $pg_sql->query_pass($total_catqry,"4");
					   $total_num = count($total_result);
						$limit = 30; // Set limit display news item per page
						$offset = 0;
						if($_REQUEST['offset']>0){
						   $offset = $_REQUEST['offset'];
						}

						//Order by Query build by obclick the label "channel short name" and "title"
						if($_REQUEST['orderby']=='channel_name_'){ // order asc && desce added on 01/08/2005 Ramkumar.G
						  $order="asc";
						  $orderby = "order by channel_short_name,pubdate $order";
						}elseif($_REQUEST['orderby']=='title_'){
						  $order="desc";
						  $orderby = "order by title $order";
						}else{
						  $orderby = "order by newsitem_id desc";
						}

					   $news_catqry = "select * from new_newsitem $lang_condition $orderby limit $limit offset $offset";
					   $news_catres = $pg_sql->query_pass($news_catqry,"4");
 				   	   $news_catnum = count($news_catres);
 				   	   if($news_catnum==0)
					   {
					 	    $msg="No News items Available";
					   }
 				  }

				   if($news_catnum>0){
			?>
          </td>
        </tr>
        <tr>
          <td valign="top"><table width="100%" border="0" cellpadding="3" cellspacing="4">
              <tr>
                <td width="15%" class="contbold"><a href="new_newsitem.php?orderby=channel_name_<?=$order?>&lang=<?=$lang?>" title="Orderby Channel Name" class="contbold"><u>Channel Name</u></a></td>
                <td width="15%" class="contbold"><a href="new_newsitem.php?orderby=title_<?=$order?>&lang=<?=$lang?>" title="Orderby Title" class="contbold"><u>Title</u></a></td>
                <td width="15%" align="center" class="contbold">Production date</td>
                <td width="25%" class="contbold">URL External</td>
                <td width="15%" class="contbold">Category/Themes</td>
                <td width="15%" class="contbold">Action</td>

              </tr>
			  <tr>
			    <td colspan="6" height="1" bgcolor="#8AC4FF"></td>
			  </tr>
              <?php
			       for($cnt=0;$cnt<$news_catnum;$cnt++)
			       {
				     $newsid = $news_catres[$cnt]['newsitem_id'];
					 $cate_query="select * from newsitem_category where newsitem_id=$newsid";
					 $catitem_res=$pg_sql->query_pass($cate_query,"4");

					 for($y=0;$y<count($catitem_res);$y++)
					 {
					    if($catitem_res[$y][category_id]!="") //*** Getting category name
					    {
					  	  $cat_id=$catitem_res[$y][category_id];
					  	  $cat_nameqry="select * from category where category_id=$cat_id";
						  $cat_nameres=$pg_sql->query_pass($cat_nameqry,"4");
					      $category_name.=$cat_nameres[0]['category_name']."/";
						}
						if($catitem_res[$y][subcategory_id]!="") //*** Getting Subcategory name
						{

						  $subcat_id=$catitem_res[$y][subcategory_id];
						  $subcat_nameqry="select * from subcategory where subcategory_id=$subcat_id";
						  $subcat_nameres=$pg_sql->query_pass($subcat_nameqry,"4");
						  $subcategory_name .= $subcat_nameres[0][subcategory_name]."/";
						 }
					 }

					 $category=rtrim($category_name,"/");
 					 $subcategory=rtrim($subcategory_name,"/");

                     unset($subcat_id);
                     unset($cat_id);
					 unset($category_name);
					 unset($subcategory_name);

					 if(trim($news_catres[$cnt]['pubdate'])!="")
					 {
					 	$date=explode("-",$news_catres[$cnt]['pubdate']);
					 	$date=$date[2]."/".$date[1]."/".$date[0];
 					 }else{
 					  $date="";
 					 }

 				     $yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
  					 $yday=explode("/",$yesterday);
					 if(substr($yday[1],0,1)==0)
					  $yday[1]=str_replace("0","",$yday[1]);
					 else
					  $yday[1]=$yday[1];

					 if(strlen(trim($yday[0]))==1)
					   $yday[0] ="0".trim($yday[0]);

 		  	         $yesterday=trim($yday[0])."/".$yday[1]."/".$yday[2];

	  				 $today=date('d/n/Y');

						if($date==$today)
						  $pubdate="Today";
						elseif($date == $yesterday)
						  $pubdate="Yesterday";
						else
						 $pubdate=$date;

			  ?>
              <tr>
                <td class="cont"><?=ucfirst($news_catres[$cnt]['channel_short_name'])?></td>
                <td class="cont"><!--a href="view_article.php?newsid=<?=$newsid?>" title="View '<?=trim($news_catres[$cnt]['title'])?>' Article" class="cont"--><?=$news_catres[$cnt]['title']?><!--/a--></td>
                <td align="center" class="cont"><?=$pubdate." ".$news_catres[$cnt]['hour']?></td>
                <td class="cont"><a href="<?=$news_catres[$cnt]['url_external']?>" target="new" class="cont"><u><?=$news_catres[$cnt]['url_external']?></u></a></td>
                <td class="cont">
				<?php
				   echo trim($category."/".$subcategory,"/");

				?></td>
				<td class="cont"><a class="link" href="newsitem_edit.php?id=<?=$newsid?>" title="Edit">Edit</a>
				<?if($u_type=="A"){?>
				/<a href="new_newsitem.php?id__=<?=$newsid?>" class="link" title="Delete" onclick="return confirm('<?=$errD?>');">Delete</a>
				<?}?>
				</td>

              </tr>
              <?php

			      } // end $cnt for loop
			  ?>
			  <tr>
			  	<td colspan="6">&nbsp;
			  	</td>
			  </tr>
			  <tr>
			  	<td align="center"  valign="bottom" colspan="6">
			         <a href="javascript:PopUp('new_categorise_search.php?lang=<?=$lang?>');"><img src="images/search.jpg" alt="Search" name="search" border="0"></a>&nbsp;
              	</td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td align="right">
				<?php
				   $prev = $offset - $limit;
				   if($prev>=0){
					 $off = $offset-$limit;
					 echo "<a href='new_newsitem.php?lang=".$lang."&offset=".$off."'><img src='images/prev.jpg' border='0' alt='Prev'></a>&nbsp;&nbsp;&nbsp;";
				   }
				   $next = $offset + $limit;
				   if($next<$total_num){
					 $offset = $offset + $limit;
					 echo "<a href='new_newsitem.php?lang=".$lang."&offset=".$offset."'><img src='images/next.jpg' border='0' alt='Next'></a>&nbsp;&nbsp;";
				   }
				?>
          </td>
        </tr>
        <tr>
          <td><?php }else{ // $news_catnum else?></td>
        </tr>
        <tr>
          <td align="center" class=msg><?=$msg?></td>
        </tr>
        <tr>
          <td><?php } // $news_catnum endif ?></td>
        </tr>
      </table></td>
  </tr>
</table>
<?php
unset($_SESSION['Keyword']);
include('footer.php');
}else{
    //Empty of session redirect to login page.
	header("location:login.php");
}
?>
Return current item: News Manager - RSS aggregator