LINE 123?
<?php
function connect_to_db() {
global $config;
global $db_connection;
if (!isset($db_connection)) {
$db_connection = mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']) or die("Impossible to open a connection to the database.".mysql_error());
if(function_exists('mysql_set_charset')) {
mysql_set_charset('utf8');
}
mysql_query('SET NAMES "UTF8"');
mysql_select_db($config['db_name']) or die("Impossible to open the given database : ". $config['db_name']);
}
}
function stripslashes_r($value) {
$value = is_array($value) ?
array_map('stripslashes_r', $value) :
stripslashes($value);
return $value;
}
function addslashes_r($value) {
$value = is_array($value) ?
array_map('addslashes_r', $value) :
addslashes($value);
return $value;
}
function magicaddslashes($t) {
return (get_magic_quotes_gpc()==1) ? $t : addslashes($t);
}
function escaporize($thing, $quotes = ENT_QUOTES, $charset = 'UTF-8') {
if (is_array($thing)) {
$escaped = array();
foreach ($thing as $key => $value) {
$escaped[$key] = escaporize($value, $quotes, $charset);
}
return $escaped;
} else {
return htmlspecialchars($thing, $quotes, $charset);
}
}
function mysql_fetch_all($sql) {
$res = mysql_query($sql);
if ($res) {
$num = mysql_num_rows($res);
$arr = array();
for($i=0; $i<$num; $i++) {
$arr[] = mysql_fetch_assoc($res);
}
return $arr;
}
return false;
}
function mysql_fetch_one($sql) {
$res = mysql_query($sql);
if ($res) {
return mysql_fetch_assoc($res);
}
return false;
}
function trace_start_file() {
echo "";
}
function trace_end_file() {
echo "";
}
function update_row_in_db($table_name, $data) {
$data = addslashes_r($data);
// Build the query.
$q = "UPDATE $table_name SET ";
foreach ($data as $key => $value) {
if ($key != 'id' && $key != 'image_file') {
$q .= "`$key` = '$value',";
}
}
$q = rtrim($q, ','); // trimming trailing comma.
$q .= " WHERE id = {$data['id']}";
return mysql_query($q) or die(mysql_error().$q);
}
function insert_row_in_db($table_name, $data) {
$data = addslashes_r($data);
// Build the query.
$q = "INSERT INTO $table_name (";
foreach ($data as $key => $value) {
if ($key != 'id' && $key != 'image_file') {
$q .= "`$key`,";
}
}
$q = rtrim($q, ','); // trimming trailing comma.
$q .= ") VALUES (";
foreach ($data as $key => $value) {
if ($key != 'id' && $key != 'image_file') {
$q .= "'$value',";
}
}
$q = rtrim($q, ',');
$q .= ")";
return mysql_query($q) or die(mysql_error().$q);
}
function resize_image($source, $dest, $max_width=60, $max_height=60) {
$source_quality = 80;
$src_img = ImageCreateFromJpeg($source);
$orig_x = ImageSX($src_img);
$orig_y = ImageSY($src_img);
$new_y = $max_height;
$new_x = $orig_x / ($orig_y / $max_height);
if ($new_x > $max_width) {
$new_x = $max_width;
$new_y = $orig_y / ($orig_x / $max_width);
}
$dst_img = ImageCreateTrueColor($new_x,$new_y);
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x, $orig_y);
$result = ImageJpeg($dst_img, $dest, $source_quality);
ImageDestroy($src_img);
ImageDestroy($dst_img);
return $result;
}
function resize_and_crop($source_file, $dest_file, $dest_side = 149) {
// Resize and crop an image to a square image that is *filled* with
// the source image.
require_once 'Image/Transform.php';
$im = Image_Transform::factory('GD');
$im->load($source_file);
if ($im->getImageWidth() > $im->getImageHeight()) {
// L'image d'origine est horizontale.
$im->scaleByY($dest_side ); // scale proportionally the image so the height = 190.
$im->crop($dest_side , $dest_side , ($im->new_x - $dest_side ) / 2, 0);
} else {
// L'image d'origine est verticale.
$im->scaleByX($dest_side ); // scale proportionally the image so the width = 190.
$im->crop($dest_side , $dest_side , 0, ($im->new_y - $dest_side ) / 2);
}
$im->save($dest_file);
$im->free();
return true;
}
# PHP Calendar (version 2.3), written by Keith Devens
# http://keithdevens.com/software/php_calendar
# see example at http://keithdevens.com/weblog
# License: http://keithdevens.com/software/license
function generate_calendar($cottage, $year, $month, $pn = array(), $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0){
$not_before = "$year-".str_pad($month, 2, "0", STR_PAD_LEFT)."-01";
$not_after = "$year-".str_pad($month, 2, "0", STR_PAD_LEFT)."-31";
$req = "SELECT * FROM reservations WHERE cottage = '$cottage' AND ((ends_on >= '$not_before' AND ends_on <= '$not_after') OR (starts_on >= '$not_before' AND starts_on <= '$not_after')) ORDER BY starts_on ASC";
$r = stripslashes_r(mysql_fetch_all($req));
$all_occupied_days = array();
foreach ($r as $resa) {
$start = (int) date('Ymd', strtotime($resa['starts_on']));
$end = (int) date('Ymd', strtotime($resa['ends_on']));
//echo $start;
for($j=$start; $j<=$end; $j++) {
//echo "j = $j\n";
$all_occupied_days[] = $j;
}
}
$all_occupied_days = array_unique($all_occupied_days);
#array(substr($j, 0, 4), substr($j, 4, 2), substr($j, 6, 2));
for($i=1; $i<=31; $i++) {
foreach($all_occupied_days as $o) {
if ($year == substr($o, 0, 4) && $month == substr($o, 4, 2) && $i == substr($o, 6, 2)) {
$relevant_occupied_days[] = $i;
}
}
}
#print_r($relevant_occupied_days);
$days = array();
if (is_array($relevant_occupied_days)) {
foreach($relevant_occupied_days as $v) {
$days[$v] = array(NULL, 'occupied');
}
}
$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()
$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
#Begin calendar. Uses a real . See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '
'.($pl ? ''.$p.'' : $p).' ';
if($n) $n = '
'.($nl ? ''.$n.'' : $n).'';
$calendar = '
'."\n".
''.$p.($month_href ? ''.$title.'' : $title).$n."\n";
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= ''.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).' | ';
$calendar .= "
\n";
}
if($weekday > 0) $calendar .= ' | '; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday = 0; #start a new week
$calendar .= "
\n";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content)) $content = $day;
$calendar .= '' : '>').
($link ? ''.$content.'' : $content).'';
}
else $calendar .= "$day | ";
}
if($weekday != 7) $calendar .= ' | '; #remaining "empty" days
return $calendar."
\n
\n";
}
// A date input widget.
// Input format : YYYY-MM-DD
function date_input($name, $date=0) {
// day - month - year
setlocale(LC_TIME, "en_US");
if ($date == 0) {
$date = date('Y-m-d');
}
$cur_year = (int) substr($date, 0, 4);
//$start_year = $cur_year - 5;
$start_year = date('Y');
$end_year = $cur_year + 2;
for ($i = $start_year; $i <= $end_year; $i++) {
$sel = $i == $cur_year ? 'selected' : '';
$year_options .= "${i}\n";
}
$cur_month = (int) substr($date, 5, 2);
$months = array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december');
for ($i=1; $i <= 12; $i++) {
$padded_month = str_pad($i, 2, '0', STR_PAD_LEFT);
$sel = $padded_month == $cur_month ? 'selected' : '';
$month_options .= "{$months[$i-1]}\n";
}
$cur_day = (int) substr($date, 8, 2);
for ($i=1; $i <= 31; $i++) {
$padded_day = str_pad($i, 2, '0', STR_PAD_LEFT);
$sel = $padded_day == $cur_day ? 'selected' : '';
$day_options .= "${i}\n";
}
$out = "${day_options}
${month_options}
${year_options}";
return $out;
}
// Concatenate the date that was submited using the date_input() widget.
function get_inputed_date($name) {
$day = $_REQUEST["${name}_d"];
$month = $_REQUEST["${name}_m"];
$year = $_REQUEST["${name}_y"];
return magicaddslashes("$year-$month-$day");
}
?>