forked from kalkun-sms/Kalkun
/
sms_credit.php
105 lines (94 loc) · 2.59 KB
/
sms_credit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Plugin Name: SMS Credit
* Plugin URI: http://azhari.harahap.us
* Version: 0.1
* Description: SMS credit system that allow you to limit user for sending SMS
* Author: Azhari Harahap
* Author URI: http://azhari.harahap.us
*/
/*
|--------------------------------------------------------------------------
| CONFIGURATION
|--------------------------------------------------------------------------
|
*/
function sms_credit_initialize()
{
$config = array('allow_user_with_no_package' => TRUE);
return $config;
}
// Add hook for outgoing message
add_action("message.outgoing_all", "sms_credit", 10);
/**
* Function called when plugin first activated
* Utility function must be prefixed with the plugin name
* followed by an underscore.
*
* Format: pluginname_activate
*
*/
function sms_credit_activate()
{
return true;
}
/**
* Function called when plugin deactivated
* Utility function must be prefixed with the plugin name
* followed by an underscore.
*
* Format: pluginname_deactivate
*
*/
function sms_credit_deactivate()
{
return true;
}
/**
* Function called when plugin first installed into the database
* Utility function must be prefixed with the plugin name
* followed by an underscore.
*
* Format: pluginname_install
*
*/
function sms_credit_install()
{
$CI =& get_instance();
$CI->load->helper('kalkun');
// check if table already exist
if (!$CI->db->table_exists('plugin_sms_credit'))
{
$db_driver = $CI->db->platform();
$db_prop = get_database_property($db_driver);
execute_sql(APPPATH."plugins/sms_credit/media/".$db_prop['file']."_sms_credit.sql");
}
return true;
}
function sms_credit($sms)
{
$CI =& get_instance();
$CI->load->model('Kalkun_model');
$CI->load->model('sms_credit/sms_credit_model', 'plugin_model');
$config = sms_credit_initialize();
$uid = $sms['uid'];
// check user credit
$user_package = $CI->plugin_model->get_users(array('id' => $uid))->row_array();
if(isset($user_package['sms_numbers']))
{
$has_package = TRUE;
$sms_used = $CI->Kalkun_model->get_sms_used('date', array('user_id' => $uid,
'sms_date_start' => $user_package['valid_start'], 'sms_date_end' => $user_package['valid_end']));
}
else
{
$has_package = FALSE;
}
if(($has_package AND $sms_used >= $user_package['sms_numbers']) OR (!$has_package AND !$config['allow_user_with_no_package']))
{
echo "Sorry, your sms credit limit exceeded.";
exit;
}
}
/* End of file sms_credit.php */
/* Location: ./application/plugins/sms_credit/sms_credit.php */