/
index.php
181 lines (159 loc) · 4.1 KB
/
index.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
<?php
define('DOMAIN','http://example.com');
define("DB_HOST", 'localhost');
define('USER','root');
define('PASS','passwd');
define('DB','ussd_session');
// var_dump($_REQUEST);die;
//echo '/ussd_framework/autoload.php';echo realpath('/ussd_framework/autoload.php');
require_once('autoload.php');
$data = @$_REQUEST['msg'];
$msisdn = @$_REQUEST['msisdn'];
$network = @$_REQUEST['network'];
$session = new ussd($msisdn);
$conf = array(
'short_code' => array('*717*30','*524*30','*718*30'),
'root_menu_chars' => array('0#'),
'back_chars' => array('*','0'),
'clear_session_chars' => array('0#', '*#'),
'remain_on_current_if_no_choice' => true,
//user db settings
//user db settings // may be unsed
'db_host' => DB_HOST,
'db_name' => DB,
'db_user' => USER,
'db_password' => PASS,
//serialize and deserialize session to/from db
'persist_sessions' => true,
//debugging
'debug' => !true,
'debug_session' => false,
'debug_menu' => false
);
$helper = new nav($session, get_pages(),$conf);
// $m = array("msisdn = $msisdn, data = $data");
// send_response_to_gateway('showMenu',$m,'');
// exit();
error_reporting(E_ALL);
nav::init($msisdn);
function &session(){
global $session;
return $session;
}
function &ussd(){
global $helper;
return $helper;
}
function getData(){
return @$_REQUEST['msg'];
}
function network(){
if(!isset($_REQUEST['network'])){
return 'network';
}
return @strtoupper($_REQUEST['network']);
}
function msisdn(){
if(!isset($_REQUEST['msisdn'])){
return 'msisdn';
}
return @$_REQUEST['msisdn'];
}
function clear_session(){
ussd::destroy();
}
function get_pages(){
return get_grouping_pages();
}
function get_grouping_pages(){
//landing area
$actions = array(
'0' => // root page
array(
'action' => array(),
'init' => function(){
// user dialed the short code
nav::show_page(array('page'=>'welcome_page'));
},
'inputComplete' => function(){
}),
'welcome_page' =>
array(
'action' => array(
'1' => function(){
nav::show_page(array('page'=>'enter_name'));
},
'2' => function(){
nav::show_page(array('page'=>'about'));
},
'3' => function(){
$menus = array(
'Good Bye , You Can Access Groupings By Dialing *718*30# On Any Network',
);
nav::display_prompt($menus);
}),
'init' => function(){
$menus = array(
'Welcome To GroupIns'.PHP_EOL,
'1. Enter Name',
'2. My Details',
'3. Exit',
);
nav::display($menus);
},
'inputComplete' => function(){
}),
'enter_name' =>
array(
'action' => array(),
'init' => function($d){
$title = array(
'Enter your Name:'
);
if( $d &&is_string($d)){
$title = $d;
}
nav::await_input('name','',$title);
},
'inputComplete' => function(){
nav::show_page(array('page'=> 'enter_age'));
}),
'enter_age' =>
array(
'action' => array(),
'init' => function($d){
$title = 'Enter Your Age ';
if( $d &&is_string($d)){
$title = $d;
}
nav::await_input('age','',$title);
},
'inputComplete' => function(){
nav::show_page(array('page'=>'about'));
}),
'about' =>
array(
'action' => array(
'1' => function(){
nav::show_page(array('page'=>'enter_name'));
},
'2' => function(){
nav::show_page(array('page'=>'enter_age'));
}),
'init' => function(){
$name = ussd::getDataItem('name') ? ussd::getDataItem('name') : "Mr Beans";
$age = ussd::getDataItem('age') ? ussd::getDataItem('age') : "Just 365";
$menus = array(
"About Me",
"Your Name Is " . $name,
"You Are " .$age." Years Old",
"Press 1 to Change Your Name , 2 To Change Your Age",
);
nav::display($menus);
},
'inputComplete' => function(){
}),
);
return $actions;
}
?>