<div class="tab-container">
   <div class="row">
      <div class="col-lg-6">
         <form method="post" action="" class="setting-mailnglist-container">
            <h5><?php echo $wo['lang']['mailing_users'];?> <small>(HTML allowed)</small></h5>
            <div class="send-errors"></div>
            <div class="form-group">
               <input name="subject" class="form-control" placeholder="<?php echo $wo['lang']['mailing_subject'];?>">
            </div>
            <div class="form-group">
               <textarea name="message" class="form-control" placeholder="<?php echo $wo['lang']['mailing_message'];?>" rows="5" cols="20"></textarea>
            </div>
            <div class="form-group">
               <input type="checkbox" name="test_message"> Test Message <small>(Send only to my email)</small>
            </div>
            <div class="row">
               <div class="col-sm-3 pull-left">
                  <button type="submit" name="save_setting" class="form-control btn-main-color btn-main">
                  <i class="fa fa-paper-plane-o progress-icon" data-icon="paper-plane-o"></i> <?php echo $wo['lang']['send'];?>
                  </button>
               </div>
               <div class="setting-saved-update-alert milinglist"></div>
            </div>
         </form>
         <br>
         <h5 ><?php echo $wo['lang']['advertisement_setting'];?></h5>
         <div class="clear"></div>
         <hr>
         <div class="ads-placement-container">
            <div class="placement-header">
               <div class="pull-left">
                  <h5>Header <small>(Appears on all pages right under the nav bar)</small></h5>
               </div>
               <div class="pull-right">
                  <h5>
                     <span class="pointer ads-activation" title="<?php echo (Wo_IsAdActive('header') == 1) ? 'Deactivate' : 'Activate';?>" onclick = "Wo_UpdateAdsStatus('header');">
                     <i class="fa <?php echo (Wo_IsAdActive('header') == 1) ? 'fa-times-circle active' : 'fa-check-circle';?> progress-icon"></i>
                     </span> | 
                     <span class="pointer" onclick="Wo_ShowAdsForm('header');">
                     <i class="fa fa-pencil"></i>
                     </span>
                  </h5>
               </div>
               <form action="#" method="post" class="ads-form-header hidden">
                  <div class="form-group">
                     <textarea name="code" cols="10" rows="5" class="form-control"><?php echo Wo_GetAd('header', true);?></textarea>
                  </div>
                  <div class="form-group pull-right">
                     <button onclick="Wo_SaveAdCode('header');" type="submit" class="btn btn-main btn-main-color"><i class="fa fa-floppy-o progress-icon" data-icon="floppy-o"></i> <?php echo $wo['lang']['save'];?></button>

                  </div>
                  <input type="hidden" name="type" value="header">
               </form>
            </div>
            <div class="clear"></div>
            <hr>
            <div class="placement-sidebar">
               <div class="pull-left">
                  <h5>Sidebar <small>(Appears on the bottom of home sidebar)</small></h5>
               </div>
               <div class="pull-right">
                  <h5>
                     <span class="pointer ads-activation" title="<?php echo (Wo_IsAdActive('sidebar') == 1) ? 'Deactivate' : 'Activate';?>" onclick = "Wo_UpdateAdsStatus('sidebar');">
                     <i class="fa <?php echo (Wo_IsAdActive('sidebar') == 1) ? 'fa-times-circle active' : 'fa-check-circle';?> progress-icon" ></i>
                     </span> | 
                     <span class="pointer" onclick="Wo_ShowAdsForm('sidebar');">
                     <i class="fa fa-pencil"></i>
                     </span>
                  </h5>
               </div>
               <form action="#" method="post" class="ads-form-sidebar hidden">
                  <div class="form-group">
                     <textarea name="code" cols="10" rows="5" class="form-control"><?php echo Wo_GetAd('sidebar', true);?></textarea>
                  </div>
                  <div class="form-group pull-right">
                     <button onclick="Wo_SaveAdCode('sidebar');" type="submit" class="btn btn-main btn-main-color "><i class="fa fa-floppy-o progress-icon" data-icon="floppy-o"></i> <?php echo $wo['lang']['save'];?></button>  
                  </div>
                  <input type="hidden" name="type" value="sidebar">
               </form>
            </div>
            <div class="clear"></div>
            <hr>
            <div class="placement-footer">
               <div class="pull-left">
                  <h5>Footer <small>(Appears on all pages right before the footer)</small></h5>
               </div>
               <div class="pull-right">
                  <h5>
                     <span class="pointer ads-activation" title="<?php echo (Wo_IsAdActive('footer') == 1) ? 'Deactivate' : 'Activate';?>" onclick = "Wo_UpdateAdsStatus('footer');">
                     <i class="fa <?php echo (Wo_IsAdActive('footer') == 1) ? 'fa-times-circle active' : 'fa-check-circle';?> progress-icon"></i>
                     </span> | 
                     <span class="pointer">
                     <i class="fa fa-pencil" onclick="Wo_ShowAdsForm('footer');"></i>
                     </span>
                  </h5>
               </div>
               <form action="#" method="post" class="ads-form-footer hidden">
                  <div class="form-group">
                     <textarea name="code" cols="10" rows="5" class="form-control"><?php echo Wo_GetAd('footer', true);?></textarea>
                  </div>
                  <div class="form-group pull-right">
                     <button onclick="Wo_SaveAdCode('footer');" type="submit" class="btn btn-main btn-main-color"><i class="fa fa-floppy-o progress-icon" data-icon="floppy-o"></i> <?php echo $wo['lang']['save'];?></button> 
                  </div>
                  <input type="hidden" name="type" value="footer">
               </form>
            </div>
            <div class="clear"></div>
         </div>
    
      </div>
      <div class="col-lg-6">
         <form method="post" action="" class="setting-announcement-container">
            <h5><?php echo $wo['lang']['announcement'];?> <small>(HTML allowed)</small></h5>
            <div class="form-group">
               <textarea name="announcement_text" class="form-control" placeholder="<?php echo $wo['lang']['new_announcement'];?>" rows="5" cols="10"></textarea>
            </div>
            <div class="row">
               <div class="col-sm-3 pull-left">
                  <button type="submit" name="save_setting" class="form-control btn-main-color btn-main">
                  <i class="fa fa-plus progress-icon" data-icon="fa-plus"></i> <?php echo $wo['lang']['add'];?>
                  </button>
               </div>
         </form>
         </div>
         <div class="page-margin">
            <hr>
            <h5>Active announcements:</h5>
            <div class="active-announcements announcements">
               <?php
                  $activeAnnouncements = Wo_GetActiveAnnouncements();
                  
                  if (count($activeAnnouncements) < 1) {
                    
                    echo '<h5 class="no-active-announcements"><small>' . $wo['lang']['there_are_no_active_announcements'] . '</small></h5>';
                  } else {
                  foreach ($activeAnnouncements as $wo['activeAnnouncement']) {
                  
                     echo Wo_LoadPage('admin/announcement/active-list');
                     
                  }
                  }
                  ?>
            </div>
         </div>
         <div class="page-margin">
            <hr>
            <h5>inactive announcements:</h5>
            <div class="inactive-announcements announcements">
               <?php 
                  $inactiveAnnouncements = Wo_GetInactiveAnnouncements();
                  
                   if (count($inactiveAnnouncements) < 1) {
                    
                    echo '<h5 class="no-inactive-announcements"><small>' . $wo['lang']['there_are_no_inactive_announcements'] . '</small></h5>';
                  } else {
                  foreach ($inactiveAnnouncements as $wo['inactiveAnnouncement']) {
                  
                     echo Wo_LoadPage('admin/announcement/inactive-list');
                     
                  } 
                  }
                  ?>
            </div>
         </div>
      </div>
      <div class="clear"></div>
   </div>
</div>
<script type="text/javascript">
$(function () {
   $('form.setting-mailnglist-container').ajaxForm({
      url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=send_mail_to_all_users',
      beforeSend: function () {
         Wo_progressIconLoader($('form.setting-mailnglist-container').find('button'));
         $('.setting-saved-update-alert.milinglist').hide().fadeIn(200).html('<i class="fa fa-clock-o"></i><span id="loading"> Please wait <span>.</span><span>.</span><span>.</span></span>');
      },
      success: function (data) {
         if (data.status == 400) {
            $('.send-errors').html('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' + data.message + '</div>');
            $('.setting-saved-update-alert.milinglist').fadeOut(200);
         } else if (data.status == 200) {
            $('.setting-saved-update-alert.milinglist').hide().fadeIn(200).html('<i class="fa fa-check"></i> Messges Sent').delay(2000).fadeOut(200);
            $('.send-errors').empty();
         }
         Wo_progressIconLoader($('form.setting-mailnglist-container').find('button'));
      }
   });

   $('form.setting-announcement-container').ajaxForm({
      url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=add_new_announcement',
      beforeSend: function () {
         Wo_progressIconLoader($('form.setting-announcement-container').find('button'));
      },
      success: function (data) {
         if (data.status == 200) {
            $('.no-active-announcements').hide(100);
            $('.active-announcements').prepend(data.text);
         }
         Wo_progressIconLoader($('form.setting-announcement-container').find('button'));
      }
   });
});

function Wo_DeleteAnnouncement(id) {
   var announcement_container = $('.announcements').find('.announcement-' + id);
   $.get(Wo_Ajax_Requests_File(), {
      f: 'admin_setting',
      s: 'delete_announcement',
      id: id
   }, function (data) {
      if (data.status == 200) {
         announcement_container.slideUp(200, function () {
            $(this).remove();
         });
      }
   });
}

function Wo_DisableAnnouncement(id) {
   var announcement_container = $('.active-announcements').find('.announcement-' + id);
   var inactiveannouncement_container = $('.inactive-announcements');
   $.get(Wo_Ajax_Requests_File(), {
      f: 'admin_setting',
      s: 'disable_announcement',
      id: id
   }, function (data) {
      if (data.status == 200) {
         announcement_container.slideUp(200, function () {
            $(this).remove();
         });
         if (data.html.length != 0) {
            $('.no-inactive-announcements').hide(100);
            inactiveannouncement_container.prepend(data.html);
         }
      }
   });
}

function Wo_ActivateAnnouncement(id) {
   var announcement_container = $('.inactive-announcements').find('.announcement-' + id);
   var activeannouncement_container = $('.active-announcements');
   $.get(Wo_Ajax_Requests_File(), {
      f: 'admin_setting',
      s: 'activate_announcement',
      id: id
   }, function (data) {
      if (data.status == 200) {
         announcement_container.slideUp(200, function () {
            $(this).remove();
         });
         if (data.html.length != 0) {
            activeannouncement_container.prepend(data.html);
         }
      }
   });
}
function Wo_ShowAdsForm(type) {
  $('.ads-form-' + type).toggleClass('hidden');
}
      
function Wo_SaveAdCode(type) {
  var ad_type  = $('.ads-form-' + type);
  ad_type.ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_ads',
    beforeSend: function() {
      Wo_progressIconLoader(ad_type.find('button'));
    },
    success: function(data) {
      if (data.status == 200) {
        Wo_ShowAdsForm(type);
      } 
        Wo_progressIconLoader(ad_type.find('button'));
      } 
  });  
}
   
function Wo_UpdateAdsStatus(type) {  
  var ad_placement = $('.placement-' + type);  
  Wo_progressIconLoader(ad_placement.find('.ads-activation'));
  $.get(Wo_Ajax_Requests_File(), {f:'admin_setting', s:'update_ads_status', type:type},function(data) {
    if (data.status == 200) {
      ad_placement.find('.ads-activation').html('<i class="fa fa-times-circle active progress-icon"></i>');
    } else { 
      ad_placement.find('.ads-activation').html('<i class="fa fa-check-circle progress-icon"></i>');  
    }  
  });
}
</script>