Rev 85 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
/*
* Revision History:
* 20161217 RWR
* Added cleanLineReturn, removeBlanLines and getDOMUDOM0
*/
include_once( './maintenance_database.php' );
include_once( './database.php' );
/* function will take all eoln ("\n") and convert to <br /> if $makeHTML
* is true, otherwise will replace all <br /> with \n.
* Will then remove duplicates IF THEY ARE EXACTLY NEXT TO EACH OTHER
* ie, with no intervening spaces.
*/
function cleanLineReturn ( $subject, $makeHTML = false ) {
if ( $makeHTML ) {
$search = "\n";
$replace = "<br />";
} else {
$search = "<br />";
$replace = "\n";
}
$subject = str_replace ( $search, $replace, $subject );
return str_replace ( $replace . $replace, $replace, $subject );
} // cleanLineReturn
function removeBlankLines( $subject, $eoln = "\n" ) {
return preg_replace( '/^[ \t]*[\r\n]+/m', '', $subject );
}
function postMaintenance($device = '', $task = '', $notes = '', $technician = '', $date = '') {
if ( $device ) { # parameters are being passed directly in
$sql = 'insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id) values (' .
implode( ',',
array(
makeSafeSQLValue($device, 'I'),
makeSafeSQLValue( $task, 'I'),
makeSafeSQLValue($date, 'I'),
makeSafeSQLValue($notes),
makeSafeSQLValue($technician, 'I')
)
) . ')';
queryDatabaseExtended( $sql );
//print "<pre>$sql</pre>";
} else {
foreach ( $_POST as $parameter => $value ) {
if ( preg_match( '/performed_(\d+)/', $parameter, $id ) ) { // this is the checkbox
if ( $value ) { // and it has a value
$id = $id[1];
$sql = array( 'select device_id', 'maintenance_task_id',$_POST["datedone_$id"],makeSafeSQLValue($_POST["notes_$id"],'S'),$_POST["technician_$id"]);
$sql = implode (',', $sql );
$sql = 'insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id) ' . $sql .
" from maintenance_schedule where maintenance_schedule_id = $id";
queryDatabaseExtended( $sql );
//print "<pre>$sql</pre>";
}
}
}
}
}
function getSoftwareVersions ( $currentOnly = true, $softwareID = '',$computerID='' ) {
$whereClause = array();
if ( $currentOnly ) {
$whereClause[] = 'installed_packages.removed_date is null';
}
if ( $softwareID ) {
$whereClause[] = "package_name like '%$softwareID%'";
}
print '<pre>' . implode( ' and ', $whereClause ) . '</pre>';
return array($sql, implode ( ' and ', $whereClause ), ' order by ');
}
function EditMaintenanceRecord( $id ) {
global $DATABASE_DEFINITION;
print $id == -1 ? addData( $DATABASE_DEFINITION['maintenance_schedule'] ) : editData( $DATABASE_DEFINITION['maintenance_schedule'], $id );
}
function postChanges( $id = '' ) {
global $DATABASE_DEFINITION;
if ($id) {
updateData( $DATABASE_DEFINITION['maintenance_schedule'], $id );
} else {
$result = insertData( $DATABASE_DEFINITION['maintenance_schedule'] );
// There MUST be a record in maintenance_performed or this is not visible
$id = $result['insert_id'];
$sql = "insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id)
select device_id,maintenance_task_id,added_date,'Added to System',login_id
from maintenance_schedule
where maintenance_schedule_id = $id";
doSQL($sql);
}
}
/*
* Determine if the machine is a DOMU or a DOM0 (it can not be both, obviously)
* If it is a DOMU, return the DOM0 name
* If it is a DOM0, return an array containing all DOMU's on it
*/
function getDOMUDOM0 ( $id = '' ) {
if ( $id ) {
// first, get See if it is a DOMU (ie, it has a "part_of" that is not null)
$query = "select
DOM0.device_id id,
DOM0.name name
from
device DOMU join device DOM0
where
DOMU.part_of = DOM0.device_id
and DOMU.removed_date is null
and DOMU.device_id = $id";
$results = queryDatabaseExtended( $query );
if ( $results['count'] == 1 ) { // can not have more than 1
return array(
'name' => $results['data'][0]['name'],
'id' => $results['data'][0]['id']
);
} else {
// see if it is a DOM0
$query = "select
device.name name,
device.device_id id
from
device join device_type using (device_type_id)
where
device.removed_date is null
and device_type.show_as_system = 'Y'
and device.part_of = $id";
$results = queryDatabaseExtended( $query );
if ( $results['count'] ) {
$returnValue = array();
$results = $results['data'];
foreach ( $results as $entry ) {
$returnValue[] = array( 'name' => $entry['name'],
'id' => $entry['id']
);
}
return $returnValue;
} // if we are a dom0
} // if..else
} // if id
return null;
} // function getDOMUDOM0
?>