示例#1
0
    public function __construct()
    {
        parent::__construct('batch_add_authors');
        if ($this->loginError) {
            return;
        }
        $this->use_mootools = true;
        $form = new HTML_QuickForm('batch_add', 'post', null, '_self', 'multipart/form-data');
        $tooltip = <<<TOOLTIP_END
New Authors::A semi-colon separated list of author names. Names can be in the following
formats:
&lt;ul&gt;
  &lt;li&gt;fist last&lt;/li&gt;
  &lt;li&gt;fist initials last&lt;/li&gt;
  &lt;li&gt;last, first&lt;/li&gt;
  &lt;li&gt;last, first initials&lt;/li&gt;
&lt;/ul&gt;
TOOLTIP_END;
        $form->addGroup(array(HTML_QuickForm::createElement('textarea', 'new_authors', null, array('cols' => 60, 'rows' => 10)), HTML_QuickForm::createElement('static', 'kwgroup_help', null, '<span class="small">Name format is: GIVEN_NAME1 [GIVEN_NAME2 .. etc.] LAST_NAME. Separate using semi-colons (;)</span>')), 'new_auth_group', "<span class=\"Tips1\" title=\"{$tooltip}\">New Authors:</span>", '<br/>', false);
        $form->addGroup(array(HTML_QuickForm::createElement('submit', 'submit', 'Add New Authors'), HTML_QuickForm::createElement('button', 'cancel', 'Cancel', array('onclick' => 'history.back()'))), null, null, '&nbsp;', false);
        if ($form->validate()) {
            $values = $form->exportValues();
            $values['new_authors'] = preg_replace("/;\\s*;/", ';', $values['new_authors']);
            $new_authors = preg_split('/;\\s*/', $values['new_authors']);
            $fl_auth_list = pdAuthorList::create($this->db, null, null, true);
            $in_db_auths = array_intersect($fl_auth_list, $new_authors);
            $new_auths = array_diff($new_authors, $fl_auth_list);
            foreach ($new_auths as $auth_name) {
                $auth = new pdAuthor();
                $auth->nameSet($auth_name);
                $auth->dbSave($this->db);
                unset($auth);
            }
            if (count($in_db_auths) > 0) {
                echo 'These authors were already in the database:<ul>';
                foreach ($in_db_auths as $auth_name) {
                    echo '<li>', $auth_name, '</li>';
                }
            }
            if (count($new_auths) > 0) {
                if (count($in_db_auths) > 0) {
                    echo '</ul>', 'Only these authors were added to the database:', '<ul>';
                } else {
                    echo 'These authors were added to the database:<ul>';
                }
                foreach ($new_auths as $auth_name) {
                    echo '<li>', $auth_name, '</li>';
                }
                echo '</ul>';
            } else {
                echo '</ul>No authors were added to the database.';
            }
        } else {
            echo '<h2>Batch Add Authors</h2>';
            $renderer =& $form->defaultRenderer();
            $form->setRequiredNote('<font color="#FF0000">*</font> shows the required fields.');
            $form->accept($renderer);
            $this->form =& $form;
            $this->renderer =& $renderer;
            $this->js = <<<JS_END
window.addEvent('domready', function() {
                    var Tips1 = new Tips(\$\$('.Tips1'));
                });
JS_END;
        }
    }
示例#2
0
 public function processForm()
 {
     $form =& $this->form;
     $values =& $form->exportValues();
     // check if user pressed "Next Step >>" button and did not enter
     // a name
     if (isset($values['next_step']) && isset($_SESSION['state']) && $_SESSION['state'] == 'pub_add') {
         if ((!isset($values['firstname']) || $values['firstname'] == '') && (!isset($values['lastname']) || $values['lastname'] == '')) {
             header('Location: add_pub3.php');
             return;
         }
     }
     // if user has not entered a name then bring
     if (isset($values['add_another']) && isset($_SESSION['state']) && $_SESSION['state'] == 'pub_add') {
         if ((!isset($values['firstname']) || $values['firstname'] == '') && (!isset($values['lastname']) || $values['lastname'] == '')) {
             header('Location: add_author.php');
             return;
         }
     }
     $author = new pdAuthor();
     if ($this->author_id != null) {
         $author->author_id = $this->author_id;
     }
     $author->name = $values['lastname'] . ', ' . $values['firstname'];
     $author->firstname = $values['firstname'];
     $author->lastname = $values['lastname'];
     $author->title = $values['title'];
     $author->email = $values['email'];
     $author->organization = $values['organization'];
     $author->webpage = $values['webpage'];
     $author->interests = array();
     if (isset($values['interests']) && count($values['interests']) > 0) {
         foreach ($values['interests'] as $int_id) {
             $author->interests[$int_id] = $this->all_interests[$int_id];
         }
     }
     if (isset($values['newInterests']) && count($values['newInterests']) > 0) {
         $author->interests = array_merge($author->interests, $values['newInterests']);
     }
     // check if an author with a similar name already exists
     if ($this->author_id == null) {
         $like_authors = pdAuthorList::create($this->db, $values['firstname'], $values['lastname']);
         if (count($like_authors) > 0) {
             $_SESSION['new_author'] = $author;
             header('Location: author_confirm.php');
             return;
         }
     }
     $author->dbSave($this->db);
     if (isset($_SESSION['state']) && $_SESSION['state'] == 'pub_add') {
         assert('isset($_SESSION["pub"])');
         $pub =& $_SESSION['pub'];
         $pub->addAuthor($this->db, $author->author_id);
         if ($this->debug) {
             return;
         }
         if (isset($values['finish'])) {
             header('Location: add_pub_submit.php');
         } else {
             if (isset($values['add_another'])) {
                 header('Location: add_author.php');
             } else {
                 header('Location: add_pub2.php');
             }
         }
         return;
     }
     header('Location: ../view_author.php?author_id=' . $author->author_id);
 }
示例#3
0
David Horn,
Kimmen Sjölander,
Steven L. Salzberg,
Dennis Vitkup,
Stanley Letovsky,
Daniel Segrè,
Charles DeLisi,
Richard J. Roberts,
Martin Steffen,
Simon Kasif
AUTHORS_NEW_END;
$db = new pdDb(array('server' => "localhost", 'user' => "dummy", 'passwd' => "ozzy498", 'name' => "pubdbdev"));
// this array contains the names in the format: FIRST OTHER LAST
$authors_in_db = pdAuthorList::create($db, null, null, true);
var_dump($authors_in_db);
$authors = array();
foreach (explode(',', $authors_new_raw) as $author_name) {
    if (in_array($author_name, $authors_in_db)) {
        exit("author {$author_name} already exists in the database");
    }
    $author = new pdAuthor();
    $author->nameSet($author_name);
    $authors[] = $author;
}
print "adding " . count($authors) . " new authors...\n";
// none of the authors already exist in the database, they can be saved
foreach ($authors as $author) {
    $author->dbSave($db);
}
print "new authors added.\n";
//var_dump($authors);