Jump to content

Jimmy85

Members
  • Posts

    15
  • Joined

  • Last visited

Posts posted by Jimmy85

  1. I am a bit confused on how to get the functions sorted as your example only show one line of html in $tdata where I have multiple lines for example how would i do 

    $table = <tbody>

                  <tr>

                     <td>IP Address: {$ip['ip']}</td>

                     <td VALIGN = Middle Align = Center>Unit Name: {$ip['name']}</td>

                  </tr>

                  <tr>

                     <td>Status is: $successValue</td>

                     <td VALIGN = Middle Align = Center>" . ($successValue == "UP" ? "<img src='/Images/GTick.jpg'>" ."<span style='color:#FFFFFF'>". $SC++ ."</span>" : "<img src='/Images/RTick.jpg'>" . "<span style='color:#FFFFFF'>".$FC++ ."</span>"). "</td>

                   </tr>

              </tbody>

              ";

      }

    "</table>";

     

    Like your $tdata variable

  2. Hi,

    As promised here is the code this is my functions.php:

    <?php
    //$GLOBAL Variables
    //$GLOBALS['SC'] = 0;
    //$GLOBALS['FC'] = 0;
    //$GLOBALS['countup'] = 0;
    //$GLOBALS['countdown'] = 0;
    
    
    function completedJC(){
    //completed call count
    include 'SqlConn.php';	
    $sql = "Select Count(Status) from EXCELMACRO...Jobs$ where Status = 'Completed'";
    			$stmt = $conn->query($sql);
    			$stmt->execute();
        		$resultCompleted = $stmt->fetchColumn();
    			echo $resultCompleted;
    }
    
    function inprogressJC(){
    //In-progress call count
    include 'SqlConn.php';	
    $sql = "Select Count(Status) from EXCELMACRO...Jobs$ where Status = 'In-Progress'";
    			$stmt = $conn->query($sql);
    			$stmt->execute();
        		$resultInprogress = $stmt->fetchColumn();
    			echo $resultInprogress;
    
    }
    
    function OnHoldJC(){
    //On-hold call count
    include 'SqlConn.php';	
    $sql = "Select Count(Status) from EXCELMACRO...Jobs$ where Status = 'ON-HOLD'";
    			$stmt = $conn->query($sql);
    			$stmt->execute();
        		$resultOnHold = $stmt->fetchColumn();
    			echo $resultOnHold;
    }
    
    function CriticalSystem(){
         //array for critical devices
        //Black #000000
        //White #FFFFFF
        $SC = 0;
        $FC = 0;
        $countup = 0;
        $countdown = 0;
        
     $systems = array( 
        array('ip' => '192.168.9.254', 'name' => 'Tech Swtich'), 
        array('ip' => '192.168.9.205', 'name' => 'Printer'),
        array('ip' => '192.168.9.200', 'name' => 'Sales Printer'),
        array('ip' => '192.168.9.201', 'name' => 'Admin Printer'),
        array('ip' => '192.168.9.1', 'name' => 'KVM'),
        array('ip' => '192.168.9.2', 'name' => 'Office Data 24 Port'),
        array('ip' => '192.168.9.3', 'name' => 'Office Data 48 Port'),
        array('ip' => '192.168.9.4', 'name' => 'Office Voice 48 Port'),
        array('ip' => '192.168.9.7', 'name' => 'Warehouse Switch'),
        array('ip' => '192.168.9.13', 'name' => 'Foundry Canteen Switch'),
        );
        //Result to search for to give success result
        $good = "Received = 1";
        $successValue;
        
        //troubleshooting to see if being re-freshed
        //echo "<h1>Site Status  ".date("h:i:s")."</h1>";
       
        echo "<table border='0' class='table'>";
        // foreach loop to ping IP and check if alive or dead & dispaly result
        foreach ($systems as $ip) {
            unset($result);
            $successValue = "DOWN";
            exec("ping -n 1 $ip[ip]", $result);
            foreach($result as $line) {
                if (strpos($line,$good) == TRUE){
                    $successValue = "UP";
                    //$count = $successValue;
                }
            }
            
            echo "<tbody>
                     <tr>
                        <td>IP Address: {$ip['ip']}</td>
                        <td>Unit Name: {$ip['name']}</td>
                     </tr>
                     <tr>
                        <td>Status is: $successValue</td>
                        <td>" . ($successValue == "UP" ? "<img src='/Images/GTick.jpg'>" ."<span style='color:#000000'>". $SC++ ."</span>" : "<img src='/Images/RTick.jpg'>" . "<span style='color:#000000'>".$FC++ ."</span>"). "</td>
                      </tr>
                 </tbody>
                 ";
         }
        echo"</table>";
         //debug dispaly full result of ping request
        //var_dump($result);
        $countup = array($SC);
        $countdown = array($FC);
        print_r($countup);
        //Print_r($countdown);
    }
    
    function countupdown(){
    global $SC, $FC, $countup, $countdown;
    echo "<center>";
    echo "<br></br>";
    echo "<img src='/Images/GTick.jpg'>". " " . "Systems Online = ".$countup;
    echo "<br></br>";
    echo  "<img src='/Images/RTick.jpg'>". " ". "Systems Offline = ".$countdown;
    echo "</center>";
    print_r($countup);
    }
    
    ?>

     Here is my index.php

    <!doctype html>
    <html lang="en">
    <?php //Function Scripts
    //SqlConn 
    include 'SqlConn.php';
    //Completed Job Count
    include 'Functions.php';
    ?>
    <head>
      <title>Support Desk</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta name="description" content="">
      <meta name="author" content="James Stirling">
      <meta name="generator" content="Hugo 0.98.0">
      <meta http-equiv="refresh" content="5" 
      
      <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
      <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
      <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
      <link rel="manifest" href="favicon/site.webmanifest">
      <link rel="mask-icon" href="favicon/safari-pinned-tab.svg" color="#5bbad5">
      <meta name="msapplication-TileColor" content="#da532c">
      <meta name="theme-color" content="#ffffff">
    
      <link rel="canonical" href="https://getbootstrap.com/docs/5.2/examples/features/">
    
      <link href="/docs/5.2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
     
    </head>
      <!-- <title>Support Desk</title> -->
    <body>
      <style>
        .btn-primary {
          --bs-btn-color: #fff;
          --bs-btn-bg: #007A53;
          --bs-btn-focus-shadow-rgb: 49, 132, 253;
          --bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125)
        }
    
        .b-divider {
          height: 3rem;
          background-color: rgba(0, 0, 0, .1);
          border: solid rgba(0, 0, 0, .15);
          border-width: 1px 0;
          box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
        }
      </style>
      <main>
        <!-- Calls Logged -->
        <div class="container px-4 py-5" id="hanging-icons">
          <center>
            <h2 class="pb-2 border-bottom">Hargreaves Foundry & Drainage Critical System Status Page</h2>
          </center>
        </div>
        <div class="container px-4 py-5" id="hanging-icons">
          <h2 class="pb-2 border-bottom">Open Calls: View all status of IT faults</h2>
          <div class="row g-4 py-5 row-cols-1 row-cols-lg-3">
            <div class="col d-flex align-items-start">
              <div
                class="icon-square bg-light text-dark d-inline-flex align-items-center justify-content-center fs-4 flex-shrink-0 me-3">
              </div>
              <div>
                <h2>Completed: (<?php completedJC();?>)</h2>
                <p>Number of all calls that have been completed for each department and staff member.</p>
                         </div>
            </div>
            <div class="col d-flex align-items-start">
              <div
                class="icon-square bg-light text-dark d-inline-flex align-items-center justify-content-center fs-4 flex-shrink-0 me-3">
              </div>
              <div>
                <h2>In-Progress: (<?php inprogressJC();?>)</h2>
                <p>Number of open calls and the progress of the call for a department or staff member.</p>
                 </div>
            </div>
            <div class="col d-flex align-items-start">
              <div
                class="icon-square bg-light text-dark d-inline-flex align-items-center justify-content-center fs-4 flex-shrink-0 me-3">
              </div>
              <div>
                <h2>ON-HOLD: (<?php OnHoldJC();?>)</h2>
                <p>Number of calls placed ON-HOLD for what ever reason or awaiting input from a third party.</p>
                        </div>
            </div>
          </div>
        </div>
        <div class="b-divider"></div>
        <!-- Critical Systems -->
        <div class="container px-4 py-5" id="hanging-icons">
          <h2 class="pb-2 border-bottom">Critical Systems Online\Offline Count</h2>
           
    <?php
    countupdown();
    ?>
     
        </div>
        <div class="b-divider"></div>
    
        <!-- Critical Systems -->
        <div class="container px-4 py-5" id="hanging-icons">
          <h2 class="pb-2 border-bottom">Critical Systems Ping Check</h2>
           
    <?php
    CriticalSystem();
    ?>
     
        </div>
    </main>
    
      <div class="b-divider"></div>
      <script src="/docs/5.2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
        crossorigin="anonymous"></script>
    </body>
    <footer class="py-3 my-4">
      <ul class="nav justify-content-center border-bottom pb-3 mb-3">
      </ul>
      <p class="text-center text-muted">© 2022 Hargreaves Foundry & Drainage, Inc</p>
      <center>
        <img src="docs/5.2/images/image1.png" style="width:40px;height:40px;margin-top:20px" />
      </center>
    </footer>
    
    </html>

    Any question please ask.

    Thanks James

  3. Basically the numbers function was only a example to see if I could do what I require.

    The $sc (successfully count) and $fc (failed count) increments after each field is populated from an array I would like to count the $sc and $fc numbers using a separate function

    Using:

    $countup = array($SC);
    $countdown = array($FC);

    Works fine in my other function but I want to pull $sc and $fc value into my other function populating the number of ok pings and failed pings 

  4. Hi Barand,

    I have extended your code you kindly changed for me and i am wanting to count how many successful pings i have and how many unsuccessful pings i have using

    <td>" . ($successValue == "UP" ? "<img src='/Images/GTick.jpg'>" ."<span style='color:#000000'>". $SC++ ."</span>" : "<img src='/Images/RTick.jpg'>" . "<span style='color:#000000'>".$FC++ ."</span>"). "</td>

    then

        $countup = array($SC);
        $countdown = array($FC);

    With a separate function

    function countupdown(){
    global $SC, $FC, $countup, $countdown;
    echo "<center>";
    echo "<br></br>";
    echo "<img src='/Images/GTick.jpg'>". " " . "Systems Online = ".$countup;
    echo "<br></br>";
    echo  "<img src='/Images/RTick.jpg'>". " ". "Systems Offline = ".$countdown;
    echo "</center>";
    }

    Then possibly use the array count values to get the numbers for the attached image

    Count.jpg

  5. Hi,

    Can you have a function for example

    <?php
    function Numbers(){
       $SC = 0;
        $FC = 0;
        $countup = 0;
        $countdown = 0;
      
        $countup = array($SC);
        $countdown = array($FC);
    }
    ?>

    Then using the global call a variable from the above function

    function countupdown(){
    global $countup, $countdown;
    echo "<center>";
    echo "<br></br>";
    echo  . "Systems Online = ".$countup;
    echo "<br></br>";
    echo . "Systems Offline = ".$countdown;
    echo "</center>";
    }
    ?>

    Or is this bad practice and what is good practice to do what i am trying to achieve.

  6. Hi,

    my table is built up of array items basically the array item is the table isn't like the others and i cannot work it out.

    (I have attached a image to show you what it looks like)

    Here is my code:

    Quote
    function CriticalSystem(){
        //array for critical devices
        $systems = array( 
        array('ip' => '192.168.9.254', 'name' => 'Tech Swtich'), 
        array('ip' => '192.168.9.205', 'name' => 'Printer'),
        array('ip' => '192.168.9.200', 'name' => 'Sales Printer'),
        array('ip' => '192.168.9.201', 'name' => 'Admin Printer'),
        array('ip' => '192.168.9.1', 'name' => 'KVM'),
        array('ip' => '192.168.9.2', 'name' => 'Office Data 24 Port'),
        array('ip' => '192.168.9.3', 'name' => 'Office Data 48 Port'),
        array('ip' => '192.168.9.4', 'name' => 'Office Voice 48 Port'),
        array('ip' => '192.168.9.7', 'name' => 'Warehouse Switch'),
        array('ip' => '192.168.9.13', 'name' => 'Foundry Canteen Switch'),
        );
        //Result to search for to give success result
        $good = "Received = 1";
        $successValue;
        
        //troubleshooting to see if being re-freshed
        //echo "<h1>Site Status  ".date("h:i:s")."</h1>";
       
        // foreach loop to ping IP and check if alive or dead & dispaly result
        foreach ($systems as $ip) {
            unset($result);
            $successValue = "DOWN";
            exec("ping -n 1 $ip[ip]", $result);
            foreach($result as $line) {
                if (strpos($line,$good) == TRUE){
                    $successValue = "UP";
                }
            }
            //echo "<br><br>";
            echo "<table class='table'>";
            echo "<tbody>";
            echo"<tr>";
            echo"<td>";
            echo "IP Address: ".$ip['ip']. " "."</td>"."<td>"."Unit Name: ".$ip['name']." "."</td>";
            //echo "</td>";
            echo"</td>";
            echo"</tr>";
            echo"<tr>";
            echo"<td>";
            If ($successValue == "UP") {
                 //echo "<br><br>";
                 echo "Status is: ".$successValue." "."<td>"."<img src='/Images/GTick.jpg'>"."</td>";
        
            }else{
                    //echo "<br><br>";
                    echo "Status is: ".$successValue." "."<img src='/Images/RTick.jpg'>";
            }
            echo "</td>";
            echo "</tr>";
            echo "</tbody>";
            echo"</table>";
        //debug dispaly full result of ping request
        //var_dump($result);
        }
    }

    Cheers James

     

    Critical System.jpg

  7. Hi,

    Basically I have written this PHP script to ping address on my network and then I would like to add the name that defines that IP after my image if successful or not.

    I am struggling on the name part can anyone assist?

    My code is below:

    <?php
    $systems = array("192.168.9.254","192.168.9.205","192.168.9.200","192.168.9.201","192.168.9.1","192.168.9.2","192.168.9.3","192.168.9.4","192.168.9.7","192.168.9.13");
    $Sysname = array("Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9");
    $good = "Received = 1";
    $successValue;
    //echo "<h1>Site Status  ".date("h:i:s")."</h1>";
    echo "<br><br>";
    foreach ($systems as $ip) {
        unset($result);
        $successValue = "DOWN";
        exec("ping -n 1 $ip", $result);
        foreach($result as $line) {
            if (strpos($line,$good) == TRUE){
                $successValue = "UP";
            }
        }
        echo "IP Address: ".$ip." ";
        If ($successValue == "UP") {
             echo "System is ".$successValue. "&nbsp;"."<img src='/Images/GTick.jpg'>"."&nbsp;";
    
        }else{
                echo "System is ".$successValue. "&nbsp;"."<img src='/Images/RTick.jpg'>"."&nbsp;";
        }
    echo "<br><br>";
    //var_dump($result);
    }
    ?>

    Cheers James

     

  8. Yes from the function which i didnt think was required  but not the

    <!DOCTYPE html>
    <html lang="en">
       <head>
          <title>Add A New Engineer | DDS Dashboard</title>
          <meta charset="utf-8"  />
          <link rel="icon" type="image/png" href="../images/favicon-16x16.png"/>
       </head>
       <body>
          <?php 
             include('nav.php');
             include('ConnectionDB.php');
             
             ?>

     

    As i use the PDO connection populate the current engineers name in the DB:

    ?php
    	$sql = "Select * from [Engineers] where [Engineer] not like '%\_%' Escape '\' order by [Engineer] asc";
    			$stmt = $conn->prepare($sql);
    			$stmt->execute();
    			$results=$stmt->fetchAll(PDO::FETCH_ASSOC);
    			?>
    			<div class="containerenglist">
    			<div class="col-sm-5">
    			<table id="alleng" class="table table-bordered">
    			<tr>
    			<th>Active Engineer's Names:</th>
    			</tr>
    			<?php
    			foreach ($results as $row) {
    				echo "<tr><td>";
    				echo $row['Engineer'];
    				echo "</td>";
    				echo "</tr>";
    			}
    			?>
    			</table>
    			</div>
    			</div>
  9. Whoops sorry meant to remove this

    Function create_eng(){
    	global $msgID;
    	global $msg, $conn;
    	include('ConnectionDB.php');
    	$conn = null;

    Should read

    Function create_eng(){
    	global $msgID;
    	global $msg, $conn;
    	$msgID = 0;

    Which it does now even after removing these lines i still get the same error

    [10-May-2019 14:02:00 UTC] PHP Fatal error:  Uncaught Error: Call to a member function prepare() on null in C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php:88
    Stack trace:
    #0 C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php(5): create_eng()
    #1 {main}
      thrown in C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php on line 88

     

  10. I have a html/php i am creating but getting the following error:

    [10-May-2019 09:42:13 UTC] PHP Fatal error:  Uncaught Error: Call to a member function prepare() on null in C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php:88
    Stack trace:
    #0 C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php(5): create_eng()
    #1 {main}
      thrown in C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php on line 88


    Here is my code:

    <?php
    $server = htmlentities($_SERVER['PHP_SELF']); 
     	if (isset($_POST['submit'])) {
            $result = create_eng();
     }
    ?>
    <!DOCTYPE html>
    <html lang="en">
       <head>
          <title>Add A New Engineer | DDS Dashboard</title>
          <meta charset="utf-8"  />
          <link rel="icon" type="image/png" href="../images/favicon-16x16.png"/>
       </head>
       <body>
          <?php 
             include('nav.php');
             include('ConnectionDB.php');
             
             ?>
          <div class="jumbotron">
             <div class="container">
                <h1><br><img src="../images/clipboard-customer.png"/> Add New Engineer:</br></h1>
             </div>
          </div>
          <form class="form-horizontal" role="form" id="add_eng" action="<?php $server ?>" method = "post">
             <div class="form-group">
    		 <!--<?php //display_msg($msg);?>-->
                <label for="EngineerName" class="col-sm-2 control-label">Engineer Name:</label>
                <div class="col-sm-6">
                   <input type="text" class="form-control" id="EngName" name="EngineersName" placeholder="Enter Engineer's Name"></input>
                   <small class="form-text text-muted">
                   Enter the new engineer's name above to enter them into the database.
                   </small>
                </div>
                <input name="submit" type="submit" value="Create Engineer" class="btn btn-primary default"></input>
                <input name="reset" type="Reset" value="Reset Form" class="btn btn-primary default"></input>
             </div>
          </form>
          <br><br>
       </body>
    </html>
    	<?php
    	$sql = "Select * from [Engineers] where [Engineer] not like '%\_%' Escape '\' order by [Engineer] asc";
    			$stmt = $conn->prepare($sql);
    			$stmt->execute();
    			$results=$stmt->fetchAll(PDO::FETCH_ASSOC);
    			?>
    			<div class="containerenglist">
    			<div class="col-sm-5">
    			<table id="alleng" class="table table-bordered">
    			<tr>
    			<th>Active Engineer's Names:</th>
    			</tr>
    			<?php
    			foreach ($results as $row) {
    				echo "<tr><td>";
    				echo $row['Engineer'];
    				echo "</td>";
    				echo "</tr>";
    			}
    			?>
    			</table>
    			</div>
    			</div>
    	
    </body>
    </html>		
    
    <?php
    
    Function create_eng(){
    	global $msgID;
    	global $msg, $conn;
    	include('ConnectionDB.php');
    	$conn = null;
    	$msgID = 0;
    	//Get POST from submit
    	$eng_name = $_POST['EngineersName'];
    	//SQL Query
    	$sql_count = "select count(*) as num from [Engineers] where [Engineer] = :eng_name";
    	//Query SQL Statement
    	//echo $eng_name;
    	$stmt = $conn->prepare($sql_count);
    	$stmt->bindValue(':eng_name', $eng_name);
    	//Execute SQL Statement
    	$stmt->execute();
    	$results=$stmt->fetchAll(PDO::FETCH_ASSOC);
    	If($results['num'] > 0){
    		echo $msg = "Engineer $eng_name exist's in the database";
    		$msgID = 1;
    	}else{
    		$sql_insert = "insert into [Engineers](Engineer) values '$eng_name'";
    		//Prepare SQL Statement
    		$stmt = $conn->Prepare($sql_insert);
    		//Execute SQL Statement
    		$stmt->execute();
    	    $results=$stmt->fetchAll(PDO::FETCH_ASSOC);
    		echo $msg = "Engineer $eng_name added to the database";
    		$msgID  = 2;
    	}
    
    }	
    ?>

    Everything works correctly until i try submitting a name to the DB the line that is being pulled is $stmt = $conn->prepare($sql_count);

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.