public function add_post() { // Hook $this->HookManager->processEvent('PRINTER_ADD_POST'); // POST if ($_REQUEST['add'] != 1) { $this->FOGCore->setMessage('Printer type changed to: ' . $_REQUEST['printertype']); $this->FOGCore->redirect($this->formAction . '&printertype=' . $_REQUEST['printertype']); } if ($_REQUEST['add'] == 1) { //Remove spaces from beginning and end offields needed. $_REQUEST['alias'] = trim($_REQUEST['alias']); $_REQUEST['port'] = trim($_REQUEST['port']); $_REQUEST['inf'] = trim($_REQUEST['inf']); $_REQUEST['model'] = trim($_REQUEST['model']); $_REQUEST['ip'] = trim($_REQUEST['ip']); try { // PrinterManager $PrinterManager = $this->getClass('PrinterManager'); // Error checking if ($_REQUEST['printertype'] == "Local") { if (empty($_REQUEST['alias']) || empty($_REQUEST['port']) || empty($_REQUEST['inf']) || empty($_REQUEST['model'])) { throw new Exception('You must specify the alias, port, model, and inf. Unable to create!'); } else { // Create new Object $Printer = new Printer(array('name' => $_REQUEST['alias'], 'config' => $_REQUEST['printertype'], 'model' => $_REQUEST['model'], 'file' => $_REQUEST['inf'], 'port' => $_REQUEST['port'], 'ip' => $_REQUEST['ip'])); } } if ($_REQUEST['printertype'] == "iPrint") { if (empty($_REQUEST['alias']) || empty($_REQUEST['port'])) { throw new Exception('You must specify the alias and port. Unable to create!'); } else { // Create new Object $Printer = new Printer(array('name' => $_REQUEST['alias'], 'config' => $_REQUEST['printertype'], 'port' => $_REQUEST['port'])); } } if ($_REQUEST['printertype'] == "Network") { if (empty($_REQUEST['alias'])) { throw new Exception('You must specify the alias. Unable to create!'); } else { // Create new Object $Printer = new Printer(array('name' => $_REQUEST['alias'], 'config' => $_REQUEST['printertype'])); } } if ($PrinterManager->exists($_REQUEST['alias'])) { throw new Exception('Printer already exists'); } // Save if ($Printer->save()) { // Hook $this->HookManager->processEvent('PRINTER_ADD_SUCCESS', array('Printer' => &$Printer)); // Log History event $this->FOGCore->logHistory(sprintf('%s: ID: %s, Name: %s', _('Printer created'), $Printer->get('id'), $Printer->get('name'))); //Send message to user $this->FOGCore->setMessage('Printer was created! Editing now!'); //Redirect to edit $this->FOGCore->redirect('?node=printer&sub=edit&id=' . $Printer->get('id')); } else { throw new Exception('Something went wrong. Add failed'); } } catch (Exception $e) { // Hook $this->HookManager->processEvent('PRINTER_ADD_FAIL', array('Printer' => &$Printer)); // Log History event $this->FOGCore->logHistory(sprintf('%s add failed: Name: %s, Error: %s', _('User'), $_REQUEST['name'], $e->getMessage())); // Set session message $this->FOGCore->setMessage($e->getMessage()); // Redirect user. $this->FOGCore->redirect($this->formAction); } } }