-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.php
1137 lines (929 loc) · 41 KB
/
test.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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require 'vendor/autoload.php';
use ToolkitTester\ToolkitVersion;
use ToolkitTester\ToolkitSource;
use ToolkitTester\TransportType;
use ToolkitApi\UserSpace;
use ToolkitApi\DataQueue;
// Display errors in browser
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
ini_set('error_log', '/usr/local/zendsvr6/var/log/php-dev.log');
error_reporting(-1);
$version = $_GET['version'];
$source = $_GET['source'];
$transportType = $_GET['transportType'];
// Remove toolkit from global include path
$include_path = get_include_path();
$include_path_array = explode(':',$include_path);
$new_include_path = '';
foreach ($include_path_array as $path)
{
if (strpos($path,'ToolkitApi') === false)
{
$new_include_path .= $path;
}
}
set_include_path($new_include_path);
try {
$tester = new ToolkitTester\Tester();
$tester->getToolkit(
new ToolkitVersion($version),
new ToolkitSource($source),
new TransportType($transportType)
);
$tester->runAllTests();
// runCwTest();
} catch(Exception $e)
{
echo makePrettyException($e);
}
function makePrettyException(Exception $e) {
$trace = $e->getTrace();
$result = 'Exception: "';
$result .= $e->getMessage();
$result .= '" @ ';
if($trace[0]['class'] != '') {
$result .= $trace[0]['class'];
$result .= '::';
}
$result .= $trace[0]['function'];
$result .= '();<br><br>';
$trace = $e->getTrace();
foreach ($trace as $member)
{
if (isset($member['file']) && strlen($member['file']) > 0) {
$result .= $member['file'] . ' on line ' . $member['line'] . '<br>';
}
}
return $result;
}
function runCwTest()
{
// @todo need to somehow get ToolkitService so we can use getConfigValue()
// some items to turn on and off in the test
$doPcml = true;
$doUserSpace = true;
$doDataQueue = true;
$doPgmCallComplex = true;
$doPgmCallSimple = true;
$doObjectList = true;
$doJobLists = true;
$doJobLogs = true;
$doSpooledFiles = true;
$doAdoptAuthority = true;
ini_set('display_errors', 1);
set_time_limit(480);
// Include CW constants
$cw_const_path = __DIR__.'/vendor/zendtech/ibmitoolkit/ToolkitApi/CW/cwconstants.php';
if (!file_exists($cw_const_path))
{
throw new Exception("File ".$cw_const_path." doesn't exist");
}
require_once $cw_const_path;
$cw_path = __DIR__.'/vendor/zendtech/ibmitoolkit/ToolkitApi/CW/cw.php';
if (!file_exists($cw_path))
{
throw new Exception("File ".$cw_path." doesn't exist");
}
require_once $cw_path;
// require_once('CW/cw.php'); // don't need if added auto_append in PHP.INI
// Use configurable demo lib/name from toolkit ini
$demoLib = trim(getConfigValue('demo', 'demo_library'));
if (!$demoLib) {
die('Demo library not set in toolkit.ini.');
}
// Use configurable encoding from toolkit ini
// We use encoding in meta tag so characters appear correctly in browser
$encoding = trim(getConfigValue('system', 'encoding'));
if (!$encoding) {
die('Encoding not set in toolkit.ini. Example: ISO-8859-1');
}
// optional demo values
$setLibList = trim(getConfigValue('demo', 'initlibl', ''));
$setCcsid = trim(getConfigValue('demo', 'ccsid', ''));
$setJobName = trim(getConfigValue('demo', 'jobname', ''));
$setIdleTimeout = trim(getConfigValue('demo', 'idle_timeout', ''));
$transportType = trim(getConfigValue ( 'demo', 'transport_type', ''));
// optional demo connection values
$private = false; // default
$privateNum = false; // default
$persistent = trim(getConfigValue('demo', 'persistent', false));
if ($persistent) {
// private can only happen with persistence
$private = trim(getConfigValue('demo', 'private', false));
$privateNum = trim(getConfigValue('demo', 'private_num', '0'));
} //(persistent)
$scriptTitle = 'Test script for IBM i Compatibility Wrapper (CW)';
// TODO get test user from toolkit.ini
// this user, TKITU1, should exist on the system
$user = 'WEBTEST';
$testPw = 'WEBTEST';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $encoding ?>">
<style type="text/css">
body {
font: 15px;
}
h1 {
font: 28px arial,sans-serif;
font-weight: bold;
border-style: solid;
color: #2278A5;
border: 1px 1px 1px 1px;
padding: 2px 2px 2px 2px;
margin-bottom: 30px;
}
h2 {
font: 20px arial,sans-serif;
font-weight: bold;
background-color: lightblue;
}
</style>
<title><?php echo $scriptTitle; ?></title>
</head>
<?php
echo h1($scriptTitle);
echo h2('Version check');
// display CW version or warning message.
$downloadSite = 'http://www.youngiprofessionals.com/wiki/XMLSERVICE';
$downloadLink = '<a href="' . $downloadSite . '" target="_blank">' . $downloadSite . '</a>';
if (function_exists('i5_version')) {
echo "You are running CW version <b>" . i5_version() . "</b>.<BR> Any updates will be found at $downloadLink.<BR>";
} else {
echo "This version of CW is out of date.<BR>Please download the latest CW from $downloadLink.<BR><BR>";
}
echo h2('Connection');
// choose connection function based on persistence choice
$connFunction = ($persistent) ? 'i5_pconnect' : 'i5_connect';
echo "About to connect with $connFunction('', '', '') (feel free to specify a real user here)<BR>";
// options (liblist, ccsid, jobname) can be changed by the user in toolkit.ini.
$options = array();
if ($setLibList) {
$options[I5_OPTIONS_INITLIBL] = $setLibList;
echo "I5_OPTIONS_INITLIBL = '$setLibList'<BR>";
}
if ($setCcsid) {
$options[I5_OPTIONS_RMTCCSID] = $setCcsid;
echo "I5_OPTIONS_RMTCCSID = '$setCcsid'<BR>";
}
if ($setJobName) {
$options[I5_OPTIONS_JOBNAME] = $setJobName;
echo "I5_OPTIONS_JOBNAME = '$setJobName'<BR>";
}
if ($setIdleTimeout) {
$options[I5_OPTIONS_IDLE_TIMEOUT] = $setIdleTimeout;
echo "I5_OPTIONS_IDLE_TIMEOUT = '$setIdleTimeout'<BR>";
}
if ($transportType) {
$options[CW_TRANSPORT_TYPE] = $transportType;
echo "CW_TRANSPORT_TYPE = '$transportType'<BR>";
}
if ($persistent && $private) {
$options[I5_OPTIONS_PRIVATE_CONNECTION] = $privateNum;
echo "I5_OPTIONS_PRIVATE_CONNECTION = '$privateNum'<BR>";
} // (private and privateNum)
echo '<BR>';
/*
* // Optionally re-use an existing database connection for your transport
* // If you specify a naming mode (i5/sql) in your connection, make sure they match.
* $namingMode = DB2_I5_NAMING_ON;
* $existingDb = db2_pconnect('', '','', array('i5_naming' => $namingMode));
* // Add to existing connection options
* $options[CW_EXISTING_TRANSPORT_CONN] = $existingDb;
* $options[CW_EXISTING_TRANSPORT_I5_NAMING] = $namingMode;
*/
$start = microtime(true);
// about to connect. Can use i5_connect or i5_pconnect.
$conn = $connFunction('localhost', '', '', $options);
$end = microtime(true);
$elapsed = $end - $start;
echo "Ran $connFunction function, with options, in $elapsed seconds.<BR>";
// if unable to connect, find out why.
if (!$conn) {
die('<BR>Could not connect. Reason: ' . printArray(i5_error()));
}
echo "Connection object output: '$conn'<BR><BR>";
if ($private) {
// if a private connection, show what number was used or generated.
$privateConnNum = i5_get_property(I5_PRIVATE_CONNECTION, $conn);
echo "Private conn number from i5_get_property(I5_PRIVATE_CONNECTION, \$conn): $privateConnNum<BR><BR>";
$isNew = i5_get_property(I5_NEW_CONNECTION, $conn);
echo "Is new connection?: $isNew<BR><BR>";
}
// CONNECTED.
// check that demo library exists
echo "About to verify that the demo library, '$demoLib', exists.<BR>";
$list = i5_objects_list('QSYS', $demoLib, '*LIB', $conn);
if (!$list) {
echo 'Error getting object list: ' . printArray(i5_error()) . '<BR><BR>';
} else {
if ($listItem = i5_objects_list_read($list)) {
echo "Demo library '$demoLib' exists.<BR><BR>";
} else {
die ("<BR>Demo library '$demoLib' NOT found. Ending.");
}
}
i5_objects_list_close($list);
// ON TO ACTUAL FUNCTIONALITY
if ($doPcml) {
echo h2('PCML program calls');
$pcml = '<pcml version="4.0">
<program name="YYPLUS" entrypoint="YYPLUS" path="/QSYS.LIB/' . $demoLib . '.LIB/YYSRVNORES.SRVPGM" >
<data name="START" type="int" length="4" precision="31" usage="inputoutput" />
<data name="RESULT" type="int" length="4" precision="31" usage="inputoutput" />
</program>
</pcml>';
echo 'About to do simple PCML program prepare.<BR>';
$pgmHandle = i5_program_prepare_PCML($pcml);
if (!$pgmHandle) {
echo 'Error preparing simple PCML program: ' . printArray(i5_error()) . '<BR><BR>';
} else {
$input = array('START' => '25', 'RESULT' => '0');
$output = array('START' => 'START', 'RESULT' => 'RESULT');
echo 'About to do simple PCML program call.<BR>';
$success = i5_program_call($pgmHandle, $input, $output);
$result = $output['RESULT'];
if ($success) {
echo "Success. Output variables: START: $start. RESULT: $result.";
} else {
echo "Problem calling PCML-described program. Error: " . print_r(i5_error(), true);
}
}
echo '<BR><BR>';
$pcml = "<pcml version=\"4.0\">
<struct name=\"S2\">
<data name=\"ZOND2\" type=\"zoned\" length=\"10\" precision=\"5\" usage=\"inherit\" />
<data name=\"PACK2\" type=\"packed\" length=\"19\" precision=\"5\" usage=\"inherit\" />
<data name=\"PACK3\" type=\"packed\" length=\"19\" precision=\"5\" usage=\"inherit\" />
<data name=\"ALPH2\" type=\"char\" length=\"20\" usage=\"inherit\" />
</struct>
<struct name=\"S1\">
<data name=\"ZOND\" type=\"zoned\" length=\"10\" precision=\"5\" usage=\"inherit\" />
<data name=\"PACK1\" type=\"packed\" length=\"19\" precision=\"5\" usage=\"inherit\" />
<data name=\"ALPH1\" type=\"char\" length=\"10\" usage=\"inherit\" />
</struct>
<program name=\"TESTSTRUC\" path=\"/QSYS.LIB/{$demoLib}.LIB/TESTSTRUC.PGM\">
<data name=\"CODE\" type=\"char\" length=\"10\" usage=\"output\" />
<data name=\"S1\" type=\"struct\" struct=\"S1\" usage=\"inputoutput\" />
<data name=\"S2\" type=\"struct\" struct=\"S2\" usage=\"inputoutput\" />
<data name=\"PACK\" type=\"packed\" length=\"1\" precision=\"1\" usage=\"output\" />
<data name=\"CH10\" type=\"char\" length=\"19\" usage=\"output\" />
<data name=\"CH11\" type=\"char\" length=\"20\" usage=\"output\" />
<data name=\"CH12\" type=\"char\" length=\"29\" usage=\"output\" />
<data name=\"CH13\" type=\"char\" length=\"33\" usage=\"output\" />
</program>
</pcml>";
echo 'About to do a complex PCML program prepare.<BR>';
$pgmHandle = i5_program_prepare_PCML($pcml);
if ($pgmHandle) {
echo "Successfully prepared complex PCML program description.<BR>";
} else {
echo "Problem while preparing complex PCML program description.<BR>";
}
// define some input values
$pack3value=7789777.44;
$alph2value=4;
$paramIn = array(
"S1"=>array("ZOND"=>54.77, "PACK1"=>16.2, "ALPH1"=>"MyValue"),
"S2"=>array("ZOND2"=>44.66, "PACK2"=>24444.99945, "PACK3"=>$pack3value, "ALPH2"=>$alph2value)
);
// now we need to define where to place output values; it will create new local variables
$paramOut = array(
"S1"=>"S1_Value", "S2"=>"S2_Value",
"CH10"=>"CH10_Value", "CH11"=>"CH11_Value", "CH12"=>"CH12_Value", "CH13"=>"CH13_Value",
"CODE"=>"Code_Value", "PACK"=>"Pack"
);
echo 'About to do complex PCML program call.';
$success = i5_program_call($pgmHandle, $paramIn, $paramOut);
if (function_exists('i5_output')) extract(i5_output()); // i5_output() required if called in a function
if ($success) {
echo "Success.";
echo "<BR>S1: " . var_export($S1_Value, true);
echo "<BR>S2: " . var_export($S2_Value, true);
echo "<BR>CH10: " . var_export($CH10_Value, true);
echo "<BR>CH11: " . var_export($CH11_Value, true);
echo "<BR>CH12: " . var_export($CH12_Value, true);
echo "<BR>CH13: " . var_export($CH13_Value, true);
echo "<BR>Code: " . var_export($Code_Value, true);
echo "<BR>Pack: " . var_export($Pack, true);
} else {
echo "Problem calling PCML-described program. Error: " . printArray(i5_error());
}
}
$bigDesc = array(
array("DSName"=>"BIGDS", "DSParm"=>array(
array("Name"=>"P1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10, "Count"=>5),
array("Name"=>"P2C", "IO"=>I5_INOUT,"Type"=>I5_TYPE_LONG, "Length"=>4),
array("Name"=>"P2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>1, "CountRef"=>"P2C"),
array("DSName"=>"PS", "Count"=>2, "DSParm"=>array(
array("Name"=>"PS1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS3", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10)
))
))
);
$bigInputValues = array(
"BIGDS"=>array(
"P1"=>array("t1", "t2", "t3", "t4", "t5"),
"P2C"=>2,
"P2"=>array("a", "b"),
"PS"=>array(
array("PS1"=>"test1", "PS2"=>"test2", "PS3"=>"test3"),
array("PS1"=>"test3", "PS2"=>"test4", "PS3"=>"test5")
)
)
);
if ($doUserSpace) {
echo h2('User spaces');
$userSpaceName = 'DEMOSPACE';
$userSpaceLib = $demoLib;
$usObj = new UserSpace($conn);
$usObj->setUSName($userSpaceName, $userSpaceLib);
// toolkit does not have an i5_userspace_delete so delete with a command.
$ret = i5_command("DLTUSRSPC USRSPC($userSpaceLib/$userSpaceName)", $conn);
if (function_exists('i5_output')) extract(i5_output()); // i5_output() required if called in a function
$status = ($ret) ? 'successfully' : 'badly';
echo "deleted user space: $status<BR>";
//$us = $usObj->CreateUserSpace('ALANUS', 'ALAN', $InitSize =1024, $Authority = '*ALL', $InitChar=' ');
$usProperties = array(I5_NAME=>$userSpaceName, I5_LIBNAME=>$userSpaceLib, I5_INIT_VALUE=>'Y');
echo "About to create user space.<BR>";
$us = i5_userspace_create($usProperties, $conn);
if (!$us) {
echo "Error returned: " . printArray(i5_error()) . "<BR><BR>";
} else {
echo "Success!<BR><BR>";
}
// prepare userspace for a put
$us = i5_userspace_prepare("$userSpaceLib/$userSpaceName", $bigDesc, $conn);
if (!$us) {
echo "Error returned from user space prepare: " . printArray(i5_error()) . "<BR><BR>";
} else {
echo "Success preparing user space.<BR><BR>";
}
// do the userspace put
$success = i5_userspace_put($us, $bigInputValues);
if (!$success) {
echo "Error returned from user space put: " . printArray(i5_error()) . "<BR><BR>";
} else {
echo "Success putting data into user space.<BR><BR>";
}
// do the userspace get
// removed counfref because doesn't work when getting.
$bigDesc = array(
array("DSName"=>"BIGDS", "DSParm"=>array(
array("Name"=>"P1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10, "Count"=>5),
array("Name"=>"P2C", "IO"=>I5_INOUT,"Type"=>I5_TYPE_LONG, "Length"=>4),
array("Name"=>"P2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>1, "Count"=>2),
array("DSName"=>"PS", "Count"=>2, "DSParm"=>array(
array("Name"=>"PS1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS3", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10)
))
))
);
// prepare userspace for a get
$us = i5_userspace_prepare("$userSpaceLib/$userSpaceName", $bigDesc, $conn);
if (!$us) {
echo "Error returned from user space prepare: " . printArray(i5_error()) . "<BR><BR>";
} else {
echo "Success preparing user space.<BR><BR>";
}
$success = i5_userspace_get($us, array("BIGDS"=>"BIGDS"));
if (function_exists('i5_output')) extract(i5_output()); // i5_output() required if called in a function
if (!$success) {
echo "Error returned from user space get: " . i5_error() . "<BR><BR>";
} else {
echo "Success getting data from user space. BIGDS=" . printArray($BIGDS) . "<BR><BR>";
}
}
// data queue
if ($doDataQueue) {
echo h2('Data queues');
$queueName = 'KEYEDQ';
$keyLen = 10;
$qObj = new DataQueue($conn);
echo "<BR>About to delete data queue $queueName. (Will fail if doesn't exist yet)<BR>";
try {
$qObj->DeleteDQ($queueName, $demoLib);
echo "Success deleting data queue $queueName.";
} catch (Exception $e) {
echo "Error deleting data queue: " . $e . "<BR><BR>";
}
echo "<BR>About to create data queue $queueName.<BR>";
try {
$qObj->CreateDataQ($queueName, $demoLib, 128, '*KEYED', $keyLen); // length 10 key
echo "Success creating data queue $queueName.";
} catch (Exception $e) {
echo "Error creating data queue: " . $e . "<BR><BR>";
}
// test case adapted from p398 of Zend Server 5.1 manual
$simpleStructure = array(
'DSName' => 'PS',
'DSParm' =>
array(
array(
'type' => 0,
'name' => 'PS1',
'length' => '10',
),
array(
'type' => 6,
'name' => 'PS2',
'length' => '10.4',
),
array(
'type' => 0,
'name' => 'PS3',
'length' => '10',
),
)
);
// prepare
$queue = i5_dtaq_prepare("$demoLib/$queueName", $simpleStructure, $keyLen);
if (!$queue) {
echo "Error preparing data queue.<BR><BR>";
}
// send
$key = 'abc';
$data = array('PS1' => 'test1', 'PS2' => 13.1415, 'PS3' => 'test2');
echo "<BR>About to send simple structure to keyed data queue $queueName with key $key.<BR>";
$success = i5_dtaq_send($queue, $key, $data);
if (!$success) {
echo "Error returned from data queue send: " . printArray(i5_error()) . "<BR><BR>";
} else {
echo "Success sending data to data queue.<BR><BR>";
}
echo "<BR>About to receive simple structure from keyed data queue $queueName with key $key.<BR>";
$data = i5_dtaq_receive($queue, 'EQ', $key);
// receive
if (!$data) {
echo "Error returned from simple data queue receive: " . printArray(i5_error());
} else {
echo "Success getting simple data structure from data queue: " . printArray($data);
}
echo '<BR>';
// unkeyed queue with complex structure
$queueName = 'NEWQ';
$qObj = new DataQueue($conn);
echo "<BR>About to delete data queue $queueName. (Will fail if doesn't exist yet)<BR>";
try {
$qObj->DeleteDQ($queueName, $demoLib);
echo "Success deleting data queue $queueName.";
} catch (Exception $e) {
echo "Error deleting data queue: " . $e . "<BR><BR>";
}
echo "<BR>About to create data queue $queueName.<BR>";
try {
$qObj->CreateDataQ($queueName, $demoLib);
echo "Success creating data queue $queueName.";
} catch (Exception $e) {
echo "Error creating data queue: " . $e . "<BR><BR>";
}
$bigDesc = array(
array("DSName"=>"BIGDS", "DSParm"=>array(
array("Name"=>"P1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10, "Count"=>5),
array("Name"=>"P2C", "IO"=>I5_INOUT,"Type"=>I5_TYPE_LONG, "Length"=>4),
array("Name"=>"P2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>1, "Count"=>2),
array("DSName"=>"PS", "Count"=>2, "DSParm"=>array(
array("Name"=>"PS1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS3", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10)
))
))
);
// prepare
$queue = i5_dtaq_prepare("$demoLib/$queueName", $bigDesc);
if (!$queue) {
echo "Error preparing data queue.<BR><BR>";
}
// send
echo "<BR>About to send big data structure to data queue $queueName.<BR>";
$success = i5_dtaq_send($queue, '', $bigInputValues);
//
if (!$success) {
echo "Error returned from data queue send: " . i5_error() . "<BR><BR>";
} else {
echo "Success sending data to data queue.<BR><BR>";
}
echo "<BR>About to receive big data structure from data queue $queueName.<BR>";
$data = i5_dtaq_receive($queue);//, $operator = null, $key = '', $timeout = 0)
// receive
if (!$data) {
echo "Error returned from data queue receive: " . printArray(i5_error());
} else {
echo "Success getting data from data queue: " . printArray($data);
}
echo '<BR>';
// Now a short-form DQ test
// short-form description
$littleDesc = array("Name"=>"sometext", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>20);
$littleInput = "Small text input";
echo "<BR>About to send small short-form data structure to data queue $queueName.<BR>";
// prepare
$queue = i5_dtaq_prepare("$demoLib/$queueName", $littleDesc);
if (!$queue) {
echo "Error preparing data queue.<BR><BR>";
}
// send
$success = i5_dtaq_send($queue, '', $littleInput);
//
if (!$success) {
echo "Error returned from data queue send of small input: " . i5_error() . "<BR><BR>";
} else {
echo "Success sending the string '$littleInput' to data queue.<BR><BR>";
}
echo "<BR>About to receive small data structure from data queue $queueName.<BR>";
$data = i5_dtaq_receive($queue);//, $operator = null, $key = '', $timeout = 0)
// receive
if (!$data) {
echo "Error returned from data queue receive of small data: " . i5_error() . "<BR><BR>";
} else {
echo "Success getting small data from data queue: '$data'<BR><BR>";
}
echo '<BR><BR>';
}
if ($doObjectList) {
echo h2('Object lists');
echo "About to do object list with '$demoLib', '*ALL','*PGM'<BR>";
// object list
$list = i5_objects_list($demoLib, '*ALL', '*PGM', $conn);
if (!$list) {
echo 'Error getting object list: ' . printArray(i5_error()) . '<BR><BR>';
} else {
while ($listItem = i5_objects_list_read($list)) {
echo printArray($listItem);
}
echo 'End of list. Error information: ' . printArray(i5_error()) . '<BR><BR>';
}
i5_objects_list_close($list);
}
if ($doPgmCallSimple) {
echo h2('Program calls');
echo 'Program call with simple parameters<BR>';
$progname = "$demoLib/TESTSTP2";
$desc = array(
array("Name"=>"code", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>"10"),
array("Name"=>"name", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>"10")
);
$desc = array(
0 => array( 'type' => 0, 'name' => 'code', 'length' => 10, 'io' => 3),
1 => array( 'type' => 0, 'name' => 'name', 'length' => 10, 'io' => 3)
);
echo "<b>About to call $progname with two char parameters.</b><BR>";
$prog = i5_program_prepare($progname, $desc);
if ($prog === FALSE) {
$errorTab = i5_error();
echo "Program prepare failed <br>\n";
var_dump($errorTab);
die();
}
/* Execute Program */
$params = array("code"=>"123","name"=>"ABC");
$retvals = array("code"=>"code","name"=>"name");
$ret = i5_program_call($prog, $params, $retvals) ;
if (function_exists('i5_output')) extract(i5_output()); // i5_output() required if called in a function
if ($ret === FALSE)
{
$errorTab = i5_error();
echo "FAIL : i5_program_call failure message: " . $conn->getLastError() . " with code <br>";
var_dump($errorTab);
}else {
// success
echo "Success! The return values are: <br>", "Name: ", $name, "<br> Code: ", $code, "<br><BR>";
}
$close_val = i5_program_close ($prog);
if ($close_val === false)
{
print ("FAIL : i5_program_close returned fales, closing an open prog.<br>\n");
$errorTab = i5_error();
var_dump($errorTab);
}
} // (simple call)
// *** data structure call! ***
if ($doPgmCallComplex) {
echo '<BR>Program call with complex parameters<BR>';
$progname = "$demoLib/RPCTEST";
echo "<b>About to call $progname with data structure parameters.</b>";
/*Call a program with parameters that include a DS */
$desc = array(
array("Name"=>"P1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10, "Count"=>5),
array("Name"=>"P2C", "IO"=>I5_INOUT,"Type"=>I5_TYPE_LONG, "Length"=>4),
array("Name"=>"P2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>1, "CountRef"=>"P2C"),
array("DSName"=>"PS", "Count"=>2, "DSParm"=>array(
array("Name"=>"PS1", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS2", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10),
array("Name"=>"PS3", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>10)
))
);
$prog = i5_program_prepare($progname, $desc);
if ($prog === FALSE) {
$errorTab = i5_error();
echo "Program prepare failed <br>\n";
var_dump($errorTab);
die();
}
/* Execute Program */
// The nameless elements in array.
$params1 = array(
array("PS1"=>"test1", "PS2"=>"test2", "PS3"=>"test3"),
array("PS1"=>"test3", "PS2"=>"test4", "PS3"=>"test5")
);
$params2 = array(
"P1"=>array("t1", "t2", "t3", "t4", "t5"),
"P2C"=>2,
"P2"=>array("a", "b"),
"PS"=>$params1);
$retvals = array("P1"=>"P1", "PS"=>"PS", "P2"=>"P2", "P2C"=>"P2C");
$ret = i5_program_call($prog, $params2, $retvals) ;
if (function_exists('i5_output')) extract(i5_output()); // i5_output() required if called in a function
if ($ret === FALSE)
{
$errorTab = i5_error();
echo "FAIL : i5_program_call failure message: " . $conn->getLastError() . " with code <br>";
var_dump($errorTab);
}else {
// success
echo "<BR><BR>Success! The return values are: <br>";
echo "P1 : " . printArray($P1) . "<BR>";
echo "P2C : " . $P2C . "<BR>";
echo "P2 : " . printArray($P2) . "<BR>";
echo "PS: " . printArray($PS) . "<BR>";
}
$close_val = i5_program_close ($prog);
if ($close_val === false)
{
print ("FAIL : i5_program_close returned fales, closing an open prog.<br>\n");
$errorTab = i5_error();
var_dump($errorTab);
}
} //(pgmcall complex)
echo h2('Commands');
$msg = 'HELLO';
$cmdString = "SNDMSG MSG($msg) TOUSR($user)";
$start = microtime(true);
$commandSuccessful = i5_command($cmdString, array(), array(), $conn);
$end = microtime(true);
$elapsed = $end - $start;
echo "Ran command $cmdString using a single string in $elapsed seconds. Return: " . OkBad($commandSuccessful) . "<BR><BR>";
$badUser = 'jerk';
$msg = 'HELLO';
$cmdString = "SNDMSG MSG($msg) TOUSR($badUser)";
$start = microtime(true);
$commandSuccessful = i5_command($cmdString, array(), array(), $conn);
$end = microtime(true);
$elapsed = $end - $start;
echo "Ran command $cmdString using a single string to BAD user in $elapsed seconds.. Return: " . OkBad($commandSuccessful). "<BR>";
if (!$commandSuccessful) {
echo "Error returned: " . printArray(i5_error()) . "<BR><BR>";
}
$cmdString = 'RTVJOBA';
$input = array();
// we want variable name ccsid to be created
$output = array('ccsid' => array('ccsid', 'dec(5 0)'),
'dftccsid' => array('defaultCcsid', 'dec(5 0)'),
'curuser'=>'currentUser', 'nbr'=>'jobNumber', 'job'=>'jobName', 'user'=>'jobUser',
'usrlibl' => 'userLibl');
$start = microtime(true);
$commandSuccessful = i5_command($cmdString, $input, $output, $conn);
if (function_exists('i5_output')) extract(i5_output()); // i5_output() required if called in a function
$end = microtime(true);
$elapsed = $end - $start;
echo "Ran command $cmdString with an output array in $elapsed seconds. Return: " .
OkBad($commandSuccessful) .
" with CCSID '$ccsid', default CCSID '$defaultCcsid', current user '$currentUser', job name '$jobName', job number '$jobNumber', job user '$jobUser', with user liblist '$userLibl'.<BR><BR>";
// Note: old toolkit cannot get interactive output of this sort (DSPJOBLOG). This is additional functionality of the new toolkit.
$cmdString ="DSPJOBLOG JOB($jobNumber/$jobUser/$jobName)";
echo "About to run " . $cmdString .".<BR>";
$conn->setToolkitServiceParams(array('plugSize'=>'5M')); // bigger to handle large joblog
$interactiveOutput = $conn->CLInteractiveCommand($cmdString);
$conn->setToolkitServiceParams(array('plugSize'=>'512K')); // put back to default
echo printArray($interactiveOutput) . "<BR><BR>";
$msg = 'HELLO_WITH_INPUTS_ARRAY';
$cmdString = "SNDMSG";
$inputs = array('MSG'=>$msg, 'TOUSR'=>$user);
$commandSuccessful = i5_command($cmdString, $inputs);
echo "Ran command $cmdString with an input array: " . printArray($inputs) . "Return: " . OkBad($commandSuccessful) . ".<BR><BR>";
$msg = "MixedCaseNoSpaces";
$cmdString = "SNDMSG";
$inputs = array('MSG'=>$msg, 'TOUSR'=>$user);
$commandSuccessful = i5_command($cmdString, $inputs);
echo "Ran command $cmdString with an input array: " . printArray($inputs) . "Return: " . OkBad($commandSuccessful) . ".<BR><BR>";
$msg = "Davey Jones embedded spaces without quotes--caused error in old toolkit";
$cmdString = "SNDMSG";
$inputs = array('MSG'=>$msg, 'TOUSR'=>$user);
$commandSuccessful = i5_command($cmdString, $inputs);
echo "Ran command $cmdString with an input array: " . printArray($inputs) . "Return: " . OkBad($commandSuccessful) . ".<BR><BR>";
$msg = "O'flanagan single quote--caused error in old toolkit";
$cmdString = "SNDMSG";
$inputs = array('MSG'=>$msg, 'TOUSR'=>$user);
$commandSuccessful = i5_command($cmdString, $inputs);
echo "Ran command $cmdString with an input array: " . printArray($inputs) . "Return: " . OkBad($commandSuccessful) . ".<BR><BR>";
echo h2('Error functions');
echo "Let's test i5_errormsg() and i5_errno()<BR>Get last error message: " . i5_errormsg();
echo "<BR>Get last error number: " . i5_errno(). "<BR><BR>";
echo h2('Get system value');
$start = microtime(true);
$date = i5_get_system_value('QDATE');
$end = microtime(true);
$elapsed = $end - $start;
echo "QDATE system value: '$date', obtained in $elapsed seconds.<BR>";
echo h2('Data areas');
$dtaara = "$demoLib/ALLEYOOP";
$ret = i5_data_area_create($dtaara, 72);
if ($ret) {
echo "Created data area $dtaara successfully.<BR>";
} else {
echo "Could not create data area $dtaara.<BR>";
}
$ret = i5_data_area_delete($dtaara);
if ($ret) {
echo "Deleted data area $dtaara successfully.<BR>";
} else {
echo "Could not delete data area $dtaara.<BR>";
}
$dtaara = 'BETTYBOOP';
$ret = i5_data_area_create($dtaara, 100);
if ($ret) {
echo "Created data area $dtaara successfully.<BR>";
} else {
echo "Could not create data area $dtaara. Reason: " . i5_errormsg() . " (it may already exist)<BR>";
}
$dtaara = 'BETTYBOOP';
$stringToWrite = 'Very nice';
$ret = i5_data_area_write($dtaara, $stringToWrite, 5, 20);
if ($ret) {
echo "Wrote '$stringToWrite' to data area $dtaara successfully.<BR>";
// try to read now.
$start = microtime(true);
$readData = i5_data_area_read($dtaara, 3, 40);
$end = microtime(true);
$elapsed = $end - $start;
if ($readData) {
echo "Read a portion of '$readData' from data area $dtaara successfully in $elapsed seconds.<BR>";
} else {
echo "Could not read from data area $dtaara. Reason: " . i5_errormsg() . "<BR>";
}
// try to read now.
$start = microtime(true);
$readData = i5_data_area_read($dtaara); // the whole thing
$end = microtime(true);
$elapsed = $end - $start;
if ($readData) {
echo "Read ALL of '$readData' from data area $dtaara successfully in $elapsed seconds.<BR>";
} else {
echo "Could not read from data area $dtaara. Reason: " . i5_errormsg() . "<BR>";
}
} else {
echo "Could not write to data area $dtaara. Reason: " . i5_errormsg() . "<BR>";
}
// job list
if ($doJobLists) {
echo h2('Job lists');
echo "About to get up to 5 jobs with jobname ZENDSVR (can also do I5_JOBUSER, I5_USERNAME, I5_JOBNUMBER, and I5_JOBTYPE).<BR>";
$list = i5_job_list(array(I5_JOBNAME=>'ZENDSVR'));
if (!$list) {
echo 'Error getting job list: ' . printArray(i5_error()) . '<BR>';
} else {
$jobCount = 0;
while (($listItem = i5_job_list_read($list)) && (++$jobCount <= 5)) {
echo printArray($listItem) . '<BR>';
}
echo 'End of list.<BR><BR>';
}
i5_job_list_close($list);
// Get info about current job
echo "Getting information about current job.<BR>";
$list = i5_job_list();//array(I5_USERNAME=>'*ALL'), $conn);
if (!$list) {
echo 'Error getting job list: ' . printArray(i5_error()) . '<BR>';
} else {
// should be only one for current job.
$listItem = i5_job_list_read($list);
echo "<BR>list item for current job: " . printArray($listItem) . "<BR><BR>";
echo "Job name: {$listItem[I5_JOB_NAME]} user: {$listItem[I5_JOB_USER_NAME]} job number: {$listItem[I5_JOB_NUMBER]}<BR><BR>";
}
i5_job_list_close($list);
}
if ($doSpooledFiles) {
echo h2('Spooled Files');
$splUser = 'QTMHHTTP';
echo "Get up to 5 spooled files for user $splUser<BR>";
$list = i5_spool_list(array(I5_USERNAME=>$splUser), $conn);
if (!$list) {
echo 'Error getting spool list: ' . printArray(i5_error()) . '<BR>';
} else {
$spoolCount = 0;