function cleanPost($str) { if (isNullOrEmptyString($str)) { echo 'Error: String is empty'; return " "; //exit(); } //$str=strip_tags($str); $str = utf8_bad_strip_improved($str); $str = strtolower($str); //$str = remove_emoji($str); //Any 4 digits together) $re = "/\\d\\d\\d\\d/"; $subst = ""; $str = preg_replace($re, $subst, $str); //Remove area codes and highways // $re = "/\\d\\d\\d/"; // $subst = ""; // $str = preg_replace($re, $subst, $str); $str = replaceTo($str); $str = removeContractions($str); $str = removePunct($str); $str = removeSlang($str); $str = removeCityAppreviations($str); $str = removeAirportAbbreviations($str); $str = removeUniversityAbbreviations($str); $str = removeHighways($str); $str = removeDollars($str); return $str; }
function test_writePostion() { appendTestMessage(NEW_LINE_LOG . " >> Tests writing of single position..." . NEW_LINE_LOG); appendTestMessage("Prepare: Create new user"); $ret = checkUser("dUser", "dPassword"); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check parameter lat"); $ret = writePostion('', '', '', '', '', '', '', '', '', ''); if (!$ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check parameter lon"); $ret = writePostion('', '', '47.50457163540115', '', '', '', '', '', '', ''); if (!$ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Prepare: Create new user"); $ret = checkUser("dUser", "dPassword"); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 1) for user (no positions yet)"); $ret = getLastPostionsAndTracksIndividually(''); if (isNullOrEmptyString($ret)) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 2) for user (no positions yet)"); $ret = getLastPostionsAndTracksIndividually('dUser'); if (isNullOrEmptyString($ret)) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 3) for user (no positions yet)"); $ret = getLastPostionsAndTracksIndividually('dUser=2013-03-03 15:48:47.484', 'true'); if (isNullOrEmptyString($ret)) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Test helper function to write the postion.csv > new"); $ret = writePositionFile('dUser', 'test;test;test'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $testDateTime = getDateForTimezoneOffset('dUser', '', false); appendTestMessage("Write single position"); $csvLine = 'lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDateTime; $ret = writePositionFile('dUser', $csvLine); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write lat and lon"); $ret = writePostion('dUser', '', '42.50457163540115', '11.071390274487026', '', '', '', '', '2012-03-03T15:48:47.484', 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 1) for user (one position yet) no track for today"); $ret = getLastPostionsAndTracksIndividually('dUser'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=42.50457163540115;lon=11.071390274487026;time=2012-03-03T15:48:47.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 2) for user (one position yet) - track excluded because of time"); $ret = getLastPostionsAndTracksIndividually('dUser=2012-03-03T15:48:47.4841'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;lat=42.50457163540115;lon=11.071390274487026;time=2012-03-03T15:48:47.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $testDate = getDateForTimezoneOffset('dUser', '', true); appendTestMessage("Write lat and lon"); $ret = writePostion('dUser', '', '42.50457163540115', '11.071390274487026', '', '', '', '', $testDate . 'T15:48:47.484', 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $today = getDateForTimezoneOffset('dUser', '', true); $gpxFileName = $today . '.csv'; appendTestMessage("Check for a data file (gpx) for this user"); $ret = getUsersForDataFileName('dUser', $gpxFileName); if ($ret == 'dUser') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Check for a data file (gpx) for this user. But exclude the user"); $ret = getUsersForDataFileName('dUser', $gpxFileName, 'dUser'); if ($ret == '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position"); $csvLine0 = 'lat=42.50457163540115;lon=11.071390274487026;time=' . $testDate . 'T15:48:47.484'; $ret = getPosition('dUser'); if ($ret === $csvLine0) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position (parameter = getGroupPostions"); $ret = getGroupPostions('dUser'); $expectedLine = 'user=dUser;' . $csvLine0; if ($ret === $expectedLine) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write lat and lon"); $ret = writePostion('dUser', 'cGroup_changed', '43.50457163540115', '11.071390274487026', '171.61432', '0.7065948', '1067.652498529502', '6.0', $testDate . 'T15:48:48.484', 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for user (omit tracks)"); $ret = getLastPostionsAndTracksIndividually('dUser', 'false'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for user (omit tracks)"); $ret = getLastPostionsAndTracksIndividually('dUser', 'no'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for user (two positions yet no last time given)"); $ret = getLastPostionsAndTracksIndividually('dUser', 'true'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484' . PHP_EOL . '[track-dUser]' . PHP_EOL . 'lat=42.50457163540115;lon=11.071390274487026;time=' . $testDate . 'T15:48:47.484' . PHP_EOL . 'lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position"); $csvLine1 = 'lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; $ret = getPosition('dUser'); if ($ret === $csvLine1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write empty multiline positions"); $ret = writePostions('dUser', 'cGroup_changed', '', 'true'); if (!$ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write multiline positions"); $csvLine2 = 'lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:41.484'; $csvLine3 = 'lat=45.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:42.484'; $csvLine4 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:43.484'; $csvLines2_4 = $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; $csvLines0_4 = $csvLine0 . PHP_EOL . $csvLine1 . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; $ret = writePostions('dUser', 'cGroup_changed', $csvLines2_4, 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position set by multiline writing"); $ret = getPosition('dUser'); if ($ret === $csvLine4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individally for user (five positions yet, last time given)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("List tracks"); $ret = listTracks('dUser'); $expectedFileName = '2012-03-03.gpx'; if ($ret == $expectedFileName) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("List tracks"); $ret = listTracksCSV('dUser'); $expectedFileNames1 = $testDate . '.csv' . PHP_EOL . '2012-03-03.csv'; $expectedFileNames2 = '2012-03-03.csv' . PHP_EOL . $testDate . '.csv'; if ($ret === $expectedFileNames1 || $ret === $expectedFileNames2) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get track check empty parameter date"); $ret = getTrack('dUser', '', ''); if ($ret === $csvLines0_4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get track"); $ret = getTrack('dUser', $today, ''); if ($ret === $csvLines0_4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // Review: This test seems to be double, see test somewhere above appendTestMessage("Get track after a certain line number only"); $ret = getTrack('dUser', $today, $testDate . 'T15:48:48.484'); if ($ret === $csvLines2_4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get track after a certain line number (at end already)"); $ret = getTrack('dUser', $today, $testDate . 'T15:54:43.484'); if ($ret === '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get postions of group"); $ret = getPositions('cGroup_changed'); $expectedString = 'user=dUser;' . $csvLine4; if ($ret === $expectedString) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Get postions of group. But exclude the user dUser"); $ret = getPositions('cGroup_changed', dUser); if ($ret === '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // Add second user with same group appendTestMessage("Prepare: Create new user"); $ret = checkUser("eUser", "ePassword"); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check for a data file (gpx) for this user. A second user is in the group but without this file."); $ret = getUsersForDataFileName('dUser', $gpxFileName); if ($ret == 'dUser') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Check for a data file (gpx) for this user. AND exclude the user. A second user is in the group but without this file."); $ret = getUsersForDataFileName('dUser', $gpxFileName, 'dUser'); if ($ret == '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Prepare: Write position new second user with same group"); $csvLine5 = 'lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:43.484'; $ret = writePostions('eUser', 'cGroup_changed', $csvLine5, 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check for a data file (gpx) for this user. A second user is in the group now."); $ret = getUsersForDataFileName('dUser', $gpxFileName); $expectedUsers = 'dUser' . PHP_EOL . 'eUser'; $expectedUsers1 = 'eUser' . PHP_EOL . 'dUser'; if ($ret == $expectedUsers || $ret == $expectedUsers1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Check for a data file (gpx) for this user. But exclude the user. A second user is in the group now."); $ret = getUsersForDataFileName('dUser', $gpxFileName, 'dUser'); $expectedUsers = 'eUser'; if ($ret == $expectedUsers) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get postions of the two members of the group"); $ret = getPositions('cGroup_changed'); $expectedPostions = 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5; $expectedPostions1 = 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4; if ($ret === $expectedPostions || $ret === $expectedPostions1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Get postions of the two members of the group. Exclude user eUser"); $ret = getPositions('cGroup_changed', 'eUser'); $expectedPostions = 'user=dUser;' . $csvLine4; if ($ret === $expectedPostions) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last time given - 1)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 2)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 3)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484;eUser='******'T15:54:42.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 4)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484;eUser='******'T15:54:43.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 5)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:54:43.484' . ';eUser='******'T15:54:43.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get postions of the two members of the group (param = getGroupPostions"); $ret = getGroupPostions('dUser'); if ($ret === $expectedPostions || $ret === $expectedPostions1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Util: write some csv files to create gpx (later)"); if (test_writeGpxFromCsv()) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Create gpx from csv and list. Check eUser"); $ret = listTracks('eUser'); $expected1 = "2013-03-10.gpx" . PHP_EOL . "2013-03-11.gpx"; $expected2 = "2013-03-11.gpx" . PHP_EOL . "2013-03-10.gpx"; if ($ret == $expected1 || $ret == $expected2) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Create gpx from csv and list. Check dUser"); $ret = listTracks('dUser'); $expected1 = "2013-03-10.gpx" . PHP_EOL . "2012-03-03.gpx"; $expected2 = "2012-03-03.gpx" . PHP_EOL . "2013-03-10.gpx"; if ($ret == $expected1 || $ret == $expected2) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write multiline positions with different dates"); $csvLine6 = 'lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2012-04-03T15:54:41.484'; $csvLine7 = 'lat=45.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:44.484'; $csvLine8 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:45.484'; $csvLines6_8 = $csvLine6 . PHP_EOL . $csvLine7 . PHP_EOL . $csvLine8; $csvLines0_8_dUser = $csvLine0 . PHP_EOL . $csvLine1 . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . $csvLine7 . PHP_EOL . $csvLine8; $ret = writePostions('dUser', 'cGroup_changed', $csvLines6_8, 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users all lines"); $ret = getLastPostionsAndTracksIndividually('dUser;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users all lines"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:54:44.484;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine8 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine8; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("List tracks"); $ret = listTracksCSV('dUser'); $expectedFileNames1 = $testDate . '.csv' . PHP_EOL . '2012-03-03.csv' . PHP_EOL . '2012-04-03.csv' . PHP_EOL . '2013-03-10.csv'; $searchString = '/' . $testDate . '.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $searchString = '/2012-03-03.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $searchString = '/2012-04-03.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $searchString = '/2013-03-10.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write multiline positions with different dates and track not stored"); $csvLine6 = 'lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2012-04-03T15:54:41.484'; $csvLine7 = 'lat=45.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:44.484'; $csvLine8 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:45.484'; $csvLine9 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:46.484'; $csvLines6_9 = $csvLine6 . PHP_EOL . $csvLine7 . PHP_EOL . $csvLine8 . PHP_EOL . $csvLine9; $ret = writePostions('dUser', 'cGroup_changed', $csvLines6_9, 'false'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users all lines"); $ret = getLastPostionsAndTracksIndividually('dUser;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine9 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine9 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } return true; }
function UpdateEmployee($fields) { $statusMessage = ""; //------------------------------------------------------------------------- // Validate Input parameters //------------------------------------------------------------------------- $inputIsValid = TRUE; $validID = false; $countOfFields = 0; foreach ($fields as $key => $value) { if ($key == EMP_ID) { $record = RetrieveEmployeeByID($value); if ($record != NULL) { $validID = true; $countOfFields++; } } else { if ($key == EMP_NAME) { $countOfFields++; if (isNullOrEmptyString($value)) { $statusMessage .= "Employee name can not be blank.</br>"; error_log("Invalid EMP_NAME passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_EMAIL) { $countOfFields++; if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $statusMessage .= "Email address is not in a valid format.</br>"; error_log("Invalid email address passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_PASSWORD) { //No validation on password, since this is an MD5 encoded string. $countOfFields++; } else { if ($key == EMP_DATEJOINED) { $countOfFields++; if (!isValidDate($value)) { $statusMessage .= "Date Joined value is not a valid date</br>"; error_log("Invalid EMP_DATEJOINED passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_LEAVE_ENTITLEMENT) { $countOfFields++; if (!is_numeric($value)) { $statusMessage .= "Employee Leave Entitlement must be a numeric value.</br>"; error_log("Invalid EMP_LEAVE_ENTITLEMENT passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_MAIN_VACATION_REQ_ID) { if ($value != NULL) { $record = RetrieveMainVacationRequestByID($value); if ($record == NULL) { $statusMessage .= "Main Vacation Request ID not found in database.</br>"; error_log("Invalid EMP_MAIN_VACATION_REQ_ID passed to UpdateEmployee."); $inputIsValid = FALSE; } } } else { if ($key == EMP_COMPANY_ROLE) { $countOfFields++; $record = RetrieveCompanyRoleByID($value); if ($record == NULL) { $statusMessage .= "Company Role ID not found in database.</br>"; error_log("Invalid EMP_COMPANY_ROLE passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_ADMIN_PERM) { $countOfFields++; } else { if ($key == EMP_MANAGER_PERM) { $countOfFields++; } else { $statusMessage .= "Unrecognised field of {$key} encountered.</br>"; error_log("Invalid field passed to UpdateEmployee. {$key}=" . $key); $inputIsValid = FALSE; } } } } } } } } } } } if (!$validID) { $statusMessage .= "No valid ID supplied.</br>"; error_log("No valid ID supplied in call to UpdateEmployee."); $inputIsValid = FALSE; } if ($countOfFields < 2) { $statusMessage .= "Insufficent fields supplied.</br>"; error_log("Insufficent fields supplied in call to UpdateEmployee."); $inputIsValid = FALSE; } //------------------------------------------------------------------------- // Only attempt to update a record in the database if the input parameters // are ok. //------------------------------------------------------------------------- $success = false; if ($inputIsValid) { $success = performSQLUpdate(EMPLOYEE_TABLE, EMP_ID, $fields); if ($success) { $statusMessage .= "Record has been successfully updated."; } else { $inputIsValid = false; $statusMessage .= "Unexpected Database error encountered. Please " . "contact your system administrator."; } } GenerateStatus($inputIsValid, $statusMessage); return $success; }
function UpdateCompanyRole($fields) { //------------------------------------------------------------------------- // Validate Input parameters //------------------------------------------------------------------------- $statusMessage = ""; $inputIsValid = TRUE; $validID = false; $countOfFields = 0; foreach ($fields as $key => $value) { if ($key == COMP_ROLE_ID) { $record = RetrieveCompanyRoleByID($value); if ($record != NULL) { $validID = true; $countOfFields++; } else { $statusMessage .= "Unable to locate Company Role in the database."; error_log("No valid ID supplied in call to UpdateCompanyRole."); $inputIsValid = FALSE; } } else { if ($key == COMP_ROLE_NAME) { $countOfFields++; if (isNullOrEmptyString($value)) { $statusMessage .= "You must enter a company role name."; error_log("Invalid COMP_ROLE_NAME passed to UpdateCompanyRole."); $inputIsValid = FALSE; } } else { if ($key == COMP_ROLE_MIN_STAFF) { $countOfFields++; if (!is_numeric($value)) { $statusMessage .= "You must enter a numeric value for minimum staff"; error_log("Invalid COMP_ROLE_MIN_STAFF passed to UpdateCompanyRole."); $inputIsValid = FALSE; } } else { $statusMessage .= "Invalid field."; error_log("Invalid field passed to UpdateCompanyRole. {$key}=" . $key); $inputIsValid = FALSE; } } } } if ($countOfFields < 2) { $statusMessage .= "You must alter at least one field before updating."; error_log("Insufficent fields supplied in call to UpdateCompanyRole."); $inputIsValid = FALSE; } //------------------------------------------------------------------------- // Only attempt to update a record in the database if the input parameters // are ok. //------------------------------------------------------------------------- $success = false; if ($inputIsValid) { $success = performSQLUpdate(COMPANY_ROLE_TABLE, COMP_ROLE_ID, $fields); $statusMessage .= "Record has been updated successfully."; } GenerateStatus($inputIsValid, $statusMessage); return $success; }
function UpdatePublicHoliday($fields) { $statusMessage = ""; //------------------------------------------------------------------------- // Validate Input parameters //------------------------------------------------------------------------- $inputIsValid = TRUE; $validID = false; $countOfFields = 0; $oldDateRecord = NULL; foreach ($fields as $key => $value) { if ($key == PUB_HOL_ID) { $record = RetrievePublicHolidayByID($value); if ($record != NULL) { $validID = true; $countOfFields++; $oldDateRecord = RetrieveDateByID($record[PUB_HOL_DATE_ID]); } } else { if ($key == PUB_HOL_NAME) { $countOfFields++; if (isNullOrEmptyString($value)) { $statusMessage .= "Public holiday name must be entered.</br>"; error_log("Invalid PUB_HOL_NAME passed to UpdatePublicHoliday."); $inputIsValid = FALSE; } } else { if ($key == PUB_HOL_DATE_ID) { $countOfFields++; $record = RetrieveDateByID($value); if ($record == NULL) { $statusMessage .= "Unable to located date in database.</br>"; error_log("Invalid PUB_HOL_DATE_ID passed to UpdatePublicHoliday."); $inputIsValid = FALSE; } } else { $statusMessage .= "Unexpected field encountered in input.</br>"; error_log("Invalid field passed to UpdatePublicHoliday."); $inputIsValid = FALSE; } } } } if (!$validID) { $statusMessage .= "No valid ID supplied in call to UpdatePublicHoliday.</br>"; error_log("No valid ID supplied in call to UpdatePublicHoliday."); $inputIsValid = FALSE; } if ($countOfFields < 2) { $statusMessage .= "Insufficent fields supplied in call to UpdatePublicHoliday.</br>"; error_log("Insufficent fields supplied in call to UpdatePublicHoliday."); $inputIsValid = FALSE; } //-------------------------------------------------------------------------- // Only attempt to update a record in the database if the input parameters // are ok. //-------------------------------------------------------------------------- $success = false; if ($inputIsValid) { $success = performSQLUpdate(PUBLIC_HOLIDAY_TABLE, PUB_HOL_ID, $fields); if ($success) { $oldDateRecord[DATE_TABLE_PUBLIC_HOL_ID] = NULL; $success = UpdateDate($oldDateRecord); $dateRecord = RetrieveDateByID($fields[PUB_HOL_DATE_ID]); //------------------------------------------------------------- // Update the date records public holiday ID field. //------------------------------------------------------------- $dateRecord[DATE_TABLE_PUBLIC_HOL_ID] = $fields[PUB_HOL_ID]; $success = UpdateDate($dateRecord); $statusMessage .= "Record successfully updated.</br>"; } else { $statusMessage .= "Unexpected error when updating the database.</br>"; $inputIsValid = false; } } GenerateStatus($inputIsValid, $statusMessage); return $success; }
$startDate = $monthStartDate; } $monthEndDate = date('Y-m-t', $planDate); if (date('w', strtotime($monthEndDate)) != 6) { $endDate = date('Y-m-d', strtotime('next saturday, 12am', strtotime($monthEndDate))); } else { $endDate = $monthEndDate; } $dates = createDateRangeArray($startDate, $endDate); $meals = DB::table('meal_calendar')->leftJoin('Recipe', 'meal_calendar.recipe_id', '=', 'Recipe.RecipeId')->whereBetween('meal_date', array($startDate, $endDate))->get(); $plans = array(); foreach ($dates as $date) { $plans[$date] = array(); foreach ($meals as $meal) { if (strtotime($meal->meal_date) == strtotime($date)) { if (isNullOrEmptyString($meal->note)) { $plans[$date][$meal->id] = "Recipe-" . $meal->RecipeName; } else { $plans[$date][$meal->id] = "Note-" . $meal->note; } } } } $recipes = Recipe::orderBy('RecipeName')->lists('RecipeName', 'RecipeId'); $lastMonth = date('Y-m-d', strtotime('-1 month', $planDate)); $nextMonth = date('Y-m-d', strtotime('+1 month', $planDate)); return View::make('recipe.plan')->with('plans', $plans)->with('recipes', $recipes)->with('currentMonth', date('F Y', $planDate))->with('monthStartDate', $monthStartDate)->with('monthEndDate', $monthEndDate)->with('lastMonth', $lastMonth)->with('nextMonth', $nextMonth); })); Route::get('recipe/', array('before' => 'auth', 'as' => 'recipe.index', function () { $searchText = ''; if (Input::has('q')) {
while ($row = mysqli_fetch_array($result)) { $clients[] = $row; } } } mysqli_free_result($result); } } databaseConnectionClose($con); ?> <!-- add existing job rows --> <select name='dropdown-client' id="dropdown-client-select"> <?php foreach ($clients as $client) { if (!isNullOrEmptyString($client['clt_client_code'])) { ?> <option value='<?php echo $client['clt_client_code']; ?> ' <?php if ($client['clt_client_code'] == $_SESSION['clt_code']) { echo 'selected'; } ?> > <?php echo $client['clt_client_name']; ?> </option>
function parseRecipe($html, $url) { $parsedRecipe = RecipeParser::parse($html, $url); $recipe = new Recipe(); $recipe->RecipeName = $parsedRecipe->title; $recipe->ServingCount = getNumberFromString($parsedRecipe->yield); $recipe->PrepTimeMinute = $parsedRecipe->time['prep']; $recipe->CookTimeMinute = $parsedRecipe->time['cook']; $recipe->RecipeNote = $parsedRecipe->url; $directions = ''; foreach ($parsedRecipe->instructions[0]['list'] as $key => $n) { if ($directions != '') { $directions .= "\n\n"; } $directions .= $parsedRecipe->instructions[0]['list'][$key]; } $recipe->Directions = $directions; $recipe->save(); foreach ($parsedRecipe->ingredients[0]['list'] as $key => $n) { $ingredient = new RecipeIngredient(); $ingredient->RecipeId = $recipe->RecipeId; $origText = $parsedRecipe->ingredients[0]['list'][$key]; try { $text = trim($origText); preg_match('~[a-z]~i', $text, $match, PREG_OFFSET_CAPTURE); $count = substr($text, 0, $match[0][1]); $countEncode = urlencode($count); $countEncode = str_replace("%C2%BC", " 1/4", $countEncode); $countEncode = str_replace("%C2%BD", " 1/2", $countEncode); $countEncode = str_replace("%C2%BE", " 3/4", $countEncode); $count = urldecode($countEncode); $count = str_replace("-", " ", $count); $count = fractionToDecimal($count); $text = trim(substr($text, $match[0][1])); $size = getItemSize(substr($text, 0, strpos($text, " "))); if (!isNullOrEmptyString($size)) { $text = trim(substr($text, strpos($text, " "))); } $ingredient->ItemCount = $count; $ingredient->ItemSize = $size; $ingredient->RecipeIngredientName = $text; //$ingredient->RecipeIngredientNote = $origText; } catch (Exception $e) { $ingredient->RecipeIngredientName = $origText; $ingredient->RecipeIngredientNote = $e->getMessage(); } // save the Tag on the Post $recipe->ingredients()->save($ingredient); } if (!isNullOrEmptyString($parsedRecipe->photo_url)) { saveImage($recipe, $parsedRecipe->photo_url); } return $recipe; }
function UpdateAbsenceType($fields) { $statusMessage = ""; //------------------------------------------------------------------------- // Validate Input parameters //------------------------------------------------------------------------- $inputIsValid = TRUE; $validID = false; $countOfFields = 0; foreach ($fields as $key => $value) { if ($key == ABS_TYPE_ID) { $record = RetrieveAbsenceTypeByID($value); if ($record != NULL) { $validID = true; $countOfFields++; } } else { if ($key == ABS_TYPE_NAME) { $countOfFields++; if (isNullOrEmptyString($value)) { $statusMessage .= "Invalid absence type name. Can not be empty.</br>"; error_log("Invalid ABS_TYPE_NAME passed to UpdateAbsenceType."); $inputIsValid = FALSE; } } else { if ($key == ABS_TYPE_USES_LEAVE) { $countOfFields++; if ($value != 0 and $value != 1) { $statusMessage .= "Invalid uses annual leave flag value.</br>"; error_log("Invalid ABS_TYPE_USES_LEAVE passed to UpdateAbsenceType."); $inputIsValid = FALSE; } } else { if ($key == ABS_TYPE_CAN_BE_DENIED) { $countOfFields++; if ($value != 0 and $value != 1) { $statusMessage .= "Invalid can be denied flag value.</br>"; error_log("Invalid ABS_TYPE_CAN_BE_DENIED passed to UpdateAbsenceType."); $inputIsValid = FALSE; } } else { $statusMessage .= "Invalid field encountered.</br>"; error_log("Invalid field passed to UpdateAbsenceType. {$key}=" . $key); $inputIsValid = FALSE; } } } } } if (!$validID) { $statusMessage .= "No valid ID supplied.</br>"; error_log("No valid ID supplied in call to UpdateAbsenceType."); $inputIsValid = FALSE; } if ($countOfFields < 2) { $statusMessage .= "Insufficent fields supplied in call.</br>"; error_log("Insufficent fields supplied in call to UpdateAbsenceType."); $inputIsValid = FALSE; } //-------------------------------------------------------------------------------- // Only attempt to update a record in the database if the input parameters are ok. //-------------------------------------------------------------------------------- $success = false; if ($inputIsValid) { $success = performSQLUpdate(ABSENCE_TYPE_TABLE, ABS_TYPE_ID, $fields); if ($success) { $statusMessage .= "Record successfully created in Database.</br>"; } else { $statusMessage .= "Unexpected database error encountered when " . "trying to perform update.</br>"; $inputIsValid = false; } } GenerateStatus($inputIsValid, $statusMessage); return $success; }
function getDateForTimezoneOffset($user, $formatedTime, $returnDateOnly) { date_default_timezone_set('UTC'); $formatedTimeGuessed = ''; $format = 'Y-m-d\\TH:i:s'; if (isNullOrEmptyString($formatedTime)) { $formatedTimeGuessed = date($format); } else { $searchStringSeconds = '/^(\\d{10,10}).*$/'; $searchStringReadable = '/(\\d\\d\\d\\d)(.*?)(\\d\\d)(.*?)(\\d\\d)(.*?)(\\d\\d)(.*?)(\\d\\d)(.*?)(\\d\\d)(.*?)/'; if (preg_match($searchStringReadable, $formatedTime, $matches)) { $formatedTimeGuessed = $matches[1] . '-' . $matches[3] . '-' . $matches[5] . 'T' . $matches[7] . ':' . $matches[9] . ':' . $matches[11]; } else { if (preg_match($searchStringSeconds, $formatedTime, $matches)) { $formatedTimeGuessed = date($format, $matches[1]); } else { return ''; } } } //$date = DateTime::createFromFormat($format, '2009-02-15 15:16:17'); $date = DateTime::createFromFormat($format, $formatedTimeGuessed); // Get the timezone offset from configuration $minutes = getConfiguration($user, CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true); if (!is_numeric($minutes)) { $minutes = ''; } if ($minutes != '') { $int = (int) $minutes; if ($int < 0) { // This is Berlin for example: -120 in the summer // -120 minutes was produced by the browser as timezone offset and sent to the server $min = (string) ($int * -1); $date->add(new DateInterval('PT' . $min . 'M')); } else { $min = (string) $int; $date->sub(new DateInterval('PT' . $min . 'M')); } } if ($returnDateOnly) { return $date->format("Y-m-d"); } else { return $date->format("Y-m-d\\TH:i:s"); } }
if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_array($result)) { $jobs[] = $row; } } } mysqli_free_result($result); } } databaseConnectionClose($con); ?> <!-- add existing job rows --> <?php foreach ($jobs as $job) { if (!isNullOrEmptyString($job['jfl_key'])) { ?> <div class="feature"> <input type="hidden" name="job-remove[]" id="job-remove-<?php echo $job['jfl_key']; ?> " value=""> <button class="button-link remove" type="button" value="<?php echo $job['jfl_key']; ?> "><i class="fa fa-times"></i></button> <p class="title"><i class="fa fa-briefcase"></i><strong>‘<?php echo $job['jfl_name']; ?> ’ job status: </strong><?php echo $job['jfl_status'];
function getParam_locally($paramName) { $paramValue = $_GET[$paramName]; if (isNullOrEmptyString($paramValue)) { $paramValue = $_POST[$paramName]; } return $paramValue; }