|
|
|
ถามเรื่อง ปฏิทิน หน่อยครับ คือผมอยากดึงข้อมูลออกมาจากbase นะครับ แล้วมาแสดงบนปฏิทินอะครับ |
|
|
|
|
|
|
|
คือผมอยากดึงข้อมูลออกมาจากbase นะครับ แล้วมาแสดงบนปฏิทินอะครับ ตองทำไง ดีครับ
calendar.php
<title>CALENDAR</title>
<?php
class Calendar{
private $arrWeekDays;
private $arrMonths;
private $arrViewTypes;
private $defaultView;
private $defaultAction;
private $isDrawNavigation;
private $crLt;
private $caption;
private $calWidth;
private $calHeight;
private $cellHeight;
function __construct()
{
// possible values 1,2,....7 มี sunday
$this->weekStartedDay = 1;
//ให้มีการขึ้นชื่อ วันด้านบน
$this->arrWeekDays = array();
$this->arrWeekDays[0] = array("short"=>"Sun", "long"=>"Sunday");
$this->arrWeekDays[1] = array("short"=>"Mon", "long"=>"Monday");
$this->arrWeekDays[2] = array("short"=>"Tue", "long"=>"Tuesday");
$this->arrWeekDays[3] = array("short"=>"Wed", "long"=>"Wednesday");
$this->arrWeekDays[4] = array("short"=>"Thu", "long"=>"Thursday");
$this->arrWeekDays[5] = array("short"=>"Fri", "long"=>"Friday");
$this->arrWeekDays[6] = array("short"=>"Sat", "long"=>"Satarday");
//มีชื่อเดือนให้เลือกใน Listbox
$this->arrMonths = array();
$this->arrMonths["1"] = "January";
$this->arrMonths["2"] = "February";
$this->arrMonths["3"] = "March";
$this->arrMonths["4"] = "April";
$this->arrMonths["5"] = "May";
$this->arrMonths["6"] = "June";
$this->arrMonths["7"] = "July";
$this->arrMonths["8"] = "August";
$this->arrMonths["9"] = "September";
$this->arrMonths["10"] = "October";
$this->arrMonths["11"] = "November";
$this->arrMonths["12"] = "December";
//มีให้เลือกเดือนกับปีที่มุมขวา
$this->arrViewTypes = array();
$this->arrViewTypes["monthly"] = "Monthly";
$this->arrViewTypes["yearly"] = "Yearly";
}
function Show()
{
//ตัว next back ปี กับ เดือน ด้านบน
$this->GetCurrentParameters();
$this->DrawJsFunctions();
//ตัวเรียก CSS
echo "<div id='calendar' style='width:".$this->calWidth.";'>".$this->crLt;
// draw calendar header ตัวเสดง TODAY และ ตัวเลือก เดือน กับ ปี ด้านบน
echo "<table id='calendar_header'>".$this->crLt;
echo "<tr>";
echo "<th class='caption_left'>".$this->DrawTodayJumper(false)."</th>";
echo "<th class='caption'>".$this->caption."</th>";
echo "<th class='types_changer'>".$this->DrawTypesChanger(false)."</th>";
echo "</tr>".$this->crLt;
echo "</table>";
switch($this->arrParameters["view_type"])
{
case "yearly":
$this->DrawYear();
break;
default:
case "monthly":
$this->DrawMonth();
break;
}
}
/**
* Set calendar dimensions
* @param $width
* @param $height กำหนดความกว้างความยาวของ ปฏิทิน
*/
function SetCalendarDimensions($width = "", $height = "")
{
$this->calWidth = ($width != "") ? $width : "800px";
$this->calHeight = ($height != "") ? $height : "470px";
$this->celHeight = number_format(((int)$this->calHeight)/5, "")."px";
}
/**
* Set week started day
* @param $started_day - started day of week 1...7 ให้มัน start ที่เท่าไร
*/
function SetWeekStartedDay($started_day = "1")
{
if(is_numeric($started_day) && (int)$started_day >= 1 && (int)$started_day <= 7){
}
}
/**
* Set week day name length
* @param $length_name - "short"|"long" ตัวแสเงชื่อวันด้านบน
*/
function SetWeekDayNameLength($length_name = "short")
{
if(strtolower($length_name) == "long"){
$this->weekDayNameLength = "long";
}
}
function GetCurrentParameters() //การสร้าง ว ด ป
{
$year = (isset($_GET['year']) && $this->isYear($_GET['year'])) ? $_GET['year'] : date("Y");
$month = (isset($_GET['month']) && $this->isMonth($_GET['month'])) ? $_GET['month'] : date("m");
$day = (isset($_GET['day']) && $this->isDay($_GET['day'])) ? $_GET['day'] : date("d");
$view_type = (isset($_GET['view_type']) && array_key_exists($_GET['view_type'], $this->arrViewTypes)) ? $_GET['view_type'] : "monthly";
$cur_date = getdate(mktime(0,0,0,$month,$day,$year));
///echo "<br>3--";
///print_r($cur_date);
$this->arrParameters["year"] = $cur_date['year'];
$this->arrParameters["month"] = $this->ConvertToDecimal($cur_date['mon']);
$this->arrParameters["month_full_name"] = $cur_date['month'];
$this->arrParameters["day"] = $day;
$this->arrParameters["view_type"] = $view_type;
$this->arrParameters["action"] = "display";
$this->arrToday = getdate();
$this->prevYear = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"],$this->arrParameters['year']-1));
$this->nextYear = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"],$this->arrParameters['year']+1));
$this->prevMonth = getdate(mktime(0,0,0,$this->arrParameters['month']-1,$this->arrParameters["day"],$this->arrParameters['year']));
$this->nextMonth = getdate(mktime(0,0,0,$this->arrParameters['month']+1,$this->arrParameters["day"],$this->arrParameters['year']));
}
/**
* Draw javascript functions
*
*/
private function DrawJsFunctions()// FUNCTIONS JUMP ที่ปุ่ม Go
{
echo "<script type='text/javascript'>";
echo "
function JumpToDate(){
var jump_day = (document.getElementById('jump_day')) ? document.getElementById('jump_day').value : '';
var jump_month = (document.getElementById('jump_month')) ? document.getElementById('jump_month').value : '';
var jump_year = (document.getElementById('jump_year')) ? document.getElementById('jump_year').value : '';
var view_type = (document.getElementById('view_type')) ? document.getElementById('view_type').value : '';
__doPostBack('view', view_type, jump_year, jump_month, jump_day);
}
function __doPostBack(action, view_type, year, month, day)
{
var action = (action != null) ? action : 'view';
var view_type = (view_type != null) ? view_type : 'monthly';
var year = (year != null) ? year : '".$this->arrToday["year"]."';
var month = (month != null) ? month : '".$this->ConvertToDecimal($this->arrToday["mon"])."';
var day = (day != null) ? day : '".$this->arrToday["mday"]."';
document.location.href = '".$this->arrParameters["current_file"]. "?action='+action+'&view_type='+view_type+'&year='+year+'&month='+month+'&day='+day;
}
";
echo "</script>";
}
/**
* Draw monthly calendar
*
*/
private function DrawMonth()
{
// today, first day and last day in month
$firstDay = getdate(mktime(0,0,0,$this->arrParameters['month'],1,$this->arrParameters['year']));
$lastDay = getdate(mktime(0,0,0,$this->arrParameters['month']+1,0,$this->arrParameters['year']));
///print_r($firstDay);
// Create a table with the necessary header informations
echo "<table class='month'>".$this->crLt;
echo "<tr>";
echo "<th colspan='7'>";
echo "<table class='table_navbar'>".$this->crLt;
echo "<tr>";
echo "<th class='tr_navbar_left'>
".$this->DrawDateJumper(false)."
</th>".$this->crLt;
echo "<th class='tr_navbar'>";
echo " <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->prevMonth['year']."', '".$this->ConvertToDecimal($this->prevMonth['mon'])."', '".$this->arrParameters['day']."')\">««</a> ";
echo $this->arrParameters['month_full_name']." - ".$this->arrParameters['year'];
echo " <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->nextMonth['year']."', '".$this->ConvertToDecimal($this->nextMonth['mon'])."', '".$this->arrParameters['day']."')\">»»</a> ";
echo "</th>".$this->crLt;
echo "<th class='tr_navbar_right'>
<a href=\"javascript:__doPostBack('view', 'monthly', '".$this->prevYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->prevYear['year']."</a> |
<a href=\"javascript:__doPostBack('view', 'monthly', '".$this->nextYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->nextYear['year']."</a>
</th>".$this->crLt;
echo "</tr>".$this->crLt;
echo "</table>".$this->crLt;
echo "</td>".$this->crLt;
echo "</tr>".$this->crLt;
echo "<tr class='tr_days'>";
for($i = $this->weekStartedDay-1; $i < $this->weekStartedDay+6; $i++){
echo "<td class='th'>".$this->arrWeekDays[($i % 7)][$this->weekDayNameLength]."</td>";
}
echo "</tr>".$this->crLt;
// Display the first calendar row with correct positioning
if ($firstDay['wday'] == 0) $firstDay['wday'] = 7;
$max_empty_days = $firstDay['wday']-($this->weekStartedDay-1);
if($max_empty_days < 7){
echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
for($i = 1; $i <= $max_empty_days; $i++){
echo "<td class='td_empty'> </td>".$this->crLt;
}
$actday = 0;
for($i = $max_empty_days+1; $i <= 7; $i++){
$actday++;
if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
$class = " class='td_actday'";
} else if ($actday == $this->arrParameters['day']){
$class = " class='td_selday'";
} else {
$class = " class='td'";
}
echo "<td$class>$actday</td>".$this->crLt;
}
echo "</tr>".$this->crLt;
}
//Get how many complete weeks are in the actual month
$fullWeeks = floor(($lastDay['mday']-$actday)/7);
for ($i=0;$i<$fullWeeks;$i++){
echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
for ($j=0;$j<7;$j++){
$actday++;
if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
$class = " class='td_actday'";
} else if ($actday == $this->arrParameters['day']){
$class = " class='td_selday'";
} else {
$class = " class='td'";
}
echo "<td$class>$actday</td>".$this->crLt;
}
echo "</tr>".$this->crLt;
}
//Now display the rest of the month
if ($actday < $lastDay['mday']){
echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
for ($i=0; $i<7;$i++){
$actday++;
if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
$class = " class='td_actday'";
} else {
$class = " class='td'";
}
if ($actday <= $lastDay['mday']){
echo "<td$class>$actday</td>".$this->crLt;
} else {
echo "<td class='td_empty'> </td>".$this->crLt;
}
}
echo "</tr>".$this->crLt;
}
echo "</table>".$this->crLt;
}
/**
* Draw calendar types changer
* @param $draw - draw or return
*/
private function DrawTypesChanger($draw = true)
{
foreach($this->arrViewTypes as $key => $val){
}
}
/**
* Draw today jumper
* @param $draw - draw or return
*/
private function DrawTodayJumper($draw = true)
{ // TODAT มุมซ้าย
$result = "<input class='form_button' type='button' value='Today' onclick=\"javascript:__doPostBack('".$this->defaultAction."', '".$this->defaultView."', '".$this->arrToday["year"]."', '".$this->ConvertToDecimal($this->arrToday["mon"])."', '".$this->arrToday["mday"]."')\" />";
if($draw){
echo $result;
}else{
return $result;
}
}
/**
* Draw date jumper
* @param $draw - draw or return
*/
private function DrawDateJumper($draw = true, $draw_day = true, $draw_month = true, $draw_year = true)
{
// draw days ddl
if($draw_day){ //ทำ LISTBOX วันที่
$result = "<select class='form_select' name='jump_day' id='jump_day'>";
for($i=1; $i <= 31; $i++){
$i_converted = $this->ConvertToDecimal($i);
$result .= "<option value='".$this->ConvertToDecimal($i)."' ".(($this->arrParameters["day"] == $i_converted) ? "selected='selected'" : "").">".$i_converted."</option>";
}
$result .= "</select> ";
}else{
}
// draw months ddl
if($draw_month){ //ทำ LISTBOX เดือน
$result .= "<select class='form_select' name='jump_month' id='jump_month'>";
for($i=1; $i <= 12; $i++){
$i_converted = $this->ConvertToDecimal($i);
$result .= "<option value='".$this->ConvertToDecimal($i)."' ".(($this->arrParameters["month"] == $i_converted) ? "selected='selected'" : "").">".$this->arrMonths[$i]."</option>";
}
$result .= "</select> ";
}else{
}
// draw years ddl
if($draw_year){ //ทำ LISTBOX ปี
$result .= "<select class='form_select' name='jump_year' id='jump_year'>";
for($i=$this->arrParameters["year"]-10; $i <= $this->arrParameters["year"]+10; $i++){
$result .= "<option value='".$i."' ".(($this->arrParameters["year"] == $i) ? "selected='selected'" : "").">".$i."</option>";
}
$result .= "</select> ";
}else{
$result .= "<input type='hidden' name='jump_year' id='jump_year' value='".$this->arrToday["year"]."' />";
}
//ปุ่ม GO
$result .= "<input class='form_button' type='button' value='Go' onclick='JumpToDate()' />";
if($draw){
echo $result;
}else{
return $result;
}
}
////////////////////////////////////////////////////////////////////////////
// Auxilary
////////////////////////////////////////////////////////////////////////////
/**
* Check if parameters is 4-digit year
* @param $year - string to be checked if it's 4-digit year
*/
private function isYear($year = "")
{
for($i = 0; $i < 4; $i++){
if(!(isset($year[$i]) && $year[$i] >= 0 && $year[$i] <= 9)){
return false;
}
}
return true;
}
/**
* Check if parameters is month
* @param $month - string to be checked if it's 2-digit month
*/
private function isMonth($month = "")
{
for($i = 0; $i < 2; $i++){
if(!(isset($month[$i]) && $month[$i] >= 0 && $month[$i] <= 9)){
return false;
}
}
return true;
}
/**
* Check if parameters is day
* @param $day - string to be checked if it's 2-digit day
*/
private function isDay($day = "")
{
for($i = 0; $i < 2; $i++){
if(!(isset($day[$i]) && $day[$i] >= 0 && $day[$i] <= 9)){
return false;
}
}
return true;
}
/**
* Convert to decimal number with leading zero
* @param $number วัน
*/
private function ConvertToDecimal($number)
{
return (($number < 10) ? "0" : "").$number;
}
}
?>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-04-09 13:29:55 |
By :
kirisaki |
View :
1130 |
Reply :
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2010-04-09 15:51:28 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*-*
|
|
|
|
|
Date :
2010-04-19 08:47:34 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้ กัน เปล่า ครับ
|
|
|
|
|
Date :
2010-04-19 14:15:40 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีโค้ดที่เรียก Class มาใช้งานไหมครับจะได้เหมือนๆกัน
|
|
|
|
|
Date :
2010-04-20 15:26:43 |
By :
jankasion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะมี อยู่ครับ คุณมีหรือครับ ส่งmail ก็ได้ นะครับ [email protected]
|
|
|
|
|
Date :
2010-04-20 15:48:59 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ครับ
|
|
|
|
|
Date :
2010-04-20 15:53:57 |
By :
jankasion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[email protected]
ผมลองรับ function show() แต่มันออกมาขาวๆไม่เหมือนในรูปเลย
|
|
|
|
|
Date :
2010-04-20 15:55:42 |
By :
jankasion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมยังทำ ไม่ได้ ครับ ผมต้องการ ดึงจาก base ขึ้นมา show อะครับ ยังทำไม่ได้ที
|
|
|
|
|
Date :
2010-04-20 15:58:52 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาใหม่
ผมอยากได้โค้ดที่ทำให้เกิดรูปปฏิทิน https://www.thaicreate.com/upload/stock/20100409132839.jpg
ที่คุณ kirisaki เอามาโพสถามครับ
เพราะว่าโค้ดที่คุณให่มาใต้รูปเป็นโค้ด class function ยังไม่ใช้โค้ดในการเรียกใช้งาน class
|
|
|
|
|
Date :
2010-04-20 16:14:42 |
By :
jankasion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ส่งให้ใน mailแล้วนะครับ
|
|
|
|
|
Date :
2010-04-20 16:31:04 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ครับผม จะปรับแก้ดูแล้วจะส่งให้ภายในคืนนี้นะครับ
|
|
|
|
|
Date :
2010-04-20 16:43:34 |
By :
jankasion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใจมาก ครับผม เอา
|
|
|
|
|
Date :
2010-04-20 16:45:36 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้เปล่าครับ
|
|
|
|
|
Date :
2010-04-21 09:39:59 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- -
|
|
|
|
|
Date :
2010-04-21 11:22:34 |
By :
kirisaki |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|