Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function room_current_select_location_number_of_racks( $attr ) {
- global $wpdb;
- // Get shortcode parameters :
- // Date Range (by month). Default: Last Calendar Month
- $date = ( isset( $attr['date'] ) ) ? $attr['date'] : date('m/Y',strtotime("last month"));
- // Room_desc. Default value: ALL Rooms (if no parameter is provided, it returns all rooms)
- $room_desc = ( isset( $attr['room_desc'] ) ) ? "AND L.room_desc = '" . $attr['room_desc'] . "'" : '';
- //Item_category. Default value: ALL Item Categories (if no parameter is provided, it returns all categories)
- $item_category = ( isset( $attr['item_category'] ) ) ? "AND I.item_category = '" .$attr['item_category'] . "'": '';
- // Set up query and make sure it's always secure (no malformed SQL injection etc...)
- $query = $wpdb->prepare( "
- SELECT
- I.item_desc,
- SUM(T.quantity)
- FROM
- wp_transactions T,
- wp_location L,
- wp_items I
- WHERE
- T.item_id=I.item_id
- AND T.location_id=L.location_id
- $item_category // 'Red Widgets, Blue Widgets, etc
- $room_desc //ROOM 4A, ROOM 4B, etc
- AND T.date= '$date' // 03/2011, 05/2011 etc
- GROUP BY
- I.item_desc
- ORDER BY
- I.item_name
- " );
- $r = $wpdb->get_var( $query );
- // next few lines simply print the results of the query on screen, nothing fancy
- echo '<pre>';
- print_r ( $r );
- echo '</pre>';
- }
- // Register a new shortcode
- // Usage :
- // [19]
- // [19 room_desc="ROOM 4A"] returns Room 4A, and defaults values: ALL item_category, date=Last Calendar Month
- // [19 item_category="Blue Widgets"] returns Blue Widgets, and default values: ALL room_desc, date=Last Calendar Month
- //[19 item_category="Green Widgets" date='03/2011'] returns Green Widgets, for March, 2011 and default value: ALL room_desc
- add_shortcode( '19', 'room_current_select_location_number_of_racks' );
Advertisement
Add Comment
Please, Sign In to add comment