public static function save($id, $data) { global $lC_DateTime; $update = array('date_available' => strstr($data['products_date_available'], '/') ? lC_DateTime::toDateTime($data['products_date_available']) : $data['products_date_available']); if (lC_Products_Admin::setDateAvailable($id, $update)) { return true; } else { return false; } }
public static function save($id = null, $data) { global $lC_Database, $lC_DateTime; $error = false; $Qproduct = $lC_Database->query('select products_price from :table_products where products_id = :products_id limit 1'); $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); $Qproduct->bindInt(':products_id', $data['products_id']); $Qproduct->execute(); $specials_price = $data['specials_price']; if (substr($specials_price, -1) == '%') { $specials_price = $Qproduct->valueDecimal('products_price') - (double) $specials_price / 100 * $Qproduct->valueDecimal('products_price'); } if ($specials_price < '0.00' || $specials_price >= $Qproduct->valueDecimal('products_price')) { $result['rpcStatus'] = -1; $error = true; } if (strtotime($data['specials_expires_date']) < strtotime($data['specials_start_date'])) { $result['rpcStatus'] = -2; $error = true; } if ($error === false) { if ($id > 0) { $Qspecial = $lC_Database->query('update :table_specials set specials_new_products_price = :specials_new_products_price, specials_last_modified = now(), expires_date = :expires_date, start_date = :start_date, status = :status where specials_id = :specials_id'); $Qspecial->bindInt(':specials_id', $id); } else { $Qspecial = $lC_Database->query('insert into :table_specials (products_id, specials_new_products_price, specials_date_added, expires_date, start_date, status) values (:products_id, :specials_new_products_price, now(), :expires_date, :start_date, :status)'); $Qspecial->bindInt(':products_id', $data['products_id']); } $Qspecial->bindTable(':table_specials', TABLE_SPECIALS); $Qspecial->bindValue(':specials_new_products_price', $specials_price); $Qspecial->bindDate(':expires_date', strstr($data['specials_expires_date'], '/') ? lC_DateTime::toDateTime($data['specials_expires_date']) : $data['specials_expires_date']); $Qspecial->bindDate(':start_date', strstr($data['specials_start_date'], '/') ? lC_DateTime::toDateTime($data['specials_start_date']) : $data['specials_start_date']); $Qspecial->bindInt(':status', $data['specials_status']); $Qspecial->setLogging($_SESSION['module'], $id); $Qspecial->execute(); if ($lC_Database->isError()) { $result['rpcStatus'] = -3; } } return $result; }
public static function save($id = null, $data, $send_email = true) { global $lC_Database, $lC_Language, $lC_DateTime; $lC_Language->loadIniFile('customers.php'); $error = false; $result = array(); if (!is_numeric($id) || is_numeric($id)) { // check that email doesnt exist $Qcheck = $lC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address'); if (isset($id) && is_numeric($id)) { $Qcheck->appendQuery('and customers_id != :customers_id'); $Qcheck->bindInt(':customers_id', $id); } $Qcheck->appendQuery('limit 1'); $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcheck->bindValue(':customers_email_address', $data['email_address']); $Qcheck->execute(); if ($Qcheck->numberOfRows() > 0) { $error = true; $result['rpcStatus'] = -2; } $Qcheck->freeResult(); if (trim($data['password']) != null) { // check that passwords match if (trim($data['password']) != trim($data['confirmation'])) { $error = true; $result['rpcStatus'] = -3; } } } else { // check that passwords match if (trim($data['password']) != trim($data['confirmation'])) { $error = true; $result['rpcStatus'] = -3; } } if ($error === false) { $lC_Database->startTransaction(); if (is_numeric($id)) { $Qcustomer = $lC_Database->query('update :table_customers set customers_group_id = :customers_group_id, customers_gender = :customers_gender, customers_firstname = :customers_firstname, customers_lastname = :customers_lastname, customers_email_address = :customers_email_address, customers_dob = :customers_dob, customers_newsletter = :customers_newsletter, customers_status = :customers_status, date_account_last_modified = :date_account_last_modified where customers_id = :customers_id'); $Qcustomer->bindRaw(':date_account_last_modified', 'now()'); $Qcustomer->bindInt(':customers_id', $id); } else { $Qcustomer = $lC_Database->query('insert into :table_customers (customers_group_id, customers_gender, customers_firstname, customers_lastname, customers_email_address, customers_dob, customers_newsletter, customers_status, number_of_logons, date_account_created) values (:customers_group_id, :customers_gender, :customers_firstname, :customers_lastname, :customers_email_address, :customers_dob, :customers_newsletter, :customers_status, :number_of_logons, :date_account_created)'); $Qcustomer->bindInt(':number_of_logons', 0); $Qcustomer->bindRaw(':date_account_created', 'now()'); } $dob = isset($data['dob']) && !empty($data['dob']) ? lC_DateTime::toDateTime($data['dob']) : '0000-00-00 00:00:00'; $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcustomer->bindValue(':customers_gender', $data['gender']); $Qcustomer->bindValue(':customers_firstname', $data['firstname']); $Qcustomer->bindValue(':customers_lastname', $data['lastname']); $Qcustomer->bindValue(':customers_email_address', $data['email_address']); $Qcustomer->bindValue(':customers_dob', $dob); $Qcustomer->bindInt(':customers_newsletter', $data['newsletter']); $Qcustomer->bindInt(':customers_status', $data['status']); $Qcustomer->bindInt(':customers_group_id', $data['group']); $Qcustomer->setLogging($_SESSION['module'], $id); $Qcustomer->execute(); if (!$lC_Database->isError()) { if (!empty($data['password'])) { $customer_id = !empty($id) ? $id : $lC_Database->nextID(); $result['new_customer_id'] = $customer_id; $Qpassword = $lC_Database->query('update :table_customers set customers_password = :customers_password where customers_id = :customers_id'); $Qpassword->bindTable(':table_customers', TABLE_CUSTOMERS); $Qpassword->bindValue(':customers_password', lc_encrypt_string(trim($data['password']))); $Qpassword->bindInt(':customers_id', $customer_id); $Qpassword->setLogging($_SESSION['module'], $customer_id); $Qpassword->execute(); if ($lC_Database->isError()) { $error = true; $result['rpcStatus'] = -1; } } } } if ($error === false) { $lC_Database->commitTransaction(); if ($send_email === true) { if (empty($id)) { $full_name = trim($data['firstname'] . ' ' . $data['lastname']); $email_text = ''; if (ACCOUNT_GENDER > -1) { if ($data['gender'] == 'm') { $email_text .= sprintf($lC_Language->get('email_greet_mr'), trim($data['lastname'])) . "\n\n"; } else { $email_text .= sprintf($lC_Language->get('email_greet_ms'), trim($data['lastname'])) . "\n\n"; } } else { $email_text .= sprintf($lC_Language->get('email_greet_general'), $full_name) . "\n\n"; } $email_text .= sprintf($lC_Language->get('email_text'), STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, trim($data['password'])); $email_subject = sprintf($lC_Language->get('email_subject'), STORE_NAME); lc_email($full_name, $data['email_address'], $email_subject, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); } } return $result; } $lC_Database->rollbackTransaction(); return $result; }
/** * Save the coupons information * * @param integer $id The coupons id used on update, null on insert * @param array $data An array containing the coupons information * @access public * @return array */ public static function save($id = null, $data) { global $lC_Database, $lC_Language; $error = false; $lC_Database->startTransaction(); if (is_numeric($id)) { $Qfeatured = $lC_Database->query('update :table_featured_products set expires_date = :expires_date, status = :status, last_modified = now() where id = :id'); $Qfeatured->bindInt(':id', $id); } else { $Qfeatured = $lC_Database->query('insert into :table_featured_products (products_id, date_added, last_modified, expires_date, status) values (:products_id, now(), now(), :expires_date, :status)'); $Qfeatured->bindInt(':products_id', $data['products_id']); } // insert/update the featured products table $Qfeatured->bindTable(':table_featured_products', TABLE_FEATURED_PRODUCTS); //$Qfeatured->bindDate(':expires_date', (($data['expires_date'] != '0000-00-00 00:00:00') ? ((strstr($data['expires_date'], '/')) ? lC_DateTime::toDateTime($data['expires_date']) : $data['expires_date']) : '0000-00-00 00:00:00')); $Qfeatured->bindDate(':expires_date', $data['expires_date'] != '0000-00-00 00:00:00' ? lC_DateTime::toDateTime($data['expires_date']) : $data['expires_date']); $Qfeatured->bindInt(':status', $data['status']); $Qfeatured->setLogging($_SESSION['module'], $id); $Qfeatured->execute(); if ($lC_Database->isError()) { $error = true; } if ($error === false) { $lC_Database->commitTransaction(); lC_Cache::clear('featured_products'); if (is_numeric($id)) { return $id; } else { return $lC_Database->nextID(); } } $lC_Database->rollbackTransaction(); return false; }
public static function save($id = null, $data) { global $lC_Database; $error = false; if (empty($data['html_text']) && empty($data['image_local']) && !empty($data['image'])) { if (!file_exists(realpath('../images/' . $data['image_target']))) { mkdir('../images/' . $data['image_target'] . '/', 0777); $path = realpath('../images/' . $data['image_target']); $insert_path = $data['image_target'] . '/'; } else { $path = realpath('../images/banners/'); $insert_path = 'banners/'; } // Remove existing image with the same name. if (file_exists($path . '/' . $data['image']['name'])) { unlink($path . '/' . $data['image']['name']); } $image = new upload($data['image'], $path); if (!$image->exists() || !$image->parse() || !$image->save()) { $error = true; } } if ($error === false) { $image_location = !empty($data['image_local']) ? $data['image_local'] : (isset($image) ? $insert_path . $image->filename : null); if (is_numeric($id)) { $Qbanner = $lC_Database->query('update :table_banners set banners_title = :banners_title, banners_url = :banners_url, banners_target = :banners_target, banners_image = :banners_image, banners_group = :banners_group, banners_html_text = :banners_html_text, expires_date = :expires_date, expires_impressions = :expires_impressions, date_scheduled = :date_scheduled, status = :status where banners_id = :banners_id'); $Qbanner->bindInt(':banners_id', $id); } else { $Qbanner = $lC_Database->query('insert into :table_banners (banners_title, banners_url, banners_target, banners_image, banners_group, banners_html_text, expires_date, expires_impressions, date_scheduled, status, date_added) values (:banners_title, :banners_url, :banners_target, :banners_image, :banners_group, :banners_html_text, :expires_date, :expires_impressions, :date_scheduled, :status, now())'); } $Qbanner->bindTable(':table_banners', TABLE_BANNERS); $Qbanner->bindValue(':banners_title', $data['title']); $Qbanner->bindValue(':banners_url', $data['url']); $Qbanner->bindInt(':banners_target', $data['target'] === true ? 1 : 0); $Qbanner->bindValue(':banners_image', $image_location); $Qbanner->bindValue(':banners_group', !empty($data['group_new']) ? $data['group_new'] : $data['group']); $Qbanner->bindValue(':banners_html_text', $data['html_text']); if (empty($data['date_expires'])) { $Qbanner->bindRaw(':expires_date', 'null'); $Qbanner->bindInt(':expires_impressions', $data['expires_impressions']); } else { $Qbanner->bindValue(':expires_date', lC_DateTime::toDateTime($data['date_expires'])); $Qbanner->bindInt(':expires_impressions', 0); } if (empty($data['date_scheduled'])) { $Qbanner->bindRaw(':date_scheduled', 'null'); $Qbanner->bindInt(':status', $data['status'] === true ? 1 : 0); } else { $Qbanner->bindValue(':date_scheduled', lC_DateTime::toDateTime($data['date_scheduled'])); $Qbanner->bindInt(':status', lC_DateTime::toDateTime($data['date_scheduled']) > @date('Y-m-d') ? 0 : ($data['status'] === true ? 1 : 0)); } $Qbanner->setLogging($_SESSION['module'], $id); $Qbanner->execute(); if (!$lC_Database->isError()) { return true; } } return false; }
/** * Save the coupons information * * @param integer $id The coupons id used on update, null on insert * @param array $data An array containing the coupons information * @access public * @return array */ public static function save($id = null, $data) { global $lC_Database, $lC_Language; $coupon_id = ''; $error = false; $lC_Database->startTransaction(); if (is_numeric($id)) { $Qcoupon = $lC_Database->query('update :table_coupons set type = :type, mode = :mode, code = :code, reward = :reward, purchase_over = :purchase_over, start_date = :start_date, expires_date = :expires_date, uses_per_coupon = :uses_per_coupon, uses_per_customer = :uses_per_customer, restrict_to_products = :restrict_to_products, restrict_to_categories = :restrict_to_categories, restrict_to_customers = :restrict_to_customers, status = :status, date_modified = now(), sale_exclude = :sale_exclude, notes = :notes where coupons_id = :coupons_id'); $Qcoupon->bindInt(':coupons_id', $id); } else { $Qcoupon = $lC_Database->query('insert into :table_coupons (type, mode, code, reward, purchase_over, start_date, expires_date, uses_per_coupon, uses_per_customer, restrict_to_products, restrict_to_categories, restrict_to_customers, status, date_created, date_modified, sale_exclude, notes) values (:type, :mode, :code, :reward, :purchase_over, :start_date, :expires_date, :uses_per_coupon, :uses_per_customer, :restrict_to_products, :restrict_to_categories, :restrict_to_customers, :status, now(), now(), :sale_exclude, :notes)'); } // insert/update the coupons table $Qcoupon->bindTable(':table_coupons', TABLE_COUPONS); $Qcoupon->bindValue(':type', $data['type']); $Qcoupon->bindValue(':mode', $data['mode']); $Qcoupon->bindValue(':code', $data['code']); $Qcoupon->bindValue(':reward', $data['reward']); $Qcoupon->bindInt(':purchase_over', $data['purchase_over'] > 0 ? str_replace('$', '', $data['purchase_over']) : 0.0); $Qcoupon->bindDate(':start_date', $data['start_date'] != '' ? strstr($data['start_date'], '/') ? lC_DateTime::toDateTime($data['start_date']) : $data['start_date'] : null); $Qcoupon->bindDate(':expires_date', $data['expires_date'] != '' ? strstr($data['expires_date'], '/') ? lC_DateTime::toDateTime($data['expires_date']) : $data['expires_date'] : null); $Qcoupon->bindInt(':uses_per_coupon', $data['uses_per_coupon']); $Qcoupon->bindInt(':uses_per_customer', $data['uses_per_customer']); $Qcoupon->bindValue(':restrict_to_products', $data['restrict_to_products']); $Qcoupon->bindValue(':restrict_to_categories', $data['restrict_to_categories']); $Qcoupon->bindValue(':restrict_to_customers', $data['restrict_to_customers']); $Qcoupon->bindInt(':status', $data['status']); $Qcoupon->bindInt(':sale_exclude', $data['sale_exclude']); $Qcoupon->bindValue(':notes', $data['notes']); $Qcoupon->setLogging($_SESSION['module'], $id); $Qcoupon->execute(); if ($lC_Database->isError()) { $error = true; } // insert/update the coupons description table if (!$lC_Database->isError()) { $coupon_id = is_numeric($id) ? $id : $lC_Database->nextID(); foreach ($lC_Language->getAll() as $l) { if (is_numeric($id)) { $Qcoupondescription = $lC_Database->query('update :table_coupons_description set name = :name where coupons_id = :coupons_id and language_id = :language_id'); $Qcoupondescription->bindInt(':coupons_id', $coupon_id); } else { $Qcoupondescription = $lC_Database->query('insert into :table_coupons_description (coupons_id, language_id, name) values (:coupons_id, :language_id, :name)'); $Qcoupondescription->bindInt(':coupons_id', $coupon_id); } $Qcoupondescription->bindTable(':table_coupons_description', TABLE_COUPONS_DESCRIPTION); $Qcoupondescription->bindInt(':language_id', $l['id']); $Qcoupondescription->bindValue(':name', $data['name'][$l['id']]); $Qcoupondescription->execute(); if ($lC_Database->isError()) { $error = true; break; } } } if ($error === false) { $lC_Database->commitTransaction(); return $coupon_id; // Return the coupon ID to with the save_close button } $lC_Database->rollbackTransaction(); return false; }