vpx_acl_group_hostname_add

Versions
mediamosa-174
vpx_acl_group_hostname_add($a_args)

REST CALL | POST

Parameters

array $a_args

Return value

object

Code

vpx_acl/vpx_acl.module, line 267

<?php
function vpx_acl_group_hostname_add($a_args) {

  try {
    vpx_funcparam_add($a_funcparam, $a_args, 'app_id', VPX_TYPE_INT, TRUE);

    vpx_funcparam_add_uri($a_funcparam, $a_args, 'groupname', VPX_TYPE_STRING, TRUE);

    vpx_funcparam_add_post_array($a_funcparam, $a_args, 'hostname', VPX_TYPE_STRING, TRUE);

    $app_id = vpx_funcparam_get_value($a_funcparam, 'app_id');
    $s_groupname = vpx_funcparam_get_value($a_funcparam, 'groupname');

    vpx_shared_must_exist("aut_group", array("app_id" => $app_id, "aut_group_name" => $s_groupname));

    $o_rest_reponse = new rest_response(vpx_return_error(ERRORCODE_OKAY));

    $a_hostname = vpx_funcparam_get_value($a_funcparam, 'hostname');

    db_set_active('data');
    $a_group = db_fetch_array(db_query("SELECT aut_group_id, aut_group_type FROM {aut_group} WHERE app_id=%d AND aut_group_name='%s'", $app_id, $s_groupname));
    db_set_active();

    $aut_group_id = $a_group['aut_group_id'];
    $host_type_group = $a_group['aut_group_type'];

    if (!$aut_group_id) {
      throw new vpx_exception_error_aut_group_not_found(array("@group" => $s_groupname));
    }

    foreach ($a_hostname as $s_hostname) {
      $s_hostname = trim($s_hostname);

      $host_type_tmp = (vpx_acl_is_realm($s_hostname) ? 'REALM' : 'DOMAIN');

      if ($host_type_tmp != $host_type_group) {
        $error = vpx_return_error(ERRORCODE_HOSTNAME_TYPE_NO_MATCH_GROUP_TYPE, array('@hostname' => $s_hostname, '@hostname_type' => $host_type_tmp, '@group' => $s_groupname, '@group_type' => $host_type_group));
        $o_rest_reponse->add_item(array(
        'hostname' => $s_hostname,
        'result' => $error['status'],
        'result_id' => $error['id'],
        'result_description' => $error['description'],
        ));

        // Dont add it
        continue;
      }

      if (vpx_shared_count_rows("aut_name", array("app_id" => $app_id, "aut_type" => $host_type_group, "aut_group_id" => $aut_group_id, "aut_name" => $s_hostname))) {
        $error = vpx_return_error(ERRORCODE_HOSTNAME_ALREADY_IN_GROUP, array('@hostname' => $s_hostname, '@group' => $s_groupname));
        $o_rest_reponse->add_item(array(
        'hostname' => $s_hostname,
        'result' => $error['status'],
        'result_id' => $error['id'],
        'result_description' => $error['description'],
        ));
      }
      else {
        db_set_active('data');
        db_query("INSERT INTO {aut_name} SET app_id=%d, aut_type='%s', aut_group_id=%d, aut_name='%s'", $app_id, $host_type_group, $aut_group_id, $s_hostname);
        db_set_active();
        $o_rest_reponse->add_item(array(
        'hostname' => $s_hostname,
        'result' => ERRORMESSAGE_OKAY,
        'result_id' => ERRORCODE_OKAY,
        'result_description' => '',
        ));
      }
    }

    return $o_rest_reponse;
  }
  catch (vpx_exception $e) {
    return $e->vpx_exception_rest_response();
  }
}
?>