| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 19:18:19 -06:00
										 |  |  | /* 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/. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Make things happen when buttons are pressed and forms submitted. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | require_once __DIR__ . "/required.php"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 12:34:36 -06:00
										 |  |  | if ($VARS['action'] !== "signout") { | 
					
						
							|  |  |  |     dieifnotloggedin(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-07 00:30:25 -06:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Redirects back to the page ID in $_POST/$_GET['source'] with the given message ID. | 
					
						
							|  |  |  |  * The message will be displayed by the app. | 
					
						
							|  |  |  |  * @param string $msg message ID (see lang/messages.php) | 
					
						
							|  |  |  |  * @param string $arg If set, replaces "{arg}" in the message string when displayed to the user. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  | function returnToSender($msg, $arg = "") { | 
					
						
							|  |  |  |     global $VARS; | 
					
						
							| 
									
										
										
										
											2019-03-01 23:37:06 -07:00
										 |  |  |     $header = "Location: app.php?page=" . urlencode($VARS['source']) . "&msg=$msg"; | 
					
						
							|  |  |  |     if ($arg != "") { | 
					
						
							|  |  |  |         $header .= "&arg=$arg"; | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-01 23:37:06 -07:00
										 |  |  |     header($header); | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  |     die(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | switch ($VARS['action']) { | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |     case "editmachine": | 
					
						
							|  |  |  |         $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  |         if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { | 
					
						
							|  |  |  |             returnToSender("no_permission"); | 
					
						
							|  |  |  |             die(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $machine = new Machine($VARS['id']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-26 19:49:57 -06:00
										 |  |  |         $machine->setType($VARS["type"]); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |         $machine->setModel($VARS['model']); | 
					
						
							|  |  |  |         $machine->setClientID($VARS['client']); | 
					
						
							|  |  |  |         $machine->setOS($VARS['os']); | 
					
						
							|  |  |  |         $machine->setSerial($VARS['serial']); | 
					
						
							|  |  |  |         $machine->setManufacturer($VARS['manufacturer']); | 
					
						
							|  |  |  |         $machine->setCondition($VARS['condition'] * 1.0); | 
					
						
							|  |  |  |         $machine->setPrice($VARS['price'] * 1.0); | 
					
						
							|  |  |  |         $machine->setPrivateNotes($VARS['privatenotes']); | 
					
						
							|  |  |  |         $machine->setPublicNotes($VARS['publicnotes']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $machine->save(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         returnToSender("machine_saved", $machine->getID()); | 
					
						
							| 
									
										
										
										
											2020-06-27 19:06:25 -06:00
										 |  |  |     case "deletemachine": | 
					
						
							|  |  |  |         $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  |         if (!$user->hasPermission("MACHINEMANAGER_DELETE")) { | 
					
						
							|  |  |  |             returnToSender("no_permission"); | 
					
						
							|  |  |  |             die(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $machine = new Machine($VARS['id']); | 
					
						
							|  |  |  |         $machine->setDeleted(true); | 
					
						
							|  |  |  |         $machine->save(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         returnToSender("machine_deleted"); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |     case "editcomponent": | 
					
						
							|  |  |  |         $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  |         if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { | 
					
						
							|  |  |  |             returnToSender("no_permission"); | 
					
						
							|  |  |  |             die(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $component = new Component($VARS['id']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 18:43:57 -06:00
										 |  |  |         if (!empty($VARS["machine"])) { | 
					
						
							|  |  |  |             if (!Machine::exists($VARS['machine'])) { | 
					
						
							|  |  |  |                 returnToSender("invalid_parameters"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $component->setMachineID($VARS['machine']); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |         $component->setSerial($VARS['serial']); | 
					
						
							|  |  |  |         $component->setTypeID($VARS['type']); | 
					
						
							| 
									
										
										
										
											2020-05-16 15:30:04 -06:00
										 |  |  |         if (!empty($VARS['date'])) { | 
					
						
							|  |  |  |             $component->setTestedDate(date( | 
					
						
							|  |  |  |                             "Y-m-d H:i:s", | 
					
						
							|  |  |  |                             strtotime(trim($VARS['date'] . " " . $VARS['time'])) | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $component->clearTestedDate(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |         $component->setCapacity($VARS['capacity']); | 
					
						
							|  |  |  |         $component->setModel($VARS['model']); | 
					
						
							| 
									
										
										
										
											2020-06-02 23:05:40 -06:00
										 |  |  |         $component->setManufacturer($VARS['manufacturer']); | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |         $component->setPrice($VARS['price'] * 1.0); | 
					
						
							|  |  |  |         $component->setPrivateNotes($VARS['privatenotes']); | 
					
						
							|  |  |  |         $component->setPublicNotes($VARS['publicnotes']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $component->save(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 19:06:07 -06:00
										 |  |  |         if (empty($VARS["machine"])) { | 
					
						
							|  |  |  |             returnToSender("component_saved"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |         returnToSender("component_saved", $component->getMachineID()); | 
					
						
							|  |  |  |     case "addevent": | 
					
						
							|  |  |  |         $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  |         if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { | 
					
						
							|  |  |  |             returnToSender("no_permission"); | 
					
						
							|  |  |  |             die(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!Machine::exists($VARS['machine'])) { | 
					
						
							|  |  |  |             returnToSender("invalid_parameters"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 20:47:02 -06:00
										 |  |  |         $evt = Event::create( | 
					
						
							|  |  |  |                         $VARS['machine'], | 
					
						
							|  |  |  |                         date( | 
					
						
							|  |  |  |                                 "Y-m-d H:i:s", | 
					
						
							|  |  |  |                                 strtotime($VARS['date'] . " " . $VARS['time']) | 
					
						
							|  |  |  |                         ), | 
					
						
							|  |  |  |                         $VARS['event'], | 
					
						
							|  |  |  |                         $user->getUID(), | 
					
						
							|  |  |  |                         $VARS['publicnotes'], | 
					
						
							|  |  |  |                         $VARS['privatenotes'] | 
					
						
							| 
									
										
										
										
											2019-09-29 22:38:10 -06:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-11 15:02:45 -06:00
										 |  |  |         returnToSender("event_added", $evt->getMachineID()); | 
					
						
							| 
									
										
										
										
											2019-10-02 16:33:53 -06:00
										 |  |  |     case "editclient": | 
					
						
							|  |  |  |         $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  |         if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { | 
					
						
							|  |  |  |             returnToSender("no_permission"); | 
					
						
							|  |  |  |             die(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!Clients::areLocal()) { | 
					
						
							|  |  |  |             returnToSender("nonlocal_client"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (Client::exists($VARS["id"])) { | 
					
						
							|  |  |  |             $client = new Client($VARS["id"]); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $client = new Client(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $client->setName($VARS["name"]); | 
					
						
							|  |  |  |         $client->setPhone($VARS["phone"]); | 
					
						
							|  |  |  |         $client->setEmail($VARS["email"]); | 
					
						
							|  |  |  |         $client->setBillingAddress($VARS["billingaddress"]); | 
					
						
							|  |  |  |         $client->setMailingAddress($VARS["mailingaddress"]); | 
					
						
							|  |  |  |         $client->setPublicNotes($VARS["publicnotes"]); | 
					
						
							|  |  |  |         $client->setPrivateNotes($VARS["privatenotes"]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $client->save(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         returnToSender("client_edited", $client->getID()); | 
					
						
							| 
									
										
										
										
											2020-08-19 21:29:37 -06:00
										 |  |  |     case "editjob": | 
					
						
							|  |  |  |         $user = new User($_SESSION['uid']); | 
					
						
							|  |  |  |         if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { | 
					
						
							|  |  |  |             returnToSender("no_permission"); | 
					
						
							|  |  |  |             die(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($VARS["jobid"]) && Job::exists($VARS["jobid"])) { | 
					
						
							|  |  |  |             $job = new Job($VARS['jobid']); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $job = Job::create(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $job->setMachineID($VARS["machineid"]); | 
					
						
							|  |  |  |         $job->setName($VARS["jobname"]); | 
					
						
							|  |  |  |         $job->setInfo($VARS["jobinfo"]); | 
					
						
							|  |  |  |         $job->setNotes($VARS["jobnotes"]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $job->save(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         returnToSender("job_saved", $job->getID()); | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  |     case "signout": | 
					
						
							|  |  |  |         session_destroy(); | 
					
						
							| 
									
										
										
										
											2018-12-22 16:57:45 -07:00
										 |  |  |         header('Location: index.php?logout=1'); | 
					
						
							| 
									
										
										
										
											2017-04-24 17:13:08 -06:00
										 |  |  |         die("Logged out."); | 
					
						
							| 
									
										
										
										
											2020-08-19 21:29:37 -06:00
										 |  |  | } |