-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcall.php
312 lines (297 loc) · 9.66 KB
/
call.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?
// ===================================================================
// License: GPL v3 (http://www.gnu.org/licenses/gpl.html)
// Copyright (c) 2016-2022 Xzero Systems, http://sim-roulette.com
// Author: Nikita Zabelin
// ===================================================================
include("_func.php");
$status=1;
$devices_=array();
$devices=array();
if ($result = mysqli_query($db, 'SELECT * FROM `devices` ORDER BY `title`'))
{
while ($row = mysqli_fetch_assoc($result))
{
$devices_[]=$row['id'];
$devices[$row['id']]=$row['title'];
}
}
if ($_GET['delete']=='all') // Delete all Call | Удаление всех входящих вызовов
{
$qry='DELETE FROM `call_incoming`
WHERE `device` in ('.implode(',',$devices_).')';
mysqli_query($db,$qry);
header('location:call.php');
exit();
}
if ($_POST['delete']) // Deleting Call | Удаление входящего вызова
{
if (count($_POST['check']))
{
foreach ($_POST['check'] as $data)
{
$qry='DELETE FROM `call_incoming` WHERE `device` in ('.implode(',',$devices_).') AND `id`='.(int)$data;
mysqli_query($db,$qry);
}
}
}
sr_header("Список входящих вызовов"); // Output page title and title | Вывод титул и заголовок страницы
$table=array();
$where=array();
if (!$_GET['page']){$_GET['page']=1;}
$limit=' LIMIT '.((int)$GLOBALS['set_data']['page_limit']*($_GET['page']-1)).','.(int)$GLOBALS['set_data']['page_limit'];
if ($_GET['number'])
{
$where[]="c.number LIKE '%".(int)$_GET['number']."%'";
}
if ($_GET['incoming'])
{
$where[]="s.incoming LIKE '%".(int)$_GET['incoming']."%'";
}
if ($_GET['operator'])
{
$where[]="(o1.title LIKE '%".mysqli_real_escape_string($db,$_GET['operator'])."%' OR o1.`name` LIKE '%".mysqli_real_escape_string($db,$_GET['operator'])."%' OR o2.title LIKE '%".mysqli_real_escape_string($db,$_GET['operator'])."%' OR o2.`name` LIKE '%".mysqli_real_escape_string($db,$_GET['operator'])."%')";
}
if ($_GET['device'])
{
$where[]="c.device=".(int)$_GET['device'];
}
if ($_GET['place'])
{
$where[]="c.place LIKE '".mysqli_real_escape_string($db,$_GET['place'])."%'";
}
if ($_GET['balance'])
{
$a=str_replace(',','.',$_GET['balance']);
if ($_GET['balance'][0]!='>' && $_GET['balance'][0]!='<')
{
$where[]="c.balance=".mysqli_real_escape_string($db,$a);
}
else
{
$where[]="c.balance".mysqli_real_escape_string($db,$a);
}
}
if (count($where)){$where=' AND '.implode(' AND ',$where);} else {$where='';}
if (!$_GET['sort'])
{
$order=' ORDER BY s.`time` DESC';
}
elseif ($_GET['sort']==1)
{
$order=' ORDER BY c.`device`,s.`time` DESC';
}
elseif ($_GET['sort']==2)
{
$order=' ORDER BY c.`place`,c.`device`,s.`time` DESC';
}
elseif ($_GET['sort']==3)
{
$order=' ORDER BY c.`balance`,s.`time` DESC';
}
elseif ($_GET['sort']==4)
{
$order=' ORDER BY c.`operator`';
}
elseif ($_GET['sort']==5)
{
$order=' ORDER BY c.`number`,s.`time` DESC';
}
elseif ($_GET['sort']==6)
{
$order=' ORDER BY s.`incoming`,s.`time` DESC';
}
$operators=array();
$qry='SELECT count(s.id) AS counter FROM `call_incoming` s
LEFT JOIN `cards` c ON s.`number`=c.`number` AND s.`done`=1
LEFT JOIN `operators` o1 ON o1.`name` LIKE CONCAT("%;",c.`operator`,";%")
LEFT JOIN `devices` d ON s.`device`=d.`id`
WHERE s.`device` in ('.implode(',',$devices_).')'.$where;
if ($result = mysqli_query($db, $qry))
{
if ($row = mysqli_fetch_assoc($result))
{
$total=$row['counter'];
}
}
$qry='SELECT c.*, o1.`title` AS `operator_name`, o1.`color` AS `color`,s.incoming,s.time,s.number,s.id AS `call_id`,d.title AS device FROM `call_incoming` s
LEFT JOIN `cards` c ON (s.`number`=c.`number` OR s.`number`=c.`place`) AND s.`device`=c.`device`
LEFT JOIN `operators` o1 ON o1.`name` LIKE CONCAT("%;",c.`operator`,";%")
LEFT JOIN `devices` d ON s.`device`=d.`id`
WHERE s.`number`<>"" AND s.`device` in ('.implode(',',$devices_).')'.$where.$order.$limit;
//echo $qry;
if ($result = mysqli_query($db, $qry))
{
$n=1;
while ($row = mysqli_fetch_assoc($result))
{
if (hexdec($row['color'])>8388607 || !$row['color']){$color='000';} else {$color='FFF';}
$table[]=array(
'num'=>$n+$GLOBALS['set_data']['page_limit']*($_GET['page']-1),
'number'=>$row['number'],
'title'=>$row['title'],
'time'=>srdate('d.m.Y H:i:s',$row['time']),
'incoming'=>$row['incoming'],
'call_id'=>$row['call_id'],
'model'=>$row['model'],
'device'=>$row['device'],
'place'=>$row['place'],
'operator'=>$row['operator'],
'operator_name'=>$row['operator_name'],
'balance'=>$row['balance'],
'time_balance'=>$row['time_balance'],
'bg'=>$row['color'],
'color'=>$color,
);
if ($row['title']){$title_td=1;}
$n++;
}
}
$a=$_GET; unset($a['page']);
if (empty($a) && count($table)){echo '<div id="filter_hint" onclick="fltr();">Отфильтровать</div>';}
?>
<div id="filter"<? if (empty($a)){echo ' class="hide"';}?>>
<form method="get">
<div class="sidebar">
Номер телефона на который пришел вызов
</div>
<input type="text" name="number" value="<?=$_GET['number']?>" maxlength="15" placeholder="Часть телефонного номера. Пример: 903">
<div class="sidebar">
<br>
Номер телефона с которого пришел вызов
</div>
<input type="text" name="incoming" value="<?=$_GET['incoming']?>" maxlength="15" placeholder="Входящий номер. Пример: 903">
<div class="sidebar">
<br>
Оператор
</div>
<input type="text" name="operator" value="<?=$_GET['operator']?>" maxlength="15" placeholder="Название оператора. Пример: МТС">
<?
if (count($devices)>1)
{
?>
<div class="sidebar">
<br>
Агрегатор
</div>
<select name="device">
<option value="0">Все агрегаторы</option>
<?
foreach ($devices as $id=>$title)
{
?>
<option value="<?=$id?>"<? if ($_GET['device']==$id){echo ' selected=1';}?>><?=$title?></option>
<?
}
?>
</select>
<?
}
?>
<div class="sidebar">
<br>
Место
</div>
<input type="text" name="place" value="<?=$_GET['place']?>" maxlength="7" placeholder="Место. Примеры: A0 или A или 2-8 или 2">
<div class="sidebar">
<br>
Отсортировать
</div>
<select name="sort">
<option value="0"<? if (!$_GET['sort']){echo ' selected=1';}?>>По времени</option>
<option value="1"<? if ($_GET['sort']==1){echo ' selected=1';}?>>По агрегаторам</option>
<option value="2"<? if ($_GET['sort']==2){echo ' selected=1';}?>>По местам</option>
<option value="4"<? if ($_GET['sort']==4){echo ' selected=1';}?>>По операторам</option>
<option value="5"<? if ($_GET['sort']==5){echo ' selected=1';}?>>По номерам телефонов</option>
<option value="6"<? if ($_GET['sort']==6){echo ' selected=1';}?>>По входящим номерам</option>
</select>
<br>
<?
if ($total>(int)$GLOBALS['set_data']['page_limit'])
{
?>
<div class="sidebar">
<br>
Страница
</div>
<select name="page">
<?
$v=ceil($total/(int)$GLOBALS['set_data']['page_limit']);
for ($i=1;$i<=$v;$i++)
{
?>
<option value="<?=$i?>"<? if ($_GET['page']==$i){echo ' selected=1';}?>><?='Страница '.$i.' ('.((int)$GLOBALS['set_data']['page_limit']*($i-1)).'—'.((int)$GLOBALS['set_data']['page_limit']*$i).')'?></option>
<?
}
?>
</select>
<?
}
?>
<div class="sidebar" style="margin-bottom: 10px;"></div>
<input type="submit" name="save" value="Отфильтровать" style="padding: 10px; margin: 5px 0">
</form>
</div>
<?
if (count($table))
{
?>
<form method="post" id="call" name="call">
<div class="table_box">
<table class="table table_sort table_adaptive">
<thead>
<tr>
<th><input type="checkbox" onclick="SelectGroup(checked,'call','check')"></th>
<th class="sidebar">№</th>
<? if ($title_td){?><th class="sidebar">Имя</th><? } ?>
<? if (count($devices)>1){ ?>
<th class="sidebar">Агрегатор</th>
<? } ?>
<th>Место</th>
<th class="sidebar">Оператор</th>
<th>На номер</th>
<th>С номера</th>
<th>Время</th>
</tr>
</thead>
<?
$n=0;
foreach ($table as $data)
{
if ($data['time_balance']){$balance=balance_out($data['balance'],'').'<div class="legend">'.srdate('d.m.Y H:i',$data['time_balance']).'</div>';} else {$balance='—';}
?>
<tr>
<td><input type="checkbox" name="check[<?=$n++?>]" id="check" value="<?=$data['call_id']?>"></td>
<td class="sidebar"><?=$data['num']?></td>
<? if ($title_td){?><td class="sidebar"><?=$data['title']?></td><? } ?>
<? if (count($devices)>1){ ?>
<td class="sidebar" nowrap><?=$data['device']?></td>
<? } ?>
<td class="sidebar" align="right"><? if ($data['place']){echo $data['place'];} else {echo '—';} ?></td>
<td class="exttab" align="right"<? if ($data['color']){?> style="color: #<?=$data['color']?>; background:#<?=$data['bg']?>"<? } ?>><?=$data['place']?></td>
<td class="sidebar"<? if ($data['color']){?> style="color: #<?=$data['color']?>; background:#<?=$data['bg']?>"<? } ?> align="center"><?=$data['operator_name']?></td>
<td><? if ($data['number']){echo '+'.$data['number'];} else {echo '—';} if ($data['title']){?><span class="extinfo"><br><s><?=$data['title']?></s></span><? } ?>
</td>
<td><? if ($data['incoming']){echo '+'.$data['incoming'];} else {echo '—';}?></td>
<td><?=$data['time']?></td>
</tr>
<?
}
?>
</table>
</div>
<?=$scroller=scrollbar($total,$_GET['page'],$GLOBALS['set_data']['page_limit'],'page');?>
<br>
<input type="submit" name="delete" value="Удалить отмеченные вызовы" class="width">
<a href="call.php?delete=all" class="link width" style="background:#FF0000;">Удалить все вызовы</a>
</form>
<?
}
else
{
?>
<div class="tooltip">— Список входящих вызовов пуст!</div>
<?
}
sr_footer();
?>