<?php

$agenda=fetch($koneksi,'agenda',['id'=>$_GET['id']]);
?>																			
  
 <?php if ($ac == '') { ?>
 <div class='row'>
 <div class='col-md-12'>
 <div class="card">
             <div class="card-header">
                    <div class='right '>
					<button class='btn btn-sm btn-outline-danger' onclick="frames['frameresult<?= $agenda[idjadwal] ?>'].print()"><i class='fa fa-print'></i> Print</button>  
                     <iframe id='loadframe' name='frameresult<?= $agenda[idjadwal] ?>' src="sandik_agenda/cetakjurnal.php?idj=<?= $agenda['idjadwal'] ?>" style='display:none'></iframe>
                    </div>
					<h5 class='box-title'><i class="fas fa-laptop"></i> Jurnal Guru</h5>
                </div>
				
           <div class='card-body'>
                <div class="table-responsive">
                     <table style="font-size: 11px" id='example1' class='table  table-hover'>
                        <thead>
                            <tr>
                                <th width="5px">
                                    #
                                </th>
                                <th>Mapel</th>
								<th>Kelas</th>
                                <th>Hari, Tanggal</th>
								
                                <th> Bahasan Materi</th>
								 <th> Hambatan</th>
								 <th> Pemecahan</th>
                                <th width="5%">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
							$bulan=date('m');
							$tahun=date('Y');
                            $query = mysqli_query($koneksi, "select * from agenda JOIN jadwal_mapel ON jadwal_mapel.id_jadwal=agenda.idjadwal 
							WHERE agenda.id='$_GET[id]'");
                            $no = 0;
                            while ($jurnal = mysqli_fetch_array($query)) {
							 $lingkup = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM lingkup WHERE lm='$jurnal[lm]'"));
							 $tujuan = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tujuan WHERE tp='$jurnal[tp]'"));
							$tanggal=date('d-m-Y',strtotime($jurnal['tanggal']));
                                $no++;
                              
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $jurnal['mapel'] ?></td>
									 <td><?= $jurnal['kelas'] ?></td>
                                    <td><?= $tanggal ?></td>
                                    <?php if($jurnal['kurikulum']=='K-13'){ ?>
									<td><?= $jurnal['materi'] ?></td>
									<?php }else{ ?>
									<td><?= $lingkup['materi'] ?></td>
									<?php } ?>
									
									<td><?= $jurnal['hambatan'] ?></td>
									<td><?= $jurnal['pemecahan'] ?></td>
                                    <td>
                                       <a href="?pg=jurnal&ac=tambah&id=<?= $jurnal['id'] ?>" class="btn btn-outline-primary btn-sm" data-bs-placement="top" data-bs-toggle="tooltip" title="Buat Jurnal"><i class="fas fa-edit"></i></a>                                       
                                      </td>
									  </tr>
												<?php } ?>			
														</tbody>
													</table>
												</div>
											</div>
										</div>
									</div>
								</div>
  	

                    <?php } elseif ($ac == 'tambah') { ?>
                        <div class='row'>
						 <div class='col-md-12'>
						 <div class="card">
                            <div class="card-header">
							<h5 class="card-title"><i class="fas fa-laptop"></i> Jurnal Guru</h5>
							</div>
							<div class="card-body">
							<?php $jurnal=fetch($koneksi,'agenda',['id'=>$_GET['id']]); ?>
							<?php $jadwal=fetch($koneksi,'jadwal_mapel',['id_jadwal'=>$jurnal['idjadwal']]); ?>
                                    <form id='formagenda' action=''>
								<input type="hidden" name="id" value="<?= $jurnal['id'] ?>" class="form-control" required>
											  
								
										<div class="row">
											<div class="col-md-7">
												   <label class="bold">Mapel</label>
														 <select name='mapel' class='form-select' style='width:100%' >
														<option value="<?= $jadwal['mapel'] ?>"><?= $jadwal['mapel'] ?></option>
															 </select>	
														</div>
													
													<div class="col-md-5">
													<label class="bold">Pilih Kelas</label>
                                                    <select name='kelas' class='form-select' style='width:100%' >
                                                        <option value="<?= $jadwal['kelas'] ?>"><?= $jadwal['kelas'] ?></option>
                                                       
                                                    </select>
														</div>
															
										<div class="col-md-12">
											<label class="bold">Tanggal</label>
											<input type="text" class="form-control datepicker" name="tgl" id="tgl" value="<?= $jurnal['tanggal'] ?>" autocomplete="off" disabled>
										</div>
									
										<div class="col-md-12">										 
											<label class="bold">Bahasan Materi</label>
											<?php if($jurnal['kurikulum']=='K-13'){ ?>
											<textarea id='editor2' name='materi' class='form-control' rows='2' cols='80' style='width:100%;' readonly><?= $jurnal['materi'] ?></textarea>
										<?php }else{ ?>
												<textarea id='editor2' name='materi' class='form-control' rows='2' cols='80' style='width:100%;' readonly><?= $lingkup['materi'] ?></textarea>
											<?php } ?>
										</div>
										
										<div class="col-md-12">									  
										<label class="bold">Hambatan</label>
										 <textarea id='editor2' name='hambat' class='form-control' rows='2' cols='80' style='width:100%;' required><?= $jurnal['hambatan'] ?></textarea>
									</div>
								
									<div class="col-md-12">
										<label class="bold">Pemecahan</label>
										 <textarea id='editor2' name='pecah' class='form-control' rows='2' cols='80' style='width:100%;' required><?= $jurnal['pemecahan'] ?></textarea>
									</div>
									</div>
									<p>
										<div class='right '>										   
											  <button type='submit' class='btn btn-primary'><i class='fa fa-check-circle'></i> Simpan</button>												
													
													 </div>
													</form>
														</div>
															</div>
																</div>
																
                                                <?php } ?>
												<script>
																	  
																	 $('#formagenda').submit(function(e) {
																		  e.preventDefault();
																			var data = new FormData(this);
																		$.ajax(
																		{
																			type: 'POST',
																			url: 'sandik_agenda/crud_jurnal.php?pg=tambah',
																			enctype: 'multipart/form-data',
																			data: data,
																			cache: false,
																			contentType: false,
																			processData: false,
																			success: function(data){   	
																				iziToast.info(
																				{
																					title: 'Sukses!',
																					message: 'Data berhasil disimpan',
																					titleColor: '#FFFF00',
																					messageColor: '#fff',
																					backgroundColor: 'rgba(0, 0, 0, 0.5)',
																					 progressBarColor: '#FFFF00',
																					  position: 'topRight'
																				});
																				setTimeout(function()
																				{
																					window.location.replace('?pg=agenda');
																				}, 2000);
																						
																			}
																		});
																		return false;
																	});
																	</script>		 
												<script>
												$(function(){
													$("#datepicker").datepicker({
														dateFormat: "D,Y-m-d"
													});
												});
												</script>