install.ajax.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use GuzzleHttp\Client;
  4. /**
  5. * Responses to AJAX calls for install.
  6. */
  7. require_once __DIR__.'/../../../vendor/autoload.php';
  8. $action = $_GET['a'];
  9. switch ($action) {
  10. case 'send_contact_information':
  11. if (!empty($_POST)) {
  12. // get params from contact form
  13. $person_name = $_POST['person_name'];
  14. $person_email = $_POST['person_email'];
  15. $person_role = $_POST['person_role'];
  16. $financial_decision = $_POST['financial_decision'];
  17. $contact_language = $_POST['language'];
  18. $company_name = $_POST['company_name'];
  19. $company_activity = $_POST['company_activity'];
  20. $company_country = $_POST['company_country'];
  21. $company_city = $_POST['company_city'];
  22. // validating required fields
  23. $a_required_fields = [$person_name, $person_role, $company_name, $company_activity, $company_country];
  24. $required_field_error = false;
  25. foreach ($a_required_fields as $required_file) {
  26. if (trim($required_file) === '') {
  27. $required_field_error = true;
  28. break;
  29. }
  30. }
  31. // Return error if any of the required fields is empty
  32. if ($required_field_error) {
  33. echo 'required_field_error';
  34. break;
  35. } else {
  36. // save contact information with web service
  37. // create a client
  38. $url = 'https://version.chamilo.org/contactv2.php';
  39. $options = [
  40. 'verify' => false,
  41. ];
  42. $urlValidated = false;
  43. try {
  44. $client = new GuzzleHttp\Client();
  45. $res = $client->request('GET', $url, $options);
  46. if ($res->getStatusCode() == '200' || $res->getStatusCode() == '301') {
  47. $urlValidated = true;
  48. }
  49. } catch (Exception $e) {
  50. error_log("Could not check $url from ".__FILE__);
  51. break;
  52. }
  53. $data = [
  54. 'person_name' => $person_name,
  55. 'person_email' => $person_email,
  56. 'person_role' => $person_role,
  57. 'financial_decision' => $financial_decision,
  58. 'contact_language' => $contact_language,
  59. 'company_name' => $company_name,
  60. 'company_activity' => $company_activity,
  61. 'company_country' => $company_country,
  62. 'company_city' => $company_city,
  63. ];
  64. $client = new GuzzleHttp\Client();
  65. $options['query'] = $data;
  66. $res = $client->request('GET', $url, $options);
  67. if ($res->getStatusCode() == '200') {
  68. echo '1';
  69. }
  70. }
  71. }
  72. break;
  73. default:
  74. echo '';
  75. }
  76. exit;