<?php 

	require_once '../cron/class.db.php';
	$user = 0;
	$info = array();
	info($_POST);
	foreach($_POST as $item => $valor){
		if ($item != 'user'){
			$cadena = explode('_', $item);
			$info[$cadena[2]][$cadena[3]][$cadena[1]][$cadena[0]] = $valor;
		}else{
			$user = $valor;
		}
	}
	
	DataBase::getInstancia();

	foreach($info as $anyo => $registro){
		foreach ($registro as $mes => $registro2){
			foreach($registro2 as $horario => $registro3){
				foreach($registro3 as $laboral => $valor){
					info('horario: '.$horario.' Laboral: '.$laboral.' Mes: '.$mes.' ANNIO: '.$anyo.' Valor:'.$valor)
					if ($horario == 'D' && $laboral == 'L'){
						$sql = 'UPDATE credit_register SET morning = '.$valor.' WHERE date_month = '.$mes.' AND date_year = '. $anyo .' AND customer_id = ' . $user;
					}elseif( $horario == 'N' && $laboral == 'L'){
						$sql = 'UPDATE credit_register SET afternoon = '.$valor.' WHERE date_month = '.$mes.' AND date_year = '. $anyo .' AND customer_id = ' . $user;
					}elseif( $horario == 'D' && $laboral == 'FS' ){
						$sql = 'UPDATE credit_register SET festivo_morning = '.$valor.' WHERE date_month = '.$mes.' AND date_year = '. $anyo .' AND customer_id = ' . $user;
					} elseif ($horario == 'N' && $laboral == 'FS'){
						$sql = 'UPDATE credit_register SET festivo_afternoon = '.$valor.' WHERE date_month = '.$mes.' AND date_year = '. $anyo .' AND customer_id = ' . $user;
					}
					$result = DataBase::execute_query($sql,'S');
				}
			}
		}
	}
	
?>
