34 | | == |
| 34 | == Opaque data == |
| 35 | |
| 36 | The application uses the following opaque data: |
| 37 | |
| 38 | * Jobs |
| 39 | {{{ |
| 40 | path: the name of image file |
| 41 | }}} |
| 42 | * Instances |
| 43 | {{{ |
| 44 | features: an array of structures, each containing: |
| 45 | |
| 46 | x: the X coordinate of the center |
| 47 | y: the Y coordinate of the center |
| 48 | type: the feature type (Tooth, Skull, Other) |
| 49 | comment: the user-supplied comment |
| 50 | }}} |
| 51 | |
| 52 | == Callback functions == |
| 53 | |
| 54 | The '''job_show()''' function displays the image and overlays |
| 55 | existing annotations. |
| 56 | Each one is shown as a box with an "info" button |
| 57 | (which pops up the type and comment) |
| 58 | and a "delete" button linked to the edit page. |
| 59 | |
| 60 | The image is an input item in a form linked to the edit page, |
| 61 | so that clicks on the image produce a new annotation. |
| 62 | Javascript is used to require that a feature type be selected |
| 63 | in order for the annotation to be accepted. |
| 64 | |
| 65 | The "Done" button is linked to '''bossa_job_finished.php'''. |
| 66 | |
| 67 | == The edit handler == |
| 68 | |
| 69 | The edit handler is invoked with the following GET arguments: |
| 70 | |
| 71 | * '''bji''': the ID of the instance |
| 72 | * '''action''': "add", "delete", or "" (to display the image) |
| 73 | * '''pic_x''' and '''pic_y''' (if action is "add") |
| 74 | |
| 75 | The code is as follows. |
| 76 | The first two functions add and delete annotations; |
| 77 | each one ends by redirecting to the same page with no "action" argument; |
| 78 | this will redisplay the image with the new set of annotations. |
| 79 | {{{ |
| 80 | 7 function handle_add($job, $inst) { |
| 81 | 8 $f = null; |
| 82 | 9 $f->x = get_int('pic_x'); |
| 83 | 10 $f->y = get_int('pic_y'); |
| 84 | 11 $f->type = get_str('type'); |
| 85 | 12 $c = get_str('comment', true); |
| 86 | 13 if (strstr($c, "(optional)")) $c = ""; |
| 87 | 14 $f->comment = $c; |
| 88 | 15 $output = $inst->get_opaque_data(); |
| 89 | 16 $output->features[] = $f; |
| 90 | 17 $inst->set_opaque_data($output); |
| 91 | 18 header("location: bossa_example4.php?bji=$inst->id"); |
| 92 | 19 } |
| 93 | 20 |
| 94 | 21 function handle_delete($job, $inst, $index) { |
| 95 | 22 $output = $inst->get_opaque_data(); |
| 96 | 23 $features = $output->features; |
| 97 | 24 array_splice($features, $index, 1); |
| 98 | 25 $output->features = $features; |
| 99 | 26 $inst->set_opaque_data($output); |
| 100 | 27 header("location: bossa_example4.php?bji=$inst->id"); |
| 101 | 28 } |
| 102 | }}} |
| 103 | |
| 104 | The main part of the script is as follows. |
| 105 | First, we get the instance ID and call a Bossa API function |
| 106 | to get the job, instance, and user: |
| 107 | {{{ |
| 108 | 30 $bji = get_int("bji"); |
| 109 | 31 if (!bossa_lookup_job($bji, $job, $inst, $u)) { |
| 110 | 32 error_page("No such instance"); |
| 111 | 33 } |
| 112 | }}} |
| 113 | Then we verify that this instance belongs to the logged-in user: |
| 114 | {{{ |
| 115 | 34 $user = get_logged_in_user(); |
| 116 | 35 if ($u->id != $user->id) { |
| 117 | 36 error_page("Not your job"); |
| 118 | 37 } |
| 119 | }}} |
| 120 | Then we perform the operation (or show the image with existing annotations): |
| 121 | {{{ |
| 122 | 39 $action = get_str("action", true); |
| 123 | 40 switch ($action) { |
| 124 | 41 case "add": |
| 125 | 42 handle_add($job, $inst); |
| 126 | 43 break; |
| 127 | 44 case "delete": |
| 128 | 45 $index = get_int("index"); |
| 129 | 46 handle_delete($job, $inst, $index); |
| 130 | 47 break; |
| 131 | 48 default: |
| 132 | 49 job_show($job, $inst, $user); |
| 133 | 50 break; |
| 134 | 51 } |
| 135 | 52 |
| 136 | 53 ?> |
| 137 | }}} |