<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide-with-html.js"></script>
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide-with-gallery.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide.css" />
<script type="text/javascript">
    hs.graphicsDir = '<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/graphics/';
    hs.align = 'center';
    hs.transitions = ['expand', 'crossfade'];
    hs.wrapperClassName = 'dark borderless floating-caption';
    hs.fadeInOut = true;
    hs.showCredits = false;
    hs.dimmingOpacity = .75;
    if (hs.addSlideshow) hs.addSlideshow({
        slideshowGroup: 'group1',
        interval: 5000,
        repeat: false,
        useControls: true,
        fixedControls: 'fit',
        overlayOptions: {
            opacity: .6,
            position: 'bottom center',
            hideOnMouseOut: true
        }
    });
    function shareFacebook(id)
    {
        SetBackground();
        $.ajax({
            type: "GET",
            url: "index.php?module=special&action=shareOnFb&ajax=Y&id="+id,
            async: true,
            success: function(status){
                UnsetBackground();
                alert("Special succesfully shared on facebook");
                if(trim(status)=='Y'){
                    $('#fbStatus-'+id).attr('src','<?= SITE_PATH ?>/powerpanel/<?= GLOBAL_ADMIN_IMAGES_PATH ?>share.gif'); 
                }
            }
        });
    }
</script>
<script type="text/javascript">
    function verify()
    {    
        SendGridBindRequest('<?= $specialObj->urlwithpara ?>','gridbody','D','chkgrow');
    }
    function share(id){
        $.ajax({
            type: "GET",
            url:"index.php" ,
            data: "module=special&action=sharedata&ajax=Y&eid="+id,
            async: false,
            success: function(result){
                //alert(result);
                $( "#modelpopup" ).html(result);
            }
        });
        $( "#modelpopup" ).dialog({            
            height:380,
            width:620,
            modal: true,
            buttons:{
                "Cancel": function() {
                    $(this).dialog( "close" );
                },
                "Push": function() {
                    var chked = false;
                    $('input:checkbox[name="fb[]"]:checked,input:checkbox[name="tw[]"]:checked').each(function(k,v){
                        chked = true;
                    });
                    if ($('#var_title').val()=='' || $('#var_short_description').val()=='')
                    {
                        alert('Please Enter required fields');
                        return false;
                    }
                    if(chked){
                        var postdata=$("#frmshareoption").serialize();
                        $.ajax({
                            type: "POST",
                            url:"index.php?module=special&action=sharedata&ajax=Y&eid="+id ,
                            data: postdata,
                            async: false,
                            success: function(result){
                                //alert(result);
                                if(trim(result)==1){
                                    alert("Specials pushed successfully.");
                                }else{
                                    alert("Error.. Please try again.");
                                }
                                $( "#modelpopup" ).dialog( "close" );
                                window.location.reload();
                            }
                        });
                    }else{
                        alert(" Please select atleast one page.");
                        return false;
                    }
                }
            }
        });
    }
</script>
<div id="modelpopup" title="Share on Facebook & Twitter"></div>
<div class="web-booking-main" id="gridbody">
    <input type="hidden" name="autosearchurl" id="autosearchurl" value="<?php echo $configObj->AutoSearchUrl ?>"  />
    <?php
    if ($_REQUEST['action'] != '')
        $action = ucwords($_REQUEST['action']);
    ?>
    <div class="breadcrumbs"><a href="index.php">&nbsp;&nbsp;Home </a>&nbsp;>&nbsp;&nbsp;  <span class="current">Manage Promotions </span> 
    </div>
    <div class="clear"></div>
    <?= $messagebox; ?>
    <?php echo $headerpanel; ?>        
    <?php echo $pagingTop; ?>  
    <?= $notemessagebox ?>
    <div class="clear"></div>
    <div class="grid-list-subtitle-bg" style="margin-top:10px;">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="2%" align="left" valign="middle" class="grid-td-left">
                    <?php if ($paramMain['Delete'] == 'Y') { ?>
                        <input name="chkall" id="chkall" type="checkbox" onclick="checkall('chkgrow')"  />
                    <?php } else { ?>
                        &nbsp;
                    <?php } ?>
                </td>
                <td width="3%" align="left" valign="middle" class="grid-td-top">&nbsp;</td>
                <td width="24%" align="left" valign="middle" class="grid-td-top"><a href="javascript:;" onclick="SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>&orderby=var_title&sorting=Y','gridbody','ST')">Title<?= $setsortimgvar_title ?></a> </td>
                <td width="9%" align="center" valign="middle" class="grid-td-top">File</td>
                <td width="9%" align="center" valign="middle" class="grid-td-top">Image</td>
                <td width="11%" align="center" valign="middle" class="grid-td-top" ><a href="javascript:;" onclick="SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>&orderby=dt_startdate&sorting=Y','gridbody','ST')">Start Date<?= $setsortimgdt_startdate ?></a> </td>
                <td width="10%" align="center" valign="middle" class="grid-td-top" ><a href="javascript:;" onclick="SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>&orderby=dt_expiredate&sorting=Y','gridbody','ST')">End Date<?= $setsortimgdt_expiredate ?></a> </td>
                
                <?php if ($configObj->glSessionObj->value('admin_id') == '1' || $configObj->glSessionObj->value('chr_user') == 'A' || DISPLAY_DISPORDER_FLAG == 'N') { ?>
                <? } else { ?>

                <? } ?>               
                <?php if ($configObj->glSessionObj->value('admin_id') == '1' || $configObj->glSessionObj->value('chr_user') == 'A' || DISPLAY_DISPORDER_FLAG == 'Y') { ?>
                    <td width="10%" align="center" valign="middle" class="grid-td-top"><a href="javascript:;" onclick="SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>&orderby=int_displayorder&sorting=Y','gridbody','ST')">Display Order<?= $setsortimgint_displayorder ?></a>
                        <a href="javascript:;" onclick="javascript:SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>','gridbody','DO');"><img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>save.png" width="16" height="16" alt="save" title="save" border="0" /></a>
                    </td>

                    
                <? } ?>
                    
                    <td width="3%" align="center" valign="middle" class="grid-td-top">
                    <a href="javascript:;" onclick="SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>&orderby=inthits&sorting=Y','gridbody','ST')"> Hits
                        <?= $setsortimginthits ?>
                    </a>
                </td>

                <td width="10%" align="center" valign="middle" class="grid-td-top"><a href="javascript:;" onclick="SendGridBindRequest('<?= $specialObj->urlwithoutsort ?>&orderby=chr_publish&sorting=Y','gridbody','ST')">Publish<?= $setsortimgchr_publish ?></a></td>
                <td width="10%" align="center" valign="middle" class="grid-td-top"> Share</td>
            </tr>
        </table>
    </div>
    <div class="information-white-bg" id="dvpersonalinformation" >
        <div class="clear"></div>
        <input type="hidden" value="special" name="hdnmodule" id="hdnmodule">
        <div class="grid-list-inner-table-text">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <?php
                if ($numofrows > 0) {
                    $rowcount = 0;
                    while ($row = $configObj->glDbObj->fetch_array($result)) {

//                        $clsname = ($row['chr_read'] == 'N') ? "grid-list-inner-table-text-active" : "grid-list-inner-table-text"; // For read unread class
                        $approveimg = ($row['var_approve'] == 'Y') ? "_tick.png" : "_tick_cross.png";
                        $starimg = ($row['chr_star'] == 'Y') ? "gstar.png" : "gstar-disable.png"; // Displaying the stat and unstart image
                        $tool = ($row['chr_star'] == 'Y') ? "Starred" : "Not starred";
                        $tickimg = ($row['chr_publish'] == 'Y') ? "tick.png" : "tick_cross.png";  // Displaying the stat and unstart image
                        $fbStatusImg = ($row['chr_fbstatus'] == 'Y') ? "share.gif" : "not-share.gif";
                        if ($row['chr_publish'] == 'Y') {
                            $title = "This means the display is on, if you would like to hide this menu item please click on the logo.";
                        } else {
                            $title = "This means the display is off, if you would like to Display this menu item please click on the logo.";
                        }
                        $shareimg = "1-push.png";
                        ?>
                        <tr id="gtr-<?= $row['int_glcode'] ?>"  style="background-color: transparent;"   onmouseover="this.style.backgroundColor='#f6f6f6'" onmouseout="this.style.backgroundColor='transparent'" >

                            <td width="2%" align="left" valign="middle" class="grid-td-left">
                                <?php if ($paramMain['Delete'] == 'Y') { ?>
                                    <input name="chkgrow" id="chkgrow" type="checkbox" value="<?php echo $row['int_glcode'] ?>" />
                                <?php } else { ?> 
                                    &nbsp;
                                <?php } ?> 
                            </td>
                            <?php if ($configObj->glSessionObj->value('admin_id') == '1') { ?>
                               <td width="3%" align="center" valign="middle" class="grid-td-top">
                            <?php } else { ?>
                                <td width="3%" align="center" valign="middle" class="grid-td-top"></td>
                            <?php } ?>
                            <td width="24%" align="left" valign="middle" class="grid-td-top">

                                <?php
                                $char = substr($row['var_title'], 0, 50);
                                if (strlen($row['var_title']) > 50) {
                                    $char.='...';
                                }
                                $createdate = strtotime($row['dt_createdate']);
                                $modifydate = strtotime($row['dt_modifydate']);
                                ?>
                                <?php if ($paramMain['Edit'] == 'Y') { ?>
                                    <a href="<?= $specialObj->urlwithpara; ?>&amp;action=edit&amp;eid=<?php echo $row['int_glcode']; ?>">
                                        <span><?php echo $char; ?></span></a>
                                <?php } else { ?>
                                    <span><?php echo $char; ?></span>
                                    <?php
                                }
                                ?>
                            </td>
                            <td width="9%" align="center" valign="middle" class="grid-td-top">
                                <?php
                                if ($row['var_pdffile'] != '') {
                                    $fileexntension = substr(strrchr($row['var_pdffile'], '.'), 1);

                                    $p = explode('.', $row['var_pdffile']);
                                    if ($fileexntension == 'doc' || $fileexntension == 'docx') {
                                        $t = 'WORD.png';
                                    } else if ($fileexntension == 'zip' || $fileexntension == 'rar') {
                                        $t = 'zip-icon.jpeg';
                                    } else if ($fileexntension == 'ppt' || $fileexntension == 'pptx') {
                                        $t = "ppt-icon.png";
                                    } else {
                                        $t = 'acrobate-readericon.png';
                                    }
                                    ?>
                                    <a href="download.php?f=<?php echo urlencode('upimages/commonpdf/' . $row['var_pdffile']); ?>&module=commonpdf" >
                                        <img id="pdficon" height="16" width="16" alt="<?= $title ?>" title="<?= $var_pdffile ?>" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/<?= $t ?>" style="vertical-align:middle;cursor:pointer;">
                                    </a>
                                <?php }
                                else {
                                    
                                     echo"N/A";
                                }?>
                            </td>
                            <td width="9%" align="center" valign="middle" class="grid-td-top">
                                <?php if (file_exists("../upimages/special/images/thumb_" . trim($row['var_image']))) { ?>
                                    <a onClick="return hs.expand(this);" href="<?php echo "../upimages/special/images/thumb_" . trim($row['var_image']) ?>">
                                        <img border="0" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/photo-gallery-icon.png" >
                                    </a>
                                    <?php
                                } else {
                                    echo"N/A";
                                }
                                ?>
                            </td>

                            <?php
                            if (DEFAULT_DATEFORMAT == '%d/%m/%Y') {
                                $start_date = $configObj->glLibraryObj->dtConvertYMDtoDMY($row['dt_startdate']);
                            }
                            if (DEFAULT_DATEFORMAT == '%m/%d/%Y') {
                                $start_date = $configObj->glLibraryObj->dtConvertYMDtoMDY($row['dt_startdate']);
                            }
                            if (DEFAULT_DATEFORMAT == '%Y/%m/%d') {
                                $start_date = $configObj->glLibraryObj->dtConvertYMDtoYMD($row['dt_startdate']);
                            }
                            if (DEFAULT_DATEFORMAT == '%Y/%d/%m') {
                                $start_date = $row['dt_startdate'];
                            }
                            $date_special = DEFAULT_DATEFORMAT;
                            if (DEFAULT_DATEFORMAT == '%d/%m/%Y') {
                                $expiry_date = $configObj->glLibraryObj->dtConvertYMDtoDMY($row['dt_expiredate']);
                            }
                            if (DEFAULT_DATEFORMAT == '%m/%d/%Y') {
                                $expiry_date = $configObj->glLibraryObj->dtConvertYMDtoMDY($row['dt_expiredate']);
                            }
                            if (DEFAULT_DATEFORMAT == '%Y/%m/%d') {
                                $expiry_date = $configObj->glLibraryObj->dtConvertYMDtoYMD($row['dt_expiredate']);
                            }
                            if (DEFAULT_DATEFORMAT == '%Y/%d/%m') {
                                $expiry_date = $row['dt_expiredate'];
                            }
                            ?>
                            <td width="11%" align="center" valign="middle"  class="grid-td-top">
                                <?php echo $row['dt_startdate']; ?>
                            </td>

                            
                            <td width="10%" align="center" valign="middle"  class="grid-td-top">
                                <?php
                                if ($expiry_date == '00/00/0000' || $expiry_date == '0000/00/00' || $expiry_date == '0000-00-00') {
                                    echo 'No Expiry';
                                } else {
                                    echo $row['dt_expiredate'];
                                }
                                ?>
                            </td>
                            
                            <td width="10%" align="center" valign="middle"  class="grid-td-top"  >
                                <input name="displayorder<?= $rowcount ?>" type="text" class="order" id="displayorder<?= $rowcount ?>"  onkeypress="return KeycheckOnlyNumeric(event);" maxlength="3" value="<?= $row['int_displayorder']; ?>" size="7%" />
                                <input type="hidden" name="hdndisplayorder<?= $rowcount ?>" id="hdndisplayorder<?= $rowcount ?>" value="<?= $row['int_displayorder'] ?>" />
                                <input type="hidden" name="hdnintglcode<?= $rowcount ?>" id="hdnintglcode<?= $rowcount ?>"  value="<?= $row['int_glcode'] ?>" />
                            </td>
                            
                            <td width="3%" align="center" valign="middle" class="grid-td-top"><?php echo $row['int_newshits']; ?></td>
                            
                            <td  width="10%" align="center" valign="middle" class="grid-td-top">
                                <?php if ($paramMain['Publish'] == 'Y') { ?>
                                    <a href="javascript:void(0);">
                                        <img id="tick-<?= $row['int_glcode'] ?>" height="16" width="16" title="<?= $title ?>"alt="publish me" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?><?= $tickimg ?>" style="vertical-align:middle;cursor:pointer;" onclick="UpdatePublish_modulewise('<?= DB_PREFIX ?>special','chr_publish','<?= $row['int_glcode'] ?>','','special');"></a> 
                                <?php } else { ?>
                                    <img id="tick-<?= $row['int_glcode'] ?>" height="16" width="16" alt="<?= $title ?>"  src="<?= GLOBAL_ADMIN_IMAGES_PATH ?><?= $tickimg ?>" style="vertical-align:middle;" >
                                    
                                <?php } ?>
                            </td>
                           
                          <!--=======================================-->  
                           
                           <td id="push_<?=$row['int_glcode']?>" width="10%" align="center" valign="middle" class="grid-td-top">
                                <?php if ($row['chr_publish'] == 'Y') { ?>
                                     <img id="shar-<?= $row['int_glcode'] ?>" height="25" width="77" alt="<?= $title . "share" ?>" title="<?= $title . " is share." ?>" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?><?= $shareimg ?>" style="vertical-align:middle;cursor:pointer;<?= $display ?>" onclick="share(<?= $row['int_glcode'] ?>);">
                                <?php } else { echo "N/A";?>
                                <?php } ?>
                           </td>
                           
                        </tr>
                        <?php
                        $rowcount++;
                    }
                } else {
                    ?>
                    <tr style="background-color: transparent;"   onmouseover="this.style.backgroundColor='#f6f6f6'" onmouseout="this.style.backgroundColor='transparent'"> 
                        <td height="25" align="center" valign="middle" colspan="6" class="form_titles">Sorry! No records are available.</td>
                    </tr>
                    <?
                }
                ?>
                <input type="hidden" name="ptrecords" id="ptrecords" value="<?= $rowcount ?>">      
            </table>
        </div>
    </div>
    <div class="clear"></div>
    <?php echo $pagingBottom; ?>
    <?php
    if ($numofrows > 0) {
        if ($paramMain['Delete'] == 'Y') {
            ?>
            <div class="add-new-user-button"><a href="javascript:" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image47','','<?= GLOBAL_ADMIN_IMAGES_PATH ?>delete-button-hover.jpg',0)"><img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>delete-button.jpg" alt="Delete" name="Image47" width="80" height="25" border="0" id="Image47" onclick="return verify();" /></a></div>
    <?php }
} ?>
</div>