array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL),
"group_serviceid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL),
'name'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save_service})'),
'algorithm'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1,2'), 'isset({save_service})'),
'showsla'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'),null),
'goodsla'=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,100), null),
'sortorder'=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535), null),
'service_times'=> array(T_ZBX_STR, O_OPT, null, null, null),
'linktrigger'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'),null),
'triggerid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'trigger'=> array(T_ZBX_STR, O_OPT, null, null, null), //??
'serverid'=> array(T_ZBX_INT, O_OPT, null, DB_ID, 'isset({add_server})'),
'new_service_time'=> array(T_ZBX_STR, O_OPT, null, null, null),
'rem_service_times'=> array(T_ZBX_STR, O_OPT, null, null, null),
'childs'=> array(T_ZBX_STR, O_OPT, P_SYS, DB_ID,NULL),
'parentid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL),
'parentname'=> array(T_ZBX_STR, O_OPT, null, null, null),
/* actions */
'saction'=> array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null),
'save_service'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'add_server'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'add_service_time'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'del_service_times'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'delete'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'cancel'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
/* other */
'form'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
'form_copy_to'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
'form_refresh'=> array(T_ZBX_INT, O_OPT, NULL, NULL, NULL),
'sform'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'), null),
'pservices'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'), null),
'cservices'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'), null),
'slink'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'), null)
);
check_fields($fields);
//----------------------------------------------------------------------
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY);
$available_triggers = get_accessible_triggers(PERM_READ_ONLY,PERM_RES_IDS_ARRAY);
if(isset($_REQUEST['serviceid']) && $_REQUEST['serviceid'] > 0){
$sql = 'SELECT s.* '.
' FROM services s '.
' WHERE (s.triggerid IS NULL OR '.DBcondition('s.triggerid',$available_triggers).') '.
' AND s.serviceid='.$_REQUEST['serviceid'];
if(!$service = DBfetch(DBselect($sql))){
access_deny();
}
}
/*-------------------------------------------- ACTIONS --------------------------------------------*/
if(isset($_REQUEST['saction'])){
$_REQUEST["showsla"] = get_request("showsla",0);
$_REQUEST["soft"] = get_request("soft", 0);
if(isset($_REQUEST["delete"]) && isset($_REQUEST["serviceid"])){
$result = delete_service($service["serviceid"]);
show_messages($result, S_SERVICE_DELETED, S_CANNOT_DELETE_SERVICE);
add_audit_if($result,AUDIT_ACTION_DELETE,AUDIT_RESOURCE_IT_SERVICE,' Name ['.$service["name"].'] id ['.$service['serviceid'].']');
unset($service);
}
else if(isset($_REQUEST["save_service"])){
$service_times = get_request('service_times',array());
$childs = get_request('childs',array());
$triggerid = (isset($_REQUEST["linktrigger"]))?($_REQUEST["triggerid"]):(null);
DBstart();
if(isset($service["serviceid"])){
$result = update_service($service["serviceid"],
$_REQUEST["name"],$triggerid,$_REQUEST["algorithm"],
$_REQUEST["showsla"],$_REQUEST["goodsla"],$_REQUEST["sortorder"],
$service_times,$_REQUEST['parentid'],$childs);
}
else {
$result = add_service(
$_REQUEST["name"],$triggerid,$_REQUEST["algorithm"],
$_REQUEST["showsla"],$_REQUEST["goodsla"],$_REQUEST["sortorder"],
$service_times,$_REQUEST['parentid'],$childs);
}
$result = DBend()?$result:false;
if(isset($serrvice['serviceid'])){
show_messages($result, S_SERVICE_UPDATED, S_CANNOT_UPDATE_SERVICE);
$serviceid = $service["serviceid"];
$audit_acrion = AUDIT_ACTION_UPDATE;
}
else{
show_messages($result, S_SERVICE_ADDED, S_CANNOT_ADD_SERVICE);
$serviceid = $result;
$audit_acrion = AUDIT_ACTION_ADD;
}
add_audit_if($result,$audit_acrion,AUDIT_RESOURCE_IT_SERVICE,' Name ['.$_REQUEST["name"].'] id ['.$serviceid.']');
}
else if(isset($_REQUEST["add_server"])){
$sql = 'SELECT h.* '.
' FROM hosts h '.
' WHERE '.DBin_node('h.hostid').
' AND '.DBcondition('h.hostid',$available_hosts).
' AND h.hostid='.$_REQUEST["serverid"];
if(!$host_data = DBfetch(DBselect($sql))){
access_deny();
}
$result = add_host_to_services($_REQUEST["serverid"], $service["serviceid"]);
add_audit_if($result,AUDIT_ACTION_ADD,AUDIT_RESOURCE_IT_SERVICE,' Host ['.$host_data["host"].'] id ['.$_REQUEST["serverid"].']');
show_messages($result, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER);
}
if($result){
zbx_add_post_js('closeform("services.php");');
include_once "include/page_footer.php";
}
}
//-------------------------------------------- --------------------------------------------
//-----------------------------------------