xah

Horrifically bad PHP

xah
Oct 4th, 2020 (edited)
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.15 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', '1');
  5.  
  6. require_once( dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../blocks/functions.php');
  7.  
  8. if (! file_exists('blocks/header.php') ){
  9.   include( dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../blocks/header.php');}
  10.  
  11. function return_type(){ // Creates a fancy looking form.
  12.     $return_form = array(  'return_detail' => 'Detailed',
  13.                           'return_summary'  => 'Summary',
  14.                           'return_condition' => 'Condition' );
  15.  
  16.     create_dropdown_query($return_form, 'return_type', 'decommissioning/return.php');}
  17.  
  18.     $customer_query = new Query(array('Name'), 'Customer', array('Owner' =>  intval($_SESSION['company_id'])), 'ORDER BY Name');
  19.     $customer_arr = array_map('end', $customer_query->array);
  20.     $customer_arr[0] = 'All';
  21.  
  22.  
  23. if( isset($_POST['return_type']) ){
  24.   echo "<section id='three' class='wrapper'><div class='inner'>";
  25.  
  26.   if( $_POST['return_type'] == 'return_detail' ){
  27.  
  28.     $status_arr = array('Any', 'Unreceived', 'Auditing', 'Completed');
  29.  
  30.     $arr_func = array(array('create_date_picker', 'table'),
  31.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'),
  32.                       array('create_dropdown', $status_arr, 'status', 'Status', 'table'),
  33.                       array('create_text_input', 'Job #', 'job_no', 'table')
  34.                       );
  35.  
  36.     create_table_form( $arr_func, '', 'small_form', 'return_detail_options' );
  37.  
  38.   }
  39.  
  40.   if( $_POST['return_type'] == 'return_summary' ){
  41.     $arr_func = array(array('create_date_picker', 'table'),
  42.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'));
  43.  
  44.     create_table_form( $arr_func, '', 'small_form', 'return_summary_options' );
  45.   }
  46.   if( $_POST['return_type'] == 'return_condition' ){
  47.     $arr_func = array(array('create_date_picker', 'table'),
  48.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'));
  49.  
  50.     create_table_form( $arr_func, '', 'small_form', 'return_condition_options');
  51.   }
  52.  
  53. }else{
  54.  
  55.   if( isset($_POST['return_detail_options']) || isset($_POST['return_summary_options']) || isset($_POST['return_condition_options'])){
  56.     $or = '';
  57.  
  58.     if(isset($_POST['start_date']) || isset($_POST['end_date']) || isset($_POST['customer']) || isset($_POST['job_no'])){
  59.       $gen_or = 'Job.Owner = ' . intval($_SESSION['company_id']) .
  60.             ' AND Job.JobType = \'I\'';
  61.  
  62.       if($_POST['customer'] != '0'){
  63.         $or .= ' AND Customer.Name = \'' . $customer_arr[$_POST['customer']] . '\'';}
  64.       if($_POST['start_date'] != ''){ ///// PROBLEM HERE! Now all have a start date
  65.       $or .= ' AND Job.DateCompleted >= \'' . $_POST['start_date'] . '\'';}
  66.       if($_POST['end_date'] != ''){ ///// PROBLEM HERE! Now all have an end date
  67.       $or .= ' AND Job.DateCompleted <= \'' . $_POST['end_date'] . '\'';}
  68.       if(isset($_POST['job_no'])){
  69.         if($_POST['job_no'] != ''){
  70.           $or .= ' AND Job.Number = ' . $_POST['job_no'];}} ///// PROBLEM! The $or .= should be separated...
  71.       if(isset($_POST['status'])){
  72.         $gen_or .= ' AND StockItem.Owner = '. intval($_SESSION['company_id']);
  73.         $cust_or = '';
  74.         $status_or = '';
  75.  
  76.         if($_POST['customer'] != '0'){
  77.           $cust_or = ' AND Customer.Name = \'' .  $customer_arr[$_POST['customer']] . '\'';
  78.         }
  79.  
  80.         if($_POST['status'] == '1'){
  81.           $status_or = ' AND Job.DateReceived IS NULL';}
  82.         elseif($_POST['status'] == '2' || $_POST['status'] == '0'){
  83.           $status_or = ' AND Job.DateCompleted IS NULL';
  84.         }
  85.  
  86.         if($_POST['status'] == '0'){ // Anything
  87.           $job_or = ' AND DateReceived IS NULL';
  88.           $or .= ' OR ' . $gen_or . $cust_or . $status_or;} //// MAJOR PROBLEM! $or should be split up coz it just ain't working
  89.         elseif( $_POST['status'] == '3' && $status_or == '' ){ // Auditing
  90.           // do nothing;
  91.         }
  92.         elseif( $_POST['status'] == '1' ){// Unreceived status
  93.           // $return_cols = array('DateReceived', 'DateCompleted', 'Number', 'Customer', 'CustomerReference',
  94.           //               'OwnerReference', 'TotalUnits', 'FreightCost', 'Job.Status');
  95.           $job_or = ' AND DateReceived IS NULL';
  96.           $unreceived_report = 'TRUE';
  97.         }
  98.         else{
  99.           $or = $cust_or . $status_or;
  100.         }
  101.         }}
  102.  
  103.         $return_sels = array('Job.Owner' => intval($_SESSION['company_id']),
  104.                       'Job.JobType' => '\'I\'');
  105.         $unreceived_job_cols = array('DateReceived', 'DateCompleted', 'Number', 'Customer', 'CustomerReference',
  106.                       'OwnerReference', 'TotalUnits', 'FreightCost', 'Job.Status');
  107.  
  108.  
  109.         if(isset($_POST['return_detail_options'])){
  110.  
  111.           if(isset($job_or)){
  112.             $unreceived_job_query = new Query($unreceived_job_cols, 'Job', $return_sels, $job_or);
  113.             $unreceived_job_array = $unreceived_job_query->array;}
  114.  
  115.           if(! isset($unreceived_report) ){
  116.             $return_sels['StockItem.Owner'] = intval($_SESSION['company_id']);
  117.             $return_cols = array('DateReceived', 'DateCompleted', 'Job', 'Customer', 'TotalUnits', 'CustomerReference',
  118.                         'OwnerReference', 'FreightCharge', 'Job.Status', 'Product');
  119.             $return_query = new Query($return_cols, 'StockItem', $return_sels, $or);
  120.             $all_stock_arr = $return_query->array;
  121.             print_r($return_query->query);
  122.             $row_count = $return_query->row_count;
  123.  
  124.             $return_headers = array('Job', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCharge', 'DateCompleted', 'Product');
  125.             $return_array = subset_array('Job', $return_headers, $all_stock_arr, 'Product');
  126.  
  127.             if(isset($unreceived_job_array)){
  128.               $full_array = array_merge($unreceived_job_array, $return_array);}
  129.             else{
  130.               $full_array = $return_array;
  131.             }
  132.  
  133.             create_title('Customer Returns', 'Number of Items : ' . $row_count);
  134.             create_general_table($return_headers, $full_array);
  135.  
  136.           }
  137.           else{
  138.             $return_headers = array('Number', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCost', 'DateCompleted');
  139.             $row_count = $unreceived_job_query->row_count;
  140.             create_title('Customer Returns', 'Number of Jobs : ' . $row_count);
  141.             create_general_table($return_headers, $unreceived_job_array);
  142.           }
  143.             }
  144.         if(isset($_POST['return_summary_options'])){
  145.           $return_cols = array('Number', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
  146.  
  147.           $return_headers = array('Number', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
  148.           $return_query = new Query($return_cols, 'Job', $return_sels, $or . ' OR ' . $gen_or . ' AND DateCompleted IS NULL');
  149.           $job_arr = $return_query->array;
  150.           create_general_table($return_headers, $job_arr);
  151.         }
  152.  
  153.   }
  154.   echo "</div></section>";
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment