2016-10-10 97 views
0

我有一個約會的網站,我使用此預訂腳本http://www.planetphp.co.uk/free-php-booking-slots-calendar/。 不幸的是,我試圖在顯示月份時更改語言。更改語言的日期()

class booking_diary { 

// Mysqli connection 
function __construct($link) { 
    $this->link = $link;  
} 

// Settings you can change: 
// Time Related Variables 
public $booking_start_time   = "09:00";   // The time of the first slot in 24 hour H:M format 
public $booking_end_time   = "21:00";   // The time of the last slot in 24 hour H:M format 
public $booking_frequency   = 30;    // The slot frequency per hour, expressed in minutes. 

// Day Related Variables 

public $day_format     = 3;    // Day format of the table header. Possible values (1, 2, 3) 
                  // 1 = Show First digit, eg: "M" 
                  // 2 = Show First 3 letters, eg: "Mon" 
                  // 3 = Full Day, eg: "Monday" 

public $day_closed     = array("Saturday", "Sunday"); // If you don't want any 'closed' days, remove the day so it becomes: = array(); 
public $day_closed_text    = "CLOSED";   // If you don't want any any 'closed' remove the text so it becomes: = ""; 

// Cost Related Variables 
public $cost_per_slot    = 20.50;   // The cost per slot 
public $cost_currency_tag   = "€";  // The currency tag in HTML such as € £ ¥  

// DO NOT EDIT BELOW THIS LINE 

public $day_order     = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); 
public $day, $month, $year, $selected_date, $back, $back_month, $back_year, $forward, $forward_month, $forward_year, $bookings, $count, $days, $is_slot_booked_today; 
/*========================================================================================================================================================*/ 
function make_calendar($selected_date, $back, $forward, $day, $month, $year,$first_name) { 

    // $day, $month and $year are the $_GET variables in the URL 
    $this->day = $day;  
    $this->month = $month; 
    $this->year = $year; 
    $this->first_name = $first_name; 
    $this->last_name = $last_name; 
    $this->telephone = $telephone; 
    $this->email = $email; 
    $this->page_id = $page_id; 
    $this->user_id = $user_id; 
    $this->uid = $uid; 
    $this->pon = $owner; 
    $this->rsvnumb = $rsvnumb; 

    // $back and $forward are Unix Timestamps of the previous/next month, used to give the back arrow the correct month and year 
    $this->selected_date = $selected_date;  
    $this->back = $back; 
    $this->back_month = date("m", $back); 
    $this->back_year = date("Y", $back); // Minus one month back arrow 

    $this->forward = $forward; 
    $this->forward_month = date("m", $forward); 
    $this->forward_year = date("Y", $forward); // Add one month forward arrow    
    // Make the booking array 
    $this->make_booking_array($year, $month);   
}  

function make_booking_array($year, $month, $j = 0) { 

    $stmt = $this->link->prepare("SELECT name, date, start FROM bookings WHERE date LIKE CONCAT(?, '-', ?, '%') and page_id=".$_GET['page_id'].""); 
    $this->is_slot_booked_today = 0; // Defaults to 0 

    $stmt->bind_param('ss', $year, $month); 
    $stmt->bind_result($name, $date, $start); 
    $stmt->execute(); 
    $stmt->store_result(); 

    while($stmt->fetch()) {  

     $this->bookings_per_day[$date][] = $start;  
     $this->bookings[] = array(
      "name" => $name, 
      "date" => $date, 
      "start" => $start   
     ); 

     // Used by the 'booking_form' function later to check whether there are any booked slots on the selected day   
     if($date == $this->year . '-' . $this->month . '-' . $this->day) { 
      $this->is_slot_booked_today = 1; 
     }  
    } 

    // Calculate how many slots there are per day 
    $this->slots_per_day = 0; 
    for($i = strtotime($this->booking_start_time); $i<= strtotime($this->booking_end_time); $i = $i + $this->booking_frequency * 60) { 
     $this->slots_per_day ++; 
    } 

    $stmt->close();  
    $this->make_days_array($year, $month);  

} // Close function  

function make_days_array($year, $month) { 

    // Calculate the number of days in the selected month     
    $num_days_month = cal_days_in_month(CAL_GREGORIAN, $month, $year); 

    // Make $this->days array containing the Day Number and Day Number in the selected month  
    for ($i = 1; $i <= $num_days_month; $i++) {  

     // Work out the Day Name (Monday, Tuesday...) from the $month and $year variables 
     $d = (mktime(0, 0, 0, $month, $i, $year)); 

     // Create the array 
     $this->days[] = array("daynumber" => $i, "dayname" => date("l", $d));  
    } 

    /* 
    Sample output of the $this->days array: 

    [0] => Array 
     (
      [daynumber] => 1 
      [dayname] => Monday 
     ) 

    [1] => Array 
     (
      [daynumber] => 2 
      [dayname] => Tuesday 
     ) 
    */ 

    $this->make_blank_start($year, $month); 
    $this->make_blank_end($year, $month); 

} // Close function  

function make_blank_start($year, $month) { 

    /* 
    Calendar months start on different days 
    Therefore there are often blank 'unavailable' days at the beginning of the month which are showed as a grey block 
    The code below creates the blank days at the beginning of the month 
    */ 

    // Get first record of the days array which will be the First Day in the month (eg Wednesday) 
    $first_day = $this->days[0]['dayname']; $s = 0; 

     // Loop through $day_order array (Monday, Tuesday ...) 
     foreach($this->day_order as $i => $r) { 

      // Compare the $first_day to the Day Order 
      if($first_day == $r && $s == 0) { 

       $s = 1; // Set flag to 1 stop further processing 

      } elseif($s == 0) { 

       $blank = array(
        "daynumber" => 'blank', 
        "dayname" => 'blank' 
       ); 

       // Prepend elements to the beginning of the $day array 
       array_unshift($this->days, $blank); 
      }    
    } // Close foreach  
} // Close function  

function make_blank_end($year, $month) { 

    /* 
    Calendar months start on different days 
    Therefore there are often blank 'unavailable' days at the end of the month which are showed as a grey block 
    The code below creates the blank days at the end of the month 
    */ 

    // Add blank elements to end of array if required. 
    $pad_end = 7 - (count($this->days) % 7); 

    if ($pad_end < 7) { 

     $blank = array(
      "daynumber" => 'blank', 
      "dayname" => 'blank' 
     ); 

     for ($i = 1; $i <= $pad_end; $i++) {        
      array_push($this->days, $blank); 
     } 

    } // Close if 

    $this->calendar_top(); 

} // Close function 

function calendar_top() { 

    // This function creates the top of the table containg the date and the forward and back arrows 

    echo " 
    <div id='lhs'><div id='outer_calendar'> 

    <table border='0' cellpadding='0' cellspacing='0' id='calendar'> 
     <tr id='week'> 
     <td align='left'><a href='?month=" . date("m", $this->back) . "&amp;first_name=" . $_GET['first_name'] . "&amp;email=" . $_GET['email'] . "&amp;last_name=" . $_GET['last_name'] . "&amp;telephone=" . $_GET['telephone'] . "&amp;user_id=" . $_GET['user_id'] . "&amp;uid=" . $_GET['uid'] . "&amp;rsvnumb=" . $_GET['rsvnumb'] . "&amp;pon=" . $_GET['pon'] . "&amp;page_id=" . $_GET['page_id'] . "&amp;year=" . date("Y", $this->back) . "'>&laquo;</a></td> 
     <td colspan='5' id='center_date'>" . date("F, Y", $this->selected_date) . "</td>  
     <td align='right'><a href='?month=" . date("m", $this->forward) . "&amp;first_name=" . $_GET['first_name'] . "&amp;email=" . $_GET['email'] . "&amp;last_name=" . $_GET['last_name'] . "&amp;telephone=" . $_GET['telephone'] . "&amp;user_id=" . $_GET['user_id'] . "&amp;uid=" . $_GET['uid'] . "&amp;rsvnumb=" . $_GET['rsvnumb'] . "&amp;pon=" . $_GET['pon'] . "&amp;page_id=" . $_GET['page_id'] . "&amp;year=" . date("Y", $this->forward) . "'>&raquo;</a></td> 
    </tr> 
    <tr>"; 

    /* 
    Make the table header with the appropriate day of the week using the $day_format variable as user defined above 
    Definition: 

     1: Show First digit, eg: "M" 
     2: Show First 3 letters, eg: "Mon" 
     3: Full Day, eg: "Monday"  

    */ 

    foreach($this->day_order as $r) { 

     switch($this->day_format) { 

      case(1):  
       echo "<th>" . substr($r, 0, 1) . "</th>";     
      break; 

      case(2): 
       echo "<th>" . substr($r, 0, 3) . "</th>";   
      break; 

      case(3):  
       echo "<th>" . $r . "</th>"; 
      break; 

     } // Close switch  
    } // Close foreach  

    echo "</tr>"; 

    $this->make_cells(); 

} // Close function 

function make_cells($table = '') { 
echo '<h3>Επέλεξε μία μέρα</h3>'; 
    echo "<tr>"; 

    foreach($this->days as $i => $r) { // Loop through the date array 

     $j = $i + 1; $tag = 0;   

     // If the the current day is found in the day_closed array, bookings are not allowed on this day 
     if(in_array($r['dayname'], $this->day_closed)) {    
      echo "\r\n<td width='21' valign='top' class='closed'>" . $this->day_closed_text . "</td>";  
      $tag = 1; 
     }   

     // Past days are greyed out 
     if (mktime(0, 0, 0, $this->month, sprintf("%02s", $r['daynumber']) + 1, $this->year) < strtotime("now") && $tag != 1) {  

      echo "\r\n<td width='21' valign='top' class='past'>";   
       // Output day number 
       if($r['daynumber'] != 'blank') echo $r['daynumber']; 

      echo "</td>";  
      $tag = 1; 
     }   

     // If the element is set as 'blank', insert blank day 
     if($r['dayname'] == 'blank' && $tag != 1) {  
      echo "\r\n<td width='21' valign='top' class='unavailable'></td>"; 
      $tag = 1; 
     }     

     // Now check the booking array $this->booking to see whether we have a booking on this day    
     $current_day = $this->year . '-' . $this->month . '-' . sprintf("%02s", $r['daynumber']); 

     if(isset($this->bookings_per_day[$current_day]) && $tag == 0) { 

      $current_day_slots_booked = count($this->bookings_per_day[$current_day]); 

       if($current_day_slots_booked < $this->slots_per_day) { 

        echo "\r\n<td width='21' valign='top'> 
        <a href='reservation.php?month=" . $this->month . "&amp;year=" . $this->year . "&amp;first_name=" . $_GET['first_name'] . "&amp;email=" . $_GET['email'] . "&amp;last_name=" . $_GET['last_name'] . "&amp;rsvnumb=" . $_GET['rsvnumb'] . "&amp;telephone=" . $_GET['telephone'] . "&amp;pon=" . $_GET['pon'] . "&amp;user_id=" . $_GET['user_id'] . "&amp;uid=" . $_GET['uid'] . "&amp;page_id=" . $_GET['page_id'] . "&amp;day=" . sprintf("%02s", $r['daynumber']) . "' class='part_booked' title='This day is part booked'>" . 
        $r['daynumber'] . "</a></td>"; 
        $tag = 1; 

       } else { 

        echo "\r\n<td width='21' valign='top'> 
        <a href='reservation.php?month=" . $this->month . "&amp;year=" . $this->year . "&amp;first_name=" . $_GET['first_name'] . "&amp;email=" . $_GET['email'] . "&amp;last_name=" . $_GET['last_name'] . "&amp;rsvnumb=" . $_GET['rsvnumb'] . "&amp;telephone=" . $_GET['telephone'] . "&amp;pon=" . $_GET['pon'] . "&amp;user_id=" . $_GET['user_id'] . "&amp;uid=" . $_GET['uid'] . "&amp;page_id=" . $_GET['page_id'] . "&amp;day=" . sprintf("%02s", $r['daynumber']) . "' class='fully_booked' title='This day is fully booked'>" . 
        $r['daynumber'] . "</a></td>"; 
        $tag = 1;   

       } // Close else    
     } // Close if  

     if($tag == 0) { 

      echo "\r\n<td width='21' valign='top'> 
      <a href='reservation.php?month=" . $this->month . "&amp;year=" . $this->year . "&amp;first_name=" . $_GET['first_name'] . "&amp;email=" . $_GET['email'] . "&amp;last_name=" . $_GET['last_name'] . "&amp;rsvnumb=" . $_GET['rsvnumb'] . "&amp;telephone=" . $_GET['telephone'] . "&amp;pon=" . $_GET['pon'] . "&amp;user_id=" . $_GET['user_id'] . "&amp;uid=" . $_GET['uid'] . "&amp;page_id=" . $_GET['page_id'] . "&amp;day=" . sprintf("%02s", $r['daynumber']) . "' class='green' title='Please click to view bookings'>" . 
      $r['daynumber'] . "</a></td>";    
     } 

     // The modulus function below ($j % 7 == 0) adds a <tr> tag to every seventh cell + 1; 
      if($j % 7 == 0 && $i >1) { 
      echo "\r\n</tr>\r\n<tr>"; // Use modulus to give us a <tr> after every seven <td> cells 
     }    
    }  

    echo "</tr></table></div><!-- Close outer_calendar DIV -->"; 

    if(isset($_GET['year'])) 
    $this->basket(); 

    echo "</div><!-- Close LHS DIV -->"; 

    // Check booked slots for selected date and only show the booking form if there are available slots 
    $current_day = $this->year . '-' . $this->month . '-' . $this->day; 
    $slots_selected_day = 0; 

    if(isset($this->bookings_per_day[$current_day])) 
    $slots_selected_day = count($this->bookings_per_day[$current_day]); 

    if($this->day != 0 && $slots_selected_day < $this->slots_per_day) { 
     $this->booking_form(); 
    }  
} // Close function 

有人對此腳本有任何想法,我該如何更改月份的語言(希臘語)?

回答

0

謝謝您的回答。我試過setlocale(LC_TIME,'el_GR.UTF-8');但沒有發生。我試過setlocale(LC_ALL,'希臘');但是希臘語是???????當我將頁面編碼到windows-1253時,我可以在希臘語中看到月份,但這不是一個解決方案。我能做什麼?

編輯: 我找到了解決辦法

$date_encoded = strftime('%B %Y', $this->selected_date); 
$date_encoded = iconv('Windows-1253', 'UTF-8//IGNORE', $date_encoded); 
0

date()函數只能使用英文輸出。您必須改用strftime(),而使用setlocale()設置區域設置。這將以設置的語言環境的語言輸出,在這種情況下 - 希臘語。

兩者有不同的格式,但並不完全不同。下面給出一個簡單的例子。

setlocale(LC_TIME, 'el_GR.UTF-8');    // Set the locale to greek 

echo strftime("%A", $d);      // Outputs weekname, Monday through Sunday 
echo strftime("%m", $this->back)    // Outputs month, numerically, e.g. "10" 
echo strftime("%B, %Y", $this->selected_date); // Outputs e.g "October, 2016" 

// These comments, about the formats, are in English, 
// because I don't know the Greek translation 
// It will be in Greek should the locale be installed and properly set 

更改date()功能strftime(),而不是(用新的參數,在documentation找到),你應該不錯!

如果上述不起作用,這是因爲該語言環境(el_GR,希臘語)尚未安裝在您的服務器上。

參考

0

如何,我們可以使用庫MySQLi分貝更改默認時間爲動態

//時間相關的變量

公共$ booking_start_time =「 09:00" ; // 24小時第一個時間段的時間H:M格式
public $ booking_end_time =「21:00」; // 24小時最後一個插槽的時間H:M格式