<?php

//ini_set("display_errors", 1);

include("../includes/site_config.php");
include('../session_handler.inc');
include ('../functions.php');
include('../error.php');
include('../languages/english_admin.php');
include('../message.php');
include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = new DB();
include_once __INCLUDE_CLASS_PATH."/class.Banner.php";
$Sess_UserType=$_SESSION['Sess_UserType'];

if ($Sess_UserType != "A") {
    exit;
}

if(isset($_GET['act'])){
restrict_demo(); 

$db->query("DELETE FROM bannercodes WHERE banner_id = '".Main::_PrepareData(form_get('id'))."'");

}
$format = form_get('format');
$banners = Banner::getList($format);
/*switch ($_GET['act']) {

    case 'remove':
        $db->query("DELETE FROM bannercodes WHERE banner_id = '".Main::_PrepareData($_REQUEST['id'])."'");
    
	default:
        $format = $_REQUEST['format'];
        $banners = Banner::getList($format);
		
		
}*/
# retrieve the template
$area = 'member';


# CODE FOR ADD BANNER 
$id = form_get('id');
if (isset($_REQUEST['active'])) $active = 1;

$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>";
			}
$format = $_GET['format'];
        if ($id) $banner = Banner::getByID($id);
        $bannerSizeOptions = Banner::getSizeOptions();


?>
<?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;Banner Admin</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"); ?>">
	<tr><td height="10px"></td></tr>
    <tr>
      <td>

       <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">

   <!-- <tr>
      <td colspan="5" align="center" class="tdhead">
        <input type="normal" class='normal' onclick="document.location = '<?=$CONST_LINK_ROOT?>/admin/admin_banners_edit.php'" value="<?=SD_ADM_BANNERS_ADD?>">-->
      </td>
    </tr>
    <tr>
      <td class="admin-head2"><?=SD_ADM_BANNER_TITLE?></td>
      <td class="admin-head2"><?=SD_ADM_BANNER_SIZE?></td>
      <td class="admin-head2"><?=SD_ADM_BANNER_STATUS?></td>
	  <td class="admin-head2"><?=SD_ADM_BANNER_POSITION?></td>
      <td class="admin-head2"><?//=GENERAL_EDIT?></td>
      <td class="admin-head2"><?//=GENERAL_DELETE?></td>
    </tr>
	<tr><td colspan="6" height="10px"></td></tr>
<?php
if (is_array($banners))
    foreach ($banners as $banner) {
?>
    <tr align=left class="normal">
      <td><a href="<?=$CONST_LINK_ROOT?>/admin/admin_banners_edit.php?id=<?=$banner->banner_id?>">
        <?=htmlspecialchars($banner->bannerName)?>
        </a></td>

      <td><?=$banner->bannerFormat?></td>
      <td><?= $banner->is_active ? ADM_BANNERS_ACTIVE : ADM_BANNERS_PAUSED ?></td>
	  <td><?=$banner->align?></td>

      <td><? if($DEMO==false){?><a href="<?=$CONST_LINK_ROOT?>/admin/admin_banners_edit.php?id=<?=$banner->banner_id?>">[
        <?=GENERAL_EDIT?>
        ]</a><? }?></td>
      <td><? if($DEMO==false){?><a href="<?=$CONST_LINK_ROOT?>/admin/admin_banners.php?act=remove&id=<?=$banner->banner_id?>" onClick="if (confirm('<?=SD_ADM_BANNERS_TEXT1?>')) {return true;} else {return false;}" >[
        <?=GENERAL_DELETE?>
        ]</a><? }?></td>
        </tr>
<?php } ?>
    <tr>
      <td colspan="5" align="center" class="tdfoot">&nbsp; </td>
    </tr>
  </table>
<!-- <img src="<?// Banner::displayBanner('728x90');?>">  -->
      </td>
	   
          <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="center">

       <table width="100%"  border="0" cellspacing="2" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
	   

                <tr>
                  <td colspan="2">&nbsp;</td>
                </tr>
				 <tr>
    <td class="admin-head">
      <?= $id ? SD_ADM_BANNER_EDIT_SECTION_NAME : SD_ADM_BANNER_ADD_SECTION_NAME ?>
    </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" selected="selected"> -- Select --</option>
                      <option value="Right" >Right</option>
                      <option value="Below"  >Below</option>
                      <option value="Home Standard" >Home Standard</option>
                      <option value="Home Premium" >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>              </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"> <input name="submit" type="submit" class="normal" value="<?=GENERAL_SAVE?>"  onClick="return Validate_Banner();">
                    <input name="normal" type="normal" class="normal" onclick="window.location = '<?=$CONST_LINK_ROOT?>/admin/admin_banners.php'" value="<?=GENERAL_CANCEL?>">                  </td>
                </tr>-->
				<tr>
      <td colspan="5" align="center" class="tdhead">
	  <? if($DEMO==false){?>
        <input type="submit" class='normal' onClick="return Validate_Banner();" value="<?=SD_ADM_BANNERS_ADD?>"><? }else{?>
		<input type="button" class='normal'  title="Can't Upload in Demo mode"  value="<?=SD_ADM_BANNERS_ADD?>">
		<? }?>
      </td>
    </tr>
              </table></td>
          </tr>
              </table></div><div class="admin-page-bottom"></div></div></td>
          </tr>
    </tr>
</table>
<?php include("include/footer.php"); ?>

