<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/miscellaneous.class.php");
require_once ("../includes/Pager/Pager.php");

$message	= "";
$pages		= "";
$data		= array();
$array		= array();
$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$flag		= isset($_REQUEST['act'])	?	trim($_REQUEST['act'])	:	"0";
$title		= isset($_REQUEST['title'])	?	trim($_REQUEST['title'])	:	"";
$order		= isset($_REQUEST['order'])	?	trim($_REQUEST['order'])	:	"";

$image='<img src="../images/bgar.gif"></img>';
if($order=='DESC') {

    $image='<img src="../images/descar.gif"></img>';
}

else if($order=='ASC') {

    $image='<img src="../images/ascrar.gif" ></img>';

}
if (!isset($_REQUEST['page'])) {
    $_SESSION['api_search']	= "";
}

if (!$objDB) {
    $message	= "Unable to Locate Database Server.";
} else {
    $objM		= new miscellaneous($objDB);
    if ($flag == "1") {
        $message	= "<font color='green'>You have successfully saved the details</font>.<br>";
    }
    if (isset($_POST['DelNow'])) {
        $message	= $objM->delete_testimonials($_POST);
    }
    if (isset($_POST['SearchNow'])) {
        $array		= $objM->search_testimonials($_POST, true);
    } else {
        $array		= $objM->search_testimonials($_SESSION,false,$sort=$title.' '.$order);
    }
//	$array		= $objM->get_all_testimonials();
    $params 	= array(
            'mode'      => 'Sliding',
            'perPage'   => PAGESIZE,
            'urlVar'    => 'page',
            'extraVars' => array(),
            'itemData'  => $array
    );
    $objP 		= & Pager::factory($params);
    $data  		= $objP->getPageData();
    if (empty($data))
        $message	.= "No record(s) exists.<br>";
}

include_once('title.inc.php');
?>
<script type="text/javascript" src="../scripts/calendar.js"></script>
<script type="text/javascript" src="../scripts/calendar-setup.js"></script>
<script type="text/javascript" src="../scripts/calendar-en.js"></script>
<link href="../scripts/calendar.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
    function confirm_check()
    {
        var chkVar;
        for (var i = 0; i < document.form1.elements.length; i++)
        {
            var e = document.form1.elements[i];
            if (e.name == "ids[]")
            {
                if(e.checked==true)
                {
                    chkVar=true;
                }//end if
            }//end if
        }//end for loop

        if(chkVar==true)
        {
            var where_to= confirm("Do you really want to delete these testimonial(s) for permenantly??");
            if (where_to== true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }//end if
    }

    $(function(){
        // add multiple select / deselect functionality
        $("#checkAll").click(function () {
            $('.case').attr('checked', this.checked);
        });

        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        $(".case").click(function(){

            if($(".case").length == $(".case:checked").length) {
                $("#checkAll").attr("checked", "checked");
            } else {
                $("#checkAll").removeAttr("checked");
            }

        });
    });
</script>
<?php include_once('tophtml.php');?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72%" valign="top">
                        <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                        <tr>
                                            <td height="10">&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td width="41%" class="headings1" colspan="2">Testimonials</td>
                                            <!--td width="59%" align="right" class="headings1"><a href="manage_testimonial.php" class="signupbuttonlink">Add New Testimonial</a></td-->
                                        </tr>
                                    </table>
                                    <div class="bordernew padding2">
                                        <table width="100%">
                                            <tr>
                                                <td align="" class="maintext"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="search_wrapper_tbl_admin">
                                                        <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="frmSearch">
                                                            <!--tr>
                                      <th width="39%" align="left" scope="col"></th>
                                      <th width="38%" align="left" scope="col"></th>
                                      <th width="23%" scope="col">&nbsp;</th>
                                    </tr-->
                                                            <tr>
                                                                <td scope="col" width="20%">From<input name="datef" id="datef" type="text" value="<?php echo isset($objM->arrSearch['datef'])?stripslashes($objM->arrSearch['datef']):""?>" maxlength="50" readonly class="textbox">
                                                                    <input type="button" value="v" id="button1" name="button1"  class="button_stylenew" style=" width:30px;"> <script type="text/javascript" language="javascript">
                                                                        Calendar.setup({
                                                                            inputField    : "datef",
                                                                            button        : "button1",
                                                                            ifFormat      : "%m/%d/%Y",       // format of the input field
                                                                            showsTime     : false,
                                                                            timeFormat    : "24"
                                                                        });
                                                                    </script> </td>
                                                                <td scope="col" width="18%">To<input name="date" id="date" type="text" value="<?php echo isset($objM->arrSearch['date'])?stripslashes($objM->arrSearch['date']):""?>" maxlength="50" readonly class="textbox"><input type="button" value="v" id="button2" name="button2"  class="button_stylenew" style=" width:30px;">
                                                                    <script type="text/javascript" language="javascript">
                                                                        Calendar.setup({
                                                                            inputField    : "date",
                                                                            button        : "button2",
                                                                            ifFormat      : "%m/%d/%Y",       // format of the input field
                                                                            showsTime     : false,
                                                                            timeFormat    : "24"
                                                                        });
                                                                    </script>   </td>
                                                                <td scope="col" width="10%">  <input name="imageField" type="image" class="nuller" src="../images/search.gif"  border="0">                            <input type="hidden" name="SearchNow" value="SearchNow">                          </td>
                                                                <td width="30%">&nbsp;</td>
                                                                <td align="right"><a href="manage_testimonial.php" class="add-btn">Add New Testimonial</a></td>
                                                            </tr>
                                                        </form>
                                                    </table></td>
                                            </tr>
                                        </table>
                                        <form name="form1" method="post" action="" onSubmit="return confirm_check();">
                                            <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                                <tr>
                                                    <td><table width="100%"  border="0" cellspacing="1" cellpadding="0" class=" listing_tbl_admin td">
                                                            <?php 	if(isset($message) && $message!='') {
                                                                ?>
                                                            <tr align="left">
                                                                <td align="center" class="maintext2">&nbsp;</td>
                                                                <td colspan="8" class="maintext2 warning"><?php echo $message;?></td>
                                                            </tr>
                                                                <?php  	}//end if
                                                            if ($objDB) {
                                                                if (!empty($data)) {
                                                                    ?>
                                                            <tr align="left">
                                                                <th class="maintext2" align="center"><input type="checkbox" id="checkAll" name="checkAll" title="Check All / Uncheck All"/></th>
                                                                <th align="center" class="maintext2">#</th>
                                                                <th class="maintext2">Content<a href="testimonials.php?title=tContent&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                                                                <th class="maintext2">Posted By<a href="testimonials.php?title=nUser_Id&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                                                                <th class="maintext2">Date<a href="testimonials.php?title=dDay&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                                                                <th class="maintext2">Active<a href="testimonials.php?title=vActive&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                                                                <th class="maintext2" align="center">Action</strong></th>

                                                            </tr>
                                                                    <?php
                                                                    foreach ($data as $key => $value) {
                                                                        $condition="where nUser_Id='".$value['nUser_Id']."'";
                                                                        $postedBy=$objST->fetchSingleValue($objST->select_rows(TABLEPREFIX.'user','vLogin',$condition),'vLogin');
                                                                        switch($value['nUser_Id']) {
                                                                            case "0":
                                                                                $postedBy='Admin';
                                                                                $shwMsg = "";
                                                                                break;

                                                                            default:
                                                                                $postedBy=$postedBy;
                                                                                if($value['vActive']=='0' ) {
                                                                                    $shwMsg='<br><span class="warning">(Waiting for approval)</span>';
                                                                                }//endif
                                                                                else {
                                                                                    $shwMsg='';
                                                                                }//end else
                                                                                break;
                                                                        }//end switch
                                                                        ?>
                                                            <tr align="left" valign="top">

                                                                <td width="5%" align="center" class="maintext2"><input name="ids[]" class="case" type="checkbox" value="<?php echo $value['nTestimonial_Id']?>"></td>
                                                                <td width="3%" align="center" class="maintext2"><?php echo $key+1;?></td>
                                                                <td width="54%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['tContent']))?></td>
                                                                <td width="10%" class="maintext2"><?php echo $postedBy;?></td>
                                                                <td width="10%" align="left" class="maintext2"><?php echo date("m/d/Y",strtotime($value['dDay']))?></td>
                                                                <td width="8%" align="left" class="maintext2"><?php echo ($value['vActive']=='1')?"Yes":"No"; ?> <?php echo $shwMsg;?></td>
                                                                <td width="8%" align="center" valign="top" style="padding-top: 8px;" class="maintext2"><a href="manage_testimonial.php?id=<?php echo $value['nTestimonial_Id']?>&page=<?php echo $objP->getCurrentPageID()?>" class="signupbuttonlink">Edit</a></td>

                                                            </tr>
                                                                        <?php 			}//end foreach
                                                                    ?>
                                                                   <!--  <tr align="left">
                                                            <td align="center" class="maintext2">&nbsp;</td>
                                                            <td colspan="5" class="maintext2">&nbsp;</td>
                                                            <td align="center" class="maintext2"><input type="submit"  name="DelNow" value="Delete" class="loginbutton"></td>
                                                          </tr>-->
                                                                    <?php
                                                                }//end if
                                                            }//end first if
                                                            ?>
                                                        </table>
                                                        <table width="100%" cellspacing="1" cellpadding="1" border="0" style="margin-top:10px;">
                                                            <tr align="left">

                                                                <td align="left" >
                                                                    <!--
                                                                    <input type="button" name="DelNow" value="Delete" class="loginbutton" style="cursor:pointer" title="Delete Selected" onClick="deleteProducts(this.form);">
                                                                    -->
                                                                    <input type="submit" name="DelNow" value="Delete" class="loginbutton" style="cursor:pointer" title="Delete Selected" >

                                                                </td>
                                                                <td width="18%"><?php if(!empty($data)) {
                                                                        ?><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                                        <tr>
                                                                            <td width="82%">&nbsp;</td>
                                                                            <td width="18%"><table width="100%"  border="0" cellspacing="2" cellpadding="0" class="pagination_style">
                                                                                    <tr align="center" class="textbox">
                                                                                        <td><?php echo $objP->links;?></td>
                                                                                    </tr>
                                                                                </table></td>
                                                                        </tr>
                                                                    </table><?php }//end if?></td>
                                                            </tr>

                                                        </table>
                                                        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                                        <tr>
                                                                            <td>&nbsp;</td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                            </table></form>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<?php include_once('bottomhtml.php');?>