00001 <?php
00002
00019
00020
00021
00022 import('scheduledTask.ScheduledTask');
00023
00024 class OpenAccessNotification extends ScheduledTask {
00025
00029 function OpenAccessNotification() {
00030 $this->ScheduledTask();
00031 }
00032
00033 function sendNotification ($users, $journal, $issue) {
00034 if ($users->getCount() != 0) {
00035
00036 import('mail.MailTemplate');
00037 $email = &new MailTemplate('OPEN_ACCESS_NOTIFY');
00038
00039 $email->setSubject($email->getSubject($journal->getPrimaryLocale()));
00040 $email->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
00041 $email->addRecipient($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
00042
00043 $paramArray = array(
00044 'journalName' => $journal->getJournalTitle(),
00045 'journalUrl' => $journal->getUrl(),
00046 'editorialContactSignature' => $journal->getSetting('contactName') . "\n" . $journal->getJournalTitle()
00047 );
00048 $email->assignParams($paramArray);
00049
00050 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00051 $publishedArticles = &$publishedArticleDao->getPublishedArticlesInSections($issue->getIssueId());
00052 $mimeBoundary = '==boundary_' . md5(microtime());
00053
00054 $templateMgr = &TemplateManager::getManager();
00055 $templateMgr->assign('body', $email->getBody($journal->getPrimaryLocale()));
00056 $templateMgr->assign('templateSignature', $journal->getSetting('emailSignature'));
00057 $templateMgr->assign('mimeBoundary', $mimeBoundary);
00058 $templateMgr->assign_by_ref('issue', $issue);
00059 $templateMgr->assign_by_ref('publishedArticles', $publishedArticles);
00060
00061 $email->addHeader('MIME-Version', '1.0');
00062 $email->setContentType('multipart/alternative; boundary="'.$mimeBoundary.'"');
00063 $email->setBody($templateMgr->fetch('subscription/openAccessNotifyEmail.tpl'));
00064
00065 while (!$users->eof()) {
00066 $user = &$users->next();
00067 $email->addBcc($user->getEmail(), $user->getFullName());
00068 }
00069
00070 $email->send();
00071 }
00072 }
00073
00074 function sendNotifications ($journal, $curDate) {
00075
00076
00077 if ($journal->getSetting('enableSubscriptions') && $journal->getSetting('enableOpenAccessNotification')) {
00078
00079 $curYear = $curDate['year'];
00080 $curMonth = $curDate['month'];
00081 $curDay = $curDate['day'];
00082
00083
00084 $issueDao = &DAORegistry::getDAO('IssueDAO');
00085 $issues = &$issueDao->getPublishedIssues($journal->getJournalId());
00086
00087 while (!$issues->eof()) {
00088 $issue = &$issues->next();
00089
00090 $accessStatus = $issue->getAccessStatus();
00091 $openAccessDate = $issue->getOpenAccessDate();
00092
00093 if ($accessStatus == SUBSCRIPTION && !empty($openAccessDate) && strtotime($openAccessDate) == mktime(0,0,0,$curMonth, $curDay, $curYear)) {
00094
00095 $userSettingsDao = &DAORegistry::getDAO('UserSettingsDAO');
00096 $users = &$userSettingsDao->getUsersBySetting('openAccessNotification', true, 'bool', $journal->getJournalId());
00097 $this->sendNotification($users, $journal, $issue);
00098 }
00099 }
00100 }
00101 }
00102
00103 function execute() {
00104
00105 $journalDao = &DAORegistry::getDAO('JournalDAO');
00106 $journals = &$journalDao->getEnabledJournals();
00107
00108 $todayDate = array(
00109 'year' => date('Y'),
00110 'month' => date('n'),
00111 'day' => date('j')
00112 );
00113
00114 while (!$journals->eof()) {
00115 $journal = &$journals->next();
00116
00117
00118 $this->sendNotifications($journal, $todayDate);
00119 unset($journal);
00120 }
00121
00122
00123
00124
00125 $shortMonths = array(2,4,6,8,10,12);
00126
00127 if (($todayDate['day'] == 1) && in_array(($todayDate['month'] - 1), $shortMonths)) {
00128
00129 $curDate['day'] = 31;
00130 $curDate['month'] = $todayDate['month'] - 1;
00131
00132 if ($curDate['month'] == 12) {
00133 $curDate['year'] = $todayDate['year'] - 1;
00134 } else {
00135 $curDate['year'] = $todayDate['year'];
00136 }
00137
00138 $journals = &$journalDao->getEnabledJournals();
00139
00140 while (!$journals->eof()) {
00141 $journal = &$journals->next();
00142
00143
00144 $this->sendNotifications($journal, $curDate);
00145 unset($journal);
00146 }
00147 }
00148
00149
00150
00151 if (($todayDate['day'] == 1) && ($todayDate['month'] == 3)) {
00152
00153 $curDate['day'] = 30;
00154 $curDate['month'] = 2;
00155 $curDate['year'] = $todayDate['year'];
00156
00157 $journals = &$journalDao->getEnabledJournals();
00158
00159 while (!$journals->eof()) {
00160 $journal = &$journals->next();
00161
00162
00163 $this->sendNotifications($journal, $curDate);
00164 unset($journal);
00165 }
00166
00167
00168 if (date("L", mktime(0,0,0,0,0,$curDate['year'])) != '1') {
00169
00170 $curDate['day'] = 29;
00171
00172 $journals = &$journalDao->getEnabledJournals();
00173
00174 while (!$journals->eof()) {
00175 $journal = &$journals->next();
00176
00177
00178 $this->sendNotifications($journal, $curDate);
00179 unset($journal);
00180 }
00181 }
00182 }
00183 }
00184 }
00185
00186 ?>