0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
marketting
/
system
/
application
/
models
/
[
Home
]
File: vendors_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* | ------------------------------------------------------------------------- | COPYRIGHT NOTICE | Copyright 2008 JROX Technologies, Inc. All Rights Reserved. | ------------------------------------------------------------------------- | This script may be only used and modified in accordance to the license | agreement attached (license.txt) except where expressly noted within | commented areas of the code body. This copyright notice and the | comments above and below must remain intact at all times. By using this | code you agree to indemnify JROX Technologies, Inc, its corporate agents | and affiliates from any liability that might arise from its use. | | Selling the code for this program without prior written consent is | expressly forbidden and in violation of Domestic and International | copyright laws. | | ------------------------------------------------------------------------- | FILENAME - vendors_model.php | ------------------------------------------------------------------------- | | This model handles the functions for managing vendors | */ class Vendors_Model extends Model { function _add_vendor() { $data = $this->db_validation_model->_clean_data($_POST); //insert into db if (!$this->db->insert('vendors', $data)) { show_error($this->lang->line('could_not_add_vendor')); //log error log_message('error', 'Could not insert vendor into vendors table'); return false; } else { $vendor_id = $this->db->insert_id(); //log success log_message('info', 'vendor '. $vendor_id . ' inserted into vendors table'); } return $vendor_id; } // ------------------------------------------------------------------------ function _change_status($id = '') { $this->db->where('vendor_id', $id); $query = $this->db->get('vendors'); $row = $query->result_array(); $status = ($row[0]['vendor_send_alert'] == '1') ? '0' : '1'; $data = array('vendor_send_alert' => $status); $this->db->where('vendor_id', $id); if ($this->db->update('vendors', $data)) { //log success log_message('info', 'Status Changed for vendor ID# ' . $id); return true; } show_error($this->lang->line('could_not_update_vendor')); //log error log_message('error', 'Could not update vendor ID #' . $id . ' in vendors table'); return false; } // ------------------------------------------------------------------------ function _delete_vendor($id = '') { if ($id == 1) { return false; } //update members vendors first $this->db->where('vendor_id', $id); $data = array('vendor_id' => 1); if ($this->db->update('products', $data)) { //log success log_message('info', 'members vendor ID #' . $id . ' updated successfully'); } else { show_error($this->lang->line('could_not_delete_vendor')); //log error log_message('error', 'members vendor ID #' . $id . ' could not be updated'); } //delete photo if any //get vendor data $vendor_data = $this->_get_vendor_details($id); //check first if photo needs to be deleted if (empty($data['vendor_image'])) { if (!empty($vendor_data['vendor_image'])) { @unlink('./images/' . $this->config->item('images_vendors_dir') . '/' . $vendor_data['vendor_image']); } } //delete vendor $this->db->where('vendor_id', $id); if ($this->db->delete('vendors')) { //log success log_message('info', 'vendor ID #' . $id . ' deleted successfully'); } else { show_error($this->lang->line('could_not_delete_vendor')); //log error log_message('error', 'vendor ID #' . $id . ' could not be deleted'); } return true; } // ------------------------------------------------------------------------ function _get_vendor_details($id = '') { //get the data from vendors table $this->db->where('vendor_id', $id); $query = $this->db->get('vendors'); if ($query->num_rows() > 0) { return $query->row_array(); } else { return false; } } // ------------------------------------------------------------------------ function _get_vendors($limit = 25, $offset = 0, $sort_column = '', $sort_order = '') { //get all the admins from db for list view if (!$sort_order) $sort_order = $this->config->item('dbs_ven_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_ven_column'); $sql = 'SELECT ' . $this->db->dbprefix('vendors') . '.*, (SELECT COUNT(*) from ' . $this->db->dbprefix('products') . ' WHERE ' . $this->db->dbprefix('vendors') . '.vendor_id = ' . $this->db->dbprefix('products') . '.vendor_id) as total FROM ' . $this->db->dbprefix('vendors') . ' ORDER BY ' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; $query = $this->db->query($sql); if ($query->num_rows() > 0) { return $query->result_array(); } return false; } // ------------------------------------------------------------------------ function _update_vendor() { //clean the data first $data = $this->db_validation_model->_clean_data($_POST); if (isset($data['userfile'])) { unset($data['userfile']); } //get vendor data $vendor_data = $this->_get_vendor_details($data['vendor_id']); //check first if photo needs to be deleted if (empty($data['vendor_image'])) { if (!empty($vendor_data['vendor_image'])) { @unlink('./images/' . $this->config->item('images_vendors_dir') . '/' . $vendor_data['vendor_image']); } } //update vendor data $this->db->where('vendor_id', $data['vendor_id']); if (!$this->db->update('vendors', $data)) { show_error($this->lang->line('could_not_update_vendor')); //log error log_message('error', 'Could not update vendor ID ' . $data['vendor_id'] . 'in vendors table'); return false; } else { //log success log_message('info', 'vendor ID '. $data['vendor_id'] . ' updated in vendors table'); } return $vendor_data; } // ------------------------------------------------------------------------ } ?>