/**
    Install custom templates in /wpi/ folder by copying them from core/templates folder
   */
  function install_templates() {
    global $wpi_settings;

    $custom_template_path = TEMPLATEPATH . "/wpi";
    $original_template_path = dirname(__FILE__) . "/template";

    if (!is_dir($custom_template_path)) {
      if (!@mkdir($custom_template_path))
        WPI_Functions::add_message(__("Unable to create 'wpi' folder in template folder. ", WPI), 'bad');
      return false;
    }

    $files_copied = 0;
    if ($dir = @opendir($original_template_path)) {
      while (($file = readdir($dir)) !== false) {
        unset($info);
        $info = pathinfo($file);
        if ($info['extension'] == 'php') {
          if (@copy($original_template_path . "/" . $file, "$custom_template_path/$file"))
            $files_copied++;
        }
      }
      closedir($dir);
    } else {
      WPI_Functions::add_message(__("Unable to open 'wpi' folder in template folder.", WPI). $original_template_path, 'bad');
      return false;
    }

    if ((intval($files_copied)) != 0) {
      WPI_Functions::add_message(sprintf(__("Success, (%s) template file(s) copied.", WPI), $files_copied));
      return true;
    } else {
      WPI_Functions::add_message(__("No template files copied.", WPI), 'bad');
      return false;
    }
  }
Esempio n. 2
0
 /**
  * Overview page
  */
 public static function pre_load_overview()
 {
     global $wpdb, $list_table;
     /* Process Bulk Actions */
     if (!empty($_REQUEST['post']) && !empty($_REQUEST['action'])) {
         self::process_invoice_actions($_REQUEST['action'], $_REQUEST['post']);
     } else {
         if (!empty($_REQUEST['delete_all']) && $_REQUEST['post_status'] == 'trash') {
             /* Get all trashed invoices */
             $ids = $wpdb->get_col("\r\n        SELECT `ID`\r\n        FROM `{$wpdb->posts}`\r\n        WHERE `post_type` = 'wpi_object'\r\n        AND `post_status` = 'trash'\r\n      ");
             /* Determine if trashed invoices exist we remove them */
             if (!empty($ids)) {
                 self::process_invoice_actions('delete', $ids);
             }
         }
     }
     //** Action Messages */
     if (!empty($_REQUEST['invoice_id'])) {
         $invoice_ids = str_replace(',', ', ', $_REQUEST['invoice_id']);
         //** Add Messages */
         if (isset($_REQUEST['trashed'])) {
             WPI_Functions::add_message(sprintf(__('"Invoice(s) %s trashed."', WPI), $invoice_ids));
         } elseif (isset($_REQUEST['untrashed'])) {
             WPI_Functions::add_message(sprintf(__('"Invoice(s) %s restored."', WPI), $invoice_ids));
         } elseif (isset($_REQUEST['deleted'])) {
             WPI_Functions::add_message(sprintf(__('"Invoice(s) %s deleted."', WPI), $invoice_ids));
         } elseif (isset($_REQUEST['unarchived'])) {
             WPI_Functions::add_message(sprintf(__('"Invoice(s) %s unarchived."', WPI), $invoice_ids));
         } elseif (isset($_REQUEST['archived'])) {
             WPI_Functions::add_message(sprintf(__('"Invoice(s) %s archived."', WPI), $invoice_ids));
         }
     }
     /** Screen Options */
     if (function_exists('add_screen_option')) {
         add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
     }
     //** Default Help items */
     $contextual_help['General Help'][] = '<h3>' . __('General Information', WPI) . '</h3>';
     $contextual_help['General Help'][] = '<p>' . __('You are on the page which lists your invoices and other item types that you are using.', WPI) . '</p>';
     $contextual_help['General Help'][] = '<p>' . __('Use filter box to find items you need.', WPI) . '</p>';
     //** Hook this action is you want to add info */
     $contextual_help = apply_filters('wpi_main_page_help', $contextual_help);
     do_action('wpi_contextual_help', array('contextual_help' => $contextual_help));
     $list_table = new New_WPI_List_Table(array('filter' => array('fields' => array(array('id' => 's', 'name' => __('Title', WPI), 'placeholder' => __('Start typing...', WPI), 'type' => 'text', 'map' => array('class' => 'post', 'type' => 'string', 'compare' => '=')), array('id' => 'invoice_id', 'name' => __('ID', WPI), 'placeholder' => __('Paste ID here', WPI), 'type' => 'text', 'map' => array('class' => 'meta', 'type' => 'string')), array('id' => 'post_status', 'name' => __('Status', WPI), 'type' => 'select', 'options' => apply_filters('wpi_overview_filter_statuses', array('any' => 'All'))), array('id' => 'type', 'name' => __('Type', WPI), 'type' => 'select', 'options' => apply_filters('wpi_overview_filter_types', array('' => 'All'))), array('id' => 'user_email', 'name' => __('Recipient', WPI), 'type' => 'select_advanced', 'js_options' => array('allowClear' => true), 'multiple' => false, 'url' => admin_url('admin-ajax.php?action=wpi_search_recipient'), 'map' => array('class' => 'meta', 'type' => 'string')), array('id' => 'post_date_min', 'name' => __('Date from', WPI), 'type' => 'date', 'js_options' => array('allowClear' => true), 'map' => array('class' => 'date_query', 'compare' => 'after')), array('id' => 'post_date_max', 'name' => __('Date to', WPI), 'type' => 'date', 'js_options' => array('allowClear' => true), 'map' => array('class' => 'date_query', 'compare' => 'before'))))));
 }
    'label' => __('Help', WPI),
    'position' => 500,
    'callback' => array('WPI_Settings_page','help')
  )
);

// Allow third-party plugins and premium features to insert and remove tabs via API
$wpi_settings_tabs = apply_filters('wpi_settings_tabs', $wpi_settings_tabs);

//** Put the tabs into position */
usort($wpi_settings_tabs, create_function('$a,$b', ' return $a["position"] - $b["position"]; '));

if(isset($_REQUEST['message'])) {
  switch($_REQUEST['message']) {
    case 'updated':
      WPI_Functions::add_message( __("Settings updated.", WPI) );
    break;
  }
}

?>
<script type="text/javascript">

jQuery(document).ready( function() {
  var wp_invoice_settings_page = jQuery("#wp_invoice_settings_page").tabs({cookie: {expires: 30}});
    // The following runs specific functions when a given tab is loaded
  jQuery('#wp_invoice_settings_page').bind('tabsshow', function(event, ui) {
    var selected = wp_invoice_settings_page.tabs('option', 'selected');

    if(selected == 5) { }
  });
  /**
   * Hook.
   * Check Request before Main (Overview) Page will be loaded.
   *
   * @since 3.0
  */
  function pre_load_main_page () {
    global $wpi_settings, $wpdb;

    
    /* Set default overview post status as 'active' */
    /* @TODO: This functionality is depriciated. Should be removed. Maxim Peshkov
    if(empty($_REQUEST['post_status'])) {

      //* Determine if invoices with 'active' statuses exist /
      $ids = $wpdb->get_col("
        SELECT ID
        FROM {$wpdb->posts}
        WHERE post_type = 'wpi_object'
        AND post_status = 'active'
      ");

      if(!empty($ids)) {
        //* Get Referer /
        $sendback = wp_get_referer();
        //* Determine if reffer is not main page, we set it ( anyway, will do redirect to main page ) /
        if(!strpos($sendback, $wpi_settings['links']['overview_page'])){
          $sendback = $wpi_settings['links']['overview_page'];
        }
        wp_redirect( add_query_arg( array('post_status' => 'active'), $sendback ) );
        die();
      }
    }
    */
    
    /* Process Bulk Actions */
    if(!empty($_REQUEST['post']) && !empty($_REQUEST['action'])) {
      self::process_invoice_actions($_REQUEST['action'], $_REQUEST['post']);
    } else if (!empty($_REQUEST['delete_all']) && $_REQUEST['post_status'] == 'trash') {
      /* Get all trashed invoices */
      $ids = $wpdb->get_col("
        SELECT `ID`
        FROM `{$wpdb->posts}`
        WHERE `post_type` = 'wpi_object'
        AND `post_status` = 'trash'
      ");

      /* Determine if trashed invoices exist we remove them */
      if(!empty($ids)) {
        self::process_invoice_actions('delete', $ids);
      }
    }

    /* Action Messages */
    if(!empty($_REQUEST['invoice_id'])) {
      $invoice_ids = str_replace(',', ', ', $_REQUEST['invoice_id']);
      // Add Messages
      if(isset($_REQUEST['trashed'])) {
        WPI_Functions::add_message(sprintf(__('"Invoice(s) %s trashed."', WPI), $invoice_ids));
      } elseif(isset($_REQUEST['untrashed'])) {
        WPI_Functions::add_message(sprintf(__('"Invoice(s) %s untrashed."', WPI), $invoice_ids));
      } elseif(isset($_REQUEST['deleted'])) {
        WPI_Functions::add_message(sprintf(__('"Invoice(s) %s deleted."', WPI), $invoice_ids));
      } elseif(isset($_REQUEST['unarchived'])) {
        WPI_Functions::add_message(sprintf(__('"Invoice(s) %s unarchived."', WPI), $invoice_ids));
      } elseif(isset($_REQUEST['archived'])) {
        WPI_Functions::add_message(sprintf(__('"Invoice(s) %s archived."', WPI), $invoice_ids));
      }
    }
  }