From a55f61d313b05ed856e76354d2d47fef71e75e2a Mon Sep 17 00:00:00 2001 From: Markus Gerstel Date: Wed, 4 Feb 2015 22:59:56 +0000 Subject: [PATCH] frontend code Yes, yes, all quite horrible. However it works, which is the important bit. You don't generally get a PhD for nicely written code. --- frontend/dropjob.php | 19 +++++ frontend/index.php | 122 ++++++++++++++++++++++++++++++ frontend/indexall.php | 117 +++++++++++++++++++++++++++++ frontend/newjob.php | 36 +++++++++ frontend/prepare.php | 73 ++++++++++++++++++ frontend/showjob.php | 167 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 534 insertions(+) create mode 100644 frontend/dropjob.php create mode 100644 frontend/index.php create mode 100644 frontend/indexall.php create mode 100644 frontend/newjob.php create mode 100644 frontend/prepare.php create mode 100644 frontend/showjob.php diff --git a/frontend/dropjob.php b/frontend/dropjob.php new file mode 100644 index 0000000..cb45e26 --- /dev/null +++ b/frontend/dropjob.php @@ -0,0 +1,19 @@ + diff --git a/frontend/index.php b/frontend/index.php new file mode 100644 index 0000000..4576ed1 --- /dev/null +++ b/frontend/index.php @@ -0,0 +1,122 @@ + +MySQL-RMySQL-R + + + + 315360000, + 'year' => 31536000, + 'month' => 2628000, + 'week' => 604800, + 'day' => 86400, + 'hour' => 3600, + 'minute' => 60, + 'second' => 1); + if ($difference < 20) { // less than 5 seconds ago, let's say "just now" + $retval = " just now"; + return $retval; + } else { + $retval = ''; + foreach ($periods as $key => $value) { + if ($difference >= $value) { + $time = floor($difference/$value); + $difference %= $value; + $retval .= ($retval ? ' ' : '').$time.' '; + $retval .= (($time > 1) ? $key.'s' : $key); + $granularity--; + } + if ($granularity == '0') { break; } + } + return ' '.$retval.' ago'; + } +} + + +while ($row = mysql_fetch_assoc($result)) { + + print '
'; + print '#'.$row['ID'].''.htmlentities($row['Name']).''. $row['Status'] .', '. time_ago($row['LastChange']). ''; + print '
'; + print 'view'; + print 'copy'; + print 'delete'; + print '
'; + print '
'; + + if (trim($row['Result']) != '') { + print 'Output:
'; + print '
';
+  print htmlentities($row['Result']);
+  print '
'; + } + + $sql2 = 'SELECT ID FROM results WHERE JobID = ' . $row['ID'] . ' LIMIT 16'; + $result2 = mysql_query($sql2); + if (!$result2) { echo "Could not select results" . mysql_error(); exit; } + if (mysql_num_rows($result2) > 0) { + print '
'; + while ($resrow = mysql_fetch_assoc($result2)) { + print '
'; + print ''; + print '
'; + } + print '
'; + } + print '
'; + + mysql_free_result($result2); +} + +mysql_free_result($result); + +?> + diff --git a/frontend/indexall.php b/frontend/indexall.php new file mode 100644 index 0000000..ffb7d98 --- /dev/null +++ b/frontend/indexall.php @@ -0,0 +1,117 @@ + +MySQL-RMySQL-R + + + + 315360000, + 'year' => 31536000, + 'month' => 2628000, + 'week' => 604800, + 'day' => 86400, + 'hour' => 3600, + 'minute' => 60, + 'second' => 1); + if ($difference < 20) { // less than 5 seconds ago, let's say "just now" + $retval = " just now"; + return $retval; + } else { + $retval = ''; + foreach ($periods as $key => $value) { + if ($difference >= $value) { + $time = floor($difference/$value); + $difference %= $value; + $retval .= ($retval ? ' ' : '').$time.' '; + $retval .= (($time > 1) ? $key.'s' : $key); + $granularity--; + } + if ($granularity == '0') { break; } + } + return ' '.$retval.' ago'; + } +} + + +while ($row = mysql_fetch_assoc($result)) { + + print '
'; + print '#'.$row['ID'].''.htmlentities($row['Name']).''. $row['Status'] .', '. time_ago($row['LastChange']). ''; + print '
'; + print 'view'; + print 'copy'; + print 'delete'; + print '
'; + print '
'; + + if (trim($row['Result']) != '') { + print 'Output:
'; + print '
';
+  print htmlentities($row['Result']);
+  print '
'; + } + + $sql2 = 'SELECT ID FROM results WHERE JobID = ' . $row['ID'] . ' LIMIT 16'; + $result2 = mysql_query($sql2); + if (!$result2) { echo "Could not select results" . mysql_error(); exit; } + if (mysql_num_rows($result2) > 0) { + print '
'; + while ($resrow = mysql_fetch_assoc($result2)) { + print '
'; + print ''; + print '
'; + } + print '
'; + } + print '
'; + + mysql_free_result($result2); +} + +mysql_free_result($result); + +?> + diff --git a/frontend/newjob.php b/frontend/newjob.php new file mode 100644 index 0000000..1d9cc7b --- /dev/null +++ b/frontend/newjob.php @@ -0,0 +1,36 @@ + 0) { + $link = mysql_connect('127.0.0.1', 'Rbatch', 'Rbatch'); + if (!$link) { echo "Unable to connect to DB: " . mysql_error(); exit; } + if (!mysql_select_db('R')) { echo "Unable to select database: " . mysql_error(); exit; } + + $query = sprintf("INSERT INTO jobs (Status, Queued, Environment, Name, Commands, Comments) VALUES ('Queued', NOW(), %d, '%s', '%s', '%s')", + $envir, + mysql_real_escape_string($name), + mysql_real_escape_string($cmds), + mysql_real_escape_string($comment)); + + // Perform Query + $result = mysql_query($query); + + // Check result + // This shows the actual query sent to MySQL, and the error. Useful for debugging. + if (!$result) { + $message = 'Invalid query: ' . mysql_error() . "\n"; + $message .= 'Whole query: ' . $query; + die($message); + } + +} +header("Location: /"); +?> diff --git a/frontend/prepare.php b/frontend/prepare.php new file mode 100644 index 0000000..d398a57 --- /dev/null +++ b/frontend/prepare.php @@ -0,0 +1,73 @@ + 0) { + $sql = "SELECT Name, Environment, Commands, Comments FROM jobs WHERE ID = $id"; + $result = mysql_query($sql); + if (!$result) { echo "Could not select jobs" . mysql_error(); exit; } + if (mysql_num_rows($result) == 0) { echo "Job not found"; exit; } + $preparedata = mysql_fetch_assoc($result); + mysql_free_result($result); +} + +?> +MySQL-RMySQL-R + + + + +
+
+ Name: + Environment: +
+
+
+ +
+
+ diff --git a/frontend/showjob.php b/frontend/showjob.php new file mode 100644 index 0000000..6840fac --- /dev/null +++ b/frontend/showjob.php @@ -0,0 +1,167 @@ + +MySQL-RMySQL-R + + + +
+#'.$job['ID'].''.htmlentities($job['Name']).' – '.$job['Status'].''; + print '
'; + print 'copy'; + print 'delete'; + print '
'; + + $job['Queued'] = $job['Queued'] == '' ? '---------- --:--:--' : $job['Queued']; + $job['Started'] = $job['Started'] == '' ? '---------- --:--:--' : $job['Started']; + $job['Completed'] = $job['Completed'] == '' ? '---------- --:--:--' : $job['Completed']; + $job['RetiredDate'] = $job['RetiredDate'] == '' ? '---------- --:--:--' : $job['RetiredDate']; + +?> +
Queued:    
Started:
Completed:
Retired:
(s runtime, s queuetime)
+
';
+  print htmlentities(trim($job['Comments']));
+  print '
'; + } + + $sql2 = 'SELECT ID, FilenameInternal FROM results WHERE JobID = ' . $job['ID']; + $result2 = mysql_query($sql2); + if (!$result2) { echo "Could not select results" . mysql_error(); exit; } + if (mysql_num_rows($result2) > 0) { + print '
'; + while ($resrow = mysql_fetch_assoc($result2)) { + print '
'; + print '

'.htmlentities($resrow['FilenameInternal']).'

'; + print ''; + print '

[PDF]

'; + print '
'; + } + print '
'; + } + + mysql_free_result($result2); + + if (trim($job['Result']) != '') { + print '
';
+  print "# Output\n\n";
+  print htmlentities(trim($job['Result']));
+  print '
'; + } + + if (trim($job['EnvCmd']) != '') { + print '
';
+  print '# Environment: '. htmlentities($job['EnvName'])."\n\n";
+  print htmlentities(trim($job['EnvCmd']));
+  print '
'; + } + + if (trim($job['Commands']) != '') { + print '
';
+  print htmlentities(trim($job['Commands']));
+  print '
'; + } + + print ''; + +?> +