public function delete($id)
	{
		$data = array();
	
		$device = new Device($id);
		$device->delete();
		
		redirect("/", "refresh");
	}
Beispiel #2
0
function device_controller()
{
    global $session, $route, $mysqli, $user, $redis;
    $result = false;
    require_once "Modules/device/device_model.php";
    $device = new Device($mysqli, $redis);
    if ($route->format == 'html') {
        if ($route->action == "view" && $session['write']) {
            $devices_templates = $device->get_templates();
            $result = view("Modules/device/Views/device_view.php", array('devices_templates' => $devices_templates));
        }
        if ($route->action == 'api') {
            $result = view("Modules/device/Views/device_api.php", array());
        }
    }
    if ($route->format == 'json') {
        if ($route->action == 'list') {
            if ($session['userid'] > 0 && $session['write']) {
                $result = $device->get_list($session['userid']);
            }
        } elseif ($route->action == "create") {
            if ($session['userid'] > 0 && $session['write']) {
                $result = $device->create($session['userid']);
            }
        } elseif ($route->action == "listtemplates") {
            if ($session['userid'] > 0 && $session['write']) {
                $result = $device->get_templates();
            }
        } else {
            $deviceid = (int) get('id');
            if ($device->exist($deviceid)) {
                $deviceget = $device->get($deviceid);
                if (isset($session['write']) && $session['write'] && $session['userid'] > 0 && $deviceget['userid'] == $session['userid']) {
                    if ($route->action == "get") {
                        $result = $deviceget;
                    }
                    if ($route->action == "delete") {
                        $result = $device->delete($deviceid);
                    }
                    if ($route->action == 'set') {
                        $result = $device->set_fields($deviceid, get('fields'));
                    }
                    if ($route->action == 'inittemplate') {
                        $result = $device->init_template($deviceid);
                    }
                }
            } else {
                $result = array('success' => false, 'message' => 'Device does not exist');
            }
        }
    }
    return array('content' => $result);
}
Beispiel #3
0
    Device::save($device);
    die('1');
}
// Update
if (isset($_POST['update'])) {
    $device = new Device();
    $device->set_id((int) $_POST['id']);
    $device->set_uid((string) $_POST['uid']);
    $device->set_name((string) $_POST['name']);
    // Get default cost for device
    if ($_POST['default']) {
        foreach (System::getValue() as $r) {
            if ($r->get_var() == 'default_cost') {
                $device->set_cost($r->get_val());
            }
        }
    } else {
        $device->set_cost((double) $_POST['cost']);
    }
    $device->set_range((int) $_POST['range']);
    Device::save($device);
    die('1');
}
// Delete
if (isset($_POST['delete'])) {
    Device::delete((int) $_POST['id']);
    die('1');
}
$devices = Device::getAll();
$smarty->assign('devices', $devices);
$smarty->display('device.tpl');
 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);
     }
 }
Beispiel #5
0
    ?>
 </a>
      &nbsp;&nbsp;&nbsp;<a href="host.php">
      <?php 
    echo gettext("No");
    ?>
 </a>
    </p>
<?php 
    exit;
}
require_once 'ossim_db.inc';
require_once 'classes/Device.inc';
$db = new ossim_db();
$conn = $db->connect();
Device::delete($conn, $ip);
$db->close($conn);
?>

    <p> <?php 
echo gettext("Device deleted");
?>
 </p>
    <p><a href="host.php">
    <?php 
echo gettext("Back");
?>
 </a></p>

</body>
</html>