/*
 * Copyright 2015 AT&T
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $contactId = $_POST['deleteContactId'];
    $aabService->deleteContact($contactId);
    $arr = array('success' => true, 'text' => 'Successfully deleted contact.');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
require_once __DIR__ . '/../lib/AAB/Group.php';
use Att\Api\AAB\AABService;
use Att\Api\AAB\Group;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gname = $_POST['updateGroupName'];
    $gid = $_POST['updateGroupId'];
    $group = new Group($gname, $gid);
    $aabService->updateGroup($group, $gid);
    $arr = array('success' => true, 'text' => 'Successfully updated group');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/*
 * Copyright 2015 AT&T
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gid = $_POST['deleteGroupId'];
    $aabService->deleteGroup($gid);
    $arr = array('success' => true, 'text' => 'Successfully deleted group');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $cid = $_POST['getGroupsContactId'];
    if ($cid === '') {
        throw new Exception('Contact Id must not be empty');
    }
    $aabService = new AABService(getFqdn(), getSessionToken());
    $resultSet = $aabService->getContactGroups($cid);
    $values = array();
    $groups = $resultSet->getGroups();
    foreach ($groups as $group) {
        $values[] = array($group->getGroupId(), $group->getGroupName(), $group->getGroupType());
    }
    $tables = array(array('caption' => 'Groups:', 'headers' => array('groupId', 'groupName', 'groupType'), 'values' => $values));
    $arr = array('success' => true, 'tables' => $tables);
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
require_once __DIR__ . '/../lib/AAB/PaginationParameters.php';
use Att\Api\AAB\AABService;
use Att\Api\AAB\PaginationParameters;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gid = $_POST['removeContactsGroupId'];
    if ($gid === '') {
        throw new Exception('Group Id must not be empty');
    }
    $cids = $_POST['removeContactIds'];
    if ($cids === '') {
        throw new Exception('Contact Ids must not be empty');
    }
    $cids = explode(",", $cids);
    $aabService->removeContactsFromGroup($gid, $cids);
    $arr = array('success' => true, 'text' => 'Successfully removed contacts from group.');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
require_once __DIR__ . '/../lib/AAB/ContactCommon.php';
use Att\Api\AAB\AABService;
use Att\Api\AAB\ContactCommon;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $keys = array('firstName', 'middleName', 'lastName', 'prefix', 'suffix', 'nickname', 'organization', 'jobTitle', 'anniversary', 'gender', 'spouse', 'children', 'hobby', 'assistant');
    $values = array($_POST['myInfoFirstName'], $_POST['myInfoMiddleName'], $_POST['myInfoLastName'], $_POST['myInfoPrefix'], $_POST['myInfoSuffix'], $_POST['myInfoNickname'], $_POST['myInfoOrganization'], $_POST['myInfoJobTitle'], $_POST['myInfoAnniversary'], $_POST['myInfoGender'], $_POST['myInfoSpouse'], $_POST['myInfoChildren'], $_POST['myInfoHobby'], $_POST['myInfoAssistant']);
    $contactArr = array();
    for ($i = 0; $i < count($keys); ++$i) {
        $key = $keys[$i];
        $value = $values[$i];
        $contactArr[$key] = $value === '' ? null : $value;
    }
    $phonesArr = array();
    $phoneCount = intval($_POST['myInfoPhoneIndex']);
    for ($i = 0; $i < $phoneCount; ++$i) {
        $number = $_POST['myInfoPhoneNumber' . $i];
        $pref = $_POST['myInfoPhonePref' . $i] === 'True' ? true : false;
        $type = $_POST['myInfoPhoneType' . $i];
        $phonesArr[] = array('number' => $number, 'preferred' => $pref, 'type' => $type);
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/aabUtil.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $contact = $aabService->getMyInfo();
    $tables = array();
    $tables[] = generateContactTable($contact);
    $contactId = $contact->getContactId();
    $table = generatePhonesTable($contactId, $contact->getPhones());
    if ($table !== null) {
        $tables[] = $table;
    }
    $table = generateEmailsTable($contactId, $contact->getEmails());
    if ($table !== null) {
        $tables[] = $table;
    }
    $table = generateImsTable($contactId, $contact->getIms());
    if ($table !== null) {
        $tables[] = $table;
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gid = $_POST['addContactsGroupId'];
    if ($gid === '') {
        throw new Exception('Group Id must not be empty');
    }
    $cids = $_POST['addContactIds'];
    if ($cids === '') {
        throw new Exception('Contact Ids must not be empty');
    }
    $cids = explode(",", $cids);
    $aabService->addContactsToGroup($gid, $cids);
    $arr = array('success' => true, 'text' => 'Successfully added contacts to group.');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/aabUtil.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $searchVal = $_POST['contactsSearchValue'];
    $resultSet = $aabService->getContacts(null, null, $searchVal);
    $tables = array();
    $contacts = $resultSet->getContacts();
    $qcontacts = $resultSet->getQuickContacts();
    foreach ($contacts as $contact) {
        $tables[] = generateContactTable($contact);
        $contactId = $contact->getContactId();
        $table = generatePhonesTable($contactId, $contact->getPhones());
        if ($table !== null) {
            $tables[] = $table;
        }
        $table = generateEmailsTable($contactId, $contact->getEmails());
        if ($table !== null) {
            $tables[] = $table;
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
use Att\Api\AAB\AABService;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gid = $_POST['getContactsGroupId'];
    if ($gid === '') {
        throw new Exception('Group Id must not be empty');
    }
    $contactIds = $aabService->getGroupContacts($gid);
    $values = array();
    foreach ($contactIds as $cid) {
        $values[] = array($cid);
    }
    $tables = array(array('caption' => 'Contacts:', 'headers' => array('contactId'), 'values' => $values));
    $arr = array('success' => true, 'tables' => $tables);
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
require_once __DIR__ . '/../lib/AAB/Contact.php';
use Att\Api\AAB\AABService;
use Att\Api\AAB\Contact;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $keys = array('contactId', 'firstName', 'middleName', 'lastName', 'prefix', 'suffix', 'nickname', 'organization', 'jobTitle', 'anniversary', 'gender', 'spouse', 'children', 'hobby', 'assistant');
    $values = array($_POST['updateContactId'], $_POST['updateFirstName'], $_POST['updateMiddleName'], $_POST['updateLastName'], $_POST['updatePrefix'], $_POST['updateSuffix'], $_POST['updateNickname'], $_POST['updateOrganization'], $_POST['updateJobTitle'], $_POST['updateAnniversary'], $_POST['updateGender'], $_POST['updateSpouse'], $_POST['updateChildren'], $_POST['updateHobby'], $_POST['updateAssistant']);
    $contactArr = array();
    for ($i = 0; $i < count($keys); ++$i) {
        $key = $keys[$i];
        $value = $values[$i];
        $contactArr[$key] = $value === '' ? null : $value;
    }
    $phonesArr = array();
    $phoneCount = intval($_POST['updatePhoneIndex']);
    for ($i = 0; $i < $phoneCount; ++$i) {
        $number = $_POST['updatePhoneNumber' . $i];
        $pref = $_POST['updatePhonePref' . $i] === 'True' ? true : false;
        $type = $_POST['updatePhoneType' . $i];
        $phonesArr[] = array('number' => $number, 'preferred' => $pref, 'type' => $type);
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
require_once __DIR__ . '/../lib/AAB/Group.php';
use Att\Api\AAB\AABService;
use Att\Api\AAB\Group;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gname = $_POST['createGroupName'];
    $group = new Group($gname);
    $location = $aabService->createGroup($group);
    $arr = array('success' => true, 'text' => $location);
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 private function _handleGetContactGroups()
 {
     $vnames = array('getContactGroups', 'contactId');
     $this->copyToSession($vnames);
     if (!isset($_SESSION['getContactGroups'])) {
         return;
     }
     $cid = $_SESSION['contactId'];
     try {
         $aabSrvc = new AABService($this->apiFQDN, $this->getSessionToken());
         $result = $aabSrvc->getContactGroups($cid);
         $this->results[C_GET_CONTACT_GROUPS] = $result;
         $this->clearSession($vnames);
     } catch (Exception $e) {
         $this->errors[C_MANAGE_GROUPS_ERROR] = $e->getMessage();
         $this->clearSession($vnames);
     }
 }
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/AAB/AABService.php';
require_once __DIR__ . '/../lib/AAB/PaginationParameters.php';
use Att\Api\AAB\AABService;
use Att\Api\AAB\PaginationParameters;
$arr = null;
try {
    envinit();
    $aabService = new AABService(getFqdn(), getSessionToken());
    $gname = $_POST['getGroupName'];
    $order = $_POST['getGroupOrder'];
    $params = new PaginationParameters();
    $params->order = $order;
    $resultSet = $aabService->getGroups($params, $gname);
    $values = array();
    $groups = $resultSet->getGroups();
    foreach ($groups as $group) {
        $values[] = array($group->getGroupId(), $group->getGroupName(), $group->getGroupType());
    }
    $tables = array(array('caption' => 'Groups:', 'headers' => array('groupId', 'groupName', 'groupType'), 'values' => $values));
    $arr = array('success' => true, 'tables' => $tables);
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}