Exemplo n.º 1
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new RegionManager();
     }
     return self::$_instance;
 }
Exemplo n.º 2
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');
 }
Exemplo n.º 3
0
			</dl>
			</fieldset>
		</form>
		<form id="regionSelectorForm">
			<dl>
				<?php 
if (RegionManager::getInstance()->isMultiRegion()) {
    ?>
    			<dd>
        			<label for="regionSelector"><?php 
    echo _('Region');
    ?>
&nbsp;</label>
        			<select id="regionSelector" name="regionSelector">
        			<?php 
    foreach (RegionManager::getInstance()->getRegions() as $regionId => $region) {
        ?>
        				<option value="<?php 
        echo $regionId;
        ?>
" <?php 
        echo $regionId == $currentRegion ? 'selected="selected"' : '';
        ?>
><?php 
        echo _($region['Abbrev']);
        ?>
</option>
        			<?php 
    }
    ?>
					
Exemplo n.º 4
0
    global $logger;
    $logger->doLog(Logger::LOG_WARN, $str);
}
function err($str)
{
    global $logger;
    $logger->doLog(Logger::LOG_ERR, $str);
}
function logException(Exception $e)
{
    global $logger;
    $logger->logException($e);
}
// Initialize locale and region objects
LocaleManager::init();
RegionManager::init();
// Start session
AuthHandler::init();
// Initialize the ACL
$acl = new SimpleAcl();
$acl->addRole(ROLE_GUEST);
$acl->addRole(ROLE_AUTHORIZED_ACCESS, ROLE_GUEST);
$acl->addRole(ROLE_IDENTIFIED, ROLE_GUEST);
$acl->addRole(ROLE_IDENTIFIED_REGISTERED, ROLE_IDENTIFIED);
$acl->addRole(ROLE_ADMINISTRATOR, ROLE_IDENTIFIED_REGISTERED);
if (ENV === ENV_DEVELOPMENT) {
    $acl->addResource(ROLE_GUEST, array('webres.php', 'test.php'));
}
$acl->addResource(ROLE_GUEST, array('auth.php', 'optout.php'));
if (getConfiguration('auth.mode') == AuthHandler::AUTH_MODE_PASS) {
    $acl->addResource(ROLE_GUEST, array('join.php', 'help.php', 'AddRideAll.php', 'GetRegionConfiguration.php'));
Exemplo n.º 5
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);
Exemplo n.º 6
0
         throw new Exception("Could not insert city {$destCity}");
     }
 }
 if ($srcCityId == LOCATION_NOT_FOUND) {
     // Now need make sure that we didn't already insert this city
     if ($srcCity !== $destCity) {
         $srcCityId = $db->addCity($srcCity, $region);
         if (!$srcCityId) {
             throw new Exception("Could not insert city {$destCity}");
         }
     } else {
         $srcCityId = $destCityId;
     }
 }
 // Update the region
 if (!RegionManager::getInstance()->setRegion($region)) {
     throw new Exception("Failed to update region");
 }
 try {
     if ($isUpdateContact) {
         $updateParams = array('name' => $name, 'phone' => $phone);
         // In some scenarios, contact might exist before having a ride -
         // we need to set their role now
         $currentRole = AuthHandler::getRole();
         if ($currentRole == ROLE_IDENTIFIED) {
             $updateParams['role'] = ROLE_IDENTIFIED_REGISTERED;
             AuthHandler::setRole(ROLE_IDENTIFIED_REGISTERED);
         }
         $updateParams['email'] = $canUpdateEmail ? $email : null;
         $db->updateContact($updateParams, $contactId);
     } else {
Exemplo n.º 7
0
<?php

include "../env.php";
include APP_PATH . "/Bootstrap.php";
if (ENV !== ENV_DEVELOPMENT && (!Utils::IsXhrRequest() || !AuthHandler::isSessionExisting())) {
    die;
}
extract($_GET, EXTR_SKIP);
$region = RegionManager::getInstance()->getCurrentRegionId();
$params = array('region' => $region);
if (isset($srcCityId) && !empty($srcCityId) && !($srcCityId == LOCATION_DONT_CARE)) {
    info("SrcCityId {$srcCityId}");
    $params['srcCityId'] = $srcCityId;
}
if (isset($destCityId) && !empty($destCityId) && !($destCityId == LOCATION_DONT_CARE)) {
    $params['destCityId'] = $destCityId;
}
if (isset($wantTo) && !empty($wantTo)) {
    $params['status'] = array($wantTo, STATUS_SHARING);
} else {
    // We need to avoid displaying of inactive rides
    $params['status'] = array(STATUS_LOOKING, STATUS_OFFERED, STATUS_SHARING);
}
$server = DatabaseHelper::getInstance();
$rides = $server->searchRides($params);
if ($rides !== false) {
    $res = array('status' => 'ok', 'results' => $rides);
} else {
    $res = array('status' => 'err');
}
echo json_encode($res);