\n";
+ if ($p1=='edit') $row['templatename']='edit';
$tobj=PUBMED_TEMPLATE_BASE::getTemplate($row['templatename']);
if (!$tobj) {
echo 'The template, "'.htmlspecialchars($row['templatename']).'" cannot be found';
- break;
+ return;
}
+ $tobj->setSortText($row['sorttext']);
+
// Set all the data.
+ $query='SELECT i.inumber as itemid, i.ibody as body, i.ititle as title, i.imore as more'.
+ ' FROM '.sql_table('item').' as i, '.
+ sql_table('plugin_pubmed_references').' as r,'.
+ sql_table('plugin_pubmed_manuscripts').' as m'.
+ ' WHERE i.inumber=r.itemid'.
+ ' AND r.manuscriptid='.(int)$msid.
+ ' AND m.manuscriptid='.(int)$msid.
+ ' AND m.userid='.(int)$mid.
+ ' ORDER BY i.ititle ASC';
$res=sql_query($query);
while($row=mysql_fetch_assoc($res)){
- $tobj->setData($row['more'],$row['sort']);
+ $pmid=$tobj->setData($row['more'],$row['itemid']);
}
// Sort the papers
- if (!$tobj->manualSort()) $tobj->sortPapers();
+ $tobj->sortPapers();
// Let's parse, finally.
$tobj->parse_all();
break;
@@ -445,5 +461,106 @@ if((document.location+'').indexOf('#pubmed')>0) np_pubmed_timer=setInterval("np_
checkTicket()) {
+ echo '
Invalid or expired ticket!
';
+ return;
+ }
+ // Clean up batch data
+ foreach($batch as $key=>$itemid) $batch[$key]=(int)$itemid;
+ // Get citation information
+ $res=sql_query('SELECT * FROM '. sql_table('plugin_pubmed_references').
+ ' WHERE manuscriptid='.(int)$msid);
+ $references=array();
+ while($row=mysql_fetch_assoc($res)){
+ $references[]=(int)$row['itemid'];
+ }
+ $sort=array();
+ $sorttext=quickQuery('SELECT sorttext as result FROM '. sql_table('plugin_pubmed_manuscripts').
+ ' WHERE manuscriptid='.(int)$msid);
+ foreach(explode(',',$sorttext) as $itemid){
+ $itemid=(int)(trim($itemid));
+ if (in_array($itemid,$references)) $sort[]=$itemid;
+ }
+ foreach($references as $itemid=>$row){
+ if (!in_array($itemid,$sort)) $sort[]=$itemid;
+ }
+ // Take action
+ switch($action){
+ case 'delete':
+ $in='';
+ foreach($batch as $itemid){
+ if (strlen($in)) $in.=',';
+ $in.=(int)$itemid;
+ }
+ sql_query('DELETE FROM '. sql_table('plugin_pubmed_references').
+ ' WHERE itemid in ('.$in.')'.
+ ' AND manuscriptid='.(int)$msid);
+ echo '
Deleted references: '.$in.'
';
+ return;
+ case 'moveup':
+ for($i=0;$iaction_manuscriptlist();
}
-
+ private function _getSortMethod($tempname){
+ // Note that $tempname is valid once.
+ static $ret;
+ if (isset($ret)) return $ret;
+ require_once(dirname(__FILE__).'/template.php');
+ $tobj=PUBMED_TEMPLATE_BASE::getTemplate($tempname);
+ if (!$tobj) return false;
+ $tobj->setSortText('');
+ $tobj->sortPapers();
+ if ($tobj->getSortText()=='authorname') $ret='authorname';
+ else $ret='manual';
+ return $ret;
+ }
private function _checkmanuscriptname($mname,$id=0){
global $member;
$mid=$member->getID();
@@ -376,12 +389,20 @@ class PubMedAdmin extends BaseActions {
$template=$row['templatename'];
if (postVar('sure')=='yes') {
$template=postVar('templatename');
- sql_query('UPDATE '.sql_table('plugin_pubmed_manuscripts').' SET'.
- ' manuscriptname="'.addslashes($mname).'",'.
- ' templatename="'.addslashes($template).'"'.
- ' WHERE manuscriptid='.(int)$manuscriptid.
- ' AND userid='.(int)$mid);
- $this->template_parse('editmanuscript',array('mname'=>$mname),'notice');
+ $sorttext=postVar('sorttext');
+ $sortmethod=$this->_getSortMethod($template);
+ if ($sortmethod) {
+ if ($sortmethod=='authorname') $sorttext='authorname';
+ sql_query('UPDATE '.sql_table('plugin_pubmed_manuscripts').' SET'.
+ ' manuscriptname="'.addslashes($mname).'",'.
+ ' templatename="'.addslashes($template).'",'.
+ ' sorttext="'.addslashes($sorttext).'"'.
+ ' WHERE manuscriptid='.(int)$manuscriptid.
+ ' AND userid='.(int)$mid);
+ $this->template_parse('editmanuscript',array('mname'=>$mname),'notice');
+ } else {
+ echo "The template '".htmlspecialchars($template)."' does not exist.";
+ }
return $this->action_manuscriptlist();
}
// Get template files
diff --git a/NP_PubMed/trunk/pubmed/index.xml b/NP_PubMed/trunk/pubmed/index.xml
index 250087d..ccdf69c 100644
--- a/NP_PubMed/trunk/pubmed/index.xml
+++ b/NP_PubMed/trunk/pubmed/index.xml
@@ -209,8 +209,9 @@ Are you sure?
-
<%ticket%>
+
+
diff --git a/NP_PubMed/trunk/pubmed/template.php b/NP_PubMed/trunk/pubmed/template.php
index 583422f..7e547fc 100644
--- a/NP_PubMed/trunk/pubmed/template.php
+++ b/NP_PubMed/trunk/pubmed/template.php
@@ -9,12 +9,8 @@ class PUBMED_TEMPLATE_BASE {
* Default methods follow.
* These methods will be overrided in PUBMED_TEMPLATE class.
*/
- public function manualSort(){
- // If the order of manuscript is manually sorted (PNAS etc),
- // this method must return true.
- return false;
- }
public function sortPapers(){
+ // Either manualSort or sortByAuthorName
$this->sortByAuthorName();
}
public function parse_header(){
@@ -61,7 +57,7 @@ END;
/*
* Following methods shouldn't be overrided.
*/
- protected $sortdata=array(),$data=array();
+ protected $sorteddata=array(),$data=array();
public static final function getTemplate($template){
// Static method.
// Define PUBLED_TEMPLATE class
@@ -72,22 +68,49 @@ END;
$obj = new PUBMED_TEMPLATE;
return $obj;
}
- public final function setData($more,$sort){
+ protected $sortarray=false;
+ public final function setSortText($text){
+ if ($text=='authorname') {
+ $this->sortarray=false;
+ return;
+ }
+ $array=array();
+ $i=0;
+ foreach(explode(',',$text) as $itemid){
+ $array[(int)$itemid]=$i;
+ $i++;
+ }
+ $this->sortarray=$array;
+ }
+ public final function getSortText(){
+ if ($this->sortarray===false) return 'authorname';
+ $ret='';
+ $s=$this->sorteddata;
+ $itemid=$this->itemid;
+ ksort($s);
+ foreach($s as $pmid){
+ if (strlen($ret)) $ret.=',';
+ $ret.=$itemid[$pmid];
+ }
+ return $ret;
+ }
+ protected $itemid=array(); // PMID <-> itemid translation table.
+ public final function setData($more,$itemid){
// $more is the $item->more.
if (!preg_match('#]*>([\s\S]*?)#',$more,$m)) return;
$xml="\r\n\r\n$m[1]\r\n";
$xml=simplexml_load_string($xml);
$pmid=(int)$xml->PMID;
$this->data[$pmid]=$xml;
- if (!isset($this->sortdata[$sort])) $this->sortdata[$sort]=$pmid;
- else $this->sortdata[]=$pmid;
+ $this->sorteddata[]=$pmid;
+ $this->itemid[$pmid]=$itemid;
}
public final function parse_all(){
echo $this->parse_header();
$num=0;
- $sortdata=$this->sortdata;
- ksort($sortdata);
- foreach($sortdata as $pmid) {
+ $sorteddata=$this->sorteddata;
+ ksort($sorteddata);
+ foreach($sorteddata as $pmid) {
$xml=$this->data[$pmid];
$num++;
// Get year
@@ -116,7 +139,19 @@ END;
/* Sort methods follow.
* note that these methods will be called from "sortPapers" method
*/
+ public final function manualSort(){
+ $itemid=$this->itemid;
+ $position=$this->sortarray;
+ $newarray=array();
+ foreach($this->sorteddata as $pmid){
+ $i=$itemid[$pmid];
+ if (isset($position[$i])) $newarray[$position[$i]]=$pmid;
+ else $newarray[]=$pmid;
+ }
+ $this->sorteddata=$newarray;
+ }
public final function sortByAuthorName(){
+ $this->sortarray=false;
$citations=array();
$papers=array();
$i=0;
@@ -166,7 +201,7 @@ END;
// Let's get the result.
$result=array();
foreach($papers as $pmid) $result[]=$pmid;
- $this->sortdata=$result;
+ $this->sorteddata=$result;
}
protected final function month($month){
if (is_numeric($month)) return (int)$month;
diff --git a/NP_PubMed/trunk/pubmed/templates/PNAS.php b/NP_PubMed/trunk/pubmed/templates/PNAS.php
index 7062f97..890938e 100644
--- a/NP_PubMed/trunk/pubmed/templates/PNAS.php
+++ b/NP_PubMed/trunk/pubmed/templates/PNAS.php
@@ -1,8 +1,8 @@
manualSort();
}
public function _parse_header(){
return ' ';
diff --git a/NP_PubMed/trunk/pubmed/templates/edit.php b/NP_PubMed/trunk/pubmed/templates/edit.php
new file mode 100644
index 0000000..8e202a7
--- /dev/null
+++ b/NP_PubMed/trunk/pubmed/templates/edit.php
@@ -0,0 +1,79 @@
+sortarray=='authorname') $this->sortByAuthorName();
+ else $this->manualSort();
+ }
+ public function parse_header(){
+ global $manager;
+ // Construct ticket hidden
+ ob_start();
+ $manager->AddTicketHidden();
+ $ticket=ob_get_contents();
+ ob_end_clean();
+ // Construct options
+ $options=<<- select action -
+
+END;
+ if ($this->sortarray!==false) $options.=<<Move up
+
+
+
+END;
+ // Everything done. Return the result.
+ return <<
+{$ticket}
+
+the selected items.
+
+
+
+(
+ Select all -
+ Unselect all
+)
+
+END;
+ }
+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){
+ $itemid=$this->itemid[$pmid];
+ if (isset($_POST['batch'])) $checked = in_array($itemid,$_POST['batch']) ? ' checked="checked"' : '';
+ else $checked='';
+ return <<
+
+{$this->parse_authors($authors)} ({$year}) {$journal}{$volume}, {$pages}
+
+
+END;
+ }
+ public function parse_footer(){
+ return <<
+
+
+END;
+ }
+
+}
\ No newline at end of file
--
2.11.0