0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
marketting
/
system
/
application
/
models
/
[
Home
]
File: support_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 - support_model.php | ------------------------------------------------------------------------- | | This model handles the functions for managing support | */ class Support_Model extends Model { function _auto_close_tickets() { if ($this->config->item('sts_support_auto_close') == 1) { $total = 0; $time = now() - ($this->config->item('sts_support_auto_close_interval') * 60 * 60 * 24); $this->db->where('ticket_parent', '1'); $this->db->where('ticket_status', '0'); $this->db->where('date_modified <=' , $time); $query = $this->db->get('support_tickets'); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $this->db->where('ticket_id', $row['ticket_id']); $this->db->update('support_tickets', array('ticket_status' => '1')); $total++; } } return $total . ' support tickets autoclosed'; } } // ------------------------------------------------------------------------ function _add_ticket($id = '') { $ticket_body = htmlentities($_POST['ticket_body']); $data = $this->db_validation_model->_clean_data($_POST); $newdata['ticket_data'] = $data; if (isset($data['userfile'])) { unset($data['userfile']); } //format the data to insert $fdata = array('ticket_parent' => '1', 'admin_response' => '0', 'parent_id' => '0', 'member_id' => $id, 'admin_id' => '0', 'ticket_status' => '0', 'ticket_priority' => $data['ticket_priority'], 'date_added' => _generate_timestamp(), 'date_modified' => _generate_timestamp(), 'ticket_subject' => $data['ticket_subject'], 'ticket_body' => $ticket_body, 'support_category_id' => $data['support_category_id'], 'last_response_made' => 'member', ); //insert into db if (!$this->db->insert('support_tickets', $fdata)) { show_error($this->lang->line('could_not_add_support_ticket')); //log error log_message('error', 'Could not insert ticket into support table'); return false; } else { //new ticket ID $newdata['id'] = $this->db->insert_id(); //get support data $member_data = $this->db_validation_model->_get_details('members', '*', 'member_id', $id); $newdata['member_data'] = $member_data[0]; //log success log_message('info', 'support '. $newdata['id'] . ' inserted into support table'); } return $newdata; } // ------------------------------------------------------------------------ function _get_user_tickets($id = '', $limit = 25, $offset = 0, $sort_column = '', $sort_order = '', $where_value = '') { //get all the admins from db for list view if (!$sort_order) $sort_order = $this->config->item('mem_dbs_sup_order'); if (!$sort_column) $sort_column = $this->config->item('mem_dbs_sup_column'); $sql = 'SELECT ' . $this->db->dbprefix('support_tickets') . '.* FROM ' . $this->db->dbprefix('support_tickets') . ' WHERE member_id = \'' . $id . '\' AND ticket_parent = \'1\''; if ($where_value == 'closed' || $where_value == 'open') { $status = $where_value == 'closed' ? '1' : '0'; $sql .= ' AND ticket_status = \'' . $status . '\' '; } $sql .= ' ORDER BY ' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; $query = $this->db->query($sql); $total_rows = $query->num_rows(); if ($query->num_rows() > 0) { $a['tickets'] = array(); foreach ($query->result_array() as $row) { $row['s_date_added'] = _show_date($row['date_added']); $row['s_date_modified'] = $this->lang->line($row['date_modified']); $row['row_style'] = alternator('jroxRowStyle1', 'jroxRowStyle2'); $row['s_ticket_status'] = $row['ticket_status'] == '1' ? 'tick' : 'warning1'; array_push($a['tickets'], $row); } //get total rows $this->db->where('member_id', $id); $this->db->where('ticket_parent', '1'); if ($where_value == 'closed' || $where_value == 'open') { $status = $where_value == 'closed' ? '1' : '0'; $this->db->where('ticket_status', $status); } $a['total_rows'] = $this->db->count_all_results('support_tickets'); return $a; } return false; } // ------------------------------------------------------------------------ function _delete_ticket($id = '') { //get support data $support_data = $this->_get_support_ticket_details($id, 'delete'); //send the email alert notification first //get member data $member_data = $this->db_validation_model->_get_details('members', '*', 'member_id', $support_data[0]['member_id']); //check if file needs to be deleted if (!empty($support_data[0]['uploaded_file'])) { @unlink($this->config->item('sts_support_upload_folder_path') . '/' . $support_data[0]['uploaded_file']); } //delete children first $this->db->where('parent_id', $id); $this->db->delete('support_tickets'); //delete support $this->db->where('ticket_id', $id); if ($this->db->delete('support_tickets')) { //log success log_message('info', 'support ID #' . $id . ' deleted successfully'); //add ticket id to array $member_data[0]['ticket_id'] = $id; return $member_data[0]; } else { show_error($this->lang->line('could_not_delete_support')); //log error log_message('error', 'support ID #' . $id . ' could not be deleted'); return false; } } // ------------------------------------------------------------------------ function _get_response_details($id = '') { $this->db->where('ticket_id', $id); $query = $this->db->get('support_tickets'); if ($query->num_rows() > 0) { return $query->row_array(); } return false; } // ------------------------------------------------------------------------ function _get_support_ticket_details($id = '') { //get the data from support table $sql = 'SELECT ' . $this->db->dbprefix('support_tickets') . '.*, (SELECT ' . $this->db->dbprefix('admin_users') . '.fname from ' . $this->db->dbprefix('admin_users') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.admin_id = ' . $this->db->dbprefix('admin_users') . '.admin_id) as admin_user, (SELECT ' . $this->db->dbprefix('members') . '.username from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as member FROM ' . $this->db->dbprefix('support_tickets') . ' WHERE ticket_id = \'' . $id . '\''; $query = $this->db->query($sql); $data = array(); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { array_push($data, $row); } if (empty($type)) { if ($data[0]['ticket_parent'] == '0') { show_error('invalid'); } } //now get all children $sql = 'SELECT ' . $this->db->dbprefix('support_tickets') . '.*, (SELECT ' . $this->db->dbprefix('admin_users') . '.fname from ' . $this->db->dbprefix('admin_users') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.admin_id = ' . $this->db->dbprefix('admin_users') . '.admin_id) as admin_user, (SELECT ' . $this->db->dbprefix('members') . '.username from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as member FROM ' . $this->db->dbprefix('support_tickets') . ' WHERE parent_id = \'' . $id . '\' ORDER BY ticket_id ASC'; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { array_push($data, $row); } } return $data; } return false; } // ------------------------------------------------------------------------ function _change_status($data = '', $type = '0') { foreach ($data as $id) { $this->db->where('ticket_id', $id); //update member in db $data = array( 'ticket_status' => $type, ); if (!$this->db->update('support_tickets', $data)) { show_error($this->lang->line('could_not_update_tickets')); //log error log_message('error', 'Could not update ticket ID #' . $id . ' in tickets table'); return false; } //log success log_message('info', 'Status Changed for ticket ID# ' . $id); } return true; } // ------------------------------------------------------------------------ function _get_support_categories($none = '', $text = '') { $query = $this->db->get('support_categories'); $data = $query->result_array(); $cat = format_array($data, 'support_category_id', 'category_name', $none, $text); return $cat; } // ------------------------------------------------------------------------ function _get_support_tickets($limit = 25, $offset = 0, $sort_column = '', $sort_order = '', $filter = 'closed', $category = '') { //get all the admins from db for list view if (!$sort_order) $sort_order = $this->config->item('dbs_stc_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_stc_column'); $sql = 'SELECT ' . $this->db->dbprefix('support_tickets') . '.*, (SELECT ' . $this->db->dbprefix('admin_users') . '.username from ' . $this->db->dbprefix('admin_users') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.admin_id = ' . $this->db->dbprefix('admin_users') . '.admin_id) as admin_user, (SELECT ' . $this->db->dbprefix('members') . '.username from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as member, (SELECT ' . $this->db->dbprefix('support_categories') . '.category_name from ' . $this->db->dbprefix('support_categories') . ' WHERE ' . $this->db->dbprefix('support_tickets') . '.support_category_id = ' . $this->db->dbprefix('support_categories') . '.support_category_id) as category_name FROM ' . $this->db->dbprefix('support_tickets') . ' WHERE ticket_parent = \'1\''; //add extra where clause if ($filter == 'closed') { $sql2 = ' AND ticket_status = \'1\''; } elseif ($filter == 'all') { $sql2 = ''; } else { $sql2 = ' AND ticket_status = \'0\''; } $sql .= $sql2; //check if category is set if (!empty($category)) { $sql3 = ' AND support_category_id = \'' . $category . '\''; } else { $sql3 = ''; } $sql .= $sql3; //check if the admin only wants to see the tickets assigned to him if ($this->session->userdata('tickets') == 1) { $sql4 = ' AND admin_id = \'' . $this->session->userdata('adminid') . '\''; } else { $sql4 = ''; } $sql .= $sql4; $sql .= ' ORDER BY ' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $row = $query->result_array(); //count the rows $row['total_rows'] = $this->db_validation_model->_get_count('support_tickets', 'WHERE ticket_parent = \'1\'' . $sql2 . $sql3 . $sql4); return $row; } return false; } // ------------------------------------------------------------------------ function _assign_ticket($id = '') { //clean the data first $data = $this->db_validation_model->_clean_data($_POST); $this->db->where('ticket_id', $id); if ($this->db->update('support_tickets', $data)) { $a = $this->db_validation_model->_get_details('admin_users', '', 'admin_id', $data['admin_id']); return $a[0]; } return false; } // ------------------------------------------------------------------------ function _update_support_ticket($type = '', $id = '') { //clean the data first $data = $this->db_validation_model->_clean_data($_POST); $newdata['ticket_data'] = $data; if (isset($data['userfile'])) { unset($data['userfile']); } //get support data $this->db->where('ticket_id', $id); $query = $this->db->get('support_tickets'); $row = $query->result_array(); //format input $ticket_subject = !empty($data['ticket_subject']) ? $data['ticket_subject'] : $row[0]['ticket_subject']; if ($type == 'admin') { //format the data to insert $fdata = array('ticket_parent' => '0', 'admin_response' => '1', 'parent_id' => $id, 'member_id' => $row[0]['member_id'], 'admin_id' => $this->session->userdata('adminid'), 'ticket_status' => $data['ticket_status'], 'ticket_priority' => $data['ticket_priority'], 'date_added' => _generate_timestamp(), 'date_modified' => _generate_timestamp(), 'ticket_subject' => $ticket_subject, 'ticket_body' => $data['ticket_body'], 'support_category_id' => $data['support_category_id'], 'last_response_made' => 'admin', ); } else //response made by user { //format the data to insert $ticket_body = htmlentities($_POST['ticket_body']); $fdata = array('ticket_parent' => '0', 'admin_response' => '0', 'parent_id' => $id, 'member_id' => $row[0]['member_id'], 'admin_id' => $row[0]['admin_id'], 'ticket_status' => $row[0]['ticket_status'], 'ticket_priority' => $row[0]['ticket_priority'], 'date_added' => _generate_timestamp(), 'date_modified' => _generate_timestamp(), 'ticket_subject' => $ticket_subject, 'ticket_body' => $ticket_body, 'support_category_id' => $row[0]['support_category_id'], 'last_response_made' => 'member', ); } if (!$this->db->insert('support_tickets', $fdata)) { show_error($this->lang->line('could_not_update_support_tickets')); //log error log_message('error', 'Could not update support ID ' .$id . 'in support table'); return false; } //new ticket ID $newdata['id'] = $this->db->insert_id(); //if this is an admin response if ($type == 'admin') { //get support data $member_data = $this->db_validation_model->_get_details('members', '*', 'member_id', $data['member_id']); $newdata['member_data'] = $member_data[0]; $newdata['member_data']['admin_fname'] = $this->session->userdata('fname'); $newdata['member_data']['admin_lname'] = $this->session->userdata('lname'); $newdata['member_data']['ticket_id'] = $id; //update FAQ if (!empty($data['add_faq'])) { $faq_data = array( 'date_published' => _generate_timestamp(), 'modified_by' => $this->session->userdata('username'), 'category_id' => (int)($this->input->post('category_id')), 'content_title' => $ticket_subject, 'content_body' => $data['ticket_body'] ); //insert into db if (!$this->db->insert('faq_articles', $faq_data)) { show_error($this->lang->line('could_not_add_faq')); //log error log_message('error', 'Could not insert faq into faq table'); return false; } else { $faq_id = $this->db->insert_id(); //log success log_message('info', 'faq '. $faq_id . ' inserted into faq table'); } } //update the original ticket $sdata = array('admin_id' => $this->session->userdata('adminid'), 'ticket_priority' => $data['ticket_priority'], 'ticket_status' => $data['ticket_status'], 'support_category_id' => $data['support_category_id'], 'last_response_made' => 'admin', 'date_modified' => _generate_timestamp()); } else //if the user responded { //get support data $member_data = $this->db_validation_model->_get_details('members', '*', 'member_id', $row[0]['member_id']); $newdata['member_data'] = $member_data[0]; //update the original ticket $sdata = array('date_modified' => _generate_timestamp(), 'last_response_made' => 'member'); } $this->db->where('ticket_id', $id); $this->db->update('support_tickets', $sdata); //log success log_message('info', 'support ID '. $id . ' updated in support_tickets table'); return $newdata; } // ------------------------------------------------------------------------ function _add_category() { $data = $this->db_validation_model->_clean_data($_POST); //insert into db if (!$this->db->insert('support_categories', $data)) { show_error($this->lang->line('could_not_add_category')); //log error log_message('error', 'Could not insert support_category into support_categories table'); return false; } else { $support_category_id = $this->db->insert_id(); //log success log_message('info', 'category '. $support_category_id . ' inserted into support_categories table'); } return $support_category_id; } // ------------------------------------------------------------------------ function _delete_category($id = '') { if ($id == 1) { return false; } //update categorys first $this->db->where('support_category_id', $id); $data = array('support_category_id' => 1); if ($this->db->update('support_tickets', $data)) { //log success log_message('info', 'category ID #' . $id . ' updated successfully'); } else { show_error($this->lang->line('could_not_delete_category')); //log error log_message('error', 'category ID #' . $id . ' could not be updated'); } //delete category $this->db->where('support_category_id', $id); if ($this->db->delete('support_categories')) { //log success log_message('info', 'category ID #' . $id . ' deleted successfully'); } else { show_error($this->lang->line('could_not_delete_category')); //log error log_message('error', 'category ID #' . $id . ' could not be deleted'); } return true; } // ------------------------------------------------------------------------ function _update_category($id = '') { //clean the data first $data = $this->db_validation_model->_clean_data($_POST); //update category data $this->db->where('support_category_id',$id); if (!$this->db->update('support_categories', $data)) { show_error($this->lang->line('could_not_update_category')); //log error log_message('error', 'Could not update category ID ' . $id . 'in categories table'); return false; } else { //log success log_message('info', 'category ID '.$id . ' updated in categories table'); } return true; } // ------------------------------------------------------------------------ function _get_support_category_details($id = '') { //get the data from support_categories table $this->db->where('support_category_id', $id); $query = $this->db->get('support_categories'); if ($query->num_rows() > 0) { return $query->result_array(); } else { return false; } } // ------------------------------------------------------------------------ function _get_categories($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_spc_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_spc_column'); $sql = 'SELECT ' . $this->db->dbprefix('support_categories') . '.*, (SELECT COUNT(*) from ' . $this->db->dbprefix('support_tickets') . ' WHERE ' . $this->db->dbprefix('support_categories') . '.support_category_id = ' . $this->db->dbprefix('support_tickets') . '.support_category_id AND ticket_parent = \'1\') as total FROM ' . $this->db->dbprefix('support_categories') . ' 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; } // ------------------------------------------------------------------------ } ?>