1: <?php
2:
3: define("MODE_INJECT_INDIVIDU", 1);
4: define("MODE_INJECT_MASSAL", 2);
5: define("MODE_INJECT_GAGAL", 3);
6:
7: require_once ("lib/nusoap.php");
8: require_once ("lib/class.wsdlcache.php");
9:
10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class webservice
21: {
22: var $proxy;
23: var $pddikti;
24: var $institusi;
25: var $sekarang;
26: var $debug;
27: var $status;
28: var $mapdb;
29: var $db;
30: var $nbaris_tabel;
31:
32:
33:
34: 35: 36: 37: 38: 39: 40: 41: 42:
43: function webservice($pddikti, $institusi, $debug=false)
44: {
45:
46: ob_start();
47:
48: set_time_limit(EXECUTION_TIME_LIMIT);
49:
50: $this->pddikti = $pddikti;
51: $this->institusi = $institusi;
52: $this->debug = $debug;
53: $this->status = array("status" => true, "pesankesalahan" => "");
54:
55: if ($this->debug)
56: {
57: echo $this->mode();
58: $this->print_r_rapi($this->pddikti);
59: }
60:
61: $this->persiapan();
62:
63: $this->periksa();
64: }
65:
66: 67: 68:
69: function __destruct()
70: {
71:
72: if ($this->debug)
73: {
74: echo "Bersih-bersih";
75: }
76:
77: $this->kirim_buffer();
78:
79: unset($this->proxy);
80: unset($this->pddikti);
81: unset($this->institusi);
82: unset($this->now);
83: unset($this->debug);
84: unset($this->status);
85: unset($this->mapdb);
86: unset($this->db);
87:
88: ob_end_clean();
89: }
90:
91: 92: 93:
94: function kirim_buffer()
95: {
96: ob_flush();
97: flush();
98: }
99:
100: 101: 102:
103: function persiapan()
104: {
105:
106: $this->terhubung_proxy();
107:
108: $this->penokenan();
109: }
110:
111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122:
123: function ping($host,$port=80,$waktutunggu=6)
124: {
125:
126: $fsock = fsockopen(str_replace("http://", "", $host), $port, $errno = 0, $errstr = "", $waktutunggu);
127:
128: if ( ! $fsock )
129: {
130: fclose($fsock);
131: return false;
132: }
133:
134: else
135: {
136: fclose($fsock);
137: return true;
138: }
139: }
140:
141: 142: 143:
144: function terhubung_proxy()
145: {
146:
147: $klien = new nusoap_client($this->pddikti["ws"]["url"], true);
148:
149: if (!$this->ping($this->pddikti["ws"]["host"], $this->pddikti["ws"]["port"]))
150: {
151: $this->status = array("status" => false, "pesankesalahan" => "Terjadi kegagalan koneksi. Apakah server FEEDER DIKTI mati?");
152: }
153:
154: else
155: {
156: $this->pddikti["proxy"] = $klien->getProxy();
157: }
158:
159: unset($klien);
160: }
161:
162: 163: 164: 165: 166: 167: 168:
169: function mode()
170: {
171: return "Mode saat ini adalah ".(($this->pddikti["ws"]["mode"]==MODE_SANDBOX)?"sandbox (percobaan)":"live (langsung)")."<br />";
172: }
173:
174: 175: 176:
177: function penokenan()
178: {
179: if ($this->status_periksa())
180: {
181:
182: $this->now = date('Y-m-d H:i:s');
183:
184: if ($_SESSION["expire"] == "" || $_SESSION["expire"] < $this->now)
185: {
186:
187: if ($_SESSION["expire"] < $this->now)
188: {
189:
190: $_SESSION["token"] = $this->token();
191: }
192:
193: $_SESSION["expire"] = date('Y-m-d H:i:s', strtotime($this->now) + $this->pddikti["ws"]["expire"] - 120);
194: }
195:
196: if ($this->debug)
197: {
198: $this->print_r_rapi($_SESSION);
199: }
200: }
201: }
202:
203: 204: 205: 206: 207:
208: function token()
209: {
210:
211: return $this->pddikti["proxy"]->getToken($this->pddikti["login"]["username"], $this->pddikti["login"]["password"]);
212: }
213:
214: 215: 216: 217: 218:
219: function status_periksa()
220: {
221: if (!$this->status["status"])
222: {
223: echo "<br />".$this->status["pesankesalahan"];
224: }
225: return $this->status["status"];
226: }
227:
228: 229: 230:
231: function periksa()
232: {
233:
234: if ($this->status_periksa())
235: {
236:
237: $hasil = $this->GetVersion();
238:
239: $this->status = (($hasil["error_code"] == 104)?array("status" => false, "pesankesalahan" => "Webservice sudah expired. Pastikan server tidak di belakang Proxy, selanjutnya ikuti petunjuk yang ada pada manual FEEDER DIKTI"):array("status" => true, "pesankesalahan" => ""));
240:
241: if (!$this->status_periksa())
242: {
243: $_SESSION["expire"] = '2010-01-01 00:00:00';
244: }
245:
246: unset($hasil);
247:
248: $this->kirim_buffer();
249: }
250: }
251:
252: 253: 254: 255: 256:
257: function setMapdb($mapdb)
258: {
259: $this->mapdb = $mapdb;
260:
261: if ($this->debug)
262: {
263: $this->print_r_rapi($this->mapdb);
264: }
265: }
266:
267:
268:
269:
270:
271: 272: 273:
274: function GetDictionary_SemuaTabel()
275: {
276:
277: $daftarTabel = $this->ListTable();
278:
279: echo "<h1>Daftar Tabel</h1>";
280:
281: $this->cetak_tabel_parsial_mulai();
282:
283: $this->cetak_tabel_parsial_indeks($daftarTabel["result"]);
284:
285: foreach ($daftarTabel["result"] as $idx => $data)
286: {
287: $this->cetak_tabel_parsial($data);
288: }
289:
290: $this->cetak_tabel_parsial_akhiri();
291:
292: reset($daftarTabel["result"]);
293: foreach ($daftarTabel["result"] as $idx => $data)
294: {
295: echo "<h2>Deskripsi Tabel ".$data["table"]."</h2>";
296:
297: $deskripsiTabel = $this->GetDictionary($data["table"]);
298:
299: $deskripsiTabel["result"] = $this->array_auto_fill($deskripsiTabel["result"]);
300:
301: $this->cetak_tabel_parsial_mulai();
302:
303: $this->cetak_tabel_parsial_indeks($deskripsiTabel["result"]);
304:
305: foreach ($deskripsiTabel["result"] as $data_)
306: {
307: $this->cetak_tabel_parsial($data_);
308: }
309:
310: $this->cetak_tabel_parsial_akhiri();
311:
312: unset($deskripsiTabel);
313: }
314:
315: unset($daftarTabel);
316: }
317:
318: 319: 320: 321: 322:
323: function ListTable()
324: {
325:
326: $this->penokenan();
327:
328: return $this->pddikti["proxy"]->ListTable($_SESSION["token"]);
329: }
330:
331: 332: 333: 334: 335: 336: 337:
338: function GetDictionary($tabel)
339: {
340:
341: if ($this->status_periksa())
342: {
343:
344: $this->penokenan();
345:
346: return $this->pddikti["proxy"]->GetDictionary($_SESSION["token"], $tabel);
347: }
348: }
349:
350: 351: 352: 353: 354: 355: 356: 357: 358: 359:
360: function GetRecord($tabel, $filter="")
361: {
362:
363: if ($this->status_periksa())
364: {
365:
366: $this->penokenan();
367:
368: return $this->pddikti["proxy"]->GetRecord($_SESSION["token"], $tabel, $filter);
369: }
370: }
371:
372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387:
388: function GetRecordset($tabel, $filter="", $order="", $batas=1000000, $mulai=0)
389: {
390:
391: if ($this->status_periksa())
392: {
393:
394: $this->penokenan();
395:
396: return $this->pddikti["proxy"]->GetRecordset($_SESSION["token"], $tabel, $filter, $order, $batas, $mulai);
397: }
398: }
399:
400: 401: 402: 403: 404: 405: 406:
407: function GetCountRecordset($tabel)
408: {
409:
410: if ($this->status_periksa())
411: {
412:
413: $this->penokenan();
414:
415: return $this->pddikti["proxy"]->GetCountRecordset($_SESSION["token"], $tabel);
416: }
417: }
418:
419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433:
434: function GetDeletedRecordset($tabel, $filter, $order, $batas=1000000, $mulai=0)
435: {
436:
437: if ($this->status_periksa())
438: {
439:
440: $this->penokenan();
441:
442: return $this->pddikti["proxy"]->GetDeletedRecordset($_SESSION["token"], $tabel, $filter, $order, $batas, $mulai);
443: }
444: }
445:
446: 447: 448: 449: 450: 451: 452:
453: function GetCountDeletedRecordset($tabel)
454: {
455:
456: if ($this->status_periksa())
457: {
458:
459: $this->penokenan();
460:
461: return $this->pddikti["proxy"]->GetCountDeletedRecordset($_SESSION["token"], $tabel);
462: }
463: }
464:
465: 466: 467: 468: 469: 470: 471: 472: 473:
474: function InsertRecord($tabel, $data)
475: {
476:
477: if ($this->status_periksa())
478: {
479:
480: $this->penokenan();
481:
482: return $this->pddikti["proxy"]->InsertRecord($_SESSION["token"], $tabel, json_encode($data, JSON_FORCE_OBJECT));
483: }
484: }
485:
486: 487: 488: 489: 490: 491: 492: 493: 494:
495: function InsertRecordset($tabel, $data)
496: {
497:
498: if ($this->status_periksa())
499: {
500:
501: $this->penokenan();
502:
503: return $this->pddikti["proxy"]->InsertRecordset($_SESSION["token"], $tabel, json_encode($data, JSON_FORCE_OBJECT));
504: }
505: }
506:
507: 508: 509: 510: 511: 512: 513: 514: 515: 516:
517: function UpdateRecord($tabel, $data)
518: {
519:
520: if ($this->status_periksa())
521: {
522:
523: $this->penokenan();
524:
525: return $this->pddikti["proxy"]->UpdateRecord($_SESSION["token"], $tabel, json_encode($data, JSON_FORCE_OBJECT));
526: }
527: }
528:
529: 530: 531: 532: 533: 534: 535: 536: 537: 538:
539: function UpdateRecordset($tabel, $data)
540: {
541:
542: if ($this->status_periksa())
543: {
544:
545: $this->penokenan();
546:
547: return $this->pddikti["proxy"]->UpdateRecordset($_SESSION["token"], $tabel, json_encode($data, JSON_FORCE_OBJECT));
548: }
549: }
550:
551: 552: 553: 554: 555: 556: 557: 558: 559: 560:
561: function DeleteRecord($tabel, $filter)
562: {
563:
564: if ($this->status_periksa())
565: {
566:
567: $this->penokenan();
568:
569: return $this->pddikti["proxy"]->DeleteRecord($_SESSION["token"], $tabel, json_encode($filter, JSON_FORCE_OBJECT));
570: }
571: }
572:
573: 574: 575: 576: 577: 578: 579: 580: 581: 582:
583: function DeleteRecordset($tabel, $filter)
584: {
585:
586: if ($this->status_periksa())
587: {
588:
589: $this->penokenan();
590:
591: return $this->pddikti["proxy"]->DeleteRecordset($_SESSION["token"], $tabel, json_encode($filter, JSON_FORCE_OBJECT));
592: }
593: }
594:
595: 596: 597: 598: 599: 600: 601: 602: 603: 604:
605: function RestoreRecord($tabel, $filter)
606: {
607:
608: if ($this->status_periksa())
609: {
610:
611: $this->penokenan();
612:
613: return $this->pddikti["proxy"]->RestoreRecord($_SESSION["token"], $tabel, json_encode($filter, JSON_FORCE_OBJECT));
614: }
615: }
616:
617: 618: 619: 620: 621: 622: 623: 624: 625: 626:
627: function RestoreRecordset($tabel, $filter)
628: {
629:
630: if ($this->status_periksa())
631: {
632:
633: $this->penokenan();
634:
635: return $this->pddikti["proxy"]->RestoreRecordset($_SESSION["token"], $tabel, json_encode($filter, JSON_FORCE_OBJECT));
636: }
637: }
638:
639: 640: 641: 642: 643:
644: function GetVersion()
645: {
646:
647: if ($this->status_periksa())
648: {
649: return $this->pddikti["proxy"]->GetVersion($_SESSION["token"]);
650: }
651: }
652:
653: 654: 655: 656: 657:
658: function GetExpired()
659: {
660:
661: if ($this->status_periksa())
662: {
663: return $this->pddikti["proxy"]->GetExpired($_SESSION["token"]);
664: }
665: }
666:
667:
668:
669:
670: 671: 672: 673: 674:
675: function mysqli_terhubung()
676: {
677:
678: $iddb = rand();
679:
680: $this->db["conn"][$iddb] = new mysqli($this->institusi["db"]["host"], $this->institusi["db"]["username"], $this->institusi["db"]["password"], $this->institusi["db"]["database"]);
681: if ($this->db["conn"][$iddb]->connect_error)
682: {
683: die("Koneksi ke basis data Institusi gagal: ".$this->db["conn"][$iddb]->connect_error);
684: }
685: return $iddb;
686: }
687:
688: 689: 690: 691: 692:
693: function mysqli_putus($iddb)
694: {
695: $this->db["conn"][$iddb]->close();
696: }
697:
698: 699: 700: 701: 702:
703: function mysqli_bersihkan($iddb)
704: {
705: if (array_key_exists("result", $this->db))
706: {
707: if (array_key_exists($iddb, $this->db["result"]))
708: {
709: if (is_object($this->db["result"][$iddb]))
710: {
711: $this->db["result"][$iddb]->free();
712: $this->db["result"][$iddb]->close();
713: unset($this->db["result"][$iddb]);
714: }
715: }
716: }
717: if (array_key_exists("field", $this->db))
718: {
719: unset($this->db["field"][$iddb]);
720: }
721: }
722:
723: 724: 725: 726: 727: 728: 729: 730: 731:
732: function mysqli_select($iddb, $sql, $filter=array())
733: {
734: $this->db["field"][$iddb] = array();
735:
736: $sql .= ((!array_key_exists("where", $filter)) ? "" : ((trim($filter["where"]) == "") ? "" : " where ".$filter["where"])).((!array_key_exists("order by", $filter)) ? "" : ((trim($filter["order by"]) == "") ? "" : " order by ".$filter["order by"])).((!array_key_exists("limit", $filter)) ? "" : ((trim($filter["limit"]) == "") ? "" : " limit ".$filter["limit"]));
737:
738: $this->db["result"][$iddb] = $this->db["conn"][$iddb]->query($sql);
739: echo $sql;
740:
741: if ($this->db["result"][$iddb]->num_rows>0)
742: {
743: $finfo = $this->db["result"][$iddb]->fetch_fields();
744: foreach ($finfo as $val)
745: {
746: $this->db["field"][$iddb][] = $val->name;
747: }
748: }
749:
750: $this->db["error"][$iddb] = $this->db["conn"][$iddb]->error;
751:
752: if ($this->debug)
753: {
754: echo $sql."<br />";
755: }
756: }
757:
758: 759: 760: 761: 762: 763: 764:
765: function mysqli_iud($iddb, $sql)
766: {
767:
768: $this->db["conn"][$iddb]->query($sql);
769:
770: $this->db["error"][$iddb] = $this->db["conn"][$iddb]->error;
771: }
772:
773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785:
786: function mysqli_mapdb_select($iddb, $tabel, $filter=array(), $iscek=false, $iscetak=false)
787: {
788:
789: if (! empty($this->mapdb["table"][$tabel]["nama"]))
790: {
791:
792: $sql = "select ".implode(",", array_filter($this->mapdb["field"][$tabel]))." from ".$this->mapdb["table"][$tabel]["nama"].(($iscek) ? " where null" : "");
793:
794: $this->mysqli_select($iddb, $sql, $filter);
795: }
796:
797: if ($iscetak)
798: {
799: $kolom = $this->infokolominstitusi_mapdb($tabel);
800: while($row = $this->db["result"][$iddb]->fetch_assoc())
801: {
802: for ($i=0; $i<$kolom["count"]; $i++)
803: {
804: echo $kolom["value"][$i].": ".$row[$kolom["value"][$i]];
805: }
806: echo "<br />";
807: }
808:
809: unset($kolom);
810: }
811: }
812:
813: 814: 815: 816: 817: 818: 819:
820: function infokolominstitusi_mapdb($tabel)
821: {
822:
823: $kolom["map"] = $this->mapdb["field"][$tabel];
824:
825: $kolom["count"] = count($kolom["map"]);
826:
827: foreach($kolom["map"] as $kolom["ws"] => $kolom["institusi"])
828: {
829: $kolom["value"][] = $kolom["institusi"];
830: }
831: return $kolom;
832: }
833:
834:
835:
836:
837: 838: 839: 840: 841:
842: function cek_tabel($exception=array())
843: {
844:
845: $listtable = $this->ListTable();
846: echo "<hr><h1>Check Mapping</h1>";
847: echo "<ol><li>Tabel Referensi akan dilihat datanya, selain itu hanya melihat <em>mapping</em> saja</li><li>Apabila ada ketidak-sesuaian antara isi tabel Institusi dan tabel FEEDER PDDIKTI, maka yang harus disesuaikan adalah isi tabel Institusi</li><li>Info selengkapnya dapat dibaca di: <a href='http://bpti.say.ac.id/check-mapping-pada-injector-feeder-dikti-perlukah/'>Check Mapping pada Injector FEEDER DIKTI, Perlukah?</a></li></ol>";
848:
849: $this->kirim_buffer();
850: $iddb = $this->mysqli_terhubung();
851:
852: foreach ($listtable["result"] as $tabel)
853: {
854:
855: $i = 0;
856: echo "<h2>Tabel ".$tabel["table"]."</h2>";
857:
858: if (count($this->mapdb["table"][$tabel["table"]]["nama"])==0 || $this->mapdb["table"][$tabel["table"]]["nama"]=="")
859: {
860: echo "Warning! Tabel ".$tabel["table"]." belum dipetakan";
861: }
862:
863: else
864: {
865: echo "Tabel ".$tabel["table"]." dipetakan ke tabel ".$this->mapdb["table"][$tabel["table"]]["nama"]."<br />";
866:
867: $listfield = $this->GetDictionary($tabel["table"]);
868: foreach ($listfield["result"] as $idx_field => $kolom)
869: {
870:
871: echo (($this->mapdb["table"][$tabel["table"]]["nama"][$idx_field]=="") ? "Warning! Field ".$tabel["table"].".".$idx_field." belum dipetakan" : "Field ".$tabel["table"].".".$idx_field." dipetakan ke field ".$this->mapdb["table"][$tabel["table"]]["nama"].".".$this->mapdb["field"][$tabel["table"]][$idx_field])."<br />";
872: }
873:
874: $this->mysqli_mapdb_select($iddb, $tabel["table"], array(), true);
875: echo (($this->db["error"][$iddb]=="") ? "Tabel ".$tabel["table"]." pada Institusi OK" : $this->db["error"][$iddb])."<br />";
876:
877: $this->mysqli_bersihkan($iddb);
878: unset($listfield);
879: }
880:
881: $this->kirim_buffer();
882:
883: if (strtolower($tabel["jenis"])=="ref")
884: {
885:
886: if (!(count($this->mapdb["table"][$tabel["table"]]["nama"])==0 || $this->mapdb["table"][$tabel["table"]]["nama"]==""))
887: {
888:
889: $this->mysqli_mapdb_select($iddb, $tabel["table"], array("order by" => $this->mapdb["pk"][$tabel["table"]][1], "where" => $this->mapdb["table"][$tabel["table"]]["filter"]));
890: $kolom = $this->infokolominstitusi_mapdb($tabel["table"]);
891:
892:
893: foreach ($kolom["value"] as $idx => $value)
894: {
895: $tabel_ref["header"][] = "ins ".$value;
896: }
897: 898: 899: 900:
901: while($row = $this->db["result"][$iddb]->fetch_assoc())
902: {
903:
904: for ($i=0; $i<$kolom["count"]; $i++)
905: {
906:
907: if ($kolom["value"][$i] == $this->mapdb["pk"][$tabel["table"]][1])
908: {
909:
910: $indeks = trim($row[$this->ignore_alias($kolom["value"][$i])]);
911:
912: $tabel_ref["data"][$indeks][$i] = $row[$this->ignore_alias($kolom["value"][$i])];
913: }
914:
915: else
916: {
917:
918: $tabel_ref["data"][$indeks][$i] .= $row[$this->ignore_alias($kolom["value"][$i])]."; ";
919: }
920: }
921: }
922:
923: $this->mysqli_bersihkan($iddb);
924: unset($kolom);
925: }
926:
927:
928: if (!in_array($tabel["table"], $exception))
929: {
930: $baris = $this->GetCountRecordset($tabel["table"]);
931: $baris = $baris["result"];
932:
933: $hasil = $this->GetRecordset($tabel["table"], "", "", 1, 0);
934:
935: foreach ($hasil["result"][0] as $idx => $value)
936: {
937: $tabel_ref["header"][] = "pdd ".$idx;
938: }
939:
940: if ($this->debug)
941: {
942: $this->print_r_rapi($hasil);
943: }
944:
945: for ($awal=0; $awal < $baris; $awal+=$this->pddikti["ws"]["limit"])
946: {
947:
948: $hasil = $this->GetRecordset($tabel["table"], "", "", $this->pddikti["ws"]["limit"], $awal);
949: foreach ($hasil["result"] as $kolom => $row)
950: {
951:
952: $j = $i;
953:
954: foreach ($row as $idx => $value)
955: {
956:
957: if ($idx == $this->mapdb["pk"][$tabel["table"]][0])
958: {
959: $indeks = trim($value);
960: }
961:
962: $tabel_ref["data"][$indeks][$j] = $value;
963: $j++;
964: }
965: }
966: }
967: }
968:
969: $this->cetak_tabel($tabel_ref["header"], $tabel_ref["data"]);
970:
971: unset($hasil);
972: unset($tabel_ref);
973: }
974: }
975:
976: unset($listtable);
977: $this->mysqli_putus($iddb);
978: }
979:
980: 981: 982: 983: 984: 985: 986: 987: 988: 989: 990: 991: 992:
993: function cetak_recordset($tabel, $filter="", $order="", $batas=1000000, $mulai=0)
994: {
995: $row = array();
996:
997: $this->cetak_tabel_parsial_mulai();
998:
999: $data = $this->GetRecordset($tabel, "", "", 1, 0);
1000:
1001: foreach ($data["result"][0] as $idx => $value)
1002: {
1003: $row[] = $idx;
1004: }
1005:
1006: $this->cetak_tabel_parsial($row, true);
1007:
1008: $data = $this->GetRecordset($tabel, $filter, $order, $batas, $mulai);
1009:
1010: $this->cetak_tabel_parsial($data["result"]);
1011:
1012: $this->cetak_tabel_parsial_akhiri();
1013:
1014: unset($row);
1015: unset($data);
1016: }
1017:
1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027:
1028: function pddikti_sinkron_guid($tabel, $filter="", $filterIns = "")
1029: {
1030:
1031: $tabel_asli = split(" ", $tabel);
1032: $tabel_asli = $tabel_asli[0];
1033: echo "<hr /><h2>Sync ".$tabel.((!array_key_exists("filter", $this->mapdb["guid"][$tabel])) ? "" : ", Filter: ".$this->mapdb["guid"][$tabel]["filter"]).(($filterIns == "") ? "" : " and ".$filterIns)."</h2>";
1034:
1035: if ($this->mapdb["guid"][$tabel]["prerequisite"] != "" && $this->is_exist($filter, $this->mapdb["guid"][$tabel]["prerequisite"], true) == false)
1036: {
1037: echo "Proses sinkronisasi dihentikan karena kebutuhan filter ".$this->mapdb["guid"][$tabel]["prerequisite"]." tidak disediakan. Hal ini untuk menjamin kebenaran data. Mohon hubungi Administrator atau Programmer.";
1038: }
1039:
1040: else
1041: {
1042:
1043: $iddb = $this->mysqli_terhubung();
1044: $this->mysqli_select($iddb, "select ".$this->mapdb["pk"][$tabel][1].",".$this->mapdb["guid"][$tabel]["variable"][1].((!array_key_exists("infotambahanerror", $this->mapdb["guid"][$tabel])) ? "" : (($this->mapdb["guid"][$tabel]["infotambahanerror"] != "") ? ",".$this->mapdb["guid"][$tabel]["infotambahanerror"] : ""))." from ".$this->mapdb["guid"][$tabel]["table"]["check"], array("where" => "(".$this->mapdb["guid"][$tabel]["guid"][1]."=\"\" or isnull(".$this->mapdb["guid"][$tabel]["guid"][1]."))".((!array_key_exists("filter", $this->mapdb["guid"][$tabel])) ? "" : (($this->mapdb["guid"][$tabel]["filter"] != "") ? " and ".$this->mapdb["guid"][$tabel]["filter"] : "")).(($filterIns == "") ? "" : " and ".$filterIns), "order by" => $this->mapdb["guid"][$tabel]["order by"]));
1045:
1046: if ($this->db["result"][$iddb]->num_rows == 0)
1047: {
1048: echo "<br />Tidak ada data yang akan diproses<br />";
1049: }
1050:
1051: else
1052: {
1053: echo "<br />Terdapat ".$this->db["result"][$iddb]->num_rows." data yang akan diproses<br />";
1054: }
1055:
1056: if ($this->db["result"][$iddb]->num_rows > 0)
1057: {
1058: $proses = 0;
1059: $error = 0;
1060:
1061: $v0 = explode(",", $this->mapdb["guid"][$tabel]["variable"][0]);
1062: $v1 = explode(",", $this->mapdb["guid"][$tabel]["variable"][1]);
1063:
1064: $this->cetak_tabel_parsial_mulai();
1065:
1066: $this->cetak_tabel_parsial(array_merge($this->db["field"][$iddb], array("no sync"), array("keterangan")), true);
1067:
1068: while($row = $this->db["result"][$iddb]->fetch_row())
1069: {
1070: $proses++;
1071:
1072: $row["syn"] = $proses;
1073:
1074: $v = array();
1075: reset($v0);
1076:
1077: foreach ($v0 as $idx => $value)
1078: {
1079: 1080: 1081: 1082: 1083:
1084: $v[] = (!(strpos($value, ".")!==false || strpos($value, "raw.")!==false)) ? "trim(".$value.")='".$row[$idx+1]."'" : ((strpos($value, "raw.")!==false)?substr($value, 4):$value)."='".$row[$idx+1]."'";
1085: }
1086:
1087: $rec = $this->GetRecordset($tabel_asli, (($filter)?$filter." and ":"").implode(" and ", $v));
1088:
1089: if (!is_array($rec["result"]))
1090: {
1091: $error++;
1092: $row["ket"] = "filter ".implode(" dan ", $v)." tidak ditemukan di tabel $tabel_asli FEEDER PDDIKTI";
1093: $this->cetak_tabel_parsial($row);
1094: }
1095: 1096: 1097:
1098: elseif (count($rec["result"]) > 1)
1099: {
1100:
1101: if (!is_array($this->mapdb["guid"][$tabel]["forcedouble"]))
1102: {
1103: $error++;
1104: $row["ket"] = "filter ".implode(" dan ", $v)." ditemukan lebih dari satu di tabel $tabel_asli FEEDER PDDIKTI"
1105: .$this->cetak_tabel_parsial_mulai(2, 2)
1106: .$this->cetak_tabel_parsial($rec["result"], false, 2, 2)
1107: .$this->cetak_tabel_parsial_akhiri(2, 2);
1108: }
1109:
1110: else
1111: {
1112:
1113: $row["ket"] = "notice! filter ".implode(" dan ", $v)." ditemukan lebih dari satu di tabel $tabel_asli FEEDER PDDIKTI, tetapi sudah dijadikan satu."
1114: .$this->cetak_tabel_parsial_mulai(2, 2)
1115: .$this->cetak_tabel_parsial($rec["result"], false, 2, 2)
1116: .$this->cetak_tabel_parsial_akhiri(2, 2);
1117:
1118: $upd = $rec["result"][count($rec["result"]) - 1][$this->mapdb["guid"][$tabel]["forcedouble"]["field"]];
1119:
1120: $this->mysqli_iud($iddb, "update ".$this->mapdb["guid"][$tabel]["table"]["update"]." set ".$this->mapdb["guid"][$tabel]["guid"][1]."='".$upd."' where ".$this->mapdb["pk"][$tabel][1]."='".$row[0]."'");
1121:
1122: foreach ($rec["result"] as $idx => $val)
1123: {
1124:
1125: if ($val[$this->mapdb["guid"][$tabel]["forcedouble"]["field"]] != $upd)
1126: {
1127:
1128: $dataupdate = array(array("key"=>array($this->mapdb["guid"][$tabel]["forcedouble"]["field"] => $val[$this->mapdb["guid"][$tabel]["forcedouble"]["field"]]), "data"=>array($this->mapdb["guid"][$tabel]["forcedouble"]["field"]=>$upd)));
1129: $hasil = $this->UpdateRecordset($this->mapdb["guid"][$tabel]["forcedouble"]["table"], $dataupdate);
1130:
1131: if ($hasil["result"]["error_desc"] != "")
1132: {
1133: $row["ket"] .= "<br />Error: ".$hasil["result"]["error_desc"];
1134: }
1135:
1136: $datadelete = array(array($this->mapdb["guid"][$tabel]["forcedouble"]["field"] => $val[$this->mapdb["guid"][$tabel]["forcedouble"]["field"]]));
1137: $this->DeleteRecordset($this->mapdb["guid"][$tabel]["forcedouble"]["table"], $datadelete);
1138:
1139: unset($dataupdate, $datadelete);
1140: }
1141: }
1142: }
1143: $this->cetak_tabel_parsial($row);
1144: }
1145:
1146: else
1147: {
1148:
1149: $g = explode(",", $this->mapdb["guid"][$tabel]["guid"][0]);
1150:
1151: if ($rec["result"][0][$g[0]] != "")
1152: {
1153: reset($g);
1154: $upd = array();
1155:
1156: foreach ($g as $idx => $val)
1157: {
1158: $upd[] = "'".$rec["result"][0][$val]."'";
1159: }
1160: $upd = "concat(".implode(",", $upd).")";
1161:
1162: echo "<br />Sync >>".$proses.">> table institusi ".$this->mapdb["guid"][$tabel]["table"]["update"]." dengan data ".$this->mapdb["guid"][$tabel]["guid"][1]."=".$upd." dimana ".$this->mapdb["pk"][$tabel][1]."='".$row[0]."' [OK]";
1163: $this->mysqli_iud($iddb, "update ".$this->mapdb["guid"][$tabel]["table"]["update"]." set ".$this->mapdb["guid"][$tabel]["guid"][1]."=".$upd." where ".$this->mapdb["pk"][$tabel][1]."='".$row[0]."'");
1164:
1165: if ($this->db["error"][$iddb] != "")
1166: {
1167: $error++;
1168: echo "Error! ".$this->db["error"][$iddb];
1169: }
1170: }
1171:
1172: else
1173: {
1174: $error++;
1175: $row["ket"] = "filter ".implode(" dan ", $v)." tidak ditemukan di tabel $tabel_asli FEEDER PDDIKTI";
1176: $this->cetak_tabel_parsial($row);
1177: }
1178:
1179: if ($proses % 50 == 0)
1180: {
1181: echo "<br />Sync ".$tabel." ($proses dari ".$this->db["result"][$iddb]->num_rows.")...<br />";
1182: $this->kirim_buffer();
1183: }
1184:
1185: unset($g);
1186: }
1187:
1188: unset($rec);
1189: }
1190: echo "<br />Sync ".$tabel." ($proses dari ".$this->db["result"][$iddb]->num_rows.")...<br />";
1191:
1192: $this->cetak_tabel_parsial_akhiri();
1193:
1194: if ($error == 0)
1195: {
1196: echo "$proses proses sync berhasil";
1197: }
1198: else
1199: {
1200: echo "$error kesalahan ditemukan pada $proses proses sync";
1201: }
1202:
1203: unset($row);
1204: unset($v0, $v1, $v);
1205: }
1206:
1207: else
1208: {
1209: echo "Tidak ada proses sync. Mungkin semua data sudah sinkron";
1210: }
1211:
1212: $this->mysqli_bersihkan($iddb);
1213: $this->mysqli_putus($iddb);
1214: }
1215: }
1216:
1217: 1218: 1219: 1220: 1221: 1222: 1223:
1224: function tahunakademiksebelum($tahunakademik)
1225: {
1226: return (($tahunakademik % 2 == 0) ? $tahunakademik-1 : ((floor($tahunakademik/10)-1)*10)+2);
1227: }
1228:
1229: 1230: 1231: 1232: 1233: 1234: 1235:
1236: function pddikti_ekstrak($tahunakademikkrs, $tabel)
1237: {
1238:
1239: $tahunakademikkrs = (($this->mapdb["extract"][$tabel]["istahunakademikkrs"]) ? $tahunakademikkrs : $this->tahunakademiksebelum($tahunakademikkrs));
1240: echo "<hr /><h2>EXTRACT Data $tabel $tahunakademikkrs</h2>";
1241:
1242: $n = $this->GetCountRecordset($tabel, $filter);
1243: $v0 = explode(",", $this->mapdb["extract"][$tabel]["uniquefield"][0]);
1244: $v1 = explode(",", $this->mapdb["extract"][$tabel]["uniquefield"][1]);
1245: $iddb = $this->mysqli_terhubung();
1246: $proses = 0;
1247:
1248: $filter = str_replace("[tahun]", substr($tahunakademikkrs, 0, 4), str_replace("[tahunakademik]", $tahunakademikkrs, $this->mapdb["extract"][$tabel]["filtertahunakademik"]));
1249: $data = $this->GetRecordset($tabel, $filter);
1250:
1251: foreach ($data["result"] as $row)
1252: {
1253: $v = array();
1254: reset($v1);
1255:
1256: foreach ($v0 as $idx => $value)
1257: {
1258: $v[] = $value."='".$row[$v1[$idx]]."'";
1259: }
1260:
1261: $columnlist = array();
1262: $datalist = array();
1263: foreach ($this->mapdb["field"][$tabel] as $idx=>$value)
1264: {
1265: if ($value != "null")
1266: {
1267: $columnlist[] = $value;
1268: $datalist[] = "'".$row[$idx]."'";
1269: }
1270: }
1271:
1272: $this->mysqli_iud($iddb, "insert into ".$this->mapdb["extract"][$tabel]["table"]." (".implode(",", $columnlist).") select ".implode(",", $datalist)." from ".$this->mapdb["extract"][$tabel]["table"]." where not exists (select 1 from ".$this->mapdb["extract"][$tabel]["table"]." where ".implode(" and ", $v).") limit 0,1");
1273: echo "<br /><b>--Extract >>".++$proses.">> </b> insert jika belum ada data pada tabel institusi ".$this->mapdb["extract"][$tabel]["table"]." dengan data ".implode(",", $datalist);
1274:
1275: if ($proses % 50 == 0)
1276: {
1277: echo "<br />Extract $tabel ($proses dari ".$n["result"].")...<br />";
1278: $this->kirim_buffer();
1279: }
1280: }
1281: echo "<br />Extract $tabel ($proses dari ".$n["result"].")...<br />Proses telah selesai!";
1282:
1283: $this->kirim_buffer();
1284:
1285: unset($row);
1286: unset($v, $v0, $v1, $columnlist, $datalist);
1287: $this->mysqli_bersihkan($iddb);
1288: $this->mysqli_putus($iddb);
1289: }
1290:
1291: 1292: 1293: 1294: 1295: 1296: 1297:
1298: function cek_penugasan($tahunakademik)
1299: {
1300:
1301: $this->update_nidn();
1302:
1303: $this->pddikti_ekstrak($tahunakademik, "dosen_pt");
1304:
1305: $tahunakademik = $this->tahunakademiksebelum($tahunakademik);
1306: echo "<hr /><h3>Cek Penugasan Untuk Transaksi T.A. $tahunakademik</h3>";
1307: $iddb = $this->mysqli_terhubung();
1308:
1309: $que = "select distinct guiddosen, namalengkap from ((select guiddosen, namalengkap from ak_jadwalkuliah jk join ak_timteaching tt on tt.kdtimteaching=ifnull(jk.kdtimteachingperubahan, jk.kdtimteaching) join ak_penawaranmatakuliah pm on pm.kdpenawaran=tt.kdpenawaran join pt_person p on p.kdperson=tt.kdpersonepsbed where tt.kdtahunakademik=".$tahunakademik." and tt.isignore=0 and pm.isignore=0 and jk.kdtahunakademik=".$tahunakademik." and pm.kdtahunakademik=".$tahunakademik." and isrealisasi=1) union all (select guiddosen, namalengkap from ak_jadwalkuliah_lab jk join ak_timteaching_lab tt on tt.kdtimteaching=ifnull(jk.kdtimteachingperubahan, jk.kdtimteaching) join ak_kelompok kl on kl.kdkelompok=tt.kdkelompok join ak_penawaranmatakuliah pm on pm.kdpenawaran=kl.kdpenawaran join pt_person p on p.kdperson=tt.kdpersonepsbed where tt.kdtahunakademik=".$tahunakademik." and tt.isignore=0 and pm.isignore=0 and jk.kdtahunakademik=".$tahunakademik." and pm.kdtahunakademik=".$tahunakademik." and isrealisasi=1)) cek_dosen where guiddosen not in (select id_sdm from ak_penugasan where tahun=left(".$tahunakademik.", 4))";
1310: $this->mysqli_select($iddb, $que);
1311:
1312: $this->cetak_tabel_parsial_mulai();
1313:
1314: while ($row = $this->db["result"][$iddb]->fetch_assoc())
1315: {
1316: $this->cetak_tabel_parsial($row);
1317: }
1318:
1319: $issemuapenugasan = ($this->db["result"][$iddb]->num_rows == 0);
1320:
1321: $this->cetak_tabel_parsial_akhiri();
1322:
1323: $this->mysqli_bersihkan($iddb);
1324: $this->mysqli_putus($iddb);
1325: return $issemuapenugasan;
1326: }
1327:
1328: 1329: 1330:
1331: function update_nidn()
1332: {
1333: echo "<hr /><h2>Update NIDN</h2>";
1334: $proses = 0;
1335: $n = $this->GetCountRecordset($this->mapdb["updatenidn"]["table"][0]);
1336:
1337: $data = $this->GetRecordset($this->mapdb["updatenidn"]["table"][0]);
1338:
1339: $iddb = $this->mysqli_terhubung();
1340: foreach ($data["result"] as $row)
1341: {
1342:
1343: $this->mysqli_iud($iddb, "update ".$this->mapdb["updatenidn"]["table"][1]." set ".$this->mapdb["updatenidn"]["nidn"][1]."='".$row[$this->ignore_alias($this->mapdb["updatenidn"]["nidn"][0])]."' where ".str_replace(":guid",$row[$this->ignore_alias($this->mapdb["updatenidn"]["guid"])],$this->mapdb["updatenidn"]["filter"]));
1344:
1345: if (++$proses % 50 == 0)
1346: {
1347: echo "<br />Update NIDN ($proses dari ".$n["result"].")...<br />";
1348: $this->kirim_buffer();
1349: }
1350:
1351: $this->mysqli_bersihkan($iddb);
1352: }
1353: echo "<br />Update NIDN ($proses dari ".$n["result"].")...<br />Proses telah selesai!";
1354:
1355: $this->kirim_buffer();
1356:
1357: unset($data);
1358: $this->mysqli_putus($iddb);
1359: }
1360:
1361: 1362: 1363: 1364: 1365: 1366: 1367: 1368: 1369: 1370: 1371: 1372: 1373: 1374: 1375:
1376: function filtertahunakademik($tahunakademik, $tandatahunakademik, $istahunakademikkrs, $tahunakademikkrs, $tahunakademiksebelum)
1377: {
1378:
1379: $array_tahunakademik = split(",", $tahunakademik);
1380: $array_filter = array();
1381:
1382: if (is_array($array_tahunakademik))
1383: {
1384:
1385: foreach ($array_tahunakademik as $value_tahunakademik)
1386: {
1387: $array_filter[] = $value_tahunakademik.$tandatahunakademik.(($istahunakademikkrs) ? $tahunakademikkrs : $tahunakademiksebelum);
1388: }
1389: return implode(" and ", $array_filter);
1390: }
1391:
1392: else
1393: {
1394: return $tahunakademik.$tandatahunakademik.(($istahunakademikkrs) ? $tahunakademikkrs : $tahunakademiksebelum);
1395: }
1396: }
1397:
1398: 1399: 1400: 1401: 1402: 1403: 1404:
1405: function pddikti_injek($tahunakademikkrs, $tabelinjectindividual="")
1406: {
1407: echo "<hr /><h2>INJECT Data $tahunakademikkrs</h2>";
1408:
1409: $tahunakademiksebelum = $this->tahunakademiksebelum($tahunakademikkrs);
1410:
1411: if(!$this->cek_penugasan($tahunakademikkrs))
1412: {
1413: echo "<br /><H2>Belum semua Dosen didaftarkan pada Penugasan, proses INJECT PDDIKTI dibatalkan. Silakan daftarkan semua nama Dosen di atas<br />";
1414: exit();
1415: }
1416: $iddb = $this->mysqli_terhubung();
1417: foreach ($this->mapdb["inject"] as $tabel => $inject)
1418: {
1419: 1420: 1421: 1422:
1423: if ($tabelinjectindividual!="" && $tabelinjectindividual==$tabel)
1424: {
1425: $mode = MODE_INJECT_INDIVIDU;
1426: }
1427: else if ($tabelinjectindividual=="" && $inject["ignoreinject"]==false)
1428: {
1429: $mode = MODE_INJECT_MASSAL;
1430: }
1431: else
1432: {
1433: $mode = MODE_INJECT_GAGAL;
1434: }
1435:
1436: if($mode == MODE_INJECT_INDIVIDU || $mode == MODE_INJECT_MASSAL)
1437: {
1438: $proses = 0;
1439: $tabel_asli = split(" ", $tabel);
1440: $tabel_asli = $tabel_asli[0];
1441: 1442: 1443:
1444: 1445: 1446: 1447: 1448: 1449: 1450: 1451:
1452: echo "<hr /><h3>Inject $tabel ".(($inject["istahunakademikkrs"]) ? $tahunakademikkrs : $tahunakademiksebelum)." - Metode ".$inject["type"]."</h3><br />";
1453:
1454: $param = array();
1455:
1456: if ($inject["type"]=="insert")
1457: {
1458:
1459: foreach ($this->mapdb["field"][$tabel] as $pddikti => $institusi)
1460: {
1461: if ($pddikti != $this->mapdb["pk"][$tabel][0])
1462: {
1463: $param[] = $institusi;
1464: }
1465: }
1466: }
1467:
1468: else if ($inject["type"]=="update")
1469: {
1470:
1471: foreach ($inject["fieldwhere"] as $idx => $pddikti)
1472: {
1473: $param[] = $this->mapdb["field"][$tabel][$this->ignore_alias($pddikti)];
1474: }
1475: foreach ($inject["fieldupdate"] as $idx => $pddikti)
1476: {
1477: $param[] = $this->mapdb["field"][$tabel][$this->ignore_alias($pddikti)];
1478: }
1479: }
1480:
1481: if (array_key_exists("jenisfilter", $inject))
1482: {
1483:
1484: if ($inject["jenisfilter"] == "internalfilter")
1485: {
1486:
1487: if (array_key_exists("tahunakademik", $inject))
1488: {
1489: $que = str_replace("[internalfilter]", $this->filtertahunakademik($inject["tahunakademik"], $inject["tandatahunakademik"], $inject["istahunakademikkrs"], $tahunakademikkrs, $tahunakademiksebelum)." and isnull(".$this->mapdb["field"][$tabel][$this->ignore_alias($this->mapdb["pk"][$tabel][0])].")".((!array_key_exists("filter", $inject)) ? "" : (($inject["filter"] != "") ? " and ".$inject["filter"] : "")), $inject["table"]);
1490: }
1491:
1492: else
1493: {
1494: $que = str_replace("[internalfilter]", "isnull(".$this->mapdb["field"][$tabel][$this->ignore_alias($this->mapdb["pk"][$tabel][0])].")".((!array_key_exists("filter", $inject)) ? "" : (($inject["filter"] != "") ? " and ".$inject["filter"] : "")), $inject["table"]);
1495: }
1496:
1497: $this->mysqli_select($iddb, $que);
1498: }
1499: }
1500:
1501: else
1502: {
1503:
1504: if (array_key_exists("tahunakademik", $inject))
1505: {
1506: $this->mysqli_select($iddb, "select ".$this->mapdb["pk"][$tabel][1].",".implode(",", $param).((!array_key_exists("infotambahanerror", $inject)) ? "" : (($inject["infotambahanerror"] != "") ? ",".$inject["infotambahanerror"] : ""))." from ".$inject["table"], array("where" => $this->filtertahunakademik($inject["tahunakademik"], $inject["tandatahunakademik"], $inject["istahunakademikkrs"], $tahunakademikkrs, $tahunakademiksebelum)." and isnull(".$this->mapdb["field"][$tabel][$this->ignore_alias($this->mapdb["pk"][$tabel][0])].")".((!array_key_exists("filter", $inject)) ? "" : (($inject["filter"] != "") ? " and ".$inject["filter"] : ""))));
1507: }
1508:
1509: else
1510: {
1511: $this->mysqli_select($iddb, "select ".$this->mapdb["pk"][$tabel][1].",".implode(",", $param).((!array_key_exists("infotambahanerror", $inject)) ? "" : (($inject["infotambahanerror"] != "") ? ",".$inject["infotambahanerror"] : ""))." from ".$inject["table"], array("where" => "isnull(".$this->mapdb["field"][$tabel][$this->ignore_alias($this->mapdb["pk"][$tabel][0])].")".((!array_key_exists("filter", $inject)) ? "" : (($inject["filter"] != "") ? " and ".$inject["filter"] : ""))));
1512: }
1513: }
1514: $error = 0;
1515:
1516: if ($this->db["result"][$iddb]->num_rows == 0)
1517: {
1518: echo "<br />Tidak ada data yang akan diproses<br />";
1519: }
1520:
1521: else
1522: {
1523: echo "<br />Terdapat ".$this->db["result"][$iddb]->num_rows." data yang akan diproses<br />";
1524:
1525: $this->cetak_tabel_parsial_mulai();
1526:
1527: $this->cetak_tabel_parsial(array_merge($this->db["field"][$iddb], array("no sync"), array("keterangan")), true);
1528:
1529: if ($inject["type"]=="insert")
1530: {
1531:
1532: while($row = $this->db["result"][$iddb]->fetch_assoc())
1533: {
1534: $proses++;
1535:
1536: $data = array();
1537: reset($this->mapdb["field"][$tabel]);
1538: foreach ($this->mapdb["field"][$tabel] as $pddikti => $institusi)
1539: {
1540:
1541: if ($pddikti != $this->mapdb["pk"][$tabel][0])
1542: {
1543: if ($row[$this->ignore_alias($institusi)] != null)
1544: {
1545: $data[$pddikti] = $row[$this->ignore_alias($institusi)];
1546: }
1547: }
1548: }
1549:
1550: $hasil = $this->InsertRecord($tabel_asli, $data);
1551:
1552: if ($hasil["result"]["error_desc"] != "")
1553: {
1554: $error++;
1555: $row["no sync"] = $proses;
1556: $row["ket"] = $hasil["result"]["error_desc"];
1557: $this->cetak_tabel_parsial($row);
1558: }
1559: 1560: 1561: 1562:
1563: else if ($hasil["result"][$this->mapdb["guid"][$tabel_asli]["guid"][0]] != "")
1564: {
1565: echo "<br /><b>Sisip >>".$proses.">> </b>";
1566: print_r($data);
1567: echo "<b> [OK]</b>";
1568:
1569: if ($mode == MODE_INJECT_MASSAL)
1570: {
1571: $upd = $hasil["result"][$this->mapdb["guid"][$tabel_asli]["guid"][0]];
1572: echo "<br /><b>--Sync Sisip >>".$proses.">> </b> sync tabel institusi ".$this->mapdb["guid"][$tabel]["table"]["update"]." dengan data ".$this->mapdb["guid"][$tabel]["guid"][1]."='".$upd."' dimana ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'";
1573: $this->mysqli_iud($iddb, "update ".$this->mapdb["guid"][$tabel]["table"]["update"]." set ".$this->mapdb["guid"][$tabel]["guid"][1]."='".$upd."' where ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'");
1574: }
1575: }
1576: 1577: 1578:
1579: else
1580: {
1581: echo "<br /><b>Sisip >>".$proses.">> </b>";
1582: print_r($data);
1583: echo "<b> [OK]</b>";
1584:
1585: if ($mode == MODE_INJECT_MASSAL)
1586: {
1587: $g = explode(",", $this->mapdb["guid"][$tabel]["guid"][0]);
1588: reset($g);
1589: $upd = array();
1590: foreach ($g as $idx => $val)
1591: {
1592: $upd[] = "'".$row[$this->ignore_alias($this->mapdb["field"][$tabel][$this->ignore_alias($val)])]."'";
1593: }
1594: $upd = "concat(".implode(",", $upd).")";
1595: echo "<br /><b>--Sync Sisip >>".$proses.">> </b> sync tabel institusi ".$this->mapdb["guid"][$tabel]["table"]["update"]." dengan data ".$this->mapdb["guid"][$tabel]["guid"][1]."=".$upd." dimana ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'";
1596: $this->mysqli_iud($iddb, "update ".$this->mapdb["guid"][$tabel]["table"]["update"]." set ".$this->mapdb["guid"][$tabel]["guid"][1]."=".$upd." where ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'");
1597: }
1598: }
1599:
1600: if ($proses % 50 == 0)
1601: {
1602: echo "<br />Inject $tabel ".(($inject["istahunakademikkrs"]) ? $tahunakademikkrs : $tahunakademiksebelum)." - Metode ".$inject["type"]." ($proses dari ".$this->db["result"][$iddb]->num_rows.")...<br />";
1603: $this->kirim_buffer();
1604: }
1605:
1606: unset($data);
1607: }
1608: }
1609:
1610: else if ($inject["type"]=="update")
1611: {
1612:
1613: while($row = $this->db["result"][$iddb]->fetch_assoc())
1614: {
1615: $proses++;
1616:
1617: $data = array();
1618:
1619: reset($inject["fieldupdate"]);
1620: foreach ($inject["fieldupdate"] as $idx => $pddikti)
1621: {
1622:
1623: if ($row[$this->ignore_alias($this->mapdb["field"][$tabel][$this->ignore_alias($pddikti)])] != null)
1624: {
1625: $data["data"][$pddikti] = $row[$this->ignore_alias($this->mapdb["field"][$tabel][$this->ignore_alias($pddikti)])];
1626: }
1627: }
1628:
1629: reset($inject["fieldwhere"]);
1630: foreach ($inject["fieldwhere"] as $idx => $pddikti)
1631: {
1632:
1633: if ($row[$this->ignore_alias($this->mapdb["field"][$tabel][$this->ignore_alias($pddikti)])] != null)
1634: {
1635: $data["key"][$pddikti] = $row[$this->ignore_alias($this->mapdb["field"][$tabel][$this->ignore_alias($pddikti)])];
1636: }
1637: }
1638:
1639: $hasil = $this->UpdateRecord($tabel_asli, $data);
1640:
1641: if ($hasil["result"]["error_desc"] != "")
1642: {
1643: $error++;
1644: $row["no sync"] = $proses;
1645: $row["ket"] = $hasil["result"]["error_desc"];
1646: $this->cetak_tabel_parsial($row);
1647: }
1648: 1649: 1650:
1651: else if ($hasil["result"][$this->mapdb["guid"][$tabel_asli]["guid"][0]] != "")
1652: {
1653: echo "<br /><b>Ubah >>".$proses.">> </b>";
1654: print_r($data);
1655: echo "<b> [OK]</b>";
1656: if ($mode == MODE_INJECT_MASSAL)
1657: {
1658: $upd = $hasil["result"][$this->mapdb["guid"][$tabel_asli]["guid"][0]];
1659: echo "<br /><b>--Sync Ubah >>".$proses.">> </b> sync tabel institusi ".$this->mapdb["guid"][$tabel]["table"]["update"]." dengan data ".$this->mapdb["guid"][$tabel]["guid"][1]."='".$upd."' dimana ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'";
1660: $this->mysqli_iud($iddb, "update ".$this->mapdb["guid"][$tabel]["table"]["update"]." set ".$this->mapdb["guid"][$tabel]["guid"][1]."='".$upd."' where ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'");
1661: }
1662: }
1663: 1664: 1665:
1666: else
1667: {
1668: echo "<b><br />Ubah >>".$proses.">> </b>";
1669:
1670: print_r($data);
1671: echo "<b> [OK]</b>";
1672: if ($mode == MODE_INJECT_MASSAL)
1673: {
1674: $upd = implode("", $data["key"]);
1675: echo "<br /><b>--Sync Ubah >>".$proses.">> </b> sync tabel institusi ".$this->mapdb["guid"][$tabel]["table"]["update"]." dengan data ".$this->mapdb["guid"][$tabel]["guid"][1]."=".$upd." dimana ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'";
1676: $this->mysqli_iud($iddb, "update ".$this->mapdb["guid"][$tabel]["table"]["update"]." set ".$this->mapdb["guid"][$tabel]["guid"][1]."='".$upd."' where ".$this->mapdb["pk"][$tabel][1]."='".$row[$this->ignore_alias($this->mapdb["pk"][$tabel][1])]."'");
1677: }
1678: }
1679:
1680: if ($proses % 50 == 0)
1681: {
1682: echo "<br />Inject $tabel ".(($inject["istahunakademikkrs"]) ? $tahunakademikkrs : $tahunakademiksebelum)." - Metode ".$inject["type"]." ($proses dari ".$this->db["result"][$iddb]->num_rows.")...";
1683: $this->kirim_buffer();
1684: }
1685:
1686: unset($data);
1687: }
1688: }
1689: $this->cetak_tabel_parsial_akhiri();
1690: }
1691:
1692: echo "<br />Inject $tabel ".(($inject["istahunakademikkrs"]) ? $tahunakademikkrs : $tahunakademiksebelum)." - Metode ".$inject["type"]." ($proses dari ".$this->db["result"][$iddb]->num_rows.")...<br />";
1693: if ($error == 0)
1694: {
1695: echo "$proses proses inject/sync berhasil";
1696: }
1697: else
1698: {
1699: echo "$error kesalahan ditemukan pada $proses proses sync";
1700: }
1701: $this->kirim_buffer();
1702: }
1703:
1704: if ($mode == MODE_INJECT_MASSAL)
1705: {
1706: if (array_key_exists("tahunakademik", $inject))
1707: {
1708: $this->pddikti_sinkron_guid($tabel, "", $inject["tahunakademik"]."=".(($inject["istahunakademikkrs"]) ? $tahunakademikkrs : $tahunakademiksebelum));
1709: }
1710: else
1711: {
1712: $this->pddikti_sinkron_guid($tabel);
1713: }
1714: }
1715: unset($inject);
1716: unset($param);
1717: }
1718:
1719: $this->mysqli_bersihkan($iddb);
1720: $this->mysqli_putus($iddb);
1721: }
1722:
1723:
1724:
1725: 1726: 1727: 1728: 1729: 1730: 1731:
1732: function ignore_alias($str)
1733: {
1734: return (strpos($str, '.') === false) ? $str : substr($str, strpos($str, '.')+1);
1735: }
1736:
1737: 1738: 1739: 1740: 1741: 1742: 1743: 1744: 1745: 1746: 1747:
1748: function is_exist($haysack, $needles, $restrict=false)
1749: {
1750: $needle = split(",", $needles);
1751: $found = 0;
1752: $tobefound = count($needle);
1753: foreach ($needle as $n)
1754: {
1755: if (strpos($haysack, $n)!==false)
1756: {
1757: $found++;
1758: }
1759: }
1760: return (($restrict && $found == $tobefound && $found > 0) || (!$restrict && $found > 0)) ? true : false;
1761: }
1762:
1763: 1764: 1765: 1766: 1767:
1768: function print_r_rapi($arr)
1769: {
1770: echo "<pre>";
1771: print_r($arr);
1772: echo "</pre>";
1773:
1774: $this->kirim_buffer();
1775: }
1776:
1777: 1778: 1779: 1780: 1781: 1782: 1783:
1784: function cetak_tabel($header, $data)
1785: {
1786: echo "<table border='1'>";
1787:
1788: echo "<tr>";
1789: foreach ($header as $idx => $cell)
1790: {
1791: echo "<td>$cell</td>";
1792: }
1793: echo "</tr>";
1794:
1795: $row = 0;
1796: foreach ($data as $idx => $value)
1797: {
1798: echo "<tr>";
1799: for ($i=0; $i<count($header); $i++)
1800: {
1801: echo "<td>".$value[$i]."</td>";
1802: }
1803: echo "</tr>";
1804:
1805: if ($row++ % 1000 == 0)
1806: {
1807: $this->kirim_buffer();
1808: }
1809: }
1810: echo "</table>";
1811: echo "Terdapat $row baris<br />";
1812: }
1813:
1814: 1815: 1816: 1817: 1818: 1819: 1820: 1821:
1822: function countdim($array)
1823: {
1824: if (is_array(reset($array)))
1825: {
1826: $return = $this->countdim(reset($array)) + 1;
1827: }
1828: else
1829: {
1830: $return = 1;
1831: }
1832: return $return;
1833: }
1834:
1835: 1836: 1837: 1838: 1839: 1840: 1841: 1842: 1843:
1844: function cetak_tabel_parsial_mulai($id=1, $mode=1)
1845: {
1846: $this->table_row[$id] = 0;
1847:
1848: if ($mode == 1)
1849: {
1850: echo "<table border='1'>";
1851: }
1852:
1853: else
1854: {
1855: return "<table border='1'>";
1856: }
1857: }
1858:
1859: 1860: 1861: 1862: 1863: 1864: 1865: 1866: 1867: 1868: 1869: 1870: 1871:
1872: function cetak_tabel_parsial($data, $ignore_count=false, $id=1, $mode=1)
1873: {
1874: $ret = "";
1875:
1876: $dimensi = $this->countdim($data);
1877:
1878: if (is_array($data) && count($data > 0) && $dimensi == 1)
1879: {
1880:
1881: if ($mode == 1)
1882: {
1883: echo "<tr>";
1884: foreach ($data as $idx => $cell)
1885: {
1886: echo "<td>$cell</td>";
1887: }
1888: echo "</tr>";
1889: }
1890:
1891: else
1892: {
1893: $ret .= "<tr>";
1894: foreach ($data as $idx => $cell)
1895: {
1896: $ret .= "<td>$cell</td>";
1897: }
1898: $ret .= "</tr>";
1899: }
1900:
1901: if (!$ignore_count)
1902: {
1903: $this->table_row[$id]++;
1904: }
1905: }
1906:
1907: else if (is_array($data) && $dimensi == 2)
1908: {
1909:
1910: if ($mode == 1)
1911: {
1912: foreach ($data as $idx => $value)
1913: {
1914: echo "<tr>";
1915: foreach ($value as $idx => $cell)
1916: {
1917: echo "<td>$cell</td>";
1918: }
1919: echo "</tr>";
1920: }
1921: }
1922:
1923: else
1924: {
1925: foreach ($data as $idx => $value)
1926: {
1927: $ret .= "<tr>";
1928: foreach ($value as $idx => $cell)
1929: {
1930: $ret .= "<td>$cell</td>";
1931: }
1932: $ret .= "</tr>";
1933: }
1934: }
1935:
1936: if (!$ignore_count)
1937: {
1938: $this->table_row[$id]++;
1939: }
1940: }
1941:
1942: else
1943: {
1944: exit();
1945: }
1946:
1947: if ($mode == 1)
1948: {
1949: $this->kirim_buffer();
1950: }
1951:
1952: else
1953: {
1954: return $ret;
1955: }
1956: }
1957:
1958: 1959: 1960: 1961: 1962: 1963: 1964: 1965: 1966:
1967: function cetak_tabel_parsial_indeks($data, $mode=1)
1968: {
1969: $ret = "";
1970:
1971: if (is_array($data))
1972: {
1973: reset($data);
1974: $arr = current($data);
1975:
1976: if ($mode == 1)
1977: {
1978: echo "<tr>";
1979: foreach ($arr as $idx => $val)
1980: {
1981: echo "<td>$idx</td>";
1982: }
1983: echo "</tr>";
1984: }
1985:
1986: else
1987: {
1988: $ret .= "<tr>";
1989: foreach ($arr as $idx => $val)
1990: {
1991: $ret .= "<td>$idx</td>";
1992: }
1993: $ret .= "</tr>";
1994: }
1995: }
1996: else
1997:
1998: {
1999: exit();
2000: }
2001:
2002: unset($arr);
2003:
2004: if ($mode == 1)
2005: {
2006: $this->kirim_buffer();
2007: }
2008:
2009: else
2010: {
2011: return $ret;
2012: }
2013: }
2014:
2015: 2016: 2017: 2018: 2019: 2020: 2021: 2022: 2023:
2024: function cetak_tabel_parsial_akhiri($id=1, $mode=1)
2025: {
2026:
2027: if ($mode == 1)
2028: {
2029: echo "</table>";
2030: echo "Terdapat ".$this->table_row[$id]." baris<br />";
2031: $this->kirim_buffer();
2032: }
2033:
2034: else
2035: {
2036: return "</table>".
2037: "Terdapat ".$this->table_row[$id]." baris<br />";
2038: }
2039: }
2040:
2041: 2042: 2043: 2044: 2045: 2046: 2047: 2048: 2049:
2050: function array_auto_fill($data)
2051: {
2052:
2053: $idxList = array();
2054: foreach ($data as $element)
2055: {
2056: foreach ($element as $idx => $val)
2057: {
2058:
2059: if (!in_array($idx, $idxList))
2060: {
2061: $idxList[$idx] = $idx;
2062: }
2063: }
2064: }
2065:
2066: reset($data);
2067: $tempData = array();
2068: foreach ($data as $idx => $val)
2069: {
2070: reset($idxList);
2071: foreach ($idxList as $idx_ => $val_)
2072: {
2073:
2074: $tempData[$idx][$idx_] = $val[$idx_];
2075: }
2076: }
2077: $data = $tempData;
2078:
2079: unset($tempData);
2080: unset($idxList);
2081: return $data;
2082: }
2083: }
2084: ?>