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