PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/delivery_list.php

https://gitlab.com/Henaway/CLFC
PHP | 253 lines | 248 code | 5 blank | 0 comment | 19 complexity | 903e8bf0f0a9f18d1bd84a2d47e43b4a MD5 | raw file
  1. <?php
  2. include_once ("config_foodcoop.php");
  3. include_once ("general_functions.php");
  4. session_start();
  5. valid_auth('route_admin');
  6. $query = '
  7. SELECT
  8. '.TABLE_ROUTE.'.*,
  9. '.TABLE_DELCODE.'.delcode_id,
  10. '.TABLE_DELCODE.'.delcode,
  11. '.TABLE_DELCODE.'.hub,
  12. '.TABLE_DELCODE.'.deldesc,
  13. '.TABLE_DELCODE.'.route_id,
  14. '.TABLE_DELCODE.'.truck_code
  15. FROM
  16. '.TABLE_ROUTE.',
  17. '.TABLE_DELCODE.'
  18. WHERE
  19. '.TABLE_ROUTE.'.route_id = "'.mysql_real_escape_string ($_GET['route_id']).'"
  20. AND '.TABLE_DELCODE.'.route_id = '.TABLE_ROUTE.'.route_id
  21. AND '.TABLE_DELCODE.'.delcode_id = "'.mysql_real_escape_string ($_GET['delcode_id']).'"
  22. ORDER BY
  23. route_name ASC';
  24. $result = @mysql_query($query, $connection) or die(debug_print ("ERROR: 769302 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  25. while ( $row = mysql_fetch_array($result) )
  26. {
  27. $delcode_array = (array) $row;
  28. }
  29. $query = '
  30. SELECT
  31. 1 AS rte_confirmed,
  32. 1 AS finalized,
  33. '.NEW_TABLE_BASKETS.'.deltype as ddeltype,
  34. '.NEW_TABLE_BASKETS.'.basket_id,
  35. '.TABLE_MEMBER.'.member_id,
  36. last_name,
  37. first_name,
  38. first_name_2,
  39. last_name_2,
  40. business_name,
  41. preferred_name,
  42. home_phone,
  43. work_phone,
  44. mobile_phone,
  45. fax,
  46. email_address,
  47. email_address_2,
  48. address_line1,
  49. address_line2,
  50. city,
  51. state,
  52. zip,
  53. work_address_line1,
  54. work_address_line2,
  55. work_city,
  56. work_state,
  57. work_zip
  58. FROM
  59. '.NEW_TABLE_BASKET_ITEMS.'
  60. LEFT JOIN '.NEW_TABLE_BASKETS.' USING(basket_id)
  61. LEFT JOIN '.TABLE_MEMBER.' USING(member_id)
  62. LEFT JOIN '.NEW_TABLE_PRODUCTS.' USING(product_id,product_version)
  63. WHERE
  64. '.NEW_TABLE_BASKETS.'.delivery_id = "'.mysql_real_escape_string (ActiveCycle::delivery_id()).'"
  65. AND '.NEW_TABLE_BASKETS.'.delcode_id = "'.mysql_real_escape_string ($delcode_array['delcode_id']).'"
  66. AND '.NEW_TABLE_BASKET_ITEMS.'.out_of_stock != "1"
  67. AND '.NEW_TABLE_PRODUCTS.'.tangible = 1
  68. GROUP BY
  69. '.NEW_TABLE_BASKETS.'.basket_id
  70. ORDER BY
  71. last_name ASC';
  72. $result = @mysql_query($query, $connection) or die(debug_print ("ERROR: 769302 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  73. $num_orders = mysql_numrows($result);
  74. while ( $row = mysql_fetch_array($result) )
  75. {
  76. $member_array = (array) $row;
  77. $display .= '
  78. <table cellpadding=0 cellspacing=0 border=0><tr><td id="'.$member_id.'" width="400" valign=top>';
  79. $display .= '
  80. <li> <b>'.(convert_route_code(array_merge ($delcode_array, $member_array))).'</b><br>
  81. <a href="show_report.php?type=customer_invoice&delivery_id='.ActiveCycle::delivery_id().'&member_id='.$member_array['member_id'].'">
  82. <b>'.$member_array['preferred_name'].' (Mem#'.$member_array['member_id'].')</b></a><!-- - Deliverable Products: '.$product_quantity_of_member.' -->';
  83. $display .= ' <ul>';
  84. if ( $member_array['ddeltype'] == 'W' )
  85. {
  86. $display .= 'Work address:<br>';
  87. if ( $member_array['work_address_line1'] )
  88. {
  89. $display .= $member_array['work_address_line1'].'<br>';
  90. }
  91. else
  92. {
  93. $display .= 'No work address available<br>';
  94. }
  95. if ( $member_array['work_address_line2'] )
  96. {
  97. $display .= $member_array['work_address_line2'].'<br>';
  98. }
  99. if ( $member_array['work_city'] || $member_array['work_state'] || $member_array['work_zip'] )
  100. {
  101. $display .= $member_array['work_city'].', '.$member_array['work_state'].', '.$member_array['work_zip'].'<br>';
  102. }
  103. }
  104. else
  105. {
  106. $display .= 'Home address:<br>';
  107. $display .= $member_array['address_line1'].'<br>';
  108. if ( $member_array['address_line2'] )
  109. {
  110. $display .= $member_array['address_line2'].'<br>';
  111. }
  112. $display .= $member_array['city'].', '.$member_array['state'].', '.$member_array['zip'].'<br>';
  113. }
  114. $display .= 'Email: '.$member_array['email_address'].' <br>';
  115. if ( $member_array['email_address_2'] )
  116. {
  117. $display .= 'Email2: '.$member_array['email_address_2'].' <br>';
  118. }
  119. if ( $member_array['home_phone'] )
  120. {
  121. $display .= 'Home: '.$member_array['home_phone'].' <br>';
  122. }
  123. if ( $member_array['work_phone'] )
  124. {
  125. $display .= 'Work: '.$member_array['work_phone'].' <br>';
  126. }
  127. if ( $member_array['mobile_phone'] )
  128. {
  129. $display .= 'Cell: '.$member_array['mobile_phone'].' <br>';
  130. }
  131. if ( $member_array['fax'] )
  132. {
  133. $display .= 'Fax: '.$member_array['fax'].'<br>';
  134. }
  135. $display .= ' </ul><br>';
  136. $display .= '</td> <!-- <td valign="middle">';
  137. if ( $member_array['rte_confirmed'] == 1 )
  138. {
  139. $display .= '<b>Route Confirmed</b>';
  140. }
  141. else
  142. {
  143. $display .= '
  144. <form action="'.$PHP_SELF.'#'.$member_array['member_id'].'" method="post">
  145. <input type="hidden" name="member_id_passed" value="'.$member_array['member_id'].'">
  146. <input type="hidden" name="basket_id_passed" value="'.$member_array['basket_id'].'">
  147. <input type="hidden" name="subtotal" value="'.$member_array['total'].'">
  148. <input type="hidden" name="route_id" value="'.$_GET['route_id'].'">
  149. <input type="hidden" name="delcode_id" value="'.$member_array['delcode_id'].'">
  150. <input type="hidden" name="confirm_route" value="yes">
  151. <input type="submit" name="where" value="Confirm '.$member_array['first_name'].'&#146;s route info">
  152. </form>
  153. <br /><a href="delivery_change.php?member_id='.$member_array['member_id'].'&basket_id='.$member_array['basket_id'].'">Change this delivery/pick-up</a>';
  154. }
  155. $display .= '
  156. </td> -->
  157. </tr>
  158. </table>';
  159. }
  160. $quantity_all = 0;
  161. $query = '
  162. SELECT
  163. '.NEW_TABLE_BASKETS.'.delivery_id,
  164. '.NEW_TABLE_BASKETS.'.delcode_id,
  165. '.NEW_TABLE_BASKET_ITEMS.'.product_id,
  166. '.NEW_TABLE_PRODUCTS.'.product_name,
  167. SUM('.NEW_TABLE_BASKET_ITEMS.'.quantity) AS sum_p,
  168. '.NEW_TABLE_PRODUCTS.'.ordering_unit,
  169. '.NEW_TABLE_BASKET_ITEMS.'.out_of_stock,
  170. '.NEW_TABLE_BASKET_ITEMS.'.product_id,
  171. 1 AS future_delivery_id,
  172. '.TABLE_PRODUCER.'.business_name
  173. FROM
  174. '.NEW_TABLE_BASKET_ITEMS.'
  175. LEFT JOIN '.NEW_TABLE_BASKETS.' USING(basket_id)
  176. LEFT JOIN '.NEW_TABLE_PRODUCTS.' USING(product_id,product_version)
  177. LEFT JOIN '.TABLE_PRODUCER.' USING(producer_id)
  178. WHERE
  179. '.NEW_TABLE_BASKETS.'.delivery_id = "'.mysql_real_escape_string (ActiveCycle::delivery_id()).'"
  180. AND '.NEW_TABLE_BASKETS.'.delcode_id = "'.mysql_real_escape_string ($delcode_array['delcode_id']).'"
  181. AND '.NEW_TABLE_BASKET_ITEMS.'.out_of_stock != "1"
  182. GROUP BY
  183. '.NEW_TABLE_BASKET_ITEMS.'.product_id
  184. ORDER BY
  185. business_name,
  186. sum_p DESC';
  187. $result = @mysql_query($query, $connection) or die(debug_print ("ERROR: 860342 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  188. while ($row = mysql_fetch_array($result))
  189. {
  190. $product_id = $row['product_id'];
  191. $product_name = $row['product_name'];
  192. $product_quantity = $row['sum_p'];
  193. $ordering_unit = $row['ordering_unit'];
  194. $business_name = $row['business_name'];
  195. if (strlen ($business_name) > 16)
  196. {
  197. $business_name = str_replace (' ', '&nbsp;', substr ($business_name, 0, 9).'...'.substr ($business_name, -4, 4));
  198. }
  199. $display_p .= '
  200. <tr>
  201. <td align="right">'.$product_quantity.'</td>
  202. <td align="left">'.str_replace (' ', '&nbsp;', Inflect::pluralize_if ($product_quantity, $ordering_unit)).' </td>
  203. <td align="left">'.$business_name.'</td>
  204. <td>&nbsp; '.$product_name.' (#&nbsp;'.$product_id.')</td>
  205. </tr>';
  206. $quantity_all += $row['sum_p'];
  207. }
  208. $content_delivery = '
  209. <div align="center">
  210. <table width="80%" bgcolor="#FFFFFF" cellspacing="2" cellpadding="2" border="0">
  211. <tr>
  212. <td align="left">
  213. <h3>Route List: '.ActiveCycle::delivery_date().'</h3>
  214. </td>
  215. </tr>
  216. <tr>
  217. <td align="left" bgcolor="#DDDDDD">
  218. <b>Delivery Specifics: '.$delcode_array['delcode'].' (Hub: '.$delcode_array['hub'].')</b><br>
  219. '.$delcode_array['deldesc'].'<br><br>
  220. </td>
  221. </tr>
  222. <tr>
  223. <td align="left">
  224. The following information is based on preliminary information since we are still waiting for producer confirmations of products.<br><br>
  225. <b>Members on this Route ('.$num_orders.' Orders)</b>
  226. <ul>
  227. '.$display.'
  228. </ul><br>
  229. <b>'.$quantity_all.' Products on this Route</b>
  230. <blockquote>
  231. <table>
  232. '.$display_p.'
  233. </table>
  234. </blockquote><br>
  235. </td>
  236. </tr>
  237. </table>
  238. </div>';
  239. $page_title_html = '<span class="title">'.$delcode_array['route_name'].' Route Members</span>';
  240. $page_subtitle_html = '<span class="subtitle">'.date ('F d, Y', strtotime (ActiveCycle::delivery_date())).'</span>';
  241. $page_title = $delcode_array['route_name'].' Route Members: '.date ('F d, Y', strtotime (ActiveCycle::delivery_date()));
  242. $page_tab = 'route_admin_panel';
  243. include("template_header.php");
  244. echo '
  245. <!-- CONTENT BEGINS HERE -->
  246. '.$content_delivery.'
  247. <!-- CONTENT ENDS HERE -->';
  248. include("template_footer.php");