Documentation is available at admin.php
- <?php
- class net_nemein_reservations_admin {
- var $_debug_prefix;
- var $_prefix;
- var $_config;
- var $_topic;
- var $_root_event;
- var $_root_group;
- var $_l10n;
- var $_l10n_midcom;
- var $_config_dm;
- var $_resource;
- var $_reservation;
- var $_mode;
- var $_auth;
- var $errcode;
- var $errstr;
- var $_local_toolbar;
- var $_topic_toolbar;
- function net_nemein_reservations_admin($topic, $config) {
- $this->_debug_prefix = "net.nemein.reservations admin::";
- $this->_prefix = $GLOBALS["midcom"]->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX);
- $this->_config = $config;
- $this->_topic = $topic;
- $this->_root_event = null;
- $this->_root_group = null;
- $this->_config_dm = null;
- $this->_mode = "";
- $this->_auth = null;
- $i18n =& $GLOBALS["midcom"]->get_service("i18n");
- $this->_l10n = $i18n->get_l10n("net.nemein.reservations");
- $this->_l10n_midcom = $i18n->get_l10n("midcom");
- $this->errcode = MIDCOM_ERROK;
- $this->errstr = "";
- $this->_local_toolbar =& $GLOBALS['midcom_admin_content_toolbar_component'];
- $this->_topic_toolbar =& $GLOBALS['midcom_admin_content_toolbar_main'];
- $this->_check_root_event();
- $this->_check_root_group();
- $this->_prepare_config_dm();
- }
- function can_handle($argc, $argv) {
- $GLOBALS["midcom"]->set_custom_context_data("configuration", $this->_config);
- $GLOBALS["midcom"]->set_custom_context_data("configuration_dm", $this->_config_dm);
- $GLOBALS["midcom"]->set_custom_context_data("root_group", $this->_root_group);
- $GLOBALS["midcom"]->set_custom_context_data("root_event", $this->_root_event);
- $GLOBALS["midcom"]->set_custom_context_data("l10n", $this->_l10n);
- $GLOBALS["midcom"]->set_custom_context_data("l10n_midcom", $this->_l10n_midcom);
- $GLOBALS["midcom"]->set_custom_context_data("errstr", $this->errstr);
- $GLOBALS["midcom"]->set_custom_context_data("auth", $this->_auth);
- $GLOBALS["midcom"]->set_custom_context_data("resource", $this->_resource);
- $GLOBALS["midcom"]->set_custom_context_data("reservation", $this->_reservation);
- $this->_auth = new net_nemein_reservations_auth();
- if ($argc == 0)
- return TRUE;
- switch ($argv[0]) {
- case "config":
- return ($argc == 1); /* config.html */
- case "resource":
- if ($argc < 2)
- return false;
- switch ($argv[1]) {
- case "create": /* resource/config.html */
- return ($argc == 2);
- case "view": /* resource/(view|edit|delete)/$id.html */
- case "edit":
- case "delete":
- return ($argc == 3);
- }
- break;
- case "reservation":
- switch ($argv[1]) {
- case "maintain": /* reservation/maintain.html */
- return ($argc == 2);
- case "approve": /* reservation/(...)/$id.html */
- case "reject":
- case "edit":
- case "delete":
- case "view":
- return ($argc == 3);
- }
- break;
- }
- return false;
- }
- function handle($argc, $argv) {
- debug_push($this->_debug_prefix . "handle");
- if (! $this->_root_event) {
- $msg = sprintf($this->_l10n->get("failed to open root event %s: %s"),
- $this->_config->get("root_event_guid"),
- mgd_errstr());
- debug_add ("Root event undefined, last midgard error was: " . mgd_errstr());
- $GLOBALS["view_contentmgr"]->msg .= "$msg<br>\n";
- }
- $this->_prep_toolbar();
- debug_pop();
- if ($argc == 0) {
- return $this->_init_welcome();
- }
- switch($argv[0]){
- case "config":
- $this->_auth->check_is_admin();
- return $this->_init_config();
- case "resource":
- switch ($argv[1]) {
- case "create":
- $this->_auth->check_is_admin();
- return $this->_init_create_resource();
- case "view":
- return $this->_init_view_resource($argv[2]);
- case "edit":
- $this->_auth->check_is_admin();
- return $this->_init_edit_resource($argv[2]);
- case "delete":
- $this->_auth->check_is_admin();
- return $this->_init_delete_resource($argv[2]);
- }
- case "reservation":
- switch ($argv[1]) {
- case "view":
- return $this->_init_view_reservation($argv[2]);
- case "edit":
- return $this->_init_edit_reservation($argv[2]);
- case "delete":
- return $this->_init_delete_reservation($argv[2]);
- case "approve":
- return $this->_init_approve_reservation($argv[2]);
- case "reject":
- return $this->_init_reject_reservation($argv[2]);
- case "maintain":
- return $this->_init_maintain_reservation();
- }
- }
- /* We should not get to this point */
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return false;
- }
- function show() {
- eval("\$this->_show_" . $this->_mode . "();");
- return TRUE;
- }
- function get_metadata() {
- return FALSE;
- }
- /******************* PAGE: Welcome ******************************/
- function _init_welcome() {
- debug_push($this->_debug_prefix . "_init_welcome");
- $this->_mode = "welcome";
- debug_pop();
- return true;
- }
- function _show_welcome() {
- midcom_show_style("admin-heading-welcome");
- $resources = net_nemein_reservations_resource::list_resources();
- foreach ($resources as $rouid => $resource) {
- $reservations = $resource->list_unapproved_reservations();
- if (count($reservations) == 0) {
- continue;
- }
- $this->_resource = $resource;
- midcom_show_style("admin-unapproved-start");
- foreach ($reservations as $resid => $reservation) {
- $this->_reservation = $reservation;
- midcom_show_style("admin-unapproved-item");
- }
- midcom_show_style("admin-unapproved-end");
- }
- }
- /******************* PAGE: Configuration ******************************/
- function _init_config() {
- debug_push($this->_debug_prefix . "_init_config");
- /* Configure toolbar */
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => '',
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('back to main'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/folder.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- switch ($this->_config_dm->process_form()) {
- case MIDCOM_DATAMGR_EDITING:
- case MIDCOM_DATAMGR_SAVED:
- case MIDCOM_DATAMGR_CANCELLED:
- // We stay here whatever happens here, at least as long as
- // there is no fatal error.
- break;
- case MIDCOM_DATAMGR_FAILED:
- $this->errstr = "Datamanager: " . $GLOBALS["midcom_errstr"];
- $this->errcode = MIDCOM_ERRCRIT;
- debug_pop();
- return false;
- }
- $this->_mode = "config";
- debug_pop();
- return true;
- }
- function _show_config() {
- midcom_show_style("admin-config");
- }
- /******************* PAGE: View Reservation ******************************/
- function _init_view_reservation($id) {
- debug_push($this->_debug_prefix . "_init_view_reservation");
- $this->_reservation = new net_nemein_reservations_reservation($id);
- if (! $this->_reservation) {
- $this->errstr = "Could not load resource, see debug log.";
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $this->_resource = $this->_reservation->resource;
- $GLOBALS["net_nemein_reservations_current_leaf"] = $this->_resource->person->id;
- /* Set toolbar */
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "resource/view/{$this->_resource->person->id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('view resource'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/view.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/edit/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit reservation'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/delete/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('delete reservation'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- if ($this->_reservation->dm->data["approved"]["timestamp"] == 0) {
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/approve/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('approve'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/approved.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/reject/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('reject and delete'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_approved.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- }
- $this->_mode = "view_reservation";
- debug_pop();
- return true;
- }
- function _show_view_reservation() {
- midcom_show_style("admin-heading-reservation-view");
- midcom_show_style("admin-dmview-reservation");
- }
- /******************* PAGE: Approve Reservation ******************************/
- function _init_approve_reservation($id) {
- debug_push($this->_debug_prefix . "_init_approve_reservation");
- $this->_reservation = new net_nemein_reservations_reservation($id);
- if (! $this->_reservation) {
- $this->errstr = "Could not load resource, see debug log.";
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $this->_resource = $this->_reservation->resource;
- $GLOBALS["net_nemein_reservations_current_leaf"] = $this->_resource->person->id;
- /* Any error is set through the reservation class at this point. */
- $this->_reservation->approve();
- /* Set toolbar */
- /* Set toolbar */
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "resource/view/{$this->_resource->person->id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('view resource'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/view.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/edit/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit reservation'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/delete/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('delete reservation'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- if ($this->_reservation->dm->data["approved"]["timestamp"] == 0) {
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/approve/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('approve'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/approved.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/reject/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('reject and delete'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_approved.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- }
- $this->_mode = "view_reservation";
- debug_pop();
- return true;
- }
- /******************* PAGE: Approve Reservation ******************************/
- function _init_reject_reservation($id) {
- debug_push($this->_debug_prefix . "_init_reject_reservation");
- $this->_reservation = new net_nemein_reservations_reservation($id);
- if (! $this->_reservation) {
- $this->errstr = "Could not load resource, see debug log.";
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $this->_resource = $this->_reservation->resource;
- $GLOBALS["net_nemein_reservations_current_leaf"] = $this->_resource->person->id;
- /* Any error is set through the reservation class at this point. */
- if ($this->_reservation->reject_and_delete()) {
- /* Success */
- $this->_relocate("resource/view/{$this->_resource->person->id}.html");
- }
- $this->errstr = "Rejection of the reseravtion failed. See debug log.";
- $this->errcode = MIDCOM_ERRCRIT;
- debug_pop();
- return false;
- }
- /******************* PAGE: Edit Reservation ******************************/
- function _init_edit_reservation($id) {
- debug_push($this->_debug_prefix . "_init_edit_reservation");
- $this->_reservation = new net_nemein_reservations_reservation($id);
- if (! $this->_reservation) {
- $this->errstr = "Could not load resource, see debug log.";
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $this->_resource = $this->_reservation->resource;
- $GLOBALS["net_nemein_reservations_current_leaf"] = $this->_resource->person->id;
- /* Set toolbar */
- $this->_local_toolbar->disable_view_page();
- /* Process form */
- switch ($this->_reservation->dm->process_form()) {
- case MIDCOM_DATAMGR_EDITING:
- debug_add("We are still editing.");
- break;
- case MIDCOM_DATAMGR_SAVED:
- case MIDCOM_DATAMGR_CANCELLED:
- debug_add("Datamanger has saved or cancelled, return to view.");
- $this->_relocate("reservation/view/{$this->_reservation->event->id}.html");
- /* This will exit() */
- case MIDCOM_DATAMGR_FAILED:
- debug_add("The DM failed critically, see above.");
- $this->errstr = "The Datamanger failed to process the request, see the Debug Log for details";
- $this->errcode = MIDCOM_ERRCRIT;
- debug_pop();
- return false;
- default:
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- debug_pop();
- return false;
- }
- $this->_mode = "edit_reservation";
- debug_pop();
- return true;
- }
- function _show_edit_reservation() {
- midcom_show_style("admin-heading-reservation-edit");
- midcom_show_style("admin-dmform-reservation");
- }
- /******************* PAGE: Delete Reservation ******************************/
- function _init_delete_reservation($id) {
- debug_push($this->_debug_prefix . "_init_delete_reservation");
- $this->_reservation = new net_nemein_reservations_reservation($id);
- if (! $this->_reservation) {
- $this->errstr = "Could not load resource, see debug log.";
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $this->_resource = $this->_reservation->resource;
- $GLOBALS["net_nemein_reservations_current_leaf"] = $this->_resource->person->id;
- /* Set toolbar */
- /* Set toolbar */
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "resource/view/{$this->_resource->person->id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('view resource'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/view.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/view/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('view reservation'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/view.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/edit/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit reservation'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- if ($this->_reservation->dm->data["approved"]["timestamp"] == 0) {
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/approve/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('approve'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/approved.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- $this->_local_toolbar->add_item(Array(
- MIDCOM_TOOLBAR_URL => "reservation/reject/${id}.html",
- MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('reject and delete'),
- MIDCOM_TOOLBAR_HELPTEXT => null,
- MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_approved.png',
- MIDCOM_TOOLBAR_ENABLED => true
- ));
- }
- if (array_key_exists("ok", $_REQUEST) && $_REQUEST["ok"] == "yes") {
- if (! $this->_reservation->delete()) {
- $this->errstr = "Failed to delete the Resoruce, see the debug log for details.";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $this->_relocate("resource/view/{$this->_resource->person->id}.html");
- /* This will exit() */
- }
- $this->_mode = "delete_reservation";
- debug_pop();
- return true;
- }
- function _show_delete_reservation() {
- midcom_show_style("admin-heading-reservation-delete");
- midcom_show_style("admin-dmview-reservation");
- }
- /******************* PAGE: View Resource ******************************/
- function _init_view_resource($id) {
- debug_push($this->_debug_prefix . "_init_view_resource");
- $this->_resource = new net_nemein_reservations_resource($id);
- if (! $this->_resource) {
- $this->errstr = "Could not load resource, see debug log.";
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $GL