-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_offers.php
517 lines (408 loc) · 14.7 KB
/
list_offers.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<?php
include_once('connect.php');
include('functions.php');
include('./inc/cleeng/cleeng_api.php');
// Check for a valid user ID, through GET or POST:
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<p class="error">This page has been accessed in error.</p>';
//include footer maybe
exit();
}
$config = getClientConfig($id);
//get total item count
$cleengApi = new Cleeng_Api();
if (cleeng_sandbox == '1') {
$cleengApi->enableSandbox();
$cleengApi->setPublisherToken(cleeng_sandbox_token);
} else {
$cleengApi->setPublisherToken(cleeng_token);
}
$offerOptions = array(
'associateEmail' => $config['cleeng_email'],
'active' => 1,
);
$offerList = $cleengApi->listPassOffers($offerOptions, 0, 5);
$totalOffers = $offerList->totalItemCount;
echo 'There are ' . $totalOffers . ' total offers.<br><br>';
//get total number of api queries to get all results
$startCount = 0;
$totalRuns = $totalOffers / 50;
$totalRuns = ceil($totalRuns);
//set up array to hold returned offers
$masterOfferList = array();
for ($i=0; $i < $totalRuns; $i++) {
$cleengApi = new Cleeng_Api();
if (cleeng_sandbox == '1') {
$cleengApi->enableSandbox();
$cleengApi->setPublisherToken(cleeng_sandbox_token);
} else {
$cleengApi->setPublisherToken(cleeng_token);
}
$offerOptions = array(
'associateEmail' => $config['cleeng_email'],
'active' => 1,
);
$offerList = $cleengApi->listPassOffers($offerOptions, $startCount, 50);
foreach ($offerList->items as $offer) {
$masterOfferList[] = $offer;
}
$subOfferList = $cleengApi->listSubscriptionOffers($offerOptions, $startCount, 50);
foreach ($subOfferList->items as $offer) {
$masterOfferList[] = $offer;
}
$startCount = $startCount + 50;
}
/*
foreach ($masterOfferList as $offer) {
echo $offer->title . '<br>';
echo $offer->id . '<br>';
echo $offer->publisherEmail . '<br>';
echo $offer->url . '<br>';
echo $offer->description . '<br>';
echo $offer->currency . '<br>';
echo $offer->price . '<br>';
foreach ($offer->tags as $tag) {
echo $tag . ", ";
}
echo '<br>';
echo $offer->contentType . '<br>';
echo '<hr>';
}
*/
?>
<hr>
old code resumes here
<?php
//old code resumes here
//get total list of offers
$cleengApi = new Cleeng_Api();
if (cleeng_sandbox == '1') {
$cleengApi->enableSandbox();
$cleengApi->setPublisherToken(cleeng_sandbox_token);
} else {
$cleengApi->setPublisherToken(cleeng_token);
}
$offerOptions = array(
'associateEmail' => $config['cleeng_email'],
'active' => 1,
);
$offerList = $cleengApi->listPassOffers($offerOptions, 0, 50);
$totalOffers = $offerList->totalItemCount;
echo 'There are ' . $totalOffers . ' total offers.<br><br>';
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src='./js/pajinate/jquery.pajinate.min.js'></script>
<script>
$(document).ready(function () {
$("#page_container").pajinate();
});
</script>
</head>
<body>
<?php include('menu.php'); ?>
<div id="wrapper">
<h2>Assign Client Offers</h2>
<?php
//echo var_dump($masterOfferList); //this is the raw response to be decoded
echo '<br><br>';
echo '<br><br>';
// use totaloffers to set the value for the array to make sure all offers are grabbed
/* this may be used for pagination
$count = 0;
while ($count < $totalOffers) {
echo $offerList->items[$count]->title . '<br>';
echo $offerList->items[$count]->id . '<br>';
// echo $offer->publisherEmail . '<br>';
// echo $offer->url . '<br>';
// echo $offer->description . '<br>';
// echo $offer->currency . '<br>';
// echo $offer->price . '<br>';
// echo $offer->tags[1] . '<br>';
// echo $offer->contentType . '<br>';
echo '<hr>';
$count = $count + 1;
} */
?>
<div id="page_container"style="border:1px solid #000;">
<div id="header-row">
<div class="table-header" style="width:20%;"> Offer Title </div>
<div class="table-header" style="width:10%;">Offer ID</div>
<div class="table-header" style="width:8%;">Email</div>
<div class="table-header" style="width:11%;">URL</div>
<div class="table-header" style="width:11%;">Date Created</div>
<div class="table-header" style="width:12%;">Last Updated</div>
<div class="table-header" style="width:3%;">Curr.</div>
<div class="table-header" style="width:3%;">Price</div>
<div class="table-header" style="width:8%;">Tags</div>
<div class="table-header" style="width:4%;">Options</div>
</div>
<div class="content">
<?php
foreach ($masterOfferList as $offer) { ?>
<div id="table-row" class="table-row">
<div class="table-cell" style="width:20%;">
<?php echo $offer->title;?>
</div>
<div class="table-cell" style="width:10%;">
<?php echo $offer->id;?>
</div>
<div class="table-cell" style="width:8%;">
<?php echo $offer->publisherEmail;?>
</div>
<div class="table-cell" style="width:11%;">
<?php echo $offer->url;?>
</div>
<div class="table-cell" style="width:11%;">
<?php
$dateconvert = $offer->createdAt;
echo gmdate("m-d-Y", $dateconvert);
?>
<br>
<?php
echo gmdate('TH:i:s\Z', $dateconvert);
?>
</div>
<div class="table-cell" style="width:12%;">
<?php
$dateconvert = $offer->updatedAt;
echo gmdate("m-d-Y", $dateconvert);
?>
<br>
<?php
echo gmdate('TH:i:s\Z', $dateconvert);
?>
</div>
<div class="table-cell" style="width:3%;">
<?php echo $offer->currency;?>
</div>
<div class="table-cell" style="width:3%;">
<?php echo $offer->price;?>
</div>
<div class="table-cell" style="width:8%;">
<?php
foreach ($offer->accessToTags as $tag) {
echo $tag . ", ";
}?>
</div>
<div class="table-cell" style="width:4%;">
<a href="edit_offer.php?id=<?php echo $id; ?>&offer=<?php echo $offer->id;?>">Edit Offer</a>
</div>
</div>
<?php }; ?>
</div>
<div class="page_navigation"></div>
</div>
</div>
<h2>Create New Pass Offer:</h2>
<form action="list_offers.php?id=<?php echo $config['clientid']; ?>" method="post">
<p>Offer Title: <input type="text" name="title" size="60" maxlength="60" value="" /></p>
<p>URL: <input type="text" name="url" size="60" maxlength="60" value="" /></p>
<p>Price: <input type="text" name="price" size="60" maxlength="60" value="" /></p>
<p>Offer Description: <input type="text" name="desc" size="120" maxlength="120" value="" /></p>
<p>Expires on Date (unix date): <input type="text" name="exp_date" size="120" maxlength="120" value="" /></p>
<h4>Add Tags:</h4>
<?php
$cats = getClientCategories($id);
foreach ($cats as $cat) {
# code...
?>
<input type="checkbox" name="tags[]" value="<?php echo $cat['slug'] ?>" /><?php echo $cat['name']; ?> <br />
<?php
}
?>
<input type="checkbox" name="tags[]" value="Year2015" />2015-2016 <br />
<input type="checkbox" name="tags[]" value="Year2016" />2016-2017 <br />
<input type="checkbox" name="tags[]" value="fall" />Fall <br />
<input type="checkbox" name="tags[]" value="winter" />Winter <br />
<input type="checkbox" name="tags[]" value="spring" />Spring <br /><br>
Renews:
<select name="period">
<option value="month">Monthly</option>
<option value="year">Yearly</option>
</select>
<br><br>
<input class="create-button" type="submit" value="Create" tabindex="6" id="submit" name="submit" />
<input type="hidden" name="newoffer" value="post" />
</form>
</div>
<h2>Create New Subscription Offer:</h2>
<form action="list_offers.php?id=<?php echo $config['clientid']; ?>" method="post">
<p>Offer Title: <input type="text" name="title" size="60" maxlength="60" value="" /></p>
<p>URL: <input type="text" name="url" size="60" maxlength="60" value="" /></p>
<p>Price: <input type="text" name="price" size="60" maxlength="60" value="" /></p>
<p>Offer Description: <input type="text" name="desc" size="120" maxlength="120" value="" /></p>
<p>Expires on Date (unix date): <input type="text" name="exp_date" size="120" maxlength="120" value="" /></p>
<h4>Add Tags:</h4>
Renews:
<select name="period">
<option value="month">Monthly</option>
<option value="year">Yearly</option>
</select>
<br><br>
<input class="create-button" type="submit" value="Create" tabindex="6" id="submit" name="submit" />
<input type="hidden" name="newSuboffer" value="post" />
</form>
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['newoffer'] )) {
$offerSetup = array(
'title' => $_POST['title'],
'price' => $_POST['price'],
'url' => $_POST['url'],
'description' => $_POST['desc'],
'period' => $_POST['period'],
'accessToTags' => $_POST['tags'],
'associateEmail' => $config['cleeng_email'],
);
$cleengApi = new Cleeng_Api();
if (cleeng_sandbox == '1') {
$cleengApi->enableSandbox();
$cleengApi->setPublisherToken(cleeng_sandbox_token);
} else {
$cleengApi->setPublisherToken(cleeng_token);
}
$offer = $cleengApi->createPassOffer($offerSetup);
if ($offer->id) {
Echo "Pass Offer Created Sucessfully.";
} else {
echo "ERROR.";
}
}
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['newSuboffer'] )) {
$offerSetup = array(
'title' => $_POST['title'],
'price' => $_POST['price'],
'url' => $_POST['url'],
'description' => $_POST['desc'],
'period' => $_POST['period'],
'accessToTags' => '(all)',
'associateEmail' => $config['cleeng_email'],
);
$cleengApi = new Cleeng_Api();
if (cleeng_sandbox == '1') {
$cleengApi->enableSandbox();
$cleengApi->setPublisherToken(cleeng_sandbox_token);
} else {
$cleengApi->setPublisherToken(cleeng_token);
}
$offer = $cleengApi->createSubscriptionOffer($offerSetup);
if ($offer->id) {
Echo "Subscription Offer Created Sucessfully.";
} else {
echo "ERROR.";
}
}
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['updateOffers'] )) {
$offerTable = $config['memberid'] . '_static_offers';
$q = "TRUNCATE $offerTable ;";
echo $q;
//execute the query added client information
$r = @mysqli_query ($dbc, $q);
// insert SQL query here to add sport cats to table
$num = 1;
$i=0;
$dbc = mysqli_connect(dbhost, dbuser, dbpassword, dbname) or die('Error connecting to Database!' . mysqli_connect_error() );
foreach ($cats as $cat) {
$sportname = $cat['slug'];
$sportoffer = $_POST['sport_offer'][$i];
echo $sportoffer . ", " . "sport, " . $sportname;
$q = "INSERT INTO $offerTable (cleeng_id, offer_type, sport ) VALUES ('$sportoffer', 'sport', '$sportname');";
echo $q;
//execute the query added client information
$r = @mysqli_query ($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
// Print a message:
echo '<p><strong>The sport offer has been added.</strong></p>';
} else { // If it did not run OK.
echo '<p class="error">The sport offer could not be added due to a system error. We apologize for any inconvenience.</p>'; // Public message.
echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
}
$i++;
}
// insert SQL query here to add 4 mains offers to table
//replace with loop of come sort and get rid of multi query
$allaccess = $_POST['allaccess'];
$fallseason = $_POST['fallseason'];
$winterseason = $_POST['winterseason'];
$springseason = $_POST['springseason'];
// Make the query:
$offerTable = $config['memberid'] . '_static_offers';
$q = "INSERT INTO $offerTable (cleeng_id, offer_type, sport ) VALUES ('$allaccess', 'all_access', 'NULL');";
$q.= "INSERT INTO $offerTable (cleeng_id, offer_type, sport ) VALUES ('$fallseason', 'fall', 'NULL');";
$q.= "INSERT INTO $offerTable (cleeng_id, offer_type, sport ) VALUES ('$winterseason', 'winter', 'NULL');";
$q.= "INSERT INTO $offerTable (cleeng_id, offer_type, sport ) VALUES ('$springseason', 'spring', 'NULL');";
//execute the query added client information
$r = @mysqli_multi_query ($dbc, $q);
//flush queries otherwise the rest wont work
// flush multi_queries
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
// Print a message:
echo '<p><strong>The fixed offers have been assigned.</strong></p>';
} else { // If it did not run OK.
echo '<p class="error">The offers could not be assigned due to a system error. We apologize for any inconvenience.</p>'; // Public message.
echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
} //end sql verification IF
mysqli_close($dbc);
} // end post submit IF
?>
<!-- ////////////////////////////////////////////////////////////////////////////////////////////// -->
<!-- Create Offer Selector for Static Offers -->
<!-- ////////////////////////////////////////////////////////////////////////////////////////////// -->
<h2>Set Client Offers</h2>
<form action="list_offers.php?id=<?php echo $config['clientid']; ?>" method="post">
<p>Current All Access Offer:
<select name="allaccess">
<?php
foreach ($masterOfferList as $offer) { ?>
<option name="allaccessoption" value = "<?php echo $offer->id; ?>" ><?php echo $offer->id . " - " . $offer->title; ?></option>
<?php } ?>
</select></p>
<p>Current Fall Season Offer:
<select name="fallseason">
<?php
foreach ($masterOfferList as $offer) { ?>
<option name="falloption" value = "<?php echo $offer->id; ?>" ><?php echo $offer->id . " - " . $offer->title; ?></option>
<?php } ?>
</select></p>
<p>Current Winter Season Offer:
<select name="winterseason">
<?php
foreach ($masterOfferList as $offer) { ?>
<option name="winteroption" value = "<?php echo $offer->id; ?>" ><?php echo $offer->id . " - " . $offer->title; ?></option>
<?php } ?>
</select></p>
<p>Current Spring Season Offer:
<select name="springseason">
<?php
foreach ($masterOfferList as $offer) { ?>
<option name="springoption" value = "<?php echo $offer->id; ?>" ><?php echo $offer->id . " - " . $offer->title; ?></option>
<?php } ?>
</select></p>
<!-- ////////////////////////////////////////////////////////////////////////////////////////////// -->
<!-- Create Offer Selector for Each sport -->
<!-- ////////////////////////////////////////////////////////////////////////////////////////////// -->
<h4>Individual Sport Offers</h4>
<?php
//create entry for each sport(category)
$num = 1;
foreach ($cats as $cat) {
?>
<p>Current <?php echo $cat['name']; ?> Sport Offer:
<select name="sport_offer[]">
<?php foreach ($masterOfferList as $offer) { ?>
<option name="<?php echo $cat['slug']; ?>" value = "<?php echo $offer->id; ?>" ><?php echo $offer->id . " - " . $offer->title; ?></option>
<?php } ?>
</select>
</p>
<?php $num = $num + 1; } ?>
<input class="create-button" type="submit" value="Set Offers Now!" tabindex="6" id="submit" name="submit" />
<input type="hidden" name="updateOffers" value="post" />
</form>
</body>
</html>