calendar.php
<!-- WANT U KONGLISH --> <html> <head> <title>:: DIARY ::</title> <style> body, td { font-family:verdana; font-size:9pt; color:#000000; text-align:center; } a:link { color:#000000; text-decoration:none; } a:hover { color:#000000; text-decoration:none; } a:visited { color:#000000; text-decoration:none; } a:active { color:#000000; text-decoration:none; } .week { background-color:#333333; height:40px; color:#ffffff; } .date { background-color:#dfdfcf; height:70px; padding:2px; line-height:220%; text-align:left; } .schedule { background-color:#f3f3f3; width:100px; height:60px; line-height:120%; overflow:hidden; } h2,h3,h4 { font-family:verdana; } </style> </head> <body topmargin=30>
<? $PHP_SELF = $_SERVER["PHP_SELF"]; /* FileName of current running script */ $TODAY = getdate(mktime()); /* Information of TODAY */ $get_month = ($_GET["month"]) ? $_GET["month"] : $TODAY["mon"]; /* Parsing and Initializing MONTH and YEAR */ $get_year = ($_GET["year"]) ? $_GET["year"] : $TODAY["year"]; $current = getdate(mktime(0,0,0,$get_month,1,$get_year)); /* current : setted value by user */ $current_month = $current["mon"]; $current_year = $current["year"]; $START_WEEKDAY = date("w",mktime(0,0,0,$current_month,1,$current["year"])); $END_DAY = date("t",mktime(0,0,0,$current_month,1,$current["year"])); $DAY = array(); $file_of_day = array(); $dir = "./diary/"; $files_in_dir = scandir($dir);
/********** Parsing the INITIAL_of_FILENAME **********/ for($i=0 ; $i<=$END_DAY ; $i++) { // 0 is not exist day. $file_of_day[$i] = strval(date("Ymd",mktime(0,0,0,$current_month,$i,$current_year))); }
for($ind=0, $i=1 ; $i<=$END_DAY ; $ind++) { /********** Initialize array_$DAYS of This_Month **********/ if($ind>$START_WEEKDAY) $DAYS[$ind] = $i++; else $DAYS[$ind] = NULL; }
/********** TITLE linked INITIAL_PAGE **********/ echo "<h3><a href='$PHP_SELF' onfocus='blur();'>:: DIARY ::</a></h3>";
/********** variables for MOVE YEAR_or_MONTH **********/ $before_month = $PHP_SELF."?month=".($current_month-1)."&year=".$current_year; $next_month = $PHP_SELF."?month=".($current_month+1)."&year=".$current_year; $before_year = $PHP_SELF."?year=".($current_year-1); /* Exist the situation that change YEAR when change MONTH */ $next_year = $PHP_SELF."?year=".($current_year+1); /* So, set YEAR passive when change MONTH */ if(($current_month-1)<1) $before_month = $PHP_SELF."?month=12&year=".($current_year-1); if(($current_month+1)>12) $next_month = $PHP_SELF."?month=1&year=".($current_year+1); ?>
<!-- MOVE_or_CHANGE YEAR_or_MONTH --> <table cellspacing=2 align=center> <tr height=30><!-- change YEAR and MONTH --> <td width=100 style='text-align:right;'><a href='<?=$before_year?>' onfocus='blur();'><<</a></td> <td width=100><?=$current_year?></td> <td width=100 style='text-align:left;'><a href='<?=$next_year?>' onfocus='blur();'>>></a></td> <td width=100><!-- BLANK --></td> <td width=100 style='text-align:right;'><a href='<?=$before_month?>' onfocus='blur();'><<</a></td> <td width=100><?=$current_month?></td> <td width=100 style='text-align:left;'><a href='<?=$next_month?>' onfocus='blur();'>>></a></td> </tr> </table>
<!-- OUTTER_LINE --> <table bgcolor=black cellspacing=1 align=center> <tr> <td bgcolor=white> <!-- DRAWING CALENDAR --> <table cellspacing=2 align=center> <tr><!-- drawing WEEKDAY table --> <td class='week' style='color:#ff3333;'>Sun</td> <td class='week'>Mon</td> <td class='week'>Tue</td> <td class='week'>Wed</td> <td class='week'>Thu</td> <td class='week'>Fri</td> <td class='week' style='color:#87cefa;'>Sat</td> </tr>
<? for($tr_num=0, $ind=1, $draw_table=0 ; $tr_num<6 ; $tr_num++) { echo "<tr>"; for($td_num=0 ; $td_num%8!=7 ; $td_num++) { /********** Print DATE **********/ if($DAYS[$ind]==$END_DAY) $draw_table=1; echo "<td class='date'>"; if($DAYS[$ind]==NULL) echo " "; /* If don't start yet, print blank */ echo "<a href='$PHP_SELF' onclick=\"window.open('./write.php?add=".$file_of_day[$DAYS[$ind]]."','AddToDoing', 'location=no,directories=no,resizable=no,status=no,toolbar=no,menubar=no, width=400, height=500,left=0,top=0, scrollbars=no'); return false\" onfocus='blur();'>"; if($td_num==0) echo "<font color=#ff3333>"; /* Color of Sunday and Saterday is RED and BLUE */ if($td_num==6) echo "<font color=#0066ff>"; if(($current_year==$TODAY["year"])&&($current_month==$TODAY["mon"])&&($TODAY["mday"]==$DAYS[$ind])) echo "<b>".$DAYS[$ind]."</b>"; /* Font of Today is BOLD */ else echo $DAYS[$ind]; echo "</a>"; if($td_num==0||$td_num==6) echo "</font>"; /********** Print DOING **********/ echo "<div class='schedule'>"; foreach($files_in_dir as $index => $name) { if( !strncmp($file_of_day[$DAYS[$ind]], $files_in_dir[$index], 8) ) { $fp=fopen($dir.$name,"r"); echo "<a href='$PHP_SELF' onclick=\"window.open('./write.php?modify=".$name."','AddToDoing', 'location=no,directories=no,resizable=no,status=no,toolbar=no,menubar=no, width=400, height=500,left=0,top=0, scrollbars=no'); return false\" onfocus='blur();'>".fgets($fp)."</a><br>"; fclose($fp); } } echo "</div>"; /*********************************/ echo "</td>"; $ind++; /* Increment Index_Number */ } echo "</tr>"; if($draw_table) break; } ?>
</table> </td> </td> </table>
</body> </html>
calendar.php
write.php
<!-- WANT U KONGLISH --> <html> <head> <title>:: DIARY ::</title> <style> body, td, textarea { font-family:verdana; font-size:9pt; color:#000000; } a:link { color:#000000; text-decoration:none; } a:hover { color:#000000; text-decoration:none; } a:visited { color:#000000; text-decoration:none; } a:active { color:#000000; text-decoration:none; } textarea { scrollbar-face-color: white; scrollbar-shadow-color:#000000; scrollbar-highlight-color:#000000; scrollbar-3dlight-color: white; scrollbar-darkshadow-color: white; scrollbar-track-color: white; scrollbar-arrow-color:#000000; background-image:url("./nanoha.gif"); /* BACKGROUND-IMAGE for write form */ background-repeat:no-repeat; background-position:right bottom; background-attachment:fixed; } input,textarea { border:1px solid; } </style> </head> <body leftmargin=20> <? $PHP_SELF = $_SERVER["PHP_SELF"]; $dir = "./diary/"; $title = $_POST["title"]."\n"; $detail = $_POST["detail"]; $add = $_GET["add"]; $modify = ($_GET["modify"]) ? $_GET["modify"] : $_POST["modify"]; $mode = (!$_POST["UNLINKFLAG"]) ? $_POST["mode"] : "del"; /* Parsing mode :: add || modify || del */ if( !($dh = opendir($dir))) { echo "<script>alert(\"ERROR : opendir() failed.\");history.back();</script>"; } closedir($dh); echo "<b>Diary</b><br/><hr><p/>"; echo "<form method=post action='".$PHP_SELF."'>"; /********** SCHEDULE ADD **********/ if($add) { $i=1; while(1) { $filename = $add."_".$i++.".txt"; /* Create FILENAME by date("Ymd",mktime()) from GET method */ if(!(file_exists($dir.$filename))) break; } echo "<input type=hidden value='$filename' name='filename'>"; echo "TITLE : <input type=text name='title' style='width:300px;height:17px;'><p />"; echo "CONTENTS<br><textarea name='detail' style='width:347px;height:300px;'></textarea><p/>"; echo "<input type=hidden value='add' name=mode>"; echo "<table width=350><tr> <td>FILENAME : <font color=navy>$filename</font></td> <td align=right><input type=submit value='GO!' style='width:100px;height:17px;'></td> </tr></table>"; } /********** SCHEDULE WRITE TO FILE **********/ if($mode=="add"||$mode=="modify"||$mode=="del") { echo "<table width=100%><tr><td align=right> <a href='$PHP_SELF' onclick='window.close();' onfocus='blur()'>CLOSE</a> </td></tr></table>"; if($mode=="add") $fp=fopen($dir.$_POST["filename"], "w+"); if($mode=="modify") $fp=fopen($dir.$modify, "w+"); if($mode=="add"||$mode=="modify") { echo $title."<br>"; echo $detail; fwrite($fp,$title); fwrite($fp,$detail); fclose($fp); } echo "<script>opener.location.reload();</script>"; /********** DELETE DOING **********/ if($mode=="del") { unlink($dir.$modify); echo "<script>window.close();</script>"; } } /********** MODIFY DOING **********/ if(!$mode&&$modify) { if($fp=fopen($dir.$modify,"r")) { echo "<input type=hidden name=modify value='$modify'>"; echo "TITLE : <input type=text name='title' style='width:300px;height:17px;' value='".fgets($fp)."'><p />"; echo "CONTENTS<br><textarea name='detail' style='width:347px;height:300px;'>"; fpassthru($fp); echo "</textarea><p/>"; echo "<input type=hidden value='modify' name=mode>"; echo "<table width=350><tr> <td>FILENAME : <font color=navy>$modify</font></td> <td>DELETE<input type=checkbox name=UNLINKFLAG><td> <td align=right><input type=submit value='GO!' style='width:50px;height:17px;'> </td></tr></table>"; fclose($fp); } else echo "<script>alert(\"ERROR : fopen() failed.\");</script>"; } echo "</form>"; ?> </body> </html>
write.php 난이도는..뭐 별로...