<?php

// include_once(ICMS_ROOT_PATH . 'mainfile.php');

function myslider_show()
{
		global $xoopsDB;

	$sql = "select * from `" . $xoopsDB->prefix("slider_data") . "` where (((`start_date`<= NOW()) or (`start_date` is NULL)) and ((`end_date`>= NOW()) or (`end_date` is NULL)) )  order by ID";

	$result = icms::$xoopsDB->query($sql);
	$mcount = icms::$xoopsDB->getRowsNum($result);

/**** for bootstrap slider ******/
	$counter = 0;
	$ans0 = "";
	$ans1 = "";
	$ans2 = "";
	$ans3 = "";
	if($mcount){
		$ans0 = '<div class="page-slider"><div id="carousel-face" class="carousel slide carousel-slider" data-ride="carousel">';
		$ans1 = '<ol class="carousel-indicators carousel-indicators-frontend">';
		$ans2 = '<div class="carousel-inner" role="listbox">';
		$ans3 = '<style>';
		while ($myrow = icms::$xoopsDB->fetchArray($result)) {
			$ans1 .= '<li data-target="#carousel-face" data-slide-to="' . $counter . '"';
			if(!$counter)
				$ans1 .= ' class="active"';
			$ans1 .= '></li>';

			$ans2 .= '<div class="item carousel-item-' . $counter;
			if(!$counter)
 				$ans2 .= ' active';
			$ans2 .= '">';
			$ans2 .= '</div>';

			$ans3 .= '.carousel-slider .carousel-item-' . $counter . '{';
			$ans3 .= 'background: url(' . XOOPS_URL . $myrow['imgfile'] . ');';
    	$ans3 .= 'background-size: cover;';
    	$ans3 .= 'background-position: center center; }';

			$counter++;
		}
		$ans1 .= '</ol>';
		$ans2 .= '</div>';
		$ans3 .= '</style>';

		$ans0 .= $ans1;
		$ans0 .= $ans2;
		$ans0 .= '
			<a class="left carousel-control carousel-control-shop carousel-control-frontend" href="#carousel-face" role="button" data-slide="prev">
      	<i class="fa fa-angle-left" aria-hidden="true"></i>
      </a>
      <a class="right carousel-control carousel-control-shop carousel-control-frontend" href="#carousel-face" role="button" data-slide="next">
        <i class="fa fa-angle-right" aria-hidden="true"></i>
      </a>
      </div>
    </div></div>';

		$bs_ans = $ans0 . $ans3;

	} else {
		$bs_ans = '
    	<div class="page-slider">
        <div id="carousel-face" class="carousel slide carousel-slider" data-ride="carousel">
            <!-- Indicators -->
            <ol class="carousel-indicators carousel-indicators-frontend">
                <li data-target="#carousel-face" data-slide-to="0" class="active"></li>
            </ol>
            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <!-- First slide -->
                <div class="item carousel-item-one active">
                </div>
            </div>
        </div>
    	</div>';
}
/*********** bs_slider end **************/
/**** for owl slider ******/
	$counter = 0;

	$result = icms::$xoopsDB->query($sql);
	$mcount = icms::$xoopsDB->getRowsNum($result);

	$scr0 = '<script>
			$(function(){
				var time = 7; // time in seconds

    	//Init the carousel
	    	$(".owl-carousel").owlCarousel({
					items: 1,
	      	singleItem : true,
					center: true,
					loop: true,
					autoplay: true,
					autoplayTimeout: 6000,
					animateOut: "fadeOutDown"
	    	});
		});
		</script>
';

	$ans0 = "";
	if($mcount){
    $ans0 = '<section id="main-slider">';
    $ans0 .= '<div class="owl-carousel">';
		while ($myrow = icms::$xoopsDB->fetchArray($result)) {
      $ans0 .= '<div class="item" style="background-image: url('  . XOOPS_URL . $myrow['imgfile'] . ');">';
      $ans0 .= '<div class="slider-inner">';
      $ans0 .= '<h2>' . $myrow['msg1'] . '</h2>';
			if($myrow['msg2'])
				$ans0 .= '<div class="slider-button"><a href="' . $myrow['msg2_link'] . '"><input type="button" class="blue" value="' . $myrow['msg2'] . '"></a></div>';
			$ans0 .= '</div>';
      $ans0 .= '</div><!--/.item-->';
		}
	}
  $ans0 .= '</div><!--/.owl-carousel-->';
  $ans0 .= '</section><!--/#main-slider-->';

	$ow_ans = $scr0 . $ans0;
	$ans = array();
	$ans['bs_ans']  = $bs_ans;
	$ans['ow_ans']  = $ow_ans;

	return $ans;

}
