<?php

class Inbox_ContactController extends Inbox_Controller_Base
{
    protected $Account;
    protected $DateAdded;
    protected $DateModified;
    protected $EntryID;
    protected $Favourite;
    protected $Global;
    protected $Shared;
    protected $SIP;
    protected $UsageCount;
    protected $UserAnniversary;
    protected $UserDOB;
    protected $UserEmail;
    protected $UserEmail2;
    protected $UserEmail3;
    protected $UserEmail4;
    protected $UserEmail5;
    protected $UserFacebookProfile;
    protected $UserFileAs;
    protected $UserFirstName;
    protected $UserGender;
    protected $UserHomeAddress;
    protected $UserHomeCity;
    protected $UserHomeCountry;
    protected $UserHomeFax;
    protected $UserHomeMobile;
    protected $UserHomePhone;
    protected $UserHomeState;
    protected $UserHomeZip;
    protected $UserIM;
    protected $UserInfo;
    protected $UserLastName;
    protected $UserLinkedInProfile;
    protected $UserMiddleName;
    protected $UserNote;
    protected $UserPhoto;
    protected $UserRelationship;
    protected $UserSignificantOther;
    protected $UserSuffix;
    protected $UserTitle;
    protected $UserTwitterProfile;
    protected $UserType;
    protected $UserURL;
    protected $UserWorkAddress;
    protected $UserWorkCity;
    protected $UserWorkCompany;
    protected $UserWorkCountry;
    protected $UserWorkDept;
    protected $UserWorkFax;
    protected $UserWorkMobile;
    protected $UserWorkOffice;
    protected $UserWorkPhone;
    protected $UserWorkState;
    protected $UserWorkTitle;
    protected $UserWorkZip;
    protected $VCardData;
    protected $CardDAVUrl;

    public function init()
    {
        parent::init();
    }

    protected function populateParameters()
    {
        if ($this->isJson())
        {
            $inputJson = file_get_contents('php://input');
            $input = json_decode( $inputJson, TRUE );

            $this->Account =              $this->getJsonParam($input, 'Account', '');
            $this->DateAdded =            $this->getJsonParam($input, 'DateAdded', '');
            $this->DateModified =         $this->getJsonParam($input, 'DateModified', '');
            $this->EntryID =              $this->getJsonParam($input, 'EntryID', '');
            $this->Favourite =            $this->getJsonParam($input, 'Favourite', '');
            $this->Global =               $this->getJsonParam($input, 'Global', '');
            $this->Shared =               $this->getJsonParam($input, 'Shared', '');
            $this->SIP =                  $this->getJsonParam($input, 'SIP', '');
            $this->UsageCount =           $this->getJsonParam($input, 'UsageCount', '');
            $this->UserAnniversary =      $this->getJsonParam($input, 'UserAnniversary', '');
            $this->UserDOB =              $this->getJsonParam($input, 'UserDOB', '');
            $this->UserEmail =            $this->getJsonParam($input, 'UserEmail', '');
            $this->UserEmail2 =           $this->getJsonParam($input, 'UserEmail2', '');
            $this->UserEmail3 =           $this->getJsonParam($input, 'UserEmail3', '');
            $this->UserEmail4 =           $this->getJsonParam($input, 'UserEmail4', '');
            $this->UserEmail5 =           $this->getJsonParam($input, 'UserEmail5', '');
            $this->UserFacebookProfile =  $this->getJsonParam($input, 'UserFacebookProfile', '');
            $this->UserFileAs =           $this->getJsonParam($input, 'UserFileAs', '');
            $this->UserFirstName =        $this->getJsonParam($input, 'UserFirstName', '');
            $this->UserGender =           $this->getJsonParam($input, 'UserGender', '');
            $this->UserHomeAddress =      $this->getJsonParam($input, 'UserHomeAddress', '');
            $this->UserHomeCity =         $this->getJsonParam($input, 'UserHomeCity', '');
            $this->UserHomeCountry =      $this->getJsonParam($input, 'UserHomeCountry', '');
            $this->UserHomeFax =          $this->getJsonParam($input, 'UserHomeFax', '');
            $this->UserHomeMobile =       $this->getJsonParam($input, 'UserHomeMobile', '');
            $this->UserHomePhone =        $this->getJsonParam($input, 'UserHomePhone', '');
            $this->UserHomeState =        $this->getJsonParam($input, 'UserHomeState', '');
            $this->UserHomeZip =          $this->getJsonParam($input, 'UserHomeZip', '');
            $this->UserIM =               $this->getJsonParam($input, 'UserIM', '');
            $this->UserInfo =             $this->getJsonParam($input, 'UserInfo', '');
            $this->UserLastName =         $this->getJsonParam($input, 'UserLastName', '');
            $this->UserLinkedInProfile =  $this->getJsonParam($input, 'UserLinkedInProfile', '');
            $this->UserMiddleName =       $this->getJsonParam($input, 'UserMiddleName', '');
            $this->UserNote =             $this->getJsonParam($input, 'UserNote', '');
            $this->UserPhoto =            $this->getJsonParam($input, 'UserPhoto', '');
            $this->UserRelationship =     $this->getJsonParam($input, 'UserRelationship', '');
            $this->UserSignificantOther = $this->getJsonParam($input, 'UserSignificantOther', '');
            $this->UserSuffix =           $this->getJsonParam($input, 'UserSuffix', '');
            $this->UserTitle =            $this->getJsonParam($input, 'UserTitle', '');
            $this->UserTwitterProfile =   $this->getJsonParam($input, 'UserTwitterProfile', '');
            $this->UserType =             $this->getJsonParam($input, 'UserType', '');
            $this->UserURL =              $this->getJsonParam($input, 'UserURL', '');
            $this->UserWorkAddress =      $this->getJsonParam($input, 'UserWorkAddress', '');
            $this->UserWorkCity =         $this->getJsonParam($input, 'UserWorkCity', '');
            $this->UserWorkCompany =      $this->getJsonParam($input, 'UserWorkCompany', '');
            $this->UserWorkCountry =      $this->getJsonParam($input, 'UserWorkCountry', '');
            $this->UserWorkDept =         $this->getJsonParam($input, 'UserWorkDept', '');
            $this->UserWorkFax =          $this->getJsonParam($input, 'UserWorkFax', '');
            $this->UserWorkMobile =       $this->getJsonParam($input, 'UserWorkMobile', '');
            $this->UserWorkOffice =       $this->getJsonParam($input, 'UserWorkOffice', '');
            $this->UserWorkPhone =        $this->getJsonParam($input, 'UserWorkPhone', '');
            $this->UserWorkState =        $this->getJsonParam($input, 'UserWorkState', '');
            $this->UserWorkTitle =        $this->getJsonParam($input, 'UserWorkTitle', '');
            $this->UserWorkZip =          $this->getJsonParam($input, 'UserWorkZip', '');
            $this->VCardData =            $this->getJsonParam($input, 'VCardData', '');
            $this->CardDAVUrl =           $this->getJsonParam($input, 'CardDAVUrl', '');
        }
        else
        {
            $this->Account =              $this->_getParam($input, 'Account', '');
            $this->DateAdded =            $this->_getParam($input, 'DateAdded', '');
            $this->DateModified =         $this->_getParam($input, 'DateModified', '');
            $this->EntryID =              $this->_getParam($input, 'EntryID', '');
            $this->Favourite =            $this->_getParam($input, 'Favourite', '');
            $this->Global =               $this->_getParam($input, 'Global', '');
            $this->Shared =               $this->_getParam($input, 'Shared', '');
            $this->SIP =                  $this->_getParam($input, 'SIP', '');
            $this->UsageCount =           $this->_getParam($input, 'UsageCount', '');
            $this->UserAnniversary =      $this->_getParam($input, 'UserAnniversary', '');
            $this->UserDOB =              $this->_getParam($input, 'UserDOB', '');
            $this->UserEmail =            $this->_getParam($input, 'UserEmail', '');
            $this->UserEmail2 =           $this->_getParam($input, 'UserEmail2', '');
            $this->UserEmail3 =           $this->_getParam($input, 'UserEmail3', '');
            $this->UserEmail4 =           $this->_getParam($input, 'UserEmail4', '');
            $this->UserEmail5 =           $this->_getParam($input, 'UserEmail5', '');
            $this->UserFacebookProfile =  $this->_getParam($input, 'UserFacebookProfile', '');
            $this->UserFileAs =           $this->_getParam($input, 'UserFileAs', '');
            $this->UserFirstName =        $this->_getParam($input, 'UserFirstName', '');
            $this->UserGender =           $this->_getParam($input, 'UserGender', '');
            $this->UserHomeAddress =      $this->_getParam($input, 'UserHomeAddress', '');
            $this->UserHomeCity =         $this->_getParam($input, 'UserHomeCity', '');
            $this->UserHomeCountry =      $this->_getParam($input, 'UserHomeCountry', '');
            $this->UserHomeFax =          $this->_getParam($input, 'UserHomeFax', '');
            $this->UserHomeMobile =       $this->_getParam($input, 'UserHomeMobile', '');
            $this->UserHomePhone =        $this->_getParam($input, 'UserHomePhone', '');
            $this->UserHomeState =        $this->_getParam($input, 'UserHomeState', '');
            $this->UserHomeZip =          $this->_getParam($input, 'UserHomeZip', '');
            $this->UserIM =               $this->_getParam($input, 'UserIM', '');
            $this->UserInfo =             $this->_getParam($input, 'UserInfo', '');
            $this->UserLastName =         $this->_getParam($input, 'UserLastName', '');
            $this->UserLinkedInProfile =  $this->_getParam($input, 'UserLinkedInProfile', '');
            $this->UserMiddleName =       $this->_getParam($input, 'UserMiddleName', '');
            $this->UserNote =             $this->_getParam($input, 'UserNote', '');
            $this->UserPhoto =            $this->_getParam($input, 'UserPhoto', '');
            $this->UserRelationship =     $this->_getParam($input, 'UserRelationship', '');
            $this->UserSignificantOther = $this->_getParam($input, 'UserSignificantOther', '');
            $this->UserSuffix =           $this->_getParam($input, 'UserSuffix', '');
            $this->UserTitle =            $this->_getParam($input, 'UserTitle', '');
            $this->UserTwitterProfile =   $this->_getParam($input, 'UserTwitterProfile', '');
            $this->UserType =             $this->_getParam($input, 'UserType', '');
            $this->UserURL =              $this->_getParam($input, 'UserURL', '');
            $this->UserWorkAddress =      $this->_getParam($input, 'UserWorkAddress', '');
            $this->UserWorkCity =         $this->_getParam($input, 'UserWorkCity', '');
            $this->UserWorkCompany =      $this->_getParam($input, 'UserWorkCompany', '');
            $this->UserWorkCountry =      $this->_getParam($input, 'UserWorkCountry', '');
            $this->UserWorkDept =         $this->_getParam($input, 'UserWorkDept', '');
            $this->UserWorkFax =          $this->_getParam($input, 'UserWorkFax', '');
            $this->UserWorkMobile =       $this->_getParam($input, 'UserWorkMobile', '');
            $this->UserWorkOffice =       $this->_getParam($input, 'UserWorkOffice', '');
            $this->UserWorkPhone =        $this->_getParam($input, 'UserWorkPhone', '');
            $this->UserWorkState =        $this->_getParam($input, 'UserWorkState', '');
            $this->UserWorkTitle =        $this->_getParam($input, 'UserWorkTitle', '');
            $this->UserWorkZip =          $this->_getParam($input, 'UserWorkZip', '');
            $this->VCardData =            $this->_getParam($input, 'VCardData', '');
            $this->CardDAVUrl =           $this->_getParam($input, 'CardDAVUrl', '');
        }
    }

    public function indexAction()
    {
        try
        {
            $account = $this->_getParam('account');

            if (null === $account)
            {
                $sql = 'SELECT * from abook';
                $contacts = $this->_dbAdapter->fetchAll($sql);
                $this->renderJson($contacts);
            }
            else
            {
                $sql = 'SELECT * from abook where account=:account';
                $stmt = $this->_dbAdapter->prepare($sql);
                $stmt->bindParam('account', $account);
                $stmt->execute();
                $result = $stmt->fetchAll();
                $this->renderJson($result);
            }
        }
        catch (Exception $e)
        {
            $this->renderJson(array('error' => array('text' => $e->getMessage())));
        }

    }

    public function getAction()
    {
        $id = $this->_getParam('id', 0);
        $sql = 'SELECT * from abook where id=:id';

        try
        {
            $stmt = $this->_dbAdapter->prepare($sql);
            $stmt->bindParam('id', $id);
            $stmt->execute();
            $result = $stmt->fetchObject();

            if ($result)
            {
                $this->renderJson($result);
            }
            else
            {
                $this->renderJson($this->_noResults);
            }
        }
        catch (Exception $e)
        {
            $this->renderJson(array('error' => array('text' => $e->getMessage())));
        }
    }

    public function postAction()
    {
        try
        {
            $sql = <<<EOD
INSERT INTO abook (
`Account`,
`DateAdded`,
`DateModified`,
`EntryID`,
`Favourite`,
`Global`,
`Shared`,
`SIP`,
`UsageCount`,
`UserAnniversary`,
`UserDOB`,
`UserEmail`,
`UserEmail2`,
`UserEmail3`,
`UserEmail4`,
`UserEmail5`,
`UserFacebookProfile`,
`UserFileAs`,
`UserFirstName`,
`UserGender`,
`UserHomeAddress`,
`UserHomeCity`,
`UserHomeCountry`,
`UserHomeFax`,
`UserHomeMobile`,
`UserHomePhone`,
`UserHomeState`,
`UserHomeZip`,
`UserIM`,
`UserInfo`,
`UserLastName`,
`UserLinkedInProfile`,
`UserMiddleName`,
`UserNote`,
`UserPhoto`,
`UserRelationship`,
`UserSignificantOther`,
`UserSuffix`,
`UserTitle`,
`UserTwitterProfile`,
`UserType`,
`UserURL`,
`UserWorkAddress`,
`UserWorkCity`,
`UserWorkCompany`,
`UserWorkCountry`,
`UserWorkDept`,
`UserWorkFax`,
`UserWorkMobile`,
`UserWorkOffice`,
`UserWorkPhone`,
`UserWorkState`,
`UserWorkTitle`,
`UserWorkZip`,
`VCardData`,
`CardDAVUrl`
) VALUES (
:Account,
:DateAdded,
:DateModified,
:EntryID,
:Favourite,
:Global,
:Shared,
:SIP,
:UsageCount,
:UserAnniversary,
:UserDOB,
:UserEmail,
:UserEmail2,
:UserEmail3,
:UserEmail4,
:UserEmail5,
:UserFacebookProfile,
:UserFileAs,
:UserFirstName,
:UserGender,
:UserHomeAddress,
:UserHomeCity,
:UserHomeCountry,
:UserHomeFax,
:UserHomeMobile,
:UserHomePhone,
:UserHomeState,
:UserHomeZip,
:UserIM,
:UserInfo,
:UserLastName,
:UserLinkedInProfile,
:UserMiddleName,
:UserNote,
:UserPhoto,
:UserRelationship,
:UserSignificantOther,
:UserSuffix,
:UserTitle,
:UserTwitterProfile,
:UserType,
:UserURL,
:UserWorkAddress,
:UserWorkCity,
:UserWorkCompany,
:UserWorkCountry,
:UserWorkDept,
:UserWorkFax,
:UserWorkMobile,
:UserWorkOffice,
:UserWorkPhone,
:UserWorkState,
:UserWorkTitle,
:UserWorkZip,
:VCardData,
:CardDAVUrl
);
EOD;

            $this->populateParameters();

            $stmt = $this->_dbAdapter->prepare($sql);

            $stmt->bindParam('Account',              $this->Account);
            $stmt->bindParam('DateAdded',            $this->DateAdded);
            $stmt->bindParam('DateModified',         $this->DateModified);
            $stmt->bindParam('EntryID',              $this->EntryID);
            $stmt->bindParam('Favourite',            $this->Favourite);
            $stmt->bindParam('Global',               $this->Global);
            $stmt->bindParam('Shared',               $this->Shared);
            $stmt->bindParam('SIP',                  $this->SIP);
            $stmt->bindParam('UsageCount',           $this->UsageCount);
            $stmt->bindParam('UserAnniversary',      $this->UserAnniversary);
            $stmt->bindParam('UserDOB',              $this->UserDOB);
            $stmt->bindParam('UserEmail',            $this->UserEmail);
            $stmt->bindParam('UserEmail2',           $this->UserEmail2);
            $stmt->bindParam('UserEmail3',           $this->UserEmail3);
            $stmt->bindParam('UserEmail4',           $this->UserEmail4);
            $stmt->bindParam('UserEmail5',           $this->UserEmail5);
            $stmt->bindParam('UserFacebookProfile',  $this->UserFacebookProfile);
            $stmt->bindParam('UserFileAs',           $this->UserFileAs);
            $stmt->bindParam('UserFirstName',        $this->UserFirstName);
            $stmt->bindParam('UserGender',           $this->UserGender);
            $stmt->bindParam('UserHomeAddress',      $this->UserHomeAddress);
            $stmt->bindParam('UserHomeCity',         $this->UserHomeCity);
            $stmt->bindParam('UserHomeCountry',      $this->UserHomeCountry);
            $stmt->bindParam('UserHomeFax',          $this->UserHomeFax);
            $stmt->bindParam('UserHomeMobile',       $this->UserHomeMobile);
            $stmt->bindParam('UserHomePhone',        $this->UserHomePhone);
            $stmt->bindParam('UserHomeState',        $this->UserHomeState);
            $stmt->bindParam('UserHomeZip',          $this->UserHomeZip);
            $stmt->bindParam('UserIM',               $this->UserIM);
            $stmt->bindParam('UserInfo',             $this->UserInfo);
            $stmt->bindParam('UserLastName',         $this->UserLastName);
            $stmt->bindParam('UserLinkedInProfile',  $this->UserLinkedInProfile);
            $stmt->bindParam('UserMiddleName',       $this->UserMiddleName);
            $stmt->bindParam('UserNote',             $this->UserNote);
            $stmt->bindParam('UserPhoto',            $this->UserPhoto);
            $stmt->bindParam('UserRelationship',     $this->UserRelationship);
            $stmt->bindParam('UserSignificantOther', $this->UserSignificantOther);
            $stmt->bindParam('UserSuffix',           $this->UserSuffix);
            $stmt->bindParam('UserTitle',            $this->UserTitle);
            $stmt->bindParam('UserTwitterProfile',   $this->UserTwitterProfile);
            $stmt->bindParam('UserType',             $this->UserType);
            $stmt->bindParam('UserURL',              $this->UserURL);
            $stmt->bindParam('UserWorkAddress',      $this->UserWorkAddress);
            $stmt->bindParam('UserWorkCity',         $this->UserWorkCity);
            $stmt->bindParam('UserWorkCompany',      $this->UserWorkCompany);
            $stmt->bindParam('UserWorkCountry',      $this->UserWorkCountry);
            $stmt->bindParam('UserWorkDept',         $this->UserWorkDept);
            $stmt->bindParam('UserWorkFax',          $this->UserWorkFax);
            $stmt->bindParam('UserWorkMobile',       $this->UserWorkMobile);
            $stmt->bindParam('UserWorkOffice',       $this->UserWorkOffice);
            $stmt->bindParam('UserWorkPhone',        $this->UserWorkPhone);
            $stmt->bindParam('UserWorkState',        $this->UserWorkState);
            $stmt->bindParam('UserWorkTitle',        $this->UserWorkTitle);
            $stmt->bindParam('UserWorkZip',          $this->UserWorkZip);
            $stmt->bindParam('VCardData',            $this->VCardData);
            $stmt->bindParam('CardDAVUrl',           $this->CardDAVUrl);

            $success = $stmt->execute();
            $id = $this->_dbAdapter->lastInsertId();

            $select = $this->_dbAdapter
                ->select()
                ->from('abook')
                ->where('id = ' . $this->_dbAdapter->quote($id, 'INTEGER'));

            $this->renderJson($this->_dbAdapter->fetchRow($select));
        }
        catch (Exception $e)
        {
            $this->renderJson(array('error' => array('text' => $e->getMessage())));
        }
    }

    public function putAction()
    {
        $id = $this->_getParam('id', 0);

        try
        {
            $sql = <<<EOD
UPDATE abook SET
`Account`              = :Account,
`DateAdded`            = :DateAdded,
`DateModified`         = :DateModified,
`EntryID`              = :EntryID,
`Favourite`            = :Favourite,
`Global`               = :Global,
`Shared`               = :Shared,
`SIP`                  = :SIP,
`UsageCount`           = :UsageCount,
`UserAnniversary`      = :UserAnniversary,
`UserDOB`              = :UserDOB,
`UserEmail`            = :UserEmail,
`UserEmail2`           = :UserEmail2,
`UserEmail3`           = :UserEmail3,
`UserEmail4`           = :UserEmail4,
`UserEmail5`           = :UserEmail5,
`UserFacebookProfile`  = :UserFacebookProfile,
`UserFileAs`           = :UserFileAs,
`UserFirstName`        = :UserFirstName,
`UserGender`           = :UserGender,
`UserHomeAddress`      = :UserHomeAddress,
`UserHomeCity`         = :UserHomeCity,
`UserHomeCountry`      = :UserHomeCountry,
`UserHomeFax`          = :UserHomeFax,
`UserHomeMobile`       = :UserHomeMobile,
`UserHomePhone`        = :UserHomePhone,
`UserHomeState`        = :UserHomeState,
`UserHomeZip`          = :UserHomeZip,
`UserIM`               = :UserIM,
`UserInfo`             = :UserInfo,
`UserLastName`         = :UserLastName,
`UserLinkedInProfile`  = :UserLinkedInProfile,
`UserMiddleName`       = :UserMiddleName,
`UserNote`             = :UserNote,
`UserPhoto`            = :UserPhoto,
`UserRelationship`     = :UserRelationship,
`UserSignificantOther` = :UserSignificantOther,
`UserSuffix`           = :UserSuffix,
`UserTitle`            = :UserTitle,
`UserTwitterProfile`   = :UserTwitterProfile,
`UserType`             = :UserType,
`UserURL`              = :UserURL,
`UserWorkAddress`      = :UserWorkAddress,
`UserWorkCity`         = :UserWorkCity,
`UserWorkCompany`      = :UserWorkCompany,
`UserWorkCountry`      = :UserWorkCountry,
`UserWorkDept`         = :UserWorkDept,
`UserWorkFax`          = :UserWorkFax,
`UserWorkMobile`       = :UserWorkMobile,
`UserWorkOffice`       = :UserWorkOffice,
`UserWorkPhone`        = :UserWorkPhone,
`UserWorkState`        = :UserWorkState,
`UserWorkTitle`        = :UserWorkTitle,
`UserWorkZip`          = :UserWorkZip,
`VCardData`            = :VCardData,
`CardDAVUrl`           = :CardDAVUrl
WHERE id=:id
EOD;

            $this->populateParameters();

            $stmt = $this->_dbAdapter->prepare($sql);
            $stmt->bindParam('id',            $id);

            $stmt->bindParam('Account',              $this->Account);
            $stmt->bindParam('DateAdded',            $this->DateAdded);
            $stmt->bindParam('DateModified',         $this->DateModified);
            $stmt->bindParam('EntryID',              $this->EntryID);
            $stmt->bindParam('Favourite',            $this->Favourite);
            $stmt->bindParam('Global',               $this->Global);
            $stmt->bindParam('Shared',               $this->Shared);
            $stmt->bindParam('SIP',                  $this->SIP);
            $stmt->bindParam('UsageCount',           $this->UsageCount);
            $stmt->bindParam('UserAnniversary',      $this->UserAnniversary);
            $stmt->bindParam('UserDOB',              $this->UserDOB);
            $stmt->bindParam('UserEmail',            $this->UserEmail);
            $stmt->bindParam('UserEmail2',           $this->UserEmail2);
            $stmt->bindParam('UserEmail3',           $this->UserEmail3);
            $stmt->bindParam('UserEmail4',           $this->UserEmail4);
            $stmt->bindParam('UserEmail5',           $this->UserEmail5);
            $stmt->bindParam('UserFacebookProfile',  $this->UserFacebookProfile);
            $stmt->bindParam('UserFileAs',           $this->UserFileAs);
            $stmt->bindParam('UserFirstName',        $this->UserFirstName);
            $stmt->bindParam('UserGender',           $this->UserGender);
            $stmt->bindParam('UserHomeAddress',      $this->UserHomeAddress);
            $stmt->bindParam('UserHomeCity',         $this->UserHomeCity);
            $stmt->bindParam('UserHomeCountry',      $this->UserHomeCountry);
            $stmt->bindParam('UserHomeFax',          $this->UserHomeFax);
            $stmt->bindParam('UserHomeMobile',       $this->UserHomeMobile);
            $stmt->bindParam('UserHomePhone',        $this->UserHomePhone);
            $stmt->bindParam('UserHomeState',        $this->UserHomeState);
            $stmt->bindParam('UserHomeZip',          $this->UserHomeZip);
            $stmt->bindParam('UserIM',               $this->UserIM);
            $stmt->bindParam('UserInfo',             $this->UserInfo);
            $stmt->bindParam('UserLastName',         $this->UserLastName);
            $stmt->bindParam('UserLinkedInProfile',  $this->UserLinkedInProfile);
            $stmt->bindParam('UserMiddleName',       $this->UserMiddleName);
            $stmt->bindParam('UserNote',             $this->UserNote);
            $stmt->bindParam('UserPhoto',            $this->UserPhoto);
            $stmt->bindParam('UserRelationship',     $this->UserRelationship);
            $stmt->bindParam('UserSignificantOther', $this->UserSignificantOther);
            $stmt->bindParam('UserSuffix',           $this->UserSuffix);
            $stmt->bindParam('UserTitle',            $this->UserTitle);
            $stmt->bindParam('UserTwitterProfile',   $this->UserTwitterProfile);
            $stmt->bindParam('UserType',             $this->UserType);
            $stmt->bindParam('UserURL',              $this->UserURL);
            $stmt->bindParam('UserWorkAddress',      $this->UserWorkAddress);
            $stmt->bindParam('UserWorkCity',         $this->UserWorkCity);
            $stmt->bindParam('UserWorkCompany',      $this->UserWorkCompany);
            $stmt->bindParam('UserWorkCountry',      $this->UserWorkCountry);
            $stmt->bindParam('UserWorkDept',         $this->UserWorkDept);
            $stmt->bindParam('UserWorkFax',          $this->UserWorkFax);
            $stmt->bindParam('UserWorkMobile',       $this->UserWorkMobile);
            $stmt->bindParam('UserWorkOffice',       $this->UserWorkOffice);
            $stmt->bindParam('UserWorkPhone',        $this->UserWorkPhone);
            $stmt->bindParam('UserWorkState',        $this->UserWorkState);
            $stmt->bindParam('UserWorkTitle',        $this->UserWorkTitle);
            $stmt->bindParam('UserWorkZip',          $this->UserWorkZip);
            $stmt->bindParam('VCardData',            $this->VCardData);
            $stmt->bindParam('CardDAVUrl',           $this->CardDAVUrl);

            $success = $stmt->execute();

            $select = $this->_dbAdapter
                ->select()
                ->from('abook')
                ->where('id = ' . $this->_dbAdapter->quote($id, 'INTEGER'));

            $this->renderJson($this->_dbAdapter->fetchRow($select));
        }
        catch (Exception $e)
        {
            $this->renderJson(array('error' => array('text' => $e->getMessage())));
        }
    }

    public function deleteAction()
    {
        $id = $this->_getParam('id', 0);

        try
        {
            $sql = 'DELETE FROM abook WHERE id=:id';

            $stmt = $this->_dbAdapter->prepare($sql);
            $stmt->bindParam('id', $id);
            $success = $stmt->execute();
            $this->renderJson($this->_statusOK);
        }
        catch (Exception $e)
        {
            $this->renderJson(array('error' => array('text' => $e->getMessage())));
        }
    }
}
