select('id') ->whereIn('gid', zmAuthGids) ->get() ->toArray(); foreach ($zmAuthPIDsObj as $zmAuthPID) { array_push($zmAuthPIDs, $zmAuthPID->id); } $hostingIDs = array(); $hostingIDsObj = Capsule::table('tblhosting') ->select('id') ->whereIn('packageid', $zmAuthPIDs) ->get() ->toArray(); foreach ($hostingIDsObj as $hostingID) { array_push($hostingIDs, $hostingID->id); } $customfieldIDs = array(); $customfieldIDsObj = Capsule::table('tblcustomfields') ->select('id') ->whereIn('relid', $zmAuthPIDs) ->where('fieldname', 'LIKE', 'username%') ->orWhere('fieldname', 'LIKE', 'maildomain%') ->get() ->toArray(); foreach ($customfieldIDsObj as $customfieldID) { array_push($customfieldIDs, $customfieldID->id); } $reservedAddresses = array(); $customfieldsvaluesObj = Capsule::table('tblcustomfieldsvalues') ->select('value') ->whereIn('relid', $hostingIDs) ->whereIn('fieldid', $customfieldIDs) ->get() ->toArray(); $i = 0; while ($i < count($customfieldsvaluesObj)) { $mailname = $customfieldsvaluesObj[$i]->value; $i++; $maildomain = $customfieldsvaluesObj[$i]->value; $i++; $reservedAddress = $mailname . '@' . $maildomain; array_push($reservedAddresses, $reservedAddress); } if(in_array($accountName, $reservedAddresses)) { echo 'no'; exit(); } // check active Zimbra Accounts $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => ''); $serverGroupIDObj = Capsule::table('tblproducts') ->select('servergroup') ->where('id', '=', $productID) ->get(); $serverGroupID = $serverGroupIDObj[0]->servergroup; $serverIDObj = Capsule::table('tblservergroupsrel') ->select('serverid') ->where('groupid', '=', $serverGroupID) ->get(); $serverID = $serverIDObj[0]->serverid; $server = Capsule::table('tblservers') ->select('hostname', 'username', 'password') ->where('id', '=', $serverID) ->where('active', '=', 1) ->get(); $accessData['zimbraServer'] = $server[0]->hostname; $accessData['adminUser'] = $server[0]->username; $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $server[0]->password)); if ($adminPassDecrypt['result'] == 'success') { $accessData['adminPass'] = $adminPassDecrypt['password']; } $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], 'admin'); $login = $api->login(); if(is_a($login, 'Exception')) { logModuleCall( 'zimbrasingle', __FUNCTION__, $accessData, 'Error: cannot login to ' . $accessData['zimbraServer'], $login->getMessage() ); exit(); } else { $apiAccountManager = new Zm_Account($api); if( $apiAccountManager->accountExists($accountName)) { echo 'no'; } else { echo 'yes'; } }