*
 * 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);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 private function _handleAddContactsToGroup()
 {
     $vnames = array('addContactsToGroup', 'groupId', 'contactIds');
     $this->copyToSession($vnames);
     if (!isset($_SESSION['addContactsToGroup'])) {
         return;
     }
     $gid = $_SESSION['groupId'];
     $cids = $_SESSION['contactIds'];
     $cids = explode(",", $cids);
     try {
         $aabSrvc = new AABService($this->apiFQDN, $this->getSessionToken());
         $aabSrvc->addContactsToGroup($gid, $cids);
         $this->results[C_ADD_CONTACTS_TO_GROUP] = true;
         $this->clearSession($vnames);
     } catch (Exception $e) {
         $this->errors[C_MANAGE_GROUPS_ERROR] = $e->getMessage();
         $this->clearSession($vnames);
     }
 }