index.php 7.37 KB
Newer Older
Tariq Khan's avatar
Tariq Khan committed
1 2 3 4
<?php
$url = strtok($_SERVER["REQUEST_URI"],'?');
require_once getcwd().'/oauth2.php';
$oauth2 = new Oauth2(array(
Tariq Khan's avatar
Tariq Khan committed
5
    'operateUrl'	=> 'https://operate-api.essensys.tech',
Tariq Khan's avatar
Tariq Khan committed
6
    'client'            => 'trustedclient',
Tariq Khan's avatar
Tariq Khan committed
7 8 9 10 11 12
    'clientSecret'	=> 'you-client-secret-key-goes-here',
    'scope'	        => 'hubapi'));
?>
<!DOCTYPE html>
<html>
<head>
Tariq Khan's avatar
Tariq Khan committed
13
    <title>Operate API sample</title>
Tariq Khan's avatar
Tariq Khan committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="container">
    <div class="navbar">
        <div class="navbar-inner">
            <ul class="nav">
            <?php if($oauth2->isUserAuthenticated()) { ?>
                <li><a href="<?php echo $url; ?>">API</a></li>
            <?php } ?>
            <!-- <li><a href="/#/oauth2Config">OAuth2 config</a></li> -->
            <?php if(!$oauth2->isUserAuthenticated()) { ?>
                <li><a href="<?php echo $url; ?>">Login</a></li>
            <?php } if($oauth2->isUserAuthenticated()) { ?>
                <li><a href="<?php echo $url; ?>?logout">Logout</a></li>
            <?php } if($oauth2->isUserAuthenticated()) { ?>
                <li><a href="<?php echo $url; ?>?refreshToken">Refresh token</a></li>
            <?php } ?>
            </ul>
        </div>
    </div>
    <div class="row">
        <div class="span12">
            <div class="well">
            <?php if(!$oauth2->isUserAuthenticated()) { ?>
                <h3>Log in</h3>
                <p>Logging in retrieves access token for the provided credentials. This token is then used for all calls to api, so credentials don't have to be kept.</p>
                <form action="<?php echo $url; ?>" method="post">
                    <div>
                        <label for="user">Username:</label>
                        <input type="text" name="user" id="user" value="name@domain.com">
                    </div>
                    <div>
                        <label for="pass">Password:</label>
                        <input type="password" name="pass" id="pass" value="operatePassword">
                    </div>
                    <input type="submit" name="login" value="Log in" class="btn btn-default">
                </form>
            <?php } else { ?>
                <div class="navbar">
                    <div class="navbar-inner">
                        <ul class="nav">
                            <li><a href="<?php echo $url; ?>">Tracking devices</a></li>
                            <li><a href="<?php echo $url; ?>?create">Create tracking device</a></li>
                        </ul>
                    </div>
                </div>
                <?php if(isset($_GET['create'])) { ?>
                <h3>Create Tracking Device</h3>
                <form action="<?php echo $url; ?>?create" method="post">
                    <div>
                        <label for="name">Name:</label>
Tariq Khan's avatar
Tariq Khan committed
65
                        <input type="text" name="trackingdevicename" id="trackingdevicename" required placeholder="Some string">
Tariq Khan's avatar
Tariq Khan committed
66 67 68
                    </div>
                    <div>
                        <label for="">Type:</label>
Tariq Khan's avatar
Tariq Khan committed
69
                        <input type="text" name="trackingtype" id="trackingtype" required placeholder="IN, OUT or IN/OUT">
Tariq Khan's avatar
Tariq Khan committed
70 71 72
                    </div>
                    <div>
                        <label for="uid">Unique id:</label>
Tariq Khan's avatar
Tariq Khan committed
73
                        <input type="text" name="uniquedeviceid" id="uniquedeviceid" required placeholder="Some string">
Tariq Khan's avatar
Tariq Khan committed
74 75 76
                    </div>
                    <div>
                        <label for="siteid">Site id:</label>
Tariq Khan's avatar
Tariq Khan committed
77
                        <input type="text" name="siteid" id="siteid" required placeholder="Some number">
Tariq Khan's avatar
Tariq Khan committed
78 79 80
                    </div>
                    <div>
                        <label for="active">Active:</label>
Tariq Khan's avatar
Tariq Khan committed
81
                        <input type="text" name="active" id="active" required placeholder="True or False">
Tariq Khan's avatar
Tariq Khan committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                    </div>
                    <input type="submit" name="create" value="Create" class="btn btn-default">
                </form>
                <?php } elseif(isset($_GET['entries'])) { ?>
                <h3>Tracking Devices Entries</h3>
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Time</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php if($oauth2->trackingEntries) foreach($oauth2->trackingEntries as $entry) { ?>
                        <tr>
                            <td>{{entry.trackingentriesid}}</td>
                            <td>{{entry.trackingentriesname}}</td>
                            <td>{{entry.trackingtype}}</td>
                            <td>{{entry.creationdate}}</td>
                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
                <?php } elseif(isset($_GET['add'])) { ?>
                <h3>Add Tracking Entry</h3>
                <form action="<?php echo $url; ?>?add=<?php echo $_GET['add']; ?>" method="post">
                    <div>
                        <label for="trackingentriesname">Name:</label>
Tariq Khan's avatar
Tariq Khan committed
112
                        <input type="text" name="trackingentriesname" id="trackingentriesname" required placeholder="Some string">
Tariq Khan's avatar
Tariq Khan committed
113 114 115
                    </div>
                    <div>
                        <label for="trackingtype">Type:</label>
Tariq Khan's avatar
Tariq Khan committed
116
                        <input type="text" name="trackingtype" id="trackingtype" required placeholder="IN or OUT">
Tariq Khan's avatar
Tariq Khan committed
117 118 119
                    </div>
                    <div>
                        <label for="contactid">Contact id:</label>
Tariq Khan's avatar
Tariq Khan committed
120
                        <input type="text" name="contactid" id="contactid" required placeholder="Some number">
Tariq Khan's avatar
Tariq Khan committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
                    </div>
                    <input type="submit" name="add" value="Create" class="btn btn-default">
                </form>
                <?php } else { ?>
                <div>
                    <h3>Tracking Devices</h3>
                    <?php if($oauth2->trackingDevices) { ?>
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>Id</th>
                                <th>name</th>
                                <th></th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach($oauth2->trackingDevices as $key => $value) { ?>
                            <tr>
                                <td><?php echo $value->trackingdeviceid; ?></td>
                                <td><?php echo $value->trackingdevicename; ?></td>
Tariq Khan's avatar
Tariq Khan committed
142 143
                                <td><a href="<?php echo $url; ?>?entries=<?php echo $value->trackingdeviceid; ?>">show entries</a></td>
                                <td><a href="<?php echo $url; ?>?add=<?php echo $value->trackingdeviceid; ?>">add entry</a></td>
Tariq Khan's avatar
Tariq Khan committed
144 145 146 147 148 149 150 151 152 153 154 155 156
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                    <?php } else { ?><p>No data!</p><?php } ?>
                </div>
                <?php } ?>
            <?php } ?>
            </div>
        </div>
    </div>
</body>
</html>