| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * This Source Code Form is subject to the terms of the Mozilla Public | 
					
						
							|  |  |  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | 
					
						
							|  |  |  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | redirectIfNotLoggedIn(); | 
					
						
							|  |  |  | $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  | if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { | 
					
						
							|  |  |  |     header("Location: ./app.php?msg=no_permission"); | 
					
						
							|  |  |  |     die(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $editing = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 18:49:34 -06:00
										 |  |  | $machine = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | if (!empty($VARS["arg"]) && Component::exists($VARS["arg"])) { | 
					
						
							|  |  |  |     $editing = true; | 
					
						
							|  |  |  |     $component = new Component($VARS["arg"]); | 
					
						
							|  |  |  | } else if (!empty($VARS["id"]) && Component::exists($VARS["id"])) { | 
					
						
							|  |  |  |     $editing = true; | 
					
						
							|  |  |  |     $component = new Component($VARS["id"]); | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     $component = Component::create(); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:43:57 -06:00
										 |  |  |     $editing = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 19:06:07 -06:00
										 |  |  | if ($editing && !empty($component->getMachineID())) { | 
					
						
							|  |  |  |     $machine = new Machine($component->getMachineID()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 18:43:57 -06:00
										 |  |  | if (!empty($VARS['machine']) && Machine::exists($VARS['machine'])) { | 
					
						
							|  |  |  |     $machine = new Machine($VARS['machine']); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |     $component->setMachineID($machine->getID()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($editing) { | 
					
						
							|  |  |  |     $form = new FormBuilder("Edit Component #" . $component->getID(), "fas fa-memory", "action.php", "POST"); | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     $form = new FormBuilder("Add Component", "fas fa-memory", "action.php", "POST"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 19:06:07 -06:00
										 |  |  | $form->setID("editcomponent"); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | $form->addHiddenInput("action", "editcomponent"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $types = [ | 
					
						
							|  |  |  |     "" => "" | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | foreach (Component::getTypes() as $k => $v) { | 
					
						
							|  |  |  |     $types[$k] = $v; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($editing) { | 
					
						
							|  |  |  |     $form->addHiddenInput("id", $component->getID()); | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     $form->addInput("id", $component->getID(), "text", true, null, null, "Component ID", "fas fa-memory", 4, 1, 20); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 19:06:07 -06:00
										 |  |  | if (!empty($machine)) { | 
					
						
							| 
									
										
										
										
											2020-07-15 18:43:57 -06:00
										 |  |  |     $form->addHiddenInput("source", "viewmachine"); | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     $form->addHiddenInput("source", "components"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | $date = date('Y-m-d'); | 
					
						
							| 
									
										
										
										
											2019-12-07 20:06:10 -07:00
										 |  |  | $time = date('H:i'); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | if (!empty($component->getTestedDate())) { | 
					
						
							|  |  |  |     $date = date("Y-m-d", strtotime($component->getTestedDate())); | 
					
						
							|  |  |  |     $time = date("H:i:s", strtotime($component->getTestedDate())); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-15 18:43:57 -06:00
										 |  |  | $form->addInput("machine", (is_null($machine) ? "" : $machine->getID()), "text", false, null, null, "Machine ID", "fas fa-desktop", 4, 0, 200); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | $form->addInput("serial", $component->getSerial(), "text", false, null, null, "Serial", "fas fa-barcode", 4, 0, 200); | 
					
						
							|  |  |  | $form->addInput("type", $component->getTypeID(), "select", false, null, $types, "Type", "fas fa-list"); | 
					
						
							| 
									
										
										
										
											2020-05-16 15:30:04 -06:00
										 |  |  | $form->addInput("date", $date, "date", false, null, null, "Tested Date", "fas fa-calendar"); | 
					
						
							|  |  |  | $form->addInput("time", $time, "time", false, null, null, "Tested Time", "fas fa-clock"); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | $form->addInput("capacity", $component->getCapacity(), "text", false, null, null, "Capacity", "fas fa-database", 4, 0, 200); | 
					
						
							|  |  |  | $form->addInput("model", $component->getModel(), "text", false, null, null, "Model", "fas fa-hashtag", 4, 0, 200); | 
					
						
							| 
									
										
										
										
											2020-06-02 22:57:14 -06:00
										 |  |  | $form->addInput("manufacturer", $component->getManufacturer(), "text", false, null, null, "Manufacturer", "fas fa-industry", 4, 0, 200); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | $form->addInput("price", $component->getPrice(), "number", false, null, null, "Price", "fas fa-money-bill-wave"); | 
					
						
							| 
									
										
										
										
											2020-06-27 16:12:21 -06:00
										 |  |  | $form->addInput("privatenotes", $component->getPrivateNotes(), "textarea", false, null, null, "Private Notes", "fas fa-comment-dots", 6, 0, 10000); | 
					
						
							|  |  |  | $form->addInput("publicnotes", $component->getPublicNotes(), "textarea", false, null, null, "Public Notes", "far fa-comment-dots", 6, 0, 10000); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | $form->addButton("Save", "fas fa-save", null, "submit", "savebtn"); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:43:57 -06:00
										 |  |  | if (!is_null($machine)) { | 
					
						
							|  |  |  |     $form->addButton("Back", "fas fa-arrow-left", "./app.php?page=viewmachine&id=" . $machine->getID(), "", null, null, "", "btn btn-info ml-2"); | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     $form->addButton("Back", "fas fa-arrow-left", "./app.php?page=components", "", null, null, "", "btn btn-info ml-2"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | $form->generate(); |