This repository contains the source code for the CoastCowConsumer Data Repository. Created by @thecodingaviator and @gordoncd.
We use state-of-the-art equipment and high-throughput protocols in our research. In the Bigelow Laboratory Analytical Facilities, we’ve developed in vitro batch assays that mimic a rumen for rapid comparisons of algal candidates and use mass spectrometry to look for promising compounds. Members of our team at the University of Vermont conduct further testing in continuous fermenters to understand how algae-based additives impact the dynamic rumen microbiome, which is responsible for the methane production. The best algal candidates, some of which come from Bigelow Laboratory’s National Center for Marine Microbiota and Algae collection, are being developed as additives to be used in holistic animal feeding trials with dairy cows at partnering research farms at University of New Hampshire, Wolfe’s Neck Center for Agriculture and the Environment, and William H. Miner Agricultural Research Institute. These studies explore the supplements’ nutritional value and subsequent effects on methane burps, milk quality, and milk yields of individual cows, as well as the implications to manure and soil health for grazing and conventional herds.
We are also conducting economic analyses with partners at Colby College, Syracuse University, and University of Vermont to explore pragmatic entry points into the supply chain and cost-benefits of using seaweed feed supplements for organic and conventional dairy in New England. In parallel, Clarkson University is using life cycle assessments to evaluate the cradle-to-grave impact on greenhouse gas emissions of the most promising seaweed additive candidates, including impacts to manure quality and utility in anaerobic digestion or as fertilizer – to ensure the final products represent a net greenhouse gas reduction and true seafood-based solution.
The Coast to Cow to Consumer Project is Funded By:
The CoastCowConsumer Data Repository is a web application designed to provide users with various features and functionality. It allows users to perform tasks such as data exploration, dataset submission, account registration, password reset, and more.
confirmation.php
confirmation.php
is responsible for displaying a confirmation page on the Coast to Cow Consumer Data Repository website. It provides feedback to the user based on certain conditions and includes HTML rendering and PHP logic.
The main features of the confirmation.php
file are as follows:
$_SESSION['email_sent']
variable. If the variable is set to true
, a notification is displayed on the confirmation page. The $_SESSION['email_sent']
variable is then unset to prevent multiple notifications.$_SESSION['update']
variable. If debugging messages are present, they are shown with a heading. If no debugging messages are found, a message indicating their absence is displayed.Developers working on the confirmation.php
file should consider the following:
dashboard.php
dashboard.php
represents the dashboard page of the Coast to Cow Consumer Data Repository website. It provides an interface for logged-in users to access various features and functionalities.
The file structure follows the standard PHP file format, starting with the <?php
opening tag. It includes a combination of PHP statements and HTML markup, with PHP code enclosed within <?php
and ?>
tags.
The main functionalities of the dashboard.php
file include:
session_status()
. If not, it starts a new session using session_start()
.$_SESSION['logged_in']
variable. If not, the user is redirected to the login page using the header()
function.$_SESSION['email_sent']
variable is set to true
, a notification is displayed on the dashboard indicating that an email containing the user's UserID has been sent. The session variable is then unset to avoid displaying the notification multiple times.navbar.php
) and a content area with various buttons for different functionalities.Important considerations for future developers working on the dashboard page:
utils/config.php
at the beginning, indicating the presence of a configuration file. Review the configuration file to ensure sensitive information like database connection details is properly protected.dashboard-common.css
, dashboard.css
) for styling. Modify these files to customize the appearance of the dashboard page if needed.navbar.php
) that may contain links to other pages or functionality. Review and modify the navigation bar as necessary to reflect the structure of the website.download.php
download.php
is responsible for downloading files from Google Drive using a service account defined in the credentials.php
file. This file should not be modified unless you understand its intricacies.
Here's an overview of the download.php
file:
GET
request and the name
parameter is set, the file ID is extracted from the request. The file metadata, including the name and MIME type, is fetched using the Google Drive API.Important notes:
utils/c3-testing-389115-f39fd8b05d5d.json
file exists and contains the correct credentials for the Google Drive service account.vendor/autoload.php
path to include the required libraries properly.explore_dash.php
explore_dash.php
represents the explore page of the Coast to Cow Consumer Data Repository website. It allows users to explore and visualize data from the MySQL database.
The file structure follows the standard PHP file format, starting with the <?php
opening tag. It includes a combination of PHP statements and HTML markup, with PHP code enclosed within <?php
and ?>
tags.
The main functionalities of the explore_dash.php
file include:
C3AnalysisTMR
table, and groups the data by components.navbar.php
) and a content area with buttons for exploring different datasets and a chart to display the average AsFed and DM values by component type.Important considerations for future developers working on the explore page:
utils/config.php
at the beginning, indicating the presence of a configuration file. Review the configuration file to ensure sensitive information like database connection details is properly protected.dashboard-common.css
, explore_dash.css
) for styling. Modify these files to customize the appearance of the explore page if needed.navbar.php
) that may contain links to other pages or functionality. Review and modify the navigation bar as necessary to reflect the structure of the website.explore.js
explore.js
provides JavaScript functionality for the explore page (explore_DO.php
) of the Coast to Cow Consumer Data Repository website. It handles data retrieval, display, and downloading using the ag-Grid library.
Here's an overview of the explore.js
file:
Error Handling: The file defines variables to display error messages in the errorDiv
and errorMessage
elements.
Search Form Submission: The file adds an event listener to the search form (#searchForm
) to handle form submissions. It retrieves the selected search table value and sends a GET request to the /utils/getTableData.php
endpoint with the search table as a parameter.
Handling Server Response: The file processes the server response in the xhr.onload
callback function. It checks the response status, parses the JSON data, and displays the number of results found in the resultsContainer
element.
Modifying Data for Display: The file modifies the retrieved data if it contains specific properties (free_download
and file_id
). It converts the unique_name
property into a link if free_download
is set to 1 and removes the free_download
and file_id
properties from each row.
Generating Column Names and Configuring ag-Grid: The file generates column names for the ag-Grid based on the retrieved data. It checks the column's data type and enables numeric column filtering if applicable. If the column name is unique_name
, a custom cell renderer is assigned to render the link for downloadable files.
Creating and Updating ag-Grid: The file creates and updates the ag-Grid using the generated column names and data. It sets pagination, auto-sizing columns, and defines default column settings.
Handling Error Conditions: The file handles error conditions in the xhr.onerror
callback function and displays the appropriate error message.
Downloading Data as CSV: The file adds an event listener to the download button (#download-csv
) to trigger the download of the ag-Grid data as a CSV file. It checks if data is populated, creates a download link, and triggers the download.
Modal Handling: The file adds event listeners to the confirm and cancel buttons of the download modal (downloadModal
). It confirms the download by converting the ag-Grid data to CSV and triggers the download. It also cancels the download by hiding the modal.
Important considerations for future developers working on the explore.js
file:
Customize error handling to suit your requirements and provide meaningful error messages to users.
Modify the form submission handler to handle additional search parameters or modify the search functionality.
Customize the data modification and column generation logic based on the structure and requirements of your data.
Customize ag-Grid configuration and functionality to match the desired display and interaction requirements.
Modify the download functionality to handle different file formats or additional data processing requirements.
explore_DO.php
explore_DO.php
is used for exploring data related to the Dairy One trials on the Coast to Cow Consumer Data Repository website. It provides a user interface to search and view data stored in the database.
Here's an overview of the explore_DO.php
file:
PHP Inclusion: The file includes the utils/config.php
file to access any necessary configurations or dependencies.
HTML Structure: The file defines the structure of the explore page using HTML markup. It includes a title, CSS stylesheets, and JavaScript libraries.
Modal Dialog: The file includes a modal dialog element (downloadModal
) that displays a data disclaimer message. Users are required to confirm their agreement before downloading data.
Navigation Bar: The file includes the navbar.php
file, which typically contains a navigation bar with links to different sections of the website.
Content Display: The main content section includes a search form and a results container. Users can select a search table, submit the form, and view the results in an ag-Grid-based table (my-grid
). The table is initially hidden (style="display: none;"
) and will be populated dynamically.
JavaScript: The file includes the utils/js/explore.js
JavaScript file, which likely contains functionality for handling search submissions, displaying search results, and handling interactions with the ag-Grid table.
Important considerations for future developers working on the explore_DO.php
file:
Ensure that the utils/config.php
file is properly configured and contains necessary database connection details.
Review and modify the search form (searchForm
) as needed to match the desired search functionality and available search tables.
Customize the downloadModal
content and functionality to reflect the specific data usage policies and requirements of the Dairy One trials.
Modify the explore.js
file (utils/js/explore.js
) to enhance or modify the functionality of the explore page, such as handling search requests and interacting with the ag-Grid table.
explore_RD.php
explore_RD.php
serves the same function as explore_DO.php
but is designed for exploring all other submitted data, not just Dairy One trials, on the Coast to Cow Consumer Data Repository website.
Here's an overview of the explore_RD.php
file:
PHP Inclusion: The file includes the utils/config.php
file to access any necessary configurations or dependencies.
HTML Structure: The file defines the structure of the explore page using HTML markup. It includes a title, CSS stylesheets, and JavaScript libraries.
Modal Dialog: The file includes a modal dialog element (downloadModal
) that displays a data disclaimer message. Users are required to confirm their agreement before downloading data.
Navigation Bar: The file includes the navbar.php
file, which typically contains a navigation bar with links to different sections of the website.
Content Display: The main content section includes a search form and a results container. Users can select a search table, submit the form, and view the results in an ag-Grid-based table (my-grid
). The table is initially hidden (style="display: none;"
) and will be populated dynamically.
JavaScript: The file includes the utils/js/explore.js
JavaScript file, which likely contains functionality for handling search submissions, displaying search results, and handling interactions with the ag-Grid table.
Important considerations for future developers working on the explore_RD.php
file:
Ensure that the utils/config.php
file is properly configured and contains necessary database connection details.
Review and modify the search form (searchForm
) as needed to match the desired search functionality and available search tables. In this case, the options include "DataMasterTest" and "AnalysisGrain".
Customize the downloadModal
content and functionality to reflect the specific data usage policies and requirements for exploring other submitted data.
Modify the explore.js
file (utils/js/explore.js
) to enhance or modify the functionality of the explore page, such as handling search requests and interacting with the ag-Grid table.
download.php
download.php
handles the download of files from Google Drive using a service account defined in credentials.php
. It is responsible for retrieving file metadata, setting appropriate headers for the file download, and downloading the file content.
The file structure follows the standard PHP file format, starting with the <?php
opening tag. It includes the necessary dependencies, such as the Google API client library, and includes the utils/config.php
file.
The main functionalities of the download.php
file include:
credentials.php
.name
parameter is provided, the file is fetched from Google Drive using the specified file ID. The file metadata is retrieved, appropriate headers are set for the file download, and the file content is downloaded and outputted to the browser.Important considerations for future developers working on the download functionality:
download.php
file expects the file ID to be provided through the name
parameter in the GET request. Modify the code as necessary to match the file ID parameter name used in the website's URL structure.utils/c3-testing-389115-f39fd8b05d5d.json
) using putenv()
. Ensure that the path to the credentials file is correct and matches the actual location of the file.index.php
index.php
serves as the homepage for the Coast to Cow Consumer Data Repository website. It handles user authentication and login functionality, allowing users to sign in to access their data.
The file structure follows the standard PHP file format, starting with the <?php
opening tag. It includes a combination of PHP statements and HTML markup, with PHP code enclosed within <?php
and ?>
tags.
The main functionalities of the index.php
file include:
session_start()
and checks if the user is already logged in. If so, they are redirected to the dashboard page using the header()
function.$_POST
superglobal. The password is hashed using SHA-256 for secure storage and comparison. The file then performs a database query to validate the credentials against the stored password in the C3UserNameAndPassword
table. If the credentials match, the user is authenticated, and their user ID is stored in the session. They are then redirected to the dashboard page using the header()
function. If the credentials do not match, an error message is assigned to the $error
variable, which is displayed on the login page.Important considerations for future developers working on the login page:
utils/config.php
at the beginning, indicating the presence of a configuration file. Review the configuration file to ensure sensitive information like database connection details is properly protected.normalize.css
, universal.css
, index.css
) for styling and includes a JavaScript function (submitForm()
) for form submission. Inspect and modify these files if necessary.C3UserNameAndPassword
table in the database to validate user credentials. Verify the database connection configuration and the table structure.mail.php
mail.php
handles sending emails using PHPMailer and SMTP.
It includes the database config file utils/config.php
and starts the session.
The main features are:
sendMail
function
Uses SMTP with Gmail
Error handling
The file depends on:
utils/config.php
Considerations:
Overall, mail.php
provides a simple API to send transactional emails from PHP applications. Further improvements can be made to handle edge cases, retries, HTML formatting, etc.
modify.php
modify.php
is responsible for handling the editing of user profiles. It allows users to update their profile information, including email, phone number, job title, institution, and password. The file also handles the verification of the current password before allowing changes to be made.
The file structure follows the standard PHP file format, starting with the <?php
opening tag. It includes the necessary dependencies, such as the utils/config.php
file, and starts the session.
The main functionalities of the modify.php
file include:
submit
button), the user input values are retrieved from the $_POST
superglobal and assigned to respective variables.C3SignUp
table. If a new password is provided, it is also updated in the C3UserNameAndPassword
table.Important considerations for future developers working on the profile editing functionality:
navbar.php
navbar.php
is responsible for rendering the navigation bar at the top of the web application. It includes links to different pages and provides user-related options, such as accessing the user's profile and logging out.
The file starts with the <?php
opening tag and includes the necessary dependencies, such as the utils/config.php
file. It also starts the session.
The main functionalities of the navbar.php
file include:
logged_in
. If the user is not logged in, they are redirected to the login page (index.php
).C3SignUp
table based on the user's ID stored in the session variable user_id
. The retrieved information is used to display the user's name in the navigation bar.Important considerations for future developers working on the navigation bar:
navbar.css
file to match the desired appearance of the navigation bar.record_dash.php
record_dash.php
is a dashboard page for recording data. It allows users to select what kind of data they will submit and then redirects users to the appropriate submission page.
record_DO.php
record_DO.php
is the dedicated page for user submission of DairyOne data. This is separate because metadata extraction has been automated elsewhere in the workflow, and allows a more simple upload process compared to the research data workflow.
The file has functionality as follows:
User session management:
File upload form:
Error handling:
Page layout:
The record_DO.php
file relies on:
utils/config.php
- Database configurationutils/css/record_DO.css
- Stylesheet utils/js/submit.js
- File upload handlingnavbar.php
- Navigation bar includeOverall, record_DO.php
provides the frontend and infrastructure to allow file uploads. The backend accesses the database through the called handleFileUpload() function in submit.js which relies on upload.php.
record_RD.php
record_RD.php
allows users to submit research dataset metadata and upload files.
It includes the database config file utils/config.php
and initializes the user session.
The main features are:
Get user details from database like email, name
Metadata submission form
C3DataMasterTest
tableFile upload
Error handling for form submission
Page layout and styles
The file relies on:
utils/config.php
- Database credentialsutils/css/record_RD.css
- Stylesheetutils/js/submit.js
- File upload handlingnavbar.php
- Navigation menu Considerations:
Overall, record_RD.php
provides the ability to collect metadata and files for research datasets. Further work needed to integrate file processing and access control for sharing the datasets/versioning.
resetpassword.php
resetpassword.php
handles the logic for resetting a user's password. It provides a form where users can enter their user ID and email to initiate the password reset process.
The file starts with the <?php
opening tag and includes the necessary dependencies, such as the utils/config.php
file. It also starts the session.
The main functionalities of the resetpassword.php
file include:
dashboard.php
).generateTemporaryPassword
function generates a random temporary password consisting of alphanumeric characters. The length of the temporary password is set to 8 characters but can be modified as needed.mail
function is used to send an email with the temporary password to the user's email address. The email includes a subject, message body, and headers.Important considerations for future developers working on the password reset functionality:
From
address in the email headers to match the desired sender email address.resetpassword.css
file to match the desired appearance of the password reset form.seaweed.php
Under construction, will incorporate a new seaweed id so a user can track the flow of a seaweed sample within the C3 project.
signup.php
signup.php
handles the logic for user registration. It provides a form where users can enter their information to create a new account.
The file starts with the <?php
opening tag and includes the necessary dependencies, such as the utils/config.php
file. It also starts the session.
The main functionalities of the signup.php
file include:
dashboard.php
).C3SignUp
table, and the user ID, password, and email are inserted into the C3UserNameAndPassword
table. The user ID is generated based on the user's last name and email.mail
function is used to send the email. The success or failure of sending the email is stored in a session variable.Important considerations for future developers working on the registration functionality:
From
address in the email headers to match the desired sender email address.signup.css
file to match the desired appearance of the registration form.submit.php
submit.php
handles the submission of a dataset by the user. It provides a form where users can enter metadata related to the dataset they want to submit.
The file starts with the <?php
opening tag and includes the necessary dependencies, such as the utils/config.php
file. It also starts the session.
The main functionalities of the submit.php
file include:
index.php
).Important considerations for future developers working on the dataset submission functionality:
submit.css
file to match the desired appearance of the submission form.templates.php
templates.php
displays a list of templates available for download. It includes HTML markup to create a page layout with a header, content section, and a card container to display the templates.
The file starts with the <?php
opening tag and includes the necessary dependencies, such as the utils/config.php
file.
The main functionalities of the templates.php
file include:
Important considerations for future developers working on the templates functionality:
href
attribute of the download links exist in the specified locations (pdfs/sample1.pdf
, pdfs/sample2.pdf
, etc.). THESE DO NOT EXIST AS OF 07/05/2023templates.css
file to match the desired appearance of the template cards. NEEDS TO BE UPDATEDsample1.pdf
, sample2.pdf
, etc.) with the actual template files to be provided to users.upload.php
upload.php
handles the file upload functionality to Google Drive using a service account defined in the credentials.php
file.
The file starts with the <?php
opening tag and includes the necessary dependencies, such as the Google Drive client library (autoload.php
) and the utils/config.php
file.
The main functionalities of the upload.php
file include:
c3-testing-389115-f39fd8b05d5d.json
.$_FILES
and $_POST
superglobal variables.unique_name
and is moved to the specified folder ID obtained from the folder_ids
array.C3DataMasterTest
.Important considerations for future developers working on the file upload functionality:
C3DataMasterTest
) matches the column names and data types used in the SQL query.To use the CoastCowConsumer Data Repository:
dashboard.php
for the main dashboard page, explore.php
for the explore page, and so on.The CoastCowConsumer Data Repository has the following dependencies:
"phpmailer/phpmailer": ^6.8 , "google/apiclient": ^2.0
To install and set up the CoastCowConsumer Data Repository:
Once the environment is properly set up, access the application by running a local server and navigating to the appropriate URL.
If one plans to localhost the repository, the user is responsible for managing their own packages to confirm proper functionality
We recommend the user uses composer for their file management. Composer is a dependency management tool for PHP programming. It is designed to simplify the process of managing dependencies, libraries, and packages in PHP projects. Composer allows developers to easily declare the libraries and dependencies their project requires and handles the installation and management of those dependencies. This way, we can confirm that libaries are all compatible and do not need to worry about managing this. Here's a quick tutorial on how and where to install composer
Once one has composer installed, they should create or update their composer.json file to include: "phpmailer/phpmailer": ^6.8
and "google/apiclient": ^2.0
as well as any additional non-native installations (libraries, APIs, other software).
Now, the user just needs to run php composer update
and/or composer install
. If any of those commands fail, add .phar
to composer
to make the commands php composer.phar update
and/or composer.phar install
More about this is included in the composer tutorial.
Google Drive API relies upon service accounts. We create a service account attached to the project, and then we use the google drive api to tell that service account to do actions on the operational database. This mostly involves file creation and movement. We use fileID's to give the service account / API the direct location of the files to be operated on. If the service account associated with the project fails, and Gordon or Parth are not available, here are the steps to making a new account and integrating it with the given codebase.
Set up a Google Cloud Project:
Create a Service Account:
Set up the Development Environment:
Authenticate the Service Account:
Congrats! You should be good to go!
The CoastCowConsumer Data Repository is released under the MIT License. See the LICENSE file for more details.