<?php 

add_action('dslc_hook_register_modules',
     create_function('', 'return dslc_register_module( "Ainex_Block_Our_Service" );')
);

class Ainex_Block_Our_Service extends DSLC_Module {
 		
 	// Module Attributes
    var $module_id = 'Ainex_Block_Our_Service';
    var $module_title = 'Our Service';
    var $module_icon = 'cogs';
    var $module_category = 'Ainex - Services';


 	// Module Options
    function options() { 
		$post_choices = array();
		$post_choices[] = array(
			'label' => '-- Select service --',
			'value' => '',
		);
		$myposts = get_posts( 'post_type=service&posts_per_page=50' );
		foreach ( $myposts as $post ) :
			$post_choices[] = array(
				'label' => $post->post_title,
				'value' => $post->ID
			);
			$post_id_default = $post->ID;
		endforeach;
		wp_reset_postdata();


    	// The options array
    	$dslc_options = array(
			array(
				'label' => 'Our Service 1 - Services Home',
				'id' => 'our_service_1',
				'std' => $post_id_default,
				'type' => 'select',
				'choices' => $post_choices,
				'section' => 'functionality',
			),
			array(
				'label' => 'Our Service 2',
				'id' => 'our_service_2',
				'std' => $post_id_default,
				'type' => 'select',
				'choices' => $post_choices,
				'section' => 'functionality',
			),
			array(
				'label' => 'Our Service 3',
				'id' => 'our_service_3',
				'std' => $post_id_default,
				'type' => 'select',
				'choices' => $post_choices,
				'section' => 'functionality',
			),
			array(
				'label' => 'Our Service 4',
				'id' => 'our_service_4',
				'std' => $post_id_default,
				'type' => 'select',
				'choices' => $post_choices,
				'section' => 'functionality',
			),
			array(
				'label' => __( 'Enable/Disable Read More', 'dslc_string' ),
				'id' => 'button_switch_readmore',
				'std' => 'enabled',
				'type' => 'select',
				'choices' => array(
					array(
						'label' => __( 'Enabled', 'dslc_string' ),
						'value' => 'enabled'
					),
					array(
						'label' => __( 'Disabled', 'dslc_string' ),
						'value' => 'disabled'
					),
				),
				'section' => 'functionality',
			),
			array(
				'label' => __( 'Left Image', 'dslc_string' ),
				'id' => 'left_image',
				'std' => get_template_directory_uri().'/assets/images/site-img32.png',
				'type' => 'image',
				'section' => 'styling',
			),
			array(
				'label' => 'Title',
				'id' => 'title',
				'std' => 'Our Services',
				'type' => 'text',
				'section' => 'styling'
			),
			array(
				'label' => 'SubTitle',
				'id' => 'sub_title',
				'std' => 'Everything Just Got Easier with Ainex',
				'type' => 'text',
				'section' => 'styling'
			),
			array(
				'label' => 'Description',
				'id' => 'desc',
				'std' => 'Many desktop publishing packages and web page editors now use Lorem Ipsum as their default modeltext and a search for "lorem ipsum" will uncover many web sites.',
				'type' => 'textarea',
				'section' => 'styling'
			),
			array(
				'label' => __( 'Margin Bottom', 'dslc_string' ),
				'id' => 'css_margin_bottom',
				'std' => '0',
				'type' => 'slider',
				'refresh_on_change' => false,
				'affect_on_change_el' => '.features_sec04',
				'affect_on_change_rule' => 'margin-bottom',
				'section' => 'styling',
				'ext' => 'px',
			),
		);

		$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';
		
		
		/**
		 * Create column class for services
		*/
		
		?>

		<?php 
		if ($options['our_service_1'] || $options['our_service_2']  || $options['our_service_3'] || $options['our_service_4']) {
			$our_service_1 = get_post($options['our_service_1']);
			$our_service_2 = get_post($options['our_service_2']);
			$our_service_3 = get_post($options['our_service_3']);
			$our_service_4 = get_post($options['our_service_4']);
		?>
			<div class="container">
				<div class="features_sec04">
					<?php if ($options['left_image']): ?>
						<div class="left"><img src="<?php echo $options['left_image']; ?>" alt="" /></div><!-- end left -->
					<?php endif ?>
				    <div class="right">
				        <h2><?php echo $options['title']; ?> <em><?php echo $options['sub_title']; ?></em></h2>
				        <?php if ($options['desc']): ?>
				        	<b><?php echo stripslashes($options['desc']); ?></b>
				        <?php endif ?>
				        <div class="clearfix"></div>

				        <?php if ($our_service_1): ?>
				        	<?php $port_img_1 = wp_get_attachment_image_src( get_post_thumbnail_id($our_service_1->ID), 'large' ); ?>
				        	<ul class="section">
					        	<li class="left">
					        		<?php if ($port_img_1[0]): ?>
					        			<img src="<?php echo $port_img_1[0]; ?>" alt="" />
					        		<?php endif ?>
					        	</li>
					            <li><strong><?php echo $our_service_1->post_title; ?></strong> <?php echo substr($our_service_1->post_content, 0, 60); ?> 
					            	<?php if ($options['button_switch_readmore']=='enabled'): ?>
					            		<br /><a href="<?php echo get_permalink( $our_service_1->ID ) ?>">Read more <i class="fa fa-caret-right"></i></a>
					            	<?php endif ?>
					            </li>
					        </ul><!-- end section -->
				        <?php endif ?>

				        <?php if ($our_service_2): ?>
				        	<?php $port_img_2 = wp_get_attachment_image_src( get_post_thumbnail_id($our_service_2->ID), 'large' ); ?>
				        	<ul class="section two">
					        	<li class="left">
					        		<?php if ($port_img_2[0]): ?>
					        			<img src="<?php echo $port_img_2[0]; ?>" alt="" />
					        		<?php endif ?>
					        	</li>
					            <li><strong><?php echo $our_service_2->post_title; ?></strong> <?php echo substr($our_service_2->post_content, 0, 60); ?> 
					            	<?php if ($options['button_switch_readmore']=='enabled'): ?>
					            		<br /><a href="<?php echo get_permalink( $our_service_2->ID ) ?>">Read more <i class="fa fa-caret-right"></i></a>
					            	<?php endif ?>
					            </li>
					        </ul><!-- end section -->
				        <?php endif ?>

				        <?php if ($our_service_3): ?>
				        	<?php $port_img_3 = wp_get_attachment_image_src( get_post_thumbnail_id($our_service_3->ID), 'large' ); ?>
				        	<ul class="section three">
					        	<li class="left">
					        		<?php if ($port_img_3[0]): ?>
					        			<img src="<?php echo $port_img_3[0]; ?>" alt="" />
					        		<?php endif ?>
					        	</li>
					            <li><strong><?php echo $our_service_3->post_title; ?></strong> <?php echo substr($our_service_3->post_content, 0, 60); ?> 
					            	<?php if ($options['button_switch_readmore']=='enabled'): ?>
					            		<br /><a href="<?php echo get_permalink( $our_service_3->ID ) ?>">Read more <i class="fa fa-caret-right"></i></a>
					            	<?php endif ?>
					            </li>
					        </ul><!-- end section -->
				        <?php endif ?>

				        <?php if ($our_service_4): ?>
				        	<?php $port_img_4 = wp_get_attachment_image_src( get_post_thumbnail_id($our_service_4->ID), 'large' ); ?>
				        	<ul class="section four">
					        	<li class="left">
					        		<?php if ($port_img_4[0]): ?>
					        			<img src="<?php echo $port_img_4[0]; ?>" alt="" />
					        		<?php endif ?>
					        	</li>
					            <li><strong><?php echo $our_service_4->post_title; ?></strong> <?php echo substr($our_service_4->post_content, 0, 60); ?> 
					            	<?php if ($options['button_switch_readmore']=='enabled'): ?>
					            		<br /><a href="<?php echo get_permalink( $our_service_4->ID ) ?>">Read more <i class="fa fa-caret-right"></i></a>
					            	<?php endif ?>
					            </li>
					        </ul><!-- end section -->
				        <?php endif ?>
				    </div>
				</div><!-- end features section 4 -->
			</div>
		    <?php wp_reset_postdata(); ?>
	    <?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 } ?>
	    <div class="clearfix"></div>
	<?php
    	// REQUIRED
    	$this->module_end( $options );

    }
 
}