<?php
	chdir('../..');
	require_once('api/Simpla.php');
	$simpla = new Simpla();
	$object = $simpla->request->get('type');
	$yms = $simpla->request->post('ym');
	//print_r($yms);
	$res = array();
	switch ($object)
	{
		case 'prod':
			foreach($yms AS $id=>$val)
				$result = $simpla->products->update_product($id, array('ym'=>$val));					
				
			
		break;
		case 'cat':
			foreach($yms AS $id=>$val){
				$result = $simpla->categories->update_category($id, array('ym'=>$val));			
				$results = $simpla->products->get_products(array('category_id'=>$id));					
				foreach($results AS $p)
					$result = $simpla->products->update_product($p->id, array('ym'=>$val));					
					/*$ids[] = $p->id;
				
				if($val==0)
					print_r($ids);*/
			}
			
		break;
	}
	//print_r($yms);
	//$res = $yms;
	header("Content-type: application/json; charset=UTF-8");
	header("Cache-Control: must-revalidate");
	header("Pragma: no-cache");
	header("Expires: -1");		
	print json_encode($res);
