1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 | /**
|
---|
3 | * Report Class
|
---|
4 | *
|
---|
5 | * @author dzungnv02
|
---|
6 | *
|
---|
7 | */
|
---|
8 |
|
---|
9 | class Report extends MX_Controller {
|
---|
10 |
|
---|
11 | private $_server = null;
|
---|
12 |
|
---|
13 | function __construct() {
|
---|
14 | parent::__construct ();
|
---|
15 | ini_set ( "soap.wsdl_cache_enabled", "1" );
|
---|
16 | $this->_server = new SoapServer ( NULL, array (
|
---|
17 | 'soap_version' => SOAP_1_2,
|
---|
18 | 'encoding' => 'UTF-8',
|
---|
19 | 'uri' => 'http://tempuri.org/'
|
---|
20 | ) );
|
---|
21 | }
|
---|
22 |
|
---|
23 | function __destruct() {
|
---|
24 | ini_set ( "soap.wsdl_cache_enabled", "0" );
|
---|
25 | }
|
---|
26 |
|
---|
27 | public function index() {
|
---|
28 | if ($this->uri->segment ( 3 ) == "wsdl") {
|
---|
29 | header ( 'Content-Type: text/xml; charset: utf-8' );
|
---|
30 | $this->load->view ( 'reportwsdl' );
|
---|
31 | return;
|
---|
32 | }
|
---|
33 | else {
|
---|
34 | header ( 'Content-Type: text/html; charset: utf-8' );
|
---|
35 | echo '<div>See Report service <a href="', base_url (), 'violetservice/report/wsdl">WSDL page</a></div>';
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public function get() {
|
---|
40 | function revenueReport () {
|
---|
41 | $aryArgs = func_get_args ();
|
---|
42 | list ( $username, $password, $fromDate, $toDate) = $aryArgs;
|
---|
43 |
|
---|
44 | $CI = & get_instance ();
|
---|
45 | if (!$toDate) $toDate = date('Y-m-d');
|
---|
46 | $message = validate ($aryArgs);
|
---|
47 | $success = $message == '' ? 1 : 0;// 0:error; 1:Success;
|
---|
48 |
|
---|
49 | if ($success == 1) {
|
---|
50 | $CI->load->model ( 'Services_model' );
|
---|
51 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
52 | $from = explode('-', $fromDate);
|
---|
53 | $to = explode('-', $toDate);
|
---|
54 | $input = array('year' => $from[0], 'month' => $from[1], 'to_year' => $to[0], 'to_month' => $to[1], 'to_date' => $to[2]);
|
---|
55 | $result = $CI->objReportModel->exportProvince( $input );
|
---|
56 |
|
---|
57 | if (count($result) > 0 && is_array($result)) {
|
---|
58 | //1|20140915|A076|0|0|0|100000|0|0
|
---|
59 | $aryTmp = array();
|
---|
60 | $aryResult = array();
|
---|
61 | foreach ($result as $provinceCode => $record) {
|
---|
62 | //No|toDate|ProvCode|TBngay|LKTBThang|TongTBNam|DTngay|LuyKeTBThang|TongDTNam
|
---|
63 | $aryTmp[] = $record['stt'];
|
---|
64 | $aryTmp[] = implode('', $to);
|
---|
65 | $aryTmp[] = $provinceCode;
|
---|
66 | $aryTmp[] = $record['tbng'];
|
---|
67 | $aryTmp[] = $record['tbt'];
|
---|
68 | $aryTmp[] = $record['tbn'];
|
---|
69 | $aryTmp[] = $record['dtng'];
|
---|
70 | $aryTmp[] = $record['dtt'];
|
---|
71 | $aryTmp[] = $record['dtn'];
|
---|
72 | $aryResult[] = implode('|', $aryTmp);
|
---|
73 | $aryTmp = array();
|
---|
74 | }
|
---|
75 |
|
---|
76 | $message = implode("\n", $aryResult);
|
---|
77 | $success = 1;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | return array($message, $success, date('YmdHis'));
|
---|
82 | }
|
---|
83 |
|
---|
84 | function subscribersReport () {
|
---|
85 | $aryArgs = func_get_args ();
|
---|
86 | list ( $username, $password, $fromDate, $toDate) = $aryArgs;
|
---|
87 |
|
---|
88 | $CI = & get_instance ();
|
---|
89 | $message = validate ($aryArgs);
|
---|
90 | $success = $message == '' ? 1 : 0;// 0:error; 1:Success;
|
---|
91 | $message = $message == '' ? 'subscribersReport' : $message;
|
---|
92 |
|
---|
93 | $CI->load->model ( 'Services_model' );
|
---|
94 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
95 |
|
---|
96 | return array($message, $success, date('YmdHis'));
|
---|
97 | }
|
---|
98 |
|
---|
99 | function validate ($aryArgs) {
|
---|
100 | list ( $username, $password, $fromDate, $toDate) = $aryArgs;
|
---|
101 |
|
---|
102 | $CI = & get_instance ();
|
---|
103 | $predefUsername = $CI->config->item ( 'report_username' );
|
---|
104 | $predefPassword = $CI->config->item ( 'report_password' );
|
---|
105 |
|
---|
106 | $message = '';
|
---|
107 |
|
---|
108 | if (! $username) {
|
---|
109 | $message = 'Username is required!';
|
---|
110 | }else if (! $password) {
|
---|
111 | $message = 'Password is required!';
|
---|
112 | }else if ($username != $predefUsername) {
|
---|
113 | $message = 'Username is not corrected!';
|
---|
114 | }else if ($password != $predefPassword) {
|
---|
115 | $message = 'Password is not corrected!';
|
---|
116 | }else if (! $fromDate) {
|
---|
117 | $message = 'fromDate is required!';
|
---|
118 | }else if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $fromDate)) {
|
---|
119 | $message = 'fromDate is not corrected!';
|
---|
120 | }else if ($toDate && !preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $toDate)) {
|
---|
121 | $message = 'toDate is not corrected!';
|
---|
122 | }
|
---|
123 |
|
---|
124 | return $message;
|
---|
125 | }
|
---|
126 |
|
---|
127 | $this->_server->addFunction ( array('revenueReport', 'subscribersReport'));
|
---|
128 |
|
---|
129 | try {
|
---|
130 | ob_start ();
|
---|
131 | $soapOutput = '';
|
---|
132 | $request = '';
|
---|
133 | $this->_server->handle ();
|
---|
134 |
|
---|
135 | if (ob_get_length () > 0) {
|
---|
136 | $soapOutput = ob_get_clean ();
|
---|
137 | }
|
---|
138 |
|
---|
139 | if ($soapOutput != '') {
|
---|
140 | error_log(var_export($soapOutput, true) . "\n\n\n", 3, '/srv/www/sbg/log/reportservicexml.log');
|
---|
141 |
|
---|
142 | $response = preg_match('/revenueReportResponse/', $soapOutput) ? 'revenueReportResponse' : (preg_match('/subscribersReportResponse/', $soapOutput) ? 'subscribersReportResponse':'');
|
---|
143 |
|
---|
144 | $pattern = '/<[^>]*[^\/]>/i';
|
---|
145 | $aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
---|
146 | error_log(var_export($aryOutput, true) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log');
|
---|
147 | $aryData = array ();
|
---|
148 | $aryData ['message'] = $aryOutput [1];
|
---|
149 | $aryData ['success'] = $aryOutput [2];
|
---|
150 | $aryData ['receiveTime'] = $aryOutput [3];
|
---|
151 | $aryData ['response'] = $response;
|
---|
152 | $xml = $this->load->view ( 'report', $aryData, TRUE );
|
---|
153 | header ( 'Content-Type: text/xml; charset: utf-8' );
|
---|
154 | echo $xml;
|
---|
155 | } else {
|
---|
156 | header ( 'Content-Type: text/html; charset: utf-8' );
|
---|
157 | echo 'See service <a href="' . base_url () . 'violetservice/report/wsdl">WSDL page</a>';
|
---|
158 | }
|
---|
159 | } catch ( Exception $e ) {
|
---|
160 | $this->_server->fault ( 'Sender', $e->getMessage () );
|
---|
161 | }
|
---|
162 | }
|
---|
163 | } |
---|