_('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 'freset': db_clear_filter(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 ======================================= page_caption_search($pagetitle); // load filter from db $flt = db_get_filter($user->id, 207, ['txt']); $w = array('(vid=:vid OR vid IS NULL)'); $p = array(':vid' => $user->vid); // TODO precision additionally as filter if (strlen($flt->txt) > 1) { $w[] = 'mname LIKE :txt'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); $order = ' ORDER BY mname'; $sql = "SELECT COUNT(*) FROM measurement WHERE " . $where; $sth = $pdo->prepare($sql); try { $sth->execute($p); } catch(PDOException $e) { $g_error->Add($e->getMessage()); $g_error->Add($sql); $g_error->Add(print_r($p, true)); $g_error->PrintOut(); } $numrows = $sth->fetchColumn(); $page = gpc_get_int($_REQUEST, 'p', 1); $rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp); $lastpage = ceil($numrows/$rows_pp); // Filter $opt_special = array( -2 => _('― all ―'), -1 => _('― none ―') ); ?>
Filter
prepare($sql); $sth->execute($p); $res = $sth->fetchAll(); // Pagination on top $pagination = get_pagination($g_scriptname, '', $page, $lastpage); echo $pagination; echo '', "\n"; echo "\n"; echo "\n"; echo ''; echo '"; echo '"; echo '"; echo '"; echo '"; echo ""; echo "\n"; echo "\n"; $i = 0; foreach ($res as $row) { $i++; echo "\n"; echo '\n"; echo "\n"; echo "\n"; echo '\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } // Table summary $numrows = count($res); table_rec_summary($i, $numrows, $numrows, 7); echo "
#', _('Measurement'), "', _('Note'), "', _('Measured'), "', _('Unit'), "', _('Accuracy'), "
', $i; echo ''; echo "", $row['mname'], "", $row['note'], "', format_vals($row['nval'], $row['val1'], $row['val2'], $row['val3']), "", $opt_unit[$row['unit']], "", $opt_accuracy[$row['accuracy']], ""; echo ''; echo "
\n"; echo $pagination; 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 '\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
', _('Equipment'), '', $opt_equipment[$measurement->eid], "
\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, eid " . "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';