Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
InstitutionalSubscriptionDAO.inc.php
1 <?php
2 
17 import('classes.subscription.SubscriptionDAO');
18 import('classes.subscription.InstitutionalSubscription');
19 
20 define('SUBSCRIPTION_INSTITUTION_NAME', 0x20);
21 define('SUBSCRIPTION_DOMAIN', 0x21);
22 define('SUBSCRIPTION_IP_RANGE', 0x22);
23 
30  function &getSubscription($subscriptionId) {
31  $result =& $this->retrieve(
32  'SELECT s.*, iss.*
33  FROM
34  subscriptions s,
35  subscription_types st,
36  institutional_subscriptions iss
37  WHERE s.type_id = st.type_id
38  AND st.institutional = 1
39  AND s.subscription_id = iss.subscription_id
40  AND s.subscription_id = ?',
41  $subscriptionId
42  );
43 
44  $returner = null;
45  if ($result->RecordCount() != 0) {
46  $returner =& $this->_returnSubscriptionFromRow($result->GetRowAssoc(false));
47  }
48 
49  $result->Close();
50  unset($result);
51 
52  return $returner;
53  }
54 
60  function &getSubscriptionsByUser($userId, $rangeInfo = null) {
61  $result =& $this->retrieveRange(
62  'SELECT s.*, iss.*
63  FROM
64  subscriptions s,
65  subscription_types st,
66  institutional_subscriptions iss
67  WHERE s.type_id = st.type_id
68  AND st.institutional = 1
69  AND s.subscription_id = iss.subscription_id
70  AND s.user_id = ?',
71  $userId,
72  $rangeInfo
73  );
74 
75  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
76 
77  return $returner;
78  }
79 
86  function &getSubscriptionsByUserForJournal($userId, $journalId, $rangeInfo = null) {
87  $result =& $this->retrieveRange(
88  'SELECT s.*, iss.*
89  FROM
90  subscriptions s,
91  subscription_types st,
92  institutional_subscriptions iss
93  WHERE s.type_id = st.type_id
94  AND st.institutional = 1
95  AND s.subscription_id = iss.subscription_id
96  AND s.user_id = ?
97  AND s.journal_id = ?',
98  array(
99  $userId,
100  $journalId
101  ),
102  $rangeInfo
103  );
104 
105  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
106 
107  return $returner;
108  }
109 
117  function &getSubscriptionsByInstitutionName($institutionName, $journalId, $exactMatch = true, $rangeInfo = null) {
118  $sql = 'SELECT s.*, iss.*
119  FROM
120  subscriptions s,
121  subscription_types st,
122  institutional_subscriptions iss
123  WHERE s.type_id = st.type_id
124  AND st.institutional = 1
125  AND s.subscription_id = iss.subscription_id' .
126  $exactMatch ? ' AND LOWER(iss.institution_name) = LOWER(?)'
127  : ' AND LOWER(iss.institution_name) LIKE LOWER(?)'
128  . ' AND s.journal_id = ?';
129 
130  $result =& $this->retrieveRange(
131  $sql,
132  array(
133  $institutionName,
134  $journalId
135  ),
136  $rangeInfo
137  );
138 
139  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
140 
141  return $returner;
142  }
143 
149  function getStatusCount($journalId, $status = null) {
150  $params = array((int) $journalId);
151  if ($status !== null) $params[] = (int) $status;
152 
153  $result =& $this->retrieve(
154  'SELECT COUNT(*)
155  FROM subscriptions s,
156  subscription_types st
157  WHERE s.type_id = st.type_id AND
158  st.institutional = 1 AND
159  s.journal_id = ?
160  ' . ($status !== null?' AND s.status = ?':''),
161  $params
162  );
163 
164  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
165 
166  $result->Close();
167  unset($result);
168 
169  return $returner;
170  }
171 
177  function getSubscribedUserCount($journalId) {
178  return $this->getStatusCount($journalId);
179  }
180 
186  function subscriptionExists($subscriptionId) {
187  $result =& $this->retrieve(
188  'SELECT COUNT(*)
189  FROM
190  subscriptions s,
191  subscription_types st
192  WHERE s.type_id = st.type_id
193  AND st.institutional = 1
194  AND s.subscription_id = ?',
195  $subscriptionId
196  );
197 
198  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
199 
200  $result->Close();
201  unset($result);
202 
203  return $returner;
204  }
205 
212  function subscriptionExistsByUser($subscriptionId, $userId){
213  $result =& $this->retrieve(
214  'SELECT COUNT(*)
215  FROM
216  subscriptions s,
217  subscription_types st
218  WHERE s.type_id = st.type_id
219  AND st.institutional = 1
220  AND s.subscription_id = ?
221  AND s.user_id = ?',
222  array(
223  $subscriptionId,
224  $userId
225  )
226  );
227 
228  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
229 
230  $result->Close();
231  unset($result);
232 
233  return $returner;
234  }
235 
242  function subscriptionExistsByUserForJournal($userId, $journalId) {
243  $result =& $this->retrieve(
244  'SELECT COUNT(*)
245  FROM
246  subscriptions s,
247  subscription_types st
248  WHERE s.type_id = st.type_id
249  AND st.institutional = 1
250  AND s.user_id = ?
251  AND s.journal_id = ?',
252  array(
253  $userId,
254  $journalId
255  )
256  );
257 
258  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
259 
260  $result->Close();
261  unset($result);
262 
263  return $returner;
264  }
265 
273  function subscriptionExistsByInstitutionName($institutionName, $journalId, $exactMatch = true) {
274  $sql = 'SELECT COUNT(*)
275  FROM
276  subscriptions s,
277  subscription_types st,
278  institutional_subscriptions iss
279  WHERE s.type_id = st.type_id
280  AND st.institutional = 1' .
281  $exactMatch ? ' AND LOWER(iss.institution_name) = LOWER(?)'
282  : ' AND LOWER(iss.institution_name) LIKE LOWER(?)'
283  . ' AND s.journal_id = ?';
284 
285  $result =& $this->retrieve(
286  $sql,
287  array(
288  $institutionName,
289  $journalId
290  )
291  );
292 
293  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
294 
295  $result->Close();
296  unset($result);
297 
298  return $returner;
299  }
300 
306  function insertSubscription(&$institutionalSubscription) {
307  $subscriptionId = null;
308  if ($this->_insertSubscription($institutionalSubscription)) {
309  $subscriptionId = $institutionalSubscription->getId();
310 
311  $returner = $this->update(
312  'INSERT INTO institutional_subscriptions
313  (subscription_id, institution_name, mailing_address, domain)
314  VALUES
315  (?, ?, ?, ?)',
316  array(
317  $subscriptionId,
318  $institutionalSubscription->getInstitutionName(),
319  $institutionalSubscription->getInstitutionMailingAddress(),
320  $institutionalSubscription->getDomain()
321  )
322  );
323 
324  $this->_insertSubscriptionIPRanges($subscriptionId, $institutionalSubscription->getIPRanges());
325  }
326 
327  return $subscriptionId;
328  }
329 
335  function updateSubscription(&$institutionalSubscription) {
336  $returner = false;
337  if ($this->_updateSubscription($institutionalSubscription)) {
338 
339  $returner = $this->update(
340  'UPDATE institutional_subscriptions
341  SET
342  institution_name = ?,
343  mailing_address = ?,
344  domain = ?
345  WHERE subscription_id = ?',
346  array(
347  $institutionalSubscription->getInstitutionName(),
348  $institutionalSubscription->getInstitutionMailingAddress(),
349  $institutionalSubscription->getDomain(),
350  $institutionalSubscription->getId()
351  )
352  );
353 
354  $this->_deleteSubscriptionIPRanges($institutionalSubscription->getId());
355  $this->_insertSubscriptionIPRanges($institutionalSubscription->getId(), $institutionalSubscription->getIPRanges());
356  }
357 
358  return $returner;
359  }
360 
366  function deleteSubscriptionById($subscriptionId) {
367  $returner = false;
368  if ($this->subscriptionExists($subscriptionId)) {
369  $returner = $this->update(
370  'DELETE
371  FROM
372  subscriptions
373  WHERE subscription_id = ?',
374  $subscriptionId
375  );
376 
377  $returner = $this->update(
378  'DELETE
379  FROM
380  institutional_subscriptions
381  WHERE subscription_id = ?',
382  $subscriptionId
383  );
384 
385  $this->_deleteSubscriptionIPRanges($subscriptionId);
386  }
387  return $returner;
388  }
389 
395  function deleteSubscriptionsByJournal($journalId) {
396  $result =& $this->retrieve(
397  'SELECT s.subscription_id
398  FROM
399  subscriptions s
400  WHERE s.journal_id = ?',
401  $journalId
402  );
403 
404  $returner = true;
405  if ($result->RecordCount() != 0) {
406  while (!$result->EOF) {
407  $subscriptionId = $result->fields[0];
408  $returner = $this->deleteSubscriptionById($subscriptionId);
409  if (!$returner) {
410  break;
411  }
412  $result->moveNext();
413  }
414  }
415 
416  $result->Close();
417  unset($result);
418 
419  return $returner;
420  }
421 
427  function deleteSubscriptionsByUserId($userId) {
428  $result =& $this->retrieve(
429  'SELECT s.subscription_id
430  FROM
431  subscriptions s
432  WHERE s.user_id = ?',
433  $userId
434  );
435 
436  $returner = true;
437  if ($result->RecordCount() != 0) {
438  while (!$result->EOF) {
439  $subscriptionId = $result->fields[0];
440  $returner = $this->deleteSubscriptionById($subscriptionId);
441  if (!$returner) {
442  break;
443  }
444  $result->moveNext();
445  }
446  }
447 
448  $result->Close();
449  unset($result);
450 
451  return $returner;
452  }
453 
460  function deleteSubscriptionsByUserIdForJournal($userId, $journalId) {
461  $result =& $this->retrieve(
462  'SELECT s.subscription_id
463  FROM
464  subscriptions s
465  WHERE s.user_id = ?
466  AND s.journal_id = ?',
467  array (
468  $userId,
469  $journalId
470  )
471  );
472 
473  $returner = true;
474  if ($result->RecordCount() != 0) {
475  while (!$result->EOF) {
476  $subscriptionId = $result->fields[0];
477  $returner = $this->deleteSubscriptionById($subscriptionId);
478  if (!$returner) {
479  break;
480  }
481  $result->moveNext();
482  }
483  }
484 
485  $result->Close();
486  unset($result);
487 
488  return $returner;
489  }
490 
496  function deleteSubscriptionsByTypeId($subscriptionTypeId) {
497  $result =& $this->retrieve(
498  'SELECT s.subscription_id
499  FROM
500  subscriptions s
501  WHERE s.type_id = ?',
502  $subscriptionTypeId
503  );
504 
505  $returner = true;
506  if ($result->RecordCount() != 0) {
507  while (!$result->EOF) {
508  $subscriptionId = $result->fields[0];
509  $returner = $this->deleteSubscriptionById($subscriptionId);
510  if (!$returner) {
511  break;
512  }
513  $result->moveNext();
514  }
515  }
516 
517  $result->Close();
518  unset($result);
519 
520  return $returner;
521  }
522 
527  function &getSubscriptions($rangeInfo = null) {
528  $result =& $this->retrieveRange(
529  'SELECT s.*, iss.*
530  FROM
531  subscriptions s,
532  subscription_types st,
533  institutional_subscriptions iss
534  WHERE s.type_id = st.type_id
535  AND st.institutional = 1
536  AND s.subscription_id = iss.subscription_id
537  ORDER BY
538  iss.institution_name ASC,
539  s.subscription_id',
540  false,
541  $rangeInfo
542  );
543 
544  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
545 
546  return $returner;
547  }
548 
553  function &getSubscribedUsers($journalId, $rangeInfo = null) {
554  $result =& $this->retrieveRange(
555  'SELECT u.*
556  FROM subscriptions s,
557  subscription_types st,
558  users u
559  WHERE s.type_id = st.type_id AND
560  st.institutional = 1 AND
561  s.user_id = u.user_id AND
562  s.journal_id = ?
563  ORDER BY u.last_name ASC, s.subscription_id',
564  array((int) $journalId),
565  $rangeInfo
566  );
567 
568  $userDao =& DAORegistry::getDAO('UserDAO');
569  $returner = new DAOResultFactory($result, $userDao, '_returnUserFromRow');
570 
571  return $returner;
572  }
573 
586  function &getSubscriptionsByJournalId($journalId, $status = null, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $rangeInfo = null) {
587 
588  $params = array($journalId);
589  $ipRangeSql1 = $ipRangeSql2 = '';
590  $searchSql = $this->_generateSearchSQL($status, $searchField, $searchMatch, $search, $dateField, $dateFrom, $dateTo, $params);
591 
592  if (!empty($search)) switch ($searchField) {
593  case SUBSCRIPTION_INSTITUTION_NAME:
594  if ($searchMatch === 'is') {
595  $searchSql = ' AND LOWER(iss.institution_name) = LOWER(?)';
596  } elseif ($searchMatch === 'contains') {
597  $searchSql = ' AND LOWER(iss.institution_name) LIKE LOWER(?)';
598  $search = '%' . $search . '%';
599  } else { // $searchMatch === 'startsWith'
600  $searchSql = ' AND LOWER(iss.institution_name) LIKE LOWER(?)';
601  $search = $search . '%';
602  }
603  $params[] = $search;
604  break;
605  case SUBSCRIPTION_DOMAIN:
606  if ($searchMatch === 'is') {
607  $searchSql = ' AND LOWER(iss.domain) = LOWER(?)';
608  } elseif ($searchMatch === 'contains') {
609  $searchSql = ' AND LOWER(iss.domain) LIKE LOWER(?)';
610  $search = '%' . $search . '%';
611  } else { // $searchMatch === 'startsWith'
612  $searchSql = ' AND LOWER(iss.domain) LIKE LOWER(?)';
613  $search = $search . '%';
614  }
615  $params[] = $search;
616  break;
617  case SUBSCRIPTION_IP_RANGE:
618  if ($searchMatch === 'is') {
619  $searchSql = ' AND LOWER(isip.ip_string) = LOWER(?)';
620  } elseif ($searchMatch === 'contains') {
621  $searchSql = ' AND LOWER(isip.ip_string) LIKE LOWER(?)';
622  $search = '%' . $search . '%';
623  } else { // $searchMatch === 'startsWith'
624  $searchSql = ' AND LOWER(isip.ip_string) LIKE LOWER(?)';
625  $search = $search . '%';
626  }
627  $params[] = $search;
628  $ipRangeSql1 = ', institutional_subscription_ip isip' ;
629  $ipRangeSql2 = ' AND s.subscription_id = isip.subscription_id';
630  break;
631  }
632 
633  $sql = 'SELECT DISTINCT
634  s.*, iss.*
635  FROM
636  subscriptions s,
637  subscription_types st,
638  users u,
639  institutional_subscriptions iss'
640  . $ipRangeSql1 .
641  ' WHERE s.type_id = st.type_id
642  AND s.user_id = u.user_id
643  AND st.institutional = 1
644  AND s.subscription_id = iss.subscription_id'
645  . $ipRangeSql2 .
646  ' AND s.journal_id = ?';
647 
648  $result =& $this->retrieveRange(
649  $sql . ' ' . $searchSql . ' ORDER BY iss.institution_name ASC, s.subscription_id',
650  count($params)===1?array_shift($params):$params,
651  $rangeInfo
652  );
653 
654  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
655 
656  return $returner;
657  }
658 
668  function isValidInstitutionalSubscription($domain, $IP, $journalId, $check = SUBSCRIPTION_DATE_BOTH, $checkDate = null) {
669  if (empty($journalId) || (empty($domain) && empty($IP))) {
670  return false;
671  }
672  $returner = false;
673 
674  $today = $this->dateToDB(Core::getCurrentDate());
675 
676  if ($checkDate == null) {
677  $checkDate = $today;
678  } else {
679  $checkDate = $this->dateToDB($checkDate);
680  }
681 
682  switch($check) {
683  case SUBSCRIPTION_DATE_START:
684  $dateSql = sprintf('%s >= s.date_start AND %s >= s.date_start', $checkDate, $today);
685  break;
686  case SUBSCRIPTION_DATE_END:
687  $dateSql = sprintf('%s <= s.date_end AND %s >= s.date_start', $checkDate, $today);
688  break;
689  default:
690  $dateSql = sprintf('%s >= s.date_start AND %s <= s.date_end', $checkDate, $checkDate);
691  }
692 
693  $nonExpiringSql = "AND ((st.non_expiring = 1) OR (st.non_expiring = 0 AND ($dateSql)))";
694 
695  // Check if domain match
696  if (!empty($domain)) {
697  $result =& $this->retrieve('
698  SELECT iss.subscription_id
699  FROM
700  institutional_subscriptions iss,
701  subscriptions s,
702  subscription_types st
703  WHERE POSITION(UPPER(LPAD(iss.domain, LENGTH(iss.domain)+1, \'.\')) IN UPPER(LPAD(?, LENGTH(?)+1, \'.\'))) != 0
704  AND iss.domain != \'\'
705  AND iss.subscription_id = s.subscription_id
706  AND s.journal_id = ?
707  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . '
708  AND s.type_id = st.type_id
709  AND st.institutional = 1 '
710  . $nonExpiringSql .
711  ' AND (st.format = ' . SUBSCRIPTION_TYPE_FORMAT_ONLINE . '
712  OR st.format = ' . SUBSCRIPTION_TYPE_FORMAT_PRINT_ONLINE . ')',
713  array(
714  $domain,
715  $domain,
716  $journalId
717  )
718  );
719 
720  if ($result->RecordCount() != 0) {
721  $returner = $result->fields[0];
722  }
723 
724  $result->Close();
725  unset($result);
726 
727  if ($returner) {
728  return $returner;
729  }
730  }
731 
732  // Check for IP match
733  if (!empty($IP)) {
734  $IP = sprintf('%u', ip2long($IP));
735 
736  $result =& $this->retrieve('
737  SELECT isip.subscription_id
738  FROM
739  institutional_subscription_ip isip,
740  subscriptions s,
741  subscription_types st
742  WHERE ((isip.ip_end IS NOT NULL
743  AND ? >= isip.ip_start AND ? <= isip.ip_end
744  AND isip.subscription_id = s.subscription_id
745  AND s.journal_id = ?
746  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . '
747  AND s.type_id = st.type_id
748  AND st.institutional = 1 '
749  . $nonExpiringSql .
750  ' AND (st.format = ' . SUBSCRIPTION_TYPE_FORMAT_ONLINE . '
751  OR st.format = ' . SUBSCRIPTION_TYPE_FORMAT_PRINT_ONLINE . '))
752  OR (isip.ip_end IS NULL
753  AND ? = isip.ip_start
754  AND isip.subscription_id = s.subscription_id
755  AND s.journal_id = ?
756  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . '
757  AND s.type_id = st.type_id
758  AND st.institutional = 1 '
759  . $nonExpiringSql .
760  ' AND (st.format = ' . SUBSCRIPTION_TYPE_FORMAT_ONLINE . '
761  OR st.format = ' . SUBSCRIPTION_TYPE_FORMAT_PRINT_ONLINE . ')))',
762  array (
763  $IP,
764  $IP,
765  $journalId,
766  $IP,
767  $journalId
768  )
769  );
770 
771  if ($result->RecordCount() != 0) {
772  $returner = $result->fields[0];
773  }
774 
775  $result->Close();
776  unset($result);
777  }
778 
779  return $returner;
780  }
781 
789  function &getSubscriptionsToRemind($dateEnd, $journalId, $reminderType, $rangeInfo = null) {
790  $result =& $this->retrieveRange(
791  sprintf(
792  'SELECT s.*, iss.*
793  FROM subscriptions s,
794  subscription_types st,
795  institutional_subscriptions iss
796  WHERE s.type_id = st.type_id
797  AND s.status = ?
798  AND st.institutional = 1
799  AND s.subscription_id = iss.subscription_id
800  AND s.date_end <= %s
801  AND s.' . ($reminderType==SUBSCRIPTION_REMINDER_FIELD_BEFORE_EXPIRY?'date_reminded_before':'date_reminded_after') . ' IS NULL
802  AND s.journal_id = ?
803  ORDER BY iss.institution_name ASC, s.subscription_id',
804  $this->datetimeToDB($dateEnd)
805  ), array(
806  SUBSCRIPTION_STATUS_ACTIVE,
807  (int) $journalId
808  ),
809  $rangeInfo
810  );
811 
812  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
813 
814  return $returner;
815  }
816 
823  function renewSubscription(&$institutionalSubscription) {
824  return $this->_renewSubscription($institutionalSubscription);
825  }
826 
831  function createObject() {
832  return new InstitutionalSubscription();
833  }
834 
840  function &_returnSubscriptionFromRow(&$row) {
841  $institutionalSubscription = parent::_returnSubscriptionFromRow($row);
842 
843  $institutionalSubscription->setInstitutionName($row['institution_name']);
844  $institutionalSubscription->setInstitutionMailingAddress($row['mailing_address']);
845  $institutionalSubscription->setDomain($row['domain']);
846 
847  $ipResult =& $this->retrieve(
848  'SELECT ip_string
849  FROM
850  institutional_subscription_ip
851  WHERE subscription_id = ?
852  ORDER BY institutional_subscription_ip_id ASC',
853  $institutionalSubscription->getId()
854  );
855 
856  $ipRanges = array();
857  while (!$ipResult->EOF) {
858  $ipRow =& $ipResult->GetRowAssoc(false);
859  $ipRanges[] = $ipRow['ip_string'];
860  $ipResult->moveNext();
861  }
862 
863  $institutionalSubscription->setIPRanges($ipRanges);
864  $ipResult->Close();
865  unset($ipResult);
866 
867  HookRegistry::call('InstitutionalSubscriptionDAO::_returnSubscriptionFromRow', array(&$institutionalSubscription, &$row));
868 
869  return $institutionalSubscription;
870  }
871 
878  function _insertSubscriptionIPRanges($subscriptionId, $ipRanges) {
879  if (empty($ipRanges)) {
880  return true;
881  }
882 
883  if (empty($subscriptionId)) {
884  return false;
885  }
886 
887  $returner = true;
888 
889  while (list(, $curIPString) = each($ipRanges)) {
890  $ipStart = null;
891  $ipEnd = null;
892 
893  // Parse and check single IP string
894  if (strpos($curIPString, SUBSCRIPTION_IP_RANGE_RANGE) === false) {
895 
896  // Check for wildcards in IP
897  if (strpos($curIPString, SUBSCRIPTION_IP_RANGE_WILDCARD) === false) {
898 
899  // Get non-CIDR IP
900  if (strpos($curIPString, '/') === false) {
901  $ipStart = sprintf("%u", ip2long(trim($curIPString)));
902 
903  // Convert CIDR IP to IP range
904  } else {
905  list($cidrIPString, $cidrBits) = explode('/', trim($curIPString));
906 
907  if ($cidrBits == 0) {
908  $cidrMask = 0;
909  } else {
910  $cidrMask = (0xffffffff << (32 - $cidrBits));
911  }
912 
913  $ipStart = sprintf('%u', ip2long($cidrIPString) & $cidrMask);
914 
915  if ($cidrBits != 32) {
916  $ipEnd = sprintf('%u', ip2long($cidrIPString) | (~$cidrMask & 0xffffffff));
917  }
918  }
919 
920  // Convert wildcard IP to IP range
921  } else {
922  $ipStart = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '0', trim($curIPString))));
923  $ipEnd = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '255', trim($curIPString))));
924  }
925 
926  // Convert wildcard IP range to IP range
927  } else {
928  list($ipStart, $ipEnd) = explode(SUBSCRIPTION_IP_RANGE_RANGE, $curIPString);
929 
930  // Replace wildcards in start and end of range
931  $ipStart = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '0', trim($ipStart))));
932  $ipEnd = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '255', trim($ipEnd))));
933  }
934 
935  // Insert IP or IP range
936  if (($ipStart != null) && ($returner)) {
937  $returner = $this->update(
938  'INSERT INTO institutional_subscription_ip
939  (subscription_id, ip_string, ip_start, ip_end)
940  VALUES
941  (?, ?, ?, ?)',
942  array(
943  $subscriptionId,
944  $curIPString,
945  $ipStart,
946  $ipEnd
947  )
948  );
949  } else {
950  $returner = false;
951  break;
952  }
953 
954  }
955 
956  return $returner;
957  }
958 
964  function _deleteSubscriptionIPRanges($subscriptionId) {
965  return $this->update(
966  'DELETE FROM institutional_subscription_ip WHERE subscription_id = ?', $subscriptionId
967  );
968  }
969 }
970 
971 ?>
_renewSubscription(&$subscription)
_updateSubscription(&$subscription)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
Basic class describing an institutional subscription.
getCurrentDate($ts=null)
Definition: Core.inc.php:94
dateToDB($d)
Definition: DAO.inc.php:306
Abstract class for retrieving and modifying subscriptions.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
_insertSubscription(&$subscription)
subscriptionExistsByInstitutionName($institutionName, $journalId, $exactMatch=true)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
_insertSubscriptionIPRanges($subscriptionId, $ipRanges)
Operations for retrieving and modifying InstitutionalSubscription objects.
& getDAO($name, $dbconn=null)
insertSubscription(&$institutionalSubscription)
updateSubscription(&$institutionalSubscription)
call($hookName, $args=null)
& getSubscriptionsToRemind($dateEnd, $journalId, $reminderType, $rangeInfo=null)
isValidInstitutionalSubscription($domain, $IP, $journalId, $check=SUBSCRIPTION_DATE_BOTH, $checkDate=null)
& getSubscriptionsByJournalId($journalId, $status=null, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $rangeInfo=null)
_generateSearchSQL($status=null, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, &$params)
& getSubscriptionsByInstitutionName($institutionName, $journalId, $exactMatch=true, $rangeInfo=null)
& getSubscribedUsers($journalId, $rangeInfo=null)
datetimeToDB($dt)
Definition: DAO.inc.php:296
subscriptionExistsByUser($subscriptionId, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
renewSubscription(&$institutionalSubscription)
& getSubscriptionsByUserForJournal($userId, $journalId, $rangeInfo=null)
& getSubscriptionsByUser($userId, $rangeInfo=null)