PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/shop/members/configure_labels.php

https://github.com/traceyambrose/foodcoop
PHP | 236 lines | 217 code | 12 blank | 7 comment | 30 complexity | 1cdd77835c361cebd48da9ee9dad0bc9 MD5 | raw file
  1. <?php
  2. require_once ("../func/label_config.class.php");
  3. session_start();
  4. $show_list = true;
  5. $defined_labels = array();
  6. if (! $_SESSION['return_target'])
  7. {
  8. $_SESSION['return_target'] = $_SERVER['HTTP_REFERER'];
  9. }
  10. if ($_GET['label_name'])
  11. {
  12. $_GET['label_name'] = strtr (base64_encode ($_GET['label_name']), '=', '-');
  13. }
  14. if ($_POST['label_name'])
  15. {
  16. $_POST['label_name'] = strtr (base64_encode ($_POST['label_name']), '=', '-');
  17. }
  18. // Get any already-stored printer configuration data
  19. if ($_COOKIE['defined_labels'])
  20. {
  21. $defined_labels = explode ('*',$_COOKIE['defined_labels']);
  22. }
  23. // Check whether we have selected a label and record that fact in the session
  24. if ($_GET['action'] == "select")
  25. {
  26. $_SESSION['label_select'] = $_GET['label_name'];
  27. $show_list = false;
  28. header( "Location:".$_SESSION['return_target']);
  29. $_SESSION['return_target'] = '';
  30. }
  31. // Check... what?
  32. if ($_POST['action'] == "YES")
  33. {
  34. $label_name = $_POST['label_name'];
  35. $defined_labels = array_diff($defined_labels, array ($label_name));
  36. $cookie_defined_labels = implode ('*', array_keys (array_flip ($defined_labels)));
  37. setcookie ('defined_labels', $cookie_defined_labels, time() + 3600 * 24 * 300);
  38. setcookie ($label_name, "", 0);
  39. }
  40. // Check whether we need to delete this label
  41. if ($_GET['action'] == "delete_query")
  42. {
  43. $label_name = $_GET['label_name'];
  44. echo '
  45. <table width="100%" height="100%"><tr><td valign="center" align="center">
  46. Do you really want to delete the label:<br><br><font size="+2">'.base64_decode (strtr ($label_name, '-', '=')).'</font><br><br>
  47. <form action="'.$_SERVER['PHP_SELF'].'" method="post">
  48. <input type="hidden" name="label_name" value="'.base64_decode (strtr ($label_name, '-', '=')).'">
  49. <input type="submit" name="action" value="YES">
  50. <input type="submit" name="action" value="NO">
  51. </form>
  52. </td></tr></table>
  53. ';
  54. $show_list = false;
  55. }
  56. // Check whether we just received a printer/label configuration
  57. //$label_name = preg_replace ("/[^0-9A-Za-z\-\+]/","", $_GET['label_name']);
  58. $label_name = $_GET['label_name'];
  59. if ($_GET['action'] == "set_config" && $label_name != '')
  60. {
  61. $number_of_columns = round (preg_replace ("/[^0-9\.\-]/","", $_GET['number_of_columns']), 3);
  62. $label_width = round (preg_replace ("/[^0-9\.\-]/","", $_GET['label_width']), 3);
  63. $horiz_spacing = round (preg_replace ("/[^0-9\.\-]/","", $_GET['horiz_spacing']), 3);
  64. $number_of_rows = round (preg_replace ("/[^0-9\.\-]/","", $_GET['number_of_rows']), 3);
  65. $label_height = round (preg_replace ("/[^0-9\.\-]/","", $_GET['label_height']), 3);
  66. $vert_spacing = round (preg_replace ("/[^0-9\.\-]/","", $_GET['vert_spacing']), 3);
  67. $page_top_margin = round (preg_replace ("/[^0-9\.\-]/","", $_GET['page_top_margin']), 3);
  68. $page_left_margin = round (preg_replace ("/[^0-9\.\-]/","", $_GET['page_left_margin']), 3);
  69. $label_margin = round (preg_replace ("/[^0-9\.\-]/","", $_GET['label_margin']), 3);
  70. $font_scaling = round (preg_replace ("/[^0-9\.]/","", $_GET['font_scaling']), 3);
  71. array_push ($defined_labels, $label_name);
  72. $cookie_defined_labels = implode ('*', array_keys (array_flip ($defined_labels)));
  73. $cookie_defined_label_config = implode ('~', array ($number_of_columns, $label_width, $horiz_spacing, $number_of_rows, $label_height, $vert_spacing, $page_top_margin, $page_left_margin, $label_margin, $font_scaling));
  74. setcookie ($label_name, $cookie_defined_label_config, time() + 3600 * 24 * 300);
  75. setcookie ('defined_labels', $cookie_defined_labels, time() + 3600 * 24 * 300);
  76. }
  77. // Display the currently configured printers
  78. if ($show_list == true)
  79. {
  80. echo '
  81. <h3>Label Selection and Configuration</h3>
  82. <table style="border:1px solid #aaa;">';
  83. foreach (array_keys (array_flip ($defined_labels)) as $defined_label)
  84. {
  85. echo '
  86. <tr style="background-color:#ddc;">
  87. <td style="font-size:1.7em;text-align:center;padding:0.1em 1em;">'.base64_decode (strtr ($defined_label, '-', '=')).'</td>
  88. <td style="text-align:center;padding:0.5em 3em;"><a href="'.$_SERVER['PHP_SELF'].'?action=configure&label_name='.base64_decode (strtr ($defined_label, '-', '=')).'">Configure<br>label</a></td>
  89. <td style="text-align:center;padding:0.5em 3em;"><a href="'.$_SERVER['PHP_SELF'].'?action=select&label_name='.base64_decode (strtr ($defined_label, '-', '=')).'">Select<br>label</a></td>
  90. <td style="text-align:center;padding:0.5em 3em;"><a href="'.$_SERVER['PHP_SELF'].'?action=delete_query&label_name='.base64_decode (strtr ($defined_label, '-', '=')).'">Delete<br>label</a></td>
  91. </tr>';
  92. }
  93. echo '
  94. </table><br>';
  95. if ($_GET['action'] != 'configure')
  96. {
  97. echo '
  98. Add a <a href="'.$_SERVER['PHP_SELF'].'?action=configure">new label</a> type.
  99. <br><br>';
  100. }
  101. echo '
  102. <div id="instr_head">
  103. <a href="#" onClick=\'{document.getElementById("instructions").style.display="";document.getElementById("instr_head").style.display="none";}\'>VIEW INSTRUCTIONS</a><br><br>
  104. </div>
  105. <div id="instructions" style="display:none";>
  106. <a href="#" onClick=\'{document.getElementById("instr_head").style.display="";document.getElementById("instructions").style.display="none";}\'>HIDE INSTRUCTIONS</a><br><br>
  107. This tool is used to configure labels for printing. Begin by
  108. choosing the &quot;new label&quot; link above. You will then be given a list
  109. of configuration options for the label sheet you will be using. The printer/label
  110. name should match the printing setup you will be using (e.g. Lexmark-Avery8160).
  111. This is just a name for your convenience and does not matter to the system. For
  112. multiple printers, it may be a good idea to include the printer name in the label
  113. because the configuration for the same labels may vary from one printer to another.
  114. <br>
  115. <br>
  116. During label configuration, please enter all units in &quot;inches&quot;. To save
  117. wasting label sheets, you might want to print &quot;page 2&quot; of the configuration
  118. screen on regular paper and hold it up to the light against your label sheet to see
  119. how well it matches. For greatest flexibility, it is advised that you set the margins
  120. on your browser print dialogue as small as they will go and make all necessary adjustments
  121. from this form. NOTE: Most measurements should be correct as measured on the label sheet
  122. but, because of the printer minimimum margin sizes, the top and left margins probably
  123. <em>will not</em> be correct. Once you print a test sheet, adjust the top and left
  124. margins accordingly to move the labels to the correct relative position.
  125. <br>
  126. <br>
  127. Once you have the labels configured the way you want, choose the &quot;Select label&quot;
  128. link to proceed. Label configurations are stored in a cookie on your computer and
  129. will remain for a year from their last update or until deleted. To create a new label,
  130. you may begin with an existing label and change the name before choosing the &quot;Set
  131. values&quot; button.
  132. <br><br></div>';
  133. }
  134. if (! $_COOKIE['defined_labels'] || $_GET['action'] == 'configure' || $_GET['action'] == 'set_config')
  135. {
  136. if ($_GET['action'] == 'configure')
  137. {
  138. list ($number_of_columns,
  139. $label_width,
  140. $horiz_spacing,
  141. $number_of_rows,
  142. $label_height,
  143. $vert_spacing,
  144. $page_top_margin,
  145. $page_left_margin,
  146. $label_margin,
  147. $font_scaling) = explode ('~', $_COOKIE[$_GET['label_name']]);
  148. }
  149. if (! $font_scaling)
  150. {
  151. $font_scaling = '1.0';
  152. };
  153. echo '
  154. <form action="'.$_SERVER['PHP_SELF'].'" method="get">
  155. <input type="hidden" name="action" value="set_config">
  156. <table style="background-color:#ddc;border:1px solid #888;">
  157. <tr>
  158. <td>Printer/Label Name</td>
  159. <td colspan="2"><input type="text" name="label_name" size="45" value="'.base64_decode (strtr ($label_name, '-', '=')).'"></td>
  160. </tr>
  161. <tr>
  162. <td><strong>N</strong>umber of <strong>Col</strong>umn<strong>s</strong></td>
  163. <td><input type="text" name="number_of_columns" size="5" value="'.$number_of_columns.'"></td>
  164. <td rowspan="10"><img src="grfx/label_calibration.gif"</td>
  165. </tr>
  166. <tr>
  167. <td>Label <strong>Width</strong></td>
  168. <td><input type="text" name="label_width" size="5" value="'.$label_width.'"> in.</td>
  169. </tr>
  170. <tr>
  171. <td><strong>H</strong>orizontal <strong>Spacing</strong></td>
  172. <td><input type="text" name="horiz_spacing" size="5" value="'.$horiz_spacing.'"> in.</td>
  173. </tr>
  174. <tr>
  175. <td><strong>Num</strong>ber of <strong>Rows</strong></td>
  176. <td><input type="text" name="number_of_rows" size="5" value="'.$number_of_rows.'"></td>
  177. </tr>
  178. <tr>
  179. <td>Label <strong>Height</strong></td>
  180. <td><input type="text" name="label_height" size="5" value="'.$label_height.'"> in.</td>
  181. </tr>
  182. <tr>
  183. <td><strong>V</strong>ertical <strong>Spacing</strong></td>
  184. <td><input type="text" name="vert_spacing" size="5" value="'.$vert_spacing.'"> in.</td>
  185. </tr>
  186. <tr>
  187. <td>* Page <strong>Top Margin</strong></td>
  188. <td><input type="text" name="page_top_margin" size="5" value="'.$page_top_margin.'"> in.</td>
  189. </tr>
  190. <tr>
  191. <td>* Page <strong>Left Margin</strong></td>
  192. <td><input type="text" name="page_left_margin" size="5" value="'.$page_left_margin.'"> in.</td>
  193. </tr>
  194. <tr>
  195. <td><strong>Label Margin</strong></td>
  196. <td><input type="text" name="label_margin" size="5" value="'.$label_margin.'"> in.</td>
  197. </tr>
  198. <tr>
  199. <td>** Font Scaling</td>
  200. <td><input type="text" name="font_scaling" size="5" value="'.$font_scaling.'"> x</td>
  201. </tr>
  202. <tr>
  203. <td colspan="2"><p style="font-size:0.8em;padding-left:2em;">* Top and left margins may differ from measured values.</p></td>
  204. </tr>
  205. <tr>
  206. <td colspan="2"><p style="font-size:0.8em;padding-left:2em;">** Font scaling can be used to make the font smaller (less than 1.0) or larger (greater than 1.0) than default size.</p></td>
  207. </tr>
  208. </table>
  209. <br>
  210. <input type="submit" name="null" value="Set Values"> &nbsp;
  211. <input type="reset" name="null" value="Reset">
  212. </form>';
  213. echo '
  214. To test this label alignment, print the page below (probably page #2 or #3, depending on your browser). You may need to set your margins to zero and turn off header and footer fields (find these in print settings for the browser you are using).<br>';
  215. if ($_GET['action'] == 'set_config' || $label_name != '')
  216. {
  217. $label_test = new output_Label ($number_of_columns, $label_width, $horiz_spacing, $number_of_rows, $label_height, $vert_spacing, $page_top_margin, $page_left_margin, $label_margin, $font_scaling);
  218. echo '<hr>';
  219. echo $label_test->printAlignmentPage();
  220. }
  221. }