From f76712a9ae823b60301af7fa7da9c2ef05fee855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Schneider?= Date: Sun, 11 Mar 2012 01:24:51 +0100 Subject: [PATCH] Added script addcalendar.php --- .../Baikal_0.1/Scripts/addcalendar.php | 86 +++++++++++++++++++ .../Baikal_0.1/Scripts/modcalendar.php | 68 +++++++++++++++ 2 files changed, 154 insertions(+) create mode 100755 CoreVersions/Baikal_0.1/Scripts/addcalendar.php create mode 100755 CoreVersions/Baikal_0.1/Scripts/modcalendar.php diff --git a/CoreVersions/Baikal_0.1/Scripts/addcalendar.php b/CoreVersions/Baikal_0.1/Scripts/addcalendar.php new file mode 100755 index 0000000..172997c --- /dev/null +++ b/CoreVersions/Baikal_0.1/Scripts/addcalendar.php @@ -0,0 +1,86 @@ +#!/usr/bin/env php + +* All rights reserved +* +* http://baikal.codr.fr +* +* This script is part of the Baïkal Server project. The Baïkal +* Server project is free software; you can redistribute it +* and/or modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +define("BAIKAL_CONTEXT", TRUE); +define("BAIKAL_CONTEXT_CLI", TRUE); + +require_once("../Bootstrap.php"); +require_once("./inc/functions.php"); + +$sUsername = @trim($argv[1]); + +if($sUsername === "") { + die("You have to provide a username; aborting.\n"); +} + +$stmt = $pdo->prepare("SELECT * FROM users WHERE username=?"); +$stmt->bindParam(1, $sUsername); +$stmt->execute(); +if(($user = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) { + die("User not found; aborting.\n"); +} + +$sCalendarID = prompt("Calendar Key (a unique, lower-case, alphanum token, like perso or sailing): "); +if($sCalendarID === "") { + die("Calendar Key cannot be empty.\n"); +} + +$sCalendarID = strtolower($sCalendarID); + +if(!preg_match("/[a-zA-Z0-9]+/", $sCalendarID)) { + die("Calendar Key should contain only letters and numbers.\n"); +} + +# Fetching calendar +$sPrincipalUri = 'principals/' . $sUsername; +$stmt = $pdo->prepare("SELECT * FROM calendars where LOWER(principaluri)=LOWER(?) AND LOWER(uri)=LOWER(?)"); +$stmt->bindParam(1, $sPrincipalUri); +$stmt->bindParam(2, $sCalendarID); +$stmt->execute(); +if(($cal = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) !== FALSE) { + die("This Calendar Key is already in use for this user; aborting.\n"); +} + +$sCalendarName = prompt("Calendar Display Name: "); +if($sCalendarName === "") { + die("Calendar Display Name cannot be empty.\n"); +} + +try { + + $stmt = $pdo->prepare("INSERT INTO calendars (principaluri, displayname, uri, description, components, ctag) VALUES (?,?,?,'','VEVENT,VTODO','1')"); + $stmt->bindParam(1, $sPrincipalUri); + $stmt->bindParam(2, $sCalendarName); + $stmt->bindParam(3, $sCalendarID); + $stmt->execute(); + + echo "Calendar has been added.\n"; + exit(0); +} catch(PDOException $e) { + echo "Fatal error. Calendar has not been added. Details follow.\n"; + die($e->getMessage()); +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Scripts/modcalendar.php b/CoreVersions/Baikal_0.1/Scripts/modcalendar.php new file mode 100755 index 0000000..cb907aa --- /dev/null +++ b/CoreVersions/Baikal_0.1/Scripts/modcalendar.php @@ -0,0 +1,68 @@ +#!/usr/bin/env php + +* All rights reserved +* +* http://baikal.codr.fr +* +* This script is part of the Baïkal Server project. The Baïkal +* Server project is free software; you can redistribute it +* and/or modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +define("BAIKAL_CONTEXT", TRUE); +define("BAIKAL_CONTEXT_CLI", TRUE); + +require_once("../Bootstrap.php"); +require_once("./inc/functions.php"); + +$sUsername = @trim($argv[1]); + +if($sUsername === "") { + die("You have to provide a username; aborting.\n"); +} + +$stmt = $pdo->prepare("SELECT * FROM users WHERE username=?"); +$stmt->bindParam(1, $sUsername); +$stmt->execute(); +if(($user = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) { + die("User not found; aborting.\n"); +} + +$sCalendarID = prompt("Calendar Key: "); +if($sCalendarID === "") { + die("Calendar Key cannot be empty.\n"); +} + +$sCalendarID = strtolower($sCalendarID); + +if(!preg_match("/[a-zA-Z0-9]+/", $sCalendarID)) { + die("Calendar Key should contain only letters and numbers.\n"); +} + +# Fetching calendar +$sPrincipalUri = 'principals/' . $sUsername; +$stmt = $pdo->prepare("SELECT * FROM calendars where LOWER(principaluri)=LOWER(?) AND LOWER(uri)=LOWER(?)"); +$stmt->bindParam(1, $sPrincipalUri); +$stmt->bindParam(2, $sCalendarID); +$stmt->execute(); +if(($cal = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) { + die("This Calendar Key is not found for this user; aborting.\n"); +} + +echo "Found calendar '" . $sCalendarID . "' for user '" . $sUsername . "':\n"; \ No newline at end of file