CMXX - Add service init Analogvoltage
This commit is contained in:
50
test.php
50
test.php
@@ -9,41 +9,25 @@ include './settings/config.php';
|
||||
include_once './settings/translations/translations_US.php';
|
||||
include_once './settings/systemfirmware.php';
|
||||
|
||||
$pdo = dbConnect($dbname);
|
||||
$sql = 'SELECT * FROM contracts WHERE status = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($messages as $message){
|
||||
//Calculate contract end date
|
||||
$end_date = date('Y-m-d', strtotime('+'.$message['duration'].' months', strtotime($message['start_date'])));
|
||||
//define('standard_profile','dashboard,profile,equipments,equipment,histories,history,servicereports,servicereport,firmwaretool,application');
|
||||
|
||||
//Validate if contract end date is in the past change contact status to closed and set users to not active
|
||||
if (date("Y-m-d") > $end_date){
|
||||
//Contract expired -> change status to closed (2)
|
||||
$sql = 'UPDATE contracts SET status = ? WHERE rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([2,$message['rowID']]);
|
||||
|
||||
//CHECK FOR ASSIGNED USER END SET SERVICE TO INACTIVE
|
||||
foreach (json_decode($message['assigned_users']) as $user_assigned){
|
||||
$allviews = ["dashboard","profile","equipments","equipment","equipmentmanage","equipment_item"];
|
||||
|
||||
//CALL TO API FOR General information
|
||||
$clientsecret = createCommunicationToken($_SESSION['userkey']);
|
||||
$responses = ioApi('/v2/users/username='.$user_assigned,'',$clientsecret);
|
||||
$admin_profile = ["dashboard","profile","equipments","equipment"];
|
||||
|
||||
if (!empty($responses)){
|
||||
$response = json_decode($responses,true);
|
||||
//If response is not null update the service flag of the user
|
||||
if (count($response) != 0){
|
||||
$id_exist_user = $response[0]['id'];
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Remove serviceflag from user when status is Closed
|
||||
$stmt->execute(['',$id_exist_user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$view = '<html><form action="" method="post">';
|
||||
|
||||
foreach ($allviews as $view){
|
||||
|
||||
if (in_array($view,$admin_profile)){
|
||||
$view .= '<input type="checkbox" id="'.$view.'" name="" value="'.$view.'" checked>';
|
||||
} else {
|
||||
$view .= '<input type="checkbox" id="'.$view.'" name="profile[]" value="'.$view.'">';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
|
||||
$view .= '</form></html>';
|
||||
|
||||
echo $view;
|
||||
Reference in New Issue
Block a user