Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/application/classes/Controller/Ajax.php
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Ajax extends Controller {

	
	public function action_getItems() {
	

		$type = !empty( $_GET['type'] ) ? addslashes($_GET['type'] ) : 'zubrowka';
		$fn = !empty( $_GET['fn'] ) ? addslashes($_GET['fn'] ) : 'zubr_wiz_01.png';
		$category = !empty( $_GET['category'] ) ? addslashes($_GET['category'] ) : 'zabawne';
		
		if( $type == 'wyborowa' ) $fn = 'wyborowa_wiz_01.png';
		if( $type == 'uniwersalna' ) $fn = 'uni_wiz_01.png';   
		if( $type == 'tadeusz' ) $fn = 'pt_01.png';  
		if( $type == 'delux' ) $fn = 'delux_01.png';
		if( $type == 'bols' ) $fn = 'bols_01.png';
		
		if( $type == 'uniwersalna' ) {
			$fn = str_replace("10x5_mini", "uni_wiz", $fn);
		} else {
			$fn = str_replace("mini", "wiz", $fn);
		}
		
		$max_page = 5;
		
       
		$items = array();
		
		$path = 'uploads/items/etykiety_podglad/'.$type.'/'.$category.'/';
	
		if( is_dir( $path ) ) {
			$dir=opendir($path);
			
			
			while($file_name=readdir($dir))
			{
				if(($file_name!=".")&&($file_name!="..")) {
					$items[$file_name] = $file_name;
					$max_page++;
				}
			}
		}
		
		sort($items);
		
		
		if( $type == "tadeusz" ) $divid = 4;
		elseif( $type == "bols" ) $divid = 4;
    else $divid = 6;
		
		$max_page = floor($max_page/$divid);
		
		$info = "<script>
	$(window).ready( function() {
	
	
		$('.item2 img').hover( function() {
			$(this).addClass('shadow_eff');
		}, function() {
		
			$(this).removeClass('shadow_eff');
		});
		
		
	$('.change_label').click( function() {
		
                $('#sider .edit-box .loading').fadeTo(300, 0.9);
                $('#sider .edit-box .loading').delay(350).hide(0);
    
    	
			$('.edit_link').addClass('edit_link_effect');
			var fn = $(this).attr('fn');
			var type = $(this).attr('type');
			
			fn = fn.replace('eleg_krupnik_','krup_wiz_eleg_');
			fn = fn.replace('krupnik_mini_','krup_wiz_');
			fn = fn.replace('wyborowa_','wyb_wiz_');
			fn = fn.replace('10x5_mini','uni_wiz');
			fn = fn.replace('mini','wiz');
			$('.visual').attr('src', 'uploads/items/butelki_wizualizacja/'+type+'/".$category."/'+fn);
			$('.link_visual').attr('href', 'product/'+type+'!".$category."!'+fn+'/1');
			$('.edit_link').attr('href', 'product/'+type+'!".$category."!'+fn+'/1');
			
			return false;
		});
		}); 
		</script>
		";
		
		$i=1; $num_lay=1; foreach( $items as $item ) : 
			if( $i == 1 ) : 
			$hid = $num_lay > 1  ? 'style="display: none;"' : '';
			$info .= '<div class="bootles_layer bootle_lay'.$num_lay.'" '.$hid.'>';
			endif;
			
			$class = ( $type=='wyborowa' ) ? 'item2_wyborowa' : ''; 
			
					$info .= '<div class="item2 '.$class.'">';
						$info .= '<a class="change_label" type="'.$type.'" fn="'.$item.'" href="?type='.$type.'&fn='.$item.'"><img src="/'.$path.$item.'" class="thumb" alt=""/></a>';
					$info .= '</div>';
				if( $i == $divid ) : $i = 0; $num_lay++; 
					$info .= '</div>';
					
					endif; 
					$i++;  endforeach; 
					
					$result = array();
					$result['info'] = $info;
					$result['max_page'] = $max_page;
					echo json_encode($result);
					exit;
					
	}
}