<?php include 'inc_classes.php';
$action=$_POST['action'];

if($action=='add_leave_comments')
{
    $staff_id=$_POST['staff_id'];
    $leave_id=$_POST['leave_id'];
    $comment=rawurldecode($_POST['comment']);

    $insert_data="INSERT INTO `pr_comment_box`(`comment`, `leave_id`,`admin_id`, `cm_id`, `added_date`) VALUES ('".$comment."','".$leave_id."','". $staff_id."','".$_SESSION['cm_id']."','".date('Y-m-d H:i:s')."')";
    $ptr_query=mysql_query($insert_data);

    //echo "Record added successfully";

}
if($action=='show_leave_comments')
{
    $leave_id=$_POST['leave_id'];
    $t=1;
    $sel_app="select * from pr_comment_box where 1 and leave_id='".$leave_id."'";
    $ptr_app=mysql_query($sel_app);
    while($data_app=mysql_fetch_array($ptr_app))
    {
        $sel_staff="select name from site_setting where 1 and admin_id='".$data_app['admin_id']."'";
        $ptr_staff=mysql_query($sel_staff);
        $data_staff=mysql_fetch_array($ptr_staff);

        $sel_admin_id="select admin_id from pr_apply_leave where leave_id='".$data_app['leave_id']."' ";
        $ptr_admin_id=mysql_query($sel_admin_id);
        $data_admin_leave=mysql_fetch_array($ptr_admin_id);
        //echo $data_admin_leave['admin_id']."==".$data_app['admin_id'];
        if($data_admin_leave['admin_id']==$data_app['admin_id'])
        {
            ?>
            <!-- coment by user -->
            <div class="item" id="comment_user" style="border-bottom: 0.5px solid gainsboro;margin-bottom:0px !important">
                <p class="message" style="margin-right: 20px; !important;display:inline-block !important; vertical-align:middle !important; width:99%; text-align:right;margin-top:15px !important; margin-left:15px !important">
                    <a href="#" class="name" style="text-align: right; margin-right:20px !important; margin-right:0px !important">
                    <small class="text-muted pull-left"><i class="fa fa-clock-o"></i> <?php echo $data_app['added_date']; ?> </small>
                    <?php echo $data_staff['name']; ?>
                    </a>
                    <?php echo $data_app['comment']; ?>
                </p>
                    <!-- <img src="dist/img/user2-160x160.jpg" alt="user image" class="offline"> -->
                </div>
                <!-- /.item -->
            </div>
            <?php
        }
        else
        {

        ?>
        <div class="item" style="border-bottom: 0.5px solid gainsboro;margin-bottom:0px !important">
            <!-- <img src="dist/img/user2-160x160.jpg" alt="user image" class="offline"> -->

            <p class="message" style="margin-top:15px !important; margin-left:15px !important">
                <a href="#" class="name">
                <small class="text-muted pull-right"><i class="fa fa-clock-o"></i> <?php echo $data_app['added_date']; ?> </small>
                <?php echo $data_staff['name']; ?>
                </a>
                <?php echo $data_app['comment']; ?>
            </p>
        </div>
        <?php
        }
        $t++;
    }
}

if($action=='Approved')
{
    $status= "Approved";
    $comment=$_POST['comment'];
    $leave_id=$_POST['leave_id'];

    $insert_salary="UPDATE `pr_apply_leave` set `status`= '$status'  where `leave_id`=' $leave_id'";
    $ptr_ins=mysql_query($insert_salary);
    // echo "leave Approved successfully";

}
if($action=='Reject')
{
    $status= 'Rejected';
     $comment=$_POST['comment'];
     $leave_id=$_POST['leave_id'];


     $insert_salary="UPDATE `pr_apply_leave` set `status`= '$status' where `leave_id`=' $leave_id'";
     $ptr_ins=mysql_query($insert_salary);
}
    //echo "Record added successfully";


?>
