/bin/service_age.php
PHP | 93 lines | 80 code | 12 blank | 1 comment | 10 complexity | b7368d0ace419592932779d84866ae04 MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, LGPL-2.1
- #!/usr/local/bin/php
- <?php
- require_once('database.php');
- require_once('date.php');
- $query = "SELECT * FROM services WHERE 1";
- $result = mysql_query($query);
- if (!$result) {
- die("Invalid query: " . mysql_error());
- }
- while ($row = @mysql_fetch_assoc($result)) {
- $age = dateDiff('d',$row['modified'],date('Y-m-d'));
- $query = "UPDATE services SET age = " . $age . " WHERE id = " . $row['id'];
- echo "Updating age as " . $age . " for service id " . $row['id'] . "\n";
- $update_result = mysql_query($query);
- if (!$update_result) {
- die("Invalid query: " . mysql_error());
- }
- }
- $query = "SELECT SUM(age) as total_age, COUNT(*) as total_no_of_service from services WHERE 1";
- $result = mysql_query($query);
- if (!$result) {
- die("Invalid query: " . mysql_error());
- }
- $row = @mysql_fetch_assoc($result);
- $total_age = $row['total_age'];
- $total_no_of_service = $row['total_no_of_service'];
- $average_age_of_service = $total_age / $total_no_of_service;
- echo " No Of Services :" . $total_no_of_service . "\n";
- echo " Total Age of Services :" . $total_age . "\n";
- echo " Average Age of Services :" . $average_age_of_service . "\n";
- $query = "SELECT COUNT(*) as total_no_of_sites from sites WHERE 1";
- $result = mysql_query($query);
- if (!$result) {
- die("Invalid query: " . mysql_error());
- }
- $row = @mysql_fetch_assoc($result);
- $total_no_of_sites = $row['total_no_of_sites'];
- echo " Total No of Sites :" . $total_no_of_sites . "\n";
- $query = "SELECT COUNT(*) as total_no_of_locations from locations WHERE 1";
- $result = mysql_query($query);
- if (!$result) {
- die("Invalid query: " . mysql_error());
- }
- $row = @mysql_fetch_assoc($result);
- $total_no_of_locations = $row['total_no_of_locations'];
- echo " Total No of Locations :" . $total_no_of_locations . "\n";
- $query = "SELECT COUNT(*) as total_no_of_users from users WHERE 1";
- $result = mysql_query($query);
- if (!$result) {
- die("Invalid query: " . mysql_error());
- }
- $row = @mysql_fetch_assoc($result);
- $total_no_of_users = $row['total_no_of_users'];
- echo " Total No of Users:" . $total_no_of_users . "\n";
- $query = "UPDATE statistics
- SET
- no_of_services = $total_no_of_service,
- total_age_of_services = $total_age,
- average_age_of_services = $average_age_of_service,
- no_of_sites = $total_no_of_sites,
- no_of_locations = $total_no_of_locations,
- no_of_users = $total_no_of_users
- WHERE 1";
- echo $query . "\n";
- $update_result = mysql_query($query);
- if (!$update_result) {
- die("Invalid query: " . mysql_error());
- }
- $query = "INSERT INTO statistics_history (
- no_of_services,
- total_age_of_services,
- average_age_of_services,
- no_of_sites,
- no_of_locations,no_of_users,created)
- VALUES ($total_no_of_service, $total_age,$average_age_of_service,$total_no_of_sites,$total_no_of_locations,$total_no_of_users,now())";
- echo $query . "\n";
- $insert_result = mysql_query($query);
- if (!$insert_result) {
- die("Invalid query: " . mysql_error());
- }
- ?>