PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/SERVER/admin/shelftags.php

https://github.com/joelbrock/is4c_nofc
PHP | 405 lines | 268 code | 45 blank | 92 comment | 32 complexity | 257ad6437b28dc615fa43bb04501ee82 MD5 | raw file
  1. <?php
  2. require_once '../define.conf';
  3. if (isset($_POST['submitted'])) {
  4. /**
  5. * fpdf is the pdf creation class doc
  6. * manual and tutorial can be found in fpdf dir
  7. */
  8. require('../src/fpdf/fpdf.php');
  9. /**
  10. * prodFuction contains several product related functions
  11. */
  12. // require('prodFunction.php');
  13. /**--------------------------------------------------------
  14. * begin barcode creation class from
  15. *--------------------------------------------------------*/
  16. /*******************************************************************************
  17. * Software: barcode *
  18. * Author: Olivier PLATHEY *
  19. * License: Freeware *
  20. * URL: www.fpdf.org *
  21. * You may use, modify and redistribute this software as you wish. *
  22. *******************************************************************************/
  23. define('FPDF_FONTPATH','font/');
  24. class PDF extends FPDF
  25. {
  26. function EAN13($x,$y,$barcode,$h=16,$w=.35)
  27. {
  28. $this->Barcode($x,$y,$barcode,$h,$w,12);
  29. }
  30. function UPC_A($x,$y,$barcode,$h=16,$w=.35)
  31. {
  32. $this->Barcode($x,$y,$barcode,$h,$w,12);
  33. }
  34. function GetCheckDigit($barcode)
  35. {
  36. //Compute the check digit
  37. $sum=0;
  38. for($i=1;$i<=11;$i+=2)
  39. $sum+=3*$barcode{$i};
  40. for($i=0;$i<=10;$i+=2)
  41. $sum+=$barcode{$i};
  42. $r=$sum%10;
  43. if($r>0)
  44. $r=10-$r;
  45. return $r;
  46. }
  47. function TestCheckDigit($barcode)
  48. {
  49. //Test validity of check digit
  50. $sum=0;
  51. for($i=1;$i<=11;$i+=2)
  52. $sum+=3*$barcode{$i};
  53. for($i=0;$i<=10;$i+=2)
  54. $sum+=$barcode{$i};
  55. return ($sum+$barcode{12})%10==0;
  56. }
  57. function Barcode($x,$y,$barcode,$h,$w,$len)
  58. {
  59. GLOBAL $genLeft;
  60. GLOBAL $descTop;
  61. //Padding
  62. //$barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
  63. //$barcode = $barcode . $check;
  64. /*if($len==12)
  65. $barcode='0'.$barcode;
  66. */
  67. //Add or control the check digit
  68. if(strlen($barcode)==12)
  69. $barcode.=$this->GetCheckDigit($barcode);
  70. elseif(!$this->TestCheckDigit($barcode))
  71. {
  72. $this->Error('This is an Incorrect check digit' . $barcode);
  73. //echo $x.$y.$barcode."\n";
  74. }
  75. //Convert digits to bars
  76. $codes=array(
  77. 'A'=>array(
  78. '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011',
  79. '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'),
  80. 'B'=>array(
  81. '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101',
  82. '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'),
  83. 'C'=>array(
  84. '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100',
  85. '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100')
  86. );
  87. $parities=array(
  88. '0'=>array('A','A','A','A','A','A'),
  89. '1'=>array('A','A','B','A','B','B'),
  90. '2'=>array('A','A','B','B','A','B'),
  91. '3'=>array('A','A','B','B','B','A'),
  92. '4'=>array('A','B','A','A','B','B'),
  93. '5'=>array('A','B','B','A','A','B'),
  94. '6'=>array('A','B','B','B','A','A'),
  95. '7'=>array('A','B','A','B','A','B'),
  96. '8'=>array('A','B','A','B','B','A'),
  97. '9'=>array('A','B','B','A','B','A')
  98. );
  99. $code='101';
  100. $p=$parities[$barcode{0}];
  101. for($i=1;$i<=6;$i++)
  102. $code.=$codes[$p[$i-1]][$barcode{$i}];
  103. $code.='01010';
  104. for($i=7;$i<=12;$i++)
  105. $code.=$codes['C'][$barcode{$i}];
  106. $code.='101';
  107. //Draw bars
  108. for($i=0;$i<strlen($code);$i++)
  109. {
  110. if($code{$i}=='1')
  111. $this->Rect($x+$i*$w,$y,$w,$h,'F');
  112. }
  113. //Print text uder barcode
  114. $this->SetFont('Arial','',9);
  115. $this->SetXY($genLeft,$descTop + 24);
  116. $this->Cell(49.609375,4,substr($barcode,-$len),0,0,'C');
  117. }
  118. }
  119. /**------------------------------------------------------------
  120. * End barcode creation class
  121. *-------------------------------------------------------------*/
  122. /**------------------------------------------------------------
  123. * Start creation of PDF Document here
  124. *------------------------------------------------------------*/
  125. if(isset($_POST['submit'])){
  126. foreach ($_POST AS $key => $value) {
  127. $$key = $value;
  128. }
  129. }else{
  130. foreach ($_GET AS $key => $value) {
  131. $$key = $value;
  132. }
  133. }
  134. $_SESSION['deptArray'] = 0;
  135. if($_POST['allDepts'] == 1) {
  136. // $_SESSION['deptArray'] = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,40";
  137. $dArray = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,40";
  138. } else {
  139. $allDepts = 0;
  140. }
  141. if(is_array($_POST['dept'])) {
  142. // $_SESSION['deptArray'] = implode(",",$_POST['dept']);
  143. $dArray = implode(",",$_POST['dept']);
  144. }
  145. /**
  146. * connect to mysql server and then
  147. * set to database with UNFI table ($data) in it
  148. * other vendors could be added here, as well.
  149. * NOTE: upc in UNFI is without check digit to match standard in
  150. * products.
  151. */
  152. // $db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
  153. // mysql_select_db(DB_NAME,$db);
  154. /**
  155. * $testQ query creates select for barcode labels for items
  156. */
  157. $testQ = "SELECT if(u.brand IS NULL,'',substring(u.brand,1,12)) as brand,
  158. if(u.sku IS NULL,'', u.sku) as sku,
  159. if(u.size IS NULL,'',u.size) as size,
  160. if(u.upc IS NULL,'',u.upc) as upc,
  161. if(u.units IS NULL,'',u.units) as units,
  162. if(u.cost IS NULL,'',u.cost) as cost,
  163. if(p.description IS NULL, substring(u.description,1,23),substring(p.description,1,23)) as description,
  164. right(p.upc,12) as pid,
  165. if(u.upc IS NULL, 'Misc', 'UNFI') as vendor,
  166. ROUND(normal_price,2) AS normal_price,
  167. p.scale AS scale
  168. FROM " . PRODUCTS_TBL . " as p left outer join UNFI as u on p.upc = u.upc
  169. WHERE p.department IN($dArray)
  170. AND date(modified) BETWEEN '$date1' AND '$date2'
  171. ORDER BY department";
  172. $result = mysql_query($testQ);
  173. if (!$result) {
  174. $message = 'Invalid query: ' . mysql_error() . "\n";
  175. $message .= 'Whole query: ' . $query;
  176. die($message);
  177. }
  178. /**
  179. * begin to create PDF file using fpdf functions
  180. */
  181. $hspace = 0.79375;
  182. $h = 29.36875;
  183. $top = 12.7 + 2.5;
  184. $left = 4.85 + 1.25;
  185. $space = 1.190625 * 2;
  186. $pdf=new PDF('P', 'mm', 'Letter');
  187. $pdf->SetMargins($left ,$top + $hspace);
  188. $pdf->SetAutoPageBreak('off',0);
  189. $pdf->AddPage('P');
  190. $pdf->SetFont('Arial','',10);
  191. /**
  192. * set up location variable starts
  193. */
  194. $barLeft = $left + 4;
  195. $descTop = $top + $hspace;
  196. $barTop = $descTop + 16;
  197. $priceTop = $descTop + 4;
  198. $labelCount = 0;
  199. $brandTop = $descTop + 4;
  200. $sizeTop = $descTop + 8;
  201. $genLeft = $left;
  202. $skuTop = $descTop + 12;
  203. $vendLeft = $left + 13;
  204. $down = 30.95625;
  205. $LeftShift = 51.990625;
  206. $w = 49.609375;
  207. $priceLeft = ($w / 2) + ($space);
  208. // $priceLeft = 24.85
  209. /**
  210. * increment through items in query
  211. */
  212. while($row = mysql_fetch_array($result)){
  213. /**
  214. * check to see if we have made 32 labels.
  215. * if we have start a new page....
  216. */
  217. if($labelCount == 32){
  218. $pdf->AddPage('P');
  219. $descTop = $top + $hspace;
  220. $barLeft = $left + 4;
  221. $barTop = $descTop + 16;
  222. $priceTop = $descTop + 4;
  223. $priceLeft = ($w / 2) + ($space);
  224. $labelCount = 0;
  225. $brandTop = $descTop + 4;
  226. $sizeTop = $descTop + 8;
  227. $genLeft = $left;
  228. $skuTop = $descTop + 12;
  229. $vendLeft = $left + 13;
  230. }
  231. /**
  232. * check to see if we have reached the right most label
  233. * if we have reset all left hands back to initial values
  234. */
  235. if($barLeft > 175){
  236. $barLeft = $left + 4;
  237. $barTop = $barTop + $down;
  238. $priceLeft = ($w / 2) + ($space);
  239. $priceTop = $priceTop + $down;
  240. $descTop = $descTop + $down;
  241. $brandTop = $brandTop + $down;
  242. $sizeTop = $sizeTop + $down;
  243. $genLeft = $left;
  244. $vendLeft = $left + 13;
  245. $skuTop = $skuTop + $down;
  246. }
  247. /**
  248. * instantiate variables for printing on barcode from
  249. * $testQ query result set
  250. */
  251. if ($row['scale'] == 0) {$price = $row['normal_price'];}
  252. elseif ($row['scale'] == 1) {$price = $row['normal_price'] . "/lb";}
  253. $desc = strtoupper(substr($row['description'],0,27));
  254. $brand = ucwords(strtolower(substr($row['brand'],0,13)));
  255. $pak = $row['units'];
  256. $size = $row['units'] . "-" . $row['size'];
  257. $sku = $row['sku'];
  258. $upc = $row['pid'];
  259. /**
  260. * determine check digit using barcode.php function
  261. */
  262. $check = $pdf->GetCheckDigit($upc);
  263. /**
  264. * get tag creation date (today)
  265. */
  266. $tagdate = date('m/d/y');
  267. $vendor = substr($row['vendor'],0,7);
  268. /**
  269. * begin creating tag
  270. */
  271. $pdf->SetXY($genLeft, $descTop);
  272. $pdf->Cell($w,4,substr($desc,0,20),0,0,'L');
  273. $pdf->SetXY($genLeft,$brandTop);
  274. $pdf->Cell($w/2,4,$brand,0,0,'L');
  275. $pdf->SetXY($genLeft,$sizeTop);
  276. $pdf->Cell($w/2,4,$size,0,0,'L');
  277. $pdf->SetXY($priceLeft+9,$skuTop);
  278. $pdf->Cell($w/3,4,$tagdate,0,0,'R');
  279. // $pdf->SetFont('Arial','',10);
  280. $pdf->SetXY($genLeft,$skuTop);
  281. $pdf->Cell($w/3,4,$sku,0,0,'L');
  282. $pdf->SetXY($vendLeft,$skuTop);
  283. $pdf->Cell($w/3,4,$vendor,0,0,'C');
  284. $pdf->SetFont('Arial','B',20);
  285. $pdf->SetXY($priceLeft,$priceTop);
  286. $pdf->Cell($w/2,8,$price,0,0,'R');
  287. /**
  288. * add check digit to pid from testQ
  289. */
  290. $newUPC = $upc . $check;
  291. $pdf->UPC_A($barLeft,$barTop,$upc,7);
  292. /**
  293. * increment label parameters for next label
  294. */
  295. $barLeft =$barLeft + $LeftShift;
  296. $priceLeft = $priceLeft + $LeftShift;
  297. $genLeft = $genLeft + $LeftShift;
  298. $vendLeft = $vendLeft + $LeftShift;
  299. $labelCount++;
  300. }
  301. /**
  302. * write to PDF
  303. */
  304. $pdf->Output();
  305. } else { // Show the form.
  306. $page_title = 'Fannie - Administration Module';
  307. $header = 'Shelftag Generator';
  308. include ('../src/header.php');
  309. echo '<link href="../style.css" rel="stylesheet" type="text/css" />
  310. <script src="../src/CalendarControl.js" language="javascript"></script>
  311. <script src="../src/putfocus.js" language="javascript"></script>
  312. </head>
  313. <body onLoad="putFocus(0,0);">
  314. <link href="../style.css" rel="stylesheet" type="text/css">
  315. <script src="../src/CalendarControl.js" language="javascript"></script>
  316. <form method="post" action="shelftags.php" target="_blank">
  317. <h2>Shelftag Generator</h2>
  318. <table border="0" cellspacing="3" cellpadding="3">
  319. <tr>
  320. <th align="center"> <p><b>Select dept.*</b></p></th>
  321. </tr>
  322. <tr>';
  323. include('../src/departments.php');
  324. echo '</tr>
  325. </table>
  326. <table border="0" cellspacing="3" cellpadding="3">
  327. <tr>
  328. <td align="right">
  329. <p><b>Date Start</b> </p>
  330. <p><b>End</b></p>
  331. </td>
  332. <td>
  333. <div class="date"><p><input type="text" name="date1" class="datepicker" />&nbsp;&nbsp;*</p></div>
  334. <div class="date"><p><input type="text" name="date2" class="datepicker" />&nbsp;&nbsp;*</p></div>
  335. </td>
  336. <td colspan=2>
  337. <p>Date format is YYYY-MM-DD</br>(e.g. 2004-04-01 = April 1, 2004)</p>
  338. </td>
  339. </tr>
  340. <tr>
  341. <td>&nbsp;</td>
  342. <td> <input type=submit name=submit value="Submit"> </td>
  343. <td> <input type=reset name=reset value="Start Over"> </td>
  344. <input type="hidden" name="submitted" value="TRUE">
  345. </tr>
  346. </table>
  347. </form>';
  348. include('../src/footer.php');
  349. }
  350. ?>
  351. <script>
  352. $(function() {
  353. $( ".datepicker" ).datepicker({
  354. dateFormat: 'yy-mm-dd'
  355. });
  356. });
  357. </script>