/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_delete($handler_id, array $args, array &$data) { // Check if we get the person $this->_person = new midcom_db_person($args[0]); $this->_person->require_do('midgard:update'); if ($this->_person->id != midcom_connection::get_user()) { midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface'); } $this->_account = new midcom_core_account($this->_person); if (!$this->_account->get_username()) { // Account needs to be created first, relocate return new midcom_response_relocate("view/" . $this->_person->guid . "/"); } $data['controller'] = midcom_helper_datamanager2_handler::get_delete_controller(); switch ($data['controller']->process_form()) { case 'delete': if (!$this->_account->delete()) { throw new midcom_error("Failed to delete account for {$this->_person->guid}, last Midgard error was: " . midcom_connection::get_error_string()); } //Fall-through //Fall-through case 'cancel': return new midcom_response_relocate('view/' . $this->_person->guid . "/"); } $this->add_stylesheet(MIDCOM_STATIC_URL . "/midcom.helper.datamanager2/legacy.css"); midcom::get('head')->enable_jquery(); midcom::get('head')->set_pagetitle("{$this->_person->firstname} {$this->_person->lastname}"); $this->_prepare_request_data(); $this->_update_breadcrumb_line('delete account'); // Add toolbar items org_openpsa_helpers::dm2_savecancel($this, 'delete'); }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_privileges($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); // Check if we get the person $this->_person = new midcom_db_person($args[0]); $this->_person->require_do('midgard:privileges'); $this->_request_data['person'] =& $this->_person; $data['acl_dm'] = $this->get_controller('simple', $this->_person); switch ($data['acl_dm']->process_form()) { case 'save': // Fall-through // Fall-through case 'cancel': return new midcom_response_relocate(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . "view/" . $this->_person->guid . "/"); } midcom::get('head')->set_pagetitle("{$this->_person->name}"); org_openpsa_helpers::dm2_savecancel($this); $this->add_breadcrumb("view/{$this->_person->guid}/", $this->_person->name); $this->add_breadcrumb('', $this->_l10n->get('permissions')); }
/** * AJAX backend for saving data on the fly * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _handler_ajax($handler_id, array $args, array &$data) { $this->_person = new midcom_db_person(midcom_connection::get_user()); // Check for the ACL's $this->_person->require_do('midgard:update'); // Patch for Midgard ACL problem of setting person's own parameters midcom::get('auth')->request_sudo('midgard.admin.asgard'); foreach ($_POST as $key => $value) { if (is_array($value)) { $value = serialize($value); } if (!$this->_person->set_parameter('midgard.admin.asgard:preferences', $key, $value)) { $this->_status = false; midcom::get('uimessages')->add(midcom::get('i18n')->get_string('midgard.admin.asgard', 'midgard.admin.asgard'), sprintf(midcom::get('i18n')->get_string('failed to save the preference for %s', 'midgard.admin.asgard'), midcom::get('i18n')->get_string($key, 'midgard.admin.asgard'))); } debug_add("Added configuration key-value pair {$key} => {$value}"); } midcom::get('auth')->drop_sudo(); }
/** * can be called by various handlers * * @param string password: leave blank for auto generated */ public function create_account($person_guid, $username, $usermail, $password = "", $send_welcome_mail = false, $auto_relocate = true) { //quick validation if (empty($person_guid)) { $this->errstr = "cannot identify user: no guid given"; return false; } if (empty($username)) { $this->errstr = "cannot create account: no username given"; return false; } if ($send_welcome_mail && empty($usermail)) { $this->errstr = "cannot deliver welcome mail: no usermail adress given"; return false; } // Check if we get the person $this->_person = new midcom_db_person($person_guid); $this->_person->require_do('midgard:update'); //need to generate password? if (empty($password)) { $generated_password = true; $password = $this->generate_safe_password($this->_config->get("min_password_length")); } else { $generated_password = false; } $this->_account = new midcom_core_account($this->_person); //an account already existing? if ($this->_account->get_password()) { $this->errstr = "Creating new account for existing account is not possible"; return false; } //try creating $success = $this->set_account($username, $password); if (!$success) { $this->errstr = "couldnt set account, reason: " . $this->errstr; return false; } //send welcome mail? if ($send_welcome_mail) { $mail = new org_openpsa_mail(); $mail->to = $usermail; $mail->from = $this->_config->get('welcome_mail_from_address'); $mail->subject = $this->_config->get('welcome_mail_title'); $mail->body = $this->_config->get('welcome_mail_body'); // Make replacements to body $mail->parameters = array("USERNAME" => $username, "PASSWORD" => $password); if (!$mail->send()) { $this->errstr = "Unable to deliver welcome mail: " . $mail->get_error_message(); return false; } } else { /* * no welcome mail was sent: * if the password was auto generated show it in an ui message */ if ($generated_password) { midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), sprintf($this->_l10n->get("account_creation_success"), $username, $password), 'ok'); } } if ($auto_relocate) { // Relocate to group view $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); midcom::get()->relocate("{$prefix}view/{$this->_person->guid}/"); // This will exit } else { if (!empty($this->errstr)) { throw new midcom_error('Could not create account: ' . $this->errstr); } return true; } }