Expand|Select|Wrap|Line Numbers
- <?php
- include "includes/connection.php";
- include "includes/Functions_category.php";
- include "includes/functions_db.php";
- $Strtitle="Category Management (Category Listing)";
- $strAddedDate=date("Y-m-d h:m:s");
- if($_POST['frmcheckall']){
- print doDeleteAll($_POST);
- }
- if(isset($_GET['id'])){
- //if($_POST['id']){
- //$strDelete=doDeleteAll['id'];
- // }
- if(!doDelete($_GET['id'])){$strMessage= "Invalid Inputs Detected!";}
- }
Expand|Select|Wrap|Line Numbers
- <link href="css/fonts.css" rel="stylesheet" type="text/css">
- <script type="text/javascript">
- function checkAll(field){
- field=document.frmcategory.frmcheckall;
- for (i = 0; i < field.length; i++){
- field[i].checked = true;
- highlightRow('frmcheckall'+i,'frmcheck'+i);
- }
- }
- function uncheckAll(field){
- field=document.frmcategory.frmcheckall;
- for (i = 0; i < field.length; i++){
- field[i].checked = false;
- highlightRow('frmcheckall'+i,'frmcheck'+i);
- }
- }
- /*function deleteall(field){
- field=document.frmcateogry.frmcheckall;
- flag=0;
- for(i=0;i< field.length;i++){
- if(field[i].checked)
- flag=1;
- }
- if(flag==1){
- alert("Hi");
- document.frmcateogry.frmcheckall.submit();
- }else
- alert("Please select one category to Delete");
- }*/
- function deleted(field){
- //field=document.frmcategory.frmcheckall;
- flag=0;
- for(i=0;i< field.length;i++){
- if(field[i].checked)
- flag=1;
- }
- if(flag==1){
- if(confirm("Are You Sure To Delete The Category List?")){
- field.submit();
- }
- }else
- alert("Please Select One Category To DELETE");
- }
- function highlightRow(id,id1) { //alert(id1);
- if (document.getElementById(id).checked) {
- document.getElementById(id1).bgColor = '#E2E6A8';
- }
- else {
- document.getElementById(id1).bgColor = '#FFFFFF';
- }
- }
- function deleteConfirm(delUrl) {
- if (confirm("Are You Sure To Delete This Category?")) {
- document.location = delUrl;
- }
- }
- </script>
- <form name="frmcategory" method="post" action="">
- <table width="90%" border="0" cellspacing="3" cellpadding="3" align="center">
- <tr><td><? print $strMessage ;?></td></tr>
- <tr>
- <td align="center">
- <?
- $strQuery="select * from tbl_categories where IsDeleted='No'";
- $strValue=SelectQry($strQuery);
- if(is_array($strValue)){
- ?>
- <span class="tablehead">Category List</span></td>
- </tr>
- </table>
- <div align="center">
- <table width="414" height="20" border="0" cellpadding="0" cellspacing="0" class="size">
- <tr>
- <td width="414" class="headerfont"><a href="javascript:onclick=checkAll();" class="headerfont">SELECT
- ALL | </a><a href="javascript:onclick=uncheckAll();" class="headerfont">UNSELECT
- ALL </a>| <a href="javascript:onclick=deleted(frmcategory);" class="headerfont">DELETE
- SELECTED </a></td>
- </tr>
- </table>
- </div>
- <table width="421" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#999999" class="headerfont" style="border-collapse:collapse">
- <tr class="tablehead">
- <td width="44" height="29"> </td>
- <td width="278" align="center">CATEGORY NAME </td>
- <td width="179" align="center">ACTION </td>
- </tr>
- <?
- //while($rows = mysql_fetch_object($stredit)){
- for($i=0;$i<count($strValue);$i++) {
- ?>
- <tr class="tablehead" id="frmcheck<?php print $i; ?>">
- <td height="25" align="center"><input name="frmcheckall" type="checkbox" id="frmcheckall<?php print $i; ?>" value="<? print $strValue[$i]['CategoryId']; ?>" onclick="highlightRow('frmcheckall<?php print $i; ?>','frmcheck<?php print $i; ?>');" />
- </td>
- <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
- <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
- | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
- </a> </td>
- </tr>
- <?
- }
- //mysql_free_result($stredit);
- ?>
- <tr align="left" class="tablehead">
- <td height="25" colspan="3"><span class="tablecontent2"><a href="javascript:onclick=checkAll();" class="size">Select
- all | </a><a href="javascript:onclick=uncheckAll();" class="size">UnSelect
- All</a> | <a href="javascript:onclick=deleted(frmcategory);" class="size">Delete
- SELECTED </a></span>
- <div align="center"></div>
- <div align="center"></div></td>
- </tr>
- <? }else{?>
- <font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="#FF0000">
- <center>
- <? print "Sorry!No Records Found !!!";?>
- </center>
- </font>
- <? }?>
- </table>
- <p class="headerfont"> </p>
- </form>
and this is the function category coding
Expand|Select|Wrap|Line Numbers
- <?
- function CheckCategory($objArray){
- $QryCheck="SELECT *
- FROM
- tbl_categories
- WHERE
- CategoryName ='".$objArray["frmCategoryName"]."'
- AND
- CategoryId <> '" .$_GET['id']."'
- AND IsDeleted='No'";
- $ResCheck = SelectQry($QryCheck);//Calling the Functions_db
- if(is_array($ResCheck))
- return 1;
- else
- return 0;
- }
- function InsertCategory($objArray){
- $strAddedDate = date("Y-m-d h:m:s");
- $strAddedIP = $_SERVER['REMOTE_ADDR'];
- $QryInsert = "INSERT
- INTO
- tbl_categories(
- CategoryName,
- CategoryDescription,
- AddedDate,
- AddedIP
- )
- VALUES
- ('".$objArray["frmCategoryName"]."',
- '".$objArray["frmCategoryDescription"]."',
- '".$strAddedDate."',
- '".$strAddedIP."')";
- if(ExecuteQry($QryInsert))//calling the functions Execute Query
- return 1;
- else
- return 0;
- }
- function getCategoryList() {
- $QryCategory = "SELECT *
- FROM
- tbl_categories
- ORDER BY
- CategoryId ";
- $ResultCategory = SelectQry($QyrCategory);
- if(is_array($ResultCategory)) {
- return $ResultCategory;
- }
- else {
- return 0;
- }
- }
- function CheckUpdateCategory($objArray) {
- $Query = "UPDATE
- tbl_categories
- SET
- CategoryName = '".$objArray["frmCategoryName"]."',
- CategoryDescription = '".$objArray["frmCategoryDescription"]."',
- AddedDate = '".$strAddedDate."'
- WHERE
- tbl_categories. CategoryId= '".$_GET['id']."'
- ";
- if(ExecuteQry($Query))
- return 1;
- else
- return 0;
- }
- function doDeleteAll($objArray){
- foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
- $strDeleteId = $strValue;
- doDelete($strDeleteId);
- //print_r($strDeleteId);
- /*$strQuery= "UPDATE
- tbl_categories
- SET
- IsDeleted = 'Yes'
- WHERE
- Ident =".$strDeleteId."
- LIMIT 1";*/
- //doDelete($objGetArray['id']);
- /*if(doDelete($objGetArray['id'])){
- return 1;
- //print_r(($objGetArray['id']));
- }
- else{
- return 0;}*/
- }
- }
- /*function doDelete($objGetArray){
- if(is_numeric($objGetArray['id'])){
- $strQuery="SELECT *
- FROM
- tbl_categories
- WHERE
- Ident=".$objGetArray['id'];
- $strRows = SelectQry($strQuery);
- if(is_array($strRows)){
- $strQuery = "UPDATE
- tbl_categories
- SET
- IsDeleted = 'Yes'
- WHERE
- Ident =".$objGetArray['id']."
- LIMIT 1";
- ExecuteQry($strQuery);
- return 1;
- }else{
- return 0;
- }
- }else{
- return 0;
- }
- } */
- function doDelete($strDeleteId){
- //print_r($objGetArray);
- //if($objGetArray['id']){
- $strQuery = "UPDATE
- tbl_categories
- SET
- IsDeleted = 'Yes'
- WHERE
- CategoryId = '".$strDeleteId."'";
- // print_r($strQuery);
- if(ExecuteQry($strQuery))
- return 1;
- else
- return 0;
- }
- function CheckId($objArray) {
- $strAddedDate=date("Y-m-d h:m:s");
- $strIp=$_SERVER['REMOTE_ADDR'];
- if(is_numeric($_GET[id])){
- $Query = "SELECT *
- FROM
- tbl_categories
- WHERE
- CategoryId=".$_GET['id'] ;
- $strRecords = SelectQry($Query );
- if(!is_array($strRecords)) {
- return 0;
- }else{
- ExecuteQry($Query);
- return $strRecords;
- }
- }
- }
- ?>