home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / Software / trial / MonitorIT 5.2.06 / monitorit_fullsetup.exe / data1.cab / Js / GroupComputerTreeFunc.js < prev    next >
Encoding:
JavaScript  |  2003-06-24  |  14.9 KB  |  403 lines

  1. /* ======================================================================
  2. DESC: Common Computer and Group Lookup Functions for the Event Log Operations
  3.  
  4. PLATFORMS: >= MS IE 4.0
  5.  
  6. USAGE NOTES: 
  7. ====================================================================== */
  8. // Initiate Computer Lookup
  9. var AC_CompStoreArr = new Array();
  10. var AC_GroupStoreArr = new Array();
  11.  
  12. var WinServcDispArr = new Array();
  13. var WinServcDispArrIndex = 0;
  14. function processInitialLookup(Lmode) {
  15.     CompRecCount = GrpLupRecCount = 0; // initialize the count
  16.     WinServcDispArr.length = 0;
  17.     WinServcDispArrIndex = 0;
  18.     AC_CompStoreArr.length = 0;
  19.     AC_GroupStoreArr.length = 0;
  20.     if ( RpmCC_AL.ComputerLookup("*","*") ) {
  21.             top.Rstatus.Pstat("Unable to start the LOOKUP request",true);
  22.     }
  23.     else { // waiting for OperationCompleteEvent
  24.         ALupMode = Lmode;
  25.           SetCursor("wait");
  26.           top.banner.processStartComm();
  27.         top.Rstatus.Pstat("One moment while LOOKUP request completes");
  28.     }
  29. }
  30.  
  31. // Add Computer to Store if NT/2000
  32. var CompRecLength = 6;
  33. var CompRecCount = 0;
  34. var CompIDArr = new Array();
  35. function processCompAddToStore(CNme,CDesc,Cid,Gid,OS) {
  36.     var OSV = mapOSVer(OS);
  37.     if ( (ALupMode == "STTCompLookup" || ALupMode == "SLCompLookup" || ALupMode == "WatchReport") || 
  38.     (OSV.charAt(0) == "N" && OSV.charAt(1) == "T") || 
  39.     (OSV != "Unknown" && (ALupMode == "FCCompLookup" || ALupMode == "DRCompLookup" || ALupMode == "PCCompLookup" )) || 
  40.     (ALupMode == "DRCompLookup" && IsSNMP(OS)) ) {
  41.         var i = CompRecCount * CompRecLength;
  42.         AC_CompStoreArr[i++] = Cid; 
  43.         AC_CompStoreArr[i++] = Gid; 
  44.         AC_CompStoreArr[i++] = CNme; 
  45.         AC_CompStoreArr[i++] = CDesc; 
  46.         AC_CompStoreArr[i++] = "0"; 
  47.         AC_CompStoreArr[i] = ""; // misc
  48.         ++CompRecCount;
  49.     }
  50. }
  51. function IsSNMP(OSVer) {
  52.     var wrkarr = new Array();
  53.     var sarr = new Array();
  54.     wrkarr = OSVer.split("[]");
  55.     OSVer = wrkarr[0];
  56.     AgentVer = (wrkarr.length >= 2) ? wrkarr[1] : "";
  57.     DomainName = (wrkarr.length >= 3) ? wrkarr[2] : "";
  58.     SNMPInfo = (wrkarr.length >= 4) ? wrkarr[3] : "";
  59.     sarr = SNMPInfo.split(":!");
  60.     return ( (sarr[0] =="1") ? true : false);
  61. }
  62.  
  63. function processELComputerOpError() {
  64.     ALupMode = "";
  65.     top.Rstatus.Pstat("An error occurred during COMPUTER LOOKUP operation",true);
  66.     goResetWait();
  67. }
  68.  
  69. // Computer Lookup Complete; Initiate Group Lookup
  70. function processComputerLookupComplete() {
  71.     var Amode = ALupMode; // save
  72.     ALupMode = "";
  73.     if (CompRecCount == 0) { // check if any records found
  74.         var emsg = "No Server/Computer record matches found";
  75.         if ( Amode == "ELCompLookup" || Amode == "WinSrvcCompLookup" || Amode == "FCCompLookup" || Amode == "PCCompLookup") {
  76.             emsg += " with NT or 2000 operating system";
  77.         }
  78.         top.Rstatus.Pstat(emsg,true);    
  79.         if ( top.banner.CurrentPageName == "AdminAlerts" ) {
  80.             SetButtonState(UResetButton,"0");
  81.         }
  82.     }
  83.     else if ( Amode == "DRCompLookup" && ALMode != "New" && ALMode != "Edit" ) {
  84.         setTimeout("processAATree()",50); // delay 50 ms. then continue process Tree        
  85.        return;
  86.     }
  87.     else if ( RpmCC_AL.GroupLookup("","","") ) { // Group Lookup
  88.         top.Rstatus.Pstat("Unable to start the GROUP LOOKUP request",true);
  89.     }
  90.     else {
  91.         ALupMode = "ELGroupLookup";
  92.         return; // exit and await Group Lookup
  93.     }
  94.     goResetWait();
  95. }
  96.  
  97. var   GrpLupRecCount = 0; // Count of records returned from Group Lookup operation
  98. var    GroupRecLength = 4; // Length of a Group Lookup record in the Store
  99. /* Process Group LOOKUP RECORD Event */
  100. function processGroupLookupRecord(Gid,GrpName,GrpDesc) {
  101.     // place data from Lookup Record into specified Store
  102.     // Add to Storage
  103.     var i = GrpLupRecCount * GroupRecLength;
  104.     AC_GroupStoreArr[i++] = GrpName;
  105.     AC_GroupStoreArr[i++] = Gid;
  106.     AC_GroupStoreArr[i++] = GrpDesc;
  107.     AC_GroupStoreArr[i] = 0;
  108.     ++GrpLupRecCount;
  109. }
  110. /* Process DB Error in Group Lookup Operation */
  111. function processGroupOpError() {
  112.     ALupMode = "";
  113.     top.Rstatus.Pstat("An error occurred during GROUP LOOKUP operation",true);
  114.     goResetWait();
  115. }
  116. var gocTid = null;
  117. function processGroupOpComplete() {
  118.     ALupMode = "";
  119.     goResetWait();
  120.     if ( GrpLupRecCount == 0 ) {
  121.         top.Rstatus.Pstat("No GROUP record matches found for LOOKUP request",true);    
  122.     }
  123.     else {
  124.         if ( top.banner.CurrentPageName == "AdminAlerts" ) {
  125.             if ( CurrentAT == WinServicesType ) {
  126.                 if ( document.WinSrvcRadio.AL_WinSrvcDisp[1].checked ) {
  127.                     processWinServicesByService();
  128.                     return;
  129.                 }
  130.                 else {
  131.                     AL_CCOneWinServ.innerHTML = ""; // clear
  132.                 }
  133.             }
  134.         }
  135.         processGroupTree(); // Go set up Specify Group Tree
  136.         gocTid = setTimeout("processGOC_Done()",25); 
  137.         processFilterSet(); // Go set up Filter with info saved in Registry
  138.         SpecificationsMade = true; // set Flag
  139.     }
  140. }
  141. function processGOC_Done() {
  142.     gocTid = null;
  143.     processSpecifyButton(); // Go get parameters    
  144. }
  145.  
  146.  
  147. function goResetWait() {
  148.      WarningBox.style.display = "none";
  149.       SetCursor("auto");
  150.     top.banner.processStopCommX();
  151. }
  152. function goSetWait() {
  153.       SetCursor("wait");
  154.       top.banner.processStartComm();
  155. }
  156. // Process and Display the Group:Computer Tree
  157. var CCEs = null;
  158. var GroupExpandedCount = 0;
  159. function processGroupTree() {
  160.     var Op = AL_CCOneEventLog; // preset
  161.     setOutHeader("Groups : Servers/Devices Tree"); // define output table header    
  162.     if ( top.banner.CurrentPageName == "AdminAlerts" ) {
  163.         if ( CurrentAT == WatchReportType ) {
  164.               Op = AL_CCOneWatchReport;
  165.         }
  166.         else if ( CurrentAT == SNMPTrapType ) {
  167.              Op = AL_CCOneSNMPTrap;
  168.          }
  169.         else if ( CurrentAT == WinServicesType ) {
  170.              Op = AL_CCOneWinServ;
  171.             setOutHeader("Groups : Servers/Workstations : Windows Services Tree"); // define output table header    
  172.          }
  173.         else if ( CurrentAT == FileCheckType ) {
  174.              Op = AL_CCOneFileCheck;
  175.              setOutHeader("Groups : Servers/Workstations Tree"); // define output table header    
  176.         }
  177.         else if ( CurrentAT == ProcessCheckType ) {
  178.              Op = AL_CCOneProcessCheck;
  179.              setOutHeader("Groups : Servers/Workstations Tree"); // define output table header    
  180.          }
  181.         else if ( CurrentAT == SyslogCheckType ) {
  182.              Op = AL_CCOneSyslogCheck;
  183.          }
  184.      }
  185.  
  186.     /* Format and Output Service tree list */
  187.     if ( (top.banner.CurrentPageName == "AdminAlerts" && CurrentAT != WatchReportType) || top.banner.CurrentPageName == "AdminReports") {
  188.         var SelT = "<table border='0' cellpadding='0' cellSpacing='1' width='490'>";
  189.         SelT += "<tr><td width='100%' height='2' align='center' valign='top' class='optextb' style='background-color:graytext; color:captiontext'>Selections</td></tr></table>";
  190.         CCEs = SelT+CCEs;
  191.     }    
  192.     GroupExpandedCount = 0; // init
  193.     for ( var i=0; i<GrpLupRecCount; i++) {
  194.         CCEs += "<table border='0' cellpadding='0' cellSpacing='0' width='490'><tr><td width='25'> </td>";
  195.         Iprefx = ( i+1 >= GrpLupRecCount ) ? "L" : "T";
  196.           CCEs += "<td width='19' align='center'><img id='lima" + i + "' expanded='0' src='images/" + Iprefx + "plus.gif' style='cursor:hand' onclick='procGrpImgClick(this)' width='19' height='20'></td>";
  197.         CCEs += "<td width='19' align='center'><img id='limb" + i + "' src='images/CloseImg.gif' style='cursor:hand' onclick='procGrpImgClick(this)' width='15' height='14' title='";
  198.         CCEs += "'></td><td width='*' class='optext'>" + AC_GroupStoreArr[i*GroupRecLength] + "</td></tr></table>";
  199.         CCEs += "<div id='lexp" + i + "' compcount=0></div>";
  200.       }
  201.     Op.insertAdjacentHTML("beforeEnd",CCEs);
  202. }
  203. /* Display Header for Service and Object:Counter Trees */
  204. function setOutHeader(Tstrg) {
  205.     CCEs = "<table border='0' cellpadding='0' cellSpacing='0' width='490'>";
  206.     CCEs += "<tr><td width='25'> </td>";
  207.       CCEs += "<td width='19' height='20' align='center'><img src='images/topopen.gif' width='19' height='20'></td><td colspan='2' width='*' class='optextb'>" + Tstrg + "</td></tr></table>";
  208. }
  209.  
  210. /* Process Click on Group in Group Tree */
  211. var CurExpGroupIx = null; // Index to Current Expanded Group
  212. var CurCmpIx = 0;
  213. var CmpsExpected = 0;
  214. function procGrpImgClick(SIm) {
  215.     isx = SIm.id;  
  216.     if ( isx.charAt(0) != "l" ) { // if not a "limaxx"
  217.         top.banner.beep();
  218.         return;
  219.     }
  220.     var cx = isx.substring(4,isx.length); // Strip off index
  221.  
  222.     CurExpGroupIx = parseInt(cx,10);
  223.     CObj = document.all["lima"+cx];
  224.     EObj = document.all["lexp"+cx];
  225.     FObj = document.all["limb"+cx];
  226.     Cpfx = (CurExpGroupIx+1 >= GrpLupRecCount) ? "L" : "T";
  227.  
  228.     if ( CObj.expanded == "1" ) { // if currently expanded
  229.         FObj.src = "images/CloseImg.gif";
  230.         CObj.src = "images/" + Cpfx + "plus.gif";
  231.         EObj.style.display = "none";
  232.         //EObj.innerHTML = ""; // Contract 
  233.        CObj.expanded = "0"; // Set contracted
  234.        GroupExpandedCount -= EObj.compcount; // decrement count of open computers
  235.      }
  236.     else { // otherwise Expand
  237.         FObj.src = "images/OpenImg.gif";
  238.         CCEs = ""; // initialize
  239.         CObj.src = "images/" + Cpfx + "minus.gif";
  240.           CObj.expanded = "1"; // Set expanded
  241.           if ( EObj.compcount == 0 ) {
  242.               CurCmpIx = 0; // initialize
  243.               var GID = AC_GroupStoreArr[(cx*GroupRecLength)+1]; // get Group ID
  244.               // Add Computers to the Tree for This Group 
  245.               var carr = new Array();
  246.            for ( var i=0, j=0, k=0; i<CompRecCount; ++i ) {
  247.                j = (i*CompRecLength); // index to Computer entry in store
  248.                // Match on Group ID
  249.                if ( GID == AC_CompStoreArr[j+1] ) {
  250.                    carr[k] = j; // save index in array
  251.                       ++k; // bump computer count
  252.                   }
  253.             }
  254.             if ( k==0 ) {
  255.                 if ( top.banner.CurrentPageName == "AdminAlerts" ) {
  256.                     if ( (CurrentAT != EventLogType && CurrentAT != WinServicesType && CurrentAT != FileCheckType && CurrentAT != ProcessCheckType) ) {
  257.                            top.Rstatus.Pstat("Group is empty!",true);
  258.                            alert("Group is empty!");
  259.                         return;
  260.                     }
  261.                 }
  262.                 if ( arguments.length == 2 ) {
  263.                     return;
  264.                 }
  265.                top.Rstatus.Pstat("Group has no NT/2000 Servers/Computers with MonitorIT Agent!",true);
  266.                alert("Group has no NT/2000 Servers/Computers with MonitorIT Agent!");
  267.                return;
  268.             }
  269.             CmpsExpected = k; // set number of computers matching
  270.             for ( var i=0; i<k; i++ ) {
  271.                 j = carr[i]; // get index to computer that matches
  272.                 processTreeComputer(AC_CompStoreArr[j+2],AC_CompStoreArr[j+3],AC_CompStoreArr[j+4],j);
  273.                 AC_CompStoreArr[j+5] = i; // Computer index into Group Tree
  274.             }
  275.             EObj.compcount = k; // set number computers opened
  276.              EObj.insertAdjacentHTML("beforeEnd",CCEs);
  277.          }
  278.           GroupExpandedCount += EObj.compcount; // increment total number of computers opened
  279.         EObj.style.display = "";
  280.     }
  281.     if ( arguments.length == 1 ) {
  282.         CObj.scrollIntoView(true);
  283.     }
  284.     // enable SelectAll/UnselectAll buttons if computers opened
  285.     checkSelUnselButtons();
  286.  }
  287. function SetButtonState(BtObj,BState) {
  288.     //BtObj.className = (BState == "0") ? "BoxButton" : "BoxButtonD";
  289.     BtObj.disabled = (BState == "0") ? "" : "disabled";
  290.     BtObj.bdis = BState;
  291. }
  292.  
  293. function processTreeComputer(CmpNme,CmpDesc,SState,CSIx) {
  294.     var WST = (top.banner.CurrentPageName == "AdminAlerts" && CurrentAT == WinServicesType) ? true : false;
  295.     var Opfx = (CurExpGroupIx+1 >= GrpLupRecCount) ? "White" : "I";
  296.     var Mpfx = (CurCmpIx+1 == CmpsExpected) ? "L" : "T";
  297.     
  298.     CCEs += "<table border='0' cellpadding='0' cellSpacing='0' width='490'>";
  299.     CCEs += "<tr><td width='25'> </td><td width='19' height='20' align='center'><img src='images/" + Opfx + ".gif' width='19' height='20'></td>";
  300.     CCEs += "<td width='19' height='20' align='center'><img src='images/" + Mpfx + ".gif' width='19' height='20'></td>";
  301.       CCEs += "<td width='11' align='center'><img id='xima" + CurExpGroupIx + "_" + CurCmpIx;
  302.  
  303.     if ( WST ) {
  304.            CCEs +=  "' checked='0' src='images/Plus.gif' width='11' height='11'"; 
  305.            CmpImg = "Computer.gif";
  306.         }
  307.     else if ( SState == "1" ) {
  308.         CCEs +=  "' checked='1' src='images/"; 
  309.        CCEs +=  "Checked.gif' width='9' height='9'"; 
  310.           CmpImg = selectImage; 
  311.     }
  312.     else {
  313.         CCEs +=  "' checked='0' src='images/"; 
  314.           CCEs += "Unchecked.gif' width='9' height='9'";
  315.           CmpImg = "Computer.gif";
  316.     }
  317.         
  318.       CCEs += " compix='" +CSIx+"' style='cursor:hand' onclick='procELCmpImgClick(this)'></td>";
  319.     CCEs += "<td width='19' align='center'><img id='zimb" + CurExpGroupIx + "_" + CurCmpIx + "' src='images/"+CmpImg+"' style='cursor:hand' onclick='procELCmpImgClick(this)' width='15' height='16' title='";
  320.     CCEs += CmpDesc + "'></td>";
  321.     CCEs += "<td width='*' id='zimc" + CurExpGroupIx + "_" + CurCmpIx;
  322.     CCEs += "' style='cursor:hand' onclick='procELCmpImgClick(this)' class='optext'>" + CmpNme + "</td>";
  323.     CCEs += "</tr></table>";
  324.     if ( WST ) {
  325.         CCEs += "<div id='sexp" + CurExpGroupIx + "_" + CurCmpIx + "' wslrec='' checkedsrvcs=0 srvcssel=0 srvcsdisp=0 style='display:none'></div>";
  326.     }
  327.     ++CurCmpIx; // bump index
  328. }
  329.  
  330. /* Process Click to Check or Uncheck a Computer */
  331. function procELCmpImgClick(CmpIm) {
  332.     var WST = (top.banner.CurrentPageName == "AdminAlerts" && CurrentAT == WinServicesType) ? true : false;
  333.     var isx = CmpIm.id;  
  334.     if ( isx.charAt(0) != "x" && isx.charAt(0) != "z") 
  335.                 return;
  336.     var cx = isx.substring(4,isx.length); // Strip off index
  337.     lx = cx.lastIndexOf("_"); // derive suffix to the Computer DIV ID
  338.     var dx = cx.substring(0,lx);
  339.  
  340.     var CObj = document.all["xima"+cx]; // Clicked Computer Entry
  341.     var FObj = document.all["zimb"+cx]; 
  342.     CSIx = parseInt(CObj.compix,10);
  343.     if ( WST ) { // Windows Services
  344.         CurExpGrpCompIx = cx;
  345.         var EObj = document.all["sexp"+CurExpGrpCompIx];
  346.         if ( CObj.checked == "1" ) { // if currently Expanded, Contract
  347.             CObj.src = "images/Plus.gif";
  348.            CObj.checked = "0"; // Set Unchecked
  349.             EObj.style.display = "none";
  350.        }
  351.         else { // otherwise Expand Windows Services
  352.             CObj.src = "images/Minus.gif";
  353.            CObj.checked = "1"; // Set Checked
  354.            if ( EObj.wslrec != "" ) {
  355.                    EObj.style.display = ""; //processWinSrvcsLookupRecord(WSLrec);
  356.             }
  357.             else if ( RpmCC_AL.NTServicesLinkListLookup(AC_CompStoreArr[CSIx],"") ) { // Services Lookup
  358.                 top.Rstatus.Pstat("Unable to start the Win Services LOOKUP request",true);
  359.                 goResetWait();
  360.             }
  361.             else {
  362.                 ALupMode = "WinSrvcsLookup";
  363.                 return; // exit and await Services Lookup
  364.             }
  365.         }
  366.     }
  367.      else {
  368.         if ( CObj.checked == "1" ) { // if currently Checked, Uncheck
  369.             FObj.src = "images/Computer.gif";
  370.             CObj.src = "images/Unchecked.gif";
  371.            CObj.checked = "0"; // Set Unchecked
  372.            AC_CompStoreArr[CSIx+4] = "0";
  373.        }
  374.         else { // otherwise Check
  375.             FObj.src = "images/"+selectImage;
  376.             CObj.src = "images/Checked.gif";
  377.            CObj.checked = "1"; // Set Checked
  378.            AC_CompStoreArr[CSIx+4] = "1";
  379.         }
  380.     }
  381.     SpecificationsMade = true; // flag that a change has been made
  382. }
  383.  
  384. // Process SelectALL or UnselectALL
  385. function processSelect(Pflg) {
  386.     var GObj = null, CObj = null;
  387.     // Look for each open/expanded Group
  388.     for ( var i=0; i<GrpLupRecCount; i++ ) {
  389.         GObj = document.all["lima"+i];
  390.         if ( GObj.expanded == "1" ) {
  391.             GObj = document.all["lexp"+i];
  392.             // if Group expanded, process each computer
  393.             for ( var j=0; j<GObj.compcount; j++ ) {
  394.                 CObj = document.all["xima"+i+"_"+j]; // computer entry in tree
  395.                 if (CObj.checked == Pflg) {
  396.                     procELCmpImgClick(CObj); // go process
  397.                 }
  398.             }
  399.         }
  400.     }
  401. }
  402.  
  403.