123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?
- //echo "posttt";
- if (!isset($db_hostname))
- {
- include 'auth.php';
- include 'functions.php';
- }
- require_once "doctrine/bootstrap.php";
- require_once 'api/vendor/autoload.php';
- foreach (array_keys($_REQUEST) as $var)
- {
- ${$var}=$_REQUEST[$var];
- //echo "<b>$var:</b> ${$var} <br>";
- }
- $pnum = intval($pnum);
- //echo "packet ".$pnum;
- //echo " id ".$id;
- //echo $id."gggg".$did." pnum ".$pnum;
- //return;
- //$num = ShortToHexString($pnum); //zeropad(dechex($pnum), 2);
- $num = intval($pnum);
- switch ($pnum) {
- case 17:
- ImageNote($num, $taskid, $img);
- $buf = pack("CC", 17,1);
- echo base64_encode($buf);
- break;
- case 19:
- AudioNote($num, $taskid, $aud, $cpid);
- $buf = pack("CC", 19,1);
- echo base64_encode($buf);
- break;
- case 33:
- WriteLog($accid, $text);
- $buf = pack("CC", 33,1);
- echo base64_encode($buf);
- break;
- }
- function base64_to_jpeg( $inputfile, $outputfile ) {
- /* read data (binary) */
- $ifp = fopen( $inputfile, "rb" );
- $imageData = fread( $ifp, filesize( $inputfile ) );
- fclose( $ifp );
- /* encode & write data (binary) */
- $ifp = fopen( $outputfile, "wb" );
- fwrite( $ifp, base64_decode( $imageData ) );
- fclose( $ifp );
- /* return output filename */
- return( $outputfile );
- }
- function base64_to_audio( $inputdata, $outputfile ) {
- /* read data (binary) */
- /* encode & write data (binary) */
- $ifp = fopen( $outputfile, "wb" );
- fwrite( $ifp, base64_decode( $inputdata ) );
- fclose( $ifp );
- /* return output filename */
- return( $outputfile );
- }
- function AudioNote($num, $taskid, $aud, $cpid)
- {
- global $link;
- // echo "AudioNote";
- // return;
- $buf = pack("C*", 16);
- $companyID = getCompanyByTask($taskid)[0];
- $project_id = getProjectIDByTask($taskid);
- $rootPath = $_SERVER['DOCUMENT_ROOT'];
- $companyPath = $rootPath."/data/$companyID";
- $projectPath = $companyPath."/$project_id";
- $imgpath = $projectPath."/$taskid/";
- $err = 0;
- //echo base64_encode($buf."ImageNote comp $companyID pr $project_id path $imgpath err $err");
- //return;
- $imagedata = base64_decode($aud);
- //$im = imagecreatefromstring($imagedata);
- if ($imagedata !== false)
- {
- if(!is_dir($companyPath))
- {
- mkdir($companyPath);
- }
- if(!is_dir($projectPath))
- {
- mkdir($projectPath);
- }
- if(!is_dir($imgpath))
- {
- mkdir($imgpath);
- }
- }
- else {
- $err = 1;
- }
- $date = date("Y-m-d-H-i-s");
- $path = $imgpath."aud".$date.".mp3";
- //echo $path;
- $f = fopen($path, 'x');
- if (!$f) {
- $err = 2;
- //return false;
- } else {
- $bytes = fwrite($f, $imagedata);
- fclose($f);
- // return $bytes;
- }
- //$str = "ImageNote comp $companyID pr $project_id path $imgpath err $err";
- //echo $str;
- $size = sizeof($imagedata);
- $sizeaud = sizeof($aud);
- // echo "AudioNote size $size err $err sizeaud $sizeaud $imagedata";
- //echo base64_encode($buf."ImageNote size $size");
- }
- function ImageNote($num, $taskid, $img)
- {
- global $link;
- // $buf = pack("C*", 16);
- /**
- * @var $task Task
- */
- $task = Task::Find($taskid);
- if ($task) {
- $companyID = getCompanyByTask($taskid)[0];
- $project_id = $task->input_id;// getProjectIDByTask($taskid);
- $rootPath = $_SERVER['DOCUMENT_ROOT'];
- $companyPath = "/data/$companyID";
- $projectPath = $companyPath . "/$project_id";
- $relativeImgpath = $projectPath . "/$taskid/";
- $imgpath = $rootPath.$relativeImgpath;
- $asusgId = $task->asusg_job_mapped_id;
- $date = date("Y-m-d-H-i-s");
- if ($asusgId)
- {
- $str = "select asusg_job_uuid from asusg_job2launch where id= $asusgId";
- $query = mysqli_query($link, $str);
- if ($res = mysqli_fetch_row($query))
- {
- $uuid = $res[0];
- require_once "curlexec.php";
- $dict = array();
- $domain = $_SERVER['SERVER_NAME'];
- $remoteImgPath = "http://".$domain.$relativeImgpath;
- $path = $remoteImgPath . "image" . $date . ".jpg";
- $dict['photos_list'] = $path;
- $dict['id_work'] = $uuid;
- $url = "http://qaplatform.digitaldepot.ru:8085/Thingworx/Things/2050UserLibraryExp/Services/add_photos_work_v2";
- $result = CURLrequestPOST($url, ["AppKey: 33cd23bb-3b03-4638-afef-7104a13e9211"], $dict);
- WriteLog("TWX Add_photos_work_v2 input ".json_encode($dict), $result);
- }
- }
- $err = 0;
- //echo base64_encode($buf."ImageNote comp $companyID pr $project_id path $imgpath err $err");
- //return;
- $imagedata = base64_decode($img);
- $im = imagecreatefromstring($imagedata);
- if ($im !== false) {
- if (!is_dir($rootPath.$companyPath)) {
- mkdir($rootPath.$companyPath);
- }
- if (!is_dir($rootPath.$projectPath)) {
- mkdir($rootPath.$projectPath);
- }
- if (!is_dir($imgpath)) {
- mkdir($imgpath);
- }
- } else {
- $err = 1;
- }
- $path = $imgpath . "image" . $date . ".jpg";
- // echo $path;
- $f = fopen($path, 'x');
- if (!$f) {
- $err = 2;
- //return false;
- } else {
- $bytes = fwrite($f, $imagedata);
- fclose($f);
- // return $bytes;
- }
- //$str = "ImageNote comp $companyID pr $project_id path $imgpath err $err";
- //echo $str;
- // $size = sizeof($img);
- //echo base64_encode($buf."ImageNote size $size");
- }
- }
- ?>
|