getModel('tooltip'); $claimModel = $this->getModel('claim'); $document =& JFactory::getDocument(); $document->addCustomTag(''); $document->addCustomTag(''); $document->addCustomTag(''); $document->addCustomTag(''); $document->addCustomTag(''); $document->addStyleSheet(JRoute::_(JURI::base().'plugins/content/yoo_tooltip/yoo_tooltip.css.php')); $document->addStyleSheet(JRoute::_(JURI::base().'media/system/css/calendar-jos.css')); $id = JRequest::getVar('id', ''); $grant = JRequest::getVar('grant', ''); $projectInfo = $this->getProjectInfo($id, $grant); $action = JRequest::getVar('action', '', 'post'); if ($action == 'submit') { $rejected = JRequest::getVar('rejected', array(), 'post'); $confirmed = JRequest::getVar('confirmed', array(), 'post'); foreach (explode(",", $rejected) as $id) { $id = base64_decode($id); JLog :: getInstance()->addEntry(array('level' => 'debug', 'comment' => (var_export('Rejecting '.$id , true)))); $claimModel->rejectDocument($id, $projectInfo->projectId); } $redirectUrl = JRoute::_('index.php?option='.JRequest::getVar('option').'&view=project_info&Itemid='.JRequest::getVar('Itemid')).'?id='.$projectInfo->projectId.'&confirm='.JRequest::getVar('confirm'); JFactory::getApplication()->redirect($redirectUrl); } $projectDocs = $this->getProjectDocuments($projectInfo->projectId, $this->isUserCoordinator($projectInfo)); $docs = array(); $scriptText = "window.addEvent('domready', function() {"; foreach ($projectDocs as $doc) { $status = $this->getClaimStatus($projectInfo->grandAgreement, $doc); if ($status == null) $status = 'harvest'; /* $scriptText .= $tipModel->createDocumentTooltip($doc, "doc-".base64_encode($doc->documentId), true); } else { $scriptText .= $tipModel->createDocumentTooltip($doc, "doc-".base64_encode($doc->documentId), false); } */ $scriptText .= $tipModel->createDocumentTooltip($doc, "doc-".base64_encode($doc->documentId), true); $docs[strtolower($status)][] = $doc; } $scriptText .= "});"; $document->addScriptDeclaration($scriptText); $this->assignRef('project', $projectInfo); $this->assignRef('docs', $docs); $this->assignRef('searchMenuId', $this->getModel('statistics')->getSearchMenuId()); parent::display($tpl); } private function getProjectInfo($id, $grant) { $model = $this->getModel('deposition'); if ($id != null) return $model->getShortProjectInfo($id); else return $model->getShortProjectInfoByGrant($grant); } private function getProjectDocuments($ga, $includePending) { $model = $this->getModel('claim'); $docs = $model->getDocumentsByProject($ga, $includePending); for ($i = 0; $i < count($docs); $i++) { $doc = $docs[$i]; if ($doc->title == null) { $doc = $this->mergeDocInfo($doc, $this->identifyDoc($doc->claimSource, $doc->claimInfo)); $docs[$i] = $doc; JLog :: getInstance()->addEntry(array('level' => 'debug', 'comment' => (var_export($doc, true)))); $model->updateDocument($doc->documentId, $doc); } } return $docs; } private function mergeDocInfo($old, $identified) { $fields = array( 'title' => $identified->title, 'authors' => $identified->authors, 'description' => $identified->description, 'repositoryName' => $identified->repositoryName, 'language' => $identified->language, 'subjects' => $identified->subjects, 'publisher' => $identified->publisher, 'publicationDate' => $identified->publicationDate, 'url' => $identified->url, 'documentId' => $old->documentId, 'claimSource' => $old->claimSource, 'claimInfo' => $old->claimInfo, 'projects' => $old->projects, 'claimers' => $old->claimers ); return new Document($fields); } private function identifyDoc($source, $info) { $model = $this->getModel('claim'); switch ($source) { case 'driver': $fields = $this->getDriverDoc($resourceId); $doc = $model->parseSearchResult($fields); break; case 'isi': case 'doi': $doc = $model->identifyDoi($info); break; case 'pubmed': $doc = $model->identifyPubmed($info); break; case 'arxiv': $doc = $model->identifyArxiv($info); break; } return $doc; } private function getDriverDoc($resourceId) { $searchModel = $this->getModel('search'); $href = base64_encode('ShowDocument.action?id='.$resourceId); $doc = $searchModel->searchDocument(array('href' => array($href)), 'driver'); return $doc; } public function isUserCoordinator($projectInfo) { if (JFactory::getUser()->guest) { JLog :: getInstance()->addEntry(array('level' => 'debug', 'comment' => ('user is guest'))); return false; } else if (JFactory::getUser()->email == $projectInfo->coordinator->email) { JLog :: getInstance()->addEntry(array('level' => 'debug', 'comment' => ('user is the coordinator'))); return true; } else if ($this->validateConfirm(JRequest::getVar('confirm', 'invalid'), $projectInfo->grandAgreement)) { JLog :: getInstance()->addEntry(array('level' => 'debug', 'comment' => ('user has correct confirm'))); return true; } JLog :: getInstance()->addEntry(array('level' => 'debug', 'comment' => ('ton poulo'))); return false; } private function validateConfirm($confirm, $ga) { return hash_hmac('sha1', $ga, 'asupercoolsecret') == $confirm; } function getClaimStatus($ga, $doc) { foreach($doc->projects as $claim) { if ($claim->project->projectGrant == $ga) return $claim->status; } return false; } } ?>