Ejemplo n.º 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;
        }
    }
Ejemplo n.º 2
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);