<?php
/***************************************************************************************************
 PROGRAM DESCRIPTION :  PROGRAM TO DISPLAY THE EXISTING BANNERS OF A SELECTED PROGRAM(PROGRAM.PHP)
                       SO THAT ADMIN CAN MANUALLY CHECK IT AND APPROVE/REJECT.
 VARIABLES          : pgmstatus       = AD STATUS(APPROVE OR REJECT)
                       linkid,id       = AD ID
                       status          = AD status
***************************************************************************************************/

// Added by SMA on 14-JUly-2006 for Admin Users
$userobj = new adminuser();
$adminUserId = $_SESSION['ADMINUSERID'];
// End Add on 14-July-2006

/***********GETTING AD STATUS AND LINKID***************/
$pgmstatus = trim($_GET['pgmstatus']);           // AD STATUS(APPROVE OR REJECT)
$linkid = intval(trim($_GET['programs']));       // AD ID
$pgmid = intval(trim($_GET['programid']));
$adstatus = trim($_GET['adstatus']);
if (empty($pgmid))
    $pgmid = $_SESSION['PGMID'];

if (empty($adstatus))
    $adstatus = 'all';
/*********************END*******************************/


/*******************APPROVING OR REJECTING ADDS **************************************/
switch ($pgmstatus) {
    case 'Approve':    // APPROVING ADDS
        $sql = "UPDATE partners_banner SET banner_status='active' WHERE banner_id='$linkid'";
        mysqli_query($conn, $sql) or die($sql . "<br/>" . mysqli_error($conn));
        break;

    case 'Reject':    // REJECTING ADDS
        $sql = "UPDATE partners_banner SET banner_status='inactive' WHERE banner_id='$linkid'";
        mysqli_query($conn, $sql) or die($sql . "<br/>" . mysqli_error($conn));
        break;
}
/*******************APPROVING OR REJECTING ADDS **************************************/


/*******************FILTERING BANNERS **************************************/
switch ($adstatus) {
    case 'active':
        $sql3 = "SELECT * FROM partners_banner WHERE banner_programid='$pgmid' AND banner_status='active' ORDER BY banner_id DESC";
        break;

    case 'inactive':
        $sql3 = "SELECT * FROM partners_banner WHERE banner_programid='$pgmid' AND banner_status='inactive' ORDER BY banner_id DESC";
        break;

    case 'all':
    default:
        $sql3 = "SELECT * FROM partners_banner WHERE banner_programid='$pgmid' ORDER BY banner_id DESC";
        break;
}
/*******************END FILTERING BANNERS **************************************/
?>


<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<div align="center">
    <center>
        <table border='0' cellpadding="0" cellspacing="0" style="border-collapse: collapse; text-align: center" width="77%" id="AutoNumber4" class="tablebdr">
            <tr>
                <td width="100%" height="18" colspan="3" class="tdhead">Existing Banners</td>
            </tr>

            <?php
            $res = mysqli_query($conn, $sql3);

            if (mysqli_num_rows($res) > 0) {
            ?>

                <tr>
                    <td width="100%" height="18" colspan="3"></td>
                </tr>
                <tr>
                    <td width="2%" height="19">&nbsp;</td>
                    <td width="97%" height="19">

                        <?php while ($row = mysqli_fetch_object($res)) {
                            $status = stripslashes(trim($row->banner_status));
                            $id = stripslashes(trim($row->banner_id));
                        ?>
                            <table cellspacing="0" cellpadding="5" width='622' class="tablebdr">
                                <tbody>
                                    <tr>
                                        <td height='1' width='300' bgcolor="#FFFFFF" class="grid1">
                                            <span class='text'><b>Type:</b>Banners<b><br />
                                                    URL:</b> <a href='<?= $row->banner_url ?>' target="new">
                                                    <?= stripslashes($row->banner_url) ?></a></span>
                                        </td>
                                        <td height='1' width='302' bgcolor="#FFFFFF" class="grid1" align="right">
                                            <?php
                                            if ($userobj->GetAdminUserLink('Approve/Reject Links', $adminUserId, 3)) {
                                                if ($status == "active") {
                                            ?>
                                                    <a href="index.php?Act=add_banner&amp;pgmstatus=Reject&amp;programs=<?= $id ?>&amp;programid=<?= $pgmid ?>&amp;adstatus=<?= $adstatus ?>">Reject</a>
                                                <?php
                                                } else {
                                                ?>
                                                    <a href="index.php?Act=add_banner&amp;pgmstatus=Approve&amp;programs=<?= $id ?>&amp;programid=<?= $pgmid ?>&amp;adstatus=<?= $adstatus ?>">Approve</a>
                                            <?php
                                                }
                                            }
                                            ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" height='69' width='608'><a href='<?= stripslashes($row->banner_url) ?>'>
                                                <img src="<?= stripslashes($row->banner_name) ?>" border='0' width="<?= $row->banner_width ?>" alt="" height="<?= $row->banner_height ?>" /></a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        <?php
                        } // while
                        ?>
                    </td>
                    <td width="1%" height="19">&nbsp;</td>
                </tr>
                <tr>
                    <td width="2%" height="19">&nbsp;</td>
                    <td width="97%" height="19">&nbsp;</td>
                    <td width="1%" height="19"></td>
                </tr>
                <tr>
                    <td width="100%" height="19" colspan="3" class="tdhead">&nbsp;</td>
                </tr>
            <?php
            } else {
            ?>
                <tr>
                    <td width="100%" align="center" class="textred" colspan="3"><?= $norec ?></td>
                </tr>
            <?php
            }
            ?>

        </table>
    </center>
</div>