forked from sirportly/whmcs-data-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
executable file
·137 lines (118 loc) · 4.1 KB
/
api.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include('../../../configuration.php');
include('../../../dbconnect.php');
include('../../../includes/functions.php');
include('../../../includes/adminfunctions.php');
include('../../../includes/countries.php');
include_once('sirportly.php');
if (!isset($_SERVER['PHP_AUTH_USER']))
{
header('WWW-Authenticate: Basic realm="Sirportly"');
header('HTTP/1.0 401 Unauthorized');
echo 'Unauthorized';
exit;
}
// Check to see for valid admin credentials
$admin = select_query('tbladmins', 'id', array('username' => $_SERVER['PHP_AUTH_USER'], 'password' => md5($_SERVER['PHP_AUTH_PW']) ));
if(mysql_num_rows($admin))
{
$admin = mysql_fetch_array($admin);
}
else
{
header('HTTP/1.1 404 Not Found');
echo 'Not Found';
die;
}
// get client details from db
$client = select_query('tblclients', '', array('email' => $_REQUEST['data']));
// check for valid client email
if(mysql_num_rows($client))
{
$client = mysql_fetch_array($client);
}
else
{
header('HTTP/1.1 404 Not Found');
echo 'Not Found';
die;
}
$current_fields = array();
$result = mysql_query('SELECT * FROM `sirportly`');
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$current_fields[$row[1]][$row[2]] = $row[2];
}
// prepare return
global $CONFIG, $customadminpath;
$api_results = array();
$api_results['contact_methods']['email'] = array($client['email']);
//Loop through the tblclients, tbldomains, tblhosting and tblinvoices tables.
foreach($current_fields as $this_table => $this_table_fields)
{
$id_field = ($this_table == 'tblclients' ? 'id' : 'userid');
$query = select_query($this_table, implode(',', $this_table_fields), array($id_field => $client['id']));
////////////////////////////////////
//WHMCS link
////////////////////////////////////
if ($this_table == 'tblclients')
{
$api_results[sirportly_lang('tblclients')]['WHMCS URL'] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/clientssummary.php?userid=' . $client['id'] . '|Profile';
}
////////////////////////////////////
if(mysql_num_rows($query) == 1)
{
$result = mysql_fetch_array($query, MYSQL_ASSOC);
foreach ($this_table_fields as $row_key => $row_value)
{
if($this_table == 'tbldomains' && $row_key == 'id')
{ //Domains
$api_results[sirportly_lang($this_table)][$row_key] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/clientsdomains.php?id=' . $result[$row_key] . '|' . $result[$row_key];
}
elseif($this_table == 'tblhosting' && $row_key == 'id')
{ //Service
$api_results[sirportly_lang($this_table)][$row_key] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/clientshosting.php?id=' . $result[$row_key] . '|' . $result[$row_key];
}
elseif($this_table == 'tblinvoices' && $row_key == 'id')
{ //Invoices
$api_results[sirportly_lang($this_table)][$row_key] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/invoices.php?action=edit&id=' . $result[$row_key] . '|' . $result[$row_key];;
}
else
{
$api_results[sirportly_lang($this_table)][$row_key] = $result[$row_key];
}
}
}
else
{
$result_block = array();
while ($result = mysql_fetch_array($query, MYSQL_ASSOC))
{
$row = array();
foreach ($this_table_fields as $row_key => $row_value)
{
if($this_table == 'tbldomains' && $row_key == 'id')
{ //Domains
$row[$row_key] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/clientsdomains.php?id=' . $result[$row_key] . '|' . $result[$row_key];
}
elseif($this_table == 'tblhosting' && $row_key == 'id')
{ //Service
$row[$row_key] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/clientshosting.php?id=' . $result[$row_key] . '|' . $result[$row_key];
}
elseif($this_table == 'tblinvoices' && $row_key == 'id')
{ //Invoices
$row[$row_key] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/invoices.php?action=edit&id=' . $result[$row_key] . '|' . $result[$row_key];
}
else
{
$row[$row_key] = $result[$row_key];
}
}
array_push($result_block, $row);
}
$api_results[sirportly_lang($this_table)] = $result_block;
}
}
header('HTTP/1.1 200 OK');
echo json_encode($api_results);
?>