Revisit template management page

Arrange templates in a group by their respective use in the system:

  * System Management Templates
  * Staff Ticket Templates (Alerts and Notices)
  * End-User Ticket Templates (Autoresponder)

This provides an interface to sort the templates and make them easier to
find and provides a nice place for new templates to be added without making
it increasingly more difficult to locate templates in the list.

This patch also fixes the missing templates in the drop-down list when
editing an implemented template.
Use config URL instead of THISPAGE

THISPAGE is unreliable for CLI cron calls. It was historically used so the
admin could figure out which file/page generated the error. But with
backtrace support we no longer need it.
Merge pull request #412 from protich/issue/baseurl

Use config URL instead of THISPAGE

Reviewed-By: Jared Hancock <jared@osticket.com>
Drop the cdata table on field type change

If a field on the ticket details form changes type, recreate the cdata table
Merge pull request #413 from greezybacon/issue/drop-cdata-on-type-change

Drop the data table on field type change

Reviewed-By: Peter Rotich <peter@osticket.com>
Don't update the session unless it changes

And deadband session token updates to 1 per 30 seconds
Don't fetch ticket thread unless necessary
Don't generate staff statistics for AJAX requests
Periodically optimize core tables

This is instead of optimizing the lock table for every cron run, which
wastes a lot of db server io
Merge pull request #415 from greezybacon/db-perf-tweaks

Several database performance tweaks

Reviewed-By: Peter Rotich <peter@osticket.com>
cdata: Only apply updates to ticket details

If the entry answer being updated does not affect the ticket details form
(with type=T), then the updates do not need to be applied to the
ticket__cdata table.
Fix cdata fields in advanced search
Fetch thread before deleting ticket
Ensure a ROOT_PATH is defined for CLI apps
Disambiguate `status` field on ticket queue view
Make using `realpath` safer
filters: Unpack the user information before filter

If a user is created / selected before opening a ticket (very likely the
case in the SCP), the email address and name should be unpacked into the
$vars dictionary prior to creating and processing ticket filters
Merge pull request #425 from greezybacon/issue/filter-deny-scp

filters: Unpack the user information before filter

Reviewed-By: Peter Rotich <peter@osticket.com>
forms: Allow decl of promt and default for choices

Allow the administrator to enter a prompt to be shown in the choices
drop-down for choice fields. Also add the option of selecting a default
value from the list initially rather than displaying a prompt.
Merge pull request #421 from greezybacon/issue/420

Ensure a ROOT_PATH is defined for CLI apps

Reviewed-By: Peter Rotich <peter@osticket.com>