/** * Creates the from used on this page. The renderer is then used to * display the form correctly on the page. */ private function createForm() { $user = null; $form = new HTML_QuickForm('advSearchForm', 'get', 'search_publication_db.php', '_self', array('onsubmit' => 'return check_authors("advSearchForm");')); $form->addElement('text', 'title', 'Title:', array('size' => 60, 'maxlength' => 250)); $form->addElement('text', 'venue', 'Venue:', array('size' => 60, 'maxlength' => 250)); $form->addElement('select', 'cat_id', 'Category:', array('' => '-- All Categories --') + pdCatList::create($this->db)); $form->addElement('text', 'abstract', 'Abstract:', array('size' => 60, 'maxlength' => 250)); $auth_list = pdAuthorList::create($this->db); if ($this->access_level > 0 && $_SESSION['user']->author_id != '') { $user =& $_SESSION['user']; unset($auth_list[$user->author_id]); } $form->addElement('textarea', 'authors', 'Authors:', array('cols' => 60, 'rows' => 5, 'class' => 'wickEnabled:MYCUSTOMFLOATER', 'wrap' => 'virtual')); $form->addElement('static', null, null, '<span class="small">' . 'There are ' . count($this->db_authors) . ' authors in the database. Type a partial name to ' . 'see a list of matching authors. Separate names ' . 'using commas.</span>'); if ($user != null) { $form->addElement('advcheckbox', 'author_myself', null, 'add me to the search', null, array('', $user->author_id)); } if (isset($_SESSION['user']) && $_SESSION['user']->showInternalInfo()) { // rankings selections $rankings = pdPublication::rankingsGlobalGet($this->db); foreach ($rankings as $rank_id => $description) { $radio_rankings[] = HTML_QuickForm::createElement('advcheckbox', 'paper_rank[' . $rank_id . ']', null, $description, null, array('', 'yes')); } $radio_rankings[] = HTML_QuickForm::createElement('static', 'paper_ranking_label', null, 'other', -1); $radio_rankings[] = HTML_QuickForm::createElement('text', 'paper_rank_other', null, array('size' => 30, 'maxlength' => 250)); $form->addGroup($radio_rankings, 'group_rank', 'Ranking:', '<br/>', false); // collaborations radio selections $collaborations = pdPublication::collaborationsGet($this->db); foreach ($collaborations as $col_id => $description) { $radio_cols[] = HTML_QuickForm::createElement('advcheckbox', 'paper_col[' . $col_id . ']', null, $description, null, array('', 'yes')); } $form->addGroup($radio_cols, 'group_collaboration', 'Collaboration:', '<br/>', false); } $form->addElement('text', 'paper', 'Paper filename:', array('size' => 60, 'maxlength' => 250)); $kwElement[0] =& HTML_QuickForm::createElement('text', 'keywords', null, array('size' => 60, 'maxlength' => 250)); $kwElement[1] =& HTML_QuickForm::createElement('static', 'auth_label', null, '<span class="small">seperate using semi-colon (;)</span>'); $form->addGroup($kwElement, 'keywordsGroup', 'Keywords:', '<br/>', false); if (isset($_SESSION['user']) && $_SESSION['user']->showUserInfo()) { $form->addElement('text', 'user_info', 'User Info:', array('size' => 60, 'maxlength' => 250)); } $form->addGroup(array(HTML_QuickForm::createElement('date', 'startdate', 'Start Date:', array('format' => 'YM', 'minYear' => pdPublication::MIN_YEAR, 'maxYear' => pdPublication::MAX_YEAR)), HTML_QuickForm::createElement('static', null, null, 'and'), HTML_QuickForm::createElement('date', 'enddate', 'End Date:', array('format' => 'YM', 'minYear' => pdPublication::MIN_YEAR, 'maxYear' => pdPublication::MAX_YEAR))), null, 'Published between:', ' ', false); if (isset($_SESSION['user'])) { $form->addElement('advcheckbox', 'show_internal_info', 'Options:', 'show internal information', null, array('no', 'yes')); } $form->addGroup(array(HTML_QuickForm::createElement('button', 'fill_last', 'Load Previous Search Terms', array('onClick' => 'lastSearchUse();')), HTML_QuickForm::createElement('submit', 'Submit', 'Search')), 'buttonsGroup', '', ' ', false); return $form; }
public function __construct() { parent::__construct(); if ($this->loginError) { return; } $this->use_mootools = true; $this->pub =& $_SESSION['pub']; if (isset($this->pub->pub_id)) { $this->page_title = 'Edit Publication'; } $this->authors = pdAuthorList::create($this->db, null, null, true); $form = new HTML_QuickForm('add_pub2', 'post', '', '', array('onsubmit' => 'return check_authors("add_pub2");')); $form->addElement('header', null, 'Select from Authors in Database'); $tooltip = 'Authors::The authors of the publication. Listed in the same order as in the publication <p/> If an author is not already in the database press the <b>Add Author not in DB</b> button.'; $form->addElement('textarea', 'authors', "<div id=\"MYCUSTOMFLOATER\" class=\"myCustomFloater\" style=\"position:absolute;top:200px;left:600px;background-color:#cecece;display:none;visibility:hidden\"><div class=\"myCustomFloaterContent\"></div></div>" . "<span class=\"Tips1\" title=\"{$tooltip}\">Authors</span>:", array('cols' => 60, 'rows' => 5, 'class' => 'wickEnabled:MYCUSTOMFLOATER', 'wrap' => 'virtual')); $form->addElement('static', null, null, '<span class="small">' . 'There are ' . count($this->authors) . ' authors in the database. Type a partial name to ' . 'see a list of matching authors. Separate names ' . 'using commas.</span>'); $form->addElement('submit', 'add_new_author', 'Add Author not in DB'); // collaborations radio selections $tooltip = 'Collaborations::If the publication is a collaboration, select the options that apply to this paper.'; $form->addElement('header', null, "<span class=\"Tips1\" title=\"{$tooltip}\">Collaborations</span>"); $collaborations = pdPublication::collaborationsGet($this->db); foreach ($collaborations as $col_id => $description) { $radio_cols[] = HTML_QuickForm::createElement('checkbox', 'paper_col[' . $col_id . ']', null, $description, 1); } $form->addGroup($radio_cols, 'group_collaboration', null, '<br/>', false); $pos = strpos($_SERVER['PHP_SELF'], 'papersdb'); $url = substr($_SERVER['PHP_SELF'], 0, $pos) . 'papersdb'; $buttons[] = HTML_QuickForm::createElement('submit', 'prev_step', '<< Previous Step'); $buttons[] = HTML_QuickForm::createElement('button', 'cancel', 'Cancel', array('onclick' => "cancelConfirm();")); $buttons[] = HTML_QuickForm::createElement('submit', 'next_step', 'Next Step >>'); if ($this->pub->pub_id != '') { $buttons[] = HTML_QuickForm::createElement('submit', 'finish', 'Finish'); } $form->addGroup($buttons, 'buttons', '', ' ', false); $this->form =& $form; if ($form->validate()) { $this->processForm(); } else { $this->renderForm(); } }
public function __construct() { parent::__construct('all_authors'); if ($this->loginError) { return; } $this->loadHttpVars(true, false); if (!isset($this->tab)) { $this->tab = 'A'; } else { $tab = strtoupper($this->tab); if (strlen($tab) != 1 || ord($tab) < ord('A') || ord($tab) > ord('Z')) { $this->pageError = true; return; } } $auth_list = pdAuthorList::create($this->db, null, $this->tab); echo $this->alphaSelMenu($this->tab, get_class($this) . '.php'); echo "<h2>Authors</h2>"; if (empty($auth_list) || count($auth_list) == 0) { echo 'No authors with last name starting with ', $this->tab, '<br/>'; return; } foreach ($auth_list as $author_id => $name) { $author = new pdAuthor(); $author->dbLoad($this->db, $author_id, pdAuthor::DB_LOAD_BASIC | pdAuthor::DB_LOAD_PUBS_MIN); $name = '<span class="emph"><a href="view_author.php?author_id=' . $author_id . '">' . $name . '</a> '; $icons = $this->getAuthorIcons($author) . '</span>'; $info = array(); if ($author->title != '') { $info[] = '<span class="small">' . $author->title . '</span>'; } if ($author->organization != '') { $info[] = '<span class="small">' . $author->organization . '</span>'; } $info[] .= '<a href="list_publication.php?author_id=' . $author_id . '&menu=0"><span class="small" style="color:#000;font-weight:normal;">' . 'Publication entries in database: ' . $author->totalPublications . '</span>'; $table = new HTML_Table(array('class' => 'publist')); $table->addRow(array($name . '<br/>' . implode('<br/>', $info), $icons)); $table->updateColAttributes(1, array('class' => 'icons'), NULL); echo $table->toHtml(); unset($table); } }
public function __construct() { parent::__construct('author_confirm', 'Author Confirm', 'Admin/author_confirm.php'); if ($this->loginError) { return; } if (!isset($_SESSION['new_author'])) { $this->pageError = true; return; } $new_author = $_SESSION['new_author']; if (isset($new_author->author_id)) { $this->pageError = true; debugVar('new_author', $new_author); return; } $this->form =& $this->confirmForm('author_confirm', null, 'Add'); if ($this->form->validate()) { $values = $this->form->exportValues(); $new_author->dbSave($this->db); if (isset($_SESSION['state']) && $_SESSION['state'] == 'pub_add') { assert('isset($_SESSION["pub"])'); $pub =& $_SESSION['pub']; $pub->addAuthor($this->db, $new_author->author_id); header('Location: add_pub2.php'); return; } echo 'Author <span class="emph">', $new_author->name, '</span> ', 'succesfully added to the database.', '<p/>', '<a href="add_author.php">', 'Add another new author</a>'; } else { $like_authors = pdAuthorList::create($this->db, $new_author->firstname, $new_author->lastname); assert('count($like_authors) > 0'); echo 'Attempting to add new author: ', '<span class="emph">', $new_author->name, "</span><p/>\n", 'The following authors, already in the database, have similar names:<ul>'; foreach ($like_authors as $auth) { echo '<li>', $auth, '</li>'; } echo '</ul>Do you really want to add this author?'; $renderer =& $this->form->defaultRenderer(); $this->form->accept($renderer); $this->renderer =& $renderer; } }
public function __construct() { parent::__construct('search_results'); if ($this->loginError) { return; } $this->optionsGet(); if ($this->debug) { debugVar('_SESSION', $_SESSION); } $this->db_authors = pdAuthorList::create($this->db, null, null, true); $sel_author_names = explode(', ', preg_replace('/\\s\\s+/', ' ', $this->sp->authors)); $this->sp->authors = implode(', ', cleanArray($sel_author_names)); $pub_id_count = 0; // We start as the result being every pub_id $search_query = "SELECT DISTINCT pub_id FROM publication"; $this->add_to_array($search_query, $this->result_pubs); $s = empty($_SERVER["HTTPS"]) ? '' : $_SERVER["HTTPS"] == "on" ? "s" : ""; $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, strpos($_SERVER["SERVER_PROTOCOL"], "/"))) . $s; $port = $_SERVER["SERVER_PORT"] == "80" ? "" : ":" . $_SERVER["SERVER_PORT"]; $position = strpos($_SERVER["REQUEST_URI"], "?"); if ($position === false) { $location = $_SERVER["REQUEST_URI"]; } else { $location = substr($_SERVER['REQUEST_URI'], 0, $position); } $search_url = $protocol . '://' . $_SERVER['SERVER_NAME'] . $port . $location . '?' . $this->sp->paramsToHtmlQueryStr(); if ($this->sp->search != "") { $this->result_pubs = $this->quickSearch(); } else { $this->advancedSearch(); } $_SESSION['search_results'] = $this->result_pubs; $_SESSION['search_url'] = $search_url; if ($this->debug) { return; } header('Location: search_results.php'); }
public function pubSelect($viewCat = null) { assert('is_object($this->db)'); echo $this->pubSelMenu($viewCat), '<br/>'; $text = ''; switch ($viewCat) { case "year": $pub_years = pdPubList::create($this->db, array('year_list' => true)); echo '<h2>Publications by Year:</h2>'; if (count($pub_years) > 0) { $table = new HTML_Table(array('class' => 'nomargins', 'width' => '100%')); $table->addRow(array('Year', 'Num. Publications'), array('class' => 'emph')); foreach (array_values($pub_years) as $item) { $cells = array(); $cells[] = '<a href="list_publication.php?year=' . $item['year'] . '">' . $item['year'] . '</a>'; $cells[] = $item['count']; $table->addRow($cells); } echo $table->toHtml(); } else { echo 'No publication entries.'; } break; case 'author': echo '<h2>Publications by Author:</h2>'; $al = pdAuthorList::create($this->db); for ($c = 65; $c <= 90; ++$c) { $table = new HTML_Table(array('class' => 'publist')); $text = ''; foreach ($al as $auth_id => $name) { if (substr($name, 0, 1) == chr($c)) { $text .= '<a href="list_publication.php?author_id=' . $auth_id . '">' . $name . '</a> '; } } $table->addRow(array(chr($c), $text)); $table->updateColAttributes(0, array('class' => 'item'), NULL); echo $table->toHtml(); } break; case 'venue': // publications by keyword unset($table); $vl = pdVenueList::create($this->db); echo '<h2>Publications by Venue:</h2>'; for ($c = 65; $c <= 90; ++$c) { $table = new HTML_Table(array('class' => 'publist')); $text = ''; foreach ($vl as $vid => $v) { if (substr($v, 0, 1) == chr($c)) { $text .= '<a href="list_publication.php?venue_id=' . $vid . '">' . $v . '</a> '; } } $table->addRow(array(chr($c), $text)); $table->updateColAttributes(0, array('class' => 'item'), NULL); echo $table->toHtml(); } break; case 'category': $table = new HTML_Table(array('class' => 'nomargins', 'width' => '100%')); $cl = pdCatList::create($this->db); $table->addRow(array('Category', 'Num. Publications'), array('class' => 'emph')); foreach ($cl as $cat_id => $category) { $cells = array(); $cells[] = '<a href="list_publication.php?cat_id=' . $cat_id . '">' . $category . '</a><br/>'; $cells[] = pdCatList::catNumPubs($this->db, $cat_id); $table->addRow($cells); } echo '<h2>Publications by Category:</h2>', $table->toHtml(); break; case 'keywords': // publications by keyword unset($table); $kl = pdPubList::create($this->db, array('keywords_list' => true)); echo '<h2>Publications by Keyword:</h2>'; for ($c = 65; $c <= 90; ++$c) { $table = new HTML_Table(array('class' => 'publist')); $text = ''; foreach ($kl as $kw) { if (substr($kw, 0, 1) == chr($c)) { $text .= '<a href="list_publication.php?keyword=' . $kw . '">' . $kw . '</a> '; } } $table->addRow(array(chr($c), $text)); $table->updateColAttributes(0, array('class' => 'item'), NULL); echo $table->toHtml(); } break; default: $this->pageError = true; } }
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); }
#!/usr/bin/env php <?php require_once '../includes/defines.php'; require_once 'includes/functions.php'; require_once 'includes/pdDb.php'; require_once 'includes/pdAuthorList.php'; require_once 'includes/pdPubList.php'; $db = new pdDb(array('name' => 'pubDB')); $authors = pdAuthorList::create($db); if (count($authors) == 0) { echo 'No authors in database'; $db->close(); exit; } foreach ($authors as $auth_id => $name) { $author = new pdAuthor(); $author->dbLoad($db, $auth_id); foreach ($author->pub_list as $pub) { $pub->dbLoad($db, $pub->pub_id); $auth_names = array(); foreach ($pub->authors as $other_auths) { $auth_names[] = $other_auths->name; } echo $author->name, "\t", $pub->title, "\t"; echo implode("\t", array_diff($auth_names, array($author->name))); echo "\n"; } } $db->close();
public function showSearchParams() { $sp =& $_SESSION['search_params']; $table = new HTML_Table(array('class' => 'nomargins', 'width' => '90%')); if ($sp->search != '') { $table->addRow(array($sp->search)); } else { // check each field of the search parameter except the dates and // authors foreach (array_diff(array_keys(get_class_vars(get_class($sp))), array('startdate', 'enddate', 'author_myself', 'authors', 'paper_rank', 'paper_rank_other', 'paper_col')) as $param) { if ($sp->{$param} != '') { $name = ''; if ($param == 'cat_id') { $cl = pdCatList::create($this->db); $name = 'Category'; $value =& $cl[$sp->cat_id]; } else { $name = preg_replace('/_/', ' ', ucwords($param)); $value = $sp->{$param}; } if ($param == 'show_internal_info' && $sp->{$param} == 'no') { continue; } if ($name != '') { $table->addRow(array($name . ':', $value)); } } } $al = null; $values = array(); if (!empty($_SESSION['user']) && $sp->author_myself != '' && $_SESSION['user']->author_id != '') { $authors = pdAuthorList::create($this->db, null, null, true); $values[] = $authors[$_SESSION['user']->author_id]; } if (!empty($sp->authors)) { $values[] = $sp->authors; } if (count($values) > 0) { $table->addRow(array('<b>Author(s)</b>:', implode(' AND ', $values))); } if (isset($_SESSION['user']) && $_SESSION['user']->showInternalInfo()) { if (!empty($sp->paper_rank)) { // ranking $label = 'Ranking:'; $rankings = pdPublication::rankingsGlobalGet($this->db); foreach ($sp->paper_rank as $rank_id => $value) { if ($value != 'yes') { continue; } $table->addRow(array($label, $rankings[$rank_id])); $label = ''; } if ($sp->paper_rank_other != '') { $table->addRow(array($label, $sp->paper_rank_other)); } } if (!empty($sp->paper_col)) { // collaboration $label = 'Collaboration:'; $collaborations = pdPublication::collaborationsGet($this->db); foreach ($sp->paper_col as $col_id => $value) { if ($value != 'yes') { continue; } $table->addRow(array($label, $collaborations[$col_id])); $label = ''; } } } if ($sp->startdate != '' && $sp->enddate != '') { $stime = strtotime(implode('-', $sp->startdate) . '-1'); $etime = strtotime(implode('-', $sp->enddate) . '-1'); // now check the dates if ($etime > $stime) { $table->addRow(array('<b>Start date</b>:', $sp->startdate['Y'] . '-' . sprintf("%02d", $sp->startdate['M']))); $table->addRow(array('<b>End date</b>:', $sp->enddate['Y'] . '-' . sprintf("%02d", $sp->enddate['M']))); } } } $table->updateColAttributes(0, array('class' => 'emph'), true); echo '<h3>SEARCH RESULTS FOR</h3>'; echo $table->toHtml(); }
public function editUser() { $this->db_authors = pdAuthorList::create($this->db, null, null, true); $user =& $_SESSION['user']; $user->collaboratorsDbLoad($this->db); $form = new HTML_QuickForm('userForm', 'post', '', '', array('onsubmit' => 'return check_authors("userForm");')); $form->addElement('static', 'login_label', 'Login:'******'hidden', 'status', 'edit'); $form->addElement('hidden', 'login', $user->login); $form->addElement('text', 'name', 'Name:', array('size' => 50, 'maxlength' => 100)); $form->addElement('text', 'email', 'E-mail:', array('size' => 50, 'maxlength' => 100)); $form->addElement('textarea', 'authors', 'Authors:', array('cols' => 60, 'rows' => 5, 'class' => 'wickEnabled:MYCUSTOMFLOATER', 'wrap' => 'virtual')); $form->addElement('static', null, null, '<span class="small">' . 'There are ' . count($this->db_authors) . ' authors in the database. Type a partial name to ' . 'see a list of matching authors. Separate names ' . 'using commas.</span>'); $form->addElement('advcheckbox', 'option_internal_info', 'Options:', 'show internal info', null, array('No', 'Yes')); $form->addElement('advcheckbox', 'option_user_info', 'Options:', 'show user info', null, array('No', 'Yes')); $auth_list = pdAuthorList::create($this->db); $form->addElement('submit', 'Submit', 'Save'); if ($form->validate()) { $values = $form->exportValues(); assert('$values["login"] == $user->login'); $user->name = $values['name']; $user->email = $values['email']; $user->options = 0; if ($values['option_internal_info'] == 'Yes') { $user->options |= pdUser::OPTION_SHOW_INTERNAL_INFO; } if ($values['option_user_info'] == 'Yes') { $user->options |= pdUser::OPTION_SHOW_USER_INFO; } unset($user->collaborators); // need to retrieve author_ids for the selected authors $selAuthors = explode(', ', preg_replace('/\\s\\s+/', ' ', $values['authors'])); $author_ids = array(); foreach ($selAuthors as $author) { if (empty($author)) { continue; } $result = array_search($author, $this->db_authors); if ($result !== false) { $user->collaborators[$result] = $this->db_authors[$result]; } } $user->dbSave($this->db); echo 'Change to user information submitted.<p/>'; echo 'Click <a href="edit_user.php?status=edit">here</a> to edit your preferences again.'; } else { echo '<h2>Login Information</h2>'; $defaults = array('name' => $user->name, 'email' => $user->email); $defaults['option_internal_info'] = $user->showInternalInfo() ? 'Yes' : 'No'; $defaults['option_user_info'] = $user->showUserInfo() ? 'Yes' : 'No'; if (count($user->collaborators) > 0) { $author_names = pdAuthorList::createFromAuthorIds($this->db, array_keys($user->collaborators), true); $defaults['authors'] = implode(', ', array_values($author_names)); } $form->setDefaults($defaults); $renderer =& $form->defaultRenderer(); $form->accept($renderer); $this->form =& $form; $this->renderer =& $renderer; $this->javascript(); } }
/** * User's most popular Authors, sorted according to number of publications * submitted. */ public function popularAuthorsDbLoad($db) { assert('is_object($db)'); assert('isset($this->login)'); if (isset($this->author_rank) && count($this->author_rank) > 0) { return; } $q = $db->select(array('publication', 'pub_author', 'user'), 'pub_author.author_id', array('publication.submit=user.name', 'publication.pub_id=pub_author.pub_id', 'user.login' => $this->login), "pdUser::popularAuthorsDbLoad"); foreach ($q as $r) { if (!isset($this->author_rank[$r->author_id])) { $this->author_rank[$r->author_id] = 0; } else { $this->author_rank[$r->author_id]++; } } if (count($this->author_rank) > 0) { arsort($this->author_rank, SORT_NUMERIC); // now remove the author ids that are invalid $valid_authors = pdAuthorList::create($db); $ranked_author_ids = array_keys($this->author_rank); foreach ($ranked_author_ids as $id) { if (!isset($valid_authors[$id])) { unset($this->author_rank[$id]); } } } }
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: <ul> <li>fist last</li> <li>fist initials last</li> <li>last, first</li> <li>last, first initials</li> </ul> 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, ' ', 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; } }
Jie Hu, Russell Greiner, 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); }