GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — labeller/api.php at master · codeTom/labeller

Expand file tree

/

api.php

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
65 lines (61 loc) · 2.55 KB
/

api.php

Copy path

File metadata and controls

65 lines (61 loc) · 2.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
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
65
<?php
require_once("config.php");
$db=new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$db->query("SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))");
//TODO check $user or admin logged-in
/**
* Get next image for given user, ordered by image priority
*/
function nextImage($user){
global $db;
$user=$db->real_escape_string($user);
$res=$db->query("SELECT id,url,type,process,priority,group_concat(username),count(username) as compl, sum(case when username = '$user' then 1 else 0 end) as userdone from (SELECT i.image_id as id,process,priority,username,url,i.type as type from images i left join labels l on l.image_id=i.image_id group by l.image_id,l.username) a group by id having compl<process and userdone=0 order by priority, RAND() desc")->fetch_assoc();
$image=(object) [
"image_id"=>$res['id'],
"url"=>$res['url'],
"type"=>$res['type'],
];
return $image;
}
if(isset($_REQUEST['save'])){
$data=json_decode($_POST['data']);
$image_id=$data->image_id;
$lblinsert=$db->prepare("INSERT INTO labels (image_id, username, type, x1, x2, y1, y2, updated) VALUES (?,?,?,?,?,?,?,FROM_UNIXTIME(?))");
foreach($data->labels as $label){
$lblinsert->bind_param('issiiiii',$image_id, $label->username, $label->type, $label->x1, $label->x2,
$label->y1,$label->y2,$t=($label->time)/1000);
$lblinsert->execute();
}
header("Location: api.php?user=".$_REQUEST['user'],true, 301);
$next=nextImage($_REQUEST['user']);
}elseif(isset($_GET['user'])){
$user=$db->real_escape_string($_GET['user']);
if(isset($_GET['image'])&&$_GET['image']){
$imid=(int) $_GET['image'];
$image=(object) $db->query("SELECT * from images where image_id='$imid'")->fetch_assoc();
}else{
$image=nextImage($_GET['user']);
$imid=$image->image_id;
}
$labels=[];
foreach($db->query("SELECT * from labels where image_id='$imid' and username='$user'") as $row){
$labels[]=(object) $row;
}
echo json_encode((object) ['labels'=>$labels,'image'=>$image]);
exit(0);
}
//dump all data
if(isset($_REQUEST['data'])&&$_REQUEST['key']==KEY){
global $db;
$data=[];
foreach($db->query("SELECT * FROM images;") as $img){
foreach($db->query("SELECT * from labels where image_id=$img[image_id]") as $l){
if(!isset($img['labels']))
$img['labels']=[];
$img['labels'][]=$l;
}
$data[]=$img;
}
header('Content-Type: application/json');
echo json_encode($data);
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.