00001 <?php
00007 class TransSDRPendingXML extends STransXML
00008 {
00009
00010
00011
00012
00013 public function translate ($si)
00014 {
00015 if (parent::translate($si) == false) return false;
00016 $xml = $this->parseXML($si->getSource());
00017 if ($xml === false) return false;
00018
00019 # If there are no results
00020 if (!isset($xml->SearchResults)) {
00021 return('No Results');
00022 }
00023
00024 # If there are results, loop through them to display
00025 $output = "";
00026
00027 # add the header
00028 $output .= $this->addForwardBackButtons($xml, $si);
00029
00030 if ($xml->SearchResults->resultsInfo->totalNumResults == 0) {
00031 $output .= "<b>No matching results were found</b>.";
00032 }
00033
00034
00035
00036 # print the results
00037 $counter = 0;
00038 foreach($xml->SearchResults->SDRSubmittedResource as $doc){
00039 $output .= $this->renderResultDocument($doc, $counter, $contributorIcons);
00040 $counter++;
00041 }
00042
00043 # add the footer
00044 $output .= $this->addForwardBackButtons($xml, $si);
00045
00046 $this->sendToTarget($si, $output);
00047 parent::translate($si);
00048 }
00049
00050 protected function addForwardBackButtons($xml, $si) {
00051 $ss = $si->getOption('ss');
00052 $sr = $si->getOption('sr');
00053 if ($ss == "" && isset($_GET['ss'])) { $ss = $_GET['ss']; }
00054 if ($sr == "" && isset($_GET['sr'])) { $sr = $_GET['sr']; }
00055
00056 $numPerPage = SConfig::getOption('fedsearch.resultsPerPage');
00057
00058 $output = "";
00059 # Display forward and back buttons:
00060
00061 if (($xml->SearchResults->resultsInfo->numSkipped + $xml->SearchResults->resultsInfo->numReturned) < ($xml->SearchResults->resultsInfo->totalNumResults)) {
00062 $newUrl = $this->buildCWISURL($ss, $sr + $numPerPage);
00063 $output .= '<div style="float:right; width: 300px; text-align:right"><a href="' . $newUrl . '">Next ' . $numPerPage . ' Results →</a></div>';
00064 }
00065
00066 if (($xml->SearchResults->resultsInfo->numSkipped) > 0) {
00067 $newUrl = $this->buildCWISURL($ss, $sr - $numPerPage);
00068 $output .= '<a href="' . $newUrl . '">← Prev ' . $numPerPage . ' Results</a>';
00069 }
00070
00071 $output .= "<br />";
00072 return $output;
00073 }
00074
00075 #
00076 #
00077 protected function renderResultDocument($doc, $counter, $contributors) {
00078 global $PATH, $prm, $PROJECT_ROOT;
00079
00080 $evenOddClass = ($counter % 2 == 0) ? 'ResultSet-ItemEven' : 'ResultSet-ItemOdd';
00081
00082 $target = (string)$doc->submissionId;
00083 $formApprove = new TKForm();
00084 $formReject = new TKForm();
00085
00086 $vbox = new TKHBox();
00087 $sub = $vbox->addButton("Approve This Submission");
00088 $sub->setAction('onclick', new TKSWATAction($target, LocalEventHandler::APPROVE_SUBMISSION, $formApprove));
00089
00090 $sub2 = $vbox->addButton("Reject This Submission");
00091 $sub2->setAction('onclick', new TKSWATAction($target, LocalEventHandler::REJECT_SUBMISSION, $formReject));
00092
00093 $newOrReplace = ($doc->cserdId != '') ?
00094 '<span style="color:red">This will replace the existing metadata for catalog item ' . $doc->cserdId . '</span>':
00095 'This will be added as a new record';
00096
00097 $xmlContent = $this->dumpMetadataInfo($doc->metadata);
00098
00099 return "
00100 <div class='$evenOddClass'>
00101 <div class='ResultSet-ItemTitle'>
00102 <a href='{$doc->url}' target='_blank' >$title</a><br />
00103 Title: {$doc->metadata->Title}<br />
00104 Submitted By: {$doc->submittedBy}<br />
00105 Date: {$doc->submitTime}<br />
00106 $newOrReplace
00107 </div>
00108 <div style='clear:both'></div>
00109 <span class='ResultSet-ItemDescription'>
00110 $descrip<br />
00111
00112 $xmlContent
00113
00114 {$formApprove->render()}
00115 {$formReject->render()}
00116 {$vbox->render()}
00117
00118 </span>
00119 <br />
00120 </div>
00121 <div style='clear:both;'></div>
00122 ";
00123 }
00124
00125 static function contentToScreen($input) {
00126
00127
00128 $input = str_replace('&', '&', $input);
00129 $input = str_replace('<', '<', $input);
00130 $input = str_replace('>', '>', $input);
00131 $input = str_replace('"', '"', $input);
00132 $input = str_replace('\'', ''', $input);
00133 $input = str_replace('\n', '<br />', $input);
00134 $input = str_replace('\r', '<br />', $input);
00135 return $input;
00136 }
00137
00138 protected function dumpMetadataInfo($input, $level = 0) {
00139 $return = '';
00140 foreach($input as $tag=>$value) {
00141 if ($value == '') continue;
00142 for($i = 0; $i < $level; $i++) {
00143 $return .= ' ';
00144 }
00145 $return .= '<b>' . $tag . ':</b> ' . $value . '<br />';
00146 if (count($value->children()) > 0) {
00147 $return .= $this->dumpMetadataInfo($value, $level + 1);
00148
00149 }
00150 }
00151 return $return;
00152 }
00153
00154 protected function buildCWISURL($ss, $sr) {
00155 $base = SWATFunctions::stripArgs($_SERVER['REQUEST_URI']);
00156 if ($sr < 0) $sr = 0;
00157 return $base . "?ss=" . $ss . "&sr=" . $sr;
00158 }
00159
00160 protected function wrapFoundTerms($term, $data) {
00161 return str_replace($term, "<span class=\"highlightedSearchTerm\">$term</span>", $data);
00162 }
00163
00164 }
00165
00166 ?>