function handleAuthorNode(&$journal, &$authorNode, &$issue, &$section, &$article, &$errors)
 {
     $errors = array();
     $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
     // => journal locales must be set up before
     $journalPrimaryLocale = $journal->getPrimaryLocale();
     $author = new Author();
     if ($node = $authorNode->getChildByName('firstname')) {
         $author->setFirstName($node->getValue());
     }
     if ($node = $authorNode->getChildByName('middlename')) {
         $author->setMiddleName($node->getValue());
     }
     if ($node = $authorNode->getChildByName('lastname')) {
         $author->setLastName($node->getValue());
     }
     for ($index = 0; $node = $authorNode->getChildByName('affiliation', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleAuthorAffiliationLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $author->setAffiliation($node->getValue(), $locale);
     }
     if ($node = $authorNode->getChildByName('country')) {
         $author->setCountry($node->getValue());
     }
     if ($node = $authorNode->getChildByName('email')) {
         $author->setEmail($node->getValue());
     }
     if ($node = $authorNode->getChildByName('url')) {
         $author->setUrl($node->getValue());
     }
     for ($index = 0; $node = $authorNode->getChildByName('competing_interests', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleAuthorCompetingInterestsLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $author->setCompetingInterests($node->getValue(), $locale);
     }
     for ($index = 0; $node = $authorNode->getChildByName('biography', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleAuthorBiographyLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $author->setBiography($node->getValue(), $locale);
     }
     $author->setPrimaryContact($authorNode->getAttribute('primary_contact') === 'true' ? 1 : 0);
     $article->addAuthor($author);
     // instead of $author->setSequence($index+1);
     return true;
 }
Example #2
0
 function handleAuthorNode(&$conference, &$schedConf, &$authorNode, &$track, &$paper, &$errors)
 {
     $errors = array();
     $conferenceSupportedLocales = array_keys($conference->getSupportedLocaleNames());
     // => conference locales must be set up before
     $conferencePrimaryLocale = $conference->getPrimaryLocale();
     $author = new Author();
     if ($node = $authorNode->getChildByName('firstname')) {
         $author->setFirstName($node->getValue());
     }
     if ($node = $authorNode->getChildByName('middlename')) {
         $author->setMiddleName($node->getValue());
     }
     if ($node = $authorNode->getChildByName('lastname')) {
         $author->setLastName($node->getValue());
     }
     if ($node = $authorNode->getChildByName('affiliation')) {
         $author->setAffiliation($node->getValue());
     }
     if ($node = $authorNode->getChildByName('country')) {
         $author->setCountry($node->getValue());
     }
     if ($node = $authorNode->getChildByName('email')) {
         $author->setEmail($node->getValue());
     }
     if ($node = $authorNode->getChildByName('url')) {
         $author->setUrl($node->getValue());
     }
     for ($index = 0; $node = $authorNode->getChildByName('biography', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $conferencePrimaryLocale;
         } elseif (!in_array($locale, $conferenceSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.paperAuthorBiographyLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
             return false;
         }
         $author->setBiography($node->getValue(), $locale);
     }
     $author->setPrimaryContact($authorNode->getAttribute('primary_contact') === 'true' ? 1 : 0);
     $paper->addAuthor($author);
     // instead of $author->setSequence($index+1);
     return true;
 }
 public function appendFormattedElement(&$wrapper, $data, $encode = false)
 {
     if (!is_array($data['author_id'])) {
         $data['author_id'] = array($data['author_id']);
     }
     $list = new XMLElement($this->get('element_name'));
     foreach ($data['author_id'] as $author_id) {
         $author = new Author($author_id);
         $list->appendChild(new XMLElement('item', $author->getFullName(), array('id' => (string) $author->get('id'), 'username' => General::sanitize($author->get('username')))));
     }
     $wrapper->appendChild($list);
 }
 public function __form()
 {
     require_once TOOLKIT . '/class.field.php';
     // Handle unknown context
     if (!in_array($this->_context[0], array('new', 'edit'))) {
         Administration::instance()->errorPageNotFound();
     }
     if ($this->_context[0] == 'new' && !Administration::instance()->Author->isDeveloper()) {
         Administration::instance()->customError(__('Access Denied'), __('You are not authorised to access this page.'));
     }
     if (isset($this->_context[2])) {
         switch ($this->_context[2]) {
             case 'saved':
                 $this->pageAlert(__('Author updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' . __('View all Authors') . '</a>', Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Author created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' . __('View all Authors') . '</a>', Alert::SUCCESS);
                 break;
         }
     }
     $this->setPageType('form');
     $isOwner = false;
     if (isset($_POST['fields'])) {
         $author = $this->_Author;
     } else {
         if ($this->_context[0] == 'edit') {
             if (!($author_id = $this->_context[1])) {
                 redirect(SYMPHONY_URL . '/system/authors/');
             }
             if (!($author = AuthorManager::fetchByID($author_id))) {
                 Administration::instance()->customError(__('Author not found'), __('The author profile you requested does not exist.'));
             }
         } else {
             $author = new Author();
         }
     }
     if ($this->_context[0] == 'edit' && $author->get('id') == Administration::instance()->Author->get('id')) {
         $isOwner = true;
     }
     if ($this->_context[0] == 'edit' && !$isOwner && !Administration::instance()->Author->isDeveloper()) {
         Administration::instance()->customError(__('Access Denied'), __('You are not authorised to edit other authors.'));
     }
     $this->setTitle(__($this->_context[0] == 'new' ? '%2$s &ndash; %3$s' : '%1$s &ndash; %2$s &ndash; %3$s', array($author->getFullName(), __('Authors'), __('Symphony'))));
     $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $author->getFullName());
     $this->insertBreadcrumbs(array(Widget::Anchor(__('Authors'), SYMPHONY_URL . '/system/authors/')));
     // Essentials
     $group = new XMLElement('fieldset');
     $group->setAttribute('class', 'settings');
     $group->appendChild(new XMLElement('legend', __('Essentials')));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'two columns');
     $label = Widget::Label(__('First Name'), NULL, 'column');
     $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name')));
     $div->appendChild(isset($this->_errors['first_name']) ? Widget::Error($label, $this->_errors['first_name']) : $label);
     $label = Widget::Label(__('Last Name'), NULL, 'column');
     $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name')));
     $div->appendChild(isset($this->_errors['last_name']) ? Widget::Error($label, $this->_errors['last_name']) : $label);
     $group->appendChild($div);
     $label = Widget::Label(__('Email Address'));
     $label->appendChild(Widget::Input('fields[email]', $author->get('email')));
     $group->appendChild(isset($this->_errors['email']) ? Widget::Error($label, $this->_errors['email']) : $label);
     $this->Form->appendChild($group);
     // Login Details
     $group = new XMLElement('fieldset');
     $group->setAttribute('class', 'settings');
     $group->appendChild(new XMLElement('legend', __('Login Details')));
     $div = new XMLElement('div');
     $label = Widget::Label(__('Username'));
     $label->appendChild(Widget::Input('fields[username]', $author->get('username')));
     $div->appendChild(isset($this->_errors['username']) ? Widget::Error($label, $this->_errors['username']) : $label);
     // Only developers can change the user type. Primary account should NOT be able to change this
     if (Administration::instance()->Author->isDeveloper() && !$author->isPrimaryAccount()) {
         // Create columns
         $div->setAttribute('class', 'two columns');
         $label->setAttribute('class', 'column');
         // User type
         $label = Widget::Label(__('User Type'), NULL, 'column');
         $options = array(array('author', false, __('Author')), array('developer', $author->isDeveloper(), __('Developer')));
         $label->appendChild(Widget::Select('fields[user_type]', $options));
         $div->appendChild($label);
     }
     $group->appendChild($div);
     // Password
     $fieldset = new XMLElement('fieldset', NULL, array('class' => 'two columns', 'id' => 'password'));
     $legend = new XMLElement('legend', __('Password'));
     $help = new XMLElement('i', __('Leave password fields blank to keep the current password'));
     $fieldset->appendChild($legend);
     $fieldset->appendChild($help);
     // Password reset
     if ($this->_context[0] == 'edit' && (!Administration::instance()->Author->isDeveloper() || $isOwner === true)) {
         $fieldset->setAttribute('class', 'three columns');
         $label = Widget::Label(NULL, NULL, 'column');
         $label->appendChild(Widget::Input('fields[old-password]', NULL, 'password', array('placeholder' => __('Old Password'))));
         $fieldset->appendChild(isset($this->_errors['old-password']) ? Widget::Error($label, $this->_errors['password']) : $label);
     }
     // New password
     $callback = Administration::instance()->getPageCallback();
     $placeholder = $callback['context'][0] == 'edit' ? __('New Password') : __('Password');
     $label = Widget::Label(NULL, NULL, 'column');
     $label->appendChild(Widget::Input('fields[password]', NULL, 'password', array('placeholder' => $placeholder)));
     $fieldset->appendChild(isset($this->_errors['password']) ? Widget::Error($label, $this->_errors['password']) : $label);
     // Confirm password
     $label = Widget::Label(NULL, NULL, 'column');
     $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password', array('placeholder' => __('Confirm Password'))));
     $fieldset->appendChild(isset($this->_errors['password-confirmation']) ? Widget::Error($label, $this->_errors['password']) : $label);
     $group->appendChild($fieldset);
     // Auth token
     if (Administration::instance()->Author->isDeveloper()) {
         $label = Widget::Label();
         $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox');
         if ($author->isTokenActive()) {
             $input->setAttribute('checked', 'checked');
         }
         $temp = SYMPHONY_URL . '/login/' . $author->createAuthToken() . '/';
         $label->setValue(__('%s Allow remote login via', array($input->generate())) . ' <a href="' . $temp . '">' . $temp . '</a>');
         $group->appendChild($label);
     }
     $label = Widget::Label(__('Default Area'));
     $sections = SectionManager::fetch(NULL, 'ASC', 'sortorder');
     $options = array();
     // If the Author is the Developer, allow them to set the Default Area to
     // be the Sections Index.
     if ($author->isDeveloper()) {
         $options[] = array('/blueprints/sections/', $author->get('default_area') == '/blueprints/sections/', __('Sections Index'));
     }
     if (is_array($sections) && !empty($sections)) {
         foreach ($sections as $s) {
             $options[] = array($s->get('id'), $author->get('default_area') == $s->get('id'), $s->get('name'));
         }
     }
     /**
      * Allows injection or manipulation of the Default Area dropdown for an Author.
      * Take care with adding in options that are only valid for Developers, as if a
      * normal Author is set to that option, they will be redirected to their own
      * Author record.
      *
      *
      * @delegate AddDefaultAuthorAreas
      * @since Symphony 2.2
      * @param string $context
      * '/system/authors/'
      * @param array $options
      * An associative array of options, suitable for use for the Widget::Select
      * function. By default this will be an array of the Sections in the current
      * installation. New options should be the path to the page after the `SYMPHONY_URL`
      * constant.
      * @param string $default_area
      * The current `default_area` for this Author.
      */
     Symphony::ExtensionManager()->notifyMembers('AddDefaultAuthorAreas', '/system/authors/', array('options' => &$options, 'default_area' => $author->get('default_area')));
     $label->appendChild(Widget::Select('fields[default_area]', $options));
     $group->appendChild($label);
     $this->Form->appendChild($group);
     // Custom Language Selection
     $languages = Lang::getAvailableLanguages();
     if (count($languages) > 1) {
         // Get language names
         asort($languages);
         $group = new XMLElement('fieldset');
         $group->setAttribute('class', 'settings');
         $group->appendChild(new XMLElement('legend', __('Custom Preferences')));
         $label = Widget::Label(__('Language'));
         $options = array(array(NULL, is_null($author->get('language')), __('System Default')));
         foreach ($languages as $code => $name) {
             $options[] = array($code, $code == $author->get('language'), $name);
         }
         $select = Widget::Select('fields[language]', $options);
         $label->appendChild($select);
         $group->appendChild($label);
         $this->Form->appendChild($group);
     }
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Author'), 'submit', array('accesskey' => 's')));
     if ($this->_context[0] == 'edit' && !$isOwner && !$author->isPrimaryAccount()) {
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this author'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this author?')));
         $div->appendChild($button);
     }
     $this->Form->appendChild($div);
     /**
      * Allows the injection of custom form fields given the current `$this->Form`
      * object. Please note that this custom data should be saved in own extension
      * tables and that modifying `tbl_authors` to house your data is highly discouraged.
      *
      * @delegate AddElementstoAuthorForm
      * @since Symphony 2.2
      * @param string $context
      * '/system/authors/'
      * @param XMLElement $form
      * The contents of `$this->Form` after all the default form elements have been appended.
      * @param Author $author
      * The current Author object that is being edited
      */
     Symphony::ExtensionManager()->notifyMembers('AddElementstoAuthorForm', '/system/authors/', array('form' => &$this->Form, 'author' => $author));
 }
 function __form()
 {
     require_once TOOLKIT . '/class.field.php';
     ## Handle unknow context
     if (!in_array($this->_context[0], array('new', 'edit'))) {
         $this->_Parent->errorPageNotFound();
     }
     if ($this->_context[0] == 'new' && !Administration::instance()->Author->isDeveloper()) {
         $this->_Parent->customError(E_USER_ERROR, 'Access Denied', 'You are not authorised to access this page.');
     }
     if (isset($this->_context[2])) {
         switch ($this->_context[2]) {
             case 'saved':
                 $this->pageAlert(__('Author updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Authors</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/system/authors/new/', URL . '/symphony/system/authors/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Author created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Authors</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/system/authors/new/', URL . '/symphony/system/authors/')), Alert::SUCCESS);
                 break;
         }
     }
     $this->setPageType('form');
     $isOwner = false;
     if (isset($_POST['fields'])) {
         $author = $this->_Author;
     } elseif ($this->_context[0] == 'edit') {
         if (!($author_id = $this->_context[1])) {
             redirect(URL . '/symphony/system/authors/');
         }
         if (!($author = AuthorManager::fetchByID($author_id))) {
             $this->_Parent->customError(E_USER_ERROR, 'Author not found', 'The author profile you requested does not exist.');
         }
     } else {
         $author = new Author();
     }
     if ($this->_context[0] == 'edit' && $author->get('id') == Administration::instance()->Author->get('id')) {
         $isOwner = true;
     }
     if ($this->_context[0] == 'edit' && !$isOwner && !Administration::instance()->Author->isDeveloper()) {
         $this->_Parent->customError(E_USER_ERROR, 'Access Denied', 'You are not authorised to edit other authors.');
     }
     $this->setTitle(__($this->_context[0] == 'new' ? '%1$s &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %2$s', array(__('Symphony'), __('Authors'), $author->getFullName())));
     $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $author->getFullName());
     ### Essentials ###
     $group = new XMLElement('fieldset');
     $group->setAttribute('class', 'settings');
     $group->appendChild(new XMLElement('legend', __('Essentials')));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'group');
     $label = Widget::Label(__('First Name'));
     $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name')));
     $div->appendChild(isset($this->_errors['first_name']) ? $this->wrapFormElementWithError($label, $this->_errors['first_name']) : $label);
     $label = Widget::Label(__('Last Name'));
     $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name')));
     $div->appendChild(isset($this->_errors['last_name']) ? $this->wrapFormElementWithError($label, $this->_errors['last_name']) : $label);
     $group->appendChild($div);
     $label = Widget::Label(__('Email Address'));
     $label->appendChild(Widget::Input('fields[email]', $author->get('email')));
     $group->appendChild(isset($this->_errors['email']) ? $this->wrapFormElementWithError($label, $this->_errors['email']) : $label);
     $this->Form->appendChild($group);
     ###
     ### Login Details ###
     $group = new XMLElement('fieldset');
     $group->setAttribute('class', 'settings');
     $group->appendChild(new XMLElement('legend', __('Login Details')));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'group');
     $label = Widget::Label(__('Username'));
     $label->appendChild(Widget::Input('fields[username]', $author->get('username'), NULL));
     $div->appendChild(isset($this->_errors['username']) ? $this->wrapFormElementWithError($label, $this->_errors['username']) : $label);
     // Only developers can change the user type. Primary account should NOT be able to change this
     if (Administration::instance()->Author->isDeveloper() && !$author->isPrimaryAccount()) {
         $label = Widget::Label(__('User Type'));
         $options = array(array('author', false, __('Author')), array('developer', $author->isDeveloper(), __('Developer')));
         $label->appendChild(Widget::Select('fields[user_type]', $options));
         $div->appendChild($label);
     }
     $group->appendChild($div);
     $div = new XMLElement('div', NULL, array('class' => 'group'));
     if ($this->_context[0] == 'edit') {
         $div->setAttribute('id', 'change-password');
         if (!Administration::instance()->Author->isDeveloper() || $isOwner === true) {
             $div->setAttribute('class', 'triple group');
             $label = Widget::Label(__('Old Password'));
             if (isset($this->_errors['old-password'])) {
                 $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->_errors['old-password']));
             }
             $label->appendChild(Widget::Input('fields[old-password]', NULL, 'password'));
             $div->appendChild(isset($this->_errors['old-password']) ? $this->wrapFormElementWithError($label, $this->_errors['old-password']) : $label);
         }
     }
     $label = Widget::Label($this->_context[0] == 'edit' ? __('New Password') : __('Password'));
     $label->appendChild(Widget::Input('fields[password]', NULL, 'password'));
     $div->appendChild(isset($this->_errors['password']) ? $this->wrapFormElementWithError($label, $this->_errors['password']) : $label);
     $label = Widget::Label($this->_context[0] == 'edit' ? __('Confirm New Password') : __('Confirm Password'));
     if (isset($this->_errors['password-confirmation'])) {
         $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->_errors['password-confirmation']));
     }
     $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password'));
     $div->appendChild($label);
     $group->appendChild($div);
     if ($this->_context[0] == 'edit') {
         $group->appendChild(new XMLElement('p', __('Leave password fields blank to keep the current password'), array('class' => 'help')));
     }
     if (Administration::instance()->Author->isDeveloper()) {
         $label = Widget::Label();
         $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox');
         if ($author->get('auth_token_active') == 'yes') {
             $input->setAttribute('checked', 'checked');
         }
         $temp = URL . '/symphony/login/' . $author->createAuthToken() . '/';
         $label->setValue(__('%1$s Allow remote login via <a href="%2$s">%2$s</a>', array($input->generate(), $temp)));
         $group->appendChild($label);
     }
     $label = Widget::Label(__('Default Section'));
     $sectionManager = new SectionManager($this->_Parent);
     $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder');
     $options = array();
     if (is_array($sections) && !empty($sections)) {
         foreach ($sections as $s) {
             $options[] = array($s->get('id'), $author->get('default_section') == $s->get('id'), $s->get('name'));
         }
     }
     $label->appendChild(Widget::Select('fields[default_section]', $options));
     $group->appendChild($label);
     $this->Form->appendChild($group);
     ###
     ### Custom Language Selection ###
     $languages = Lang::getAvailableLanguages(Administration::instance()->ExtensionManager);
     if (count($languages) > 1) {
         // Get language names
         asort($languages);
         $group = new XMLElement('fieldset');
         $group->setAttribute('class', 'settings');
         $group->appendChild(new XMLElement('legend', __('Custom Preferences')));
         $div = new XMLElement('div');
         $div->setAttribute('class', 'group');
         $label = Widget::Label(__('Language'));
         $options = array(array(NULL, is_null($author->get('language')), __('System Default')));
         foreach ($languages as $code => $name) {
             $options[] = array($code, $code == $author->get('language'), $name);
         }
         $select = Widget::Select('fields[language]', $options);
         $label->appendChild($select);
         $group->appendChild($label);
         $this->Form->appendChild($group);
     }
     ###
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Author'), 'submit', array('accesskey' => 's')));
     if ($this->_context[0] == 'edit' && !$isOwner && !$author->isPrimaryAccount()) {
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this author'), 'type' => 'submit'));
         $div->appendChild($button);
     }
     $this->Form->appendChild($div);
 }