Browse Source

Initial commit

master
Skylar Ittner 3 years ago
commit
0016096c2e
  1. 4
      .gitignore
  2. 3790
      assets/machinelabel-sample.svg
  3. 12
      composer.json
  4. 78
      composer.lock
  5. BIN
      database.mwb
  6. 22
      index.php
  7. 62
      machine.php
  8. 7
      nbproject/project.properties
  9. 9
      nbproject/project.xml
  10. 28
      required.php
  11. 18
      routes.php
  12. 53
      routes/home.php
  13. 136
      routes/info.php
  14. 12
      settings.template.php

4
.gitignore

@ -0,0 +1,4 @@
nbproject/private
database.mwb.bak
vendor
settings.php

3790
assets/machinelabel-sample.svg
File diff suppressed because it is too large
View File

12
composer.json

@ -0,0 +1,12 @@
{
"name": "netsyms/pc-info",
"require": {
"catfan/medoo": "^1.5"
},
"authors": [
{
"name": "Skylar Ittner",
"email": "admin@netsyms.com"
}
]
}

78
composer.lock

@ -0,0 +1,78 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "c80bb87dd0094978b34bdd28fbeb6413",
"content-hash": "e389a785f072eecc16c5846a620f50b8",
"packages": [
{
"name": "catfan/medoo",
"version": "v1.5.7",
"source": {
"type": "git",
"url": "https://github.com/catfan/Medoo.git",
"reference": "8d90cba0e8ff176028847527d0ea76fe41a06ecf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/8d90cba0e8ff176028847527d0ea76fe41a06ecf",
"reference": "8d90cba0e8ff176028847527d0ea76fe41a06ecf",
"shasum": ""
},
"require": {
"ext-pdo": "*",
"php": ">=5.4"
},
"suggest": {
"ext-pdo_dblib": "For MSSQL or Sybase database on Linux/UNIX platform",
"ext-pdo_mysql": "For MySQL or MariaDB database",
"ext-pdo_oci": "For Oracle database",
"ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_pqsql": "For PostgreSQL database",
"ext-pdo_sqlite": "For SQLite database",
"ext-pdo_sqlsrv": "For MSSQL database"
},
"type": "framework",
"autoload": {
"psr-4": {
"Medoo\\": "/src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Angel Lai",
"email": "angel@catfan.me"
}
],
"description": "The lightest PHP database framework to accelerate development",
"homepage": "https://medoo.in",
"keywords": [
"database",
"lightweight",
"mariadb",
"mssql",
"mysql",
"oracle",
"php framework",
"postgresql",
"sql",
"sqlite"
],
"time": "2018-06-14 18:59:08"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

BIN
database.mwb

22
index.php

@ -0,0 +1,22 @@
<?php
require_once __DIR__ . "/required.php";
require_once __DIR__ . "/routes.php";
?>
<!DOCTYPE html>
<meta charset="UTF-8">
<title><?php echo SITE_TITLE; ?></title>
<link href="https://static.netsyms.net/bootstrap/4/bootstrap.materia.min.css" rel="stylesheet" />
<script src="https://static.netsyms.net/jquery/jquery-3.3.1.slim.min.js"></script>
<script src="https://static.netsyms.net/bootstrap/4/bootstrap.min.js"></script>
<script async defer src="https://static.netsyms.net/fontawesome/5.0/fontawesome-all.min.js"></script>
<?php
if (empty($_GET['page'])) {
include __DIR__ . "/routes/" . Routes::getRoute();
} else {
include __DIR__ . "/routes/" . Routes::getRoute($_GET['page']);
}
?>

62
machine.php

@ -0,0 +1,62 @@
<?php
class Machine {
private $machineid = "";
private $machine = [];
private $history = [];
private $components = [];
public function __construct($machineid) {
global $database;
if ($database->has('machines', ['machineid' => $machineid])) {
$this->machineid = $machineid;
$this->machine = $database->get('machines', ['machineid', 'notes', 'model', 'condition', 'price'], ['machineid' => $machineid]);
$this->history = $database->select('history', ['[>]event_types' => 'eventid'], ['historyid', 'date', 'eventname', 'notes'], ['machineid' => $machineid]);
$this->components = $database->select('components', ['[>]component_types' => 'typeid'], ['compid', 'serial', 'typename', 'tested', 'notes', 'capacity', 'model'], ['machineid' => $machineid]);
} else {
throw new Exception("No machine with that ID number could be found.");
}
}
public function getHistory() {
return $this->history;
}
public function getMachineInfo() {
$info = [];
$info['machineid'] = $this->machineid;
if (!empty($this->machine['model'])) {
$info['model'] = $this->machine['model'];
}
if (!empty($this->machine['condition'])) {
$info['condition'] = $this->machine['condition'];
}
if (!empty($this->machine['price'])) {
$info['price'] = $this->machine['price'];
}
$info['notes'] = $this->machine['notes'];
return $info;
}
public function getComponents() {
$info = [];
foreach ($this->components as $c) {
$info[$c['compid']] = [
'serial' => $c['serial'],
'type' => $c['typename'],
'notes' => $c['notes']
];
if (!empty($c['tested'])) {
$info[$c['compid']]['tested'] = $c['tested'];
}
if (!empty($c['capacity'])) {
$info[$c['compid']]['capacity'] = $c['capacity'];
}
if (!empty($c['model'])) {
$info[$c['compid']]['model'] = $c['model'];
}
}
return $info;
}
}

7
nbproject/project.properties

@ -0,0 +1,7 @@
include.path=${php.global.include.path}
php.version=PHP_70
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=false
web.root=.

9
nbproject/project.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>PCInfo</name>
</data>
</configuration>
</project>

28
required.php

@ -0,0 +1,28 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once __DIR__ . "/settings.php";
require_once __DIR__ . "/vendor/autoload.php";
use Medoo\Medoo;
$database;
try {
$database = new Medoo([
'database_type' => DB_TYPE,
'database_name' => DB_NAME,
'server' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => DB_CHARSET
]);
} catch (Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');
die("Database error. Try again later. (" . $ex->getMessage() . ")");
}

18
routes.php

@ -0,0 +1,18 @@
<?php
class Routes {
private static $ROUTES = [
"home" => "home.php",
"info" => "info.php"
];
public static function getRoute($page = "home") {
if (array_key_exists($page, Routes::$ROUTES)) {
return Routes::$ROUTES[$page];
} else {
return Routes::$ROUTES["home"];
}
}
}

53
routes/home.php

@ -0,0 +1,53 @@
<div class="modal fade" id="helpModal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="helpModalLabel">Finding the Machine ID Number</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row justify-content-center">
<div class="col-sm-6">
<h5>Desktops</h5>
<p>On a desktop computer tower, the sticker is usually on the top or a side near the top, close to the back of the computer.</p>
</div>
<div class="col-sm-6">
<h5>Laptops</h5>
<p>On a laptop computer, the sticker is usually on the bottom side.</p>
</div>
<div class="col-12 d-flex">
<img class="mx-auto" style="border: 1px solid grey; border-radius: 15px;" src="assets/machinelabel-sample.svg" alt="Sample machine ID label" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="container mt-4">
<div class="d-flex justify-content-center">
<div class="card">
<img class="card-img-top p-4 mx-auto" style="max-width: 100%; width: 400px;" src="https://static.netsyms.net/images/netsyms/logo-flat-words.png" alt="Netsyms Technologies" />
<div class="card-body py-0">
<h5>
PC Info Finder
</h5>
</div>
<div class="card-body">
<p>
Enter the machine ID number on the sticker. <span class="text-primary" style="cursor: pointer;" onclick='$("#helpModal").modal();'>Click here</span> if you can't find it.
</p>
<form method="GET">
<input type="hidden" name="page" value="info" />
<input type="text" name="serial" class="form-control" placeholder="Machine ID Number" required />
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button>
</form>
</div>
</div>
</div>
</div>

136
routes/info.php

@ -0,0 +1,136 @@
<div class="container mt-4">
<div class="d-flex justify-content-center">
<div class="card">
<img class="card-img-top p-4 mx-auto" style="max-width: 100%; width: 400px;" src="https://static.netsyms.net/images/netsyms/logo-flat-words.png" alt="Netsyms Technologies" />
<div class="card-body py-0">
<h5>
Machine #<?php echo htmlspecialchars($_GET['serial']); ?>
</h5>
</div>
<div class="card-body">
<?php
require_once __DIR__ . "/../machine.php";
try {
$machine = new Machine($_GET['serial']);
$info = $machine->getMachineInfo();
if (count($info) > 0) {
?>
<h6>Machine Info:</h6>
<div class="list-group">
<?php
foreach ($info as $key => $val) {
if (empty($val)) {
continue;
}
$echo = "";
switch ($key) {
case "model":
$echo = "Model: " . htmlspecialchars($val);
break;
case "condition":
$filled = floor($val);
$echo = "Condition: ";
$empty = 10;
while ($filled > 0) {
$filled--;
$empty--;
$echo .= "<i class=\"fas fa-star\"></i> ";
}
if ($val - floor($val) > 0.75) {
$empty--;
$echo .= "<i class=\"fas fa-star\"></i> ";
} else if ($val - floor($val) > 0.25) {
$empty--;
$echo .= "<i class=\"fas fa-star-half-alt\"></i> ";
}
while ($empty > 0) {
$empty--;
$echo .= "<i class=\"far fa-star\"></i> ";
}
break;
case "price":
$echo = "Sale Value: $" . number_format($val * 1.0, 2);
break;
case "notes":
$echo = "<div>" . htmlspecialchars($val) . "</div>";
break;
}
if ($echo != "") {
echo "<div class=\"list-group-item\">\n$echo\n</div>\n";
}
}
?>
</div>
<?php
}
$history = $machine->getHistory();
if (count($history) > 0) {
?>
<h6 class="mt-3">History:</h6>
<div class="list-group">
<?php
foreach ($history as $h) {
echo "<div class=\"list-group-item\">\n";
echo "<b>$h[eventname]</b> on " . date(DATETIME_FORMAT, strtotime($h['date'])) . "<br />\n";
if (!empty($h['notes'])) {
echo "<div>" . htmlspecialchars($h['notes']) . "</div>";
}
echo "\n</div>\n";
}
?>
</div>
<?php
}
$components = $machine->getComponents();
if (count($components) > 0) {
?>
<h6 class="mt-3">Components:</h6>
<div class="list-group">
<?php
foreach ($components as $c) {
echo "<div class=\"list-group-item\">\n";
echo "<b>$c[type]</b><br />\n";
echo "Serial: $c[serial]<br />\n";
if (!empty($c['tested'])) {
echo "Tested on: " . date(DATETIME_FORMAT, strtotime($c['tested'])) . "<br />\n";
}
if (!empty($c['capacity'])) {
echo "Capacity: $c[capacity]<br />\n";
}
if (!empty($c['model'])) {
echo "Model: $c[model]<br />\n";
}
if (!empty($h['notes'])) {
echo "<div>" . htmlspecialchars($h['notes']) . "</div>";
}
echo "\n</div>\n";
}
?>
</div>
<?php
}
} catch (Exception $ex) {
echo "<p class=\"text-danger\">" . $ex->getMessage() . "</p>";
}
?>
</div>
<div class="card-body">
<p>Look up another machine:</p>
<form method="GET">
<input type="hidden" name="page" value="info" />
<input type="text" name="serial" class="form-control" placeholder="Machine ID Number" required />
<button type="submit" class="btn btn-primary btn-block mt-2">Get PC Info</button>
</form>
</div>
</div>
</div>
</div>

12
settings.template.php

@ -0,0 +1,12 @@
<?php
define("SITE_TITLE", "PC Info");
define("DB_TYPE", "mysql");
define("DB_NAME", "pcinfo");
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_CHARSET", "utf8");
define("DATETIME_FORMAT", "M j, Y @ g:i A");
Loading…
Cancel
Save