_('Unknown'), 'precise' => _('Precise'), 'normal' => _('Normal'), 'rough' => _('Rough'), 'estimated' => _('Estimated') ); $opt_dimensions = array( 1 => _('1D'), 2 => _('2D'), 3 => _('3D') ); $opt_equipment = array(-1 => _('unassigned')); $sth = $pdo->prepare("SELECT eid, ename FROM equipment WHERE vid=? ORDER BY ename"); $sth->execute([$user->vid]); foreach ($sth->fetchAll() as $row) { $opt_equipment[$row['eid']] = $row['ename']; } // ========== ACTIONS START =================================================== switch ($submit = form_get_action()) { case NULL: break; case 'add': $action = ACT_ADD; break; case 'view': $action = ACT_VIEW; break; case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; case 'filter': $flt = array(); $flt['precision'] = gpc_get_string($_POST, 'flt_precision'); $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); db_save_filter($flt, 207); $action = ACT_DEFAULT; break; case 'insert': $p[':mname'] = gpc_get_string($_POST, 'mname'); $p[':note'] = gpc_get_string($_POST, 'note'); $p[':nval'] = gpc_get_int($_POST, 'nval'); // 1 to 3 dimensions $p[':val1'] = gpc_get_int($_POST, 'val1'); $p[':val2'] = NULL; $p[':val3'] = NULL; if ($p[':nval'] > 1) { $p[':val2'] = gpc_get_int($_POST, 'val2'); } if ($p[':nval'] > 2) { $p[':val3'] = gpc_get_int($_POST, 'val3'); } $p[':unit'] = gpc_get_int($_POST, 'unit'); $p[':accuracy'] = gpc_get_string($_POST, 'accuracy'); $p[':eid'] = gpc_get_int($_POST, 'eid'); if ($p[':eid'] == -1) { $p[':eid'] = NULL; } $id = db_exec_insert('measurement', $p); $action = ACT_VIEW; break; case 'update': $p[':mid'] = $id; $p[':mname'] = gpc_get_string($_POST, 'mname'); $p[':nval'] = gpc_get_int($_POST, 'nval'); // 1 to 3 dimensions $p[':val1'] = gpc_get_int($_POST, 'val1'); $p[':val2'] = NULL; $p[':val3'] = NULL; if ($p[':nval'] > 1) { $p[':val2'] = gpc_get_int($_POST, 'val2'); } if ($p[':nval'] > 2) { $p[':val3'] = gpc_get_int($_POST, 'val3'); } $p[':unit'] = gpc_get_int($_POST, 'unit'); $p[':accuracy'] = gpc_get_string($_POST, 'accuracy'); $p[':mdate'] = gpc_get_date($_POST, 'mdate'); $p[':note'] = gpc_get_string($_POST, 'note'); $p[':eid'] = gpc_get_int($_POST, 'eid'); if ($p[':eid'] == -1) { $p[':eid'] = NULL; } db_exec_update('measurement', $p, 'mid'); $action = ACT_VIEW; break; case 'delete': // Security token needed! if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { $g_error->Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } $action = ACT_DEFAULT; break; default: $g_error->Add(sprintf(_('Unknown function!'), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= // load filter from db $flt = db_get_filter($user->id, 207); function format_vals($n, $v1, $v2, $v3) { if ($n == 1) { return $v1; } elseif ($n == 2) { return $v1 . 'x'. $v2; } else { return $v1 . 'x'. $v2 . 'x' . $v3; } } echo "

$pagetitle

\n"; // Filter $opt_special = array( -2 => _('― all ―'), -1 => _('― none ―') ); ?>
Filter
query($sql); $res = $sth->fetchAll(); echo '', "\n"; echo "\n"; echo "\n"; echo '"; echo '"; echo '"; echo '"; echo '"; echo ""; echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; echo "\n"; echo "\n"; echo '\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } // Table summary echo "\n"; echo '', "\n"; echo "\n"; echo "
', _('Measurement'), "', _('Note'), "', _('Measured'), "', _('Unit'), "', _('Accuracy'), "
", $row['mname'], "", $row['note'], "', format_vals($row['nval'], $row['val1'], $row['val2'], $row['val3']), "", $opt_unit[$row['unit']], "", $opt_accuracy[$row['accuracy']], ""; // Action buttons form_action_buttons($g_scriptname, $row['mid']); echo "
', sprintf(_('%d records'), count($res)), '
\n"; form_add_button($g_scriptname); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= echo '

', _('Add measurement'), "

\n"; ?>
prepare($sql); $sth->execute([$id]); $measurement = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Measurement'), "

\n"; echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Name'),"", $measurement->mname, "
', _('Unit'),"", $opt_unit[$measurement->unit], "
', _('Values'),"$measurement->nval
', _('Value 1'),"$measurement->val1
', _('Value 2'),"$measurement->val2
', _('Value 3'),"$measurement->val3
', _('Accuracy'),"$measurement->accuracy
', _('Date'),"$measurement->mdate
', _('Note'),"$measurement->note
\n"; form_view_buttons($g_scriptname, $id); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT mname, nval, val1, val2, val3, unit, accuracy, note " . "FROM measurement " . "WHERE mid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $measurement = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Edit measurement'), "

\n"; ?>
nval); ?>
unit); form_create_select('accuracy', _('Accuracy'), $opt_accuracy, $measurement->accuracy); form_create_select('eid', _('Equipment'), $opt_equipment, $measurement->eid); form_edit_buttons($g_scriptname, $id); echo "
\n"; elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

', _('Unknown function call: Please report to system development!'), "

\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';