<?php	
	require_once("../includes/config.php");
	$ac = new DbQuery();
    $ac->checkLogin();
    
    if(isset($_POST) && $_POST['action']=='save-products-record' )
	{
	    $row = '';
	     foreach($_POST['products'] as $key=> $value){
	          $param = array(	
					'table' => 'product',
					'get'   =>'*',
					'where' => array('product'=> $value['product']),
				);

				$select = $ac->select($param,'get_row');
				 $params['table'] = 'product';
				 $params['field']['product'] = $value['product'];
				 $params['field']['vendor'] = $value['vendor'];
	            if($select)
				{
				    $params['where']['ID'] = $select['ID'];
					$row = $ac->update($params);
				}
				else
				{
					$row = $ac->insert($params);
				}
	    }
	    if($row){
			$_SESSION['success'] = $ac->getMessage('SUC_MSG');
			header('location:'.ROOT.'products.php');
			die();
    	}
    	else{
    		$_SESSION['failed'] = $ac->getMessage('INS_ERR_MSG');
    		header('location:'.ROOT.'products.php');
    		die();
    	}
	}
?>