<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');

?>           
	
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">AGENDA GURU</h5>
										
                                    </div>
                                    <div class="card-body">
									
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered table-hover" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th> 
													<th>ROMBEL</th>													                           
                                                    <th>MAPEL</th>
													 <th>PENCAPAIAN</th>
													  <th>HADIR</th>
													
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM agenda"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM agenda WHERE idguru='$user[id_user]'"); 	
											endif;
											  while ($data = mysqli_fetch_array($query)) :
											 $peg = fetch($koneksi,'users',['id_user'=>$data['idguru']]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['kelas'] ?> - <?= $peg['nama'] ?></td>
                                                      <td><h5><?= $data['mapel'] ?> <span class="badge badge-primary"><?= $data['kuri'] ?></span></h5></td>										   
													  <td><?= $data['pencapaian'] ?></td>
													   <td><h5><span class="badge badge-secondary"><?= $data['absen'] ?>%</span></h5></td>
													  
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
											</div>
										</div>
										
									</div>
									<?php if ($ac == '') : ?>
					       <div class="col-md-4">
                     
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                  
                                    </div>
                                    <div class="card-body">
                                        <div class="widget-payment-request-container">
                                            <div class="widget-payment-request-author">
                                                <div class="avatar m-r-sm">
                                                    <img src="../images/user.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name"><?= strtoupper($user['nama']) ?></span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                               
											   </div>
                                            </div>
											
									<div class="widget-payment-request-info m-t-md">
									 <div class="d-grid gap-2">
									<button class="btn btn-dark" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 AGENDA HARIAN GURU
									</button>
											</div>
										
									<form id='formlingkup' class="row g-1"> 
									 <div class="col-md-12">
								<label class="form-label bold">Tanggal</label>
								<input type="text" name="tanggal" class="datepicker form-control" required="true" autocomplete="off">
							     </div>	
                               <div class="col-md-12">
								<label class="form-label bold">Rombel</label>
								<select name='kelas' id='kelas' class='form-select' required='true' style="width: 100%">
								    <option value="">Pilih Rombel</option>
                                       <?php									
											$query = mysqli_query($koneksi, "SELECT * FROM kelas"); 
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[kelas]'>$tkt[kelas]</option>";
													}
													?>						
									 </select>
							     </div>	
							         
							<div class="col-md-12">
								<label class="form-label bold">Mata Pelajaran</label>
								<select name='mapel' id='mapel' class='form-select' required='true' style="width: 100%">
								<option value=''>Pilih Mapel</option>
								<?php
										
											$query = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"); 	
										  
										while ($mpl = mysqli_fetch_array($query)) {										
										echo "<option value='$mpl[kode]'>$mpl[nama_mapel]</option>";
													}
													?>						
									 </select>
									
							</div>
							<div class="col-md-12">
								<label class="form-label bold">Kurikulum</label>
								<select name='kuri' id='kuri' class='form-select' required='true' style="width: 100%">
								  	<option value=''>Pilih Kurikulum</option>
									<option value='K-2013'>K-2013</option>
									<option value='K-Merdeka'>K-Merdeka</option>
									 </select>
									
							</div>
							<div id="kd" style="display: none;">
							<div class='col-md-12'>
                                     <label class="bold">No KI/KD</label>
                                   <input type="text" name="kd"  class="form-control" autocomplete='off' >
                                  </div>
								<div class='col-md-12'>
                                     <label class="bold">Materi</label>
                                   <input type="text" name="materi"  class="form-control" autocomplete='off' >
                                     </div>				
									<div class='col-md-12'>
                                     <label class="bold">Indikator</label>
                                   <input type="text" name="indikator"  class="form-control" autocomplete='off' >
                                     </div>																
								 </div>		
                                     <div id="lingkup" style="display: none;">
									 <div class='col-md-12'>
                                        <label class="bold">Materi</label>
                                          <input type="text" name="lm"  class="form-control" autocomplete='off' >
                                                </div> 
											<div class='col-md-12'>
                                        <label class="bold">Tujuan Pembelajaran</label>
                                          <input type="text" name="tp"  class="form-control" autocomplete='off' >
                                                </div> 
								           </div>	
								 <div class="col-md-12">
								<label class="form-label bold">Guru Pengampu</label>
								<select name="guru" class='form-select' required='true' style="width: 100%" >
										 <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM users where level='guru'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM users where id_user='$user[id_user]'"); 	
										  endif;
										while ($guru = mysqli_fetch_array($query)) {
                                         
										echo "<option value='$guru[id_user]'>$guru[nama]</option>";
													}
													?>	
												</select>
							          </div><p>
									  
								           <div class="d-grid gap-2">
                                       
										 
                                         <button type="submit" class="btn btn-primary flex-grow-1 m-l-xxs" id="blockui-2">Simpan</button>
                                          
                                            </div>
										</form>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<script type="text/javascript">
    $(function () {
        $("#kuri").change(function () {
            if ($(this).val() == "K-2013") {
                $("#kd").show();             
				 $("#lingkup").hide();
				
            } else {
                $("#kd").hide();
				 $("#lingkup").show();
				
            }
        });
    });
</script>						
							<script>
						$('#formlingkup').submit(function(e) {
								e.preventDefault();
								var data = new FormData(this);
								$.ajax({
									type: 'POST',
									 url: 'cbtserver_ptm/tjadwal.php?pg=agenda',
									enctype: 'multipart/form-data',
									data: data,
									cache: false,
									contentType: false,
									processData: false,
									beforeSend: function() {},
									success: function(data) {
									   
										setTimeout(function() {
											window.location.reload();
										}, 1500);
									}
								})
								return false;
							});
							</script>
							
							
             <?php elseif ($ac == 'edit'): ?>
			 <?php
			 $idl = $_GET['idl'];
			 $lingkup = fetch($koneksi,'lingkup',['idl'=>$idl]);
			 ?>
	                <div class="col-md-4">
                     
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                  
                                    </div>
                                    <div class="card-body">
                                        <div class="widget-payment-request-container">
                                            <div class="widget-payment-request-author">
                                                <div class="avatar m-r-sm">
                                                    <img src="../images/user.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name"><?= strtoupper($user['nama']) ?></span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                               
											   </div>
                                            </div>
											
									<div class="widget-payment-request-info m-t-md">
									 <div class="d-grid gap-2">
									<button class="btn btn-primary" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 EDIT LINGKUP MATERI
									</button>
											</div>
										
									<form id='formedit' class="row g-1"> 
									
                                    <input type="hidden" name="idl" value="<?= $idl ?>" >
									
                               <div class="col-md-12">
								<label class="form-label bold">Tingkat</label>
								<select name='level' id='level' class='form-select' required='true' style="width: 100%">
								    <option value="<?= $lingkup['tingkat'] ?>"><?= $lingkup['tingkat'] ?></option>
                                       					
									 </select>
							     </div>	
							             
								
							<div class="col-md-12">
								<label class="form-label bold">Mata Pelajaran</label>
								<select name='mapel' id='mapel' class='form-select' required='true' style="width: 100%">
								  <option value="<?= $lingkup['kodemap'] ?>"><?= $lingkup['kodemap'] ?></option>
									 </select>
							</div>
							 <div class="col-md-12">
								<label class="form-label bold">Materi</label>
							   <textarea name="materi" class="form-control" rows="5" required="true" maxlength="200" ><?= $lingkup['materi'] ?></textarea>							   
							   </div>
							   <div id="count">
								<span id="current_count">0</span>
								<span id="maximum_count">/ 200</span>
							</div>
							<script type="text/javascript">
							$('textarea').keyup(function() {    
								var characterCount = $(this).val().length,
									current_count = $('#current_count'),
									maximum_count = $('#maximum_count'),
									count = $('#count');    
									current_count.text(characterCount);        
							});
							</script>
								<p>
									  
								           <div class="d-grid gap-2">
                                       
										 
                                         <button type="submit" class="btn btn-primary flex-grow-1 m-l-xxs" id="blockui-2">Simpan</button>
                                          
                                            </div>
										</form>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							<script>
						$('#formedit').submit(function(e) {
								e.preventDefault();
								var data = new FormData(this);
								$.ajax({
									type: 'POST',
									 url: 'cbtserver_rapor/kurmer/tkurmer.php?pg=edit',
									enctype: 'multipart/form-data',
									data: data,
									cache: false,
									contentType: false,
									processData: false,
									beforeSend: function() {},
									success: function(data) {
									   
										setTimeout(function() {
											window.location.replace('?pg=lingkup');
										}, 1500);
									}
								})
								return false;
							});
							</script>
							
							   
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					