コード例 #1
0
ファイル: article.php プロジェクト: doubotis/PHP-Blog
 public static function fromID($id)
 {
     $sql = "SELECT *, COALESCE(release_date, created_date) AS \"date\" FROM articles WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     if ($res == false) {
         throw new Exception("Impossible de trouver cet article", 404);
     }
     $instance = new Article($res["id"], $res["title"], $res["summary"], $res["content"], null, null);
     $instance->_author = User::fromID($res["author_id"]);
     $instance->_categories = array();
     $instance->_date = $res["date"];
     $instance->_published = $res["published"];
     $instance->_last_modified_date = $res["last_modified_date"];
     $instance->_comment_fb_url = DOMAIN_NAME . WEBAPP_WEBSITE_URL . "news/" . $instance->_id;
     $instance->_comments = $instance->queryCommentsCount();
     // Get the count of articles.
     $sql = "SELECT * FROM categories INNER JOIN articles_categories ON (articles_categories.category_id = categories.id) WHERE article_id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     while ($row = $sth->fetch()) {
         array_push($instance->_categories, $row);
     }
     return $instance;
 }
コード例 #2
0
ファイル: news-list.php プロジェクト: doubotis/PHP-Blog
 function build($tpl)
 {
     $page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
     $categ = isset($_REQUEST["category"]) ? $_REQUEST["category"] : "developer|gaming";
     $categories = explode("|", $categ);
     $conditions = "";
     if (count($categories) > 0) {
         $conditions = $conditions . " WHERE (";
         for ($i = 0; $i < count($categories); $i++) {
             $conditions = $conditions . "categories.label LIKE ?";
             if ($i < count($categories) - 1) {
                 $conditions = $conditions . " OR ";
             }
         }
         $conditions = $conditions . ")";
     }
     if (isset($_REQUEST["author"])) {
         if ($conditions != "") {
             $conditions = $conditions . " AND username LIKE ?";
         } else {
             $conditions = $conditions . " WHERE username LIKE ?";
         }
     }
     $conditions = $conditions . " GROUP BY published_articles.id ORDER BY published_articles.published_date DESC";
     if (isset($_REQUEST["author"])) {
         array_push($categories, $_REQUEST["author"]);
     }
     // Query the count of elements.
     $sqlCount = "SELECT COUNT(published_articles.id) AS count FROM published_articles " . "INNER JOIN articles_categories ON (published_articles.id" . " = articles_categories.article_id) INNER JOIN categories " . "ON (categories.id = articles_categories.category_id) INNER" . " JOIN users ON (users.id = published_articles.author_id)" . $conditions;
     $sthCount = DatabaseHelper::getInstance()->prepare($sqlCount);
     $sthCount->execute($categories);
     $resCount = $sthCount->fetch(PDO::FETCH_ASSOC);
     $countArticles = $resCount["count"];
     // Compute the number of articles.
     $pageCount = intval($countArticles / 5);
     // Now query the IDs for the current page only.
     $offset = intval(($page - 1) * 5);
     $sql = "SELECT published_articles.id AS id FROM published_articles " . "INNER JOIN articles_categories ON (published_articles.id" . " = articles_categories.article_id) INNER JOIN categories " . "ON (categories.id = articles_categories.category_id) INNER" . " JOIN users ON (users.id = published_articles.author_id)" . $conditions . " LIMIT 5 OFFSET {$offset}";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute($categories);
     $articles = array();
     while ($row = $sth->fetch()) {
         $articleID = $row["id"];
         $articleObj = Article::fromID($articleID);
         $data = $articleObj->getProperties();
         if ($data["published"] == 0) {
             continue;
         }
         array_push($articles, $data);
     }
     $pageLink = isset($_REQUEST["category"]) ? "?category=" . $_REQUEST["category"] . "&" : "?";
     $tpl->assign("articles", $articles);
     $tpl->assign("pageLink", $pageLink);
     $tpl->assign("pageCount", $pageCount);
     $tpl->assign("pageIndex", $page);
     $tpl->display('news-list.tpl');
 }
コード例 #3
0
ファイル: sitemap.php プロジェクト: doubotis/PHP-Blog
 function __construct()
 {
     $sql = "SELECT *, COALESCE(release_date, created_date) AS \"date\" FROM published_articles";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $this->_articles = array();
     while ($row = $sth->fetch()) {
         array_push($this->_articles, $row);
     }
 }
コード例 #4
0
 function build($tpl)
 {
     $sql = "SELECT * FROM articles";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $articles = array();
     while ($row = $sth->fetch()) {
         array_push($articles, $row);
     }
     $tpl->assign("articles", $articles);
 }
コード例 #5
0
 function prepareDataForLeftPanel()
 {
     $sql = "SELECT * FROM published_articles ORDER BY published_date DESC LIMIT 5";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $lastArticles = array();
     while ($row = $sth->fetch()) {
         $row["title"] = strlen($row["title"]) > 40 ? substr($row["title"], 0, 40) . "..." : $row["title"];
         array_push($lastArticles, $row);
     }
     $this->_lastArticles = $lastArticles;
 }
コード例 #6
0
 function authenticate($params)
 {
     assert(isset($params['user']) && isset($params['pass']));
     $contactId = $params['user'];
     $token = $params['pass'];
     $contact = DatabaseHelper::getInstance()->getContactByIdentifier($contactId, $identifier);
     if ($contact) {
         info(__METHOD__ . ': Contact ' . $contact['Id'] . ' succesfully authenticated');
         return array('Id' => $contact['Id'], 'Role' => $contact['Role']);
     } else {
         warn(__METHOD__ . ': Authentication failed for contact "' . $contactId . '" and token "' . $identifier . '"');
         return false;
     }
 }
コード例 #7
0
 function testSuccessLogonNewUser()
 {
     TestUtils::clearDatabase();
     $id = DatabaseHelper::getInstance()->addContact('user2', '', '*****@*****.**', ROLE_IDENTIFIED, Utils::hashPassword('---longpassword123---'));
     // First let's fail
     $params1 = array('email' => '*****@*****.**', 'password' => '---longpassword12---');
     $this->assertFalse($this->helper->authenticate($params1));
     // This should work
     $params2 = array('email' => '*****@*****.**', 'password' => '---longpassword123---');
     $contact = $this->helper->authenticate($params2);
     $this->assertTrue($contact !== false);
     $this->assertEquals($id, $contact['Id']);
     $this->assertEquals(ROLE_IDENTIFIED, $contact['Role']);
 }
コード例 #8
0
ファイル: testenv.php プロジェクト: atrakroo/carpool-1
 static function createSimpleRide($from, $to, $status, $notify = 1, $region = 1)
 {
     $db = DatabaseHelper::getInstance();
     $testContact = $db->addContact('test' . self::$ridesCounter, '1234', 'test' . self::$ridesCounter . '@test.com', ROLE_IDENTIFIED_REGISTERED);
     if (!$testContact) {
         return false;
     }
     $testRide = $db->addRide($from, 'city_' . $from, $to, 'city_' . $to, TIME_IRRELEVANT, TIME_IRRELEVANT, $testContact, '', $status, $notify, $region);
     if (!$testRide) {
         return false;
     }
     ++self::$ridesCounter;
     return $testRide;
 }
コード例 #9
0
ファイル: users-list.php プロジェクト: doubotis/PHP-Blog
 function build($tpl)
 {
     $sql = "SELECT a.id, (SELECT COUNT(*) FROM published_articles WHERE author_id = a.id) AS articles_count FROM users a";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $users = array();
     while ($row = $sth->fetch()) {
         $user = User::fromID($row["id"]);
         $data = $user->getProperties();
         $data["icon"] = WEBAPP_WEBSITE_URL . "upload/bc6cea68f3a413d20d17202cb67b03d2.jpg";
         $data["articles_count"] = $row["articles_count"];
         array_push($users, $data);
     }
     $tpl->assign("users", $users);
     $tpl->display('users-list.tpl');
 }
コード例 #10
0
 function build($tpl)
 {
     $articleID = $_GET["id"];
     $sql = "SELECT * FROM articles WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $articleID);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $res["release_date"] = $res["release_date"] == NULL ? NULL : date("Y-m-d\\TH:i", strtotime($res["release_date"]));
     $sql = "SELECT *, (SELECT COUNT(*) FROM articles_categories AS b WHERE b.category_id = a.id AND b.article_id = ?) AS checked FROM categories a";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $articleID);
     $sth->execute();
     $categories = $sth->fetchAll();
     $tpl->assign("categories", $categories);
     $tpl->assign("article", $res);
 }
コード例 #11
0
 function testFindRidesToNotify()
 {
     TestUtils::clearDatabase();
     $ride1 = TestUtils::createSimpleRide(1, 2, STATUS_LOOKING, 1);
     $ride2 = TestUtils::createSimpleRide(3, 4, STATUS_LOOKING, 0);
     $ride3 = TestUtils::createSimpleRide(1, 2, STATUS_OFFERED, 1);
     $ride4 = TestUtils::createSimpleRide(3, 4, STATUS_OFFERED, 0);
     $ride5 = TestUtils::createSimpleRide(5, 6, STATUS_LOOKING, 0);
     DatabaseHelper::getInstance()->updateRideActive($ride5, RIDE_INACTIVE);
     $ride6 = TestUtils::createSimpleRide(5, 6, STATUS_SHARING, 1);
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_LOOKING, 1);
     $this->assertRidesContainIds($toNotify, array($ride1));
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_OFFERED, 1);
     $this->assertRidesContainIds($toNotify, array($ride3));
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_SHARING, 1);
     $this->assertRidesContainIds($toNotify, array($ride6));
 }
コード例 #12
0
ファイル: users-view.php プロジェクト: doubotis/PHP-Blog
 function build($tpl)
 {
     $sql = "SELECT id FROM users WHERE username LIKE ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $_GET["name"]);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $user = User::fromID($res["id"]);
     $arr = $user->getProperties();
     // Query the number of articles.
     $sql = "SELECT COUNT(*) AS count FROM published_articles INNER JOIN users ON (published_articles.author_id = users.id) WHERE published = 1";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $arr["articles_count"] = $res["count"];
     $tpl->assign("userInfo", $arr);
     $tpl->display('users-view.tpl');
 }
コード例 #13
0
 public static function run($contactId)
 {
     $db = DatabaseHelper::getInstance();
     try {
         $db->beginTransaction();
         if (!$db->deleteRideByContact($contactId)) {
             throw new Exception("Could not delete rides for contact {$contact}`Id");
         }
         if (!$db->deleteContact($contactId)) {
             throw new Exception("Could not delete contact {$contactId}");
         }
         $db->commit();
         AuthHandler::logout();
     } catch (Exception $e) {
         logException($e);
         $db->rollBack();
         throw $e;
     }
 }
コード例 #14
0
 function authenticate($params)
 {
     assert('isset($params["user"]) && isset($params["password"])');
     $con = false;
     if (($domain = getConfiguration('auth.ldap.domain')) !== false) {
         $port = (int) getConfiguration('auth.ldap.port', self::LDAP_DEFAULT_PORT);
         $con = ldap_connect($domain, $port);
     }
     if ($con === false) {
         throw new Exception(__METHOD__ . ": Failed to connect to {$domain} in port {$port}");
     }
     $authUser = $user = $this->ldap_escape($params['user']);
     $pass = $this->ldap_escape($params['password']);
     $ldapDomainName = getConfiguration('auth.ldap.domain.name');
     if ($ldapDomainName) {
         $authUser = $ldapDomainName . '\\' . $authUser;
     }
     debug(__METHOD__ . ": Trying to authenticate {$authUser} against {$domain}");
     if (ldap_bind($con, $authUser, $pass)) {
         // We're assuming that the email used is as the user name
         $email = $email = Utils::buildEmail($user);
         // Close the connection - we don't need it any more
         ldap_unbind($con);
         // Fetch contact
         $contact = DatabaseHelper::getInstance()->getContactByEmail($email);
         if ($contact !== false) {
             return array('Id' => $contact['Id'], 'Role' => $contact['Role']);
         } else {
             // Contact is not in the database - we better create it
             // TODO: Put the option to read data
             return array('Id' => DatabaseHelper::getInstance()->addContact('', '', $email, ROLE_IDENTIFIED), 'Role' => ROLE_IDENTIFIED);
         }
     } else {
         $errCode = ldap_errno($con);
         if ($errCode == self::LDAP_INAPPROPRIATE_AUTH || $errCode == self::LDAP_INVALID_CREDENTIALS) {
             // Invalid credentials - simply fail
             return false;
         }
         // Internal error
         throw new Exception(__METHOD__ . " : LDAP error: " . ldap_err2str($errCode));
     }
 }
コード例 #15
0
 function authenticate($params)
 {
     assert('isset($params["email"]) && isset($params["password"])');
     // TODO: A primitive brute-force defense?
     // We must call buildEmail as we may have explicitely added the
     // domain suffix during registration
     $email = Utils::buildEmail($params['email']);
     $pass = $params['password'];
     // Created a hashed hexadecimal string, use the salt if possible
     $hashed = Utils::hashPassword($pass);
     $contact = DatabaseHelper::getInstance()->getContactByEmail($email);
     if ($contact !== false) {
         if ($contact['Identifier'] === $hashed) {
             info(__METHOD__ . ': Contact ' . $contact['Id'] . ' succesfully authenticated');
             return array('Id' => $contact['Id'], 'Role' => $contact['Role']);
         } else {
             warn(__METHOD__ . ': Contact ' . $contact['Id'] . ' failed to authorize: wrong password');
         }
     }
     return false;
 }
コード例 #16
0
ファイル: RegionManager.php プロジェクト: atrakroo/carpool-1
 public function initInternal()
 {
     $this->_regions = DatabaseHelper::getInstance()->getRegions();
     if (isset($_GET['regionSelector']) && array_key_exists($_GET['regionSelector'], $this->_regions)) {
         $this->_currentRegion = $this->_regions[$_GET['regionSelector']];
         // Set the cookie for 14 days
         if (!setcookie('region', $_GET['regionSelector'], time() + TWO_WEEKS, getConfiguration('public.path') . '/')) {
             warn(__METHOD__ . ': Could not set cookie for user! Output already exists.');
         }
         unset($_GET['region']);
     } else {
         if (isset($_COOKIE['region']) && array_key_exists($_COOKIE['region'], $this->_regions)) {
             $this->_currentRegion = $this->_regions[$_COOKIE['region']];
             // Update cookie expiry time
             setcookie('region', $_COOKIE['region'], time() + TWO_WEEKS, getConfiguration('public.path') . '/');
         } else {
             $this->_currentRegion = $this->_regions[self::getDefaultRegion()];
         }
     }
     info(__METHOD__ . ' region selected: ' . $this->_currentRegion['Id'] . ' (' . $this->_currentRegion['Name'] . ')');
 }
コード例 #17
0
ファイル: LocaleManager.php プロジェクト: atrakroo/carpool-1
 private function initInternal()
 {
     $this->locales = DatabaseHelper::getInstance()->getLocales();
     if (isset($_GET['lang']) && array_key_exists($_GET['lang'], $this->locales)) {
         $this->locale = $this->locales[$_GET['lang']];
         // Set the cookie for 14 days
         if (!setcookie('lang', $_GET['lang'], time() + TWO_WEEKS, getConfiguration('public.path') . '/')) {
             warn(__METHOD__ . ': Could not set cookie for user! Output already exists.');
         }
         unset($_GET['lang']);
     } else {
         if (isset($_COOKIE['lang']) && array_key_exists($_COOKIE['lang'], $this->locales)) {
             $this->locale = $this->locales[$_COOKIE['lang']];
             // Update cookie expiry time
             setcookie('lang', $_COOKIE['lang'], time() + TWO_WEEKS, getConfiguration('public.path') . '/');
         } else {
             $this->locale = $this->locales[self::getDefaultLocale()];
         }
     }
     info(__METHOD__ . ' locale selected: ' . $this->locale['Name'] . ' (' . $this->locale['Locale'] . ')');
     setlocale(LC_ALL, $this->locale['Locale']);
     putenv('LC_ALL=' . $this->locale['Locale']);
 }
コード例 #18
0
ファイル: user.php プロジェクト: doubotis/PHP-Blog
 public static function fromID($id)
 {
     $sql = "SELECT * FROM users WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $instance = new User($res["id"], $res["username"], $res["content"], null);
     $instance->_register_date = $res["register_date"];
     $instance->_last_logon_date = $res["last_logon_date"];
     $instance->_role = $res["roles"];
     $instance->_description = $res["description"];
     $instance->_permissions = array();
     $sql = "SELECT * FROM permissions INNER JOIN users_permissions ON (users_permissions.permission_id = permissions.id) WHERE user_id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetchAll();
     for ($i = 0; $i < count($res); $i++) {
         array_push($instance->_permissions, $res[$i]["label"]);
     }
     return $instance;
 }
コード例 #19
0
ファイル: help.php プロジェクト: atrakroo/carpool-1
<?php

include "env.php";
include APP_PATH . "/Bootstrap.php";
AuthHandler::putUserToken();
$content = DatabaseHelper::getInstance()->getQuestionsAnswersByLang(LocaleManager::getInstance()->getSelectedLanaguageId());
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/reset-fonts.css">
<link rel="stylesheet" type="text/css" href="css/common.css">
<?php 
if (LocaleManager::getInstance()->isRtl()) {
    ?>
<link rel="stylesheet" type="text/css" href="css/common_rtl.css">
<?php 
}
?>
<title>Carpool</title>
</head>
<body>
<div id="bd">
<?php 
echo View_Navbar::buildNavbar();
echo View_Header::render(null);
?>
<div id="content">
<?php 
if ($content) {
コード例 #20
0
 public function setUp()
 {
     $this->dbh = DatabaseHelper::getInstance();
 }
コード例 #21
0
 function contactExists($id)
 {
     $db = DatabaseHelper::getInstance();
     return $db->getContactById($id) !== false;
 }
コード例 #22
0
<?php

include "../env.php";
include APP_PATH . "/Bootstrap.php";
if (ENV !== ENV_DEVELOPMENT && (!Utils::IsXhrRequest() || !AuthHandler::isSessionExisting())) {
    die;
}
extract($_GET, EXTR_SKIP);
if (!isset($regionId)) {
    die;
}
try {
    $regionConfiguration = RegionManager::getInstance()->getRegionConfiguration($regionId);
    $cities = DatabaseHelper::getInstance()->getCities($regionId);
    if ($regionConfiguration !== false) {
        $res = array('status' => 'ok', 'results' => array('regionConfiguration' => $regionConfiguration, 'cities' => $cities));
    } else {
        warn("Could not find configuration for region {$regionId}");
        $res = array('status' => 'err', 'msg' => _("Region not found"));
    }
} catch (Exception $e) {
    logException($e);
    $res = array('status' => 'err', 'msg' => _("Internal Error"));
}
echo json_encode($res);
コード例 #23
0
ファイル: index.php プロジェクト: atrakroo/carpool-1
<?php

include "env.php";
include APP_PATH . "/Bootstrap.php";
$db = DatabaseHelper::getInstance();
AuthHandler::putUserToken();
$displayDest = getConfiguration('mode.single.dest', 0) == 0;
$currentRegion = RegionManager::getInstance()->getCurrentRegionId();
if ($displayDest) {
    $availableCities = $db->getAllAvailableCities($currentRegion);
} else {
    $availableCities = $db->getAvailableCities('Dest', $currentRegion);
}
$availableDestCities =& $availableCities;
$availableSrcCities =& $availableCities;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/reset-fonts.css">
<link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap_custom.min.css">
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<?php 
if (LocaleManager::getInstance()->isRtl()) {
    ?>
<link rel="stylesheet" type="text/css" href="css/common_rtl.css">
<?php 
}
?>
コード例 #24
0
ファイル: admin.php プロジェクト: doubotis/PHP-Blog
 function updateTags($withinTransaction, $categories, $articleID)
 {
     if (!$withinTransaction) {
         DatabaseHelper::getInstance()->beginTransaction();
     }
     for ($i = 0; $i < count($categories); $i++) {
         //print_r($categories[$i]);
         if ($categories[$i]["before"] == 0 && $categories[$i]["after"] == 1) {
             // We must insert the row.
             $sql = "INSERT INTO articles_categories (article_id, category_id) VALUES (?,?)";
             $sth = DatabaseHelper::getInstance()->prepare($sql);
             $sth->bindParam(1, $articleID);
             $sth->bindParam(2, $categories[$i]["id"]);
             $sth->execute();
         } else {
             if ($categories[$i]["before"] == 1 && $categories[$i]["after"] == 0) {
                 // We must delete the row.
                 $sql = "DELETE FROM articles_categories WHERE article_id = ? AND category_id = ?";
                 $sth = DatabaseHelper::getInstance()->prepare($sql);
                 $sth->bindParam(1, $articleID);
                 $sth->bindParam(2, $categories[$i]["id"]);
                 $sth->execute();
             }
         }
     }
     if (!$withinTransaction) {
         DatabaseHelper::getInstance()->commit();
     }
 }
コード例 #25
0
 public function testUpdate3()
 {
     TestUtils::clearDatabase();
     DatabaseHelper::getInstance()->insert('Contacts', array('Email' => '*****@*****.**', 'Phone' => '123', 'Name' => 'test1', 'Role' => ROLE_GUEST));
     $contact = DatabaseHelper::getInstance()->getContactByEmail('*****@*****.**');
     $this->assertTrue($contact !== false);
     $this->assertEquals('test1', $contact['Name']);
     $updatedData = array('Phone' => '987', 'Name' => null, 'Role' => ROLE_ADMINISTRATOR, 'Email' => null);
     DatabaseHelper::getInstance()->update('Contacts', $updatedData, 'id=?', array($contact['Id']), true);
     // Make sure only the relevant fields were changed
     $contact = DatabaseHelper::getInstance()->getContactByEmail('*****@*****.**');
     $this->assertTrue($contact !== false);
     $this->assertEquals('test1', $contact['Name']);
     $this->assertEquals('987', $contact['Phone']);
     $this->assertEquals(ROLE_ADMINISTRATOR, $contact['Role']);
 }
コード例 #26
0
ファイル: ActivateToggle.php プロジェクト: atrakroo/carpool-1
<?php

include "../env.php";
include APP_PATH . "/Bootstrap.php";
if (ENV !== ENV_DEVELOPMENT && (!Utils::IsXhrRequest() || !AuthHandler::isSessionExisting())) {
    die;
}
$contactId = AuthHandler::getLoggedInUserId();
if (!$contactId) {
    warn("Toggle activate command sent while no user is logged in");
    die;
}
try {
    $server = DatabaseHelper::getInstance();
    $ride = $server->getRideProvidedByContactId($contactId);
    if (!$ride) {
        throw new Exception("No ride found for contact {$contactId}");
    }
    $rideId = $ride['Id'];
    if ($ride['Active'] == RIDE_ACTIVE) {
        // Hidden status is always status + 2
        $newStatus = RIDE_INACTIVE;
        $msg = _("Ride de-activated. From now on, this ride will not appear in the search results.");
    } else {
        if ($ride['Active'] == RIDE_INACTIVE) {
            $newStatus = RIDE_ACTIVE;
            $msg = _("Ride activated. You are back in business!");
        } else {
            throw new Exception("Illegal status");
        }
    }
コード例 #27
0
ファイル: test.php プロジェクト: atrakroo/carpool-1
<?php

include '../tests/testenv.php';
/*
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Carpool</title>
</head>
<body>
<?php 
*/
//$rides = DatabaseHelper::getInstance()->searchRides(array());
//echo MailHelper::render(VIEWS_PATH . '/showInterestMail.php', array('rides' => $rides));
$contact = DatabaseHelper::getInstance()->getContactById(1);
echo MailHelper::render(VIEWS_PATH . '/registrationMail.php', array('contact' => $contact));
コード例 #28
0
ファイル: translations.php プロジェクト: atrakroo/carpool-1
    echo _('Edit existing translations');
    ?>
">
		<tr>
			<th>
    			<span><?php 
    echo _('Language');
    ?>
</span>
    		</th>
			<th></th>		
    		<th></th>
		</tr>
<?php 
    $locales = LocaleManager::getInstance()->getLocales();
    $currentQuestions = DatabaseHelper::getInstance()->getQuestionsAnswers();
    foreach ($currentQuestions as $questionAnswerAllLangs) {
        $id = $questionAnswerAllLangs[LocaleManager::getDefaultLocale()]['Id'];
        $first = true;
        foreach ($locales as $lang => $locale) {
            $questionAnswer = isset($questionAnswerAllLangs[$lang]) ? $questionAnswerAllLangs[$lang] : null;
            ?>
    	<tr>
    		<td>
    			<span><?php 
            echo $locales[$lang]['Name'];
            ?>
</span>
    		</td>
        	<td>
        		<input style="width: 100%;" type="text" id="question_<?php 
コード例 #29
0
 public static function run($rideId = null)
 {
     info('ShowInterestNotifier: started');
     if ($rideId === null) {
         $statuses = array(STATUS_LOOKING, STATUS_OFFERED, STATUS_SHARING);
         foreach ($statuses as $status) {
             foreach (array_keys(RegionManager::getInstance()->getRegions()) as $region) {
                 $potentialRides = self::findPotentialRides($status, $region);
                 $ridesToNotify = self::findRidesToNotify($status, $region);
                 $results = self::searchForMatchingRides($potentialRides, $ridesToNotify);
                 foreach ($results as $contactId => $potentialResults) {
                     self::notify($contactId, $potentialRides, $potentialResults);
                 }
             }
         }
     } else {
         $newRide = array(0 => DatabaseHelper::getInstance()->getRideById($rideId));
         $newRideStatus = $newRide[0]['Status'];
         $region = $newRide[0]['Region'];
         $ridesToNotify = self::findRidesToNotify(self::getOppositeStatus($newRideStatus), $region);
         $results = self::searchForMatchingRides($newRide, $ridesToNotify);
         foreach ($results as $contactId => $potentialResults) {
             self::notify($contactId, $newRide, $potentialResults);
         }
     }
     DatabaseHelper::getInstance()->updateLastShowInterestNotifier(time());
     info('ShowInterestNotifier: done');
 }
コード例 #30
0
ファイル: AuthHandler.php プロジェクト: atrakroo/carpool-1
 /**
  * Automatically authenticate a given contact. This function should
  * only be used when there is no need to authenticate, such as right
  * after signing up
  * 
  * @param int $contactId Contact id of contact
  * @returns Contact data if authenticated, or false if no such contact exists
  */
 public static function authByContactId($contactId)
 {
     if (isset($_SESSION[self::SESSION_KEY_AUTH_USER])) {
         return DatabaseHelper::getInstance()->getContactById($contactId);
     } else {
         $contact = DatabaseHelper::getInstance()->getContactById($contactId);
         if ($contact) {
             $_SESSION[self::SESSION_KEY_AUTH_USER] = $contactId;
             info('Contact ' . $contactId . ' automatically authenticated');
             return $contact;
         } else {
             warn('Contact "' . $contactId . '" was not found in the database');
             return false;
         }
     }
 }