$selected_device = NULL; } } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); $fatal_error = true; } /******************************************************************************** * * Execute actions * *********************************************************************************/ if (!$fatal_error) { switch ($action) { case 'add': try { $new_device = Device::add($database, $current_user, $log, $new_name, $new_parent_id); $html->set_variable('refresh_navigation_frame', true, 'boolean'); if (!$add_more) { $selected_device = $new_device; $selected_id = $selected_device->get_id(); } } catch (Exception $e) { $messages[] = array('text' => 'Die neue Baugruppe konnte nicht angelegt werden!', 'strong' => true, 'color' => 'red'); $messages[] = array('text' => 'Fehlermeldung: ' . nl2br($e->getMessage()), 'color' => 'red'); } break; case 'delete': try { if (!is_object($selected_device)) { throw new Exception('Es ist keine Baugruppe markiert oder es trat ein Fehler auf!'); }
public static function Device($type, $data) { require_once 'device.class.php'; $class = new Device(); $status = false; $class->setData($data); $class->filter = ManagementFunction::getPostVariable('filter'); switch ($type) { case 'add': $status = $class->add(); break; case 'update': $status = $class->update(); break; case 'delete': $status = $class->delete(); break; case 'getsingle': $status = $class->getsingle(); break; case 'getpage': $status = $class->getpage(); break; case 'search': $status = $class->search(); break; default: break; } if ($status) { wp_send_json_success($status); } else { wp_send_json_error($class->error); } }
/** * @brief Create a new Device as a copy from this one. All DeviceParts will be copied too. * * @param string $name The name of the new device * @param integer $parent_id The ID of the new device's parent device * @param boolean $with_subdevices If true, all subdevices will be copied too * * @throws Exception if there was an error */ public function copy($name, $parent_id, $with_subdevices = false) { try { if ($with_subdevices && $parent_id > 0) { // check if $parent_id is NOT a child of this device $parent_device = new Device($this->database, $this->current_user, $this->log, $parent_id); if ($parent_device->get_id() == $this->get_id() || $parent_device->is_child_of($this)) { throw new Exception('Eine Baugruppe kann nicht in sich selber kopiert werden!'); } } $transaction_id = $this->database->begin_transaction(); // start transaction $new_device = Device::add($this->database, $this->current_user, $this->log, $name, $parent_id); $device_parts = $this->get_parts(); foreach ($device_parts as $part) { $new_part = DevicePart::add($this->database, $this->current_user, $this->log, $new_device->get_id(), $part->get_part()->get_id(), $part->get_mount_quantity(), $part->get_mount_names()); } if ($with_subdevices) { $subdevices = $this->get_subelements(false); foreach ($subdevices as $device) { $device->copy($device->get_name(), $new_device->get_id(), true); } } $this->database->commit($transaction_id); // commit transaction } catch (Exception $e) { $this->database->rollback(); // rollback transaction throw new Exception("Die Baugruppe \"" . $this->get_name() . "\"konnte nicht kopiert werden!\nGrund: " . $e->getMessage()); } }