$pid, "firstname" => $firstname, "lastname" => $lastname, "email" => $email ]; $response = make_post_request($url, $data); if ($response === FALSE) { $errorCount++; continue; } $response_data = json_decode($response, true); if ($response_data['status'] === 201) { $successCount++; //-------------------------- CONVERTION OF ROLE--------------------------------------------// $roleConverted = strtolower($role); if ($roleConverted === 'guest') { $role = 'guest'; //------------------------CONVERTION ENDS HERE--------------------------------------------// //--------------------------------------API CALL FOR PASSWORD CREATION-----------------------// $jsonFilePath = __DIR__ . '/../urls/api_endpoints.json'; $jsonData = file_get_contents($jsonFilePath); $endpoints = json_decode($jsonData, true); $url = $endpoints['password_function'] . $pid . "/password?"; //--------------------------------------------API CALL ENDS-------------------------------// $data = [ "access_level" => "NONE", "password" => $password, "pid" => $pid, "expiration" => '', "valid_from" => date('Y-m-d'), "category" => "1", "access_duration" => "1D" ]; $response = make_post_request($url, $data); continue; //---------------------------------------ROLE GUEST ENDS ----------------------------------------// //--------------------------------------ROLE USER STARTS--------------------------------------------// } else { $role = 'User'; //------------------------------------API CALL FOR PASSWORD CREATION----------------------------------// $jsonFilePath = __DIR__ . '/../urls/api_endpoints.json'; $jsonData = file_get_contents($jsonFilePath); $endpoints = json_decode($jsonData, true); $url = $endpoints['password_function'] . $pid . "/password?"; //------------------------------------------API CALL FOR PASSWORD ENDS HERE----------------------------// $data = [ "access_level" => "NONE", "password" => $password, "pid" => $pid, "expiration" => date('Y-m-d', strtotime('+3 years')), "valid_from" => date('Y-m-d'), "category" => "6", "access_duration" => "" ]; $response = make_post_request($url, $data); if ($response === FALSE) { $errorCount++; continue; } } } elseif ($response_data['status'] === 409) { $existingCount++; $existingUsers[] = $pid; } else { $errorCount++; } } if(empty($password)){ $passwordCount++; $passwordMissing[] =$pid; continue; } } if (!empty($existingUsers)) { if (!is_dir(__DIR__ . '/../downloads')) { mkdir(__DIR__ . '/../downloads', 0777, true); } $csvFile = __DIR__ . '/../downloads/existing_users.csv'; $fileHandle = fopen($csvFile, 'w'); if ($fileHandle === FALSE) { die('Failed to create CSV file.'); } fputcsv($fileHandle, ['PID']); foreach ($existingUsers as $pid) { fputcsv($fileHandle, [$pid]); } fclose($fileHandle); } if (!empty($passwordMissing)) { if (!is_dir(__DIR__ . '/../downloads')) { mkdir(__DIR__ . '/../downloads', 0777, true); } $csvFile = __DIR__ . '/../downloads/deleted_users.csv'; $fileHandle = fopen($csvFile, 'w'); if ($fileHandle === FALSE) { die('Failed to create CSV file.'); } fputcsv($fileHandle, ['PID']); foreach ($passwordMissing as $pid) { fputcsv($fileHandle, [$pid]); } fclose($fileHandle); } $_SESSION['successCount'] = $successCount; $_SESSION['passwordCount'] = $passwordCount; $_SESSION['csvFile'] = !empty($existingUsers) ? 'existing_users.csv' : ''; $_SESSION['passwordFile'] =!empty($passwordMissing) ? 'password_miss.csv' : ''; header("Location: ../user/upload_summary.php"); exit(); } } } } ?>