<?php
	include_once(__DIR__."/../../core.php");
	
	switch( $html->form('op', 'post') ){
		case "update":
			if( $modules_info[$module_name]["permessi"] == 'rw' ){
				
				include ($docroot . "/lib/salva_personalizzati.php");		
				
				$r_nome = save( $_POST['r_nome'] );
				$r_mansione = save( $_POST['r_mansione'] );
				$r_stato = save( $_POST['r_stato'] );
				$r_telefono = save( $_POST['r_telefono'] );
				$r_cellulare = save( $_POST['r_cellulare'] );
				$r_email = save( $_POST['r_email'] );
				$r_note = save( $_POST['r_note'] );
				$r_fax = save( $_POST['r_fax'] );
			

				$query = "UPDATE an_referenti SET nome=\"$r_nome\", mansione=\"$r_mansione\", stato=\"$r_stato\", telefono=\"$r_telefono\", cellulare=\"$r_cellulare\",
				email=\"$r_email\", note=\"$r_note\", fax=\"$r_fax\" WHERE id=\"".$id_record."\"";

				$rs = $dbo->query( $query );
				array_push( $_SESSION['infos'], "Modifiche referente salvate!" );
			}
			break;

		case "add":
			if( $modules_info[$module_name]["permessi"] == 'rw' ){
				$idanagrafica = save( $_POST['idanagrafica'] );
				$r_nome = save( $_POST['r_nome'] );
				$r_mansione = save( $_POST['r_mansione'] );

				$query = "INSERT INTO an_referenti( idanagrafica, nome, mansione, stato ) VALUES ( \"$idanagrafica\", \"$r_nome\", \"$r_mansione\", 'Attivo' )";
				$dbo->query($query);
				
				array_push( $_SESSION['infos'], "Nuovo referente aggiunto!" );
				$id_record = $dbo->last_inserted_id();
			}
			break;

		case "delete":
			if( $modules_info[$module_name]["permessi"] == 'rw' ){
				$query="DELETE FROM an_referenti WHERE id=\"".$id_record."\"";
				$dbo->query($query);

				array_push( $_SESSION['infos'], "Referente eliminato!" );
			}
			break;
	}
?>
