<?php 

function createOptions2($module, $dest) {

    if (!file_exists("modules/$module/PDFTemplate/types.php"))
        return "";
    include "modules/$module/PDFTemplate/types.php";

    if (count($pdf_types) == 0) {
        return false;
        } else {

        $html = "<fieldset id='$dest'><legend>Ustawienia PDF</legend>";
        if (count($pdf_types) > 0) {
		$html.='Typ&nbsp;<select id="pdf_type" name="pdf_type">';
		foreach ($pdf_types as $k=>$v)
		    $html.='<option value="'.$k.'">'.$v.'</option>';
		$html.='</select><br>';
		}
		if ($pdf_languages) {
		if (count($pdf_types) > 0) $html.='<br>';
		$html.='Język&nbsp;<select name="pdf_lang" id="pdf_lang">';
		$html.='<option value="pl_pl">Polski</option>';
		$html.='<option value="en_us">Angielski</option>';
		$html.='</select><br>';
		}
		    if (count($pdf_options) > 0) {
		    if (count($pdf_types) > 0 || $pdf_languages == true) $html.='<br>';
		    foreach ($pdf_options as $k=>$v)
		        $html.='<input type="checkbox" name="'.$k.'" id = "'.$k.'"/>&nbsp;&nbsp;'.$v.'<br>';
		}
		$html.= "</fieldset>";
	//js function preparing data
	$js = "<script>function get".$dest."Opt() { var pdf_params = '';";
	if (count($pdf_types) > 0) $js.="pdf_params+='pdf_type='+$('#".$dest."').find('#pdf_type').val()+'&';";
	if ($pdf_languages) $js.="pdf_params+='pdf_language='+$('#".$dest."').find('#pdf_lang :selected').val()+'&';";
	if (count($pdf_options) > 0) {
		$js.="var opt = $('#".$dest." input:checkbox:checked').map(function() {return this.id}).get();";
		$js.="pdf_params+='pdf_opt='+opt+'&';";
		}
		    $js.="return pdf_params;}</script>";
		    return $html.$js;

	}
}

function showBtn2($module, $dest) {
	$html='<input title="PDF" class="button" onclick="if($(\'#div_pdf\').css(\'display\') == \'none\'){$(\'#div_pdf\').show(\'slow\'); } else { $(\'#div_pdf\').hide(\'slow\'); }" type="button" name="productcard" id="productcard" value="PDF">';
	$html.='<div id="div_pdf" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;position:absolute;display:none;">';
	$html.=createOptions2($module, $dest);
	$html.='<input name="quote_pdf" id="quote_pdf" title="Show PDF" accessKey="" class="button" onclick="window.open(\'index.php?\'+get'.$dest.'Opt()+\'module='.$module.'&action=createPDF&to_pdf=1&record='.$_REQUEST['record'].'\',\'_blank\');" type="button" value="Pokaż PDF"></div>';
	$html.='</div>';
	return $html;
}


//if ($_REQUEST['destination'] && $_REQUEST['']);
switch ($_REQUEST['action']){

    case 'DetailView':
        if(!$_REQUEST['destination']){
            
            echo showBtn($_REQUEST['module'], 'PdfOptionDiv');
        }
        break;
}

?>