Kaseya Community

Custom view creation assistance

This question has suggested answer(s)

We're looking to use custom views in our live Kaseya environment to help us run reports and identify machines with particular problems or work that's not run lately.  A lot of these views are simple to create, but there's several that aren't apparent as to how (or if) they can be done. 

1) A view to see all machines that are "new" (have a First Checkin date within the last X number of days).  I know through advanced filtering you can look for machines that first checked in since a particular specified date, but that would require modifying the view every time we needed to check (or run a scheduled report).

2) Machines with no antivirus installed.  We can set a view to see machines that do have KES or AntiVirus installed, but not the inverse.  There's a canned report for Antivirus Installation Statistics but it does not pick up on AVG installs or any other install.

3) Machines that have not had an audit in the last X days.  Trying to schedule audits as an agent procedure does not appear to be an option as when creating procedures there's no way to select a type of audit to run, nor do audits show up as pre-selectable procedure.

 

Any assistance in creating these views (if they can even be created at all) would be greatly appreciated.

Thank you.

 

All Replies
  • I had the same problem - and here is the solution that I arrived at:

    OF COURSE AS ALWAYS - DO THIS AT YOUR OWN RISK - I have added steps to revert to original code base at the end

    I have modified a couple of Kaseya pages and added 1 column onto the ViewDef table to store a view or table that contains a column named "agentGuid".  If the column does not exist, it defaults to vAgentLabel so as to not break the view.  This also allows you to continue to use the rest of the filter criteria.

    I also store all of my views in a secondary database - it is never good to alter someone else's schema unless required!

    Step 1

     

    alter table viewdef

    add column viewToFilter varchar(100) default ''

     

    Step 2  -SAVE A COPY OF C:\Kaseya\WebPages\Toolbox\editView.asp BEFORE OVERWRITING

    Step 3 - SAVE A COPY OF C:\Kaseya\WebPages\inc\editView.inc BEFORE OVERWRITING

    With all of this said - I have an alert set if a patch overwrites one of these 2 files to send me an email so I can go fix it.  While it is not optimal to change someone else's code - business needs dictate requirements and our requirements forced me to make this change.  I could have overwritten a column in editView that we will never use (such as PatchManagement) but that would have caused me to have to alter the length of an existing column in the viewDef table.  I do not like touching someone else's schema and adding a column is a whole lot safer then altering an existing column.
    This code change will allow you to create a database view as complex as you need and just point the view to it (such as failures/ groups of machines etc)
    This can be reverted by:

    copying your original 2 files back into the 2 paths
    Running this sql - Alter table ViewDef drop column viewToFilter

     

  • EDITVIEW.ASP

     

    <!-- #include virtual = "/inc/jscriptHdr.inc"-->

    <!-- #include file = "../inc/connectdb.inc" -->

    <!-- #include file = "../inc/groupSql.inc" -->

    <!-- #include file = "../inc/checkFuncAccess.inc" -->

    <!-- #include file = "../inc/getSQLstring.inc" -->

    <%

    // use current machine ID filter or default to abx*

    // use the current group id filter or default to groupx

    // Show machines currently online/offline

    // Show machines that have/have not checked in since y/m/d h:s

    // Checking in from connection gateway 1.2.3.4

    // In IP address range 1.2.3.4 to 1.2.3.4

     

    // machines with script "x" pending

    // machines with script "x" failed/succeeded

    // machines that have/have not run script "x" since y/m/d h:s

     

    // computer name filter

    // operating system type & OS version

     

    var recSet = Server.CreateObject("ADODB.Recordset");

    var tempSet = Server.CreateObject("ADODB.Recordset");

    var needToSave = new String("false");

    var radioSet = new String("");

    var reloadCmd = new String("");

    var databaseName = new String("");

    var sql = new String("");

    var objectName = new String("");

     

    var newView = getQueryStr("newView");

    var firstPass = new String(Request.form("firstPass"));

    if (firstPass == "undefined") firstPass = "";

    var activeViewId = new Number(Request.form("activeViewId"));

    if (isNaN(activeViewId)) activeViewId = 0;

    var takeId = new Number(Request.form("takeId"));

    if (isNaN(takeId)) takeId = 0;

    var lastViewId = new Number(Request.form("lastViewId"));

    if (isNaN(lastViewId)) lastViewId = -1;

    var buttonType = new Number(Request.form("buttonType"));

    if (isNaN(buttonType)) buttonType = 0;

    var editTitle = new String(Request.form("editTitle"));

    if (editTitle == "undefined") editTitle = "";

    editTitle = editTitle.replace(/[\%\'\"\/\\\:\?\<\>\|]/g,"").substr(0,100);

    var useMachFil = new String(Request.form("useMachFil"));

    if (useMachFil == "undefined") useMachFil = "";

    var overMachFil = new String(Request.form("overMachFil"));

    if (overMachFil == "undefined") overMachFil = "*";

    overMachFil = overMachFil.replace(/[\%,\'\"\/\\\:\?\<\>\| ]/g,"").substr(0,100);

    if (overMachFil.length == 0) overMachFil = "*";

    var useGroupFil = new String(Request.form("useGroupFil"));

    if (useGroupFil == "undefined") useGroupFil = "";

    var groupIdFil = new String(Request.form("groupIdFil"));

    if (groupIdFil == "undefined") groupIdFil = "";

    var useViewColFil = new String(Request.form("useViewColFil"));

    if (useViewColFil == "undefined") useViewColFil = "";

    var useColFil = new String(Request.form("useColFil"));

    if (useColFil == "undefined") useColFil = "";

    var colIdFil = new Number(Request.form("colIdFil"));

    if (isNaN(colIdFil)) colIdFil = 0;

    var showHideCollection = new Number(Request.form("showHideCollection"));

    if (isNaN(showHideCollection)) showHideCollection = 0;

    var showCheckin = new String(Request.form("showCheckin"));

    if (showCheckin == "undefined") showCheckin = "";

    var checkinStat = new Number(Request.form("checkinStat"));

    if (isNaN(checkinStat)) checkinStat = 1;

    var onLineMin = new Number(Request.form("onLineMin"));

    if (isNaN(onLineMin)) onLineMin = 1;

    if (onLineMin < 1) onLineMin = 1;

    if (onLineMin > 9999) onLineMin = 9999;

    var onLineMinUnit = new String(Request.form("onLineMinUnit"));

    if (onLineMinUnit == "undefined") onLineMinUnit = "Day";

    var showSuspended = new String(Request.form("showSuspended"));

    if (showSuspended == "undefined") showSuspended = "";

    var suspendedStat = new Number(Request.form("suspendedStat"));

    if (isNaN(suspendedStat)) suspendedStat = 1;

    var showReboot = new String(Request.form("showReboot"));

    if (showReboot == "undefined") showReboot = "";

    var rebootStat = new Number(Request.form("rebootStat"));

    if (isNaN(rebootStat)) rebootStat = 1;

    var rebootMin = new Number(Request.form("rebootMin"));

    if (isNaN(rebootMin)) rebootMin = 1;

    if (rebootMin < 1) rebootMin = 1;

    if (rebootMin > 9999) rebootMin = 9999;

    var rebootMinUnit = new String(Request.form("rebootMinUnit"));

    if (rebootMinUnit == "undefined") rebootMinUnit = "Day";

    var useAgentCredentialStatus = new String(Request.form("useAgentCredentialStatus"));

    if (useAgentCredentialStatus == "undefined") useAgentCredentialStatus = "";

    var agentCredentialStatus = new Number(Request.form("agentCredentialStatus"));

    if (isNaN(agentCredentialStatus)) agentCredentialStatus = -1;

    var useGateway = new String(Request.form("useGateway"));

    if (useGateway == "undefined") useGateway = "";

    var onlyGateway = new String(Request.form("onlyGateway"));

    if (onlyGateway == "undefined") onlyGateway = "";

    onlyGateway = onlyGateway.replace(/[^\d\.\*]/g,"").substr(0,20);

    var useIpFil = new String(Request.form("useIpFil"));

    if (useIpFil == "undefined") useIpFil = "";

    var ipFil = new String(Request.form("ipFil"));

    if (ipFil == "undefined") ipFil = "";

    ipFil = ipFil.replace(/[^\d\.\*]/g,"").substr(0,20);

    var useOs = new String(Request.form("useOs"));

    if (useOs == "undefined") useOs = "";

    var osType = new Number(Request.form("osType"));

    if (isNaN(osType)) osType = 0;

    var useOsVer = new String(Request.form("useOsVer"));

    if (useOsVer == "undefined") useOsVer = "";

    var osVer = new String(Request.form("osVer"));

    if (osVer == "undefined") osVer = "*";

    osVer = osVer.replace(/[\%']/g,"").substr(0,100);

    if (osVer.length == 0) osVer = "*";

    var scriptId = new Number(Request.form("scriptId"));

    if (isNaN(scriptId)) scriptId = 0;

    var scriptName = new String(Request.form("scriptName"));

    if (scriptName == "undefined") scriptName = "";

    var useScriptPending = new String(Request.form("useScriptPending"));

    if (useScriptPending == "undefined") useScriptPending = "";

    var scriptPending = new Number(Request.form("scriptPending"));

    if (isNaN(scriptPending)) scriptPending = 0;

    var useScriptResult = new String(Request.form("useScriptResult"));

    if (useScriptResult == "undefined") useScriptResult = "";

    var scriptResult = new Number(Request.form("scriptResult"));

    if (isNaN(scriptResult)) scriptResult = 0;

    var useScriptSince = new String(Request.form("useScriptSince"));

    if (useScriptSince == "undefined") useScriptSince = "";

    var scriptSince = new Number(Request.form("scriptSince"));

    if (isNaN(scriptSince)) scriptSince = 0;

    var scriptMin = new Number(Request.form("scriptMin"));

    if (isNaN(scriptMin)) scriptMin = 1;

    if (scriptMin < 1) scriptMin = 1;

    if (scriptMin > 9999) scriptMin = 9999;

    var scriptMinUnit = new String(Request.form("scriptMinUnit"));

    if (scriptMinUnit == "undefined") scriptMinUnit = "Day";

    var useAppName = new String(Request.form("useAppName"));

    if (useAppName == "undefined") useAppName = "";

    var appContainMiss = new Number(Request.form("appContainMiss"));

    if (isNaN(appContainMiss)) appContainMiss = 1;

    var appFilter = new String(Request.form("appFilter"));

    if (appFilter == "undefined") appFilter = "*";

    appFilter = appFilter.substr(0,100);

    var useAppVer = new String(Request.form("useAppVer"));

    if (useAppVer == "undefined") useAppVer = "";

    var verCompare = new Number(Request.form("verCompare"));

    if (isNaN(verCompare)) verCompare = 1;

    var verFilter = new String(Request.form("verFilter"));

    if (verFilter == "undefined") verFilter = "0";

    verFilter = verFilter.substr(0,100);

    var usePatchFil = new String(Request.form("usePatchFil"));

    if (usePatchFil == "undefined") usePatchFil = "";

    var missingPatches = new Number(Request.form("missingPatches"));

    if (isNaN(missingPatches)) missingPatches = 0;

    if (missingPatches < 1) missingPatches = 0;

    if (missingPatches > 9999) missingPatches = 9999;

    var usePatchPolicy = new String(Request.form("usePatchPolicy"));

    if (usePatchPolicy == "0") {

        usePatchPolicy = "";

    } else if (usePatchPolicy == "undefined") {

        usePatchPolicy = "";

    }

    var usePatchScanPending = new String(Request.form("usePatchScanPending"));

    if (usePatchScanPending == "undefined") usePatchScanPending = "";

    var patchScanPending = new Number(Request.form("patchScanPending"));

    if (isNaN(patchScanPending)) patchScanPending = 0;

    var usePatchScanResult = new String(Request.form("usePatchScanResult"));

    if (usePatchScanResult == "undefined") usePatchScanResult = "";

    var patchScanResult = new Number(Request.form("patchScanResult"));

    if (isNaN(patchScanResult)) patchScanResult = 0;

    var usePatchScanSince = new String(Request.form("usePatchScanSince"));

    if (usePatchScanSince == "undefined") usePatchScanSince = "";

    var patchScanSince = new Number(Request.form("patchScanSince"));

    if (isNaN(patchScanSince)) patchScanSince = 0;

    var patchScanMin = new Number(Request.form("patchScanMin"));

    if (isNaN(patchScanMin)) patchScanMin = 1;

    if (patchScanMin < 1) patchScanMin = 0;

    if (patchScanMin > 9999) patchScanMin = 9999;

    var patchScanMinUnit = new String(Request.form("patchScanMinUnit"));

    if (patchScanMinUnit == "undefined") patchScanMinUnit = "Day";

    var usePatchRebootPending = new String(Request.form("usePatchRebootPending"));

    if (usePatchRebootPending == "undefined") usePatchRebootPending = "";

    var usePatchTestStatus = new String(Request.form("usePatchTestStatus"));

    if (usePatchTestStatus == "undefined") usePatchTestStatus = "";

    var patchTestStatus = new Number(Request.form("patchTestStatus"));

    if (isNaN(patchTestStatus)) patchTestStatus = -2;

    var usePatchAutoUpdateConfig = new String(Request.form("usePatchAutoUpdateConfig"));

    if (usePatchAutoUpdateConfig == "undefined") usePatchAutoUpdateConfig = "";

    var patchAutoUpdateConfig = new Number(Request.form("patchAutoUpdateConfig"));

    if (isNaN(patchAutoUpdateConfig)) patchAutoUpdateConfig = 0;

    var usePatchRebootConfig = new String(Request.form("usePatchRebootConfig"));

    if (usePatchRebootConfig == "undefined") usePatchRebootConfig = "";

    var patchRebootConfig = new Number(Request.form("patchRebootConfig"));

    if (isNaN(patchRebootConfig)) patchRebootConfig = 0;

    var usePatchFileSrcConfig = new String(Request.form("usePatchFileSrcConfig"));

    if (usePatchFileSrcConfig == "undefined") usePatchFileSrcConfig = "";

    var patchFileSrcConfig = new String(Request.form("patchFileSrcConfig"));

    if (patchFileSrcConfig == "undefined") patchFileSrcConfig = "0,4";

    var usePatchUnscanned = new String(Request.form("usePatchUnscanned"));

    if (usePatchUnscanned == "undefined") usePatchUnscanned = "";

    var usePatchMissingKB = new String(Request.form("usePatchMissingKB"));

    if (usePatchMissingKB == "undefined") usePatchMissingKB = "";

    var viewToFilter = new String(Request.form("viewToFilter"));

    if (viewToFilter == "undefined") viewToFilter = "";

    var patchMissingKB = new String(Request.form("patchMissingKB"));

    if (patchMissingKB == "undefined") patchMissingKB = "";

     

    var advFilter = new String(Request.form("advFilter"));

    if (advFilter == "undefined") advFilter = "";

    var advFilterId = new Number(Request.form("advFilterId"));

    if (isNaN(advFilterId)) advFilterId = 0;

     

    var useMonitorset = new String(Request.form("useMonitorset"));

    if (useMonitorset == "undefined") useMonitorset = "";

    var useMonitorsetID = new String(Request.form("useMonitorsetID"));

    if (useMonitorsetID == "undefined") useMonitorsetID = 0;

     

    var useSNMPMonitorset = new String(Request.form("useSNMPMonitorset"));

    if (useSNMPMonitorset == "undefined") useSNMPMonitorset = "";

    var useSNMPMonitorsetID = new String(Request.form("useSNMPMonitorsetID"));

    if (useSNMPMonitorsetID == "undefined") useSNMPMonitorsetID = 0;

     

    var useApp1 = new String(Request.form("useApp1"));

    if (useApp1 == "undefined") useApp1 = "";

    var useApp2 = new String(Request.form("useApp2"));

    if (useApp2 == "undefined") useApp2 = "";

    var useApp3 = new String(Request.form("useApp3"));

    if (useApp3 == "undefined") useApp3 = "";

    var useApp4 = new String(Request.form("useApp4"));

    if (useApp4 == "undefined") useApp4 = "";

    var useApp5 = new String(Request.form("useApp5"));

    if (useApp5 == "undefined") useApp5 = "";

    var useApp6 = new String(Request.form("useApp6"));

    if (useApp6 == "undefined") useApp6 = "";

    var useApp7 = new String(Request.form("useApp7"));

    if (useApp7 == "undefined") useApp7 = "";

    var useApp8 = new String(Request.form("useApp8"));

    if (useApp8 == "undefined") useApp8 = "";

    var useApp9 = new String(Request.form("useApp9"));

    if (useApp9 == "undefined") useApp9 = "";

    var useApp10 = new String(Request.form("useApp10"));

    if (useApp10 == "undefined") useApp10 = "";

    var useApp11 = new String(Request.form("useApp11"));

    if (useApp11 == "undefined") useApp11 = "";

    var useApp12 = new String(Request.form("useApp12"));

    if (useApp12 == "undefined") useApp12 = "";

    var useApp13 = new String(Request.form("useApp13"));

    if (useApp13 == "undefined") useApp13 = "";

    var useApp14 = new String(Request.form("useApp14"));

    if (useApp14 == "undefined") useApp14 = "";

    var useApp15 = new String(Request.form("useApp15"));

    if (useApp15 == "undefined") useApp15 = "";

    var useApp16 = new String(Request.form("useApp16"));

    if (useApp16 == "undefined") useApp16 = "";

    var useApp17 = new String(Request.form("useApp17"));

    if (useApp17 == "undefined") useApp17 = "";

    var useApp18 = new String(Request.form("useApp18"));

    if (useApp18 == "undefined") useApp18 = "";

    var useApp19 = new String(Request.form("useApp19"));

    if (useApp19 == "undefined") useApp19 = "";

    var useApp20 = new String(Request.form("useApp20"));

    if (useApp20 == "undefined") useApp20 = "";

     

    /* Temporary conditional statement */

    cmd = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS  " +

        " WHERE TABLE_NAME = 'ViewDef' AND COLUMN_NAME = 'useMonsetFilter') " +

        " BEGIN "  +

        " ALTER TABLE ViewDef ADD useMonsetFilter INT NULL" +

        " END;  ";

    dbConn.Execute(cmd ,0,128);

     

    /* Temporary conditional statement */

    cmd = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS  " +

        " WHERE TABLE_NAME = 'ViewDef' AND COLUMN_NAME = 'MonsetID') " +

        " BEGIN "  +

        " ALTER TABLE ViewDef ADD MonsetID INT NULL" +

        " END;  ";

    dbConn.Execute(cmd ,0,128);

     

    /* Temporary conditional statement */

    cmd = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS  " +

        " WHERE TABLE_NAME = 'ViewDef' AND COLUMN_NAME = 'useSNMPsetFilter') " +

        " BEGIN "  +

        " ALTER TABLE ViewDef ADD useSNMPsetFilter INT NULL" +

        " END;  ";

    dbConn.Execute(cmd ,0,128);

     

    /* Temporary conditional statement */

    cmd = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS  " +

        " WHERE TABLE_NAME = 'ViewDef' AND COLUMN_NAME = 'SNMPsetID') " +

        " BEGIN "  +

        " ALTER TABLE ViewDef ADD SNMPsetID INT NULL" +

        " END;  ";

    dbConn.Execute(cmd ,0,128);

     

    if (firstPass.length == 0 && newView.length == 0) {

        recSet.Open("SELECT activeViewId FROM adminMachFil WHERE adminId="+sessionAdminId,dbConn);

        if (recSet.EOF == false) {

            activeViewId = Number(recSet("activeViewId"));

        }

        recSet.Close();

    }

     

     

     

    var appInt = new Number(Request.form("appInt"));

    if (isNaN(appInt)) appInt = 0;

    var appArray = new Array();

    var appArrayStr = new Array();

    var appArrayOn = new Array();

    recSet.Open("select id, ref, isNull(viewId,0) AS viewId from partnerApp pa LEFT OUTER JOIN viewDefApp va ON pa.id = va.appId and va.viewId = "+activeViewId+" where usageCountsAvail = 1 and partitionId = "+sessionPartition+" ",dbConn);

    while (recSet.EOF == false) {

        appArray[appInt] = new Number(recSet("id"));

        appArrayStr[appInt] = new String(recSet("ref"));

        appArrayOn[appInt] = new Number(recSet("viewId"));

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 0 && appArrayOn[0] != 0) {

                useApp1 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 1 && appArrayOn[1] != 0) {

                useApp2 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 2 && appArrayOn[2] != 0) {

                useApp3 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 3 && appArrayOn[3] != 0) {

                useApp4 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 4 && appArrayOn[4] != 0) {

                useApp5 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 5 && appArrayOn[5] != 0) {

                useApp6 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 6 && appArrayOnDevil != 0) {

                useApp7 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 7 && appArrayOn[7] != 0) {

                useApp8 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 8 && appArrayOnMusic != 0) {

                useApp9 = 'checked';

            }

        }

        if (firstPass.length == 0 && newView.length == 0) {

            if(appInt == 9 && appArrayOn[9] != 0) {

                useApp10 = 'checked';

            }

        }

        appInt = appInt + 1;

        recSet.MoveNext();

    }

    recSet.Close();

     

    if ((takeId > 0)&&(sessionAdminType==2)) {

        // Take ownership

        dbConn.Execute("UPDATE viewDef SET adminId="+sessionAdminId+" WHERE adminId > 0 AND viewId="+takeId,0,128);

    }

     

    showCollections = true;

     

    switch (Number(buttonType)) {

      case 0: // nothing hit

      default:

        break;

      case 1: // save hit

      case 2: // save as hit. create a new view

        if (useMachFil.length == 0) uMachFil = 0;

        else uMachFil = 1;

        if (useGroupFil.length == 0) uGroupFil = 0;

        else uGroupFil = 1;

        if (useViewColFil.length == 0) uViewColFil = 0;

        else uViewColFil = 1;

        if (useColFil.length == 0) uColFil = 0;

        else if (Number(showHideCollection) == 1) uColFil = 2;

        else uColFil = 1;

        if (showCheckin.length == 0) sCheckin = 0;

        else if (Number(checkinStat) == 0) sCheckin = 1;

        else if (Number(checkinStat) == 1) sCheckin = 2;

        else sCheckin = 3;

        switch (String(onLineMinUnit)) {

          case "Min":

          default:

            oMin = onLineMin;

            break;

          case "Hr":

            oMin = onLineMin * 60;

            break;

          case "Day":

            oMin = onLineMin * 60 * 24;

            break;

        }

        if (showSuspended.length == 0) sSuspended = 0;

        else if (Number(suspendedStat) == 0) sSuspended = 1;

        else sSuspended = 2;

        if (showReboot.length == 0) sReboot = 0;

        else if (Number(rebootStat) == 0) sReboot = 1;

        else sReboot = 2;

        switch (String(rebootMinUnit)) {

          case "Min":

          default:

            rMin = rebootMin;

            break;

          case "Hr":

            rMin = rebootMin * 60;

            break;

          case "Day":

            rMin = rebootMin * 60 * 24;

            break;

        }

        if (useAgentCredentialStatus.length > 0) cCredentialStatus = 1;

        else cCredentialStatus = 0;

        if (cCredentialStatus == 0) agentCredentialStatus = -1;

        if (useGateway.length == 0) uGateway = 0;

        else uGateway = 1;

        if (useIpFil.length == 0) uIp = 0;

        else uIp = 1;

        if (Number(useOs) == 0) uOs = 0;

        else uOs = osType;

        if (useOsVer.length == 0) uOsVer = 0;

        else uOsVer = 1;

        if (useScriptPending.length == 0) uScriptPending = 0;

        else if (Number(scriptPending) == 1) uScriptPending = 1;

        else uScriptPending = 2;

        if (useScriptResult.length == 0) uScriptResult = 0;

        else if (Number(scriptResult) == 1) uScriptResult = 1;

        else uScriptResult = 2;

        if (useScriptSince.length == 0) uScriptSince = 0;

        else if (Number(scriptSince) == 1) uScriptSince = 1;

        else uScriptSince = 2;

        switch (String(scriptMinUnit)) {

          case "Min":

          default:

            sMin = scriptMin;

            break;

          case "Hr":

            sMin = scriptMin * 60;

            break;

          case "Day":

            sMin = scriptMin * 60 * 24;

            break;

        }

        if (Number(useAppName) == 0) uApp = 0;

        else uApp = appContainMiss;

        if (Number(useAppName) == 0) uAppVer = 0;

        else if (Number(useAppVer) == 0) uAppVer = 0;

        else uAppVer = verCompare;

     

        if (usePatchFil.length == 0) {

            uPatch = 0;

            uMissingPatch = 0;

            uPatchPolicy = 0;

        } else {

            if (Number(missingPatches) > 0) {

               uPatch = 1;

               uMissingPatch = Number(missingPatches);

               if (usePatchPolicy.length == 0) {

                   uPatchPolicy = 0;

               } else {

                   uPatchPolicy = 1;

               }

            } else {

               uPatch = 0;

               uMissingPatch = 0;

               uPatchPolicy = 0;

            }

        }

        if (usePatchScanPending.length == 0) uPatchScanPending = 0;

        else if (Number(patchScanPending) == 1) uPatchScanPending = 1;

        else uPatchScanPending = 2;

        if (usePatchScanResult.length == 0) uPatchScanResult = 0;

        else if (Number(patchScanResult) == 1) uPatchScanResult = 1;

        else uPatchScanResult = 2;

        if (usePatchScanSince.length == 0) uPatchScanSince = 0;

        else if (Number(patchScanSince) == 1) uPatchScanSince = 1;

        else uPatchScanSince = 2;

        switch (String(patchScanMinUnit)) {

          case "Min":

          default:

            psMin = patchScanMin;

            break;

          case "Hr":

            psMin = patchScanMin * 60;

            break;

          case "Day":

            psMin = patchScanMin * 60 * 24;

            break;

        }

        if (uPatchScanSince == 0) {

            patchScanMinUnit = "Day";

            psMin = 60 * 24;

        }

     

        if (usePatchRebootPending.length > 0) cPatchRebootPending = 1;

        else cPatchRebootPending = 0;

     

        if (usePatchTestStatus.length > 0) cPatchTestStatus = 1;

        else cPatchTestStatus = 0;

        if (cPatchTestStatus == 0) patchTestStatus = -2;

     

        if (usePatchAutoUpdateConfig.length > 0) cPatchAutoUpdateConfig = 1;

        else cPatchAutoUpdateConfig = 0;

        if (cPatchAutoUpdateConfig == 0) patchAutoUpdateConfig = 0;

     

        if (usePatchRebootConfig.length > 0) cPatchRebootConfig = 1;

        else cPatchRebootConfig = 0;

        if (cPatchRebootConfig == 0) patchRebootConfig = 0;

     

        if (usePatchFileSrcConfig.length > 0) cPatchFileSrcConfig = 1;

        else cPatchFileSrcConfig = 0;

        if (cPatchFileSrcConfig == 0) patchFileSrcConfig = "0,4";

     

        if (usePatchUnscanned.length > 0) cPatchUnscanned = 1;

        else cPatchUnscanned = 0;

     

        if (usePatchMissingKB.length > 0) cPatchMissingKB = 1;

        else cPatchMissingKB = 0;

        if (cPatchMissingKB == 0) patchMissingKB = "";

     

        if (advFilter.length > 0) cAdvFilter = 1;

        else cAdvFilter = 0;

     

        if (useMonitorset.length > 0) useMonitorset = 1;

        else useMonitorset = 0;

     

        if (useMonitorsetID <= 0)

        {

            useMonitorset = 0;

        }

     

        if (useSNMPMonitorset.length > 0) useSNMPMonitorset = 1;

        else useSNMPMonitorset = 0;

     

        if (useSNMPMonitorsetID <= 0)

        {

           useSNMPMonitorset = 0;

        }

     

        if (viewToFilter.length > 0) 

        {

            if (viewToFilter.indexOf(".") > 0) 

            {

                databaseName = viewToFilter.substring(0,viewToFilter.indexOf("."));

                objectName = viewToFilter.substring(viewToFilter.lastIndexOf(".")+1);

                sql = "use "+databaseName+" select COUNT(*) as validObject from sys.columns where OBJECT_NAME(object_ID) = '"+objectName+"' and name = 'AgentGuid' use ksubscribers"

            }

            else

            {

                sql = "select COUNT(*) as validObject from sys.columns where OBJECT_NAME(object_ID) = '"+viewToFilter+"' and name = 'AgentGuid'"

            }

     

            recSet.Open(sql,dbConn);

            if (recSet.EOF == false) 

            {

                if (Number(recSet("validObject")) != 1)

                {

                    viewToFilter = "vAgentLabel";

                }

            }

            else 

            {

                viewToFilter = "";

            }

            recSet.Close();

        }

     

     

        if (Number(buttonType) == 2) { // process save as

            // create a unique id for this view

            oldActiveViewId = activeViewId;

            activeViewId = Number(String(Math.random()).substr(2,8));

            // duplicate the advanced filter so this new view gets its own copy to use

            newAdvFilterId = Number(String(Math.random()).substr(2,8));

     

            numViewName = 0;

            tempSet.Open("SELECT COUNT(*) AS numViewName "+

                         "FROM viewDef v "+

                             "JOIN adminIdTab t ON v.adminId = t.adminId "+

                             "JOIN administrators a ON t.adminName = a.adminName "+

                                                  "AND a.partitionStr = '"+sessionPartition+"' "+

                         "WHERE v.viewName = N'"+editTitle+"'",dbConn);

            if (!tempSet.EOF) {

                numViewName = Number(tempSet("numViewName"));

            }

            tempSet.Close();

            if (numViewName > 0) {

                editTitle = xlate("Copy of",true) + " " + editTitle;

            }

     

            dbConn.Execute("INSERT reportFilters (filterId,colId,showCol,filter) "+

                "(SELECT "+newAdvFilterId+",colId,showCol,filter FROM reportFilters "+

                "WHERE filterId="+advFilterId+")",0,128);

            dbConn.Execute("INSERT INTO viewDef (viewId,adminId,viewName,readWrite,shareAll,"+

                "useMachFil,overMachFil,useGroupFil,groupIdFil,showCheckin,onLineMin,showSuspended,"+

                "showReboot,rebootMin,useAgentCredentialStatus,agentCredentialStatus,useGateway,onlyGateway,useIpFil,ipFil,useOs,useOsVer,osVer,"+

                "useScriptPending,scriptId,useScriptResult,useScriptSince,scriptMin,useViewColFil,useColFil,colIdFil,"+

                "useAppName,appFilter,useAppVer,verFilter,usePatchFil,missingPatches,usePatchPolicy,usePatchScanPending,"+

                "usePatchScanResult,usePatchScanSince,patchScanMin,usePatchRebootPending,usePatchTestStatus,patchTestStatus,"+

                "usePatchAutoUpdateConfig,patchAutoUpdateConfig,usePatchRebootConfig,patchRebootConfig,"+

                "usePatchFileSrcConfig,patchFileSrcConfig,usePatchUnscanned,usePatchMissingKB,patchMissingKB,advFilter,advFilterId, useMonsetFilter, MonsetID, useSNMPsetFilter, SNMPsetID, viewToFilter) "+

                "VALUES ("+activeViewId+","+sessionAdminId+",N'"+editTitle+"',0,0,"+uMachFil+

                ",N'"+overMachFil+"',"+uGroupFil+",N'"+groupIdFil+

                "',"+sCheckin+","+oMin+","+sSuspended+","+sReboot+","+rMin+","+cCredentialStatus+","+agentCredentialStatus+","+uGateway+",N'"+onlyGateway+

                "',"+uIp+",N'"+ipFil+"',"+uOs+","+uOsVer+",N'"+osVer+"',"+uScriptPending+

                ","+scriptId+","+uScriptResult+","+uScriptSince+","+sMin+","+uViewColFil+","+uColFil+","+colIdFil+

                ","+uApp+",N'"+appFilter.replace(/\'/g,"''")+"',"+uAppVer+",N'"+verFilter.replace(/\'/g,"''")+

                "',"+uPatch+","+uMissingPatch+","+uPatchPolicy+","+uPatchScanPending+","+uPatchScanResult+

                ","+uPatchScanSince+","+psMin+","+cPatchRebootPending+","+cPatchTestStatus+","+patchTestStatus+

                ","+cPatchAutoUpdateConfig+","+patchAutoUpdateConfig+","+cPatchRebootConfig+","+patchRebootConfig+

                ","+cPatchFileSrcConfig+",N'"+patchFileSrcConfig+"',"+cPatchUnscanned+","+cPatchMissingKB+",N'"+patchMissingKB+"',"+cAdvFilter+","+newAdvFilterId+"," + useMonitorset+","+

                useMonitorsetID+"," + useSNMPMonitorset+","+useSNMPMonitorsetID+",'"+viewToFilter+"')",0,128);

            dbConn.Execute("delete from viewDefApp where viewId = "+activeViewId+" ",0,128);

            for(i = 0; i < appInt; i++) {

                if (i == 0) {

                    if (useApp1 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[0]+", '"+appArrayStr[0]+"') ",0,128);

                    }

                }

                if (i == 1) {

                    if (useApp2 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[1]+", '"+appArrayStr[1]+"') ",0,128);

                    }

                }

                if (i == 2) {

                    if (useApp3 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[2]+", '"+appArrayStr[2]+"') ",0,128);

                    }

                }

                if (i == 3) {

                    if (useApp4 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[3]+", '"+appArrayStr[3]+"') ",0,128);

                    }

                }

                if (i == 4) {

                    if (useApp5 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[4]+", '"+appArrayStr[4]+"') ",0,128);

                    }

                }

                if (i == 5) {

                    if (useApp6 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[5]+", '"+appArrayStr[5]+"') ",0,128);

                    }

                }

                if (i == 6) {

                    if (useApp7 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArrayDevil+", '"+appArrayStrDevil+"') ",0,128);

                    }

                }

                if (i == 7) {

                    if (useApp8 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[7]+", '"+appArrayStr[7]+"') ",0,128);

                    }

                }

                if (i == 8) {

                    if (useApp9 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArrayMusic+", '"+appArrayStrMusic+"') ",0,128);

                    }

                }

                if (i == 9) {

                    if (useApp10 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[9]+", '"+appArrayStr[9]+"') ",0,128);

                    }

                }

            }

            // copy over any view collection attached to the old view

            dbConn.Execute("INSERT viewCollection (viewId,agentGuid) "+

                "(SELECT "+activeViewId+",agentGuid FROM viewCollection WHERE viewId="+oldActiveViewId+")",0,128);

        } else {

            // save hit

            dbConn.Execute("UPDATE viewDef SET viewName=N'"+editTitle+"',useMachFil="+uMachFil+

                ",overMachFil=N'"+overMachFil+"',useGroupFil="+uGroupFil+",groupIdFil=N'"+groupIdFil+

                "',showCheckin="+sCheckin+",onLineMin="+oMin+",showSuspended="+sSuspended+",showReboot="+sReboot+",rebootMin="+rMin+

                ",useAgentCredentialStatus="+cCredentialStatus+",agentCredentialStatus="+agentCredentialStatus+

                ",useGateway="+uGateway+",onlyGateway=N'"+onlyGateway+

                "',useIpFil="+uIp+",ipFil=N'"+ipFil+"',useOs="+uOs+",useOsVer="+uOsVer+

                ",osVer=N'"+osVer+"',useScriptPending="+uScriptPending+",scriptId="+scriptId+

                ",useScriptResult="+uScriptResult+",useScriptSince="+uScriptSince+",scriptMin="+sMin+

                ",useViewColFil="+uViewColFil+",useColFil="+uColFil+",colIdFil="+colIdFil+",useAppName="+uApp+

                ",appFilter=N'"+appFilter.replace(/\'/g,"''")+"',useAppVer="+uAppVer+

                ",verFilter=N'"+verFilter.replace(/\'/g,"''")+

                "',advFilter="+cAdvFilter+",advFilterId="+advFilterId+

                ",usePatchFil="+uPatch+",missingPatches="+uMissingPatch+",usePatchPolicy="+uPatchPolicy+

                ",usePatchScanPending="+uPatchScanPending+",usePatchScanResult="+uPatchScanResult+

                ",usePatchScanSince="+uPatchScanSince+",patchScanMin="+psMin+",usePatchRebootPending="+cPatchRebootPending+

                ",usePatchTestStatus="+cPatchTestStatus+",patchTestStatus="+patchTestStatus+

                ",usePatchAutoUpdateConfig="+cPatchAutoUpdateConfig+",patchAutoUpdateConfig="+patchAutoUpdateConfig+

                ",usePatchRebootConfig="+cPatchRebootConfig+",patchRebootConfig="+patchRebootConfig+

                ",usePatchFileSrcConfig="+cPatchFileSrcConfig+",patchFileSrcConfig=N'"+patchFileSrcConfig+"' "+

                ",usePatchUnscanned="+cPatchUnscanned+

                ",usePatchMissingKB="+cPatchMissingKB+",patchMissingKB=N'"+patchMissingKB+"' "+

                ",useMonsetFilter="+useMonitorset+",MonsetID="+useMonitorsetID+

                ",useSNMPsetFilter="+useSNMPMonitorset+",SNMPsetID="+useSNMPMonitorsetID+

                ",viewToFilter='"+viewToFilter+"'"+

                " WHERE viewId="+activeViewId+

                " AND (adminId="+sessionAdminId+

                " OR (readWrite=1 AND shareAll=1)"+

                " OR (readWrite=1 AND EXISTS (SELECT 1 FROM viewAcl WHERE viewId = "+activeViewId+

                " AND adminId="+sessionAdminId+")))",0,128);

            dbConn.Execute("delete from viewDefApp where viewId = "+activeViewId+" ",0,128);

            for(i = 0; i < appInt; i++) {

                if (i == 0) {

                    if (useApp1 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[0]+", '"+appArrayStr[0]+"') ",0,128);

                    }

                }

                if (i == 1) {

                    if (useApp2 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[1]+", '"+appArrayStr[1]+"') ",0,128);

                    }

                }

                if (i == 2) {

                    if (useApp3 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[2]+", '"+appArrayStr[2]+"') ",0,128);

                    }

                }

                if (i == 3) {

                    if (useApp4 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[3]+", '"+appArrayStr[3]+"') ",0,128);

                    }

                }

                if (i == 4) {

                    if (useApp5 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[4]+", '"+appArrayStr[4]+"') ",0,128);

                    }

                }

                if (i == 5) {

                    if (useApp6 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[5]+", '"+appArrayStr[5]+"') ",0,128);

                    }

                }

                if (i == 6) {

                    if (useApp7 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArrayDevil+", '"+appArrayStrDevil+"') ",0,128);

                    }

                }

                if (i == 7) {

                    if (useApp8 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[7]+", '"+appArrayStr[7]+"') ",0,128);

                    }

                }

                if (i == 8) {

                    if (useApp9 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArrayMusic+", '"+appArrayStrMusic+"') ",0,128);

                    }

                }

                if (i == 9) {

                    if (useApp10 == 'checked') {

                        dbConn.Execute("insert into viewDefApp (viewId, appId, appRef) values ("+activeViewId+", "+appArray[9]+", '"+appArrayStr[9]+"') ",0,128);

                    }

                }

            }

        }

        // set the selected view for this admin to the new activeViewId

        saveDbView(activeViewId);

        dbConn.Execute("UPDATE adminMachFil SET activeViewId="+activeViewId+

            " WHERE adminId="+sessionAdminId,0,128);

        reloadCmd = "opener.document.location.href.indexOf('#') > -1?opener.document.location = opener.document.location.href.replace('#', '&reload=true#'):opener.document.location = opener.document.location.href+'&reload=true'; ";

        if (reloadCmd.indexOf("?") < 0) reloadCmd = reloadCmd.replace(/\&/,"?");

        lastViewId = -1;

        break;

      case 3: // delete hit

        dbConn.Execute("DELETE FROM viewDef WHERE viewId="+activeViewId+"; "+

            "DELETE FROM viewAcl WHERE viewId="+activeViewId+"; "+

            "DELETE FROM viewDefApp WHERE viewId="+activeViewId+"; ",0,128);

        dropDbView(activeViewId);

        dbConn.Execute("if exists (select id from partnerApp where id = 44 and partitionId = "+sessionPartition+") " +

            " insert into policy.event (id, partitionId, policyEventType, contextFK, policyEventGuid) values " +

            " (dbo.fn_GenerateKid(),"+sessionPartition+",23,1,"+activeViewId+")",0,128);

        dbConn.Execute("UPDATE adminMachFil SET activeViewId=0 WHERE activeViewId="+activeViewId,0,128);

        activeViewId = 0;

        reloadCmd = "opener.document.location.href.indexOf('#') > -1?opener.document.location = opener.document.location.href.replace('#', '&reload=true#'):opener.document.location = opener.document.location.href+'&reload=true'; ";

        if (reloadCmd.indexOf("?") < 0) reloadCmd = reloadCmd.replace(/\&/,"?");

        break;

    }

     

    recSet.Open("SELECT v.*,ISNULL(s.scriptName,N'') AS scriptName FROM viewDef v LEFT OUTER JOIN "+

        "scriptIdTab s ON s.scriptId=v.scriptId WHERE viewId="+activeViewId,dbConn);

    if (recSet.EOF == false)  {

        editTitle = String(recSet("viewName"));

        ownerId = Number(recSet("adminId"));

        readWrite = Number(recSet("readWrite"));

        if (Number(recSet("useMachFil")) == 1) useMachFil = "checked";

        else useMachFil = "";

        overMachFil = String(recSet("overMachFil"));

        if (Number(recSet("useGroupFil")) == 1) useGroupFil = "checked";

        else useGroupFil = "";

        groupIdFil = String(recSet("groupIdFil"));

        if (Number(recSet("useViewColFil")) == 1) useViewColFil = "checked";

        else useViewColFil = "";

        if ((Number(recSet("useColFil")) > 0)&&(showCollections == true)) {

            useColFil = "checked";

            if (Number(recSet("useColFil")) == 1) {

                radioSet += "showHideCollection[0].checked=true; showHideCollection[1].checked=false; ";

            } else {

                radioSet += "showHideCollection[0].checked=false; showHideCollection[1].checked=true; ";

            }

        } else {

            useColFil = "";

            if (showCollections == true) {

                radioSet += "showHideCollection[0].checked=true; showHideCollection[1].checked=false; ";

            }

        }

        colIdFil = Number(recSet("colIdFil"));

        if (Number(recSet("showCheckin")) == 0) {

            showCheckin = "";

            radioSet += "checkinStat[0].checked=false; checkinStat[1].checked=true; setOnlineStat(); ";

        } else {

            showCheckin = "checked";

            if (Number(recSet("showCheckin")) == 1) {

                radioSet += "checkinStat[0].checked=true; checkinStat[1].checked=false; checkinStat[2].checked=false; setOnlineStat(); ";

            } else if (Number(recSet("showCheckin")) == 2) {

                radioSet += "checkinStat[0].checked=false; checkinStat[1].checked=true; checkinStat[2].checked=false; setOnlineStat(); ";

            } else {

                radioSet += "checkinStat[0].checked=false; checkinStat[1].checked=false; checkinStat[2].checked=true; setOnlineStat(); ";

            }

        }

        onLineMin = Number(recSet("onLineMin"));

        // convert to hour or day

        onLineHr = onLineMin / 60;

        onLineDay = onLineHr / 24;

        if (Math.round(onLineDay) == onLineDay) {

            onLineMin = onLineDay;

            onLineMinUnit = "Day";

        } else if (Math.round(onLineHr) == onLineHr) {

            onLineMin = onLineHr;

            onLineMinUnit = "Hr";

        } else {

            onLineMinUnit = "Min";

        }

        if (Number(recSet("showSuspended")) == 0) {

            showSuspended = "";

            radioSet += "suspendedStat[0].checked=false; suspendedStat[1].checked=true; ";

        } else {

            showSuspended = "checked";

            if (Number(recSet("showSuspended")) == 1) {

                radioSet += "suspendedStat[0].checked=true; suspendedStat[1].checked=false; ";

            } else {

                radioSet += "suspendedStat[0].checked=false; suspendedStat[1].checked=true; ";

            }

        }

        if (Number(recSet("showReboot")) == 0) {

            showReboot = "";

            radioSet += "rebootStat[0].checked=false; rebootStat[1].checked=true; ";

        } else {

            showReboot = "checked";

            if (Number(recSet("showReboot")) == 1) {

                radioSet += "rebootStat[0].checked=true; rebootStat[1].checked=false; ";

            } else {

                radioSet += "rebootStat[0].checked=false; rebootStat[1].checked=true; ";

            }

        }

        rebootMin = Number(recSet("rebootMin"));

        // convert to hour or day

        rebootHr = rebootMin / 60;

        rebootDay = rebootHr / 24;

        if (Math.round(rebootDay) == rebootDay) {

            rebootMin = rebootDay;

            rebootMinUnit = "Day";

        } else if (Math.round(rebootHr) == rebootHr) {

            rebootMin = rebootHr;

            rebootMinUnit = "Hr";

        } else {

            rebootMinUnit = "Min";

        }

        if (Number(recSet("useAgentCredentialStatus")) == 0) useAgentCredentialStatus = "";

        else useAgentCredentialStatus = "checked";

        agentCredentialStatus = Number(recSet("agentCredentialStatus"));

        if (Number(recSet("useGateway")) == 1) useGateway = "checked";

        else useGateway = "";

        onlyGateway = String(recSet("onlyGateway"));

        if (Number(recSet("useIpFil")) == 1) useIpFil = "checked";

        else useIpFil = "";

        ipFil = String(recSet("ipFil"));

        if (Number(recSet("useOs")) > 0) useOs = "checked";

        else useOs = "";

        osType = Number(recSet("useOs"));

        if (Number(recSet("useOsVer")) == 1) useOsVer = "checked";

        else useOsVer = "";

        osVer = String(recSet("osVer"));

        if (Number(activeViewId) != Number(lastViewId)) {

            scriptId = Number(recSet("scriptId"));

            scriptName = String(recSet("scriptName"));

        } else {

            tempSet.Open("SELECT scriptName FROM scriptIdTab WHERE scriptId="+scriptId,dbConn);

            if (tempSet.EOF == false) {

                scriptName = String(tempSet("scriptName"));

                needToSave = "true";

            }

            tempSet.Close();

        }

        if (Number(recSet("useScriptPending")) == 0) {

            useScriptPending = "";

            radioSet += "scriptPending[0].checked=false; scriptPending[1].checked=true; ";

        } else {

            useScriptPending = "checked";

            if (Number(recSet("useScriptPending")) == 1) {

                radioSet += "scriptPending[0].checked=true; scriptPending[1].checked=false; ";

            } else {

                radioSet += "scriptPending[0].checked=false; scriptPending[1].checked=true; ";

            }

        }

        if (Number(recSet("useScriptResult")) == 0) {

            useScriptResult = "";

            radioSet += "scriptResult[0].checked=false; scriptResult[1].checked=true; ";

        } else {

            useScriptResult = "checked";

            if (Number(recSet("useScriptResult")) == 1) {

                radioSet += "scriptResult[0].checked=true; scriptResult[1].checked=false; ";

            } else {

                radioSet += "scriptResult[0].checked=false; scriptResult[1].checked=true; ";

            }

        }

        if (Number(recSet("useScriptSince")) == 0) {

            useScriptSince = "";

            radioSet += "scriptSince[0].checked=false; scriptSince[1].checked=true; ";

        } else {

            useScriptSince = "checked";

            if (Number(recSet("useScriptSince")) == 1) {

                radioSet += "scriptSince[0].checked=true; scriptSince[1].checked=false; ";

            } else {

                radioSet += "scriptSince[0].checked=false; scriptSince[1].checked=true; ";

            }

        }

        scriptMin = Number(recSet("scriptMin"));

        // convert to hour or day

        scriptHr = scriptMin / 60;

        scriptDay = scriptHr / 24;

        if (Math.round(scriptDay) == scriptDay) {

            scriptMin = scriptDay;

            scriptMinUnit = "Day";

        } else if (Math.round(scriptHr) == scriptHr) {

            scriptMin = scriptHr;

            scriptMinUnit = "Hr";

        } else {

            scriptMinUnit = "Min";

        }

     

        if (Number(recSet("useAppName")) == 0) {

            useAppName = "";

            radioSet += "appContainMiss[0].checked=true; appContainMiss[1].checked=false; ";

        } else {

            useAppName = "checked";

            if (Number(recSet("useAppName")) == 1) {

                radioSet += "appContainMiss[0].checked=true; appContainMiss[1].checked=false; ";

            } else {

                radioSet += "appContainMiss[0].checked=false; appContainMiss[1].checked=true; ";

            }

        }

        appFilter = String(recSet("appFilter"));

        if (String(appFilter) == "null") appFilter = "*";

        if (Number(recSet("useAppVer")) == 0) {

            useAppVer = "";

            radioSet += "verCompare[0].checked=true; verCompare[1].checked=false; verCompare[2].checked=false; verCompare[3].checked=false; ";

        } else {

            useAppVer = "checked";

            if (Number(recSet("useAppVer")) == 1) {

                radioSet += "verCompare[0].checked=true; verCompare[1].checked=false; verCompare[2].checked=false; verCompare[3].checked=false; ";

            } else if (Number(recSet("useAppVer")) == 2) {

                radioSet += "verCompare[0].checked=false; verCompare[1].checked=true; verCompare[2].checked=false; verCompare[3].checked=false; ";

            } else if (Number(recSet("useAppVer")) == 3) {

                radioSet += "verCompare[0].checked=false; verCompare[1].checked=false; verCompare[2].checked=true; verCompare[3].checked=false; ";

            } else {

                radioSet += "verCompare[0].checked=false; verCompare[1].checked=false; verCompare[2].checked=false; verCompare[3].checked=true; ";

            }

        }

        verFilter = String(recSet("verFilter"));

        if (String(verFilter) == "null") verFilter = "0";

     

        if (Number(recSet("usePatchFil")) == 1) usePatchFil = "checked";

        else usePatchFil = "";

        missingPatches = Number(recSet("missingPatches"));

        if (Number(recSet("usePatchPolicy")) == 1) usePatchPolicy = "checked";

        else usePatchPolicy = "";

        if (Number(recSet("usePatchScanPending")) == 0) {

            usePatchScanPending = "";

            radioSet += "patchScanPending[0].checked=false; patchScanPending[1].checked=true; ";

        } else {

            usePatchScanPending = "checked";

            if (Number(recSet("usePatchScanPending")) == 1) {

                radioSet += "patchScanPending[0].checked=true; patchScanPending[1].checked=false; ";

            } else {

                radioSet += "patchScanPending[0].checked=false; patchScanPending[1].checked=true; ";

            }

        }

        if (Number(recSet("usePatchScanResult")) == 0) {

            usePatchScanResult = "";

            radioSet += "patchScanResult[0].checked=false; patchScanResult[1].checked=true; ";

        } else {

            usePatchScanResult = "checked";

            if (Number(recSet("usePatchScanResult")) == 1) {

                radioSet += "patchScanResult[0].checked=true; patchScanResult[1].checked=false; ";

            } else {

                radioSet += "patchScanResult[0].checked=false; patchScanResult[1].checked=true; ";

            }

        }

        if (Number(recSet("usePatchScanSince")) == 0) {

            usePatchScanSince = "";

            radioSet += "patchScanSince[0].checked=false; patchScanSince[1].checked=true; ";

        } else {

            usePatchScanSince = "checked";

            if (Number(recSet("usePatchScanSince")) == 1) {

                radioSet += "patchScanSince[0].checked=true; patchScanSince[1].checked=false; ";

            } else {

                radioSet += "patchScanSince[0].checked=false; patchScanSince[1].checked=true; ";

            }

        }

        patchScanMin = Number(recSet("patchScanMin"));

        // convert to hour or day

        patchScanHr = patchScanMin / 60;

        patchScanDay = patchScanHr / 24;

        if (Math.round(patchScanDay) == patchScanDay) {

            patchScanMin = patchScanDay;

            patchScanMinUnit = "Day";

        } else if (Math.round(patchScanHr) == patchScanHr) {

            patchScanMin = patchScanHr;

            patchScanMinUnit = "Hr";

        } else {

            patchScanMinUnit = "Min";

        }

     

        if (Number(recSet("usePatchRebootPending")) == 0) usePatchRebootPending = "";

        else usePatchRebootPending = "checked";

     

        if (Number(recSet("usePatchTestStatus")) == 0) usePatchTestStatus = "";

        else usePatchTestStatus = "checked";

        patchTestStatus = Number(recSet("patchTestStatus"));

     

        if (Number(recSet("usePatchAutoUpdateConfig")) == 0) usePatchAutoUpdateConfig = "";

        else usePatchAutoUpdateConfig = "checked";

        patchAutoUpdateConfig = Number(recSet("patchAutoUpdateConfig"));

     

        if (Number(recSet("usePatchRebootConfig")) == 0) usePatchRebootConfig = "";

        else usePatchRebootConfig = "checked";

        patchRebootConfig = Number(recSet("patchRebootConfig"));

     

        if (Number(recSet("usePatchFileSrcConfig")) == 0) usePatchFileSrcConfig = "";

        else usePatchFileSrcConfig = "checked";

        patchFileSrcConfig = String(recSet("patchFileSrcConfig"));

     

        if (Number(recSet("usePatchUnscanned")) == 0) usePatchUnscanned = "";

        else usePatchUnscanned = "checked";

     

        if (Number(recSet("usePatchMissingKB")) == 0) usePatchMissingKB = "";

        else usePatchMissingKB = "checked";

        patchMissingKB = String(recSet("patchMissingKB"));

     

        if (Number(recSet("viewToFilter")) == 0) ckView = "";

        else ckView = "checked";

        viewToFilter = String(recSet("viewToFilter"));

     

        if (Number(recSet("advFilter")) == 0) advFilter = "";

        else advFilter = "checked";

        advFilterId = Number(recSet("advFilterId"));

        if (advFilterId == 0) advFilterId = Number(String(Math.random()).substr(2,8));

     

     

        if (Number(recSet("useMonsetFilter")) == 0) useMonitorset = "";

        else useMonitorset = "checked";

        useMonitorsetID = Number(recSet("MonsetID"));

     

       if (Number(recSet("useSNMPsetFilter")) == 0) useSNMPMonitorset = "";

        else useSNMPMonitorset = "checked";

        useSNMPMonitorsetID = Number(recSet("SNMPsetID"));

    } else {

        editTitle = "";

        ownerId = sessionAdminId;

        readWrite = 0;

        useMachFil = "";

        overMachFil = "*";

        useGroupFil = "";

        useViewColFil = "";

        useColFil = 0;

        groupIdFil = "";

        if (showCollections == true) {

            radioSet += "showHideCollection[0].checked=true; showHideCollection[1].checked=false; ";

        }

        showCheckin = "";

        radioSet += "checkinStat[0].checked=false; checkinStat[1].checked=true; checkinStat[2].checked=false; setOnlineStat(); ";

        onLineMin = 1;

        onLineMinUnit = "Min";

        showSuspended = "";

        radioSet += "suspendedStat[0].checked=false; suspendedStat[1].checked=true; ";

        showReboot = "";

        radioSet += "rebootStat[0].checked=false; rebootStat[1].checked=true; ";

        rebootMin = 1;

        rebootMinUnit = "Min";

        useAgentCredentialStatus = "";

        agentCredentialStatus = -1;

        useGateway = "";

        onlyGateway = "";

        useIpFil = "";

        ipFil = "";

        useOs = "";

        osType = 0;

        useOsVer = "";

        osVer = "*";

        scriptId = 0;

        scriptName = "";

        useScriptPending = "";

        radioSet += "scriptPending[0].checked=false; scriptPending[1].checked=true; ";

        useScriptResult = "";

        radioSet += "scriptResult[0].checked=false; scriptResult[1].checked=true; ";

        useScriptSince = "";

        radioSet += "scriptSince[0].checked=false; scriptSince[1].checked=true; ";

        scriptMin = 1;

        scriptMinUnit = "Day";

        useAppName = "";

        radioSet += "appContainMiss[0].checked=true; appContainMiss[1].checked=false; ";

        appFilter = "*";

        useAppVer = "";

        radioSet += "verCompare[0].checked=true; verCompare[1].checked=false; verCompare[2].checked=false; verCompare[3].checked=false; ";

        verFilter = "0";

        usePatchFil = "";

        missingPatches = 0;

        usePatchPolicy = "";

        usePatchScanPending = "";

        radioSet += "patchScanPending[0].checked=false; patchScanPending[1].checked=true; ";

        usePatchScanResult = "";

        radioSet += "patchScanResult[0].checked=false; patchScanResult[1].checked=true; ";

        usePatchScanSince = "";

        radioSet += "patchScanSince[0].checked=false; patchScanSince[1].checked=true; ";

        patchScanMin = 1;

        patchScanMinUnit = "Day";

        usePatchRebootPending = "";

        usePatchTestStatus = "";

        patchTestStatus = -2;

        usePatchAutoUpdateConfig = "";

        patchAutoUpdateConfig = 0;

        usePatchRebootConfig = "";

        patchRebootConfig = 0;

        usePatchFileSrcConfig = "";

        patchFileSrcConfig = "0,4";

        usePatchUnscanned = "";

        usePatchMissingKB = "";

        ckView = "";

        patchMissingKB = "";

     

        advFilter = "";

        advFilterId = Number(String(Math.random()).substr(2,8));

     

        useMonitorset = "";

        useMonitorsetID = 0;

        useSNMPMonitorset = "";

        useSNMPMonitorsetID = 0;

     

    }

    recSet.Close();

     

    if (scriptName.length == 0) scriptName = "select agent procedure";

    if ((Number(activeViewId) == 0)||

        ((Number(readWrite)!=1)&&(Number(ownerId)!=Number(sessionAdminId)))) {

        shareDisabled = "disabled";

    } else {

        shareDisabled = "";

    }

    %>

    <HTML>

    <HEAD>

    <title>View Definitions</title>

    <!-- #include file = "../inc/mainStyle.inc" -->

    <style>

    <!--

    input {font-size: 12 px; font-family : Arial;}

    p {text-indent:-23px; padding-left:23px; margin-top:2px; margin-bottom:0px;}

    div {width:100%; padding-top:2px;}

    .viewButton {width:90px;margin-bottom:4px;}

    -->

    </style>

    </HEAD>

    <%

    if ((Number(readWrite) == 2)&&(Number(ownerId)!=Number(sessionAdminId))) {

        // execute only for this view. Do not let anyone other than the owner view or edit

    %>

    <body bgcolor="#FFFFFF">

    <table border="0" ID="Table1">

      <tr>

        <td width=80 align='center' valign='middle'>

          <img border="0" src="../images/warning32.gif">

        </td>

        <td align="left">

          <b><%Response.Write(xlate("You do not have rights to view or edit this view",false)+". "+

            xlate("You may only use this view",false))%>.</b>

        </td>

        <td align="center" valign="top" style="padding-left:20px;">

          <a href="javascript:self.close()"><%Response.Write(xlate("Close",false))%></a>

        </td>

      </tr>

    <%

        if (Number(sessionAdminType) == 2) {

    %>

      <tr>

        <td>&nbsp;</td>

        <td align="center"><a href="javascript:document.UserForm.submit()"><%Response.Write(xlate("Take Ownership",false))%></a></td>

        <td>&nbsp;</td>

      </tr>

      <form method="post" name="UserForm" ID="Form1">

        <input type="hidden" name="takeId" value="<%=activeViewId%>" ID="Hidden1">

      </form>

    <%

        }

    %>

    </table>

    <%

    } else {

    %>

    <script language="javascript">

    <!--#include file = "../inc/setSelector.js" -->

    var needToSave=<%=needToSave%>;

    var errMsg = new String("");

    function checkForm() {

      with (document.UserForm) {

        if ((useGateway.checked)&&(onlyGateway.value.length == 0)) {

            errMsg = "<%Response.Write(xlate("Enter connection gateway IP address",true))%>";

            onlyGateway.focus();

            onlyGateway.select();

            return(false);

        }

        if ((useIpFil.checked)&&(ipFil.value.length == 0)) {

            errMsg = "<%Response.Write(xlate("Fill in the IP address filter",true))%>";

            ipFil.focus();

            ipFil.select();

            return(false);

        }

        if ((useGroupFil.checked)&&(groupIdFil.length == 0)) {

            errMsg = "<%Response.Write(xlate("Select a group ID to filter on",true))%>";

            return(false);

        }

        if (editTitle.value.search(/[\%\'\"\/\\\:\?\<\>\|]/g) >= 0) {

            errMsg = "\%\'\"\/\\\:\?\<\>\| <%Response.Write(xlate("are illegal characters for names",true))%>"; //'

            return(false);

        }

        if (editTitle.value.length == 0) {

            errMsg = "<%Response.Write(xlate("Title is blank",true)+". "+xlate("Enter a name for this view",true))%>.";

            editTitle.focus();

            editTitle.select();

            return(false);

        }

      }

      return(true);

    }

    function buttonClick(bType) {

    // 1: save

    // 2: save as

    // 3: delete

        needToSave = false;

        document.UserForm.buttonType.value = bType;

        if (Number(bType) == 3) {

            if (confirm("<%Response.Write(xlate("Are you sure you want to permanently delete this view",true)+"?")%>")) {

                document.UserForm.submit();

            }

        } else if (Number(bType) == 2) {

            if (document.UserForm.editTitle.value.length == 0) {

                currViewName = "<%Response.Write(xlate("New View",true))%>";

            } else {

                currViewName = "<%Response.Write(xlate("Copy of",true))%> " + document.UserForm.editTitle.value;

            }

            saveAsViewName = prompt("<%Response.Write(xlate("Please enter new View name",true))%>", currViewName);

            if (String(saveAsViewName).toLowerCase() != "null") {

                document.UserForm.editTitle.disabled = false;

                document.UserForm.editTitle.value = saveAsViewName;

                if (checkForm()) {

                    document.UserForm.submit();

                }

            }

        } else if (checkForm()) {

            document.UserForm.submit();

        } else {

            alert(errMsg);

        }

    }

    function saveChanges() {

        if ((needToSave == true)&&("<%=shareDisabled%>".length == 0)) {

            if (confirm("Save changes first?") == true) {

                if (checkForm() == true) {

                    document.UserForm.buttonType.value = 1;

                    document.UserForm.submit();

                    return(true);

                } else {

                    alert(errMsg);

                }

            }

        }

        return(false);

    }

     

    function pickScript() {

        searchWin = window.open("/InstallTab/scriptSearch.asp?scriptPick=true","searchWin",

            "dependent,toolbar=no,scrollbars,resizable=yes,width=400,height=288,top=20,left=20");

        searchWin.focus();

    }

    function showScript() {

        document.UserForm.scriptId.value = document.UserForm.selectScriptId.value;

        document.getElementById("scriptLabel1").innerHTML=document.UserForm.scriptName.value;

        document.getElementById("scriptLabel2").innerHTML=document.UserForm.scriptName.value;

        document.getElementById("scriptLabel3").innerHTML=document.UserForm.scriptName.value;

    }

    function changeGroup() {

        if (document.UserForm.groupIdFil.value.length == 0) {

            document.UserForm.useGroupFil.checked = false;

        } else {

            document.UserForm.useGroupFil.checked = true;

        }

    }

    function changeView(ctl) {

        if (needToSave == true) {

            if (confirm("Save changes first?") == true) {

                setSelector("activeViewId",document.UserForm.lastViewId.value);

                if (checkForm() == true) {

                    if (document.UserForm.lastViewId.value == 0) {

                        document.UserForm.buttonType.value = 2; // Save As for a new view

                    } else {

                        document.UserForm.buttonType.value = 1;

                    }

                } else {

                    alert(errMsg);

                    return(false);

                }

            }

        }

        needToSave = false;

        changeCtlValue(ctl,true);

    }

    function openAdvanced(filId) {

        viewAdvWin=window.open("/ReportsTab/dataTableFilter.asp?viewFilter="+filId+

            "&viewOnly=<%=shareDisabled%>&"+String(Math.random()).substr(2,6),

            "viewAdvWin","scrollbars,toolbar=no,width=500,height=580,top=30,left=30,resizable=yes");

        document.UserForm.advFilter.checked = true;

        viewAdvWin.focus();

    }

    function setShare() {

        shareWin = window.open("/InstallTab/scriptShare.asp?itemId=<%=activeViewId%>&shareType=4"+

            "&"+String(Math.random()).substr(2,6),

            "shareWin","dependent,toolbar=no,resizable=yes,width=500,height=370,top=20,left=20");

        shareWin.focus();

    }

    function setOnlineStat() {

        if (document.UserForm.checkinStat[2].checked == true) {

            document.UserForm.onLineMin.disabled = true;

            document.UserForm.onLineMinUnit.disabled = true;

        } else {

            document.UserForm.onLineMin.disabled = false;

            document.UserForm.onLineMinUnit.disabled = false;

        }

    }

    function editViewCollection() {

        viewCollectionWin = window.open("collectionPicker.asp?editViewId=<%=activeViewId%>"+

            "&"+String(Math.random()).substr(2,6),

            "viewCollectionWin","dependent,toolbar=no,scrollbars,resizable=yes,width=966,height=700,top=20,left=20");

        viewCollectionWin.focus();

    }

    </script>

    <body bgcolor="#ffffff" onunload="saveChanges();">

    <form method="post" name="UserForm" style="margin-bottom:0px;">

    <input type="hidden" name="firstPass" value="true">

    <input type="hidden" name="buttonType" value=0>

    <input type="hidden" name="lastViewId" value="<%=activeViewId%>">

    <input type="hidden" name="scriptId" value="<%=scriptId%>">

    <input type="hidden" name="selectScriptId" value="<%=scriptId%>">

    <input type="hidden" name="scriptName" value="<%=scriptName%>">

    <table border=0 cellspacing=0 cellpadding=0 width="100%">

      <tr>

        <td rowspan=2 width=100 align="center" valign="middle" nowrap>

          <input type="button" name="saveBut" value="<%Response.Write(xlate("Save",true))%>" class="viewButton" onclick="return buttonClick(1)">

          <br>

          <input type="button" name="saveAsBut"  value="<%Response.Write(xlate("Save As",true))%>" class="viewButton" onclick="return buttonClick(2)">

          <br>

          <input type="button" name="deleteBut"  value="<%Response.Write(xlate("Delete",true))%>" class="viewButton" onclick="return buttonClick(3)">

        </td>

        <td align="left" width=70 class="label" nowrap><%Response.Write(xlate("Select View",false))%></td>

        <td align="left" width=150>

          <select size=1 name="activeViewId" class="small9pt" style="WIDTH:130px"

            onchange="changeView(this)" onmousedown="expandCtlWidth(this)" onblur="resetCtlWidth(this)">

            <option value=0 selected>&lt; <%Response.Write(xlate("New View",true))%> &gt;</option>

    <%

    recSet.Open("SELECT viewId,viewName,shareAll FROM viewDef WHERE adminId="+sessionAdminId+

        " OR viewId IN (SELECT viewId FROM viewAcl WHERE adminId="+sessionAdminId+

        " OR adminId = (select adminGroupId from appSession where appSessionId = "+sessionId+")) "+

        "OR (shareAll > 0 AND adminId in (select adminId from partnerUser WHERE partitionId = "+sessionPartition+"))"+

        " ORDER BY viewName",dbConn);

    while (recSet.EOF == false) {

        Response.Write("<option value="+recSet("viewId")+">"+recSet("viewName")+"</option>");

        recSet.MoveNext();

    }

    recSet.Close();

    %>

          </select>

        </td>

        <td align="center" valign="top">

    <!-- #include file = "../inc/helpLink.inc" -->

        <a href="javascript:getHelp()">

        <img border="0" src="/images/help.gif"></a>

        </td>

        <td align="right" valign="top">

        <a href="javascript:self.close();"><%Response.Write(xlate("Close",false))%></a>

        </td>

      </tr>

      <tr>

        <td align="left" class="label" nowrap>

          <%Response.Write(xlate("Edit Title",false))%>

        </td>

        <td align="left">

          <input type="text" name="editTitle" size=20 value="<%=editTitle%>"

            onclick="javascript:needToSave=true;">

        </td>

        <td colspan=2 align="center" valign="top">

          <input value='<%Response.Write(xlate("Share",true))%>...' name="shareButton" onclick="javascript:setShare()" type='button' <%=shareDisabled%>>

        </td>

      </tr>

    </table>

    <div onclick="needToSave=true;">

    <p style="padding-top:6px;" title="<%Response.Write(xlate("Force the machine ID filter to this setting when selecting this view",true)+". "+xlate("Machine ID may not be editted when using this view",true))%>.">

      <input type="checkbox" name="useMachFil" value="checked" <%=useMachFil%>>

      <%Response.Write(xlate("Set machine ID",false))%> <input type="text" size=15 name="overMachFil" value="<%=overMachFil%>"

        onchange="document.UserForm.useMachFil.checked=true">

    </p>

    <p title="<%Response.Write(xlate("Force the group ID filter to this setting when selecting this view",true)+". "+xlate("Group ID may not be edited when using this view",true))%>.">

      <input type="checkbox" name="useGroupFil" value="checked" <%=useGroupFil%>>

      <%Response.Write(xlate("Set group ID",false))%>

    <select size="1" name="groupIdFil" class="small9pt" style="width:168px;"

        onchange=document.UserForm.useGroupFil.checked=true; changeCtlValue(this,false)" onmousedown="expandCtlWidth(this)" onblur="resetCtlWidth(this)">

    <option value=''>&lt; <%Response.Write(xlate("Select Group ID",true))%> &gt;</option>

    <option value='*'>&lt; <%Response.Write(xlate("All Groups",true))%> &gt;</option>

    <%  //get all the group names to load into the drop down control

    var recSet = Server.CreateObject("ADODB.Recordset");

    recSet.Open(groupSql(),dbConn);

    while (recSet.EOF == false) {

        theGroupId = String(recSet("groupId"));

        Response.Write("<option value='"+theGroupId+"'");

        if (String(theGroupId) == groupIdFil) Response.Write(" selected");

        Response.Write(">"+theGroupId+"</option>");

        recSet.MoveNext();

    }

    recSet.Close();

    %>

    </select>

    </p>

    <p style="padding-top:6px;" title="<%Response.Write(xlate("Restict this view to only show data from selected machines",true)+".")%>.">

      <input type="checkbox" name="useViewColFil" value="checked" <%=useViewColFil%> ID="Checkbox4">

      <%Response.Write(xlate("Only show selected machine IDs",false))%>

    <%

    if (Number(activeViewId) > 0) {

        // remove any agentGuids that were deleted but the system has not cleaned the db yet.

        dbConn.Execute("DELETE FROM viewCollection WHERE agentGuid IN "+

            "(SELECT v.agentGuid FROM viewCollection v LEFT OUTER JOIN machNameTab m "+

            "ON v.agentGuid=m.agentGuid WHERE m.agentGuid IS NULL)",0,128);

        recSet.Open("SELECT COUNT(*) FROM viewCollection WHERE viewId="+activeViewId,dbConn,3);

        memberCnt = Number(recSet(0));

        recSet.Close();

    %>

    <a href="javascript:editViewCollection()" title="<%Response.Write(xlate("Click to select machines for a view collection",true))%>"

      ><%Response.Write("<span id='memberCnt'>"+memberCnt+"</span>&nbsp;"+xlate("machines selected",true))%></a>

    </p>

    <%

    } else {

        Response.Write("&nbsp;&nbsp;&nbsp;<i>"+xlate("Save view before assigning machines",true)+"</i>");

    }

    %>

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <p title="<%Response.Write(xlate("List machines that have or have not checked into the server within the specified period of time",true))%>.">

      <input type="checkbox" name="showCheckin" value="checked" <%=showCheckin%>>

      <%Response.Write(xlate("Show machines that",false))%>

      <input type="radio" name="checkinStat" value="0" onclick="setOnlineStat()"> <b><%Response.Write(xlate("have",false))%></b>

      <input type="radio" name="checkinStat" value="1" onclick="setOnlineStat()"> <b><%Response.Write(xlate("have not",false))%></b>

      <input type="radio" name="checkinStat" value="2" onclick="setOnlineStat()"> <b><%Response.Write(xlate("have never",false))%></b>

      <br><%Response.Write(xlate("been online in the last",false))%> <input type="text" name="onLineMin" value="<%=onLineMin%>" size=2>

      <select size=1 name="onLineMinUnit" class="small9pt">

        <option value="Min"><%Response.Write(xlate("Min",true))%></option>

        <option value="Hr"><%Response.Write(xlate("Hr",true))%></option>

        <option value="Day"><%Response.Write(xlate("Day",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that currently are suspended or not suspended",true))%>.">

      <input type="checkbox" name="showSuspended" value="checked" <%=showSuspended%>> <%Response.Write(xlate("Show machines that are",false))%>

      <input type="radio" name="suspendedStat" value=0 ID="Radio10"> <b><%Response.Write(xlate("suspended",false))%></b>

      <input type="radio" name="suspendedStat" value=1 ID="Radio11"> <b><%Response.Write(xlate("not suspended",false))%></b>

    </p>

    <p title="<%Response.Write(xlate("List machines that have or have not rebooted within the specified period of time",true))%>.">

      <input type="checkbox" name="showReboot" value="checked" <%=showReboot%> ID="Checkbox1">

      <%Response.Write(xlate("Show machines that",false))%>

      <input type="radio" name="rebootStat" value="0" ID="Radio1"> <b><%Response.Write(xlate("have",false))%></b>

      <input type="radio" name="rebootStat" value="1" ID="Radio2"> <b><%Response.Write(xlate("have not",false))%></b>

      <br><%Response.Write(xlate("rebooted in the last",false))%> <input type="text" name="rebootMin" value="<%=rebootMin%>" size=2 ID="Text1">

      <select size=1 name="rebootMinUnit" class="small9pt" ID="Select1">

        <option value="Min"><%Response.Write(xlate("Min",true))%></option>

        <option value="Hr"><%Response.Write(xlate("Hr",true))%></option>

        <option value="Day"><%Response.Write(xlate("Day",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific Credential status",true))%>.">

      <input type="checkbox" name="useAgentCredentialStatus" value="checked" <%=useAgentCredentialStatus%>>

      <%Response.Write(xlate("Machines with Credential status",false))%>

      <select size=1 name="agentCredentialStatus" class="small9pt" onchange="document.UserForm.useAgentCredentialStatus.checked=true">

        <option value=-1><%Response.Write(xlate("Missing Credential",true))%></option>

        <option value=0><%Response.Write(xlate("Credential Not Tested",true))%></option>

        <option value=1><%Response.Write(xlate("Credential Test Failed",true))%></option>

        <option value=2><%Response.Write(xlate("Credential Test Passed",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines whose connection gateway address match this filter",true)+". "+xlate("Use * as a wildcard",true))%>.">

      <input type="checkbox" name="useGateway" value="checked" <%=useGateway%>>

      <%Response.Write(xlate("Connection gateway filter",false))%> <input type="text" size=12 name="onlyGateway" value="<%=onlyGateway%>"

       onchange="document.UserForm.useGateway.checked=true">

    </p>

    <p title="<%Response.Write(xlate("List machines whose IP address match this filter",true)+". "+xlate("Use * as a wildcard",true)+". "+xlate("For instance: 192.168.* displays all machines in the class C private network space 192.168.0.0 through 192.168.255.255",true))%>">

      <input type="checkbox" name="useIpFil" value="checked" <%=useIpFil%>>

      <%Response.Write(xlate("IP address filter",false))%> <input type="text" size=12 name="ipFil" value="<%=ipFil%>"

        onchange="document.UserForm.useIpFil.checked=true">

    </p>

     

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <p title="<%Response.Write(xlate("List all machines running the selected operating system",true))%>.">

      <input type="checkbox" name="useOs" value="checked" <%=useOs%>> <%Response.Write(xlate("OS Type",false))%>

      <select size=1 name="osType" class="small9pt" onchange="document.UserForm.useOs.checked=true">

        <option value=0>&lt; <%Response.Write(xlate("Select Type",true))%> &gt;</option>

        <option value=13><%Response.Write(xlate("Mac OS X",true))%></option>

        <option value=17><%Response.Write(xlate("Linux",true))%></option>

        <option value=14><%Response.Write(xlate("All Windows Operating Systems",true))%></option>

        <option value=10><%Response.Write(xlate("All Workstations",true))%></option>

        <option value=11><%Response.Write(xlate("All Servers",true))%></option>

        <option value=1>Windows NT4 / 2000 / XP / 2003 / 2008 / 7</option>

        <option value=15>Windows Server 2008</option>

        <option value=9>Windows Server 2003</option>

        <option value=16>Windows 7</option>

        <option value=12>Windows Vista</option>

        <option value=8>Windows XP</option>

        <option value=3>Windows 2000</option>

        <option value=4>Windows NT4</option>

        <option value=2>Windows 95 / 98 / Me</option>

        <option value=5>Windows Me</option>

        <option value=6>Windows 98</option>

        <option value=7>Windows 95</option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines matching the operating system version string filter. Use * for wildcard. The Name/OS Info function under the Audit tab lists the OS version string. Use this filter to find all machines running a particular service pack.",true))%>">

      <input type="checkbox" name="useOsVer" value="checked" <%=useOsVer%>>

      <%Response.Write(xlate("OS version filter",false))%> <input type="text" name="osVer" value="<%=osVer%>" style="width:300px"

        onchange="document.UserForm.useOsVer.checked=true">

    </p>

     

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <p title="<%Response.Write(xlate("List machines that currently have the specified agent procedure scheduled or not",true)+". "+xlate("Select the script by clicking the 'select agent procedure' link",true))%>.">

      <input type="checkbox" name="useScriptPending" value="checked" <%=useScriptPending%>>

      <%Response.Write(xlate("With agent procedure",false))%> <a href='javascript:pickScript()'><span id='scriptLabel1'></span></a>

      <b><input type="radio" name="scriptPending" value=1> <%Response.Write(xlate("scheduled",false))%>

      <input type="radio" name="scriptPending" value=2> <%Response.Write(xlate("not scheduled",false))%></b>

    </p>

    <p title="<%Response.Write(xlate("List machines that have run the specified agent procedure at least once and whose result was either success or failure",true)+". "+xlate("Select the agent procedure by clicking the 'select agent procedure' link",true))%>.">

      <input type="checkbox" name="useScriptResult" value="checked" <%=useScriptResult%>>

      <%Response.Write(xlate("Last execution status for",false))%> <a href='javascript:pickScript()'><span id='scriptLabel2'></span></a>

      <b><input type="radio" name="scriptResult" value=1> <%Response.Write(xlate("success",false))%>

      <input type="radio" name="scriptResult" value=2> <%Response.Write(xlate("failed",false))%></b>

    </p>

    <p title="<%Response.Write(xlate("List machines that have or have not executed the specified script in the given period of time",true)+". "+xlate("Select the script by clicking the 'select agent procedure' link",true))%>.">

      <input type="checkbox" name="useScriptSince" value="checked" <%=useScriptSince%>>

      <%Response.Write(xlate("Agent Procedure",false))%> <a href='javascript:pickScript()'><span id='scriptLabel3'></span></a>

      <b><input type="radio" name="scriptSince" value=1> <%Response.Write(xlate("has",false))%>

      <input type="radio" name="scriptSince" value=2> <%Response.Write(xlate("has not",false))%></b>

      <br><%Response.Write(xlate("executed in the last",false))%> <input type="text" name="scriptMin" value="<%=scriptMin%>" size=2>

      <select size=1 name="scriptMinUnit" class="small9pt">

        <option value="Min"><%Response.Write(xlate("Min",true))%></option>

        <option value="Hr"><%Response.Write(xlate("Hr",true))%></option>

        <option value="Day"><%Response.Write(xlate("Day",true))%></option>

      </select>

    </p>

     

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <p title="<%Response.Write(xlate("List machines containing or missing applications matching the filter",true)+". "+xlate("Use * for wildcard",true)+". "+xlate("Use this view to find all machines containing an application",true))%>.">

      <input type="checkbox" name="useAppName" value="checked" <%=useAppName%> ID="Checkbox2">

      <input type="radio" name="appContainMiss" value=1 ID="Radio3"><b><%Response.Write(xlate("Contains",false))%></b>

      <input type="radio" name="appContainMiss" value=2 ID="Radio4"><b><%Response.Write(xlate("Missing",false))%></b>

      <%Response.Write(xlate("application",false))%> <input type="text" name="appFilter" value="<%=appFilter%>" style="width:160px"

        onchange="document.UserForm.useAppName.checked=true" ID="Text2">

    </p>

    <p title="<%Response.Write(xlate("List machines with applications matching the application filter AND whose application version string is greater than or less than or equal to the specified string",true)+". \r\n"+

       xlate("NOTE: This is a string, NOT a number, so the compare is in alphabetical order",true))%>.">

      <input type="checkbox" name="useAppVer" value="checked" <%=useAppVer%> style="margin-left:24px;">

      <%Response.Write(xlate("Version string is",false))%>

      <input type="radio" name="verCompare" value=1 ID="Radio5"><b>&gt;</b>

      <input type="radio" name="verCompare" value=2 ID="Radio6"><b>&lt;</b>

      <input type="radio" name="verCompare" value=3 ID="Radio7"><b>=</b>

      <input type="radio" name="verCompare" value=4 ID="Radio9"><b>Like</b>

      <input type="text" name="verFilter" value="<%=verFilter%>" style="width:100px"

        onchange="document.UserForm.useAppVer.checked=true" ID="Text3">

    </p>

     

    <%

    if(appInt > 0) {

    %>

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <%

        Response.Write(xlate("Show machines with the following modules installed",false));

    }

    for(i = 0;i < appInt; i++) {

      if(i == 0) {

    %>

      <br /><input type="checkbox" name="useApp1" value="checked" <%=useApp1%>>

    <%

        } else if (i == 1) {

    %>

      <br /><input type="checkbox" name="useApp2" value="checked" <%=useApp2%>>

    <%

        } else if (i == 2) {

    %>

      <br /><input type="checkbox" name="useApp3" value="checked" <%=useApp3%>>

    <%

        } else if (i == 3) {

    %>

      <br /><input type="checkbox" name="useApp4" value="checked" <%=useApp4%>>

    <%

        } else if (i == 4) {

    %>

      <br /><input type="checkbox" name="useApp5" value="checked" <%=useApp5%>>

    <%

        } else if (i == 5) {

    %>

      <br /><input type="checkbox" name="useApp6" value="checked" <%=useApp6%>>

    <%

        } else if (i == 6) {

    %>

      <br /><input type="checkbox" name="useApp7" value="checked" <%=useApp7%>>

    <%

        } else if (i == 7) {

    %>

      <br /><input type="checkbox" name="useApp8" value="checked" <%=useApp8%>>

    <%

        } else if (i == 8) {

    %>

      <br /><input type="checkbox" name="useApp9" value="checked" <%=useApp9%>>

    <%

        } else if (i == 9) {

    %>

      <br /><input type="checkbox" name="useApp10" value="checked" <%=useApp10%>>

    <%

        } else if (i == 10) {

    %>

      <br /><input type="checkbox" name="useApp11" value="checked" <%=useApp11%>>

    <%

        } else if (i == 11) {

    %>

      <br /><input type="checkbox" name="useApp12" value="checked" <%=useApp12%>>

    <%

        } else if (i == 12) {

    %>

      <br /><input type="checkbox" name="useApp13" value="checked" <%=useApp13%>>

    <%

        } else if (i == 13) {

    %>

      <br /><input type="checkbox" name="useApp14" value="checked" <%=useApp14%>>

    <%

        } else if (i == 14) {

    %>

      <br /><input type="checkbox" name="useApp15" value="checked" <%=useApp15%>>

    <%

        } else if (i == 15) {

    %>

      <br /><input type="checkbox" name="useApp16" value="checked" <%=useApp16%>>

    <%

        } else if (i == 16) {

    %>

      <br /><input type="checkbox" name="useApp17" value="checked" <%=useApp17%>>

    <%

        } else if (i == 17) {

    %>

      <br /><input type="checkbox" name="useApp18" value="checked" <%=useApp18%>>

    <%

        } else if (i == 18) {

    %>

      <br /><input type="checkbox" name="useApp19" value="checked" <%=useApp19%>>

    <%

        } else if (i == 19) {

    %>

      <br /><input type="checkbox" name="useApp20" value="checked" <%=useApp20%>>

    <%

        }

        Response.Write(xlate(appArrayStrIdea,false));

    }

    %>

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <%if (showCollections == true) { %>

    <p title="<%Response.Write(xlate("Only show machines from this patch policy that match the machine ID and group ID filters",true))%>.">

      <input type="checkbox" name="useColFil" value="checked" <%=useColFil%>>

      <input type="radio" name="showHideCollection" value="0"> <b><%Response.Write(xlate("Show",false))%></b>

      <input type="radio" name="showHideCollection" value="1"> <b><%Response.Write(xlate("Hide",false))%></b>

      <%Response.Write(xlate("members of patch policy",false))%>

    <select size="1" name="colIdFil" class="small9pt" style="width:210px;"

        onchange="document.UserForm.useColFil.checked=true; changeCtlValue(this,false)" onmousedown="expandCtlWidth(this)" onblur="resetCtlWidth(this)">

            <option value='0'>&lt; <%Response.Write(xlate("unassigned machines",true))%> &gt;</option>

    <!-- #include virtual = "/PatchTab/patchPolicySql.inc" -->

    <%

    recSet.Open(patchPolicySql,dbConn,3);

    while (recSet.EOF == false) {

        Response.Write("<option value='"+String(recSet("collectionId"))+"'>"+

            String(recSet("collectionName"))+"</option>");

        recSet.MoveNext();

    }

    recSet.Close();

    %>

    </select>

    </p>

    <% } %>

    <p title="<%Response.Write(xlate("List machines that have not been scanned for missing patches",true))%>.">

      <input type="checkbox" name="usePatchUnscanned" value="checked" <%=usePatchUnscanned%>>

      <%Response.Write(xlate("Machines that have no patch scan results (unscanned)",false))%>

    </p>

    <p>

      <span title="<%Response.Write(xlate("List machines with a minimum number of missing patches",false))%>.">

          <input type="checkbox" name="usePatchFil" value="checked" <%=usePatchFil%>>

          <%Response.Write(xlate("Machines missing greater than or equal to",true))%>

          <input type="text" name="missingPatches" value="<%=missingPatches%>" maxlength="3" style="width:30px" onchange="document.UserForm.usePatchFil.checked=true">

          <%Response.Write(xlate("patches",true))%>.&nbsp;&nbsp;(

      </span>

      <span title="<%Response.Write(xlate("List machines with a minimum number of missing approved patches according to patch approval policies",false))%>.">

          <input type="checkbox" name="usePatchPolicy" value="checked" <%=usePatchPolicy%>>

          <%Response.Write(xlate("Use Patch Policy",true))%>&nbsp;)

      </span>

    </p>

    <p title="<%Response.Write(xlate("List machines that currently have a patch scan scheduled or not",true))%>.">

      <input type="checkbox" name="usePatchScanPending" value="checked" <%=usePatchScanPending%>>

      <%Response.Write(xlate("Patch scan",false))%>

      <b><input type="radio" name="patchScanPending" value=1> <%Response.Write(xlate("scheduled",false))%>

      <input type="radio" name="patchScanPending" value=2> <%Response.Write(xlate("not scheduled",false))%></b>

    </p>

    <p title="<%Response.Write(xlate("List machines that have run a patch scan at least once and whose result was either success or failure",true))%>.">

      <input type="checkbox" name="usePatchScanResult" value="checked" <%=usePatchScanResult%>>

      <%Response.Write(xlate("Last execution status for patch scan",false))%>

      <b><input type="radio" name="patchScanResult" value=1> <%Response.Write(xlate("success",false))%>

      <input type="radio" name="patchScanResult" value=2> <%Response.Write(xlate("failed",false))%></b>

    </p>

    <p title="<%Response.Write(xlate("List machines that have or have not executed a patch scan in the given period of time",true))%>.">

      <input type="checkbox" name="usePatchScanSince" value="checked" <%=usePatchScanSince%>>

      <%Response.Write(xlate("Patch scan",false))%>

      <b><input type="radio" name="patchScanSince" value=1> <%Response.Write(xlate("has",false))%>

      <input type="radio" name="patchScanSince" value=2> <%Response.Write(xlate("has not",false))%></b>

      <%Response.Write(xlate("executed in the last",false))%> <input type="text" name="patchScanMin" value="<%=patchScanMin%>" size=2>

      <select size=1 name="patchScanMinUnit" class="small9pt">

        <option value="Min"><%Response.Write(xlate("Min",true))%></option>

        <option value="Hr"><%Response.Write(xlate("Hr",true))%></option>

        <option value="Day"><%Response.Write(xlate("Day",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that have Reboot Pending for patch installations",true))%>.">

      <input type="checkbox" name="usePatchRebootPending" value="checked" <%=usePatchRebootPending%>>

      <%Response.Write(xlate("Machines with Reboot Pending for patch installations",false))%>

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific Patch Test Result",true))%>.">

      <input type="checkbox" name="usePatchTestStatus" value="checked" <%=usePatchTestStatus%>>

      <%Response.Write(xlate("Machines with Patch Test Result",false))%>

      <select size=1 name="patchTestStatus" class="small9pt" onchange="document.UserForm.usePatchTestStatus.checked=true">

        <option value=-2><%Response.Write(xlate("Pending",true))%></option>

        <option value=-1><%Response.Write(xlate("Untested",true))%></option>

        <option value=0><%Response.Write(xlate("Passed",true))%></option>

        <option value=1><%Response.Write(xlate("Failed-All",true))%></option>

        <option value=2><%Response.Write(xlate("Failed-Credential",true))%></option>

        <option value=3><%Response.Write(xlate("Failed-Other",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific Automatic Update configuration",true))%>.">

      <input type="checkbox" name="usePatchAutoUpdateConfig" value="checked" <%=usePatchAutoUpdateConfig%>>

      <%Response.Write(xlate("Machines with Patch Automatic Update configuration",false))%>

      <select size=1 name="patchAutoUpdateConfig" class="small9pt" onchange="document.UserForm.usePatchAutoUpdateConfig.checked=true">

        <option value=0><%Response.Write(xlate("None",true))%></option>

        <option value=1><%Response.Write(xlate("Daily",true))%></option>

        <option value=2><%Response.Write(xlate("Weekly",true))%></option>

        <option value=3><%Response.Write(xlate("Monthly",true))%></option>

        <option value=4><%Response.Write(xlate("Run Once",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific Patch Reboot Action configuration",true))%>.">

      <input type="checkbox" name="usePatchRebootConfig" value="checked" <%=usePatchRebootConfig%>>

      <%Response.Write(xlate("Machines with Patch Reboot Action configuration",false))%>

      <select size=1 name="patchRebootConfig" class="small9pt" onchange="document.UserForm.usePatchRebootConfig.checked=true">

        <option value=0><%Response.Write(xlate("Reboot Immediately",true))%></option>

        <option value=6><%Response.Write(xlate("Reboot at Time",true))%></option>

        <option value=4><%Response.Write(xlate("Warn User",true))%></option>

        <option value=5><%Response.Write(xlate("Skip",true))%></option>

        <option value=7><%Response.Write(xlate("Ask until Reboot",true))%></option>

        <option value=3><%Response.Write(xlate("Ask - Reboot",true))%></option>

        <option value=1><%Response.Write(xlate("Ask - Do Nothing",true))%></option>

        <option value=2><%Response.Write(xlate("Do Not Reboot",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific File Source configuration",true))%>.">

      <input type="checkbox" name="usePatchFileSrcConfig" value="checked" <%=usePatchFileSrcConfig%>>

      <%Response.Write(xlate("Machines with Patch File Source configuration",false))%>

      <select size=1 name="patchFileSrcConfig" class="small9pt" onchange="document.UserForm.usePatchFileSrcConfig.checked=true">

        <option value='0,4'><%Response.Write(xlate("Internet",true))%></option>

        <option value='1,5'><%Response.Write(xlate("System Server",true))%></option>

        <option value='2,3,6,7'><%Response.Write(xlate("File Server",true))%></option>

      </select>

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific patch missing (use KB Article ID)",true))%>.">

      <input type="checkbox" name="usePatchMissingKB" value="checked" <%=usePatchMissingKB%>>

      <%Response.Write(xlate("Machines missing patch (use 6 digit KB Article ID)",false))%>

      <input type="text" name="patchMissingKB" value="<%=patchMissingKB%>" maxlength="10" style="width:100px" onchange="document.UserForm.usePatchMissingKB.checked=true">

    </p>

    <p title="<%Response.Write(xlate("List machines that have a specific patch missing (use KB Article ID)",true))%>.">

      <input type="checkbox" name="ckView" value="checked" <%=ckView%>>

      <%Response.Write(xlate("View or table (with agentGuid) to filter on (ie. CustomData.dbo.vTeleflora)",false))%>

      <input type="text" name="viewToFilter" value="<%=viewToFilter%>" maxlength="100" style="width:350px" onchange="document.UserForm.ckView.checked=true">

      <br><b><%Response.Write(xlate("If you enter an invalid table/view value will reset to vAgentLabel",false))%></b>

    </p>

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <p title="<%Response.Write(xlate("Only display the machine IDs whose data matches the specified filter parameters",true))%>.">

      <input type="checkbox" name="advFilter" value="checked" <%=advFilter%> ID="Checkbox3">

      <%Response.Write(xlate("Advanced agent data filter",false))%>

      <input type="button" value="<%Response.Write(xlate("Define Filter",true))%>..."

      class="tinyButton" onclick="openAdvanced(<%=advFilterId%>)" >

      <input type="hidden" name="advFilterId" value="<%=advFilterId%>">

    </p>

    </div>

    <div><img border="0" src="/images/horizontalLine.gif" width="100%" height="1"></div>

    <p title="<%Response.Write(xlate("Only show machines with monitorset assigned",true))%>.">

      <input type="checkbox" name="useMonitorset" value="checked" <%=useMonitorset%>>

      <%Response.Write(xlate("Only show machines with monitorset assigned",false))%>

    <select size="1" name="useMonitorsetID" class="small9pt" style="width:210px;"

        onchange="document.UserForm.useMonitorset.checked=true; changeCtlValue(this,false)" onmousedown="expandCtlWidth(this)" onblur="resetCtlWidth(this)">

            <option value='0'>&lt; <%Response.Write(xlate("Select a Monitorset ...",true))%> &gt;</option>

    <%

    monsetSQL = "";

    thisAdminType = 1;

    recSet.Open("select a.adminType from administrators a left outer join adminIdTab ait on a.adminName = ait.adminName where ait.adminId = " + sessionAdminId,dbConn,3);

    if(recSet.EOF == false) {

    thisAdminType = recSet["adminType"];

    }

    recSet.Close();

     

    if(thisAdminType == 2) {

    monsetSQL =  " select distinct MS.name, MS.monitorSetId from monitorSetMachineXref  MXF with (nolock) Join Monitorset MS WITH (NOLOCK) " +

    " on MXF.Monitorsetid = MS.Monitorsetid and MS.partitionId = "+sessionPartition+" ORDER BY MS.Name";

    } else {

    monsetSQL =  "SELECT ms.name, ms.description, ms.monitorsetid, ISNULL(TRN.TreeFullPath, '') TreeFullPath  FROM monitorset ms  WITH(NOLOCK) " + 

    " Join fn_treePresCommon_List (" + sessionAdminId + " , " + sessionId + ", NULL, " + sessionPartition + " , NULL, 20, 'myMonitorSets', 'N', 'Y' ) TRN" + 

    " ON ms.MonitorsetID = TRN.treeNodeObjectFK  WHERE TRN.TreeFullPath NOT LIKE 'Kaseya Samples%'  " +        

    " ORDER BY ms.name";

    }

    recSet.Open(monsetSQL,dbConn,3);

    while (recSet.EOF == false) {

        Response.Write("<option value='"+String(recSet("MonitorsetID"))+"'>"+

            String(recSet("Name"))+"(" + String(recSet("MonitorsetID")) + ")" + "</option>");

        recSet.MoveNext();

    }

    recSet.Close();

    %>

    </select>

    </p>

    <p title="<%Response.Write(xlate("Only show machines with SNMPset assigned",true))%>.">

      <input type="checkbox" name="useSNMPMonitorset" value="checked" <%=useSNMPMonitorset%>>

      <%Response.Write(xlate("Only show machines with monitorset assigned",false))%>

    <select size="1" name="useSNMPMonitorsetID" class="small9pt" style="width:210px;"

        onchange="document.UserForm.useSNMPMonitorset.checked=true; changeCtlValue(this,false)" onmousedown="expandCtlWidth(this)" onblur="resetCtlWidth(this)">

            <option value='0'>&lt; <%Response.Write(xlate("Select a SNMPset ...",true))%> &gt;</option>

    <%

    monsetSQL = "";

    if(thisAdminType == 2) {

    monsetSQL =  " select distinct  MS.name, MS.monitorsnmpSetId from monitorSnmpSetAgentXref  MXF with (nolock) Join Monitorsnmpset MS WITH (NOLOCK)  " +

    " on MXF.Monitorsnmpsetid = MS.Monitorsnmpsetid and MS.partitionId = "+sessionPartition+ "  ORDER BY MS.Name";

    } else {

    monsetSQL =  "SELECT ms.name, ms.description, ms.monitorSNMPsetid, ISNULL(TRN.TreeFullPath, '') TreeFullPath  FROM monitorsnmpset ms  WITH(NOLOCK) " + 

    " Join fn_treePresCommon_List (" + sessionAdminId + " , " + sessionId + ", NULL, " + sessionPartition + " , NULL, 21, 'mySNMPSets', 'N', 'Y' ) TRN" + 

    " ON ms.monitorSnmpSetId = TRN.treeNodeObjectFK  WHERE TRN.TreeFullPath NOT LIKE 'Kaseya Samples%'  " +        

    " ORDER BY ms.name";

    }

    recSet.Open(monsetSQL,dbConn,3);

    while (recSet.EOF == false) {

        Response.Write("<option value='"+String(recSet("monitorsnmpSetId"))+"'>"+

            String(recSet("Name"))+"(" + String(recSet("monitorsnmpSetId")) + ")" + "</option>");

        recSet.MoveNext();

    }

    recSet.Close();

    %>

    </select>

    </p>

    </div>

     

     

     

     

    </form>

    <script language="javascript">

    showScript();

    setSelector("activeViewId","<%=activeViewId%>");

    with (document.UserForm) {

        <% =radioSet %>

        if ("<%=shareDisabled%>".length > 0) {

            saveBut.disabled = true;

            deleteBut.disabled = true;

            editTitle.disabled = true;

            shareButton.disabled = true;

        }

        setSelector("onLineMinUnit","<%=onLineMinUnit%>");

        setSelector("rebootMinUnit","<%=rebootMinUnit%>");

        setSelector("agentCredentialStatus","<%=agentCredentialStatus%>");

        setSelector("scriptMinUnit","<%=scriptMinUnit%>");

        setSelector("patchScanMinUnit","<%=patchScanMinUnit%>");

        setSelector("patchTestStatus","<%=patchTestStatus%>");

        setSelector("patchAutoUpdateConfig","<%=patchAutoUpdateConfig%>");

        setSelector("patchRebootConfig","<%=patchRebootConfig%>");

        setSelector("patchFileSrcConfig","<%=patchFileSrcConfig%>");

        setSelector("useMonitorsetID","<%=useMonitorsetID%>");

        setSelector("useSNMPMonitorsetID","<%=useSNMPMonitorsetID%>");

        setSelector("groupIdFil","<%=groupIdFil%>");

    <% if (showCollections == true) { %>

        setSelector("colIdFil","<%=colIdFil%>");

    <% } %>

        setSelector("osType","<%=osType%>");

    }

    try {

        <%

        var checkPostBack = new String(Request.ServerVariables("REQUEST_METHOD"))

        if (checkPostBack == "POST")

            {

        %>

        if(opener.document.location.href.indexOf('#') > 1)

        {

            if(opener.document.location.href.indexOf('?') > 1)

            {

                opener.document.location = opener.document.location.href.replace('#', '&reload=true#');

            }

            else

            {

                opener.document.location = opener.document.location.href.replace('#', '?reload=true#');

            }

        }

        else

        {

            if(opener.document.location.href.indexOf('?') > 1)

            {

                opener.document.location = opener.document.location.href+'&reload=true';

     

            }

            else

            {

                opener.document.location = opener.document.location.href+'?reload=true';

            }

        }

        <% } %>

    }

    catch(err) { }

    setTimeout("self.focus();",1500);

    </script>

    <!-- #include virtual = "/inc/selectExpand.js" -->

    <%

    }

    %>

    <!-- #include virtual = "/inc/xlate.inc" -->

    </body>

    </HTML>

  • EDITVIEW.inc

     

    <!-- #include file = "../inc/smbiosArray.inc" -->

    <!-- #include file = "../inc/colFilterToSql.inc" -->

    <!-- #include file = "../inc/getDataTabSql.inc" -->

    <!-- #include file = "../inc/convertData.inc" -->

    <!-- #include file = "../inc/errorLogger.inc" -->

    <%

    // Database views created for view filters use the following naming convention:

    //    fvFilterView99999999

    // where 99999999 represents the viewDef.viewId primary key value

    var viewSet = Server.CreateObject("ADODB.Recordset");

    var advFilterSet = Server.CreateObject("ADODB.Recordset");

     

    var tempSet = Server.CreateObject("ADODB.Recordset");

     

    function doViews(){

        tempSet.Open("SELECT viewId FROM viewDef", dbConn);

        while (!tempSet.EOF) {

            saveDbView(Number(tempSet("viewId")));

            tempSet.MoveNext();

        }

        tempSet.Close();

     

        tempSet.Open("SELECT so.name FROM ksubscribers..sysobjects so "+

                     "LEFT OUTER JOIN viewDef v ON v.viewId = CAST(SUBSTRING(so.name, 13, 128) AS INT) "+

                     "WHERE name LIKE N'fvFilterView%' AND v.viewId IS NULL", dbConn);

        while (!tempSet.EOF) {

            dbConn.Execute("DROP VIEW "+String(tempSet("name")),0,128);

            tempSet.MoveNext();

        }

        tempSet.Close();

    }

     

    function escapeSearchString(sourceStr) {

        return sourceStr.replace(/\%/g,"[%]").replace(/\_/g,"[_]").replace(/\*/g,"%");

    }

     

    function buildDbViewSql(viewId) {

        viewIdStr = String(viewId);

        dbViewDef = "CREATE VIEW fvFilterView"+viewIdStr+" AS "+

                    "SELECT a.agentGuid, a.agentGuidStr, a.machName, a.groupName, a.displayName, a.partitionId FROM machNameTab a ";

     

        joinClause = "";

        whereClause = "";

     

        viewSet.Open("SELECT * FROM viewDef WHERE viewId = "+viewId, dbConn);

        if (!viewSet.EOF) {

            // show machines in a view collection

            if (Number(viewSet("useViewColFil")) > 0) {

                joinClause += "JOIN viewCollection vc ON a.agentGuid = vc.agentGuid ";

                whereClause += "AND (vc.viewId = "+viewId+")";

            }

            // show machines online

            if (Number(viewSet("showCheckin")) > 0) {

                joinClause += "LEFT OUTER JOIN agentState b ON a.agentGuid = b.agentGuid ";

                if (Number(viewSet("showCheckin")) == 1) {

                    // have checked in in the last N time

                    whereClause += "AND ((ISNULL(b.online,199) = 1) OR (b.offlineTime > DATEADD(MINUTE,-"+String(viewSet("onLineMin"))+",CURRENT_TIMESTAMP))) ";

                } else if (Number(viewSet("showCheckin")) == 2) {

                    // have not checked in in the last N time

                    whereClause += "AND ((ISNULL(b.online,199) = 0) AND (b.offlineTime < DATEADD(MINUTE,-"+String(viewSet("onLineMin"))+",CURRENT_TIMESTAMP))) ";

                } else {

                    // have never checked in

                    whereClause += "AND (b.online IS NULL) ";

                }

            }

            // show machines that are/are not suspended

            if (Number(viewSet("showSuspended")) > 0) {

                joinClause += "JOIN users su ON a.agentGuid = su.agentGuid ";

                whereClause += "AND ISNULL(su.suspendAgent,0) = ";

                if (Number(viewSet("showSuspended")) == 1) {

                    // suspended

                    whereClause += "1 ";

                } else {

                    // not suspended

                    whereClause += "0 ";

                }

            }

            // show machines that rebooted in last N minutes

            if (Number(viewSet("showReboot")) > 0) {

                joinClause += "JOIN lastReboot lr ON a.agentGuid = lr.agentGuid ";

                whereClause += "AND (lr.rebootTime";

                if (Number(viewSet("showReboot")) == 1) {

                    whereClause += " > ";

                } else {

                    whereClause += " < ";

                }

                whereClause += "DATEADD(MINUTE,-"+String(viewSet("rebootMin"))+",CURRENT_TIMESTAMP)) ";

            }

            // credential status filter

            if (Number(viewSet("useAgentCredentialStatus")) != 0) {

                joinClause += "LEFT OUTER JOIN credential cre ON a.agentGuid = cre.agentGuid ";

                if (Number(viewSet("agentCredentialStatus")) == -1) {

                    whereClause += "AND cre.username IS NULL ";

                } else if (Number(viewSet("agentCredentialStatus")) == 0) {

                    whereClause += "AND cre.username IS NOT NULL AND ISNULL(cre.testStatus,0) = 0";

                } else {

                    whereClause += "AND ISNULL(cre.testStatus,0) = "+Number(viewSet("agentCredentialStatus"))+" ";

                }

            }

            // connection gateway filter

            if (Number(viewSet("useGateway")) > 0) {

                joinClause += "JOIN userIpInfo c ON a.agentGuid = c.agentGuid ";

                whereClause += "AND (c.connectionGatewayIp LIKE '"+escapeSearchString(String(viewSet("onlyGateway")))+"') ";

            }

            // IP address filter

            if (Number(viewSet("useIpFil")) > 0) {

                joinClause += "JOIN userIpInfo d ON a.agentGuid = d.agentGuid ";

                whereClause += "AND (d.ipAddress LIKE '"+escapeSearchString(String(viewSet("ipFil")))+"') ";

            }

            // os type filter

            if (Number(viewSet("useOs")) > 0) {

                switch (Number(viewSet("useOs"))) {

                default:

                    break;

                case 1: // Windows NT4 / 2000 / XP / 2003 / 2008 / 7

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType IN ('NT4','2000','XP','2003','2008','7')) ";

                    break;

                case 2: // Windows 95 / 98 / Me

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType IN ('95','98','Me')) ";

                    break;

                case 3: // Windows 2000

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='2000') ";

                    break;

                case 4: // Windows NT4

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='NT4') ";

                    break;

                case 5: // Windows Me

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='Me') ";

                    break;

                case 6: // Windows 98

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='98') ";

                    break;

                case 7: // Windows 95

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='95') ";

                    break;

                case 8: // Windows XP

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='XP') ";

                    break;

                case 9: // Windows Server 2003

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='2003') ";

                    break;

                case 10: // All Workstations

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType IN ('95','98','XP','Vista','7') OR ((e.osType='NT4') AND (e.osInfo LIKE '%Workstation%')) "+

                                         "OR ((e.osType='2000') AND (e.osInfo LIKE '%Professional%')) OR ((e.osType='Mac OS X') AND (e.osInfo NOT LIKE '%Server%')) ) ";

                    break;

                case 11: // All Servers

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND ((e.osType='2008')OR(e.osType='2003')OR(e.osInfo LIKE '%server%')) ";

                    break;

                case 12: // Windows Vista

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='Vista') ";

                    break;

                case 13: // Mac OS X

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='Mac OS X') ";

                    break;

                case 14: // All Windows

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType IN ('95','98','NT4','2000','XP','2003','Vista','2008','7')) ";

                    break;

                case 15: // Windows Server 2008

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='2008') ";

                    break;

                case 16: // Windows 7

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='7') ";

                    break;

                case 17: // Linux

                    joinClause += "JOIN userIpInfo e ON a.agentGuid = e.agentGuid ";

                    whereClause += "AND (e.osType='Linux') ";

                    break;

                }

            }

            // OS version filter

            if (Number(viewSet("useOsVer")) != 0) {

                joinClause += "JOIN userIpInfo f ON a.agentGuid = f.agentGuid ";

                whereClause += "AND (f.osInfo LIKE '"+escapeSearchString(String(viewSet("osVer")))+"%') ";

            }

            // script pending filter

            if (Number(viewSet("useScriptPending")) != 0) {

                joinClause += "LEFT OUTER JOIN Hermes.vScriptEventStatus g ON a.agentGuid = g.agentGuid AND g.scriptId = "+String(viewSet("scriptId"))+" ";

                if (Number(viewSet("useScriptPending")) == 1) {

                    whereClause += "AND (g.nextRunTime IS NOT NULL) ";

                } else {

                    whereClause += "AND (g.nextRunTime IS NULL) ";

                }

            }

            // script exec status filter

            if (Number(viewSet("useScriptResult")) != 0) {

                joinClause += "JOIN scriptStatus h ON a.agentGuid = h.agentGuid AND h.scriptId = "+String(viewSet("scriptId"))+" ";

                if (Number(viewSet("useScriptResult")) == 1) {

                    whereClause += "AND (h.lastExecStatus LIKE '%Success%') ";

                } else {

                    whereClause += "AND (h.lastExecStatus LIKE '%Failed%') ";

                }

            }

            // script exec in last N minutes filter

            if (Number(viewSet("useScriptSince")) != 0) {

                joinClause += "LEFT OUTER JOIN scriptStatus i ON a.agentGuid = i.agentGuid AND i.scriptId = "+String(viewSet("scriptId"))+" ";

                if (Number(viewSet("useScriptSince")) == 1) {

                    whereClause += "AND (ISNULL(i.lastExecTime,'19800101') > DATEADD(MINUTE,-"+String(viewSet("scriptMin"))+",CURRENT_TIMESTAMP)) ";

                } else {

                    whereClause += "AND (ISNULL(i.lastExecTime,'19800101') < DATEADD(MINUTE,-"+String(viewSet("scriptMin"))+",CURRENT_TIMESTAMP)) ";

                }

            }

            // application filter

            if (Number(viewSet("useAppName")) == 1) {

                whereClause += "AND (a.agentGuid IN (SELECT agentGuid FROM auditRsltApps "+

                                                    "WHERE lastAudit = 1 AND applicationName LIKE '"+

                                                    escapeSearchString(String(viewSet("appFilter")))+"'";

                if (Number(viewSet("useAppVer")) == 1) {

                    whereClause += " AND dbo.fnCompareVersionStrings(version,'"+escapeSearchString(String(viewSet("verFilter")))+"') = 1 ";

                } else if (Number(viewSet("useAppVer")) == 2) {

                    whereClause += " AND dbo.fnCompareVersionStrings(version,'"+escapeSearchString(String(viewSet("verFilter")))+"') = -1 ";

                } else if (Number(viewSet("useAppVer")) == 3) {

                    whereClause += " AND dbo.fnCompareVersionStrings(version,'"+escapeSearchString(String(viewSet("verFilter")))+"') = 0 ";

                } else if (Number(viewSet("useAppVer")) == 4) {

                    whereClause += " AND version LIKE '"+escapeSearchString(String(viewSet("verFilter")))+"'";

                }

                whereClause += ")) ";

            } else if (Number(viewSet("useAppName")) == 2) {

                whereClause += "AND (a.agentGuid NOT IN (SELECT agentGuid FROM auditRsltApps "+

                                                        "WHERE lastAudit = 1 AND applicationName LIKE '"+

                                                        escapeSearchString(String(viewSet("appFilter")))+"'";

                if (Number(viewSet("useAppVer")) == 1) {

                    whereClause += " AND dbo.fnCompareVersionStrings(version,'"+escapeSearchString(String(viewSet("verFilter")))+"') = 1 ";

                } else if (Number(viewSet("useAppVer")) == 2) {

                    whereClause += " AND dbo.fnCompareVersionStrings(version,'"+escapeSearchString(String(viewSet("verFilter")))+"') = -1 ";

                } else if (Number(viewSet("useAppVer")) == 3) {

                    whereClause += " AND dbo.fnCompareVersionStrings(version,'"+escapeSearchString(String(viewSet("verFilter")))+"') = 0 ";

                } else if (Number(viewSet("useAppVer")) == 4) {

                    whereClause += " AND version LIKE '"+escapeSearchString(String(viewSet("verFilter")))+"'";

                }

                whereClause += ")) ";

            }

            // show machines in patch policy

            if (Number(viewSet("useColFil")) > 0) {

                if (Number(viewSet("useColFil")) == 1) {

                    // show machines that are members

                    unassignedFlag = "NOT ";

                    memberFlag = "";

                } else {

                    // hide machines that are members

                    unassignedFlag = "";

                    memberFlag = "NOT ";

                }

                if (Number(viewSet("colIdFil")) == 0) {

                    whereClause += "AND a.agentGuid "+unassignedFlag+" IN (SELECT agentGuid FROM collectionMembers)";

                } else {

                    whereClause += "AND a.agentGuid "+memberFlag+" IN (SELECT agentGuid FROM collectionMembers WHERE collectionId="+Number(viewSet("colIdFil"))+")";

                }

            }

            // patch unscanned filter

            if (Number(viewSet("usePatchUnscanned")) != 0) {

                    whereClause += "AND a.agentGuid IN (SELECT agentGuid FROM vAgentLabel aLbl WHERE aLbl.online != 199 "+

                                "AND ((aLbl.agentGuid NOT IN (SELECT agentGuid FROM patchStatus)) OR "+

                                "(aLbl.agentGuid IN (SELECT agentGuid FROM patchstatus WHERE productId = 499999) AND "+

                                "(SELECT COUNT(*) FROM patchstatus WHERE agentGuid = aLbl.agentGuid) = 1)) "+

                                "AND aLbl.agentGuid NOT IN (SELECT agentGuid FROM patchParams WHERE nonSupportedOS LIKE 'OS not supported%')) ";

            }

            // missing patches filter

            if ((Number(viewSet("usePatchFil")) == 1) && (Number(viewSet("missingPatches")) > 0)) {

                if (Number(viewSet("usePatchPolicy")) == 1) {

                    whereClause += "AND a.agentGuid IN (SELECT s.agentGuid FROM patchStatus s JOIN patchdata pd "+

                                "ON s.patchdataId=pd.patchDataid AND pd.updateClassification != 999 "+

                                "LEFT OUTER JOIN patchApprovalPolicy pap ON pap.patchDataId=s.patchDataId "+

                                "AND pap.collectionId = (SELECT TOP 1 px.collectionId FROM patchApprovalPolicy px "+

                                "WHERE px.patchDataId=s.patchDataId AND px.collectionId IN (SELECT mx.collectionId "+

                                "FROM collectionMembers mx WHERE mx.agentGuid = s.agentGuid) ORDER BY ISNULL(px.approvalStatus,0) DESC) "+

                                "WHERE s.patchState=0 AND ISNULL(pap.approvalStatus,0)=0 AND ISNULL(s.ignore,0)=0 "+

                                "GROUP BY s.agentGuid HAVING COUNT(s.agentGuid) >= "+Number(viewSet("missingPatches"))+") ";

                } else {

                    whereClause += "AND a.agentGuid IN (SELECT s.agentGuid FROM patchStatus s JOIN patchdata pd "+

                                "ON s.patchdataId=pd.patchDataId AND pd.updateClassification != 999 "+

                                "WHERE s.patchState=0 GROUP BY s.agentGuid HAVING COUNT(s.agentGuid) >= "+

                                Number(viewSet("missingPatches"))+") ";

                }

            }

            // patch scan pending filter

            if (Number(viewSet("usePatchScanPending")) != 0) {

                if (Number(viewSet("usePatchScanPending")) == 1) {

                    whereClause += "AND EXISTS (SELECT 1 FROM Hermes.vScriptEventStatus "+

                                               "WHERE agentGuid = a.agentGuid "+

                                               "AND scriptId IN (148,237,241,269) "+

                                               "AND nextRunTime IS NOT NULL)";

                } else {

                    whereClause += "AND NOT EXISTS (SELECT 1 FROM Hermes.vScriptEventStatus "+

                                                   "WHERE agentGuid = a.agentGuid "+

                                                   "AND scriptId IN (148,237,241,269) "+

                                                   "AND nextRunTime IS NOT NULL)";

                }

            }

            // patch scan exec status filter

            if (Number(viewSet("usePatchScanResult")) != 0) {

                joinClause += "JOIN scriptStatus k ON a.agentGuid = k.agentGuid "+

                              "AND k.scriptId = (SELECT CASE scanType WHEN 1 THEN 237 WHEN 2 THEN 241 ELSE 148 END AS scanScriptId FROM patchParams WHERE agentGuid = k.agentGuid) ";

                if (Number(viewSet("usePatchScanResult")) == 1) {

                    whereClause += "AND (k.lastExecStatus LIKE '%Success%') ";

                } else {

                    whereClause += "AND (k.lastExecStatus LIKE '%Failed%') ";

                }

            }

            // patch scan exec in last N minutes filter

            if (Number(viewSet("usePatchScanSince")) != 0) {

                joinClause += "LEFT OUTER JOIN scriptStatus m ON a.agentGuid = m.agentGuid "+

                              "AND m.scriptId = (SELECT CASE transitionScan WHEN 1 THEN 148 ELSE "+

                                                       "CASE scanType WHEN 1 THEN 237 WHEN 2 THEN 241 ELSE 148 END "+

                                                       "END AS scanScriptId "+

                                                "FROM patchParams WHERE agentGuid = m.agentGuid) ";

                if (Number(viewSet("usePatchScanSince")) == 1) {

                    whereClause += "AND (ISNULL(m.lastExecTime,'19800101') > DATEADD(MINUTE,-"+String(viewSet("patchScanMin"))+",CURRENT_TIMESTAMP)) ";

                } else {

                    whereClause += "AND (ISNULL(m.lastExecTime,'19800101') < DATEADD(MINUTE,-"+String(viewSet("patchScanMin"))+",CURRENT_TIMESTAMP)) ";

                }

            }

            // patch scan reboot pending filter

            if (Number(viewSet("usePatchRebootPending")) != 0) {

                joinClause += "JOIN patchStatus ps ON a.agentGuid = ps.agentGuid ";

                whereClause += "AND ps.schedTogether = 4 ";

            }

            // patch test filter

            if (Number(viewSet("usePatchTestStatus")) != 0) {

                joinClause += "LEFT OUTER JOIN patchParams pp1 ON a.agentGuid = pp1.agentGuid ";

                if (Number(viewSet("patchTestStatus")) <= 0) {

                    whereClause += "AND ISNULL(pp1.testStatus,-1) = "+Number(viewSet("patchTestStatus"))+" ";

                } else if (Number(viewSet("patchTestStatus")) == 1) {

                    whereClause += "AND ISNULL(pp1.testStatus,-1) > 0 ";

                } else if (Number(viewSet("patchTestStatus")) == 2) {

                    whereClause += "AND ISNULL(pp1.testStatus,-1) IN (10001,10002,10003,10004) ";

                } else if (Number(viewSet("patchTestStatus")) == 3) {

                    whereClause += "AND ISNULL(pp1.testStatus,-1) > 0 AND ISNULL(pp1.testStatus,-1) NOT IN (10001,10002,10003,10004) ";

                }

            }

            // patch auto update config filter

            if (Number(viewSet("usePatchAutoUpdateConfig")) != 0) {

                joinClause += "LEFT OUTER JOIN orgCalendarSchedule ocs ON a.agentGuid = ocs.agentGuid AND rowDesc = 'Patch Automatic Update' ";

                if (Number(viewSet("patchAutoUpdateConfig")) == 0) {

                    joinClause += "LEFT OUTER JOIN Hermes.EventInstance ei ON ocs.id = ei.orgCalendarScheduleId ";

                    whereClause += "AND ei.ScheduledDate IS NULL ";

                } else if (Number(viewSet("patchAutoUpdateConfig")) == 1) {

                    whereClause += "AND ocs.recurrenceType = 'DAILY' ";

                    whereClause += "AND EXISTS (SELECT 1 FROM Hermes.EventInstance WHERE orgCalendarScheduleId = ocs.id AND ScheduledDate > CURRENT_TIMESTAMP) ";

                } else if (Number(viewSet("patchAutoUpdateConfig")) == 2) {

                    whereClause += "AND ocs.recurrenceType = 'WEEKLY' ";

                    whereClause += "AND EXISTS (SELECT 1 FROM Hermes.EventInstance WHERE orgCalendarScheduleId = ocs.id AND ScheduledDate > CURRENT_TIMESTAMP) ";

                } else if (Number(viewSet("patchAutoUpdateConfig")) == 3) {

                    whereClause += "AND ocs.recurrenceType = 'MONTHLY' ";

                    whereClause += "AND EXISTS (SELECT 1 FROM Hermes.EventInstance WHERE orgCalendarScheduleId = ocs.id AND ScheduledDate > CURRENT_TIMESTAMP) ";

                } else if (Number(viewSet("patchAutoUpdateConfig")) == 4) {

                    whereClause += "AND ocs.recurrenceType = 'ONCE' ";

                    whereClause += "AND EXISTS (SELECT 1 FROM Hermes.EventInstance WHERE orgCalendarScheduleId = ocs.id AND ScheduledDate > CURRENT_TIMESTAMP) ";

                }

            }

            // patch reboot config filter

            if (Number(viewSet("usePatchRebootConfig")) != 0) {

                joinClause += "LEFT OUTER JOIN patchParams pp3 ON a.agentGuid = pp3.agentGuid ";

                whereClause += "AND ISNULL(pp3.reset,0) = "+Number(viewSet("patchRebootConfig"))+" ";

            }

            // patch file source config filter

            if (Number(viewSet("usePatchFileSrcConfig")) != 0) {

                joinClause += "LEFT OUTER JOIN patchParams pp4 ON a.agentGuid = pp4.agentGuid ";

                whereClause += "AND ISNULL(pp4.sourceType,0) IN ("+String(viewSet("patchFileSrcConfig"))+") ";

            }

            // patch missing KB filter

            missingKBStr = String(viewSet("patchMissingKB"));

            if ((Number(viewSet("usePatchMissingKB")) != 0)

                && (missingKBStr.length > 0)) {

                joinClause += "JOIN patchStatus psm ON a.agentGuid = psm.agentGuid "+

                              "JOIN patchData pdm ON psm.patchDataId = pdm.patchDataId ";

                whereClause += "AND psm.patchState = 0 AND pdm.kbArticleId = '"+missingKBStr+"' ";

            }

            // viewToFilter

            viewToFilterStr = String(viewSet("viewToFilter"));

            if ((Number(viewSet("viewToFilter")) != 0)

                && (viewToFilterStr.length > 0)) {

                whereClause += "AND a.agentGuid in (Select agentGuid from "+viewToFilter+")";

            }

     

            // agent status filter

            if (Number(viewSet("advFilter")) != 0) {

                innerWhereStr = "";

                filterSetId = Number(viewSet("advFilterId"));

                advFilterSet.Open("SELECT colId,filter FROM reportFilters WHERE filterId="+filterSetId, dbConn);

                if (!advFilterSet.EOF) {

                    colFilterErr = ""; // if something is calling build in a loop then we need to clear the

                                       // error message from the last run since colFilterErr is initialized only once in the include file.

                    var colId;

                    var manualJoin = "";

                    while (!advFilterSet.EOF) {

                        colId = Number(advFilterSet("colId"));

                        manualJoin += getManualJoin(colId);

                        if (colId == 35)

                            colName = "mg.reverseName";

                        else

                            colName = colIdToColName(colId);

                        innerWhereStr += colFilterToSql(colName,String(advFilterSet("filter")));

                        if (colFilterErr.length > 0) {

                            break;

                        }

                        advFilterSet.MoveNext();

                    }

                    if (innerWhereStr.length > 0) {

                        innerWhereStr = innerWhereStr.substr(0,innerWhereStr.lastIndexOf(" AND "));

                        whereClause += "AND (a.agentGuid IN (SELECT aLbl.agentGuid FROM vAgentLabel aLbl "+

                            "LEFT OUTER JOIN users u ON aLbl.agentGuid=u.agentGuid "+

                            "LEFT OUTER JOIN machNameTab a ON u.agentGuid=a.agentGuid "+

                            "LEFT OUTER JOIN machGroup mg ON a.machGroupGuid=mg.machGroupGuid " +

                            "LEFT OUTER JOIN userIpInfo i ON u.agentGuid=i.agentGuid "+

                            "LEFT OUTER JOIN agentState s ON u.agentGuid=s.agentGuid "+

                            "LEFT OUTER JOIN userLogon l ON u.agentGuid=l.agentGuid "+

                            "LEFT OUTER JOIN auditRsltSmbios b ON u.agentGuid=b.agentGuid "+

                            "LEFT OUTER JOIN lastReboot lr ON u.agentGuid=lr.agentGuid "+

                            "LEFT OUTER JOIN machNameTab mn ON u.agentGuid=mn.agentGuid "+

                            "LEFT OUTER JOIN auditRsltCpu c ON u.agentGuid=c.agentGuid AND c.resultGroup=1 AND c.locked=0 "+

                            manualJoin + " WHERE "+innerWhereStr+" )) ";

                    }

                }

                advFilterSet.Close();

            }

     

     

             // Monitorset

            if (Number(viewSet("useMonsetFilter")) != 0 && Number(viewSet("MonsetID")) >0) {

                joinClause += "JOIN monitorMachineParam MMP on a.agentGuid = MMP.agentGuid " +

                "JOIN monitorSetMachineXref MXF on mmp.monitorMachineParamId = mxf.monitorMachineParamId ";

     

                whereClause += "AND (MXF.MonitorsetID = " +Number(viewSet("MonsetID")) + ") ";

            }

     

            // SNMPSet

            if (Number(viewSet("useSNMPsetFilter")) != 0 && Number(viewSet("SNMPsetID")) >0) {

               whereClause += "AND a.agentguid in (  select agentGuid  from snmpAgent SA Join monitorSnmpSetAgentXref MXF on SA.snmpAgentId = MXF.snmpAgentId  " +

                    " JOIN monitorSnmpSet MS on MXF.monitorSnmpSetId = MS.monitorSnmpSetId   and MS.monitorSnmpSetId = " +Number(viewSet("SNMPsetID")) + ") ";

            }

     

            // Addons that can be selected

            advFilterFirstFlag = 1;

            advFilterSet.Open("select va.viewId, pa.usageView from viewDefApp va INNER JOIN partnerApp pa ON va.appId = pa.id where va.viewId = "+viewId+" and usageCountsAvail in (1,2) ",dbConn,3);

            while(advFilterSet.EOF == false) {

                tempViewName = String(advFilterSet("usageView"));

                if(advFilterFirstFlag == 1) { whereClause += "and ("; } else { whereClause += " or "; }

                whereClause += " a.agentguid in ( select agentGuid from "+tempViewName+"("+sessionPartition+") ) ";

                advFilterFirstFlag = 0;

                advFilterSet.MoveNext();

            }

        if(advFilterFirstFlag == 0) {

                whereClause += ")"; }

            advFilterSet.Close();

        }

        viewSet.Close();

     

        if (trimString(whereClause).length > 0) {

            whereClause = "WHERE " + whereClause.substr(3);

        }

     

        return (dbViewDef + joinClause + whereClause);

    }

     

    function dropDbView(viewId)

    {

        viewIdStr = String(viewId);

        dbConn.Execute("IF EXISTS (SELECT name FROM ksubscribers..sysobjects WHERE name = N'fvFilterView"+viewIdStr+"') "+

                       "DROP VIEW fvFilterView"+viewIdStr,0,128);

    }

     

    function saveDbView(viewId)

    {

        viewIdStr = String(viewId);

        // build the database view definition SQL command

        dbViewSql = buildDbViewSql(viewId);

        // drop the database view if it exists

        dropDbView(viewId);

        // create the actual database view

        try {

            dbConn.Execute(dbViewSql,0,128);

        } catch ( err ) {

            logErrMessage(err.message, "*Error*", "creating machine View filter database view (viewId = "+viewIdStr+" - DBViewSQL = "+dbViewSql+")");

        }

        dbConn.Execute("if exists (select id from partnerApp where id = 44 and partitionId = "+sessionPartition+") " +

            " insert into policy.event (id, partitionId, policyEventType, contextFK, policyEventGuid) values " +

            " (dbo.fn_GenerateKid(),"+sessionPartition+",1,1,"+viewId+")",0,128);

     

    }

     

    %>