Beispiel #1
0
    /**
     * Draw widget.
     *
     * @see WP_Widget::widget
     * @global type $current_user
     *
     * @param type $args
     * @param type $instance
     *
     * @return type
     */
    function widget($args, $instance)
    {
        extract($args);
        global $current_user, $wpi_settings;
        if (!$current_user->ID) {
            return;
        }
        $title = apply_filters('widget_title', !empty($instance['title']) ? $instance['title'] : '');
        $allow_types = !empty($instance['allow_types']) ? $instance['allow_types'] : array('invoice', 'recurring');
        $allow_statuses = !empty($instance['allow_statuses']) ? $instance['allow_statuses'] : array('active', 'paid');
        if (!is_array($allow_types)) {
            $allow_types = explode(',', $allow_types);
        }
        if (!is_array($allow_statuses)) {
            $allow_statuses = explode(',', $allow_statuses);
        }
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
    <div class="wpi_widget_invoice_history">
      <?php 
        foreach ($allow_types as $_type) {
            $invoice_array = WPI_Functions::get_user_invoices(array('user_email' => $current_user->user_email, 'status' => $allow_statuses, 'type' => $_type));
            $invoices_found = false;
            if (!empty($invoice_array) && is_array($invoice_array)) {
                $invoices_found = true;
                ?>
          <b class="wpi_sidebar_title"><?php 
                echo $wpi_settings['types'][$_type]['label'];
                ?>
</b>
          <ul class="wpi_invoice_history_list wpi_active_invoices">
            <?php 
                foreach ($invoice_array as $invoice) {
                    ?>
              <li class="<?php 
                    echo $_type;
                    ?>
 <?php 
                    echo $invoice->data['post_status'];
                    ?>
">
                <a href="<?php 
                    echo get_invoice_permalink($invoice->data['invoice_id']);
                    ?>
"><?php 
                    echo $invoice->data['post_title'];
                    ?>
</a> (<?php 
                    echo $invoice->data['post_status'];
                    ?>
)
              </li>
            <?php 
                }
                ?>
          </ul>
        <?php 
            }
        }
        ?>
    </div>
    <?php 
        echo $after_widget;
        ?>
  <?php 
    }
  /** @see WP_Widget::widget */
  function widget($args, $instance) {
    extract($args);
    global $current_user;

    if (!$current_user->ID)
      return;

    $title = apply_filters('widget_title', $instance['title']);
    $message = $instance['message'];
    $button_text = !empty($instance['button_text']) ? $instance['button_text'] : __('Submit');
    ?>
      <?php echo $before_widget; ?>
      <?php if ($title)
        echo $before_title . $title . $after_title; ?>
    <div class="wpi_widget_invoice_history">
      <!-- <?php //$invoice_array = WPI_Functions::get_user_quotes("user_id={$current_user->ID}");
      if (!empty($invoice_array) && is_array($invoice_array)) { ?>
          <b class="wpi_sidebar_title">Quotes</b>
          <ul class="wpi_invoice_history_list wpi_quotes_list">
        <?php foreach ($invoice_array as $invoice) {
          if ($invoice['reporting']['status'] == 'balance_due') { ?>
                          <li><a href="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>"><?php echo $invoice['subject']; ?></a></li>
          <?php }
        } ?>
          </ul>
      <?php } ?> -->

      <?php
      //$invoice_array = WPI_Functions::get_user_invoices("user_id={$current_user->ID}&status=balance_due");
      /* if(is_array($invoice_array)) {
        ?>
        <b class="wpi_sidebar_title">Due Invoice(s)</b>
        <ul class="wpi_invoice_history_list wpi_due_invoices">
        <?php
        foreach($invoice_array as $invoice) {
        if($invoice['reporting']['status'] == 'balance_due') {
        ?>
        <li><a href="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>"><?php echo $invoice['subject']; ?></a></li>
        <?php
        }
        }
        ?>
        </ul>
        <?php
        } */
      ?>

      <?php
      $invoice_array = WPI_Functions::get_user_invoices("user_email={$current_user->user_email}&status=active");

      if (!empty($invoice_array) && is_array($invoice_array)) {
        ?>
        <b class="wpi_sidebar_title"><?php _e("Active Invoice(s)"); ?></b>
        <ul class="wpi_invoice_history_list wpi_active_invoices">
          <?php
          foreach ($invoice_array as $invoice) {
            ?>
            <li><a href="<?php echo get_invoice_permalink($invoice->data['invoice_id']); ?>"><?php echo $invoice->data['post_title']; ?></a></li>
          <?php
        }
        ?>
        </ul>
        <?php
      }
      ?>

    <?php
    $invoice_array = WPI_Functions::get_user_invoices("user_email={$current_user->user_email}&status=paid");
    if (!empty($invoice_array) && is_array($invoice_array)) {
      ?>
        <b class="wpi_sidebar_title"><?php _e("Paid Invoice(s)"); ?></b>
        <ul class="wpi_invoice_history_list wpi_active_invoices">
          <?php
          foreach ($invoice_array as $invoice) {
            ?>
            <li><a href="<?php echo get_invoice_permalink($invoice->data['invoice_id']); ?>"><?php echo $invoice->data['post_title']; ?></a></li>
          <?php
        }
        ?>
        </ul>
      <?php
    }
    ?>

    </div>

    <?php echo $after_widget; ?>
    <?php
  }