<?php


function smarty_function_sugar_printer($params, &$smarty)
{
    include_once 'modules/'.$params['module'].'/PDFTemplate/types.php';
    $onclick="if($('#PrinterDivList').css('display') == 'none'){ $('#PrinterDivList').show('slow'); } else { $('#PrinterDivList').hide('slow'); }";
    $html='<script src="include/jQuery/printerScripts.js"></script><input type="button" onclick="'.$onclick.'" value="Druk">';
    $html.='<div id="PrinterDivList" style="border: 1px solid rgb(204, 204, 204); background: none repeat scroll 0% 0% rgb(230, 230, 230); padding: 5px; position: absolute;display:none;">';
               
    $db=$GLOBALS['db'];
	$wp=$db->query("select id,name,description,ip from ecmdevices where type='0' and deleted='0'");
	
	if ($wp->num_rows == '0') {
		$html.='Brak skonfigurowanych drukarek. Skontaktuj się z administratorem systemu</div>';
		return $html;
	}
		
	$html.='<table><tr><td>Urządzenie:</td><td><select id="PrinterSelectList">';
	$list=array();
	while($a=$db->fetchByAssoc($wp)){
	    $html.='<option value="'.$a['id'].'">'.$a['name'].'</option>';
	}
	$printpar="'".$params['module']."','".$params['id']."'";
	$html.='</select></td></tr>';

	
	//add mz 06-05-2015
	//load PDF settings
	$html.='<tr><td colspan="2">';
	$_REQUEST['destination'] = "PrintPdf";
	require_once 'include/ECM/EcmCreatePdfButton.php';
	$html.=createOptions($_REQUEST['module'], "PrintPdf");
	unset($_REQUEST['destination']);
	$html.='</td></tr>';
	//end mz
	
	$html.='<tr><td><input type="button" onclick="checkPrint('.$printpar.',getPrintPdfOpt())" value="Drukuj"></td><td></td></tr></table></div>';
	return $html;
	if(!isset($params['name'])){
		$smarty->trigger_error("sugar_field: missing 'name' parameter");
		return;
	}
	$db=$GLOBALS['db'];
	$wp=$db->query("select id,name from ecmdevices");
	while($a=$db->fetchByAssoc($wp)){
	    
	}
	return 'ok!';
	
}