From 5f5810928472591e424a8c416245bbd34dfd6ffa Mon Sep 17 00:00:00 2001 From: Ross Brunner Date: Mon, 11 Apr 2016 16:08:59 -0500 Subject: [PATCH 1/3] fixes issue 25, at the request of Jeff Mudge, for version 1.X --- admin/classes/domain/SushiService.php | 669 +++++++++++++++----------- uploadComplete.php | 351 ++++++++------ uploadConfirmation.php | 411 +++++++++------- 3 files changed, 816 insertions(+), 615 deletions(-) diff --git a/admin/classes/domain/SushiService.php b/admin/classes/domain/SushiService.php index 2425da4..1b18446 100755 --- a/admin/classes/domain/SushiService.php +++ b/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"); @@ -200,10 +200,10 @@ 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; } @@ -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/uploadComplete.php b/uploadComplete.php index 3fbef21..0a04409 100755 --- a/uploadComplete.php +++ b/uploadComplete.php @@ -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,7 +87,7 @@ $logSummary = "\n" . $orgFileName; $topLogOutput = ""; -$logOutput = "Process started on " . date('l jS \of F Y h:i A') . "
"; +$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=''; @@ -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 (($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); - - 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 @@ -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 @@ -356,7 +375,7 @@ if ($publisherName == ""){ $publisherName = $holdPublisher; } - + if (($publisherID) == NULL || ($publisherName != $holdPublisher)){ //get the publisher object $publisherTestObj = new Publisher(); @@ -389,7 +408,7 @@ // Query to see if the Publisher / Platform already exists, if so, get the ID ################################################################# //check it against the previous row - no need to do another lookup if we've already figured out the publisherplatformID - if (!isset($publisherPlatformID) || ($publisherName != $holdPublisher) || ($platformName != $holdPlatform)){ + if (($publisherPlatformID) == NULL || ($publisherName != $holdPublisher) || ($platformName != $holdPlatform)){ //get the publisher platform object $publisherPlatformTestObj = new PublisherPlatform(); $publisherPlatformObj = $publisherPlatformTestObj->getPublisherPlatform($publisherID, $platformID); @@ -664,7 +683,6 @@ $logOutput .="

Title: " . $resourceTitle; } - //now we can insert the actual stats for ($i=$startMonth; $i<=$endMonth; $i++){ $usageCount = ''; @@ -686,113 +704,121 @@ //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); + //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); + //now delete the old one ($i = month) + $titleObj->deleteMonth($archiveInd, $year, $i, $publisherPlatformID); + $logOutput .= "Merged"; + //flag when inserted into db that this is a merged statistic + $mergeInd = 1; - //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; - } - - #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 ((!$mergeInd) && ($overrideInd == 1)){ + if ($multYear && $i >= $startMonth) { + $titleObj->deleteMonth($archiveInd, $startYear, $i, $publisherPlatformID); } + else if ($multYear && $i < $startMonth && $i <= $endMonth) { + $titleObj->deleteMonth($archiveInd, $endYear, $i, $publisherPlatformID); + } + else { + $titleObj->deleteMonth($archiveInd, $startYear, $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{ @@ -803,10 +829,21 @@ $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; } @@ -873,7 +910,7 @@ $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 @@ -884,14 +921,14 @@ } - //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 +980,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,$holdEndMonth,10,$endYear)); include 'templates/header.php'; @@ -955,7 +992,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 +1031,22 @@ ?> - - + +
-
Status
-
-

File archived as .

-

Log file available at: .

-

Process completed.

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

 

+ + - -
+
Status
+
+

File archived as .

+

Log file available at: .

+

Process completed.

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

 

-
+
- + \ No newline at end of file diff --git a/uploadConfirmation.php b/uploadConfirmation.php index b071e96..aeeb4d6 100755 --- a/uploadConfirmation.php +++ b/uploadConfirmation.php @@ -25,7 +25,7 @@ //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; @@ -33,7 +33,7 @@ $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,22 +111,22 @@ 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); @@ -97,217 +142,219 @@ -
-
-
- +
+
+
- $layoutID))); - $layoutKey = $layoutsArray['ReportTypes'][$layout->layoutCode]; - $columnsToCheck = $layoutsArray[$layoutKey]['columnToCheck']; - $reportTypeDisplay = $layout->name; - $layoutColumns = $layoutsArray[$layoutKey]['columns']; - $numberOfColumns = count($layoutColumns); - } - - if ((isset($uploadConfirm)) and (!empty($uploadConfirm))) { - echo $uploadConfirm; - } - echo ""; - //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 ""; + 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 "
" . $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); + 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){ + foreach($lineArray as $value){ - //Clean some of the data + //Clean some of the data - //strip everything after (Subs from Title - if (strpos($value,' (Subs') !== false) $value = substr($value,0,strpos($value,' (Subs')); + //strip everything after (Subs from Title + if (strpos($value,' (Subs') !== false) $value = substr($value,0,strpos($value,' (Subs')); - //remove " quotes - $value = str_replace("\"","",$value); - - 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"; - } + } - } - 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); + #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.

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

Found columns: " . $foundColumns . "


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.

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

Found columns: " . $foundColumns . "


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; + } -
-
- - - - - - - - - - - -
- onclick="javascript:updateSubmit();" /> - - -
+ 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 ($importLog->importLogID > 0) { + echo "
File has been imported from SUSHI. The default behavior for imported SUSHI files is to overwrite previously imported data. If this is incorrect, please contact a system administrator.
"; + } + ?> + +
+ + + + + + + + + + + + + + +
+ onclick="javascript:updateSubmit();" /> + + +
\ No newline at end of file From 57e1499b9320394b4971233c027148ac37ff074f Mon Sep 17 00:00:00 2001 From: Ross Brunner Date: Tue, 12 Apr 2016 15:46:29 -0500 Subject: [PATCH 2/3] simplifies logic when generating the SUSHI header in SuhsiService.php --- admin/classes/domain/SushiService.php | 79 ++++----------------------- 1 file changed, 10 insertions(+), 69 deletions(-) diff --git a/admin/classes/domain/SushiService.php b/admin/classes/domain/SushiService.php index 1b18446..915618c 100755 --- a/admin/classes/domain/SushiService.php +++ b/admin/classes/domain/SushiService.php @@ -657,76 +657,17 @@ private function parseXML($fName, $reportLayout, $overwritePlatform){ // 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++) { - 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; + 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--) { From 19e29dbe3bce1356b0ffb3880099cd05789b85a5 Mon Sep 17 00:00:00 2001 From: Ross Brunner Date: Wed, 20 Apr 2016 16:32:24 -0500 Subject: [PATCH 3/3] re-adds _() for translation and fixes an error with the logged date when importing from a single year. --- admin/classes/domain/SushiService.php | 8 ++-- uploadComplete.php | 69 ++++++++++++++------------- uploadConfirmation.php | 34 ++++++------- 3 files changed, 57 insertions(+), 54 deletions(-) diff --git a/admin/classes/domain/SushiService.php b/admin/classes/domain/SushiService.php index 915618c..de49189 100755 --- a/admin/classes/domain/SushiService.php +++ b/admin/classes/domain/SushiService.php @@ -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!"); } } @@ -208,7 +208,7 @@ public function runAll($overwritePlatform = TRUE){ } if ($reportLayouts == ""){ - return "No report types are set up!"; + return _("No report types are set up!"); } return implode("\n", $detailsForOutput); @@ -903,4 +903,4 @@ function __construct ($innerVal){ -?> \ No newline at end of file +?> diff --git a/uploadComplete.php b/uploadComplete.php index 0a04409..77c5038 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); @@ -87,9 +87,9 @@ $logSummary = "\n" . $orgFileName; $topLogOutput = ""; -$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 . "

"; +$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 = ''; @@ -102,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']; @@ -282,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']; @@ -291,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 . "."; } } @@ -319,7 +319,7 @@ //For log output we only want to print the year once if ($year != $holdYear) { - $logOutput .= "
Year: " . $startYear; + $logOutput .= _("
Year: ") . $startYear; if ($startYear != $endYear) { $logOutput .= " - " . $endYear; } @@ -356,7 +356,7 @@ #add to output on screen - $screenOutput .= "
New Platform set up: " . $platformName . " edit"; + $screenOutput .= "
"._("New Platform set up: ") . $platformName . " "._("edit").""; } @@ -438,7 +438,7 @@ #add to log output - $logOutput .= "
New Publisher / Platform set up: " . $publisherName . " / " . $platformName; + $logOutput .= "
"._("New Publisher / Platform set up: ") . $publisherName . " / " . $platformName; } @@ -671,7 +671,7 @@ if ($pubPlat != $holdPubPlat) { if (trim($pubPlat)){ - $logOutput .= "

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

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

Title: " . $resourceTitle; + $logOutput .="

"._("Title: ") . $resourceTitle; } //now we can insert the actual stats @@ -716,7 +716,7 @@ //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; + $logOutput .= _("Duplicate record for this Print ISSN in same spreadsheet: Month: ") . $i . _(" New Count: ") . $usageCount; } #calculate Outlier - dont bother if this is a new Title @@ -808,16 +808,16 @@ if (is_numeric($usageCount)){ - $logOutput .= "New Usage Count Record Added: Month: " . $i . " - " . $year . " Count: " . $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."; + $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 . ""; + $logOutput .= "
"._("Outlier found for this record: Level ") . $outlierLevel . ""; } @@ -826,7 +826,7 @@ //} }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 @@ -876,7 +876,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 @@ -900,14 +900,14 @@ 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 @@ -979,9 +979,12 @@ $mailOutput = "Email to " . implode(", ", $emailAddresses) . " Failed!"; } } - -$logSummary .= date("F Y", mktime(0,0,0,$startMonth,10,$startYear)) . " - " . date("F Y", mktime(0,0,0,$holdEndMonth,10,$endYear)); - +if ($multYear) { + $logSummary .= date("F Y", mktime(0,0,0,$startMonth,10,$startYear)) . " - " . date("F Y", mktime(0,0,0,$holdEndMonth,10,$endYear)); +} +else { + $logSummary .= date("F Y", mktime(0,0,0,$startMonth,10,$startYear)) . " - " . date("F Y", mktime(0,0,0,$endMonth,10,$startYear)); +} include 'templates/header.php'; //Log import in database @@ -1033,13 +1036,13 @@
-
Status
+

-

File archived as .

-

Log file available at: .

-

Process completed.

+

.

+

.

+


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


 

@@ -1049,4 +1052,4 @@
- \ No newline at end of file + diff --git a/uploadConfirmation.php b/uploadConfirmation.php index aeeb4d6..77f8a17 100755 --- a/uploadConfirmation.php +++ b/uploadConfirmation.php @@ -30,7 +30,7 @@ $layout->getByLayoutCode($importLog->layoutCode); $layoutID = $layout->layoutID; - $pageTitle = 'SUSHI Import Confirmation'; + $pageTitle = _('SUSHI Import Confirmation'); $target_path = $importLog->fileName; //$checkYear = date("Y"); //checkYear is not used for SUSHI imports anymore @@ -112,7 +112,7 @@ }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:
"; + $uploadConfirm = _("The file "). basename( $_FILES['usageFile']['name'])._(" has been uploaded successfully.")."
"._("Please confirm the following data:")."
"; } else{ header( 'Location: import.php?error=2' ) ; } @@ -132,7 +132,7 @@ $file_handle = $util->utf8_fopen_read($target_path, false); - $pageTitle = 'Upload Process Confirmation'; + $pageTitle = _('Upload Process Confirmation'); } @@ -144,7 +144,7 @@ function updateSubmit(){ document.confirmForm.submitForm.disabled=true; - document.confirmForm.submitForm.value="Processing Contents..."; + document.confirmForm.submitForm.value=_("Processing Contents..."); document.confirmForm.submit(); } @@ -182,7 +182,7 @@ function updateSubmit(){ //print out headers automaticall if this was from sushi if ($importLog->loginID == "sushi"){ //print out report type and year - echo "" . $reportTypeDisplay . " for " . date("F", strtotime($startMonth)) . " " . $startYear; + echo "" . $reportTypeDisplay . _(" for ") . date("F", strtotime($startMonth)) . " " . $startYear; echo " - " . date("F", mktime(0,0,0,date("n",strtotime($startMonth))+$numMonths-1)) . " " . $endYear . ""; #also print out column headers echo ""; @@ -229,7 +229,7 @@ function updateSubmit(){ if (strpos($fileColName, strtolower($colCheckName)) === false){ if (!$unmatched){ - $unmatched = "Looking for \"$colCheckName\" in column $key but found \"$fileColName\""; + $unmatched = _("Looking for")." '$colCheckName' "._("in column ").$key._(" but found ")."'$fileColName'"; } $formatCorrectFlag='N'; } @@ -246,7 +246,7 @@ function updateSubmit(){ } //print out report type and year - echo "" . $reportTypeDisplay . " for " . $checkYear . ""; + echo "" . $reportTypeDisplay . _(" for ") . $checkYear . ""; #also print out column headers echo ""; @@ -304,37 +304,37 @@ function updateSubmit(){ $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."; + 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 (!$layoutKey){ - echo "
Error with Setup: This report format is not set up in layouts.ini.
"; + echo "
"._("Error with Setup: This report format is not set up in layouts.ini.")."
"; $errorFlag="Y"; } if (($startFlag == "N")){ - echo "
Error with Format: The line preceding the first should start with 'Total'.
"; + echo "
"._("Error with Format: The line preceding the first should start with 'Total'.")."
"; $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.
"; + 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.
"; + 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.
"; + echo "
"._("Report Format").": " . $reportTypeDisplay . "
"._("If this is incorrect, please use 'Cancel' to go back and fix the headers of the file.")."
"; } if ($importLog->importLogID > 0) { - echo "
File has been imported from SUSHI. The default behavior for imported SUSHI files is to overwrite previously imported data. If this is incorrect, please contact a system administrator.
"; + echo "
"._("File has been imported from SUSHI. The default behavior for imported SUSHI files is to overwrite previously imported data. If this is incorrect, please contact a system administrator.")."
"; } ?> @@ -351,10 +351,10 @@ function updateSubmit(){ -
- onclick="javascript:updateSubmit();" /> + onclick="javascript:updateSubmit();" /> - +
\ No newline at end of file +