Kalender dengan PHP

Alhamdulillah PR saya udah selesai, meski ngerjainnya butuh waktu juga 😀 .
Soalnya dapet kerjaan lumayan ribet juga nih padahal sih udah tinggal nerusin kerjaan temen aja.
Jadi saya dapet “warisan” hehehe kenapa “warisan” soalnya ini job dia tadinya sekarang buat saya biar ada “kerjaan” 😀 nah “warisan” dia ini bikin kalender akademik, udah setengah jadi sih tinggal benerin stylenya aja.

Dari awalnya cuman ngerubah stylenya aja ehh ini malah ngerubah logicnya juga hahahhaaa abisnya kurang greget aja kalo n’ga ikutan dalam logicnya (gaya beud saya :D).

Ini penampakannya 😀

php_calendar

Nah ini nih skripnya :

<?php
$connection = pg_connect("host=localhost port=5432 dbname=sisfo user=postgres password=password") or die ("Nao consegui conectar ao PostGres --> " . pg_last_error($connection));
function tgl($bulan,$tahun)
{
	date_default_timezone_set("Asia/Jakarta");
	$d=date('d');
	$x= date(mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
	$m=date('m');
	$y=date('Y');
	$Y=date('y');
	$nm=date('M');
	$bln=$bulan;
	$thn=$tahun;
	if (($bln !="") && ($thn!=""))
	{
	  $m=date('m',mktime(0,0,0,$bln,1,$thn));
	  $y=date('Y',mktime(0,0,0,$bln,1,$thn));
	  $nm=date('M',mktime(0,0,0,$bln,1,$thn));
	}
	$mbef=$m-1;
	$maft=$m+1;
	$nmmbef=date('M',mktime(0,0,0,$mbef,1,$thn));
	$nmmaft=date('M',mktime(0,0,0,$maft,1,$thn));
	$ybef=$y;
	$yaft=$y;
	if ($mbef<1) {$mbef=12; $ybef=$y-1;}
	if ($maft>12) {$maft=1; $yaft=$y+1;}
	$jmlkosong=date('w',mktime(0,0,0,$m,1,$y));

	$tang = '
	  <table width="100%">
	      <tr>
		<td style="font-weight:bold;font-size:10px; text-align:center;vertical-align:midle;">&nbsp;'.$nm.'<br>'.substr($tahun, -2).'&nbsp;</td>
	      </tr>
	  </table>
	';
	return $tang;
}

function kalender($bulan,$tahun)
{
	date_default_timezone_set("Asia/Jakarta");
	$d=date('d');
	$x= date(mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
	$m=date('m');
	$y=date('Y');
	$Y=date('y');
	$nm=date('M');
	$bln=$bulan;
	$thn=$tahun;
	if (($bln !="") && ($thn!=""))
	{
	  $m=date('m',mktime(0,0,0,$bln,1,$thn));
	  $y=date('Y',mktime(0,0,0,$bln,1,$thn));
	  $nm=date('M',mktime(0,0,0,$bln,1,$thn));
	}
	$mbef=$m-1;
	$maft=$m+1;
	$nmmbef=date('M',mktime(0,0,0,$mbef,1,$thn));
	$nmmaft=date('M',mktime(0,0,0,$maft,1,$thn));
	$ybef=$y;
	$yaft=$y;
	if ($mbef<1) {$mbef=12; $ybef=$y-1;}
	if ($maft>12) {$maft=1; $yaft=$y+1;}
	$jmlkosong=date('w',mktime(0,0,0,$m,1,$y));

	$kal='';

	$jmlhari=date('t',mktime(0,0,0,$m,1,$y));

	for ($i=1; $i<=$jmlkosong; $i++)
	{
	    if($i==1 || $i==7){
	    $kal.='<table class="asd" width="100%" cellpadding="0" cellspacing="0">
		      <tbody>
			<tr>
			<td rowspan="2" bgcolor="#ff0000" style="width:40%; font-weight:bold;height:43px; font-size:10px; text-align:center;vertical-align:midle;">
			    &nbsp;
			</td>
		      <td bgcolor="#ff0000" style="width:30%; font-weight:bold;height:21.5px; font-size:10px; text-align:center;vertical-align:midle;">
			  &nbsp;
		      </td>
		  </tr>
		  <tr>
		      <td bgcolor="#ff0000" style="width:30%; font-weight:bold;height:21.5px; font-size:10px; text-align:center;vertical-align:midle;">
			&nbsp;
		      </td>
		    </tr>
		    </tbody>
		    </table>
		    ';
		    }else{
		  $kal.='<table class="asd" width="100%" cellpadding="0" cellspacing="0">
		      <tbody>
			<tr>
			<td rowspan="2" style="width:40%; font-weight:bold;height:43px; font-size:10px; text-align:center;vertical-align:midle;">
			    &nbsp;
			</td>
		      <td style="width:30%; font-weight:bold;height:21.5px; font-size:10px; text-align:center;vertical-align:midle;">
			  &nbsp;
		      </td>
		  </tr>
		  <tr>
		      <td style="width:30%; font-weight:bold;height:21.5px; font-size:10px; text-align:center;vertical-align:midle;">
			&nbsp;
		      </td>
		    </tr>
		    </tbody>
		    </table>
		    ';
		    }
	    }
	$kolom=$jmlkosong;

	for ($i=1; $i<=$jmlhari;$i++)
	{
	    $kolom=$kolom+1;
	    $warna="#000000";
	    if ($kolom=='1') {$warna="#FF0000";}
	    if (($i==date('j')) && ($m==date('m')) && ($y==date('Y')))
	    {
	    $warna="";
	    }
	    $tanggal = $y.'-'.$m.'-'.$i;

	    $q=pg_query ("
			      SELECT
				event.warna,
				event.event,
				kalender.event_id,
				kalender.title,
				kalender.mulai,
				kalender.akhir,
				kalender.jenis
			      FROM
				public.event,
				public.kalender
			      WHERE
				kalender.event_id = event.id and
				kalender.mulai<='".$tanggal."' and kalender.akhir>='".$tanggal."' AND
				kalender.jenis = 'XX'
			    ");

	    $warna_h="#000000";
	    $h=pg_fetch_array($q);

	    $clk="";
	    $cur="";
	    $warna = $h['warna'];

	    if ($kolom=='1' || $kolom=='7') {$warna="#FF0000";$warna_h="#FFFFFF"; $matkul = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";}else{$warna=$warna; $matkul = "YEAH";}

	    if($warna=="")
	    {
		if ($kolom=='1' || $kolom=='7' ) {$warna="#FF0000"; $matkul = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";}else{$warna="#FFFFFF"; $matkul = "FUCK";}
	    }

	    $kal.='<table id="tab1" style="text-align: left; width: 100%;" border="1" cellpadding="0" cellspacing="0">
		      <tbody>
			<tr>
			<td rowspan="2" style="background:'.$warna.';color:'.$warna_h.';width:40%; font-weight:bold;border:1px solid #000;height:43px; font-size:9px; text-align:center;vertical-align:midle;">
			    '.$i.'&nbsp;
			</td>
		      <td bgcolor='.$warna.' style="width:30%; color:'.$warna_h.'; font-weight:bold;border-bottom:1px solid #000;border-top:1px solid #000;height:21.5px; font-size:9px; text-align:center;vertical-align:midle;">
			  '.$matkul.'
		      </td>
		  </tr>';

	    $kal.='
		    <tr>
		      <td bgcolor='.$warna.' style="width:30%; color:'.$warna_h.'; font-weight:bold;border-bottom:1px solid #000;height:21.5px; font-size:9px; text-align:center;vertical-align:midle;">
			'.$matkul.'
		      </td>
		    </tr>
		    </tbody>
		    </table>
		    ';

	    if ($kolom=='7')
	    {
	    $kal.= '';
	    $kolom=0;
	    }
	}

	for($kolom=$kolom;$kolom<7;$kolom++)
	{
	//$kal.= '<tr><td></td></tr>';

	}
	$kal .= '';
	return $kal;
}
?>
  <style>
  table,th,td
  {
  font-weight:bold;
  font-size:10px;
  border:1px solid black;
  border-collapse:collapse;
  }
  .asd td
  {
  border: 0px solid white;
  }
  #tab1 {
	border-left: solid 0px black;
	border-top: solid 0px black;
	border-spacing:0;
	border-collapse: collapse;
  }
  #tab1 td {
	  border-right: solid 0px black;
	  border-bottom: solid 0px black;
  }
  </style>
<body>
  <table id="tab1" style="text-align: left;" width="100%" border="1" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
	<td style="vertical-align: midle; text-align: center;" colspan="22">
	  MATERI
	</td>
      </tr>
      <tr>
	<td style="vertical-align: midle; text-align: center;" width="8%" rowspan="2">HARI<br>
	</td>
	<td style="vertical-align: midle; text-align: center;" width="12%" rowspan="2">WAKTU<br>
	</td>
	<td style="vertical-align: top; text-align: center;" width="80%" colspan="21">BULAN<br>
	</td>
      </tr>
      <tr>
<!-- 	<td style="vertical-align: top; text-align: center;" width="80%" colspan="21"> -->
	<?php
		$tahun=2014;
		for($i=7;$i<=12;$i++)
		{
			echo '<td>';
				echo tgl($i,$tahun);
			echo '</td>';
		}
		for($i=1;$i<=12;$i++)
		{
			echo '<td>';
				echo tgl($i,$tahun+1);
			echo '</td>';
		}

		for($i=1;$i<=2;$i++)
		{
			echo '<td>';
				echo tgl($i,$tahun+2);
			echo '</td>';
		}
	?>
<!-- 	</td> -->
      </tr>
      <tr>
	<td colspan="2" rowspan="1" style="vertical-align: top;">
	<?php
	      for($x=1;$x<=6;$x++)
		{
		    for($x2=1;$x2<=7;$x2++)
		    {
		    if ($x2==1){$nama_hari="Minggu";	$bg="#ff0000"; $fc="#ffffff";}
		    if ($x2==2){$nama_hari="Senin";		$bg="#ffffff"; $fc="#000000";}
		    if ($x2==3){$nama_hari="Selasa";	$bg="#ffffff"; $fc="#000000";}
		    if ($x2==4){$nama_hari="Rabu";		$bg="#ffffff"; $fc="#000000";}
		    if ($x2==5){$nama_hari="kamis";		$bg="#ffffff"; $fc="#000000";}
		    if ($x2==6){$nama_hari="Jum'at";	$bg="#ffffff"; $fc="#000000";}
		    if ($x2==7){$nama_hari="Sabtu";		$bg="#ff0000"; $fc="#ffffff";}

		    $warna_h="#000000";

		    if($nama_hari == "Minggu" || $nama_hari == "Sabtu"){
		      $jam1 = "";
		      $jam2 = "";
		      $bgcolor = "red";
		    }else{
		      $jam1 = "09:00 - 11:30";
		      $jam2 = "13:30 - 16:00";
		      $bgcolor = "";
		    }
		      echo '
			<table id="tab1" style="text-align: left; width: 100%;" border="1" cellpadding="0" cellspacing="0">
			  <tbody>
			    <tr>
			      <td bgcolor= "'.$bgcolor.'" rowspan="2" style="width:40%;font-weight:bold;height:43px; font-size:10px; text-align:center;vertical-align:midle;">
				  '.$nama_hari.'
			      </td>
			      <td bgcolor= "'.$bgcolor.'" style="width:60%; font-weight:bold;height:21.5px; font-size:10px; text-align:center;vertical-align:midle;">
				  '.$jam1.'
			      </td>
			    </tr>
			    <tr>
			      <td bgcolor= "'.$bgcolor.'" style="width:60%; font-weight:bold;height:21.5px; font-size:10px; text-align:center;vertical-align:midle;">
				'.$jam2.'
			      </td>
			    </tr>
			  </tbody>
			</table>
		      ';
		    }
		}
	?>
	</td>
	<?php
		$tahun=2014;
		for($i=7;$i<=12;$i++)
		{
			echo '<td valign="top" rowspan="82">';
				echo kalender($i,$tahun);
			echo '</td>';
		}
		for($i=1;$i<=12;$i++)
		{
			echo '<td valign="top" rowspan="82">';
				echo kalender($i,$tahun+1);
			echo '</td>';
		}

		for($i=1;$i<=2;$i++)
		{
			echo '<td valign="top" rowspan="82">';
				echo kalender($i,$tahun+2);
			echo '</td>';
		}
	?>
      </tr>
    </tbody>
  </table>
  <br>

Gimana?? lumayanlah yaa 😀 , kalo punya referensi ato style yang lbih bagus share jg kesaya yaa hehheee.

Advertisements
This entry was posted in php. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s