$v) { if (is_array($v)) { strip_slashes_from_user_data($array[$k]); continue; } $array[$k] = stripslashes($v); } } if (get_magic_quotes_gpc()) { strip_slashes_from_user_data($_GET); strip_slashes_from_user_data($_POST); strip_slashes_from_user_data($_COOKIE); } function redirect($path='') { $url = 'http' . (!empty($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . $path; header('Location: '.$url); exit; } class Wikazzle { protected $datas = array(); private $needSave = false; public function __construct() { if (file_exists(STORAGE_FILE)) { $this->datas = unserialize(file_get_contents(STORAGE_FILE)); } @session_start(); } public function __destruct() { if ($this->needSave) { $datas = serialize($this->datas); file_put_contents(STORAGE_FILE, $datas); } } private function needSave() { $this->needSave = true; } public function getOccupationForDay($day) { if (isset($this->datas[$day])) { return $this->datas[$day]; } return false; } public function freeOccupationForDay($day) { unset($this->datas[$day]); $this->needSave(); } public function setOccupationForDay($day, $people, $notes='') { $this->datas[$day] = array('people' => $people, 'notes' => $notes); $this->needSave(); } public function authLogin($login, $password) { if ($password != PASSWORD) { return false; } $_SESSION['auth'] = $login; return true; } public function authLogout() { $_SESSION = array(); } public function authCheck() { if (!empty($_SESSION['auth'])) return $_SESSION['auth']; return false; } } class Render { private $wk = false; private $months = array(1 => "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"); private $days = array(1 => "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"); private $colors = array("ffdbfc", "eedbff", "e2dbff", "dbffe4", "dbe9ff", "dbfcff", "e9ffb3", "eeffdb", "fdffdb", "ffd085", "b5ffa7", "e3d4ae", "ffdbdb", "fff1db"); public function __construct($wk) { $this->wk =& $wk; } private function getColor($string) { $string = strtolower($string); while ($string[$n]) { $txt_sum += ord($string[$n++]); } $txt_sum %= count($this->colors); return $this->colors[$txt_sum]; } private function head() { echo ' '.TITLE.'

'.TITLE.'

'; if ($this->wk->authCheck()) { echo '

Connecté en tant que '.$this->escape($this->wk->authCheck()).'.

Déconnexion

'; } else { echo '

Vous n\'êtes pas connecté. '; if (ACCESS_LIMIT == 'write') echo 'Vous devez vous connecter pour modifier le calendrier.'; else if (ACCESS_LIMIT == 'none') echo 'Vous pouvez vous connecter pour faciliter les modifications du calendrier.'; echo '

Connexion

'; } } private function foot() { echo ' '; } private function escape($str) { return htmlspecialchars($str); } public function login($msg='') { $this->head(); if (!empty($msg)) { echo '

'.$this->escape($msg).'

'; } echo '
Connexion

'; $this->foot(); } public function calendar() { $this->head(); if (!empty($_GET['y'])) $year = (int) $_GET['y']; else $year = date('Y'); if (!empty($_GET['m'])) $month = (int) $_GET['m']; else $month = date('m'); $month = sprintf("%02d", $month); $year = sprintf("%04d", $year); $ts_first = mktime(0, 0, 0, $month, 1, $year); $today = date('Ymd'); list($month, $year, $weekday) = explode(',', strftime('%m,%Y,%w', $ts_first)); $weekday = ($weekday + 7 - 1) % 7; #adjust for $first_day $days_in_month = date('t', $ts_first); if ($month == 12) $next = '?y=' . ($year+1) . '&m=01'; else $next = '?y=' . $year . '&m=' . ($month+1); if ($month == 1) $prev = '?y=' . ($year-1) . '&m=12'; else $prev = '?y=' . $year . '&m=' . ($month-1); echo ' '; for ($i=1; $i<=7; $i++) { echo ''; } echo ' '; for ($i=1; $i <= $weekday; $i++) { echo ' '; } for ($day=1; $day <= $days_in_month; $day++, $weekday++) { $day = sprintf("%02d", $day); $id = $year.$month.$day; if ($weekday == 7) { $weekday = 0; echo ' '; } $class = ''; if ($weekday == 6) $class .= 'lastday'; if ($id == $today) $class .= ' today'; if ($d = $this->wk->getOccupationForDay($id)) { echo ' '; } else { echo ' '; } } for ($i=$weekday; $i <= 7; $i++) { echo ' '; } echo '
'.$this->months[(int)$month].' '.$year.'
'.$this->days[$i].'

'.(int)$day.'

'.$this->escape($d['people']).'

'; if (!empty($d['notes'])) echo '

'.nl2br($this->escape($d['notes'])).'

'; if ($this->wk->authCheck()) echo '

Modifier | Libérer

'; echo '

'.(int)$day.'

Libre

'; if ($this->wk->authCheck()) echo '

Occuper

'; echo '
'; $this->foot(); } public function setOccupation($day) { $this->head(); if ($occ = $this->wk->getOccupationForDay($day)) { $people = $occ['people']; $notes = $occ['notes']; echo '

Attention ce jour est déjà occupé.

'; } else { $people = $this->wk->authCheck(); $notes = ''; } $jour = substr($day, -2) . '/' . substr($day, 4, 2) . '/' . substr($day, 0, 4); echo '
Occuper le '.$jour.'
(obligatoire)

'; $this->foot(); } } $wk = new Wikazzle; $render = new Render(&$wk); $error = ''; if ($wk->authCheck() || ACCESS_LIMIT == 'none') { if (!empty($_POST['setOccupation'])) { if (empty($_POST['people']) || empty($_POST['day'])) $error = 'EMPTY'; else { if (empty($_POST['notes'])) $_POST['notes'] = ''; $wk->setOccupationForDay($_POST['day'], $_POST['people'], $_POST['notes']); $error = 'OK'; } redirect(); } else if (!empty($_POST['free'])) { $wk->freeOccupationForDay($_POST['free']); redirect(); } } else { if (!empty($_POST['login']) && !empty($_POST['password'])) { if (!$wk->authLogin($_POST['login'], $_POST['password'])) { $error = 'MISMATCH'; } else { redirect('?success'); } } } if ((!$wk->authCheck() && ACCESS_LIMIT == 'read') || isset($_REQUEST['login'])) { if (empty($error) && ACCESS_LIMIT == 'read') $msg = 'Vous avez besoin de vous connecter pour accéder à cette page.'; if ($error == 'MISMATCH') $msg = 'Mauvais mot de passe.'; $render->login($msg); } elseif ($wk->authCheck() && isset($_GET['setOccupation'])) { $render->setOccupation($_GET['setOccupation']); } elseif (isset($_GET['logout'])) { $wk->authLogout(); redirect(); } else { $render->calendar(); } ?>