Wednesday, February 20, 2019

Membuat Struktur Organisasi dengan php dan Mysql

Assalamualakum...
Apa kabar sahabat pojok code, semoga dalam keadaan baik baik saja. Sahabat pernah tidak kamu merasa kesulitan ketika ingin membuat tamilan struktur organisasi yang di load langsung dari database, dengan kamu load langsung dari database struktur bisa menjadi lebih dinamis dan bisa di ubah-ubah tanpa merubah codingannya.
Hampir setiap projek yang berhubungan dengan system apalagi system yang dipakai di sebuah perusahaan atau organisasi, pasti membutuhkan tampilan struktur organisasi. Berdasarkan hal itu saya akan share ke kalian cara membuat struktur organisasi load dari DB mengunakan PHP dan MySql atau mariaDB. Meskipun untuk postingan kaliini belum disertai insert dan updatenya tapi hanya load langsung dari data yang sudah disimpan di database, mungkin bagi kamu yang kreatif silahkan di kembangkan sendiri.

Daftar isi postingan
  1. Gambaran umum, suah di lakukan diatas.
  2. Material dan bahan pendukung
  3. Coding dan programming.
  4. Testing dan preview
  5. File Latihan
Bagian deskripsi secara umum saya kira cukup diatas, sekarang kita akan siapkan apa saja material pendukung untuk membuat projek ini.
  • JQuery bisa di download dari situs resminya.
  • Lib ORGChart, saya lupa linknya tapi bagi kami tinggal download saja dari file latihan yang sudah disiapka dibawah.
  • Database MariaDb
  • WAMP server atau XAMPP untuk menjalankan PHP nya.
Setelah semua material pendukung dikumpulkan satnya kita membuat projek baru, oh iya sampai lupa, sebelum kita buat projek baru kita buat dulu databasenya dan input datanya, ikuti langkah-langkah dibawah ini.
buat database baru (namanya terserah) dan tabel baru.

 CREATE TABLE IF NOT EXISTS `simpeople` (
  `people_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `telepon` varchar(15) DEFAULT NULL,
  `address` varchar(250) NOT NULL,
  `status_id` varchar(100) NOT NULL,
  `join_date` date NOT NULL,
  `active_status` varchar(5) DEFAULT NULL,
  `end_date` varchar(45) DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  `komitment` float DEFAULT NULL,
  `username` varchar(250) DEFAULT NULL,
  `password` varchar(250) DEFAULT NULL,
  `cabang` int(11) DEFAULT NULL,
  PRIMARY KEY (`people_id`)
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8;
Input data nya.

INSERT INTO `simpeople` (`people_id`, `name`, `telepon`, `address`, `status_id`, `join_date`, `active_status`, `end_date`, `email`, `komitment`, `username`, `password`, `cabang`) VALUES
 (1, 'Asep Komarudin', '082121232730', 'Jl. Flamboyan No. 44 Srengseng Kembangan Jakarta Barat', 'Karyawan', '2017-04-04', 'on', NULL, 'aasseepp@gmail.com', 50000, 'asep', '*A4B6157319038724E3560894F7F932C8886EBFCF', 2),
 (2, 'Arga', '1234', 'binus', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (3, 'Muhammad Ikhsan', '1234', 'DM', 'Pelajar', '2014-04-01', 'on', NULL, 'dumy@test.com', 100000, NULL, NULL, NULL),
 (4, 'Dedy Suginato', '1234', 'DM', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (5, 'Asep Rusmana', '1234', 'jakarta', 'Pelajar', '2017-04-02', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (6, 'Nanang', '123', 'nihil', 'Pelajar', '2017-04-02', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (7, 'Muhammad Karno Utomo', '123', 'Srengseng', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (8, 'Yustian', '123', 'Jl. Flamboyan No. 59 Srengseng Kembangan Jakarta Barat', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 100000, NULL, NULL, NULL),
 (9, 'Hersa', '123', 'DM', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (10, 'Dedy Sudrajat', '123', 'Al-ansor', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (11, 'Muhammad Farid', '13213', 'Dm', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (12, 'Santoso', '1234', 'Kontrakan Pak Roto', 'Pelajar', '2014-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (13, 'Faisal', '1234', 'DM', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (14, 'Edy Mohtar', '1234', 'DEkat Musola Ataawun', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 15000, NULL, NULL, NULL),
 (15, 'Tarno', '1234', 'Kontrakan Pak RT', 'Pelajar', '2014-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (16, 'Sudarmono', '1234', 'Kosong', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (17, 'Hamdani', '1234', 'Kosong', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (18, 'Syarif', '1234', 'Kosong', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (19, 'Hudan', '1234', 'Kosong', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 30000, NULL, NULL, NULL),
 (20, 'Ayubi', '1234', 'Kembangan', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (21, 'Alvin STY', '1234', 'Dekat mesjid Al-Huda', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 50000, 'alvin', '*FBFD34E4561C6E9863547D3521D7A090554E00E6', NULL),
 (22, 'Rizki', '1234', 'Nissan', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (23, 'Huda', '1234', 'Kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (24, 'Wahyu UBL', '1234', 'Kosong (UBL)', 'HU', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (25, 'Adiat', '1234', 'Kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (26, 'Kurdiono', '1234', 'Kontrakan Bu Roto', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (27, 'Ade', '1234', 'Masih Koasong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 50000, 'ase', '*246788DFD1F79D9635A58F8121B32F00A8A0D065', 2),
 (28, 'Alfin Bin Nur', '1234', 'DM', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (29, 'Umar DM', '1234', 'DM', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (30, 'Slamet Tri Waluyo', '1234', 'Belakang Ust. Sofar', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (31, 'Wahyu Andri Irawan', '1234', 'Belakang UST. Sofar', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (32, 'Maman', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (33, 'Agung Sunaryadi', '1234', 'Belakang DM', 'Pelajar', '2015-04-01', 'off', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (34, 'Hafidz', '1234', 'Dekat Mesjid ', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (35, 'Nino', '1234', 'Dekat Mesjid Almutaakhirin', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (36, 'Adi Santoso', '1234', 'Dekat Mesjid At-taawun', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 100000, NULL, NULL, NULL),
 (37, 'Rully Van Hod Nababn', '1234', 'DM', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (38, 'Hery Siswanto', '1234', 'DM', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 40000, NULL, NULL, NULL),
 (39, 'Arif Nissan', '1234', 'Ciledug', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (40, 'Sadam Mubarok', '1234', 'Palmerah', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (41, 'Husen', '123', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 40000, NULL, NULL, NULL),
 (42, 'Ajang Setiawan', '1234', 'Jalan Tolo', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 50000, 'ajang', '*A4B6157319038724E3560894F7F932C8886EBFCF', 2),
 (43, 'mas Ahmad', '1234', 'kosong', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (44, 'Mas Tarjo', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (45, 'pak Ade Rohana', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (46, 'H. Iskandar', '1234', 'jl. Srengseng', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (47, 'H. Muhyidin', '1234', 'Tanggerang', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (48, 'Muhaimin', '1234', 'kosong', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (49, 'Surya', '1234', 'kosong', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (50, 'Pak Asep', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (52, 'Pak Pri', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (53, 'Deni', '1234', 'Kontrakan Pak RT', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (54, 'Hendra DM', '1234', 'DM', 'Pelajar', '2016-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (55, 'Awaludin', '1234', 'DM', 'Pelajar', '2015-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (56, 'Ahmad', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (57, 'Ardianto', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (58, 'Ahmad Yani', '1234', 'kosong', 'Pelajar', '2017-04-07', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (59, 'Muslim', '1234', 'kosong', 'Karyawan', '2011-04-01', 'on', NULL, 'dumy@test.com', 100000, 'muslim', '*A4B6157319038724E3560894F7F932C8886EBFCF', NULL),
 (60, 'Harits', '1234', 'kosong', 'Karyawan', '2010-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (61, 'Sulaiman', '1234', 'kembangan', 'Karyawan', '2010-04-01', 'on', NULL, 'dumy@test.com', 75000, 'sulaiman', '*2FADBE3B28E3DF0BE9AAC4D06472A4F12C6BC342', NULL),
 (62, 'Rahmadi', '1234', 'jakarta Timur', 'Karyawan', '2012-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (63, 'Suryadi', '1234', 'palmerah', 'Karyawan', '2011-04-01', 'on', NULL, 'dumy@test.com', 200000, NULL, NULL, NULL),
 (64, 'Rustandi', '1234', 'kosong', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (65, 'Sumarna', '1234', 'kosong', 'Karyawan', '2012-04-02', 'on', NULL, 'dumy@test.com', 30000, NULL, NULL, NULL),
 (66, 'Gunawan', '1234', 'kosong', 'Karyawan', '2010-04-01', 'on', NULL, 'dumy@test.com', 125000, 'gunawan', '*A4B6157319038724E3560894F7F932C8886EBFCF', 2),
 (67, 'Nurjaman', '1234', 'kosong', 'Karyawan', '2012-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (68, 'Parno', '123', 'kosong', 'Karyawan', '2014-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (69, 'Supriono', '1234', 'kosong', 'Karyawan', '2011-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (70, 'Imam', '1234', 'kosong', 'Karyawan', '2010-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (71, 'Firman', '1234', 'seskoal', 'Karyawan', '2009-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (72, 'Fatur Rohman', '1234', 'kosong', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 90000, NULL, NULL, NULL),
 (73, 'KH. Sofar Mawardi', '1234', 'Srengseng Kembangan', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 100000, NULL, NULL, NULL),
 (74, 'Musoffa', '1234', 'Kontakan Ibu ZRoto', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 40000, NULL, NULL, NULL),
 (75, 'Muhammad Nazib', '1234', 'DM', 'Karyawan', '2014-04-01', 'on', NULL, 'dumy@test.com', 40000, NULL, NULL, NULL),
 (76, 'Partono', '1234', 'Belakang DM', 'Karyawan', '2017-04-07', 'on', NULL, 'dumy@test.com', 40000, NULL, NULL, NULL),
 (77, 'Rohmat', '1234', 'srengseng kembangan', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 50000, NULL, NULL, NULL),
 (78, 'Untung', '1234', 'Dekang rumah Ustad Soffar', 'Karyawan', '2013-04-01', 'on', NULL, 'dumy@test.com', 30000, NULL, NULL, NULL),
 (79, 'Mahmudin', '1234', 'Kembangan', 'Karyawan', '2010-04-01', 'on', NULL, 'dumy@test.com', 0, NULL, NULL, NULL),
 (80, 'Didik Dm', '1234', 'DM', 'HU', '2016-04-01', 'on', NULL, 'test@gmail.com', 0, NULL, NULL, NULL),
 (81, 'Tolhah Ubayidilah', '1234', 'DM', 'HU', '2016-04-01', 'on', NULL, 'test@gmail.com', 0, NULL, NULL, NULL),
 (82, 'Alif DM', '1234', 'dekat mesjid aluswah', 'HU', '2016-04-01', 'off', NULL, 'test@gmail.com', 0, 'alif', '*A4B6157319038724E3560894F7F932C8886EBFCF', 2),
 (83, 'Unu', '1234', 'bogor', 'Pelajar', '2016-01-01', '1', NULL, 'test@gmail.com', 50000, NULL, NULL, NULL),
 (84, 'Firman Nissan', '1234', 'nissan daanmogot', 'Kontakan', '1900-01-01', 'off', NULL, 'test@gmail.com', 0, NULL, NULL, NULL),
 (85, 'Rudi Hidayat', '085697513898', 'cengkareng', 'Pelajar', '2016-01-05', '1', NULL, 'test@gmail.com', 100000, NULL, NULL, NULL),
 (87, 'Dede Iskandar', '121313', 'DM', 'Pelajar', '2016-05-03', 'off', NULL, 'qweqe', 0, NULL, NULL, NULL),
 (88, 'Eko DM', '1234', 'DM', 'HU', '2016-06-01', 'off', NULL, 'test@gmail.com', 0, 'eko', '*A4B6157319038724E3560894F7F932C8886EBFCF', NULL),
 (89, 'Zaki', '1234', 'Samping Attaawun', 'HU', '2016-06-01', 'off', NULL, 'test@gmail.com', 0, 'zaki', '*A4B6157319038724E3560894F7F932C8886EBFCF', NULL);
tabel posisi

CREATE TABLE IF NOT EXISTS `simposisi` (
  `posisi_id` int(11) NOT NULL AUTO_INCREMENT,
  `kode_posisi` varchar(50) NOT NULL,
  `nama_posisi` varchar(200) NOT NULL,
  `parent` int(11) DEFAULT NULL,
  `parent_path` varchar(200) DEFAULT NULL,
  `cabang_id` int(11) NOT NULL,
  `active_status` int(11) DEFAULT '1',
  `people_id` int(11) DEFAULT '0',
  `pembinaan` int(11) DEFAULT NULL,
  `hari` varchar(50) DEFAULT NULL,
  `jam` varchar(10) DEFAULT NULL,
  `kitab` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`posisi_id`),
  KEY `FK__simcabang` (`cabang_id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1;
Isi tabel posisi

INSERT INTO `simposisi` (`posisi_id`, `kode_posisi`, `nama_posisi`, `parent`, `parent_path`, `cabang_id`, `active_status`, `people_id`, `pembinaan`, `hari`, `jam`, `kitab`) VALUES
 (1, 'KBJ-MGR', 'Manager', 0, '', 2, 1, 61, 0, '', '', ''),
 (3, 'KBJ-AMN-1', 'Asmen', 1, '1', 2, 1, 59, 0, '', '', ''),
 (5, 'KBJ-AMN-2', 'Asmen', 1, '1', 2, 1, 66, 0, '', '', ''),
 (6, 'KBJ-MSF-1', 'Pengajar', 3, '1,3', 2, 1, 66, 1, 'Ahad', '07:00', 'Mafahim'),
 (7, 'KBJ-MSF-2', 'Pengajar', 3, '1,3', 2, 1, 1, 1, 'Ahad', '05:00', 'Materi Dasar Islam'),
 (8, 'KBJ-MSF-3', 'Pengajar', 5, '1,5', 2, 1, 73, 1, 'Selasa', '18:00', 'Mapahim'),
 (9, 'KBJ-MSF-4', 'Pengajar', 5, '1,5', 2, 1, NULL, NULL, NULL, NULL, NULL),
 (10, 'KBJ-PLJ-1', 'Pelajar', 6, '1,3,6', 2, 1, 33, 0, '', '', ''),
 (11, 'KBJ-MAL', 'Maliah', 1, '1', 2, 1, 1, 0, '', '', ''),
 (13, 'PE-01', 'Pelajar', 6, '1,3,6', 2, 1, 36, 0, '', '', ''),
 (14, 'PE-02', 'Pelajar', 7, '1,3,7', 2, 1, 82, 0, '', '', ''),
 (15, 'KBJ-PE-003', 'Pengajar', 3, '1,3', 2, 1, 21, 1, 'Sabtu', '16:00', 'Nizomul Islam'),
 (16, 'KBJ-PEL-004', 'Pelajar', 15, '1,3,15', 2, 1, 39, 0, '', '', ''),
 (17, 'KBJ-PEN-0003', 'Pengajar', 3, '1,3', 2, 1, 1, 1, 'Ahad', '07:00', 'Materi Dasar Islam'),
 (18, 'KBJ-PEL-0004', 'Pelajar', 7, '1,3,7', 2, 1, 80, 0, '', '', ''),
 (19, 'KBJ-PLJ-0012', 'Pelajar', 7, '1,3,7', 2, 1, 87, 0, '', '', ''),
 (20, 'KBJ-PLJ-0005', 'Pelajar', 7, '1,3,7', 2, 1, 81, 0, '', '', ''),
 (21, 'KBJ-DRS-0001', 'Pelajar', 8, '1,5,8', 2, 1, 47, 0, '', '', ''),
 (22, 'KBJ-DRS-0002', 'Pelajar', 8, '1,5,8', 2, 1, 46, 0, '', '', ''),
 (23, 'PE_KBJ_001', 'pelajar', 17, '1,3,17', 2, 1, 33, 0, '', '', ''),
 (24, 'KBJ_PEL', 'Pelajar', 7, '1,3,7', 2, 1, 89, 0, '', '', ''),
 (25, 'KBJ_PEL_01', 'Pelajar', 7, '1,3,7', 2, 1, 88, 0, '', '', ''); 
Setelah itu buatlah projek baru dengan struktur seperti gambar dibawah ini.
Isi file DBConnection seperi code dibawah ini. untuk nama databse user dan passwordnya silahkan di sesuaikan dengan setting yang ada di komputer kamu.

class DBConnection {
    private $host = "localhost";
    private $dbName = "latihan3";
    private $usr = "root";
    private $pwd = "root";
    public function getConnection() {
        try {
            $conn = new PDO("mysql:host=$this->host;dbname=$this->dbName", $this->usr, $this->pwd);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            echo "Connection failed: " . $e->getMessage();
        }
        return $conn;
    }
}

Selanjutnya buatlah entity class untuk people.php dan Posisi.php

class People {
    private $peopleId;
    private $name;
    private $telepon;
    private $adress;
    private $statusId;
    private $joindate;
    private $activeStatus;
    private $endDate;
    private $email;
    private $komitment;
    private $username;
    private $password;
    private $cabang;
    
    function getCabang() {
        return $this->cabang;
    }

    function setCabang($cabang) {
        $this->cabang = $cabang;
    }
    
    function getUsername() {
        return $this->username;
    }

    function getPassword() {
        return $this->password;
    }

    function setUsername($username) {
        $this->username = $username;
    }

    function setPassword($password) {
        $this->password = $password;
    }
    
    function getKomitment() {
        return $this->komitment;
    }

    function setKomitment($komitment) {
        $this->komitment = $komitment;
    }

    function getPeopleId() {
        return $this->peopleId;
    }

    function getName() {
        return $this->name;
    }

    function getTelepon() {
        return $this->telepon;
    }

    function getAdress() {
        return $this->adress;
    }

    function getStatusId() {
        return $this->statusId;
    }

    function getJoindate() {
        return $this->joindate;
    }

    function getActiveStatus() {
        return $this->activeStatus;
    }

    function getEndDate() {
        return $this->endDate;
    }

    function getEmail() {
        return $this->email;
    }

    function setPeopleId($peopleId) {
        $this->peopleId = $peopleId;
    }

    function setName($name) {
        $this->name = $name;
    }

    function setTelepon($telepon) {
        $this->telepon = $telepon;
    }

    function setAdress($adress) {
        $this->adress = $adress;
    }

    function setStatusId($statusId) {
        $this->statusId = $statusId;
    }

    function setJoindate($joindate) {
        $this->joindate = $joindate;
    }

    function setActiveStatus($activeStatus) {
        $this->activeStatus = $activeStatus;
    }

    function setEndDate($endDate) {
        $this->endDate = $endDate;
    }

    function setEmail($email) {
        $this->email = $email;
    }
}

class Posisi {
    private $posisiId;
    private $kodePosisi;
    private $namaPosisi;
    private $parent;
    private $parentPath;
    private $cabangId;
    private $activeStatus;
    private $peopleId;
    private $pembinaan;
    private $hari;
    private $jam;
    private $kitab;
    
    function getPembinaan() {
        return $this->pembinaan;
    }

    function getHari() {
        return $this->hari;
    }

    function getJam() {
        return $this->jam;
    }

    function getKitab() {
        return $this->kitab;
    }

    function setPembinaan($pembinaan) {
        $this->pembinaan = $pembinaan;
    }

    function setHari($hari) {
        $this->hari = $hari;
    }

    function setJam($jam) {
        $this->jam = $jam;
    }

    function setKitab($kitab) {
        $this->kitab = $kitab;
    }

        
    function getPeopleId() {
        return $this->peopleId;
    }

    function setPeopleId($peopleId) {
        $this->peopleId = $peopleId;
    }

        
    function getPosisiId() {
        return $this->posisiId;
    }

    function getKodePosisi() {
        return $this->kodePosisi;
    }

    function getNamaPosisi() {
        return $this->namaPosisi;
    }

    function getParent() {
        return $this->parent;
    }

    function getParentPath() {
        return $this->parentPath;
    }

    function getCabangId() {
        return $this->cabangId;
    }

    function getActiveStatus() {
        return $this->activeStatus;
    }

    function setPosisiId($posisiId) {
        $this->posisiId = $posisiId;
    }

    function setKodePosisi($kodePosisi) {
        $this->kodePosisi = $kodePosisi;
    }

    function setNamaPosisi($namaPosisi) {
        $this->namaPosisi = $namaPosisi;
    }

    function setParent($parent) {
        $this->parent = $parent;
    }

    function setParentPath($parentPath) {
        $this->parentPath = $parentPath;
    }

    function setCabangId($cabangId) {
        $this->cabangId = $cabangId;
    }

    function setActiveStatus($activeStatus) {
        $this->activeStatus = $activeStatus;
    }
}

Sekarang buatlah code pada file index

<?php
require_once './DBConnection.php';
require_once './People.php';
require_once './Posisi.php';

$conn= new DBConnection();
$connection=$conn->getConnection();

function getPeopleById($id,$connection) {
    $people = new People();
    $sql = "select * from simpeople where people_id='$id'";
    $stmt = $connection->prepare($sql);
    $stmt->execute();
    if ($v = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $people = new People();
        $people->setPeopleId($v['people_id']);
        $people->setName($v['name']);
        $people->setTelepon($v['telepon']);
        $people->setAdress($v['address']);
        $people->setStatusId($v['status_id']);
        $people->setJoindate($v['join_date']);
        $people->setEmail($v['email']);
        $people->setEndDate($v['end_date']);
        $people->setKomitment($v['komitment']);
        $people->setActiveStatus($v['active_status']);
        $people->setUsername($v['username']);
        $people->setPassword($v['password']);
        $people->setCabang($v['cabang']);
    }
    return $people;
}

function getOrgData($connection) {
    $posisiAcess = array();
    $sql = "select * from simposisi";
    $stmt = $connection->prepare($sql);
    $stmt->execute();
    foreach ($stmt->fetchAll() as $k => $v) {
        $posisi = new Posisi();
        $posisi->setPosisiId($v['posisi_id']);
        $posisi->setKodePosisi($v['kode_posisi']);
        $posisi->setParent($v['parent']);
        $posisi->setNamaPosisi($v['nama_posisi']);
        $posisi->setParentPath($v['parent_path']);
        $posisi->setCabangId($v['cabang_id']);
        $posisi->setActiveStatus($v['active_status']);
        $posisi->setPeopleId(getPeopleById($v['people_id'],$connection));
        $posisi->setPembinaan($v['pembinaan']);
        $posisi->setHari($v['hari']);
        $posisi->setJam($v['jam']);
        $posisi->setKitab($v['kitab']);
        $posisiAcess[] = $posisi;
    }
    return $posisiAcess;
}

$all = getOrgData($connection);

//untuk mendapatkan menu
function has_children($rows, $id) {
    foreach ($rows as $row) {
        if ($row->getParent() == $id)
            return true;
    }
    return false;
}

function build_menu($rows, $parent = 0, $vert = 0) {
    if ($vert == 1) {
        $result = "<ul type=\"vertical\">";
    } else {
        $result = "<ul>";
    }
    foreach ($rows as $row) {
        if ($row->getParent() == $parent) {
            $result .= "<li><b>{$row->getNamaPosisi()}<br></b>{$row->getPeopleId()->getName()}";
            if (has_children($rows, $row->getPosisiId()))
                $result .= build_menu($rows, $row->getPosisiId(), $row->getPembinaan());
            $result .= "</li>";
        }
    }
    $result .= "</ul>";

    return $result;
}
?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Tampilan Struktur</title>
        <script src="./jquery.min.js"></script>
        <link href="./orgchart/orgchart.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="./orgchart/orgchart.js"></script>
        <script>
            $(document).ready(function () {
                // create a tree
                $("#tree-data").jOrgChart({
                    chartElement: $("#tree-view"),
                    nodeClicked: nodeClicked
                });

                // lighting a node in the selection
                function nodeClicked(node, type) {
                    node = node || $(this);
                    $('.jOrgChart .selected').removeClass('selected');
                    node.addClass('selected');
                }
            });
        </script>
    </head>
    <body>
        <div>
            <center>
                <div class="container">
                    <ul id="tree-data" style="display:none">
                        <li id="root" style="background-color: blue;">
                            <b>Struktir Organisasi</b>
                            <?php echo build_menu($all); ?>
                        </li>
                    </ul>
                    <div id="tree-view"></div>  
                </div>
            </center>
        </div>
    </body>
</html>

Jika sudah sekarang coba jalankan, jika tampilan seperti gambar paling atas, berarti sudah berhasil. Silahkan di kembangkan kembali dan sampai ketemu di tutorial selanjutnya. Klik Tombol Dibawah Untuk Memunculkan Link Download :

Tutorial Cara Download File :

This Is The Newest Post


EmoticonEmoticon