/**
  * Queue payment and save gift details.
  */
 function execute()
 {
     $journal = $this->request->getJournal();
     $journalId = $journal->getId();
     // Create new gift and save details
     import('classes.gift.Gift');
     import('classes.payment.ojs.OJSPaymentManager');
     $paymentManager = new OJSPaymentManager($this->request);
     $paymentPlugin =& $paymentManager->getPaymentPlugin();
     $gift = new Gift();
     if ($paymentPlugin->getName() == 'ManualPayment') {
         $gift->setStatus(GIFT_STATUS_AWAITING_MANUAL_PAYMENT);
     } else {
         $gift->setStatus(GIFT_STATUS_AWAITING_ONLINE_PAYMENT);
     }
     $gift->setAssocType(ASSOC_TYPE_JOURNAL);
     $gift->setAssocId($journalId);
     $gift->setGiftType(GIFT_TYPE_SUBSCRIPTION);
     $gift->setGiftAssocId($this->getData('typeId'));
     $gift->setBuyerFirstName($this->getData('buyerFirstName'));
     $gift->setBuyerMiddleName($this->getData('buyerMiddleName'));
     $gift->setBuyerLastName($this->getData('buyerLastName'));
     $gift->setBuyerEmail($this->getData('buyerEmail'));
     $gift->setBuyerUserId($this->buyerUserId ? $this->buyerUserId : null);
     $gift->setRecipientFirstName($this->getData('recipientFirstName'));
     $gift->setRecipientMiddleName($this->getData('recipientMiddleName'));
     $gift->setRecipientLastName($this->getData('recipientLastName'));
     $gift->setRecipientEmail($this->getData('recipientEmail'));
     $gift->setRecipientUserId(null);
     $gift->setLocale($this->getData('giftLocale'));
     $gift->setGiftNoteTitle($this->getData('giftNoteTitle'));
     $gift->setGiftNote($this->getData('giftNote'));
     $giftDao = DAORegistry::getDAO('GiftDAO');
     $giftId = $giftDao->insertObject($gift);
     // Create new queued payment
     $subscriptionTypeDao = DAORegistry::getDAO('SubscriptionTypeDAO');
     $subscriptionType =& $subscriptionTypeDao->getSubscriptionType($this->getData('typeId'));
     $queuedPayment =& $paymentManager->createQueuedPayment($journalId, PAYMENT_TYPE_GIFT, null, $giftId, $subscriptionType->getCost(), $subscriptionType->getCurrencyCodeAlpha());
     $queuedPaymentId = $paymentManager->queuePayment($queuedPayment);
     $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
 }
 /**
  * Create institutional subscription. 
  */
 function execute()
 {
     $journal = $this->request->getJournal();
     $journalId = $journal->getId();
     $typeId = $this->getData('typeId');
     $subscriptionTypeDao = DAORegistry::getDAO('SubscriptionTypeDAO');
     $nonExpiring = $subscriptionTypeDao->getSubscriptionTypeNonExpiring($typeId);
     $today = date('Y-m-d');
     $insert = false;
     if (!isset($this->subscription)) {
         import('classes.subscription.InstitutionalSubscription');
         $subscription = new InstitutionalSubscription();
         $subscription->setJournalId($journalId);
         $subscription->setUserId($this->userId);
         $subscription->setReferenceNumber(null);
         $subscription->setNotes(null);
         $insert = true;
     } else {
         $subscription =& $this->subscription;
     }
     import('classes.payment.ojs.OJSPaymentManager');
     $paymentManager = new OJSPaymentManager($this->request);
     $paymentPlugin =& $paymentManager->getPaymentPlugin();
     if ($paymentPlugin->getName() == 'ManualPayment') {
         $subscription->setStatus(SUBSCRIPTION_STATUS_AWAITING_MANUAL_PAYMENT);
     } else {
         $subscription->setStatus(SUBSCRIPTION_STATUS_AWAITING_ONLINE_PAYMENT);
     }
     $subscription->setTypeId($typeId);
     $subscription->setMembership($this->getData('membership') ? $this->getData('membership') : null);
     $subscription->setDateStart($nonExpiring ? null : $today);
     $subscription->setDateEnd($nonExpiring ? null : $today);
     $subscription->setInstitutionName($this->getData('institutionName'));
     $subscription->setInstitutionMailingAddress($this->getData('institutionMailingAddress'));
     $subscription->setDomain($this->getData('domain'));
     $subscription->setIPRanges($this->getData('ipRanges'));
     $institutionalSubscriptionDao = DAORegistry::getDAO('InstitutionalSubscriptionDAO');
     if ($insert) {
         $institutionalSubscriptionDao->insertSubscription($subscription);
     } else {
         $institutionalSubscriptionDao->updateSubscription($subscription);
     }
     $subscriptionTypeDao = DAORegistry::getDAO('SubscriptionTypeDAO');
     $subscriptionType =& $subscriptionTypeDao->getSubscriptionType($this->getData('typeId'));
     $queuedPayment =& $paymentManager->createQueuedPayment($journalId, PAYMENT_TYPE_PURCHASE_SUBSCRIPTION, $this->userId, $subscription->getId(), $subscriptionType->getCost(), $subscriptionType->getCurrencyCodeAlpha());
     $queuedPaymentId = $paymentManager->queuePayment($queuedPayment);
     $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
 }
 /**
  * Store decline by author to review an object.
  * @param array $args
  * @param PKPRequest $request
  */
 function declineToReviewObject($args, $request)
 {
     $journal =& $request->getJournal();
     $journalId = $journal->getId();
     $user =& $request->getUser();
     $objectId = !isset($args) || empty($args) ? null : (int) $args[0];
     if (!$this->_ensureObjectExists($objectId, $journalId)) {
         $request->redirect(null, 'objectsForReview');
     }
     $ofrDao =& DAORegistry::getDAO('ObjectForReviewDAO');
     $objectForReview =& $ofrDao->getById($objectId);
     $ofrAssignmentDao =& DAORegistry::getDAO('ObjectForReviewAssignmentDAO');
     $assignment =& $ofrAssignmentDao->getByObjectAndUserId($objectId, $user->getId());
     $redirect = true;
     if ($assignment) {
         import('classes.mail.MailTemplate');
         $email = new MailTemplate('OFR_OBJECT_DECLINED');
         $send = $request->getUserVar('send');
         // Author has filled out mail form or decided to skip email
         if ($send && !$email->hasErrors()) {
             // Update object for review as requested
             $assignment->setStatus(OFR_STATUS_DECLINED);
             $ofrAssignmentDao->updateObject($assignment);
             $email->send();
             $this->_createTrivialNotification(NOTIFICATION_TYPE_OFR_DECLINED, $request);
         } else {
             $returnUrl = $request->url(null, 'author', 'declineToReviewObject', $objectId);
             $this->_displayEmailForm($email, $objectForReview, $user, $returnUrl, 'OFR_OBJECT_DECLINED', $request);
             $redirect = false;
         }
     }
     if ($redirect) {
         $request->redirect(null, 'author', 'objectsForReview');
     }
 }
 /**
  * Batch import from an ONIX XML export.
  * @param array $args
  * @param PKPRequest $request
  */
 function uploadONIXObjectForReview($args, &$request)
 {
     $user = $request->getUser();
     $journal =& $request->getJournal();
     $ofrOrgDao =& DAORegistry::getDAO('ObjectForReviewOrganizationDAO');
     $ofrPlugin =& $this->_getObjectsForReviewPlugin();
     $ofrPlugin->import('classes.form.ObjectForReviewForm');
     $reviewObjectTypeId = (int) $request->getUserVar('reviewObjectTypeId');
     import('classes.file.TemporaryFileManager');
     $temporaryFileManager = new TemporaryFileManager();
     $temporaryFile = $temporaryFileManager->handleUpload('onixFile', $user->getId());
     $filePath = $temporaryFile->getFilePath();
     $parser = new XMLParser();
     $doc =& $parser->parse($filePath);
     $multiple = $request->getUserVar('multiple');
     if ($doc) {
         // Determine if we have short or long tags.
         $productNodes = $doc->getChildByName('product');
         $shortTags = $productNodes ? true : false;
         for ($index = 0; $productNode = $doc->getChildByName($this->_getOnixTag('Product', $shortTags), $index); $index++) {
             $importData = array();
             if ($productNode) {
                 $publisherNode = $productNode->getChildByName($this->_getOnixTag('Publisher', $shortTags));
                 if ($publisherNode) {
                     $publisherNameNode = $publisherNode->getChildByName($this->_getOnixTag('PublisherName', $shortTags));
                     if ($publisherNameNode) {
                         $publisher = $publisherNameNode->getValue();
                         $organization =& $ofrOrgDao->getOrganizationByName(trim($publisher));
                         if ($organization) {
                             $importData['publisherId'] = $organization->getId();
                         }
                     }
                 }
                 $websiteNode = $publisherNode->getChildByName($this->_getOnixTag('Website', $shortTags));
                 if ($websiteNode) {
                     $websiteLinkNode = $websiteNode->getChildByName($this->_getOnixTag('WebsiteLink', $shortTags));
                     $websiteLink = $websiteLinkNode->getValue();
                     $importData['book_publisher_url'] = $websiteLink;
                 }
                 $titleNode = $productNode->getChildByName($this->_getOnixTag('Title', $shortTags));
                 if ($titleNode) {
                     $titleTextNode = $titleNode->getChildByName($this->_getOnixTag('TitleText', $shortTags));
                     $title = $titleTextNode->getValue();
                     $importData['title'] = $title;
                 }
                 $subTitleNode = $titleNode->getChildByName($this->_getOnixTag('Subtitle', $shortTags));
                 if ($subTitleNode) {
                     $subTitle = $subTitleNode->getValue();
                     $importData['shortTitle'] = $subTitle;
                 }
                 $seriesNode = $productNode->getChildByName($this->_getOnixTag('Series', $shortTags));
                 if ($seriesNode) {
                     $seriesTextNode = $seriesNode->getChildByName($this->_getOnixTag('TitleOfSeries', $shortTags));
                     $series = $seriesTextNode->getValue();
                     $importData['book_series'] = $series;
                 }
                 $languageNode = $productNode->getChildByName($this->_getOnixTag('Language', $shortTags));
                 if ($languageNode) {
                     $languageCodeNode = $languageNode->getChildByName($this->_getOnixTag('LanguageCode', $shortTags));
                     $language = $languageCodeNode->getValue();
                     $importData['language'] = substr($language, 0, 2);
                 } else {
                     $importData['language'] = 'en';
                 }
                 $pageNode = $productNode->getChildByName($this->_getOnixTag('NumberOfPages', $shortTags));
                 if ($pageNode) {
                     $pages = $pageNode->getValue();
                     $importData['book_pages_no'] = $pages;
                 }
                 // Abstract. Look for OtherText with
                 // sub element of TextTypeCode of '01' (main description)
                 $abstract = '';
                 for ($authorIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('OtherText', $shortTags), $authorIndex); $authorIndex++) {
                     $typeNode = $node->getChildByName($this->_getOnixTag('TextTypeCode', $shortTags));
                     if ($typeNode && $typeNode->getValue() == '01') {
                         $textNode = $node->getChildByName($this->_getOnixTag('Text', $shortTags));
                         if ($textNode) {
                             $abstract = strip_tags($textNode->getValue());
                         }
                         break;
                     }
                 }
                 $importData['abstract'] = $abstract;
                 // ISBN-13
                 for ($productIdentifierIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('ProductIdentifier', $shortTags), $productIdentifierIndex); $productIdentifierIndex++) {
                     $idTypeNode = $node->getChildByName($this->_getOnixTag('ProductIDType', $shortTags));
                     if ($idTypeNode && $idTypeNode->getValue() == '15') {
                         // ISBN-13
                         $textNode = $node->getChildByName($this->_getOnixTag('IDValue', $shortTags));
                         if ($textNode) {
                             $importData['book_isbn'] = $textNode->getValue();
                         }
                         break;
                     }
                 }
                 // Subjects
                 $importData['subjectKeywords'] = '';
                 $subjects = array();
                 for ($subjectIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('Subject', $shortTags), $subjectIndex); $subjectIndex++) {
                     $textNode = $node->getChildByName($this->_getOnixTag('SubjectHeadingText', $shortTags));
                     if ($textNode) {
                         $subjects[] = $textNode->getValue();
                     }
                 }
                 $importData['subjectKeywords'] = join(', ', $subjects);
                 $publicationDateNode = $productNode->getChildByName($this->_getOnixTag('PublicationDate', $shortTags));
                 if ($publicationDateNode) {
                     $publicationDate = $publicationDateNode->getValue();
                     $importData['date'] = $publicationDate;
                 }
                 // Contributors.
                 $persons = array();
                 for ($authorIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('Contributor', $shortTags), $authorIndex); $authorIndex++) {
                     $firstNameNode = $node->getChildByName($this->_getOnixTag('NamesBeforeKey', $shortTags));
                     if ($firstNameNode) {
                         $firstName = $firstNameNode->getValue();
                     }
                     $lastNameNode = $node->getChildByName($this->_getOnixTag('KeyNames', $shortTags));
                     if ($lastNameNode) {
                         $lastName = $lastNameNode->getValue();
                     }
                     $seqNode = $node->getChildByName($this->_getOnixTag('SequenceNumber', $shortTags));
                     if ($seqNode) {
                         $seq = $seqNode->getValue();
                     }
                     $contributorRoleNode = $node->getChildByName($this->_getOnixTag('ContributorRole', $shortTags));
                     $contributorRole = '';
                     if ($contributorRoleNode) {
                         switch ($contributorRoleNode->getValue()) {
                             case 'A01':
                                 $contributorRole = '1';
                                 break;
                             case 'B01':
                                 $contributorRole = '3';
                                 break;
                             case 'B09':
                                 $contributorRole = '4';
                                 break;
                             case 'B06':
                                 $contributorRole = '5';
                                 break;
                             default:
                                 $contributorRole = '2';
                                 // Contributor
                                 break;
                         }
                     }
                     $persons[] = array('personId' => '', 'role' => $contributorRole, 'firstName' => $firstName, 'middleName' => '', 'lastName' => $lastName, 'seq' => (int) $seq);
                     unset($node);
                 }
                 $importData['persons'] = $persons;
                 if (!$multiple) {
                     $temporaryFileManager->deleteFile($temporaryFile->getId(), $user->getId());
                     $this->editObjectForReview($args, &$request, $importData);
                     break;
                 } else {
                     // we are processing more than one Product.  Instaniate the form and let it
                     // handle the object creation.
                     $ofrForm = new ObjectForReviewForm($ofrPlugin->getName(), null, $reviewObjectTypeId, $importData);
                     $ofrForm->initData();
                     $ofrForm->execute();
                 }
             } else {
                 $request->redirect(null, 'editor', 'objectsForReview', 'onixError');
             }
         }
         $request->redirect(null, 'editor', 'objectsForReview');
     } else {
         // this deleteFile is only called if the document does not parse.
         $temporaryFileManager->deleteFile($temporaryFile->getId(), $user->getId());
         $request->redirect(null, 'editor', 'objectsForReview');
     }
 }