adapter.php
24.3 KB
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
<?php
/*
Adapter Web-API MANTRA
Programmed by: Didi Sukyadi
ver:1.99z
*/
//--------------------- Konektor CURL menggunakan metode HTTP -----------------------------\\
function callAPI($endpoint,$operation,$accesskey='',$parameter=array(),$callmethod='REST',$outputformat='array'){
$result=false;
$axml=array();
$agent="MANTRA";
$rootkeytag='response';
$callmethod=strtoupper($callmethod);
$content_type=$callmethod=='POST'?"Content-Type:application/x-www-form-urlencoded;charset=UTF-8":"Content-Type:text/plain;charset=UTF-8";
if(empty($endpoint)){
$response=array('status'=>0,'code'=>20001,'message'=>'URL/EndPoint tidak terdefinisi (kosong)','data'=>'');
$axml=array($rootkeytag=>$response);
}
else{
//persiapkan parameter untuk method REST, RESTFULL, dan RESTFULLPAR
$rest_pars='';
$http_pars=array();
if($callmethod=='REST' && !empty($parameter)){
$apar=array();
foreach($parameter as $key=>$value){
$apar[$key]=urlencode($value);
}
$rest_pars=http_build_query($apar);
}
if($callmethod=='RESTFULL' && !empty($parameter)){
$apar=array();
foreach($parameter as $key=>$value){
$apar[$key]=urlencode($value);
}
$rest_pars=implode('/',$apar);
}
if($callmethod=='RESTFULLPAR' && !empty($parameter)){
$rest_pars="";
foreach($parameter as $key=>$value){
$rest_pars.='/'.$key.'/'.urlencode($value);
}
$rest_pars=substr($rest_pars,1);
}
if(in_array($callmethod,array('GET','POST')) && !empty($parameter)){
$http_pars=http_build_query($parameter);
}
//susun uri
$uri=$endpoint;
if (!empty($operation)) {
$uri.=substr($uri,-1)=='/'?$operation:'/'.$operation;
}
if (!empty($rest_pars)){ //tambah parameter untuk method REST, RESTFULL, dan RESTFULLPAR
$uri.=substr($uri,-1)=='/'?$rest_pars:'/'.$rest_pars;
}
if (!empty($http_pars) && $callmethod=='GET'){ //tambah parameter untuk method GET
$uri=substr($uri,-1)=='/'?substr($uri,0,-1):$uri;
$uri.=strpos($uri,"?")===false?"?".$http_pars:"&".$http_pars;
}
//file_put_contents(TMPDIR.'apiconnector.txt',$uri);
if(empty($uri)){
$response=array('status'=>0,'code'=>20002,'message'=>'URI tidak terdefinisi (kosong)','data'=>'');
$axml=array($rootkeytag=>$response);
}
else{
$uri=substr($uri,-1)=='/'?substr($uri,0,-1):$uri;
$ch = curl_init();
// URL target koneksi
curl_setopt($ch, CURLOPT_URL, $uri);
if($agent!='') curl_setopt($ch, CURLOPT_USERAGENT, $agent);
// Output dengan header=true hanya untuk meta document (xml/json)
curl_setopt($ch, CURLOPT_HEADER, FALSE);
if($accesskey!='') curl_setopt($ch, CURLOPT_HTTPHEADER, array($content_type,"AccessKey:".$accesskey));
else curl_setopt($ch, CURLOPT_HTTPHEADER, array($content_type));
// Mendapatkan tanggapan
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
// Menggunakan metode HTTP GET
if(in_array($callmethod,array('GET','REST','RESTFULL','RESTFULLPAR')) ){
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
}
// Menggunakan metode HTTP POST
if($callmethod=='POST'){
curl_setopt($ch, CURLOPT_POST, TRUE);
// Sisipkan parameter
curl_setopt($ch, CURLOPT_POSTFIELDS,$http_pars);
}
// Buka koneksi dan dapatkan tanggapan
$content=curl_exec($ch);
$errno=curl_errno($ch);
$errmsg=curl_strerror($errno);
// Periksa kesalahan
if ($errno!=0){
$response=array('status'=>0,'code'=>$errno,'message'=>$errmsg,'data'=>'');
$axml=array($rootkeytag=>$response);
}
else{
if(substr($content,0,5)=='<?xml' || substr($content,0,5)=='<ows:'){
try{
$acontent=setXML2Array($content);
}
catch(exception $e){
$acontent=$e->getCode().": ".$e->getMessage();
}
if(!isset($acontent[$rootkeytag]['status'])){
$response=array('status'=>1,'code'=>200,'message'=>'Sukses','data'=>$acontent);
$axml=array($rootkeytag=>$response);
}
else $axml=$acontent;
}
elseif(substr($content,0,1)=='{' && substr($content,-1)=='}'){
$acontent=json_decode($content,true);
if(!isset($acontent[$rootkeytag]['status'])){
$response=array('status'=>1,'code'=>200,'message'=>'Sukses','data'=>$acontent);
$axml=array($rootkeytag=>$response);
}
else $axml=$acontent;
}
else{
$acontent=unserialize($content);
if(!$acontent) $acontent=$content;
if(!isset($acontent[$rootkeytag]['status'])){
$response=array('status'=>1,'code'=>200,'message'=>'Sukses','data'=>$acontent);
$axml=array($rootkeytag=>$response);
}
else $axml=$acontent;
}
}
curl_close($ch);
}
}
if(!empty($axml))
switch ($outputformat){
case "xml":
try{
$result=setArray2XML($rootkeytag,$axml[$rootkeytag]);
}
catch(exception $e){
$response=array('status'=>0,'code'=>20004,'message'=>$e->getMessage(),'data'=>"");
$axml=array($rootkeytag=>$response);
$result=setArray2XML($rootkeytag,$axml[$rootkeytag]);
}
break;
case "json":
$result=json_encode($axml,JSON_PRETTY_PRINT);
if(json_last_error()!=JSON_ERROR_NONE){
$response=array('status'=>0,'code'=>20005,'message'=>"Encode hasil operasi {$apitype}:{$wsmethod} gagal",'data'=>"");
$axml=array($rootkeytag=>$response);
$result=json_encode($axml,JSON_PRETTY_PRINT);
}
break;
case "array":
default:
$result=$axml;
}
return $result;
}
function getAPI($endpoint,$operation,$accesskey='',$parameter=array(),$callmethod='REST'){
return callAPI($endpoint,$operation,$accesskey,$parameter,$callmethod);
}
function getAPIJSON($endpoint,$operation,$accesskey='',$parameter=array(),$callmethod='REST'){
return callAPI($endpoint,$operation,$accesskey,$parameter,$callmethod,"json");
}
function getAPIXML($endpoint,$operation,$accesskey='',$parameter=array(),$callmethod='REST'){
return callAPI($endpoint,$operation,$accesskey,$parameter,$callmethod,"xml");
}
function enc64data($data){
$encdata=base64_encode($data);
return strrev($encdata);
}
function dec64data($data){
$decdata=strrev($data);
return base64_decode($decdata);
}
function setXML2Array($xmldata){
if (!extension_loaded('dom')) return array();
return XML2Array::createArray($xmldata);
}
function setArray2XML($nodename,$data){
if (!extension_loaded('dom')) return '';
$xml=Array2XML::createXML($nodename,$data);
return $xml->saveXML();
}
/**
* XML2Array: A class to convert XML to array in PHP
* It returns the array which can be converted back to XML using the Array2XML script
* It takes an XML string or a DOMDocument object as an input.
*
* Created by: Lalit Patel
*
* Usage:
* $array = XML2Array::createArray($xml);
*/
class XML2Array {
private static $xml = null;
private static $encoding = 'UTF-8';
/**
* Initialize the root XML node [optional]
* @param $version
* @param $encoding
* @param $format_output
*/
public static function init($version = '1.0', $encoding = 'UTF-8',
$format_output = true) {
self::$xml = new DOMDocument($version, $encoding);
self::$xml->formatOutput = $format_output;
self::$encoding = $encoding;
}
/**
* Convert an XML to Array
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DOMDocument
*/
public static function &createArray($input_xml) {
$xml = self::getXMLRoot();
if(is_string($input_xml)) {
$parsed = $xml->loadXML($input_xml); // untuk sistem 64bit gunakan: loadXML($input_xml,LIBXML_PARSEHUGE);
if(!$parsed) {
throw new Exception('[XML2Array] Error parsing the XML string.');
}
} else {
if(get_class($input_xml) != 'DOMDocument') {
throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
}
$xml = self::$xml = $input_xml;
}
$array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $array;
}
/**
* Convert an Array to XML
* @param mixed $node - XML as a string or as an object of DOMDocument
* @return mixed
*/
private static function &convert($node) {
$output = array();
switch ($node->nodeType) {
case XML_CDATA_SECTION_NODE:
$output['@cdata'] = trim($node->textContent);
break;
case XML_TEXT_NODE:
$output = trim($node->textContent);
break;
case XML_ELEMENT_NODE:
// for each child node, call the covert function recursively
for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) {
$child = $node->childNodes->item($i);
$v = self::convert($child);
if(isset($child->tagName)) {
$t = $child->tagName;
// assume more nodes of same kind are coming
if(!isset($output[$t])) {
$output[$t] = array();
}
$output[$t][] = $v;
} else {
//check if it is not an empty text node
if($v !== '') {
$output = $v;
}
}
}
if(is_array($output)) {
// if only one node of its kind,
// assign it directly instead if array($value);
foreach ($output as $t => $v) {
if(is_array($v) && count($v)==1) {
$output[$t] = $v[0];
}
}
if(empty($output)) {
//for empty nodes
$output = '';
}
}
// loop through the attributes and collect them
if($node->attributes->length) {
$a = array();
foreach($node->attributes as $attrName => $attrNode) {
$a[$attrName] = (string) $attrNode->value;
}
// if its an leaf node, store the value in @value
// instead of directly storing it.
if(!is_array($output)) {
$output = array('@value' => $output);
}
$output['@attributes'] = $a;
}
break;
}
return $output;
}
/*
* Get the root XML node, if there isn't one, create it.
*/
private static function getXMLRoot(){
if(empty(self::$xml)) {
self::init();
}
return self::$xml;
}
}
/**
* Array2XML: A class to convert array in PHP to XML
* It also takes into account attributes names unlike SimpleXML in PHP
* It returns the XML in form of DOMDocument class for further manipulation.
* It throws exception if the tag name or attribute name has illegal chars.
*
* Author : Lalit Patel
*
* Usage:
* $xml = Array2XML::createXML('root_node_name', $php_array);
* echo $xml->saveXML();
*/
class Array2XML {
private static $xml = null;
private static $encoding = 'UTF-8';
/**
* Initialize the root XML node [optional]
* @param $version
* @param $encoding
* @param $format_output
*/
public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
self::$xml = new DomDocument($version, $encoding);
self::$xml->formatOutput = $format_output;
self::$encoding = $encoding;
}
/**
* Convert an Array to XML
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DomDocument
*/
public static function &createXML($node_name, $arr=array()) {
$xml = self::getXMLRoot();
$xml->appendChild(self::convert($node_name, $arr));
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $xml;
}
/**
* Convert an Array to XML
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DOMNode
*/
private static function &convert($node_name, $arr=array()) {
//print_arr($node_name);
$xml = self::getXMLRoot();
$node = $xml->createElement($node_name);
if(is_array($arr)){
// get the attributes first.;
if(isset($arr['@attributes'])) {
foreach($arr['@attributes'] as $key => $value) {
if(is_string($key)) $vkey=str_replace(" ","_",$key);
if(!self::isValidTagName($vkey)) {
//file_put_contents(TMPDIR."array2xml.txt",'Illegal character in attribute name. attribute: '.$key.' in node: '.$node_name);
throw new Exception('[Array2XML] Illegal character in attribute name. attribute: '.$key.' in node: '.$node_name);
}
$node->setAttribute($vkey, self::bool2str($value));
}
unset($arr['@attributes']); //remove the key from the array once done.
}
// check if it has a value stored in @value, if yes store the value and return
// else check if its directly stored as string
if(isset($arr['@value'])) {
$node->appendChild($xml->createTextNode(self::bool2str($arr['@value'])));
unset($arr['@value']); //remove the key from the array once done.
//return from recursion, as a note with value cannot have child nodes.
return $node;
} else if(isset($arr['@cdata'])) {
$node->appendChild($xml->createCDATASection(self::bool2str($arr['@cdata'])));
unset($arr['@cdata']); //remove the key from the array once done.
//return from recursion, as a note with cdata cannot have child nodes.
return $node;
}
}
//create subnodes using recursion
if(is_array($arr)){
// recurse to get the node for that key
foreach($arr as $key=>$value){
if(is_string($key)) $vkey=str_replace(" ","_",$key);
if(!self::isValidTagName($vkey)) {
//file_put_contents(TMPDIR."array2xml.txt",'Illegal character in tag name: '.$key.' in node: '.$node_name);
throw new Exception('[Array2XML] Illegal character in tag name. tag: '.$key.' in node: '.$node_name);
}
if(is_array($value) && is_numeric(key($value))) {
// MORE THAN ONE NODE OF ITS KIND;
// if the new array is numeric index, means it is array of nodes of the same kind
// it should follow the parent key name
foreach($value as $k=>$v){
$node->appendChild(self::convert($vkey, $v));
}
} else {
// ONLY ONE NODE OF ITS KIND
$node->appendChild(self::convert($vkey, $value));
}
unset($arr[$key]); //remove the key from the array once done.
}
}
// after we are done with all the keys in the array (if it is one)
// we check if it has any text value, if yes, append it.
if(!is_array($arr)) {
$node->appendChild($xml->createTextNode(self::bool2str($arr)));
}
return $node;
}
/*
* Get the root XML node, if there isn't one, create it.
*/
private static function getXMLRoot(){
if(empty(self::$xml)) {
self::init();
}
return self::$xml;
}
/*
* Get string representation of boolean value
*/
private static function bool2str($v){
//convert boolean to text value.
$v = $v === true ? 'true' : $v;
$v = $v === false ? 'false' : $v;
return $v;
}
/*
* Check if the tag name or attribute name contains illegal characters
* Ref: http://www.w3.org/TR/xml/#sec-common-syn
*/
private static function isValidTagName($tag){
$pattern = '/^[a-z_]+[a-z0-9\:\-\.\_]*[^:]*$/i';
return preg_match($pattern, $tag, $matches) && $matches[0] == $tag;
}
}
/**
* This file is part of the array_column library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
* @license http://opensource.org/licenses/MIT MIT
*/
if (!function_exists('array_column')) {
/**
* Returns the values from a single column of the input array, identified by
* the $columnKey.
*
* Optionally, you may provide an $indexKey to index the values in the returned
* array by the values from the $indexKey column in the input array.
*
* @param array $input A multi-dimensional array (record set) from which to pull
* a column of values.
* @param mixed $columnKey The column of values to return. This value may be the
* integer key of the column you wish to retrieve, or it
* may be the string key name for an associative array.
* @param mixed $indexKey (Optional.) The column to use as the index/keys for
* the returned array. This value may be the integer key
* of the column, or it may be the string key name.
* @return array
*/
function array_column($input = null, $columnKey = null, $indexKey = null)
{
// Using func_get_args() in order to check for proper number of
// parameters and trigger errors exactly as the built-in array_column()
// does in PHP 5.5.
$argc = func_num_args();
$params = func_get_args();
if ($argc < 2) {
trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
return null;
}
if (!is_array($params[0])) {
trigger_error(
'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
E_USER_WARNING
);
return null;
}
if (!is_int($params[1])
&& !is_float($params[1])
&& !is_string($params[1])
&& $params[1] !== null
&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
) {
trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
return false;
}
if (isset($params[2])
&& !is_int($params[2])
&& !is_float($params[2])
&& !is_string($params[2])
&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
) {
trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
return false;
}
$paramsInput = $params[0];
$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
$paramsIndexKey = null;
if (isset($params[2])) {
if (is_float($params[2]) || is_int($params[2])) {
$paramsIndexKey = (int) $params[2];
} else {
$paramsIndexKey = (string) $params[2];
}
}
$resultArray = array();
foreach ($paramsInput as $row) {
$key = $value = null;
$keySet = $valueSet = false;
if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
$keySet = true;
$key = (string) $row[$paramsIndexKey];
}
if ($paramsColumnKey === null) {
$valueSet = true;
$value = $row;
} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
$valueSet = true;
$value = $row[$paramsColumnKey];
}
if ($valueSet) {
if ($keySet) {
$resultArray[$key] = $value;
} else {
$resultArray[] = $value;
}
}
}
return $resultArray;
}
}
function count_dimension($Array, $count = 0) {
if(is_array($Array)) {
return count_dimension(current($Array), ++$count);
} else {
return $count;
}
}
function nav_table($navid,$maxpage)
{
if($maxpage>1){
?>
<div class="page-nav" style="text-align:right;margin-bottom:8px;font-family:sans-serif;font-size:14px;">
<span>Data: <?php echo $maxpage;?> Halaman. </span>
<button type="button" style="padding:4px;width:24px;border:1px solid silver;background:#fafafa;color:#333;cursor:pointer;outline:none;" onclick="goPageTable('<?php echo $navid;?>','page','<','<?php echo $maxpage;?>');">«</button>
<button type="button" style="padding:4px;width:24px;border:1px solid silver;background:#fafafa;color:#333;cursor:pointer;outline:none;" onclick="goPageTable('<?php echo $navid;?>','page','-','<?php echo $maxpage;?>');">‹</button>
<span id="nav-pagenum<?php echo $navid;?>" >
<script runat="server" type="text/javascript" autoload="true">
goPageTable('<?php echo $navid;?>','page','<','<?php echo $maxpage;?>');
</script>
</span>
<button type="button" style="padding:4px;width:24px;border:1px solid silver;background:#fafafa;color:#333;cursor:pointer;outline:none;" onclick="goPageTable('<?php echo $navid;?>','page','+','<?php echo $maxpage;?>');">›</button>
<button type="button" style="padding:4px;width:24px;border:1px solid silver;background:#fafafa;color:#333;cursor:pointer;outline:none;" onclick="goPageTable('<?php echo $navid;?>','page','>','<?php echo $maxpage;?>');">»</button>
</div>
<?php
}
}
function view_table($data,$key,$rowsperpage=5){
if(isset($data) and is_array($data)){
$data=array_column($data,$key);
if(is_array($data) and (count($data)>0)){
$data=current($data);
if(count_dimension($data)<2) $data=array($data);
$header=current($data);
$maxdata=count($data);
$maxpage=$maxdata>$rowsperpage?ceil($maxdata/$rowsperpage):1;
reset($data);
nav_table(1,$maxpage);
for($page=1;$page<=$maxpage;$page++){
$datapage=array();
for($row=0;$row<$rowsperpage;$row++)
if(current($data)){
$datapage[]=current($data);
$x=next($data);
}
$display=$page==1?"display:block;":"display:none;";
echo '<div id="page'.$page.'" class="page" style="'.$display.'overflow-x:scroll;font-family:sans-serif;font-size:14px;">';
echo '<table style="table-layout:auto;width:100%;border-collapse:separate;border-spacing:1px;border:1px solid silver;">';
echo '<tr>';
foreach($header as $key=>$field) echo "<th style='padding:4px;background-color:#008bca;color:#fff;'>".strtoupper($key)."</th>";
echo '</tr>';
foreach($datapage as $records){
echo '<tr>';
foreach($records as $field){
echo "<td style='padding:4px;background-color:#eaeaea;color:#000;'>";
echo is_array($field)?var_export($field):$field;
echo "</td>";
}
echo '</tr>';
}
echo '</table>';
echo '</div>';
}
echo '<br/>';
}
}
}
function printScript(){
?>
<script runat="server" type="text/javascript">
function eraseChild(el){
if(el) while(el.hasChildNodes()) el.removeChild(el.firstChild);
}
function createPageNumber(navID,className,pageNum,maxPage,interval){
if(interval<1) interval=1;
skip=pageNum>interval?pageNum-interval:0;
step=maxPage<interval?maxPage:interval;
idxPage=new Array();
for(i=1;i<=step;i++) idxPage[i-1]=skip+i;
el = document.getElementById('nav-pagenum'+navID);
if(el){
eraseChild(el);
for(i=0;i<idxPage.length;i++) {
obj=document.createElement('button');
obj.style.margin='0 2px';
obj.style.padding='4px';
obj.style.minWidth='32px';
obj.style.border='1px solid silver';
if(pageNum==idxPage[i]){
obj.style.backgroundColor='#008bca';
obj.style.color='#fff';
}
else{
obj.style.backgroundColor='#fafafa';
obj.style.color='#333';
}
obj.style.cursor='pointer';
obj.style.outline='none';
obj.appendChild(document.createTextNode(idxPage[i]));
obj.onclick=function(){
goPageTable(navID,className,this.firstChild.nodeValue,maxPage);
}
el.appendChild(obj);
}
}
}
function goPageTable(navID,className,sign,maxPage){
currentPage=0;
for(i=1;i<=maxPage;i++){
el = document.getElementById(className+i);
if(el){
if(el.style.display=='block') currentPage=i;
el.style.display='none';
}
}
switch(sign){
case '<':pageNum=1;break;
case '-':pageNum=currentPage-1<1?1:currentPage-1;break;
case '+':pageNum=currentPage+1>maxPage?maxPage:currentPage+1;break;
case '>':pageNum=maxPage;break;
default :pageNum=parseInt(sign);break;
}
createPageNumber(navID,className,pageNum,maxPage,5);
el=document.getElementById(className+pageNum);
if(el) el.style.display='block';
}
</script>
<?php
}
if(floatval(phpversion())<5.5){
echo "Saat ini anda menggunakan PHP versi ".phpversion().", aplikasi ini hanya dapat digunakan pada PHP versi >= 5.5";
exit(0);
}