<?php
include("../includes/site_config.php");
include('../session_handler.inc');
include ('../functions.php');//include ('../includes/functions.php');
//include('../lib/lib.Functions.php');
include('../languages/english_admin.php');
include('../error.php');
include_once __INCLUDE_CLASS_PATH."/class.Banner.php";

/*if(!isset($_REQUEST['format']))
{
$_REQUEST['format']='Right';
}*/

$db =& db::getInstance();
/*
if ($Sess_UserType != "A") {
    exit;
}*/

$id = form_get('id');
//$id = $_GET['id'];
if (isset($_REQUEST['active'])) $active = 1;

switch ($_REQUEST['act']) {
    case 'save':
        $banner = new Banner($id);
        if ($banner->save($_REQUEST['format'], $_REQUEST['lable'], $_REQUEST['code'], $_REQUEST['hits'], $_REQUEST['active'], $_REQUEST['align'], $_REQUEST['url'])) {
            //redirect($CONST_LINK_ROOT.'/admin/admin_banners.php');
			echo "<script>location.href=\"admin_banners.php\"</script>";
            break;}
			
			case 'edit':
        $banner = new Banner($id);

        $db->query("UPDATE bannercodes 
                       SET size = '".$_REQUEST['format']."',
                           label = '".$_REQUEST['lable']."',
                           code = '".$_REQUEST['code']."',
                           hits = '".$_REQUEST['hits']."',
                           is_active = '$active',
						align = '".$_REQUEST['align']."',
						url = '".$_REQUEST['url']."'	
                     WHERE banner_id = '".$_REQUEST['id']."'");
       // return true;
			echo "<script>location.href=\"admin_banners.php\"</script>";
            break;
        //else error_page(join("<br>",$banner->error),GENERAL_USER_ERROR);
    default:
        //$format = formGet('format');		
$format = $_GET['format'];
        if ($id) $banner = Banner::getByID($id);
        $bannerSizeOptions = Banner::getSizeOptions();

}

# retrieve the template
$area = 'member';

$sql_result = mysql_query("SELECT * FROM stories", $link);

?><?php include("include/header.php"); ?>

<script language="javascript">
function Validate_Banner(){
if (document.banner.align) {
    if (document.banner.align.selected == 'select' ) {
                alert("Select Position");
                document.banner.align.focus();
                return (false);
   		}

	}
}

function getformat(k){
var format=k;

location.href='<?=$_SERVER['PHP_SELF']?>?format='+k;
}

</script>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Edit Banner</div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">

    <tr>
      <td><table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
        <form method="post" name="banner" action="<?php echo $CONST_LINK_ROOT?>/admin/admin_banners_edit.php<?php print("?PHPSESSID=".session_id());  ?>" >
        <?php
		if(!isset($_REQUEST['id'])){
		?>
          <input type="hidden" name="act" value="save">
		<?php
		}
		else
		{
		?>
			<input type="hidden" name="act" value="edit">
		<?php
		}
		?>		 
          <input type="hidden" name="id" value="<?=$id?>">
          <tr>
            <td align="left">

       <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 class="teven">
                  <td><?=SD_ADM_BANNER_ALIGN?></td>
                  <td>
				  <? //if(isset($_REQUEST['id'])) {?> 
				  <select  name="align" size="1"  > 
				  <? //} else{?>
				 <!-- <select  name="align" size="1"  onchange="getformat(this.value);">-->
				   <? //}?>
                      <option value="select"> -- Select --</option>
                      <option value="Right" <? if ($_REQUEST['format']=='Right' || $banner->align=='Right') print "selected";?>>Right</option>
                      <option value="Below" <? if ($_REQUEST['format']=='Below' || $banner->align=='Below') print "selected";?> >Below</option>
                      <option value="Home Standard" <? if ($_REQUEST['format']=='Home Standard' || $banner->align=='Home Standard') print "selected";?>>Home Standard</option>
                      <option value="Home Premium" <? if ($_REQUEST['format']=='Home Premium' || $banner->align=='Home Premium') print "selected";?>>Home Premium</option>
                      <?php
                    
                    ?>
                  </select></td>
                </tr>
                <tr class="teven">
                  <td><?=SD_ADM_BANNER_FORMAT?></td>
				 
                  <td><select name="format">
				  
                    <?php
                    foreach ($bannerSizeOptions as $k=>$v)
					
                        echo "<option value=\"$k\"".(($banner->size == $k) ? ' selected' : '').">".$v;
                    ?>
                  </select></td><? echo $banner->align;?>                </tr>
                <tr class="normal">
                  <td>
                    <?=SD_ADM_BANNER_TITLE?>                  </td>
                  <td> <input name="lable" type="text" class="input" value="<?=htmlspecialchars($banner->label)?>"></td>
                </tr>
                <tr class="normal">
                  <td>
                    <?=SD_ADM_BANNER_CODE?>                  </td>
                  <td> <textarea name="code" cols="50" rows="10" wrap="soft" class="inputl"><?=htmlspecialchars($banner->code)?></textarea></td>
                </tr>
                <!--<tr class="normal">
                  <td>Banner Url: </td>
                  <td><input name="url" type="text" class="input" value="<?=htmlspecialchars($banner->url)?>"></td>
                </tr>-->
                <tr class="normal">
                  <td>
                    <?=SD_ADM_BANNER_HITS?>                  </td>
                  <td> <input name="hits" type="text" class="input" value="<?=htmlspecialchars($banner->hits)?>"></td>
                </tr>
                <tr class="normal">
                  <td>
                    <?=SD_ADM_BANNER_ACTIVE?>                  </td>
                  <td> <input name="active" type="checkbox"<?= $banner->is_active ? ' checked' : ''?>></td>
                </tr>
                <tr class="normal">
                  <td>                  </td>
                </tr>
                <tr>
                  <td colspan="2" align="center" class="tdfoot"> 
				   <? if($DEMO==false){?>
       <input name="submit" type="submit" class="normal" value="<?=GENERAL_SAVE?>"  onClick="return Validate_Banner();"><? }else{?>
		<input type="button" class='normal'  title="Can't Upload in Demo mode"  value="<?=GENERAL_SAVE?>">
		<? }?>
                    <input name="normal" type="button" class="normal" onclick="window.location = '<?=$CONST_LINK_ROOT?>/admin/admin_banners.php'" value="<?=GENERAL_CANCEL?>">                  </td>
                </tr>
              </table></td>
          </tr>
        </form>
      </table></td>
    </tr>
</table></div><div class="admin-page-bottom"></div></div>
<?php include("include/footer.php"); ?>
