diff -Nur ./include/defines.inc.php /usr/share/zabbix/include/defines.inc.php
--- ./include/defines.inc.php	2012-12-08 12:09:20.000000000 +0100
+++ /usr/share/zabbix/include/defines.inc.php	2012-12-27 22:46:46.934291589 +0100
@@ -458,6 +458,11 @@
 		"Device service uptime: {DISCOVERY.SERVICE.UPTIME}"
 );
 
+define('SUCCEED',      1);
+define('FAIL',         0);
+define('MEDIA_STATUS_ACTIVE',         0);
+
+
 define('ACTION_STATUS_ENABLED',		0);
 define('ACTION_STATUS_DISABLED',	1);
 
diff -Nur ./include/menu.inc.php /usr/share/zabbix/include/menu.inc.php
--- ./include/menu.inc.php	2012-12-08 12:09:18.000000000 +0100
+++ /usr/share/zabbix/include/menu.inc.php	2012-12-27 12:55:07.898311698 +0100
@@ -174,6 +174,7 @@
 					'tr_logform.php',
 					'tr_testexpr.php',
 					'popup_trexpr.php',
+					'popup_action.php',
 					'host_discovery.php',
 					'disc_prototypes.php',
 					'trigger_prototypes.php'
diff -Nur ./include/views/configuration.triggers.list.php /usr/share/zabbix/include/views/configuration.triggers.list.php
--- ./include/views/configuration.triggers.list.php	2012-12-08 12:09:17.000000000 +0100
+++ /usr/share/zabbix/include/views/configuration.triggers.list.php	2012-12-29 01:36:25.967373015 +0100
@@ -95,7 +95,8 @@
 	make_sorting_header(_('Name'), 'description', $link),
 	_('Expression'),
 	make_sorting_header(_('Status'), 'status', $link),
-	empty($this->data['parent_discoveryid']) ? _('Error') : null
+	empty($this->data['parent_discoveryid']) ? _('Error') : null,
+	empty($this->data['action_test']) ? _('Action?') : null
 ));
 foreach ($this->data['triggers'] as $tnum => $trigger) {
 	$triggerid = $trigger['triggerid'];
@@ -192,6 +193,17 @@
 		$status = new CLink(_('Enabled'), $status_link, 'enabled');
 	}
 
+        # TODO: Don't show for templates
+        if ($trigger['status'] == TRIGGER_STATUS_ENABLED) {
+                $action_test = new CButton('actions', _('Actions?'), 'return PopUp("popup_action.php?dstfrm=action&triggerid='.$triggerid.'", 700, 500);', 'link_menu');
+        }
+        # Trigger disabled or on a template
+        elseif ($trigger['status'] == TRIGGER_STATUS_DISABLED)  {
+                $action_test = null;
+        }
+
+
+
 	$hosts = null;
 	if (empty($this->data['hostid'])) {
 		foreach ($trigger['hosts'] as $hostid => $host) {
@@ -215,7 +227,8 @@
 		$description,
 		$expressionColumn,
 		$status,
-		$error
+		$error,
+		$action_test
 	));
 	$triggers[$tnum] = $trigger;
 }
diff -Nur ./popup_action.php /usr/share/zabbix/popup_action.php
--- ./popup_action.php	1970-01-01 01:00:00.000000000 +0100
+++ /usr/share/zabbix/popup_action.php	2013-01-02 14:27:07.458296046 +0100
@@ -0,0 +1,870 @@
+<?php
+/*
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+**/
+
+
+require_once dirname(__FILE__).'/include/actions.inc.php';
+require_once dirname(__FILE__).'/include/config.inc.php';
+require_once dirname(__FILE__).'/include/triggers.inc.php';
+require_once dirname(__FILE__).'/include/forms.inc.php';
+require_once dirname(__FILE__).'/include/perm.inc.php';
+require_once dirname(__FILE__).'/include/js.inc.php';
+
+$page['title'] = _('Action simulator');
+$page['file'] = 'popup_action.php';
+$page['scripts'] = array('class.calendar.js');
+
+
+define('ZBX_PAGE_NO_MENU', 1);
+
+require_once dirname(__FILE__).'/include/page_header.php';
+
+if ($USER_DETAILS['alias'] == ZBX_GUEST_USER) {
+	access_deny();
+}
+
+//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
+$fields = array(
+	'dstfrm'=>		array(T_ZBX_STR, O_MAND,P_SYS,	NOT_EMPTY,		NULL),
+	'triggerid'=>		array(T_ZBX_INT, O_MAND,P_SYS,	NOT_EMPTY,		NULL),
+	'maint'=>			array(T_ZBX_INT, O_OPT,	P_SYS,	IN('0,1'),	NULL),
+	'close'=>				array(T_ZBX_INT, O_OPT,	NULL,	IN('1'),	NULL),
+	'open'=>				array(T_ZBX_INT, O_OPT,	NULL,	IN('1'),	NULL),
+
+/* other */
+	'form'=>		array(T_ZBX_STR, O_OPT, P_SYS,	NULL,	NULL),
+);
+
+check_fields($fields);
+
+
+if (!isset($_REQUEST['maint'])) {
+	$_REQUEST['maint'] = 0;
+}
+
+if(isset($_REQUEST['open'])){
+	$showAll = 1;
+}
+else{
+	$hideAll = 1;
+}
+
+if(isset($showAll)){
+	$url = '?close=1'.
+		url_param('groupid').
+		url_param('hostid').
+		url_param('select');
+	$link = new CLink(new CImg('images/general/minus.png'),$url);
+}
+else{
+	$url = '?open=1'.
+		url_param('groupid').
+		url_param('hostid').
+		url_param('select');
+	$link = new CLink(new CImg('images/general/plus.png'),$url);
+}
+
+
+$triggerid = get_request('triggerid');
+$period = get_request('period', ZBX_DEFAULT_INTERVAL);
+
+$debug = array();
+$debug_messaging = array();
+
+function action_evaltype2str($evaltype) {
+    $str_type[ACTION_EVAL_TYPE_AND_OR] = 'AND/OR';
+    $str_type[ACTION_EVAL_TYPE_AND] = 'AND';
+    $str_type[ACTION_EVAL_TYPE_OR] = 'OR';
+
+    if (isset($str_type[$evaltype])) {
+        return $str_type[$evaltype];
+    }    
+
+    return _('Unknown');
+}
+        
+    //Possible reasons for operations to fail
+    //System -- per user
+    //Host -- per trigger
+    //Severity -- per trigger
+    //Time -- per trigger time and media settings
+    //Media not defined
+    //Medium inactive
+
+function process_actions($data) {
+    //TODO: Only works properly for Super Admins, because there are permission restrictions
+	$actions = API::Action()->get(array(
+            'selectConditions' => API_OUTPUT_EXTEND,
+            'selectOperations' => API_OUTPUT_EXTEND,
+            'output' => API_OUTPUT_EXTEND,
+	        'filter' => array('status' => '0', 'eventsource' => '0'),
+	));
+
+    $valid_actions = array();
+    foreach ($actions as $action) {
+        if (action_conditions($action, $data) == SUCCEED) {
+            $valid_actions[] = $action;
+            
+            $actionid = $action['actionid'];
+        }
+    }
+
+    $notifications = execute_operations($data['hosts'][0]['hostid'], $data['priority'], $valid_actions);
+    
+    return $notifications;
+}
+
+
+function action_conditions($action, $data) {
+        
+    global $debug;
+
+    $exit = 0;
+    $old_type = -1;
+    $cond = -1;
+    $ret = SUCCEED;
+    $conditiontypes = array();
+    
+    //Sort by conditiontype within the action, otherwise evaluation can fail
+    foreach ($action['conditions'] as $condition) {
+        $conditiontypes[] = $condition['conditiontype'];
+    }
+
+    array_multisort($conditiontypes, SORT_ASC, $action['conditions']);
+
+    $actionid = $action['actionid'];
+    $debug[$actionid] = array('name' => $action['name'], 'evaltype' => $action['evaltype']);
+
+    foreach ($action['conditions'] as $condition) {
+        $conditionid = $condition['conditionid'];
+        if ($exit == 0) {
+            switch ($action['evaltype']) {
+                case ACTION_EVAL_TYPE_AND_OR:
+                    // OR part of conditions
+                    if ($old_type == $condition['conditiontype']) {
+                        if (check_trigger_condition($condition, $data) == SUCCEED) {
+                            $ret = SUCCEED;
+                        }
+                    }
+                    // AND part of conditions
+                    else {
+                        // Break if PREVIOUS AND condition is FALSE
+                        if ($ret == FAIL) {
+                            $exit = 1;
+                        }
+                        //HIER könnte das Problem liegen
+                        elseif (check_trigger_condition($condition, $data) == FAIL) {
+                            $ret = FAIL;
+                        }
+                    }
+
+                    $old_type = $condition['conditiontype'];
+
+                    break;
+                
+                case ACTION_EVAL_TYPE_AND:
+                    $cond = check_trigger_condition($condition, $data);
+                    // break if any AND condition is FALSE
+                    if ($cond == FAIL) {
+                        $ret = FAIL;
+                        $exit = 1;
+                    }
+                    else {
+                        $ret = SUCCEED;
+                    }
+                    
+                    break;
+
+                case ACTION_EVAL_TYPE_OR:
+                    $cond = check_trigger_condition($condition, $data);
+                    // break if any OR condition is TRUE
+                    if ($cond == SUCCEED) {
+                        $ret = SUCCEED;
+                        $exit = 1;
+                    }
+                    else {
+                        $ret = FAIL;
+                    }
+                    
+                    break;
+            }
+        }
+        elseif ($exit == 1) {
+            break;
+        }
+    }
+    return $ret;
+}
+
+
+function check_trigger_condition($condition, $data){
+    
+    //DEBUG
+    global $debug;
+    $actionid = $condition['actionid'];
+    $conditionid = $condition['conditionid'];
+    $debug[$actionid]['conditions'][$conditionid]['conditiontype'] = $condition['conditiontype'];
+    $debug[$actionid]['conditions'][$conditionid]['operator'] = $condition['operator'];
+    $debug[$actionid]['conditions'][$conditionid]['conditionvalue'] = $condition['value'];
+    
+    $ret = FAIL;
+
+    if ($condition['conditiontype'] == CONDITION_TYPE_HOST_GROUP) {
+
+        $condition_matches = API::Trigger()->get(array(
+                'groupids' => array($condition['value']),
+                'triggerids' => array($data['triggerid'])
+        ));
+
+        //TODO: Debugging needs work here
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+                if ($condition_matches) {
+                    $ret = SUCCEED;
+                }
+                $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = 'Something matching';
+                break;
+            case CONDITION_OPERATOR_NOT_EQUAL:
+                if (!$condition_matches) {
+                    $ret = SUCCEED;
+                }
+                $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = 'Something not matching';
+                break;
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_HOST_TEMPLATE) {
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+            case CONDITION_OPERATOR_NOT_EQUAL:
+                $triggerid = $data['triggerid'];
+
+                //Loop until you hit the template
+                while ($ret != SUCCEED and $triggerid != 0){
+                    $condition_matches = API::Trigger()->get(array(
+                            'triggerids' => $triggerid,
+                            'selectHosts' => API_OUTPUT_EXTEND,
+                            'output' => API_OUTPUT_EXTEND,
+                    ));
+                    $condition_matches = reset($condition_matches);
+                    if ($condition_matches) {
+
+                        $triggerid = $condition_matches['templateid'];
+                        $debug[$actionid]['conditions'][$conditionid]['actualvalue'][] = $triggerid;
+
+                        if ($condition_matches['hosts'][0]['hostid'] == $condition['value']) {
+                            $ret = SUCCEED;
+                            break;
+                        }
+                    }
+                    else {
+                        $triggerid = 0;
+                    }
+                }
+                if ($condition['operator'] == CONDITION_OPERATOR_NOT_EQUAL) {
+                    $ret = ($ret == SUCCEED) ? FAIL : SUCCEED;
+                break;
+                }
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_HOST) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $data['hosts'][0]['hostid'];
+
+        if ($data['hosts'][0]['hostid'] == $condition['value']) {
+            $condition_matches = 1;
+        }
+        else {
+            $condition_matches = 0;
+        }
+
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+                if ($condition_matches == 1){
+                    $ret = SUCCEED;}
+                break;
+            case CONDITION_OPERATOR_NOT_EQUAL:
+                if ($condition_matches == 0){
+                    $ret = SUCCEED;}
+                break;
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_TRIGGER) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $data['triggerid'];
+
+        if ($data['triggerid'] == $condition['value']) {
+            $condition_matches = 1;
+        }
+        else {
+            $condition_matches = 0;
+        }
+
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+                if ($condition_matches == 1)
+                    $ret = SUCCEED;
+                break;
+            case CONDITION_OPERATOR_NOT_EQUAL:
+                if ($condition_matches == 0)
+                    $ret = SUCCEED;
+                break;
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_TRIGGER_NAME) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $data['description'];
+
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_LIKE:
+                if (strstr($data['description'], $condition['value'])) {
+                    $ret = SUCCEED;
+                }
+                break;
+            case CONDITION_OPERATOR_NOT_LIKE:
+                if (!strstr($data['description'], $condition['value'])) {
+                    $ret = SUCCEED;
+                }
+                break;
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_TRIGGER_SEVERITY) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $data['priority'];
+
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+                if ($data['priority'] == $condition['value']) {
+                    $ret = SUCCEED;
+                }
+                break;
+            case CONDITION_OPERATOR_NOT_EQUAL:
+                if ($data['priority'] != $condition['value']) {
+                    $ret = SUCCEED;
+                }
+                break;
+            case CONDITION_OPERATOR_MORE_EQUAL:
+                if ($data['priority'] >= $condition['value']) {
+                    $ret = SUCCEED;
+                }
+                break;
+            case CONDITION_OPERATOR_LESS_EQUAL:
+                if ($data['priority'] <= $condition['value']) {
+                    $ret = SUCCEED;
+                }
+                break;
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_TRIGGER_VALUE) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = 'Don\'t care';
+
+        //TODO: Not implemented yet; should only be relevant for recovery messages
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+                break;
+        }
+        $ret = SUCCEED;
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_TIME_PERIOD) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = 'Don\'t care';
+        
+        //TODO: Not implemented yet
+        //TODO: Implement a check_time_period function
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_IN:
+                break;
+            case CONDITION_OPERATOR_NOT_IN:
+                break;
+        }
+        $ret = SUCCEED;
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_MAINTENANCE) {
+
+        $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $_REQUEST['maint'];
+
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_IN:
+	            if ($_REQUEST['maint'] == HOST_MAINTENANCE_STATUS_ON) {
+                    $ret = SUCCEED;
+                }
+                break;
+            case CONDITION_OPERATOR_NOT_IN:
+	            if ($_REQUEST['maint'] == HOST_MAINTENANCE_STATUS_OFF) {
+                    $ret = SUCCEED;
+                }
+                break;
+        }
+    }
+    elseif ($condition['conditiontype'] == CONDITION_TYPE_APPLICATION) {
+        $items = array_map(function($item) {return $item['itemid'];}, $data['items']);
+        //No output customization possible
+        $applications = API::Application()->get(array(
+            'itemids' => $items,
+	        'output' => API_OUTPUT_EXTEND,
+            ));
+
+        switch ($condition['operator']) {
+            case CONDITION_OPERATOR_EQUAL:
+                foreach ($applications as $app) {
+                   $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $app['name'];
+                   if (strcmp($app['name'], $condition['value']) == 0){
+                       $ret = SUCCEED;
+                       break;
+                   }
+                }
+                break;
+            case CONDITION_OPERATOR_LIKE:
+                foreach ($applications as $app) {
+                   $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $app['name'];
+                   if (strstr($app['name'], $condition['value'])){
+                       $ret = SUCCEED;
+                       break;
+                   }
+                }
+                break;
+            case CONDITION_OPERATOR_NOT_LIKE:
+                $ret = SUCCEED;
+                foreach ($applications as $app) {
+                   $debug[$actionid]['conditions'][$conditionid]['actualvalue'] = $app['name'];
+                   if (strstr($app['name'], $condition['value'])){
+                       $ret = FAIL;
+                       break;
+                   }
+                }
+                break;
+        }
+    }
+
+    $debug[$actionid]['conditions'][$conditionid]['status'] = $ret;
+
+    return $ret;
+}
+
+
+// Operations
+function get_host_permissions($userid, $hostid) {
+    // Make sure host is readable to the specified user
+    //
+    // 
+
+    $user = API::User()->get(array(
+        'userids' => $userid,
+        'output' => API_OUTPUT_EXTEND
+    ));
+    $user = reset($user);
+
+    if ($user['type'] == USER_TYPE_SUPER_ADMIN) {
+        $ret = SUCCEED;
+        return $ret;
+    }
+    //Found nothing fitting in API and present functions
+    //get_accessible_hosts_by_user
+    //get_accessible_groups_by_user
+    //get_accessible_hosts_by_rights
+    //get_accessible_groups_by_rights
+
+    $sql = 'SELECT MIN(r.permission)'.
+           ' FROM rights r, hosts_groups hg, users_groups ug'.
+           ' WHERE r.groupid=ug.usrgrpid'.
+            ' AND r.id=hg.groupid'.
+            ' AND hg.hostid='.$hostid.
+            ' AND ug.userid='.$userid;
+    $permission = DBfetch(DBselect($sql));
+    //TODO: Gertjan: It seems like the result of this query can be invalid, but I wonder why. Possibly a result of just being a Zabbix Admin user type?
+    if ($permission AND $permission['min'] > PERM_DENY) {
+        $ret = SUCCEED;
+    }
+    else {
+        $ret = FAIL;
+    }
+
+    return $ret;
+}
+
+
+function add_user_msg($hostid, $earlier_results) {
+    //Check user's system and host permissions
+    //
+    //Returns list of resulting notifications so far
+
+    global $debug_messaging;
+
+    $preliminary_results = array();
+
+    //User is enabled and allowed to receive notification for this host
+    foreach ($earlier_results as $earlier_result) {
+        $userid = $earlier_result['userid'];
+
+        if (!check_perm2system($userid)) {
+            //Debug
+            $debug_message = $earlier_result;
+            $debug_message['error'] = 'User is not allowed to access Zabbix';
+            $debug_messaging[] = $debug_message;
+            continue;
+        }
+        
+        if (get_host_permissions($userid, $hostid) == SUCCEED) {
+            $preliminary_results[] = $earlier_result;
+        }
+        else {
+            $debug_message = $earlier_result;
+            $debug_message['error'] = 'Host permissions';
+            $debug_message['mediatypeid'] = '';
+            $debug_message['sendto'] = '';
+            $debug_messaging[] = $debug_message;
+        }
+    }
+    return $preliminary_results;
+}
+
+
+function add_object_msg($hostid, $priority, $action_name, $operation) {
+    //Resolve user groups in operations and create preliminary results
+
+    //TODO: Should rather be "resultS"
+    $preliminary_result = array();
+    $mediatypeid = $operation['opmessage']['mediatypeid'];
+
+    //Operations on per user-group basis
+    if ($operation['opmessage_grp']) {
+        $usergroups = array_map(function($item) {return $item['usrgrpid'];}, $operation['opmessage_grp']);
+
+        //Multiple user groups can be specified per operation
+        //TODO: Merge branches
+        foreach ($usergroups as $usergroup) {
+            $users = API::UserGroup()->get(array(
+                'usrgrpids' => $usergroup,
+                'selectUsers' => API_OUTPUT_EXTEND
+            ));
+            $users = reset($users);
+            foreach ($users['users'] as $user) {
+                //actionid and operationid are only for debugging
+                $preliminary_result[] = array('operationid' => $operation['operationid'], 'actionid' => $operation['actionid'], 'action_name' => $action_name, 'alias' => $user['alias'], 'userid' => $user['userid'], 'reason' => 'Group', 'mediatypeid' => $mediatypeid);
+            }
+        }
+    }
+
+    //Operations on per user basis
+    if ($operation['opmessage_usr']) {
+        //var_dump($operation['opmessage_usr']);
+        $users = array_map(function($item) {return $item['userid'];}, $operation['opmessage_usr']);
+
+        //Multiple users can be specified per operation
+        //TODO: Geschachtelte Schleifen, die die gleichen Variablennamen verwenden
+        foreach ($users as $user) {
+            $users = API::User()->get(array(
+                'userids' => $user,
+                'output' => API_OUTPUT_EXTEND
+            ));
+            //var_dump($users);
+
+            foreach ($users as $user) {
+                //actionid and operationid are only for debugging
+                //Mittlerweile unnötig
+                $preliminary_result[] = array('operationid' => $operation['operationid'], 'actionid' => $operation['actionid'], 'action_name' => $action_name, 'alias' => $user['alias'], 'userid' => $user['userid'], 'reason' => 'User', 'mediatypeid' => $mediatypeid);
+            }
+        }
+    }
+    $notifications = add_user_msg($hostid, $preliminary_result);
+    //TODO: Check for empty arrays
+    return $notifications;
+}
+
+
+function add_message_alert($priority, $preliminary_results) {
+    // Resolves effective media types for users and user groups,
+    // if no specific media type was specified
+    //TODO: Ignoring temporal restrictions for now
+
+    //DEBUG
+    global $debug_messaging;
+
+    $results = array();
+
+    //Mediatype active system-wide?
+    $mediatypes = API::Mediatype()->get(array(
+        'output' => API_OUTPUT_EXTEND,
+        'filter' => array('status' => 0),
+        'preservekeys' => '1'
+    ));
+
+    foreach ($preliminary_results as $preliminary_result) {
+        if ($preliminary_result['mediatypeid'] == 0) {
+            //No specific media type given
+            //TODO: Don't use the filter to allow better debugging
+            $usermedias = API::UserMedia()->get(array(
+                'userids' => $preliminary_result['userid'],
+                'filter' => array('active' => MEDIA_STATUS_ACTIVE),
+                'output' => API_OUTPUT_EXTEND
+            ));
+        }
+        else {
+            //Specific media type given
+            $usermedias = API::UserMedia()->get(array(
+                'userids' => $preliminary_result['userid'],
+                'filter' => array('active' => MEDIA_STATUS_ACTIVE),
+                'mediatypeids' => $preliminary_result['mediatypeid'],
+                'output' => API_OUTPUT_EXTEND
+            ));
+        }
+
+        if ($usermedias) {
+            foreach ($usermedias as $usermedia) {
+
+                $sendto = $usermedia['sendto'];
+                if (array_key_exists($usermedia['mediatypeid'],$mediatypes)) {
+                    $mediatype = $mediatypes[$usermedia['mediatypeid']]['description'];
+                }
+
+                if((1 << $priority & $usermedia['severity']) == 0) {
+
+                    //Debug
+                    $debug_message = $preliminary_result;
+                    $debug_message['error'] = 'Severity doesn\'t match media type settings';
+                    $debug_message['mediatypeid'] = $mediatype;
+                    $debug_message['sendto'] = $sendto;
+                    $debug_messaging[] = $debug_message;
+
+                    continue;
+                }
+
+                //Debugging doesn't work here yet
+                //if (!$usermedia) {
+
+                //    //Debug
+                //    $debug_message = $preliminary_result;
+                //    $debug_message['error'] = 'Media type not defined for user';
+                //    $debug_message['mediatypeid'] = $mediatype;
+                //    $debug_message['sendto'] = '';
+                //    $debug_messaging[] = $debug_message;
+                //    continue;
+                //}
+
+                $preliminary_result['mediatypeid'] = $mediatype;
+                $preliminary_result['sendto'] = $sendto;
+
+                $results[] = $preliminary_result;
+            }
+        }
+        else {
+            //Debug
+            $debug_message = $preliminary_result;
+            $debug_message['error'] = 'Media type not defined for user';
+            $debug_message['mediatypeid'] = $mediatype;
+            $debug_message['sendto'] = '';
+            $debug_messaging[] = $debug_message;
+        }
+    }
+    return $results;
+}
+
+
+function execute_operations($hostid, $priority, $actions) {
+    // Escalation belongs here
+
+    $result = array();
+
+    foreach ($actions as $action) {
+        foreach ($action['operations'] as $operation) {
+            // Messaging
+            if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE) {
+                $result = array_merge(add_object_msg($hostid, $priority, $action['name'], $operation), $result);
+            }
+        }
+    }
+    
+    $final = add_message_alert($priority, $result);
+    return $final;
+}
+
+
+//////////////////////
+
+$data = API::Trigger()->get(array(
+	'triggerids' => $triggerid,
+    'expandDescription' => '1',
+	'output' => API_OUTPUT_EXTEND,
+	'selectGroups' => API_OUTPUT_EXTEND,
+	'selectHosts' => API_OUTPUT_EXTEND,
+	'selectItems' => API_OUTPUT_EXTEND,
+	'selectFunctions' => API_OUTPUT_EXTEND,
+	'selectDependencies' => API_OUTPUT_EXTEND,
+	'selectDiscoveryRule' => API_OUTPUT_EXTEND
+));
+$data = reset($data);
+
+$frmAction = new CFormTable(_('Actions and notifications'));
+$frmAction->setName('frmAction');
+$frmAction->addVar('dstfrm', $_REQUEST['dstfrm']);
+$frmAction->addVar('triggerid', $_REQUEST['triggerid']);
+
+$trigger = $data['description'];
+$description = array();
+
+// Taken from include/views/configuration.triggers.list.php
+$dependencies = $data['dependencies'];
+if (count($dependencies) > 0) {
+	foreach ($dependencies as $dep_trigger) {
+
+		$db_hosts = get_hosts_by_triggerid($dep_trigger['triggerid']);
+		while ($host = DBfetch($db_hosts)) {
+			$description[] = $host['name'];
+			$description[] = ', ';
+		}
+		array_pop($description);
+		$description[] = ' : ';
+		$description[] = $dep_trigger['description'];
+        $description[] = BR();
+	}
+}
+
+
+$notifications = process_actions($data);
+
+
+$trigger_table = new CTableInfo(_('No trigger -- something went wrong'));
+$notification_table = new CTableInfo(_('No notification'));
+$debug_table = new CTableInfo(_('No actions found'));
+$debug_messaging_table = new CTableInfo(_('No messaging considered'));
+
+$frmAction->addVar('trigger_at', date('YmdHi'));
+
+$calendarIcon = new CImg('images/general/bar/cal.gif', 'calendar', 16, 12, 'pointer'); 
+$calendarIcon->addAction('onclick', 'javascript: var pos = getPosition(this); pos.top += 10; pos.left += 16; CLNDR["trigger_at"].clndr.clndrshow(pos.top, pos.left); CLNDR["trigger_at"].clndr.clndrhide();');
+$triggerAtDay = new CNumericBox('trigger_at_day', date('d'), 2);
+$triggerAtDay->setAttribute('placeholder', _('dd'));
+$triggerAtMonth = new CNumericBox('trigger_at_month', date('m'), 2);
+$triggerAtMonth->setAttribute('placeholder', _('mm'));
+$triggerAtYear = new CNumericBox('trigger_at_year', date('Y'), 4);
+$triggerAtYear->setAttribute('placeholder', _('yyyy'));
+$triggerAtHour = new CNumericBox('trigger_at_hour', date('H'), 2);
+$triggerAtHour->setAttribute('placeholder', _('hh'));
+$triggerAtMinute = new CNumericBox('trigger_at_minute', date('i'), 2);
+
+$maintenanceFormList = new CFormList('maintenanceFormList');
+$maintenanceForm = array($triggerAtDay, '/', $triggerAtMonth, '/', $triggerAtYear, SPACE, $triggerAtHour, ':', $triggerAtMinute, $calendarIcon);
+zbx_add_post_js('create_calendar(null, ["trigger_at_day", "trigger_at_month", "trigger_at_year", "trigger_at_hour", "trigger_at_minute"], "trigger_at", "trigger_at");');
+
+$trigger_table->addRow(array('Host', $data['hosts'][0]['host']));
+$trigger_table->addRow(array('Trigger', $trigger));
+$trigger_table->addRow(array('Severity', getSeverityCell($data['priority'])));
+$trigger_table->addRow(array(_('Maintenance'), new CCheckbox('maint', $_REQUEST['maint'], null, 1)));
+$trigger_table->addRow(array(_('Trigger time'), $maintenanceForm));
+if ($description) {
+    $trigger_table->addRow(array(_('Depends on'), $description));
+}
+
+$notification_table->setHeader(array(
+	_('Action name'),
+	_('Media type'),
+	_('Alias'),
+	_('Send To'),
+	_('Reason')
+));
+
+$debug_table->setHeader(array(
+	$link,
+	_('Action name'),
+	_('Eval type'),
+	_('Condition type'),
+	_('Operator'),
+	_('Condition Value'),
+	_('Trigger Value'),
+	_('Result')
+));
+
+$debug_messaging_table->setHeader(array(
+	_('Action name'),
+	_('Media type'),
+	_('Alias'),
+	_('Send To'),
+	_('Reason'),
+	_('Failed step'),
+));
+
+if ($notifications) {
+    foreach ($notifications as $notification) {
+        //TODO: Process here
+        $notification_table->addRow(array(
+            $notification['action_name'],
+            $notification['mediatypeid'],
+            $notification['alias'],
+            $notification['sendto'],
+            $notification['reason']
+            ));
+    }
+}
+
+foreach ($debug as $row) {
+    foreach ($row['conditions'] as $condition) {
+        if ($condition['status'] == SUCCEED) {
+            //TODO: Irgendwie ist das verkehrt; Womöglich ist das Exit
+            $status = new CSpan($condition['status'], 'off');
+        }
+        else {
+            $status = new CSpan($condition['status'], 'on');
+        }
+        
+
+        $debug_table->addRow(array(
+            $link,
+            $row['name'],
+            action_evaltype2str($row['evaltype']),
+            condition_type2str($condition['conditiontype']),
+            condition_operator2str($condition['operator']),
+            $condition['conditionvalue'],
+            $condition['actualvalue'],
+            $status
+            ));
+    }
+}
+
+foreach ($debug_messaging as $row) {
+    $debug_messaging_table->addRow(array(
+        $row['action_name'],
+        $row['mediatypeid'],
+        $row['alias'],
+        $row['sendto'],
+        $row['reason'],
+        $row['error']
+    ));
+}
+
+$trigger_widget = new CUIWidget('trigger', $trigger_table);
+$trigger_widget->setHeader(_('Trigger details'));
+
+$notification_widget = new CUIWidget('notifications', $notification_table, 1, 1);
+$notification_widget->setHeader(_('Notifications'));
+
+$mdebug_widget = new CUIWidget('messaging_debug', $debug_messaging_table, 0, 1);
+$mdebug_widget->setHeader(_('Notification mismatch'));
+
+$debug_widget = new CUIWidget('action_debug', $debug_table, 0, 1);
+$debug_widget->setHeader(_('Action conditions match'));
+
+$div = new CDiv(array($trigger_widget, $notification_widget, $mdebug_widget, $debug_widget), 'column');
+$frmAction->addRow($div);
+
+//IDEA: Escalation could be integrated by offering a time slider and re-evaluate on that basis.
+
+$frmAction->addItemToBottomRow(array(
+	new CSubmit('re_eval', _('Re-evaluate')),
+	new CButton('close', _('Close'),'javascript: self.close();')
+));
+$frmAction->Show();
+
+require_once dirname(__FILE__).'/include/page_footer.php';
