Could not find the db.php file required for this installation. "; exit(); } include("db.php"); 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" ); // Generic functions function framework($option, $htmltitle, $pagetitle, $print) { // generates html code for the beginning and end of all pages 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; } else { $bgcolor = BACKGROUND_COLOR; $textcolor = TEXT_COLOR; $linkcolor = LINK_COLOR; $vlinkcolor = VLINK_COLOR; $hdgcolor = HEADING_COLOR; } echo " $htmltitle "; echo " "; if ($htmltitle || $pagetitle) { echo " $htmltitle - $pagetitle
"; } } else if ($option == "end") { // generates everything from the last horiz rule down to end of page echo "


"; if (defined("FOOTER_MESSAGE")) { $footer_msg = FOOTER_MESSAGE; echo "
$footer_msg

"; } echo " "; } else { echo "
Invalid option \"$option\" passed to framework(). Valid options are \"begin\" and \"end\".
"; exit(1); } } function pagetable($option) { if ($option == "begin") { echo "
"; } else if ($option == "end") { echo "
"; } else { echo "
Invalid option \"$option\" passed to pagetable(). Valid options are \"begin\" and \"end\".
"; exit(1); } } function pageblock($block, $option) { global $sbcolor; if ($block == "left") { if ($option == "begin") { echo " "; } else if ($option == "end") { echo " "; } else { echo "
Invalid option \"$option\" passed to pageblock(). Valid options are \"begin\" and \"end\".
"; exit(1); } } else if ($block == "right") { if ($option == "begin") { echo " "; } else if ($option == "end") { echo " "; } else { echo "
Invalid option \"$option\" passed to pageblock(). Valid options are \"begin\" and \"end\".
"; exit(1); } } else { echo "
Invalid block \"$block\" passed to pageblock(). Valid blocks are \"left\" and \"right\".
"; exit(1); } } function sidemenu($noprint = false) { // Displays sidebar menu global $db, $mbgcolor, $noprint; $doparts = PARTS_FUNCTIONS; $doschedmaint = SCHEDMAINT_FUNCTIONS; echo "

Logbook
Add Logbook Entry
Search Logbook

"; if ($doparts) { echo "
Maintenance Forms
New Maintenance Form
Search Maintenance Forms

Parts
Add New Part
Search Parts

"; } if ($doschedmaint) { echo "
Scheduled Maintenance

"; } echo "
Administration
My Profile
Manage Templates
"; if (!isset($_SESSION['login'])) { echo "
Log In
"; } else { $loginid = $_SESSION['login']; $loggedinas = mysqli_fetch_row(mysqli_query($db, "select techname from techs where techid=\"$loginid\""))[0]; echo "
Logged in as $loggedinas
Log Out
"; } if (!$noprint) { echo "

"; } echo "
About
"; } function banner($print) { // displays a banner global $db; $bannerid = BANNER; // get banner parameters from banner table $banrow = mysqli_fetch_assoc(mysqli_query($db, "select * from banners where bannerid=\"$bannerid\"")); if (!$banrow) { $bannerid = 1; } else { $bannertext = $banrow["bannername"]; if ($print) { $bannercolor = "#FFFFFF"; $bannertxtcolor = "#000000"; } else { $bannercolor = $banrow["bannercolor"]; $bannertxtcolor = $banrow["textcolor"]; } } if ($bannerid != 1) { echo "
$bannertext
"; } } 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\""); if (mysqli_num_rows($dbqry)) { $out_data = mysqli_fetch_row($dbqry)[0]; } else { $out_data = NULL; } return ($out_data); } 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; } else { $mbackyear = $year; $mbackmonth = $month - 1; } if ($month == 12) { $mfwdyear = $year + 1; $mfwdmonth = 1; } else { $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'); echo << Prev month   $MonthNames[$MonthToShow]   Next month
Prev year   $YearToShow   Next year Sun Mon Tue Wed Thu Fri Sat EOT; $FirstDayOfWeek = date(l, mktime(0, 0, 0, $MonthToShow, 1, $YearToShow)); switch ($FirstDayOfWeek) { case 'Monday': $offset = 1; break; case 'Tuesday': $offset = 2; break; case 'Wednesday': $offset = 3; break; case 'Thursday': $offset = 4; break; case 'Friday': $offset = 5; break; case 'Saturday': $offset = 6; break; default: $offset = 0; } if ($offset > 0) { print "\n"; echo str_repeat(" \n", $offset); } for ($i = 1; $i <= $NumberOfDays; $i++) { $DayOfWeek = date(l, mktime(0, 0, 0, $MonthToShow, $i, $YearToShow)); if ($DayOfWeek == 'Sunday') { print "\n"; } if ($i != $DayToShow) { print "$i\n"; } else { print "$i\n"; } if ($DayOfWeek == 'Saturday') { print "\n"; } } if ((($offset == 5) && ($NumberOfDays > 30)) || (($offset == 6) && ($NumberOfDays > 29))) { if (42 - $NumberOfDays - $offset > 0) { echo str_repeat(" \n", 42 - $NumberOfDays - $offset); } print "\n"; } elseif (($NumberOfDays != 28) || ($offset > 0)) { if (35 - $NumberOfDays - $offset > 0) { echo str_repeat(" \n", 35 - $NumberOfDays - $offset); print "\n"; } } print "\n"; } function colorpicker($baseurl) { // takes a standard url and tacks the color number on to the end of it // giving a palette of links echo " \"#330033\" \"#330099\" \"#000066\" \"#003333\" \"#003300\" \"#333300\" \"#663333\" \"#663300\" \"#330000\" \"#000000\" \"#663366\" \"#333399\" \"#000099\" \"#336666\" \"#006600\" \"#666600\" \"#996633\" \"#993300\" \"#660000\" \"#333333\" \"#993399\" \"#6600CC\" \"#3333FF\" \"#339999\" \"#009900\" \"#999900\" \"#CC9933\" \"#CC6600\" \"#990000\" \"#666666\" \"#CC33CC\" \"#6633FF\" \"#3366FF\" \"#00CCCC\" \"#33CC00\" \"#FFCC00\" \"#FFCC33\" \"#FF6600\" \"#CC0000\" \"#999999\" \"#CC66CC\" \"#6666CC\" \"#33CCFF\" \"#66CCCC\" \"#33FF33\" \"#FFFF00\" \"#FFCC66\" \"#FF9900\" \"#FF0000\" \"#C0C0C0\" \"#FF99FF\" \"#9999FF\" \"#66FFFF\" \"#33FFFF\" \"#66FF99\" \"#FFFF33\" \"#FFFF66\" \"#FF9966\" \"#FF6666\" \"#CCCCCC\" \"#FFCCFF\" \"#CCCCFF\" \"#CCFFFF\" \"#99FFFF\" \"#99FF99\" \"#FFFFCC\" \"#FFFF99\" \"#FFCC99\" \"#FFCCCC\" \"#FFFFFF\" "; } // Project functions 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\""); if (mysqli_num_rows($custqry)) { $custvalue = mysqli_fetch_row($custqry)[0]; } // if value in custom table, use it if (mysqli_num_rows($custqry)) { $retvalue = $custvalue; $table = "customs"; } else { $retvalue = $confvalue; $table = "configs"; } $result = array('value' => $retvalue, 'table' => $table, 'id' => $confid); return $result; } 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\""); if (mysqli_num_rows($custqry)) { if ($setting_value == $confvalue) { mysqli_query($db, "delete from customs where customtech=\"$tech_id\" and customconfnum=\"$confid\""); } $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\""); } } else { mysqli_query($db, "insert into customs(customtech,customconfnum,customconfvalue) values(\"$tech_id\",\"$confid\",\"$setting_value\")"); } } 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')"); if (mysqli_num_rows($refqry)) { return 1; } else { return 0; } } 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']; } $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]; } $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 = $tptr + 1; } $captr = $captr + 1; } // sort and return the output array sort($chainarray); return ($chainarray); } function convertweblinks($rawstring) { // takes a string, finds urls, and returns the string with urls converted to clickable links $urlchunksize = URL_CHUNK_SIZE; // define regex pattern for urls $urlpatt = "/]*>(.*?)<\/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); unset($urlstack); foreach ($spliturl as $urlchunk) { $urlstack[] = "$urlchunk"; } $hyperlink = implode("
", $urlstack); $rawstring = str_replace($urlblock[0], $hyperlink, $rawstring); } return $rawstring; } function showlinklist($print) { global $db; $linkresult = mysqli_query($db, "select linkid from links where status=\"1\""); if (mysqli_num_rows($linkresult) && !$print) { echo " Links
"; $link = mysqli_query($db, "select displaytxt,urltxt from links where status=\"1\" order by linkpriority asc"); while ($linkrow = mysqli_fetch_row($link)) { printf("%s
", $linkrow[1], $linkrow[0]); } } } 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")); if ($mfpending) { echo "NOTICE: You have one or more maintenance forms to complete. Click here to complete them.

"; } // scheduled maintenance events $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 ($due) { echo "NOTICE: One or more scheduled maintenance events are due today. Click here to view them.

"; } if ($overdue) { echo "NOTICE: One or more scheduled maintenance events are OVERDUE. Click here to view them.

"; } } 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 // where result=0 for success, 1 for no data found, 2 for mismatch global $db; $checkmm = FALSE; $result = 0; // pull input data from input array $partid = (array_key_exists('partid', $partinputdata) && $partinputdata['partid'] != "") ? $partinputdata['partid'] : NULL; $uid = (array_key_exists('uid', $partinputdata) && $partinputdata['uid'] != "") ? $partinputdata['uid'] : NULL; $partnum = (array_key_exists('partnum', $partinputdata) && $partinputdata['partnum'] != "") ? $partinputdata['partnum'] : NULL; $sernum = (array_key_exists('sernum', $partinputdata) && $partinputdata['sernum'] != "") ? $partinputdata['sernum'] : NULL; // for part data supplied, see what info is available // if a partid is supplied, pull other info from parts if ($partid) { // if partid supplied $partqry = mysqli_query($db, "select * from parts where partid=\"$partid\""); } else if ($uid && (!$partnum && !$sernum)) { // if uid only supplied $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\""); } else if (($partnum && $sernum) && !$uid) { // if pn/sn only supplied $partqry = mysqli_query($db, "select * from parts where partnum=\"$partnum\" and sernum=\"$sernum\""); } else if ($uid && $partnum && $sernum) { //if uid and pn/sn supplied $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\" and partnum=\"$partnum\" and sernum=\"$sernum\""); $checkmm = TRUE; $mismatchqry = mysqli_query($db, "select * from parts where (uid like \"$uid\" and ((partnum !=\"$partnum\" and partnum !=\"\")or (sernum !=\"$sernum\" and sernum !=\"\"))) or ((uid not like \"$uid\" and uid not like \"\") and (partnum =\"$partnum\" and sernum =\"$sernum\")) "); } else if ($uid && $partnum && ! $sernum) { //if uid and pn only supplied $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\" and partnum=\"$partnum\""); $checkmm = TRUE; $mismatchqry = mysqli_query($db, "select partid from parts where (uid like \"$uid\" and partnum !=\"$partnum\") or (uid not like \"$uid\" and partnum =\"$partnum\") "); } else if ($uid && ! $partnum && $sernum) { //if uid and sn only supplied $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\" and sernum=\"$sernum\""); $checkmm = TRUE; $mismatchqry = mysqli_query($db, "select partid from parts where (uid like \"$uid\" and sernum !=\"$sernum\") or (uid not like \"$uid\" and sernum =\"$sernum\") "); } else { // not enough input data supplied, so return result of 1 $result = 1; } if (! $result) { if (mysqli_num_rows($partqry)) { $partdata = mysqli_fetch_assoc($partqry); } else { $result = 1; } } // detect mismatched input data if ($checkmm) { if (mysqli_num_rows($mismatchqry)) { $result = 2; } } if ($result) { $partdata = array(); $partdata['result'] = $result; } else { $partdata['result'] = 0; } return $partdata; } 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)) { // provide eventid,task,device,start_date,last_date,deferred_flag,deferred_date,active_flag 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"); // 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; } else { // create last date object $lastdatestrg = "$eventdata_last_date"; $last = date_create($eventdata_last_date); } 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; 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; 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"); while ($testdate <= $last) { date_add($nextdue, date_interval_create_from_date_string("$taskdata_frequency $taskdata_period")); $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 date_add($nextdue, date_interval_create_from_date_string("1 days")); } 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 == "+") { if ($daysaway == 0) { $duedatestrg = " $duedate "; } else if ($daysaway < 4) { $duedatestrg = " $duedate "; } else { $duedatestrg = " $duedate "; } } else { $duedatestrg = " $duedate "; } $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; } } return $ucevents; } 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"; } else { $state = "ui-state-error"; $icon = "ui-icon-alert"; } if ($msgtxt == "") $msgtxt = "PROGRAM ERROR: No message text was supplied."; echo "

$msgtxt



"; } 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" or NULL global $db; $isadmin = dblookup($db, "techs", "techid", "admin", $techid); echo "
"; // generate template selection line echo " "; // list user templates echo "
 or  "; // list global templates echo "    "; // show load button echo " Manage templates

"; } function fix_date($datestring) { // accepts a string as an argument // returns a valid date string in the format YYYY-MM-DD // if input string is not a valid date, return the current date global $db, $today; if (!$datestring) $datestring = $today; $datepatt = '/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/'; if (!preg_match($datepatt, $datestring)) $datestring = $today; $datestring = mysqli_real_escape_string($db, $datestring); return $datestring; } function fix_time($timestring) { // accepts a string as an argument // returns a valid time string in the format HH:MM:SS // if input string is not a valid time, return the current time global $db, $now; if (!$timestring) $timestring = $now; $timepatt = '/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/'; if (!preg_match($timepatt, $timestring)) $timestring = $now; $timestring = mysqli_real_escape_string($db, $timestring); return $timestring; }