Esempio n. 1
0
    /**
     * View for displaying the inventory items in the admin dashboard.
     */
    public static function list_items()
    {
        $inventory_display = wpinventory_get_display_settings('admin');
        $columns = array();
        $name_columns = array('inventory_name', 'inventory_description');
        $ignore_columns = array('inventory_image', 'inventory_images', 'inventory_media');
        foreach ($inventory_display as $item) {
            $class = in_array($item, $name_columns) ? 'name' : 'medium';
            if (!in_array($item, $ignore_columns)) {
                $columns[$item] = array('title' => self::get_label($item), 'class' => $class);
            }
        }
        echo wpinventory_filter_form_admin();
        $args = '';
        $filters = array("inventory_search" => "search", "inventory_sort_by" => "order", "inventory_category_id" => "category_id", "inventory_page" => "page");
        foreach ($filters as $filter => $field) {
            if (self::request($filter)) {
                $args[$field] = self::request($filter);
            }
        }
        $args = self::permission_args($args);
        $loop = new WPIMLoop($args);
        global $wpinventory_item;
        ?>
		<?php 
        if (self::check_permission('add_item', FALSE)) {
            ?>
			<a class="button button-primary"
			   href="<?php 
            echo self::$self_url;
            ?>
&action=add"><?php 
            self::_e('Add Inventory Item');
            ?>
</a>
		<?php 
        }
        ?>
		<table class="grid itemgrid">
			<?php 
        echo self::grid_columns($columns, self::$self_url, 'inventory_number');
        while ($loop->have_items()) {
            $loop->the_item();
            $edit_url = self::check_permission('view_item', $wpinventory_item->inventory_id) ? self::$self_url . '&action=edit&inventory_id=' . $wpinventory_item->inventory_id : '';
            $delete_url = self::check_permission('edit_item', $wpinventory_item->inventory_id) ? self::$self_url . '&action=delete&delete_id=' . $wpinventory_item->inventory_id : '';
            if (!$edit_url) {
                continue;
            }
            ?>
				<tr>
					<?php 
            foreach ($columns as $field => $data) {
                $field = $field == 'category_id' ? 'inventory_category' : $field;
                $url = $edit_url;
                if ($field == 'user_id' || $field == 'inventory_user_id') {
                    $url = get_edit_user_link($wpinventory_item->{$field});
                }
                echo '<td class="' . $field . '"><a href="' . $url . '">' . $loop->get_field($field) . '</a></td>';
            }
            ?>
					<td class="action">
						<?php 
            if ($edit_url) {
                ?>
							<a href="<?php 
                echo $edit_url;
                ?>
"><?php 
                self::_e('edit');
                ?>
</a>
						<?php 
            }
            if ($delete_url) {
                ?>
							<a class="delete" data-name="<?php 
                echo $wpinventory_item->inventory_name;
                ?>
"
							   href="<?php 
                echo $delete_url;
                ?>
"><?php 
                self::_e('delete');
                ?>
</a>
						<?php 
            }
            ?>
						<?php 
            do_action('wpim_admin_action_links', $wpinventory_item->inventory_id);
            ?>
					</td>
				</tr>
			<?php 
        }
        ?>
		</table>

		<?php 
        echo wpinventory_pagination(self::$self_url, $loop->get_pages());
        do_action('wpim_admin_items_listing', $loop->get_query_args());
    }
Esempio n. 2
0
function wpinventory_process_reserve($data)
{
    $to_email = wpinventory_get_config('reserve_email');
    if (!$to_email) {
        $to_email = get_option('admin_email');
    }
    $subject = WPIMCore::__('An item has been reserved from') . ' ' . get_bloginfo('site_name');
    $message = '';
    $fields = array('inventory_number', 'inventory_serial', 'inventory_name');
    $fields = apply_filters('wpim_reserve_item_fields', $fields);
    $item_title = WPIMCore::__('Item Details');
    $item_title = apply_filters('wpim_reserve_title_item_details', $item_title);
    $message .= PHP_EOL . $item_title;
    $inventory_display = wpinventory_get_display_settings('detail');
    if (!empty($data['inventory_id'])) {
        $loop = new WPIMLoop(array('inventory_id' => $data['inventory_id']));
        while ($loop->have_items()) {
            $loop->the_item();
            foreach ($inventory_display as $field) {
                $message .= PHP_EOL . $loop->get_label($field) . ': ' . $loop->get_field($field);
            }
        }
    }
    $reservation_title = WPIMCore::__('Reservation Details');
    $reservation_title = apply_filters('wpim_reserve_title_reservation_details', $reservation_title);
    $message .= PHP_EOL . PHP_EOL . $reservation_title;
    $exclude = array('inventory_id');
    $exclude = apply_filters('wpim_reserve_exclude_form_fields', $exclude);
    $args = wpinventory_get_reserve_config();
    foreach ($data as $field => $d) {
        if (!in_array($field, $exclude) && $args['display_' . $field]) {
            $message .= PHP_EOL . $d['label'] . ': ' . $d['value'];
        }
    }
    $subject = apply_filters('wpim_reserve_email_subject', $subject);
    $message = apply_filters('wpim_reserve_email_message', $message);
    $status = FALSE;
    $test_mode = FALSE;
    if ($test_mode) {
        echo '<br>== E-Mail output (in test mode) ==<br>';
        echo '<pre>';
        echo 'To: ' . $to_email . PHP_EOL;
        echo 'Subject: ' . $subject . PHP_EOL;
        echo 'Message:' . PHP_EOL;
        echo $message;
        echo '</pre>';
    }
    $success = wp_mail($to_email, $subject, $message);
    if (!$success) {
        return WPIMCore::__('There was an issue sending your e-mail.  Please try again later.');
    } else {
        if (wpinventory_get_config('reserve_decrement')) {
            $wpim_item = new WPIMItem();
            $wpim_item->save_reserve($data['inventory_id'], $data['quantity']['value']);
            do_action('wpim_reserve_sent', $data['inventory_id'], $data, $subject, $message);
            $status = TRUE;
        }
    }
    $send_confirmation = wpinventory_get_config('reserve_confirmation');
    if ($send_confirmation) {
        // Grab e-mail from the form
        $confirm_email = $data['email']['value'];
        // If the user is logged in, use that e-mail
        if (is_user_logged_in()) {
            $current_user = wp_get_current_user();
            $confirm_email = $current_user->user_email;
        }
        $subject = apply_filters('wpim_reserve_confirmation_email_subject', $subject);
        $message = apply_filters('wpim_reserve_confirmation_email_message', $message);
        if ($test_mode) {
            echo '<br>== E-Mail Confirmation output (in test mode) ==<br>';
            echo '<pre>';
            echo 'To: ' . $confirm_email . PHP_EOL;
            echo 'Subject: ' . $subject . PHP_EOL;
            echo 'Message:' . PHP_EOL;
            echo $message;
            echo '</pre>';
        }
        $success = wp_mail($confirm_email, $subject, $message);
        if (!$success) {
            return WPIMCore::__('There was an issue sending the confirmation e-mail.  Please try again later.');
        } else {
            do_action('wpim_reserve_confirmation_sent', $data['inventory_id'], $data, $subject, $message);
            $status = TRUE;
        }
    }
    return $status;
}