/**
  * Fixes billing structure
  * @param array $wpi_settings_billings
  * @param array &$invoice_billings
  */
 function merge_billings($wpi_settings_billings, $invoice_billings) {
   if (!isset($invoice_billings) || !is_array($invoice_billings)) {
     $invoice_billings = array();
   }
   if (is_array($wpi_settings_billings)) {
     foreach ($wpi_settings_billings as $key => $value) {
       // TODO: Refactor on|yes|true off|no|false
       // WPI_Functions::is_true() used temporary
       if (!WPI_Functions::is_true($value['allow'])) {
         unset($invoice_billings[$key]);
       } else {
         if (!empty($invoice_billings[$key])) {
           if (!isset($invoice_billings[$key]['name'])) {
             $invoice_billings[$key]['name'] = $value['name'];
           }
           if (!isset($invoice_billings[$key]['allow'])) {
             $invoice_billings[$key]['allow'] = $value['allow'];
           }
           if (!isset($invoice_billings[$key]['default_option'])) {
             $invoice_billings[$key]['default_option'] = $value['default_option'];
           }
           if (!empty($value['settings'])) {
             foreach ($value['settings'] as $setting_key => $setting_value) {
               foreach ($setting_value as $setting_key_field => $setting_value_field) {
                 if (!isset($invoice_billings[$key]['settings'][$setting_key][$setting_key_field])) {
                   $invoice_billings[$key]['settings'][$setting_key][$setting_key_field] = $setting_value_field;
                 }
               }
             }
           }
         } else {
           $invoice_billings[$key] = $value;
         }
       }
     }
   }
 }
Beispiel #2
0
 /**
  * Renders invoice in the content.
  *
  * Invoice object already loaded into $wpi_invoice_object at template_redirect()
  *
  */
 static function the_content($content)
 {
     global $wpi_settings;
     /**
      * Well. Here I'm trying to fix conflicts with plugins such as Simple Facebook Connect.
      * I will try to determine the source of function hook calling using debug_backtrace() function.
      * Correct source is /wp-includes/post-template.php We need to ignore other cases.
      * Probably this condition shoud be changed somehow with new version of Wordpress
      * The condition may be turned off in settings if it causes errors.
      *
      * @author korotkov@ud
      * @since 3.08.6
      */
     if (!WPI_Functions::is_true(isset($wpi_settings['turn_off_compatibility_mode']) ? $wpi_settings['turn_off_compatibility_mode'] : false)) {
         if (function_exists('debug_backtrace')) {
             if ($call_stack = debug_backtrace()) {
                 if (!empty($call_stack[2]['file'])) {
                     if (basename($call_stack[2]['file']) != 'post-template.php') {
                         return $content;
                     }
                 }
             }
         }
     }
     //** Continue as usually */
     global $post, $invoice, $invoice_id, $wpi_settings, $wpi_invoice_object;
     $invoice = $wpi_invoice_object->data;
     /** Mark invoice as viewed if not by admin */
     if (!current_user_can('manage_options')) {
         /** Prevent duplicating of 'viewed' item. */
         /** 1 time per $hours */
         $hours = 12;
         $viewed_today_from_cur_ip = false;
         foreach ($invoice['log'] as $key => $value) {
             if ($value['user_id'] == '0') {
                 if (strstr(strtolower($value['text']), "viewed by {$_SERVER['REMOTE_ADDR']}")) {
                     $time_dif = time() - $value['time'];
                     if ($time_dif < $hours * 60 * 60) {
                         $viewed_today_from_cur_ip = true;
                     }
                 }
             }
         }
         if (!$viewed_today_from_cur_ip) {
             $wpi_invoice_object->add_entry("note=Viewed by {$_SERVER['REMOTE_ADDR']}");
         }
     }
     /** Include our template functions */
     include_once 'wpi_template_functions.php';
     ob_start();
     if ($invoice['post_status'] == 'paid') {
         if (WPI_Functions::wpi_use_custom_template('receipt_page.php')) {
             include $wpi_settings['frontend_template_path'] . 'receipt_page.php';
         } else {
             include $wpi_settings['default_template_path'] . 'receipt_page.php';
         }
     } elseif ($invoice['post_status'] == 'refund') {
         if (WPI_Functions::wpi_use_custom_template('receipt_page.php')) {
             include $wpi_settings['frontend_template_path'] . 'receipt_page.php';
         } else {
             include $wpi_settings['default_template_path'] . 'receipt_page.php';
         }
     } else {
         if (WPI_Functions::wpi_use_custom_template('invoice_page.php')) {
             include $wpi_settings['frontend_template_path'] . 'invoice_page.php';
         } else {
             include $wpi_settings['default_template_path'] . 'invoice_page.php';
         }
     }
     $result = ob_get_contents();
     ob_end_clean();
     switch ($wpi_settings['where_to_display']) {
         case 'overwrite':
             return $result;
             break;
         case 'below_content':
             return $content . $result;
             break;
         case 'above_content':
             return $result . $content;
             break;
         case 'replace_tag':
             return str_replace('[wp-invoice]', $result, $content);
             break;
         default:
             return $content;
             break;
     }
 }
  function payment($wpi_settings) { ?>
    <table class="form-table">
          <tr>
            <th><?php _e("Default Currency", WPI);?></th>
            <td><?php echo WPI_UI::select("name=wpi_settings[currency][default_currency_code]&values=".serialize($wpi_settings['currency']['types'])."&current_value={$wpi_settings['currency']['default_currency_code']}"); ?></td>
          </tr>

          <tr class="column-payment-method-default">
            <th><?php _e("Default Payment Method:", WPI) ?></th>
            <td ><select id="wp_invoice_payment_method">
                <?php foreach ($wpi_settings['installed_gateways'] as $key => $payment_option) { ?>
                <option value="<?php echo $key; ?>" <?php if($payment_option['object']->options['default_option']) { echo "SELECTED"; } ?>><?php echo $payment_option['name']; ?></option>
                <?php } ?>
              </select>&nbsp;&nbsp;
            <?php echo WPI_UI::checkbox("class=wpi_client_change_payment_method&name=wpi_settings[client_change_payment_method]&value=yes&label=".__('Client can change payment option.', WPI), WPI_Functions::is_true($wpi_settings['client_change_payment_method']))?>

            </td>
          </tr>

          <tr class='wpi-payment-setting column-paymenth-method-<?php echo $key; ?>'>
            <th><?php _e('Payment Gateways', WPI);?></th>
            <td>
            <ul>
          <?php foreach($wpi_settings['installed_gateways'] as $key => $value) { ?>
            <li>
              <?php echo WPI_UI::checkbox("&name=wpi_settings[billing][{$key}][allow]&id={$key}&value=true&label=" . $value['name'] . "&class=wpi_billing_section_show", $value['object']->options['allow']);?>
            </li>
          <?php } ?>
          </ul>
          </td>
          </tr>
          <tr>
            <th>&nbsp;</th>
            <td><div class="wp_invoice_accordion">
              <?php foreach($wpi_settings['installed_gateways'] as $key => $value) { ?>
              <div class="<?php echo $key; ?>-setup-section wp_invoice_accordion_section">
                  <h3 id="<?php echo $key; ?>-setup-section-header"><a href="#" class="selector"><?php echo $value['name'] ?></a></h3>
                  <div> <?php echo !empty($wpi_settings['billing'][$key])?WPI_UI::input("type=hidden&name=wpi_settings[billing][{$key}][default_option]&class=billing-default-option billing-{$key}-default-option&value={$wpi_settings['billing'][$key]['default_option']}"):'';?>
                    <table class="form-table">

                      <?php if ( $value['object']->options['settings'] ) foreach($value['object']->options['settings'] as $key2 => $setting_value) {
                        $setting_value['value'] = urldecode($setting_value['value']);
                        $setting_value['type'] = !empty( $setting_value['type'] ) ? $setting_value['type'] : 'input' ;
                        ?>
                      <tr>
                        <th width="300"><span class="<?php echo (!empty($setting_value['description']) ? "wp_invoice_tooltip" : ""); ?>" title="<?php echo (!empty($setting_value['description']) ? $setting_value['description'] : ''); ?>"><?php echo $setting_value['label']; ?></span></th>
                        <td>
                          <?php if ($setting_value['type'] == 'select') : ?>
                            <?php echo WPI_UI::select("name=wpi_settings[billing][{$key}][settings][{$key2}][value]&values=" . serialize($setting_value['data']) . "&current_value={$setting_value['value']}"); ?>
                          <?php elseif ($setting_value['type'] == 'textarea') : ?>
                            <?php echo WPI_UI::textarea("name=wpi_settings[billing][{$key}][settings][{$key2}][value]&value={$setting_value['value']}"); ?>
                          <?php elseif ($setting_value['type'] == 'readonly') : ?>
                          <?php $setting_value['value'] = urlencode($setting_value['value']); ?>
                            <?php echo WPI_UI::textarea("name=wpi_settings[billing][{$key}][settings][{$key2}][value]&value={$setting_value['value']}&special=readonly='readonly'"); ?>
                          <?php else : ?>
                            <?php echo WPI_UI::input("name=wpi_settings[billing][{$key}][settings][{$key2}][value]&value={$setting_value['value']}"); ?>
                          <?php endif; ?>
                          <?php if (!empty($setting_value['special']) && is_array($setting_value['special']) && $setting_value['type'] != 'select') : ?>
                            <?php $s_count = 0; ?>
                            <br/>
                            <?php foreach($setting_value['special'] as $s_label => $s_value): ?>
                              <span class="wp_invoice_click_me" onclick="jQuery('input[name=\'wpi_settings[billing][<?php echo $key; ?>][settings][<?php echo $key2; ?>][value]\']').val('<?php echo $s_value; ?>');"><?php echo $s_label; ?></span>
                              <?php echo (++$s_count < count($setting_value['special']) ? ' | ' : '' ); ?>
                            <?php endforeach; ?>
                          <?php endif; ?>
                        </td>
                      </tr>
                      <?php } ?>
                    </table>
                  </div>
                </div>
                <?php } ?>
              </div></td>
          </tr>

          <tr>

            <th>
              <?php _e("Manual Payment information", WPI) ?></a>
            </th>

            <td>
              <?php echo WPI_UI::textarea("name=manual_payment_info&group=wpi_settings&value=".(!empty( $wpi_settings['manual_payment_info'] )?$wpi_settings['manual_payment_info']:''))?>
              <div class="description"><?php _e('If an invoice has no payment gateways, this message will be displayed offering the customer guidance on their course of action.', WPI) ?></div>
              </td>

          </tr>

        </table>

  <?php }
_e('Whether to exclude Products from front end search results.', WPI);
?>
</div>
        </li>
        <li>
          <?php 
echo WPI_UI::checkbox("name=wpi_settings[products][post_type][hierarchical]&value=true&label=" . __('Hierarchical Products', WPI), WPI_Functions::is_true(!empty($wpi_settings['products']['post_type']['hierarchical']) ? $wpi_settings['products']['post_type']['hierarchical'] : self::$defaults['post_type']['hierarchical']));
?>
          <div class="description"><?php 
_e('Whether Products are hierarchical.', WPI);
?>
</div>
        </li>
        <li>
          <?php 
echo WPI_UI::checkbox("name=wpi_settings[products][post_type][has_archive]&value=true&label=" . __('Products have archives', WPI), WPI_Functions::is_true(!empty($wpi_settings['products']['post_type']['has_archive']) ? $wpi_settings['products']['post_type']['has_archive'] : self::$defaults['post_type']['has_archive']));
?>
          <div class="description"><?php 
_e('Enables Products archives.', WPI);
?>
</div>
        </li>
        <li>
          <?php 
_e('Products Menu Position', WPI);
?>
<br />
          <?php 
echo WPI_UI::input("type=text&name=menu_position&group=wpi_settings[products][post_type]&value=" . (!empty($wpi_settings['products']['post_type']['menu_position']) ? $wpi_settings['products']['post_type']['menu_position'] : self::$defaults['post_type']['menu_position']));
?>
          <div class="description"><?php 
Beispiel #5
0
 /**
  * Can be used to setup invoives.
  * Otherwise, set() function can also be used to set this information
  * @global type $wpi_settings
  * @param type $args
  */
 function create_new_invoice($args = '')
 {
     global $wpi_settings;
     $this->data['new_invoice'] = true;
     //** Include global tax if option turned on */
     if (!empty($wpi_settings['use_global_tax']) && $wpi_settings['use_global_tax'] == 'true' && !empty($wpi_settings['global_tax'])) {
         $this->data['tax'] = (double) $wpi_settings['global_tax'];
     }
     $defaults = array('invoice_id' => '', 'custom_id' => '', 'subject' => '', 'description' => '');
     extract(wp_parse_args($args, $defaults), EXTR_SKIP);
     //** Set Random Invoice Id */
     $this->data['invoice_id'] = $invoice_id ? $invoice_id : rand(10000000, 99999999);
     if (!empty($subject)) {
         $this->data['subject'] = $subject;
     }
     if (!empty($description)) {
         $this->data['description'] = $description;
     }
     if (!empty($custom_id)) {
         $this->data['meta']['custom_id'] = $custom_id;
     }
     //** Load Globals */
     $this->data = array_merge($this->data, $wpi_settings['globals']);
     //** Default Currency */
     $this->data['default_currency_code'] = $wpi_settings['currency']['default_currency_code'];
     //** Default payment method */
     $dpm = '';
     foreach ($wpi_settings['billing'] as $key => $value) {
         if (!empty($value['allow']) && WPI_Functions::is_true($value['allow']) && $value['default_option'] == 'true') {
             $dpm = $key;
         }
     }
     $this->data['default_payment_method'] = $dpm;
     //** Default Billings */
     WPI_Functions::merge_billings($wpi_settings['billing'], $this->data['billing']);
 }
    /**
     * Payment tab
     *
     * @global type $wpi_chargify
     * @param type $wpi_settings
     */
    static function payment($wpi_settings)
    {
        global $wpi_chargify;
        ?>
    <table class="form-table">
      <tr>
        <th><?php 
        _e("Default Currency", WPI);
        ?>
</th>
        <td><?php 
        echo WPI_UI::select("name=wpi_settings[currency][default_currency_code]&values=" . serialize($wpi_settings['currency']['types']) . "&current_value={$wpi_settings['currency']['default_currency_code']}");
        ?>
</td>
      </tr>
      <tr>
        <th></th>
        <td>

    <?php 
        $currency_array = apply_filters('wpi_currency', $wpi_settings['currency']);
        ?>

          <div id="currency-list">
            <h3><a href="#"><?php 
        _e("Currency list", WPI);
        ?>
</a></h3>
            <div>
              <table class="ud_ui_dynamic_table widefat form-table edit-currency-tab" style="margin-bottom:8px;" auto_increment="true">
                <thead>
                  <tr>
                    <th style="width:10%; padding-left: 50px;"><?php 
        _e('Code', WPI);
        ?>
</th>
                    <th style="text-align: center;"><?php 
        _e('Symbol', WPI);
        ?>
</th>
                    <th style="width:40%; text-align: center;"><?php 
        _e('Name', WPI);
        ?>
</th>
                  </tr>
                </thead>
                <tbody>
    <?php 
        foreach ($currency_array['types'] as $slug => $title) {
            ?>
                    <tr class="wpi_dynamic_table_row" slug="<?php 
            echo $slug;
            ?>
" new_row="false">
                      <td >
                        <span class="row_delete" verify_action="true">&nbsp;</span>
      <?php 
            echo WPI_UI::input("name=wpi_settings[currency][code][{$slug}]&value={$slug}&type=text&class=" . urlencode("names_changer code") . "&special=disabled='disabled'&pattern=[A-Z]{3}&required=required&title=" . urlencode("Please,fill in the field with three capital letters (A-Z)") . "&style=width:4em;margin-left:50px;");
            ?>
                      </td>
                      <td align="left" class="symbol-row" style="text-align: center;">
      <?php 
            echo WPI_UI::input("name=wpi_settings[currency][symbol][{$slug}]&class=currency_sign&value=" . urlencode($currency_array['symbol'][$slug]) . "&type=text&required=required&style=float:right;width:150px;margin-right:55px;");
            ?>
                      </td>
                      <td>
      <?php 
            echo WPI_UI::input("name=wpi_settings[currency][types][{$slug}]&value={$title}&type=text&required=required&style=width:150px;margin-left:35px;");
            ?>
                      </td>

                    </tr>
    <?php 
        }
        ?>
                </tbody>
                <tfoot>
                  <tr>
                    <th colspan="4">
                      <input type='button' class="button wpi_button wpi_add_row" value="<?php 
        esc_attr(_e('Add Currency', WPI));
        ?>
"/>
                    </th>
                  </tr>
                </tfoot>
              </table>
            </div>
          </div>
        </td>
      </tr>

      <tr class="column-payment-method-default">
        <th><?php 
        _e("Default Payment Method", WPI);
        ?>
</th>
        <td>
          <select id="wp_invoice_payment_method">
            <?php 
        foreach ((array) $wpi_settings['installed_gateways'] as $key => $payment_option) {
            ?>
                <option value="<?php 
            echo $key;
            ?>
" <?php 
            echo $payment_option['object']->options['default_option'] ? 'SELECTED' : '';
            ?>
><?php 
            echo $payment_option['name'];
            ?>
</option>
            <?php 
        }
        ?>
          </select>&nbsp;&nbsp;
        <?php 
        echo WPI_UI::checkbox("class=wpi_client_change_payment_method&name=wpi_settings[client_change_payment_method]&value=yes&label=" . __('Client can change payment option.', WPI), WPI_Functions::is_true($wpi_settings['client_change_payment_method']));
        ?>
        </td>
      </tr>

      <tr class='wpi-payment-setting column-paymenth-method-<?php 
        echo $key;
        ?>
'>
        <th><?php 
        _e('Payment Gateways', WPI);
        ?>
</th>
        <td>
          <ul>
                  <?php 
        foreach ($wpi_settings['installed_gateways'] as $key => $value) {
            ?>
              <li>
                    <?php 
            echo WPI_UI::checkbox("&name=wpi_settings[billing][{$key}][allow]&id={$key}&value=true&label=" . $value['name'] . "&class=wpi_billing_section_show", $value['object']->options['allow']);
            ?>
              </li>
    <?php 
        }
        ?>
          </ul>
        </td>
      </tr>
      <tr>
        <th>&nbsp;</th>
        <td><div class="wp_invoice_accordion">
                      <?php 
        foreach ((array) $wpi_settings['installed_gateways'] as $key => $value) {
            ?>
              <div class="<?php 
            echo $key;
            ?>
-setup-section wp_invoice_accordion_section">
                <h3 id="<?php 
            echo $key;
            ?>
-setup-section-header"><a href="#" class="selector"><?php 
            echo $value['name'];
            ?>
</a></h3>
                <div> <?php 
            echo !empty($wpi_settings['billing'][$key]) ? WPI_UI::input("type=hidden&name=wpi_settings[billing][{$key}][default_option]&class=billing-default-option billing-{$key}-default-option&value={$wpi_settings['billing'][$key]['default_option']}") : '';
            ?>
                  <table class="form-table">

                        <?php 
            if ($value['object']->options['settings']) {
                foreach ($value['object']->options['settings'] as $key2 => $setting_value) {
                    $setting_value['value'] = urldecode(isset($setting_value['value']) ? $setting_value['value'] : '');
                    $setting_value['type'] = !empty($setting_value['type']) ? $setting_value['type'] : 'input';
                    ?>
                        <tr>
                          <th width="300"><span class="<?php 
                    echo !empty($setting_value['description']) ? "wp_invoice_tooltip" : "";
                    ?>
" title="<?php 
                    echo !empty($setting_value['description']) ? $setting_value['description'] : '';
                    ?>
"><?php 
                    echo !empty($setting_value['label']) ? $setting_value['label'] : '';
                    ?>
</span></th>
                          <td>
                        <?php 
                    if ($setting_value['type'] == 'select') {
                        ?>
            <?php 
                        echo WPI_UI::select("name=wpi_settings[billing][{$key}][settings][{$key2}][value]&values=" . serialize($setting_value['data']) . "&current_value={$setting_value['value']}");
                        ?>
          <?php 
                    } elseif ($setting_value['type'] == 'textarea') {
                        ?>
                    <?php 
                        echo WPI_UI::textarea("name=wpi_settings[billing][{$key}][settings][{$key2}][value]&value={$setting_value['value']}");
                        ?>
                  <?php 
                    } elseif ($setting_value['type'] == 'readonly') {
                        ?>
                              <p class="wpi_readonly"><?php 
                        echo $setting_value['value'];
                        ?>
</p>
            <?php 
                    } elseif (isset($setting_value['type']) && $setting_value['type'] == 'static') {
                        ?>
                    <p><?php 
                        echo !empty($setting_value['data']) ? $setting_value['data'] : '';
                        ?>
</p>
          <?php 
                    } else {
                        ?>
            <?php 
                        echo WPI_UI::input("type=text&name=wpi_settings[billing][{$key}][settings][{$key2}][value]&value={$setting_value['value']}");
                        ?>
          <?php 
                    }
                    ?>
          <?php 
                    if (!empty($setting_value['special']) && is_array($setting_value['special']) && $setting_value['type'] != 'select') {
                        ?>
                  <?php 
                        $s_count = 0;
                        ?>
                              <br/>
            <?php 
                        foreach ($setting_value['special'] as $s_label => $s_value) {
                            ?>
                                <span class="wp_invoice_click_me" onclick="jQuery('input[name=\'wpi_settings[billing][<?php 
                            echo $key;
                            ?>
][settings][<?php 
                            echo $key2;
                            ?>
][value]\']').val('<?php 
                            echo $s_value;
                            ?>
');"><?php 
                            echo $s_label;
                            ?>
</span>
                    <?php 
                            echo ++$s_count < count($setting_value['special']) ? ' | ' : '';
                            ?>
                  <?php 
                        }
                        ?>
          <?php 
                    }
                    ?>
                          </td>
                        </tr>
        <?php 
                }
            }
            ?>
                  </table>
                </div>
              </div>
          <?php 
        }
        ?>
          </div></td>
      </tr>

      <tr>

        <th>
      <?php 
        _e("Manual Payment information", WPI);
        ?>
        </th>

        <td>
    <?php 
        echo WPI_UI::textarea("name=manual_payment_info&group=wpi_settings&value=" . (!empty($wpi_settings['manual_payment_info']) ? $wpi_settings['manual_payment_info'] : ''));
        ?>
          <div class="description"><?php 
        _e('If an invoice has no payment gateways, this message will be displayed offering the customer guidance on their course of action.', WPI);
        ?>
</div>
        </td>

      </tr>

    <?php 
        if (is_callable(array($wpi_chargify, 'wpi_chargify_settings'))) {
            ?>
        <tr>
          <th>
      <?php 
            _e("Subscription Payments", WPI);
            ?>
          </th>
          <td>
      <?php 
            $wpi_chargify->wpi_chargify_settings();
            ?>
          </td>
        </tr>
    <?php 
        }
        ?>

    </table>

<?php 
    }
Beispiel #7
0
 /**
  * Handle user data updating
  *
  * Typically called when saving an invoice.
  *
  * @since 3.0
  */
 static function update_user($userdata)
 {
     $user_id = email_exists($userdata['user_email']);
     if ($user_id) {
         $userdata['ID'] = $user_id;
     }
     if (empty($userdata['ID']) && empty($userdata['user_email'])) {
         return false;
     }
     if ($user_id) {
         $user_id = wp_update_user($userdata);
     } else {
         if (empty($userdata['user_login'])) {
             if (!empty($userdata['first_name']) && !empty($userdata['last_name'])) {
                 $userdata['display_name'] = $userdata['first_name'] . ' ' . $userdata['last_name'];
             } else {
                 //** Nothing to do here... */
             }
         }
         $userdata['user_login'] = $userdata['user_email'];
         if (empty($userdata['user_pass'])) {
             $userdata['user_pass'] = wp_generate_password(12, false);
         }
         $user_id = wp_insert_user($userdata);
         global $wpi_settings;
         if (is_int($user_id) && WPI_Functions::is_true($wpi_settings['send_password_to_new_users'])) {
             wp_mail($userdata['user_email'], sprintf(__('Your Access Credentials [%s]', WPI), get_bloginfo('url')), sprintf(__("Dear customer,\n\nwe have set an account for you on %s. You are able to login now using the following credentials:\n\nURL: %s\nLogin: %s\nPassword: %s", WPI), get_bloginfo('url'), wp_login_url(), $userdata['user_login'], $userdata['user_pass']));
         }
     }
     //** Prevent entering of wrong phone number to avoid errors on front-end */
     if (!preg_match('/\\A[\\d.+?]{0,3}-[\\d.+?]{0,3}-[\\d.+?]{0,4}\\Z/si', $userdata['phonenumber'])) {
         if (preg_match('/\\A[\\d.+?]{0,10}\\Z/si', $userdata['phonenumber'])) {
             $phonenumber = $userdata['phonenumber'];
             $userdata['phonenumber'] = substr($phonenumber, 0, 3) . '-' . substr($phonenumber, 3, 3) . '-' . substr($phonenumber, 6, 4);
         } else {
             $userdata['phonenumber'] = '';
         }
     }
     if (!is_object($user_id) && $user_id > 0) {
         /* Update user's meta data */
         $non_meta_data = array('ID', 'first_name', 'last_name', 'nickname', 'description', 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered', 'role');
         foreach ($userdata as $key => $value) {
             if (!in_array($key, $non_meta_data)) {
                 update_user_meta($user_id, $key, $value);
             }
         }
         return $user_id;
     }
     return $user_id;
 }
/**
 * Publish metabox
 * @global type $wpi_settings
 * @param type $this_invoice
 */
function postbox_publish($this_invoice)
{
    global $wpi_settings;
    $invoice_id = $this_invoice['invoice_id'];
    $status_names = apply_filters('wpi_invoice_statuses', $wpi_settings['invoice_statuses']);
    if (!empty($this_invoice['status'])) {
        $status_label = !empty($status_names[$this_invoice['status']]) ? $status_names[$this_invoice['status']] : $this_invoice['status'];
    }
    ?>
  <div id="submitpost" class="submitbox">
    <div id="minor-publishing">
      <ul class="wpi_publish_seetings">
        <li class="wpi_hide_until_saved"><a target="_blank" class="wpi_new_win wpi_update_with_invoice_url" href="<?php 
    echo get_invoice_permalink(!empty($this_invoice['invoice_id']) ? $this_invoice['invoice_id'] : '');
    ?>
"><?php 
    _e('View Online', WPI);
    ?>
</a></li>

        <?php 
    do_action('wpi_publish_options', $this_invoice);
    ?>

        <li class="wpi_hide_until_saved"><span onclick="wpi_show_paycharge_box();" class="wpi_link" id="wpi_button_show_paycharge_box"><?php 
    _e('Enter Payment', WPI);
    ?>
</span></li>
        <li class="wpi_hide_until_saved"><span onclick='wpi_show_notification_box();' class="wpi_link" id="wpi_button_show_notification"><?php 
    _e('Send Notification', WPI);
    ?>
</span></li>

        <?php 
    if ($wpi_settings['allow_deposits'] == 'true') {
        ?>
          <li class="wpi_not_for_recurring wpi_hide_deposit_option wpi_not_for_quote">
            <?php 
        $app_title = __("Allow Partial Payment", WPI);
        ?>
            <?php 
        echo WPI_UI::checkbox("name=wpi_invoice[deposit]&value=true&label={$app_title}", !empty($this_invoice['deposit_amount']) && (int) $this_invoice['deposit_amount'] > 0 ? true : (WPI_Functions::is_true(isset($wpi_settings['allow_deposits_by_default']) ? $wpi_settings['allow_deposits_by_default'] : false) && !empty($this_invoice['new_invoice']) ? true : false));
        ?>
</li>
          <li class="wpi_deposit_settings">
            <table class="wpi_deposit_settings">
              <tr>
                <th><?php 
        _e("Minimum Payment", WPI);
        ?>
</th>
                <td><?php 
        echo WPI_UI::input("id=wpi_meta_deposit_amount&name=wpi_invoice[deposit_amount]&value=" . (!empty($this_invoice['deposit_amount']) ? $this_invoice['deposit_amount'] : 0));
        ?>
</td>
              </tr>
            </table>
          </li>
        <?php 
    }
    ?>

        <?php 
    if ($wpi_settings['show_recurring_billing'] == 'true') {
        ?>
          <li class="wpi_turn_off_recurring wpi_not_for_quote">
            <?php 
        echo WPI_UI::checkbox("name=wpi_invoice[recurring][active]&value=true&label=" . __('Recurring Bill', WPI), !empty($this_invoice['recurring']) ? $this_invoice['recurring']['active'] : false);
        ?>
          </li>
          <li class="wpi_recurring_bill_settings <?php 
        if (!empty($this_invoice['recurring']) && $this_invoice['recurring']['active'] != 'on') {
            ?>
hidden<?php 
        }
        ?>
">

            <?php 
        $recurring_settings = apply_filters('wpi_recurring_settings', array(), $this_invoice);
        foreach ($recurring_settings as $gateway) {
            do_action('wpi_recurring_settings_' . $gateway, $this_invoice);
        }
        ?>

          </li>
        <?php 
    }
    ?>
      </ul>
      <table class="form-table">
        <thead>
          <th colspan="2">
            <span id="wpi_button_show_advanced" class="wpi_link"><?php 
    _e('Toggle Advanced', WPI);
    ?>
</span>
          </th>
        </thead>
        <tbody>
          <tr class="column-publish-due-date wpi_not_for_recurring wpi_not_for_quote">
            <th><?php 
    _e('Due Date', WPI);
    ?>
</th>
            <td>
              <div class="timestampdiv" style="display:block;">
                <?php 
    echo WPI_UI::select("id=due_date_mm&name=wpi_invoice[due_date_month]&values=months&current_value=" . (!empty($this_invoice['due_date_month']) ? $this_invoice['due_date_month'] : ''));
    ?>
                <?php 
    echo WPI_UI::input("id=due_date_jj&name=wpi_invoice[due_date_day]&value=" . (!empty($this_invoice['due_date_day']) ? $this_invoice['due_date_day'] : '') . "&special=size='2' maxlength='2' autocomplete='off'");
    ?>
                <?php 
    echo WPI_UI::input("id=due_date_aa&name=wpi_invoice[due_date_year]&value=" . (!empty($this_invoice['due_date_year']) ? $this_invoice['due_date_year'] : '') . "&special=size='2' maxlength='4' autocomplete='off'");
    ?>
<br />
                <span onclick="wp_invoice_add_time('due_date', 7);" class="wp_invoice_click_me"><?php 
    _e('In One Week', WPI);
    ?>
</span> | <span onclick="wp_invoice_add_time('due_date', 30);" class="wp_invoice_click_me"><?php 
    _e('In 30 Days', WPI);
    ?>
</span> | <span onclick="wp_invoice_add_time('due_date','clear');" class="wp_invoice_click_me"><?php 
    _e('Clear', WPI);
    ?>
</span>
              </div>
            </td>
          </tr>
          <tr class="invoice_main column-publish-invoice_id">
            <th><?php 
    _e('Invoice ID', WPI);
    ?>
 </th>
            <td>
              <?php 
    $custom_invoice_id = !empty($this_invoice['custom_id']) ? $this_invoice['custom_id'] : '';
    if (empty($custom_invoice_id) && $wpi_settings['increment_invoice_id'] == 'true') {
        $highest_custom_id = WPI_Functions::get_highest_custom_id();
        $custom_invoice_id = $highest_custom_id ? $highest_custom_id + 1 : $this_invoice['invoice_id'];
        echo WPI_UI::input("name=wpi_invoice[meta][custom_id]&value={$custom_invoice_id}");
    } else {
        ?>
                <input style="width: 80px;" class="input_field wp_invoice_custom_invoice_id<?php 
        echo empty($this_invoice['custom_id']) ? " wp_invoice_hidden" : "";
        ?>
" name="wpi_invoice[meta][custom_id]" value="<?php 
        echo !empty($this_invoice['custom_id']) ? $this_invoice['custom_id'] : '';
        ?>
">
                <span class="wp_invoice_custom_invoice_id">
                  <?php 
        echo $this_invoice['invoice_id'];
        ?>
                </span>
                <a onClick="jQuery('.wp_invoice_custom_invoice_id').toggle(); return false;" class="wp_invoice_click_me <?php 
        echo empty($this_invoice['custom_id']) ? " wp_invoice_hidden" : "";
        ?>
" href="#"><?php 
        _e('Custom Invoice ID', WPI);
        ?>
</a>
              <?php 
    }
    ?>
            </td>
          </tr>
          <tr class="invoice_main column-publish-global_tax">
            <th><?php 
    _e('Global Tax', WPI);
    ?>
</th>
            <td>
              <?php 
    echo WPI_UI::input("id=wp_invoice_tax&name=wpi_invoice[meta][tax]&value=" . (!empty($this_invoice['tax']) ? $this_invoice['tax'] : ''));
    ?>
            </td>
          </tr>
          <tr class="invoice_main column-publish-global_tax">
            <th><?php 
    _e('Tax Method', WPI);
    ?>
</th>
            <td>
    <?php 
    $tax_method = !empty($this_invoice['tax_method']) ? $this_invoice['tax_method'] : (isset($wpi_settings['tax_method']) ? $wpi_settings['tax_method'] : '');
    ?>
    <?php 
    echo WPI_UI::select("id=wpi_tax_method&name=wpi_invoice[tax_method]&values=" . serialize(array('before_discount' => __('Before Discount', WPI), 'after_discount' => __('After Discount', WPI))) . "&current_value={$tax_method}");
    ?>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <div id="major-publishing-actions" class="clearfix">
      <div id="delete-action" class="wpi_hide_until_saved">
        <a href="<?php 
    echo admin_url($wpi_settings['links']['overview_page']) . "&action=trash&post=" . (!empty($this_invoice['ID']) ? $this_invoice['ID'] : '') . "&_wpnonce=" . wp_create_nonce('wpi-status-change-' . (!empty($this_invoice['ID']) ? $this_invoice['ID'] : ''));
    ?>
" class="submitdelete deletion"><?php 
    _e('Trash Invoice', WPI);
    ?>
</a>
      </div>
      <div id="publishing-action">
        <input type="submit" class="alignright button-primary" value="<?php 
    esc_attr(_e('Save', WPI));
    ?>
" id="wpi_save_invoice">
      </div>
    </div>
  </div>
  <?php 
}