<?php
add_action('dslc_hook_register_modules',
    create_function('', 'return dslc_register_module( "Ainex_Client_List" );')
);

class Ainex_Client_List extends DSLC_Module {

 	// Module Attributes
    var $module_id = 'Ainex_Client_List';
    var $module_title = 'Client List';
    var $module_icon = 'user';
    var $module_category = 'Ainex - Posts';


 	// Module Options
    function options() {
    	global $ts_animation_style;
		// Get post gallery
		$post_choices = array();
		$posts_array = get_posts( 'post_type=dslc_galleries' );
		$post_choices[] = array(
			'label' => '--Select Post Gallery--',
			'value' => '',
		);
		foreach ($posts_array as $post ) :
			$post_choices[] = array(
				'label' => $post->post_title,
				'value' => $post->ID,
			);
		endforeach;
		wp_reset_postdata();



    	// The options array
    	$dslc_options = array(

			array(
				'label' => 'Client List - Post Galleries',
				'id' => 'gallery_post',
				'std' => '',
				'type' => 'select',
				'choices' => $post_choices,
				'section' => 'functionality',
			),
			array(
				'label' => 'Title',
				'id' => 'title',
				'std' => '<strong>Our Clients</strong> FlivaHost Proud to be Trusted By',
				'type' => 'textarea',
				'section' => 'functionality',
			),
			array(
				'label' => __( 'Margin Bottom', 'dslc_string' ),
				'id' => 'css_margin_bottom',
				'std' => '0',
				'type' => 'slider',
				'refresh_on_change' => false,
				'affect_on_change_el' => '.clients_sec',
				'affect_on_change_rule' => 'margin-bottom',
				'section' => 'styling',
				'ext' => 'px',
			),

			/*
			 * Animation Style
			*/
			array(
				'label' => __( 'Animation Style', 'dslc_string' ),
				'id' => 'css_animation_class',
				'std' => 'fadeInDown',
				'type' => 'select',
				'choices' => $ts_animation_style,
				'section' => 'styling',
				'tab' => 'Ainex Animation',
			),
			array(
				'label' => __( 'Animation Duration', 'dslc_string' ),
				'id' => 'animation_duration',
				'std' => '',
				'type' => 'slider',
				'section' => 'styling',
				'tab' => 'Ainex Animation',
				'refresh_on_change' => false,
				'affect_on_change_el' => '',
				'affect_on_change_rule' => '',
				'ext' => 's',
				'min' => 0,
				'max' => 10,
				'increment' => 0.1,
			),
			array(
				'label' => __( 'Animation Delay', 'dslc_string' ),
				'id' => 'animation_delay',
				'std' => '',
				'type' => 'slider',
				'section' => 'styling',
				'tab' => 'Ainex Animation',
				'refresh_on_change' => false,
				'affect_on_change_el' => '',
				'affect_on_change_rule' => '',
				'ext' => 's',
				'min' => 0,
				'max' => 10,
				'increment' => 0.1,
			),
		);
		$dslc_options = array_merge( $dslc_options, $this->shared_options('animation_options') );
    	// Return the array
    	return apply_filters( 'dslc_module_options', $dslc_options, $this->module_id );

    }

 	// Module Output
    function output( $options ) {

    	global $dslc_active;

		if ( $dslc_active && is_user_logged_in() && current_user_can( DS_LIVE_COMPOSER_CAPABILITY ) )
			$dslc_is_admin = true;
		else
			$dslc_is_admin = false;

		//REQUIRED
		$this->module_start( $options );

		$services_active = '';
		if ( $dslc_active )
			$services_active .= 'helight';

		if($options['gallery_post']):
			$slider_id 		= rand(1,1000);
			$post_id 		= $options['gallery_post'];
			$attachments2 	= get_post_meta( $post_id, 'dslc_gallery_images', true );
		?>
			<div class="container">
				<div class="clients_sec">
		            <div class="title">
		            	<?php echo $options['title']; ?>
		            </div>
		            <div class="clients wow <?php echo $options['css_animation_class'] ?>" <?php if ($options['animation_duration']) { echo 'data-wow-duration="'.$options['animation_duration'].'s"';} ?> <?php if ($options['animation_delay']) { echo 'data-wow-delay="'.$options['animation_delay'].'s"';} ?>>
				    	<ul id="mycarousel<?php echo $slider_id; ?>" class="jcarousel-skin-tango">
				    		<?php if($attachments2){ ?>
					    		<?php 
					    			$attachments2 = trim($attachments2);
					    			$attachments = explode(" ", $attachments2);
					    			foreach ( $attachments as $attachment2 ){
					    			$image_attributes = wp_get_attachment_image_src( $attachment2 );
					    		?>
						  			<li><img src="<?php echo $image_attributes[0]; ?>" alt=""></li>
						  		<?php } ?>
						  	<?php } ?>
				    	</ul>
					</div>
		    	</div>
			</div>
			<script type="text/javascript">
				/* <![CDATA[ */
				jQuery(document).ready(function() {
					jQuery('#mycarousel<?php echo $slider_id; ?>').jcarousel();
				});
				jQuery(document).ready(function($) {
				    var wow = new WOW(
						{
						    boxClass:     'wow',
						    animateClass: 'animated',
						    offset:       0,
						    mobile:       true
						}
					);
					wow.init();
				});
				/* ]]> */
			</script>

		<?php else: ?>
			<div class="dslc-notification dslc-red"><?php echo __( 'No data has been set yet, edit the module to set one.', 'themestudio' ); ?></div>
		<?php endif; ?>

		<div class="clearfix"></div>

	<?php
    	// REQUIRED
    	$this->module_end( $options );

    }

}