· 7 years ago · Jan 09, 2019, 08:32 AM
1<?php
2if(isset($_GET["id"])){
3 include 'db_connection.php';
4 // Get the Client IP
5 $ip = $_SERVER['REMOTE_ADDR'];
6 // Get id param as string
7 $key = htmlspecialchars($_GET["id"]);
8 $key = strtoupper($key);
9 // Check if id param is bad
10 if(!preg_match("/^([A-Z0-9]){23}+$/", $key))
11 die("loso zadaden key: ili ne e tocno 23karakteri ili sodrzi nesto drugo od bukvi i brojki");
12 // Open conection with db
13 $conn = OpenCon();
14 // If Table Exists
15 if($conn->query("DESCRIBE cache")) {
16 echo "exists";
17 }
18 // ELSE IF Table Does Not Exists
19 else {
20
21 //Get the wsdl
22 $wsdl = dirname(__FILE__) . '/wsdl/eShop_WSDL.wsdl';
23 //Try to make Soap Request with the wsdl
24 try{
25 $client = new SoapClient($wsdl);
26 //Set location of the WS
27 $client->__setLocation('http://10.245.89.25:8020/WSDL/eShopService.serviceagent/AddEshopOrder');
28 //Call checkRewardsUrl method with given id parameter
29 $response = $client->checkRewardsUrl(array("id" => $key));
30
31 IF(isset($response->subscriberId)){
32 // sql to create table
33 $sql = "CREATE TABLE cache (
34 `id` INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
35 `key` VARCHAR(500),
36 `offer1` VARCHAR(500),
37 `offer2` VARCHAR(500),
38 `offer3` VARCHAR(500),
39 `valid_to` DATE
40 )";
41
42 // Check if table is successfully created
43 if ($conn->query($sql) === FALSE) {
44 die("error creating table " . $conn->error);
45 }
46
47 //Set the parameters returned from WS
48 $subscriberId = $response->subscriberId;
49 $msisdn = $response->msisdn;
50 $offer1 = $response->offer1;
51 $offer2 = $response->offer2;
52 $offer3 = $response->offer3;
53 $validTo = $response->validTo;
54 $pos = strrpos($validTo, "T");
55 $validTo = substr($validTo, 0, $pos);
56
57 // sql to insert record when first time page loaded
58 $sql = "INSERT INTO `cache`(`key`,`offer1`,`offer2`,`offer3`,`valid_to`)
59 VALUES('" . $subscriberId . "','" . $offer1 . "','" . $offer2 . "','" . $offer3 . "','" . $validTo . "')";
60 if($conn->query($sql) === FALSE){
61 die("error inserting into table cache " . $conn->error);
62 }
63 }
64 }
65 catch(Exception $e){
66 echo "<h2>Exception Error!</h2>";
67 echo $e->getMessage();
68 }
69
70
71
72
73 }
74 CloseCon($conn);
75
76
77}
78else {
79 die("Error");
80}
81?>
82<html>
83<head>
84</head>
85<body>
86
87
88
89</body>
90</html>