Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * During the copying of a view, we might be allowed to copy
  * blogposts but not the containing blog.  We need to create a new
  * blog to hold the copied posts.
  */
 public function default_parent_for_copy(&$view, &$template, $artefactstoignore)
 {
     static $blogids;
     global $USER, $SESSION;
     $viewid = $view->get('id');
     if (isset($blogids[$viewid])) {
         return $blogids[$viewid];
     }
     $blogname = get_string('viewposts', 'artefact.blog', $viewid);
     $data = (object) array('title' => $blogname, 'description' => get_string('postscopiedfromview', 'artefact.blog', $template->get('title')), 'owner' => $view->get('owner'), 'group' => $view->get('group'), 'institution' => $view->get('institution'));
     $blog = new ArtefactTypeBlog(0, $data);
     $blog->commit();
     $blogids[$viewid] = $blog->get('id');
     if (!empty($data->group) || !empty($data->institution)) {
         $SESSION->add_ok_msg(get_string('copiedblogpoststonewjournal', 'collection'));
     } else {
         try {
             $user = get_user($view->get('owner'));
             set_account_preference($user->id, 'multipleblogs', 1);
             $SESSION->add_ok_msg(get_string('copiedblogpoststonewjournal', 'collection'));
         } catch (Exception $e) {
             $SESSION->add_error_msg(get_string('unabletosetmultipleblogs', 'error', $user->username, $viewid, get_config('wwwroot') . 'account/index.php'), false);
         }
         try {
             $USER->accountprefs = load_account_preferences($user->id);
         } catch (Exception $e) {
             $SESSION->add_error_msg(get_string('pleaseloginforjournals', 'error'));
         }
     }
     return $blogids[$viewid];
 }
Exemplo n.º 4
0
 /**
  * During the copying of a view, we might be allowed to copy
  * blogposts but not the containing blog.  We need to create a new
  * blog to hold the copied posts.
  */
 public function default_parent_for_copy(&$view, &$template, $artefactstoignore)
 {
     static $blogid;
     if (!empty($blogid)) {
         return $blogid;
     }
     $blogname = get_string('viewposts', 'artefact.blog', $view->get('id'));
     $data = (object) array('title' => $blogname, 'description' => get_string('postscopiedfromview', 'artefact.blog', $template->get('title')), 'owner' => $view->get('owner'), 'group' => $view->get('group'), 'institution' => $view->get('institution'));
     $blog = new ArtefactTypeBlog(0, $data);
     $blog->commit();
     $blogid = $blog->get('id');
     return $blogid;
 }