コード例 #1
0
 /**
  * @param array $data
  * @return int
  */
 public function addCustomer($data)
 {
     $key_sql = '';
     if ($this->dcrypt->active) {
         $data = $this->dcrypt->encrypt_data($data, 'customers');
         $key_sql = ", key_id = '" . (int) $data['key_id'] . "'";
     }
     if (!(int) $data['customer_group_id']) {
         $data['customer_group_id'] = (int) $this->config->get('config_customer_group_id');
     }
     if (!isset($data['status'])) {
         if ($this->config->get('config_customer_email_activation')) {
             // if need to activate via email  - disable status
             $data['status'] = 0;
         } else {
             $data['status'] = 1;
         }
     }
     if (isset($data['approved'])) {
         $data['approved'] = (int) $data['approved'];
     } else {
         if (!$this->config->get('config_customer_approval')) {
             $data['approved'] = 1;
         }
     }
     // delete subscription accounts for given email
     $subscriber = $this->db->query("SELECT customer_id\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("customers") . "\n\t\t\t\t\t\t\t\t\t\tWHERE LOWER(`email`) = LOWER('" . $this->db->escape($data['email']) . "')\n\t\t\t\t\t\t\t\t\t\t\tAND customer_group_id IN (SELECT customer_group_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  FROM " . $this->db->table('customer_groups') . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE `name` = 'Newsletter Subscribers')");
     foreach ($subscriber->rows as $row) {
         $this->db->query("DELETE FROM " . $this->db->table("customers") . " WHERE customer_id = '" . (int) $row['customer_id'] . "'");
         $this->db->query("DELETE FROM " . $this->db->table("addresses") . " WHERE customer_id = '" . (int) $row['customer_id'] . "'");
     }
     $sql = "INSERT INTO " . $this->db->table("customers") . "\n\t\t\t  SET\tstore_id = '" . (int) $this->config->get('config_store_id') . "',\n\t\t\t\t\tloginname = '" . $this->db->escape($data['loginname']) . "',\n\t\t\t\t\tfirstname = '" . $this->db->escape($data['firstname']) . "',\n\t\t\t\t\tlastname = '" . $this->db->escape($data['lastname']) . "',\n\t\t\t\t\temail = '" . $this->db->escape($data['email']) . "',\n\t\t\t\t\ttelephone = '" . $this->db->escape($data['telephone']) . "',\n\t\t\t\t\tfax = '" . $this->db->escape($data['fax']) . "',\n\t\t\t\t\tpassword = '******'password'])) . "',\n\t\t\t\t\tnewsletter = '" . (int) $data['newsletter'] . "',\n\t\t\t\t\tcustomer_group_id = '" . (int) $data['customer_group_id'] . "',\n\t\t\t\t\tapproved = '" . (int) $data['approved'] . "',\n\t\t\t\t\tstatus = '" . (int) $data['status'] . "'" . $key_sql . ",\n\t\t\t\t\tip = '" . $this->db->escape($data['ip']) . "',\n\t\t\t\t\tdate_added = NOW()";
     $this->db->query($sql);
     $customer_id = $this->db->getLastId();
     $key_sql = '';
     if ($this->dcrypt->active) {
         $data = $this->dcrypt->encrypt_data($data, 'addresses');
         $key_sql = ", key_id = '" . (int) $data['key_id'] . "'";
     }
     $this->db->query("INSERT INTO " . $this->db->table("addresses") . " \n      \t\t\t\t\t  SET \tcustomer_id = '" . (int) $customer_id . "', \n      \t\t\t\t\t  \t\tfirstname = '" . $this->db->escape($data['firstname']) . "', \n      \t\t\t\t\t  \t\tlastname = '" . $this->db->escape($data['lastname']) . "', \n      \t\t\t\t\t  \t\tcompany = '" . $this->db->escape($data['company']) . "', \n      \t\t\t\t\t  \t\taddress_1 = '" . $this->db->escape($data['address_1']) . "', \n      \t\t\t\t\t  \t\taddress_2 = '" . $this->db->escape($data['address_2']) . "', \n      \t\t\t\t\t  \t\tcity = '" . $this->db->escape($data['city']) . "', \n      \t\t\t\t\t  \t\tpostcode = '" . $this->db->escape($data['postcode']) . "', \n      \t\t\t\t\t  \t\tcountry_id = '" . (int) $data['country_id'] . "'" . $key_sql . ",\n      \t\t\t\t\t  \t\tzone_id = '" . (int) $data['zone_id'] . "'");
     $address_id = $this->db->getLastId();
     $this->db->query("UPDATE " . $this->db->table("customers") . " SET address_id = '" . (int) $address_id . "' WHERE customer_id = '" . (int) $customer_id . "'");
     if (!$data['approved']) {
         $language = new ALanguage($this->registry);
         $language->load('account/create');
         //notify administrator of pending customer approval
         $msg_text = sprintf($language->get('text_pending_customer_approval'), $data['firstname'] . ' ' . $data['lastname'], $customer_id);
         $msg = new AMessage();
         $msg->saveNotice($language->get('text_new_customer'), $msg_text);
     }
     return $customer_id;
 }
コード例 #2
0
ファイル: review.php プロジェクト: siddht1/abantecart-src
 /**
  * @param int $product_id
  * @param array $data
  * @return int
  */
 public function addReview($product_id, $data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("reviews") . " \n\t\t\t\t\t\t  SET author = '" . $this->db->escape($data['name']) . "',\n\t\t\t\t\t\t      customer_id = '" . (int) $this->customer->getId() . "',\n\t\t\t\t\t\t      product_id = '" . (int) $product_id . "',\n\t\t\t\t\t\t      text = '" . $this->db->escape(strip_tags($data['text'])) . "',\n\t\t\t\t\t\t      rating = '" . (int) $data['rating'] . "',\n\t\t\t\t\t\t      date_added = NOW()");
     $review_id = $this->db->getLastId();
     //notify administrator of pending review approval
     $language = new ALanguage($this->registry);
     $language->load('product/product');
     $msg_text = sprintf($language->get('text_pending_review_approval'), $product_id, $review_id);
     $msg = new AMessage();
     $msg->saveNotice($language->get('text_new_review'), $msg_text);
     $this->cache->remove('product');
     return $review_id;
 }
コード例 #3
0
ファイル: user.php プロジェクト: siddht1/abantecart-src
 public function editUser($user_id, $data)
 {
     $fields = array('username', 'firstname', 'lastname', 'email', 'user_group_id', 'status');
     $update = array();
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if ($data['password'] || $data['email'] || $data['username']) {
         //notify admin user of important infoamtion change
         $language = new ALanguage($this->registry, '', 1);
         $language->load('common/im');
         $message_arr = array(1 => array('message' => $language->get('im_account_update_text_to_admin')));
         $this->im->sendToUser($user_id, 'account_update', $message_arr);
     }
     if (!empty($data['password'])) {
         $update[] = "password = '******'password'])) . "'";
     }
     if (!empty($update)) {
         $sql = "UPDATE " . $this->db->table("users") . " SET " . implode(',', $update) . " WHERE user_id = '" . (int) $user_id . "'";
         $this->db->query($sql);
     }
 }
コード例 #4
0
 public function block_info()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('design/blocks');
     //load specific template/page/layout
     $template = $this->request->get['template'];
     $page_id = $this->request->get['page_id'];
     $layout_id = $this->request->get['layout_id'];
     $lm = new ALayoutManager($template, $page_id, $layout_id);
     //acccept 2 type of ids. Number based and custom [block]_[custom_block]
     $custom_block_id = $this->request->get['block_id'];
     if (preg_match("/(\\d+)_(\\d+)/", $custom_block_id, $match)) {
         //take last postion of id for custom block
         $block_id = $match[1];
         $custom_block_id = $match[2];
     } else {
         if (is_numeric($custom_block_id)) {
             $block_id = $custom_block_id;
             $custom_block_id = 0;
         } else {
             //error
             $this->load->library('json');
             $this->response->addJSONHeader();
             $this->response->setOutput(AJson::encode(array('error' => 'Incorrect Block ID')));
             return null;
         }
     }
     $info = $lm->getBlockInfo((int) $block_id);
     foreach ($info as &$i) {
         $i['block_date_added'] = dateISO2Display($i['block_date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
     }
     //expect only 1 block details per layout
     $this->data = array_merge($info[0], $this->data);
     $this->data['block_info'] = $info;
     //get specific description
     if ($custom_block_id > 0) {
         $descr = $lm->getBlockDescriptions((int) $custom_block_id);
         $language_id = $this->language->getContentLanguageID();
         $this->data['title'] = $descr[$language_id]['title'];
         $this->data['description'] = $descr[$language_id]['description'];
         //detect edit URL and build button
         if ($this->data['block_txt_id'] == 'html_block' || $this->data['block_txt_id'] == 'listing_block') {
             $edit_url = $this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $custom_block_id);
         } else {
             if ($this->data['block_txt_id'] == 'banner_block') {
                 $edit_url = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
             } else {
                 //just list all
                 $edit_url = $this->html->getSecureURL('design/blocks');
             }
         }
         $this->data['block_edit'] = $edit_url;
         $this->data['allow_edit'] = 'true';
     } else {
         //get details from language for static blocks from storefront
         $alang = new ALanguage($this->registry, $this->language->getContentLanguageCode(), 0);
         $alang->load($this->data['controller'], 'silent');
         $this->data['title'] = $alang->get('heading_title');
         $this->data['title'] = $this->data['title'] == 'heading_title' ? $this->data['block_txt_id'] : $this->data['title'];
     }
     $this->data['blocks_layouts'] = $lm->getBlocksLayouts($block_id, $custom_block_id);
     $this->data['text_edit'] = $this->language->get('text_edit');
     $this->data['text_close'] = $this->language->get('text_close');
     //update controller data
     $this->view->batchAssign($this->data);
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->processTemplate('responses/design/block_details.tpl');
 }
コード例 #5
0
ファイル: order.php プロジェクト: Cali-gula/abantecart-src
 /**
  * @param int $order_id
  * @param int $order_status_id
  * @param string $comment
  * @param bool $notify
  */
 public function update($order_id, $order_status_id, $comment = '', $notify = FALSE)
 {
     $order_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t FROM `" . $this->db->table("orders") . "` o\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . $this->db->table("languages") . " l ON (o.language_id = l.language_id)\n\t\t\t\t\t\t\t\t\t\t WHERE o.order_id = '" . (int) $order_id . "' AND o.order_status_id > '0'");
     if ($order_query->num_rows) {
         $order_row = $this->dcrypt->decrypt_data($order_query->row, 'orders');
         $this->db->query("UPDATE `" . $this->db->table("orders") . "`\n\t\t\t\t\t\t\t\tSET order_status_id = '" . (int) $order_status_id . "',\n\t\t\t\t\t\t\t\t\tdate_modified = NOW()\n\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'");
         $this->db->query("INSERT INTO " . $this->db->table("order_history") . "\n\t\t\t\t\t\t\t\tSET order_id = '" . (int) $order_id . "',\n\t\t\t\t\t\t\t\t\torder_status_id = '" . (int) $order_status_id . "',\n\t\t\t\t\t\t\t\t\tnotify = '" . (int) $notify . "',\n\t\t\t\t\t\t\t\t\tcomment = '" . $this->db->escape($comment) . "',\n\t\t\t\t\t\t\t\t\tdate_added = NOW()");
         if ($notify) {
             $language = new ALanguage($this->registry, $order_row['code']);
             $language->load($order_row['filename']);
             $language->load('mail/order_update');
             $subject = sprintf($language->get('text_subject'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
             $message = $language->get('text_order') . ' ' . $order_id . "\n";
             $message .= $language->get('text_date_added') . ' ' . dateISO2Display($order_row['date_added'], $language->get('date_format_short')) . "\n\n";
             $order_status_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_statuses") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_status_id = '" . (int) $order_status_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $order_row['language_id'] . "'");
             if ($order_status_query->num_rows) {
                 $message .= $language->get('text_order_status') . "\n\n";
                 $message .= $order_status_query->row['name'] . "\n\n";
             }
             $message .= $language->get('text_invoice') . "\n";
             $message .= $order_row['store_url'] . 'index.php?rt=account/invoice&order_id=' . $order_id . "\n\n";
             if ($comment) {
                 $message .= $language->get('text_comment') . "\n\n";
                 $message .= $comment . "\n\n";
             }
             $message .= $language->get('text_footer');
             $mail = new AMail($this->config);
             $mail->setTo($order_row['email']);
             $mail->setFrom($this->config->get('store_main_email'));
             $mail->setSender($order_row['store_name']);
             $mail->setSubject($subject);
             $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
             $mail->send();
         }
     }
 }
コード例 #6
0
ファイル: order.php プロジェクト: afshinnj/abantecart-src
 /**
  * @param int $order_id
  * @param array $data
  * @throws AException
  */
 public function addOrderHistory($order_id, $data)
 {
     $this->db->query("UPDATE `" . $this->db->table("orders") . "`\n\t\t\t\t\t\t\tSET order_status_id = '" . (int) $data['order_status_id'] . "',\n\t\t\t\t\t\t\t\tdate_modified = NOW()\n\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'");
     if ($data['append']) {
         $this->db->query("INSERT INTO " . $this->db->table("order_history") . "\n      \t\t                    SET order_id = '" . (int) $order_id . "',\n      \t\t                        order_status_id = '" . (int) $data['order_status_id'] . "',\n      \t\t                        notify = '" . (isset($data['notify']) ? (int) $data['notify'] : 0) . "',\n      \t\t                        comment = '" . $this->db->escape(strip_tags($data['comment'])) . "',\n      \t\t                        date_added = NOW()");
     }
     if ($data['notify']) {
         $order_query = $this->db->query("SELECT *, os.name AS status\n        \t                                FROM `" . $this->db->table("orders") . "` o\n        \t                                LEFT JOIN " . $this->db->table("order_statuses") . " os ON (o.order_status_id = os.order_status_id AND os.language_id = o.language_id)\n        \t                                LEFT JOIN " . $this->db->table("languages") . " l ON (o.language_id = l.language_id)\n        \t                                WHERE o.order_id = '" . (int) $order_id . "'");
         if ($order_query->num_rows) {
             //load language specific for the order in admin section
             $language = new ALanguage(Registry::getInstance(), $order_query->row['code'], 1);
             $language->load($order_query->row['filename']);
             $language->load('mail/order');
             $this->load->model('setting/store');
             $subject = sprintf($language->get('text_subject'), $order_query->row['store_name'], $order_id);
             $message = $language->get('text_order') . ' ' . $order_id . "\n";
             $message .= $language->get('text_date_added') . ' ' . dateISO2Display($order_query->row['date_added'], $language->get('date_format_short')) . "\n\n";
             $message .= $language->get('text_order_status') . "\n\n";
             $message .= $order_query->row['status'] . "\n\n";
             $message .= $language->get('text_invoice') . "\n";
             $message .= html_entity_decode($order_query->row['store_url'] . 'index.php?rt=account/invoice&order_id=' . $order_id, ENT_QUOTES, 'UTF-8') . "\n\n";
             if ($data['comment']) {
                 $message .= $language->get('text_comment') . "\n\n";
                 $message .= strip_tags(html_entity_decode($data['comment'], ENT_QUOTES, 'UTF-8')) . "\n\n";
             }
             $message .= $language->get('text_footer');
             if ($this->dcrypt->active) {
                 $customer_email = $this->dcrypt->decrypt_field($order_query->row['email'], $order_query->row['key_id']);
             } else {
                 $customer_email = $order_query->row['email'];
             }
             $mail = new AMail($this->config);
             $mail->setTo($customer_email);
             $mail->setFrom($this->config->get('store_main_email'));
             $mail->setSender($order_query->row['store_name']);
             $mail->setSubject($subject);
             $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
             $mail->send();
         }
     }
 }
コード例 #7
0
ファイル: blocks_grid.php プロジェクト: harshzalavadiya/fatak
 public function block_info()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('design/blocks');
     //load specific template/page/layout
     $template = $this->request->get['template'];
     $page_id = $this->request->get['page_id'];
     $layout_id = $this->request->get['layout_id'];
     $lm = new ALayoutManager($template, $page_id, $layout_id);
     //acccept 2 type of ids. Number based and custom [block]_[custom_block]
     $custom_block_id = $this->request->get['block_id'];
     if (preg_match("/(\\d+)_(\\d+)/", $custom_block_id, $match)) {
         //take last postion of id for custom block
         $block_id = $match[1];
         $custom_block_id = $match[2];
     } else {
         //error
         $this->load->library('json');
         $this->response->addJSONHeader();
         $this->response->setOutput(AJson::encode(array('error' => 'Incorrect Block ID')));
         return null;
     }
     $info = $lm->getBlockInfo((int) $block_id);
     //expect only 1 block details per layout
     $this->data = array_merge($info[0], $this->data);
     //get specific description
     if ($custom_block_id > 0) {
         $descr = $lm->getBlockDescriptions((int) $custom_block_id);
         $language_id = $this->language->getContentLanguageID();
         $this->data['block_id'] = $block_id;
         $this->data['custom_block_id'] = $custom_block_id;
         $this->data['title'] = $descr[$language_id]['title'];
         $this->data['description'] = $descr[$language_id]['description'];
         //detect edit URL and build button
         if ($this->data['block_txt_id'] == 'html_block' || $this->data['block_txt_id'] == 'listing_block') {
             $edit_url = $this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $custom_block_id);
         } else {
             if ($this->data['block_txt_id'] == 'banner_block') {
                 $edit_url = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
             } else {
                 //just list all
                 $edit_url = $this->html->getSecureURL('design/blocks');
             }
         }
         $this->data['block_edit_brn'] = $this->html->buildButton(array('type' => 'button', 'name' => 'btn_edit', 'id' => 'btn_edit', 'text' => $this->language->get('text_edit'), 'href' => $edit_url, 'target' => '_new', 'style' => 'button1'));
         $this->data['allow_edit'] = 'true';
     } else {
         //get details from language for static blocks from storefront
         $alang = new ALanguage($this->registry, $language_id, 0);
         $alang->load($this->data['controller'], 'silent');
         $this->data['title'] = $alang->get('heading_title');
         $this->data['title'] = $this->data['title'] == 'heading_title' ? $this->data['block_txt_id'] : $this->data['title'];
         $this->data['description'] = $this->language->get('text_controller') . ": " . $this->data['controller'];
         $this->data['description'] .= "<br/>" . $this->language->get('text_templates') . ": ";
         $this->data['description'] .= "<br/>" . str_replace(',', '<br/>', $this->data['templates']);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($this->data));
 }
コード例 #8
0
 /**
  * Method for reloading definitions from xml-file to database
  * @param int $language_id 
  * @param string $section  - 1 or 0 - admin or storefront
  * @param string $specific_block - name of the block
  * @return bool
  */
 public function definitionAutoLoad($language_id, $section, $specific_block)
 {
     if ((int) $language_id === 0 && !is_integer($language_id)) {
         $this->error = 'Cannot reload definitions when language id is unknown ("' . $language_id . '").';
         return false;
     }
     if (!in_array($section, array(1, 0, 'all', 'admin', 'storefront'), true)) {
         $this->error = 'Cannot reload definitions when section is not in array( 1, 0, "all" ).';
         return false;
     }
     ini_set('max_execution_time', 600);
     $sections = $section == 'all' ? array('admin', 'storefront') : '';
     $sections = in_array($section, array('admin', 1), true) ? array('admin') : $sections;
     $sections = in_array($section, array('storefront', 0), true) ? array('storefront') : $sections;
     $language_name = '';
     $language_code = '';
     foreach ($this->available_languages as $lang) {
         if ($language_id == $lang['language_id']) {
             $language_name = $lang['directory'];
             $language_code = $lang['code'];
             break;
         }
     }
     //delete cash before loading
     if (is_object($this->cache)) {
         $this->cache->delete('lang');
         $this->cache->delete('language_definitions');
         $this->cache->delete('storefront_menu');
     }
     //get list of lang blocks for every language
     $language_blocks = array();
     if ($specific_block == 'all') {
         $language_blocks = $this->getAllLanguageBlocks($language_name);
     } else {
         // create list of language blocks when $block is set
         $blocks = $this->getAllLanguageBlocks($language_name);
         foreach ($sections as $sect) {
             foreach ($blocks[$sect] as $rt) {
                 if ($rt == $specific_block) {
                     $language_blocks[$sect][] = $rt;
                     break;
                 }
             }
             foreach ($blocks['extensions'][$sect] as $rt) {
                 if ($rt == $specific_block) {
                     $language_blocks['extensions'][$sect][] = $rt;
                     break;
                 }
             }
             $language_blocks[$sect] = !isset($language_blocks[$sect]) ? array() : $language_blocks[$sect];
             $language_blocks['extensions'][$sect] = !isset($language_blocks['extensions'][$sect]) ? array() : $language_blocks['extensions'][$sect];
         }
     }
     foreach ($sections as $sect) {
         $alang = new ALanguage($this->registry, $language_code, $sect == 'admin' ? 1 : 0);
         // load into db extensions definitions
         if ($language_blocks['extensions'][$sect]) {
             foreach ($language_blocks['extensions'][$sect] as $rt) {
                 if ($specific_block != 'all' && $rt != $specific_block) {
                     continue;
                 }
                 $alang->load($rt, 'silent');
             }
         }
         // load into db core admin & storefront
         if ($language_blocks[$sect]) {
             foreach ($language_blocks[$sect] as $rt) {
                 $alang->load($rt, 'silent');
             }
         }
     }
     return true;
 }
コード例 #9
0
ファイル: customer.php プロジェクト: siddht1/abantecart-src
 /**
  * @param string $loginname
  * @param string $password
  */
 public function editPassword($loginname, $password)
 {
     $password = AEncryption::getHash($password);
     $this->db->query("UPDATE " . $this->db->table("customers") . "\n      \t                SET password = '******'\n      \t                WHERE loginname = '" . $this->db->escape($loginname) . "'");
     //send IM
     $sql = "SELECT customer_id\n \t\t\t\tFROM " . $this->db->table("customers") . "\n\t\t      \tWHERE loginname = '" . $this->db->escape($loginname) . "'";
     $result = $this->db->query($sql);
     $customer_id = $result->row['customer_id'];
     if ($customer_id) {
         $language = new ALanguage($this->registry);
         $language->load('common/im');
         $message_arr = array(0 => array('message' => $language->get('im_customer_account_update_password_to_customer')));
         $this->im->send('customer_account_update', $message_arr);
     }
 }
コード例 #10
0
 /**
  * @param array $data
  * @return bool|int
  * @throws AException
  */
 public function addCustomerTransaction($data = array())
 {
     if (!(double) $data['credit'] && !(double) $data['debit'] || !(int) $data['customer_id']) {
         return false;
     }
     $sql = "INSERT INTO " . $this->db->table("customer_transactions") . "\n                    (`customer_id`,`order_id`,`created_by`,`credit`,`debit`,`section`, `transaction_type`,`comment`,`description`,`date_added`)\n                VALUES (\n                        '" . (int) $data['customer_id'] . "',\n                        '" . (int) $data['order_id'] . "',\n                        '" . $this->user->getId() . "',\n                        '" . (double) $data['credit'] . "',\n                        '" . (double) $data['debit'] . "',\n                        '1',\n                        '" . $this->db->escape($data['transaction_type']) . "',\n                        '" . $this->db->escape($data['comment']) . "',\n                        '" . $this->db->escape($data['description']) . "',\n                        NOW()\n                        )";
     $this->db->query($sql);
     $transaction_id = $this->db->getLastId();
     if ($data['notify']) {
         $this->load->model('sale/customer');
         $customer_info = $this->model_sale_customer->getCustomer($data['customer_id']);
         if ($customer_info) {
             //detect customer's language
             $sql = "SELECT language_id\n                        FROM " . $this->db->table('orders') . "\n                        WHERE customer_id = '" . (int) $data['customer_id'] . "'\n                        ORDER BY date_added DESC";
             $result = $this->db->query($sql);
             $language_code = '';
             if ($result->row['language_id']) {
                 $lang = $this->language->getLanguageDetailsByID($result->row['language_id']);
                 $language_code = $lang['code'];
             }
             if (!$language_code) {
                 $language_code = $this->language->getDefaultLanguageCode();
             }
             //load language specific for the order in admin section
             $language = new ALanguage(Registry::getInstance(), $language_code, 1);
             $language->load('sale/customer');
             $this->load->model('setting/store');
             $store_info = $this->model_setting_store->getStore((int) $this->session->data['current_store_id']);
             $subject = sprintf($language->get('text_transaction_notification_subject'), $store_info['store_name']);
             $url = html_entity_decode($store_info['config_url'] . 'index.php?rt=account/transactions', ENT_QUOTES, 'UTF-8');
             $amount = $this->currency->format($data['credit'] - $data['debit']);
             $message = sprintf($language->get('text_transaction_notification_message'), $store_info['store_name'], $amount, $store_info['store_name']) . "\n\n";
             $message .= $url . "\n\n";
             $message .= $data['description'];
             $mail = new AMail($this->config);
             $mail->setTo($customer_info['email']);
             $mail->setFrom($store_info['store_main_email']);
             $mail->setSender($store_info['store_name']);
             $mail->setSubject($subject);
             $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
             $mail->send();
             //notify customer
             $language->load('common/im');
             $message_arr = array(0 => array('message' => sprintf($language->get('im_customer_account_update_text_to_customer'), $store_info['store_name'], $amount, $store_info['store_name'])));
             $this->im->sendToCustomer($data['customer_id'], 'customer_account_update', $message_arr);
         }
     }
     return $transaction_id;
 }