<?php
// +-------------------------------------------------+
// © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: serialcirc_diff.inc.php,v 1.14.6.1 2025/10/23 08:34:01 dgoron Exp $

if (stristr($_SERVER['REQUEST_URI'], ".inc.php")) die("no access");

global $class_path, $sub, $action;
global $id_serialcirc, $num_abt, $empr_id;
global $duration, $id_empr, $id_diff, $diff_list;

require_once("$class_path/serialcirc_diff.class.php");

$id_serialcirc = intval($id_serialcirc);
$num_abt = intval($num_abt);
$empr_id = intval($empr_id);

$serialcirc_diff=new serialcirc_diff($id_serialcirc,$num_abt);

switch($sub){		
	case 'option_form':
		if($action=='save'){
			$data = $serialcirc_diff->get_option_data_from_form();
			$serialcirc_diff->option_save($data); 	
			print $serialcirc_diff->show_form();
		}
	break;	
	case 'ficheformat_form':
		if(!isset($data)) $data = array();
		if($action=='save'){
			
			$serialcirc_diff->ficheformat_save($data); 
			print $serialcirc_diff->show_form(5);
		} elseif($action=='add_field'){			
			$serialcirc_diff->ficheformat_add_field($data); 
			print $serialcirc_diff->show_form(5);
		} elseif($action=='del_field'){			
			$serialcirc_diff->ficheformat_del_field($data); 
			print $serialcirc_diff->show_form(5);
		} elseif($action=='change_fields'){
			$serialcirc_diff->ficheformat_change_fields($data); 
			print $serialcirc_diff->show_form(5);
		}
	break;	
	case 'empr_form':
		if($action=='save'){
		    if(!isset($data)) {
		        $data = array();
		    }
			$data['duration'] = intval($duration);
			$data['id_empr'] = intval($id_empr);
			$serialcirc_diff->empr_save($id_diff,$data);
			$serialcirc_diff->sort_diff(); 
			print $serialcirc_diff->show_form($form_ask);
		}
	break;	
	case 'group_form':		
		if($action=='save'){
		    $data = $serialcirc_diff->get_group_data_from_form();
			$serialcirc_diff->group_save($id_diff,$data);
			$serialcirc_diff->sort_diff();
			print $serialcirc_diff->show_form();
		}		
	break;	
	case 'del_empr':
		print $serialcirc_diff->del_empr($id_empr); 	
	break;	
	case 'del_diff':
	    if (is_countable($diff_list) && count($diff_list)) {
    		foreach($diff_list as $id_diff){
    			$serialcirc_diff->del_diff($id_diff);
    		}
	    }
		print $serialcirc_diff->show_form(1);
	break;		
	case 'delete':
		if($msg_error=$serialcirc_diff->delete($num_abt)){
			$retour = "./circ.php?categ=serialcirc";
			error_message('', $msg_error, 1, $retour);
			print $serialcirc_diff->show_form();
		}else {			
			$query="select num_notice from abts_abts where abt_id=$num_abt";
			$result = pmb_mysql_query($query);
			if(pmb_mysql_num_rows($result)){
				$r = pmb_mysql_fetch_object($result);
				print "<script type=\"text/javascript\">document.location='catalog.php?categ=serials&sub=view&view=abon&serial_id=".$r->num_notice."';</script>";				
			}	
		}
	break;
	case 'sort_diff':
		$serialcirc_diff->sort_diff();
		print $serialcirc_diff->show_form();
		break;
	default :			
		if($empr_id){	
			print $serialcirc_diff->show_form(4,$empr_id);
		} else {
		    print $serialcirc_diff->show_form();
		}
	break;		
	
}
