<?php

include("../includes/site_config.php");
include('../session_handler.inc');
include('../message.php');
include('../error.php');

$Sess_UserType=$_SESSION['Sess_UserType'];
if ($Sess_UserType != "A") {
    exit;
}

if($_POST['action'] == 'add')
{
    restrict_demo();
    $name = mysql_escape_string($_POST['name']);
    $uri = mysql_escape_string($_POST['uri']);
    $sql_query = "INSERT INTO premium_func (prf_name, prf_uri) VALUES ('$name', '$uri')";
    mysql_query($sql_query, $link);
    echo "<script>location.href='" . $CONST_LINK_ROOT . "/admin/member_access.php'</script>";
//header('Location: '.$CONST_LINK_ROOT.'admin/member_access.php');	echo "<script> location.href='$CONST_LINK_ROOT/admin/member_access.php'</script>";
    //exit;
}
if($_POST['action'] == 'save')
{
    restrict_demo();
    $sql_result = mysql_query("SELECT prf_id FROM premium_func", $link);
    while($func = mysql_fetch_object($sql_result))
    {
        $chkName = 'active'.$func->prf_id;
        if(isset($_POST[$chkName]) && $_POST[$chkName] == '1')
            $active = 1;
        else
            $active = 0;
        $sql_query = "
            UPDATE premium_func
            SET
                prf_name = '".mysql_escape_string($_POST['name'.$func->prf_id])."',
                prf_uri = '".mysql_escape_string($_POST['uri'.$func->prf_id])."',
                prf_app = ".$_POST['app'.$func->prf_id].",
                prf_active = $active
            WHERE prf_id = $func->prf_id
        ";
        mysql_query($sql_query, $link);
    }
echo "<script>location.href='" . $CONST_LINK_ROOT . "/admin/member_access.php'</script>";
//	header('Location: '.$CONST_LINK_ROOT.'admin/member_access.php');
//	exit;
}
if($_GET['action'] == 'remove')
{
    restrict_demo();
    $prf_id = $_GET['prf_id'];
    $sql_query = "DELETE FROM premium_func WHERE prf_id = $prf_id";
    mysql_query($sql_query, $link);
    //header('Location: '.$CONST_LINK_ROOT.'/admin/member_access.php');
	echo "<script> location.href='$CONST_LINK_ROOT/admin/member_access.php'</script>";
    exit;
}

# retrieve the template
$area = 'member';

?>
<?php include("include/header.php"); ?>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Premium Access</div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="650" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
  <!--DWLayoutTable-->
  <tr>
    <td width="650">
    <table width="100%"  border="0" cellspacing="" cellpadding="">
        <?php
            $sql_result = mysql_query("SELECT * FROM premium_func", $link);
            if(mysql_num_rows($sql_result))
            {
                ?>

        <form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/member_access.php<?php print("?PHPSESSID=".session_id()); ?>" name="frmPremFunc">
          <input type="hidden" name="action" value="save">
          <tr>
            <td align="center">
    <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
                <tr  class="tdhead">                </tr>
                <tr>
                  <td rowspan="3" align="center" class="admin-head2"><div align="left">                    <?=PREMIUM_FUNC_NAME?>
                  </div></td>
                  <td rowspan="3" align="center" class="admin-head2"><div align="left">
                    <?=PREMIUM_FUNC_URI?>
                  </div></td>
                  <!--<td colspan="3" align="center" class="admin-head2"><div align="left">
                    <?=PREMIUM_FUNC_ERROR_APP?>
                    </div></td>-->
                  <td rowspan="3" align="center" class="admin-head2"><div align="left">
                    <?=PREMIUM_FUNC_ACTIVE?>
                  </div></td>
                  <td rowspan="3" align="center" class="admin-head2"><div align="left">
                    <?=PREMIUM_FUNC_ACTION?>
                  </div></td>
                </tr>

                <tr>
                 <!-- <td rowspan="2" align="center" class="normal">
                    <div align="left">
                      <?=PREMIUM_FUNC_ERROR_APP_WINDOW?>              
                    </div></td>
                  <td colspan="2" align="center" class="normal">
                    <div align="left">
                      <?=PREMIUM_FUNC_ERROR_APP_MESSAGE?>              
                    </div></td>-->
                </tr>

                <tr>
                 <!-- <td align="center" class="normal">
                    <div align="left">
                      <?=PREMIUM_FUNC_ERROR_APP_WINDOW_CLOSE?>              
                    </div></td>
                  <td align="center" class="normal">
                    <div align="left">
                      <?=PREMIUM_FUNC_ERROR_APP_WINDOW_BACK?>              
                    </div></td>-->
                </tr>

                <?php
                            while($func = mysql_fetch_object($sql_result))
                            {
                                ?>

                <tr class="normal">

                  <td><div align="left">
                    <input type="text" class="input" name="name<?=$func->prf_id?>" value="<?=htmlspecialchars($func->prf_name)?>">
                  </div></td>
                  <td><div align="left">
                    <input type="text" class="input" name="uri<?=$func->prf_id?>" value="<?=htmlspecialchars($func->prf_uri)?>">
                  </div></td>
                 <!-- <td align="center"><div align="left">-->
                    <input type="hidden" name="app<?=$func->prf_id?>" value="0"<?php if($func->prf_app == 0) echo ' checked'; ?>>
                  <!--</div></td>
                  <td align="center"><div align="left">-->
                    <input type="hidden" name="app<?=$func->prf_id?>" value="1"<?php if($func->prf_app == 1) echo ' checked'; ?>>
                 <!-- </div></td>
                  <td align="center"><div align="left">-->
                    <input type="hidden" name="app<?=$func->prf_id?>" value="2"<?php if($func->prf_app == 2) echo ' checked'; ?>>
                  <!--</div></td>-->
                  <td align="center"><div align="left">
                    <input type="checkbox" name="active<?=$func->prf_id?>" value="1"<?php if($func->prf_active) echo ' checked'; ?>>
                  </div></td>
                  <td align=""><div align="left"><a href="<?=$CONST_LINK_ROOT?>/admin/member_access.php?action=remove&prf_id=<?=$func->prf_id?>">remove</a></div></td>
                </tr>

                <?php
                            }
                            ?>
                <tr>
                  <td align="center" class="tdfoot" colspan="7"><input name="submit" type="submit" class="normal" value="<?=PREMIUM_FUNC_SAVE?>"></td>
                </tr>
              </table>            </td>
          </tr>
          <tr>
            <td align="left"></td>
          </tr>
          <tr>
            <td align="left"></td>
          </tr>
        </form>
        <?php
            }
            ?>
        <tr>
          <form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/member_access.php<?php print("?PHPSESSID=".session_id()); ?>" name="frmPremFunc">
            <input type="hidden" name="action" value="add">
            <td align="center">
    <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
                <tr>
                  <td colspan="2" class="tdhead">&nbsp;</td>
                </tr>
                <tr>
                  <td width="25%" class="admin-head2">
                    <?=PREMIUM_FUNC_NAME?>:</td>
                  <td width="75%" class="normal"><input type="text" name="name" class="inputl"></td>
                </tr>
                <tr>
                  <td class="admin-head2">
                    <?=PREMIUM_FUNC_URI?>:</td>
                  <td class="normal"><input type="text" name="uri"  class="inputl"></td>
                </tr>
                <tr>
                  <td colspan="2"   class="tdfoot" align="center"><input name="submit" type="submit" class="normal" value="<?=PREMIUM_FUNC_ADD?>"></td>
                </tr>
                </table></td>
          </form>
        </tr>
  </table>    </td>
  </tr>
  <tr>
    <td height="31">&nbsp;</td>
  </tr>
  <tr>
    <td height="33" valign="top"><span class="style1">Note: </span>If you want a feature to be only available to Premium Members, then checkbox that feature. Then only Premium Members can access that feature. For more information, refer to the Admin Guide.</td>
  </tr>
</table>
</div><div class="admin-page-bottom"></div></div>
<?php
mysql_close( $link );
?>
<?php include("include/footer.php"); ?>