Skip to content

Commit

Permalink
merge branch plugin-sms-billing
Browse files Browse the repository at this point in the history
  • Loading branch information
back2arie committed Feb 1, 2013
2 parents b493389 + d753f58 commit 82b9abb
Show file tree
Hide file tree
Showing 19 changed files with 1,068 additions and 6 deletions.
10 changes: 10 additions & 0 deletions application/config/kalkun_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@
*/
$config['ncpr'] = FALSE;

/*
|--------------------------------------------------------------------------
| UNICODE
|--------------------------------------------------------------------------
|
| Enable unicode by default?
| Send as Unicode checkbox will automatically checked
|
*/
$config['unicode'] = FALSE;

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions application/controllers/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function compose_process()

// hook for outgoing message
$dest = do_action("message.outgoing", $dest);
$sms = do_action("message.outgoing_all", $data);

// check for field
$field_status = FALSE;
Expand Down
10 changes: 9 additions & 1 deletion application/controllers/pluginss.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class Pluginss extends MY_Controller {
function __construct()
{
parent::__construct();

// Prevent non-admin user
if($this->session->userdata('level') != 'admin')
{
$this->session->set_flashdata('notif', 'Only administrator can manage plugin');
redirect('/');
}

$this->load->library('Plugins');
$this->load->model('Plugin_model');
}
Expand Down Expand Up @@ -152,4 +160,4 @@ function deactivate($plugin_name)
}

/* End of file plugin.php */
/* Location: ./application/controllers/plugin.php */
/* Location: ./application/controllers/plugin.php */
12 changes: 11 additions & 1 deletion application/models/kalkun_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,17 @@ function get_sms_used($option, $param, $type = 'out')
case 'date':
$this->db->select_sum($type.'_sms_count');
$this->db->from('sms_used');
$this->db->where('sms_date', $param['sms_date']);

if(isset($param['sms_date_start']) AND isset($param['sms_date_end']))
{
$this->db->where('sms_date >=', $param['sms_date_start']);
$this->db->where('sms_date <=', $param['sms_date_end']);
}
else
{
$this->db->where('sms_date', $param['sms_date']);
}

if (isset($param['user_id']))
{
$this->db->where('id_user', $param['user_id']);
Expand Down
7 changes: 7 additions & 0 deletions application/plugins/Plugin_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function Plugin_Controller($login=TRUE)
{
parent::__construct($login);

// Prevent non-admin user
if($login AND $this->session->userdata('level') != 'admin')
{
$this->session->set_flashdata('notif', 'Only administrator can manage plugin');
redirect('/');
}

/* Prevent this controller from being called directly */
if (get_class() == get_class($this))
{
Expand Down
206 changes: 206 additions & 0 deletions application/plugins/sms_credit/controllers/sms_credit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php
/**
* Kalkun
* An open source web based SMS Management
*
* @package Kalkun
* @author Kalkun Dev Team
* @license http://kalkun.sourceforge.net/license.php
* @link http://kalkun.sourceforge.net
*/

// ------------------------------------------------------------------------

/**
* SMS_credit Class
*
* @package Kalkun
* @subpackage Plugin
* @category Controllers
*/
include_once(APPPATH.'plugins/Plugin_Controller.php');

class SMS_credit extends Plugin_Controller {

/**
* Constructor
*
* @access public
*/
function __construct()
{
parent::Plugin_Controller();
$this->load->model('sms_credit_model', 'plugin_model');
}

// --------------------------------------------------------------------

/**
* Index
*
* Display list of all users
*
* @access public
*/
function index()
{
$param = array();
if($_POST)
{
$param['q'] = $this->input->post('search_name');
$data['query'] = $param['q'];
}

$this->load->library('pagination');
$config['base_url'] = site_url('plugin/sms_credit/index');
$config['total_rows'] = $this->plugin_model->get_users()->num_rows();
$config['per_page'] = $this->Kalkun_model->get_setting()->row('paging');
$config['cur_tag_open'] = '<span id="current">';
$config['cur_tag_close'] = '</span>';
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$param['limit'] = $config['per_page'];
$param['offset'] = $this->uri->segment(4,0);

$data['main'] = 'index';
$data['title'] = 'Users Credit';
$data['users'] = $this->plugin_model->get_users($param);
$data['packages'] = $this->plugin_model->get_packages();

$this->load->view('main/layout', $data);
}

// --------------------------------------------------------------------

/**
* Add Users
*
* Add an User with packages
*
* @access public
*/
function add_users()
{
if($_POST)
{
$param['id_user'] = $this->input->post('id_user');
$param['id_template_credit'] = $this->input->post('package');
$param['valid_start'] = $this->input->post('package_start');
$param['valid_end'] = $this->input->post('package_end');

if(empty($param['id_user']))
{
unset($param['id_user']);
$param['realname'] = trim($this->input->post('realname'));
$param['username'] = trim($this->input->post('username'));
$param['phone_number'] = $this->input->post('phone_number');
$param['level'] = $this->input->post('level');
$param['password'] = sha1($this->input->post('password'));
$this->plugin_model->add_users($param);
}
else
{
$this->plugin_model->change_users_package($param);
}

redirect('plugin/sms_credit');
}
}

// --------------------------------------------------------------------

/**
* Delete Users
*
* Delete an User
*
* @access public
*/
function delete_users($id = NULL)
{
$this->plugin_model->delete_users($id);
redirect('plugin/sms_credit');
}

// --------------------------------------------------------------------

/**
* Packages
*
* Display list of all packages
*
* @access public
*/
function packages()
{
$this->load->library('pagination');
$config['base_url'] = site_url('plugin/sms_credit/packages');
$config['total_rows'] = $this->plugin_model->get_packages()->num_rows();
$config['per_page'] = $this->Kalkun_model->get_setting()->row('paging');
$config['cur_tag_open'] = '<span id="current">';
$config['cur_tag_close'] = '</span>';
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$param['limit'] = $config['per_page'];
$param['offset'] = $this->uri->segment(4,0);

if($_POST)
{
$data['query'] = $this->input->post('query');
$data['packages'] = $this->plugin_model->search_packages($data['query']);
}
else
{
$data['packages'] = $this->plugin_model->get_packages($param);
}

$data['main'] = 'packages';
$data['title'] = 'Credit Package';
$this->load->view('main/layout', $data);
}

// --------------------------------------------------------------------

/**
* Add Packages
*
* Add Packages
*
* @access public
*/
function add_packages()
{
if($_POST)
{
$param['id_credit_template'] = $this->input->post('id_package');

if(empty($param['id_credit_template'])) {
unset($param['id_credit_template']);
}

$param['template_name'] = trim($this->input->post('package_name'));
$param['sms_numbers'] = trim($this->input->post('sms_amount'));
$this->plugin_model->add_packages($param);
redirect('plugin/sms_credit/packages');
}
}

// --------------------------------------------------------------------

/**
* Delete Packages
*
* Delete Packages
*
* @access public
*/
function delete_packages($id = NULL)
{
$this->plugin_model->delete_packages($id);
redirect('plugin/sms_credit/packages');
}

}

/* End of file sms_credit.php */
/* Location: ./application/plugins/sms_credit/controllers/sms_credit.php */
13 changes: 13 additions & 0 deletions application/plugins/sms_credit/media/mysql_sms_credit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS `plugin_sms_credit` (
`id_user_credit` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`id_user` INT( 11 ) NOT NULL ,
`id_template_credit` INT( 11 ) NOT NULL ,
`valid_start` DATETIME NOT NULL ,
`valid_end` DATETIME NOT NULL
) ENGINE = MYISAM ;

CREATE TABLE IF NOT EXISTS `plugin_sms_credit_template` (
`id_credit_template` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`template_name` VARCHAR( 50 ) NOT NULL ,
`sms_numbers` INT( 11 ) NOT NULL
) ENGINE = MYISAM ;
13 changes: 13 additions & 0 deletions application/plugins/sms_credit/media/pgsql_sms_credit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TABLE "plugin_sms_credit" (
"id_user_credit" serial PRIMARY KEY,
"id_user" integer NOT NULL,
"id_template_credit" integer NOT NULL,
"valid_start" timestamp(0) WITHOUT time zone NOT NULL,
"valid_end" timestamp(0) WITHOUT time zone NOT NULL
);

CREATE TABLE "plugin_sms_credit_template" (
"id_credit_template" serial PRIMARY KEY,
"template_name" varchar(50) NOT NULL,
"sms_numbers" integer NOT NULL
);
13 changes: 13 additions & 0 deletions application/plugins/sms_credit/media/sqlite_sms_credit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TABLE "plugin_sms_credit" (
"id_user_credit" INTEGER PRIMARY KEY AUTOINCREMENT,
"id_user" INTEGER NOT NULL,
"id_template_credit" INTEGER NOT NULL,
"valid_start" DATETIME NOT NULL,
"valid_end" DATETIME NOT NULL
);

CREATE TABLE "plugin_sms_credit_template" (
"id_credit_template" INTEGER PRIMARY KEY AUTOINCREMENT,
"template_name" VARCHAR(50) NOT NULL,
"sms_numbers" INTEGER NOT NULL
);
Loading

0 comments on commit 82b9abb

Please sign in to comment.