function copyTempEmails($key)
 {
     global $application;
     $tables = Subscriptions::getTables();
     $stable = 'subscription_temp';
     $itable = 'email_address';
     $iquery = new DB_Insert_Select($itable);
     $iquery->setModifiers(DB_IGNORE);
     $iquery->setInsertFields(array($tables[$itable]['columns']['email'], $tables[$itable]['columns']['lng']));
     $squery = new DB_Select($stable);
     $squery->addSelectField($tables[$stable]['columns']['email']);
     $squery->addSelectValue('\'' . modApiFunc('MultiLang', 'getLanguage') . '\'', 'lng');
     $squery->Where($tables[$stable]['columns']['action_key'], DB_EQ, DBQuery::quoteValue($key));
     $iquery->setSelectQuery($squery);
     $application->db->getDB_Result($iquery);
 }
 /**
  * Return the stock sum of all inventory table.
  * @return mixed Return int or null.
  */
 function getQuantityInStockByInventoryTable($parent_entity, $entity_id, $positive_only = false)
 {
     global $application;
     $tables = $this->getTables();
     $it_table = $tables['po_inventory']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('po_inventory');
     if ($positive_only) {
         $query->addSelectValue('SUM(IF(quantity>0,quantity,0))', 'quantity');
     } else {
         $query->addSelectValue('SUM(quantity)', 'quantity');
     }
     $query->WhereValue($it_table['parent_entity'], DB_EQ, $parent_entity);
     $query->WhereAND();
     $query->WhereValue($it_table['entity_id'], DB_EQ, $entity_id);
     $res = $application->db->getDB_Result($query);
     $stock = null;
     if (!empty($res)) {
         $stock = $res[0]['quantity'];
     }
     return $stock;
 }