예제 #1
0
 function getTerm($code)
 {
     CI::db()->select('term');
     $result = CI::db()->get_where('search', array('code' => $code));
     $result = $result->row();
     return $result->term;
 }
예제 #2
0
 function getVideos($criteria = false)
 {
     $table = TABLE_PREFIX . 'masterdebate_videos';
     $q = " SELECT * FROM {$table} order by id DESC ";
     //print $q ;
     $query = CI::db()->query($q);
     $query = $query->result_array();
     return $query;
 }
예제 #3
0
 public function delete($direction = false, $id = false)
 {
     if ($id) {
         \CI::db()->delete($this->_db_table[$direction], array('id' => $id));
     } else {
         //if they do not provide an id send them to the product list page with an error
         \CI::session()->set_flashdata('error', lang('error_not_found'));
     }
     redirect('admin/materials/' . $direction);
 }
예제 #4
0
파일: Tax.php 프로젝트: haouach/GoCart3
 public function getAreaTaxRate()
 {
     $rate = CI::db()->where(array('code' => $this->address['zip'], 'zone_id' => $this->address['zone_id']))->get('country_zone_areas')->row();
     if ($rate) {
         $rate = $rate->tax / 100;
     } else {
         $rate = 0;
     }
     return $rate;
 }
예제 #5
0
 function checkUserPassById($id, $pass)
 {
     global $cms_db_tables;
     $table = $cms_db_tables['table_users'];
     $q = " select count(*) as qty from {$table} where password like '%{$pass}%' and id='{$id}' ";
     $q = CI::db()->query($q);
     $q = $q->row_array();
     $q = intval($q['qty']);
     if ($q == 0) {
         return false;
     } else {
         return true;
     }
 }
예제 #6
0
 function login()
 {
     $back_to = CI::model('core')->getParamFromURL('back_to');
     global $cms_db_tables;
     $table = $cms_db_tables['table_users'];
     $username = $this->input->post('username', TRUE);
     $password = $this->input->post('password', TRUE);
     $user_action = $this->input->post('user_action', TRUE);
     if ($user_action == 'register') {
         $q = "select username from " . $table . " where username='******' ";
         $query = CI::db()->query($q);
         $query = $query->row_array();
         $query = array_values($query);
         $username = $query[0];
         if ($username != '') {
             $this->template['message'] = 'This user exists, try another one!';
         } else {
             $data = array('updated_on' => date("Y-m-d h:i:s"), 'is_active' => 0, 'username' => $username, 'password' => $password);
             $this->db->insert($table, $data);
             $this->template['message'] = 'Success, try login now!';
         }
     } else {
         $q = "select * from " . $table . " where username='******' and password='******' and is_active=1";
         $query = CI::db()->query($q);
         $query = $query->row_array();
         if (empty($query)) {
             $this->template['message'] = 'Wrong username or password, or user is disabled!';
         } else {
             CI::library('session')->set_userdata('user', $query);
             if ($back_to == false) {
                 redirect('dashboard');
             } else {
                 redirect(base64_decode($back_to));
             }
         }
     }
     $this->load->vars($this->template);
     $layout = CI::view('layout', true, true);
     $primarycontent = '';
     $secondarycontent = '';
     $primarycontent = CI::view('login', true, true);
     $layout = str_ireplace('{primarycontent}', $primarycontent, $layout);
     $layout = str_ireplace('{secondarycontent}', $secondarycontent, $layout);
     //CI::view('welcome_message');
     //CI::library('output')->set_output ( $layout );
 }
예제 #7
0
 public function sendNotification($gc_data)
 {
     CI::load()->helper('formatting_helper');
     $row = CI::db()->where('id', '1')->get('canned_messages')->row_array();
     // set replacement values for subject & body
     $row['subject'] = str_replace('{from}', $gc_data['from'], $row['subject']);
     $row['subject'] = str_replace('{site_name}', config_item('company_name'), $row['subject']);
     $row['content'] = str_replace('{code}', $gc_data['code'], $row['content']);
     $row['content'] = str_replace('{amount}', format_currency($gc_data['beginning_amount']), $row['content']);
     $row['content'] = str_replace('{from}', $gc_data['from'], $row['content']);
     $row['content'] = str_replace('{personal_message}', nl2br($gc_data['personal_message']), $row['content']);
     $row['content'] = str_replace('{url}', config_item('base_url'), $row['content']);
     $row['content'] = str_replace('{site_name}', config_item('company_name'), $row['content']);
     $config['mailtype'] = 'html';
     CI::load()->library('email');
     CI::email()->initialize($config);
     CI::email()->from(config_item('email'));
     CI::email()->to($gc_data['to_email']);
     CI::email()->subject($row['subject']);
     CI::email()->message($row['content']);
     CI::email()->send();
 }
예제 #8
0
 public function download($fileId, $orderId)
 {
     //get the order.
     $order = \CI::db()->where('orders.id', $orderId)->join('customers', 'customers.id = orders.customer_id')->get('orders')->row();
     $file = \CI::db()->where('order_item_files.id', $fileId)->join('digital_products', 'digital_products.id = order_item_files.file_id')->get('order_item_files')->row();
     if ($order && $file) {
         if ($order->is_guest || $order->customer_id == $this->customer->id) {
             if ($file->max_downloads == 0 || $file->downloads_used < $file->max_downloads) {
                 \CI::DigitalProducts()->touchDownload($fileId);
                 \CI::DigitalProducts()->downloadFile($file->filename);
             }
         } else {
             //send to login page
             if (\CI::Login()->isLoggedIn(false, false)) {
                 redirect('login');
             } else {
                 throw_404();
             }
         }
     } else {
         //move along nothing to see here
         throw_404();
     }
 }
예제 #9
0
 public function get_manufacturers($option = true)
 {
     if ($option) {
         $results = CI::db()->get('manufacturers')->result();
         $tmp[] = array();
         $tmp[0] = 'Select manufacturer';
         foreach ($results as $result) {
             $tmp[$result->id] = $result->name;
         }
         return $tmp;
     } else {
         return CI::db()->get('manufacturers')->result_array();
     }
 }
예제 #10
0
 public function transaction($transaction = false)
 {
     //no transaction provided? create a new one and return it.
     if (!$transaction) {
         $order_number = str_replace('.', '-', microtime(true)) . $this->cart->id;
         $transaction = ['order_id' => $this->cart->id, 'order_number' => $order_number, 'created_at' => date('Y-m-d H:i:s')];
         \CI::db()->insert('transactions', $transaction);
         $transaction['id'] = \CI::db()->insert_id();
         return (object) $transaction;
     } else {
         //we have a transaction, update it with the response
         \CI::db()->where('id', $transaction->id)->update('transactions', (array) $transaction);
     }
 }
예제 #11
0
 public function getProductOptions($product_id)
 {
     CI::db()->where('product_id', $product_id);
     CI::db()->order_by('sequence', 'ASC');
     $result = CI::db()->get('options');
     $return = [];
     foreach ($result->result() as $option) {
         $option->values = $this->getOptionValues($option->id);
         $return[] = $option;
     }
     return $return;
 }
예제 #12
0
 /**
  * MySQL Export
  *
  * @access	private
  * @param	array	Preferences
  * @return	mixed
  */
 function _backup($params = array())
 {
     if (count($params) == 0) {
         return FALSE;
     }
     // Extract the prefs for simplicity
     extract($params);
     // Build the output
     $output = '';
     foreach ((array) $tables as $table) {
         // Is the table in the "ignore" list?
         if (in_array($table, (array) $ignore, TRUE)) {
             continue;
         }
         // Get the table schema
         $query = CI::db()->query("SHOW CREATE TABLE `" . $this->db->database . '`.' . $table);
         // No result means the table name was invalid
         if ($query === FALSE) {
             continue;
         }
         // Write out the table schema
         $output .= '#' . $newline . '# TABLE STRUCTURE FOR: ' . $table . $newline . '#' . $newline . $newline;
         if ($add_drop == TRUE) {
             $output .= 'DROP TABLE IF EXISTS ' . $table . ';' . $newline . $newline;
         }
         $i = 0;
         $result = $query->result_array();
         foreach ($result[0] as $val) {
             if ($i++ % 2) {
                 $output .= $val . ';' . $newline . $newline;
             }
         }
         // If inserts are not needed we're done...
         if ($add_insert == FALSE) {
             continue;
         }
         // Grab all the data from the current table
         $query = CI::db()->query("SELECT * FROM {$table}");
         if ($query->num_rows() == 0) {
             continue;
         }
         // Fetch the field names and determine if the field is an
         // integer type.  We use this info to decide whether to
         // surround the data with quotes or not
         $i = 0;
         $field_str = '';
         $is_int = array();
         while ($field = mysql_fetch_field($query->result_id)) {
             // Most versions of MySQL store timestamp as a string
             $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)), array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), TRUE) ? TRUE : FALSE;
             // Create a string of field names
             $field_str .= '`' . $field->name . '`, ';
             $i++;
         }
         // Trim off the end comma
         $field_str = preg_replace("/, \$/", "", $field_str);
         // Build the insert string
         foreach ($query->result_array() as $row) {
             $val_str = '';
             $i = 0;
             foreach ($row as $v) {
                 // Is the value NULL?
                 if ($v === NULL) {
                     $val_str .= 'NULL';
                 } else {
                     // Escape the data if it's not an integer
                     if ($is_int[$i] == FALSE) {
                         $val_str .= $this->db->escape($v);
                     } else {
                         $val_str .= $v;
                     }
                 }
                 // Append a comma
                 $val_str .= ', ';
                 $i++;
             }
             // Remove the comma at the end of the string
             $val_str = preg_replace("/, \$/", "", $val_str);
             // Build the INSERT string
             $output .= 'INSERT INTO ' . $table . ' (' . $field_str . ') VALUES (' . $val_str . ');' . $newline;
         }
         $output .= $newline . $newline;
     }
     return $output;
 }
예제 #13
0
 /**
  * Column Modify
  *
  * @access	public
  * @param	string	the table name
  * @param	string	the column name
  * @param	string	the column definition
  * @return	bool
  */
 function modify_column($table = '', $field = array())
 {
     if ($table == '') {
         show_error('A table name is required for that operation.');
     }
     // add field info into field array, but we can only do one at a time
     // so we cycle through
     foreach ($field as $k => $v) {
         $this->add_field(array($k => $field[$k]));
         if (count($this->fields) == 0) {
             show_error('Field information is required.');
         }
         $sql = $this->_alter_table('CHANGE', $this->db->dbprefix . $table, $this->fields);
         $this->_reset();
         if (CI::db()->query($sql) === FALSE) {
             return FALSE;
         }
     }
     return TRUE;
 }
예제 #14
0
 public function touchDownload($file_id)
 {
     CI::db()->where('id', $file_id)->set('downloads_used', 'downloads_used+1', false)->update('order_item_files');
 }
예제 #15
0
 function fakeSend()
 {
     $table = TABLE_PREFIX . 'cacaomail_mails_to_send';
     $table2 = TABLE_PREFIX . 'cacaomail_mails_to_send_log';
     $q = " select * from {$table} where id NOT IN (SELECT mail_id FROM\n        {$table2} where mail_id is not null\n         group by mail_id)  \n         \n         and for_download = 0 and is_active = 1\n         ";
     $query = CI::db()->query($q);
     $query = $query->result_array();
     var_dump($query);
     foreach ($query as $i) {
     }
     return true;
 }
예제 #16
0
파일: main.php 프로젝트: Gninety/Microweber
 function bb_sync()
 {
     CI::helper('url');
     global $cms_db_tables;
     $table = $cms_db_tables['table_taxonomy'];
     $table2 = 'bb_forums';
     $sitemaps_count = false;
     $q = "select * from {$table}  where taxonomy_type='category' and users_can_create_content='y' ";
     $q = CI::model('core')->dbQuery($q);
     $data_to_save_options['use_this_field_for_id'] = 'forum_id';
     foreach ($q as $item) {
         $skip = false;
         if (intval($item['parent_id']) == 91) {
             $skip = false;
             $item['parent_id'] = 0;
         } else {
             //
         }
         if (intval($item['id']) == 91) {
             $skip = true;
         }
         $to_save = array();
         $to_save['forum_id'] = $item['id'];
         $to_save['forum_name'] = $item['taxonomy_value'];
         $to_save['forum_slug'] = url_title($item['taxonomy_value']);
         $to_save['forum_parent'] = $item['parent_id'];
         //CI::model('core')-> saveData($table2, $to_save, $data_to_save_options);
         if ($skip == false) {
             CI::db()->query("REPLACE\n                             INTO {$table2}\n                              SET forum_id              = ?,\n                                  forum_name      = ?,\n                                  forum_slug       = ?,\n                                  forum_parent   = ?\n                                  ", array($item['id'], $item['taxonomy_value'], url_title($item['taxonomy_value']), $item['parent_id']));
         }
         p($to_save);
     }
     exit('Yes!');
 }
예제 #17
0
<?php

$table_name = false;
$table_name = TABLE_PREFIX . "users_activities";
$query = CI::db()->query("show tables like '{$table_name}'");
$query = $query->row_array();
$query = array_values($query);
if ($query[0] != $table_name) {
    $sql = "CREATE TABLE " . $table_name . " (\n\t\tid bigint(20) NOT NULL auto_increment,\n\t\tUNIQUE KEY id (id)\n\t\t);";
    CI::db()->query($sql);
}
$sql = "show tables like '{$table_name}'";
$query = CI::db()->query($sql);
$query = $query->row_array();
$query = array_values($query);
if ($query[0] == $table_name) {
    $fields_to_add = array();
    $fields_to_add[] = array('user_id', 'int(10) NOT NULL');
    $fields_to_add[] = array('message', 'TEXT NOT NULL');
    $fields_to_add[] = array('updated_on', 'datetime default NULL');
    $fields_to_add[] = array('created_on', 'datetime default NULL');
    $fields_to_add[] = array('created_by', 'int(11) default NULL');
    $fields_to_add[] = array('edited_by', 'int(11) default NULL');
    $this->set_db_tables($table_name, $fields_to_add);
}
$this->setEngine($table_name);
CI::db()->query("ALTER TABLE {$table_name} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;");
// foreign keys
$this->addForeignKey('FK_firecms_users_activities_1', $table_name, array('user_id'), TABLE_PREFIX . 'users', array('id'), $aOptions = array('delete' => 'CASCADE'));
예제 #18
0
 public function delete($id)
 {
     if ($this->checkId($id)) {
         $admin = $this->getAdmin($id);
         CI::db()->where('id', $id);
         CI::db()->limit(1);
         CI::db()->delete('admin');
         return $admin->firstname . ' ' . $admin->lastname . ' has been removed.';
     } else {
         return 'The admin could not be found.';
     }
 }
    $fields_to_add[] = array('mailsent_date', 'datetime default NULL');
    $fields_to_add[] = array('mailread_date', 'datetime default NULL');
    $fields_to_add[] = array('updated_on', 'datetime default NULL');
    //$fields_to_add[] = array( 'is_active',   'int(1) default 1');
    //$fields_to_add[] = array( 'limit_per_day',   'int(100) default NULL');
    foreach ($fields_to_add as $the_field) {
        $sql = false;
        $the_field[0] = strtolower($the_field[0]);
        if ($exisiting_fields[$the_field[0]] != true) {
            $sql = "alter table {$table_name} add column {$the_field[0]} {$the_field[1]} ";
            CI::db()->query($sql);
        } else {
            $sql = "alter table {$table_name} modify {$the_field[0]} {$the_field[1]} ";
            CI::db()->query($sql);
        }
    }
}
$sql = "SHOW INDEXES FROM {$table_name} \t";
//print $sql;
$query = CI::db()->query($sql);
$query = $query->result_array();
$query = array_change_key_case($query, CASE_LOWER);
$indexes = array();
foreach ($query as $item) {
    $item = array_change_key_case($item, CASE_LOWER);
    $indexes[] = $item['key_name'];
}
if (in_array('job_email', $indexes) == false) {
    $q = "ALTER IGNORE TABLE {$table_name} ADD FULLTEXT KEY job_email (job_email)  ";
    CI::db()->query($q);
}
예제 #20
0
 public function delete_message($id)
 {
     CI::db()->where('id', $id)->delete('canned_messages');
     return $id;
 }
예제 #21
0
 public function save_group($data)
 {
     if (!empty($data['id'])) {
         CI::db()->where('id', $data['id'])->update('customer_groups', $data);
         return $data['id'];
     } else {
         CI::db()->insert('customer_groups', $data);
         $groupId = CI::db()->insert_id();
         //create the new fields.
         CI::load()->dbforge();
         $fields = ['enabled_' . $groupId => ['type' => 'TINYINT', 'constraint' => '1', 'default' => '1'], 'price_' . $groupId => ['type' => 'DECIMAL', 'constraint' => '10,2', 'default' => '0.00'], 'saleprice_' . $groupId => ['type' => 'DECIMAL', 'constraint' => '10,2', 'default' => '0.00']];
         CI::dbforge()->add_column('products', $fields);
         CI::dbforge()->add_column('order_items', $fields);
         $fields = ['enabled_' . $groupId => ['type' => 'TINYINT', 'constraint' => '1', 'default' => '1']];
         CI::dbforge()->add_column('categories', $fields);
     }
 }
예제 #22
0
파일: Orders.php 프로젝트: haouach/GoCart3
 public function getBestSellers($start, $end)
 {
     if (!empty($start)) {
         CI::db()->where('ordered_on >=', $start);
     }
     if (!empty($end)) {
         CI::db()->where('ordered_on <', $end);
     }
     // just fetch a list of order id's
     $orders = CI::db()->select('sum(quantity) as quantity_sold, order_items.name as name, sku')->group_by('product_id')->order_by('quantity_sold', 'DESC')->where('status !=', 'cart')->where('order_items.type', 'product')->join('order_items', 'order_items.order_id = orders.id')->get('orders')->result();
     return $orders;
 }
예제 #23
0
 public function index()
 {
     $redirect = \CI::Login()->isLoggedIn(false, false);
     //if they are logged in, we send them back to the my_account by default
     if ($redirect) {
         redirect('my-account');
     }
     \CI::load()->library('form_validation');
     //default values are empty if the customer is new
     $data = ['company' => '', 'firstname' => '', 'lastname' => '', 'email' => '', 'phone' => '', 'address1' => '', 'address2' => '', 'city' => '', 'state' => '', 'zip' => '', 'redirect' => \CI::session()->flashdata('redirect')];
     \CI::form_validation()->set_rules('company', 'lang:address_company', 'trim|max_length[128]');
     \CI::form_validation()->set_rules('firstname', 'lang:address_firstname', 'trim|required|max_length[32]');
     \CI::form_validation()->set_rules('lastname', 'lang:address_lastname', 'trim|required|max_length[32]');
     \CI::form_validation()->set_rules('email', 'lang:address_email', ['trim', 'required', 'valid_email', 'max_length[128]', ['check_email_callable', function ($str) {
         return $this->check_email($str);
     }]]);
     \CI::form_validation()->set_rules('phone', 'lang:address_phone', 'trim|required|max_length[32]');
     \CI::form_validation()->set_rules('email_subscribe', 'lang:account_newsletter_subscribe', 'trim|numeric|max_length[1]');
     \CI::form_validation()->set_rules('password', 'Password', 'required|min_length[6]');
     \CI::form_validation()->set_rules('confirm', 'Confirm Password', 'required|matches[password]');
     if (\CI::form_validation()->run() == FALSE) {
         //if they have submitted the form already and it has returned with errors, reset the redirect
         if (\CI::input()->post('submitted')) {
             $data['redirect'] = \CI::input()->post('redirect');
         }
         // load other page content
         //\CI::load()->model('banner_model');
         \CI::load()->helper('directory');
         $this->view('register', $data);
     } else {
         $save['id'] = false;
         $save['firstname'] = \CI::input()->post('firstname');
         $save['lastname'] = \CI::input()->post('lastname');
         $save['email'] = \CI::input()->post('email');
         $save['phone'] = \CI::input()->post('phone');
         $save['company'] = \CI::input()->post('company');
         $save['active'] = config_item('new_customer_status');
         $save['email_subscribe'] = intval((bool) \CI::input()->post('email_subscribe'));
         $save['password'] = \CI::input()->post('password');
         $redirect = \CI::input()->post('redirect');
         //if we don't have a value for redirect
         if ($redirect == '') {
             $redirect = 'my-account';
         }
         // save the customer info and get their new id
         $id = \CI::Customers()->save($save);
         /* send an email */
         // get the email template
         $row = \CI::db()->where('id', '6')->get('canned_messages')->row_array();
         // set replacement values for subject & body
         // {customer_name}
         $row['subject'] = str_replace('{customer_name}', \CI::input()->post('firstname') . ' ' . \CI::input()->post('lastname'), $row['subject']);
         $row['content'] = str_replace('{customer_name}', \CI::input()->post('firstname') . ' ' . \CI::input()->post('lastname'), $row['content']);
         // {url}
         $row['subject'] = str_replace('{url}', config_item('base_url'), $row['subject']);
         $row['content'] = str_replace('{url}', config_item('base_url'), $row['content']);
         // {site_name}
         $row['subject'] = str_replace('{site_name}', config_item('company_name'), $row['subject']);
         $row['content'] = str_replace('{site_name}', config_item('company_name'), $row['content']);
         \CI::load()->library('email');
         $config['mailtype'] = 'html';
         \CI::email()->initialize($config);
         \CI::email()->from(config_item('email'), config_item('company_name'));
         \CI::email()->to($save['email']);
         \CI::email()->bcc(config_item('email'));
         \CI::email()->subject($row['subject']);
         \CI::email()->message(html_entity_decode($row['content']));
         \CI::email()->send();
         \CI::session()->set_flashdata('message', sprintf(lang('registration_thanks'), \CI::input()->post('firstname')));
         //lets automatically log them in
         \CI::Login()->loginCustomer($save['email'], \CI::input()->post('confirm'));
         //we're just going to make this secure regardless, because we don't know if they are
         //wanting to redirect to an insecure location, if it needs to be secured then we can use the secure redirect in the controller
         //to redirect them, if there is no redirect, the it should redirect to the homepage.
         redirect($redirect);
     }
 }
예제 #24
0
 function input_data_from_link($type = 0, $active = false)
 {
     \CI::load()->helper('simple_html_dom');
     set_time_limit(1800);
     if ($type == 0) {
         $csv_data = array_map('str_getcsv', file($_SERVER['DOCUMENT_ROOT'] . '/perkins-data.csv'));
         $product_list = array();
         foreach ($csv_data as $key => $product) {
             if ($key == 0 || $key == 1 || $product[0] == '' || $product[2] == '') {
                 continue;
             }
             $index = $key - 2;
             $product_list[$index]['active'] = $product[1];
             $product_list[$index]['product']['name'] = $product[2];
             $product_list[$index]['product']['slug'] = strtolower(str_replace(' ', '-', $product[2]));
             $product_list[$index]['product']['note'] = $product[18];
             $product_list[$index]['product']['ref_link'] = $product[19];
             $product_list[$index]['product']['document_link'] = $product[20];
             $product_list[$index]['product']['document_link_2'] = $product[21];
             $product_list[$index]['product']['price_1'] = $product[22];
             $product_list[$index]['engine']['standby'] = $product[3];
             $product_list[$index]['engine']['prime'] = $product[4];
             $product_list[$index]['engine']['rpm'] = $product[9] > 0 ? $product[9] : 1500;
             $product_list[$index]['engine']['standby_2'] = $product[10];
             $product_list[$index]['engine']['prime_2'] = $product[11];
             $product_list[$index]['engine']['rpm_2'] = $product[16] > 0 ? $product[16] : 1800;
             $product_list[$index]['fuel'][50]['hz'] = 50;
             $product_list[$index]['fuel'][50]['standby_fuel_con_1'] = $product[5];
             $product_list[$index]['fuel'][50]['prime_fuel_con_1'] = $product[6];
             $product_list[$index]['fuel'][50]['prime_fuel_con_2'] = $product[7];
             $product_list[$index]['fuel'][50]['prime_fuel_con_3'] = $product[8];
             $product_list[$index]['fuel'][50]['unit'] = $product[17] != '' ? 1 : 0;
             $product_list[$index]['fuel'][60]['hz'] = 60;
             $product_list[$index]['fuel'][60]['standby_fuel_con_1'] = $product[12];
             $product_list[$index]['fuel'][60]['prime_fuel_con_1'] = $product[13];
             $product_list[$index]['fuel'][60]['prime_fuel_con_2'] = $product[14];
             $product_list[$index]['fuel'][60]['prime_fuel_con_3'] = $product[15];
             $product_list[$index]['fuel'][60]['unit'] = $product[17] != '' ? 1 : 0;
             //$ref_link = 0;
             $ref_link = $product[19];
             if (!isset($get_data[$ref_link])) {
                 //if ($ref_link > 0) {
                 $data = array();
                 // Create DOM from URL or file
                 $html = file_get_html($ref_link);
                 $modelTitle = $html->find('div.modelTitle');
                 foreach ($modelTitle as $element) {
                     $title = trim($element->plaintext);
                     break;
                 }
                 $img = $html->find('ul#carousel-photos a img');
                 foreach ($img as $element) {
                     $link_img = $element->src;
                     break;
                 }
                 //echo $title;continue;
                 if ($active == false) {
                     $images = $this->save_image($title, $link_img);
                 }
                 foreach ($html->find('.specifications tbody tr') as $key2 => $element) {
                     $tmp = $element->childNodes(1);
                     $label = trim($element->childNodes(0)->plaintext);
                     //echo $label.'<br/>';
                     $value = trim($tmp->find('.unit-metric')[0]->plaintext);
                     if ($label == 'Bore') {
                         $tmp_data['bore'] = $value;
                     }
                     if ($label == 'Stroke') {
                         $tmp_data['stroke'] = $value;
                     }
                     if ($label == 'Displacement') {
                         $tmp_data['displacement'] = $value;
                     }
                     if ($label == 'Cycle') {
                         $tmp_data['cylinders'] = $value;
                     }
                     if ($label == 'Compression ratio') {
                         $tmp_data['compression_ratio'] = $value;
                     }
                     if ($label == 'Cooling system') {
                         $tmp_data['cooling_system'] = $value;
                     }
                     if ($label == 'Emissions') {
                         $tmp_data['emissions'] = $value;
                     }
                     if ($label == 'Length') {
                         $tmp_data['length'] = $value;
                     }
                     if ($label == 'Width') {
                         $tmp_data['width'] = $value;
                     }
                     if ($label == 'Height') {
                         $tmp_data['height'] = $value;
                     }
                     if ($label == 'Dry weight') {
                         $tmp_data['weight'] = $value;
                     }
                 }
                 $tmp_data['dimensions'] = str_replace('.0 mm', '', $tmp_data['length']) . 'x' . str_replace('.0 mm', '', $tmp_data['width']) . 'x' . str_replace('.0 mm', '', $tmp_data['height']);
                 $tmp_data['weight'] = str_replace(' kg', '', $tmp_data['weight']);
                 if ($active == false) {
                     $product_list[$index]['product']['images'] = $get_data[$ref_link]['images'] = $images ? $images : '';
                 }
                 $product_list[$index]['product']['dimensions'] = $get_data[$ref_link]['dimensions'] = $tmp_data['dimensions'] ? $tmp_data['dimensions'] : 0;
                 $product_list[$index]['product']['weight'] = $get_data[$ref_link]['weight'] = $tmp_data['weight'] ? $tmp_data['weight'] : 0;
                 $product_list[$index]['engine']['bore'] = $get_data[$ref_link]['bore'] = $tmp_data['bore'] ? $tmp_data['bore'] : 0;
                 $product_list[$index]['engine']['stroke'] = $get_data[$ref_link]['stroke'] = $tmp_data['stroke'] ? $tmp_data['stroke'] : 0;
                 $product_list[$index]['engine']['displacement'] = $get_data[$ref_link]['displacement'] = $tmp_data['displacement'] ? $tmp_data['displacement'] : 0;
                 $product_list[$index]['engine']['cylinders_number'] = $get_data[$ref_link]['cylinders_number'] = $tmp_data['cylinders'] ? $tmp_data['cylinders'] : 0;
                 $product_list[$index]['engine']['compression_ratio'] = $get_data[$ref_link]['compression_ratio'] = $tmp_data['compression_ratio'] ? $tmp_data['compression_ratio'] : 0;
                 $product_list[$index]['engine']['type_cooled'] = $get_data[$ref_link]['type_cooled'] = $tmp_data['cooling_system'] ? $tmp_data['cooling_system'] : 0;
                 $product_list[$index]['engine']['emissions'] = $get_data[$ref_link]['emissions'] = $tmp_data['emissions'] ? $tmp_data['emissions'] : 0;
             } else {
                 if ($active == false) {
                     $product_list[$index]['product']['images'] = $get_data[$ref_link]['images'];
                 }
                 $product_list[$index]['product']['dimensions'] = $get_data[$ref_link]['dimensions'];
                 $product_list[$index]['product']['weight'] = $get_data[$ref_link]['weight'];
                 $product_list[$index]['engine']['bore'] = $get_data[$ref_link]['bore'];
                 $product_list[$index]['engine']['stroke'] = $get_data[$ref_link]['stroke'];
                 $product_list[$index]['engine']['displacement'] = $get_data[$ref_link]['displacement'];
                 $product_list[$index]['engine']['cylinders_number'] = $get_data[$ref_link]['cylinders_number'];
                 $product_list[$index]['engine']['compression_ratio'] = $get_data[$ref_link]['compression_ratio'];
                 $product_list[$index]['engine']['type_cooled'] = $get_data[$ref_link]['type_cooled'];
                 $product_list[$index]['engine']['emissions'] = $get_data[$ref_link]['emissions'];
             }
             //break;
         }
         //pr($product_list);exit;
         foreach ($product_list as $product) {
             $product['product']['primary_category'] = 1;
             $product['product']['enabled_1'] = 1;
             $product['product']['manufacturers'] = 3;
             if ($active == false) {
                 \CI::db()->insert('products', $product['product']);
                 $product_id = \CI::db()->insert_id();
                 \CI::db()->insert('category_products', array('product_id' => $product_id, 'category_id' => 1));
                 $product['engine']['product_id'] = $product_id;
                 \CI::db()->insert('engines', $product['engine']);
                 $product['fuel'][50]['product_id'] = $product_id;
                 \CI::db()->insert('fuel_consumptions', $product['fuel'][50]);
                 $product['fuel'][60]['product_id'] = $product_id;
                 \CI::db()->insert('fuel_consumptions', $product['fuel'][60]);
             } else {
                 $query = \CI::db()->where('slug', $product['product']['slug'])->get('products');
                 if ($query->num_rows() > 0) {
                     $result = $query->row_array();
                     $product_id = $result['id'];
                     \CI::db()->where('id', $product_id);
                     \CI::db()->update('products', $product['product']);
                     \CI::db()->where('product_id', $product_id);
                     \CI::db()->update('engines', $product['engine']);
                     \CI::db()->where('product_id', $product_id)->where('hz', 50);
                     \CI::db()->insert('fuel_consumptions', $product['fuel'][50]);
                     \CI::db()->where('product_id', $product_id)->where('hz', 60);
                     \CI::db()->insert('fuel_consumptions', $product['fuel'][60]);
                 } else {
                     \CI::db()->insert('products', $product['product']);
                     $product_id = \CI::db()->insert_id();
                     \CI::db()->insert('category_products', array('product_id' => $product_id, 'category_id' => 1));
                     $product['engine']['product_id'] = $product_id;
                     \CI::db()->insert('engines', $product['engine']);
                     $product['fuel'][50]['product_id'] = $product_id;
                     \CI::db()->insert('fuel_consumptions', $product['fuel'][50]);
                     $product['fuel'][60]['product_id'] = $product_id;
                     \CI::db()->insert('fuel_consumptions', $product['fuel'][60]);
                 }
             }
         }
     }
     // input database control
     if ($type == 1) {
         $csv_data = array_map('str_getcsv', file($_SERVER['DOCUMENT_ROOT'] . '/leroy-somer-data.csv'));
         $product_list = array();
         foreach ($csv_data as $key => $product) {
             if ($key == 0 || $key == 1 || $product[0] == '' || $product[2] == '') {
                 continue;
             }
             $index = $key - 2;
             $product_list[$index]['active'] = $product[1];
             $product_list[$index]['product']['name'] = $product[2];
             $product_list[$index]['product']['slug'] = strtolower(str_replace(' ', '-', str_replace('.', '-', $product[2])));
             $product_list[$index]['product']['group'] = $product[3];
             $product_list[$index]['product']['note'] = $product[43];
             $product_list[$index]['product']['ref_link'] = $product[44];
             $product_list[$index]['product']['document_link'] = $product[45];
             $product_list[$index]['product']['price_1'] = $product[47];
             $product_list[$index]['product']['protection_class'] = $product[40];
             $product_list[$index]['product']['weight'] = $product[42];
             $product_list[$index]['alternator'][50]['hz'] = 50;
             $product_list[$index]['alternator'][50]['power'] = $product[4];
             $product_list[$index]['alternator'][50]['power_standby'] = $product[5];
             $product_list[$index]['alternator'][50]['phase'] = 3;
             $product_list[$index]['alternator'][50]['voltage'] = $product[33];
             $product_list[$index]['alternator'][50]['pole'] = $product[34];
             $product_list[$index]['alternator'][50]['speed'] = $product[35];
             $product_list[$index]['alternator'][50]['shaft_height'] = $product[36];
             $product_list[$index]['alternator'][50]['excitation'] = $product[38];
             $product_list[$index]['alternator'][50]['max_efficiency'] = $product[37];
             $product_list[$index]['alternator'][50]['regulation'] = $product[39];
             $product_list[$index]['alternator'][50]['number_of_wires'] = $product[40];
             $product_list[$index]['alternator'][50]['about_power'] = $product[32];
             $product_list[$index]['alternator'][50]['efficiency_standby'] = $product[6];
             $product_list[$index]['alternator'][50]['efficiency'] = $product[7];
             $product_list[$index]['alternator'][50]['efficiency_2'] = $product[8];
             $product_list[$index]['alternator'][50]['efficiency_3'] = $product[9];
             //$product_list[$index]['alternator'][50]['efficiency_4'] = $product[8];
             $product_list[$index]['alternator'][50]['power_single_phase'] = $product[11];
             $product_list[$index]['alternator'][50]['power_single_phase_standby'] = $product[12];
             $product_list[$index]['alternator'][50]['efficiency_single_standby'] = $product[13];
             $product_list[$index]['alternator'][50]['efficiency_single'] = $product[14];
             $product_list[$index]['alternator'][50]['efficiency_single_2'] = $product[15];
             $product_list[$index]['alternator'][50]['efficiency_single_3'] = $product[16];
             //$product_list[$index]['alternator'][50]['efficiency_single_4'] = $product[8];
             //hz 60
             $product_list[$index]['alternator'][60]['hz'] = 60;
             $product_list[$index]['alternator'][60]['power'] = $product[18];
             $product_list[$index]['alternator'][60]['power_standby'] = $product[19];
             $product_list[$index]['alternator'][60]['phase'] = 3;
             $product_list[$index]['alternator'][60]['voltage'] = $product[33];
             $product_list[$index]['alternator'][60]['pole'] = $product[34];
             $product_list[$index]['alternator'][60]['speed'] = $product[35];
             $product_list[$index]['alternator'][60]['shaft_height'] = $product[36];
             $product_list[$index]['alternator'][60]['excitation'] = $product[38];
             $product_list[$index]['alternator'][60]['max_efficiency'] = $product[37];
             $product_list[$index]['alternator'][60]['regulation'] = $product[39];
             $product_list[$index]['alternator'][60]['number_of_wires'] = $product[40];
             $product_list[$index]['alternator'][60]['about_power'] = $product[32];
             $product_list[$index]['alternator'][60]['efficiency_standby'] = $product[20];
             $product_list[$index]['alternator'][60]['efficiency'] = $product[21];
             $product_list[$index]['alternator'][60]['efficiency_2'] = $product[22];
             $product_list[$index]['alternator'][60]['efficiency_3'] = $product[23];
             //$product_list[$index]['alternator'][60]['efficiency_4'] = $product[8];
             $product_list[$index]['alternator'][60]['power_single_phase'] = $product[25];
             $product_list[$index]['alternator'][60]['power_single_phase_standby'] = $product[26];
             $product_list[$index]['alternator'][60]['efficiency_single_standby'] = $product[27];
             $product_list[$index]['alternator'][60]['efficiency_single'] = $product[28];
             $product_list[$index]['alternator'][60]['efficiency_single_2'] = $product[29];
             $product_list[$index]['alternator'][60]['efficiency_single_3'] = $product[30];
             //$product_list[$index]['alternator'][60]['efficiency_single_4'] = $product[8];
         }
         foreach ($product_list as $product) {
             $product['product']['primary_category'] = 2;
             $product['product']['enabled_1'] = 1;
             $product['product']['manufacturers'] = 7;
             if ($active == false) {
                 \CI::db()->insert('products', $product['product']);
                 $product_id = \CI::db()->insert_id();
                 \CI::db()->insert('category_products', array('product_id' => $product_id, 'category_id' => 2));
                 $product['alternator'][50]['product_id'] = $product_id;
                 \CI::db()->insert('alternators', $product['alternator'][50]);
                 $product['alternator'][60]['product_id'] = $product_id;
                 \CI::db()->insert('alternators', $product['alternator'][60]);
             } else {
                 $query = \CI::db()->where('slug', $product['product']['slug'])->get('products');
                 if ($query->num_rows() > 0) {
                     $result = $query->row_array();
                     $product_id = $result['id'];
                     \CI::db()->where('id', $product_id);
                     \CI::db()->update('products', $product['product']);
                     \CI::db()->where('product_id', $product_id)->where('hz', 50);
                     \CI::db()->insert('alternators', $product['alternator'][50]);
                     \CI::db()->where('product_id', $product_id)->where('hz', 60);
                     \CI::db()->insert('alternators', $product['alternator'][60]);
                 } else {
                     \CI::db()->insert('products', $product['product']);
                     $product_id = \CI::db()->insert_id();
                     \CI::db()->insert('category_products', array('product_id' => $product_id, 'category_id' => 2));
                     $product['alternators'][50]['product_id'] = $product_id;
                     \CI::db()->insert('alternators', $product['alternator'][50]);
                     $product['alternators'][60]['product_id'] = $product_id;
                     \CI::db()->insert('alternators', $product['alternator'][60]);
                 }
             }
         }
     }
     //pr($product_list);
     exit;
     \CI::db()->insert('engines', $parameters);
     $product_id = \CI::db()->insert_id();
     $data = array();
     // Create DOM from URL or file
     $html = file_get_html('https://www.perkins.com/en_GB/products/new/perkins/electric-power-generation/diesel-generators/1000002660.html');
     $modelTitle = $html->find('div.modelTitle');
     foreach ($modelTitle as $element) {
         $data['name'] = trim($element->plaintext);
         break;
     }
     $data['slug'] = strtolower(str_replace(' ', '-', $data['name']));
     $download = $html->find('div#toggle-product-downloads ul li a');
     foreach ($download as $element) {
         $data['document_link'] = $element->href;
         break;
     }
     $img = $html->find('ul#carousel-photos a img');
     foreach ($img as $element) {
         $link_img = $element->src;
         break;
     }
     $tmp_name = '404D-22G';
     $images = $this->save_image($tmp_name, $link_img);
     echo $images;
     exit;
     // Find all images
     $tmp_array = array('bore', 'stroke', 'displacement', 'aspiration', 'rotation ', 'cylinders', 'cycle', 'compression_ratio', 'combustion_system', 'cooling_system', 'total_coolant_capacity', 'total_lubricating_capacity', 'length', 'width', 'height', 'weight', 'disclaimer1', 'disclaimer2', 'emissions');
     $tmp_data = array();
     foreach ($html->find('.unit-metric') as $key => $element) {
         $tmp_data[$tmp_array[$key]] = trim($element->plaintext);
         if (count($tmp_array) == $key + 1) {
             break;
         }
     }
     $data['dimensions'] = str_replace('.0 mm', '', $tmp_data['length']) . 'x' . str_replace('.0 mm', '', $tmp_data['width']) . 'x' . str_replace('.0 mm', '', $tmp_data['height']);
     $data['weight'] = str_replace(' kg', '', $tmp_data['weight']);
     //\CI::db()->insert('products', $data);
     //$product_id = \CI::db()->insert_id();
     $parameters = array();
     //$parameters['product_id']   = $product_id;
     $parameters['bore'] = $tmp_data['bore'];
     $parameters['stroke'] = $tmp_data['stroke'];
     $parameters['displacement'] = $tmp_data['displacement'];
     $parameters['cylinders_number'] = $tmp_data['cylinders'];
     $parameters['compression_ratio'] = $tmp_data['compression_ratio'];
     $parameters['type_cooled'] = $tmp_data['cooling_system'];
     $parameters['emissions'] = $tmp_data['emissions'];
     //\CI::db()->insert('engines', $parameters);
     echo '<pre>';
     print_r($data);
     pr($parameters);
     // Find all links
     //foreach($html->find('a') as $element)
     //  echo $element->href . '<br>';
     echo 'aaaa';
     exit;
 }
예제 #25
0
 static function Order($order)
 {
     if ($order->is_guest) {
         //if the customer is a guest, get their name from the Billing address
         $customerName = $order->billing_firstname . ' ' . $order->billing_lastname;
         $customerEmail = $order->billing_email;
     } else {
         $customerName = $order->firstname . ' ' . $order->lastname;
         $customerEmail = $order->email;
     }
     $cannedMessage = \CI::db()->where('id', '7')->get('canned_messages')->row_array();
     $loader = new \Twig_Loader_String();
     $twig = new \Twig_Environment($loader);
     //load in the view class so we can get our order view
     $view = \GoCart\Libraries\View::getInstance();
     $fields = ['customer_name' => $customerName, 'site_name' => config_item('company_name'), 'order_summary' => $view->get('order_summary_email', ['order' => $order])];
     $subject = $twig->render($cannedMessage['subject'], $fields);
     $content = $twig->render($cannedMessage['content'], $fields);
     $email = \Swift_Message::newInstance();
     $email->setFrom(config_item('email_from'));
     //email address the website sends from
     $email->setTo($customerEmail);
     $email->setBcc(config_item('email_to'));
     //admin email the website sends to
     $email->setReturnPath(config_item('email_to'));
     //this is the bounce if they submit a bad email
     $email->setSubject($subject);
     $email->setBody($content, 'text/html');
     self::sendEmail($email);
 }
예제 #26
0
 public function getProductIds($coupon_id)
 {
     CI::db()->select('product_id');
     CI::db()->where('coupon_id', $coupon_id);
     $res = CI::db()->where('coupon_id', $coupon_id)->get('coupons_products')->result();
     $list = [];
     foreach ($res as $item) {
         $list[] = $item->product_id;
     }
     return $list;
 }
예제 #27
0
파일: Banners.php 프로젝트: haouach/GoCart3
 function organize($banners)
 {
     foreach ($banners as $sequence => $id) {
         $data = array('sequence' => $sequence);
         CI::db()->where('banner_id', $id);
         CI::db()->update('banners', $data);
     }
 }
예제 #28
0
 function calculate_setup($type = 1)
 {
     //echo '<pre>';print_r($_POST);exit;
     $kVA = $_POST['kVA'];
     $phase = $_POST['phase'];
     $gen_number = $_POST['gen_number'];
     \CI::load()->library('Setup');
     \CI::Setup()->set($kVA, $phase, $gen_number);
     if (isset($_POST['bon_dau'])) {
         \CI::Setup()->bon_dung($_POST['dung_tich_bon_dau'], $_POST['duong_kinh_bon_dau'], $_POST['do_day_bon_dau']);
         \CI::Setup()->ong_dan_dau('ODD21', 'VDD21', $_POST['do_dai_ong_dau'], 1);
         \CI::Setup()->tu_bom($_POST['so_luong_tu_bom']);
     }
     //public function ong_khoi($phi, $length, $rockwool = true, $quantity_ong_nhung = 1){
     if (isset($_POST['rockwool'])) {
         $rockwool = true;
     } else {
         $rockwool = false;
     }
     if ($kVA <= 15) {
         $phi = 49;
         $funnel_quantity = 1;
     } else {
         if ($kVA >= 750) {
             \CI::db()->where('group', 2);
         }
         $query = \CI::db()->where('kVA <= ', $kVA)->order_by('kVA', 'DESC')->limit(1)->get('parameters_kva');
         if ($query->num_rows() > 0) {
             $get_phi = $query->row();
             if ($_POST['do_dai_ong_khoi'] > 20) {
                 if ($kVA >= 750) {
                     \CI::db()->where('group', 2);
                 }
                 $query = \CI::db()->where('funnel_phi > ', $get_phi->funnel_phi)->order_by('funnel_phi', 'ASC')->limit(1)->get('parameters_kva');
                 if ($query->num_rows() > 0) {
                     $get_phi = $query->row();
                     $phi = $get_phi->funnel_phi;
                 } else {
                     if ($kVA >= 750) {
                         \CI::db()->where('group', 2);
                     }
                     $query = \CI::db()->order_by('funnel_phi', 'DESC')->limit(1)->get('parameters_kva');
                     $get_phi = $query->row();
                     $phi = $get_phi->funnel_phi;
                 }
             } else {
                 $phi = $get_phi->funnel_phi;
             }
         } else {
             if ($kVA >= 750) {
                 \CI::db()->where('group', 2);
             }
             $query = \CI::db()->order_by('phi', 'DESC')->limit(1)->get('parameters_kva');
             $get_phi = $query->row();
             $phi = $get_phi->funnel_phi;
         }
         $funnel_quantity = $get_phi->funnel_quantity;
     }
     if (isset($_POST['vat_tu'])) {
         \CI::Setup()->ong_khoi($phi, $_POST['do_dai_ong_khoi'], $_POST['do_day_ong_khoi'], $rockwool, 1, $funnel_quantity);
         \CI::Setup()->cap_dong_luc($_POST['do_dai_day_cap']);
         \CI::Setup()->cap_te($_POST['do_dai_day_cap']);
         \CI::Setup()->cap_dieu_khien($_POST['do_dai_day_cap']);
         // can xac dinh lai do dai
         \CI::Setup()->bao_ve_cap($_POST['do_dai_day_cap']);
         \CI::Setup()->vat_tu_phu(1);
     }
     if (isset($_POST['kiem_dinh'])) {
         \CI::Setup()->kiem_dinh($_POST['kd_chat_luong'], $_POST['kd_tt3'], $_POST['thu_tai_gia']);
     }
     if (isset($_POST['nhan_cong'])) {
         \CI::Setup()->nhan_cong($_POST['nc_thao_ra_vo'], $_POST['nc_day_vao_vi_tri_dg'], $_POST['nc_day_vao_vi_tri_pt'], $_POST['nc_lap_may'], $_POST['nc_lap_dat_ats'], $_POST['nc_lap_tu_hoa'], $_POST['nc_hd_sudung_nt']);
     }
     if (isset($_POST['van_chuyen'])) {
         \CI::Setup()->khoang_cach($_POST['province'], $_POST['district'], $_POST['ward'], $_POST['address']);
         \CI::Setup()->vc_thu_cong($_POST['transport_hands']);
     }
     if (isset($_POST['ats'])) {
         \CI::Setup()->tu_ats();
     }
     if (isset($_POST['thoat_nhiet'])) {
         \CI::Setup()->thoat_nhiet();
     }
     echo \CI::Setup()->get_all_value();
     exit;
 }
예제 #29
0
파일: cart.php 프로젝트: Gninety/Microweber
<?php

$table_name = false;
$table_name = TABLE_PREFIX . "cart";
$query = CI::db()->query("show tables like '{$table_name}'");
$query = $query->row_array();
$query = array_values($query);
if ($query[0] != $table_name) {
    $sql = "CREATE TABLE " . $table_name . " (\n\t\tid int(11) NOT NULL auto_increment,\n\t\tUNIQUE KEY id (id)\n\t\t);";
    CI::db()->query($sql);
}
$sql = "show tables like '{$table_name}'";
$query = CI::db()->query($sql);
$query = $query->row_array();
$query = array_values($query);
if ($query[0] == $table_name) {
    //$columns = $db->fetchAll("show columns from $table_name");
    $fields_to_add = array();
    $fields_to_add[] = array('to_table', 'varchar(1500) default NULL');
    $fields_to_add[] = array('to_table_id', 'int(11) default NULL');
    $fields_to_add[] = array('updated_on', 'datetime default NULL');
    $fields_to_add[] = array('created_on', 'datetime default NULL');
    $fields_to_add[] = array('item_name', 'TEXT default NULL');
    $fields_to_add[] = array('price', 'TEXT default NULL');
    $fields_to_add[] = array('currency', 'TEXT default NULL');
    $fields_to_add[] = array('weight', 'TEXT default NULL');
    $fields_to_add[] = array('height', 'TEXT default NULL');
    $fields_to_add[] = array('length', 'TEXT default NULL');
    $fields_to_add[] = array('width', 'TEXT default NULL');
    $fields_to_add[] = array('qty', 'TEXT default NULL');
    $fields_to_add[] = array('other_info', 'TEXT default NULL');
예제 #30
0
 function validate_slug($slug, $id = false, $counter = false)
 {
     CI::db()->select('slug');
     CI::db()->from('pages');
     CI::db()->where('slug', $slug . $counter);
     if ($id) {
         CI::db()->where('id !=', $id);
     }
     $count = CI::db()->count_all_results();
     if ($count > 0) {
         if (!$counter) {
             $counter = 1;
         } else {
             $counter++;
         }
         return $this->validate_slug($slug, $id, $counter);
     } else {
         return $slug . $counter;
     }
 }