-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggbn.agi
59 lines (48 loc) · 1.42 KB
/
ggbn.agi
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
#!/usr/bin/php -q
<?php
//FreePBXブートストラップ
require_once('/etc/freepbx.conf');
//AGI環境をセットアップ
include("phpagi.php");
$AGI = new AGI();
//結果保存用変数初期化
$result = "";
//ログを出力
$AGI->verbose("gnbn.agi starting up");
//CID取得 - 指定がない場合は処理終了
if(isset($argv[1])){
$number = $argv[1];
}else{
$AGI->verbose("No number provided, exiting.");;
$AGI->set_variable($result, 'error');
exit;
}
//データベース接続を初期化
global $db;
$sql = "SELECT * FROM contactmanager_groups ";
$sql .= "LEFT OUTER JOIN contactmanager_group_entries ON contactmanager_groups.id = contactmanager_group_entries.groupid ";
$sql .= "LEFT OUTER JOIN contactmanager_entry_numbers ON contactmanager_group_entries.id = contactmanager_entry_numbers.entryid ";
$sql .= "WHERE number LIKE '%$number%'";
//SQLを実行
$res = $db->prepare($sql);
$res->execute();
//戻り値をチェック
if (DB::IsError($res)) {
//エラー処理
error_log( "SQL Error<br>($sql)<br>\n" . $res->getMessage() . "\n<br>\n");
}else{
$row = $res->fetchAll(PDO::FETCH_ASSOC);
if(count($row) > 0){
foreach($row as $group){
$result = $group['name'];
}
}else{
$result = "No group found";
}
}
//ログに結果を出力
$AGI->verbose("Group : ".$result);
//asteriskチャネル変数に結果を出力
$AGI->set_variable("gn", $result);
exit;
?>