public function index()
	{
		$data = array();
	
		$devices = new Device();
		$data['devices'] = $devices->get()->all;
		
		$data['breadcrumbs'] = array('Devices' => '');
		$data['content'] = 'devices/viewall';
		$this->load->view('layouts/main/index', $data);
	}
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
             // Add this item to end of array
             $log->lwrite("main: Queue: cmd: " . $item['cmd'], 1);
         }
     }
     continue;
     // End this iteration of the loop
 } else {
     $log->lwrite("main:: Action: time: " . $items[$i]['secs'] . ", scene: " . $items[$i]['scene'] . ", cmd: " . $items[$i]['cmd'], 2);
     $cmd = $items[$i]['cmd'];
 }
 // If we have all devices, $devices contains list of devices
 // It is possible to look the device up through room and device combination!!
 list($room, $dev, $value) = sscanf($items[$i]['cmd'], "!R%dD%dF%s\n");
 $log->lwrite("main:: room: " . $room . " ,device: " . $dev . " value: " . $value, 1);
 // Search the correct unit in the room. Thus dev is here the unit number
 $device = $dlist->get($room, $dev);
 // For which room, device is it, and what is the action?
 if (substr($value, 0, 2) == "dP") {
     $value = substr($value, 2);
     $device['val'] = $value;
     $device['lastval'] = $value;
     $sndval = $value;
 } else {
     if ($value == '1') {
         // in case F1
         if ($device['type'] == "switch") {
             $device['val'] = '1';
         } else {
             $device['val'] = $device['lastval'];
         }
         $sndval = "on";
Beispiel #4
0
 public static function getDevice($key = null, $val = null)
 {
     if (is_null($key)) {
         $c = Device::get();
         self::$device = $c;
         return new self();
     } else {
         $c = Device::where($key, '=', $val)->first();
         self::$device = $c;
         return $c;
     }
 }