/**
     * Saves passed settings
     * 
     * @global array $wpi_settings
     * @param array $new_settings 
     */
    function SaveSettings($new_settings) {
      global $wpi_settings;
        
        //** Set 'first_time_setup_ran' as 'true' to avoid loading First Time Setup Page in future */
        $new_settings['first_time_setup_ran'] = 'true';
        
        $this->options = WPI_Functions::array_merge_recursive_distinct($this->options, $new_settings);
        
        //** Copy template files from plugin folder to active theme/template */
        if(isset($new_settings['install_use_custom_templates']) &&
          isset($new_settings['use_custom_templates']) &&
          $new_settings['install_use_custom_templates'] == 'yes' && 
          $new_settings['use_custom_templates'] == 'yes') {
            WPI_Functions::install_templates();
        }
        
        //** Process Special Settings */
        //** Default predefined services */
        $this->options['predefined_services'][0]['name']     = __("Web Design Services", WPI);
        $this->options['predefined_services'][0]['quantity'] = 1;
        $this->options['predefined_services'][0]['price']    = 30;
        $this->options['predefined_services'][1]['name']     = __("Web Development Services", WPI);
        $this->options['predefined_services'][1]['quantity'] = 1;
        $this->options['predefined_services'][1]['price']    = 30;
        
        $this->options['predefined_services'] = ( isset($new_settings['predefined_services']) ? $new_settings['predefined_services'] : $this->options['predefined_services'] );

        //** E-Mail Templates */
        if(isset($new_settings['notification'])) {
          $this->options['notification'] = $new_settings['notification'];
        }
        
        //** Process Special Settings */
        
        //** fix checkboxes */
        foreach($this->options['billing'] as $key => $value) {
            if(!isset($new_settings['billing'][$key]['allow'])) unset($this->options['billing'][$key]['allow']);
        }
        
        $checkbox_array = array('increment_invoice_id', 'send_thank_you_email', 'cc_thank_you_email', 'force_https', 'show_recurring_billing', 'send_invoice_creator_email');
        foreach($checkbox_array as $checkbox_name) {
            if(!isset($new_settings[$checkbox_name])) unset($this->options[$checkbox_name]);
        }
        
        $this->CommitUpdates();
        
        //** Update global variable */
        $wpi_settings = WPI_Functions::array_merge_recursive_distinct($wpi_settings, $this->options);
        //** Fix Predefined Services */
        $wpi_settings['predefined_services'] = $this->options['predefined_services'];
        //** Fix E-Mail Templates */
        $wpi_settings['notification'] = $this->options['notification'];
        wpi_gateway_base::sync_billing_objects();
    }
  /**
    We use this to merge two arrays.
    Used when loading default billing data, and then being updated by invoice-specific data
    Awesome function from http://us2.php.net/manual/en/function.array-merge-recursive.php
   */
  function &array_merge_recursive_distinct() {
    $aArrays = func_get_args();
    $aMerged = $aArrays[0];

    for ($i = 1; $i < count($aArrays); $i++) {
      if (is_array($aArrays[$i])) {
        foreach ($aArrays[$i] as $key => $val) {
          if (is_array($aArrays[$i][$key])) {
            $aMerged[$key] = (isset($aMerged[$key]) && is_array($aMerged[$key]) ) ? WPI_Functions::array_merge_recursive_distinct($aMerged[$key], $aArrays[$i][$key]) : $aArrays[$i][$key];
          } else {
            $aMerged[$key] = $val;
          }
        }
      }
    }

    return $aMerged;
  }
Exemple #3
0
 /**
  * Saves passed settings
  *
  * @global array $wpi_settings
  *
  * @param array $new_settings
  */
 function SaveSettings($new_settings)
 {
     global $wpi_settings;
     //** Set 'first_time_setup_ran' as 'true' to avoid loading First Time Setup Page in future */
     $new_settings['first_time_setup_ran'] = 'true';
     $this->options = WPI_Functions::array_merge_recursive_distinct($this->options, $new_settings);
     //** just fo now we use the merged options array and overwrite two brances with new values. It is the custom solution to be able detete currency. odokienko@UD */
     if (isset($new_settings['currency']) && $new_settings['currency']) {
         $this->options['currency']['symbol'] = $new_settings['currency']['symbol'];
         $this->options['currency']['types'] = $new_settings['currency']['types'];
     }
     //** Process Special Settings */
     //** Default predefined services */
     $this->options['predefined_services'][0]['name'] = __("Web Design Services", WPI);
     $this->options['predefined_services'][0]['quantity'] = 1;
     $this->options['predefined_services'][0]['price'] = 30;
     $this->options['predefined_services'][1]['name'] = __("Web Development Services", WPI);
     $this->options['predefined_services'][1]['quantity'] = 1;
     $this->options['predefined_services'][1]['price'] = 30;
     $this->options['predefined_services'] = isset($new_settings['predefined_services']) ? $new_settings['predefined_services'] : $this->options['predefined_services'];
     //** E-Mail Templates */
     if (isset($new_settings['notification'])) {
         $this->options['notification'] = $new_settings['notification'];
     }
     //** fix checkboxes */
     foreach ($this->options['billing'] as $key => $value) {
         if (!isset($new_settings['billing'][$key]['allow'])) {
             unset($this->options['billing'][$key]['allow']);
         }
     }
     $checkbox_array = array('increment_invoice_id', 'send_thank_you_email', 'cc_thank_you_email', 'force_https', 'show_recurring_billing', 'send_invoice_creator_email');
     foreach ($checkbox_array as $checkbox_name) {
         if (!isset($new_settings[$checkbox_name])) {
             unset($this->options[$checkbox_name]);
         }
     }
     $this->CommitUpdates();
     //** Update global variable */
     $wpi_settings = WPI_Functions::array_merge_recursive_distinct($wpi_settings, $this->options);
     //** Fix Predefined Services */
     $wpi_settings['predefined_services'] = $this->options['predefined_services'];
     //** Fix E-Mail Templates */
     $wpi_settings['notification'] = $this->options['notification'];
     wpi_gateway_base::sync_billing_objects();
 }