Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Remote.class.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. class Remote {
  3. private $config;
  4. private $db;
  5. function __construct() {
  6. global $db, $config; //App/boostrap.php
  7. $this->config = $config;
  8. $this->db = $db;
  9. }
  10. public function createRemoteRequest($survey_code=null) {
  11. $attach = [];
  12. $status = 'ok';
  13. $survey = $this->db
  14. ->join('survey_registry sry', 'sry.survey_id=sy.id')
  15. ->join('survey_types stp', 'stp.id=sy.type_id')
  16. ->where('sy.code', $survey_code)
  17. ->where('sy.json_answers', NULL, 'IS NOT')
  18. ->where('sy.remote_added', 0)
  19. ->getOne('survey sy', "sy.*, sry.*, sy.id survey_id, stp.survey_label, stp.cc_id, stp.ms_id, sry.created_at registry_created_at");
  20. if (isset($survey['code'])) {
  21. $attach = $this->db->where('survey_uuid', $survey_code)->get('survey_attachments');
  22. if (is_array($attach) && !empty($attach)) {
  23. foreach($attach as $index => $file) {
  24. $attach[$index]['data'] = base64_encode(file_get_contents(ATTACH_DIR.$file['uuid']));
  25. }
  26. }
  27. } else {
  28. $status = 'err';
  29. }
  30. $return_data = json_encode(['status'=>$status, 'survey'=>$survey, 'survey_code'=>$survey_code, 'attach'=>$attach]);
  31. $endpoint = $this->config['settings']['sportellocura']['api']['endpoint'];
  32. $cmd = (int)$survey['remote_auto_tlc_id'] > 0 ? 'update-request' : 'create-request';
  33. $remote_auto_tlc_id = (isset($survey['remote_auto_tlc_id'])&&(int)$survey['remote_auto_tlc_id']>0) ? $survey['remote_auto_tlc_id'] : 0;
  34. $vars = ['data'=>$return_data, 'cmd'=>$cmd, 'request-id'=>$remote_auto_tlc_id];
  35. $ch = curl_init();
  36. curl_setopt($ch, CURLOPT_URL, $endpoint);
  37. curl_setopt($ch, CURLOPT_POST, 1);
  38. curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); //Post Fields
  39. //curl_setopt($ch, CURLOPT_USERPWD, "dev-ght:demo");
  40. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  41. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  42. curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout in seconds
  43. $curldata = curl_exec($ch);
  44. $curl_info = curl_getinfo($ch);
  45. file_put_contents(PUBLIC_HTML.'request.log', json_encode(curl_getinfo($ch)));
  46. curl_close($ch);
  47. return $curldata;
  48. }
  49. }