<?php
/***************************************************************************************************
  PROGRAM DESCRIPTION : PROGRAM TO DISPLAY THE EXISTING FLASHS 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

require_once("dbconnection.php"); // Make sure this contains $conn = new mysqli(...)

// Get and sanitize input
$pgmstatus = trim($_GET['pgmstatus'] ?? '');
$linkid    = intval(trim($_GET['programs'] ?? 0));
$pgmid     = intval(trim($_GET['programid'] ?? 0));
$adstatus  = trim($_GET['adstatus'] ?? '');

if (empty($pgmid)) {
    $pgmid = $_SESSION['PGMID'];
}

if (empty($adstatus)) {
    $adstatus = 'all';
}

// Approve or Reject Flash
switch ($pgmstatus) {
    case 'Approve':
        $stmt = $conn->prepare("UPDATE partners_flash SET flash_status='active' WHERE flash_id=?");
        $stmt->bind_param("i", $linkid);
        $stmt->execute();
        $stmt->close();
        break;

    case 'Reject':
        $stmt = $conn->prepare("UPDATE partners_flash SET flash_status='inactive' WHERE flash_id=?");
        $stmt->bind_param("i", $linkid);
        $stmt->execute();
        $stmt->close();
        break;
}

// Select flashs based on status
switch ($adstatus) {
    case 'active':
        $sql3 = "SELECT * FROM partners_flash WHERE flash_programid='$pgmid' AND flash_status='active' ORDER BY flash_id DESC";
        break;

    case 'inactive':
        $sql3 = "SELECT * FROM partners_flash WHERE flash_programid='$pgmid' AND flash_status='inactive' ORDER BY flash_id DESC";
        break;

    case 'all':
    default:
        $sql3 = "SELECT * FROM partners_flash WHERE flash_programid='$pgmid' ORDER BY flash_id DESC";
        break;
}
?>

<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="16" colspan="3" class="tdhead">Existing flashs</td>
</tr>

<?php
$res = $conn->query($sql3);
if ($res && $res->num_rows > 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 = $res->fetch_object()) {
        $status = stripslashes(trim($row->flash_status));
        $id     = stripslashes(trim($row->flash_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: flash flash<br/>
                URL:</b> <a href='<?= $row->flash_url ?>'><?= stripslashes($row->flash_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_flash&amp;pgmstatus=Reject&amp;programs=<?= $id ?>&amp;programid=<?= $pgmid ?>&amp;adstatus=<?= $adstatus ?>">Reject</a>
                <?php
                    } else {
                ?>
                        <a href="index.php?Act=add_flash&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'>
                <object type="application/x-shockwave-flash" data="<?= stripslashes($row->flash_url) ?>" width="468" height="60">
                    <param name="movie" value="<?= stripslashes($row->flash_url) ?>" />
                </object>
            </td>
        </tr>
        </tbody>
    </table>
<?php
    } // end 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>