Esempio n. 1
0
 /**
  *
  *
  * @
  * @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 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 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);
 }
 /**
  *                  : Active /   -active.
  *                -active,                                           .
  */
 function updateRowsFromQuantityDiscount($active_rates)
 {
     global $application;
     //                ,                             ,
     //                  View.                    ,               View.
     $YES = 1;
     //Active
     $NO = 2;
     //Disabled
     $not_active_rates_ids = array();
     $active_rates_ids = array();
     foreach ($active_rates as $rate_id => $status) {
         if ($status == $YES) {
             $active_rates_ids[] = $rate_id;
         } else {
             if ($status == $NO) {
                 $not_active_rates_ids[] = $rate_id;
             } else {
                 //: report error.
                 exit(1);
             }
         }
     }
     $tables = $this->getTables();
     $columns = $tables['quantity_discounts_rates_table']['columns'];
     $query = new DB_Update('quantity_discounts_rates_table');
     $query->addUpdateExpression($columns['b_active'], $YES);
     $query->WhereField($columns['id'], DB_IN, "('" . implode("','", $active_rates_ids) . "')");
     $application->db->getDB_Result($query);
     $query = new DB_Update('quantity_discounts_rates_table');
     $query->addUpdateExpression($columns['b_active'], $NO);
     $query->WhereField($columns['id'], DB_IN, "('" . implode("','", $not_active_rates_ids) . "')");
     $application->db->getDB_Result($query);
 }
 /**
  * Moves the category.
  *
  * @author Alexander Girin
  * @param integer $newParentCatId the new category id,
  *        to which the category is moved
  * @param integer $cid the moved category id
  * @return
  */
 function moveCategory($newParentCatId, $cid)
 {
     global $application;
     $NewParentCatInfo = $this->fetchCategoryInfo($newParentCatId);
     $CatInfo = $this->fetchCategoryInfo($cid);
     $catobj = new CCategoryInfo($cid);
     $CurrentParentCatInfo = $catobj->getCategoryTagValue('parentid');
     if ($NewParentCatInfo == FALSE || $CatInfo == FALSE) {
         return;
     }
     $tables = $this->getTables();
     $c = $tables['categories']['columns'];
     # categories is a database table
     $deltaLevel = -($CatInfo['level'] - 1) + $NewParentCatInfo['level'];
     if ($NewParentCatInfo['left'] < $CatInfo['left'] && $NewParentCatInfo['right'] > $CatInfo['right'] && $NewParentCatInfo['level'] < $CatInfo['level'] - 1) {
         $query = new DB_Update('categories');
         $query->addUpdateExpression($c['level'], $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['level'] . sprintf('%+d', $deltaLevel), $c['level']));
         $query->addUpdateExpression($c['right'], $query->fIf($c['right'] . ' ' . DB_BETWEEN . ' ' . ($CatInfo['right'] + 1) . ' ' . DB_AND . ' ' . ($NewParentCatInfo['right'] - 1), $c['right'] . '-' . ($CatInfo['right'] - $CatInfo['left'] + 1), $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['right'] . '+' . (($NewParentCatInfo['right'] - $CatInfo['right'] - $CatInfo['level'] + $NewParentCatInfo['level']) / 2 * 2 + $CatInfo['level'] - $NewParentCatInfo['level'] - 1), $c['right'])));
         $query->addUpdateExpression($c['left'], $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . ($CatInfo['right'] + 1) . ' ' . DB_AND . ' ' . ($NewParentCatInfo['right'] - 1), $c['left'] . '-' . ($CatInfo['right'] - $CatInfo['left'] + 1), $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['left'] . '+' . (($NewParentCatInfo['right'] - $CatInfo['right'] - $CatInfo['level'] + $NewParentCatInfo['level']) / 2 * 2 + $CatInfo['level'] - $NewParentCatInfo['level'] - 1), $c['left'])));
         $query->WhereField($c['left'], DB_BETWEEN, "'" . ($NewParentCatInfo['left'] + 1) . "'" . ' ' . DB_AND . " '" . ($NewParentCatInfo['right'] - 1) . "'");
         $application->db->getDB_Result($query);
     } elseif ($NewParentCatInfo['left'] < $CatInfo['left']) {
         $query = new DB_Update('categories');
         $query->addUpdateExpression($c['level'], $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['level'] . sprintf('%+d', $deltaLevel), $c['level']));
         $query->addUpdateExpression($c['left'], $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $NewParentCatInfo['right'] . ' ' . DB_AND . ' ' . ($CatInfo['left'] - 1), $c['left'] . '+' . ($CatInfo['right'] - $CatInfo['left'] + 1), $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['left'] . '-' . ($CatInfo['left'] - $NewParentCatInfo['right']), $c['left'])));
         $query->addUpdateExpression($c['right'], $query->fIf($c['right'] . ' ' . DB_BETWEEN . ' ' . $NewParentCatInfo['right'] . ' ' . DB_AND . ' ' . $CatInfo['left'], $c['right'] . '+' . ($CatInfo['right'] - $CatInfo['left'] + 1), $query->fIf($c['right'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['right'] . '-' . ($CatInfo['left'] - $NewParentCatInfo['right']), $c['right'])));
         $query->WhereField($c['left'], DB_BETWEEN, "'" . $NewParentCatInfo['left'] . "'" . ' ' . DB_AND . " '" . $CatInfo['right'] . "'");
         $query->WhereOR();
         $query->WhereField($c['right'], DB_BETWEEN, "'" . $NewParentCatInfo['left'] . "'" . ' ' . DB_AND . " '" . $CatInfo['right'] . "'");
         $application->db->getDB_Result($query);
     } else {
         $query = new DB_Update('categories');
         $query->addUpdateExpression($c['level'], $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['level'] . sprintf('%+d', $deltaLevel), $c['level']));
         $query->addUpdateExpression($c['left'], $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['right'] . ' ' . DB_AND . ' ' . $NewParentCatInfo['right'], $c['left'] . '-' . ($CatInfo['right'] - $CatInfo['left'] + 1), $query->fIf($c['left'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['left'] . '+' . ($NewParentCatInfo['right'] - $CatInfo['right'] - 1), $c['left'])));
         $query->addUpdateExpression($c['right'], $query->fIf($c['right'] . ' ' . DB_BETWEEN . ' ' . ($CatInfo['right'] + 1) . ' ' . DB_AND . ' ' . ($NewParentCatInfo['right'] - 1), $c['right'] . '-' . ($CatInfo['right'] - $CatInfo['left'] + 1), $query->fIf($c['right'] . ' ' . DB_BETWEEN . ' ' . $CatInfo['left'] . ' ' . DB_AND . ' ' . $CatInfo['right'], $c['right'] . '+' . ($NewParentCatInfo['right'] - $CatInfo['right'] - 1), $c['right'])));
         $query->WhereField($c['left'], DB_BETWEEN, "'" . $CatInfo['left'] . "'" . ' ' . DB_AND . " '" . $NewParentCatInfo['right'] . "'");
         $query->WhereOR();
         $query->WhereField($c['right'], DB_BETWEEN, "'" . $CatInfo['left'] . "'" . ' ' . DB_AND . " '" . $NewParentCatInfo['right'] . "'");
         $application->db->getDB_Result($query);
     }
     modApiFunc('EventsManager', 'throwEvent', 'CategoryMoved', array('OLD_PARENT_CATEGORY_ID' => $CurrentParentCatInfo, 'NEW_PARENT_CATEGORY_ID' => $newParentCatId, 'CATEGORY_ID_LIST' => $cid));
 }
 function flipPersonInfoTypeStatus($person_info_type_id)
 {
     global $application;
     $tables = $this->getTables();
     $columns = $tables['person_info_types']['columns'];
     $query = new DB_Update('person_info_types');
     $query->addUpdateExpression($columns['active'], "IF(" . $columns['active'] . " = '" . DB_TRUE . "','" . DB_FALSE . "','" . DB_TRUE . "')");
     $query->WhereValue($columns['id'], DB_EQ, $person_info_type_id);
     $application->db->getDB_Result($query);
 }
 function updatePromoCodeTimesUsed($PromoCodeID)
 {
     global $application;
     $tables = $this->getTables();
     $tr = $tables['promo_codes_coupons_table']['columns'];
     $query = new DB_Update('promo_codes_coupons_table');
     $query->addUpdateExpression($tr['times_used'], $tr['times_used'] . "+1");
     $query->WhereValue($tr['id'], DB_EQ, $PromoCodeID);
     $application->db->getDB_Result($query);
 }
 /**
  * Updates the field qunatity in the Inventory table.
  *
  * @param int $inv_id - ID of the updated element
  * @param int $quantity_offset - quantity update (any integer number)
  * @return bool; true if it is updated, false otherwise
  */
 function updateInventoryQuantity($inv_id, $quantity_offset)
 {
     global $application;
     $tables = $this->getTables();
     $it_table = $tables['po_inventory']['columns'];
     $query = new DB_Update('po_inventory');
     $query->addUpdateExpression($it_table['quantity'], $it_table['quantity'] . '+(' . $quantity_offset . ')');
     $query->WhereValue($it_table['it_id'], DB_EQ, $inv_id);
     $application->db->PrepareSQL($query);
     if ($application->db->DB_Exec()) {
         $inv_info = $this->getInventoryInfo($inv_id);
         $sets = $this->getOptionsSettingsForEntity($inv_info['parent_entity'], $inv_info['entity_id']);
         if ($sets['LL_NTF'] != '' and $inv_info['quantity'] <= $sets['LL_NTF']) {
             modApiFunc('EventsManager', 'throwEvent', 'InventoryLowLevel', $inv_info);
         }
     }
 }
 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();
 }