<?php

require_once "../lib/HighriseAPI.class.php";
if (count($argv) != 3) {
    die("Usage: php users.test.php [account-name] [access-token]\n");
}
$hr = new HighriseAPI();
$hr->debug = false;
$hr->setAccount($argv[1]);
$hr->setToken($argv[2]);
print "Finding my user...\n";
$user = $hr->findMe();
print_r($user);
print "Finding all users...\n";
$users = $hr->findAllUsers();
print_r($users);
        $completed_task->delete();
    }
}
if (!isset($found_completed)) {
    throw new Exception("Couldn't find the completed task");
}
print "Finding Upcoming Tasks...\n";
$tasks = $hr->findUpcomingTasks();
print_r($tasks);
// For this to work you need at least two users in the system
print "Assigning task to user";
$assigned_task = new HighriseTask($hr);
$assigned_task->setBody("Assigned Task");
$assigned_task->setFrame("today");
$users = $hr->findAllUsers();
$me = $hr->findMe();
foreach ($users as $user) {
    if ($user->getId() != $me->getId()) {
        $assigned_user = $user;
    }
}
$assigned_task->assignToUser($assigned_user);
$assigned_task->save();
print "Finding all Assigned Tasks...";
$assigned_tasks = $hr->findAssignedTasks();
print_r($assigned_tasks);
foreach ($assigned_tasks as $a_task) {
    if ($a_task->getId() == $assigned_task->getId()) {
        $found_assigned = true;
        $a_task->delete();
    }