<?php
// +-------------------------------------------------+
// | 2002-2011 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: dynamics_fields_selector.class.php,v 1.1 2025/10/17 06:48:59 dgoron Exp $

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

class dynamics_fields_selector extends dynamics_fields {
    
    public static function val($field) {
        $name=$field['NAME'];
        global ${$name};
        
        return ${$name};
    }
    
    public static function aff($field,&$check_scripts) {
        global $msg;
        
        if (isset($field["OPTIONS"][0]["METHOD"]["0"]["value"]) && $field["OPTIONS"][0]["METHOD"]["0"]["value"] == 1) {
            $text_name=$field['NAME']."_label";
            $hidden_name=$field['NAME'];
            $param = $hidden_name;
            global ${$param};
            $text_value = get_authority_isbd_from_field($field, ${$param});
            $hidden_value = ${$param};
        } else {
            $text_name=$field['NAME'];
            $hidden_name=$field['NAME']."_id";
            $param = $text_name;
            global ${$param};
            $text_value = ${$param};
            $hidden_value = '';
        }
        
        $selection_parameters = get_authority_selection_parameters($field["OPTIONS"][0]["DATA_TYPE"]["0"]["value"]);
        $what = $selection_parameters['what'];
        $completion = $selection_parameters['completion'];
        $ret="<span style='width: 251px;'><input type='text' name='".$text_name."' id='".$text_name."' value='".$text_value."' class='saisie-30emr' completion='$completion' autfield='$hidden_name'></span>";
        
        $form_name = static::get_form_name();
        
        $ret.="<input class='bouton' value='...' onclick=\"openPopUp('./select.php?what=".$what."".(($selection_parameters['element']) ? "&element=".($selection_parameters['element']) : "")."&dyn=&caller=".$form_name."&param1=".$hidden_name."&param2=".$text_name."&p1=".$hidden_name."&p2=".$text_name."&deb_rech='+".pmb_escape()."(''), 'selector')\" type='button'>";
        $ret.="<input name='".$hidden_name."' id='".$hidden_name."' value='".$hidden_value."' type='hidden'>";
        
        if ($field['MANDATORY']=="yes") {
            $check_scripts.="if (document.".$form_name.".".$field['NAME'].".value==\"\") return cancel_submit(\"".sprintf($msg["parperso_field_is_needed"],$field['ALIAS'][0]['value'])."\");\n";
        }
        return $ret;
    }
}