Jump to content

SalientAnimal

Members
  • Posts

    366
  • Joined

  • Last visited

Everything posted by SalientAnimal

  1. $result = mysqli_query($link,$sqlsearch)or die(mysqli_error()); while($row = mysqli_fetch_array($result)) { $store_code = $row['store_code']; $outlet_name = $row['outlet_name']; $address_0 = $row['address_0']; $address_1 = $row['address_1']; $address_2 = $row['address_2']; $address_3 = $row['address_3']; $address_4 = $row['address_4']; $contact_number_1 = $row['contact_number_1']; $contact_number_2 = $row['contact_number_2']; $license = $row['scanned_license']; $permit_renewal = $row['scanned_permit_renewal']; $identity_document = $row['scanned_identity_document']; $other_document = $row['scanned_other_document']; echo "<div class='row'>"; echo "<div class='col-md-12'>"; echo "<div class='box box-primary'>"; echo "<div class='box-header with-border'>"; echo "<h3 class='box-title'>Outlet Details</h3>"; echo "<table> <tr> <th>Outlet Details</th> <th>Outlet Documentation</th> </tr> <tr> <td> <table> <tr> <th>Store Code</th> </tr> <tr> <td>".$store_code."</td> </tr> <tr> <th>Store Name</th> </tr> <tr> <td>".$outlet_name."</td> </tr> <tr> <th>Store Address</th> </tr> <tr> <td>".$address_0."</td> </tr> <tr> <td>".$address_1."</td> </tr> <tr> <td>".$address_2."</td> </tr> <tr> <td>".$address_3."</td> </tr> <tr> <td>".$address_4."</td> </tr> <tr> <th>Contact Person</th> </tr> <tr> <td>Jim</td> </tr> <tr> <th>Contact Number</th> </tr> <tr> <td>".$contact_number_1."</td> </tr> <tr> <td>".$contact_number_2."</td> </tr> </table> </td> <td> <table> <tr> <th>License</th> </tr> <tr> <td><a href='uploads/".$license."'>".$license."</a></td> </tr> <tr> <th>Permit Renewal</th> </tr> <tr> <td><a href='uploads/".$permit_renewal."'>".$permit_renewal."</a></td> </tr> <tr> <th>Identity Document</th> </tr> <tr> <td><a href='uploads/".$identity_document."'>".$identity_document."</a></td> </tr> <tr> <th>Other Documents</th> </tr> <tr> <td><a href='uploads/".$other_document."'>".$other_document."</a></td> </tr> <tr> <th>Reference Number</th> </tr> <tr> <td>HSA0123456</td> </tr> <tr> <td>HSA0123457</td> </tr> </table> </td> </table> "; } echo "</table>"; mysqli_close($link); Some code improvements made
  2. Hi All, I'm trying to get my head wrapped around how to create a Table from a DB. I have no issues getting the information, and all the data is pulling through as expected. I just cant seem to get my layout of my table right. I have tried to draw a diagram of how I would like my table to be displayed. The left hand side of the table is pretty much static with the amount of rows always being static. Here there are 5 rows with headings, the 3 row / nested table returning an address section with 5 address rows, and the last row will return the contact number row with 2 contact numbers. The biggest complication is on the right hand side of the table which shows a list of hyperlinked documents, however each document type (heading) may have anywhere from 1 - 10 documents. And I would need this section of the table to expand as each row with a new document is returned. I have attached the layout diagram. My current code for this section looks as follows (The code below is still a work in progress): echo "<div class='row'>"; echo "<div class='col-md-12'>"; echo "<div class='box box-primary'>"; echo "<div class='box-header with-border'>"; echo "<h3 class='box-title'>Outlet Details</h3>"; echo "<table border = '0'>"; echo " <tr> <th width='50%'>Outlet Details</th> <th width='50%'>Outlet Documentation</th> </tr> "; while($row = mysqli_fetch_array($result)) { $store_code = $row['store_code']; $outlet_name = $row['outlet_name']; $address_0 = $row['address_0']; $address_1 = $row['address_1']; $address_2 = $row['address_2']; $address_3 = $row['address_3']; $address_4 = $row['address_4']; $license = $row['scanned_license']; $permit_renewal = $row['scanned_permit_renewal']; $identity_document = $row['scanned_identity_document']; $other_document = $row['scanned_other_document']; echo "<tr> <td>".$store_code."</td> <td><a href='uploads/".$license."'>".$license."</a></td> </tr>"; echo "<tr> <td>".$outlet_name."</td> <td><a href='uploads/".$permit_renewal."'>".$permit_renewal."</a></td> </tr>"; echo "<tr> <td>".$address_0."</td> <td><a href='uploads/".$identity_document."'>".$identity_document."</a></td> </tr>"; echo "<tr> <td>".$address_1."</td> <td><a href='uploads/".$other_document."'>".$other_document."</a></td> </tr>"; }
  3. Somehow with my brain working overtime and not being a seasoned php script writer I didn't even think of doing this, although I know I have done it in the past. Thanks...
  4. Hi All, I am running a PHP script on a daily basis to import data into my database. THe PHP file is executed by my Windows Services. The PHP file is a LOAD DATA IN FILE script and looks like the below: LOAD DATA LOCAL INFILE '\master_import\\myfilename.csv' IGNORE INTO TABLE mydatabase.mytable CHARACTER SET latin1 FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES ( record_number , name , action_date , location , type_of_outlet .... ) ; The ENCLOSED BY '"' is where my problem lies, as I do not know how to use the '"' without PHP reading it as a " to close the script. Any help will be appreciated. Thanks.
  5. I've made some changes to this now and I have managed to get the entity code from the previous page to echo correctly. But what I can seem to get right is to now use this entity number that is passed to query my database and populate the form: $link = mysqli_connect("localhost", "username", "password", "db"); if(isset($_GET['entity_number'])) { $store_code = $_GET['entity_number'];} echo $entity_number; $sql = mysqli_query ($link,"SELECT id , username , entity_number , entity_name , address_0 , address_1 , address_2 , address_3 , address_4 , contact_number_1 , contact_number_2 FROM scrm.liquor_licenses WHERE entity_number= '$entity_number'"); while ($row = mysqli_fetch_assoc($sql)); $username = $row['username']; $entity_number= $row['entity_number']; $entity_name= $row['entity_name']; /* close connection */ The form which is on the same page as the above query: <input type="hidden" class="form-control" value="<?php ECHO $_SESSION['username']; ?>" name="username" readonly> <div class="form-group"> <label>Outlet Number :</label> <input type="text" class="form-control" value="<?php ECHO $entity_number?>" name="entity_number"> </div> <div class="form-group"> <label>Outlet Number :</label> <input type="text" class="form-control" value="<?php ECHO $entity_name?>" name="entity_name"> </div>
  6. Hi all, I have a pretty basic front end system where specific details are displayed. There is also and edit button next to each record that is displayed however not all info about this record is displayed. When I click edit, I want a query to run on my next page, which will pre-populate the form with information from a query using the reference from the previous page. A basic example is: if(isset($_GET['entity_code'])) echo $entity_code; $sql = "SELECT id , username , region , entity_code , address_0 , address_1 , address_2 , address_3 , address_4 , contact_number_1 , contact_number_2 FROM scrm.entity_details WHERE entity_number= '$entity_number'"; if ($result = $mysqli->query($sql)) { /* fetch associative array */ while ($row = $result->fetch_assoc()) { printf ("%s (%s)\n", $row['outlet_number'], $row['outlet_name']); } } /* close connection */ $mysqli->close(); The entity number is passed successfully from the previous page, however my form is not populating and various I have tried give me a number of different outcomes. The below is where I am trying to populate my form: <input type="hidden" class="form-control" value="<?php ECHO $_SESSION['username']; ?>" name="username" readonly> <div class="form-group"> <label>Entity Number :</label> <input type="text" class="form-control" value="<?php ECHO $row['entity_number']; ?>" name="outlet_number"> </div> <div class="form-group"> <label>Entity Name :</label> <input type="text" class="form-control" value="<?php ECHO $row['entity_name']; ?>" name="outlet_number"> </div> I really don't know where I am going wrong...
  7. Thanks Jacques1, really appreciate the help. And it eliminates having to use the prepared statements and then dropping them after one use.
  8. The prepare statement is to compile the CSV file with a datestamp. I used it this way in MySQL Workbench to compile the export file with the datestamp. From my understanding on the research I did, this was the only way to add a datestamp to a file in MySQL Workbench.
  9. I can't say I am experienced at all in doing out files when it comes to PHP. Doing it under MySQL Workbench is a lot easier, so my question is really the principle of applying it. My understanding in PHP is that the actual query needs to be within Double quotation marks, however this becomes a challenge when taking the existing file / script directly from MySQL Workbench and trying to plug it into PHP. I'm unsure of how to apply this. That said, I'm going to attempt a change based on what you have said, let me see what the outcome is.
  10. The single quote you are referring to has a corresponding single quote after the .csv Although, this does work when run directly on MySQL Workbench, I'm not sure what needs to change for plugging it into PHP. This is what the working script in MySQL Workbench looks like: SET @exportfile = CONCAT("SELECT 'FILED_1' , 'FIELD_2' , .... UNION ALL SELECT * FROM mydatabasetable INTO OUTFILE 'E:/Data/exports/DailyExport/myoutputfile" , DATE_FORMAT( NOW(), '%Y%m%d') , ".csv' FIELDS TERMINATED BY ',' ENCLOSED BY '''' LINES TERMINATED BY '\r\n'" ); PREPARE processing FROM @exportfile; EXECUTE processing; DROP PREPARE processing;
  11. Hi All, This is part of a PHP script that I am wanting to use to automate some daily data exports. The problem I am having, is adding a datestamp to my export file. The script itself works when executed in MySQL but not under PHP. Does anyone have any insight into how I can get this working? The error message I am currently getting is, and the part of php script I am running can be seen below. $sql1 = "SET @exportfile = CONCAT(SELECT 'FIELD_1' , 'FIELD_2' , .... UNION ALL SELECT * FROM mydatabasetable INTO OUTFILE 'E:/Data/exports/DailyExport/myexportfile" , DATE_FORMAT( NOW(), '%Y%m%d') , ".csv' FIELDS TERMINATED BY ',' ENCLOSED BY '''' LINES TERMINATED BY '\r\n' );"; $sql2 = "PREPARE processing FROM @exportfile;"; $sql3 = "EXECUTE processing;"; $sql4 = "DROP PREPARE processing;"; Any help here is greatly appreciated.
  12. Thanks guys, you answers really add a lot of value. And definitely help me in knowing where I need to do a lot more learning. @requinix The scripts would be just about exactly the same in each scenario yes, with the only difference being the column counts and the destination tables as mentioned. The party/s whom need to be notified of a failed / successful script in some instances may also differ, but this would not be often. @Jacques1 I was actually not aware of TWIG, so will be looking into making use of this and learning more about it. I broke the TSL certification, as I could not get any of my settings to work correctly. The "Send" e-mail address I am using at the moment, is also only for a test scenario, and I will be creating the reporting e-mail address as soon as everything is working. I am still running everything on a "Virtual Environment". The column names are luckily not named as listed here no I'm not sure how to answer your other comments
  13. Thanks for your answer here requinix. Basically what I mean by a cleaner script really comes down to understand how to use and populate a mail and then send it via PHP mailer. My current script is made up of a lot of code from various sources, meaning I don't always fully understand what it is doing, and secondly, I have quite a bit of code repetition. Another problem would be that I am possibly using outdated source code. Here is an example of what I have / am using: <?php $sql1 = "USE mydatabase"; $sql2 = "TRUNCATE TABLE mytable"; $sql3 = "LOAD DATA LOCAL INFILE 'DataImport//sourcefile.csv' REPLACE INTO TABLE mytable CHARACTER SET latin1 FIELDS TERMINATED BY ',' IGNORE 1 LINES (`id` , `column1` , `column2` , `column3` , `column4` , `column5` , `column6` , `column7` , `column8` , `column9` , `column10` , `column11` , `column12`);"; $con=mysqli_connect("localhost","root","mypassword","mydatabase"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }; $result1 = mysqli_query($con, $sql1); $result2 = mysqli_query($con, $sql2); $result3 = mysqli_query($con, $sql3); if (mysqli_affected_rows($con) > 1) { $message ="". mysqli_affected_rows($con). " rows were successfully added to the table!"; } else { $message = "" . mysqli_error($con). "has caused the updateto fail"; }; echo $message; // To send HTML mail, the Content-type header must be set require("PHPMailerAutoload.php"); // path to the PHPMailerAutoload.php file. require("class.phpmailer.php"); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $body = "<html>\n"; $body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#344433;\">\n"; $body = $message; $body .= "</body>\n"; $body .= "</html>\n"; // Additional headers $subject = 'Daily Import Result' ."\r\n"; $mail = new PHPMailer(); $mail->IsSMTP(true); $mail->Mailer = "smtp"; $mail->Host = "smtp.mydomain.co.za"; $mail->Port = 587; // 8025, 587 and 25 can also be used. Use Port 465 for SSL. $mail->SMTPAuth = true; $mail->SMTPSecure = 'tls'; $mail->Username = "myusername@mydomain.co.za"; $mail->Password = "mymailpassword"; $mail->CharSet = "UTF-8"; $mail->SMTPOptions = array( // Bypass security verification on e-mail. 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->From = 'reportingserver@mydomain.co.za'; $mail->FromName = 'Reporting Server'; //$mail->AddAddress('mail1@mydomain.co.za', 'Mail1'); //$mail->AddAddress('mail2@mydomain.co.za', 'Mail2'); //$mail->AddAddress('mail3@mydomain.co.za', 'Mail3'); $mail->AddReplyTo('me@mymailserver.com', 'My Name'); $mail->Subject = $subject; $mail->Body = $body."\r\n"; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; exit; } else { echo 'Message has been sent.'; } mysqli_close($con); ?>
  14. Hi All, I haven't made use of PHPMailer for quite sometime, as I had been in a different environment. I have noticed that the has been quite a few changes since I last used it, and after struggling the whole day to eventually get it working I am not entirely satisfied with the solution. Some background of what I am doing and will be using it for: I have a number of PHP Scripts that are executing through the use of *.bat files through windows Task Manager. The scripts execute running a number of tasks, and at the end of the task I need a mail to be sent with the results of the task i.e. Successful, Failed, Lines added to database etc... The mail will be going to not only myself, but to a number of other users, and eventually I want to expand the use of it. So I would like to achieve the following: A cleaner script Select mail recipients from a database table, so that I don't need to manually input it into each form / script. Send the mails as HTML using base64 for the images / other "beautifying" elements. Understand exactly how to use all / at least most of the tags correctly. I fully understand that many of these answers could probably be found on google, but I am yet to find a source, where the explanation is clear and precise. What I have noticed, is that 95% of coders expect the user to understand coding on the same level as they are on, but it is not always the case, so any help / guidance will really be appreciated. /if need be, I can supply my current code. Thanks.
  15. Would a simple echo statement do the trick? Or should I rather look to ind out more about something a little more complex? Reason I'm asking is because when the list of users is populated I would like to perform a number of functions by simply clicking on the drop down arrow associated with each user. This will then give me 3 links, i.e send a message, edit user, delete user. This is the extent of my current idea, by I can see it extending once I have the basics working
  16. From what I can see, the css seem to dynamically generate the different div classes, although I could be wrong. How would I update the data-for".cyruxx" dynmically?
  17. Are the dynamic div sections required? Or would I be able to do this with just one div? I will try and find something on how to create the dynamic div sections.
  18. Hi All, I'm hoping that this is the correct place to be posting this question. I have a Bootstrap theme which I downloaded. Having just recently discovered bootstrap, I am still struggling to to fully customize the templates and was hoping that I could get some advice / assistance here. I have over the last week written a script that I would like to use to track user activity and I have gotten this to work 90% like I want it to. One of the challenges I have with this, is how to make the information display in the bootstrap template. The demo's have the information hard coded, and I haven't been able to find some thing that tells me how to use the template, linking it to a database to populate the information. Here is the code to the bootstrap theme (Link to the full theme: https://github.com/Cyruxx/Bootstrap-User-List-Snippet) : <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title>Admin Table for Bootstrap</title> <!-- Bootstrap core CSS --> <link href="css/bootstrap.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="adminTable.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> <![endif]--> </head> <body> <br><br> <div class="container"> <div class="well col-sm-12 col-md-8 col-md-offset-2"> <div class="row user-row"> <div class="col-md-1"> <img class="img-circle" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=50" alt="User Pic"> </div> <div class="col-md-10"> <strong>Cyruxx</strong><br> <span class="text-muted">User level: Administrator</span> </div> <!-- add .rowname class to attribute data-for (Dropdown!)--> <div class="col-md-1 dropdown-user" data-for=".cyruxx"> <i class="glyphicon glyphicon-chevron-down text-muted"></i> </div> </div> <!-- Add data-for class to this row --> <div class="row user-infos cyruxx"> <div class="col-sm-10 col-md-10 col-md-offset-1"> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">User information</h3> </div> <div class="panel-body"> <div class="row"> <div class="col-md-3"> <img class="img-circle" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=100" alt="User Pic"> </div> <div class="col-md-6"> <strong>Cyruxx</strong><br> <table class="table table-condensed table-responsive table-user-information"> <tbody> <tr> <td>User level:</td> <td>Administrator</td> </tr> <tr> <td>Registered since:</td> <td>11/12/2013</td> </tr> <tr> <td>Topics</td> <td>15</td> </tr> <tr> <td>Warnings</td> <td>0</td> </tr> </tbody> </table> </div> </div> </div> <div class="panel-footer"> <button class="btn btn-sm btn-primary" type="button" data-toggle="tooltip" data-original-title="Send message to user"><i class="glyphicon glyphicon-envelope"></i></button> <span class="pull-right"> <button class="btn btn-sm btn-warning" type="button" data-toggle="tooltip" data-original-title="Edit this user"><i class="glyphicon glyphicon-edit"></i></button> <button class="btn btn-sm btn-danger" type="button" data-toggle="tooltip" data-original-title="Remove this user"><i class="glyphicon glyphicon-remove"></i></button> </span> </div> </div> </div> </div> </div> </div> </div> </div> </div><!-- /.container --> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="userTable.js"></script> </body> </html> Any help / assistance here will really be appreciated. Thanks.
  19. I have removed it so the script only looks at the newly posted part. That said, I wouldn't mind learning and understanding what is wrong with the part of the code you are commenting on... With what I have done, I have seen the possibility of also using the same code to indicate my online users. Also, I have updated the code to include the page id, which I create each time using a variable, but this is not throwing out a new error: The updated code with a page_id <?php error_reporting(E_ALL & ~E_NOTICE); require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconfig.php'); $timestamp = date("Y-m-d H:i:s"); { #INSERT THE USER INTO THE PAGE_HIT TABLE IF THEY DO NOT EXIST ELSE UPDATE THE DUPLICATE KEY (memberID) $stmtinsrt = $db->prepare('INSERT INTO sys_online_users (memberID, username, last_active, page_id) VALUES (:memberID, :username, :last_active, :page_id) ON DUPLICATE KEY UPDATE last_active= :last_active AND page_id = :page_id'); $stmtinsrt->execute(array( ':memberID' => $_SESSION['memberID'], ':username' => $_SESSION['username'], ':last_active' => $timestamp, ':page_id' => $_POST['page_id'], )); $id = $db->lastInsertId('memberID'); } ?>
  20. I have actually managed to resolve this by simplifying my query quite a bit. Here is the solution that worked for me, although I do not know if it is the best solution. Please let me know your thoughts, and advise if you would do anything differently. <?php error_reporting(E_ALL & ~E_NOTICE); require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconfig.php'); $timestamp = date("Y-m-d H:i:s"); { #INSERT THE USER INTO THE PAGE_HIT TABLE IF THEY DO NOT EXIST ELSE UPDATE THE DUPLICATE KEY (memberID) $stmtinsrt = $db->prepare('INSERT INTO sys_page_hit (memberID, username, last_active) VALUES (:memberID, :username, :last_active) ON DUPLICATE KEY UPDATE last_active= :last_active'); $stmtinsrt->execute(array( ':memberID' => $_SESSION['memberID'], ':username' => $_SESSION['username'], ':last_active' => $timestamp )); $id = $db->lastInsertId('memberID'); } ?>
  21. Hi Guys, I've been working on a site for quite a while now, and still being a "learner" in the area of development I have run into a number of challenges that I am not sure how to resolve, or exactly what to look for. The most recent as a script that is executed by JavaScript each time a user visits a page. This way I am able to track how frequently a page is visited and by whom. I am however getting the following error when testing the script: Here is my code for the "page_hit.php" file: <?php error_reporting(E_ALL & ~E_NOTICE); require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconfig.php'); $timestamp = date("Y-m-d H:i:s"); #RETURN A LIST OF WHICH USERS ARE INDICATED IN THE PAGE_HIT TABLE $stmtvisit = $db->prepare('SELECT * FROM sys_page_hit WHERE memberID = $_SESSION[memberID]'); $stmtvisit->execute; $results = $stmtvisit->fetchAll(PDO::FETCH_ASSOC); echo $results; if($results=="0") { #INSERT THE USER INTO THE PAGE_HIT TABLE IF THEY DO NOT EXIST $stmtinsrt = $db->prepare('INSERT INTO sys_page_hit (memberID, username, last_active) VALUES (:memberID, :username, :last_active)'); $stmtinsrt->execute(array( ':memberID' => $_SESSION['memberID'], ':username' => $_SESSION['username'], ':last_active' => $timestamp )); $id = $db->lastInsertId('memberID'); } else { #UPDATE THE USER'S CURRENT VISIT IN THE TABLE IF THEY DO EXIST $stmtupd = $db->prepare('UPDATE sys_page_hit SET last_active = :lastactive WHERE memberID = :memberID'); $stmtupd->execute(array( ':memberID' => $_SESSION['memberID'], ':last_active' => $timestamp )); $id = $db->lastInsertId('memberID'); } ?> Thanks in advance
  22. Thanks Gizmola, let me see if I can get this approach working
  23. I forgot to mention that I did also have a look at Pusher last night, but I am left horribly confused trying to put things together. The Pusher option is really nice for when the site runs completely online, however there may be instances where my entire site is actually going to run on a intranet which won't have access to and internet connection.
  24. Gizmola, I spent the entire day today searching for both an Ajax and Websocket solution. I would very much like to implement the websocket solution, but I was not able to find a working solution with code that I could easily implement into my page. If you could direct me to a good working example which would help me in achieving my goals, I would really appreciate that. Some more info about the site that I am developing is: When a user has been registered, they will be assigned to a team / group, when the group leader signs in they will need to see only their team members who are both online and offline. The online members should have a little green light next to their names and the offline members should have a red light. Members who are in an away state should reflect an orange light. For this reason, I will need to be looking up certain information in my database, like which team they belong to and return this id along with the users status to the group leader. Regular users should be able to see all members status.
  25. I have managed to find a bit of code which shows the activity status to the user who is logged in. If I navigate to a different tab, it picks up that I have navigated away, and sets my status as such, the question now is, How do I pass this information to the database so that I can use it to show other users who is online? How would I show an online icon (small green / yellow / red) instead of echoing a new row of text? I am using the following code as an include file (I think it is important to state that this is not my own code, so I am not entirely sure how it functions): <html> <head> <title>Idle.Js Test</title> <script src="../js/jquery.min.js"></script> <script src="../js/idle.js"></script> <script> $(function() { function setMessage(msg) { $('#ActivityList').append("<li>" + new Date().toTimeString() + ": " + msg + "</li>"); } var awayCallback = function() { setMessage("away"); }; var awayBackCallback = function() { setMessage("back"); }; var hiddenCallback = function() { setMessage("User is not looking at page"); }; var visibleCallback = function(){ setMessage("User started looking at page again") }; var idle = new Idle({ onHidden : hiddenCallback, onVisible : visibleCallback, onAway : awayCallback, onAwayBack : awayBackCallback, awayTimeout : $('#Timeout').val() //away with default value of the textbox }).start(); $('#Timeout').keydown(function(e) { if(e.keyCode == 13) { var timeout = $(this).val(); setMessage("Timeout changed to: " + timeout); idle.setAwayTimeout(timeout); } }) }); </script> <style> #ActivityList { border: 1px solid #ccc; padding: 5px; width: 400px; } #ActivityList li { border-bottom: 1px solid #eee; margin: 5px 0; } </style> </head> <body> <label for="Timeout">Set timeout</label> <input id="Timeout" type="text" value="10000" /> <ul id="ActivityList"></ul> </body> </html> Idle.js file: (function() { var Idle; if (!document.addEventListener) { if (document.attachEvent) { document.addEventListener = function(event, callback, useCapture) { return document.attachEvent("on" + event, callback, useCapture); }; } else { document.addEventListener = function() { return {}; }; } } if (!document.removeEventListener) { if (document.detachEvent) { document.removeEventListener = function(event, callback) { return document.detachEvent("on" + event, callback); }; } else { document.removeEventListener = function() { return {}; }; } } "use strict"; Idle = {}; Idle = (function() { Idle.isAway = false; Idle.awayTimeout = 3000; Idle.awayTimestamp = 0; Idle.awayTimer = null; Idle.onAway = null; Idle.onAwayBack = null; Idle.onVisible = null; Idle.onHidden = null; function Idle(options) { var activeMethod, activity; if (options) { this.awayTimeout = parseInt(options.awayTimeout, 10); this.onAway = options.onAway; this.onAwayBack = options.onAwayBack; this.onVisible = options.onVisible; this.onHidden = options.onHidden; } activity = this; activeMethod = function() { return activity.onActive(); }; window.onclick = activeMethod; window.onmousemove = activeMethod; window.onmouseenter = activeMethod; window.onkeydown = activeMethod; window.onscroll = activeMethod; window.onmousewheel = activeMethod; } Idle.prototype.onActive = function() { this.awayTimestamp = new Date().getTime() + this.awayTimeout; if (this.isAway) { if (this.onAwayBack) { this.onAwayBack(); } this.start(); } this.isAway = false; return true; }; Idle.prototype.start = function() { var activity; if (!this.listener) { this.listener = (function() { return activity.handleVisibilityChange(); }); document.addEventListener("visibilitychange", this.listener, false); document.addEventListener("webkitvisibilitychange", this.listener, false); document.addEventListener("msvisibilitychange", this.listener, false); } this.awayTimestamp = new Date().getTime() + this.awayTimeout; if (this.awayTimer !== null) { clearTimeout(this.awayTimer); } activity = this; this.awayTimer = setTimeout((function() { return activity.checkAway(); }), this.awayTimeout + 100); return this; }; Idle.prototype.stop = function() { if (this.awayTimer !== null) { clearTimeout(this.awayTimer); } if (this.listener !== null) { document.removeEventListener("visibilitychange", this.listener); document.removeEventListener("webkitvisibilitychange", this.listener); document.removeEventListener("msvisibilitychange", this.listener); this.listener = null; } return this; }; Idle.prototype.setAwayTimeout = function(ms) { this.awayTimeout = parseInt(ms, 10); return this; }; Idle.prototype.checkAway = function() { var activity, t; t = new Date().getTime(); if (t < this.awayTimestamp) { this.isAway = false; activity = this; this.awayTimer = setTimeout((function() { return activity.checkAway(); }), this.awayTimestamp - t + 100); return; } if (this.awayTimer !== null) { clearTimeout(this.awayTimer); } this.isAway = true; if (this.onAway) { return this.onAway(); } }; Idle.prototype.handleVisibilityChange = function() { if (document.hidden || document.msHidden || document.webkitHidden) { if (this.onHidden) { return this.onHidden(); } } else { if (this.onVisible) { return this.onVisible(); } } }; return Idle; })(); if (typeof define === 'function' && define.amd) { define([], Idle); } else if (typeof exports === 'object') { module.exports = Idle; } else { window.Idle = Idle; } }).call(this);
×
×
  • 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.