Bladeren bron

Ability to add activities

Closes #35
tags/SensorLogger/0.2.0
Chris Smith 14 jaren geleden
bovenliggende
commit
11096a909a
2 gewijzigde bestanden met toevoegingen van 69 en 0 verwijderingen
  1. 51
    0
      website/admin.php
  2. 18
    0
      website/common.php

+ 51
- 0
website/admin.php Bestand weergeven

@@ -32,8 +32,59 @@
32 32
 
33 33
  }
34 34
 
35
+ # -------------- End of authentication code --------------------------
36
+
35 37
  require('common.php');
36 38
 
39
+ # -------------- Form handling -----------------
40
+
41
+ function process_activity_add($args) {
42
+  $sql  = 'INSERT INTO activities (activity_name, activity_parent) VALUES (\'';
43
+  $sql .= m($args['name']) . '\', ' . ((int) $args['parent']) . ')';
44
+  mysql_query($sql);
45
+ }
46
+
47
+ if (isset($_POST['action'])) {
48
+  $args = array();
49
+  $action = str_replace('.', '_', $_POST['action']) . '_';
50
+  foreach ($_POST as $k => $v) {
51
+   if (substr($k, 0, strlen($action)) == $action) {
52
+    $args[substr($k, strlen($action))] = $v;
53
+   }
54
+  }
55
+
56
+  call_user_func('process_' . str_replace('.', '_', $_POST['action']), $args);
57
+  header('Location: /android/admin.php');
58
+  exit;
59
+ }
60
+
61
+ # ------------------- End of form handling ----------------------
62
+
63
+ $acs = getActivityArray();
64
+
65
+?>
66
+<h1>Activity management</h1>
67
+
68
+<h2>Add an activity</h2>
69
+
70
+<form action="admin.php" method="post">
71
+ <input type="hidden" name="action" value="activity.add">
72
+ <select name="activity.add.parent">
73
+<?PHP
74
+ asort($acs);
75
+
76
+ foreach ($acs as $id => $name) {
77
+  echo ' <option value="', $id, '">', htmlentities($name), '</option>';
78
+ }
79
+?>
80
+ </select> / 
81
+ <input type="text" name="activity.add.name">
82
+ <input type="submit" value="Add">
83
+</form>
84
+
85
+<h1>Sample management</h1>
86
+<?PHP
87
+
37 88
  $sql = 'SELECT log_id, log_imei, log_version, log_time, log_activity, log_data FROM sensorlogger WHERE log_statuscode = 1';
38 89
  $res = mysql_query($sql);
39 90
 

+ 18
- 0
website/common.php Bestand weergeven

@@ -31,6 +31,24 @@
31 31
         }
32 32
  }
33 33
 
34
+ function getActivityArray() {
35
+	$acs = array();
36
+	$sql = 'SELECT activity_id, activity_name, activity_parent FROM activities ORDER BY activity_parent';
37
+	$res = mysql_query($sql);
38
+
39
+	while ($row = mysql_fetch_assoc($res)) {
40
+		$name = $row['activity_name'];
41
+
42
+		if (isset($acs[(int) $row['activity_parent']])) {
43
+			$name = $acs[(int) $row['activity_parent']] . '/' . $name;
44
+		}
45
+
46
+		$acs[(int) $row['activity_id']] = $name;
47
+	}
48
+
49
+	return $acs;
50
+ }
51
+
34 52
  function getStatusCodeReason($code) {
35 53
  	switch ((int) $code) {
36 54
 		case 2: return 'no IMEI code was specified';

Laden…
Annuleren
Opslaan