function updateStatus($errdoc_status)
 {
     global $application;
     $tables = Configuration::getTables();
     $columns = $tables['store_settings']['columns'];
     $query = new DB_Update('store_settings');
     $query->addUpdateValue($columns['value'], (int) $errdoc_status);
     $query->WhereValue($columns['name'], DB_EQ, 'enable_error_document');
     $application->db->getDB_Result($query);
 }
 function updateSettings($settings)
 {
     global $application;
     $tables = $this->getTables();
     $stable = $tables['frg_settings']['columns'];
     foreach ($settings as $skey => $sval) {
         $query = new DB_Update('frg_settings');
         $query->addUpdateValue($stable['setting_value'], $sval);
         $query->WhereValue($stable['setting_key'], DB_EQ, $skey);
         $application->db->PrepareSQL($query);
         $application->db->DB_Exec();
     }
 }
 /**
  * Sets the parameter value of module settings.
  * @param string $key - the parameter name
  * @param string $val - the parameter value
  */
 function setValue($key, $value)
 {
     global $application;
     if (!array_key_exists($key, $this->settings) || $this->settings[$key] == $value) {
         return;
     }
     $type = gettype($this->settings[$key]);
     $this->settings[$key] = $value;
     settype($this->settings[$key], $type);
     $tables = $this->getTables();
     $columns = $tables['news_settings']['columns'];
     $query = new DB_Update('news_settings');
     $query->addUpdateValue($columns['value'], $value);
     $query->WhereValue($columns['key'], DB_EQ, $key);
     $application->db->getDB_Result($query);
 }
 /**
  * Saves the sort of credit card types.
  *
  * @return
  */
 function setCreditCardTypesSortOrder($ccTypesSortOrderArray)
 {
     global $application;
     foreach ($ccTypesSortOrderArray as $sort_order => $cc_type_id) {
         $tables = $this->getTables();
         $columns = $tables['credit_card_settings']['columns'];
         $query = new DB_Update('credit_card_settings');
         $query->addUpdateValue($columns['sort_order'], $sort_order);
         $query->WhereValue($columns['id'], DB_EQ, $cc_type_id);
         $application->db->getDB_Result($query);
     }
 }
 function setQuantityDiscountRowActive($rate_id, $rate_status)
 {
     global $application;
     $tables = $this->getTables();
     $columns = $tables['quantity_discounts_rates_table']['columns'];
     $query = new DB_Update('quantity_discounts_rates_table');
     $query->addUpdateValue($columns['b_active'], $rate_status);
     $query->WhereValue($columns['id'], DB_EQ, $rate_id);
     $application->db->getDB_Result($query);
 }
Beispiel #6
0
/**
 * Update the value of an option that was already added.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is inserted into the database. Remember,
 * resources can not be serialized or added as an option.
 *
 * If the option does not exist, then the option will be added with the option
 * value, but you will not be able to set whether it is autoloaded.
 *
 * @since 4.7.5
 * @package Avactis
 * @subpackage Option
 *
 *
 * @param string $option Option name.
 * @param mixed $newvalue Option value.
 */
function asc_update_option($option, $newvalue)
{
    global $application;
    $option = trim($option);
    if (empty($option)) {
        return false;
    }
    $result = asc_get_option($option);
    $old_value = $result;
    $NewserializeVal = serialize($newvalue);
    if ($result) {
        $tables = Configuration::getTables();
        $tr = $tables['options']['columns'];
        $query = new DB_Update('options');
        $query->addUpdateValue($tr['option_value'], $NewserializeVal);
        $query->WhereValue($tr["option_name"], DB_EQ, $option);
        $application->db->PrepareSQL($query);
        $application->db->DB_Exec();
        /**
         * Fires after the value of a specific option has been successfully updated.
         *
         * @param mixed $old_value The old option value.
         * @param mixed $value     The new option value.
         */
        do_action("asc_update_option_{$option}", $old_value, $newvalue);
        /**
         * Fires after the value of an option has been successfully updated.
         *
         * @param string $option    Name of the updated option.
         * @param mixed  $old_value The old option value.
         * @param mixed  $value     The new option value.
         */
        do_action('asc_updated_option', $option, $old_value, $newvalue);
        return true;
    } else {
        asc_add_option($option, $newvalue);
    }
}
 function updateImagesSortOrder($product_id, $sort_order)
 {
     global $application;
     $tables = $this->getTables();
     $images_table = $tables['pi_images']['columns'];
     for ($i = 0; $i < count($sort_order); $i++) {
         $query = new DB_Update('pi_images');
         $query->addUpdateValue($images_table['sort_order'], $i);
         $query->WhereValue($images_table['product_id'], DB_EQ, $product_id);
         $query->WhereAND();
         $query->WhereValue($images_table['image_id'], DB_EQ, $sort_order[$i]);
         $application->db->PrepareSQL($query);
         $application->db->DB_Exec();
     }
     return;
 }
 function updateFsRuleArea($data)
 {
     global $application;
     $tables = $this->getTables();
     $tr = $tables['scc_fs_rules']['columns'];
     $query = new DB_Update('scc_fs_rules');
     $query->addUpdateValue($tr['prods'], $data["prods"]);
     $query->addUpdateValue($tr['cats'], $data["cats"]);
     $query->WhereValue($tr['id'], DB_EQ, $data['fsr_id']);
     $application->db->getDB_Result($query);
 }
 /**
  * updates set's rates in DB
  * imports new set, kills an old one
  * and switches id and sid to substitute
  *
  * @param int $upd_sid
  * @param int $sid
  */
 function substituteSetInDB($upd_sid, $sid)
 {
     global $application;
     // delete the old one
     $this->deleteSetFromDB($upd_sid);
     $tables = TaxRateByZip::getTables();
     // alter rates' sids
     $table = "tax_zip_rates";
     $columns = $tables[$table]['columns'];
     $query = new DB_Update($table);
     $query->addUpdateValue($columns['sid'], $upd_sid);
     $query->WhereValue($columns['sid'], DB_EQ, $sid);
     $application->db->getDB_Result($query);
     // alter set's id
     $table = "tax_zip_sets";
     $columns = $tables[$table]['columns'];
     $query = new DB_Update($table);
     $query->addUpdateValue($columns['id'], $upd_sid);
     $query->WhereValue($columns['id'], DB_EQ, $sid);
     $application->db->getDB_Result($query);
 }
Beispiel #10
0
 /**
  * Updates the specified module in the system.
  *
  * @param ModuleInfo $moduleInfo
  */
 function updateModule($moduleInfo)
 {
     global $application;
     if (version_compare($this->getModuleVersion($moduleInfo->name), $moduleInfo->version) >= 0) {
         return;
     }
     /** check any table changes in the api **/
     $this->includeAPIFileOnce($moduleInfo->name);
     /** Call to update function in the api
      *
      * Structure of UPDATE Module
      * function update(){
      * 		avactis_db_delta(Extension_Name::getTables());
      *      or if supportable
      *      avactis_db_delta($this->getTables());
      *
      *  }
      *  if you are using plain queries you can use
      *
      *  The structure of plain query should be:
      *  function getQueries(){
      *  	global $application
      *  	$table_prefix=$application->getAppIni('DB_TABLE_PREFIX');
      *  	$queries="
      *  	CREATE TABLE {$table_prefix}.avactis_attribute_taxonomies (
      *  	attribute_id bigint(20) NOT NULL auto_increment,
      *  	attribute_name varchar(200) NOT NULL,
      *  	attribute_label longtext NULL,
      *  	attribute_type varchar(200) NOT NULL,
      *  	attribute_orderby varchar(200) NOT NULL,
      *  	 PRIMARY KEY  (attribute_id),
      *  	KEY attribute_name (attribute_name)
      *  	);";
      *  	return $queries;
      *  }
      *  function update(){
      *  	do_dbDelta(Extension_Name::getQueries());
      *      or if supportable
      *      do_dbDelta($this->getQueries());
      *
      *  }
      */
     call_user_func(array($moduleInfo->name, 'update'));
     $tables = $this->getTables();
     $module_tbl = 'module';
     $module_columns = $tables[$module_tbl]['columns'];
     $module_class_tbl = 'module_class';
     $module_class_columns = $tables[$module_class_tbl]['columns'];
     // Update main module info
     $query = new DB_Update($module_tbl);
     $query->addUpdateValue($module_columns['groups'], $moduleInfo->groups);
     $query->addUpdateValue($module_columns['description'], $moduleInfo->description);
     $query->addUpdateValue($module_columns['version'], $moduleInfo->version);
     $query->addUpdateValue($module_columns['author'], $moduleInfo->author);
     $query->addUpdateValue($module_columns['contact'], $moduleInfo->contact);
     $query->addUpdateValue($module_columns['system'], strpos($this->apiFiles[_ml_strtolower($moduleInfo->name)], $this->add_modules_directory) ? 'E' : $moduleInfo->systemModule);
     $query->addUpdateValue($module_columns['updated'], TRUE);
     $query->WhereValue($module_columns['name'], DB_EQ, $moduleInfo->name);
     $application->db->getDB_Result($query);
     // get module_id
     $query = new DB_Select();
     $query->addSelectTable($module_tbl);
     $query->addSelectField($module_columns['id']);
     $query->WhereValue($module_columns['name'], DB_EQ, $moduleInfo->name);
     list(list($moduleId)) = $application->db->getDB_Result($query, QUERY_RESULT_NUM);
     // delete all records from the table module_class that is refferred to the current module
     $query = new DB_Delete($module_class_tbl);
     $query->WhereValue($module_class_columns['module_id'], DB_EQ, $moduleId);
     $application->db->getDB_Result($query);
     $this->insertModuleClassInfo($moduleId, $moduleInfo);
     /*
     //	Extesntion upgrade should be handled by extension itself.
     //	So database upgrade queries should be handled by extentions's 'update' function.
     
     		$upgradeFolder = $this->store_dir.$moduleInfo->directory."/upgrade/";
     		$this->executeUpgradeSQL($oldModuleVersion,$upgradeFolder);
     */
 }
 /**
  * Reelects the default value for the option of the type 'SS'
  *
  * @param int $option_id - option ID
  * @param int $value_id - ID of the value, dominating in the reelection
  * (if it is null, no dominating value exists)
  *
  * @return true it was successfully reelected, false otherwise
  */
 function __chooseAndSetDefaultValueForOption($option_id, $value_id = 0)
 {
     global $application;
     $tables = $this->getTables();
     $values = $tables['po_options_values']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('po_options_values');
     $query->addSelectField($values['value_id'], 'value_id');
     $query->addSelectField($values['is_default'], 'is_default');
     $query->WhereValue($values['option_id'], DB_EQ, $option_id);
     $query->SelectOrder($values['sort_order'], 'ASC');
     $res = $application->db->getDB_Result($query);
     if (!is_array($res)) {
         return false;
     }
     if (!empty($res)) {
         $default_ids = array();
         foreach ($res as $k => $v) {
             if ($v['is_default'] == 'Y') {
                 $default_ids[] = $v['value_id'];
             }
         }
         if (empty($default_ids)) {
             $new_default_id = $value_id > 0 ? $value_id : $res[0]['value_id'];
             $query = new DB_Update('po_options_values');
             $query->addUpdateValue($values['is_default'], 'Y');
             $query->WhereValue($values['value_id'], DB_EQ, $new_default_id);
             $application->db->PrepareSQL($query);
             return $application->db->DB_Exec();
         } elseif (count($default_ids) == 1) {
             if ($value_id > 0) {
                 $query = new DB_Update('po_options_values');
                 $query->addUpdateValue($values['is_default'], 'N');
                 $query->WhereValue($values['value_id'], DB_EQ, $default_ids[0]);
                 $application->db->PrepareSQL($query);
                 if ($application->db->DB_Exec()) {
                     $query = new DB_Update('po_options_values');
                     $query->addUpdateValue($values['is_default'], 'Y');
                     $query->WhereValue($values['value_id'], DB_EQ, $value_id);
                     $application->db->PrepareSQL($query);
                     return $application->db->DB_Exec();
                 } else {
                     return false;
                 }
             }
             return true;
         } else {
             $query = new DB_Update('po_options_values');
             $query->addUpdateValue($values['is_default'], 'N');
             $query->WhereValue($values['option_id'], DB_EQ, $option_id);
             $application->db->PrepareSQL($query);
             if ($application->db->DB_Exec()) {
                 $new_default_id = $value_id > 0 ? $value_id : $default_ids[0];
                 $query = new DB_Update('po_options_values');
                 $query->addUpdateValue($values['is_default'], 'Y');
                 $query->WhereValue($values['value_id'], DB_EQ, $new_default_id);
                 $application->db->PrepareSQL($query);
                 return $application->db->DB_Exec();
             } else {
                 return false;
             }
         }
     }
     return true;
 }
 function updateCurrency($c_id, $c_name, $c_active, $c_default, $c_visible)
 {
     global $application;
     $tables = $this->getTables();
     $c = $tables['currencies']['columns'];
     $query = new DB_Update('currencies');
     $query->addUpdateValue($c["active"], $c_active);
     $query->addUpdateValue($c["default"], $c_default);
     $query->addUpdateValue($c["visible"], $c_visible);
     if ($c_name) {
         $query->addUpdateValue($c["name"], $c_name);
     }
     $query->WhereValue($c["id"], DB_EQ, $c_id);
     $application->db->getDB_Result($query);
 }
 /**
  *
  *
  * @param
  * @return
  */
 function updateTaxRate($id, $c_id, $s_id, $ptc_id, $tn_id, $rate, $formula, $applicable, $rates_set)
 {
     global $application;
     $tables = $this->getTables();
     $tr = $tables['tax_rates']['columns'];
     $query = new DB_Update('tax_rates');
     $query->addUpdateValue($tr['c_id'], $c_id);
     $query->addUpdateValue($tr['s_id'], $s_id);
     $query->addUpdateValue($tr['ptc_id'], $ptc_id);
     $query->addUpdateValue($tr['tn_id'], $tn_id);
     $query->addUpdateValue($tr['rate'], $rate);
     $query->addUpdateValue($tr['formula'], $formula);
     $query->addUpdateValue($tr['applicable'], $applicable);
     $query->addUpdateValue($tr['rates_set'], $rates_set);
     $query->WhereValue($tr['id'], DB_EQ, $id);
     $application->db->getDB_Result($query);
 }
 function __increaseHotlinkTries($hl_key)
 {
     global $application;
     $tables = $this->getTables();
     $hl_table = $tables['pf_hotlinks']['columns'];
     $query = new DB_Update('pf_hotlinks');
     $query->addUpdateExpression($hl_table['was_try'], 'was_try+1');
     $query->WhereValue($hl_table['hotlink_key'], DB_EQ, $hl_key);
     $application->db->PrepareSQL($query);
     return $application->db->DB_Exec();
 }
 /**
  * Copies the part of the updateOrder($data) functionality. It is created
  * only, because updateOrder is too hungus for the small update.
  */
 function updateOrderPersonDataAttribute($order_id, $person_info_variant_id, $person_attribute_id, $b_encrypted, $encrypted_symmetric_secret_key, $rsa_public_key_asc_format, $new_value)
 {
     global $application;
     $tables = $this->getTables();
     $opd = $tables['order_person_data']['columns'];
     $db_update = new DB_Update('order_person_data');
     $db_update->addUpdateValue($opd['value'], $new_value);
     $db_update->addUpdateValue($opd['encrypted_secret_key'], $encrypted_symmetric_secret_key);
     $db_update->addUpdateValue($opd['rsa_public_key_asc_format'], $rsa_public_key_asc_format);
     $db_update->WhereValue($opd['order_id'], DB_EQ, $order_id);
     $db_update->WhereAND();
     $db_update->WhereValue($opd['attribute_id'], DB_EQ, $person_attribute_id);
     $db_update->WhereAND();
     $db_update->WhereValue($opd['variant_id'], DB_EQ, $person_info_variant_id);
     $db_update->WhereAND();
     $db_update->WhereValue($opd['b_encrypted'], DB_EQ, $b_encrypted ? "1" : "0");
     $application->db->PrepareSQL($db_update);
     $application->db->DB_Exec();
 }
 /**
  * Update notification info in the database.
  *
  *@param array $data - the array of features taken from the form
  *
  *@return
  */
 function updateNotification($data)
 {
     global $application;
     $tables = $this->getTables();
     $n = $tables['notifications']['columns'];
     $query = new DB_Update('notifications');
     $query->addUpdateValue($n['na_id'], $data['Action']);
     $query->addMultiLangUpdateValue($n['name'], $data['Name'], $n['id'], '', 'Notifications');
     $query->addMultiLangUpdateValue($n['subject'], $data['Subject'], $n['id'], '', 'Notifications');
     $query->addMultiLangUpdateValue($n['body'], $data['Body'], $n['id'], '', 'Notifications');
     if (key($data['SendFrom']) === 'EMAIL_ADMINISTRATOR') {
         $query->addUpdateValue($n['from_email_admin_id'], $data['SendFrom'][key($data['SendFrom'])]);
         $query->addUpdateValue($n['from_email_custom_address'], "");
     } else {
         $query->addUpdateValue($n['from_email_admin_id'], DB_NULL);
         $query->addUpdateValue($n['from_email_custom_address'], $data['SendFrom'][key($data['SendFrom'])]);
     }
     $query->addUpdateValue($n['from_email_code'], key($data['SendFrom']));
     $query->addUpdateValue($n['active'], $data['Active']);
     $query->WhereValue($n['id'], DB_EQ, $data['Id']);
     $application->db->getDB_Result($query);
     $nst = $tables['notification_send_to']['columns'];
     $query = new DB_Delete('notification_send_to');
     $query->WhereValue($nst['n_id'], DB_EQ, $data['Id']);
     $application->db->getDB_Result($query);
     foreach ($data['SendTo'] as $email) {
         $query = new DB_Insert('notification_send_to');
         $query->addInsertValue($data['Id'], $nst['n_id']);
         $query->addInsertValue($email[key($email)], $nst['email']);
         $query->addInsertValue(key($email), $nst['code']);
         $application->db->getDB_Result($query);
     }
     if ($data['OptionsValues']) {
         $ov2n = $tables['option_values_to_notification']['columns'];
         $query = new DB_Delete('option_values_to_notification');
         $query->WhereValue($ov2n['n_id'], DB_EQ, $data['Id']);
         $application->db->getDB_Result($query);
         foreach ($data['OptionsValues'] as $key => $val) {
             $query = new DB_Insert('option_values_to_notification');
             $query->addInsertValue($key, $ov2n['naov_id']);
             $query->addInsertValue($data['Id'], $ov2n['n_id']);
             $query->addInsertValue('true', $ov2n['value']);
             $application->db->getDB_Result($query);
         }
     }
     if ($data['BlockBodies']) {
         $nbb = $tables['notification_blocktag_bodies']['columns'];
         foreach ($data['BlockBodies'] as $block_id => $body) {
             $query = new DB_Update('notification_blocktag_bodies');
             $query->addMultiLangUpdateValue($nbb['body'], $body, $nbb['id'], '', 'Notifications');
             $query->WhereValue($nbb['nb_id'], DB_EQ, $block_id);
             $query->WhereAnd();
             $query->WhereValue($nbb['n_id'], DB_EQ, $data['Id']);
             $application->db->getDB_Result($query);
         }
     }
 }
 function setManufacturersSortOrder($params)
 {
     global $application;
     $tables = $this->getTables();
     $mnfs_table = $tables['manufacturers']['columns'];
     $new_sort_order = 0;
     foreach ($params as $mnf_id) {
         $query = new DB_Update('manufacturers');
         $query->addUpdateValue($mnfs_table['sort_order'], $new_sort_order);
         $query->WhereValue($mnfs_table['manufacturer_id'], DB_EQ, $mnf_id);
         $application->db->PrepareSQL($query);
         $application->db->DB_Exec();
         $new_sort_order++;
     }
     modApiFunc('EventsManager', 'throwEvent', 'ManufacturerSortOrderUpdated', $params);
 }
 /**
  * function updates products_affected and categories_affected
  * for a given promocode_id
  *
  */
 function updatePromoCodeArea($data)
 {
     global $application;
     $tables = $this->getTables();
     $tr = $tables['promo_codes_coupons_table']['columns'];
     $query = new DB_Update('promo_codes_coupons_table');
     $query->addUpdateValue($tr['products_affected'], $data["prods"]);
     $query->addUpdateValue($tr['categories_affected'], $data["cats"]);
     $query->WhereValue($tr['id'], DB_EQ, $data['pcid']);
     $application->db->getDB_Result($query);
 }
 function updateMd5ByMetaId($meta_id, $current_md5)
 {
     global $application;
     $tables = $this->getTables();
     $tr = $tables['resource_meta']['columns'];
     $query = new DB_Update('resource_meta');
     $query->addUpdateValue($tr['md5'], $current_md5);
     $query->WhereValue($tr['id'], DB_EQ, $meta_id);
     $application->db->getDB_Result($query);
 }
 function disableMRforLayout($layout_path)
 {
     global $application;
     $tables = $this->getTables();
     $int_table = $tables['mr_integrity']['columns'];
     $query = new DB_Update('mr_integrity');
     $query->addUpdateValue($int_table['mr_active'], 'N');
     $query->WhereValue($int_table['layout_path'], DB_EQ, $layout_path);
     $result = $application->db->getDB_Result($query);
     modApiFunc('EventsManager', 'throwEvent', 'ModRewriteChanged');
     return;
 }
 function linkTempEmails($key)
 {
     global $application;
     $tables = Subscriptions::getTables();
     $table = 'subscription_temp';
     $columns =& $tables[$table]['columns'];
     $atable = 'email_address';
     $acolumns =& $tables[$atable]['columns'];
     $query = new DB_Update($table);
     $query->addUpdateTable($atable);
     $query->addUpdateExpression($columns['email_id'], $acolumns['email_id']);
     $query->addUpdateValue($columns['state'], SUBSCRIPTION_TEMP_EXISTS);
     $query->WhereValue($columns['action_key'], DB_EQ, $key);
     $query->WhereAND();
     $query->WhereField($columns['email'], DB_EQ, $acolumns['email']);
     $application->db->getDB_Result($query);
     $query = new DB_Update($table);
     $query->addUpdateValue($columns['state'], SUBSCRIPTION_TEMP_DONT_EXISTS);
     $query->WhereValue($columns['action_key'], DB_EQ, $key);
     $query->WhereAND();
     $query->WhereValue($columns['state'], DB_EQ, SUBSCRIPTION_TEMP_UNKNOWN);
     $application->db->getDB_Result($query);
 }
 /**
  * Reencrypts temporary data on the server. The step of replacing RSA keys.
  * It selects encrypted data by chunks from the database. It reencrypts it and
  * saves back to the temporary table. If all data are reencrypted, returns
  * b_finished =true in the returned array, false otherwise.
  *
  * @param string $rsa_private_key_cryptrsa_format old RSA private key, which
  * was used to encrypt data, stored in the DB
  * @param string $new_rsa_public_key_asc_format new RSA public key, which is
  * used to encrypt data, decrypted by the old RSA private key.
  */
 function ReplaceRSAKeyPairStep2ReencryptTmpData($rsa_private_key_cryptrsa_format, $new_rsa_public_key_asc_format)
 {
     global $application;
     $new_rsa_public_key_cryptrsa_format = modApiFunc("Crypto", "convert_rsa_public_key_from_asc_into_cryptrsa_format", $new_rsa_public_key_asc_format);
     /**
      * Read out from the temporary table 500 records at a time (empirical
      * value).
      *
      * Reencrypt by chunks, that have the same Blowfish key, it is about
      * 10 database records. The decryption of one blowfish key (RSA), if no
      * mathematical libraries exist, can take 10 sec.
      * Check the timeout after each chunk - 2 sec.
      * If no records are left and the timeout is over, exit.
      *
      * Write what has been reencrypted to the database.
      */
     $tmp_table_name = "order_person_data" . $this->getTmpTableSuffix();
     // TableInfo only, but not data. Refer to the table using AVACTIS.
     $opd_tmp_info = clone_db_table_info("Checkout", "order_person_data", $tmp_table_name);
     $opd_tmp = $opd_tmp_info['columns'];
     # get Person Info data. Total record number.
     $query = new DB_Select();
     $query->addSelectField($query->fCount('*'), 'count');
     $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1");
     $result = $application->db->getDB_Result($query);
     $n_total = $result[0]['count'];
     # get Person Info data.
     $query = new DB_Select();
     $query->addSelectField($opd_tmp['id'], 'id');
     $query->addSelectField($opd_tmp['value'], 'value');
     $query->addSelectField($opd_tmp['encrypted_secret_key'], 'encrypted_secret_key');
     $query->addSelectField($opd_tmp['rsa_public_key_asc_format'], 'rsa_public_key_asc_format');
     $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1");
     $query->WhereAnd();
     $query->Where($opd_tmp['id'], DB_GTE, $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId);
     $query->SelectOrder($opd_tmp['id']);
     $query->SelectLimit(0, 500);
     $_person_data = $application->db->getDB_Result($query);
     if (sizeof($_person_data) == 0) {
         //No unreencrypted data is left. The reencryption is completed.
         return array("error_msg" => "", "b_finished" => true, "progress_position" => 1.0);
     } else {
         $i = 0;
         // a number of record from order_person_data
         $start_time = time();
         while (time() - $start_time < 2) {
             //Process one block with the same blowfish key.
             $rsa_encrypted_blowfish_key = $_person_data[$i]['encrypted_secret_key'];
             /*
             If the loaded Private key doesn't match the Public key storing in the database  -
             output an error message. Don't rewrite anything in the database.
             */
             $old_rsa_public_key_asc_format = $_person_data[$i]['rsa_public_key_asc_format'];
             $old_rsa_public_key_cryptrsa_format = modApiFunc("Crypto", "convert_rsa_public_key_from_asc_into_cryptrsa_format", $old_rsa_public_key_asc_format);
             if (modApiFunc("Crypto", "rsa_do_public_key_match_private_key", $old_rsa_public_key_cryptrsa_format, $rsa_private_key_cryptrsa_format) === true) {
                 //BEGIN decrypt blowfish key.
                 $rsa_obj = new Crypt_RSA();
                 $blowfish_key = $rsa_obj->decrypt($rsa_encrypted_blowfish_key, $rsa_private_key_cryptrsa_format);
                 $new_blowfish_key = modApiFunc("Crypto", "blowfish_gen_blowfish_key");
                 $new_encrypted_blowfish_key = $rsa_obj->encrypt($new_blowfish_key, $new_rsa_public_key_cryptrsa_format);
                 //END decrypt blowfish key.
                 //Bulk INSERT will increase the rate greatly!
                 for (; $i < sizeof($_person_data) && $_person_data[$i]['encrypted_secret_key'] == $rsa_encrypted_blowfish_key; $i++) {
                     $decrypted_value = modApiFunc("Crypto", "blowfish_decrypt", base64_decode($_person_data[$i]['value']), $blowfish_key);
                     //Store decrypted data:
                     $query = new DB_Update($tmp_table_name);
                     $query->addUpdateValue($opd_tmp['value'], base64_encode(modApiFunc("Crypto", "blowfish_encrypt", $decrypted_value, $new_blowfish_key)));
                     $query->addUpdateValue($opd_tmp['encrypted_secret_key'], $new_encrypted_blowfish_key);
                     $query->addUpdateValue($opd_tmp['rsa_public_key_asc_format'], $new_rsa_public_key_asc_format);
                     $query->WhereValue($opd_tmp['id'], DB_EQ, $_person_data[$i]['id']);
                     $application->db->getDB_Result($query);
                     $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId = $_person_data[$i]['id'] + 1;
                     $this->saveState();
                     //Don't lose reencrypted data and save correct number
                     //of the last processed record. Otherwise the timeout can occur during the
                     //SQL query and data in the session will be incorrect.
                 }
                 if ($i >= sizeof($_person_data)) {
                     break;
                 }
             } else {
                 //Report an error: keys don't match.
                 $MessageResources =& $application->getInstance('MessageResources');
                 $msg = $MessageResources->getMessage('CRYPTO_RSA_PUBLIC_PRIVATE_KEYS_MISMATCH_DECRYPT_ERROR');
                 return array("error_msg" => $msg, "b_finished" => false, "progress_position" => 0.0);
             }
         }
         # get Person Info data. Total record count.
         $query = new DB_Select();
         $query->addSelectField($query->fCount('*'), 'count');
         $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1");
         $query->WhereAnd();
         $query->Where($opd_tmp['id'], DB_LT, $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId);
         $result = $application->db->getDB_Result($query);
         $n_done = $result[0]['count'];
         return array("error_msg" => "", "b_finished" => false, "progress_position" => 1.0 * $n_done / $n_total);
     }
 }
 /**
  * Sets up module attributes and logs it to the database.
  *
  * @param array $Settings -  module settings array. The undefined parameter values
  * remain unchanged.
  */
 function updateSettings($Settings)
 {
     global $application;
     $tables = $this->getTables();
     $columns = $tables['pm_paypal_settings']['columns'];
     foreach ($Settings as $key => $value) {
         $query = new DB_Update('pm_paypal_settings');
         $query->addUpdateValue($columns['value'], serialize($value));
         $query->WhereValue($columns['key'], DB_EQ, $key);
         $application->db->getDB_Result($query);
     }
 }
 function __install_AddAttrsVisibleNames()
 {
     global $application;
     $MR =& $application->getInstance('MessageResources', 'customer-account-messages', 'AdminZone');
     $tables = Customer_Account::getTables();
     $atg_table = $tables['ca_attrs_to_groups']['columns'];
     foreach ($this->attr_lang_code as $attr_id => $lang_code) {
         $query = new DB_Update('ca_attrs_to_groups');
         $query->addUpdateValue($atg_table['visible_name'], $MR->getMessage($lang_code));
         $query->WhereValue($atg_table['attr_id'], DB_EQ, $attr_id);
         $application->db->PrepareSQL($query);
         $application->db->DB_Exec();
     }
     return;
 }
 function updateModuleStatus($uid, $new_status)
 {
     global $application;
     $tables = TransactionTracking::getTables();
     $columns = $tables['transaction_tracking_modules']['columns'];
     $query = new DB_Update('transaction_tracking_modules');
     $query->addUpdateValue($columns["status_active"], $new_status);
     $query->WhereValue($columns["module_id"], DB_EQ, $uid);
     $result = $application->db->getDB_Result($query);
 }
 /**
  *
  *
  * @param
  * @return
  */
 function encrypt($name, $string)
 {
     if (!$name && !$string) {
         return $string;
     }
     global $application;
     $session_id = session_id();
     $key = md5($session_id . $this->uuid());
     $tables = $this->getTables();
     $table = 'crypto_keys';
     $k = $tables[$table]['columns'];
     $query = new DB_Select();
     $query->addSelectField($k["key"], "crypto_key");
     $query->WhereValue($k["id"], DB_EQ, $session_id);
     $query->WhereAnd();
     $query->WhereValue($k["name"], DB_EQ, $name);
     $result = $application->db->getDB_Result($query);
     if (isset($result[0]['crypto_key']) && $result[0]['crypto_key']) {
         $query = new DB_Update($table);
         $query->addUpdateValue($k["key"], $key);
         $query->addUpdateValue($k['lifetime'], time() + 600);
         $query->WhereValue($k["id"], DB_EQ, $session_id);
         $query->WhereAnd();
         $query->WhereValue($k["name"], DB_EQ, $name);
         $application->db->getDB_Result($query);
     } else {
         $query = new DB_Insert($table);
         $query->addInsertValue($session_id, $k['id']);
         $query->addInsertValue($name, $k['name']);
         $query->addInsertValue($key, $k['key']);
         $query->addInsertValue(time() + 600, $k['lifetime']);
         $application->db->getDB_Result($query);
     }
     $blowfish = new Crypt_Blowfish($key);
     $encrypted_string = $blowfish->encrypt($string);
     return $encrypted_string;
 }
 /**
  *
  *
  * @
  * @param
  * @return
  */
 function updateAdmin($id, $firs_name, $last_name, $e_mail, $options)
 {
     global $application;
     $tables = $this->getTables();
     $a = $tables['admin']['columns'];
     $query = new DB_Update('admin');
     $query->addUpdateValue($a['firstname'], $firs_name);
     $query->addUpdateValue($a['lastname'], $last_name);
     $query->addUpdateValue($a['email'], $e_mail);
     $query->addUpdateExpression($a['modified'], $query->fNow());
     $admin_options = 0;
     for ($i = 1; $i <= sizeof($options); $i++) {
         $admin_options += $options[$i] ? pow(2, $i - 1) : 0;
     }
     $query->addUpdateValue($a['options'], $admin_options);
     $query->WhereValue($a['id'], DB_EQ, $id);
     $application->db->getDB_Result($query);
 }
 function dropCustomerPassword($var, $var_type = 'customer_account')
 {
     if (!in_array($var_type, array('customer_account', 'customer_id'))) {
         return false;
     }
     global $application;
     $tables = $this->getTables();
     $ca_table = $tables['ca_customers']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('ca_customers');
     $query->addSelectField($ca_table['customer_id'], 'customer_id');
     $query->addSelectField($ca_table['customer_account'], 'customer_account');
     $query->WhereValue($ca_table[$var_type], DB_EQ, $var);
     $res = $application->db->getDB_Result($query);
     if (count($res) != 1) {
         return false;
     } else {
         $customer_id = $res[0]['customer_id'];
         $customer_account = $res[0]['customer_account'];
     }
     $query = new DB_Update('ca_customers');
     $query->addUpdateValue($ca_table['customer_password'], $this->__genPseudoPasswd());
     $query->addUpdateValue($ca_table['customer_status'], 'R');
     $query->WhereValue($ca_table['customer_id'], DB_EQ, $customer_id);
     $application->db->PrepareSQL($query);
     return $application->db->DB_Exec() and $this->replaceActivationKey($customer_account);
 }
 function setModuleActive($module_id, $b_active)
 {
     //The condition, where a module doesn't exist in the Checkout table
     // settings, and setModuleActive is called for it, should
     //not exist. So you can get to the place only from the page of
     // module settings, or by automatic operatins into the system
     // (for example, by adding all_inactive to the table at the begining,
     //  when the table is empty).
     //In the first case to open the page of settings, the module should
     // be Selected, and has been added to the setting table before.
     //In the second case hte function setModuleActive is not called. The flag
     // Active is passed in within data for the function setSelectedModules.
     //Delete operations with the falg Active from the function setSelectedModules,
     // it may take much time. For all modules, which become non-Selected,
     // should be set the status non-Active.
     //But to simplify the code, they can be separated.
     global $application;
     $tables = Checkout::getTables();
     $columns = $tables['checkout_pm_sm_settings']['columns'];
     $YES = "1";
     $NO = "2";
     $query = new DB_Update('checkout_pm_sm_settings');
     $query->addUpdateExpression($columns['status_active_value_id'], $b_active === true ? $YES : $NO);
     $query->WhereValue($columns['module_id'], DB_EQ, $module_id);
     $application->db->getDB_Result($query);
     //: add the check to update only one string
     // If zero strings are updated, then an error occurred: the module
     // doesn't exist  in the table.
     if ($b_active === true) {
         Checkout::setPM_SM_RequiredCurrencieslist();
     }
 }
 function __changeAccount($account, $new_account)
 {
     global $application;
     $tables = Customer_Account::getTables();
     $customers_table = $tables['ca_customers']['columns'];
     $query = new DB_Update('ca_customers');
     $query->addUpdateValue($customers_table['customer_account'], $new_account);
     $query->WhereValue($customers_table['customer_account'], DB_EQ, $account);
     $application->db->PrepareSQL($query);
     return $application->db->DB_Exec();
 }