public static function postprocess($sessions, $groupparams, $user, $yachs, $sport, $period)
 {
     $gpsdata = " ['Lat', 'Lon', 'Name']";
     foreach ($sessions as $item) {
         $d1 = new Jdate($item->tdate);
         $a1 = '<a href="' . JRoute::_('index.php?option=com_htraininglogs&view=sessions&page=daypage&date=' . $item->tdate) . '">' . $d1->Format('Y-m-d H:i') . '</a>';
         $gpsdata = $gpsdata . ",[" . $item->lat . "," . $item->lon . "," . "'" . $a1 . '<br>' . $item->method . '<br>' . $item->location . "']";
     }
     return $gpsdata;
 }
Example #2
0
 /**
  * @param $data
  * @return int
  */
 public function addCategory($data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("categories") . " \n\t\t\t\t\t\t  SET parent_id = '" . (int) $data['parent_id'] . "',\n\t\t\t\t\t\t      sort_order = '" . (int) $data['sort_order'] . "',\n\t\t\t\t\t\t      status = '" . (int) $data['status'] . "',\n\t\t\t\t\t\t      date_modified = '" . Jdate::now() . "',\n\t\t\t\t\t\t      date_added = '" . Jdate::now() . "'");
     $category_id = $this->db->getLastId();
     foreach ($data['category_description'] as $language_id => $value) {
         $this->language->replaceDescriptions('category_descriptions', array('category_id' => (int) $category_id), array($language_id => array('name' => $value['name'], 'meta_keywords' => $value['meta_keywords'], 'meta_description' => $value['meta_description'], 'description' => $value['description'])));
     }
     if (isset($data['category_store'])) {
         foreach ($data['category_store'] as $store_id) {
             $this->db->query("INSERT INTO " . $this->db->table("categories_to_stores") . " SET category_id = '" . (int) $category_id . "', store_id = '" . (int) $store_id . "'");
         }
     }
     if ($data['keyword']) {
         $seo_key = SEOEncode($data['keyword'], 'category_id', $category_id);
     } else {
         //Default behavior to save SEO URL keword from category name in default language
         /**
          * @var ALanguageManager
          */
         $seo_key = SEOEncode($data['category_description'][$this->language->getDefaultLanguageID()]['name'], 'category_id', $category_id);
     }
     if ($seo_key) {
         $this->language->replaceDescriptions('url_aliases', array('query' => "category_id=" . (int) $category_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $seo_key)));
     } else {
         $this->db->query("DELETE\n\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\tWHERE query = 'category_id=" . (int) $category_id . "'\n\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
     }
     $this->cache->delete('category');
     return $category_id;
 }
Example #3
0
 /**
  * @param array $data
  * @return int
  */
 public function addReview($data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("reviews") . " \n\t\t\t\t\t\t  SET author = '" . $this->db->escape($data['author']) . "',\n\t\t\t\t\t\t\t  product_id = '" . $this->db->escape($data['product_id']) . "',\n\t\t\t\t\t\t\t  text = '" . $this->db->escape(strip_tags($data['text'])) . "',\n\t\t\t\t\t\t\t  rating = '" . (int) $data['rating'] . "',\n\t\t\t\t\t\t\t  status = '" . (int) $data['status'] . "',\n\t\t\t\t\t\t\t  date_added = '" . Jdate::now() . "',\n                                                          date_modified = '" . Jdate::now() . "'");
     $this->cache->delete('product.reviews.totals');
     $this->cache->delete('product.all_info');
     return $this->db->getLastId();
 }
Example #4
0
 /**
  * @param string $message
  */
 public function write($message)
 {
     if (!$this->mode) {
         return null;
     }
     $file = $this->filename;
     $handle = fopen($file, 'a+');
     fwrite($handle, Jdate::now() . ' - ' . $message . "\n");
     fclose($handle);
 }
Example #5
0
 /**
  * @param $data
  * @return int
  */
 public function addCustomer($data)
 {
     //encrypt customer data
     $key_sql = '';
     if ($this->dcrypt->active) {
         $data = $this->dcrypt->encrypt_data($data, 'customers');
         $key_sql = ", key_id = '" . (int) $data['key_id'] . "'";
     }
     $this->db->query("INSERT INTO " . $this->db->table("customers") . "\n      \t                SET loginname = '" . $this->db->escape($data['loginname']) . "',\n      \t                \tfirstname = '" . $this->db->escape($data['firstname']) . "',\n      \t                    lastname = '" . $this->db->escape($data['lastname']) . "',\n      \t                    email = '" . $this->db->escape($data['email']) . "',\n      \t                    telephone = '" . $this->db->escape($data['telephone']) . "',\n      \t                    fax = '" . $this->db->escape($data['fax']) . "',\n      \t                    newsletter = '" . (int) $data['newsletter'] . "',\n      \t                    customer_group_id = '" . (int) $data['customer_group_id'] . "',\n      \t                    password = '******'password'])) . "',\n      \t                    status = '" . (int) $data['status'] . "',\n      \t                    approved = '" . (int) $data['approved'] . "'" . $key_sql . ",\n      \t                    date_added = '" . Jdate::now() . "',\n                            date_modified = '" . Jdate::now() . "'");
     return $this->db->getLastId();
 }
Example #6
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 = '" . Jdate::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;
 }
Example #7
0
 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 = '" . Jdate::now() . "',\n                                                      date_modified = '" . Jdate::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->delete('product.rating.' . (int) $product_id);
     $this->cache->delete('product.reviews.totals');
     $this->cache->delete('product.reviews.totals.' . $product_id);
     return '';
 }
Example #8
0
 /**
  * @param int $location_id
  * @param array $data
  * @return int
  */
 public function addLocationZone($location_id, $data)
 {
     $zones = !is_array($data['zone_id']) ? array((int) $data['zone_id']) : $data['zone_id'];
     if (!$zones || !$location_id) {
         return null;
     }
     $sql = "INSERT INTO " . $this->db->table("zones_to_locations") . " (`country_id`, `zone_id`, `location_id`, `date_added`) VALUES ";
     foreach ($zones as $zone_id) {
         $temp[] = "('" . (int) $data['country_id'] . "',\n\t\t\t\t\t'" . (int) $zone_id . "',\n\t\t\t\t\t'" . (int) $location_id . "',\n\t\t\t\t\t'" . Jdate::now() . "')";
     }
     $sql .= implode(", \n", $temp) . ';';
     $this->db->query($sql);
     $this->cache->delete('location');
     $this->cache->delete('zone.location.' . (int) $location_id);
     return $this->db->getLastId();
 }
Example #9
0
 /**
  * @param array $data
  * @return int
  */
 public function addDownload($data)
 {
     if ($data['activate'] != 'order_status') {
         $data['activate_order_status_id'] = 0;
     }
     if ($data['activate'] == 'before_order') {
         $data['expire_days'] = 0;
         $data['max_downloads'] = 0;
     }
     $this->db->query("INSERT INTO " . $this->db->table('downloads') . "\n        \t              SET filename  = '" . $this->db->escape($data['filename']) . "',\n        \t                  mask = '" . $this->db->escape($data['mask']) . "',\n      \t                  \t  max_downloads = " . ((int) $data['max_downloads'] ? "'" . (int) $data['max_downloads'] . "'" : 'NULL') . ",\n      \t                  \t  " . (isset($data['shared']) ? "shared = " . (int) $data['shared'] . ", " : '') . "\n      \t                  \t  expire_days = " . ((int) $data['expire_days'] ? "'" . (int) $data['expire_days'] . "'" : 'NULL') . ",\n      \t                  \t  sort_order = '" . (int) $data['sort_order'] . "',\n      \t                  \t  activate = '" . $this->db->escape($data['activate']) . "',\n      \t                  \t  activate_order_status_id = '" . (int) $data['activate_order_status_id'] . "',\n      \t                  \t  status = '" . (int) $data['status'] . "',\n      \t                  \t  date_added = '" . Jdate::now() . "'");
     $download_id = $this->db->getLastId();
     $this->language->replaceDescriptions('download_descriptions', array('download_id' => (int) $download_id), array($this->language->getContentLanguageID() => array('name' => $data['name'])));
     $this->addDownloadAttributeValues($download_id, $data['attributes'][0]);
     // assign download to product
     if (isset($data['product_id'])) {
         $this->mapDownload($download_id, $data['product_id']);
     }
     return $download_id;
 }
Example #10
0
 /**
  * @param array $data
  */
 public function addOrder($data)
 {
     //encrypt order data
     $key_sql = '';
     if ($this->dcrypt->active) {
         $data = $this->dcrypt->encrypt_data($data, 'orders');
         $key_sql = ", key_id = '" . (int) $data['key_id'] . "'";
     }
     $this->db->query("INSERT INTO `" . $this->db->table("orders") . "`\n\t\t\t\t\t\t\tSET store_name = '" . $this->db->escape($data['store_name']) . "',\n\t\t\t\t\t\t\t\tstore_url = '" . $this->db->escape($data['store_url']) . "',\n\t\t\t\t\t\t\t\tfirstname = '" . $this->db->escape($data['firstname']) . "',\n\t\t\t\t\t\t\t\tlastname = '" . $this->db->escape($data['lastname']) . "',\n\t\t\t\t\t\t\t\ttelephone = '" . $this->db->escape($data['telephone']) . "',\n\t\t\t\t\t\t\t\temail = '" . $this->db->escape($data['email']) . "',\n\t\t\t\t\t\t\t\tshipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "',\n\t\t\t\t\t\t\t\tshipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "',\n\t\t\t\t\t\t\t\tshipping_company = '" . $this->db->escape($data['shipping_company']) . "',\n\t\t\t\t\t\t\t\tshipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "',\n\t\t\t\t\t\t\t\tshipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "',\n\t\t\t\t\t\t\t\tshipping_city = '" . $this->db->escape($data['shipping_city']) . "',\n\t\t\t\t\t\t\t\tshipping_zone = '" . $this->db->escape($data['shipping_zone']) . "',\n\t\t\t\t\t\t\t\tshipping_zone_id = '" . (int) $data['shipping_zone_id'] . "',\n\t\t\t\t\t\t\t\tshipping_country = '" . $this->db->escape($data['shipping_country']) . "',\n\t\t\t\t\t\t\t\tshipping_country_id = '" . (int) $data['shipping_country_id'] . "',\n\t\t\t\t\t\t\t\tpayment_firstname = '" . $this->db->escape($data['payment_firstname']) . "',\n\t\t\t\t\t\t\t\tpayment_lastname = '" . $this->db->escape($data['payment_lastname']) . "',\n\t\t\t\t\t\t\t\tpayment_company = '" . $this->db->escape($data['payment_company']) . "',\n\t\t\t\t\t\t\t\tpayment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "',\n\t\t\t\t\t\t\t\tpayment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "',\n\t\t\t\t\t\t\t\tpayment_city = '" . $this->db->escape($data['payment_city']) . "',\n\t\t\t\t\t\t\t\tpayment_postcode = '" . $this->db->escape($data['payment_postcode']) . "',\n\t\t\t\t\t\t\t\tpayment_zone = '" . $this->db->escape($data['payment_zone']) . "',\n\t\t\t\t\t\t\t\tpayment_zone_id = '" . (int) $data['payment_zone_id'] . "',\n\t\t\t\t\t\t\t\tpayment_country = '" . $this->db->escape($data['payment_country']) . "',\n\t\t\t\t\t\t\t\tpayment_country_id = '" . (int) $data['payment_country_id'] . "',\n\t\t\t\t\t\t\t\tip = '" . $this->db->escape('0.0.0.0') . "',\n\t\t\t\t\t\t\t\ttotal = '" . $this->db->escape(preformatFloat($data['total'], $this->language->get('decimal_point'))) . "'" . $key_sql . ",\n\t\t\t\t\t\t\t\tdate_modified ='" . Jdate::now() . "'");
     $order_id = $this->db->getLastId();
     if (isset($data['product'])) {
         foreach ($data['product'] as $product) {
             if ($product['product_id']) {
                 $product_query = $this->db->query("SELECT *, p.product_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("products") . " p\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->db->table("product_descriptions") . " pd ON (p.product_id = pd.product_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE p.product_id='" . (int) $product['product_id'] . "'");
                 $this->db->query("INSERT INTO " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\tSET order_id = '" . (int) $order_id . "',\n\t\t\t\t\t\t\t\t\t\tproduct_id = '" . (int) $product['product_id'] . "',\n\t\t\t\t\t\t\t\t\t\tname = '" . $this->db->escape($product_query->row['name']) . "',\n\t\t\t\t\t\t\t\t\t\tmodel = '" . $this->db->escape($product_query->row['model']) . "',\n\t\t\t\t\t\t\t\t\t\tprice = '" . $this->db->escape(preformatFloat($product['price'], $this->language->get('decimal_point'))) . "',\n\t\t\t\t\t\t\t\t\t\ttotal = '" . $this->db->escape(preformatFloat($product['total'], $this->language->get('decimal_point'))) . "',\n\t\t\t\t\t\t\t\t\t\tquantity = '" . $this->db->escape($product['quantity']) . "'");
             }
         }
     }
 }
Example #11
0
 public function RunSQL($data)
 {
     $db = new ADB($data['db_driver'], $data['db_host'], $data['db_user'], $data['db_password'], $data['db_name']);
     $file = DIR_APP_SECTION . 'abantecart_database.sql';
     if ($sql = file($file)) {
         $query = '';
         foreach ($sql as $line) {
             $tsl = trim($line);
             if ($sql != '' && substr($tsl, 0, 2) != "--" && substr($tsl, 0, 1) != '#') {
                 $query .= $line;
                 if (preg_match('/;\\s*$/', $line)) {
                     $query = str_replace("DROP TABLE IF EXISTS `ac_", "DROP TABLE IF EXISTS `" . $data['db_prefix'], $query);
                     $query = str_replace("CREATE TABLE `ac_", "CREATE TABLE `" . $data['db_prefix'], $query);
                     $query = str_replace("INSERT INTO `ac_", "INSERT INTO `" . $data['db_prefix'], $query);
                     $query = str_replace("ON `ac_", "ON `" . $data['db_prefix'], $query);
                     $db->query($query);
                     //no silence mode! if error - will throw to exception
                     $query = '';
                 }
             }
         }
         $db->query("SET CHARACTER SET utf8;");
         $db->query("SET @@session.sql_mode = 'MYSQL40';");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "users`\n\t\t\t\tSET user_id = '1',\n\t\t\t\t\tuser_group_id = '1',\n\t\t\t\t\temail = '" . $db->escape($data['email']) . "',\n\t\t\t\t    username = '******'username']) . "',\n\t\t\t\t    password = '******'password'])) . "',\n\t\t\t\t    status = '1',\n\t\t\t\t    date_added = '" . Jdate::now() . "';");
         $db->query("UPDATE `" . $data['db_prefix'] . "settings` SET value = '" . $db->escape($data['email']) . "' WHERE `key` = 'store_main_email'; ");
         $db->query("UPDATE `" . $data['db_prefix'] . "settings` SET value = '" . $db->escape(HTTP_ABANTECART) . "' WHERE `key` = 'config_url'; ");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "settings` SET `group` = 'config', `key` = 'install_date', value = '" . Jdate::now() . "'; ");
         $db->query("UPDATE `" . $data['db_prefix'] . "products` SET `viewed` = '0';");
         //process triggers
         //$this->create_triggers($db, $data['db_name']);
         //run descructor and close db-connection
         unset($db);
     }
     //clear cache dir in case of reinstall
     $cache = new ACache();
     $cache->delete('*');
 }
Example #12
0
 static function createFromFormatYmd($string_date)
 {
     if ($string_date) {
         $configJ = JComponentHelper::getParams('com_bookpro');
         $php_format = $configJ->get('date_day_short', 'Y-m-d');
         $date = Jdate::createFromFormat($php_format, $string_date);
         if ($date) {
             return $date->format('Y-m-d');
         }
     }
     return '';
 }
Example #13
0
 public function getCouponsReport($data = array(), $mode = 'default')
 {
     $filter = isset($data['filter']) ? $data['filter'] : array();
     $total_sql = '';
     if ($mode == 'total_only') {
         $total_sql = "COUNT(DISTINCT o.coupon_id) AS total ";
     } else {
         //condition if coupon is deleted
         $total_sql = "\tIF(cd.name IS NULL OR cd.name = '', ot.title, cd.name) as coupon_name,\n\t\t\t\t\t\t\tc.code, \n\t\t\t\t\t\t\tCOUNT(DISTINCT o.order_id), \n\t\t\t\t\t\t\tSUM(o.total) AS total, \n\t\t\t\t\t\t\tSUM(ot.value) AS discount_total,  \n\t\t\t\t\t\t\tCOUNT(o.order_id) AS orders ";
     }
     $sql = "SELECT {$total_sql} FROM `" . $this->db->table("orders") . "` o \n\t\t\t\t\tLEFT JOIN `" . $this->db->table("coupons") . "` c ON (o.coupon_id = c.coupon_id) \n\t\t\t\t\tLEFT JOIN `" . $this->db->table("coupon_descriptions") . "` cd ON (c.coupon_id = cd.coupon_id) \n\t\t\t\t\tLEFT JOIN `" . $this->db->table("order_totals") . "` ot ON (o.order_id = ot.order_id) \n\t\t\t\t\tWHERE ot.type = 'discount' ";
     if (isset($filter['date_start'])) {
         $date_start = dateDisplay2ISO($filter['date_start'], $this->language->get('date_format_short'));
     } else {
         $date_start = Jdate::toJalali();
     }
     if (isset($filter['date_end'])) {
         $date_end = dateDisplay2ISO($filter['date_end'], $this->language->get('date_format_short'));
     } else {
         $date_end = Jdate::date();
     }
     $sql .= " AND (DATE_FORMAT(o.date_added,'%Y-%m-%d') >= DATE_FORMAT('" . $this->db->escape($date_start) . "','%Y-%m-%d') \n\t\t\t\t  AND DATE_FORMAT(o.date_added,'%Y-%m-%d') <= DATE_FORMAT('" . $this->db->escape($date_end) . "','%Y-%m-%d') )";
     //If for total, we done bulding the query
     if ($mode == 'total_only') {
         $query = $this->db->query($sql);
         return $query->row['total'];
     }
     $sql .= " GROUP BY o.coupon_id ";
     $sort_data = array('coupon_name' => 'cd.name', 'code' => 'c.code', 'orders' => 'COUNT(o.order_id)', 'total' => 'SUM(o.total)', 'discount_total' => 'SUM(ot.value)');
     if (isset($data['sort']) && array_key_exists($data['sort'], $sort_data)) {
         $sql .= " ORDER BY " . $sort_data[$data['sort']];
     } else {
         $sql .= " ORDER BY c.coupon_id";
     }
     $sql .= " " . $this->db->escape($data['order']);
     if (isset($data['start']) || isset($data['limit'])) {
         if ($data['start'] < 0) {
             $data['start'] = 0;
         }
         if ($data['limit'] < 1) {
             $data['limit'] = 20;
         }
         $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
     }
     $query = $this->db->query($sql);
     return $query->rows;
 }
Example #14
0
 public static function makeStartpoints($data)
 {
     $gpsdata = " ['Lat', 'Lon', 'Name']";
     foreach ($data as $item) {
         $d1 = new Jdate($item->tdate);
         $a1 = '<a href="' . JRoute::_('index.php?option=com_htraininglogs&view=sessions&page=daypage&date=' . $item->tdate) . '">' . $d1->Format('Y-m-d H:i') . '</a>';
         $gpsdata = $gpsdata . ",[" . $item->lat . "," . $item->lon . "," . "'" . $a1 . '<br>' . $item->method . '<br>' . $item->location . "']";
     }
     return $gpsdata;
 }
Example #15
0
 /**
  * save notice
  *
  * @param  $title - string - message title
  * @param  $message - string - message body
  * @param  $status - message status ( N - notice, W - warning, E - error )
  * @param bool $repetition_group - sign to group repetitions of message based on same title of message
  * @void
  */
 private function _saveMessage($title, $message, $status, $repetition_group = true)
 {
     $last_message = $this->getLikeMessage($title);
     // if last message equal new - update it's repeated field
     if ($last_message['title'] == $title && $repetition_group) {
         $this->db->query("UPDATE " . $this->db->table("messages") . " SET `repeated` = `repeated` + 1, viewed='0', date_modified='" . Jdate::now() . "' WHERE msg_id = '" . $last_message['msg_id'] . "'");
     } else {
         $this->db->query("INSERT INTO " . $this->db->table("messages") . " \n\t\t\t\t\t\t    SET `title` = '" . $this->db->escape($title) . "',\n\t\t\t\t\t\t    `message` = '" . $this->db->escape($message) . "',\n\t\t\t\t\t\t    `status` = '" . $this->db->escape($status) . "',\t\t\t\t\t\t    \n\t\t\t\t\t\t    `date_added` = '" . Jdate::now() . "',\n                                                    `date_modified` = '" . Jdate::now() . "'");
     }
 }
Example #16
0
 /**
  * @param array $data
  * @return int
  */
 public function addCurrency($data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("currencies") . " \n\t\t                    (`title`,\n\t\t                     `code`,\n\t\t                     `symbol_left`,\n\t\t                     `symbol_right`,\n\t\t                     `decimal_place`,\n\t\t                     `value`,\n\t\t                     `status`,\n\t\t                     `date_modified`)\n\t\t\t\t\t\t  VALUES ('" . $this->db->escape($data['title']) . "',\n\t\t\t\t\t\t          '" . $this->db->escape($data['code']) . "',\n\t\t\t\t\t\t          '" . $this->db->escape($data['symbol_left']) . "',\n\t\t\t\t\t\t          '" . $this->db->escape($data['symbol_right']) . "',\n\t\t\t\t\t\t          '" . $this->db->escape($data['decimal_place']) . "',\n\t\t\t\t\t\t          '" . $this->db->escape($data['value']) . "',\n\t\t\t\t\t\t          '" . (int) $data['status'] . "',\n\t\t\t\t\t\t          '" . Jdate::now() . "')");
     $this->cache->delete('currency');
     return $this->db->getLastId();
 }
Example #17
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('common/home');
     $data = array();
     $data['order'] = array();
     $data['customer'] = array();
     $data['xaxis'] = array();
     $data['order']['label'] = $this->language->get('text_order');
     $data['customer']['label'] = $this->language->get('text_customer');
     if (isset($this->request->get['range'])) {
         $range = $this->request->get['range'];
     } else {
         $range = 'month';
     }
     switch ($range) {
         case 'day':
             for ($i = 0; $i < 24; $i++) {
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND (DATE(date_added) = DATE('" . Jdate::now() . "') AND HOUR(date_added) = '" . (int) $i . "') GROUP BY HOUR(date_added) ORDER BY date_added ASC");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->table("customers") . " WHERE DATE(date_added) = DATE(NOW()) AND HOUR(date_added) = '" . (int) $i . "' GROUP BY HOUR(date_added) ORDER BY date_added ASC");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('H', mktime($i, 0, 0, date('n'), date('j'), date('Y'))));
             }
             break;
         case 'week':
             $date_start = strtotime('-' . date('w') . ' days');
             for ($i = 0; $i < 7; $i++) {
                 $date = date('Y-m-d', $date_start + $i * 86400);
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND DATE(date_added) = '" . Jdate::Jalali($date) . "' GROUP BY DATE(date_added)");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("customers") . "` WHERE DATE(date_added) = '" . Jdate::Jalali($date) . "' GROUP BY DATE(date_added)");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('D', strtotime($date)));
             }
             break;
         default:
         case 'month':
             for ($i = 1; $i <= jdate::day(); $i++) {
                 $date = Jdate::year() . '-' . Jdate::month() . '-' . $i;
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND (DATE(date_added) = '" . $this->db->escape($date) . "') GROUP BY DAY(date_added)");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->table("customers") . " WHERE DATE(date_added) = '" . $this->db->escape($date) . "' GROUP BY DAY(date_added)");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('j', strtotime($date)));
             }
             break;
         case 'year':
             for ($i = 1; $i <= 12; $i++) {
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND YEAR(date_added) = '" . Jdate::year() . "' AND MONTH(date_added) = '" . $i . "' GROUP BY MONTH(date_added)");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->table("customers") . " WHERE YEAR(date_added) = '" . date('Y') . "' AND MONTH(date_added) = '" . $i . "' GROUP BY MONTH(date_added)");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('M', mktime(0, 0, 0, $i, 1, date('Y'))));
             }
             break;
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($data));
 }
Example #18
0
 /** @param array $data
  * @return int
  */
 public function addProduct($data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("products") . " \n\t\t\t\t\t\t\tSET model = '" . $this->db->escape($data['model']) . "',\n\t\t\t\t\t\t\t\tsku = '" . $this->db->escape($data['sku']) . "',\n\t\t\t\t\t\t\t\tlocation = '" . $this->db->escape($data['location']) . "',\n\t\t\t\t\t\t\t\tquantity = '" . preformatInteger($data['quantity']) . "',\n\t\t\t\t\t\t\t\tminimum = '" . preformatInteger($data['minimum']) . "',\n\t\t\t\t\t\t\t\tmaximum = '" . preformatInteger($data['maximum']) . "',\n\t\t\t\t\t\t\t\tsubtract = '" . (int) $data['subtract'] . "',\n\t\t\t\t\t\t\t\tstock_status_id = '" . (int) $data['stock_status_id'] . "',\n\t\t\t\t\t\t\t\tdate_available = '" . $this->db->escape($data['date_available']) . "',\n\t\t\t\t\t\t\t\tmanufacturer_id = '" . (int) $data['manufacturer_id'] . "',\n\t\t\t\t\t\t\t\tshipping = '" . (int) $data['shipping'] . "',\n\t\t\t\t\t\t\t\tship_individually = '" . (int) $data['ship_individually'] . "',\n\t\t\t\t\t\t\t\tfree_shipping = '" . (int) $data['free_shipping'] . "',\n\t\t\t\t\t\t\t\tshipping_price = '" . preformatFloat($data['shipping_price'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\tprice = '" . preformatFloat($data['price'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\tcost = '" . preformatFloat($data['cost'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\tweight = '" . preformatFloat($data['weight'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\tweight_class_id = '" . (int) $data['weight_class_id'] . "',\n\t\t\t\t\t\t\t\tlength = '" . preformatFloat($data['length'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\twidth = '" . preformatFloat($data['width'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\theight = '" . preformatFloat($data['height'], $this->language->get('decimal_point')) . "',\n\t\t\t\t\t\t\t\tlength_class_id = '" . (int) $data['length_class_id'] . "',\n\t\t\t\t\t\t\t\tstatus = '" . (int) $data['status'] . "',\n\t\t\t\t\t\t\t\ttax_class_id = '" . (int) $data['tax_class_id'] . "',\n\t\t\t\t\t\t\t\tsort_order = '" . (int) $data['sort_order'] . "',\n\t\t\t\t\t\t\t\tdate_added = '" . Jdate::now() . "'");
     $product_id = $this->db->getLastId();
     // if new product
     if (!is_int(key($data['product_description']))) {
         $update = array();
         foreach ($data['product_description'] as $field => $value) {
             $update[(int) $this->language->getContentLanguageID()][$field] = $value;
         }
         $this->language->replaceDescriptions('product_descriptions', array('product_id' => (int) $product_id), $update);
     } else {
         // if cloning
         foreach ($data['product_description'] as $language_id => $value) {
             $this->db->query("INSERT INTO " . $this->db->table("product_descriptions") . " \n\t\t\t\t\t\t\t\tSET product_id = '" . (int) $product_id . "',\n\t\t\t\t\t\t\t\t\tlanguage_id = '" . (int) $language_id . "',\n\t\t\t\t\t\t\t\t\tname = '" . $this->db->escape($value['name']) . "',\n\t\t\t\t\t\t\t\t\tmeta_keywords = '" . $this->db->escape($value['meta_keywords']) . "',\n\t\t\t\t\t\t\t\t\tmeta_description = '" . $this->db->escape($value['meta_description']) . "',\n\t\t\t\t\t\t\t\t\tdescription = '" . $this->db->escape($value['description']) . "',\n\t\t\t\t\t\t\t\t\tblurb = '" . $this->db->escape($value['blurb']) . "'");
         }
         reset($data['product_description']);
     }
     if ($data['featured']) {
         $this->setFeatured($product_id, true);
     }
     if ($data['keyword']) {
         $seo_key = SEOEncode($data['keyword'], 'product_id', $product_id);
     } else {
         //Default behavior to save SEO URL keword from product name in default language
         if (!is_int(key($data['product_description']))) {
             // when creates
             $seo_key = SEOEncode($data['product_description']['name'], 'product_id', $product_id);
         } else {
             // when clones
             $seo_key = SEOEncode($data['product_description'][$this->language->getDefaultLanguageID()]['name'], 'product_id', $product_id);
         }
     }
     if ($seo_key) {
         $this->language->replaceDescriptions('url_aliases', array('query' => "product_id=" . (int) $product_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $seo_key)));
     } else {
         $this->db->query("DELETE\n\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\tWHERE query = 'product_id=" . (int) $product_id . "'\n\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
     }
     if ($data['product_tags']) {
         if (is_string($data['product_tags'])) {
             $tags = (array) explode(',', $data['product_tags']);
         } elseif (is_array($data['product_tags'])) {
             $tags = $data['product_tags'];
         } else {
             $tags = (array) $data['product_tags'];
         }
         foreach ($tags as &$tag) {
             $tag = trim($tag);
         }
         unset($tag);
         $tags = array_unique($tags);
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if ($tag) {
                 $this->language->addDescriptions('product_tags', array('product_id' => (int) $product_id, 'tag' => $this->db->escape($tag)), array((int) $this->language->getContentLanguageID() => array('tag' => $tag)));
             }
         }
     }
     $this->cache->delete('product');
     return $product_id;
 }
Example #19
0
 public static function getDate($str = 'Now', $off = 0)
 {
     $config = CFactory::getConfig();
     $mainframe = JFactory::getApplication();
     $my = CFactory::getUser();
     $cMy = CFactory::getUser();
     $extraOffset = $config->get('daylightsavingoffset');
     $date = new Jdate($str);
     $systemOffset = new JDate('now', $mainframe->getCfg('offset'));
     $systemOffset = $systemOffset->getOffsetFromGMT(true);
     if (!$my->id) {
         $date->setTimezone(new DateTimeZone(self::getTimezone($systemOffset + $extraOffset)));
     } else {
         if (!empty($my->params)) {
             $pos = JString::strpos($my->params, 'timezone');
             $offset = $systemOffset + $extraOffset;
             if ($pos === false) {
                 $offset = $systemOffset + $extraOffset;
             } else {
                 $offset = $my->getParam('timezone', -100);
                 $myParams = $cMy->getParams();
                 $myDTS = $myParams->get('daylightsavingoffset');
                 $cOffset = !empty($myDTS) ? $myDTS : $config->get('daylightsavingoffset');
                 if ($offset == -100) {
                     $offset = $systemOffset + $extraOffset;
                 } else {
                     $offset = $offset + $cOffset;
                 }
             }
             $date->setTimezone(new DateTimeZone(self::getTimezone($offset)));
         } else {
             $date->setTimezone(new DateTimeZone(self::getTimezone($systemOffset + $extraOffset)));
         }
     }
     return $date;
 }
Example #20
0
 public function addUser($data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("users") . " \n\t\t\t\t\t\t  SET username = '******'username']) . "',\n\t\t\t\t\t\t      password = '******'password'])) . "',\n\t\t\t\t\t\t      firstname = '" . $this->db->escape($data['firstname']) . "',\n\t\t\t\t\t\t      lastname = '" . $this->db->escape($data['lastname']) . "',\n\t\t\t\t\t\t      email = '" . $this->db->escape($data['email']) . "',\n\t\t\t\t\t\t      user_group_id = '" . (int) $data['user_group_id'] . "',\n\t\t\t\t\t\t      status = '" . (int) $data['status'] . "',\n\t\t\t\t\t\t      date_added = '" . Jdate::now() . "'");
     return $this->db->getLastId();
 }