-
Notifications
You must be signed in to change notification settings - Fork 15
/
class_package.php
executable file
·118 lines (106 loc) · 3.68 KB
/
class_package.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
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/* For licensing terms, see /license.txt */
class package extends model {
public $columns = array('id', 'name','backend', 'description','type', 'server', 'admin','reseller','additional', 'order', 'is_hidden', 'is_disabled');
public $table_name = 'packages';
public $has_many = array('addon' => array('table_name'=>'package_addons','columns'=>array('package_id', 'addon_id')));
/**
* Creates a new package
*
* @param array parameters
*
*/
public function create($params) {
global $main;
$id = $this->save($params);
$main->addLog("package::create #$id");
return $id;
}
/**
* Edits an object
*/
public function edit($id, $params) {
global $main;
$this->setId($id);
$main->addLog("package::edit ticket #$id");
$this->update($params);
}
public function delete($id) {
global $main;
$this->setId($id);
parent::delete();
$main->addLog("package::delete #$id");
return true;
}
/**
* Gets all package information by billing cycle
* @param int package id
* @param int billing cycle id
* @return array package information
*/
public function getAllPackagesByBillingCycle($billing_id) {
global $db;
$addong_list = array();
if (!empty($billing_id)) {
$billing_id = intval($billing_id);
$sql = "SELECT a.id, a.name, amount, bc.name as billing_name FROM `<PRE>packages` a INNER JOIN `<PRE>billing_products` b ON (a.id = b.product_id) INNER JOIN `<PRE>billing_cycles` bc
ON (bc.id = b.billing_id) WHERE bc.id = {$billing_id} AND b.type= '".BILLING_TYPE_PACKAGE."'";
$addons_billing = $db->query($sql);
$addong_list = array();
while($data = $db->fetch_array($addons_billing)) {
$addong_list[$data['id']] = array('id'=>$data['id'], 'name' => $data['name'], 'amount'=>$data['amount']);
}
}
return $addong_list;
}
/**
* Gets the package information by billing cycle
* @param int package id
* @param int billing cycle id
* @return array package information
*/
public function getPackageByBillingCycle($package_id, $billing_id) {
global $db;
$package_info = array();
if (!empty($package_id) && !empty($billing_id)) {
$billing_id = intval($billing_id);
$package_id = intval($package_id);
$sql = "SELECT a.id, a.name, amount, bc.name as billing_name FROM `<PRE>packages` a INNER JOIN `<PRE>billing_products` b ON (a.id = b.product_id) INNER JOIN `<PRE>billing_cycles` bc
ON (bc.id = b.billing_id) WHERE bc.id = {$billing_id} AND a.id = {$package_id} AND b.type= '".BILLING_TYPE_PACKAGE."'";
$addons_billing = $db->query($sql);
$addon_list = array();
$data = $db->fetch_array($addons_billing);
$package_info = array('id'=>$data['id'], 'name' => $data['name'], 'amount'=>$data['amount']);
}
return $package_info;
}
/**
* Gets package information
* @param int package id
* @return array package information
*/
public function getPackage($package_id) {
global $db;
$package_id = intval($package_id);
$sql = "SELECT * FROM ".$this->getTableName()." WHERE id = $package_id ";
$result = $db->query($sql);
$data = array();
if ($db->num_rows($result)> 0) {
$data = $db->fetch_array($result, 'ASSOC');
}
return $data;
}
public function getAllPackages($status = 0) {
global $db;
$status = intval($status);
$sql = "SELECT * FROM ".$this->getTableName()." WHERE is_hidden = $status";
$result = $db->query($sql);
$data = array();
if ($db->num_rows($result)> 0) {
while($package= $db->fetch_array($result, 'ASSOC')) {
$data[$package['id']]=$package;
}
}
return $data;
}
}