<?php
define("WP_ADMIN", true);
// Call WP Load
$wp_include = "../wp-load.php";$i = 0;
while (!file_exists($wp_include) && $i++ < 10) {$wp_include = "../$wp_include";} require($wp_include);

if ( !is_user_logged_in() || !current_user_can('edit_posts') ) 
	wp_die(__("You are not allowed to be here","cloudfw"));
	
require (TMP_ADMIN_PATH.'/inc/core/core.slider.include_forms.php'); 
	
	global $_opt;
	
	$action = $_POST["action"];
	$type = $_POST["type"];
	
	$id = $_POST["id"];
	$main_slider_id = $_POST["main_slider_id"];
	$lastID = $_POST["lastID"];
	$this_page = $_POST["thispage"];
	
	
	switch ($action){
		case 'edit':
		
			if ($type == 'main_sliders') {
				
				if (isset($id)) {
					$data_ = $_opt[PFIX."_slider_ids"];
					$data = $data_[$id];
				}
						
				cloudfw_main_slider_forms( $this_page, $lastID, $data, $id );	
				
			}else{
				
							
				if (isset($id)) {
					$data_ = cloudfw_get_slider($main_slider_id);
					$data = $data_[$id];
				} 
					
				cloudfw_sub_slider_forms( $this_page ,$lastID, $data, $id, $main_slider_id);
					
			}
				
					
		
		break;	
		
		case 'loop':
			
			if (isset($main_slider_id)) {
				
				$slider_type = cloudfw_get_slider_type($main_slider_id);
				cloudfw_loop_slider_items(cloudfw_get_slider($main_slider_id),$slider_type, $main_slider_id);
			}
			else
				cloudfw_loop_all_sliders($_opt[PFIX."_slider_ids"],NULL, $this_page);
			
		
		break;

		
		case 'delete':
			
			if ($type == 'main_sliders') {
				
				cloudfw_loop_all_sliders(cloudfw_delete_slider($id),NULL,$this_page);
				
			}else{
				
				$slider_content = cloudfw_get_slider($main_slider_id);
				$slider_type = cloudfw_get_slider_type($main_slider_id);
				ksort($slider_content);
		
				$ii = 0;
				foreach ($slider_content as $vars => $var){
					
					if ((int)$vars !== (int)$id):
					
						$new_slider_content[$ii] = $slider_content[$vars];
					
						$ii++;		
					
					endif;
					}
				
				update_option($main_slider_id, $new_slider_content);
				cloudfw_loop_slider_items($new_slider_content, $slider_type, $id);

			}			
		
		break;

		
	}
	
	

?>