PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/panel_producer_admin.php

https://gitlab.com/Henaway/CLFC
PHP | 308 lines | 245 code | 27 blank | 36 comment | 29 complexity | adb9009e811a270d9a89a60f37aedad0 MD5 | raw file
  1. <?php
  2. include_once ('config_foodcoop.php');
  3. include_once ('general_functions.php');
  4. session_start();
  5. valid_auth('producer_admin');
  6. $producer_admin_true = 0;
  7. if (CurrentMember::auth_type('producer_admin')) $producer_admin_true = 1;
  8. else header("Location: index.php");
  9. // Check if we need to change the unlisted_producer status
  10. if (isset ($_REQUEST['list_producer']) && $_SESSION['producer_id_you'] != '' )
  11. {
  12. if ( $_REQUEST['list_producer'] == 'relist' )
  13. {
  14. $unlisted_producer = 0;
  15. }
  16. elseif($_REQUEST['list_producer'] == "unlist")
  17. {
  18. $unlisted_producer = 1;
  19. }
  20. elseif($_REQUEST['list_producer'] == "suspend")
  21. {
  22. $unlisted_producer = 2;
  23. }
  24. $sqlr = '
  25. UPDATE
  26. '.TABLE_PRODUCER.'
  27. SET
  28. unlisted_producer = "'.mysql_real_escape_string ($unlisted_producer).'"
  29. WHERE
  30. producer_id = "'.mysql_real_escape_string ($_SESSION['producer_id_you']).'"';
  31. $resultr = @mysql_query($sqlr,$connection) or die(debug_print ("ERROR: 904933", array ($sqlr,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  32. $message = 'Producer # '.$producer_id.' has been updated.<br>';
  33. }
  34. if ($_GET['producer_id_you'])
  35. {
  36. // Make sure we are authorized to "become" this producer
  37. // Either we are the member who is the producer or we are a producer admin
  38. $query = '
  39. SELECT
  40. business_name
  41. FROM
  42. '.TABLE_PRODUCER.'
  43. WHERE
  44. producer_id = "'.mysql_real_escape_string ($_GET['producer_id_you']).'"';
  45. $result = @mysql_query($query, $connection) or die(debug_print ("ERROR: 860943 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  46. while ($row = mysql_fetch_object($result))
  47. {
  48. $_SESSION['producer_id_you'] = $_GET['producer_id_you'];
  49. $active_business_name = $row->business_name;
  50. }
  51. }
  52. // // If we have reached this point without a producer_id_you, then we need to get a default one or abort...
  53. // // Make sure we are authorized to "become" this producer
  54. // // Either we are the member who is the producer or we are a producer admin
  55. // if (! $_SESSION['producer_id_you'])
  56. // {
  57. // $query = '
  58. // SELECT
  59. // producer_id,
  60. // business_name
  61. // FROM
  62. // '.TABLE_PRODUCER.'
  63. // WHERE
  64. // member_id = '.mysql_real_escape_string ($_SESSION['member_id']).'
  65. // OR producer_id = "'.mysql_real_escape_string ($_SESSION['producer_id_you']).'"
  66. // ORDER BY
  67. // business_name
  68. // LIMIT 0,1';
  69. // $result = @mysql_query($query, $connection) or die(debug_print ("ERROR: 537557 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  70. // while ($row = mysql_fetch_object($result))
  71. // {
  72. // if ($row->producer_id)
  73. // {
  74. // $_SESSION['producer_id_you'] = $row->producer_id;
  75. // $active_business_name = $row->business_name;
  76. // }
  77. // }
  78. // }
  79. // Get a list of all the producer_id values for this member
  80. $query = '
  81. SELECT
  82. member_id,
  83. producer_id,
  84. business_name,
  85. pending AS pending_producer,
  86. unlisted_producer
  87. FROM
  88. '.TABLE_PRODUCER.'
  89. WHERE
  90. 1
  91. ORDER BY
  92. unlisted_producer,
  93. business_name';
  94. $result = @mysql_query($query, $connection) or die(debug_print ("ERROR: 759326 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
  95. while ( $row = mysql_fetch_object($result) )
  96. {
  97. $pending_producer = $row->pending_producer;
  98. // Preset/clear variables
  99. $active_class = '';
  100. $active_display = '';
  101. $pending_class = '';
  102. $pending_display = '';
  103. if ($row->pending_producer == 1)
  104. {
  105. $pending_class = ' pending';
  106. $pending_display = '[PENDING] ';
  107. }
  108. if ($row->producer_id == $_SESSION['producer_id_you'])
  109. {
  110. $active_class = ' current';
  111. $active_display = '';
  112. $active_business_name = $row->business_name;
  113. }
  114. if ($row->unlisted_producer == 0)
  115. {
  116. $producer_list = '
  117. <li class="listed'.$active_class.$pending_class.'"><a href="'.$_SERVER['PHP_SELF'].'?producer_id_you='.$row->producer_id.'">'.$active_display.$pending_display.htmlspecialchars($row->business_name, ENT_QUOTES).'</a> (Listed)</li>';
  118. if ($row->producer_id == $_SESSION['producer_id_you'])
  119. $list_status_html = '
  120. <ul class="fancyList1">
  121. '.$producer_list.'<br>
  122. <li class="unlisted"><a href="'.$_SERVER['PHP_SELF'].'?list_producer=unlist">Unlist '.$active_business_name.'</a><br>(Temporarily remove all '.$active_business_name.' products from the shopping lists)</li><br>
  123. <li class="suspended last_of_group"><a href="'.$_SERVER['PHP_SELF'].'?list_producer=suspend">Suspend '.$active_business_name.'</a><br>(Temporarily remove '.$active_business_name.' from all producer lists and all '.$active_business_name.' products from the shopping lists)</li>
  124. </ul>';
  125. }
  126. elseif ($row->unlisted_producer == 1)
  127. {
  128. $producer_list = '
  129. <li class="unlisted'.$active_class.$pending_class.'"><a href="'.$_SERVER['PHP_SELF'].'?producer_id_you='.$row->producer_id.'">'.$active_display.$pending_display.htmlspecialchars($row->business_name, ENT_QUOTES).'</a> (Unlisted)</li>';
  130. if ($row->producer_id == $_SESSION['producer_id_you'])
  131. $list_status_html = '
  132. <ul class="fancyList1">
  133. '.$producer_list.'<br>
  134. <li class="listed"><a href="'.$_SERVER['PHP_SELF'].'?list_producer=relist">Relist '.$active_business_name.'</a><br>(Make retail and wholesale products available. This does not change the status of products that are unlisted or archived)</li><br>
  135. <li class="suspended last_of_group"><a href="'.$_SERVER['PHP_SELF'].'?list_producer=suspend">Suspend '.$active_business_name.'</a><br>(Temporarily remove '.$active_business_name.' from all producer lists and all '.$active_business_name.' products from the shopping lists)</li>
  136. </ul>';
  137. }
  138. elseif ($row->unlisted_producer == 2)
  139. {
  140. $producer_list = '
  141. <li class="suspended'.$active_class.$pending_class.'"><a href="'.$_SERVER['PHP_SELF'].'?producer_id_you='.$row->producer_id.'">'.$active_display.$pending_display.''.htmlspecialchars($row->business_name, ENT_QUOTES).'</a> (Suspended)</li>';
  142. if ($row->producer_id == $_SESSION['producer_id_you'])
  143. $list_status_html = '
  144. <ul class="fancyList1">
  145. '.$producer_list.'<br>
  146. <li class="unlisted"><a href="'.$_SERVER['PHP_SELF'].'?list_producer=unlist">Unsuspend '.$active_business_name.'</a><br>(Temporarily remove all '.$active_business_name.' products from the shopping lists)</li><br>
  147. <li class="listed last_of_group"><a href="'.$_SERVER['PHP_SELF'].'?list_producer=relist">Relist '.$active_business_name.'</a><br>(Make retail and wholesale products available. This does not change the status of products that are unlisted or archived)</li>
  148. </ul>';
  149. }
  150. if ($producer_admin_true)
  151. $admin_list .= $producer_list;
  152. $producer_count ++;
  153. }
  154. /////////////// FINISH PRE-PROCESSING AND BEGIN PAGE GENERATION /////////////////
  155. // Generate the display output
  156. $display .= '
  157. <table width="100%" class="compact">
  158. <tr valign="top">
  159. <td align="left" width="50%">';
  160. // If there is a current producer_id_you, then show the current status
  161. if ($list_status_html)
  162. {
  163. $display .= '
  164. <img src="grfx/status.png" width="32" height="32" align="left" hspace="2" alt="Status"><br>
  165. <b>Selected Producer Status:</b> '.$list_status_html;
  166. }
  167. // Generate the administrative display list of producers
  168. $display .= '
  169. <img src="grfx/producer3.png" width="32" height="32" align="left" hspace="2" alt="Select producer identity"><br>
  170. <b>ADMIN: Select Producer Identity</b>
  171. <p>Producer administrators may choose an identity below to edit on behalf of the producer.</p>
  172. <div class="height_400">
  173. <ul class="fancyList1">'.$admin_list.'
  174. </ul>
  175. </div>';
  176. $display .= '
  177. </td>
  178. <td align="left" width="50%">';
  179. if ($_SESSION['producer_id_you'])
  180. {
  181. $display .= '
  182. <div id="this_producer">
  183. <div class="title">Links for '.$active_business_name.'</div>
  184. <img src="grfx/labels.png" width="32" height="32" align="left" hspace="2" alt="Delivery Day Labels"><br>
  185. <b>'.$active_business_name.' Delivery Day Labels</b>
  186. <ul class="fancyList1">
  187. <li><a href="product_list.php?&type=labels_bystoragecustomer">One Label per Customer/Storage</a></li>
  188. <li class="last_of_group"><a href="product_list.php?&type=labels_byproduct">One Label per Item</a></li>
  189. </ul>
  190. <img src="grfx/invoices.png" width="32" height="32" align="left" hspace="2" alt="Producer invoices"><br>
  191. <b>'.$active_business_name.' Producer Orders</b>
  192. <ul class="fancyList1">
  193. <!-- <li><a href="orders_prdcr_cust.php">by Customer</a></li> -->
  194. <!-- <li><a href="orders_prdcr_cust_storage.php">by Storage/Customer</a></li> -->
  195. <!-- <li><a href="orders_prdcr.php">by Product</a></li> -->
  196. <!-- <li><a href="orders_prdcr_multi.php">Multi-sort / Mass-update</a></li> -->
  197. <li><a href="product_list.php?&type=producer_byproduct">Producer Basket (by product)</a></li>
  198. <li><a href="product_list.php?&type=producer_bystoragecustomer">Producer Basket List (by storage/customer)</a></li>
  199. <li class="last_of_group"><a href="product_list.php?&type=producer_bycustomer">Producer Basket List (by customer)</a></li>
  200. <li><a href="order_summary.php">Order Summary</a></li>
  201. <li><a href="show_report.php?type=producer_invoice">Producer Invoice</a></li>
  202. <li class="last_of_group"><a href="orders_saved2.php">Past Producer Invoices</a></li>
  203. <li><a href="route_list.php?delivery_id='.ActiveCycle::delivery_id().'&type=pickup&producer_id='.$_SESSION['producer_id_you'].'">Routing Checklist (by customer)</a></li>
  204. <li class="last_of_group"><a href="route_list.php?delivery_id='.ActiveCycle::delivery_id().'&type=dropoff&producer_id='.$_SESSION['producer_id_you'].'">Routing Checklist (by destination)</a></li>
  205. </ul>
  206. <img src="grfx/product.png" width="32" height="32" align="left" hspace="2" alt="Edit your products"><br>
  207. <b>Edit '.$active_business_name.' Products</b>
  208. <ul class="fancyList1">
  209. <li><a href="product_list.php?a=retail&type=producer_list">Listed&nbsp;Retail</a></li>
  210. <li><a href="product_list.php?a=wholesale&type=producer_list">Listed&nbsp;Wholesale</a></li>
  211. <li><a href="product_list.php?a=unfi&type=producer_list">Listed&nbsp;UNFI</a></li>
  212. <li><a href="product_list.php?a=unlisted&type=producer_list">Unlisted</a></li>
  213. <li class="last_of_group"><a href="product_list.php?a=archived&type=producer_list">Archived</a></li>
  214. <li class="last_of_group"><a href="edit_products.php?producer_id='.$_SESSION['producer_id_you'].'">Add A New Product</a></li>
  215. <li class="last_of_group"><a href="edit_inventory.php">Manage Inventory</a></li>
  216. </ul>
  217. </div>';
  218. }
  219. $display .= '
  220. <div id="all_producers">
  221. <div class="title">General producer links</div>
  222. <img src="grfx/producers.png" width="32" height="32" align="left" hspace="2" alt="Food Stamps"><br>
  223. <b>Manage Producers and Products</b>
  224. <ul class="fancyList1">
  225. <!-- <li><a href="edit_prdcr_list.php">Producer/Product List</a></li> -->
  226. <li><a href="product_list.php?type=confirm">Confirm Changed Products</a></li>
  227. <li><a href="edit_info_list.php">Edit Producer Info</a></li>
  228. </ul>
  229. <img src="grfx/kcron.png" width="32" height="32" align="left" hspace="2" alt="Delivery Cycle Functions"><br>
  230. <b>Delivery Cycle Functions</b>
  231. <ul class="fancyList1">
  232. <li class="last_of_group"><a href="orders_prdcr_list.php?delivery_id='.ActiveCycle::delivery_id().'">Producers with Customers this Cycle</a></li>
  233. </ul>
  234. <img src="grfx/bottom.png" width="32" height="32" align="left" hspace="2" alt="Producer Membership Information"><br>
  235. <b>Producer Membership Information</b>
  236. <ul class="fancyList1">
  237. <li><a href="producers_pending.php">Pending Producers</a></li>
  238. <li class="last_of_group"><a href="producer_applications.php">Producer Applications</a></li>
  239. </ul>
  240. <img src="grfx/report.png" width="32" height="32" align="left" hspace="2" alt="Manage products"><br>
  241. <b>Reports</b>
  242. <ul class="fancyList1">
  243. <li> <a href="producers_labels.php">All Producers</a></li>
  244. <li><a href="prdcr_list_email.php">Producer Email Addresses</a></li>
  245. <li><a href="coopproducers.php">Producer Contact Info</a></li>
  246. <li class="last_of_group"> <a href="report_members.php?p=1">Download a Spreadsheet of All Members/Producers</a></li>
  247. </ul>
  248. <!-- <img src="grfx/invoices.png" width="32" height="32" align="left" hspace="2" alt="Available Products"><br>
  249. <b>Printable Product Lists</b>
  250. <ul class="fancyList1">
  251. <li><strike><a href="printprod_new.php" target="_blank">New Products</a></strike></li>
  252. <li><strike><a href="printprod_changed.php" target="_blank">Changed Products</a></strike></li>
  253. <li><strike><a href="printprod_deleted.php" target="_blank">Unlisted Products</a></strike></li>
  254. <li class="last_of_group"><strike><a href="printprod_list_all.php" target="_blank">Full Product List</a></strike></li>
  255. </ul>-->
  256. </div>
  257. </td>
  258. </tr>
  259. </table>';
  260. $page_specific_css .= '
  261. <style type="text/css">
  262. #this_producer {
  263. border:3px solid #ddd;
  264. padding:0.5em;
  265. }
  266. #all_producers {
  267. margin-top:1em;
  268. border:3px solid #ddd;
  269. padding:0.5em;
  270. }
  271. </style>';
  272. $page_title_html = '<span class="title">'.$active_business_name.'</span>';
  273. $page_subtitle_html = '<span class="subtitle">Producer Admin Panel</span>';
  274. $page_title = $active_business_name.': Producer Admin Panel';
  275. $page_tab = 'producer_admin_panel';
  276. include("template_header.php");
  277. echo '
  278. <!-- CONTENT BEGINS HERE -->
  279. '.$display.'
  280. <!-- CONTENT ENDS HERE -->';
  281. include("template_footer.php");