Documentation is available at viewer.php
- <?php
- class net_nemein_registrations_viewer {
- var $_debug_prefix;
- var $_config;
- var $_topic;
- var $_auth;
- var $_root_event;
- var $_l10n;
- var $_l10n_midcom;
- var $_mode;
- var $_regevent;
- var $_registrar;
- var $_registration;
- var $_registrar_dm;
- var $_registration_dm;
- var $_session;
- var $_processing_msg;
- var $_regfact;
- var $_pending_grp;
- var $_registrar_grp;
- var $errcode;
- var $errstr;
- function net_nemein_registrations_viewer($topic, $config) {
- $this->_debug_prefix = "net.nemein.registrations viewer::";
- $this->_config = $config;
- $this->_topic = $topic;
- $this->_root_event = null;
- $this->_regevent = null;
- $this->_registrar = null;
- $this->_registration = null;
- $this->_registrar_dm = null;
- $this->_registration_dm = null;
- $this->_session = null;
- $this->_processing_msg = "";
- $i18n =& $GLOBALS["midcom"]->get_service("i18n");
- $this->_l10n = $i18n->get_l10n("net.nemein.registrations");
- $this->_l10n_midcom = $i18n->get_l10n("midcom");
- $this->errcode = MIDCOM_ERROK;
- $this->errstr = "";
- }
- function get_metadata() {
- return FALSE;
- }
- function can_handle($argc, $argv) {
- if ($argc == 0)
- return TRUE;
- switch($argv[0]){
- case "register":
- return ($argc >= 3);
- case "logout":
- return ($argc == 1);
- }
- return FALSE;
- }
- function handle($argc, $argv) {
- debug_push($this->_debug_prefix . "handle");
- /* Make this component uncacheable in general */
- $GLOBALS["midcom"]->cache->content->no_cache();
- $this->_auth = new net_nemein_registrations__auth($this->_topic, $this->_config);
- $this->_root_event = mgd_get_object_by_guid($this->_config->get("root_event_guid"));
- $this->_registrar_grp = mgd_get_object_by_guid($this->_config->get("account_grp"));
- if (!$this->_registrar_grp) {
- debug_add("Could not open pending account group (GUID: " . $this->_config->get("account_grp")
- . ": " . mgd_errstr());
- $this->errstr = "Could not open pending account group (GUID: " . $this->_config->get("account_grp")
- . ": " . mgd_errstr();
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $this->_pending_grp = mgd_get_object_by_guid($this->_config->get("pending_account_grp"));
- if (!$this->_pending_grp) {
- debug_add("Could not open pending account group (GUID: " . $this->_config->get("pending_account_grp")
- . ": " . mgd_errstr());
- $this->errstr = "Could not open pending account group (GUID: " . $this->_config->get("pending_account_grp")
- . ": " . mgd_errstr();
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $this->_regfact = new net_nemein_registrations_registrar_factory($this->_topic, $this->_config,
- $this->_auth, $this->_registrar_grp);
- if (! $this->_root_event) {
- $msg = sprintf($this->_l10n->get("failed to open root event"),
- $this->_config->get("root_event_guid"),
- mgd_errstr());
- debug_add ("Root event undefined, last midgard error was: " . mgd_errstr());
- $this->errstr = $msg;
- $this->errcode = MIDCOM_ERRCRIT;
- debug_pop();
- return false;
- }
- /* Start up Sessioning (call session_start only if needed) */
- if (session_id() == "")
- session_start();
- if (! array_key_exists("net.nemein.registrations", $_SESSION))
- $_SESSION["net.nemein.registrations"] = Array();
- $this->_session =& $_SESSION["net.nemein.registrations"];
- debug_print_r("Set session variable to this:", $this->_session);
- debug_pop();
- if ($argc == 0) {
- $this->_check_login();
- $this->_mode = "welcome";
- return true;
- }
- switch($argv[0]){
- case "register":
- if ($argc < 3) {
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return TRUE;
- }
- if ($argc > 3) {
- $ac = $argc - 3;
- $av = array_slice($argv, 3);
- } else {
- $ac = 0;
- $av = Array();
- }
- return $this->_init_register($argv[1], $argv[2], $ac, $av);
- case "logout":
- $this->_session = null;
- $_SESSION["net.nemein.registrations"] = Array();
- $this->_session =& $_SESSION["net.nemein.registrations"];
- debug_add("Cleared Session Variable to an empty array.");
- $this->_relocate("");
- // this will exit()
- default:
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return TRUE;
- }
- }
- /************** HANDLE DELEGATION METHODS ***************************/
- function _init_register($name, $step, $argc, $argv) {
- debug_push($this->_debug_prefix . "_init_register");
- $events = mgd_list_events($this->_root_event->id);
- if (! $events) {
- $this->errstr = sprintf($this->_l10n->get("failed to open event %s: %s"), $name, "Not Found");
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $found = false;
- while (! $found && $events->fetch()) {
- $event = mgd_get_event($events->id);
- if ($event->extra == $name)
- $found = true;
- }
- if (! $found) {
- $this->errstr = sprintf($this->_l10n->get("failed to open event %s: %s"), $name, "Not Found");
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $this->_regevent = new net_nemein_registrations_regevent($event, $this->_topic, $this->_config, $this->_auth, $this->_root_event);
- if (! $this->_regevent) {
- $this->errstr = sprintf($this->_l10n->get("failed to open event %s: %s"), $name, mgd_errstr());
- $this->errcode = MIDCOM_ERRNOTFOUND;
- debug_pop();
- return false;
- }
- $GLOBALS["net_nemein_registrations_current_leaf"] = $event->id;
- debug_add("Registration step $step now commencing...");
- debug_pop();
- switch($step){
- case "welcome": // This is the welcome page with the login field and the new registrar form
- if ($argc != 0) {
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return false;
- }
- debug_push($this->_debug_prefix . "_init_registeration_welcome");
- $ret = $this->_init_registration_welcome();
- break;
- case "create_account": // This is called if the DM is not able to save the new account immediately
- if ($argc != 1) {
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return false;
- }
- debug_push($this->_debug_prefix . "_init_registeration_create");
- $ret = $this->_init_registration_create_account($argv[0]);
- break;
- case "register":
- if ($argc > 1) {
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return false;
- }
- debug_push($this->_debug_prefix . "_init_registeration_register");
- if ($argc == 0) {
- $ret = $this->_init_registration_register();
- } else if ($argc == 1) {
- $ret = $this->_init_registration_register_id($argv[0]);
- }
- break;
- default:
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown";
- return false;
- }
- debug_pop();
- return $ret;
- }
- function _init_registration_welcome() {
- $this->_mode = "reg_welcome";
- return $this->_prep_personcreation_dm();
- }
- function _init_registration_create_account($guid) {
- $this->_registrar = mgd_get_object_by_guid($guid);
- if ($this->_registrar && $this->_registrar->__table__ != "person")
- $this->_registrar = false;
- if (!$this->_registrar) {
- $this->errcode = MIDCOM_ERRNOTFOUND;
- $this->errstr = "The id $guid is unknown.";
- return false;
- }
- $this->_registrar_dm = new midcom_helper_datamanager ($this->_config->get("schemadb"));
- if (! $this->_registrar_dm) {
- $this->errstr = "Could not create datamanager, see Logfile";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- if (!$this->_registrar_dm->init($this->_registrar)) {
- $this->errstr = "Could not initialize datamanager, see Logfile";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- // Now we have _registrar and _registrar_dm set.
- // So we go into a datamanager loop
- $this->_su();
- $result = $this->_registrar_dm->process_form();
- $this->_su(false);
- switch ($result) {
- case MIDCOM_DATAMGR_EDITING:
- $this->_mode = "create_account";
- return true;
- case MIDCOM_DATAMGR_SAVED:
- if (!$this->_check_created_account()) {
- // Stay in the edit loop
- $this->_mode = "create_account";
- return true;
- } else {
- $this->_relocate("register/" . $this->_regevent->event->extra . "/register.html");
- }
- case MIDCOM_DATAMGR_CANCELLED:
- // Delete the account
- debug_add("User cancelled the account activation process.");
- $this->_relocate("register/" . $this->_regevent->event->extra . "/welcome.html");
- case MIDCOM_DATAMGR_FAILED:
- $this->errstr = "Datamanager: " . $GLOBALS["midcom_errstr"];
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- }
- function _init_registration_register() {
- if (! $this->_check_login()) {
- debug_add("Login failed, redirecting to access denied.");
- $this->_mode = "access_denied";
- return true;
- }
- $this->_mode = "register";
- if ($this->_is_already_registered()) {
- $this->_mode = "already_registered";
- return true;
- }
- // This one will bring a creation-mode datamanager online
- // Taken basically from the example code from the new taviewer,
- // with the exception that the subsequent edit runs (if
- // neccessaray will be handled by the _init_..._register_id
- // method below to make the code clearer).
- $this->_registration_dm = new midcom_helper_datamanager ($this->_config->get("schemadb"));
- if (! $this->_registration_dm) {
- $this->errstr = "Could not create datamanager, see Logfile";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $schema = $this->_regevent->get_additional_questions_schema();
- if (! $schema) {
- $this->errstr = "Additional Questions Schema not set, this must be definied.";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- if (! $this->_registration_dm->init_creation_mode($schema, $this, "_init_registration_register_dmcallback")) {
- $this->errstr = "Could not initialize datamanager, see Logfile";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- if (! $this->_su()) {
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $result = $this->_registration_dm->process_form();
- $this->_su(false);
- switch($result) {
- case MIDCOM_DATAMGR_CREATING:
- debug_add("First call of the Datamanager, display the form like usual.");
- return true;
- case MIDCOM_DATAMGR_SAVED:
- return $this->_process_registration();
- case MIDCOM_DATAMGR_EDITING:
- $this->_session["errormsg"] = $this->_registration_dm->errstr;
- $this->_relocate( "register/" . $this->_regevent->event->extra
- . "/register/" . $this->_registration->guid()
- . ".html");
- // this will exit().
- case MIDCOM_DATAMGR_CANCELLED_NONECREATED:
- $this->_relocate("");
- // This will exit()
- case MIDCOM_DATAMGR_FAILED:
- case MIDCOM_DATAMGR_CREATEFAILED:
- // there was sth. really wrong, we show the welcome view to get the error messages displayed.
- $this->errstr = "Datamanager failed critically:" . $this->_registration_dm->errstr;
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- default:
- // This should not happen
- $this->errcode = MIDCOM_ERRCRIT;
- $this->errstr = "Method unknown.";
- return false;
- }
- // We should not get here.
- }
- function _init_registration_register_dmcallback (&$datamanager) {
- $result = Array (
- "success" => true,
- "storage" => null
- );
- // No su here, the callee already should do this anyway, as this
- // is called out of datamanager::process_form
- $id = mgd_create_event_member($this->_regevent->event->id, $this->_registrar->id, "");
- if (!$id) {
- debug_add("This is really strange, we could not create anything:" . mgd_errstr());
- return null;
- }
- $this->_registration = mgd_get_event_member($id);
- $result["storage"] =& $this->_registration;
- return $result;
- }
- function _init_registration_register_id($guid) {
- if (! $this->_check_login()) {
- debug_add("Login failed, redirecting to access denied.");
- $this->_mode = "access_denied";
- return true;
- }
- $this->_mode = "register";
- // This one will bring a creation-mode datamanager online
- // Taken basically from the example code from the new taviewer,
- // with the exception that the subsequent edit runs (if
- // neccessaray will be handled by the _init_..._register_id
- // method below to make the code clearer).
- $this->_registration = mgd_get_object_by_guid($guid);
- if ($this->_registration && $this->_registration->__table__ != "eventmember")
- $this->_registration = false;
- if (! $this->_registration) {
- debug_add("Could not open temporary event member object: " . mgd_errstr());
- $this->errstr = "Could not open event member record &guid. See debug log.";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $this->_registration_dm = new midcom_helper_datamanager ($this->_config->get("schemadb"));
- if (! $this->_registration_dm) {
- $this->errstr = "Could not create datamanager, see Logfile";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- if (! $this->_registration_dm->init($this->_registration)) {
- $this->errstr = "Could not initialize datamanager, see Logfile";
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- if (! $this->_su()) {
- $this->errcode = MIDCOM_ERRCRIT;
- return false;
- }
- $result = $this->_registration_dm->process_form();
- $this->_su(false);
- switch($result) {
- case MIDCOM_DATAMGR_EDITING:
- return true;
- case MIDCOM_DATAMGR_SAVED:
- return $this->_process_registration();
- case MIDCOM_DATAMGR_CANCELLED:
- $this->_su();
- $this->_registration->delete();
- $this->_su(false);
- $this->_relocate("");
- // This will exit()
- case MIDCOM_DATAMGR_FAILED:
- $this->errstr = "Datamanager: " . $GLOBALS["midcom_errstr"];
- $this->errcode = MIDCOM_ERRCRIT;
- return FALSE;
- }
- }
- /*** MAIN SHOW HANDLER ***/
- function show() {
- $GLOBALS["view_msg"] =& $this->_processing_msg;
- $GLOBALS["view_l10n"] =& $this->_l10n;
- $GLOBALS["view_l10n_midcom"] =& $this->_l10n_midcom;
- $GLOBALS["view_config"] =& $this->_config;
- $GLOBALS["view_topic"] =& $this->_topic;
- $GLOBALS["view_auth"] =& $this->_auth;
- $GLOBALS["view_regevent"] =& $this->_regevent;
- $GLOBALS["view_registrar"] =& $this->_registrar;
- $GLOBALS["view_registrar_dm"] =& $this->_registrar_dm;
- $GLOBALS["view_registration"] =& $this->_registration;
- $GLOBALS["view_registration_dm"] =& $this->_registration_dm;
- if (is_object($this->_regevent))
- $GLOBALS["view_event"] =& $this->_regevent->event;
- else
- $GLOBALS["view_event"] = null;
- if (array_key_exists("errormsg", $this->_session)) {
- $GLOBALS["view_errstr"] = $this->_session["errormsg"];
- unset($this->_session["errormsg"]);
- } else {
- $GLOBALS["view_errstr"] = "";
- }
- eval("\$this->_show_" . $this->_mode . "();");
- return TRUE;
- }
- /************** SHOW MODE METHODS ***************************/
- function _show_welcome() {
- midcom_show_style("welcome-begin");
- $elist = new net_nemein_registrations_eventlist($this->_topic, $this->_config, $this->_auth, $this->_root_event);
- $events = $elist->query();
- if (count($events) == 0) {
- midcom_show_style("welcome-nonefound");
- } else {
- foreach ($events as $id => $event) {
- $GLOBALS["view_event"] =& $event;
- $regevent = $elist->get_regevent($event);
- if ($regevent->is_open())
- $GLOBALS["view_open"] = true;
- else
- $GLOBALS["view_open"] = false;
- if ($GLOBALS["view_open"] && ! is_null ($this->_registrar)) {
- $regs = mgd_list_event_members($event->id);
- $registrars = Array();
- if ($regs)
- while($regs->fetch())
- $registrars[] = $regs->uid;
- $GLOBALS["view_already_registered"] = in_array($this->_registrar->id, $registrars);
- } else {
- $GLOBALS["view_already_registered"] = false;
- }
- midcom_show_style("welcome-item");
- }
- }
- midcom_show_style("welcome-end");
- }
- function _show_reg_welcome() {
- midcom_show_style("registration-step-welcome");
- }
- function _show_access_denied() {
- midcom_show_style("access-denied");
- }
- function _show_create_account() {
- midcom_show_style("registration-step-create-account");
- }
- function _show_register() {
- midcom_show_style("registration-step-register");
- }
- function _show_registration_complete() {
- midcom_show_style("registration-complete");
- }
- function _show_already_registered() {
- midcom_show_style("registration-already-registered");
- }
- /************** PRIVATE HELPER METHODS **********************/
- function _su ($on = true) {
- if ($on) {
- if (! mgd_auth_midgard ($this->_config->get("admin_user"), $this->