<?php
	include_once(__DIR__."/../../core.php");
	
	switch( $html->form('op', 'post') ){		

		case "update":
			if( $modules_info[$module_name]["permessi"] == 'rw' ){

				$id = $_POST['id_record'];
				$nome = save($_POST['nome']);
				$codice = save($_POST['codice']);
				$query = "UPDATE lb_formati SET nome=\"$nome\", codice=\"$codice\" WHERE id=$id";
				$rs = $dbo->query( $query );
				array_push( $_SESSION['infos'], "Informazioni salvate correttamente!" );
			}
			break;

		case "add":
			if( $modules_info[$module_name]["permessi"] == 'rw' ){
				$nome = save( $_POST['nome'] );
				$codice = save($_POST['codice']);
				$query = "INSERT INTO lb_formati(nome,codice) VALUES ('".$nome."','".$codice."')";
				$rs = $dbo->query($query);
				$id_record = $dbo->last_inserted_id();
				array_push( $_SESSION['infos'], "Nuovo tipo di etichetta aggiunto!" );
			}
			break;

		case "delete":
			if( $modules_info[$module_name]["permessi"] == 'rw' ){
				$query="DELETE FROM lb_formati WHERE id=\"$id_record\"";
				$rs = $dbo->query($query);
				array_push( $_SESSION['infos'], "Tipo di etichetta eliminato!" );
			}
			break;
	}
?>
