Running log widget
Jump to navigation
Jump to search
<?php $user_info = wp_get_current_user(); if (($_POST[new_entry]) && ($user_info->user_level=="10")) { // first check to avoid duplicate entries $fp = fopen('/home/httpd/html/misc/running_log.txt', 'r'); $dupe_check = fgets($fp, 1000); // get rid of trailing whitespace and compare if (chop($dupe_check) != chop($_POST[new_entry])) { // read the new entry into a variable $new_entry = stripslashes(htmlspecialchars($_POST[new_entry])); // add a line break $new_entry .= "\n"; // write entry to a temp file $fp = fopen('/tmp/temp.txt','w'); fputs($fp, $new_entry); fclose($fp); // use file commands to update/replace the old log file exec("cat /home/httpd/html/misc/running_log.txt >> /tmp/temp.txt"); exec("mv /tmp/temp.txt /home/httpd/html/misc/running_log.txt"); } } $fp = fopen('/home/httpd/html/misc/running_log.txt', 'r'); $first_line = fgets($fp, 1000); fclose($fp); if ($user_info->user_level=="10") { $edit_form = "<form method='post' action='$PHP_SELF'>"; $edit_form .= "<br><input type='text' size='10' maxlength='1000' name='new_entry' value='". date("n\/d\/Y - ") ."' style='background-color: #FFEDB2; color: #000000'><br><br>"; $edit_form .= "<input style='color: #000000' type='submit' value='Update log' >"; $edit_form .= "</form>"; $link = "<br><a href='/misc/running_log.txt'>View complete log</a>"; $output = $first_line . $edit_form . $link; } else { $link = "<br><br><a href='/misc/running_log.txt'>View complete log</a>"; $output = $first_line . $link; } echo $output; ?>