Various reformats. Changed boolean variables from 1/0 to TRUE/FALSE in multiple files.

This commit is contained in:
2026-02-19 14:08:40 -05:00
parent 9122040863
commit 01fd47814b
22 changed files with 3502 additions and 3150 deletions

View File

@@ -28,48 +28,50 @@ include("settings.php");
// build the basic color array
$basic_colors=array(
"White" => "#FFFFFF",
"Silver" => "#C0C0C0",
"Gray" => "#808080",
"Black" => "#000000",
"Red" => "#FF0000",
"Maroon" => "#800000",
"Orange" => "#FFA500",
"Yellow" => "#FFFF00",
"Olive" => "#808000",
"Lime" => "#00FF00",
"Green" => "#008000",
"Aqua" => "#00FFFF",
"Teal" => "#008080",
"Blue" => "#0000FF",
"Navy" => "#000080",
"Fuchsia" => "#FF00FF",
"Purple" => "#800080");
$basic_colors = array(
"White" => "#FFFFFF",
"Silver" => "#C0C0C0",
"Gray" => "#808080",
"Black" => "#000000",
"Red" => "#FF0000",
"Maroon" => "#800000",
"Orange" => "#FFA500",
"Yellow" => "#FFFF00",
"Olive" => "#808000",
"Lime" => "#00FF00",
"Green" => "#008000",
"Aqua" => "#00FFFF",
"Teal" => "#008080",
"Blue" => "#0000FF",
"Navy" => "#000080",
"Fuchsia" => "#FF00FF",
"Purple" => "#800080"
);
// Generic functions
function framework($option,$htmltitle,$pagetitle,$print) {
function framework($option, $htmltitle, $pagetitle, $print)
{
// generates html code for the beginning and end of all pages
if ($option=="begin") {
if ($option == "begin") {
// generates everything down to the first horiz rule inclusive
// htmltitle is the page title that appears in the window titlebar
// pagetitle is what will appear as the title of the page itself
// print is whether to format for printing or not
if ($print) {
$bgcolor=P_BACKGROUND_COLOR;
$textcolor=P_TEXT_COLOR;
$linkcolor=P_LINK_COLOR;
$vlinkcolor=P_VLINK_COLOR;
$hdgcolor=P_HEADING_COLOR;
$bgcolor = P_BACKGROUND_COLOR;
$textcolor = P_TEXT_COLOR;
$linkcolor = P_LINK_COLOR;
$vlinkcolor = P_VLINK_COLOR;
$hdgcolor = P_HEADING_COLOR;
} else {
$bgcolor=BACKGROUND_COLOR;
$textcolor=TEXT_COLOR;
$linkcolor=LINK_COLOR;
$vlinkcolor=VLINK_COLOR;
$hdgcolor=HEADING_COLOR;
$bgcolor = BACKGROUND_COLOR;
$textcolor = TEXT_COLOR;
$linkcolor = LINK_COLOR;
$vlinkcolor = VLINK_COLOR;
$hdgcolor = HEADING_COLOR;
}
echo "
<html>
<head>
@@ -91,13 +93,13 @@ function framework($option,$htmltitle,$pagetitle,$print) {
<font size=5 color=\"$hdgcolor\"><b> $htmltitle - $pagetitle</b></font><br>
";
}
} else if ($option=="end") {
} else if ($option == "end") {
// generates everything from the last horiz rule down to end of page
echo "
<hr><br><br>
";
if (defined("FOOTER_MESSAGE")) {
$footer_msg=FOOTER_MESSAGE;
$footer_msg = FOOTER_MESSAGE;
echo "
<center>$footer_msg</center><br>
";
@@ -221,14 +223,15 @@ function framework($option,$htmltitle,$pagetitle,$print) {
}
}
function pagetable($option) {
if ($option=="begin") {
function pagetable($option)
{
if ($option == "begin") {
echo "
<br>
<table border=\"0\" width=\"100%\" cellpadding=\"10\">
<tr>
";
} else if ($option=="end") {
} else if ($option == "end") {
echo "
</tr></table>
";
@@ -240,14 +243,15 @@ function pagetable($option) {
}
}
function pageblock($block,$option) {
function pageblock($block, $option)
{
global $sbcolor;
if ($block=="left") {
if ($option=="begin") {
if ($block == "left") {
if ($option == "begin") {
echo "
<td width=\"210\" bgcolor=\"$sbcolor\" valign=\"top\">
";
} else if ($option=="end") {
} else if ($option == "end") {
echo "
</td>
";
@@ -257,12 +261,12 @@ function pageblock($block,$option) {
";
exit(1);
}
} else if ($block=="right") {
if ($option=="begin") {
} else if ($block == "right") {
if ($option == "begin") {
echo "
<td valign=\"top\">
";
} else if ($option=="end") {
} else if ($option == "end") {
echo "
</td>
";
@@ -280,11 +284,12 @@ function pageblock($block,$option) {
}
}
function sidemenu($noprint=false) {
function sidemenu($noprint = false)
{
// Displays sidebar menu
global $db,$mbgcolor,$noprint;
$doparts=PARTS_FUNCTIONS;
$doschedmaint=SCHEDMAINT_FUNCTIONS;
global $db, $mbgcolor, $noprint;
$doparts = PARTS_FUNCTIONS;
$doschedmaint = SCHEDMAINT_FUNCTIONS;
echo "
<hr><br>
<table bgcolor=\"$mbgcolor\" border=\"1\" width=\"100%\">
@@ -333,8 +338,8 @@ function sidemenu($noprint=false) {
</table>
";
} else {
$loginid=$_SESSION['login'];
$loggedinas=mysqli_fetch_row(mysqli_query($db,"select techname from techs where techid=\"$loginid\""))[0];
$loginid = $_SESSION['login'];
$loggedinas = mysqli_fetch_row(mysqli_query($db, "select techname from techs where techid=\"$loginid\""))[0];
echo "
<hr>
<table bgcolor=\"$mbgcolor\" border=\"1\" width=\"100%\">
@@ -359,22 +364,23 @@ function sidemenu($noprint=false) {
";
}
function banner($print) {
function banner($print)
{
// displays a banner
global $db;
$bannerid=BANNER;
$bannerid = BANNER;
// get banner parameters from banner table
$banrow=mysqli_fetch_assoc(mysqli_query($db,"select * from banners where bannerid=\"$bannerid\""));
$banrow = mysqli_fetch_assoc(mysqli_query($db, "select * from banners where bannerid=\"$bannerid\""));
if (!$banrow) {
$bannerid=1;
$bannerid = 1;
} else {
$bannertext=$banrow["bannername"];
$bannertext = $banrow["bannername"];
if ($print) {
$bannercolor="#FFFFFF";
$bannertxtcolor="#000000";
$bannercolor = "#FFFFFF";
$bannertxtcolor = "#000000";
} else {
$bannercolor=$banrow["bannercolor"];
$bannertxtcolor=$banrow["textcolor"];
$bannercolor = $banrow["bannercolor"];
$bannertxtcolor = $banrow["textcolor"];
}
}
if ($bannerid != 1) {
@@ -385,47 +391,49 @@ function banner($print) {
}
}
function dblookup($dbhandle,$table,$in_field,$out_field,$in_data) {
function dblookup($dbhandle, $table, $in_field, $out_field, $in_data)
{
// look up a single field in a database given a value for a single field
$dbqry=mysqli_query($dbhandle,"select $out_field from $table where $in_field=\"$in_data\"");
$dbqry = mysqli_query($dbhandle, "select $out_field from $table where $in_field=\"$in_data\"");
if (mysqli_num_rows($dbqry)) {
$out_data=mysqli_fetch_row($dbqry)[0];
$out_data = mysqli_fetch_row($dbqry)[0];
} else {
$out_data=NULL;
$out_data = NULL;
}
return($out_data);
return ($out_data);
}
function calendar($year,$month,$day,$link_url) {
function calendar($year, $month, $day, $link_url)
{
// takes a numeric year, month, day, and the basic url for the day links as arguments
// Shows a calendar with clickable dates.
// Based on an embeddable calendar by Yves Glodt.
// See http://www.mind.lu/~yg/stuff/
$YearToShow = $year;
$MonthToShow = $month;
$DayToShow = $day;
$NumberOfDays = date(t,mktime(0,0,0,$MonthToShow+1,0,$YearToShow,-1));
if ($month==1) {
$mbackyear=$year-1;
$mbackmonth=12;
$NumberOfDays = date(t, mktime(0, 0, 0, $MonthToShow + 1, 0, $YearToShow, -1));
if ($month == 1) {
$mbackyear = $year - 1;
$mbackmonth = 12;
} else {
$mbackyear=$year;
$mbackmonth=$month-1;
$mbackyear = $year;
$mbackmonth = $month - 1;
}
if ($month==12) {
$mfwdyear=$year+1;
$mfwdmonth=1;
if ($month == 12) {
$mfwdyear = $year + 1;
$mfwdmonth = 1;
} else {
$mfwdyear=$year;
$mfwdmonth=$month+1;
$mfwdyear = $year;
$mfwdmonth = $month + 1;
}
$ybackyear=$year-1;
$ybackmonth=$month;
$yfwdyear=$year+1;
$yfwdmonth=$month;
$MonthNames = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
$ybackyear = $year - 1;
$ybackmonth = $month;
$yfwdyear = $year + 1;
$yfwdmonth = $month;
$MonthNames = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
echo <<<EOT
<table border="1" cellpadding="1" cellspacing="0">
@@ -452,39 +460,39 @@ function calendar($year,$month,$day,$link_url) {
EOT;
$FirstDayOfWeek = date(l,mktime(0,0,0,$MonthToShow,1,$YearToShow));
$FirstDayOfWeek = date(l, mktime(0, 0, 0, $MonthToShow, 1, $YearToShow));
switch ($FirstDayOfWeek) {
case 'Monday':
$offset = 1;
break;
break;
case 'Tuesday':
$offset = 2;
break;
break;
case 'Wednesday':
$offset = 3;
break;
break;
case 'Thursday':
$offset = 4;
break;
break;
case 'Friday':
$offset = 5;
break;
break;
case 'Saturday':
$offset = 6;
break;
break;
default:
$offset = 0;
}
if ($offset > 0) {
print "<tr align=\"center\">\n";
echo str_repeat("<td class=\"n\">&nbsp;</td>\n",$offset);
echo str_repeat("<td class=\"n\">&nbsp;</td>\n", $offset);
}
for ($i=1; $i <= $NumberOfDays; $i++) {
$DayOfWeek = date(l,mktime(0,0,0,$MonthToShow,$i,$YearToShow));
if($DayOfWeek == 'Sunday') {
for ($i = 1; $i <= $NumberOfDays; $i++) {
$DayOfWeek = date(l, mktime(0, 0, 0, $MonthToShow, $i, $YearToShow));
if ($DayOfWeek == 'Sunday') {
print "<tr align=\"center\">\n";
}
if ($i != $DayToShow) {
@@ -492,27 +500,28 @@ EOT;
} else {
print "<td><a href=\"$link_url?y=$YearToShow&m=$MonthToShow&d=$i\"><b><font size=\"+1\" color=\"#FF0000\">$i</font></b></a></td>\n";
}
if($DayOfWeek == 'Saturday') {
if ($DayOfWeek == 'Saturday') {
print "</tr>\n";
}
}
if ( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) ) {
if (42-$NumberOfDays-$offset > 0) {
echo str_repeat("<td class=\"n\">&nbsp;</td>\n",42-$NumberOfDays-$offset);
if ((($offset == 5) && ($NumberOfDays > 30)) || (($offset == 6) && ($NumberOfDays > 29))) {
if (42 - $NumberOfDays - $offset > 0) {
echo str_repeat("<td class=\"n\">&nbsp;</td>\n", 42 - $NumberOfDays - $offset);
}
print "</tr>\n";
} elseif ( ($NumberOfDays != 28) || ($offset > 0) ) {
if (35-$NumberOfDays-$offset > 0) {
echo str_repeat("<td class=\"n\">&nbsp;</td>\n",35-$NumberOfDays-$offset);
print "</tr>\n";
} elseif (($NumberOfDays != 28) || ($offset > 0)) {
if (35 - $NumberOfDays - $offset > 0) {
echo str_repeat("<td class=\"n\">&nbsp;</td>\n", 35 - $NumberOfDays - $offset);
print "</tr>\n";
}
}
}
print "</table>\n";
}
function colorpicker($baseurl) {
function colorpicker($baseurl)
{
// takes a standard url and tacks the color number on to the end of it
// giving a palette of links
echo "
@@ -595,54 +604,57 @@ function colorpicker($baseurl) {
// Project functions
function getsetting($setting_name,$tech_id) {
function getsetting($setting_name, $tech_id)
{
// get the value of a setting for a tech
global $db;
$confinfo=mysqli_fetch_assoc(mysqli_query($db,"select confid,confvalue from configs where confname=\"$setting_name\""));
$confid=$confinfo["confid"];
$confvalue=$confinfo["confvalue"];
$custqry=mysqli_query($db,"select customconfvalue from customs where customconfnum=\"$confid\" and customtech=\"$tech_id\"");
$confinfo = mysqli_fetch_assoc(mysqli_query($db, "select confid,confvalue from configs where confname=\"$setting_name\""));
$confid = $confinfo["confid"];
$confvalue = $confinfo["confvalue"];
$custqry = mysqli_query($db, "select customconfvalue from customs where customconfnum=\"$confid\" and customtech=\"$tech_id\"");
if (mysqli_num_rows($custqry)) {
$custvalue=mysqli_fetch_row($custqry)[0];
$custvalue = mysqli_fetch_row($custqry)[0];
}
// if value in custom table, use it
if (mysqli_num_rows($custqry)) {
$retvalue=$custvalue;
$table="customs";
$retvalue = $custvalue;
$table = "customs";
} else {
$retvalue=$confvalue;
$table="configs";
$retvalue = $confvalue;
$table = "configs";
}
$result=array('value' => $retvalue,'table' => $table,'id' => $confid);
$result = array('value' => $retvalue, 'table' => $table, 'id' => $confid);
return $result;
}
function putsetting($setting_name,$setting_value,$tech_id) {
function putsetting($setting_name, $setting_value, $tech_id)
{
// set the value of a setting for a tech
global $db;
$confinfo=mysqli_fetch_assoc(mysqli_query($db,"select confid,confvalue from configs where confname=\"$setting_name\""));
$confid=$confinfo["confid"];
$confvalue=$confinfo["confvalue"];
$custqry=mysqli_query($db,"select customconfvalue from customs where customconfnum=\"$confid\" and customtech=\"$tech_id\"");
$confinfo = mysqli_fetch_assoc(mysqli_query($db, "select confid,confvalue from configs where confname=\"$setting_name\""));
$confid = $confinfo["confid"];
$confvalue = $confinfo["confvalue"];
$custqry = mysqli_query($db, "select customconfvalue from customs where customconfnum=\"$confid\" and customtech=\"$tech_id\"");
if (mysqli_num_rows($custqry)) {
if ($setting_value == $confvalue) {
mysqli_query($db,"delete from customs where customtech=\"$tech_id\" and customconfnum=\"$confid\"");
mysqli_query($db, "delete from customs where customtech=\"$tech_id\" and customconfnum=\"$confid\"");
}
$custvalue=mysqli_fetch_row($custqry)[0];
$custvalue = mysqli_fetch_row($custqry)[0];
if ($custvalue != $setting_value) {
mysqli_query($db,"update customs set customconfvalue=\"$setting_value\" where customconfnum=\"$confid\" and customtech=\"$tech_id\"");
mysqli_query($db, "update customs set customconfvalue=\"$setting_value\" where customconfnum=\"$confid\" and customtech=\"$tech_id\"");
}
} else {
mysqli_query($db,"insert into customs(customtech,customconfnum,customconfvalue) values(\"$tech_id\",\"$confid\",\"$setting_value\")");
mysqli_query($db, "insert into customs(customtech,customconfnum,customconfvalue) values(\"$tech_id\",\"$confid\",\"$setting_value\")");
}
}
function islink($il_note) {
function islink($il_note)
{
// takes a noteid number as an argument
// determines if the argument is a link in a reference chain
// returns 1 if note is a link, 0 if not
global $db;
$refqry=mysqli_query($db,"select id from reflinks where noteid is not null and (noteid='$il_note' or target='$il_note')");
$refqry = mysqli_query($db, "select id from reflinks where noteid is not null and (noteid='$il_note' or target='$il_note')");
if (mysqli_num_rows($refqry)) {
return 1;
} else {
@@ -651,97 +663,101 @@ function islink($il_note) {
}
function generate_chain($chainlink) {
function generate_chain($chainlink)
{
// generate a reference chain
// takes a single parameter, a noteid
// finds all notes that are members of a chain containing the supplied noteid
// returns a sorted array (chainarray) of all notes in chain
global $db;
// create notes and refs arrays from the reflinks table
$notes=[];
$targets=[];
$linkqry=mysqli_query($db,"select noteid,target from reflinks where noteid is not null");
while ($link=mysqli_fetch_assoc($linkqry)) {
$notes[]=$link['noteid'];
$targets[]=$link['target'];
$notes = [];
$targets = [];
$linkqry = mysqli_query($db, "select noteid,target from reflinks where noteid is not null");
while ($link = mysqli_fetch_assoc($linkqry)) {
$notes[] = $link['noteid'];
$targets[] = $link['target'];
}
$chainarray=array(); // create the chainarray
$chainarray[]=$chainlink; // add the incoming noteid for which the chain should be generated
$captr=0; // chainarray pointer
while($captr<count($chainarray)) { // as long as the chainarray is growing
$nptr=0; // note pointer
$chainarray = array(); // create the chainarray
$chainarray[] = $chainlink; // add the incoming noteid for which the chain should be generated
$captr = 0; // chainarray pointer
while ($captr < count($chainarray)) { // as long as the chainarray is growing
$nptr = 0; // note pointer
// run through the notes array, adding all targets for this note to the chainarray
while($nptr<count($notes)) {
if(($notes[$nptr]==$chainarray[$captr]) && ( ! in_array($targets[$nptr],$chainarray))) {
$chainarray[]=$targets[$nptr];
while ($nptr < count($notes)) {
if (($notes[$nptr] == $chainarray[$captr]) && (! in_array($targets[$nptr], $chainarray))) {
$chainarray[] = $targets[$nptr];
}
$nptr=$nptr+1;
$nptr = $nptr + 1;
}
// run through the targets array, adding all notes for this target to the chainarray
$tptr=0; //target pointer
while($tptr<count($targets)) {
if(($targets[$tptr]==$chainarray[$captr]) && ( ! in_array($notes[$tptr],$chainarray))) {
$chainarray[]=$notes[$tptr];
$tptr = 0; //target pointer
while ($tptr < count($targets)) {
if (($targets[$tptr] == $chainarray[$captr]) && (! in_array($notes[$tptr], $chainarray))) {
$chainarray[] = $notes[$tptr];
}
$tptr=$tptr+1;
$tptr = $tptr + 1;
}
$captr=$captr+1;
$captr = $captr + 1;
}
// sort and return the output array
sort($chainarray);
return($chainarray);
return ($chainarray);
}
function convertweblinks($rawstring) {
function convertweblinks($rawstring)
{
// takes a string, finds urls, and returns the string with urls converted to clickable links
$urlchunksize=URL_CHUNK_SIZE;
$urlchunksize = URL_CHUNK_SIZE;
// define regex pattern for urls
$urlpatt="/<weblink\b[^>]*>(.*?)<\/weblink>/";
preg_match_all($urlpatt,$rawstring,$weblinks, PREG_SET_ORDER);
$urlpatt = "/<weblink\b[^>]*>(.*?)<\/weblink>/";
preg_match_all($urlpatt, $rawstring, $weblinks, PREG_SET_ORDER);
foreach ($weblinks as $urlblock) {
// split up really long url
$spliturl=str_split($urlblock[1],$urlchunksize);
$spliturl = str_split($urlblock[1], $urlchunksize);
unset($urlstack);
foreach ($spliturl as $urlchunk) {
$urlstack[]="<a href=\"$urlblock[1]\" target=\"_blank\">$urlchunk</a>";
$urlstack[] = "<a href=\"$urlblock[1]\" target=\"_blank\">$urlchunk</a>";
}
$hyperlink=implode("<br>",$urlstack);
$rawstring=str_replace($urlblock[0],$hyperlink,$rawstring);
$hyperlink = implode("<br>", $urlstack);
$rawstring = str_replace($urlblock[0], $hyperlink, $rawstring);
}
return $rawstring;
}
function showlinklist($print) {
function showlinklist($print)
{
global $db;
$linkresult=mysqli_query($db,"select linkid from links where status=\"1\"");
$linkresult = mysqli_query($db, "select linkid from links where status=\"1\"");
if (mysqli_num_rows($linkresult) && !$print) {
echo "
<b>Links</b><br>
";
$link=mysqli_query($db,"select displaytxt,urltxt from links where status=\"1\" order by linkpriority asc");
$link = mysqli_query($db, "select displaytxt,urltxt from links where status=\"1\" order by linkpriority asc");
while ($linkrow = mysqli_fetch_row($link)) {
printf("<a href=\"%s\">%s</a><br>",$linkrow[1],$linkrow[0]);
printf("<a href=\"%s\">%s</a><br>", $linkrow[1], $linkrow[0]);
}
}
}
function nag($tech_id) {
function nag($tech_id)
{
// nags the user if something is pending
global $db, $today;
// maintenance forms
$mfpending=mysqli_num_rows(mysqli_query($db,"select maintformid from maintforms where mftech=\"$tech_id\" and pending=1"));
$mfpending = mysqli_num_rows(mysqli_query($db, "select maintformid from maintforms where mftech=\"$tech_id\" and pending=1"));
if ($mfpending) {
echo "<font color=\"#FF0000\">NOTICE</font>: You have one or more maintenance forms to complete. <a href=\"maintform.php\">Click here to complete them</a>.<br><hr>";
}
// scheduled maintenance events
$ucevents=get_upcoming_events();
$due=false;
$overdue=false;
$ucevents = get_upcoming_events();
$due = false;
$overdue = false;
foreach ($ucevents as $event) {
if ($event['duedate'] == $today) $due=true;
if ($event['duedate'] < $today) $overdue=true;
if ($event['duedate'] == $today) $due = true;
if ($event['duedate'] < $today) $overdue = true;
}
if ($due) {
echo "<font color=\"#FF0000\">NOTICE</font>: One or more scheduled maintenance events are due today. <a href=\"schedmaint.php\">Click here to view them</a>.<br><hr>";
@@ -751,7 +767,8 @@ function nag($tech_id) {
}
}
function get_part_data($partinputdata) {
function get_part_data($partinputdata)
{
// given an associative array of partid, uid, partnum, sernum,
// return an associative array of
// partid, uid, partnum, sernum, partname, result
@@ -797,131 +814,133 @@ function get_part_data($partinputdata) {
// not enough input data supplied, so return result of 1
$result = 1;
}
if (! $result) {
if (! $result) {
if (mysqli_num_rows($partqry)) {
$partdata=mysqli_fetch_assoc($partqry);
$partdata = mysqli_fetch_assoc($partqry);
} else {
$result=1;
$result = 1;
}
}
// detect mismatched input data
if ($checkmm) {
if (mysqli_num_rows($mismatchqry)) {
$result=2;
$result = 2;
}
}
if ($result) {
$partdata=array();
$partdata['result']=$result;
$partdata = array();
$partdata['result'] = $result;
} else {
$partdata['result']=0;
$partdata['result'] = 0;
}
return $partdata;
}
function get_upcoming_events() {
function get_upcoming_events()
{
// build array of upcoming events
// takes no arguments
// returns an array containing arrays of upcoming event data
global $db, $today;
$uceventsqry=mysqli_query($db,"select * from events where active_flag=\"1\" and (deferred_flag=\"0\" or (deferred_flag=\"1\" and deferred_date <= \"$today\"))");
$ucevents=array();
while ($uceventrow=mysqli_fetch_assoc($uceventsqry)) {
$uceventsqry = mysqli_query($db, "select * from events where active_flag=\"1\" and (deferred_flag=\"0\" or (deferred_flag=\"1\" and deferred_date <= \"$today\"))");
$ucevents = array();
while ($uceventrow = mysqli_fetch_assoc($uceventsqry)) {
// provide eventid,task,device,start_date,last_date,deferred_flag,deferred_date,active_flag
extract($uceventrow,EXTR_PREFIX_ALL,"eventdata");
extract($uceventrow, EXTR_PREFIX_ALL, "eventdata");
// provide deviceid,devicename,devicedesc,group_flag,active_flag
$devicedata=mysqli_fetch_assoc(mysqli_query($db,"select * from devices where deviceid=\"$eventdata_device\""));
extract($devicedata,EXTR_PREFIX_ALL,"devicedata");
$devicedata = mysqli_fetch_assoc(mysqli_query($db, "select * from devices where deviceid=\"$eventdata_device\""));
extract($devicedata, EXTR_PREFIX_ALL, "devicedata");
// provide taskid,taskname,taskdesc,frequency,period,weekdays_only,nextdue_relative,refdoc_name,refdoc_url,active_flag
$taskdata=mysqli_fetch_assoc(mysqli_query($db,"select * from tasks where taskid=\"$eventdata_task\""));
extract($taskdata,EXTR_PREFIX_ALL,"taskdata");
if ( ! ($taskdata_period == "once" && $eventdata_last_date >= $eventdata_start_date)) { // ignore completed one-time events
$start=date_create($eventdata_start_date); // create start date object
if ($eventdata_last_date=="0000-00-00") { // event has never been done. last date object will be start date object
$lastdatestrg="never";
$last=$start;
$taskdata = mysqli_fetch_assoc(mysqli_query($db, "select * from tasks where taskid=\"$eventdata_task\""));
extract($taskdata, EXTR_PREFIX_ALL, "taskdata");
if (! ($taskdata_period == "once" && $eventdata_last_date >= $eventdata_start_date)) { // ignore completed one-time events
$start = date_create($eventdata_start_date); // create start date object
if ($eventdata_last_date == "0000-00-00") { // event has never been done. last date object will be start date object
$lastdatestrg = "never";
$last = $start;
} else { // create last date object
$lastdatestrg="$eventdata_last_date";
$last=date_create($eventdata_last_date);
$lastdatestrg = "$eventdata_last_date";
$last = date_create($eventdata_last_date);
}
if ($taskdata_period=="once") { // nextdue object will be start date object
$nextdue=$start;
if ($taskdata_period == "once") { // nextdue object will be start date object
$nextdue = $start;
} else { // determine nextdue object from last date object (relative) or interval from start date object (absolute)
if ($lastdatestrg=="never") { // event has been scheduled to start today but has not been completed
$nextdue=$start;
} else if ($last==$start) { // event was completed for the first time on the start date
$nextdue=$start;
if ($lastdatestrg == "never") { // event has been scheduled to start today but has not been completed
$nextdue = $start;
} else if ($last == $start) { // event was completed for the first time on the start date
$nextdue = $start;
date_add($nextdue, date_interval_create_from_date_string("$taskdata_frequency $taskdata_period"));
} else {
if ($taskdata_nextdue_relative) { // calculate from day of last done date
$nextdue=$last;
$nextdue = $last;
date_add($nextdue, date_interval_create_from_date_string("$taskdata_frequency $taskdata_period"));
} else { // calculate from day of start date
$nextdue=$start;
$testdate=date_create("1970-01-01");
$nextdue = $start;
$testdate = date_create("1970-01-01");
while ($testdate <= $last) {
date_add($nextdue, date_interval_create_from_date_string("$taskdata_frequency $taskdata_period"));
$testdate=$nextdue;
$testdate = $nextdue;
}
}
}
}
if ($taskdata_weekdays_only) { // move forward off the weekend if required
$nextduedow=date("w",date_timestamp_get($nextdue));
if ($nextduedow==0) { // due on a Sunday
$nextduedow = date("w", date_timestamp_get($nextdue));
if ($nextduedow == 0) { // due on a Sunday
date_add($nextdue, date_interval_create_from_date_string("1 days"));
}
if ($nextduedow==6) { // due on a Saturday
if ($nextduedow == 6) { // due on a Saturday
date_add($nextdue, date_interval_create_from_date_string("2 days"));
}
}
$duedate=date_format($nextdue, 'Y-m-d');
$daysaway=date_diff(date_create($today),$nextdue)->format('%a');
$direction=date_diff(date_create($today),$nextdue)->format('%R');
if ($direction=="+") {
$duedate = date_format($nextdue, 'Y-m-d');
$daysaway = date_diff(date_create($today), $nextdue)->format('%a');
$direction = date_diff(date_create($today), $nextdue)->format('%R');
if ($direction == "+") {
if ($daysaway == 0) {
$duedatestrg="<font color=\"#FF0000\"> $duedate </font>";
$duedatestrg = "<font color=\"#FF0000\"> $duedate </font>";
} else if ($daysaway < 4) {
$duedatestrg="<font color=\"#FFFF00\"> $duedate </font>";
$duedatestrg = "<font color=\"#FFFF00\"> $duedate </font>";
} else {
$duedatestrg="<font color=\"#00FF00\"> $duedate </font>";
$duedatestrg = "<font color=\"#00FF00\"> $duedate </font>";
}
} else {
$duedatestrg="<font size=\"+1\" color=\"#FF0000\"><b> $duedate </b></font><img src=\"icons/exclamation-red.png\" border=\"0\">";
$duedatestrg = "<font size=\"+1\" color=\"#FF0000\"><b> $duedate </b></font><img src=\"icons/exclamation-red.png\" border=\"0\">";
}
$uceventline=array(
'eventdata_eventid'=>$eventdata_eventid,
'duedate'=>$duedate,
'duedatestrg'=>$duedatestrg,
'devicedata_devicedesc'=>$devicedata_devicedesc,
'devicedata_devicename'=>$devicedata_devicename,
'taskdata_taskdesc'=>$taskdata_taskdesc,
'taskdata_taskname'=>$taskdata_taskname,
'lastdatestrg'=>$lastdatestrg
$uceventline = array(
'eventdata_eventid' => $eventdata_eventid,
'duedate' => $duedate,
'duedatestrg' => $duedatestrg,
'devicedata_devicedesc' => $devicedata_devicedesc,
'devicedata_devicename' => $devicedata_devicename,
'taskdata_taskdesc' => $taskdata_taskdesc,
'taskdata_taskname' => $taskdata_taskname,
'lastdatestrg' => $lastdatestrg
);
$ucevents[]=$uceventline;
$ucevents[] = $uceventline;
}
}
return $ucevents;
}
function format_message($msgtype,$msgtxt) {
function format_message($msgtype, $msgtxt)
{
// displays a formatted message
// $msgtype is 0 for success or anything else for failure
// $msgtxt is the string to display
if ($msgtype == 0) {
$state="ui-state-highlight";
$icon="ui-icon-info";
$state = "ui-state-highlight";
$icon = "ui-icon-info";
} else {
$state="ui-state-error";
$icon="ui-icon-alert";
$state = "ui-state-error";
$icon = "ui-icon-alert";
}
if ($msgtxt == "") $msgtxt="PROGRAM ERROR: No message text was supplied.";
if ($msgtxt == "") $msgtxt = "PROGRAM ERROR: No message text was supplied.";
echo "
<div class=\"$state ui-corner-all\" style=\"margin-top: 20px; padding: 0 .7em;\">
<p><span class=\"ui-icon $icon\" style=\"float: left; margin-right: .3em;\"></span>
@@ -930,7 +949,8 @@ function format_message($msgtype,$msgtxt) {
";
}
function templateselect($techid,$operation) {
function templateselect($techid, $operation)
{
// Displays a line enabling selection of a user or global template
// $techid is the id number of the current tech
// $operation is one of "add" "edit" "delete"
@@ -947,10 +967,10 @@ function templateselect($techid,$operation) {
<td>
<select name=\"usertemplateid\" title=\"Select the user template you'd like to load and click the Load Template button. User template selection takes precedence.\">
";
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"$techid\" order by templatename asc");
printf("<option value=\"%s\" selected>%s</option>","0","Select user template");
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
$templaterow = mysqli_query($db, "select * from notetemplates where tech=\"$techid\" order by templatename asc");
printf("<option value=\"%s\" selected>%s</option>", "0", "Select user template");
while ($templateitem = mysqli_fetch_assoc($templaterow)) {
printf("<option value=\"%s\">%s</option>", $templateitem["templateid"], $templateitem["templatename"]);
}
echo "
</select>&nbsp;or&nbsp;
@@ -959,10 +979,10 @@ function templateselect($techid,$operation) {
echo "
<select name=\"globaltemplateid\" title=\"Select the global template you'd like to load and click the Load Template button. User template selection takes precedence.\">
";
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"0\" order by templatename asc");
printf("<option value=\"%s\" selected>%s</option>","0","Select global template");
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
$templaterow = mysqli_query($db, "select * from notetemplates where tech=\"0\" order by templatename asc");
printf("<option value=\"%s\" selected>%s</option>", "0", "Select global template");
while ($templateitem = mysqli_fetch_assoc($templaterow)) {
printf("<option value=\"%s\">%s</option>", $templateitem["templateid"], $templateitem["templatename"]);
}
echo "
</select>&nbsp;&nbsp;
@@ -980,4 +1000,3 @@ function templateselect($techid,$operation) {
</form>
";
}
?>