public function edit() { $this->assertLoggedIn(); $this->set('area', 'bots'); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } else { throw new Exception("Could not find that bot."); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } $this->setTitle('Edit Bot - ' . $bot->getName()); $wizard = new Wizard('bot', $this->args()); if (!$this->args('setup')) { $wizard->disableWizardMode(); } // Create our forms $infoForm = $this->_createInfoForm($bot); $queuesForm = $this->_createQueueForm($bot); $slicingForm = $this->_createSlicingForm($bot); $driverForm = $this->_createDriverForm($bot); // Add them to the wizard $wizard->add("Information / Details", $infoForm); $wizard->add("Queues", $queuesForm); $wizard->add("Slicing Setup", $slicingForm); $wizard->add("Driver Configuration", $driverForm); //handle our forms if ($infoForm->checkSubmitAndValidate($this->args())) { $bot->set('name', $infoForm->data('name')); $bot->set('manufacturer', $infoForm->data('manufacturer')); $bot->set('model', $infoForm->data('model')); $bot->set('electronics', $infoForm->data('electronics')); $bot->set('firmware', $infoForm->data('firmware')); $bot->set('extruder', $infoForm->data('extruder')); $bot->save(); Activity::log("edited the information for bot " . $bot->getLink() . "."); } else { if ($queuesForm->checkSubmitAndValidate($this->args())) { $sql = "DELETE FROM bot_queues WHERE bot_id = ?"; db()->execute($sql, array($bot->id)); $priority = 1; $used = array(); foreach ($this->args() as $key => $value) { if (substr($key, 0, 6) === "queue-" && $value != 0) { if (in_array($value, $used)) { continue; } else { $used[] = $value; } $sql = "INSERT INTO bot_queues VALUES(?, ?, ?)"; $data = array($value, $bot->id, $priority); $priority++; db()->execute($sql, $data); } } } else { if ($slicingForm->checkSubmitAndValidate($this->args())) { $bot->set('slice_engine_id', $slicingForm->data('slice_engine_id')); $bot->set('slice_config_id', $slicingForm->data('slice_config_id')); $config = $bot->getDriverConfig(); $config->can_slice = (bool) $slicingForm->data('can_slice'); $bot->set('driver_config', json::encode($config)); $bot->save(); Activity::log("edited the slicing info for bot " . $bot->getLink() . "."); } else { if ($driverForm->checkSubmitAndValidate($this->args())) { $bot->set('oauth_token_id', $driverForm->data('oauth_token_id')); $bot->set('driver_name', $driverForm->data('driver_name')); //create and save our config $config = $bot->getDriverConfig(); $config->driver = $bot->get('driver_name'); if ($bot->get('driver_name') == 'dummy') { if ($this->args('delay')) { $config->delay = $this->args('delay'); } } elseif ($bot->get('driver_name') == 'printcore' || $bot->get('driver_name') == 's3g') { $config->port = $this->args('serial_port'); $config->port_id = $this->args('port_id'); $config->baud = $this->args('baudrate'); } //did we get webcam info? if ($this->args('webcam_device')) { if (!isset($config->webcam)) { $config->webcam = new stdClass(); } $config->webcam->device = $this->args('webcam_device'); if ($this->args('webcam_id')) { $config->webcam->id = $this->args('webcam_id'); } if ($this->args('webcam_name')) { $config->webcam->name = $this->args('webcam_name'); } if ($this->args('webcam_brightness')) { $config->webcam->brightness = (int) $this->args('webcam_brightness'); } if ($this->args('webcam_contrast')) { $config->webcam->contrast = (int) $this->args('webcam_contrast'); } } else { unset($config->webcam); } //save it all to the bot as json. $bot->set('driver_config', json::encode($config)); $bot->save(); Activity::log("edited the driver configuration for bot " . $bot->getLink() . "."); } } } } if ($wizard->isFinished()) { $this->forwardToURL($bot->getUrl()); } $this->set('bot_id', $bot->id); $this->set('wizard', $wizard); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Bot Edit - Error"); } }