Ejemplo n.º 1
0
 public function getToken()
 {
     if (is_null($this->_token)) {
         $response = $this->apiCall('/users/' . $this->getAttribute('id') . '/token', 'GET');
         if (Floorplanner::success($response)) {
             $this->_token = $response['data'];
         } else {
             throw new Floorplanner_Exception($response);
         }
     }
     return $this->_token;
 }
Ejemplo n.º 2
0
<?php

# include the Floorplanner API classes
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../classes');
require_once 'Floorplanner.php';
# load the API key from the config file
require_once './config.php';
session_start();
if (empty($_SESSION['fp_token'])) {
    header('Location: index.php');
}
$fp = Floorplanner::connectWithToken($config['api_key'], $_SESSION['fp_token']);
$projects = $fp->getProjects();
?>

<p> Logging in using token: <?php 
echo $fp->token;
?>
 </p>
<h2> <?php 
echo count($projects);
?>
 projects</h2>
<ul>
<?php 
foreach ($projects as $project) {
    ?>
	<li><a href="project.php?id=<?php 
    echo $project->id;
    ?>
"><?php 
Ejemplo n.º 3
0
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../classes');
require_once 'Floorplanner.php';
# load the API key from the config file
require_once './config.php';
# Connect to the floorplanner server
$fp = Floorplanner::connect($config['api_key']);
# Note: this function does not communicate with the Floorplanner server.
# It will only set the right parameters for API calls that will be done
# later  by calling function on the $fp-object. It will therefore never
# fail.
# Now, lets do something useful.
# Get a list of all the users accessible with the current API key.
$users = $fp->getUsers();
foreach ($users as $user) {
    print $user->email . " (#{$user->id})\n";
}
# get an authentication token for the last user, so we can impersonate him.
$token = $user->getToken();
print "\nToken for user #{$user->id}: {$token}\n\n";
# Now, connect to the Floorplanner server with an authentication token.
# This eassentially means that you will be logged in as the user the token
# is generated for. Note that the API key is still required.
$user_fp = Floorplanner::connectWithToken($config['api_key'], $token);
# Get a list of all the projects accessible with the current API key
$projects = $user_fp->getProjects();
foreach ($projects as $project) {
    print $project->name . " (#{$project->id})\n";
}
# get an authentication token for the last project, in case we want to
# open it in the Flash application.
print "\nToken for project #{$project->id}: " . $project->getToken() . "\n\n";
Ejemplo n.º 4
0
<?php

require '../classes/Floorplanner.php';
require 'config.php';
session_start();
$fp = Floorplanner::connect($config['api_key']);
$page = empty($_GET['page']) ? 1 : intval($_GET['page']);
if ($page < 1) {
    $page = 1;
}
$user = $fp->getUser($_GET['user_id']);
$projects = $user->getProjects();
?>

<h1> User info </h1>

<p> E-mail: <a href="mailto:<?php 
echo htmlspecialchars($user->email);
?>
"><?php 
echo htmlspecialchars($user->email);
?>
</a></p>
	

<h2> Projects </h2>
<ul>
<?php 
foreach ($projects as $project) {
    ?>
	<li><a href="project.php?project_id=<?php 
Ejemplo n.º 5
0
#!/usr/bin/php
<?php 
# include the Floorplanner API classes
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../classes');
require_once 'Floorplanner.php';
# load the API key from the config file
require_once './config.php';
if (count($argv) <= 1) {
    try {
        print "Trying to get a list of users with an API only account...\n";
        $tokenless_fp = Floorplanner::connect($config['api_key']);
        $tokenless_fp->getUsers();
        print "It succeeded. This should not happen!!!";
    } catch (Floorplanner_Exception $fe) {
        print "It failed miserably, as expected.\n";
        print "With an API only account, you WILL need an authentication token.\n\n";
        print "Please provide a user token as the first argument to this script.\n";
    }
} else {
    # A user token must be provided as first argument
    print "Trying to get a list of projects that are accessible with the given token...\n";
    # Connect to the Floorplanner server with the provided auth token
    $fp = Floorplanner::connectWithToken($config['api_key'], $argv[1]);
    # Now, get all the projects of the user associated with the token.
    $projects = $fp->getProjects();
    foreach ($projects as $project) {
        print $project->id . ': ' . $project->name . "\n";
    }
    print "\nTotal projects found: " . count($projects) . "\n";
}