From aead8a896bd5c0ac0db08a4531f1f595ff7e358f Mon Sep 17 00:00:00 2001 From: Ross Brunner Date: Thu, 31 Mar 2016 17:49:08 -0500 Subject: [PATCH] fixes usage issue 25 in original repo --- usage/admin/classes/domain/SushiService.php | 675 ++++++++++++-------- usage/uploadComplete.php | 385 +++++------ usage/uploadConfirmation.php | 411 ++++++------ 3 files changed, 831 insertions(+), 640 deletions(-) diff --git a/usage/admin/classes/domain/SushiService.php b/usage/admin/classes/domain/SushiService.php index c6e13a90d..1b1844690 100755 --- a/usage/admin/classes/domain/SushiService.php +++ b/usage/admin/classes/domain/SushiService.php @@ -73,7 +73,7 @@ public function getByDayOfMonth($serviceDayOfMonth){ } return $objects; - } + } @@ -171,7 +171,7 @@ public function allServices(){ 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"); @@ -183,9 +183,9 @@ public function runTest(){ } if ($reportLayouts == ""){ - echo _("At least one report type must be set up!"); + echo "At least one report type must be set up!"; }else{ - echo _("Connection test successful!"); + echo "Connection test successful!"; } } @@ -200,15 +200,15 @@ public function runAll($overwritePlatform = TRUE){ foreach($rlArray as $reportLayout){ $this->statusLog = array(); $this->detailLog = array(); - + $xmlFile = $this->sushiTransfer($reportLayout); - $this->parseXML($xmlFile, $reportLayout, $overwritePlatform); - + $this->parseXML($xmlFile, $reportLayout, $overwritePlatform); + $detailsForOutput = $this->statusLog; } if ($reportLayouts == ""){ - return _("No report types are set up!"); + return "No report types are set up!"; } return implode("\n", $detailsForOutput); @@ -222,14 +222,14 @@ 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" ); + $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')); + //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 + //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')); @@ -240,16 +240,16 @@ public function setDefaultImportDates(){ }else{ $this->startDate = date_format($endDate, "Y") . "-01-01"; } - + } public function setImportDates($sDate = null, $eDate = null){ - + if (!$sDate){ $this->setDefaultImportDates(); - }else{ + }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"); @@ -286,7 +286,7 @@ public function saveLogAndExit($reportLayout = NULL, $txtFile = NULL, $success = $logFileLocation = 'logs/' . $txtFile; $this->log("Log File Name: $logFileLocation"); - + if ($success){ $this->logStatus("Finished processing " . $this->getServiceProvider . ": $reportLayout."); } @@ -325,9 +325,9 @@ public function saveLogAndExit($reportLayout = NULL, $txtFile = NULL, $success = } if(!$success){ - throw new Exception(implode("\n", $this->detailLog)); + throw new Exception(implode("\n", $this->detailLog)); } - + } @@ -336,47 +336,47 @@ public function saveLogAndExit($reportLayout = NULL, $txtFile = NULL, $success = 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'))) - ) + "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); + try{ + $client = new SoapClient($wsdl, $parameters); - //returns soapfault - }catch (Exception $e){ - $error = $e->__toString(); + //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))){ + //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)); + $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); - } - } + //try connection again with 1.2 + $client = new SoapClient($wsdl, $parameters); + } + } - //throws soap fault - }catch (Exception $e){ - $error = $e->getMessage(); + //throws soap fault + }catch (Exception $e){ + $error = $e->getMessage(); - $this->logStatus("Failed to establish soap connection: " . $error); - $this->saveLogAndExit(); - } + $this->logStatus("Failed to establish soap connection: " . $error); + $this->saveLogAndExit(); + } $this->log(""); - $this->log("-- Soap Connection successfully completed --"); - $this->log(""); + $this->log("-- Soap Connection successfully completed --"); + $this->log(""); return $client; } @@ -384,8 +384,8 @@ private function soapConnection($wsdl, $parameters){ private function sushiTransfer($reportLayout){ - - + + $ppObj = $this->getPublisherOrPlatform(); $serviceProvider = str_replace('"','',$ppObj->reportDisplayName); @@ -407,116 +407,134 @@ private function sushiTransfer($reportLayout){ $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; - } - } + $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'; + 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("/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); - } + // 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); + $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); @@ -539,7 +557,7 @@ private function sushiTransfer($reportLayout){ $message = trim($reader->value); } - } + } } $reader->close(); @@ -547,21 +565,21 @@ private function sushiTransfer($reportLayout){ 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->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"); + 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; - + } @@ -591,6 +609,19 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ $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()) { @@ -599,32 +630,118 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ $name = $reader->getAttribute("Name"); $version = $reader->getAttribute("Version"); - $layoutCode = $name; + $layoutCode = $name; if (($version == "3") || ($version =="4")){ $version = "R" . $version; } if ($version != ''){ - $layoutCode .= "_" . $version; + $layoutCode .= "_" . $version; }else{ - $layoutCode .= "_R" . $this->releaseNumber; + $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']; + $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; + //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']; - } - + $layoutColumns = $layoutsArray[$layoutKey]['columns']; + + /////////////////////////////////////////////////////// + // Create header for SUSHI file + /////////////////////////////////////////////////////// + $header = $layoutColumns; + for ($i = 0; $i < sizeof($header); $i++) { + if ($header[$i] == "jan" && $startMonth == 1) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "jan" && $startMonth != 1) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "feb" && $startMonth <= 2) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "feb" && $startMonth > 2) { + + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "mar" && $startMonth <= 3) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "mar" && $startMonth > 3) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "apr" && $startMonth <= 4) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "apr" && $startMonth > 4) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "may" && $startMonth <= 5) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "may" && $startMonth > 5) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "jun" && $startMonth <= 6) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "jun" && $startMonth > 6) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "jul" && $startMonth <= 7) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "jul" && $startMonth > 7) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "aug" && $startMonth <= 8) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "aug" && $startMonth > 8) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "sep" && $startMonth <= 9) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "sep" && $startMonth > 9) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "oct" && $startMonth <= 10) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "oct" && $startMonth > 10) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "nov" && $startMonth <= 11) { + $header[$i] .= "-" . $startYear; + } + else if ($header[$i] == "nov" && $startMonth == 12) { + $header[$i] .= "-" . $endYear; + } + if ($header[$i] == "dec" && $startMonth <= 12) { + $header[$i] .= "-" . $startYear; + } + } + 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); - + } @@ -632,58 +749,58 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ 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()) { + while ($reader->read()) { - //get the element name - if ($reader->nodeType == XMLReader::ELEMENT){ - $elementName = trim($reader->localName); + //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 (($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); @@ -695,108 +812,108 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ $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; - } - - } + + 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; + $totalCountsArray[$m] = $countArray; - //now figure out the months and the ytd, etc totals - foreach ($totalCountsArray as $key => $countArray){ + //now figure out the months and the ytd, etc totals + foreach ($totalCountsArray as $key => $countArray){ - if ($key != ''){ + if ($key != ''){ - if (intval($countArray['ytd']) == "0"){ - $reportArray[$key] = intval($countArray['pdf']) + intval($countArray['html']); - }else{ - $reportArray[$key] = intval($countArray['ytd']); - } + 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) + if ($reportArray['ytdPDF']===null) $reportArray['ytdPDF'] = intval($countArray['pdf']); else $reportArray['ytdPDF'] += intval($countArray['pdf']); - if ($reportArray['ytdHTML']===null) + 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){ + //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"; + $txtOut .= implode($finalArray,"\t") . "\n"; $totalCountsArray=array(); break; - } - } - } + } + } + } - } + } - $reader->close(); + $reader->close(); - if (($layoutKey == "") || (count($layoutColumns) == '0') || ($txtOut == "")){ - if (file_exists($xmlFileName)) { + 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:"); @@ -804,7 +921,7 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ }else{ $this->log("Failed loading XML file. Please verify you have write permissions on /sushistore/ directory."); - } + } $this->saveLogAndExit($layoutCode); } @@ -829,20 +946,20 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ //for soap headers class clsWSSEAuth{ - private $username; - private $password; - function __construct($username, $password){ - $this->username=$username; - $this->password=$password; - } + private $username; + private $password; + function __construct($username, $password){ + $this->username=$username; + $this->password=$password; + } } class clsWSSEToken{ - private $usernameToken; - function __construct ($innerVal){ - $this->usernameToken = $innerVal; - } + private $usernameToken; + function __construct ($innerVal){ + $this->usernameToken = $innerVal; + } } -?> +?> \ No newline at end of file diff --git a/usage/uploadComplete.php b/usage/uploadComplete.php index 8b8cc7b97..97c56e9e8 100755 --- a/usage/uploadComplete.php +++ b/usage/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,7 +35,29 @@ $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(); @@ -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 . "

"; -$logOutput.= _("Report Format: ") . $reportTypeDisplay . "

"; +$logOutput = "Process started on " . date('l \t\h\e jS \o\f F Y \a\t h:i A') . "
"; +$logOutput.= "File: " . $uploadedFile . "

"; +$logOutput.= "Report Format: " . $reportTypeDisplay . "

"; $monthlyInsert=''; $screenOutput = ''; @@ -79,14 +102,14 @@ if ($config->settings->useOutliers == "Y"){ - $logOutput.=_("Outlier Parameters:")."
"; + $logOutput.="Outlier Parameters:
"; $outliers = new Outlier(); $outlierArray = array(); foreach($outliers->allAsArray as $outlierArray) { - $logOutput.=_("Level ") . $outlierArray['outlierLevel'] . ": " . $outlierArray['overageCount'] . _(" over plus ") . $outlierArray['overagePercent'] . "% "._("over")."
"; + $logOutput.="Level " . $outlierArray['outlierLevel'] . ": " . $outlierArray['overageCount'] . " over plus " . $outlierArray['overagePercent'] . "% over
"; $outlier[$outlierArray['outlierID']]['overageCount'] = $outlierArray['overageCount']; $outlier[$outlierArray['outlierID']]['overagePercent'] = $outlierArray['overagePercent']; @@ -106,7 +129,7 @@ $formatCorrectFlag = "Y"; $startFlag = "Y"; $logSummary .= " $reportTypeDisplay"; - $logSummary .= "\n$year for "; + $logSummary .= "\nfor "; $overrideInd="1"; } @@ -117,68 +140,63 @@ $holdPublisher = ''; $holdPublisherPlatformID = ''; $holdYear = ''; -$startMonth = ''; +if ($importLogID > 0) { + $startMonth = $startMonth; +} +else { + $startMonth = ''; +} //loop through each line of file while (!feof($file_handle)) { - //get each line out of the file handler - $line = stream_get_line($file_handle, 10000000, "\n"); - - //set delimiter - if ((!isset($del)) or (empty($del))) { - if(count(explode("\t",$line)) > 5){ - $del = "\t"; - }else if (count(explode(",",$line)) > 5){ - $del = ","; - } - - } - - //check column formats to get the year and months - if (($formatCorrectFlag == "N") && (count(explode("\t",$line)) >= count($columnsToCheck))){ - //positive unless proven negative - $formatCorrectFlag = "Y"; - $lineArray = explode("\t",$line); - - foreach ($columnsToCheck as $key => $colCheckName){ - $fileColName = strtolower(trim($lineArray[$key])); - - if (strpos($fileColName, strtolower($colCheckName)) === false){ - $formatCorrectFlag='N'; - } + //get each line out of the file handler + $line = stream_get_line($file_handle, 10000000, "\n"); + //set delimiter + if (($del) == NULL or (empty($del))) { + if(count(explode("\t",$line)) > 5){ + $del = "\t"; + }else if (count(explode(",",$line)) > 5){ + $del = ","; + } - } + } + //check column formats to get the year and months + if (($formatCorrectFlag == "N") && (count(explode("\t",$line)) >= count($columnsToCheck))){ + //positive unless proven negative + $formatCorrectFlag = "Y"; + $lineArray = explode("\t",$line); - if ($formatCorrectFlag == 'Y'){ + foreach ($columnsToCheck as $key => $colCheckName){ + $fileColName = strtolower(trim($lineArray[$key])); + if (strpos($fileColName, strtolower($colCheckName)) === false){ + $formatCorrectFlag='N'; + } + } + if ($formatCorrectFlag == 'Y'){ //at this point, $fileColName has the last column check value, Jan //determine the year - list ($checkMonth,$year) = preg_split("/[-\/.]/",$fileColName); - if ($year < 100) $year = 2000 + $year; + list ($checkMonth,$year) = preg_split("/[-\/.]/",$fileColName); + if ($year < 100) $year = 2000 + $year; $missingMonths = array(); - // determine the latest month - // since months may not all exist + // determine the latest months may not all exist $jan_i = array_search('jan',$layoutColumns); - for($i=$jan_i;$i<12+$jan_i;$i++){ $month = $i - $jan_i + 1; $monthName = date("M", mktime(0,0,0,$month,10)); if (strpos(strtolower($lineArray[$i]), strtolower($monthName)) === false){ unset($layoutColumns[$i]); } - - } - + } $layoutColumns = array_values($layoutColumns); $logSummary .= " $reportTypeDisplay"; $logSummary .= "\n$year for "; - - } - } + } + } //as long as the flags are set to print out then we can continue if (($startFlag == "Y") && ($formatCorrectFlag == "Y") && !(strpos($line,"\t") == "0") && (substr($line,0,5) != "Total") && (count(explode("\t",$line)) > 5)) { @@ -233,7 +251,6 @@ $ytdHTML = $columnValues['ytdHTML']; $ytdPDF = $columnValues['ytdPDF']; - // loop through each month to assign month array $month=array(); for($i=1;$i<=12;$i++){ @@ -241,8 +258,7 @@ if(isset($columnValues[strtolower($monthName)])){ $month[$i] = $columnValues[strtolower($monthName)]; } - } - + } ################################################################ // PLATFORM @@ -255,7 +271,7 @@ $platformName = $holdPlatform; } - if (!isset($platformID) || ($platformName != $holdPlatform)){ + if (($platformID) == NULL || ($platformName != $holdPlatform)){ //get the platformID if available $platformTestObj = new Platform(); $platformObj = new Platform(); @@ -266,7 +282,7 @@ //Find the most recent month for this year / Platform that we have statistics for if override isn't set if (($platformID) && !($startMonth)){ if ($overrideInd == 1){ - $logOutput .= _("Override indicator set - all months will be imported."); + $logOutput .= "Override indicator set - all months will be imported."; }else{ $monthArray = $platformObj->getTotalMonths($resourceType, $archiveInd, $year); $count_months = $monthArray['count_months']; @@ -275,16 +291,16 @@ if ($count_months == 12){ - $logOutput .= _("Entire year already exists for this Platform / year. No counts will be imported."); + $logOutput .= "Entire year already exists for this Platform / year. No counts will be imported."; $startMonth = 13; }else if (($min_month == 1) && ($max_month < 13)) { $startMonth=$max_month + 1; - $logOutput .= _("Month Started at: ") . $startMonth; + $logOutput .= "Month Started at: " . $startMonth; }else if ($count_months == 0){ - $logOutput .= _("No records exist for this Platform / year. Import will start with month 1."); + $logOutput .= "No records exist for this Platform / year. Import will start with month 1."; }else{ $endMonth=$min_month-1; - $logOutput .= _("Partial year records exist for this Platform / year. Import will start with month 1 and end with month"). $endMonth."."; + $logOutput .= "Partial year records exist for this Platform / year. Import will start with month 1 and end with month $endMonth."; } } @@ -292,7 +308,7 @@ } } - if (!isset($startMonth) || ($startMonth == '')){ + if (($startMonth) == NULL || ($startMonth == '')){ $startMonth = 1; } @@ -303,7 +319,10 @@ //For log output we only want to print the year once if ($year != $holdYear) { - $logOutput .= "
"._("Year: ") . $year; + $logOutput .= "
Year: " . $startYear; + if ($startYear != $endYear) { + $logOutput .= " - " . $endYear; + } } //If Platform does not already exist, insert it and get the new ID @@ -337,7 +356,7 @@ #add to output on screen - $screenOutput .= "
"._("New Platform set up: ") . $platformName . " "._("edit").""; + $screenOutput .= "
New Platform set up: " . $platformName . " edit"; } @@ -356,8 +375,8 @@ if ($publisherName == ""){ $publisherName = $holdPublisher; } - - if (!isset($publisherID) || ($publisherName != $holdPublisher)){ + + if (($publisherID) == NULL || ($publisherName != $holdPublisher)){ //get the publisher object $publisherTestObj = new Publisher(); $publisherObj = new Publisher(); @@ -419,7 +438,7 @@ #add to log output - $logOutput .= "
"._("New Publisher / Platform set up: ") . $publisherName . " / " . $platformName; + $logOutput .= "
New Publisher / Platform set up: " . $publisherName . " / " . $platformName; } @@ -652,7 +671,7 @@ if ($pubPlat != $holdPubPlat) { if (trim($pubPlat)){ - $logOutput .= "

"._("Publisher / Platform: ") . $pubPlat; + $logOutput .= "

Publisher / Platform: " . $pubPlat; } } @@ -661,10 +680,9 @@ $rownumber++; //Add Title to log output if (trim($resourceTitle)){ - $logOutput .="

"._("Title: ") . $resourceTitle; + $logOutput .="

Title: " . $resourceTitle; } - //now we can insert the actual stats for ($i=$startMonth; $i<=$endMonth; $i++){ $usageCount = ''; @@ -686,113 +704,113 @@ //if (($overrideInd == 1) || ($pISSNArray[$pISSN] == 1)) { - //this is a merged title - if (($resourceType == "Journal") && ($pISSN) && (isset($pISSNArray[$pISSN]) && $pISSNArray[$pISSN] == 1)) { - //add the other titles count in with this titles counts to merge the two together ($i = month) - $usageCount+=$titleObj->getUsageCountByMonth($archiveInd, $year, $i, $publisherPlatformID); - - //now delete the old one ($i = month) - $titleObj->deleteMonth($archiveInd, $year, $i, $publisherPlatformID); + //this is a merged title + if (($resourceType == "Journal") && ($pISSN) && (isset($pISSNArray[$pISSN]) && $pISSNArray[$pISSN] == 1)) { + //add the other titles count in with this titles counts to merge the two together ($i = month) + $usageCount+=$titleObj->getUsageCountByMonth($archiveInd, $year, $i, $publisherPlatformID); + //now delete the old one ($i = month) + $titleObj->deleteMonth($archiveInd, $year, $i, $publisherPlatformID); - //flag when inserted into db that this is a merged statistic - $mergeInd = 1; - $logOutput .= _("Duplicate record for this Print ISSN in same spreadsheet: Month: ") . $i . _(" New Count: ") . $usageCount; - } + //flag when inserted into db that this is a merged statistic + $mergeInd = 1; - #calculate Outlier - dont bother if this is a new Title - if (($newTitle == 0) && (count($outlier) > 0)){ - #figure out which months to pull - start with this month previous year - $prevYear = $year-1; - $prevMonths=''; - $currMonths=''; - $yearAddWhere=''; - $outlierID = '0'; - $outlierLevel = ''; + $logOutput .= "Duplicate record for this Print ISSN in same spreadsheet: Month: " . $i . " New Count: " . $usageCount; + } - if ($i == 1){ - $yearAddWhere = "(year = " . $prevYear . ")"; - }else{ - for ($j=$i; $j<=11; $j++){ - $prevMonths .= $j . ", "; - } - $prevMonths .= "12"; + #calculate Outlier - dont bother if this is a new Title + if (($newTitle == 0) && (count($outlier) > 0)){ + #figure out which months to pull - start with this month previous year + $prevYear = $year-1; + $prevMonths=''; + $currMonths=''; + $yearAddWhere=''; + $outlierID = '0'; + $outlierLevel = ''; + + if ($i == 1){ + $yearAddWhere = "(year = " . $prevYear . ")"; + }else{ + for ($j=$i; $j<=11; $j++){ + $prevMonths .= $j . ", "; + } + $prevMonths .= "12"; - for ($j=1; $j<$i-1; $j++){ - $currMonths .= $j . ", "; - } - $currMonths .= $j; - $yearAddWhere .= "((year = $prevYear and month in ($prevMonths)) or (year = $year and month in ($currMonths)))"; + for ($j=1; $j<$i-1; $j++){ + $currMonths .= $j . ", "; } + $currMonths .= $j; + $yearAddWhere .= "((year = $prevYear and month in ($prevMonths)) or (year = $year and month in ($currMonths)))"; + } - //get the previous 12 months data in an array - $usageCountArray = array(); - $usageCountArray = $titleObj->get12MonthUsageCount($archiveInd, $publisherPlatformID, $yearAddWhere); + //get the previous 12 months data in an array + $usageCountArray = array(); + $usageCountArray = $titleObj->get12MonthUsageCount($archiveInd, $publisherPlatformID, $yearAddWhere); - $avgCount = 0; - if (count($usageCountArray) == "12"){ + $avgCount = 0; + if (count($usageCountArray) == "12"){ - foreach ($usageCountArray as $usageCountRec) { - $avgCount += $usageCountRec['usageCount']; - } + foreach ($usageCountArray as $usageCountRec) { + $avgCount += $usageCountRec['usageCount']; + } - $avgCount = $avgCount / 12; + $avgCount = $avgCount / 12; - foreach ($outlier as $k => $outlierArray) { - if ($usageCount > ((($avgCount * ($outlierArray['overagePercent']/100)) + $outlierArray['overageCount'])) ) { - //we can overwrite previous Outlier level so that we just take the highest Outlier level - $outlierID = $k; - $outlierLevel = $outlierArray['outlierLevel']; - } + foreach ($outlier as $k => $outlierArray) { + if ($usageCount > ((($avgCount * ($outlierArray['overagePercent']/100)) + $outlierArray['overageCount'])) ) { + //we can overwrite previous Outlier level so that we just take the highest Outlier level + $outlierID = $k; + $outlierLevel = $outlierArray['outlierLevel']; } - - }else{ - $outlierID = '0'; } }else{ $outlierID = '0'; } - //if override and this is not a merged title delete original data so we don't have duplicates in system ($i = month) - if ((!isset($pISSNArray[$pISSN])) && ($overrideInd == 1)){ - $titleObj->deleteMonth($archiveInd, $year, $i, $publisherPlatformID); - } + }else{ + $outlierID = '0'; + } - $monthlyUsageSummary = new MonthlyUsageSummary(); - $monthlyUsageSummary->titleID = $titleID; - $monthlyUsageSummary->publisherPlatformID = $publisherPlatformID; - $monthlyUsageSummary->year = $year; - $monthlyUsageSummary->month = $i; - $monthlyUsageSummary->archiveInd = $archiveInd; - $monthlyUsageSummary->usageCount = $usageCount; - $monthlyUsageSummary->outlierID = $outlierID; - $monthlyUsageSummary->mergeInd = $mergeInd; - $monthlyUsageSummary->ignoreOutlierInd = '0'; - $monthlyUsageSummary->overrideUsageCount = null; - $monthlyUsageSummary->sectionType = $sectionType; - $monthlyUsageSummary->activityType = $activityType; - - try { - $monthlyUsageSummary->save(); - } catch (Exception $e) { - echo $e->getMessage(); - } + //if override and this is not a merged title delete original data so we don't have duplicates in system ($i = month) + if ((!isset($pISSNArray[$pISSN])) && ($overrideInd == 1)){ + $titleObj->deleteMonth($archiveInd, $year, $i, $publisherPlatformID); + } + $monthlyUsageSummary = new MonthlyUsageSummary(); + $monthlyUsageSummary->titleID = $titleID; + $monthlyUsageSummary->publisherPlatformID = $publisherPlatformID; + $monthlyUsageSummary->year = $year; + $monthlyUsageSummary->month = $i; + $monthlyUsageSummary->archiveInd = $archiveInd; + $monthlyUsageSummary->usageCount = $usageCount; + $monthlyUsageSummary->outlierID = $outlierID; + $monthlyUsageSummary->mergeInd = $mergeInd; + $monthlyUsageSummary->ignoreOutlierInd = '0'; + $monthlyUsageSummary->overrideUsageCount = null; + $monthlyUsageSummary->sectionType = $sectionType; + $monthlyUsageSummary->activityType = $activityType; + + try { + $monthlyUsageSummary->save(); + } catch (Exception $e) { + echo $e->getMessage(); + } - if (is_numeric($usageCount)){ - $logOutput .= _("New Usage Count Record Added: Month: ") . $i . _(" Count: ") . $usageCount; - }else{ - $logOutput .= _("Usage Count Record is not numeric for month: ") . $i . _(" Count: ") . $usageCount . _(" imported as 0."); - } + if (is_numeric($usageCount)){ + $logOutput .= "New Usage Count Record Added: Month: " . $i . " - " . $year . " Count: " . $usageCount; + }else{ + $logOutput .= "Usage Count Record is not numeric for month: " . $i . " Count: " . $usageCount . " imported as 0."; + } - $monthlyInsert=1; - if ($outlierID){ - $logOutput .= "
"._("Outlier found for this record: Level ") . $outlierLevel . ""; - } + $monthlyInsert=1; + + if ($outlierID){ + $logOutput .= "
Outlier found for this record: Level " . $outlierLevel . ""; + } //}else{ @@ -800,13 +818,24 @@ //} }else{ - $logOutput .= _("Current or future month will not be imported: ") . $i . "-" . $year . ": " . $usageCount; + $logOutput .= "Current or future month will not be imported: " . $i . "-" . $year . ": " . $usageCount; } - //end usage count is entered + //end usage count is entered + } + if ($i == 12 && $multYear) { + $year = $endYear; + $startMonth = 1; + $endMonth = $holdEndMonth; + $i = 0; } - //end month for loop + //end month for loop + } + if ($multYear) { + $year = $startYear; + $startMonth = $holdStartMonth; + $endMonth = 12; } @@ -839,7 +868,7 @@ $ytdHTML += $yearCountArray['ytdHTMLCount']; $ytdPDF += $yearCountArray['ytdPDFCount']; - $logOutput .= "
"._("YTD Already Exists for this Print ISSN, counts are added together."); + $logOutput .= "
YTD Already Exists for this Print ISSN, counts are added together."; } //delete these yearly stats since we will next overwrite them @@ -863,35 +892,35 @@ try { $yearlyUsageSummary->save(); - $logOutput .= "
"._("YTD Total Count: ") . $ytd . "
"._("YTD HTML Count: ") . $ytdHTML . "
"._("YTD PDF Count: ") . $ytdPDF; + $logOutput .= "
YTD Total Count: " . $ytd . "
YTD HTML Count: " . $ytdHTML . "
YTD PDF Count: " . $ytdPDF; } catch (Exception $e) { echo $e->getMessage(); } }else{ - $logOutput .= "
"._("No YTD import performed since monthly stats were not imported"); + $logOutput .= "
No YTD import performed since monthly stats were not imported"; } - //end ytd if statement + //end ytd if statement } # add to array so we can determine if print ISSN already exists in this spreadsheet to add counts together $pISSNArray[$pISSN] = 1; }else{ //end if for if Title match found - $topLogOutput .= ""._("Title match did not complete correctly, please check ISBN / ISSN to verify for Title: ") . $resourceTitle . ".
"; + $topLogOutput .= "Title match did not complete correctly, please check ISBN / ISSN to verify for Title: " . $resourceTitle . ".
"; } - //end start flag if + //end start flag if } - #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"; - } + #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"; + } //reset all ID variables that were just set $titleID=''; @@ -943,7 +972,7 @@ } } -$logSummary .= date("M", mktime(0,0,0,$startMonth,10)) . "-" . date("M", mktime(0,0,0,$endMonth,10)); +$logSummary .= date("F Y", mktime(0,0,0,$startMonth,10,$startYear)) . " - " . date("F Y", mktime(0,0,0,$endMonth,10,$endYear)); include 'templates/header.php'; @@ -955,7 +984,7 @@ $importLog->details = $importLog->details . "\n" . $rownumber . " titles processed." . $logSummary; }else{ - $importLog = new ImportLog(); + $importLog = new ImportLog(); $importLog->importLogID = ''; $importLog->fileName = $orgFileName; $importLog->archiveFileURL = 'archive/' . $uploadedFilename; @@ -994,22 +1023,22 @@ ?> - - + +
-
-
-

.

-

.

-

-
- " . nl2br($logSummary); ?>
-
-
-

 

+ + - -
+
Status
+
+

File archived as .

+

Log file available at: .

+

Process completed.

+
+ Summary:" . nl2br($logSummary); ?>
+
+
+

 

-
+
- + \ No newline at end of file diff --git a/usage/uploadConfirmation.php b/usage/uploadConfirmation.php index bdf320b8a..31bfc9670 100755 --- a/usage/uploadConfirmation.php +++ b/usage/uploadConfirmation.php @@ -25,15 +25,15 @@ //this file has been created from SUSHI if ($_GET['importLogID'] > 0){ $importLog = new ImportLog(new NamedArguments(array('primaryKey' => $_GET['importLogID']))); - + $layout = new Layout(); $layout->getByLayoutCode($importLog->layoutCode); $layoutID = $layout->layoutID; - $pageTitle = _('SUSHI Import Confirmation'); + $pageTitle = 'SUSHI Import Confirmation'; $target_path = $importLog->fileName; - $checkYear = date("Y"); + //$checkYear = date("Y"); //checkYear is not used for SUSHI imports anymore $formatCorrectFlag = "Y"; $errorFlag = "N"; $startFlag = "Y"; @@ -42,6 +42,51 @@ #read this file $file_handle = $util->utf8_fopen_read($target_path, true); + //takes the first line of the SUSHI import file and finds the year(s) associated + $firstLine = stream_get_line($file_handle, 10000000, "\n"); + $firstArray = explode("\t",$firstLine); + $numCol = count($firstArray); + //gets the start and ending years from the first line of the SUSHI import + $startYearArr = explode("-",$firstArray[($numCol-1)]); + $startYear = $startYearArr[1];//the month of december is always the starting year + $endYearArrHelp = explode("-",$firstLine); + $endYearArr = explode("\t",$endYearArrHelp[1]); + $endYear = $endYearArr[0];//find january's year, which is always the end year + for ($i = 0; $i < 12; $i++) { + $monthArray[$i] = $firstArray[($numCol-12+$i)]; + } + $startMonth = NULL; + //find the startMonth if only one year is present + if ($startYear == $endYear) { + $cMonth = explode("-",$monthArray[0]); + for ($i = 0; $cMonth[2] == 'x'; $i++) { + $cMonth = explode("-",$monthArray[$i]); + if ($cMonth[2] != 'x') { + $startMonth = $cMonth[0]; + } + } + $startMonth = $cMonth[0];//this will set the startMonth to January if the program never enters the for loop + } + //find the startMonth if multiple years are represented in the file + else { + $cMonth = explode("-",$monthArray[0]); + for ($i = 0; $cMonth[1] != $startYear; $i++) { + $cMonth = explode("-",$monthArray[$i]); + if($cMonth[1] == $startYear) { + $startMonth = $cMonth[0]; + } + } + } + $startDate = array($startMonth, $startYear); + $startDate = implode("-", $startDate); + $numMonths = 12; + for ($i = 11; $i >= 0; $i--) { + $cMonth = explode("-",$monthArray[$i]); + if ($cMonth[2] == 'x') + $numMonths--; + } +//came from file import + //came from file import }else{ @@ -66,28 +111,28 @@ header( 'Location: import.php?error=1' ) ; }else{ - if(move_uploaded_file($_FILES['usageFile']['tmp_name'], $target_path)) { - $uploadConfirm = _("The file "). basename( $_FILES['usageFile']['name'])._(" has been uploaded successfully.")."
"._("Please confirm the following data:")."
"; - } else{ - header( 'Location: import.php?error=2' ) ; - } + if(move_uploaded_file($_FILES['usageFile']['tmp_name'], $target_path)) { + $uploadConfirm = "The file ". basename( $_FILES['usageFile']['name'])." has been uploaded successfully.
Please confirm the following data:
"; + } else{ + header( 'Location: import.php?error=2' ) ; + } } - #file upload was OK, now we can read the file to output for confirmation - $formatCorrectFlag = "N"; - $foundColumns = ""; - $errorFlag = "N"; - $startFlag = "N"; - $unmatched = ""; - $del = ""; //delimiter - $layoutID = $_POST['layoutID']; + #file upload was OK, now we can read the file to output for confirmation + $formatCorrectFlag = "N"; + $foundColumns = ""; + $errorFlag = "N"; + $startFlag = "N"; + $unmatched = ""; + $del = ""; //delimiter + $layoutID = $_POST['layoutID']; #read this file $file_handle = $util->utf8_fopen_read($target_path, false); - $pageTitle = _('Upload Process Confirmation'); + $pageTitle = 'Upload Process Confirmation'; } @@ -97,217 +142,217 @@ -"; + if ($layoutID != ""){ + $reportTypeSet = 'Y'; + $layout = new Layout(new NamedArguments(array('primaryKey' => $layoutID))); + $layoutKey = $layoutsArray['ReportTypes'][$layout->layoutCode]; + $columnsToCheck = $layoutsArray[$layoutKey]['columnToCheck']; + $reportTypeDisplay = $layout->name; + $layoutColumns = $layoutsArray[$layoutKey]['columns']; + $numberOfColumns = count($layoutColumns); + } - #also print out column headers - echo ""; - foreach ($layoutColumns as $value){ - echo ""; - } - echo ""; + if ((isset($uploadConfirm)) and (!empty($uploadConfirm))) { + echo $uploadConfirm; + } + echo "
-
-
- - -
+
+
- #read layouts ini file to get the available layouts - $layoutsArray = parse_ini_file("layouts.ini", true); - if ($layoutID != ""){ - $reportTypeSet = 'Y'; - $layout = new Layout(new NamedArguments(array('primaryKey' => $layoutID))); - $layoutKey = $layoutsArray['ReportTypes'][$layout->layoutCode]; - $columnsToCheck = $layoutsArray[$layoutKey]['columnToCheck']; - $reportTypeDisplay = $layout->name; - $layoutColumns = $layoutsArray[$layoutKey]['columns']; - $numberOfColumns = count($layoutColumns); - } + "; - //print out headers automaticall if this was from sushi - if ($importLog->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 "
" . $reportTypeDisplay . _(" for ") . $checkYear . "
" . strtoupper($value) . "
"; + + //print out headers automaticall if this was from sushi + if ($importLog->loginID == "sushi"){ + //print out report type and year + echo ""; + #also print out column headers + echo ""; + foreach ($layoutColumns as $value){ + echo ""; + } + echo ""; + } - } + while (!feof($file_handle)) { + //get each line out of the file handler + $line = stream_get_line($file_handle, 10000000, "\n"); - while (!feof($file_handle)) { - //get each line out of the file handler - $line = stream_get_line($file_handle, 10000000, "\n"); + //if report type hasn't been figured out, check for it in the first row / column + if ($reportTypeSet == ""){ - //if report type hasn't been figured out, check for it in the first row / column - if ($reportTypeSet == ""){ + foreach ($layoutsArray['ReportTypes'] as $reportTypeKey => $layoutKey){ + list($report,$release) = explode("_",$reportTypeKey); + if ((strpos($line, $report) !== false) && (strpos($line, $release) !== false)){ + $reportTypeSet = 'Y'; + $columnsToCheck = $layoutsArray[$layoutKey]['columnToCheck']; + $reportTypeDisplay = $line; + $layout = $layoutKey; + } + } - foreach ($layoutsArray['ReportTypes'] as $reportTypeKey => $layoutKey){ - list($report,$release) = explode("_",$reportTypeKey); - if ((strpos($line, $report) !== false) && (strpos($line, $release) !== false)){ - $reportTypeSet = 'Y'; - $columnsToCheck = $layoutsArray[$layoutKey]['columnToCheck']; - $reportTypeDisplay = $line; - $layout = $layoutKey; - } - } + } - } + //set delimiter + $del = "\t"; - //set delimiter - $del = "\t"; + //check column formats if the format correct flag has not been set yet + if (($formatCorrectFlag == "N") && (count(explode($del,$line)) >= count($columnsToCheck)) && (strlen($line) > 20)){ + //positive unless proven negative + $formatCorrectFlag = "Y"; + $lineArray = explode("\t",$line); - //check column formats if the format correct flag has not been set yet - if (($formatCorrectFlag == "N") && (count(explode($del,$line)) >= count($columnsToCheck)) && (strlen($line) > 20)){ - //positive unless proven negative - $formatCorrectFlag = "Y"; - $lineArray = explode("\t",$line); + if (($columnsToCheck) && (count($lineArray) >=5)){ + foreach ($columnsToCheck as $key => $colCheckName){ + $fileColName = strtolower(trim($lineArray[$key])); - if (($columnsToCheck) && (count($lineArray) >=5)){ - foreach ($columnsToCheck as $key => $colCheckName){ - $fileColName = strtolower(trim($lineArray[$key])); + if (strpos($fileColName, strtolower($colCheckName)) === false){ + if (!$unmatched){ + $unmatched = "Looking for \"$colCheckName\" in column $key but found \"$fileColName\""; + } + $formatCorrectFlag='N'; + } - if (strpos($fileColName, strtolower($colCheckName)) === false){ - if (!$unmatched){ - $unmatched = _("Looking for")." '$colCheckName' "._("in column ").$key._(" but found")." '$fileColName'"; + } } - $formatCorrectFlag='N'; - } - - } - } - if ($formatCorrectFlag == 'Y'){ - $numberOfColumns = count($lineArray); - - if ($checkYear == ""){ - list ($checkMonth,$checkYear) = preg_split("/[-\/.]/",$fileColName); - if ($checkYear < 100) $checkYear = 2000 + $checkYear; - } - - //print out report type and year - echo ""; - - #also print out column headers - echo ""; - foreach ($lineArray as $value){ - echo ""; - } - echo ""; - }else{ - if (!$foundColumns){ - $foundColumns = implode(", ", $lineArray); - } - } - } + if ($formatCorrectFlag == 'Y'){ + $numberOfColumns = count($lineArray); + + if ($checkYear == ""){ + list ($checkMonth,$checkYear) = preg_split("/[-\/.]/",$fileColName); + if ($checkYear < 100) $checkYear = 2000 + $checkYear; + } + + //print out report type and year + echo ""; + + #also print out column headers + echo ""; + foreach ($lineArray as $value){ + echo ""; + } + 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); - - foreach($lineArray as $value){ + 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 ""; - }else{ - echo ""; - } - } - echo ""; + //remove " quotes + $value = str_replace("\"","",$value); - } + if (($value == '') || ($value == ' ')) { + echo ""; + }else{ + 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"; - } + #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 "
" . $reportTypeDisplay . " for " . date("F", strtotime($startMonth)) . " " . $startYear; + echo " - " . date("F", mktime(0,0,0,date("n",strtotime($startMonth))+$numMonths-1)) . " " . $endYear . "
" . strtoupper($value) . "
" . $reportTypeDisplay . _(" for ") . $checkYear . "
" . $value . "
" . $reportTypeDisplay . " for " . $checkYear . "
" . $value . "
 " . $value . "
 " . $value . "
"; - fclose($file_handle); + } + echo ""; + fclose($file_handle); - $errrorFlag="N"; - 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.

"._("Expecting columns: ") . implode(", ", $columnsToCheck) . "

"._("Found columns: ") . $foundColumns . "


"._("If problems persist you can copy an existing header that works into this file."); - $errorFlag="Y"; - } + $errrorFlag="N"; - if (!$layoutKey){ - echo "
"._("Error with Setup: This report format is not set up in layouts.ini.")."
"; - $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.

Expecting columns: " . implode(", ", $columnsToCheck) . "

Found columns: " . $foundColumns . "


If problems persist you can copy an existing header that works into this file."; + $errorFlag="Y"; + } - if (($startFlag == "N")){ - echo "
"._("Error with Format: The line preceding the first should start with 'Total'.")."
"; - $errorFlag="Y"; - } + if (!$layoutKey){ + echo "
Error with Setup: This report format is not set up in layouts.ini.
"; + $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 (($startFlag == "N")){ + echo "
Error with Format: The line preceding the first should start with 'Total'.
"; + $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 ($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 ($errorFlag != "Y"){ - echo "
"._("Report Format:")." " . $reportTypeDisplay . "
"._("If this is incorrect, please use 'Cancel' to go back and fix the headers of the file.")."
"; - } + 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 ($errorFlag != "Y"){ + echo "
Report Format: " . $reportTypeDisplay . "
If this is incorrect, please use 'Cancel' to go back and fix the headers of the file.
"; + } -
-
- - - - - - - - - - - -
- onclick="javascript:updateSubmit();" /> - - -
+ ?> + +
+ + + + + + + + + + + + + + +
+ onclick="javascript:updateSubmit();" /> + + +
\ No newline at end of file