server_post.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?
  2. //echo "posttt";
  3. if (!isset($db_hostname))
  4. {
  5. include 'auth.php';
  6. include 'functions.php';
  7. }
  8. require_once "doctrine/bootstrap.php";
  9. require_once 'api/vendor/autoload.php';
  10. foreach (array_keys($_REQUEST) as $var)
  11. {
  12. ${$var}=$_REQUEST[$var];
  13. //echo "<b>$var:</b> ${$var} <br>";
  14. }
  15. $pnum = intval($pnum);
  16. //echo "packet ".$pnum;
  17. //echo " id ".$id;
  18. //echo $id."gggg".$did." pnum ".$pnum;
  19. //return;
  20. //$num = ShortToHexString($pnum); //zeropad(dechex($pnum), 2);
  21. $num = intval($pnum);
  22. switch ($pnum) {
  23. case 17:
  24. ImageNote($num, $taskid, $img);
  25. $buf = pack("CC", 17,1);
  26. echo base64_encode($buf);
  27. break;
  28. case 19:
  29. AudioNote($num, $taskid, $aud, $cpid);
  30. $buf = pack("CC", 19,1);
  31. echo base64_encode($buf);
  32. break;
  33. case 33:
  34. WriteLog($accid, $text);
  35. $buf = pack("CC", 33,1);
  36. echo base64_encode($buf);
  37. break;
  38. }
  39. function base64_to_jpeg( $inputfile, $outputfile ) {
  40. /* read data (binary) */
  41. $ifp = fopen( $inputfile, "rb" );
  42. $imageData = fread( $ifp, filesize( $inputfile ) );
  43. fclose( $ifp );
  44. /* encode & write data (binary) */
  45. $ifp = fopen( $outputfile, "wb" );
  46. fwrite( $ifp, base64_decode( $imageData ) );
  47. fclose( $ifp );
  48. /* return output filename */
  49. return( $outputfile );
  50. }
  51. function base64_to_audio( $inputdata, $outputfile ) {
  52. /* read data (binary) */
  53. /* encode & write data (binary) */
  54. $ifp = fopen( $outputfile, "wb" );
  55. fwrite( $ifp, base64_decode( $inputdata ) );
  56. fclose( $ifp );
  57. /* return output filename */
  58. return( $outputfile );
  59. }
  60. function AudioNote($num, $taskid, $aud, $cpid)
  61. {
  62. global $link;
  63. // echo "AudioNote";
  64. // return;
  65. $buf = pack("C*", 16);
  66. $companyID = getCompanyByTask($taskid)[0];
  67. $project_id = getProjectIDByTask($taskid);
  68. $rootPath = $_SERVER['DOCUMENT_ROOT'];
  69. $companyPath = $rootPath."/data/$companyID";
  70. $projectPath = $companyPath."/$project_id";
  71. $imgpath = $projectPath."/$taskid/";
  72. $err = 0;
  73. //echo base64_encode($buf."ImageNote comp $companyID pr $project_id path $imgpath err $err");
  74. //return;
  75. $imagedata = base64_decode($aud);
  76. //$im = imagecreatefromstring($imagedata);
  77. if ($imagedata !== false)
  78. {
  79. if(!is_dir($companyPath))
  80. {
  81. mkdir($companyPath);
  82. }
  83. if(!is_dir($projectPath))
  84. {
  85. mkdir($projectPath);
  86. }
  87. if(!is_dir($imgpath))
  88. {
  89. mkdir($imgpath);
  90. }
  91. }
  92. else {
  93. $err = 1;
  94. }
  95. $date = date("Y-m-d-H-i-s");
  96. $path = $imgpath."aud".$date.".mp3";
  97. //echo $path;
  98. $f = fopen($path, 'x');
  99. if (!$f) {
  100. $err = 2;
  101. //return false;
  102. } else {
  103. $bytes = fwrite($f, $imagedata);
  104. fclose($f);
  105. // return $bytes;
  106. }
  107. //$str = "ImageNote comp $companyID pr $project_id path $imgpath err $err";
  108. //echo $str;
  109. $size = sizeof($imagedata);
  110. $sizeaud = sizeof($aud);
  111. // echo "AudioNote size $size err $err sizeaud $sizeaud $imagedata";
  112. //echo base64_encode($buf."ImageNote size $size");
  113. }
  114. function ImageNote($num, $taskid, $img)
  115. {
  116. global $link;
  117. // $buf = pack("C*", 16);
  118. /**
  119. * @var $task Task
  120. */
  121. $task = Task::Find($taskid);
  122. if ($task) {
  123. $companyID = getCompanyByTask($taskid)[0];
  124. $project_id = $task->input_id;// getProjectIDByTask($taskid);
  125. $rootPath = $_SERVER['DOCUMENT_ROOT'];
  126. $companyPath = "/data/$companyID";
  127. $projectPath = $companyPath . "/$project_id";
  128. $relativeImgpath = $projectPath . "/$taskid/";
  129. $imgpath = $rootPath.$relativeImgpath;
  130. $asusgId = $task->asusg_job_mapped_id;
  131. $date = date("Y-m-d-H-i-s");
  132. if ($asusgId)
  133. {
  134. $str = "select asusg_job_uuid from asusg_job2launch where id= $asusgId";
  135. $query = mysqli_query($link, $str);
  136. if ($res = mysqli_fetch_row($query))
  137. {
  138. $uuid = $res[0];
  139. require_once "curlexec.php";
  140. $dict = array();
  141. $domain = $_SERVER['SERVER_NAME'];
  142. $remoteImgPath = "http://".$domain.$relativeImgpath;
  143. $path = $remoteImgPath . "image" . $date . ".jpg";
  144. $dict['photos_list'] = $path;
  145. $dict['id_work'] = $uuid;
  146. $url = "http://qaplatform.digitaldepot.ru:8085/Thingworx/Things/2050UserLibraryExp/Services/add_photos_work_v2";
  147. $result = CURLrequestPOST($url, ["AppKey: 33cd23bb-3b03-4638-afef-7104a13e9211"], $dict);
  148. WriteLog("TWX Add_photos_work_v2 input ".json_encode($dict), $result);
  149. }
  150. }
  151. $err = 0;
  152. //echo base64_encode($buf."ImageNote comp $companyID pr $project_id path $imgpath err $err");
  153. //return;
  154. $imagedata = base64_decode($img);
  155. $im = imagecreatefromstring($imagedata);
  156. if ($im !== false) {
  157. if (!is_dir($rootPath.$companyPath)) {
  158. mkdir($rootPath.$companyPath);
  159. }
  160. if (!is_dir($rootPath.$projectPath)) {
  161. mkdir($rootPath.$projectPath);
  162. }
  163. if (!is_dir($imgpath)) {
  164. mkdir($imgpath);
  165. }
  166. } else {
  167. $err = 1;
  168. }
  169. $path = $imgpath . "image" . $date . ".jpg";
  170. // echo $path;
  171. $f = fopen($path, 'x');
  172. if (!$f) {
  173. $err = 2;
  174. //return false;
  175. } else {
  176. $bytes = fwrite($f, $imagedata);
  177. fclose($f);
  178. // return $bytes;
  179. }
  180. //$str = "ImageNote comp $companyID pr $project_id path $imgpath err $err";
  181. //echo $str;
  182. // $size = sizeof($img);
  183. //echo base64_encode($buf."ImageNote size $size");
  184. }
  185. }
  186. ?>