function make_aws_content_data($aws_id, $view) { $d = get_graph_data($aws_id, $view); switch ($view) { case 'today': $time_name = 'Today'; break; case 'yesterday': $time_name = 'Yesterday'; break; case '7days': $time_name = '7 day'; break; case '30days': $time_name = '30 day'; break; case 'monthly': $time_name = 'Each month'; break; } $html = '<h2>' . $time_name . '\'s data for ' . $d[0] . '</h2>'; switch ($view) { case 'today': case 'yesterday': // make graphs $args = array('title' => $time_name . '\'s temperatures for ' . $d[0], 'data' => serialize($d[1]['airT']), 'is_bar_graph' => 'false', 'colour' => 'red'); $alt = 'no data for ' . $time_name . '\'s temperatures'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('title' => $time_name . '\'s rain for ' . $d[0], 'data' => serialize($d[1]['rain']), 'is_bar_graph' => 'true', 'colour' => 'blue'); $alt = 'no data for ' . $time_name . '\'s rain'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('title' => $time_name . '\'s relative humidity for ' . $d[0], 'data' => serialize($d[1]['rh']), 'is_bar_graph' => 'false', 'colour' => 'purple'); $alt = 'no data for ' . $time_name . '\'s relative humidity'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('title' => $time_name . '\'s solar radiation (GSR) for ' . $d[0], 'data' => serialize($d[1]['gsr']), 'is_bar_graph' => 'true', 'colour' => 'red'); $alt = 'no data for ' . $time_name . '\'s solar radiation (GSR)'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('is_multi' => 'true', 'title' => $time_name . '\'s windspeeds for ' . $d[0], 'data' => serialize(array('min' => null, 'avg' => $d[1]['Wavg'], 'max' => $d[1]['Wmax'])), 'is_bar_graph' => 'false'); $alt = 'no data for ' . $time_name . '\'s windspeeds)'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; // make HTML table $html .= make_table_hourly($d, $time_name) . "\n\n"; break; case '7days': case '30days': case 'monthly': // make graphs $args = array('title' => $time_name . '\'s ET (tall) for ' . $d[0], 'data' => serialize($d[1]['et_asce_t']), 'is_bar_graph' => 'true', 'colour' => 'red'); $alt = 'no data for ' . $time_name . '\'s ET'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('title' => $time_name . '\'s rain for ' . $d[0], 'data' => serialize($d[1]['rain']), 'is_bar_graph' => 'true', 'colour' => 'blue'); $alt = 'no data for ' . $time_name . '\'s rain'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('is_multi' => 'true', 'title' => $time_name . '\'s air temperatures for ' . $d[0], 'data' => serialize(array('min' => $d[1]['airT_min'], 'avg' => $d[1]['airT_avg'], 'max' => $d[1]['airT_max'])), 'is_bar_graph' => 'false'); $alt = 'no data for ' . $time_name . '\'s air temperatures)'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('is_multi' => 'true', 'title' => $time_name . '\'s relative humidity for ' . $d[0], 'data' => serialize(array('min' => $d[1]['rh_min'], 'avg' => $d[1]['rh_avg'], 'max' => $d[1]['rh_max'])), 'is_bar_graph' => 'false'); $alt = 'no data for ' . $time_name . '\'s relative humidity)'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('title' => $time_name . '\'s solar radiation (GSR) for ' . $d[0], 'data' => serialize($d[1]['gsr']), 'is_bar_graph' => 'true', 'colour' => 'red'); $alt = 'no data for ' . $time_name . '\'s solar radiation (GSR)'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; $args = array('is_multi' => 'true', 'title' => $time_name . '\'s windspeeds for ' . $d[0], 'data' => serialize(array('min' => null, 'avg' => $d[1]['Wavg'], 'max' => $d[1]['Wmax'])), 'is_bar_graph' => 'false'); $alt = 'no data for ' . $time_name . '\'s windspeeds)'; $html .= '<p><img src="graph.php?' . http_build_query($args) . '" alt="' . $alt . '"/></p>' . "\n"; // make HTML table $html .= make_table_daily($d, $time_name) . "\n\n"; break; } return $html; }
} // EOF } $static_select = " SELECT prodid as id, sum(quantity) as quantity, sum(price * quantity) as sales, wtcc.name as products"; $from = " FROM \t\t{$wpdb->prefix}wpsc_cart_contents AS wtcc\n \t JOIN {$wpdb->prefix}wpsc_purchase_logs AS wtpl ON (wtcc.`purchaseid` = wtpl.`id`)\n LEFT JOIN {$wpdb->prefix}postmeta AS postmeta ON (postmeta.post_id = prodid AND postmeta.meta_key = '_thumbnail_id')"; $order_by = "ORDER BY sales DESC"; //To get categories $static_select .= " , ( SELECT GROUP_CONCAT( DISTINCT wt.name SEPARATOR ', ')\n\t FROM \t\t \t{$wpdb->prefix}posts\n\t\t\t LEFT JOIN {$wpdb->prefix}term_relationships AS wtr ON (if(post_parent = 0,ID,post_parent) = wtr.object_id)\n\t\t\t LEFT JOIN {$wpdb->prefix}term_taxonomy AS wtt ON (wtr.term_taxonomy_id = wtt.term_taxonomy_id AND taxonomy = 'wpsc_product_category')\n\t\t\t LEFT JOIN {$wpdb->prefix}terms AS wt ON (wtt.term_id = wt.term_id)\n\t WHERE ID = prodid\n\t GROUP BY ID\n \t) AS category"; $static_select .= ", postmeta.meta_value as image"; if (isset($_GET['searchText']) && $_GET['searchText'] != '') { $search_on = $wpdb->_real_escape(trim($_GET['searchText'])); $search_ons = explode(' ', $search_on); if (is_array($search_ons)) { $where .= " AND ("; foreach ($search_ons as $search_on) { $where .= " (wtcc.name LIKE '%{$search_on}%' \n\t \t\t\t OR prodid in ( \n\t SELECT prodid \n\t FROM \t {$wpdb->prefix}wpsc_cart_contents\n\t JOIN {$wpdb->prefix}posts AS p ON (p.ID = prodid)\n\t LEFT JOIN {$wpdb->prefix}term_relationships AS wtr ON (if(p.post_parent = 0,prodid,post_parent) = wtr.object_id)\n\t LEFT JOIN {$wpdb->prefix}term_taxonomy AS wtt ON (wtr.term_taxonomy_id = wtt.term_taxonomy_id AND taxonomy = 'wpsc_product_category')\n\t LEFT JOIN {$wpdb->prefix}terms AS wt ON (wtt.term_id = wt.term_id)\n\t WHERE wt.name LIKE '%{$search_on}%'\n\t \t\t\t\t\t\t)\n\t\t\t \t) OR"; } $where = substr($where, 0, -3) . ') '; } else { $where .= " AND (wtcc.name LIKE '%{$search_on}%' \n \t\t\t OR prodid in ( \n SELECT prodid \n FROM \t {$wpdb->prefix}wpsc_cart_contents\n JOIN {$wpdb->prefix}posts AS p ON (p.ID = prodid)\n LEFT JOIN {$wpdb->prefix}term_relationships AS wtr ON (if(p.post_parent = 0,prodid,post_parent) = wtr.object_id)\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS wtt ON (wtr.term_taxonomy_id = wtt.term_taxonomy_id AND taxonomy = 'wpsc_product_category')\n LEFT JOIN {$wpdb->prefix}terms AS wt ON (wtt.term_id = wt.term_id)\n WHERE wt.name LIKE '%{$search_on}%'\n \t\t\t\t\t\t)\n\t\t \t)"; } } if ($_GET['cmd'] == 'gridGetData') { $encoded = get_grid_data($static_select, $from, $where, $order_by); } else { if ($_GET['cmd'] == 'getData') { $encoded = get_graph_data($_GET['id'], $static_select, $from, $group_by, $where, $parts); } } } echo json_encode($encoded);
arr_init($frm['yr'], $to['yr']); } // EOF } $static_select = "SELECT order_item.product_id AS id,\n\t\t\t\t\t\t order_item.product_name AS products,\n\t\t\t\t\t\t category,\n\t\t\t\t\t\t SUM( order_item.quantity ) AS quantity,\n\t\t\t\t\t\t SUM( order_item.sales ) AS sales,\n\t\t\t\t\t\t SUM( order_item.discount ) AS discount,\n\t\t\t\t\t\t image_postmeta.meta_value AS thumbnail\n\t\t\t\t\t\t"; $from = " FROM {$wpdb->prefix}sr_woo_order_items AS order_item\n\t\t\t\t LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.id = order_item.product_id )\n\t\t\t\t LEFT JOIN ( SELECT GROUP_CONCAT(wt.name SEPARATOR ', ') AS category, wtr.object_id\n\t\t\t\t\t\tFROM {$wpdb->prefix}term_relationships AS wtr \t \n\t\t\t\t\t\tJOIN {$wpdb->prefix}term_taxonomy AS wtt ON (wtr.term_taxonomy_id = wtt.term_taxonomy_id and taxonomy = 'product_cat')\n\t\t\t\t\t\tJOIN {$wpdb->prefix}terms AS wt ON (wtt.term_id = wt.term_id)\n\t\t\t\t\t\tGROUP BY wtr.object_id) AS prod_categories on (products.id = prod_categories.object_id OR products.post_parent = prod_categories.object_id)\n\t\t\t\t LEFT JOIN {$wpdb->prefix}postmeta as image_postmeta ON (products.ID = image_postmeta.post_id \n\t\t\t\t\t\tAND image_postmeta.meta_key = '_thumbnail_id')\n\t\t\t\t LEFT JOIN {$wpdb->prefix}posts as posts ON ( posts.ID = order_item.order_id )\n\t\t\t\t "; $where = " WHERE products.post_type IN ('product', 'product_variation') "; $group_by = " GROUP BY order_item.product_id "; $order_by = " ORDER BY sales DESC "; if (isset($_GET['searchText']) && $_GET['searchText'] != '') { $search_on = $wpdb->_real_escape(trim($_GET['searchText'])); $search_ons = explode(' ', $search_on); if (is_array($search_ons)) { $search_condn = " HAVING "; foreach ($search_ons as $search_on) { $search_condn .= " order_item.product_name LIKE '%{$search_on}%' \n\t\t\t\t\t\t\t\t\t OR prod_categories.category LIKE '%{$search_on}%' \n\t\t\t\t\t\t\t\t\t OR order_item.product_id LIKE '%{$search_on}%'\n\t\t\t\t\t\t\t\t\t OR"; } $search_condn = substr($search_condn, 0, -2); } else { $search_condn = " HAVING order_item.product_name LIKE '%{$search_on}%' \n\t\t\t\t\t\t\t\t\t OR prod_categories.category LIKE '%{$search_on}%' \n\t\t\t\t\t\t\t\t\t OR order_item.product_id LIKE '%{$search_on}%'\n\t\t\t\t\t\t\t"; } } if ($_GET['cmd'] == 'gridGetData') { $encoded = get_grid_data($static_select, $from, $where, $where_date, $group_by, $search_condn, $order_by); } else { if ($_GET['cmd'] == 'getData') { $encoded = get_graph_data($_GET['id'], $where_date, $parts); } } echo json_encode($encoded); }