Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } unset($_SESSION['token']); // get information for redirect $sth = $pdo->prepare("SELECT notetype, refid FROM note WHERE noteid=?"); $sth->execute([$id]); $note = $sth->fetch(PDO::FETCH_OBJ); if ($note->notetype == 'task') { $backlink = 'task.php'; } else { $backlink = 'maintenance.php'; } $backlink .= '?f=view&id='. $note->refid; // now really delete $sth = $pdo->prepare("DELETE FROM note WHERE noteid=?"); $sth->execute([$id]); header_location($backlink, ['info' => _('Note deleted.')]); break; default: $g_error->Add(sprintf(_("Unknown function '%s'!"), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= echo '

', $pagetitle, "

\n"; $sql = "SELECT n.noteid, n.notetype, n.refid," . " IF(CHAR_LENGTH(n.annotation) > 60, CONCAT(LEFT(n.annotation, 60), '…'), n.annotation) AS annotation " . "FROM note AS n JOIN task AS t ON (n.notetype='task' AND n.refid=t.taskid AND t.vid=:vid) " . "UNION " . "SELECT n.noteid, n.notetype, n.refid," . " IF(CHAR_LENGTH(n.annotation) > 60, CONCAT(LEFT(n.annotation, 60), '…'), n.annotation) AS annotation " . "FROM note AS n JOIN maintenance AS m ON (n.notetype='maint' AND n.refid=m.maintid AND m.vid=:vid) " . "ORDER BY noteid"; $sth = $pdo->prepare($sql); $sth->execute([':vid' => $user->vid]); $res = $sth->fetchAll(); ?> \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; form_action_buttons($g_scriptname, $row['noteid']); echo "\n"; } // Table summary echo "\n"; echo '', "\n"; echo "\n"; echo "
", $row['noteid'], "", $row['refid'], "", $row['notetype'], "", $row['annotation'], "
', sprintf(_('%d records'), count($res)), '
\n"; elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= echo '

', _('Add Note'), "

\n"; $notetype = gpc_get_enum($_REQUEST, 't', $opt_notetype); // get task info for reference if ($notetype == 'task') { $sql = "SELECT taskname FROM task WHERE taskid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $taskname = $sth->fetchColumn(); echo '

', sprintf(_('Task: %s'), $taskname), "

\n"; } elseif ($notetype == 'maint') { $sql = "SELECT activities FROM maintenance WHERE maintid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $activities = $sth->fetchColumn(); echo '

', sprintf(_('Maintenance: %s'), $activities), "

\n"; } ?>
', _('View Note'), "\n"; $sql = "SELECT refid, notetype, annotation FROM note WHERE noteid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $note = $sth->fetch(PDO::FETCH_OBJ); // TODO // view annotation // edit button // list where annotaion used echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Reference'),"", $note->refid, "
', _('Type'),"", $note->notetype, "
', _('Annotation'),"", nl2br($note->annotation), "
\n"; $link = $note->notetype == 'task' ? 'task.php' : 'maintenance.php'; // echo '

', _('Parent'), "

\n"; form_view_buttons($g_scriptname, $id, $link.'?f=view&id='.$note->refid); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT refid, notetype, annotation FROM note WHERE noteid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $note = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Edit Note'), "

\n"; ?>
\n"; elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== $sql = "SELECT notetype, annotation FROM note WHERE noteid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $note = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Delete Note'), "

\n"; echo '

', sprintf(_('Record no. %d'), $id), "

\n"; echo '

', $note->annotation, "

"; echo '

', _('Deleting an note item is final. There is no way back. Only delete if you are absolute sure.'), "

\n"; $_SESSION['token'] = bin2hex(random_bytes(8)); form_delete_buttons($g_scriptname, $id, $_SESSION['token']); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

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

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