Пример #1
0
 public function routes(&$router)
 {
     // Get all contact
     $router->get('/contacts', function () use($router) {
         $contacts = Contacts::load($GLOBALS['user']->id);
         if ($router->compact()) {
             $router->render(compact('contacts'));
             return;
         }
         $users = array();
         foreach ($contacts as $user_id) {
             $user = $router->dispatch('get', '/user(/:user_id)', $user_id);
             $users[] = $user['user'];
         }
         $router->render(compact('contacts', 'users'));
     });
     // Add contact
     $router->put('/contacts/:user_id', function ($user_id) use($router) {
         $user = \User::find($user_id);
         if (!$user) {
             $router->halt(404, 'User "%s" not found', $user_id);
         }
         $contact_id = Contacts::locate($GLOBALS['user']->id, $user_id);
         if ($contact_id) {
             $router->halt(406, 'User "%s" is already a contact', $user_id);
         }
         AddNewContact($user_id);
         $router->render($router->dispatch('get', '/contacts'));
     });
     // Remove contact
     $router->delete('/contacts/:user_id', function ($user_id) use($router) {
         $user = \User::find($user_id);
         if (!$user) {
             $router->halt(404, 'User "%s" not found', $user_id);
         }
         $contact_id = Contacts::locate($GLOBALS['user']->id, $user_id);
         if (!$contact_id) {
             $router->halt(406, 'User "%s" is not a contact', $user_id);
         }
         DeleteContact($contact_id);
         $router->halt(200, 'Contact "%s" has been removed', $user_id);
     });
 }
Пример #2
0
// evaluate method
switch ($method) {
    case 'PUT':
        UpdateContact();
        break;
    case 'POST':
        SaveContact();
        break;
    case 'GET':
        GetContact();
        break;
    case 'HEAD':
        echo "HEAD";
        break;
    case 'DELETE':
        DeleteContact();
        break;
    case 'OPTIONS':
        echo "OPTIONS";
        break;
    default:
        echo "{$method}";
        break;
}
//// DB
//// REST Functions
// GET: /Usuario/uuser
function GetContact()
{
    //
    session_start();
Пример #3
0
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
include_once dirname(__FILE__) . "/ressources/class.obm.inc";
include_once dirname(__FILE__) . "/ressources/class.contacts.inc";
include_once dirname(__FILE__) . "/ressources/class.templates.inc";
include_once dirname(__FILE__) . "/framework/frame.class.inc";
$param = $argv[1];
if (preg_match("#--user=(.+)#", $param, $re)) {
    write_syslog("Checking {$re[1]}", __FILE__);
    SynCcontact($re[1]);
    die;
}
if (preg_match("#--delete=(.+)#", $param, $re)) {
    write_syslog("deleting {$re[1]}", __FILE__);
    DeleteContact($re[1]);
    die;
}
function SynCcontact($employeeNumber)
{
    $ct = new contacts(null, $employeeNumber);
    $obmex = new obm_export(1);
    if ($ct->uidNumber == null) {
        write_syslog("Checking {$employeeNumber} uidNumber is null aborting, failed to import to OBM database", __FILE__);
        die;
    }
    if (preg_match("#ou=(.+?),ou=People,#", $ct->dn, $re)) {
        $uidMaster = $re[1];
        $contact = new user($uidMaster);
        if (preg_match("#(.+?)@(.+)#", $contact->mail, $re)) {
            $DomainId = GetobmDomainId($re[2]);