<?php
/*=======================================================================
 *
 * stock_barcodelist.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/
 

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../include/inc_dbfields2array.inc.php");


// Check HTTP-Parameters
// Stocks
getSecHttpVars("1",array("f_act", "customerId", "cscIdRoot", "statusMessage", "deactivateMenu",
                         "stkIdRoot", "stkIdCurrent"));

// Id of the current employee and the costcenter (individual root-node) logged in
if ($cscIdRoot == ""): $cscIdRoot = getFieldValueFromId("employee","emp_id",$emp_id,"csc_id"); endif;
if ($customerId == ""): $customerId = getFieldValueFromId("costcenter","csc_id",$cscIdRoot,"cs_id"); endif;

// Get the rights of the employee logged in
$empRights = getRights($emp_id);

// Init
if ($cscIdCurrent == ""): $cscIdCurrent = $cscIdRoot; endif;
if ($hqId == ""): $hqId = $hq_id; endif;
if ($customerId == ""): $customerId = "0"; endif;

// Attention: Definition AFTER definitions of $customerId, $cscIdRoot and $cscIdCurrent
$pageTitel = "LÄGER";
$deactivateMenuStatic = "1";
if ($generatePDF != "1") :
   include_once ("../geo/geocode.inc.php");
endif;
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_stock.inc.php");

// Get the rights of the employee logged in and check the accessibility
// authCheckEmployeeRights($emp_id, "14", "1");

// Select user-type for mode of security check 
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);

// Parameters have to exist for both: customer and headquarter
if (($userTypeName != "stk") && ($customerId == "" || $cscIdRoot == "" || $cscIdCurrent == "")) :
   gotoReferer("1");  // Parameter missing
endif;

// Check authentication verifying emmployee an his/her costcenter- and customer-association
if ( !( ($userType == "1") || ($userType == "4") || authCheck($hq_id,$usr_id,$emp_id,$cscIdRoot,$customerId,$cscIdActual) ) ) :
   gotoReferer("1");
endif;

if ($stkIdCurrent == "" || !is_numeric($stkIdCurrent) && isStkChild($stkIdRoot, $stkIdCurrent, "1")) :
   $stkIdCurrent = $stkIdRoot;
endif;

// Get all stocks of the current root stock
$output = "";
$tableSpacer = "150";
if ($stkIdCurrent != "" && is_numeric($stkIdCurrent)) :

   $sqlStmt = getStmtAllStocksByStkId($stkIdCurrent);
   $result = $db->query($sqlStmt);     
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   $orientation = "0";
   $output .= "<table>\n";
   while ($row = $result->fetch_assoc()):
     if ($orientation == "0") :
        $output .= "  <tr>\n";
     endif;
     $output .= "    <td>\n";
     $output .= "      <span class=\"f14bp1\">" . $row["stk_name"] . "</span>";
     $output .= "    </td>\n";
     $output .= "    <td>&nbsp;&nbsp;&nbsp;</td>";
     $output .= "    <td>\n";
     $tmpStkBarcode = trim($row["stk_barcode"]);
     if ($tmpStkBarcode != "") :
        $output .= "       <img src=\"../include/barcode_BCGcode39.php?scale=1&text=" . $tmpStkBarcode . "\">";
        $output .= "       <br><br>";
     endif;
     $output .= "    </td>\n";
     
     if ($orientation == "0") :
        $output .= "    <td width=\"" . $tableSpacer . "\">\n";
        $output .= "      &nbsp;";
        $output .= "    </td>\n";
     endif;
     
     if ($orientation == "1") :     
        $output .= "  </tr>\n";
     endif;   
     
     if ($orientation == "0") :
        $orientation = "1";
     else :
        $orientation = "0";
     endif;
   endwhile;
   $result->free();
   $output .= "</table>\n";
endif;
?>


<html>

<head>
<title>BARCODES DER LAGERORTE</title>

</head>

<body>

<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>

<div class="maincontent" name="maincontent" id="maincontent">

<?php echo $output ?>

</div>
</body>

</html>

