function requiredfields_submit(Pieform $form, $values) { global $USER, $SESSION; if (isset($values['password1'])) { $authobj = AuthFactory::create($USER->authinstance); // This method should exist, because if it did not then the change // password form would not have been shown. if ($password = $authobj->change_password($USER, $values['password1'])) { $SESSION->add_ok_msg(get_string('passwordsaved')); } else { throw new SystemException('Attempt by "' . $USER->get('username') . '@' . $USER->get('institution') . 'to change their password failed'); } } if (isset($values['username'])) { $SESSION->set('resetusername', false); if ($values['username'] != $USER->get('username')) { $USER->username = $values['username']; $USER->commit(); $otherfield = true; } } if (isset($values['state'])) { $current_app_name = explode(".", $_SERVER["HTTP_HOST"]); $current_app_short_name = $current_app_name[0]; $current_app_short_name = str_replace("http://", "", $current_app_short_name); $current_app_short_name = str_replace("https://", "", $current_app_short_name); Doctrine_Query::create()->update('GcrUsers')->set('state', '?', $values['state'])->set('country', '?', $values['country'])->where('platform_short_name = ?', $current_app_short_name)->andWhere('user_id = ?', $USER->get('id'))->execute(); } if (isset($values['socialprofile_hidden']) && $values['socialprofile_hidden']) { // Socialprofile fields. Save them on their own as they are a fieldset. set_profile_field($USER->get('id'), 'socialprofile', $values); $otherfield = true; } foreach ($values as $field => $value) { if (in_array($field, array('submit', 'sesskey', 'password1', 'password2', 'username', 'socialprofile_service', 'socialprofile_profiletype', 'socialprofile_profileurl', 'socialprofile_hidden', 'state', 'country'))) { continue; } if ($field == 'email') { $email = $values['email']; // Need to update the admin email on installation if ($USER->get('admin')) { $oldemail = get_field('usr', 'email', 'id', $USER->get('id')); if ($oldemail == '*****@*****.**') { // we are dealing with the dummy email that is set on install update_record('usr', array('email' => $email), array('id' => $USER->get('id'))); update_record('artefact_internal_profile_email', array('email' => $email), array('owner' => $USER->get('id'))); } } // Check if a validation email has been sent, if not send one if (!record_exists('artefact_internal_profile_email', 'owner', $USER->get('id'))) { $key = get_random_key(); $key_url = get_config('wwwroot') . 'artefact/internal/validate.php?email=' . rawurlencode($email) . '&key=' . $key; $key_url_decline = $key_url . '&decline=1'; try { $sitename = get_config('sitename'); email_user((object) array('id' => $USER->get('id'), 'username' => $USER->get('username'), 'firstname' => $USER->get('firstname'), 'lastname' => $USER->get('lastname'), 'preferredname' => $USER->get('preferredname'), 'admin' => $USER->get('admin'), 'staff' => $USER->get('staff'), 'email' => $email), null, get_string('emailvalidation_subject', 'artefact.internal'), get_string('emailvalidation_body1', 'artefact.internal', $USER->get('firstname'), $email, $sitename, $key_url, $sitename, $key_url_decline)); } catch (EmailException $e) { $SESSION->add_error_msg($email); } insert_record('artefact_internal_profile_email', (object) array('owner' => $USER->get('id'), 'email' => $email, 'verified' => 0, 'principal' => 1, 'key' => $key, 'expiry' => db_format_timestamp(time() + 86400))); $SESSION->add_ok_msg(get_string('validationemailsent', 'artefact.internal')); } } else { set_profile_field($USER->get('id'), $field, $value); $otherfield = true; } } if (isset($otherfield)) { $SESSION->add_ok_msg(get_string('requiredfieldsset', 'auth')); } // Update the title of user's first blog if first and/or last name have been changed $updatedfields = array_keys($values); if (in_array('firstname', $updatedfields) || in_array('lastname', $updatedfields)) { safe_require('artefact', 'blog'); $userblogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($USER->get('id'))); if ($userblogs && count($userblogs) == 1) { $defaultblog = new ArtefactTypeBlog($userblogs[0]->id); $defaultblog->set('title', get_string('defaultblogtitle', 'artefact.blog', display_name($USER, null, true))); $defaultblog->commit(); } } redirect(); }
/** * This function creates a new blog. * * @param User or null * @param array */ public static function new_blog($user, array $values) { require_once 'embeddedimage.php'; db_begin(); $artefact = new ArtefactTypeBlog(); $artefact->set('title', $values['title']); $artefact->set('description', $values['description']); if (!empty($values['institution'])) { $artefact->set('institution', $values['institution']); } else { if (!empty($values['group'])) { $artefact->set('group', $values['group']); } else { $artefact->set('owner', $user->get('id')); } } $artefact->set('tags', $values['tags']); if (get_config('licensemetadata')) { $artefact->set('license', $values['license']); $artefact->set('licensor', $values['licensor']); $artefact->set('licensorurl', $values['licensorurl']); } $artefact->commit(); $blogid = $artefact->get('id'); $newdescription = EmbeddedImage::prepare_embedded_images($artefact->get('description'), 'blog', $blogid); $artefact->set('description', $newdescription); db_commit(); }
/** * This function updates an existing blog. * * @param User * @param array */ public static function edit_blog(User $user, array $values) { require_once 'embeddedimage.php'; if (empty($values['id']) || !is_numeric($values['id'])) { return; } $artefact = new ArtefactTypeBlog($values['id']); if ($user->get('id') != $artefact->get('owner')) { return; } $artefact->set('title', $values['title']); $newdescription = EmbeddedImage::prepare_embedded_images($values['description'], 'blog', $values['id']); $artefact->set('description', $newdescription); $artefact->set('tags', $values['tags']); if (get_config('licensemetadata')) { $artefact->set('license', $values['license']); $artefact->set('licensor', $values['licensor']); $artefact->set('licensorurl', $values['licensorurl']); } $artefact->commit(); }
/** * Creates a catch-all blog if one doesn't exist already * * @param PluginImportLeap $importer The importer * @return int The artefact ID of the catch-all blog */ private static function ensure_catchall_blog(PluginImportLeap $importer) { static $blogid = null; if (is_null($blogid)) { $time = time(); // TODO maybe the importer will get a time field to record time of import $blog = new ArtefactTypeBlog(); $title = $importer->get('xml')->xpath('//a:feed/a:title'); $blog->set('title', get_string('dataimportedfrom', 'artefact.blog', (string) $title[0])); $blog->set('description', get_string('entriesimportedfromleapexport', 'artefact.blog')); $blog->set('owner', $importer->get('usr')); $blog->set('ctime', $time); $blog->set('mtime', $time); $blog->commit(); $blogid = $blog->get('id'); } return $blogid; }
/** * This function updates an existing blog. * * @param User * @param array */ public static function edit_blog(User $user, array $values) { if (empty($values['id']) || !is_numeric($values['id'])) { return; } $artefact = new ArtefactTypeBlog($values['id']); if ($user->get('id') != $artefact->get('owner')) { return; } $artefact->set('title', $values['title']); $artefact->set('description', $values['description']); $artefact->set('tags', $values['tags']); $artefact->commit(); }