/** expecting host name as $in_hostname
 *
 * processes a host array and sends to the hostdetails.php page
 */
function process_host_detail($in_hostname)
{
    global $NagiosData;
    global $NagiosUser;
    $hd = $NagiosData->get_details_by('host', $in_hostname);
    $hostname = $hd['host_name'];
    if (!$NagiosUser->is_authorized_for_host($hostname)) {
        return false;
    }
    //bail if not authorized
    $duration = calculate_duration($hd['last_state_change']);
    $current_state = return_host_state($hd['current_state']);
    $statetype = return_state_type($hd['state_type']);
    //calculate state
    $current_check = $hd['current_attempt'] . ' of ' . $hd['max_attempts'];
    $date_format = 'M d H:i\\:s\\s Y';
    $last_check = date($date_format, $hd['last_check']);
    $next_check = date($date_format, $hd['next_check']);
    $last_state_change = date($date_format, $hd['last_state_change']);
    if ($hd['last_notification'] == 0) {
        $last_notification = 'Never';
    } else {
        $last_notification = date($date_format, $hd['last_notification']);
    }
    $check_type = $hd['check_type'] == 0 ? 'Active' : 'Passive';
    $check_latency = $hd['check_latency'] . ' seconds';
    $execution_time = $hd['check_execution_time'] . ' seconds';
    $state_change = $hd['percent_state_change'] . '%';
    $membership = check_membership($hostname);
    $state = return_host_state($hd['current_state']);
    //host attributes
    //if else statements generate links for Nagios core commands based on status
    $active_checks = return_enabled($hd['active_checks_enabled']);
    if ($active_checks == 'Enabled') {
        $cmd_active_checks = core_function_link('DISABLE_HOST_CHECK', $hostname);
    } else {
        $cmd_active_checks = core_function_link('ENABLE_HOST_CHECK', $hostname);
    }
    $passive_checks = return_enabled($hd['passive_checks_enabled']);
    if ($passive_checks == 'Enabled') {
        $cmd_passive_checks = core_function_link('DISABLE_PASSIVE_HOST_CHECKS', $hostname);
    } else {
        $cmd_passive_checks = core_function_link('ENABLE_PASSIVE_HOST_CHECKS', $hostname);
    }
    $notifications = return_enabled($hd['notifications_enabled']);
    if ($notifications == 'Enabled') {
        $cmd_notifications = core_function_link('DISABLE_HOST_NOTIFICATIONS', $hostname);
    } else {
        $cmd_notifications = core_function_link('ENABLE_HOST_NOTIFICATIONS', $hostname);
    }
    $flap_detection = return_enabled($hd['flap_detection_enabled']);
    if ($flap_detection == 'Enabled') {
        $cmd_flap_detection = core_function_link('DISABLE_HOST_FLAP_DETECTION', $hostname);
    } else {
        $cmd_flap_detection = core_function_link('ENABLE_HOST_FLAP_DETECTION', $hostname);
    }
    $process_perf_data = return_enabled($hd['process_performance_data']);
    $obsession = return_enabled($hd['obsess_over_host']);
    if ($obsession == 'Enabled') {
        $cmd_obsession = core_function_link('STOP_OBSESSING_OVER_HOST', $hostname);
    } else {
        $cmd_obsession = core_function_link('START_OBSESSING_OVER_HOST', $hostname);
    }
    $add_comment = core_function_link('ADD_HOST_COMMENT', $hostname);
    if ($hd['problem_has_been_acknowledged'] == 0) {
        $cmd_acknowledge = core_function_link('ACKNOWLEDGE_HOST_PROBLEM', $hostname);
        $ack_title = 'Acknowledge Problem';
    } else {
        $cmd_acknowledge = core_function_link('REMOVE_HOST_ACKNOWLEDGEMENT', $hostname);
        $ack_title = 'Remove Acknowledgement';
    }
    $cmd_custom_notification = core_function_link('SEND_CUSTOM_HOST_NOTIFICATION', $hostname);
    $cmd_schedule_downtime = core_function_link('SCHEDULE_HOST_DOWNTIME', $hostname);
    $cmd_schedule_dt_all = core_function_link('SCHEDULE_HOST_SVC_DOWNTIME', $hostname);
    $cmd_schedule_checks = core_function_link('SCHEDULE_HOST_SVC_CHECKS', $hostname);
    $cmd_map = CORECGI . 'statusmap.cgi?host=' . $hostname;
    $core_link = CORECGI . 'extinfo.cgi?type=1&host=' . $hostname;
    $details = array('Host' => $hostname, 'MemberOf' => $membership, 'StatusInformation' => $hd['plugin_output'], 'State' => $current_state, 'Duration' => $duration, 'StateType' => $statetype, 'CurrentCheck' => $current_check, 'LastCheck' => $last_check, 'NextCheck' => $next_check, 'LastStateChange' => $last_state_change, 'LastNotification' => $last_notification, 'CheckType' => $check_type, 'CheckLatency' => $check_latency, 'ExecutionTime' => $execution_time, 'StateChange' => $state_change, 'PerformanceData' => $hd['performance_data'], 'ActiveChecks' => $active_checks, 'PassiveChecks' => $passive_checks, 'Notifications' => $notifications, 'FlapDetection' => $flap_detection, 'ProcessPerformanceData' => $process_perf_data, 'Obsession' => $obsession, 'AddComment' => htmlentities($add_comment), 'MapHost' => htmlentities($cmd_map), 'CmdActiveChecks' => htmlentities($cmd_active_checks), 'CmdPassiveChecks' => htmlentities($cmd_passive_checks), 'CmdNotifications' => htmlentities($cmd_notifications), 'CmdFlapDetection' => htmlentities($cmd_flap_detection), 'CmdObsession' => htmlentities($cmd_obsession), 'CmdAcknowledge' => htmlentities($cmd_acknowledge), 'CmdCustomNotification' => htmlentities($cmd_custom_notification), 'CmdScheduleDowntime' => htmlentities($cmd_schedule_downtime), 'CmdScheduleDowntimeAll' => htmlentities($cmd_schedule_dt_all), 'CmdScheduleChecks' => htmlentities($cmd_schedule_checks), 'AckTitle' => $ack_title, 'CoreLink' => htmlentities($core_link));
    return $details;
}
//  Checks that the player is a member / not a member of an alliance
//  $Requirement == true -> the player has to be in an alliance
//  $Requirement == false -> the player may NOT be in an alliance
function check_membership($requirement)
{
    global $game;
    $in_alliance = !empty($game->player['alliance_name']) ? true : false;
    if ($in_alliance && !$requirement) {
        message(NOTICE, constant($game->sprache("TEXT1")));
    }
    if (!$in_alliance && $requirement) {
        message(NOTICE, constant($game->sprache("TEXT2")));
    }
    return true;
}
check_membership(true);
$sql = 'SELECT *
            FROM alliance
            WHERE alliance_id = ' . $game->player['user_alliance'];
if (($alliance = $db->queryrow($sql)) === false) {
    message(DATABASE_ERROR, 'Could not query alliance data');
}
if ($game->player['user_alliance_rights8'] != 1 && $game->player['user_id'] != $alliance['alliance_owner']) {
    message(NOTICE, constant($game->sprache("TEXT3")));
}
if (isset($_POST['save'])) {
    $user_id = $_POST['user_id'];
    $sql = 'SELECT user_id, user_alliance FROM user WHERE user_id = ' . $user_id;
    if (($user_data = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query user alliance data');
    }
	  <td  align="center">' . $alliance['alliance_member'] . '</td>
	  <td >' . $alliance['alliance_points'] . '</td>
	  <td >' . $alliance['alliance_rank_points'] . '</td>
	
  
  ');
        if ($alliance['alliance_application'] == 1) {
            $game->out('<td >[<a href="' . parse_link('a=alliance_application&application=new&alliance=' . $alliance['alliance_id'] . '') . '"><span style="color: #00FF00;">' . constant($game->sprache("TEXT33")) . '</span></a>]</td></tr>');
        } else {
            $game->out(' <td ><span style="color: #FF0000;">' . constant($game->sprache("TEXT36")) . '</span></td></tr>');
        }
    }
    $game->out(' </table> ');
}
if (isset($_POST['application_submit'])) {
    check_membership(false);
    $sql = 'SELECT * FROM alliance WHERE alliance_id = ' . $_POST['alliance_id'];
    if (($alliance_check = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query app data');
    }
    if ($alliance_check['alliance_application'] != 1) {
        message(NOTICE, constant($game->sprache("TEXT37")));
    }
    $sql = 'SELECT * FROM alliance_application WHERE application_user = '******'user_id'];
    if (($app_data = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query alliance data');
    }
    if (!empty($app_data['application_user'])) {
        message(NOTICE, constant($game->sprache("TEXT38")));
    }
    if ($game->player['last_alliance_kick'] + 480 >= $ACTUAL_TICK && $game->player['last_alliance_kick'] != 0) {
 public function action_join()
 {
     $tournies_id = $this->request->param();
     $view = View::factory('tournament_join');
     $exclusive = DB::select('exclusive')->from('tournies')->where('tournies_id', '=', $tournies_id)->execute()->get('exclusive');
     $community = DB::select('community')->from('tournies')->where('tournies_id', '=', $tournies_id)->execute()->get('community');
     if ($exclusive && check_membership($this->user, $community) || !$exclusive) {
         if (DB::insert('tournies')->set(array('players' => $players))->where('tournies_id', '=', $tournies_id)->execute()) {
             $view->message = "Successfully joined.";
         } else {
             $view->message = "Joining failed.";
         }
         $this->template->content = $view;
     } else {
         $this->request->redirect('/tournament?exclusive');
     }
 }
function object_visibility($objectid)
{
    $visbility = get_field('view_method', $objectid);
    $userid = is_login();
    if ($visbility == 'free') {
        return true;
    }
    if ($userid === FALSE) {
        return false;
    }
    $membresia = get_field('membresia', $objectid);
    $renta = get_field('renta', $objectid);
    $compra = get_field('compra', $objectid);
    if ($renta == '' || $compra == '' || $renta == 0 || $compra == 0) {
        return true;
    }
    if (($membresia == '' || $membresia == 0) && check_membership($userid)) {
        return true;
    }
    if (check_userbuy($userid, $objectid)) {
        return true;
    }
    return false;
}