<?php

    ob_start();
	if ( !isset($refcde) )
    {
        $refcde = '';

        if ( isset($_REQUEST['refcde']) && trim($_REQUEST['refcde'])!='' )
        {
            $refcde = $_REQUEST['refcde'];
        }

   }
	
    if ( !isset($fld)  )
    {
        $fld = 'empcode';
    
        if ( isset($_REQUEST['fld']) && trim($_REQUEST['fld'])!='' )
        {
            $fld = $_REQUEST['fld'];
        }
    }
    
    require_once(prog_dir.'appconfig.php');

    if ( isset($_REQUEST['event_action']) && trim($_REQUEST['event_action'])=='delete' )
    {
        $xqry = "DELETE FROM employeeattachments WHERE recid=?;";   
        $stmt = $link_id->prepare($xqry);

        $arr_qry_params = array($_REQUEST['item_id']);

        $stmt->execute($arr_qry_params);
    }    


    $xqry = "SELECT * FROM employeeattachments WHERE $fld=?;";
    $stmt = $link_id->prepare($xqry);

    $arr_qry_params = array($refcde);

    $stmt->execute($arr_qry_params);

    if ( $rs = $stmt->fetch() )
    {

        echo "<table border='1' align='center' cellpadding='0' cellspacing='0'>
                <tr >
                    <td class='ui-widget-header' width='80px'>&nbsp;Date</td>
                    <td class='ui-widget-header' width='100px'>&nbsp;Doc. Type</td>
                     <td class='ui-widget-header' width='150px'>&nbsp;Filename</td>
                    <td class='ui-widget-header' width='200px'>&nbsp;Remarks</td>
                    <td class='ui-widget-header' width='100px' align='center'>&nbsp;Actions</td>
                </tr>";
        while($rs)
        {
            
            $item_id = $rs['recid'];

            $args = "event_action=edit&item_id=$item_id&refcde=$refcde";
/* <a href='#' onclick="<?php echo "edit_violations('$fld','$refcde','$item_id');"; ?>"><img src='./images/editbutton.gif' /></a>
                    <a href='#' onclick="<?php echo "delete_violations('$fld','$refcde','$item_id');"; ?>" >Delete</a>*/
?>
            <tr>
                <td><?php echo display_date($rs['dte']); ?></td>
                <td><?php echo $rs['doccode']; ?></td>
                <td><?php echo $rs['filename']; ?></td>
                <td><?php echo $rs['dsc']; ?></td>
                <td align='center'>
					<a href='#' onclick="<?php echo "open_dialog('{$args}','".prog_dir."proc_attachments.php','550','450','Attachments');"; ?>">Edit </a> |
                    <a href='#' onclick="<?php echo "open_dialog_delete('$fld','$refcde','$item_id','".prog_dir."list_attachments.php','attch');"; ?>" >Delete</a>
                   
                </td>
            </tr>
<?php
            $rs = $stmt->fetch();
        }        

        echo "</table>";
    }

    ob_end_flush();

?>
