diff --git a/.gitignore b/.gitignore
index 9631778..9dc8805 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
-.DS_Store
-/admin/configuration.ini
-/archive/*
-/logs/*
-/sushistore/*
+.DS_Store
+/admin/configuration.ini
+/archive/*
+/logs/*
+/sushistore/*
+*.bak
diff --git a/LangCodes.php b/LangCodes.php
new file mode 100644
index 0000000..13aa984
--- /dev/null
+++ b/LangCodes.php
@@ -0,0 +1,29 @@
+'fr_FR',
+ 'en_US'=>'en_US'//,
+ //'zh_CN'=>'zh_CN',
+ //'zh_TW'=>'zh_TW',
+ //'de_DE'=>'de_DE'
+ );
+ return array_key_exists($code, $all_lang) ? $all_lang[$code] : "en_US";
+ }
+ public function getNameLang($code_lang){
+ $name_lang=array(
+ 'fr_FR'=>'Français',
+ 'en_US'=>'English'//,
+ //'zh_CN'=>'中文 (中国)',
+ //'zh_TW'=>'中文 (台灣)',
+ //'de_DE'=>'Deutsch'
+ );
+ return array_key_exists($code_lang, $name_lang) ? $name_lang[$code_lang] : "English";
+ }
+}
+?>
\ No newline at end of file
diff --git a/README b/README
index 91c50d3..776a260 100755
--- a/README
+++ b/README
@@ -1,39 +1,38 @@
-**************************
-Installation
-Copy this entire directory to your web server under a directory named '/coral/usage/', then point your web browser to:
-http://your_server/coral/usage/install/
-and follow instructions
-
-For the manual install, refer to the Technical Documentation available on http://erm.library.nd.edu
-
-
-**************************
-License / Copyright notices
-
-Copyright (c) 2013 University of Notre Dame
-This file is part of CORAL.
-CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
-CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along with CORAL. If not, see .
-
-
-Parts of code used in the SushiService class is reused from Sushi Starters. Here is their license:
-Copyright (c) 2011, Cranfield University
- All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-
-More information on Sushi Starters here:
-http://cclibweb-4.dmz.cranfield.ac.uk/projects/sushistarters/
-
-
-
-**************************
-To contact the CORAL Developers:
-CORAL-ADMIN@LISTSERV.ND.EDU
+**************************
+Installation
+Copy this entire directory to your web server under a directory named '/coral/usage/', then point your web browser to:
+http://your_server/coral/usage/install/
+and follow instructions
+
+For the manual install, refer to the Technical Documentation available on http://erm.library.nd.edu
+
+**************************
+License / Copyright notices
+
+Copyright (c) 2013 University of Notre Dame
+This file is part of CORAL.
+CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+You should have received a copy of the GNU General Public License along with CORAL. If not, see .
+
+
+Parts of code used in the SushiService class is reused from Sushi Starters. Here is their license:
+Copyright (c) 2011, Cranfield University
+ All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+More information on Sushi Starters here:
+http://cclibweb-4.dmz.cranfield.ac.uk/projects/sushistarters/
+
+
+
+**************************
+To contact the CORAL Developers:
+CORAL-ADMIN@LISTSERV.ND.EDU
diff --git a/admin.php b/admin.php
index f1b64e9..e6bfaaa 100755
--- a/admin.php
+++ b/admin.php
@@ -1,5 +1,5 @@
diff --git a/admin/classes/common/Configuration.php b/admin/classes/common/Configuration.php
index e650f3a..5a1420f 100755
--- a/admin/classes/common/Configuration.php
+++ b/admin/classes/common/Configuration.php
@@ -1,32 +1,36 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-
-class Configuration extends DynamicObject {
-
- public function init(NamedArguments $arguments) {
- $arguments->setDefaultValueForArgumentName('filename', BASE_DIR . '/admin/configuration.ini');
- $config = parse_ini_file($arguments->filename, true);
- foreach ($config as $section => $entries) {
- $this->$section = Utility::objectFromArray($entries);
- }
- }
-
-}
-
+.
+**
+**************************************************************************************************************************
+*/
+
+
+class Configuration extends DynamicObject {
+
+ public function init(NamedArguments $arguments) {
+ $arguments->setDefaultValueForArgumentName('filename', BASE_DIR . 'admin/configuration.ini');
+ if ((file_exists($arguments->filename)) and (is_readable($arguments->filename))) {
+ $config = parse_ini_file($arguments->filename, true);
+ } else {
+ die( BASE_DIR . 'admin/configuration.ini is missing or unreadable.');
+ }
+ foreach ($config as $section => $entries) {
+ $this->$section = Utility::objectFromArray($entries);
+ }
+ }
+
+}
+
?>
\ No newline at end of file
diff --git a/admin/classes/common/DBService.php b/admin/classes/common/DBService.php
index 4cc44e0..000d9ab 100755
--- a/admin/classes/common/DBService.php
+++ b/admin/classes/common/DBService.php
@@ -36,7 +36,7 @@ protected function dealloc() {
protected function checkForError() {
if ($this->error = mysqli_error($this->db)) {
- throw new Exception("There was a problem with the database: " . $this->error);
+ throw new Exception(_("There was a problem with the database: ") . $this->error);
}
}
diff --git a/admin/classes/common/LdapPerson.php b/admin/classes/common/LdapPerson.php
index 7365fd6..b1cfc79 100755
--- a/admin/classes/common/LdapPerson.php
+++ b/admin/classes/common/LdapPerson.php
@@ -1,64 +1,64 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-
-class LdapPerson extends DynamicObject {
-
- public function __construct($userKey) {
-
- $config = new Configuration;
-
- //try to connect to ldap if the settings are entered
- if ($config->ldap->host) {
-
- //If you are using OpenLDAP 2.x.x you can specify a URL instead of the hostname. To use LDAP with SSL, compile OpenLDAP 2.x.x with SSL support, configure PHP with SSL, and set this parameter as ldaps://hostname/.
- //note that connect happens regardless if host is valid
- $ds = ldap_connect($config->ldap->host);
-
- //may need ldap_bind( $ds, $username, $password )
- $bd = ldap_bind($ds) or die("
Could not connect to " . $config->ldap->host . "
");
-
- if ($bd){
- $filter = $config->ldap->search_key . "=" . $userKey;
-
- $sr = ldap_search($ds, $config->ldap->base_dn, $filter);
-
- if ($entries = ldap_get_entries($ds, $sr)) {
- $entry = $entries[0];
-
- $fieldNames = array('fname', 'lname', 'email', 'phone', 'department', 'title', 'address');
-
- foreach ($fieldNames as $fieldName) {
- $configName = $fieldName . '_field';
-
- $this->$fieldName = $entry[$config->ldap->$configName][0];
-
- }
- $this->fullname = addslashes($this->fname . ' ' . $this->lname);
-
- }
-
- ldap_close($ds);
-
- }
- }
- }
-
-}
-
+.
+**
+**************************************************************************************************************************
+*/
+
+
+class LdapPerson extends DynamicObject {
+
+ public function __construct($userKey) {
+
+ $config = new Configuration;
+
+ //try to connect to ldap if the settings are entered
+ if ($config->ldap->host) {
+
+ //If you are using OpenLDAP 2.x.x you can specify a URL instead of the hostname. To use LDAP with SSL, compile OpenLDAP 2.x.x with SSL support, configure PHP with SSL, and set this parameter as ldaps://hostname/.
+ //note that connect happens regardless if host is valid
+ $ds = ldap_connect($config->ldap->host);
+
+ //may need ldap_bind( $ds, $username, $password )
+ $bd = ldap_bind($ds) or die("
"._("Could not connect to ") . $config->ldap->host . "
");
+
+ if ($bd){
+ $filter = $config->ldap->search_key . "=" . $userKey;
+
+ $sr = ldap_search($ds, $config->ldap->base_dn, $filter);
+
+ if ($entries = ldap_get_entries($ds, $sr)) {
+ $entry = $entries[0];
+
+ $fieldNames = array('fname', 'lname', 'email', 'phone', 'department', 'title', 'address');
+
+ foreach ($fieldNames as $fieldName) {
+ $configName = $fieldName . '_field';
+
+ $this->$fieldName = $entry[$config->ldap->$configName][0];
+
+ }
+ $this->fullname = addslashes($this->fname . ' ' . $this->lname);
+
+ }
+
+ ldap_close($ds);
+
+ }
+ }
+ }
+
+}
+
?>
\ No newline at end of file
diff --git a/admin/classes/common/Object.php b/admin/classes/common/Object.php
index d356817..2b590de 100755
--- a/admin/classes/common/Object.php
+++ b/admin/classes/common/Object.php
@@ -1,89 +1,89 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-
-class Object {
-
- public function __construct(NamedArguments $arguments = NULL) {
- if (method_exists($this, 'init')) {
- if (!is_a($arguments, 'NamedArguments')) {
- $arguments = new NamedArguments(array());
- }
- $this->init($arguments);
- }
- }
-
- // An optional initializer to use instead of |__construct()|.
- protected function init(NamedArguments $arguments) {
-
- }
-
- public function __destruct() {
- if (method_exists($this, 'dealloc')) {
- $this->dealloc();
- }
- }
-
- // An optional method called on deconstruction instead of |__deconstruct()|.
- protected function dealloc() {
-
- }
-
- // Setters are functions called |$instance->setPropertyName($value)|.
- public function __set($name, $value) {
- $methodName = 'set' . ucfirst($name);
- $this->$methodName($value);
- }
-
- // Getters are functions called |$instance->propertyName()|.
- public function __get($name) {
- return $this->$name();
- }
-
- // Default setter uses declared properties.
- protected function setValueForKey($key, $value) {
- if (property_exists($this, $key)) {
- $this->$key = $value;
- } else {
- throw new Exception("Cannot set value for undefined key ($key).");
- }
- }
-
- // Default getter uses declared properties.
- protected function valueForKey($key) {
- if (property_exists($this, $key)) {
- return $this->$key;
- } else {
- throw new Exception("Cannot get value for undefined key ($key).");
- }
- }
-
- // Call |valueForKey| and |setValueForKey| as default setter and getter.
- public function __call($name, $arguments) {
- if (preg_match('/^set[A-Z]/', $name)) {
- $key = preg_replace('/^set/', '\1', $name);
- $key = lcfirst($key);
- $this->setValueForKey($key, $arguments[0]);
- } else {
- return $this->valueForKey($name);
- }
- }
-
-}
-
+.
+**
+**************************************************************************************************************************
+*/
+
+
+class Object {
+
+ public function __construct(NamedArguments $arguments = NULL) {
+ if (method_exists($this, 'init')) {
+ if (!is_a($arguments, 'NamedArguments')) {
+ $arguments = new NamedArguments(array());
+ }
+ $this->init($arguments);
+ }
+ }
+
+ // An optional initializer to use instead of |__construct()|.
+ protected function init(NamedArguments $arguments) {
+
+ }
+
+ public function __destruct() {
+ if (method_exists($this, 'dealloc')) {
+ $this->dealloc();
+ }
+ }
+
+ // An optional method called on deconstruction instead of |__deconstruct()|.
+ protected function dealloc() {
+
+ }
+
+ // Setters are functions called |$instance->setPropertyName($value)|.
+ public function __set($name, $value) {
+ $methodName = 'set' . ucfirst($name);
+ $this->$methodName($value);
+ }
+
+ // Getters are functions called |$instance->propertyName()|.
+ public function __get($name) {
+ return $this->$name();
+ }
+
+ // Default setter uses declared properties.
+ protected function setValueForKey($key, $value) {
+ if (property_exists($this, $key)) {
+ $this->$key = $value;
+ } else {
+ throw new Exception(_("Cannot set value for undefined key (").$key.").");
+ }
+ }
+
+ // Default getter uses declared properties.
+ protected function valueForKey($key) {
+ if (property_exists($this, $key)) {
+ return $this->$key;
+ } else {
+ throw new Exception(_("Cannot get value for undefined key (").$key.").");
+ }
+ }
+
+ // Call |valueForKey| and |setValueForKey| as default setter and getter.
+ public function __call($name, $arguments) {
+ if (preg_match('/^set[A-Z]/', $name)) {
+ $key = preg_replace('/^set/', '\1', $name);
+ $key = lcfirst($key);
+ $this->setValueForKey($key, $arguments[0]);
+ } else {
+ return $this->valueForKey($name);
+ }
+ }
+
+}
+
?>
\ No newline at end of file
diff --git a/admin/classes/common/Utility.php b/admin/classes/common/Utility.php
index 9e55623..f3ada5a 100755
--- a/admin/classes/common/Utility.php
+++ b/admin/classes/common/Utility.php
@@ -1,136 +1,136 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-
-class Utility {
-
- static public function unixTimeFromMysqlTimestamp($timestamp) {
-
- // taken from Dan Green, and then modified to be correct
- // http://www.weberdev.com/get_example-1427.html
-
- $year = substr($timestamp,0,4);
- $month = substr($timestamp,5,2);
- $day = substr($timestamp,8,2);
- $hour = substr($timestamp,11,2);
- $minute = substr($timestamp,14,2);
- $second = substr($timestamp,17,2);
- $newdate = mktime($hour,$minute,$second,$month,$day,$year);
-
- return $newdate;
-
- }
-
- static public function secondsFromDays($days) {
- return $days * 24 * 60 * 60;
- }
-
- static public function objectFromArray($array) {
- $object = new DynamicObject;
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- $object->$key = Utility::objectFromArray($value);
- } else {
- $object->$key = $value;
- }
- }
- return $object;
- }
-
- //returns file path up to /coral/
- static public function getCORALPath(){
- $pagePath = $_SERVER["DOCUMENT_ROOT"];
-
- $currentFile = $_SERVER["SCRIPT_NAME"];
- $parts = Explode('/', $currentFile);
- for($i=0; $i.
+**
+**************************************************************************************************************************
+*/
+
+
+class Utility {
+
+ static public function unixTimeFromMysqlTimestamp($timestamp) {
+
+ // taken from Dan Green, and then modified to be correct
+ // http://www.weberdev.com/get_example-1427.html
+
+ $year = substr($timestamp,0,4);
+ $month = substr($timestamp,5,2);
+ $day = substr($timestamp,8,2);
+ $hour = substr($timestamp,11,2);
+ $minute = substr($timestamp,14,2);
+ $second = substr($timestamp,17,2);
+ $newdate = mktime($hour,$minute,$second,$month,$day,$year);
+
+ return $newdate;
+
+ }
+
+ static public function secondsFromDays($days) {
+ return $days * 24 * 60 * 60;
+ }
+
+ static public function objectFromArray($array) {
+ $object = new DynamicObject;
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
+ $object->$key = Utility::objectFromArray($value);
+ } else {
+ $object->$key = $value;
+ }
+ }
+ return $object;
+ }
+
+ //returns file path up to /coral/
+ static public function getCORALPath(){
+ $pagePath = $_SERVER["DOCUMENT_ROOT"];
+
+ $currentFile = $_SERVER["SCRIPT_NAME"];
+ $parts = Explode('/', $currentFile);
+ for($i=0; $i
\ No newline at end of file
diff --git a/admin/classes/domain/ImportLog.php b/admin/classes/domain/ImportLog.php
index e5b991a..9a09000 100755
--- a/admin/classes/domain/ImportLog.php
+++ b/admin/classes/domain/ImportLog.php
@@ -1,187 +1,186 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-class ImportLog extends DatabaseObject {
-
- protected function defineRelationships() {}
-
- protected function overridePrimaryKeyName() {}
-
-
- static public function shortStatusFromDetails($details){
- //first, find if titles were processed
- preg_match('/[0-9]+ titles processed/i', $details, $matches);
- $titles = str_replace(" processed", "", $matches[0]);
-
- if ($titles){
- if (preg_match("/finished/i", $details)){
- $status = $titles . " (via sushi)";
- }else{
- $status = $titles;
- }
-
- }else{
-
- if (preg_match("/fail/i", $details)){
- $status = "Failed";
- }elseif (preg_match("/finished/i", $details)){
- $status = "awaiting import";
- }
-
- }
-
- return $status;
-
- }
-
-
- //returns array of Platform records
- public function getPlatforms(){
-
- //now formulate query
- $query = "SELECT platformID
- FROM ImportLogPlatformLink
- WHERE importLogID = '" . $this->importLogID . "'";
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $searchArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($searchArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($searchArray, $resultArray);
- }
- }
-
- return $searchArray;
-
-
- }
-
-
-
- //returns array of import log records
- public function getImportLogRecords($limit){
-
- if ($limit != ""){
- $limitStatement = " LIMIT " . $limit;
- }else{
- $limitStatement = "";
- }
-
-
- //now formulate query
- $query = "SELECT importLogID, loginID, importDateTime dateTime, fileName, archiveFileURL, logFileURL, details
- FROM ImportLog
- ORDER BY importDateTime DESC " . $limitStatement;
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $searchArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['importLogID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($searchArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($searchArray, $resultArray);
- }
- }
-
- return $searchArray;
-
-
- }
-
-
-
- //returns array of import log records from user "sushi"
- public function getSushiImports(){
-
- //now formulate query
- $query = "SELECT importLogID, loginID, importDateTime, fileName, archiveFileURL, logFileURL, details
- FROM ImportLog
- WHERE loginID = 'sushi'
- AND fileName is not null
- AND ucase(details) not like '%FAIL%'
- ORDER BY importDateTime DESC";
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $searchArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['importLogID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($searchArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($searchArray, $resultArray);
- }
- }
-
- return $searchArray;
-
-
- }
-
-
-
-
-}
-
+.
+**
+**************************************************************************************************************************
+*/
+
+class ImportLog extends DatabaseObject {
+
+ protected function defineRelationships() {}
+
+ protected function overridePrimaryKeyName() {}
+
+
+ static public function shortStatusFromDetails($details){
+ //first, find if titles were processed
+ preg_match('/[0-9]+ titles processed/i', $details, $matches);
+ if (isset($matches[0])) {
+ $titles = str_replace(" processed", "", $matches[0]);
+ }
+
+ if (isset($titles)){
+ if (preg_match("/finished/i", $details)){
+ $status = $titles . _(" (via sushi)");
+ }else{
+ $status = $titles;
+ }
+ }else{
+ if (preg_match("/fail/i", $details)){
+ $status = _("Failed");
+ }elseif (preg_match("/finished/i", $details)){
+ $status = ""._("awaiting import")."";
+ } else {
+ $status = null;
+ }
+ }
+ return $status;
+ }
+
+
+ //returns array of Platform records
+ public function getPlatforms(){
+
+ //now formulate query
+ $query = "SELECT platformID
+ FROM ImportLogPlatformLink
+ WHERE importLogID = '" . $this->importLogID . "'";
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $searchArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($searchArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($searchArray, $resultArray);
+ }
+ }
+
+ return $searchArray;
+
+
+ }
+
+
+
+ //returns array of import log records
+ public function getImportLogRecords($limit){
+
+ if ($limit != ""){
+ $limitStatement = " LIMIT " . $limit;
+ }else{
+ $limitStatement = "";
+ }
+
+
+ //now formulate query
+ $query = "SELECT importLogID, loginID, importDateTime dateTime, fileName, archiveFileURL, logFileURL, details
+ FROM ImportLog
+ ORDER BY importDateTime DESC " . $limitStatement;
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $searchArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['importLogID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($searchArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($searchArray, $resultArray);
+ }
+ }
+
+ return $searchArray;
+
+
+ }
+
+
+
+ //returns array of import log records from user "sushi"
+ public function getSushiImports(){
+
+ //now formulate query
+ $query = "SELECT importLogID, loginID, importDateTime, fileName, archiveFileURL, logFileURL, details
+ FROM ImportLog
+ WHERE loginID = 'sushi'
+ AND fileName is not null
+ AND ucase(details) not like '%FAIL%'
+ ORDER BY importDateTime DESC";
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $searchArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['importLogID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($searchArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($searchArray, $resultArray);
+ }
+ }
+
+ return $searchArray;
+
+
+ }
+
+
+
+
+}
+
?>
\ No newline at end of file
diff --git a/admin/classes/domain/Platform.php b/admin/classes/domain/Platform.php
index 25af66e..fa2bcaf 100755
--- a/admin/classes/domain/Platform.php
+++ b/admin/classes/domain/Platform.php
@@ -1,1052 +1,1054 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-class Platform extends DatabaseObject {
-
- protected function defineRelationships() {}
-
- protected function overridePrimaryKeyName() {}
-
-
- protected function defineAttributes() {
- $this->addAttribute('platformID');
- $this->addAttribute('organizationID');
- $this->addAttribute('name');
- $this->addAttribute('reportDisplayName');
- $this->addAttribute('reportDropDownInd');
- }
-
-
-
- //override of database object all() function
- //returns array of all platform objects - needed for proper ordering
- public function all(){
-
- $query = "SELECT *
- FROM Platform
- ORDER BY name;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['platformID'])){
- $object = new Platform(new NamedArguments(array('primaryKey' => $result['platformID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new Platform(new NamedArguments(array('primaryKey' => $row['platformID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
- //returns array of publisher platform note objects
- public function getPlatformNotes(){
-
- $query = "SELECT *
- FROM PlatformNote
- WHERE platformID='" . $this->platformID . "';";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['platformNoteID'])){
- $object = new PlatformNote(new NamedArguments(array('primaryKey' => $result['platformNoteID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new PlatformNote(new NamedArguments(array('primaryKey' => $row['platformNoteID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
- //returns array of importlog objects
- public function getImportLogs(){
-
- $query = "SELECT *
- FROM ImportLog
- WHERE importLogID IN (select importLogID from ImportLogPlatformLink WHERE platformID ='" . $this->platformID . "')
- Order by importDateTime desc;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['importLogID'])){
- $object = new ImportLog(new NamedArguments(array('primaryKey' => $result['importLogID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new ImportLog(new NamedArguments(array('primaryKey' => $row['importLogID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
-
- //returns most recent date of the last month of imports for any titles under this platform
- public function getLastImportDate(){
-
- $query = "SELECT max(concat(year,'-',month,'-01')) max_month
- FROM MonthlyUsageSummary tsm INNER JOIN Title USING (titleID), PublisherPlatform pp
- WHERE pp.publisherPlatformID = tsm.publisherPlatformID
- AND pp.platformID = '" . $this->platformID . "';";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
- if (isset($result['max_month'])){
- return $result['max_month'];
- }
-
- }
-
-
-
-
- //returns array of import log records from user "sushi"
- public function removeFailedSushiImports(){
-
- //now formulate query
- $query = "DELETE FROM ImportLog
- WHERE loginID = 'sushi'
- AND importLogID IN (SELECT importLogID FROM ImportLogPlatformLink WHERE platformID = '" . $this->platformID . "')
- AND ucase(details) like '%FAIL%'";
-
-
- return $this->db->processQuery($query);
-
- }
-
-
-
-
-
-
- //returns array of platforms - used on publisherPlatformList.php
- public function getPlatformArray(){
-
-
- //now formulate query
- $query = "SELECT * FROM Platform ORDER BY name;";
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
-
- }
-
-
- //returns array of external login objects
- public function getExternalLogins(){
-
- $query = "SELECT *
- FROM ExternalLogin
- WHERE platformID='" . $this->platformID . "';";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['externalLoginID'])){
- $object = new ExternalLogin(new NamedArguments(array('primaryKey' => $result['externalLoginID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new ExternalLogin(new NamedArguments(array('primaryKey' => $row['externalLoginID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
-
- //returns array of titles and identifiers
- public function getJournalTitles(){
-
- $query = "SELECT DISTINCT t.titleID titleID, t.title title,
- MAX(IF(ti.identifierType='DOI', identifier, null)) doi,
- MAX(IF(ti.identifierType='Proprietary Identifier', identifier, null)) pi,
- MAX(IF(ti.identifierType='ISSN', concat(substr(ti.identifier,1,4), '-', substr(ti.identifier,5,4)),null)) issn,
- MAX(IF(ti.identifierType='eISSN', concat(substr(ti.identifier,1,4), '-', substr(ti.identifier,5,4)),null)) eissn
- FROM MonthlyUsageSummary mus, PublisherPlatform pp, Title t LEFT JOIN TitleIdentifier ti ON t.titleID = ti.titleID
- WHERE pp.publisherPlatformID = mus.publisherPlatformID
- AND mus.titleID = t.titleID
- AND pp.platformID = '" . $this->platformID . "'
- AND t.resourceType='Journal'
- GROUP BY t.titleID, t.title
- ORDER BY title;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['titleID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
- }
-
-
-
- //returns array of titles and identifiers
- public function getBookTitles(){
-
- $query = "SELECT DISTINCT t.titleID titleID, t.title title,
- MAX(IF(ti.identifierType='DOI', identifier, null)) doi,
- MAX(IF(ti.identifierType='Proprietary Identifier', identifier, null)) pi,
- MAX(IF(ti.identifierType='ISBN', identifier, null)) isbn,
- MAX(IF(ti.identifierType='ISSN', concat(substr(ti.identifier,1,4), '-', substr(ti.identifier,5,4)),null)) issn
- FROM MonthlyUsageSummary mus, PublisherPlatform pp, Title t LEFT JOIN TitleIdentifier ti ON t.titleID = ti.titleID
- WHERE pp.publisherPlatformID = mus.publisherPlatformID
- AND mus.titleID = t.titleID
- AND pp.platformID = '" . $this->platformID . "'
- AND t.resourceType='Book'
- GROUP BY t.titleID, t.title
- ORDER BY title;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['titleID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
- }
-
- //returns array of titles and identifiers
- public function getDatabaseTitles(){
-
- $query = "SELECT DISTINCT t.titleID titleID, t.title title
- FROM MonthlyUsageSummary mus, PublisherPlatform pp, Title t
- WHERE pp.publisherPlatformID = mus.publisherPlatformID
- AND mus.titleID = t.titleID
- AND t.resourceType='Database'
- AND pp.platformID = '" . $this->platformID . "'
- GROUP BY t.titleID, t.title
- ORDER BY title;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['titleID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
- }
-
-
-
- //returns array of publisher platform objects
- public function getPublisherPlatforms(){
-
- $query = "SELECT publisherPlatformID
- FROM PublisherPlatform pp, Publisher
- WHERE pp.publisherID = Publisher.publisherID
- AND platformID = '" . $this->platformID . "'
- ORDER BY Publisher.name;";
-
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['publisherPlatformID'])){
- $object = new PublisherPlatform(new NamedArguments(array('primaryKey' => $result['publisherPlatformID'])));
- array_push($objects, $object);
- }else{
- $db = new DBService;
- foreach ($result as $row) {
- $object = new PublisherPlatform(new NamedArguments(array('primaryKey' => $row['publisherPlatformID'],'db'=>$db)));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
-
-
- //returns array of monthly outlier records
- public function getMonthlyOutliers($resourceType, $archiveInd, $year, $month){
-
-
- //now formulate query
- $query = "select monthlyUsageSummaryID, Title, archiveInd, usageCount, overrideUsageCount, color
- from MonthlyUsageSummary tsm, Title t, Outlier o, PublisherPlatform pp
- where tsm.titleID = t.titleID
- and o.outlierID = tsm.outlierID
- and pp.publisherPlatformID = tsm.publisherPlatformID
- and platformID='" . $this->platformID . "'
- and archiveInd='" . $archiveInd . "'
- and resourceType='" . $resourceType . "'
- and year='" . $year . "'
- and month='" . $month . "' and ignoreOutlierInd = 0
- order by 1,2,3;";
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['monthlyUsageSummaryID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
-
- }
-
-
-
- //returns array of yearly override records
- public function getYearlyOverrides($resourceType, $archiveInd, $year){
-
- //now formulate query
- $query = "SELECT DISTINCT yearlyUsageSummaryID, Title, totalCount, ytdHTMLCount, ytdPDFCount, overrideTotalCount, overrideHTMLCount, overridePDFCount
- FROM YearlyUsageSummary tsy, MonthlyUsageSummary tsm, Title t, PublisherPlatform pp
- WHERE tsy.titleID = t.titleID
- AND tsm.publisherPlatformID = tsy.publisherPlatformID
- AND tsm.titleID = tsy.titleID
- AND tsm.year = tsy.year
- AND tsm.archiveInd = tsy.archiveInd
- AND tsm.outlierID > 0
- AND pp.publisherPlatformID = tsm.publisherPlatformID
- AND pp.platformID='" . $this->platformID . "'
- AND tsy.archiveInd='" . $archiveInd . "'
- AND tsy.year='" . $year . "'
- AND t.resourceType='" . $resourceType . "'
- AND ignoreOutlierInd = 0;";
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['yearlyUsageSummaryID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
-
- }
-
-
-
- //returns array of full statistics info for display
- public function getFullStatsDetails($resourceType = null){
-
- if ($resourceType){
- $addWhere = "AND t.resourceType = '" . $resourceType . "'";
- }
-
- //now formulate query
- $query = "SELECT DISTINCT resourceType, year, GROUP_CONCAT(DISTINCT concat(month, '|', if(ignoreOutlierInd=0,ifnull(outlierID,0),0)) ORDER BY month, 1 SEPARATOR ',') months, archiveInd, MAX(month) max_month, MIN(month) min_month, MAX(IF(ignoreOutlierInd=0,outlierID,null)) outlierID
- FROM PublisherPlatform pp, MonthlyUsageSummary tsm INNER JOIN Title t USING (titleID)
- WHERE pp.platformID = '" . $this->platformID . "'
- AND pp.publisherPlatformID = tsm.publisherPlatformID " . $addWhere . "
- GROUP BY resourceType, year, archiveInd
- ORDER BY resourceType desc, year desc, archiveInd, month;";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['year'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
-
- }
-
-
-
-
- //returns array of months available for a given year
- public function getAvailableMonths($resourceType, $archiveInd, $year){
-
- //now formulate query
- if ($year){
- $addWhere = " AND year = '" . $year . "'";
- }
- if ($archiveInd){
- $addWhere .= " AND archiveInd = '" . $archiveInd . "'";
- }
- if ($resourceType){
- $addWhere = " AND resourceType = '" . $resourceType . "'";
- }
-
- $query = "SELECT DISTINCT year, month, archiveInd
- FROM MonthlyUsageSummary tsm INNER JOIN Title USING (titleID), PublisherPlatform pp
- WHERE pp.publisherPlatformID = tsm.publisherPlatformID
- AND pp.platformID = '" . $this->platformID . "'" . $addWhere . "
- ORDER BY year, archiveInd, month;";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['month'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
-
- }
-
-
- //remove an entire month for this platform
- public function deleteMonth($resourceType, $archiveInd, $year, $month){
-
- //now formulate query
- $query = "DELETE FROM MonthlyUsageSummary
- WHERE publisherPlatformID IN
- (SELECT publisherPlatformID
- FROM PublisherPlatform
- WHERE platformID = '" . $this->platformID . "')
- AND year = '" . $year . "'
- AND month = '" . $month . "'
- AND titleID IN (select titleID from Title where resourceType = '" . $resourceType . "')
- AND archiveInd = '" . $archiveInd . "';";
-
- return $this->db->processQuery($query);
-
- }
-
-
-
- //returns array total stats devided by month
- public function getStatMonthlyTotals($resourceType, $archiveInd, $year){
-
- //now formulate query
- $query = "SELECT pp.platformID,
- SUM(IF(month='1',usageCount,null)) january,
- SUM(IF(month='2',usageCount,null)) february,
- SUM(IF(month='3',usageCount,null)) march,
- SUM(IF(month='4',usageCount,null)) april,
- SUM(IF(month='5',usageCount,null)) may,
- SUM(IF(month='6',usageCount,null)) june,
- SUM(IF(month='7',usageCount,null)) july,
- SUM(IF(month='8',usageCount,null)) august,
- SUM(IF(month='9',usageCount,null)) september,
- SUM(IF(month='10',usageCount,null)) october,
- SUM(IF(month='11',usageCount,null)) november,
- SUM(IF(month='12',usageCount,null)) december
- FROM Title t, MonthlyUsageSummary tsm, PublisherPlatform pp, Publisher p
- WHERE t.titleID = tsm.titleID
- AND tsm.publisherPlatformID = pp.publisherPlatformID
- AND pp.publisherID = p.publisherID
- AND pp.platformID = '" . $this->platformID . "'
- AND tsm.year='" . $year . "'
- AND tsm.archiveInd = '" . $archiveInd . "'
- AND t.resourceType = '" . $resourceType . "'
- GROUP BY pp.platformID;";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- }
-
- return $resultArray;
-
-
- }
-
-
-
-
-
-
- //returns array total stats devided by month
- public function getStatYearlyTotals($resourceType, $archiveInd, $year){
-
- //now formulate query
- $query = "SELECT pp.platformID, SUM(totalCount) totalCount, SUM(ytdHTMLCount) ytdHTMLCount, SUM(ytdPDFCount) ytdPDFCount
- FROM YearlyUsageSummary yus, PublisherPlatform pp, MonthlyUsageSummary mus INNER JOIN Title t ON (mus.titleID = t.titleID)
- WHERE pp.publisherPlatformID = yus.publisherPlatformID
- AND pp.platformID = '" . $this->platformID . "'
- AND yus.archiveInd ='" . $archiveInd . "'
- AND yus.year='" . $year . "'
- AND yus.titleID=mus.titleID
- AND mus.publisherPlatformID = yus.publisherPlatformID
- AND mus.year = '" . $year . "'
- AND mus.archiveInd = '" . $archiveInd . "'
- AND t.resourceType = '" . $resourceType . "'
- AND mus.month = '1'
- GROUP BY pp.platformID;";
-
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- }
-
- return $resultArray;
-
-
- }
-
-
-
-
- //returns arrays of monthly statistics by title
- public function getMonthlyStats($resourceType, $archiveInd, $year){
-
- //now formulate query
- $query = "SELECT pp.publisherPlatformID, t.titleID, t.Title, Publisher.name Publisher, Platform.name Platform,
- MAX(IF(month='1',usageCount,null)) january,
- MAX(IF(month='2',usageCount,null)) february,
- MAX(IF(month='3',usageCount,null)) march,
- MAX(IF(month='4',usageCount,null)) april,
- MAX(IF(month='5',usageCount,null)) may,
- MAX(IF(month='6',usageCount,null)) june,
- MAX(IF(month='7',usageCount,null)) july,
- MAX(IF(month='8',usageCount,null)) august,
- MAX(IF(month='9',usageCount,null)) september,
- MAX(IF(month='10',usageCount,null)) october,
- MAX(IF(month='11',usageCount,null)) november,
- MAX(IF(month='12',usageCount,null)) december,
- MAX(IF(month='1',outlierID,0)) january_outlier,
- MAX(IF(month='2',outlierID,0)) february_outlier,
- MAX(IF(month='3',outlierID,0)) march_outlier,
- MAX(IF(month='4',outlierID,0)) april_outlier,
- MAX(IF(month='5',outlierID,0)) may_outlier,
- MAX(IF(month='6',outlierID,0)) june_outlier,
- MAX(IF(month='7',outlierID,0)) july_outlier,
- MAX(IF(month='8',outlierID,0)) august_outlier,
- MAX(IF(month='9',outlierID,0)) september_outlier,
- MAX(IF(month='10',outlierID,0)) october_outlier,
- MAX(IF(month='11',outlierID,0)) november_outlier,
- MAX(IF(month='12',outlierID,0)) december_outlier,
- MAX(mergeInd) mergeInd, activityType
- FROM Title t, MonthlyUsageSummary tsm, PublisherPlatform pp, Publisher, Platform
- WHERE t.titleID = tsm.titleID
- AND tsm.publisherPlatformID = pp.publisherPlatformID
- AND pp.publisherID = Publisher.publisherID
- AND pp.platformID = Platform.platformID
- AND pp.platformID = '" . $this->platformID . "'
- AND tsm.year='" . $year . "'
- AND tsm.archiveInd = '" . $archiveInd . "'
- AND t.resourceType = '" . $resourceType . "'
- GROUP BY t.titleID, t.Title, activityType
- ORDER BY t.Title;";
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['publisherPlatformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
-
- }
-
-
-
-
- //returns platform object from name
- public function getByName($platformName){
-
- $query = "select platformID from Platform where upper(name) = upper('" . str_replace("'","''", $platformName) . "') LIMIT 1;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['platformID'])){
- $obj = new Platform(new NamedArguments(array('primaryKey' => $result['platformID'])));
- return $obj;
- }else{
- return false;
- }
-
- }
-
-
-
- //returns array of month counts available for a given year
- public function getTotalMonths($resourceType, $archiveInd, $year){
-
- //now formulate query
- $query = "SELECT COUNT(month) count_months, MIN(month) min_month, MAX(month) max_month
- FROM MonthlyUsageSummary mus INNER JOIN Title t USING (titleID), PublisherPlatform pp
- WHERE mus.publisherPlatformID = pp.publisherPlatformID
- AND year = '" . $year . "'
- AND pp.PlatformID = '" . $this->platformID . "'
- AND resourceType = '" . $resourceType . "'
- AND archiveInd=$archiveInd;";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
-
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['count_months'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- }
-
- return $resultArray;
-
-
- }
-
-
-
-
-
-
-
-
- //search used for the autocomplete
- public function searchOrganizations($q){
- $config = new Configuration;
-
- $q = str_replace("+", " ",$q);
- $q = str_replace("%", "&",$q);
-
- $orgArray = array();
-
- //if the org module is installed get the org names from org database
- if ($config->settings->organizationsModule == 'Y'){
-
- $dbName = $config->settings->organizationsDatabaseName;
-
-
- $query = "SELECT CONCAT(A.name, ' (', O.name, ')') name, O.organizationID
- FROM " . $dbName . ".Alias A, " . $dbName . ".Organization O
- WHERE A.organizationID=O.organizationID
- AND upper(A.name) like upper('%" . $q . "%')
- UNION
- SELECT name, organizationID
- FROM " . $dbName . ".Organization
- WHERE upper(name) like upper('%" . $q . "%')
- ORDER BY 1;";
-
- $result = mysqli_query($this->db->getDatabase(), $query);
-
- while ($row = mysqli_fetch_assoc($result)){
- $orgArray[] = $row['organizationID'] . "|" . $row['name'];
- }
-
- }
-
-
- return $orgArray;
- }
-
-
-
-
- //search used index page drop down
- public function getOrganizationList(){
- $config = new Configuration;
-
- $orgArray = array();
-
- //if the org module is installed get the org names from org database
- if ($config->settings->organizationsModule == 'Y'){
- $dbName = $config->settings->organizationsDatabaseName;
- $query = "SELECT name, organizationID FROM " . $dbName . ".Organization ORDER BY 1;";
- }
-
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['organizationID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($orgArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($orgArray, $resultArray);
- }
- }
-
- return $orgArray;
-
- }
-
-
-
- //go to organizations and get the org name for this platform
- public function getOrganizationName(){
- $config = new Configuration;
-
- //if the org module is installed get the org name from org database
- if ($config->settings->organizationsModule == 'Y'){
- $dbName = $config->settings->organizationsDatabaseName;
-
- $orgArray = array();
- $query = "SELECT name FROM " . $dbName . ".Organization WHERE organizationID = " . $this->organizationID;
-
- if ($result = mysqli_query($this->db->getDatabase(), $query)){
-
- while ($row = mysqli_fetch_assoc($result)){
- return $row['name'];
- }
- }
- }
- }
-
-
- //returns array of external login data
- public function getOrganizationExternalLogins(){
- $config = new Configuration;
-
- //if the org module is installed get the org info from org database
- if (($config->settings->organizationsModule == 'Y') && ($this->organizationID)){
- $dbName = $config->settings->organizationsDatabaseName;
-
- $query = "SELECT externalLoginID, ELT.shortName externalLoginType, updateDate, loginURL, emailAddress, username, password, noteText
- FROM " . $dbName . ".ExternalLogin EL, " . $dbName . ".ExternalLoginType ELT
- WHERE EL.externalLoginTypeID = ELT.externalLoginTypeID
- AND organizationID = '" . $this->organizationID . "'
- ORDER BY ELT.shortName";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['externalLoginID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
-
- }
-
- }
-
-
-
-
- //used for A-Z on search (index)
- public function getAlphabeticalList(){
- $allArray = array();
- $result = $this->db->processQuery("SELECT DISTINCT UPPER(SUBSTR(TRIM(LEADING 'The ' FROM name),1,1)) letter, COUNT(SUBSTR(TRIM(LEADING 'The ' FROM name),1,1)) letter_count
- FROM Platform
- GROUP BY SUBSTR(TRIM(LEADING 'The ' FROM name),1,1)
- ORDER BY 1;", "assoc");
-
-
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['letter'])){
- $allArray = $result;
- }else{
- foreach ($result as $row) {
- $allArray[$row['letter']] = $row['letter_count'];
- }
- }
-
- return $allArray;
- }
-
-
- //returns array based on search
- public function search($whereAdd, $orderBy, $limit){
-
- if (count($whereAdd) > 0){
- $whereStatement = " WHERE " . implode(" AND ", $whereAdd);
- }else{
- $whereStatement = "";
- }
-
- if ($limit != ""){
- $limitStatement = " LIMIT " . $limit;
- }else{
- $limitStatement = "";
- }
-
-
- //now actually execute query
- $query = "SELECT P.platformID, P.name, P.reportDisplayName,
- GROUP_CONCAT(DISTINCT PP.publisherPlatformID ORDER BY PP.reportDisplayName DESC SEPARATOR ':') publishers,
- date(importDateTime) last_import,
- loginID,
- details,
- if(serviceDayOfMonth > day(now()), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()), lpad(serviceDayOfMonth,2,'0')), '%Y%m%d'), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()) + 1, lpad(serviceDayOfMonth,2,'0')), '%Y%m%d') ) next_import
- FROM
- Platform P
- LEFT JOIN (PublisherPlatform PP
- INNER JOIN Publisher USING (publisherID))
- ON P.PlatformID = PP.PlatformID
- LEFT JOIN (SELECT platformID, mil.importLogID, max(importDateTime) importDateTime, loginID, details FROM ImportLog mil INNER JOIN ImportLogPlatformLink mipl USING (ImportLogID) GROUP BY platformID) mil ON P.platformID = mil.platformID
- LEFT JOIN SushiService SS ON P.PlatformID = SS.PlatformID
- " . $whereStatement . "
- GROUP By P.platformID
- ORDER BY " . $orderBy . $limitStatement;
-
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
- $searchArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($searchArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($searchArray, $resultArray);
- }
- }
-
- return $searchArray;
- }
-
-
-}
-
-
-?>
+.
+**
+**************************************************************************************************************************
+*/
+
+class Platform extends DatabaseObject {
+
+ protected function defineRelationships() {}
+
+ protected function overridePrimaryKeyName() {}
+
+
+ protected function defineAttributes() {
+ $this->addAttribute('platformID');
+ $this->addAttribute('organizationID');
+ $this->addAttribute('name');
+ $this->addAttribute('reportDisplayName');
+ $this->addAttribute('reportDropDownInd');
+ }
+
+
+
+ //override of database object all() function
+ //returns array of all platform objects - needed for proper ordering
+ public function all(){
+
+ $query = "SELECT *
+ FROM Platform
+ ORDER BY name;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+ $object = new Platform(new NamedArguments(array('primaryKey' => $result['platformID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new Platform(new NamedArguments(array('primaryKey' => $row['platformID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+ //returns array of publisher platform note objects
+ public function getPlatformNotes(){
+
+ $query = "SELECT *
+ FROM PlatformNote
+ WHERE platformID='" . $this->platformID . "';";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['platformNoteID'])){
+ $object = new PlatformNote(new NamedArguments(array('primaryKey' => $result['platformNoteID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new PlatformNote(new NamedArguments(array('primaryKey' => $row['platformNoteID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+ //returns array of importlog objects
+ public function getImportLogs(){
+
+ $query = "SELECT *
+ FROM ImportLog
+ WHERE importLogID IN (select importLogID from ImportLogPlatformLink WHERE platformID ='" . $this->platformID . "')
+ Order by importDateTime desc;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['importLogID'])){
+ $object = new ImportLog(new NamedArguments(array('primaryKey' => $result['importLogID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new ImportLog(new NamedArguments(array('primaryKey' => $row['importLogID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+
+ //returns most recent date of the last month of imports for any titles under this platform
+ public function getLastImportDate(){
+
+ $query = "SELECT max(concat(year,'-',month,'-01')) max_month
+ FROM MonthlyUsageSummary tsm INNER JOIN Title USING (titleID), PublisherPlatform pp
+ WHERE pp.publisherPlatformID = tsm.publisherPlatformID
+ AND pp.platformID = '" . $this->platformID . "';";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+ if (isset($result['max_month'])){
+ return $result['max_month'];
+ }
+
+ }
+
+
+
+
+ //returns array of import log records from user "sushi"
+ public function removeFailedSushiImports(){
+
+ //now formulate query
+ $query = "DELETE FROM ImportLog
+ WHERE loginID = 'sushi'
+ AND importLogID IN (SELECT importLogID FROM ImportLogPlatformLink WHERE platformID = '" . $this->platformID . "')
+ AND ucase(details) like '%FAIL%'";
+
+
+ return $this->db->processQuery($query);
+
+ }
+
+
+
+
+
+
+ //returns array of platforms - used on publisherPlatformList.php
+ public function getPlatformArray(){
+
+
+ //now formulate query
+ $query = "SELECT * FROM Platform ORDER BY name;";
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+
+ }
+
+
+ //returns array of external login objects
+ public function getExternalLogins(){
+
+ $query = "SELECT *
+ FROM ExternalLogin
+ WHERE platformID='" . $this->platformID . "';";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['externalLoginID'])){
+ $object = new ExternalLogin(new NamedArguments(array('primaryKey' => $result['externalLoginID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new ExternalLogin(new NamedArguments(array('primaryKey' => $row['externalLoginID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+
+ //returns array of titles and identifiers
+ public function getJournalTitles(){
+
+ $query = "SELECT DISTINCT t.titleID titleID, t.title title,
+ MAX(IF(ti.identifierType='DOI', identifier, null)) doi,
+ MAX(IF(ti.identifierType='Proprietary Identifier', identifier, null)) pi,
+ MAX(IF(ti.identifierType='ISSN', concat(substr(ti.identifier,1,4), '-', substr(ti.identifier,5,4)),null)) issn,
+ MAX(IF(ti.identifierType='eISSN', concat(substr(ti.identifier,1,4), '-', substr(ti.identifier,5,4)),null)) eissn
+ FROM MonthlyUsageSummary mus, PublisherPlatform pp, Title t LEFT JOIN TitleIdentifier ti ON t.titleID = ti.titleID
+ WHERE pp.publisherPlatformID = mus.publisherPlatformID
+ AND mus.titleID = t.titleID
+ AND pp.platformID = '" . $this->platformID . "'
+ AND t.resourceType='Journal'
+ GROUP BY t.titleID, t.title
+ ORDER BY title;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['titleID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+ }
+
+
+
+ //returns array of titles and identifiers
+ public function getBookTitles(){
+
+ $query = "SELECT DISTINCT t.titleID titleID, t.title title,
+ MAX(IF(ti.identifierType='DOI', identifier, null)) doi,
+ MAX(IF(ti.identifierType='Proprietary Identifier', identifier, null)) pi,
+ MAX(IF(ti.identifierType='ISBN', identifier, null)) isbn,
+ MAX(IF(ti.identifierType='ISSN', concat(substr(ti.identifier,1,4), '-', substr(ti.identifier,5,4)),null)) issn
+ FROM MonthlyUsageSummary mus, PublisherPlatform pp, Title t LEFT JOIN TitleIdentifier ti ON t.titleID = ti.titleID
+ WHERE pp.publisherPlatformID = mus.publisherPlatformID
+ AND mus.titleID = t.titleID
+ AND pp.platformID = '" . $this->platformID . "'
+ AND t.resourceType='Book'
+ GROUP BY t.titleID, t.title
+ ORDER BY title;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['titleID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+ }
+
+ //returns array of titles and identifiers
+ public function getDatabaseTitles(){
+
+ $query = "SELECT DISTINCT t.titleID titleID, t.title title
+ FROM MonthlyUsageSummary mus, PublisherPlatform pp, Title t
+ WHERE pp.publisherPlatformID = mus.publisherPlatformID
+ AND mus.titleID = t.titleID
+ AND t.resourceType='Database'
+ AND pp.platformID = '" . $this->platformID . "'
+ GROUP BY t.titleID, t.title
+ ORDER BY title;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['titleID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+ }
+
+
+
+ //returns array of publisher platform objects
+ public function getPublisherPlatforms(){
+
+ $query = "SELECT publisherPlatformID
+ FROM PublisherPlatform pp, Publisher
+ WHERE pp.publisherID = Publisher.publisherID
+ AND platformID = '" . $this->platformID . "'
+ ORDER BY Publisher.name;";
+
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['publisherPlatformID'])){
+ $object = new PublisherPlatform(new NamedArguments(array('primaryKey' => $result['publisherPlatformID'])));
+ array_push($objects, $object);
+ }else{
+ $db = new DBService;
+ foreach ($result as $row) {
+ $object = new PublisherPlatform(new NamedArguments(array('primaryKey' => $row['publisherPlatformID'],'db'=>$db)));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+
+
+ //returns array of monthly outlier records
+ public function getMonthlyOutliers($resourceType, $archiveInd, $year, $month){
+
+
+ //now formulate query
+ $query = "select monthlyUsageSummaryID, Title, archiveInd, usageCount, overrideUsageCount, color
+ from MonthlyUsageSummary tsm, Title t, Outlier o, PublisherPlatform pp
+ where tsm.titleID = t.titleID
+ and o.outlierID = tsm.outlierID
+ and pp.publisherPlatformID = tsm.publisherPlatformID
+ and platformID='" . $this->platformID . "'
+ and archiveInd='" . $archiveInd . "'
+ and resourceType='" . $resourceType . "'
+ and year='" . $year . "'
+ and month='" . $month . "' and ignoreOutlierInd = 0
+ order by 1,2,3;";
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['monthlyUsageSummaryID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+
+ }
+
+
+
+ //returns array of yearly override records
+ public function getYearlyOverrides($resourceType, $archiveInd, $year){
+
+ //now formulate query
+ $query = "SELECT DISTINCT yearlyUsageSummaryID, Title, totalCount, ytdHTMLCount, ytdPDFCount, overrideTotalCount, overrideHTMLCount, overridePDFCount
+ FROM YearlyUsageSummary tsy, MonthlyUsageSummary tsm, Title t, PublisherPlatform pp
+ WHERE tsy.titleID = t.titleID
+ AND tsm.publisherPlatformID = tsy.publisherPlatformID
+ AND tsm.titleID = tsy.titleID
+ AND tsm.year = tsy.year
+ AND tsm.archiveInd = tsy.archiveInd
+ AND tsm.outlierID > 0
+ AND pp.publisherPlatformID = tsm.publisherPlatformID
+ AND pp.platformID='" . $this->platformID . "'
+ AND tsy.archiveInd='" . $archiveInd . "'
+ AND tsy.year='" . $year . "'
+ AND t.resourceType='" . $resourceType . "'
+ AND ignoreOutlierInd = 0;";
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['yearlyUsageSummaryID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+
+ }
+
+
+
+ //returns array of full statistics info for display
+ public function getFullStatsDetails($resourceType = null){
+
+ if ($resourceType){
+ $addWhere = "AND t.resourceType = '" . $resourceType . "'";
+ } else {
+ $addWhere = "";
+ }
+
+ //now formulate query
+ $query = "SELECT DISTINCT resourceType, year, GROUP_CONCAT(DISTINCT concat(month, '|', if(ignoreOutlierInd=0,ifnull(outlierID,0),0)) ORDER BY month, 1 SEPARATOR ',') months, archiveInd, MAX(month) max_month, MIN(month) min_month, MAX(IF(ignoreOutlierInd=0,outlierID,null)) outlierID
+ FROM PublisherPlatform pp, MonthlyUsageSummary tsm INNER JOIN Title t USING (titleID)
+ WHERE pp.platformID = '" . $this->platformID . "'
+ AND pp.publisherPlatformID = tsm.publisherPlatformID " . $addWhere . "
+ GROUP BY resourceType, year, archiveInd
+ ORDER BY resourceType desc, year desc, archiveInd, month;";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['year'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+
+ }
+
+
+
+
+ //returns array of months available for a given year
+ public function getAvailableMonths($resourceType, $archiveInd, $year){
+
+ //now formulate query
+ if ($year){
+ $addWhere = " AND year = '" . $year . "'";
+ }
+ if ($archiveInd){
+ $addWhere .= " AND archiveInd = '" . $archiveInd . "'";
+ }
+ if ($resourceType){
+ $addWhere = " AND resourceType = '" . $resourceType . "'";
+ }
+
+ $query = "SELECT DISTINCT year, month, archiveInd
+ FROM MonthlyUsageSummary tsm INNER JOIN Title USING (titleID), PublisherPlatform pp
+ WHERE pp.publisherPlatformID = tsm.publisherPlatformID
+ AND pp.platformID = '" . $this->platformID . "'" . $addWhere . "
+ ORDER BY year, archiveInd, month;";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['month'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+
+ }
+
+
+ //remove an entire month for this platform
+ public function deleteMonth($resourceType, $archiveInd, $year, $month){
+
+ //now formulate query
+ $query = "DELETE FROM MonthlyUsageSummary
+ WHERE publisherPlatformID IN
+ (SELECT publisherPlatformID
+ FROM PublisherPlatform
+ WHERE platformID = '" . $this->platformID . "')
+ AND year = '" . $year . "'
+ AND month = '" . $month . "'
+ AND titleID IN (select titleID from Title where resourceType = '" . $resourceType . "')
+ AND archiveInd = '" . $archiveInd . "';";
+
+ return $this->db->processQuery($query);
+
+ }
+
+
+
+ //returns array total stats devided by month
+ public function getStatMonthlyTotals($resourceType, $archiveInd, $year){
+
+ //now formulate query
+ $query = "SELECT pp.platformID,
+ SUM(IF(month='1',usageCount,null)) january,
+ SUM(IF(month='2',usageCount,null)) february,
+ SUM(IF(month='3',usageCount,null)) march,
+ SUM(IF(month='4',usageCount,null)) april,
+ SUM(IF(month='5',usageCount,null)) may,
+ SUM(IF(month='6',usageCount,null)) june,
+ SUM(IF(month='7',usageCount,null)) july,
+ SUM(IF(month='8',usageCount,null)) august,
+ SUM(IF(month='9',usageCount,null)) september,
+ SUM(IF(month='10',usageCount,null)) october,
+ SUM(IF(month='11',usageCount,null)) november,
+ SUM(IF(month='12',usageCount,null)) december
+ FROM Title t, MonthlyUsageSummary tsm, PublisherPlatform pp, Publisher p
+ WHERE t.titleID = tsm.titleID
+ AND tsm.publisherPlatformID = pp.publisherPlatformID
+ AND pp.publisherID = p.publisherID
+ AND pp.platformID = '" . $this->platformID . "'
+ AND tsm.year='" . $year . "'
+ AND tsm.archiveInd = '" . $archiveInd . "'
+ AND t.resourceType = '" . $resourceType . "'
+ GROUP BY pp.platformID;";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ }
+
+ return $resultArray;
+
+
+ }
+
+
+
+
+
+
+ //returns array total stats devided by month
+ public function getStatYearlyTotals($resourceType, $archiveInd, $year){
+
+ //now formulate query
+ $query = "SELECT pp.platformID, SUM(totalCount) totalCount, SUM(ytdHTMLCount) ytdHTMLCount, SUM(ytdPDFCount) ytdPDFCount
+ FROM YearlyUsageSummary yus, PublisherPlatform pp, MonthlyUsageSummary mus INNER JOIN Title t ON (mus.titleID = t.titleID)
+ WHERE pp.publisherPlatformID = yus.publisherPlatformID
+ AND pp.platformID = '" . $this->platformID . "'
+ AND yus.archiveInd ='" . $archiveInd . "'
+ AND yus.year='" . $year . "'
+ AND yus.titleID=mus.titleID
+ AND mus.publisherPlatformID = yus.publisherPlatformID
+ AND mus.year = '" . $year . "'
+ AND mus.archiveInd = '" . $archiveInd . "'
+ AND t.resourceType = '" . $resourceType . "'
+ AND mus.month = '1'
+ GROUP BY pp.platformID;";
+
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ }
+
+ return $resultArray;
+
+
+ }
+
+
+
+
+ //returns arrays of monthly statistics by title
+ public function getMonthlyStats($resourceType, $archiveInd, $year){
+
+ //now formulate query
+ $query = "SELECT pp.publisherPlatformID, t.titleID, t.Title, Publisher.name Publisher, Platform.name Platform,
+ MAX(IF(month='1',usageCount,null)) january,
+ MAX(IF(month='2',usageCount,null)) february,
+ MAX(IF(month='3',usageCount,null)) march,
+ MAX(IF(month='4',usageCount,null)) april,
+ MAX(IF(month='5',usageCount,null)) may,
+ MAX(IF(month='6',usageCount,null)) june,
+ MAX(IF(month='7',usageCount,null)) july,
+ MAX(IF(month='8',usageCount,null)) august,
+ MAX(IF(month='9',usageCount,null)) september,
+ MAX(IF(month='10',usageCount,null)) october,
+ MAX(IF(month='11',usageCount,null)) november,
+ MAX(IF(month='12',usageCount,null)) december,
+ MAX(IF(month='1',outlierID,0)) january_outlier,
+ MAX(IF(month='2',outlierID,0)) february_outlier,
+ MAX(IF(month='3',outlierID,0)) march_outlier,
+ MAX(IF(month='4',outlierID,0)) april_outlier,
+ MAX(IF(month='5',outlierID,0)) may_outlier,
+ MAX(IF(month='6',outlierID,0)) june_outlier,
+ MAX(IF(month='7',outlierID,0)) july_outlier,
+ MAX(IF(month='8',outlierID,0)) august_outlier,
+ MAX(IF(month='9',outlierID,0)) september_outlier,
+ MAX(IF(month='10',outlierID,0)) october_outlier,
+ MAX(IF(month='11',outlierID,0)) november_outlier,
+ MAX(IF(month='12',outlierID,0)) december_outlier,
+ MAX(mergeInd) mergeInd, activityType
+ FROM Title t, MonthlyUsageSummary tsm, PublisherPlatform pp, Publisher, Platform
+ WHERE t.titleID = tsm.titleID
+ AND tsm.publisherPlatformID = pp.publisherPlatformID
+ AND pp.publisherID = Publisher.publisherID
+ AND pp.platformID = Platform.platformID
+ AND pp.platformID = '" . $this->platformID . "'
+ AND tsm.year='" . $year . "'
+ AND tsm.archiveInd = '" . $archiveInd . "'
+ AND t.resourceType = '" . $resourceType . "'
+ GROUP BY t.titleID, t.Title, activityType
+ ORDER BY t.Title;";
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['publisherPlatformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+
+ }
+
+
+
+
+ //returns platform object from name
+ public function getByName($platformName){
+
+ $query = "select platformID from Platform where upper(name) = upper('" . str_replace("'","''", $platformName) . "') LIMIT 1;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+ $obj = new Platform(new NamedArguments(array('primaryKey' => $result['platformID'])));
+ return $obj;
+ }else{
+ return false;
+ }
+
+ }
+
+
+
+ //returns array of month counts available for a given year
+ public function getTotalMonths($resourceType, $archiveInd, $year){
+
+ //now formulate query
+ $query = "SELECT COUNT(month) count_months, MIN(month) min_month, MAX(month) max_month
+ FROM MonthlyUsageSummary mus INNER JOIN Title t USING (titleID), PublisherPlatform pp
+ WHERE mus.publisherPlatformID = pp.publisherPlatformID
+ AND year = '" . $year . "'
+ AND pp.PlatformID = '" . $this->platformID . "'
+ AND resourceType = '" . $resourceType . "'
+ AND archiveInd=$archiveInd;";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['count_months'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ }
+
+ return $resultArray;
+
+
+ }
+
+
+
+
+
+
+
+
+ //search used for the autocomplete
+ public function searchOrganizations($q){
+ $config = new Configuration;
+
+ $q = str_replace("+", " ",$q);
+ $q = str_replace("%", "&",$q);
+
+ $orgArray = array();
+
+ //if the org module is installed get the org names from org database
+ if ($config->settings->organizationsModule == 'Y'){
+
+ $dbName = $config->settings->organizationsDatabaseName;
+
+
+ $query = "SELECT CONCAT(A.name, ' (', O.name, ')') name, O.organizationID
+ FROM " . $dbName . ".Alias A, " . $dbName . ".Organization O
+ WHERE A.organizationID=O.organizationID
+ AND upper(A.name) like upper('%" . $q . "%')
+ UNION
+ SELECT name, organizationID
+ FROM " . $dbName . ".Organization
+ WHERE upper(name) like upper('%" . $q . "%')
+ ORDER BY 1;";
+
+ $result = mysqli_query($this->db->getDatabase(), $query);
+
+ while ($row = mysqli_fetch_assoc($result)){
+ $orgArray[] = $row['organizationID'] . "|" . $row['name'];
+ }
+
+ }
+
+
+ return $orgArray;
+ }
+
+
+
+
+ //search used index page drop down
+ public function getOrganizationList(){
+ $config = new Configuration;
+
+ $orgArray = array();
+
+ //if the org module is installed get the org names from org database
+ if ($config->settings->organizationsModule == 'Y'){
+ $dbName = $config->settings->organizationsDatabaseName;
+ $query = "SELECT name, organizationID FROM " . $dbName . ".Organization ORDER BY 1;";
+ }
+
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['organizationID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($orgArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($orgArray, $resultArray);
+ }
+ }
+
+ return $orgArray;
+
+ }
+
+
+
+ //go to organizations and get the org name for this platform
+ public function getOrganizationName(){
+ $config = new Configuration;
+
+ //if the org module is installed get the org name from org database
+ if ($config->settings->organizationsModule == 'Y'){
+ $dbName = $config->settings->organizationsDatabaseName;
+
+ $orgArray = array();
+ $query = "SELECT name FROM " . $dbName . ".Organization WHERE organizationID = " . $this->organizationID;
+
+ if ($result = mysqli_query($this->db->getDatabase(), $query)){
+
+ while ($row = mysqli_fetch_assoc($result)){
+ return $row['name'];
+ }
+ }
+ }
+ }
+
+
+ //returns array of external login data
+ public function getOrganizationExternalLogins(){
+ $config = new Configuration;
+
+ //if the org module is installed get the org info from org database
+ if (($config->settings->organizationsModule == 'Y') && ($this->organizationID)){
+ $dbName = $config->settings->organizationsDatabaseName;
+
+ $query = "SELECT externalLoginID, ELT.shortName externalLoginType, updateDate, loginURL, emailAddress, username, password, noteText
+ FROM " . $dbName . ".ExternalLogin EL, " . $dbName . ".ExternalLoginType ELT
+ WHERE EL.externalLoginTypeID = ELT.externalLoginTypeID
+ AND organizationID = '" . $this->organizationID . "'
+ ORDER BY ELT.shortName";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['externalLoginID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+
+ }
+
+ }
+
+
+
+
+ //used for A-Z on search (index)
+ public function getAlphabeticalList(){
+ $allArray = array();
+ $result = $this->db->processQuery("SELECT DISTINCT UPPER(SUBSTR(TRIM(LEADING 'The ' FROM name),1,1)) letter, COUNT(SUBSTR(TRIM(LEADING 'The ' FROM name),1,1)) letter_count
+ FROM Platform
+ GROUP BY SUBSTR(TRIM(LEADING 'The ' FROM name),1,1)
+ ORDER BY 1;", "assoc");
+
+
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['letter'])){
+ $allArray = $result;
+ }else{
+ foreach ($result as $row) {
+ $allArray[$row['letter']] = $row['letter_count'];
+ }
+ }
+
+ return $allArray;
+ }
+
+
+ //returns array based on search
+ public function search($whereAdd, $orderBy, $limit){
+
+ if (count($whereAdd) > 0){
+ $whereStatement = " WHERE " . implode(" AND ", $whereAdd);
+ }else{
+ $whereStatement = "";
+ }
+
+ if ($limit != ""){
+ $limitStatement = " LIMIT " . $limit;
+ }else{
+ $limitStatement = "";
+ }
+
+
+ //now actually execute query
+ $query = "SELECT P.platformID, P.name, P.reportDisplayName,
+ GROUP_CONCAT(DISTINCT PP.publisherPlatformID ORDER BY PP.reportDisplayName DESC SEPARATOR ':') publishers,
+ date(importDateTime) last_import,
+ loginID,
+ details,
+ if(serviceDayOfMonth > day(now()), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()), lpad(serviceDayOfMonth,2,'0')), '%Y%m%d'), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()) + 1, lpad(serviceDayOfMonth,2,'0')), '%Y%m%d') ) next_import
+ FROM
+ Platform P
+ LEFT JOIN (PublisherPlatform PP
+ INNER JOIN Publisher USING (publisherID))
+ ON P.PlatformID = PP.PlatformID
+ LEFT JOIN (SELECT platformID, mil.importLogID, max(importDateTime) importDateTime, loginID, details FROM ImportLog mil INNER JOIN ImportLogPlatformLink mipl USING (ImportLogID) GROUP BY platformID) mil ON P.platformID = mil.platformID
+ LEFT JOIN SushiService SS ON P.PlatformID = SS.PlatformID
+ " . $whereStatement . "
+ GROUP By P.platformID
+ ORDER BY " . $orderBy . $limitStatement;
+
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+ $searchArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($searchArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($searchArray, $resultArray);
+ }
+ }
+
+ return $searchArray;
+ }
+
+
+}
+
+
+?>
diff --git a/admin/classes/domain/SushiService.php b/admin/classes/domain/SushiService.php
index 4bd0bca..e1e06a7 100755
--- a/admin/classes/domain/SushiService.php
+++ b/admin/classes/domain/SushiService.php
@@ -1,829 +1,905 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-class SushiService extends DatabaseObject {
-
- protected function defineRelationships() {}
-
- protected function overridePrimaryKeyName() {}
-
- public $startDate;
- public $endDate;
- private $statusLog = array();
- private $detailLog = array();
-
- public function getByPlatformID($platformID){
- if (isset($platformID)) {
- $query = "SELECT * FROM `$this->tableName` WHERE `platformID` = '$platformID'";
- $result = $this->db->processQuery($query, 'assoc');
-
- foreach (array_keys($result) as $attributeName) {
- $this->addAttribute($attributeName);
- $this->attributes[$attributeName] = $result[$attributeName];
- }
- }
- }
-
- public function getByPublisherPlatformID($publisherPlatformID){
- if (isset($publisherPlatformID)) {
- $query = "SELECT * FROM `$this->tableName` WHERE `publisherPlatformID` = '$publisherPlatformID'";
- $result = $this->db->processQuery($query, 'assoc');
-
- foreach (array_keys($result) as $attributeName) {
- $this->addAttribute($attributeName);
- $this->attributes[$attributeName] = $result[$attributeName];
- }
- }
- }
-
- //returns array of sushi service objects that need to be run on a particular day
- public function getByDayOfMonth($serviceDayOfMonth){
- //now formulate query
- $query = "SELECT * FROM SushiService WHERE `serviceDayOfMonth` = '$serviceDayOfMonth';";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['sushiServiceID'])){
- $object = new SushiService(new NamedArguments(array('primaryKey' => $result['sushiServiceID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new SushiService(new NamedArguments(array('primaryKey' => $row['sushiServiceID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
-
-
- public function getPublisherOrPlatform(){
- if (($this->platformID != "") && ($this->platformID > 0)){
- return new Platform(new NamedArguments(array('primaryKey' => $this->platformID)));
- }else{
- return new PublisherPlatform(new NamedArguments(array('primaryKey' => $this->publisherPlatformID)));
- }
- }
-
-
- public function getServiceProvider(){
- return str_replace('"','',$this->getPublisherOrPlatform->reportDisplayName);
- }
-
-
-
-
- public function failedImports(){
- $query = "SELECT ipl.platformID, ss.sushiServiceID, date(il.importDateTime), details, il.importLogID
- FROM ImportLog il
- INNER JOIN ImportLogPlatformLink ipl USING (ImportLogID)
- INNER JOIN SushiService ss ON (ss.platformID = ipl.platformID)
- INNER JOIN (SELECT platformID, max(importLogID) importLogID, max(importDateTime) importDateTime FROM ImportLog mil INNER JOIN ImportLogPlatformLink mipl USING (ImportLogID) GROUP BY platformID) mil ON (mil.importLogID = il.importLogID)
- WHERE ucase(details) like '%FAIL%'
- ORDER BY il.importDateTime desc";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
- $searchArray = array();
- $importArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($importArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($importArray, $resultArray);
- }
- }
-
- return $importArray;
-
- }
-
- public function allServices(){
- $query = "SELECT ss.platformID, ss.publisherPlatformID, sushiServiceID, serviceURL, reportLayouts, releaseNumber,
- if(serviceDayOfMonth > day(now()), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()), lpad(serviceDayOfMonth,2,'0')), '%Y%m%d'), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()) + 1, lpad(serviceDayOfMonth,2,'0')), '%Y%m%d') ) next_import
- FROM SushiService ss
- LEFT JOIN Platform p on (p.platformID = ss.platformID)
- LEFT JOIN PublisherPlatform pp
- INNER JOIN Publisher pub USING(publisherID)
- ON (pp.publisherPlatformID = ss.publisherPlatformID)
- ORDER BY p.name, pub.name";
-
- $result = $this->db->processQuery(stripslashes($query), 'assoc');
-
- $searchArray = array();
- $importArray = array();
-
- //need to do this since it could be that there's only one result and this is how the dbservice returns result
- if (isset($result['platformID'])){
-
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($importArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($importArray, $resultArray);
- }
- }
-
- return $importArray;
-
- }
-
-
- //run through ajax function on publisherplatform
- public function runTest(){
- $reportLayouts = $this->reportLayouts;
- $rlArray = explode(";", $reportLayouts);
-
- //just default test import dates to just be january 1 - 31 of this year
- $sDate = date_format(date_create_from_format("Ymd", date("Y")."0101"), "Y-m-d");
- $eDate = date_format(date_create_from_format("Ymd", date("Y")."0131"), "Y-m-d");
- $this->setImportDates($sDate, $eDate);
-
-
- foreach($rlArray as $reportLayout){
- $xmlFile = $this->sushiTransfer($reportLayout);
- }
-
- if ($reportLayouts == ""){
- echo "At least one report type must be set up!";
- }else{
- echo "Connection test successful!";
- }
-
- }
-
- //run through post or through sushi scheduler
- public function runAll($overwritePlatform = TRUE){
- $reportLayouts = $this->reportLayouts;
- $rlArray = explode(";", $reportLayouts);
-
- $detailsForOutput = array();
-
- foreach($rlArray as $reportLayout){
- $this->statusLog = array();
- $this->detailLog = array();
-
- $xmlFile = $this->sushiTransfer($reportLayout);
- $this->parseXML($xmlFile, $reportLayout, $overwritePlatform);
-
- $detailsForOutput = $this->statusLog;
- }
-
- if ($reportLayouts == ""){
- return "No report types are set up!";
- }
-
- return implode("\n", $detailsForOutput);
- }
-
-
-
-
-
- public function setDefaultImportDates(){
-
- // Determine the End Date
- //start with first day of this month
- $endDate = date_create_from_format("Ymd", date("Y") . date("m") . "01" );
-
- //subtract one day
- date_sub($endDate, date_interval_create_from_date_string('1 days'));
- $this->endDate = date_format($endDate,"Y-m-d");
-
- //Determine the Start Date
- //first, get this publisher/platform's last day of import
- $lastImportDate = $this->getPublisherOrPlatform->getLastImportDate();
- $lastImportDate = date_create_from_format("Y-m-d", $lastImportDate);
- date_add($lastImportDate, date_interval_create_from_date_string('1 month'));
-
- //if that date is set and it's sooner than the first of this year, default it to that date
- if (($lastImportDate) && (date_format($lastImportDate, "Y-m-d") > date_format($endDate, "Y") . "-01-01")){
- $this->startDate = date_format($lastImportDate, "Y-m-d");
- }else{
- $this->startDate = date_format($endDate, "Y") . "-01-01";
- }
-
- }
-
-
-
- public function setImportDates($sDate = null, $eDate = null){
-
- if (!$sDate){
- $this->setDefaultImportDates();
- }else{
- //using the multiple functions in order to make sure leading zeros, and this is a date
- $this->startDate = date_format(date_create_from_format("Y-m-d", $sDate), "Y-m-d");
- $this->endDate = date_format(date_create_from_format("Y-m-d", $eDate), "Y-m-d");
- }
-
- }
-
-
-
-
- //status for storing in DB and displaying in rows
- private function logStatus($logText){
- array_push($this->statusLog, $logText);
- array_push($this->detailLog, $logText);
- }
-
- //longer log for storing in log file and displaying output
- private function log($logText){
- array_push($this->detailLog, $logText);
- }
-
- //logs process to import log table and to log file
- public function saveLogAndExit($reportLayout = NULL, $txtFile = NULL, $success = FALSE){
-
-
- //First, delete any preexisting Failured records, these shouldn't be needed/interesting after this.
- $this->log("Cleaning up prior failed import logs....");
-
- $this->getPublisherOrPlatform->removeFailedSushiImports;
-
- if (!$txtFile){
- $txtFile = strtotime("now") . '.txt';
- }
- $logFileLocation = 'logs/' . $txtFile;
-
- $this->log("Log File Name: $logFileLocation");
-
- if ($success){
- $this->logStatus("Finished processing " . $this->getServiceProvider . ": $reportLayout.");
- }
-
- //save the actual log file
- $fp = fopen(BASE_DIR . $logFileLocation, 'w');
- fwrite($fp, implode("\n", $this->detailLog));
- fclose($fp);
-
-
- //save to import log!!
- $importLog = new ImportLog();
- $importLog->loginID = "sushi";
- $importLog->layoutCode = $reportLayout;
- $importLog->fileName = 'archive/' . $txtFile;
- $importLog->archiveFileURL = 'archive/' . $txtFile;
- $importLog->logFileURL = $logFileLocation;
- $importLog->details = implode(" ", $this->statusLog);
-
- try {
- $importLog->save();
- $importLogID = $importLog->primaryKey;
- } catch (Exception $e) {
- echo $e->getMessage();
- }
-
- $importLogPlatformLink = new ImportLogPlatformLink();
- $importLogPlatformLink->importLogID = $importLogID;
- $importLogPlatformLink->platformID = $this->platformID;
-
-
- try {
- $importLogPlatformLink->save();
- } catch (Exception $e) {
- echo $e->getMessage();
- }
-
- if(!$success){
- throw new Exception(implode("\n", $this->detailLog));
- }
-
-
- }
-
-
-
- private function soapConnection($wsdl, $parameters){
-
- $parameters = array_merge($parameters, array(
- "keep_alive" => true,
- "connection_timeout"=>1000,
- "trace" => 1,
- "exceptions" => 1,
- "cache_wsdl" => WSDL_CACHE_NONE,
- "stream_context" => stream_context_create(array(
- 'http' => array('protocol_version' => 1.0,
- 'header' => 'Content-Type: application/soap+xml')))
- )
- );
-
- try{
- try{
- $client = new SoapClient($wsdl, $parameters);
-
- //returns soapfault
- }catch (Exception $e){
- $error = $e->__toString();
-
- //if soap fault returned version mismatch or http headers error, try again with soap 1.2
- if ((preg_match('/Version/i', $error)) || (preg_match('/HTTP/i', $error))){
-
- $this->log("Using Soap Version 1.2");
- $parameters = array_merge($parameters, array("soap_version" => SOAP_1_2));
-
- //try connection again with 1.2
- $client = new SoapClient($wsdl, $parameters);
- }
- }
-
- //throws soap fault
- }catch (Exception $e){
- $error = $e->getMessage();
-
- $this->logStatus("Failed to establish soap connection: " . $error);
- $this->saveLogAndExit();
- }
-
- $this->log("");
- $this->log("-- Soap Connection successfully completed --");
- $this->log("");
-
- return $client;
- }
-
-
-
- private function sushiTransfer($reportLayout){
-
-
-
- $ppObj = $this->getPublisherOrPlatform();
- $serviceProvider = str_replace('"','',$ppObj->reportDisplayName);
-
- //if report layout is BR and Release is 3, change it to 1
- if((preg_match('/BR/i', $reportLayout)) && ($this->releaseNumber == "3")){
- $releaseNumber = '1';
- }else{
- $releaseNumber = $this->releaseNumber;
- }
-
- if (($this->wsdlURL == '') || (strtoupper($this->wsdlURL) == 'COUNTER')){
- if ($this->releaseNumber == "4"){
- $wsdl = 'http://www.niso.org/schemas/sushi/counter_sushi4_0.wsdl';
- }else{
- $wsdl = 'http://www.niso.org/schemas/sushi/counter_sushi3_0.wsdl';
- }
- }else{
- $wsdl=$this->wsdlURL;
- }
-
-
-
- $createDate = date("Y-m-d\TH:i:s.0\Z");
- $id = uniqid("CORAL:", true);
-
- // look at $Security to ses if it uses an extension
- if(preg_match('/Extension=/i', $this->security)){
- $extensions = array();
- $varlist = explode(";", $this->security);
- foreach( $varlist as $params){
- list($extVar, $extVal) = explode("=", $params);
- $extensions[$extVar] = $extVal;
- if ($extVar == 'Extension'){
- $extension = $extVal;
- }
- }
- }
-
- if (!empty($extension)){
- include BASE_DIR . 'sushiincludes/extension_'.$extension.'.inc.php';
- }else{
- if (preg_match("/http/i", $this->security)){
- $this->log("Using HTTP Basic authentication via login and password.");
-
- $parameters = array(
- 'login' => $this->login,
- 'password' => $this->password,
- 'location' => $this->serviceURL,
- );
- }else{
- if ((strtoupper($this->wsdlURL) != 'COUNTER') && ($this->wsdlURL != '')){
- $this->log("Using provided wsdl: $wsdl");
- $parameters = array();
-
- }else{
- $this->log("Using COUNTER wsdl, connecting to $this->serviceURL");
- $parameters = array('location'=> $this->serviceURL);
- }
- }
-
- $client = $this->soapConnection($wsdl, $parameters);
- }
-
- if (preg_match("/wsse/i", $this->security)){
- // Prepare SoapHeader parameters
- $strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
- $objSoapVarUser = new SoapVar($this->login, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
- $objSoapVarPass = new SoapVar($this->password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
- $objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
- $objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
- $objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
- $objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
- $objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
- $objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,false);
-
- // Prepare Soap Client
- try{
- $client->__setSoapHeaders(array($objSoapVarWSSEHeader));
- }catch (Exception $e){
- $error = $e->getMessage();
- $this->logStatus("Failed to connect to $serviceProvider: " . $error);
- $this->log("Tried: " . var_dump($client));
- $this->saveLogAndExit($reportLayout);
- }
-
- }
-
- try{
- $reportRequest = array
- ('Requestor' => array
- ('ID' => $this->requestorID,
- 'Name' => 'CORAL Processing',
- 'Email' => $this->requestorID
- ),
- 'CustomerReference' => array
- ('ID' => $this->customerID,
- 'Name' => 'CORAL Processing'
- ),
- 'ReportDefinition' => array
- ('Filters' => array
- ('UsageDateRange' => array
- ('Begin' => $this->startDate,
- 'End' => $this->endDate
- )
- ),
- 'Name' => $reportLayout,
- 'Release' => $releaseNumber
- ),
- 'Created' => $createDate,
- 'ID' => $id,
- 'connection_timeout' => 1000
- );
-
- $result = $client->GetReport($reportRequest);
- }catch(Exception $e){
- $error = $e->getMessage();
-
- $this->logStatus("Exception performing GetReport with connection to $serviceProvider: $error");
-
- //exceptions seem to happen that don't matter, continue processing and if no data or error is found then it will quit.
- //$this->saveLogAndExit($reportLayout);
- }
-
- $xml = $client->__getLastResponse();
-
- $fname = $serviceProvider.'_'.$reportLayout.'_'.$this->startDate.'_'.$this->endDate.'.xml';
- $replace="_";
- $pattern="/([[:alnum:]_\.-]*)/";
- $fname = 'sushistore/' . str_replace(str_split(preg_replace($pattern,$replace,$fname)),$replace,$fname);
-
- $xmlFileName = BASE_DIR . $fname;
- file_put_contents($xmlFileName, $xml);
-
- //open file to look for errors
- $reader = new XMLReader();
- if (!$reader->open($xmlFileName)) {
- $this->logStatus("Failed trying to open XML File: " . $xmlFileName . ". This could be due to not having write access to the /sushistore/ directory.");
- $this->saveLogAndExit($reportLayout);
- }
-
- while ($reader->read()) {
- if ($reader->nodeType == XMLReader::ELEMENT){
- if ($reader->localName == 'Severity') {
- $reader->read();
- $severity = trim($reader->value);
- }
- if ($reader->localName == 'Message') {
- $reader->read();
- $message = trim($reader->value);
- }
-
- }
- }
-
- $reader->close();
-
- if ($message !=""){
- if (($severity == "Error") || (stripos($message, "Error") !== FALSE)){
- $this->logStatus("Failed to request report from $serviceProvider: " . $message);
-
- $this->log("Please fix the settings for this provider and try again.");
- $this->saveLogAndExit($reportLayout);
- }else{
- $this->logStatus("$serviceProvider says: $severity: $message");
- }
- }
-
- $this->log("$reportLayout successfully retrieved from $serviceProvider for start date: $this->startDate, end date: $this->endDate");
-
- $this->log("");
- $this->log("-- Sushi Transfer completed --");
-
- return $fname;
-
-
- }
-
-
-
- private function parseXML($fName, $reportLayout, $overwritePlatform){
-
-
- //////////////////////////////////////
- //PARSE XML!!
- //////////////////////////////////////
-
- $serviceProvider = $this->getServiceProvider();
- $xmlFileName = BASE_DIR . $fName;
-
- //read layouts ini file to get the available layouts
- $layoutsArray = parse_ini_file(BASE_DIR . "layouts.ini", true);
- $layoutColumns = array();
-
- $reader = new XMLReader();
- if (!$reader->open($xmlFileName, 'UTF-8')) {
- $this->logStatus("Failed trying to open XML File: " . $xmlFileName . ". This could be due to not having write access to the /sushistore/ directory.");
- $this->saveLogAndExit($reportLayout);
- }
-
-
- $layoutCode = "";
- $countArray = array();
-
- while ($reader->read()) {
- //First - get report information
- if (($reader->nodeType == XMLReader::ELEMENT) && ($reader->localName == 'Report') && (count($layoutColumns) == '0')) {
- $name = $reader->getAttribute("Name");
- $version = $reader->getAttribute("Version");
-
- $layoutCode = $name;
-
- if (($version == "3") || ($version =="4")){
- $version = "R" . $version;
- }
- if ($version != ''){
- $layoutCode .= "_" . $version;
- }else{
- $layoutCode .= "_R" . $this->releaseNumber;
- }
-
- //At this point, determine the format of the report to port to csv from the layouts.ini file
- $layoutKey = $layoutsArray[ReportTypes][$layoutCode];
- $layoutColumns = $layoutsArray[$layoutKey]['columns'];
-
-
- //if this way of determining layout was unsuccessful, just use the layout sent in
- if (count($layoutColumns) == "0"){
- $layoutCode = $reportLayout . "_R" . $this->releaseNumber;
-
- $layoutKey = $layoutsArray[ReportTypes][$layoutCode];
- $layoutColumns = $layoutsArray[$layoutKey]['columns'];
- }
-
- $this->log("Layout validated successfully against layouts.ini : " . $layoutCode);
-
-
- }
-
- if (($reader->nodeType == XMLReader::ELEMENT) && ($reader->localName == 'ReportItems')) {
- if ((count($layoutColumns) == '0') || ($layoutCode == '')){
- $this->logStatus("Failed determining layout: Reached report items before establishing layout. Please make sure this layout is set up in layouts.ini");
- $this->saveLogAndExit($reportLayout);
- }
-
- //reset variables
- $identifierArray=array();
- $reportArray = array();
-
- //loop through each element under "Item"
- while ($reader->read()) {
-
- //get the element name
- if ($reader->nodeType == XMLReader::ELEMENT){
- $elementName = trim($reader->localName);
-
- //move to next to get the text
- if (($elementName != "Instance") && ($elementName != "ItemIdentifier") && ($elementName != "Period")){
- $reader->read();
- }
-
-
-
- if ($reader->nodeType == XMLReader::TEXT
- || $reader->nodeType == XMLReader::CDATA
- || $reader->nodeType == XMLReader::WHITESPACE
- || $reader->nodeType == XMLReader::SIGNIFICANT_WHITESPACE) {
- $elementValue = trim($reader->value);
-
- switch ($elementName) {
- case 'ItemPlatform':
- if ($overwritePlatform){
- $reportArray['platform'] = $serviceProvider;
- }else{
- $reportArray['platform'] = $elementValue;
- }
-
- break;
- case 'ItemPublisher':
- $reportArray['publisher'] = $elementValue;
- break;
- case 'ItemName':
- $reportArray['title'] = $elementValue;
- break;
- case 'ActivityType':
- $reportArray['activityType'] = strtoupper($reader->value);
- break;
- case 'Type':
- $idType = strtoupper($reader->value);
- break;
- case 'Value':
- $identifierArray[$idType] = $reader->value;
- break;
- case 'Begin':
- $date = new DateTime($reader->value);
-
- if (strtolower($date->format('M')) != $m){
- $totalCountsArray[$m] = $countArray;
-
- $m = strtolower($date->format('M'));
- $y = strtolower($date->format('Y'));
-
- $countArray = array();
- }
-
- break;
- case 'MetricType':
- $metricType = strtoupper($reader->value);
-
- //make sure metric types have conformity
- if (!(strpos($metricType,'HTML') === false)){
- $metricType ='html';
- }else if (!(strpos($metricType,'PDF') === false)){
- $metricType ='pdf';
- }else{
- $metricType ='ytd';
- }
-
- break;
- case 'Count':
- $countArray[$metricType] = $reader->value;
- break;
- }
-
-
- }
-
- //Finished parsing the Title!!!
- }else if ($reader->nodeType == XMLReader::END_ELEMENT
- && $reader->localName == "ReportItems") {
-
- foreach($identifierArray as $key => $value){
- if (!(strrpos($key,'PRINT') === false) && !(strrpos($key,'ISSN') === false)){
- $reportArray['issn'] = $value;
- }else if (!(strrpos($key,'ONLINE') === false) && !(strrpos($key,'ISSN') === false)){
- $reportArray['eissn'] = $value;
- }else if (!(strpos($key,'PRINT') === false) && !(strpos($key,'ISBN') === false)){
- $reportArray['isbn'] = $value;
- }else if (!(strpos($key,'ONLINE') === false) && !(strpos($key,'ISBN') === false)){
- $reportArray['eisbn'] = $value;
- }else if (!(strpos($key,'DOI') === false)){
- $reportArray['doi'] = $value;
- }else if (!(strpos($key,'PROPRIETARY') === false)){
- $reportArray['pi']=$value;
- }
-
- }
-
- //get the last array into the totals array
- $totalCountsArray[$m] = $countArray;
-
- //now figure out the months and the ytd, etc totals
- foreach ($totalCountsArray as $key => $countArray){
-
- if ($key != ''){
-
- if (intval($countArray['ytd']) == "0"){
- $reportArray[$key] = intval($countArray['pdf']) + intval($countArray['html']);
- }else{
- $reportArray[$key] = intval($countArray['ytd']);
- }
-
- $reportArray['ytd'] += intval($countArray['ytd']);
- $reportArray['ytdPDF'] += intval($countArray['pdf']);
- $reportArray['ytdHTML'] += intval($countArray['html']);
- }
-
- }
-
-
- //Now look at the report's layoutcode's columns to order them properly
- $finalArray=array();
- foreach($layoutColumns as $colName){
- $finalArray[] = $reportArray[$colName];
- }
-
- $txtOut .= implode($finalArray,"\t") . "\n";
-
- $totalCountsArray=array();
- break;
- }
- }
- }
-
- }
-
- $reader->close();
-
- if (($layoutKey == "") || (count($layoutColumns) == '0') || ($txtOut == "")){
- if (file_exists($xmlFileName)) {
- $this->logStatus("Failed XML parsing or no data was found.");
-
- $xml = simplexml_load_file($xmlFileName);
- $this->log("The following is the XML response:");
-
- $this->log(htmlentities(file_get_contents($xmlFileName)));
-
- }else{
- $this->log("Failed loading XML file. Please verify you have write permissions on /sushistore/ directory.");
- }
-
- $this->saveLogAndExit($layoutCode);
- }
-
- #Save final text delimited "file" and log output on server
- $txtFile = strtotime("now") . '.txt';
- $fp = fopen(BASE_DIR . 'archive/' . $txtFile, 'w');
- fwrite($fp, $txtOut);
- fclose($fp);
-
-
- $this->log("");
- $this->log("-- Sushi XML parsing completed --");
-
- $this->log("Archive/Text File Name: " . $utility->getPageURL . 'archive/' . $txtFile);
-
- $this->saveLogAndExit($layoutCode, $txtFile, true);
- }
-
-}
-
-
-//for soap headers
-class clsWSSEAuth{
- private $username;
- private $password;
- function __construct($username, $password){
- $this->username=$username;
- $this->password=$password;
- }
-}
-class clsWSSEToken{
- private $usernameToken;
- function __construct ($innerVal){
- $this->usernameToken = $innerVal;
- }
-}
-
-
-
-?>
+.
+**
+**************************************************************************************************************************
+*/
+
+class SushiService extends DatabaseObject {
+
+ protected function defineRelationships() {}
+
+ protected function overridePrimaryKeyName() {}
+
+ public $startDate;
+ public $endDate;
+ private $statusLog = array();
+ private $detailLog = array();
+
+ public function getByPlatformID($platformID){
+ if (isset($platformID)) {
+ $query = "SELECT * FROM `$this->tableName` WHERE `platformID` = '$platformID'";
+ $result = $this->db->processQuery($query, 'assoc');
+
+ foreach (array_keys($result) as $attributeName) {
+ $this->addAttribute($attributeName);
+ $this->attributes[$attributeName] = $result[$attributeName];
+ }
+ }
+ }
+
+ public function getByPublisherPlatformID($publisherPlatformID){
+ if (isset($publisherPlatformID)) {
+ $query = "SELECT * FROM `$this->tableName` WHERE `publisherPlatformID` = '$publisherPlatformID'";
+ $result = $this->db->processQuery($query, 'assoc');
+
+ foreach (array_keys($result) as $attributeName) {
+ $this->addAttribute($attributeName);
+ $this->attributes[$attributeName] = $result[$attributeName];
+ }
+ }
+ }
+
+ //returns array of sushi service objects that need to be run on a particular day
+ public function getByDayOfMonth($serviceDayOfMonth){
+ //now formulate query
+ $query = "SELECT * FROM SushiService WHERE `serviceDayOfMonth` = '$serviceDayOfMonth';";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['sushiServiceID'])){
+ $object = new SushiService(new NamedArguments(array('primaryKey' => $result['sushiServiceID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new SushiService(new NamedArguments(array('primaryKey' => $row['sushiServiceID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+
+
+ public function getPublisherOrPlatform(){
+ if (($this->platformID != "") && ($this->platformID > 0)){
+ return new Platform(new NamedArguments(array('primaryKey' => $this->platformID)));
+ }else{
+ return new PublisherPlatform(new NamedArguments(array('primaryKey' => $this->publisherPlatformID)));
+ }
+ }
+
+
+ public function getServiceProvider(){
+ return str_replace('"','',$this->getPublisherOrPlatform->reportDisplayName);
+ }
+
+
+
+
+ public function failedImports(){
+ $query = "SELECT ipl.platformID, ss.sushiServiceID, date(il.importDateTime), details, il.importLogID
+ FROM ImportLog il
+ INNER JOIN ImportLogPlatformLink ipl USING (ImportLogID)
+ INNER JOIN SushiService ss ON (ss.platformID = ipl.platformID)
+ INNER JOIN (SELECT platformID, max(importLogID) importLogID, max(importDateTime) importDateTime FROM ImportLog mil INNER JOIN ImportLogPlatformLink mipl USING (ImportLogID) GROUP BY platformID) mil ON (mil.importLogID = il.importLogID)
+ WHERE ucase(details) like '%FAIL%'
+ ORDER BY il.importDateTime desc";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+ $resultArray = array();
+ $importArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($importArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($importArray, $resultArray);
+ }
+ }
+
+ return $importArray;
+
+ }
+
+ public function allServices(){
+ $query = "SELECT ss.platformID, ss.publisherPlatformID, sushiServiceID, serviceURL, reportLayouts, releaseNumber,
+ if(serviceDayOfMonth > day(now()), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()), lpad(serviceDayOfMonth,2,'0')), '%Y%m%d'), str_to_date(concat(EXTRACT(YEAR_MONTH FROM NOW()) + 1, lpad(serviceDayOfMonth,2,'0')), '%Y%m%d') ) next_import
+ FROM SushiService ss
+ LEFT JOIN Platform p on (p.platformID = ss.platformID)
+ LEFT JOIN PublisherPlatform pp
+ INNER JOIN Publisher pub USING(publisherID)
+ ON (pp.publisherPlatformID = ss.publisherPlatformID)
+ ORDER BY p.name, pub.name";
+
+ $result = $this->db->processQuery(stripslashes($query), 'assoc');
+
+ $resultArray = array();
+ $importArray = array();
+
+ //need to do this since it could be that there's only one result and this is how the dbservice returns result
+ if (isset($result['platformID'])){
+
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($importArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($importArray, $resultArray);
+ }
+ }
+
+ return $importArray;
+
+ }
+
+
+ //run through ajax function on publisherplatform
+ public function runTest(){
+ $reportLayouts = $this->reportLayouts;
+ $rlArray = explode(";", $reportLayouts);
+
+ //just default test import dates to just be january 1 - 31 of this year
+ $sDate = date_format(date_create_from_format("Ymd", date("Y")."0101"), "Y-m-d");
+ $eDate = date_format(date_create_from_format("Ymd", date("Y")."0131"), "Y-m-d");
+ $this->setImportDates($sDate, $eDate);
+
+
+ foreach($rlArray as $reportLayout){
+ $xmlFile = $this->sushiTransfer($reportLayout);
+ }
+
+ if ($reportLayouts == ""){
+ echo _("At least one report type must be set up!");
+ }else{
+ echo _("Connection test successful!");
+ }
+
+ }
+
+ //run through post or through sushi scheduler
+ public function runAll($overwritePlatform = TRUE){
+ $reportLayouts = $this->reportLayouts;
+ $rlArray = explode(";", $reportLayouts);
+
+ $detailsForOutput = array();
+
+ foreach($rlArray as $reportLayout){
+ $this->statusLog = array();
+ $this->detailLog = array();
+
+ $xmlFile = $this->sushiTransfer($reportLayout);
+ $this->parseXML($xmlFile, $reportLayout, $overwritePlatform);
+
+ $detailsForOutput = $this->statusLog;
+ }
+
+ if ($reportLayouts == ""){
+ return _("No report types are set up!");
+ }
+
+ return implode("\n", $detailsForOutput);
+ }
+
+
+
+
+
+ public function setDefaultImportDates(){
+
+ // Determine the End Date
+ //start with first day of this month
+ $endDate = date_create_from_format("Ymd", date("Y") . date("m") . "01" );
+
+ //subtract one day
+ date_sub($endDate, date_interval_create_from_date_string('1 days'));
+ $this->endDate = date_format($endDate,"Y-m-d");
+
+ //Determine the Start Date
+ //first, get this publisher/platform's last day of import
+ $lastImportDate = $this->getPublisherOrPlatform->getLastImportDate();
+ $lastImportDate = date_create_from_format("Y-m-d", $lastImportDate);
+ date_add($lastImportDate, date_interval_create_from_date_string('1 month'));
+
+ //if that date is set and it's sooner than the first of this year, default it to that date
+ if (($lastImportDate) && (date_format($lastImportDate, "Y-m-d") > date_format($endDate, "Y") . "-01-01")){
+ $this->startDate = date_format($lastImportDate, "Y-m-d");
+ }else{
+ $this->startDate = date_format($endDate, "Y") . "-01-01";
+ }
+
+ }
+
+
+
+ public function setImportDates($sDate = null, $eDate = null){
+
+ if (!$sDate){
+ $this->setDefaultImportDates();
+ }else{
+ //using the multiple functions in order to make sure leading zeros, and this is a date
+ $this->startDate = date_format(date_create_from_format("Y-m-d", $sDate), "Y-m-d");
+ $this->endDate = date_format(date_create_from_format("Y-m-d", $eDate), "Y-m-d");
+ }
+
+ }
+
+
+
+
+ //status for storing in DB and displaying in rows
+ private function logStatus($logText){
+ array_push($this->statusLog, $logText);
+ array_push($this->detailLog, $logText);
+ }
+
+ //longer log for storing in log file and displaying output
+ private function log($logText){
+ array_push($this->detailLog, $logText);
+ }
+
+ //logs process to import log table and to log file
+ public function saveLogAndExit($reportLayout = NULL, $txtFile = NULL, $success = FALSE){
+
+
+ //First, delete any preexisting Failured records, these shouldn't be needed/interesting after this.
+ $this->log("Cleaning up prior failed import logs....");
+
+ $this->getPublisherOrPlatform->removeFailedSushiImports;
+
+ if (!$txtFile){
+ $txtFile = strtotime("now") . '.txt';
+ }
+ $logFileLocation = 'logs/' . $txtFile;
+
+ $this->log("Log File Name: $logFileLocation");
+
+ if ($success){
+ $this->logStatus("Finished processing " . $this->getServiceProvider . ": $reportLayout.");
+ }
+
+ //save the actual log file
+ $fp = fopen(BASE_DIR . $logFileLocation, 'w');
+ fwrite($fp, implode("\n", $this->detailLog));
+ fclose($fp);
+
+
+ //save to import log!!
+ $importLog = new ImportLog();
+ $importLog->loginID = "sushi";
+ $importLog->layoutCode = $reportLayout;
+ $importLog->fileName = 'archive/' . $txtFile;
+ $importLog->archiveFileURL = 'archive/' . $txtFile;
+ $importLog->logFileURL = $logFileLocation;
+ $importLog->details = implode(" ", $this->statusLog);
+
+ try {
+ $importLog->save();
+ $importLogID = $importLog->primaryKey;
+ } catch (Exception $e) {
+ echo $e->getMessage();
+ }
+
+ $importLogPlatformLink = new ImportLogPlatformLink();
+ $importLogPlatformLink->importLogID = $importLogID;
+ $importLogPlatformLink->platformID = $this->platformID;
+
+
+ try {
+ $importLogPlatformLink->save();
+ } catch (Exception $e) {
+ echo $e->getMessage();
+ }
+
+ if(!$success){
+ throw new Exception(implode("\n", $this->detailLog));
+ }
+
+
+ }
+
+
+
+ private function soapConnection($wsdl, $parameters){
+
+ $parameters = array_merge($parameters, array(
+ "keep_alive" => true,
+ "connection_timeout"=>1000,
+ "trace" => 1,
+ "exceptions" => 1,
+ "cache_wsdl" => WSDL_CACHE_NONE,
+ "stream_context" => stream_context_create(array(
+ 'http' => array('protocol_version' => 1.0,
+ 'header' => 'Content-Type: application/soap+xml')))
+ )
+ );
+
+ try{
+ try{
+ $client = new SoapClient($wsdl, $parameters);
+
+ //returns soapfault
+ }catch (Exception $e){
+ $error = $e->__toString();
+
+ //if soap fault returned version mismatch or http headers error, try again with soap 1.2
+ if ((preg_match('/Version/i', $error)) || (preg_match('/HTTP/i', $error))){
+
+ $this->log("Using Soap Version 1.2");
+ $parameters = array_merge($parameters, array("soap_version" => SOAP_1_2));
+
+ //try connection again with 1.2
+ $client = new SoapClient($wsdl, $parameters);
+ }
+ }
+
+ //throws soap fault
+ }catch (Exception $e){
+ $error = $e->getMessage();
+
+ $this->logStatus("Failed to establish soap connection: " . $error);
+ $this->saveLogAndExit();
+ }
+
+ $this->log("");
+ $this->log("-- Soap Connection successfully completed --");
+ $this->log("");
+
+ return $client;
+ }
+
+
+
+ private function sushiTransfer($reportLayout){
+
+
+
+ $ppObj = $this->getPublisherOrPlatform();
+ $serviceProvider = str_replace('"','',$ppObj->reportDisplayName);
+
+ //if report layout is BR and Release is 3, change it to 1
+ if((preg_match('/BR/i', $reportLayout)) && ($this->releaseNumber == "3")){
+ $releaseNumber = '1';
+ }else{
+ $releaseNumber = $this->releaseNumber;
+ }
+
+ if (($this->wsdlURL == '') || (strtoupper($this->wsdlURL) == 'COUNTER')){
+ if ($this->releaseNumber == "4"){
+ $wsdl = 'http://www.niso.org/schemas/sushi/counter_sushi4_0.wsdl';
+ }else{
+ $wsdl = 'http://www.niso.org/schemas/sushi/counter_sushi3_0.wsdl';
+ }
+ }else{
+ $wsdl=$this->wsdlURL;
+ }
+
+
+
+ $createDate = date("Y-m-d\TH:i:s.0\Z");
+ $id = uniqid("CORAL:", true);
+
+ // look at $Security to ses if it uses an extension
+ if(preg_match('/Extension=/i', $this->security)){
+ $extensions = array();
+ $varlist = explode(";", $this->security);
+ foreach( $varlist as $params){
+ list($extVar, $extVal) = explode("=", $params);
+ $extensions[$extVar] = $extVal;
+ if ($extVar == 'Extension'){
+ $extension = $extVal;
+ }
+ }
+ }
+
+ if (!empty($extension)){
+ include BASE_DIR . 'sushiincludes/extension_'.$extension.'.inc.php';
+ }else{
+ if (preg_match("/http/i", $this->security)){
+ $this->log("Using HTTP Basic authentication via login and password.");
+
+ $parameters = array(
+ 'login' => $this->login,
+ 'password' => $this->password,
+ 'location' => $this->serviceURL,
+ );
+ }else{
+ if ((strtoupper($this->wsdlURL) != 'COUNTER') && ($this->wsdlURL != '')){
+ $this->log("Using provided wsdl: $wsdl");
+ $parameters = array();
+
+ }else{
+ $this->log("Using COUNTER wsdl, connecting to $this->serviceURL");
+ $parameters = array('location'=> $this->serviceURL);
+ }
+ }
+
+ $client = $this->soapConnection($wsdl, $parameters);
+ }
+
+ if (preg_match("/wsse/i", $this->security)){
+ // Prepare SoapHeader parameters
+ $strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
+ $objSoapVarUser = new SoapVar($this->login, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
+ $objSoapVarPass = new SoapVar($this->password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
+ $objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
+ $objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
+ $objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
+ $objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
+ $objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
+ $objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,false);
+
+ // Prepare Soap Client
+ try{
+ $client->__setSoapHeaders(array($objSoapVarWSSEHeader));
+ }catch (Exception $e){
+ $error = $e->getMessage();
+ $this->logStatus("Failed to connect to $serviceProvider: " . $error);
+ $this->log("Tried: " . var_dump($client));
+ $this->saveLogAndExit($reportLayout);
+ }
+
+ }
+ $uStartArray = explode("-",$this->startDate);
+ $usd = $uStartArray[2];//the start day used to find the unix timestamp for the start date
+ $usm = $uStartArray[1];//the start month used to find the unix timestamp for the start date
+ $usy = $uStartArray[0];//the start year used to find the unix timestamp for the start date
+ $uStartDate = mktime(0,0,0,$usm,$usd,$usy);//finds the unix timestamp for the start date
+ //Do exactly the same thing for the end date
+ $uEndDate = explode("-", $this->endDate);
+ $ued = $uEndDate[2];
+ $uem = $uEndDate[1];
+ $uey = $uEndDate[0];
+ $uEndDate = mktime(0,0,0,$uem,$ued,$uey);
+ if (($uEndDate-$uStartDate)<31536000){
+ try{
+ $reportRequest = array
+ ('Requestor' => array
+ ('ID' => $this->requestorID,
+ 'Name' => 'CORAL Processing',
+ 'Email' => $this->requestorID
+ ),
+ 'CustomerReference' => array
+ ('ID' => $this->customerID,
+ 'Name' => 'CORAL Processing'
+ ),
+ 'ReportDefinition' => array
+ ('Filters' => array
+ ('UsageDateRange' => array
+ ('Begin' => $this->startDate,
+ 'End' => $this->endDate
+ )
+ ),
+ 'Name' => $reportLayout,
+ 'Release' => $releaseNumber
+ ),
+ 'Created' => $createDate,
+ 'ID' => $id,
+ 'connection_timeout' => 1000
+ );
+ $dateError=FALSE;
+
+ $result = $client->GetReport($reportRequest);
+ }catch(Exception $e){
+ $error = $e->getMessage();
+
+ $this->logStatus("Exception performing GetReport with connection to $serviceProvider: $error");
+
+ //exceptions seem to happen that don't matter, continue processing and if no data or error is found then it will quit.
+ //$this->saveLogAndExit($reportLayout);
+ }
+ }
+ else {
+ $dateError = TRUE;
+ $this->logStatus("Invalid Dates entered. Must enter a start and end date less than or equal to one year apart.");
+ }
+
+ $xml = $client->__getLastResponse();
+
+ $fname = $serviceProvider.'_'.$reportLayout.'_'.$this->startDate.'_'.$this->endDate.'.xml';
+ $replace="_";
+ $pattern="/([[:alnum:]_\.-]*)/";
+ $fname = 'sushistore/' . str_replace(str_split(preg_replace($pattern,$replace,$fname)),$replace,$fname);
+
+ $xmlFileName = BASE_DIR . $fname;
+ file_put_contents($xmlFileName, $xml);
+
+ //open file to look for errors
+ $reader = new XMLReader();
+ if (!$reader->open($xmlFileName)) {
+ $this->logStatus("Failed trying to open XML File: " . $xmlFileName . ". This could be due to not having write access to the /sushistore/ directory.");
+ $this->saveLogAndExit($reportLayout);
+ }
+
+ $message = "";
+ while ($reader->read()) {
+ if ($reader->nodeType == XMLReader::ELEMENT){
+ if ($reader->localName == 'Severity') {
+ $reader->read();
+ $severity = trim($reader->value);
+ }
+ if ($reader->localName == 'Message') {
+ $reader->read();
+ $message = trim($reader->value);
+ }
+
+ }
+ }
+
+ $reader->close();
+
+ if ($message !=""){
+ if (($severity == "Error") || (stripos($message, "Error") !== FALSE)){
+ $this->logStatus("Failed to request report from $serviceProvider: " . $message);
+
+ $this->log("Please fix the settings for this provider and try again.");
+ $this->saveLogAndExit($reportLayout);
+ }else{
+ $this->logStatus("$serviceProvider says: $severity: $message");
+ }
+ }
+ if (!$dateError)
+ $this->log("$reportLayout successfully retrieved from $serviceProvider for start date: $this->startDate, end date: $this->endDate");
+
+ $this->log("");
+ $this->log("-- Sushi Transfer completed --");
+
+ return $fname;
+
+
+ }
+
+
+
+ private function parseXML($fName, $reportLayout, $overwritePlatform){
+
+
+ //////////////////////////////////////
+ //PARSE XML!!
+ //////////////////////////////////////
+
+ $serviceProvider = $this->getServiceProvider();
+ $xmlFileName = BASE_DIR . $fName;
+
+ //read layouts ini file to get the available layouts
+ $layoutsArray = parse_ini_file(BASE_DIR . "layouts.ini", true);
+ $layoutColumns = array();
+
+ $reader = new XMLReader();
+ if (!$reader->open($xmlFileName, 'UTF-8')) {
+ $this->logStatus("Failed trying to open XML File: " . $xmlFileName . ". This could be due to not having write access to the /sushistore/ directory.");
+ $this->saveLogAndExit($reportLayout);
+ }
+
+
+ $layoutCode = "";
+ $countArray = array('ytd'=>null,'pdf'=>null,'html'=>null);
+ $txtOut = "";
+ $startDateArr = explode("-", $this -> startDate);
+ $endDateArr = explode("-", $this -> endDate);
+ $startYear = $startDateArr[0];
+ $startMonth = $startDateArr[1];
+ $endYear = $endDateArr[0];
+ $endMonth = $endDateArr[1];
+ $numMonths = 0;
+ if ($startMonth > $endMonth)
+ $numMonths = (13 - ($startMonth - $endMonth));
+ else if ($endMonth > $startMonth)
+ $numMonths = ($endMonth - $startMonth);
+ else
+ $numMonths = 1;
+ $m = null; //month
+
+ while ($reader->read()) {
+ //First - get report information
+ if (($reader->nodeType == XMLReader::ELEMENT) && ($reader->localName == 'Report') && (count($layoutColumns) == '0')) {
+ $name = $reader->getAttribute("Name");
+ $version = $reader->getAttribute("Version");
+
+ $layoutCode = $name;
+
+ if (($version == "3") || ($version =="4")){
+ $version = "R" . $version;
+ }
+ if ($version != ''){
+ $layoutCode .= "_" . $version;
+ }else{
+ $layoutCode .= "_R" . $this->releaseNumber;
+ }
+
+ //At this point, determine the format of the report to port to csv from the layouts.ini file
+ $layoutKey = $layoutsArray['ReportTypes'][$layoutCode];
+ $layoutColumns = $layoutsArray[$layoutKey]['columns'];
+
+
+ //if this way of determining layout was unsuccessful, just use the layout sent in
+ if (count($layoutColumns) == "0"){
+ $layoutCode = $reportLayout . "_R" . $this->releaseNumber;
+
+ $layoutKey = $layoutsArray['ReportTypes'][$layoutCode];
+ $layoutColumns = $layoutsArray[$layoutKey]['columns'];
+
+ ///////////////////////////////////////////////////////
+ // Create header for SUSHI file
+ ///////////////////////////////////////////////////////
+ $header = $layoutColumns;
+ $startMonthArray = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12);
+ for ($i = 0; $i < sizeof($header); $i++) {
+ foreach ($startMonthArray as $monthName => $monthNumber) {
+ if($header[$i] == $monthName && $monthNumber >= $startMonth) {
+ $header[$i] .= "-$startYear";
+ break;
+ }
+ else if ($header[$i] == $monthName && $monthNumber < $startMonth){
+ $header[$i] .= "-$endYear";
+ break;
+ }
+ }
+ }
+ for ($i = 12; $i > 0; $i--) {
+ if ($startMonth > $endMonth && $i < $startMonth && $i > $endMonth)
+ $header[(count($header) - 13)+$i] .= "-x";
+ else if ($endMonth > $startMonth && ($i < $startMonth || $i > $endMonth))
+ $header[(count($header) - 13)+$i] .= "-x";
+ else if ($endMonth == $startMonth && $i < $startMonth && $i > $endMonth)
+ $header[(count($header) - 13)+$i] .= "-x";
+ }
+ $txtOut .= implode($header, "\t") . "\n";
+ }
+
+ $this->log("Layout validated successfully against layouts.ini : " . $layoutCode);
+
+
+ }
+
+ if (($reader->nodeType == XMLReader::ELEMENT) && ($reader->localName == 'ReportItems')) {
+ if ((count($layoutColumns) == '0') || ($layoutCode == '')){
+ $this->logStatus("Failed determining layout: Reached report items before establishing layout. Please make sure this layout is set up in layouts.ini");
+ $this->saveLogAndExit($reportLayout);
+ }
+
+ //reset variables
+ $identifierArray=array();
+ $reportArray = array('ytd'=>null,'ytdHTML'=>null,'ytdPDF'=>null);
+
+ //loop through each element under "Item"
+ while ($reader->read()) {
+
+ //get the element name
+ if ($reader->nodeType == XMLReader::ELEMENT){
+ $elementName = trim($reader->localName);
+
+ //move to next to get the text
+ if (($elementName != "Instance") && ($elementName != "ItemIdentifier") && ($elementName != "Period")){
+ $reader->read();
+ }
+
+
+
+ if ($reader->nodeType == XMLReader::TEXT
+ || $reader->nodeType == XMLReader::CDATA
+ || $reader->nodeType == XMLReader::WHITESPACE
+ || $reader->nodeType == XMLReader::SIGNIFICANT_WHITESPACE) {
+ $elementValue = trim($reader->value);
+
+ switch ($elementName) {
+ case 'ItemPlatform':
+ if ($overwritePlatform){
+ $reportArray['platform'] = $serviceProvider;
+ }else{
+ $reportArray['platform'] = $elementValue;
+ }
+
+ break;
+ case 'ItemPublisher':
+ $reportArray['publisher'] = $elementValue;
+ break;
+ case 'ItemName':
+ $reportArray['title'] = $elementValue;
+ break;
+ case 'ActivityType':
+ $reportArray['activityType'] = strtoupper($reader->value);
+ break;
+ case 'Type':
+ $idType = strtoupper($reader->value);
+ break;
+ case 'Value':
+ $identifierArray[$idType] = $reader->value;
+ break;
+ case 'Begin':
+ $date = new DateTime($reader->value);
+ if ($m === null) {
+ $m = strtolower($date->format('M'));
+ $countArray = array('ytd'=>null,'pdf'=>null,'html'=>null);
+ } else if (strtolower($date->format('M')) !== $m){
+ $totalCountsArray[$m] = $countArray;
+
+ $m = strtolower($date->format('M'));
+ //$y = strtolower($date->format('Y'));
+
+ $countArray = array('ytd'=>null,'pdf'=>null,'html'=>null);
+ }
+
+ break;
+ case 'MetricType':
+ $metricType = strtoupper($reader->value);
+
+ //make sure metric types have conformity
+ if (!(strpos($metricType,'HTML') === false)){
+ $metricType ='html';
+ }else if (!(strpos($metricType,'PDF') === false)){
+ $metricType ='pdf';
+ }else{
+ $metricType ='ytd';
+ }
+
+ break;
+ case 'Count':
+ $countArray[$metricType] = $reader->value;
+ break;
+ }
+
+
+ }
+
+ //Finished parsing the Title!!!
+ }else if ($reader->nodeType == XMLReader::END_ELEMENT
+ && $reader->localName == "ReportItems") {
+
+ foreach($identifierArray as $key => $value){
+ if (!(strrpos($key,'PRINT') === false) && !(strrpos($key,'ISSN') === false)){
+ $reportArray['issn'] = $value;
+ }else if (!(strrpos($key,'ONLINE') === false) && !(strrpos($key,'ISSN') === false)){
+ $reportArray['eissn'] = $value;
+ }else if (!(strpos($key,'PRINT') === false) && !(strpos($key,'ISBN') === false)){
+ $reportArray['isbn'] = $value;
+ }else if (!(strpos($key,'ONLINE') === false) && !(strpos($key,'ISBN') === false)){
+ $reportArray['eisbn'] = $value;
+ }else if (!(strpos($key,'DOI') === false)){
+ $reportArray['doi'] = $value;
+ }else if (!(strpos($key,'PROPRIETARY') === false)){
+ $reportArray['pi']=$value;
+ }
+
+ }
+
+ //get the last array into the totals array
+ $totalCountsArray[$m] = $countArray;
+
+ //now figure out the months and the ytd, etc totals
+ foreach ($totalCountsArray as $key => $countArray){
+
+ if ($key != ''){
+
+ if (intval($countArray['ytd']) == "0"){
+ $reportArray[$key] = intval($countArray['pdf']) + intval($countArray['html']);
+ }else{
+ $reportArray[$key] = intval($countArray['ytd']);
+ }
+
+ if ($reportArray['ytd']===null)
+ $reportArray['ytd'] = intval($countArray['ytd']);
+ else
+ $reportArray['ytd'] += intval($countArray['ytd']);
+
+ if ($reportArray['ytdPDF']===null)
+ $reportArray['ytdPDF'] = intval($countArray['pdf']);
+ else
+ $reportArray['ytdPDF'] += intval($countArray['pdf']);
+
+ if ($reportArray['ytdHTML']===null)
+ $reportArray['ytdHTML'] = intval($countArray['html']);
+ else
+ $reportArray['ytdHTML'] += intval($countArray['html']);
+ }
+
+ }
+
+
+ //Now look at the report's layoutcode's columns to order them properly
+ $finalArray=array();
+ foreach($layoutColumns as $colName){
+ if (isset($reportArray[$colName]))
+ $finalArray[] = $reportArray[$colName];
+ else
+ $finalArray[] = null;
+ }
+
+ $txtOut .= implode($finalArray,"\t") . "\n";
+
+ $totalCountsArray=array();
+ break;
+ }
+ }
+ }
+
+ }
+
+ $reader->close();
+
+ if (($layoutKey == "") || (count($layoutColumns) == '0') || ($txtOut == "")){
+ if (file_exists($xmlFileName)) {
+ $this->logStatus("Failed XML parsing or no data was found.");
+
+ $xml = simplexml_load_file($xmlFileName);
+ $this->log("The following is the XML response:");
+
+ $this->log(htmlentities(file_get_contents($xmlFileName)));
+
+ }else{
+ $this->log("Failed loading XML file. Please verify you have write permissions on /sushistore/ directory.");
+ }
+
+ $this->saveLogAndExit($layoutCode);
+ }
+
+ #Save final text delimited "file" and log output on server
+ $txtFile = strtotime("now") . '.txt';
+ $fp = fopen(BASE_DIR . 'archive/' . $txtFile, 'w');
+ fwrite($fp, $txtOut);
+ fclose($fp);
+
+
+ $this->log("");
+ $this->log("-- Sushi XML parsing completed --");
+
+ $this->log("Archive/Text File Name: " . Utility::getPageURL() . 'archive/' . $txtFile);
+
+ $this->saveLogAndExit($layoutCode, $txtFile, true);
+ }
+
+}
+
+
+//for soap headers
+class clsWSSEAuth{
+ private $username;
+ private $password;
+ function __construct($username, $password){
+ $this->username=$username;
+ $this->password=$password;
+ }
+}
+class clsWSSEToken{
+ private $usernameToken;
+ function __construct ($innerVal){
+ $this->usernameToken = $innerVal;
+ }
+}
+
+
+
+?>
diff --git a/admin/classes/domain/Title.php b/admin/classes/domain/Title.php
index e5fa519..fb612bc 100755
--- a/admin/classes/domain/Title.php
+++ b/admin/classes/domain/Title.php
@@ -1,358 +1,360 @@
-.
-**
-**************************************************************************************************************************
-*/
-
-class Title extends DatabaseObject {
-
- protected function defineRelationships() {}
-
- protected function overridePrimaryKeyName() {}
-
- protected function defineAttributes() {
- $this->addAttribute('titleID');
- $this->addAttribute('title');
- $this->addAttribute('resourceType');
- }
-
- //returns identifier (issn, isbn, etc) only of the first print identifier found for this title
- public function getIdentifier($idType){
- $query = "SELECT * FROM TitleIdentifier ti
- WHERE ti.titleID = '" . $this->titleID . "'
- AND identifierType='" . $idType . "'
- ORDER BY 1
- LIMIT 1;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['titleIdentifierID'])){
- $identifier = $result['identifier'];
- return substr($identifier, 0, 4) . "-" . substr($identifier, 4, 4);
- }else{
- return;
- }
-
-
- }
-
-
-
- //find out if there is an existing identifier for a title
- public function getExistingIdentifier($identifier){
-
- $query = "SELECT distinct identifier
- FROM TitleIdentifier ti
- WHERE ti.titleID = '" . $this->titleID . "'
- AND identifier = '" . $identifier . "'
- ORDER BY identifierType DESC
- LIMIT 1;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- //only one identifier will be returned
- if (isset($result['identifier'])){
- return true;
- }else{
- return false;
- }
-
-
- }
-
-
- //returns array of identifier objects
- public function getIdentifiers($idType = null){
-
- if($idType){
- $addWhere = " AND identifierType='" . $idType . "'";
- }
-
- $query = "SELECT *
- FROM TitleIdentifier ti
- WHERE ti.titleID = '" . $this->titleID . "' " . $addWhere . "
- ORDER BY identifierType DESC;";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['titleIdentifierID'])){
- $object = new TitleIdentifier(new NamedArguments(array('primaryKey' => $result['titleIdentifierID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new TitleIdentifier(new NamedArguments(array('primaryKey' => $row['titleIdentifierID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
-
- //returns array of title objects
- public function getRelatedTitles(){
-
- $query = "SELECT DISTINCT t.titleID
- FROM TitleIdentifier ti, Title t, TitleIdentifier ti2
- WHERE ti.titleID = t.titleID
- AND ti.identifier = ti2.identifier
- AND ti.identifierType = ti2.identifierType
- AND ti2.titleID = '" . $this->titleID . "';";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $objects = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['titleID'])){
- $object = new Title(new NamedArguments(array('primaryKey' => $result['titleID'])));
- array_push($objects, $object);
- }else{
- foreach ($result as $row) {
- $object = new Title(new NamedArguments(array('primaryKey' => $row['titleID'])));
- array_push($objects, $object);
- }
- }
-
- return $objects;
- }
-
-
-
-
- //returns array of yearly stats for this title
- public function getYearlyStats($archiveInd, $year, $publisherPlatformID, $activityType){
-
- $addWhere = '';
- if ($activityType){
- $addWhere=" AND activityType='" . $activityType . "'";
- }
- $query = "SELECT titleID, totalCount, ytdHTMLCount, ytdPDFCount
- FROM YearlyUsageSummary
- WHERE titleID = '" . $this->titleID . "'
- AND archiveInd ='" . $archiveInd . "'
- AND year='" . $year . "'" . $addWhere . "
- AND publisherPlatformID = '" . $publisherPlatformID . "';";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['titleID'])){
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- foreach ($result as $row) {
- $resultArray = array();
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- array_push($allArray, $resultArray);
- }
- }
-
- return $allArray;
- }
-
-
- //returns array of the first listed identifier objects
- public function getByTitle($resourceType, $resourceTitle, $pISSN, $eISSN, $pISBN, $eISBN, $publisherPlatformID){
-
- //default search to print ISBN only - we're confident that's the same title
- if ($pISBN) {
- $query = "SELECT DISTINCT ti.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t USING (titleID) WHERE identifierType = 'ISBN' AND identifier = '" . $pISBN . "' AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
-
- //Otherwise try ISSN if it's a journal or there's no p-isbn
- } else if (($pISSN) && (($resourceType == "Journal") || (!$pISBN))) {
- $query = "SELECT DISTINCT ti.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t USING (titleID) WHERE identifierType = 'ISSN' AND identifier = '" . $pISSN . "' AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
-
- //not so confident about online identifier so we also search on common platform / publisher
- }else if ((!$pISBN) && ($eISBN)){
- $query = "SELECT DISTINCT t.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t ON (ti.titleID = t.titleID) INNER JOIN MonthlyUsageSummary mus ON (mus.titleID = t.titleID) WHERE identifierType = 'eISBN' AND identifier = '" . $eISBN . "' AND publisherPlatformID = '" . $publisherPlatformID . "' AND ucase(title) = ucase('" . $resourceTitle . "') AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
-
-
- //not so confident about online identifier so we also search on common platform / publisher
- }else if ((!$pISSN) && ($eISSN) && ($resourceType == "Journal")){
- $query = "SELECT DISTINCT t.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t ON (ti.titleID = t.titleID) INNER JOIN MonthlyUsageSummary mus ON (mus.titleID = t.titleID) WHERE identifierType = 'eISSN' AND identifier = '" . $eISSN . "' AND publisherPlatformID = '" . $publisherPlatformID . "' AND ucase(title) = ucase('" . $resourceTitle . "') AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
-
- //this is a title search so we're also searching on common platform / publisher (used for Databases probably primarily)
- }else if ((!$pISSN) && (!$eISSN) && (!$pISBN) && (!$eISBN)){
- $query = "SELECT DISTINCT t.titleID as titleID FROM Title t INNER JOIN MonthlyUsageSummary mus ON (mus.titleID = t.titleID) WHERE publisherPlatformID = '" . $publisherPlatformID . "' AND ucase(title) = ucase('" . $resourceTitle . "') AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
- }
-
- $result = $this->db->processQuery($query, 'assoc');
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['titleID'])){
- return $result['titleID'];
- }else{
- return false;
- }
-
- }
-
-
-
-
- //remove an entire month for this title/publisher
- public function deleteMonth($archiveInd, $year, $month, $publisherPlatformID){
-
- //now formulate query
- $query = "DELETE FROM MonthlyUsageSummary
- WHERE archiveInd = '" . $archiveInd . "'
- AND titleID = '" . $this->titleID . "'
- AND publisherPlatformID = '" . $publisherPlatformID . "'
- AND year = '" . $year . "'
- AND month = '" . $month . "';";
-
- return $this->db->processQuery($query);
-
- }
-
-
- //remove an entire month for this title/publisher
- public function deleteYearlyStats($archiveInd, $year, $publisherPlatformID, $activityType){
-
- if ($activityType){
- $addWhere = " AND activityType='" . $activityType . "'";
- }
-
- //now formulate query
- $query = "DELETE FROM YearlyUsageSummary
- WHERE archiveInd = '" . $archiveInd . "'
- AND titleID = '" . $this->titleID . "'
- AND publisherPlatformID = '" . $publisherPlatformID . "' " . $addWhere . "
- AND year = '" . $year . "';";
-
- return $this->db->processQuery($query);
-
- }
-
-
- //returns usage count only
- public function getUsageCountByMonth($archiveInd, $year, $month, $publisherPlatformID){
-
- $query = "SELECT usageCount FROM MonthlyUsageSummary
- WHERE archiveInd = '" . $archiveInd . "'
- AND titleID = '" . $this->titleID . "'
- AND publisherPlatformID = '" . $publisherPlatformID . "'
- AND year = '" . $year . "'
- AND month = '" . $month . "';";
-
-
-
- $result = $this->db->processQuery($query, 'assoc');
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['usageCount'])){
- return $result['usageCount'];
- }else{
- return false;
- }
-
- }
-
-
-
-
-
- //returns array of the first listed identifier objects
- public function getTotalCountByYear($archiveInd, $year, $publisherPlatformID){
-
- $query = "SELECT totalCount usageCount, ytdHTMLCount, ytdPDFCount FROM YearlyUsageSummary
- WHERE archiveInd = '" . $archiveInd . "'
- AND titleID = '" . $this->titleID . "'
- AND publisherPlatformID = '" . $publisherPlatformID . "'
- AND year = '" . $year . "';";
-
-
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $resultArray = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['usageCount'])){
- $resultArray['usageCount'] = $result['usageCount'];
- $resultArray['ytdHTMLCount'] = $result['ytdHTMLCount'];
- $resultArray['ytdPDFCount'] = $result['ytdPDFCount'];
-
- return $resultArray;
- }else{
- return false;
- }
-
- }
-
-
-
- //returns array of yearly stats for this title
- public function get12MonthUsageCount($archiveInd, $publisherPlatformID, $yearAddWhere){
-
- $query = "SELECT usageCount FROM MonthlyUsageSummary
- WHERE archiveInd = '" . $archiveInd . "'
- AND titleID = '" . $this->titleID . "'
- AND publisherPlatformID = '" . $publisherPlatformID . "'
- AND " . $yearAddWhere . ";";
-
- $result = $this->db->processQuery($query, 'assoc');
-
- $allArray = array();
- $resultArray = array();
-
- //need to do this since it could be that there's only one request and this is how the dbservice returns result
- if (isset($result['usageCount'])){
- foreach (array_keys($result) as $attributeName) {
- $resultArray[$attributeName] = $result[$attributeName];
- }
-
- array_push($allArray, $resultArray);
- }else{
- if ($result){
- foreach ($result as $row) {
- $resultArray = array();
- if ($resultArray){
- foreach (array_keys($row) as $attributeName) {
- $resultArray[$attributeName] = $row[$attributeName];
- }
- }
- array_push($allArray, $resultArray);
- }
- }
- }
-
- return $allArray;
- }
-
-
-
-
-
-
-
-
-}
-
-?>
+.
+**
+**************************************************************************************************************************
+*/
+
+class Title extends DatabaseObject {
+
+ protected function defineRelationships() {}
+
+ protected function overridePrimaryKeyName() {}
+
+ protected function defineAttributes() {
+ $this->addAttribute('titleID');
+ $this->addAttribute('title');
+ $this->addAttribute('resourceType');
+ }
+
+ //returns identifier (issn, isbn, etc) only of the first print identifier found for this title
+ public function getIdentifier($idType){
+ $query = "SELECT * FROM TitleIdentifier ti
+ WHERE ti.titleID = '" . $this->titleID . "'
+ AND identifierType='" . $idType . "'
+ ORDER BY 1
+ LIMIT 1;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['titleIdentifierID'])){
+ $identifier = $result['identifier'];
+ return substr($identifier, 0, 4) . "-" . substr($identifier, 4, 4);
+ }else{
+ return;
+ }
+
+
+ }
+
+
+
+ //find out if there is an existing identifier for a title
+ public function getExistingIdentifier($identifier){
+
+ $query = "SELECT distinct identifier
+ FROM TitleIdentifier ti
+ WHERE ti.titleID = '" . $this->titleID . "'
+ AND identifier = '" . $identifier . "'
+ ORDER BY identifierType DESC
+ LIMIT 1;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ //only one identifier will be returned
+ if (isset($result['identifier'])){
+ return true;
+ }else{
+ return false;
+ }
+
+
+ }
+
+
+ //returns array of identifier objects
+ public function getIdentifiers($idType = null){
+
+ if($idType){
+ $addWhere = " AND identifierType='" . $idType . "'";
+ }
+
+ $query = "SELECT *
+ FROM TitleIdentifier ti
+ WHERE ti.titleID = '" . $this->titleID . "' " . $addWhere . "
+ ORDER BY identifierType DESC;";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['titleIdentifierID'])){
+ $object = new TitleIdentifier(new NamedArguments(array('primaryKey' => $result['titleIdentifierID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new TitleIdentifier(new NamedArguments(array('primaryKey' => $row['titleIdentifierID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+
+ //returns array of title objects
+ public function getRelatedTitles(){
+
+ $query = "SELECT DISTINCT t.titleID
+ FROM TitleIdentifier ti, Title t, TitleIdentifier ti2
+ WHERE ti.titleID = t.titleID
+ AND ti.identifier = ti2.identifier
+ AND ti.identifierType = ti2.identifierType
+ AND ti2.titleID = '" . $this->titleID . "';";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $objects = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['titleID'])){
+ $object = new Title(new NamedArguments(array('primaryKey' => $result['titleID'])));
+ array_push($objects, $object);
+ }else{
+ foreach ($result as $row) {
+ $object = new Title(new NamedArguments(array('primaryKey' => $row['titleID'])));
+ array_push($objects, $object);
+ }
+ }
+
+ return $objects;
+ }
+
+
+
+
+ //returns array of yearly stats for this title
+ public function getYearlyStats($archiveInd, $year, $publisherPlatformID, $activityType){
+
+ $addWhere = '';
+ if ($activityType){
+ $addWhere=" AND activityType='" . $activityType . "'";
+ }
+ $query = "SELECT titleID, totalCount, ytdHTMLCount, ytdPDFCount
+ FROM YearlyUsageSummary
+ WHERE titleID = '" . $this->titleID . "'
+ AND archiveInd ='" . $archiveInd . "'
+ AND year='" . $year . "'" . $addWhere . "
+ AND publisherPlatformID = '" . $publisherPlatformID . "';";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['titleID'])){
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ foreach ($result as $row) {
+ $resultArray = array();
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+
+ return $allArray;
+ }
+
+
+ //returns array of the first listed identifier objects
+ public function getByTitle($resourceType, $resourceTitle, $pISSN, $eISSN, $pISBN, $eISBN, $publisherPlatformID){
+
+ //default search to print ISBN only - we're confident that's the same title
+ if ($pISBN) {
+ $query = "SELECT DISTINCT ti.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t USING (titleID) WHERE identifierType = 'ISBN' AND identifier = '" . $pISBN . "' AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
+
+ //Otherwise try ISSN if it's a journal or there's no p-isbn
+ } else if (($pISSN) && (($resourceType == "Journal") || (!$pISBN))) {
+ $query = "SELECT DISTINCT ti.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t USING (titleID) WHERE identifierType = 'ISSN' AND identifier = '" . $pISSN . "' AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
+
+ //not so confident about online identifier so we also search on common platform / publisher
+ }else if ((!$pISBN) && ($eISBN)){
+ $query = "SELECT DISTINCT t.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t ON (ti.titleID = t.titleID) INNER JOIN MonthlyUsageSummary mus ON (mus.titleID = t.titleID) WHERE identifierType = 'eISBN' AND identifier = '" . $eISBN . "' AND publisherPlatformID = '" . $publisherPlatformID . "' AND ucase(title) = ucase('" . $resourceTitle . "') AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
+
+
+ //not so confident about online identifier so we also search on common platform / publisher
+ }else if ((!$pISSN) && ($eISSN) && ($resourceType == "Journal")){
+ $query = "SELECT DISTINCT t.titleID as titleID FROM TitleIdentifier ti INNER JOIN Title t ON (ti.titleID = t.titleID) INNER JOIN MonthlyUsageSummary mus ON (mus.titleID = t.titleID) WHERE identifierType = 'eISSN' AND identifier = '" . $eISSN . "' AND publisherPlatformID = '" . $publisherPlatformID . "' AND ucase(title) = ucase('" . $resourceTitle . "') AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
+
+ //this is a title search so we're also searching on common platform / publisher (used for Databases probably primarily)
+ }else if ((!$pISSN) && (!$eISSN) && (!$pISBN) && (!$eISBN)){
+ $query = "SELECT DISTINCT t.titleID as titleID FROM Title t INNER JOIN MonthlyUsageSummary mus ON (mus.titleID = t.titleID) WHERE publisherPlatformID = '" . $publisherPlatformID . "' AND ucase(title) = ucase('" . $resourceTitle . "') AND t.resourceType = '" . $resourceType . "' LIMIT 1;";
+ }
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['titleID'])){
+ return $result['titleID'];
+ }else{
+ return false;
+ }
+
+ }
+
+
+
+
+ //remove an entire month for this title/publisher
+ public function deleteMonth($archiveInd, $year, $month, $publisherPlatformID){
+
+ //now formulate query
+ $query = "DELETE FROM MonthlyUsageSummary
+ WHERE archiveInd = '" . $archiveInd . "'
+ AND titleID = '" . $this->titleID . "'
+ AND publisherPlatformID = '" . $publisherPlatformID . "'
+ AND year = '" . $year . "'
+ AND month = '" . $month . "';";
+
+ return $this->db->processQuery($query);
+
+ }
+
+
+ //remove an entire month for this title/publisher
+ public function deleteYearlyStats($archiveInd, $year, $publisherPlatformID, $activityType){
+
+ if ($activityType){
+ $addWhere = " AND activityType='" . $activityType . "'";
+ } else {
+ $addWhere = null;
+ }
+
+ //now formulate query
+ $query = "DELETE FROM YearlyUsageSummary
+ WHERE archiveInd = '" . $archiveInd . "'
+ AND titleID = '" . $this->titleID . "'
+ AND publisherPlatformID = '" . $publisherPlatformID . "' " . $addWhere . "
+ AND year = '" . $year . "';";
+
+ return $this->db->processQuery($query);
+
+ }
+
+
+ //returns usage count only
+ public function getUsageCountByMonth($archiveInd, $year, $month, $publisherPlatformID){
+
+ $query = "SELECT usageCount FROM MonthlyUsageSummary
+ WHERE archiveInd = '" . $archiveInd . "'
+ AND titleID = '" . $this->titleID . "'
+ AND publisherPlatformID = '" . $publisherPlatformID . "'
+ AND year = '" . $year . "'
+ AND month = '" . $month . "';";
+
+
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['usageCount'])){
+ return $result['usageCount'];
+ }else{
+ return false;
+ }
+
+ }
+
+
+
+
+
+ //returns array of the first listed identifier objects
+ public function getTotalCountByYear($archiveInd, $year, $publisherPlatformID){
+
+ $query = "SELECT totalCount usageCount, ytdHTMLCount, ytdPDFCount FROM YearlyUsageSummary
+ WHERE archiveInd = '" . $archiveInd . "'
+ AND titleID = '" . $this->titleID . "'
+ AND publisherPlatformID = '" . $publisherPlatformID . "'
+ AND year = '" . $year . "';";
+
+
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['usageCount'])){
+ $resultArray['usageCount'] = $result['usageCount'];
+ $resultArray['ytdHTMLCount'] = $result['ytdHTMLCount'];
+ $resultArray['ytdPDFCount'] = $result['ytdPDFCount'];
+
+ return $resultArray;
+ }else{
+ return false;
+ }
+
+ }
+
+
+
+ //returns array of yearly stats for this title
+ public function get12MonthUsageCount($archiveInd, $publisherPlatformID, $yearAddWhere){
+
+ $query = "SELECT usageCount FROM MonthlyUsageSummary
+ WHERE archiveInd = '" . $archiveInd . "'
+ AND titleID = '" . $this->titleID . "'
+ AND publisherPlatformID = '" . $publisherPlatformID . "'
+ AND " . $yearAddWhere . ";";
+
+ $result = $this->db->processQuery($query, 'assoc');
+
+ $allArray = array();
+ $resultArray = array();
+
+ //need to do this since it could be that there's only one request and this is how the dbservice returns result
+ if (isset($result['usageCount'])){
+ foreach (array_keys($result) as $attributeName) {
+ $resultArray[$attributeName] = $result[$attributeName];
+ }
+
+ array_push($allArray, $resultArray);
+ }else{
+ if ($result){
+ foreach ($result as $row) {
+ $resultArray = array();
+ if ($resultArray){
+ foreach (array_keys($row) as $attributeName) {
+ $resultArray[$attributeName] = $row[$attributeName];
+ }
+ }
+ array_push($allArray, $resultArray);
+ }
+ }
+ }
+
+ return $allArray;
+ }
+
+
+
+
+
+
+
+
+}
+
+?>
diff --git a/admin/configuration_sample.ini b/admin/configuration_sample.ini
index 3c8c450..2ffad93 100755
--- a/admin/configuration_sample.ini
+++ b/admin/configuration_sample.ini
@@ -3,6 +3,7 @@ organizationsModule=
organizationsDatabaseName=
licensingModule=
resourcesModule=
+managementModule=
reportingModule=
authModule=
authDatabaseName=
diff --git a/ajax_forms.php b/ajax_forms.php
index 6334de4..c1a1e57 100755
--- a/ajax_forms.php
+++ b/ajax_forms.php
@@ -36,11 +36,11 @@
if (isset($_GET['logEmailAddressID']) && ($_GET['logEmailAddressID'] != '')){
$logEmailAddressID = $_GET['logEmailAddressID'];
- $addUpdate = 'Update';
+ $addUpdate = _('Update');
$logEmailAddress = new LogEmailAddress(new NamedArguments(array('primaryKey' => $_GET['logEmailAddressID'])));
}else{
$logEmailAddressID = '';
- $addUpdate = 'Add';
+ $addUpdate = _('Add');
$logEmailAddress = new LogEmailAddress();
}
@@ -52,18 +52,16 @@
- link to associated organization
+
0){
echo " ";
- echo "Login Credentials are also available for the following publishers: ";
+ echo _("Login Credentials are also available for the following publishers:") . " ";
foreach ($pubArray as $pubID => $pubName){
echo "" . $pubName . " ";
@@ -317,7 +318,7 @@
?>
-
";
@@ -619,9 +620,9 @@
if ($statArray['outlierID'] > 0){
- echo " update overrides for this year";
+ echo " " . _("update overrides for this year") . "";
}else{
- echo " (no outliers found for this year)";
+ echo " " . _("(no outliers found for this year)");
}
echo "";
@@ -634,7 +635,7 @@
}
}else{
- echo "
+
-Directions: Mark the checkboxes to add / remove specific Platforms or Publishers to the default report list. Click 'edit report display name' to change the display name in the reporting system for specific Platforms or Publishers.
+ " . _("Mark the checkboxes to add / remove specific Platforms or Publishers to the default report list.") . " " . _("Click 'edit report display name' to change the display name in the reporting system for specific Platforms or Publishers.");?>
";
-
- //get the first Identifier to use for the terms tool lookup
- $doi = $title['doi'];
- $issn = $title['issn'];
- $eissn = $title['eissn'];
-
- echo "\n
" . $doi . "
";
- echo "\n
" . $issn . "
";
- echo "\n
" . $eissn . "
";
-
-
- echo "
";
-
- #end Title loop
- }
-}else{
-
- foreach($titleArray as $title) {
-
- echo "\n
";
-
- echo "\n
" . $title['title'] . "
";
-
- //get the first Identifier to use for the terms tool lookup
- $doi = $title['doi'];
- $isbn = $title['isbn'];
- $issn = $title['issn'];
-
- echo "\n
";
+
+ //get the first Identifier to use for the terms tool lookup
+ $doi = $title['doi'];
+ $issn = $title['issn'];
+ $eissn = $title['eissn'];
+
+ echo "\n
" . $doi . "
";
+ echo "\n
" . $issn . "
";
+ echo "\n
" . $eissn . "
";
+
+
+ echo "
";
+
+ #end Title loop
+ }
+}else{
+
+ foreach($titleArray as $title) {
+
+ echo "\n
";
+
+ echo "\n
" . $title['title'] . "
";
+
+ //get the first Identifier to use for the terms tool lookup
+ $doi = $title['doi'];
+ $isbn = $title['isbn'];
+ $issn = $title['issn'];
+
+ echo "\n
" . $doi . "
";
+ echo "\n
'" . $isbn . "
";
+ echo "\n
" . $issn . "
";
+
+
+ echo "
";
+
+ #end Title loop
+ }
+
+}
+?>
+
+
+
+
diff --git a/uploadComplete.php b/uploadComplete.php
index dfeb37f..fc58b40 100755
--- a/uploadComplete.php
+++ b/uploadComplete.php
@@ -22,7 +22,7 @@
$util = new Utility();
-$pageTitle = 'Upload Process Complete';
+$pageTitle = _('Upload Process Complete');
//read layouts ini file to get the layouts to map to columns in the database
$layoutsArray = parse_ini_file("layouts.ini", true);
@@ -35,14 +35,36 @@
$overrideInd = $_POST['overrideInd'];
$layoutID = $_POST['layoutID'];
$importLogID = $_POST['importLogID'];
-$year = $_POST['checkYear'];
+$startDate = $_POST['startDate'];
+$numMonths = $_POST['numMonths'];
+$startYearArr = explode("-", $startDate);
+$startYear = $startYearArr[1];
+$startMonthArr = explode("-", $startDate);
+$startMonth = date("n",strtotime($startMonthArr[0]));
+$holdStartMonth = $startMonth;
+$endMonth = date("n",mktime(0,0,0,$startMonth+$numMonths-1));
+if($startMonth <= $endMonth) {
+ $endYear = $startYear;
+ $multYear = false;//lets us know that we don't need to account for multiple years
+}
+else {
+ $endYear = $startYear + 1;
+ $multYear = true;//lets us know that we need to account for multiple years
+ $holdEndMonth = $endMonth;
+ $endMonth = 12;
+}
+
+if ($_POST['checkYear'] == NULL)
+ $year = $startYear;
+else
+ $year = $_POST['checkYear'];
$pISSNArray = array();
$platformArray = array();
$layout = new Layout(new NamedArguments(array('primaryKey' => $_POST['layoutID'])));
-$layoutKey = $layoutsArray[ReportTypes][$layout->layoutCode];
+$layoutKey = $layoutsArray['ReportTypes'][$layout->layoutCode];
$reportTypeDisplay = $layout->name;
$resourceType = $layout->resourceType;
@@ -56,6 +78,7 @@
//if this came from sushi
if ($importLogID > 0){
$file_handle = $util->utf8_fopen_read($uploadedFile, true);
+ $headerline = stream_get_line($file_handle, 10000000, "\n");//This is just disregarded
}else{
$file_handle = $util->utf8_fopen_read($uploadedFile, false);
}
@@ -64,9 +87,9 @@
$logSummary = "\n" . $orgFileName;
$topLogOutput = "";
-$logOutput = "Process started on " . date('l jS \of F Y h:i A') . " ";
-$logOutput.= "File: " . $uploadedFile . "
";
+ loginID == "sushi"){
+ #read layouts ini file to get the available layouts
+ $layoutsArray = parse_ini_file("layouts.ini", true);
- //print out report type and year
- echo "
";
+ }else{
+ if (!$foundColumns){
+ $foundColumns = implode(", ", $lineArray);
+ }
+ }
+ }
- //as long as the flags are set to print out, and the line exists, print the line formatted in table
- //(strpos($line,"\t\t\t\t") === false)
+ //as long as the flags are set to print out, and the line exists, print the line formatted in table
+ //(strpos($line,"\t\t\t\t") === false)
//if (($startFlag == "Y") && ($formatCorrectFlag == "Y") && !(strpos($line,"\t") == "0") && (substr($line,0,5) != "Total") && (count(explode("\t",$line)) > 5)) {
- if (($formatCorrectFlag == "Y") && (substr($line,0,5) != "Total") && ($startFlag == "Y") && (strpos($line,$del) != "0" ) && (count(explode("\t",$line)) > 5)) {
- echo "
";
+ $lineArray = explode($del,$line);
- //Clean some of the data
+ foreach($lineArray as $value){
- //strip everything after (Subs from Title
- if (strpos($value,' (Subs') !== false) $value = substr($value,0,strpos($value,' (Subs'));
+ //Clean some of the data
- //remove " quotes
- $value = str_replace("\"","",$value);
+ //strip everything after (Subs from Title
+ if (strpos($value,' (Subs') !== false) $value = substr($value,0,strpos($value,' (Subs'));
- if (($value == '') || ($value == ' ')) {
- echo "
";
+ }
+ }
+ echo "";
- #check "Total for all" is in first column - set flag to start import after this
- if ((substr($line,0,5) == "Total") || ($formatCorrectFlag == "Y")){
- $startFlag = "Y";
- }
+ }
- }
- echo "
";
- fclose($file_handle);
+ #check "Total for all" is in first column - set flag to start import after this
+ if ((substr($line,0,5) == "Total") || ($formatCorrectFlag == "Y")){
+ $startFlag = "Y";
+ }
- $errrorFlag="N";
+ }
+ echo "
";
+ fclose($file_handle);
- if (($formatCorrectFlag == "N")){
- echo " Error with Format: Report format is set to " . $reportTypeDisplay . " but does not match the column names listed in layouts.ini for this format - $unmatched.
If problems persist you can copy an existing header that works into this file.";
- $errorFlag="Y";
- }
- if (!$layoutKey){
- echo " Error with Setup: This report format is not set up in layouts.ini. ";
- $errorFlag="Y";
- }
+ $errrorFlag="N";
- if (($startFlag == "N")){
- echo " Error with Format: The line preceding the first should start with 'Total'. ";
- $errorFlag="Y";
- }
+ if (($formatCorrectFlag == "N")){
+ echo " " . _("Error with Format") . ": " . _("Report format is set to ") . "" . $reportTypeDisplay . "" . _(" but does not match the column names listed in layouts.ini for this format") . " - " . $unmatched . "
" . _("If problems persist you can copy an existing header that works into this file.");
+ $errorFlag="Y";
+ }
- if ($checkYear > date('Y')){
- echo " Error with Year: Year listed in header (" . $checkYear . ") may not be ahead of current year. Please correct and submit again. ";
- $errorFlag="Y";
- }
+ if (!$layoutKey){
+ echo " "._("Error with Setup: This report format is not set up in layouts.ini.")." ";
+ $errorFlag="Y";
+ }
- if (isset($_POST['overrideInd'])){
- echo " File is flagged to override verifications of previous month data. If this is incorrect use 'Cancel' to fix. ";
- $overrideInd = 1;
- }else{
- $overrideInd = 0;
- }
+ if (($startFlag == "N")){
+ echo " "._("Error with Format: The line preceding the first should start with 'Total'.")." ";
+ $errorFlag="Y";
+ }
- if ($errorFlag != "Y"){
- echo " Report Format: " . $reportTypeDisplay . " If this is incorrect, please use 'Cancel' to go back and fix the headers of the file. ";
- }
+ if ($checkYear > date('Y')){
+ echo " " . _("Error with Year: Year listed in header") . " (" . $checkYear . ") " . _("may not be ahead of current year. Please correct and submit again.") . " ";
+ $errorFlag="Y";
+ }
-?>
+ if (isset($_POST['overrideInd'])){
+ echo " "._("File is flagged to override verifications of previous month data. If this is incorrect use 'Cancel' to fix.")." ";
+ $overrideInd = 1;
+ }else{
+ $overrideInd = 0;
+ }
-
-
\ No newline at end of file
diff --git a/user.php b/user.php
index 381285b..ba69d53 100755
--- a/user.php
+++ b/user.php
@@ -56,6 +56,7 @@
$authURL = $util->getCORALURL() . "auth/" . $addURL . htmlentities($_SERVER['REQUEST_URI']);
header('Location: ' . $authURL, true);
+ exit; //PREVENT SECURITY HOLE
}
@@ -78,8 +79,11 @@
$remoteAuth=eval("return \$$theVarStem;");
//use the split in case the remote login is supplied as an email address
- list ($loginID,$restofAddr) = explode("@", $remoteAuth);
-
+ if (strpos($remoteAuth,'@') !== false) {
+ list ($loginID,$restofAddr) = explode("@", $remoteAuth);
+ } else {
+ $loginID = $remoteAuth;
+ }
session_start();
@@ -107,6 +111,7 @@
//if the user doesn't exist in database we need to redirect them to a page to give instructions on how to be added
if ($user->privilegeID == ""){
header('Location: not_avail.php');
+ exit; //PREVENT SECURITY HOLE
}
}