0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
marketting
/
system
/
application
/
models
/
[
Home
]
File: groups_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 - groups_model.php | ------------------------------------------------------------------------- | | This model handles the functions for managing groups | */ class Groups_Model extends Model { function _get_member_group_id($id = '', $type = '') { $this->db->where('group_type', $type); $this->db->where('member_id', $id); $query = $this->db->get('members_groups'); if ($query->num_rows() > 0) { return $query->row_array(); } return false; } function _add_affiliate_group() { $data = $this->db_validation_model->_clean_data($_POST); //insert into db if (!$this->db->insert('affiliate_groups', $data)) { show_error($this->lang->line('could_not_add_group')); //log error log_message('error', 'Could not insert group into affiliate groups table'); return false; } else { $group_id = $this->db->insert_id(); //log success log_message('info', 'affiliate group '. $group_id . ' inserted into affiliate groups table'); } return $group_id; } // ------------------------------------------------------------------------ function _add_discount_group() { $data = $this->db_validation_model->_clean_data($_POST); //insert into db if (!$this->db->insert('discount_groups', $data)) { show_error($this->lang->line('could_not_add_group')); //log error log_message('error', 'Could not insert group into discount groups table'); return false; } else { $group_id = $this->db->insert_id(); //log success log_message('info', 'discount group '. $group_id . ' inserted into discount groups table'); } return $group_id; } // ------------------------------------------------------------------------ function _update_member_group($type = '', $id = '', $group_id = '') { $aff_group = array('group_id' => $group_id); $this->db->where('member_id', $id); $this->db->where('group_type', $type); if ($this->db->update('members_groups', $aff_group)) { return true; } return false; } // ------------------------------------------------------------------------ function _change_aff_group_status() { $data = $this->db_validation_model->_clean_data($_POST); foreach ($data as $k => $v) { if (strstr($k, "group") == true) { $id = explode("-", $k); $this->db->where('group_id', $id[1]); //update member in db $data = array('tier' => $v); if (!$this->db->update('affiliate_groups', $data)) { show_error($this->lang->line('could_not_update_affiliate_group')); //log error log_message('error', 'Could not update affiliate group #' . $k . ' in affiliate groups table'); return false; } } } //make sure tiers are numbered sequentially $this->db_validation_model->_db_sort_order('affiliate_groups', 'group_id', 'tier'); return true; } // ------------------------------------------------------------------------ function _delete_aff_group($id = '') { if ($id == 1) { return false; } //update members groups first $this->db->where('group_id', $id); $this->db->where('group_type', 'affiliate'); $data = array('group_id' => 1); if ($this->db->update('members_groups', $data)) { //log success log_message('info', 'members group ID #' . $id . ' updated successfully'); } else { show_error($this->lang->line('could_not_delete_group')); //log error log_message('error', 'members group ID #' . $id . ' could not be updated'); } //update products $this->db->where('add_affiliate_group', $id); $data = array('add_affiliate_group' => 0); if ($this->db->update('products', $data)) { //log success log_message('info', 'products ID #' . $id . ' updated successfully'); } else { show_error($this->lang->line('could_not_delete_group')); //log error log_message('error', 'products ID #' . $id . ' could not be updated'); } //delete from products to aff groups $this->db->where('group_id', $id); $this->db->delete('products_to_aff_groups'); //delete affiliate group $this->db->where('group_id', $id); if ($this->db->delete('affiliate_groups')) { //log success log_message('info', 'group ID #' . $id . ' deleted successfully'); } else { show_error($this->lang->line('could_not_delete_group')); //log error log_message('error', 'affiliate group ID #' . $id . ' could not be deleted'); } return true; } // ------------------------------------------------------------------------ function _delete_discount_group($id = '') { if ($id == 1) { return false; } //update members groups first $this->db->where('group_id', $id); $this->db->where('group_type', 'discount'); $data = array('group_id' => 1); if ($this->db->update('members_groups', $data)) { //log success log_message('info', 'members group ID #' . $id . ' updated successfully'); } else { show_error($this->lang->line('could_not_delete_group')); //log error log_message('error', 'members group ID #' . $id . ' could not be updated'); } //update products $this->db->where('add_discount_group', $id); $data = array('add_discount_group' => 0); if ($this->db->update('products', $data)) { //log success log_message('info', 'products ID #' . $id . ' updated successfully'); } else { show_error($this->lang->line('could_not_delete_group')); //log error log_message('error', 'products ID #' . $id . ' could not be updated'); } //delete from products to groups $this->db->where('group_id', $id); $this->db->delete('products_to_disc_groups'); //delete discount group $this->db->where('group_id', $id); if ($this->db->delete('discount_groups')) { //log success log_message('info', 'group ID #' . $id . ' deleted successfully'); } else { show_error($this->lang->line('could_not_delete_group')); //log error log_message('error', 'discount group ID #' . $id . ' could not be deleted'); } return true; } // ------------------------------------------------------------------------ function _get_aff_group_details($id = '') { //get the data from affiliate groups table $this->db->where('group_id', $id); $query = $this->db->get('affiliate_groups'); if ($query->num_rows() > 0) { return $query->result_array(); } else { return false; } } // ------------------------------------------------------------------------ function _check_user_group($type = '', $id = '') { //get the data from affiliate groups table $this->db->where('group_type', $type); $this->db->where('member_id', $id); $this->db->join($type . '_groups', 'members_groups.group_id = ' . $type . '_groups.group_id', 'left'); $query = $this->db->get('members_groups'); if ($query->num_rows() > 0) { return $query->row_array(); } else { return false; } } // ------------------------------------------------------------------------ function _get_discount_group_details($id = '') { //get the data from affiliate groups table $this->db->where('group_id', $id); $query = $this->db->get('discount_groups'); if ($query->num_rows() > 0) { return $query->result_array(); } else { return false; } } // ------------------------------------------------------------------------ function _get_affiliate_groups($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_ag_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_ag_column'); $sql = 'SELECT ' . $this->db->dbprefix('affiliate_groups') . '.*, (SELECT COUNT(*) from ' . $this->db->dbprefix('members_groups') . ' WHERE ' . $this->db->dbprefix('affiliate_groups') . '.group_id = ' . $this->db->dbprefix('members_groups') . '.group_id AND ' . $this->db->dbprefix('members_groups') . '.group_type = \'affiliate\') as total FROM ' . $this->db->dbprefix('affiliate_groups') . ' 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 _get_discount_groups($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_dg_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_dg_column'); $sql = 'SELECT ' . $this->db->dbprefix('discount_groups') . '.*, (SELECT COUNT(*) from ' . $this->db->dbprefix('members_groups') . ' WHERE ' . $this->db->dbprefix('discount_groups') . '.group_id = ' . $this->db->dbprefix('members_groups') . '.group_id AND ' . $this->db->dbprefix('members_groups') . '.group_type = \'discount\') as total FROM ' . $this->db->dbprefix('discount_groups') . ' 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_affiliate_group() { //clean the data first $data = $this->db_validation_model->_clean_data($_POST); $this->db->where('group_id', $data['group_id']); if (!$this->db->update('affiliate_groups', $data)) { show_error($this->lang->line('could_not_update_group')); //log error log_message('error', 'Could not update group ID ' . $data['group_id'] . 'in affiliate groups table'); return false; } else { //log success log_message('info', 'group ID '. $data['group_id'] . ' updated in affiliate groups table'); } } // ------------------------------------------------------------------------ function _update_discount_group() { //clean the data first $data = $this->db_validation_model->_clean_data($_POST); $this->db->where('group_id', $data['group_id']); if (!$this->db->update('discount_groups', $data)) { show_error($this->lang->line('could_not_update_group')); //log error log_message('error', 'Could not update group ID ' . $data['group_id'] . 'in discount groups table'); return false; } else { //log success log_message('info', 'group ID '. $data['group_id'] . ' updated in discount groups table'); } } // ------------------------------------------------------------------------ } ?>