php - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of php.php

  1. <?php
  2. /*. require_module 'mcrypt'; .*/
  3.  
  4. /*. forward string function do_activation_hdd(string $ehdd_sn); .*/
  5. /*. forward string function do_activation_orderno(string $eorderno_sn); .*/
  6. /*. forward string function do_activation_customername(string $ecustomername_sn); .*/
  7. /*. forward string function do_ak_noc_server(string $noclients); .*/
  8. /*. forward string function do_encryption_hdd(string $ohdd); .*/
  9. /*. forward string function do_encryption_customername(string $customername); .*/
  10. /*. forward string function do_activationkey_ns(string $activationkey); .*/
  11. /*. forward string function do_encryption_order(string $orderno); .*/
  12. /*. forward string function lic_encrypt(string $value,string $secret); .*/
  13. /*. forward string function do_encryption_prodid(string $ProdID_pc); .*/
  14.  
  15. // require_once(__DIR__ ."/product_util.php");
  16. // require_once(__DIR__ ."/visit_submit_in_popup.php");
  17. // require_once(__DIR__ ."/function.send_sms.php");
  18. // require_once(__DIR__ ."/function.update_in_hdr.php"); 
  19. // require_once(__DIR__.'/log.php');
  20. $secret ="1c363e82e2db9a14a556e4258e9ebe62";
  21.  
  22. /**
  23.  * @param string $data
  24.  * 
  25.  * @return string
  26.  */
  27. function fun_hex2bin_str($data) {
  28.     $len = strlen($data);
  29.     return pack("H" . $len, $data);
  30. }
  31.  
  32.  
  33. /**
  34.  * @param string $data
  35.  *
  36.  * @return string
  37.  */
  38. function pad($data) {
  39.         $padlen = 8-(strlen($data) % 8);
  40.         if($padlen == 8){
  41.                 return $data;
  42.         }
  43.  
  44.       for ($i=0; $i<$padlen; $i++){
  45.                 //$data .= chr($padlen);
  46.                 $data .= chr(0);
  47.         }
  48.       return $data;
  49. }
  50.  
  51. /**
  52.  * @param string $key
  53.  *
  54.  * @return string
  55.  */
  56. function make_openssl_blowfish_key($key)
  57. {
  58.     if("$key" === ''){
  59.         return $key;
  60.     }
  61.  
  62.     $len = (16+2) * 4;
  63.     while(strlen($key) < $len) {
  64.         $key .= $key;
  65.     }
  66.     $key = substr($key, 0, $len);
  67.     return $key;
  68. }
  69. /**
  70.  * @param string $value
  71.  * @param string $secret
  72.  * 
  73.  * @return string
  74.  */
  75. function lic_decrypt($value,$secret){
  76.         $secret=fun_hex2bin_str($secret);
  77.         $value=pad($value);  
  78.         $value=base64_decode($value);
  79.         $iv = random_bytes(8);
  80.         $secret = make_openssl_blowfish_key($secret);
  81.     $v = openssl_decrypt(($value), 'BF-ECB', $secret, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
  82.         $v = rtrim($v, "\0");
  83.         /*
  84.     //$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
  85.         $iv = mcrypt_create_iv(8,MCRYPT_DEV_URANDOM);
  86.     $v=mcrypt_decrypt(MCRYPT_BLOWFISH, $secret, $value, MCRYPT_MODE_ECB, $iv);
  87.         $v=rtrim($v, "\0"); //Remove the leading '\0' character
  88.         */
  89.     $v = preg_replace('/[\x01-\x08]/u', '', $v); //to remove data which are padded in blowfish encryption
  90.         return $v;
  91. }
  92.  
  93. /**
  94.  * @param string $value
  95.  * @param string $secret
  96.  *
  97.  * @return string
  98.  */
  99. function lic_encrypt($value,$secret){ 
  100.         $secretVar='701241';
  101.         $valueVar='AKIAQVSVNCI4VWN7GANM';
  102.         $secret=fun_hex2bin_str($secret);
  103.     $value=pad($value); 
  104.     $iv = random_bytes(8);
  105.     $blockSize = 8;
  106.     $len = strlen($value);
  107.     $paddingLen = intval(($len + $blockSize - 1) / $blockSize) * $blockSize - $len;
  108.     $padding = str_repeat("\0", $paddingLen);
  109.     $data = $value . $padding;
  110.     $secret = make_openssl_blowfish_key($secret);
  111.     $v = openssl_encrypt($data, 'BF-ECB', $secret, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
  112.     $encdata =  base64_encode($v);
  113.     /*$secret=fun_hex2bin_str($secret);
  114.         $value=pad($value);        
  115.     //$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
  116.     $iv = mcrypt_create_iv(8,MCRYPT_DEV_URANDOM);
  117.         $v=mcrypt_encrypt(MCRYPT_BLOWFISH,$secret, $value, MCRYPT_MODE_ECB,$iv);
  118.         $encdata=base64_encode($v);
  119.         */
  120.        
  121.         //For Validation
  122.         $v2_val=base64_decode($encdata);
  123.         $value2_val = lic_decrypt($encdata,$secretVar);
  124.         if ($v != $v2_val){
  125.                 throw new ErrorException("Problem in  base64_decode -- lic_util.php::lic_encrypt()");
  126.         }
  127.        
  128.        if ($value2_val != $valueVar){
  129.                error_log("value=::".$value ."::");
  130.                $arr = unpack("H*",$value);
  131.                $arr_str=print_r($arr,true);
  132.                //$arr_str='';
  133.                //for($k=1; $k <=count($arr); $k++){
  134.                //   $arr_str .="-0x".$arr[$k];
  135.                //}
  136.                error_log("value HH=::".strval($arr_str)."::");
  137.                error_log("value2_val=::".$value2_val ."::");
  138.                error_log("valueVar=::".$valueVar."::");
  139.                throw new ErrorException("Problem in  lic_decrypt  --- lic_util.php::lic_encrypt() ");
  140.        }
  141.        echo 'Encrypted', $encdata;
  142.         return $encdata;
  143. }
  144.  
  145.  
  146. /**
  147.  * @param string $customername
  148.  * 
  149.  * @return string
  150.  */
  151.  
  152. function do_encryption_customername($customername){
  153.         $ltmp1 = 0;
  154.         for( $i = 0;$i<strlen($customername);$i++){
  155.             $ltmp1 = $ltmp1 + ord(substr($customername,$i, 1));
  156.         }
  157.  
  158.         if ((strlen($customername) <= 5) or ($ltmp1 <= 60)){$ltmp1 = $ltmp1 + 86;} 
  159.         elseif (strlen($customername) <= 10){$ltmp1 = $ltmp1 + 73;}
  160.         elseif (strlen($customername) <= 15){$ltmp1 = $ltmp1 + 61;}
  161.         elseif (strlen($customername) <= 20){$ltmp1 = $ltmp1 + 55;}
  162.         elseif (strlen($customername) <= 25){$ltmp1 = $ltmp1 + 47;}
  163.         elseif (strlen($customername) <= 30){$ltmp1 = $ltmp1 + 39;} 
  164.         elseif (strlen($customername) <= 35){$ltmp1 = $ltmp1 + 23;}
  165.         elseif (strlen($customername) <= 40){$ltmp1 = $ltmp1 + 18;}
  166.         elseif (strlen($customername) <= 45){$ltmp1 = $ltmp1 + 41;} 
  167.         elseif (strlen($customername) <= 50){ $ltmp1 = $ltmp1 + 33;}
  168.         else{}
  169.         if ($ltmp1 <= 999 ){    $ltmp1 = $ltmp1 + 4011;}
  170.         elseif ($ltmp1 > 9999){    $ltmp1 =substr($ltmp1,-4) - 789;} 
  171.         $ecustomername = $ltmp1;
  172.         return "$ecustomername";
  173. }
  174.  
  175. /**
  176.  * @param string $orderno
  177.  *
  178.  * @return string 
  179.  */
  180.  
  181. function do_encryption_order($orderno){
  182.         $ltmp=0;
  183.         for( $i = 0;$i<strlen($orderno);$i++){      
  184.             $ltmp = $ltmp + ord(substr($orderno,$i, 1));
  185.        }
  186.         if ($ltmp <= 999){$ltmp = $ltmp + 1947;}
  187.         elseif($ltmp > 9999){$ltmp =substr($ltmp,-4) - 321;}
  188.         $eorderno = $ltmp;
  189.         return "$eorderno";
  190. }
  191.  
  192. /**
  193.  * @param string $ProdID_pc
  194.  * 
  195.  * @return string
  196.  */
  197. function do_encryption_prodid($ProdID_pc){
  198.         $sProdID='';
  199.        
  200.         if (strlen($ProdID_pc)<6){
  201.                 //Note: For the proper value - $ProdID_pc can be 8
  202.                 throw new ErrorException("Invalid product Id value :".$ProdID_pc.": of length=".strlen($ProdID_pc));
  203.         }
  204.        
  205.         if (strlen($ProdID_pc) < 7){$pp="00";$ProdID_pc =$ProdID_pc.$pp;}
  206.         elseif (strlen($ProdID_pc) < 8){$pp="0"; $ProdID_pc = $ProdID_pc.$pp;}
  207.         $pk0=(int)substr($ProdID_pc,0,1);
  208.     $pcode=substr($ProdID_pc,0,3);
  209.  
  210.     if (strpos($ProdID_pc,"EMPLOYEE")!== false){
  211.             return $ProdID_pc;
  212.     }
  213.  
  214.         if ($pk0==0){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +20);} 
  215.         elseif ($pk0==1){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +22);}   
  216.         elseif ($pk0==2){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +24);}   
  217.         elseif ($pk0==3){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +26);}   
  218.         elseif ($pk0==4){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +28);}   
  219.         elseif ($pk0==5){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +19);}   
  220.         elseif ($pk0==6){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +21);}   
  221.         elseif ($pk0==7){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +23);}   
  222.         elseif ($pk0==8){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +25);}   
  223.         elseif ($pk0==9){$sProdID =$sProdID.chr(ord(substr($ProdID_pc,0,1)) +27);}   
  224.         $fProdID0=$sProdID;
  225.  
  226.         $pk1=(int)substr($ProdID_pc,1,1);
  227.         if ($pk1==0){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,1,1)) + 23);} 
  228.         elseif ($pk1==1){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 25);}   
  229.         elseif ($pk1==2){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 27);}   
  230.         elseif ($pk1==3){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 29);}   
  231.         elseif ($pk1==4){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 31);}   
  232.         elseif ($pk1==5){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 24);}   
  233.         elseif ($pk1==6){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 26);}   
  234.         elseif ($pk1==7){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 28);}   
  235.         elseif ($pk1==8){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 30);}   
  236.         elseif ($pk1==9){$sProdID = $sProdID.chr(ord(substr($ProdID_pc, 1, 1)) + 32);}   
  237.         $fProdID1=$sProdID;
  238.  
  239.         $pk2=(int)substr($ProdID_pc,2,1);
  240.         if ($pk2==0){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 21);} 
  241.         elseif ($pk2==1){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 23);}   
  242.         elseif ($pk2==2){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 25);}   
  243.         elseif ($pk2==3){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 27);}   
  244.         elseif ($pk2==4){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 29);}   
  245.         elseif ($pk2==5){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 22);}   
  246.         elseif ($pk2==6){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 24);}   
  247.         elseif ($pk2==7){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 26);}   
  248.         elseif ($pk2==8){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 28);}   
  249.         elseif ($pk2==9){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,2,1)) + 30);}   
  250.         $fProdID2=$sProdID;
  251.  
  252.         $pk3=(int)substr($ProdID_pc,3,1);
  253.         if ($pk3==0){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 24);} 
  254.         elseif ($pk3==1){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 26);}   
  255.         elseif ($pk3==2){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 28);}   
  256.         elseif ($pk3==3){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 30);}   
  257.         elseif ($pk3==4){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 32);}   
  258.         elseif ($pk3==5){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 25);}   
  259.         elseif ($pk3==6){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 27);}   
  260.         elseif ($pk3==7){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 29);}   
  261.         elseif ($pk3==8){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 31);}   
  262.         elseif ($pk3==9){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,3,1)) + 33);}   
  263.         $fProdID3=$sProdID;
  264.  
  265.         $pk4=(int)substr($ProdID_pc,4,1);
  266.         if ($pk4==0){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 17);} 
  267.         elseif ($pk4==1){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 19);}   
  268.         elseif ($pk4==2){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 21);}   
  269.         elseif ($pk4==3){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 23);}   
  270.         elseif ($pk4==4){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 25);}   
  271.         elseif ($pk4==5){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 18);}   
  272.         elseif ($pk4==6){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 20);}   
  273.         elseif ($pk4==7){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 22);}   
  274.         elseif ($pk4==8){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 24);}   
  275.         elseif ($pk4==9){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,4,1)) + 26);}   
  276.         $fProdID4=$sProdID;
  277.  
  278.         $pk5=(int)substr($ProdID_pc,5,1);
  279.         if ($pk5==0){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 19);} 
  280.         elseif ($pk5==1){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 21);}   
  281.         elseif ($pk5==2){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 23);}   
  282.         elseif ($pk5==3){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 25);}   
  283.         elseif ($pk5==4){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 27);}   
  284.         elseif ($pk5==5){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 20);}   
  285.         elseif ($pk5==6){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 22);}   
  286.         elseif ($pk5==7){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 24);}   
  287.         elseif ($pk5==8){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 26);}   
  288.         elseif ($pk5==9){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,5,1)) + 28);}   
  289.         $fProdID5=$sProdID;
  290.        
  291.         $pk6=substr($ProdID_pc,6,1);
  292.         if ($pk6=="0"){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,6,1)) + 22);} 
  293.         elseif ($pk6=="A"){$sProdID = $sProdID.chr(85);}
  294.         elseif ($pk6=="B"){$sProdID = $sProdID.chr(71);}
  295.         elseif ($pk6=="C"){$sProdID = $sProdID.chr(73);}
  296.         elseif ($pk6=="D"){$sProdID = $sProdID.chr(77);}
  297.         elseif ($pk6=="E"){$sProdID = $sProdID.chr(74);}
  298.         elseif ($pk6=="F"){$sProdID = $sProdID.chr(80);}
  299.         elseif ($pk6=="G"){$sProdID = $sProdID.chr(86);}
  300.         elseif ($pk6=="H"){$sProdID = $sProdID.chr(82);}
  301.         elseif ($pk6=="I"){$sProdID = $sProdID.chr(69);}
  302.         elseif ($pk6=="J"){$sProdID = $sProdID.chr(81);}
  303.         elseif ($pk6=="K"){$sProdID = $sProdID.chr(67);}
  304.         elseif ($pk6=="L"){$sProdID = $sProdID.chr(89);}
  305.         elseif ($pk6=="M"){$sProdID = $sProdID.chr(66);}
  306.         elseif ($pk6=="N"){$sProdID = $sProdID.chr(65);}
  307.         elseif ($pk6=="P"){$sProdID = $sProdID.chr(87);}
  308.         elseif ($pk6=="R"){$sProdID = $sProdID.chr(75);}
  309.         elseif ($pk6=="S"){$sProdID = $sProdID.chr(88);}   
  310.         //elseif ($pk6=="T"){$sProdID = $sProdID.chr(72);}
  311.         elseif ($pk6=="U"){$sProdID = $sProdID.chr(90);}
  312.        
  313.         $eprodcode=$sProdID;
  314.         $pk7=substr($ProdID_pc,7,1);
  315.         if ($pk7=="0"){$sProdID = $sProdID.chr(ord(substr($ProdID_pc,7,1)) + 18);} 
  316.         elseif ($pk7=="A"){$sProdID = $sProdID.chr(81);}
  317.         elseif ($pk7=="B"){$sProdID = $sProdID.chr(86);}
  318.         elseif ($pk7=="C"){$sProdID = $sProdID.chr(73);}
  319.         elseif ($pk7=="D"){$sProdID = $sProdID.chr(71);}
  320.         elseif ($pk7=="E"){$sProdID = $sProdID.chr(74);}
  321.         elseif ($pk7=="F"){$sProdID = $sProdID.chr(65);}
  322.         elseif ($pk7=="G"){$sProdID = $sProdID.chr(78);}
  323.         elseif ($pk7=="H"){$sProdID = $sProdID.chr(82);}
  324.         elseif ($pk7=="I"){$sProdID = $sProdID.chr(87);}
  325.         elseif ($pk7=="J"){$sProdID = $sProdID.chr(84);}
  326.         elseif ($pk7=="K"){$sProdID = $sProdID.chr(68);}
  327.         elseif ($pk7=="L"){$sProdID = $sProdID.chr(89);}
  328.         elseif ($pk7=="M"){$sProdID = $sProdID.chr(66);}
  329.         elseif ($pk7=="N"){$sProdID = $sProdID.chr(69);}
  330.         elseif ($pk7=="P"){$sProdID = $sProdID.chr(88);}
  331.         elseif ($pk7=="R"){$sProdID = $sProdID.chr(75);}
  332.         elseif ($pk7=="S"){$sProdID = $sProdID.chr(80);}
  333.         elseif ($pk7=="T"){$sProdID = $sProdID.chr(72);}
  334.         elseif ($pk7=="U"){$sProdID = $sProdID.chr(90);}
  335.        
  336.         $eprodcode=$sProdID;
  337.         return "$eprodcode";
  338. }
  339.  
  340. /**
  341.  * @param string $eproductkey
  342.  * 
  343.  * @return string
  344.  */
  345. function do_encryption_productkey_ns($eproductkey){ 
  346.        
  347.         if (strlen($eproductkey)<20){
  348.                 //Note: For the proper value - $eproductkey can be 24
  349.                 throw new ErrorException("Invalid eproductkey value :".$eproductkey.": of length=".strlen($eproductkey));
  350.         }
  351.        
  352.        $ns=$eproductkey;
  353.         $ns=strrev($ns);
  354.         $n1=substr($ns,1,1);
  355.         $n2=substr($ns,3,1); 
  356.         $n3=substr($ns,5,1);
  357.         $n4=substr($ns,7,1);
  358.         $n5=substr($ns,9,1);
  359.         $n6=substr($ns,11,1);
  360.         $n7=substr($ns,13,1);
  361.         $n8=substr($ns,15,1);
  362.         $n9=substr($ns,17,1);
  363.         $n10=substr($ns,19,1);
  364.         //$n11=substr($ns,21,1);
  365.         //$n12=substr($ns,23,1);
  366.        
  367.         $nn1=substr($ns,0,1);
  368.         $nn2=substr($ns,2,1); 
  369.         $nn3=substr($ns,4,1);
  370.         $nn4=substr($ns,6,1);
  371.         $nn5=substr($ns,8,1);
  372.         $nn6=substr($ns,10,1);
  373.         $nn7=substr($ns,12,1);
  374.         $nn8=substr($ns,14,1);
  375.         $nn9=substr($ns,16,1);
  376.         $nn10=substr($ns,18,1);
  377.         //$nn11=substr($ns,20,1);
  378.         //$nn12=substr($ns,22,1);
  379.         //$nf=$n1.$n2.$n3.$n4.$n5.$n6.$n7.$n8.$n9.$n10.$n11.$n12; 
  380.         //$nse=$nn1.$nn2.$nn3.$nn4.$nn5.$nn6.$nn7.$nn8.$nn9.$nn10.$nn11.$nn12;
  381.        
  382.         $nf=$n1.$n2.$n3.$n4.$n5.$n6.$n7.$n8.$n9.$n10; 
  383.         $nse=$nn1.$nn2.$nn3.$nn4.$nn5.$nn6.$nn7.$nn8.$nn9.$nn10;
  384.         $normaltoswap=$nf.$nse;
  385.         return $normaltoswap;
  386. }
  387.  
  388. /**
  389.  * @param string $product_key_normal
  390.  * @param string $fullfillment_no
  391.  * 
  392.  * @return string
  393.  */
  394.  
  395. function add_productkey_with_fullfillment_no($product_key_normal,$fullfillment_no='0001'){
  396.         $swap_to_last=$product_key_normal[2];$product_key_normal[2]=$fullfillment_no[0];
  397.         $swap_to_last.=$product_key_normal[4];$product_key_normal[4]=$fullfillment_no[1];
  398.         $swap_to_last.=$product_key_normal[11];$product_key_normal[11]=$fullfillment_no[2];
  399.         $swap_to_last.=$product_key_normal[13];$product_key_normal[13]=$fullfillment_no[3];
  400.         $product_key_normal=$product_key_normal.$swap_to_last;
  401.        
  402.         if (strlen($product_key_normal)<24){
  403.                 //Note: For the proper value - $eproductkey can be 24
  404.                 throw new ErrorException("Invalid eproductkey after fullfillment no added :".$product_key_normal.": of length=".strlen($product_key_normal));
  405.         }
  406.         return $product_key_normal;
  407. }
  408.  
  409. /**
  410.  * @param string $shop_name
  411.  * @param string $order_no
  412.  * @param string $hdd_key
  413.  * @param string $product_id
  414.  * @param int $fullfillment_no
  415.  * 
  416.  * @return string
  417.  */
  418. function generate_product_key($shop_name,$order_no,$hdd_key,$product_id,$fullfillment_no){
  419.         $product_key_normal=do_encryption_customername($shop_name);
  420.         $product_key_normal.=do_encryption_order($order_no);
  421.         $product_key_normal.=do_encryption_hdd($hdd_key);
  422.         $product_key_normal.='1';
  423.         $product_key_normal.=do_encryption_prodid($product_id);             
  424.      $product_key=do_encryption_productkey_ns($product_key_normal);
  425.      $fullfillment_no=substr("0000".$fullfillment_no,-4);
  426.         $product_key=add_productkey_with_fullfillment_no($product_key,$fullfillment_no);
  427.         /* should be of length 24 */
  428.         return         $product_key;
  429. }
  430. /**
  431.  * @param string $eproductkey_user
  432.  *
  433.  * @return string
  434.  */
  435. function do_encryption_productkey_sn($eproductkey_user){ 
  436.         $swaptonormal='';
  437.         $l1=strlen($eproductkey_user);
  438.         if($l1==20){
  439.                 $sn=$eproductkey_user;
  440.                 $p1=substr($sn,0,10);
  441.                 $p2=substr($sn,10,10);
  442.                 $sn1=substr($p2,0,1).substr($p1,0,1);
  443.                 $sn2=substr($p2,1,1).substr($p1,1,1);
  444.                 $sn3=substr($p2,2,1).substr($p1,2,1);
  445.                 $sn4=substr($p2,3,1).substr($p1,3,1);
  446.                 $sn5=substr($p2,4,1).substr($p1,4,1);
  447.                $sn6=substr($p2,5,1).substr($p1,5,1);
  448.                $sn7=substr($p2,6,1).substr($p1,6,1);
  449.                $sn8=substr($p2,7,1).substr($p1,7,1);
  450.                $sn9=substr($p2,8,1).substr($p1,8,1);
  451.                $sn10=substr($p2,9,1).substr($p1,9,1);
  452.                $swaptonormal=$sn1.$sn2.$sn3.$sn4.$sn5.$sn6.$sn7.$sn8.$sn9.$sn10;
  453.        }
  454.        $swaptonormal=strrev($swaptonormal);
  455.        return $swaptonormal;
  456. }
  457.  
  458.  
  459. /**
  460.  * @param string $enoclients
  461.  * 
  462.  * @return string
  463.  */
  464. function do_clientno_normal($enoclients){
  465.         $sProdID='';
  466.  
  467.         $sProdID =$sProdID.chr(ord(substr($enoclients,0,1))-20);
  468.         $sProdID =$sProdID.chr(ord(substr($enoclients,1,1))-25);
  469.     return $sProdID;
  470. }
  471.  
  472.  
  473. /**
  474.  * @param string $ohdd
  475.  * 
  476.  * @return string
  477.  */
  478. function do_encryption_hdd($ohdd){
  479.         $ltmp2 = 0;
  480.         for( $i = 0;$i<strlen($ohdd);$i++){
  481.             $ltmp2 = ($ltmp2 + ord(substr($ohdd,$i, 1))+13);
  482.         }
  483.         if($ltmp2 <= 99){$ltmp2 = $ltmp2 + 555;}
  484.         elseif ($ltmp2 > 99){$ltmp2 =substr($ltmp2,-3);}
  485.         $oehdd = $ltmp2;
  486.         return "$oehdd";
  487. }
  488.  
  489.  
  490. /**
  491.  * @param string $ecustomername_sn
  492.  * 
  493.  * @return string
  494.  */
  495. function do_activation_customername($ecustomername_sn){
  496.         $varstr1 = $ecustomername_sn;
  497.         $Tmp_Str1 = chr(ord(substr($varstr1, 0, 1)) + 29) . chr(ord(substr($varstr1, 1, 1)) + 33) . chr(ord(substr($varstr1, 2, 1)) + 23) . chr(ord(substr($varstr1, 3, 1)) + 17);
  498.         $acustomername = $Tmp_Str1;
  499.         return $acustomername;   
  500. }
  501.  
  502. /** 
  503.  * @param string $eorderno_sn
  504.  * 
  505.  * @return string
  506.  */
  507.  
  508. function do_activation_orderno($eorderno_sn){
  509.         $varstr = $eorderno_sn;
  510.         $Tmp_Str = chr(ord(substr($varstr, 0, 1)) + 28) . chr(ord(substr($varstr, 1, 1)) + 32) . chr(ord(substr($varstr, 2, 1)) + 22) . chr(ord(substr($varstr, 3, 1)) + 18);
  511.         $aorderno = $Tmp_Str;
  512.         return $aorderno;   
  513. }
  514.  
  515.  
  516. /**
  517.  * @param string $ehdd_sn
  518.  * 
  519.  * @return string
  520.  */
  521. function do_activation_hdd($ehdd_sn){
  522.         $varstr2 = $ehdd_sn;
  523.         $Tmp_Str2 = chr(ord(substr($varstr2, 0, 1)) + 27) . chr(ord(substr($varstr2, 1, 1)) + 31) . chr(ord(substr($varstr2, 2, 1)) + 21) . chr(ord(substr($varstr2, 3, 1)) + 19);
  524.        $ahdd = $Tmp_Str2;
  525.        return $ahdd;   
  526. }
  527.  
  528.  
  529.  
  530. /**
  531.  * Activation code generation algorithm for 4 & 5th part
  532.  *
  533.  * @param string $eprodcode0_sn
  534.  * @param string $pcode
  535.  * 
  536.  * @return string
  537.  */
  538. function do_activation_prodid0($eprodcode0_sn,$pcode=null){ 
  539.         $a0=substr($eprodcode0_sn,0,1);/*char 1*/
  540.         if($a0=='D'){$a0=0;} 
  541.         elseif($a0=='G'){$a0=1;} 
  542.         elseif($a0=='F'){$a0=1;} 
  543.         elseif($a0=='H'){$a0=2;} 
  544.         elseif($a0=='J'){$a0=3;} 
  545.         elseif($a0=='P'){$a0=4;} 
  546.         elseif($a0=='C'){$a0=5;} 
  547.         elseif($a0=='E'){$a0=6;} 
  548.         elseif($a0=='N'){$a0=7;}        //done on sep 8th //Remove pcode 100 on May 23 2007
  549.         elseif($a0=='T'){$a0=7;}
  550.         elseif($a0=='Q'){$a0=8;}       // changes done on 06-11-06//check in on 24-11-06 (rpos super)
  551.         elseif($a0=='K'){$a0=9;} 
  552.         $akp0=$a0; 
  553.        
  554.        $a1=substr($eprodcode0_sn,1,1);/* char 2 */
  555.         if($a1=='G'){$a1=0;} 
  556.         elseif($a1=='I'){$a1=1;}   
  557.         elseif($a1=='K'){$a1=2;} 
  558.         elseif($a1=='M'){$a1=3;} 
  559.         elseif($a1=='O'){$a1=4;} 
  560.         elseif($a1=='H'){$a1=5;} 
  561.         elseif($a1=='J'){$a1=6;} 
  562.         elseif($a1=='L'){$a1=7;} 
  563.         elseif($a1=='N'){$a1=8;} 
  564.         elseif($a1=='P'){$a1=9;} 
  565.         $akp1=$a1; 
  566.         $a2=substr($eprodcode0_sn,2,1);/* char 3*/
  567.         if($a2=='E'){$a2=0;} 
  568.         elseif($a2=='G'){$a2=1;}   
  569.         elseif($a2=='I'){$a2=2;} 
  570.         elseif($a2=='K'){$a2=3;} 
  571.         elseif($a2=='M'){$a2=4;} 
  572.         elseif($a2=='F'){$a2=5;} 
  573.         elseif($a2=='H'){$a2=6;} 
  574.         elseif($a2=='J'){$a2=7;} 
  575.         elseif($a2=='L'){$a2=8;} 
  576.         elseif($a2=='N'){$a2=9;}
  577.         elseif($a2=='Q'){$a2=9;}  
  578.         $akp2=$a2; 
  579.         $a3=substr($eprodcode0_sn,3,1); /* char 4 */
  580.         if($a3=='H'){$a3=0;} 
  581.         elseif($a3=='J'){$a3=1;}
  582.         elseif($a3=='L'){$a3=2;} 
  583.         elseif($a3=='N'){$a3=3;} 
  584.         elseif($a3=='P'){$a3=4;} 
  585.         elseif($a3=='I'){$a3=5;} 
  586.         elseif($a3=='K'){$a3=6;} 
  587.         elseif($a3=='M'){$a3=7;} 
  588.         elseif($a3=='O'){$a3=8;} 
  589.         elseif($a3=='Q'){$a3=9;} 
  590.         $akp3=$a3; 
  591.         $prodcode4=$akp0.$akp1.$akp2.$akp3;
  592.         return $prodcode4;   
  593. }
  594.  
  595. /**
  596.  * @param string $eprodcode1_sn
  597.  *
  598.  * @return string
  599.  */
  600. function do_activation_prodid1($eprodcode1_sn){
  601.         $a0=substr($eprodcode1_sn,0,1);/*char1*/
  602.         if($a0=='A'){$a0=0;} 
  603.         elseif($a0=='C'){$a0=1;}   
  604.         elseif($a0=='E'){$a0=2;} 
  605.         elseif($a0=='G'){$a0=3;} 
  606.         elseif($a0=='I'){$a0=4;} 
  607.         elseif($a0=='B'){$a0=5;} 
  608.         elseif($a0=='D'){$a0=6;} 
  609.         elseif($a0=='F'){$a0=7;} 
  610.         elseif($a0=='H'){$a0=8;} 
  611.         elseif($a0=='J'){$a0=9;} 
  612.         $akp4=$a0; 
  613.  
  614.       $a1=substr($eprodcode1_sn,1,1);/*char 2*/
  615.         if($a1=='C'){$a1=0;} 
  616.         elseif($a1=='E'){$a1=1;}   
  617.         elseif($a1=='G'){$a1=2;} 
  618.         elseif($a1=='I'){$a1=3;} 
  619.         elseif($a1=='K'){$a1=4;} 
  620.         elseif($a1=='D'){$a1=5;} 
  621.         elseif($a1=='F'){$a1=6;} 
  622.         elseif($a1=='H'){$a1=7;} 
  623.         elseif($a1=='J'){$a1=8;} 
  624.         elseif($a1=='L'){$a1=9;} 
  625.         $akp5=$a1;
  626.         $a2=substr($eprodcode1_sn,2,1);/*char 3*/
  627.         if($a2=='F'){$a2=0;} 
  628.         elseif($a2=='H'){$a2=1;}   
  629.         elseif($a2=='J'){$a2=2;}   
  630.         elseif($a2=='L'){$a2=3;}   
  631.         elseif($a2=='N'){$a2=4;}   
  632.         elseif($a2=='G'){$a2=5;}   
  633.         elseif($a2=='I'){$a2=6;}   
  634.         elseif($a2=='K'){$a2=7;}   
  635.         elseif($a2=='M'){$a2=8;}   
  636.         elseif($a2=='O'){$a2=9;}
  637.         elseif($a2=='Y'){$a2='L';}   
  638.         elseif($a2=='Z'){$a2='U';}   
  639.      $akp6=$a2;
  640.  
  641.         $a3=substr($eprodcode1_sn,3,1);/*char 4*/
  642.         if($a3=='B'){$a3=0;} 
  643.         elseif($a3=='D'){$a3=1;}   
  644.         elseif($a3=='F'){$a3=2;}   
  645.         elseif($a3=='H'){$a3=3;}   
  646.         elseif($a3=='J'){$a3=4;}   
  647.         elseif($a3=='C'){$a3=5;}   
  648.         elseif($a3=='E'){$a3=6;}   
  649.         elseif($a3=='G'){$a3=7;}   
  650.         elseif($a3=='I'){$a3=8;}   
  651.         elseif($a3=='K'){$a3=9;}
  652.         elseif($a3=='Y'){$a3='L';}   
  653.         elseif($a3=='X'){$a3='S';}
  654.         $akp7=$a3;
  655.         $prodcode5=$akp4.$akp5.$akp6.$akp7; 
  656.     return $prodcode5; 
  657. }
  658.  
  659.  
  660. /**
  661.  * @param string $fullfill
  662.  *
  663.  * @return string
  664.  */
  665. function do_ak_orderfullfillmentno($fullfill){
  666.         if(strlen($fullfill)<4){
  667.                 $femt="0000";
  668.                 $fullfill=$femt.$fullfill;
  669.                 $fullfill=substr($fullfill,-4);
  670.         }
  671.         $p1=substr($fullfill,0,1);
  672.         if($p1==0){$p1=ord($p1)+19; $p1=chr($p1);}
  673.         elseif($p1==1){$p1=ord($p1)+21; $p1=chr($p1);}
  674.         elseif($p1==2){$p1=ord($p1)+23; $p1=chr($p1);}
  675.         elseif($p1==3){$p1=ord($p1)+25;$p1=chr($p1);}
  676.         elseif($p1==4){$p1=ord($p1)+27;$p1=chr($p1);}
  677.         elseif($p1==5){$p1=ord($p1)+30;$p1=chr($p1);}
  678.         elseif($p1==6){$p1=ord($p1)+27;$p1=chr($p1);}
  679.         elseif($p1==7){$p1=ord($p1)+25;$p1=chr($p1);}
  680.         elseif($p1==8){$p1=ord($p1)+21;$p1=chr($p1);}
  681.         elseif($p1==9){$p1=ord($p1)+18;$p1=chr($p1);}
  682.         $pfirst=$p1;
  683.         $p2=substr($fullfill,1,1);/*second digit */
  684.         if($p2==0){$p2=ord($p2)+34;  $p2=chr($p2);}
  685.         elseif($p2==1){$p2=ord($p2)+32;  $p2=chr($p2);}
  686.         elseif($p2==2){$p2=ord($p2)+30;  $p2=chr($p2);}
  687.         elseif($p2==3){$p2=ord($p2)+28;  $p2=chr($p2);}
  688.         elseif($p2==4){$p2=ord($p2)+26;  $p2=chr($p2);}
  689.         elseif($p2==5){$p2=ord($p2)+24;  $p2=chr($p2);}
  690.         elseif($p2==6){$p2=ord($p2)+22;  $p2=chr($p2);}
  691.         elseif($p2==7){$p2=ord($p2)+20;  $p2=chr($p2);}
  692.         elseif($p2==8){$p2=ord($p2)+18;  $p2=chr($p2);}
  693.         elseif($p2==9){$p2=ord($p2)+16;  $p2=chr($p2);}
  694.         $psecond=$p2;
  695.         $p3=substr($fullfill,2,1);/*3rd digit*/
  696.         if($p3==0){$p3=ord($p3)+17; $p3=chr($p3);}
  697.         elseif($p3==1){$p3=ord($p3)+18;  $p3=chr($p3);}
  698.         elseif($p3==2){$p3=ord($p3)+20;  $p3=chr($p3);}
  699.         elseif($p3==3){$p3=ord($p3)+22;  $p3=chr($p3);}
  700.         elseif($p3==4){$p3=ord($p3)+24;  $p3=chr($p3);}
  701.         elseif($p3==5){$p3=ord($p3)+26;  $p3=chr($p3);}
  702.         elseif($p3==6){$p3=ord($p3)+28;  $p3=chr($p3);}
  703.         elseif($p3==7){$p3=ord($p3)+30;  $p3=chr($p3);}
  704.         elseif($p3==8){$p3=ord($p3)+32;  $p3=chr($p3);}
  705.         elseif($p3==9){$p3=ord($p3)+33;  $p3=chr($p3);}
  706.         $pthird=$p3;
  707.         $p4=substr($fullfill,3,1);/*4th digit*/
  708.         if($p4==0){$p4=ord($p4)+18;  $p4=chr($p4);}
  709.         elseif($p4==1){$p4=ord($p4)+20;  $p4=chr($p4);}
  710.         elseif($p4==2){$p4=ord($p4)+25;  $p4=chr($p4);}
  711.         elseif($p4==3){$p4=ord($p4)+27;  $p4=chr($p4);}
  712.         elseif($p4==4){$p4=ord($p4)+30;  $p4=chr($p4);}
  713.         elseif($p4==5){$p4=ord($p4)+27;  $p4=chr($p4);}
  714.         elseif($p4==6){$p4=ord($p4)+25;  $p4=chr($p4);}
  715.         elseif($p4==7){$p4=ord($p4)+28;  $p4=chr($p4);}
  716.         elseif($p4==8){$p4=ord($p4)+21;  $p4=chr($p4);}
  717.         elseif($p4==9){$p4=ord($p4)+19;  $p4=chr($p4);}
  718.         $pfourth=$p4;
  719.         $sixactivekey6 = $p1.$p2.$p3.$p4;
  720.         return $sixactivekey6;
  721. }
  722.  
  723. /**
  724.  * @param string $noclients
  725.  *
  726.  * @return string
  727.  */
  728. function do_ak_noc_server($noclients){
  729.         if((int)$noclients>99){        
  730.                 $albhabet_sno=substr($noclients,0,2);
  731.                 $albhabet_sno_later=substr($noclients,2,1);
  732.         }
  733.         $p1=substr($noclients,0,1);/*first digit*/
  734.         if($p1==0){$p1=ord($p1)+19;  $p1=chr($p1);}
  735.         elseif($p1==1){$p1=ord($p1)+21;  $p1=chr($p1);}
  736.         elseif($p1==2){$p1=ord($p1)+23;  $p1=chr($p1);}
  737.         elseif($p1==3){$p1=ord($p1)+25;  $p1=chr($p1);}
  738.         elseif($p1==4){$p1=ord($p1)+27;  $p1=chr($p1);}
  739.         elseif($p1==5){$p1=ord($p1)+30;  $p1=chr($p1);}
  740.         elseif($p1==6){$p1=ord($p1)+27;  $p1=chr($p1);}
  741.         elseif($p1==7){$p1=ord($p1)+25;  $p1=chr($p1);}
  742.         elseif($p1==8){$p1=ord($p1)+21;  $p1=chr($p1);}
  743.         elseif($p1==9){$p1=ord($p1)+18;  $p1=chr($p1);}
  744.         $p1=$p1;
  745.         $p2=substr($noclients,1,1);/*Second  digit */
  746.         if($p2==0){$p2=ord($p2)+34;  $p2=chr($p2);}
  747.         elseif($p2==1){$p2=ord($p2)+32;  $p2=chr($p2);}
  748.         elseif($p2==2){$p2=ord($p2)+30;  $p2=chr($p2);}
  749.         elseif($p2==3){$p2=ord($p2)+28;  $p2=chr($p2);}
  750.         elseif($p2==4){$p2=ord($p2)+26;  $p2=chr($p2);}
  751.         elseif($p2==5){$p2=ord($p2)+24;  $p2=chr($p2);}
  752.         elseif($p2==6){$p2=ord($p2)+22;  $p2=chr($p2);}
  753.         elseif($p2==7){$p2=ord($p2)+20;  $p2=chr($p2);}
  754.         elseif($p2==8){$p2=ord($p2)+18;  $p2=chr($p2);}
  755.         elseif($p2==9){$p2=ord($p2)+16;  $p2=chr($p2);}
  756.         $p2=$p2;
  757.         $noclients = $p1.$p2;
  758.         return $noclients;
  759. }
  760.  
  761.  
  762. /**
  763.  *  normal activation key to swap 
  764.  *
  765.  * @param string $activationkey
  766.  *
  767.  * @return string
  768.  */
  769. function do_activationkey_ns($activationkey){ 
  770.         $ns=$activationkey;
  771.        $ns=strrev($ns);
  772.         $n1=substr($ns,1,1);
  773.         $n2=substr($ns,3,1); 
  774.         $n3=substr($ns,5,1);
  775.         $n4=substr($ns,7,1);
  776.         $n5=substr($ns,9,1);
  777.         $n6=substr($ns,11,1);
  778.         $n7=substr($ns,13,1);
  779.         $n8=substr($ns,15,1);
  780.         $n9=substr($ns,17,1);
  781.         $n10=substr($ns,19,1);
  782.         $n11=substr($ns,21,1);
  783.         $n12=substr($ns,23,1);
  784.         $n13=substr($ns,25,1);
  785.         $n14=substr($ns,27,1);
  786.         $n15=substr($ns,29,1);
  787.         $n16=substr($ns,31,1);
  788.         $n17=substr($ns,33,1);
  789.         $n18=substr($ns,35,1);
  790.         $nn1=substr($ns,0,1);
  791.         $nn2=substr($ns,2,1); 
  792.         $nn3=substr($ns,4,1);
  793.         $nn4=substr($ns,6,1);
  794.         $nn5=substr($ns,8,1);
  795.         $nn6=substr($ns,10,1);
  796.         $nn7=substr($ns,12,1);
  797.         $nn8=substr($ns,14,1);
  798.         $nn9=substr($ns,16,1);
  799.         $nn10=substr($ns,18,1);
  800.         $nn11=substr($ns,20,1);
  801.         $nn12=substr($ns,22,1);
  802.         $nn13=substr($ns,24,1);
  803.         $nn14=substr($ns,26,1);
  804.         $nn15=substr($ns,28,1);
  805.         $nn16=substr($ns,30,1);
  806.         $nn17=substr($ns,32,1);
  807.         $nn18=substr($ns,34,1);
  808.         $nf=$n1.$n2.$n3.$n4.$n5.$n6.$n7.$n8.$n9.$n10.$n11.$n12.$n13.$n14.$n15.$n16.$n17.$n18; 
  809.        $nse=$nn1.$nn2.$nn3.$nn4.$nn5.$nn6.$nn7.$nn8.$nn9.$nn10.$nn11.$nn12.$nn13.$nn14.$nn15.$nn16.$nn17.$nn18;
  810.        $normaltoswap_a=$nf.$nse;
  811.         return $normaltoswap_a;
  812. }
  813.  
  814. /**
  815.  * swap to normal
  816.  * this swap is for server 26 digit activation key
  817.  *
  818.  * @param string $normaltoswap_a
  819.  * 
  820.  * @return string
  821.  */
  822. function do_activationkey_sn($normaltoswap_a){ 
  823.         $sn=$normaltoswap_a;
  824.         $p1=substr($sn,0,13);
  825.         $p2=substr($sn,13,13);
  826.         $sn1=substr($p2,0,1).substr($p1,0,1);
  827.         $sn2=substr($p2,1,1).substr($p1,1,1);
  828.         $sn3=substr($p2,2,1).substr($p1,2,1);
  829.         $sn4=substr($p2,3,1).substr($p1,3,1);
  830.         $sn5=substr($p2,4,1).substr($p1,4,1);
  831.         $sn6=substr($p2,5,1).substr($p1,5,1);
  832.         $sn7=substr($p2,6,1).substr($p1,6,1);
  833.         $sn8=substr($p2,7,1).substr($p1,7,1);
  834.         $sn9=substr($p2,8,1).substr($p1,8,1);
  835.         $sn10=substr($p2,9,1).substr($p1,9,1);
  836.         $sn11=substr($p2,10,1).substr($p1,10,1);
  837.         $sn12=substr($p2,11,1).substr($p1,11,1);
  838.         $sn13=substr($p2,12,1).substr($p1,12,1);
  839.         $swaptonormal_a=$sn1.$sn2.$sn3.$sn4.$sn5.$sn6.$sn7.$sn8.$sn9.$sn10.$sn11.$sn12.$sn13;
  840.         $swaptonormal_a=strrev($swaptonormal_a);
  841.         return $swaptonormal_a;
  842. }
  843.  
  844. /**
  845.  * @param string $ltmp0
  846.  *
  847.  * @return string
  848.  */
  849. function do_ak_graceperiod($ltmp0){
  850.         $p1=substr($ltmp0,0,1);
  851.         $tp1=substr($ltmp0,0,1);
  852.         if($p1==0){$p1=ord($p1)+19;       $p1=chr($p1);       }
  853.         elseif($p1==1){$p1=ord($p1)+21;   $p1=chr($p1);       }
  854.         elseif($p1==2){$p1=ord($p1)+23;   $p1=chr($p1);       }
  855.         elseif($p1==3){$p1=ord($p1)+25;   $p1=chr($p1);       }
  856.         elseif($p1==4){$p1=ord($p1)+27;   $p1=chr($p1);       }
  857.         elseif($p1==5){$p1=ord($p1)+30;   $p1=chr($p1);       }
  858.         elseif($p1==6){$p1=ord($p1)+27;   $p1=chr($p1);       }
  859.         elseif($p1==7){$p1=ord($p1)+25;   $p1=chr($p1);       }
  860.         elseif($p1==8){$p1=ord($p1)+21;   $p1=chr($p1);       }
  861.         elseif($p1==9){$p1=ord($p1)+18;   $p1=chr($p1);       }
  862.         $pfirst=$p1;
  863.         $p2=substr($ltmp0,1,1);
  864.         $tp2=substr($ltmp0,1,1);
  865.         if($p2==0){       $p2=ord($p2)+18;      $p2=chr($p2);       }
  866.         elseif($p2==1){   $p2=ord($p2)+20;      $p2=chr($p2);       }
  867.         elseif($p2==2){   $p2=ord($p2)+25;      $p2=chr($p2);       }
  868.         elseif($p2==3){   $p2=ord($p2)+27;      $p2=chr($p2);       }
  869.         elseif($p2==4){   $p2=ord($p2)+30;      $p2=chr($p2);       }
  870.         elseif($p2==5){   $p2=ord($p2)+27;      $p2=chr($p2);       }
  871.         elseif($p2==6){   $p2=ord($p2)+25;      $p2=chr($p2);       }
  872.         elseif($p2==7){   $p2=ord($p2)+22;      $p2=chr($p2);       }
  873.         elseif($p2==8){   $p2=ord($p2)+18;      $p2=chr($p2);       }
  874.         elseif($p2==9){   $p2=ord($p2)+19;      $p2=chr($p2);       }
  875.         $psecond=$p2;
  876.         $p3=substr($ltmp0,2,1);
  877.         $tp3=substr($ltmp0,2,1);
  878.         if($p3==0){       $p3=ord($p3)+17;      $p3=chr($p3);       }
  879.         elseif($p3==1){   $p3=ord($p3)+18;      $p3=chr($p3);       }
  880.         elseif($p3==2){   $p3=ord($p3)+20;      $p3=chr($p3);       }
  881.         elseif($p3==3){   $p3=ord($p3)+22;      $p3=chr($p3);       }
  882.         elseif($p3==4){   $p3=ord($p3)+24;      $p3=chr($p3);       }
  883.         elseif($p3==5){   $p3=ord($p3)+26;      $p3=chr($p3);       }
  884.         elseif($p3==6){   $p3=ord($p3)+28;      $p3=chr($p3);       }
  885.         elseif($p3==7){   $p3=ord($p3)+30;      $p3=chr($p3);       }
  886.         elseif($p3==8){   $p3=ord($p3)+32;      $p3=chr($p3);       }
  887.         elseif($p3==9){   $p3=ord($p3)+33;      $p3=chr($p3);       }
  888.         $pthird=$p3;
  889.         $p4=substr($ltmp0,3,1);
  890.         $tp4=substr($ltmp0,3,1);
  891.         if($p4==0){       $p4=ord($p4)+34;      $p4=chr($p4);       }
  892.         elseif($p4==1){   $p4=ord($p4)+32;      $p4=chr($p4);       }
  893.         elseif($p4==2){   $p4=ord($p4)+30;      $p4=chr($p4);       }
  894.         elseif($p4==3){   $p4=ord($p4)+28;      $p4=chr($p4);       }
  895.         elseif($p4==4){   $p4=ord($p4)+26;      $p4=chr($p4);       }
  896.         elseif($p4==5){   $p4=ord($p4)+24;      $p4=chr($p4);       }
  897.         elseif($p4==6){   $p4=ord($p4)+22;      $p4=chr($p4);       }
  898.         elseif($p4==7){   $p4=ord($p4)+20;      $p4=chr($p4);       }
  899.         elseif($p4==8){   $p4=ord($p4)+18;      $p4=chr($p4);       }
  900.         elseif($p4==9){   $p4=ord($p4)+16;      $p4=chr($p4);       }
  901.         $pfourth=$p4;
  902.         $p5=substr($ltmp0,4,1);
  903.         $tp5=substr($ltmp0,4,1);
  904.         if($p5!=''){
  905.                 if($p5==0){  $p5=ord($p5)+19;  $p5=chr($p5);}
  906.                 elseif($p5==1){  $p5=ord($p5)+21;  $p5=chr($p5);}
  907.                 elseif($p5==2){  $p5=ord($p5)+23;  $p5=chr($p5);}
  908.                 elseif($p5==3){  $p5=ord($p5)+25;  $p5=chr($p5);}
  909.                 elseif($p5==4){  $p5=ord($p5)+27;  $p5=chr($p5);}
  910.                 elseif($p5==5){  $p5=ord($p5)+30;  $p5=chr($p5);}
  911.                 elseif($p5==6){  $p5=ord($p5)+27;  $p5=chr($p5);}
  912.                 elseif($p5==7){  $p5=ord($p5)+25;  $p5=chr($p5);}
  913.                 elseif($p5==8){  $p5=ord($p5)+21;  $p5=chr($p5);}
  914.                 elseif($p5==9){  $p5=ord($p5)+18;  $p5=chr($p5);}
  915.                 $pfifth=$p5;
  916.         }
  917.         $p6=substr($ltmp0,5,1);
  918.         $tp6=substr($ltmp0,5,1);
  919.         if($p6!=''){
  920.                 if($p6==0){  $p6=ord($p6)+18;  $p6=chr($p6);}
  921.                 elseif($p6==1){  $p6=ord($p6)+20;  $p6=chr($p6);}
  922.                 elseif($p6==2){  $p6=ord($p6)+25;  $p6=chr($p6);}
  923.                 elseif($p6==3){  $p6=ord($p6)+27;  $p6=chr($p6);}
  924.                 elseif($p6==4){  $p6=ord($p6)+30;  $p6=chr($p6);}
  925.                 elseif($p6==5){  $p6=ord($p6)+27;  $p6=chr($p6);}
  926.                 elseif($p6==6){  $p6=ord($p6)+25;  $p6=chr($p6);}
  927.                 elseif($p6==7){  $p6=ord($p6)+22;  $p6=chr($p6);}
  928.                 elseif($p6==8){  $p6=ord($p6)+18;  $p6=chr($p6);}
  929.                 elseif($p6==9){  $p6=ord($p6)+19;  $p6=chr($p6);}
  930.                 $psix=$p6;
  931.         }
  932.         $sixactivekey7 = $p1.$p2.$p3.$p4.$p5.$p6;
  933.         return $sixactivekey7;
  934. }
  935.  
  936.         /**
  937.          * @param string $minimum_version
  938.          * @param string $request_version
  939.          * 
  940.          * @return  boolean
  941.          * */
  942.        
  943.         function license_version_check_minimum($minimum_version,$request_version){
  944.                 $request_version=(string)str_replace('-','.',$request_version);
  945.                 $minimum_version=(string)str_replace('-','.',$minimum_version);
  946.  
  947.                 $request_version=(string)str_replace("RC","",$request_version);
  948.                 $minimum_version=(string)str_replace("RC","",$minimum_version);
  949.                 $request_version=(string)str_replace("SP",".",$request_version);
  950.                 $minimum_version=(string)str_replace("SP",".",$minimum_version);
  951.                                
  952.                 $r = version_compare($request_version,$minimum_version);
  953.                 if ($r <0){
  954.                         return false;
  955.                 }
  956.                 return true;
  957.         }
  958.        
  959.         /**
  960.          * @param string $lead_code
  961.          * @param string $order_no
  962.          *
  963.          * @return string[int]
  964.          */
  965.         function get_incharge_name_no($lead_code='',$order_no=''){
  966.                 $ret_name = /*. (string[int]) .*/array();
  967.                 $ret_name[0] = $ret_name[1] = $que1 = '';
  968.                 $sel_que = " select GEM_EMP_NAME, GEM_MOBILE from gft_emp_master ";
  969.                 if($lead_code!=''){
  970.                     $lead_own = get_valid_lead_owner($lead_code);
  971.                     if($lead_own==0){
  972.                         $lead_own = get_lead_mgmt_incharge('', '', 0, 0,100,$lead_code);
  973.                     }
  974.                         $que1 = " where GEM_EMP_ID='$lead_own' ";
  975.                 }else if ($order_no!=''){
  976.                         $que1 = " join gft_order_hdr on (GEM_EMP_ID = GOD_INCHARGE_EMP_ID ) ".
  977.                                         " where GOD_ORDER_NO='$order_no' and GEM_STATUS='A' ";
  978.                 }
  979.                 if($que1!='') {
  980.                         $res1 = execute_my_query($sel_que.$que1);
  981.                         if($row1 = mysqli_fetch_array($res1)){
  982.                                 $ret_name[0] = $row1['GEM_EMP_NAME'];
  983.                                 $ret_name[1] = $row1['GEM_MOBILE'];
  984.                         }
  985.                 }
  986.                 return $ret_name;
  987.         }
  988.        
  989.         /**
  990.          * @param string $lead_code
  991.          * @param int $vertical_id
  992.          * 
  993.          * @return void
  994.          */
  995.         function update_vertical_for_customer($lead_code,$vertical_id){
  996.                 $upquery = "update gft_lead_hdr set GLH_VERTICAL_CODE='$vertical_id' where GLH_LEAD_CODE='$lead_code'";
  997.                 if(!execute_my_query($upquery)){
  998.                         //error
  999.                 }
  1000.         }
  1001.  
  1002.  
  1003. /**
  1004.  * Used for old license
  1005.  *
  1006.  * @param string $product_key
  1007.  * 
  1008.  * @return string
  1009.  */
  1010. function getFullFillmentNumberFromProductKey($product_key){
  1011.         $pk=explode('-',$product_key);
  1012.         $prodkeyfull='';
  1013.         for($i=0;$i<count($pk);$i++){
  1014.                 $prodkeyfull.=$pk[$i];
  1015.         } 
  1016.  
  1017.         $fullfill_no='';
  1018.         if(strlen($prodkeyfull)==24){
  1019.                 //get_fullfillment_no  
  1020.                 $fullfill[0]=substr($prodkeyfull,2,1);
  1021.                 $fullfill[1]=substr($prodkeyfull,4,1);
  1022.                 $fullfill[2]=substr($prodkeyfull,11,1);
  1023.                 $fullfill[3]=substr($prodkeyfull,13,1);
  1024.                 //swaped pk     
  1025.                 $miss_p[0]=substr($prodkeyfull,20,1);   
  1026.                 $miss_p[1]=substr($prodkeyfull,21,1);
  1027.                 $miss_p[2]=substr($prodkeyfull,22,1);
  1028.                 $miss_p[3]=substr($prodkeyfull,23,1);   
  1029.                 $pr_arr=str_split($prodkeyfull,1);  
  1030.                 $pr_arr[2]=$miss_p[0];
  1031.                 $pr_arr[4]=$miss_p[1];
  1032.                 $pr_arr[11]=$miss_p[2];
  1033.                 $pr_arr[13]=$miss_p[3];
  1034.                 $prodkeyfull=implode("",$pr_arr);
  1035.                 $prodkeyfull=substr(implode("",$pr_arr),0,20);
  1036.                 $fullfill_no=implode("",$fullfill);
  1037.         }
  1038.         return $fullfill_no;
  1039. }
  1040.  
  1041. /**
  1042.  * @param int $code
  1043.  * @param string $group
  1044.  * @param string $fullfill_no
  1045.  *
  1046.  * @return string[int]
  1047.  */
  1048. function get_product_id($code,$group,$fullfill_no) {
  1049.         $return_array = /*. (string[int]) .*/array();
  1050.         $query= " select GLL_PRODUCT_ID,GLL_CLIENTS from gft_local_license_master where GLL_PRODUCT_FCODE='$code' and ".
  1051.                         " GLL_PRODUCT_GROUP='$group' and GLL_FULLFILLMENT_NO=$fullfill_no";
  1052.         $res = execute_my_query($query);
  1053.         if($row = mysqli_fetch_array($res)){
  1054.                 $return_array[0] = $row['GLL_PRODUCT_ID'];
  1055.                 $return_array[1] = $row['GLL_CLIENTS'];
  1056.         }
  1057.         return $return_array;
  1058. }
  1059.  
  1060. /**
  1061.  * @param string $order_no
  1062.  * @param string $fullfillment_no
  1063.  * @param string $pcode
  1064.  * @param string $pskew
  1065.  * 
  1066.  * @return string
  1067.  */
  1068. function get_lead_code_from_idendity($order_no, $fullfillment_no, $pcode, $pskew) {
  1069.         $int_val_of_fullfill_no = (int)$fullfillment_no;
  1070.         $query =" select GID_LEAD_CODE from gft_install_dtl_new ".
  1071.                         " join gft_product_master on (GPM_PRODUCT_CODE=GID_LIC_PCODE and GPM_PRODUCT_SKEW=GID_LIC_PSKEW)  ".
  1072.                         " where GID_ORDER_NO='$order_no' and GID_FULLFILLMENT_NO=$int_val_of_fullfill_no and GID_LIC_PCODE='$pcode' ".
  1073.                         " and (GID_LIC_PSKEW='$pskew' or GPM_REFERER_SKEW='$pskew') ";
  1074.         $res = execute_my_query($query);
  1075.         if($row_data = mysqli_fetch_array($res)){
  1076.                 return $row_data['GID_LEAD_CODE'];
  1077.         }
  1078.         return '';
  1079. }
  1080.  
  1081. /**
  1082.  * @param string $order_no
  1083.  * @param string $fullfillment_no
  1084.  * 
  1085.  * @return boolean
  1086.  */
  1087. function is_dft_order($order_no,$fullfillment_no){
  1088.         $fullfill_no = (int)$fullfillment_no;
  1089.         $sql1 = " select GOP_ORDER_NO from gft_order_product_dtl join gft_order_hdr on (GOD_ORDER_NO=GOP_ORDER_NO) ".
  1090.                         " where GOP_ORDER_NO='$order_no' and GOP_FULLFILLMENT_NO=$fullfill_no and GOP_PRODUCT_CODE=120 and GOD_ORDER_STATUS='A' ";
  1091.         $res1 = execute_my_query($sql1);
  1092.         if(mysqli_num_rows($res1) > 0){
  1093.                 return true;
  1094.         }
  1095.         return false;
  1096. }
  1097.  
  1098. /**
  1099.  * @param string  $identity
  1100.  * 
  1101.  * @return boolean
  1102.  */
  1103. function is_local_user_identity($identity){
  1104.     $mob_no = substr($identity, 0,10);
  1105.     $emp_id = (int)substr($identity, 10,5);
  1106.     $qr1 = execute_my_query(" select GEM_EMP_ID from gft_emp_master where GEM_MOBILE='$mob_no' and GEM_EMP_ID='$emp_id' and GEM_STATUS='A' ");
  1107.     if(mysqli_num_rows($qr1) > 0){
  1108.         return true;
  1109.     }
  1110.     return false;
  1111. }
  1112.  
  1113. /**
  1114.  * @param string $idendity
  1115.  * 
  1116.  * @return string[int]
  1117.  */
  1118. function get_details_from_idendity($idendity) {
  1119.     global $secure_conn;
  1120.         $arr_dtl = /*. (string[int]) .*/array();
  1121.         if(strlen($idendity)!=27){
  1122.                 return $arr_dtl;
  1123.         }
  1124.         $order_no = substr($idendity, 0, 15);
  1125.         $fullfillment_no = substr($idendity, 15, 4);
  1126.         $pcode = substr($idendity, 19, 3);
  1127.         $pskew = substr($idendity, 22, 2).".".substr($idendity, 24, 3);
  1128.         if( is_dft_order($order_no,$fullfillment_no) && ($pcode!='120') ){ //dft order no with Base product license
  1129.                 $pcode = '120';
  1130.                 $pskew = "01.0SL";
  1131.         }
  1132.         $query =" select GID_LEAD_CODE,GID_LIC_PSKEW,GID_INSTALL_ID,GID_NO_CLIENTS,GID_LIC_ORDER_NO,GPM_PRODUCT_TYPE,GID_INSTALL_DATE ".
  1133.                         " from gft_install_dtl_new ".
  1134.                         " join gft_product_master on (GPM_PRODUCT_CODE=GID_LIC_PCODE and GPM_PRODUCT_SKEW=GID_LIC_PSKEW)  ".
  1135.                         " where GID_ORDER_NO={order_no} and GID_FULLFILLMENT_NO={fullfillment_no} and GID_LIC_PCODE={pcode} ".
  1136.                         " and (GID_LIC_PSKEW={pskew} or GPM_REFERER_SKEW={pskew}) and GID_STATUS in ('A','S') ";
  1137.         $stmt = $secure_conn->preparedStatement($query);
  1138.         $stmt->setParam("order_no",$order_no);
  1139.         $stmt->setParam("fullfillment_no",$fullfillment_no);
  1140.         $stmt->setParam("pcode",$pcode);
  1141.         $stmt->setParam("pskew",$pskew);
  1142.         $select_res = $stmt->executeQuery();
  1143.         if($select_res->numRows()>0 && $row_data=$select_res->fetchArray()) {
  1144.                 $arr_dtl[0] = $row_data['GID_LEAD_CODE'];
  1145.                 $arr_dtl[1] = $row_data['GID_INSTALL_ID'];
  1146.                 $arr_dtl[2] = $order_no;
  1147.                 $arr_dtl[3] = $fullfillment_no;
  1148.                 $arr_dtl[4] = $pcode;
  1149.                 $arr_dtl[5] = $row_data['GID_LIC_PSKEW'];
  1150.                 $arr_dtl[6] = $row_data['GID_NO_CLIENTS'];
  1151.                 $arr_dtl[7] = $row_data['GID_LIC_ORDER_NO'];
  1152.                 $arr_dtl[8] = $row_data['GPM_PRODUCT_TYPE'];
  1153.                 $arr_dtl[9] = $row_data['GID_INSTALL_DATE'];
  1154.         }
  1155.         return $arr_dtl;
  1156. }
  1157.  
  1158. /**
  1159.  * @param string $lead_code
  1160.  * @param string $check_status
  1161.  * 
  1162.  * @return boolean
  1163.  */
  1164. function system_assessment_available($lead_code,$check_status=""){
  1165.         $where_con      =       "";
  1166.         if($check_status!=""){
  1167.                 $where_con      =       " AND HW_STATUS='$check_status'";
  1168.         }
  1169.         $query_res = execute_my_query("select HW_CUST_ID from gft_hwassessment_info where HW_CUST_ID='$lead_code$where_con");
  1170.         if(mysqli_num_rows($query_res) > 0){
  1171.                 return true;
  1172.         }
  1173.         return false;
  1174. }
  1175.  
  1176. /**
  1177.  * @param string $xmlRaw
  1178.  * @param string[int] $xmlFieldNames
  1179.  * 
  1180.  * @return string[string]
  1181.  */
  1182. function give_parsed_xml($xmlRaw,$xmlFieldNames){
  1183.         $parsedXML=/*. (string[string]) .*/ array();
  1184.         foreach ($xmlFieldNames as $xmlField) {
  1185.                 if(strpos($xmlRaw,"<$xmlField>")!==false){
  1186.                         $parsedXML[$xmlField]=substr($xmlRaw,
  1187.                                         strpos($xmlRaw,"<$xmlField>")+strlen("<$xmlField>"),
  1188.                                         strpos($xmlRaw,"</$xmlField>")-strlen("<$xmlField>")
  1189.                                         -strpos($xmlRaw,"<$xmlField>"));
  1190.                 }
  1191.                 foreach($parsedXML as $key=>$value){
  1192.                         if(strpos($value,"<![CDATA[")!==false){
  1193.                                 $value = str_replace(array("<![CDATA[","]]>"), "", $value);
  1194.                         }
  1195.                         $parsedXML[$key]=trim($value);
  1196.                 }
  1197.         }
  1198.         return $parsedXML;
  1199. }
  1200.  
  1201. /**
  1202.  * @param string $productcode
  1203.  * @param string $skew_group
  1204.  * 
  1205.  * @return string
  1206.  */
  1207. function get_product_manager($productcode, $skew_group){
  1208.     global $secure_conn;
  1209.         $sel_que = "select GPG_PRODUCT_MANAGER from gft_product_group_master where gpg_product_family_code={productcode} and gpg_skew={skew_group} ";
  1210.         $stmt = $secure_conn->preparedStatement($sel_que);
  1211.         $stmt->setParam("productcode",$productcode);
  1212.         $stmt->setParam("skew_group",$skew_group);
  1213.         $select_res = $stmt->executeQuery();
  1214.         if($select_res->numRows()>0 && $row1=$select_res->fetchArray()) {
  1215.                 return $row1['GPG_PRODUCT_MANAGER'];  
  1216.         }
  1217.         return '';
  1218. }
  1219.  
  1220. /**
  1221.  * @param string $order_no
  1222.  * @param string $fullfill_no
  1223.  * @param string $lic_pcode
  1224.  * @param string $lic_pskew
  1225.  * @param string $cust_id
  1226.  * 
  1227.  * @return string 
  1228.  */
  1229. function get_db_password($order_no, $fullfill_no, $lic_pcode, $lic_pskew, $cust_id){
  1230.         $quer = " select GID_DB_PASSWORD from gft_install_dtl_new where GID_ORDER_NO='$order_no' and GID_FULLFILLMENT_NO=$fullfill_no ".
  1231.                         " and GID_LIC_PCODE='$lic_pcode' and GID_LIC_PSKEW='$lic_pskew' ";
  1232.         $resul = execute_my_query($quer);
  1233.         if($row1 = mysqli_fetch_array($resul)){
  1234.                 if($row1['GID_DB_PASSWORD']!=''){
  1235.                         return $row1['GID_DB_PASSWORD'];
  1236.                 }
  1237.         }
  1238.         $swap_cust_id = substr(str_shuffle($cust_id),-4);
  1239.         $c1 = chr(65+(((int)substr($swap_cust_id, 0,1))*2));
  1240.         $c2 = chr(65+(((int)substr($swap_cust_id, 1,1))*2));
  1241.         $c3 = chr(65+(((int)substr($swap_cust_id, 2,1))*2));
  1242.         $c4 = chr(65+(((int)substr($swap_cust_id, 3,1))*2));
  1243.         $db_password = str_shuffle(date('Ym').$c1.$c4.$c2.$c3);
  1244.         return $db_password;
  1245. }
  1246.  
  1247. /**
  1248.  * @param string $input_data
  1249.  * @param string $ret_data
  1250.  * @param string $ret_encrypt_data
  1251.  * @param string $lead_code
  1252.  * @param string $req_type
  1253.  * @param string $err_code
  1254.  * @param string $err_msg
  1255.  * @param string $decrpted_input_data
  1256.  * @param string $expiry_date
  1257.  *
  1258.  * @return void
  1259.  */
  1260. function log_request($input_data, $ret_data, $ret_encrypt_data, $lead_code, $req_type, $err_code='', $err_msg='',$decrpted_input_data='',$expiry_date=''){
  1261.         global $log;
  1262.         $ins_request=/*. (mixed[string]) .*/array();
  1263. //      $ins_request['GLC_REQUEST_ID']='';
  1264.         $ins_request['GLC_ONLINE_CONTENT']=$input_data;
  1265.         $ins_request['GLC_REQUEST_TIME']=date('Y-m-d H:i:s');
  1266.         $ins_request['GLC_RETURN_DATA']=$ret_data;
  1267. //      $ins_request['GLC_RETURN_ENCRYPTED_DATA']=$ret_encrypt_data;
  1268.         $ins_request['GLC_LEAD_CODE']=$lead_code;
  1269.         $ins_request['GLC_IP_ADDRESS']=isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:gethostbyname(gethostname());
  1270.         $ins_request['GLC_REQUEST_PURPOSE_ID']=$req_type;
  1271.         $ins_request['GLC_ERROR_CODE']=$err_code;
  1272.         $ins_request['GLC_ERROR_MESSAGE']=$err_msg;
  1273.         $ins_request['GLC_DECRYPTED_CONTENT']=$decrpted_input_data;
  1274.         $ins_request['GLC_PROCESSING_TIME']=getDeltaTime();
  1275.         if($expiry_date!=''){
  1276.                 $ins_request['GLC_EXPIRY_DATE'] = $expiry_date;
  1277.         }
  1278.         //array_update_tables_common($ins_request,'gft_lic_request',null,null,SALES_DUMMY_ID,null,null,$ins_request);
  1279.         $log->logInfo($ins_request,null,true);
  1280. }
  1281.  
  1282. /**
  1283.  * @param int $lead_code
  1284.  * 
  1285.  * @return string
  1286.  */
  1287. function contact_info_for_authentication($lead_code){
  1288.         $sel_query = " select group_concat(distinct GCC_CONTACT_NO order by GCC_CONTACT_TYPE desc) as contact_info ".
  1289.                                  " from gft_lead_hdr join gft_customer_contact_dtl on (GCC_LEAD_CODE=GLH_LEAD_CODE) ".
  1290.                                  " left join gft_contact_dtl_group_map on (GCC_ID=GCG_CONTACT_ID) ".
  1291.                                  " where GLH_LEAD_CODE='$lead_code' and (gcc_designation=1 or GCG_GROUP_ID=3) ".
  1292.                                  " and if(GLH_COUNTRY='India',GCC_CONTACT_TYPE in (1,4), GCC_CONTACT_TYPE in (4)) ".
  1293.                                  " group by GLH_LEAD_CODE ";
  1294.         $res_query      = execute_my_query($sel_query);
  1295.         if($row_data = mysqli_fetch_array($res_query)){
  1296.                 return $row_data['contact_info'];
  1297.         }
  1298.         return '';
  1299. }
  1300.  
  1301. /**
  1302.  * @param int $install_id
  1303.  * 
  1304.  * @return string
  1305.  */
  1306. function get_last_reinstall_date($install_id){
  1307.         $query = " select max(GRD_REINSTALL_DATE) as reins_date from gft_reinstall_dtl where GRD_INSTALL_REFF='$install_id' having reins_date is not null ";
  1308.         $res = execute_my_query($query);
  1309.         if(mysqli_num_rows($res)==0){
  1310.                 $query = " select GID_INSTALL_DATE as reins_date from gft_install_dtl_new where GID_INSTALL_ID='$install_id'";
  1311.                 $res = execute_my_query($query);
  1312.         }
  1313.         if($row1 = mysqli_fetch_array($res)){
  1314.                 return $row1['reins_date'];
  1315.         }
  1316.         return '';
  1317. }
  1318.  
  1319. /**
  1320.  * @param int $install_id
  1321.  * @param string $hkey
  1322.  * 
  1323.  * @return boolean
  1324.  */
  1325. function is_previous_hkey($install_id,$hkey){
  1326.     global $secure_conn;
  1327.     $check_res = execute_my_query("select GHL_INSTALL_ID from gft_hkey_log where GHL_INSTALL_ID='$install_id' and GHL_CURRENT_STATUS='A'");
  1328.         if(mysqli_num_rows($check_res)==0){
  1329.                 return false;
  1330.         }
  1331.         $query_res = (" select GHL_INSTALL_ID from gft_hkey_log where GHL_INSTALL_ID={install_id} and GHL_HKEY={hkey} and GHL_CURRENT_STATUS='I'");
  1332.         $stmt = $secure_conn->preparedStatement($query_res);
  1333.         $stmt->setParam("hkey",$hkey);
  1334.         $stmt->setParam("install_id",$install_id);
  1335.         $select_res = $stmt->executeQuery();
  1336.         if($select_res->numRows() > 0){
  1337.                 return true;
  1338.         }
  1339.         return false;
  1340. }
  1341.  
  1342. /**
  1343.  * @param string $prodkeyfull
  1344.  *
  1345.  * @return string[int]
  1346.  */
  1347. function split_pkey_from_fullno($prodkeyfull){
  1348.         if($prodkeyfull!='' and strlen($prodkeyfull)==24){
  1349.                 //get_fullfillment_no
  1350.                 $fullfill[0]=substr($prodkeyfull,2,1);
  1351.                 $fullfill[1]=substr($prodkeyfull,4,1);
  1352.                 $fullfill[2]=substr($prodkeyfull,11,1);
  1353.                 $fullfill[3]=substr($prodkeyfull,13,1);
  1354.                 //swaped pk
  1355.                 $miss_p[0]=substr($prodkeyfull,20,1);
  1356.                 $miss_p[1]=substr($prodkeyfull,21,1);
  1357.                 $miss_p[2]=substr($prodkeyfull,22,1);
  1358.                 $miss_p[3]=substr($prodkeyfull,23,1);
  1359.                 $pr_arr=str_split($prodkeyfull,1);
  1360.                 $pr_arr[2]=$miss_p[0];
  1361.                 $pr_arr[4]=$miss_p[1];
  1362.                 $pr_arr[11]=$miss_p[2];
  1363.                 $pr_arr[13]=$miss_p[3];
  1364.                 $prodkeyfull=implode("",$pr_arr);
  1365.                 $prodkeyfull=substr(implode("",$pr_arr),0,20);
  1366.                 $fullfill_no=implode("",$fullfill);
  1367.                 $spk=array($prodkeyfull,$fullfill_no);
  1368.                 return $spk;
  1369.         }
  1370.         $spk=array('','0');
  1371.         return $spk;
  1372. }
  1373.  
  1374. /**
  1375.  * @param string $install_id
  1376.  * 
  1377.  * @return string
  1378.  */
  1379. function get_reinstall_prepared_time($install_id){
  1380.         $select_query = " select max(GRP_PREPARED_DATETIME) as prepared_time from gft_reinstall_prepare_dtl where GRP_INSTALL_ID='$install_id' and GRP_PREPARE_STATUS=1 ";
  1381.         $result1 = execute_my_query($select_query);
  1382.         if($row1 = mysqli_fetch_array($result1)){
  1383.                 return $row1['prepared_time'];
  1384.         }
  1385.         return '';
  1386. }
  1387.  
  1388. /**
  1389.  * @param string $install_id
  1390.  * 
  1391.  * @return boolean
  1392.  */
  1393. function is_valid_asa($install_id){
  1394.         $validity_date = get_single_value_from_single_table("GID_VALIDITY_DATE", "gft_install_dtl_new", "GID_INSTALL_ID", $install_id);
  1395.         if(strtotime($validity_date) >= strtotime(date('Y-m-d'))){
  1396.                 return true;
  1397.         }
  1398.         return false;
  1399. }
  1400.  
  1401. /**
  1402.  * @param string[string] $data_arr
  1403.  * 
  1404.  * @return string
  1405.  */
  1406. function get_offline_key($data_arr){
  1407.         $ak = $data_arr['activation_key'];
  1408.         $ak_arr = str_split($ak,1);
  1409.         $checksum = 0;
  1410.         foreach ($ak_arr as $key => $val){
  1411.                 $ascii_val = (ord($val)*($key+1));
  1412.                 $checksum += $ascii_val;
  1413.         }
  1414.         $checksum = substr("000000"."$checksum", -6);
  1415.         $s = str_split($checksum,1);
  1416.         $o = str_split($data_arr['dukaan_order_no'],1);
  1417.         $c = str_split($data_arr['customer_id'],1);
  1418.         $e = str_split($data_arr['expiry_date'],1);
  1419.         $n = str_split($data_arr['noc'],1);
  1420.         $i = str_split($data_arr['lic_type'],1);
  1421.        
  1422.         $mode = $data_arr['mode'];
  1423.         if($mode=='1'){
  1424.                 $act_key = $o[4].$o[1].$e[5].$s[5].$c[0].$o[8].$o[11].$c[2].$o[2].$s[2].$o[0].
  1425.                                         $c[4].$e[3].$i[0].$o[5].$n[1].$c[1].$mode.$n[0].$s[0].$c[6].$c[5].$e[1].$o[6].$s[1].
  1426.                                         $c[3].$e[4].$e[2].$o[7].$o[3].$e[0].$c[7].$o[9].$s[4].$o[10].$s[3];
  1427.         }else if($mode=='2'){
  1428.                 $act_key = $c[7].$e[5].$o[8].$o[4].$c[2].$o[9].$c[6].$c[5].$e[3].$o[5].$o[6].$s[3].$s[0].$s[1].
  1429.                                         $o[1].$c[3].$i[0].$mode.$e[0].$o[3].$e[2].$o[2].$o[11].$c[0].$e[1].$n[1].
  1430.                                         $c[1].$c[4].$s[2].$s[4].$o[0].$o[7].$o[10].$e[4].$s[5].$n[0];
  1431.         }else if($mode=='3'){
  1432.                 $act_key = $c[1].$n[0].$s[3].$e[0].$c[5].$o[7].$s[1].$s[2].$c[0].$o[10].$s[4].$o[0].$e[2].$c[7].
  1433.                                         $o[9].$n[1].$c[6].$mode.$o[1].$e[5].$s[0].$c[2].$e[4].$e[1].$c[3].$i[0].$o[3].$o[6].$c[4].
  1434.                                         $e[3].$s[5].$o[4].$o[2].$o[8].$o[11].$o[5];
  1435.         }
  1436.         $split_act_key = "";
  1437.         for($m=0;$m<strlen($act_key);$m++){
  1438.                 $split_act_key .= substr($act_key, $m, 1);
  1439.                 if( ($m!=35) && ($m%6 == 5) ){
  1440.                         $split_act_key .= "-";
  1441.                 }
  1442.         }
  1443.         return $split_act_key;
  1444. }
  1445.  
  1446. /**
  1447.  * @param string $order_no
  1448.  * @param string $pcode
  1449.  * @param string $pgroup
  1450.  * 
  1451.  * @return string
  1452.  */
  1453. function get_kit_based_validity($order_no,$pcode,$pgroup){
  1454.         $sql1 = " select GSK_PRODUCT_QTY from gft_order_product_dtl ".
  1455.                         " join gft_product_master on (GOP_PRODUCT_CODE=GPM_PRODUCT_CODE and GOP_PRODUCT_SKEW=GPM_PRODUCT_SKEW) ".
  1456.                         " join gft_skew_kit_master on (GOP_PRODUCT_CODE=GSK_KIT_PCODE and GOP_PRODUCT_SKEW=GSK_KIT_PSKEW and GSK_PRODUCT_CODE=300) ". //to get hq qty
  1457.                         " where GOP_ORDER_NO='$order_no' and GPM_ORDER_TYPE=2 ";
  1458.         $res1 = execute_my_query($sql1);
  1459.         $hq_qty = 0;
  1460.         if($row1 = mysqli_fetch_array($res1)){
  1461.                 $hq_qty = (int)$row1['GSK_PRODUCT_QTY'];
  1462.         }
  1463.         if($hq_qty==0){
  1464.                 return '';
  1465.         }
  1466.         $sql2 = " select GID_INSTALL_ID from gft_install_dtl_new where GID_ORDER_NO='$order_no' ".
  1467.                         " and GID_LIC_PCODE='$pcode' and substr(GID_LIC_PSKEW,1,4)='$pgroup' ";
  1468.         $res2 = execute_my_query($sql2);
  1469.         $num_rows = mysqli_num_rows($res2);
  1470.         if($num_rows <= $hq_qty){
  1471.                 $sql3 = " select GID_VALIDITY_DATE from gft_install_dtl_new where GID_ORDER_NO='$order_no' order by GID_INSTALL_DATE limit 1 ";
  1472.                 $res3 = execute_my_query($sql3);
  1473.                 if($row2 = mysqli_fetch_array($res3)){
  1474.                         return $row2['GID_VALIDITY_DATE'];
  1475.                 }
  1476.         }
  1477.         return '';
  1478. }
  1479.  
  1480. /**
  1481.  * @param string $lead_code
  1482.  * @param string $return_format
  1483.  * 
  1484.  * @return int
  1485.  */
  1486. function get_pos_details_for_kit_based_customer($lead_code,$return_format){
  1487.         $sql1 = " select GOD_ORDER_NO from gft_order_hdr join gft_order_product_dtl on (GOD_ORDER_NO=GOP_ORDER_NO) ".
  1488.                         " join gft_product_master on (GOP_PRODUCT_CODE=GPM_PRODUCT_CODE and GOP_PRODUCT_SKEW=GPM_PRODUCT_SKEW) ".
  1489.                         " where GOD_LEAD_CODE='$lead_code' and GOD_ORDER_STATUS='A' and GPM_ORDER_TYPE in (2,3) group by GOD_ORDER_NO ";
  1490.        
  1491.         $que1 = " select GOP_PRODUCT_CODE,if(GPM_REFERER_SKEW='',GOP_PRODUCT_SKEW,GPM_REFERER_SKEW) as REFERER_SKEW,sum(GOP_QTY) as tot_qty,sum(GOP_CP_USEDQTY) as used_qty,GPT_TYPE_NAME ".
  1492.                         " from gft_order_product_dtl ".
  1493.                         " join gft_product_master on (GOP_PRODUCT_CODE=GPM_PRODUCT_CODE and GOP_PRODUCT_SKEW=GPM_PRODUCT_SKEW) ".
  1494.                         " join gft_product_type_master on (GPT_TYPE_ID=GPM_PRODUCT_TYPE) ".
  1495.                         " where GFT_SKEW_PROPERTY in (1,11) and GPM_ORDER_TYPE not in (2,3,4) and GOP_PRODUCT_CODE in (200,500) and GOP_ORDER_NO in ($sql1) and GPM_PRODUCT_TYPE!=8 ".
  1496.                         " group by GOP_PRODUCT_CODE,REFERER_SKEW ";
  1497.         $res1 = execute_my_query($que1);
  1498.         $total_cnt = $used_cnt = /*. (int[string]) .*/array();
  1499.         $edition_name = /*. (string[string]) .*/array();
  1500.         while($row1 = mysqli_fetch_array($res1)){
  1501.                 $pcode = $row1['GOP_PRODUCT_CODE'];
  1502.                 $pskew = $row1['REFERER_SKEW'];
  1503.                 $prod_id = $pcode.(string)str_replace(".", "", $pskew);
  1504.                 $total_cnt[$prod_id]= (int)$row1['tot_qty'];
  1505.                 $used_cnt[$prod_id] = (int)$row1['used_qty'];
  1506.                 $edition_name[$prod_id] = $row1['GPT_TYPE_NAME'];
  1507.         }
  1508.         $out_txt = "";
  1509.         if($return_format=='xml'){
  1510.                 foreach($total_cnt as $product_id => $val){
  1511.                         $out_txt .= "<POS CODE='$product_id' EDITION='$edition_name[$product_id]' TOTAL_CNT='$val' USED_CNT='$used_cnt[$product_id]' />";
  1512.                 }
  1513.         }else if($return_format=='only_count'){
  1514.                 $out_txt .= (string)array_sum($total_cnt); 
  1515.         }
  1516.         return $out_txt;
  1517. }
  1518.  
  1519. /**
  1520.  * @param string $cust_id
  1521.  * @param int $outlet_cust_id
  1522.  * 
  1523.  * @return string[int][int]
  1524.  */
  1525. function get_outlet_info_in_array($cust_id,$outlet_cust_id=0){
  1526.     global $secure_conn;
  1527.     $param_list =array();
  1528.     $param_list["cust_id"] = $cust_id ;
  1529.         $sql1 = " select GLH_LEAD_CODE, GLH_CUST_NAME,GLH_CUST_STREETADDR2,GOL_OUTLET_ID,GOL_VAT_TIN, ".
  1530.                         " GLH_CUST_PINCODE,GLH_CUST_CITY,GLH_CUST_STATECODE,outlet.GID_ORDER_NO,outlet.GID_FULLFILLMENT_NO, ".
  1531.                         " group_concat(if(GCC_CONTACT_TYPE in (1,2) AND gcc_designation=1,GCC_CONTACT_NO,null)) as mobile, ".
  1532.                         " group_concat(if(GCC_CONTACT_TYPE=4 AND gcc_designation=1,GCC_CONTACT_NO,null)) as email ".
  1533.                         " from gft_install_dtl_new base ".
  1534.                         " join gft_outlet_lead_code_mapping on (base.GID_INSTALL_ID=GOL_INSTALL_ID) ".
  1535.                         " join gft_lead_hdr on (GLH_LEAD_CODE=GOL_CUST_ID) ".
  1536.                         " join gft_customer_contact_dtl on (GCC_LEAD_CODE=GLH_LEAD_CODE) ".
  1537.                         " left join gft_install_dtl_new outlet on (outlet.GID_LEAD_CODE=GLH_LEAD_CODE and outlet.GID_STATUS!='U' and outlet.GID_LIC_PCODE in (500,200) ) ".
  1538.                         " where base.GID_LEAD_CODE={cust_id} and base.GID_LIC_PCODE=300 and base.GID_STATUS!='U' and GOL_OUTLET_STATUS='A' ";
  1539.         if( ($outlet_cust_id!=0) && ($outlet_cust_id!=$cust_id) ){
  1540.                 $sql1 .= " and GOL_CUST_ID={outlet_cust_id} ";
  1541.                 $param_list["outlet_cust_id"] = $outlet_cust_id ;
  1542.         }
  1543.         $sql1 .= " group by GOL_OUTLET_ID ";
  1544.         $stmt = $secure_conn->preparedStatement($sql1);
  1545.         foreach($param_list as $key=>$value){
  1546.             $stmt->setParam("$key", $value);
  1547.         }
  1548.         $arr = /*. (string[int][int]) .*/array();
  1549.         $res1 = $stmt->executeQuery();
  1550.         if($res1->numRows()>0){
  1551.             $qd = $res1->fetchAll();
  1552.             foreach ($qd as $row1){
  1553.                     $gid_order_no = $row1['GID_ORDER_NO'];
  1554.                     $mobile_arr = explode(",", $row1['mobile']);
  1555.                     $email_arr  = explode(",", $row1['email']);
  1556.                     $address       = $row1['GLH_CUST_CITY']." - ".$row1['GLH_CUST_PINCODE']." , ".$row1['GLH_CUST_STATECODE'];
  1557.                     $arr[0][]      = $row1['GOL_OUTLET_ID'];
  1558.                     $arr[1][]       = $row1['GLH_CUST_NAME'];
  1559.                     $arr[2][]      = $row1['GLH_CUST_STREETADDR2'];
  1560.                     $arr[3][]      = "SELL";
  1561.                     $arr[4][]      = $address;
  1562.                     $arr[5][]      = $mobile_arr[0];
  1563.                     $arr[6][]      = $email_arr[0];
  1564.                     $arr[7][]      = ($gid_order_no=="")?"":$gid_order_no.substr("0000".$row1['GID_FULLFILLMENT_NO'], -4);
  1565.                     $arr[8][]      = $row1['GOL_VAT_TIN'];
  1566.                     $arr[9][]      = $row1['GLH_LEAD_CODE'];
  1567.             }
  1568.         }
  1569.         return $arr;
  1570. }
  1571.  
  1572. /**
  1573.  * @param int $lead_code
  1574.  * 
  1575.  * @return int
  1576.  */
  1577. function get_number_of_clients_from_order($lead_code){
  1578.         $sql1 = " select sum(GOP_QTY) as qty_val from gft_order_hdr ".
  1579.                         " join gft_order_product_dtl on (GOP_ORDER_NO=GOD_ORDER_NO) ".
  1580.                         " join gft_product_master on (GPM_PRODUCT_CODE=GOP_PRODUCT_CODE and GPM_PRODUCT_SKEW=GOP_PRODUCT_SKEW) ".
  1581.                         " where GOD_LEAD_CODE='$lead_code' and GOD_ORDER_STATUS='A' and GFT_SKEW_PROPERTY=3 ";
  1582.         $res1 = execute_my_query($sql1);
  1583.         if ($row1 = mysqli_fetch_array($res1)){
  1584.                 return (int)$row1['qty_val'];
  1585.         }
  1586.         return 0;
  1587. }
  1588.  
  1589. /**
  1590.  * @param string $version
  1591.  * 
  1592.  * @return string
  1593.  */
  1594. function get_valid_version($version){
  1595.         $version = (string)str_replace('-','.',$version);
  1596.         $version = (string)str_replace("RC","",$version);
  1597.         $version = (string)str_replace("SP",".",$version);
  1598.         return $version;
  1599. }
  1600.  
  1601. /**
  1602.  * @return string[string]
  1603.  */
  1604. function get_api_key_info(){
  1605.         $ret_arr = /*. (string[string]) .*/array();
  1606.         $headers = apache_request_headers();
  1607.         $api_key = isset($headers['X-Api-Key'])?(string)$headers['X-Api-Key']:'';
  1608.         $ip_addr = isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'';
  1609.         $ret_arr['partner_id'] = "0";
  1610.         $ret_arr['api_key'] = $api_key;
  1611.         $ret_arr['ip_addr'] = $ip_addr;
  1612.         if($api_key!=''){
  1613.                 $sql1 = " select GPK_EMP_ID,GPK_IP_CHECK,GPK_IP_ADDRESS from gft_api_key ".
  1614.                                 " where GPK_STATUS=1 and GPK_API_KEY='".mysqli_real_escape_string_wrapper($api_key)."' ";
  1615.                 $res1 = execute_my_query($sql1);
  1616.                 if($row1 = mysqli_fetch_array($res1)){
  1617.                         $partner_id            = $row1['GPK_EMP_ID'];
  1618.                         $is_ip_check           = (int)$row1['GPK_IP_CHECK'];
  1619.                         $list_of_ip_address = $row1['GPK_IP_ADDRESS'];
  1620.                         if( ($is_ip_check==1) && ($list_of_ip_address!='') ){
  1621.                                 if($ip_addr!=''){ //remote addr should be present. not supported when called via cron
  1622.                                         if(strpos($list_of_ip_address, $ip_addr)!==false){
  1623.                                                 $ret_arr['partner_id'] = $partner_id;
  1624.                                         }
  1625.                                 }
  1626.                         }else{
  1627.                                 $ret_arr['partner_id'] = $partner_id;
  1628.                         }
  1629.                 }
  1630.         }
  1631.         return $ret_arr;
  1632. }
  1633.  
  1634. /**
  1635.  * @param string $message
  1636.  * @param string $error_code
  1637.  * @param string $request_data
  1638.  * @param string $req_type
  1639.  * @param string $lead_code
  1640.  *
  1641.  * @return void
  1642.  */
  1643. function send_error_code_with_log($message,$error_code,$request_data,$req_type,$lead_code){
  1644.         header('X-PHP-Response-Code: '.$error_code, true, $error_code);
  1645.         $error['message']=$message;
  1646.         $resp = json_encode($error);
  1647.         echo $resp;
  1648.         log_request($request_data, $resp, '', $lead_code, $req_type,'',$message);
  1649. }
  1650.  
  1651. /**
  1652.  * @param int $plugin_type
  1653.  * @param string $pcode
  1654.  * @param string $pgroup
  1655.  * 
  1656.  * @return string[string]
  1657.  */
  1658. function get_latest_plugin_version($plugin_type,$pcode,$pgroup){
  1659.         $ret_arr = /*. (string[string]) .*/array();
  1660.         $sql1 = " select GAV_VERSION,GAV_DOWNLOAD_PATH,GAV_DESCRIPTION from gft_plugins_version where GAV_BASE_PCODE='$pcode' ".
  1661.                         " and GAV_BASE_PSKEW='$pgroup' and GAV_PLUGIN_TYPE='$plugin_type' order by GAV_ID desc limit 1 ";
  1662.         $res1 = execute_my_query($sql1);
  1663.         if($row1 = mysqli_fetch_array($res1)){
  1664.                 $ret_arr['version']            = $row1['GAV_VERSION'];
  1665.                 $ret_arr['download_path']      = $row1['GAV_DOWNLOAD_PATH'];
  1666.                 $ret_arr['description']        = $row1['GAV_DESCRIPTION'];
  1667.         }
  1668.         return $ret_arr;
  1669.        
  1670. }
  1671.  
  1672. /**
  1673.  * @param string $plugin_type
  1674.  * @param string $install_id
  1675.  * @param string $version
  1676.  * 
  1677.  * @return void
  1678.  */
  1679. function update_plugin_version($plugin_type, $install_id, $version){
  1680.     global $secure_conn;
  1681.     if($plugin_type=='1'){
  1682.                 $up1 = "update gft_install_dtl_new set GID_PRINT_PROFILE_VERSION={version} where GID_INSTALL_ID={install_id} ";
  1683.                 $stmt = $secure_conn->preparedStatement($up1);
  1684.                 $stmt->setParam("version",$version);
  1685.                 $stmt->setParam("install_id",$install_id);
  1686.                 $stmt->executeQuery();
  1687.         }
  1688.         $insert_arr['GPI_INSTALL_ID']  = $install_id;
  1689.         $insert_arr['GPI_PLUGIN_TYPE'] = $plugin_type;
  1690.         $insert_arr['GPI_VERSION']     = $version;
  1691.         $insert_arr['GPI_UPDATE_DATE'] = date('Y-m-d H:i:s');
  1692.         array_insert_query("gft_plugins_installed", $insert_arr);
  1693. }
  1694.  
  1695. /**
  1696.  * @param string $emply_id
  1697.  * 
  1698.  * @return string[string][int]
  1699.  */
  1700. function get_employee_mapped_custom_license($emply_id){
  1701.         $ret_arr['rpos6'] = /*. (string[int]) .*/array();
  1702.         $ret_arr['rpos7'] = /*. (string[int]) .*/array();
  1703.        
  1704.         $mobile_no       = get_single_value_from_single_table("GEM_MOBILE", "gft_emp_master", "GEM_EMP_ID", $emply_id);
  1705.         $local_order = substr($mobile_no, -10).substr("00000".$emply_id, -5);
  1706.         $que_custom = " select GLLD_PRODUCT_CODE,GLLD_PRODUCT_SKEW from gft_local_license_dtl where GLLD_ORDER_NO='$local_order' ";
  1707.         $res_custom = execute_my_query($que_custom);
  1708.         while ($row1 = mysqli_fetch_array($res_custom)){
  1709.                 $pcode = $row1['GLLD_PRODUCT_CODE'];
  1710.                 $pskew = (string)str_replace(".", "", $row1['GLLD_PRODUCT_SKEW']);
  1711.                 if(substr($pskew, 0,3)=='065'){
  1712.                         $ret_arr['rpos6'][] = $pcode.$pskew;
  1713.                 }else if(substr($pskew, 0,3)=='070'){
  1714.                         $ret_arr['rpos7'][] = $pcode.$pskew;
  1715.                 }
  1716.         }
  1717.         return $ret_arr;
  1718. }
  1719.  
  1720. /**
  1721.  * @param string $lead_code
  1722.  * 
  1723.  * @return string[int][string]
  1724.  */
  1725. function get_addons_bought_for_kit($lead_code){
  1726.         $lead_type = (int)get_single_value_from_single_table("GLH_LEAD_TYPE","gft_lead_hdr","GLH_LEAD_CODE","$lead_code");
  1727.         $lead_code = ($lead_type==3) ? $lead_code : (int)get_single_value_from_single_table("glh_reference_given","gft_lead_hdr","GLH_LEAD_CODE","$lead_code");
  1728.     $que_res = execute_my_query("select GLH_LEAD_CODE from gft_lead_hdr where glh_reference_given='$lead_code' and GLH_LEAD_SOURCECODE=7");
  1729.     $all_leads = array($lead_code);
  1730.     while($row_data = mysqli_fetch_array($que_res)){
  1731.         $all_leads[] = $row_data['GLH_LEAD_CODE'];
  1732.     }
  1733.     $all_lead_str = implode(",", $all_leads);
  1734.     $feature_sub = " select GAF_NAME,GAM_PRODUCT_CODE,GAM_PRODUCT_SKEW from gft_addon_feature_master join gft_addon_feature_skew_mapping on (GAM_FEATURE_ID=GAF_ID) group by GAM_PRODUCT_CODE,GAM_PRODUCT_SKEW ";
  1735.         $qu_add=" select GOP_ORDER_NO,GOP_FULLFILLMENT_NO,GOP_PRODUCT_CODE,concat(GOP_PRODUCT_CODE,'-',GOP_PRODUCT_SKEW) as prod_id, ".
  1736.                         " ifnull(GAF_NAME,GPM_PRODUCT_NAME) GPM_PRODUCT_NAME, sum(GOP_QTY) as pqty from gft_order_product_dtl ".
  1737.                         " join gft_order_hdr on (GOD_ORDER_NO=GOP_ORDER_NO and GOD_ORDER_STATUS='A') ".
  1738.                         " join gft_product_master pm on (pm.GPM_PRODUCT_SKEW=GOP_PRODUCT_SKEW and pm.GPM_PRODUCT_CODE=GOP_PRODUCT_CODE) ".
  1739.                         " join gft_product_family_master pfm on (pfm.GPM_PRODUCT_CODE=GOP_PRODUCT_CODE and pfm.GPM_STATUS='A') ".
  1740.                         " left join ($feature_sub) fs on (fs.GAM_PRODUCT_CODE=GOP_PRODUCT_CODE and fs.GAM_PRODUCT_SKEW=GOP_PRODUCT_SKEW) ".
  1741.                         " where GOD_LEAD_CODE in ($all_lead_str) and GPM_LICENSE_TYPE!=3 and (pfm.GPM_IS_INTERNAL_PRODUCT=2 or pfm.GPM_CATEGORY=6) ".
  1742.                         " and GFT_SKEW_PROPERTY in (1,11,18) and GOP_PRODUCT_CODE not in (306) group by prod_id ";
  1743.         $re_add = execute_my_query($qu_add);
  1744.         $ret_arr = /*. (string[int][string]) .*/array();
  1745.         while ($add_row = mysqli_fetch_array($re_add)){
  1746.                 $arr[0] = $add_row['GPM_PRODUCT_NAME'];
  1747.                 $arr[1] = $add_row['prod_id'];
  1748.                 $arr[2] = $add_row['pqty'];
  1749.                 $arr[3] = $add_row['GOP_ORDER_NO'].substr("0000".$add_row['GOP_FULLFILLMENT_NO'], -4);
  1750.                 $arr[4] = (in_array($add_row['GOP_PRODUCT_CODE'], array('514','529','727','728')))?"integration":"mobile";
  1751.                 $ret_arr[] = $arr;
  1752.         }
  1753.         return $ret_arr;
  1754. }
  1755.  
  1756. /**
  1757.  * @param string $order_no
  1758.  * @param string $fullfill_no
  1759.  * @param string $prod_code
  1760.  * @param string $prod_skew
  1761.  * 
  1762.  * @return int
  1763.  */
  1764. function get_extended_count($order_no,$fullfill_no,$prod_code,$prod_skew){
  1765.         $sql1 = " select count(GLA_LEAD_CODE) as ext_cnt from gft_lic_approved_log where GLA_STATUS_ID=3 and GLA_ORDER_NO='$order_no' ".
  1766.                         " and GLA_FULLFILLMENT_NO='".(int)$fullfill_no."' and GLA_PRODUCT_CODE='$prod_code' and GLA_PRODUCT_SKEW='$prod_skew' ";
  1767.         $res1 = execute_my_query($sql1);
  1768.         if($row1 = mysqli_fetch_array($res1)){
  1769.                 $extended_cnt = (int)$row1['ext_cnt'];
  1770.                 return $extended_cnt;
  1771.         }
  1772.         return 0;
  1773. }
  1774.  
  1775. /**
  1776.  * @param string $validity_date
  1777.  * 
  1778.  * @return void
  1779.  */
  1780. function get_alternate_day_for_holiday($validity_date){
  1781.         $validity_date = db_date_format($validity_date);
  1782.         $ret_date = $validity_date;
  1783.         $date_query = " select GVD_TO_DATE from gft_validity_date_change where GVD_FROM_DATE='$validity_date' and GVD_DATETIME=(select max(GVD_DATETIME) from gft_validity_date_change where gvd_from_date='$validity_date') ";
  1784.         $date_res = execute_my_query($date_query);
  1785.         if($row = mysqli_fetch_array($date_res)) {
  1786.                 $ret_date = $row['GVD_TO_DATE'];
  1787.         }
  1788. //     if(in_array($validity_date, array('2017-10-17','2017-10-18','2017-10-19'))){
  1789. //             $ret_date = '2017-10-20';
  1790. //     }
  1791.         return $ret_date;
  1792. }
  1793.  
  1794. /**
  1795.  * @param string $lead_code
  1796.  * 
  1797.  * @return boolean
  1798.  */
  1799. function is_gosecure_provisioned($lead_code){
  1800.     $qr = execute_my_query("select GCD_LEAD_CODE from gft_cust_env_data where GCD_LEAD_CODE='$lead_code' and gcd_provision_status='success'");
  1801.     if(mysqli_num_rows($qr) > 0){
  1802.         return true;
  1803.     }
  1804.     return false;
  1805. }
  1806.  
  1807. /**
  1808.  * @param string $gid_lead_code
  1809.  * @param string $gid_lic_pcode
  1810.  * 
  1811.  * @return string
  1812.  */
  1813. function get_connectplus_token($gid_lead_code,$gid_lic_pcode){
  1814.         $cp_token = "";
  1815.         if( ($gid_lic_pcode=='706') && !is_gosecure_provisioned($gid_lead_code) ){
  1816.             return $cp_token;
  1817.         }
  1818.         $sql1 = " select GID_CONNECTPLUS_TOKEN from gft_install_dtl_new ".
  1819.                         " where GID_LEAD_CODE='$gid_lead_code' and GID_LIC_PCODE='$gid_lic_pcode' and GID_STATUS!='U' ";
  1820.         $res1 = execute_my_query($sql1);
  1821.         if($row1 = mysqli_fetch_array($res1)){
  1822.                 $cp_token = $row1['GID_CONNECTPLUS_TOKEN'];
  1823.         }
  1824.         return $cp_token;
  1825. }
  1826.  
  1827. /**
  1828.  * @param string $req_url
  1829.  * @param string $req_data
  1830.  * @param string $req_header
  1831.  * @param string $req_method
  1832.  * @param string $resp_code
  1833.  * @param string $resp_body
  1834.  * 
  1835.  * @return void
  1836.  */
  1837. function insert_into_sync_queue($req_url,$req_data,$req_header,$req_method,$resp_code='',$resp_body=''){
  1838.         $today_time = date('Y-m-d H:i:s');
  1839.         $ins_arr = array(
  1840.                         'GSQ_REQUEST_URL'       => $req_url,         
  1841.                         'GSQ_REQUEST_BODY'      => $req_data,
  1842.                         'GSQ_REQUEST_HEADER'=> $req_header,
  1843.                         'GSQ_REQUEST_METHOD'=> $req_method,
  1844.                         'GSQ_STATUS'            => 'P',
  1845.                         'GSQ_RESPONSE_CODE'     => $resp_code,
  1846.                         'GSQ_RESPONSE_BODY'     => $resp_body,
  1847.                         'GSQ_CREATED_DATE'      => $today_time,
  1848.                         'GSQ_UPDATED_DATE'      => $today_time
  1849.         );
  1850.         array_insert_query("gft_sync_queue", $ins_arr);
  1851. }
  1852.  
  1853. /**
  1854.  * @param string $cust_id
  1855.  * @param string $install_id
  1856.  * 
  1857.  * @return void
  1858.  */
  1859. function post_token_to_authservice($cust_id,$install_id=''){
  1860.         $sql1 = " select GID_VALIDITY_DATE,GID_CONNECTPLUS_TOKEN,GPG_PRODUCT_ALIAS from gft_install_dtl_new ".
  1861.                         " join gft_product_group_master on (gpg_product_family_code=GID_LIC_PCODE and gpg_skew=substr(GID_LIC_PSKEW,1,4)) ".
  1862.                         " where GID_LEAD_CODE='$cust_id' and GID_CONNECTPLUS_TOKEN!='' and GID_CONNECTPLUS_TOKEN is not null ".
  1863.                         " and GID_STATUS!='U' ";
  1864.         if($install_id!=''){
  1865.                 $sql1 .= " and GID_INSTALL_ID='$install_id' ";
  1866.         }
  1867.         $res1 = execute_my_query($sql1);
  1868.         $data_arr = /*. (string[int][string]) .*/array();
  1869.         while ($row1 = mysqli_fetch_array($res1)){
  1870.                 $data_arr[] = array(
  1871.                                 'addonApiToken'=>$row1['GID_CONNECTPLUS_TOKEN'],
  1872.                                 'addonExpiryDate'=>$row1['GID_VALIDITY_DATE'],
  1873.                                 'addonProductName'=>$row1['GPG_PRODUCT_ALIAS']
  1874.                 );
  1875.         }
  1876.         if(count($data_arr) > 0){
  1877.                 $cp_config     = get_connectplus_config();
  1878.                 $cp_api_key = $cp_config['provision_api_key'];
  1879.                 $post_url      = str_replace("{{customerId}}", $cust_id, $cp_config['post_token_url']);
  1880.                 $post_data     = json_encode($data_arr);
  1881.                 $header_arr = array("Content-Type: application/json","x-api-key: $cp_api_key");
  1882.                 do_curl_to_connectplus($cust_id, $post_url, $post_data, $header_arr);
  1883.         }
  1884. }
  1885.  
  1886. /**
  1887.  * @param string $cust_id
  1888.  * @param string $pcode
  1889.  * @param string $pgroup
  1890.  * @param string $pversion
  1891.  *
  1892.  * @return string[int][string]
  1893.  */
  1894. function get_addon_feature_for_base_product($cust_id,$pcode,$pgroup,$pversion){
  1895.     $feature_arr = /*. (string[int][string]) .*/array();
  1896.         $pversion = get_valid_version($pversion);
  1897.         if(($pcode>0) && ($pgroup>0)){
  1898.                 $pcode_group = $pcode."-".$pgroup;
  1899.                 $sql = " select gam.GAM_MIN_SUPPORTED_BASE_PRODUCT_VERSION as MIN_VERSION, gpm.GPM_NAME, gpm.GPM_ID ". 
  1900.                            " from gft_pos_approval_product_mapping gam inner join gft_pos_approval_master gpm on (gam.GAM_APPROVAL_MASTER_ID = gpm.GPM_ID) ".
  1901.                            " where GAM_BASE_PRODUCT = '$pcode_group' order by gpm.GPM_ID ";
  1902.                 $res = execute_my_query($sql);
  1903.                 while($row = mysqli_fetch_assoc($res)){
  1904.                         $version_validator = version_compare($pversion, get_valid_version($row['MIN_VERSION']),">=");                       
  1905.                         if($version_validator){
  1906.                                 $feature_arr[] = array("code"=> $row['GPM_ID'], "name"=> $row['GPM_NAME']);
  1907.                         }
  1908.                 }
  1909.         }
  1910.     return $feature_arr;
  1911. }
  1912.  
  1913.  
  1914. /**
  1915.  * @param string $customerId
  1916.  * 
  1917.  * @return int
  1918.  */
  1919. function get_valid_lead_owner($customerId){
  1920.     global $secure_conn;
  1921.     $q1 = " select GLH_LFD_EMP_ID from gft_lead_hdr join gft_emp_master on (GEM_EMP_ID=GLH_LFD_EMP_ID and GEM_STATUS='A') ".
  1922.         " where GLH_LEAD_CODE={customerId} and GLH_LFD_EMP_ID not in (9999,9998) ";
  1923.     $lfd_emp = 0;
  1924.     $stmt = $secure_conn->preparedStatement($q1);
  1925.     $stmt->setParam("customerId",$customerId);
  1926.     $select_res = $stmt->executeQuery();
  1927.     if($select_res->numRows()>0 && $d1=$select_res->fetchArray()) {
  1928.         $lfd_emp = (int)$d1['GLH_LFD_EMP_ID'];
  1929.     }
  1930.     return $lfd_emp;
  1931. }
  1932.  
  1933. /**
  1934.  * @param string $customerId
  1935.  *
  1936.  * @return int
  1937.  */
  1938. function get_valid_last_activity_by($customerId){
  1939.     $q1 = " select GLD_ACTIVITY_BY,GLD_VISIT_DATE from gft_activity join gft_emp_master on (GEM_EMP_ID=GLD_ACTIVITY_BY and GEM_STATUS='A') ".
  1940.         " join gft_activity_master on (GAM_ACTIVITY_ID=GLD_VISIT_NATURE) ".
  1941.         " where GLD_LEAD_CODE='$customerId' and GLD_ACTIVITY_BY!=9999 and GAM_AUTOMATIC_ACTIVITY='N' ".
  1942.         " order by GLD_VISIT_DATE desc,GLD_DATE desc,GLD_ACTIVITY_ID desc limit 1 ";
  1943.     $r1 = execute_my_query($q1);
  1944.     $act_arr = /*. (string[int]) .*/array();
  1945.     if($d1 = mysqli_fetch_assoc($r1)){
  1946.         $act_arr[0] = $d1['GLD_ACTIVITY_BY'];
  1947.         $act_arr[1] = $d1['GLD_VISIT_DATE'];
  1948.     }
  1949.     return $act_arr;
  1950. }
  1951.  
  1952. /**
  1953.  * @param string $cust_id
  1954.  * @param string $product_code
  1955.  * @param string $mob_no
  1956.  * @param string $mobile_os
  1957.  * @param string $created_by_id
  1958.  * @param string $created_by_no
  1959.  * @param string $gai_user_mode
  1960.  *
  1961.  * @return void
  1962.  */
  1963. function update_in_app_installed_dtl($cust_id,$product_code,$mob_no,$mobile_os,$created_by_id,$created_by_no,$gai_user_mode){
  1964.     global $secure_conn;
  1965.     $mobile_os_id = 0;
  1966.     if(strcasecmp($mobile_os,"android")==0){
  1967.         $mobile_os_id=1;
  1968.     }else if(strcasecmp($mobile_os, "ios")==0){
  1969.         $mobile_os_id=2;
  1970.     }
  1971.     $qres1 = (" select GAI_ID from gft_app_installed_dtl where GAI_MOBILE={mob_no} and GAI_APP_PCODE={product_code} ");
  1972.     $stmt = $secure_conn->preparedStatement($qres1);
  1973.     $stmt->setParam("mob_no",$mob_no);
  1974.     $stmt->setParam("product_code",$product_code);
  1975.     $select_res = $stmt->executeQuery();
  1976.     if($select_res->numRows()>0 && $d1=$select_res->fetchArray()) {
  1977.         $prime_id = $d1['GAI_ID'];
  1978.         $up1 =  " update gft_app_installed_dtl set GAI_LEAD_CODE={cust_id},GAI_DEVICE_OS={mobile_os_id},GAI_USER_MODE={gai_user_mode},GAI_UPDATED_DATETIME=now() where GAI_ID={prime_id} ";
  1979.         $up1_stmt = $secure_conn->preparedStatement($up1);
  1980.         $up1_stmt->setParam("cust_id",$cust_id);
  1981.         $up1_stmt->setParam("mobile_os_id",$mobile_os_id);
  1982.         $up1_stmt->setParam("gai_user_mode",$gai_user_mode);
  1983.         $up1_stmt->setParam("prime_id",$prime_id);
  1984.         $up1_stmt->executeQuery();
  1985.     }else{
  1986.         $install_by_remarks = 'GFT Employee / Partner';
  1987.         if((int)$created_by_id==0){
  1988.             $q1 = " select GAI_INSTALLED_EMP,date(GAI_CREATED_DATETIME) as created_dt from gft_app_installed_dtl join gft_emp_master on (GEM_EMP_ID=GAI_INSTALLED_EMP and GEM_STATUS='A') ".
  1989.                 " where GAI_LEAD_CODE='$cust_id' order by GAI_CREATED_DATETIME desc limit 1";
  1990.             $r1 = execute_my_query($q1);
  1991.             if($rd1 = mysqli_fetch_assoc($r1)){
  1992.                 $created_by_id = $rd1['GAI_INSTALLED_EMP'];
  1993.                 $install_by_remarks = 'Based on previous installation on '.$rd1['created_dt'];
  1994.             }else{
  1995.                 $created_by_id = get_valid_lead_owner($cust_id);
  1996.                 $install_by_remarks = 'Based on lead owner';
  1997.                 if((int)$created_by_id==0){
  1998.                     $last_act_dtl = get_valid_last_activity_by($cust_id);
  1999.                     if(count($last_act_dtl) > 1){
  2000.                         $created_by_id = $last_act_dtl[0];
  2001.                         $install_by_remarks = 'Based on last activity on '.$last_act_dtl[1];
  2002.                     }
  2003.                 }
  2004.                 if((int)$created_by_id==0){
  2005.                     $created_by_id = get_lead_mgmt_incharge('', '', 0, 0,100,$cust_id);
  2006.                     $install_by_remarks = 'Based on agile mapping';
  2007.                 }
  2008.             }
  2009.             if((int)$created_by_id!=0){
  2010.                 $created_by_no = get_single_value_from_single_table("GEM_MOBILE", "gft_emp_master", "GEM_EMP_ID", $created_by_id);
  2011.             }
  2012.         }
  2013.         $insarr = array(
  2014.             'GAI_LEAD_CODE'=>$cust_id,
  2015.             'GAI_MOBILE'=>$mob_no,
  2016.             'GAI_APP_PCODE'=>$product_code,
  2017.             'GAI_DEVICE_OS'=>$mobile_os_id,
  2018.             'GAI_INSTALLED_EMP'=>$created_by_id,
  2019.             'GAI_INSTALLED_CONTACT'=>$created_by_no,
  2020.             'GAI_INSTALLED_REMARKS'=>$install_by_remarks,
  2021.             'GAI_USER_MODE'=>$gai_user_mode,
  2022.             'GAI_CREATED_DATETIME'=>date('Y-m-d H:i:s'),
  2023.             'GAI_UPDATED_DATETIME'=>date('Y-m-d H:i:s'),
  2024.         );
  2025.         array_insert_query("gft_app_installed_dtl", $insarr);
  2026.     }
  2027. }
  2028.  
  2029. /**
  2030.  * @param string $customer_id
  2031.  * @param string $pcode
  2032.  * 
  2033.  * @return boolean
  2034.  */
  2035. function is_license_agreement_agreed($customer_id, $pcode){
  2036.     $q1 = " select GCL_LEAD_CODE from gft_customer_license_agreement_dtl where GCL_LEAD_CODE='$customer_id' and GCL_PRODUCT_CODE='$pcode' ";
  2037.     $r1 = execute_my_query($q1);
  2038.     if(mysqli_num_rows($r1) > 0){
  2039.         return true;
  2040.     }
  2041.     return false;
  2042. }
  2043.  
  2044. /**
  2045.  * @param string $cust_id
  2046.  * @param string $mobile_no
  2047.  * 
  2048.  * @return string
  2049.  */
  2050. function get_peekaboo_auto_login_url($cust_id,$mobile_no){
  2051.     $login_url = "";
  2052.     if(is_product_installed($cust_id, 734)){
  2053.         $mob_cond = getContactDtlWhereCondition("GCC_CONTACT_NO", $mobile_no);
  2054.         $que1 = " select GPU_USER_NAME,GPU_PASSWORD from gft_pos_users ".
  2055.                 " join gft_install_dtl_new on (GID_INSTALL_ID=GPU_INSTALL_ID) ".
  2056.                 " join gft_customer_contact_dtl on (GCC_ID=GPU_CONTACT_ID) ".
  2057.                 " where GID_LEAD_CODE='$cust_id' and GPU_CONTACT_STATUS='A' and GID_STATUS!='U' and $mob_cond ".
  2058.                 " and GPU_PASSWORD!='' and GPU_PASSWORD is not null ";
  2059.         $res1 = execute_my_query($que1);
  2060.         if($row1 = mysqli_fetch_array($res1)){
  2061.             $arr = array('username'=>$row1['GPU_USER_NAME'],'password'=>$row1['GPU_PASSWORD']);
  2062.             $config = get_connectplus_config();
  2063.             $cloud_domain = str_replace("{{customerId}}", $cust_id, $config['cloud_domain']);
  2064.             $login_url= $cloud_domain."/peekaboo/#/signed/".base64_encode(json_encode($arr));
  2065.         }
  2066.     }
  2067.     return $login_url;
  2068. }
  2069.  
  2070. /**
  2071.  * @param string $cust_id
  2072.  * 
  2073.  * @return string[string]
  2074.  */
  2075. function get_base_product_info_for_customer_id($cust_id){
  2076.     $que = " select GID_INSTALL_ID,GID_LIC_PCODE,GID_LIC_PSKEW,GPG_PRODUCT_ALIAS from gft_install_dtl_new ".
  2077.         " join gft_product_master on (GPM_PRODUCT_CODE=GID_LIC_PCODE and GPM_PRODUCT_SKEW=GID_LIC_PSKEW) ".
  2078.         " join gft_product_group_master on (gpg_product_family_code=GID_LIC_PCODE and gpg_skew=substr(GID_LIC_PSKEW,1,4)) ".
  2079.         " where GID_LEAD_CODE='$cust_id' and GID_LIC_PCODE in (200,300,500) and GID_STATUS!='U' ".
  2080.         " order by GPM_LICENSE_TYPE limit 1";
  2081.     $res = execute_my_query($que);
  2082.     $ret_arr = array();
  2083.     if($row = mysqli_fetch_array($res)){
  2084.         $ret_arr = array(
  2085.             'install_id'=>$row['GID_INSTALL_ID'],
  2086.             'pcode'=>$row['GID_LIC_PCODE'],
  2087.             'pskew'=>$row['GID_LIC_PSKEW'],
  2088.             'alias'=>$row['GPG_PRODUCT_ALIAS']
  2089.         );
  2090.     }
  2091.     return $ret_arr;
  2092. }
  2093.  
  2094. /**
  2095.  * @param string $cust_id
  2096.  * 
  2097.  * @return void
  2098.  */
  2099. function post_gosecure_license_type($cust_id){
  2100.     $gosecure_ref_id = isset($_SESSION['gosecure_ref_id'])?(int)$_SESSION['gosecure_ref_id']:null;
  2101.     $que = " select GID_STATUS,GPM_LICENSE_TYPE,GID_VALIDITY_DATE from gft_install_dtl_new ".
  2102.         " join gft_product_master on (GPM_PRODUCT_CODE=GID_LIC_PCODE and GPM_PRODUCT_SKEW=GID_LIC_PSKEW) ".
  2103.         " where GID_LEAD_CODE='$cust_id' and GID_LIC_PCODE=706 ";
  2104.     $res = execute_my_query($que);
  2105.     if($row = mysqli_fetch_array($res)){
  2106.         $license_type = "SUBSCRIPTION";
  2107.         $expiry_date  = date('Y-m-d\T23:59:59.000P',strtotime($row['GID_VALIDITY_DATE']." 23:59:59"));
  2108.         if($row['GID_STATUS']=='U'){
  2109.             $license_type = "NA";
  2110.         }else if($row['GPM_LICENSE_TYPE']=='3'){
  2111.             $license_type = "TRIAL";
  2112.         }
  2113.         $base_prod_info = get_base_product_info_for_customer_id($cust_id);
  2114.         $base_prod_alias = isset($base_prod_info['alias']) ? $base_prod_info['alias'] : '';
  2115.         if($base_prod_alias!=''){
  2116.             $ord_arr = get_order_dtl_of_lead($cust_id,null,false,'706');
  2117.             $len     = count($ord_arr);
  2118.             $lastOrderDate = ($len > 0) ? date('Y-m-d\T23:59:59.000P',strtotime($ord_arr[$len-1][1])) : null;            
  2119.             $post_arr   = array(
  2120.                             array('customerId'=>$cust_id,'licenseType'=>$license_type,'product'=>$base_prod_alias,
  2121.                                   'licenseExpiry'=>$expiry_date,'lastOrderDate'=>$lastOrderDate,
  2122.                                   'referenceId'=>$gosecure_ref_id)
  2123.                           );
  2124.             $cp_config  = get_connectplus_config();
  2125.             $post_url   = str_replace("{{customerId}}", $cust_id, $cp_config['cloud_domain']).$cp_config['gosecure_lic_post'];
  2126.             $cp_api_key = $cp_config['gosecure_lic_key'];
  2127.             $header_arr = array("Content-Type: application/json","x-api-key: $cp_api_key");
  2128.             do_curl_to_connectplus($cust_id, $post_url, json_encode($post_arr), $header_arr,"PUT");
  2129.         }
  2130.     }
  2131. }
  2132.  
  2133. /**
  2134.  * @param string $orderNo
  2135.  * @param string $fullfillmentNo
  2136.  * @param string $validity_date
  2137.  * 
  2138.  * @return int
  2139.  */
  2140. function create_installation_entry($orderNo,$fullfillmentNo,$validity_date=''){
  2141.     $full_no= (int)$fullfillmentNo;
  2142.     $que = " select GOD_LEAD_CODE,GOP_PRODUCT_CODE,GOP_PRODUCT_SKEW,GPM_LICENSE_TYPE, ".
  2143.            " if(GPM_LICENSE_TYPE=1,GPM_DEFAULT_ASS_PERIOD,GPM_SUBSCRIPTION_PERIOD) valid_days ".
  2144.            " from gft_order_hdr ".
  2145.            " join gft_order_product_dtl on (GOP_ORDER_NO=GOD_ORDER_NO) ".
  2146.            " join gft_product_master on (GPM_PRODUCT_CODE=GOP_PRODUCT_CODE and GPM_PRODUCT_SKEW=GOP_PRODUCT_SKEW) ".
  2147.            " where GOP_ORDER_NO='$orderNo' and GOP_FULLFILLMENT_NO=$full_no and god_order_splict=0 ";
  2148.     $res = execute_my_query($que);
  2149.     $install_id = 0;
  2150.     if($row = mysqli_fetch_array($res)){
  2151.         $pcode = $row['GOP_PRODUCT_CODE'];
  2152.         $pskew = $row['GOP_PRODUCT_SKEW'];
  2153.         $lcode = $row['GOD_LEAD_CODE'];
  2154.         $valid_days = $row['valid_days'];
  2155.         $today = date('Y-m-d');
  2156.         $ins_arr = array(
  2157.             'GID_EMP_ID'            => SALES_DUMMY_ID,
  2158.             'GID_SALESEXE_ID'       => SALES_DUMMY_ID,
  2159.             'GID_ORDER_NO'          => $orderNo,
  2160.             'GID_FULLFILLMENT_NO'   => $fullfillmentNo,
  2161.             'GID_LIC_ORDER_NO'      => $orderNo,
  2162.             'GID_LIC_FULLFILLMENT_NO'=>$fullfillmentNo,
  2163.             'GID_PRODUCT_CODE'      => $pcode,
  2164.             'GID_LIC_PCODE'         => $pcode,
  2165.             'GID_HEAD_OF_FAMILY'    => $pcode,
  2166.             'GID_PRODUCT_SKEW'      => $pskew,
  2167.             'GID_LIC_PSKEW'         => $pskew,
  2168.             'GID_CREATED_TIME'      => date('Y-m-d H:i:s'),
  2169.             'GID_INSTALL_DATE'      => $today,
  2170.             'GID_STATUS'            => 'A',
  2171.             'GID_LEAD_CODE'         => $lcode,
  2172.             'GID_VALIDITY_DATE'     => $validity_date!=''?$validity_date:add_date($today, $valid_days),
  2173.             'GID_EXPIRE_FOR'        => ($row['GPM_LICENSE_TYPE']=='1') ? '1' : '2'
  2174.         );
  2175.         $install_id = array_insert_query("gft_install_dtl_new", $ins_arr);
  2176.     }
  2177.     return $install_id;
  2178. }
  2179.  
  2180. /**
  2181.  * @param string $activation
  2182.  * @param string $addon_code
  2183.  * @param string $addon_name
  2184.  * @param string $addon_qty
  2185.  * @param string $valid_period
  2186.  * @param string $order_no
  2187.  * @param string $expiry_type
  2188.  * @param string $lic_type
  2189.  * @param string $edition
  2190.  * @param string $vtype
  2191.  * @param string $vmethod
  2192.  * @param string $is_free
  2193.  * @param string $prod_alias
  2194.  * @param string $send_url
  2195.  * @param string $addon_category
  2196.  * @param string $stat
  2197.  * @param string $pskew
  2198.  * @param string $cp_tkn
  2199.  * @param string $nf_tkn
  2200.  * @param string $free_license
  2201.  * @param string $grace_period
  2202.  * @param string $is_pilot
  2203.  * @param string $lic_agreement
  2204.  * @param string $download_url
  2205.  * @param string[int] $custom_lic_arr
  2206.  * @param string $configure_url
  2207.  * 
  2208.  * @return string[string]
  2209.  */
  2210. function get_addon_formatted_response($activation,$addon_code,$addon_name,$addon_qty,$valid_period,$order_no,
  2211.             $expiry_type='',$lic_type='',$edition='',$vtype='',$vmethod='',$is_free='',$prod_alias='',$send_url='',
  2212.     $addon_category='',$stat='A',$pskew='',$cp_tkn='',$nf_tkn='',$free_license='N',$grace_period='',
  2213.                     $is_pilot='N',$lic_agreement='NA',$download_url='',$custom_lic_arr=array(),$configure_url=''){
  2214.     $custom_lic_count = count($custom_lic_arr);
  2215.     $arr = array(
  2216.         'ACTIVATION'        => $activation,
  2217.         'PCODE'             => $addon_code,
  2218.         'PRODUCT_NAME'      => $addon_name,
  2219.         'QTY'               => $addon_qty,
  2220.         'VALIDITY_PERIOD'   => $valid_period,
  2221.         'ORDERNO'           => $order_no,
  2222.         'EXPIRY_TYPE'       => $expiry_type,
  2223.         'LIC_TYPE'          => $lic_type,
  2224.         'EDITION'           => $edition,
  2225.         'VALIDATIAN_TYPE'   => ($configure_url!='') ? "Configure" : $vtype,
  2226.         'VALIDATIAN_METHOD' => $vmethod,
  2227.         'IS_FREE'           => ($custom_lic_count > 0) ? "" : $is_free,
  2228.         'PRODUCT_ALIAS'     => $prod_alias,
  2229.         'URL'               => $send_url,
  2230.         'ADDON_CATEGORY'    => $addon_category,
  2231.         'STATUS'            => $stat,
  2232.         'PSKEW'             => $pskew,
  2233.         'CONNECTPLUS_TOKEN' => $cp_tkn,
  2234.         'NOTIFICATION_TOKEN'=> $nf_tkn,
  2235.         'FREE_LICENSE'      => $free_license,
  2236.         'GRACE_PERIOD'      => $grace_period,
  2237.         'IS_PILOT'          => $is_pilot,
  2238.         'LICENSE_AGREEMENT' => $lic_agreement,
  2239.         'DOWNLOAD_URL'      => $download_url,
  2240.         'CUSTOM_LICENSE_COUNT'=>$custom_lic_count,
  2241.         'CUSTOM_LICENSE'    => $custom_lic_arr,
  2242.         'CONFIGURE_URL'     => $configure_url 
  2243.     );
  2244.     return $arr;
  2245. }
  2246.  
  2247. /**
  2248.  * @param string $pcode
  2249.  * @param string $lead_code
  2250.  * @param string $response_for
  2251.  * @param string $base_prod_id
  2252.  * 
  2253.  * @return string[int][string]
  2254.  */
  2255. function get_addon_features_license_details($pcode,$lead_code,$response_for='pos',$base_prod_id=''){
  2256.     $ret_arr = /*. (string[int][string]) .*/array();
  2257.     global $secure_conn;
  2258.     if($pcode=='526'){
  2259.         $q1 = " select GAF_NAME,GAF_CODE,GAM_PRODUCT_SKEW,GAI_NO_OF_DEVICE,GAI_VALIDITY_DATETIME,GAI_INSTALLED_DATETIME, ".
  2260.               " GPM_VALIDATIAN_METHOD,GPM_VALIDATIAN_TYPE,'YES' activation, 0 is_trial,GPM_LICENSE_TYPE ".
  2261.               " from gft_addon_feature_master join gft_addon_feature_skew_mapping on (GAM_FEATURE_ID=GAF_ID) ".
  2262.               " join gft_product_master on (GPM_PRODUCT_CODE=GAM_PRODUCT_CODE and GPM_PRODUCT_SKEW=GAM_PRODUCT_SKEW) ".
  2263.               " join gft_addon_feature_install_dtl on (GAI_LEAD_CODE={lead_code} and GAI_PRODUCT_CODE=GAM_PRODUCT_CODE and GAI_PRODUCT_SKEW=GAM_PRODUCT_SKEW) ".
  2264.               " where GAM_PRODUCT_CODE={pcode} and GAI_STATUS='A' group by GAF_CODE ";
  2265.         
  2266.         $q2 = " select GAF_NAME,GAF_CODE,GAM_PRODUCT_SKEW,GAI_NO_OF_DEVICE,GAI_VALIDITY_DATETIME,GAI_INSTALLED_DATETIME, ".
  2267.               " GPM_VALIDATIAN_METHOD,GPM_VALIDATIAN_TYPE,'NO' activation,sum(if(GPM_LICENSE_TYPE=3,1,0)) is_trial,GPM_LICENSE_TYPE ".
  2268.               " from gft_addon_feature_master join gft_addon_feature_skew_mapping on (GAM_FEATURE_ID=GAF_ID) ".
  2269.               " join gft_product_master on (GPM_PRODUCT_CODE=GAM_PRODUCT_CODE and GPM_PRODUCT_SKEW=GAM_PRODUCT_SKEW) ".
  2270.               " join gft_addon_product_map on (GAP_ADDON_PRODUCT_CODE=GAM_PRODUCT_CODE and GAP_PRODUCT_CODE={base_prod_id} and GAP_FEATURE_CODE=GAF_CODE) ".
  2271.               " left join gft_addon_feature_install_dtl on (GAI_LEAD_CODE={lead_code} and GAI_PRODUCT_CODE=GAM_PRODUCT_CODE and GAI_PRODUCT_SKEW=GAM_PRODUCT_SKEW) ".
  2272.               " where GAM_PRODUCT_CODE={pcode} and GAI_LEAD_CODE is null group by GAF_CODE ";
  2273.         
  2274.         $main_que = "select * from ($q1 union $q2) t1 group by GAF_CODE ";
  2275.         $stmt = $secure_conn->preparedStatement($main_que);
  2276.         $stmt->setParam("pcode",$pcode);
  2277.         $stmt->setParam("lead_code",$lead_code);
  2278.         $stmt->setParam("base_prod_id",$base_prod_id);
  2279.         $select_res = $stmt->executeQuery();
  2280.         if($select_res->numRows()>0) {
  2281.             $qd=$select_res->fetchAll();
  2282.             foreach ($qd as $d1){
  2283.                 $action_flag = ((int)$d1['is_trial'] > 0) ? "Try & Buy" : "Buy";
  2284.                 $activation = $d1['activation'];
  2285.                 $addon_name = $d1['GAF_NAME'];
  2286.                 $addon_code = $d1['GAF_CODE'];
  2287.                 $valid_date = (string)$d1['GAI_VALIDITY_DATETIME'];
  2288.                 $lic_count  = (string)$d1['GAI_NO_OF_DEVICE'];
  2289.                 if($response_for=='app'){
  2290.                     if($activation=='YES'){
  2291.                         $lic_type   = ((int)$d1['GPM_LICENSE_TYPE']=='3') ? "trial" : "live";
  2292.                         $ret_arr[] = array(
  2293.                             "name"=>$addon_name,
  2294.                             "code"=>$addon_code,
  2295.                             "expiryDate"=>$valid_date,
  2296.                             "installedDate"=>$d1['GAI_INSTALLED_DATETIME'],
  2297.                             "licenseCount"=>$lic_count,
  2298.                             "userType"=>$lic_type
  2299.                         );
  2300.                     }
  2301.                 }else if($response_for=='pos'){
  2302.                     $ret_arr[] = get_addon_formatted_response($activation, $addon_code, $addon_name, $lic_count,
  2303.                         $valid_date, "","2","","Starter",$d1['GPM_VALIDATIAN_TYPE'],$d1['GPM_VALIDATIAN_METHOD'],$action_flag,"","","","A",$d1['GAM_PRODUCT_SKEW']);
  2304.                 }
  2305.             }
  2306.         }
  2307.     }
  2308.     return $ret_arr;
  2309. }
  2310.  
  2311. /**
  2312.  * @param string $lead_code
  2313.  * @param string $pcode
  2314.  * @param string $pskew
  2315.  * @param string $client_qty
  2316.  * 
  2317.  * @return void
  2318.  */
  2319. function update_feature_install_dtl($lead_code,$pcode,$pskew,$client_qty){
  2320.     $que1 = " select GAM_FEATURE_ID,GPM_SUBSCRIPTION_PERIOD,GFT_SKEW_PROPERTY,GPM_REFERER_SKEW ".
  2321.             " from gft_addon_feature_skew_mapping join gft_addon_feature_master on (GAF_ID=GAM_FEATURE_ID) ".
  2322.             " join gft_product_master on (GPM_PRODUCT_CODE=GAM_PRODUCT_CODE and GPM_PRODUCT_SKEW=GAM_PRODUCT_SKEW) ".
  2323.             " where GAM_PRODUCT_CODE='$pcode' and GAM_PRODUCT_SKEW='$pskew' ";
  2324.     $res1 = execute_my_query($que1);
  2325.     $today_time = date('Y-m-d H:i:s');
  2326.     while($row1 = mysqli_fetch_array($res1)){
  2327.         $feature_id = $row1['GAM_FEATURE_ID'];
  2328.         $subsc_days = $row1['GPM_SUBSCRIPTION_PERIOD'];
  2329.         $sku_prop   = $row1['GFT_SKEW_PROPERTY'];
  2330.         $ref_sku    = $row1['GPM_REFERER_SKEW'];
  2331.         if($sku_prop=='26'){
  2332.             $rup = " update gft_addon_feature_install_dtl set GAI_NO_OF_DEVICE='$client_qty',GAI_VALIDITY_DATETIME=(if(GAI_VALIDITY_DATETIME > now(),GAI_VALIDITY_DATETIME,now()) + INTERVAL $subsc_days DAY) ".
  2333.                    " where GAI_LEAD_CODE='$lead_code' and GAI_PRODUCT_CODE='$pcode' and GAI_PRODUCT_SKEW='$ref_sku' ";
  2334.             execute_my_query($rup);
  2335.         }else{
  2336.             $que2 = " select GAI_ID from gft_addon_feature_install_dtl ".
  2337.                 " where GAI_LEAD_CODE='$lead_code' and GAI_PRODUCT_CODE='$pcode' and GAI_PRODUCT_SKEW='$pskew' ";
  2338.             $res2 = execute_my_query($que2);
  2339.             if($row2 = mysqli_fetch_array($res2)){
  2340.                 $prime_id = $row2['GAI_ID'];
  2341.                 $up1 = " update gft_addon_feature_install_dtl set GAI_NO_OF_DEVICE=GAI_NO_OF_DEVICE+$client_qty where GAI_ID='$prime_id' ";
  2342.                 execute_my_query($up1);
  2343.             }else{
  2344.                 //mark existing trial row to 'U'
  2345.                 $up2 =" update gft_addon_feature_install_dtl join gft_product_master on (GPM_PRODUCT_CODE=GAI_PRODUCT_CODE and GPM_PRODUCT_SKEW=GAI_PRODUCT_SKEW) ".
  2346.                     " set GAI_STATUS='U' where GAI_LEAD_CODE='$lead_code' and GAI_FEATURE_ID='$feature_id' and GPM_LICENSE_TYPE=3 and GAI_STATUS='A' ";
  2347.                 execute_my_query($up2);
  2348.                 $install_datetime   = $today_time;
  2349.                 $validity_datetime  = date('Y-m-d H:i:s',strtotime("+$subsc_days days"));
  2350.                 $ins_arr = array(
  2351.                     'GAI_LEAD_CODE'         => $lead_code,
  2352.                     'GAI_PRODUCT_CODE'      => $pcode,
  2353.                     'GAI_PRODUCT_SKEW'      => $pskew,
  2354.                     'GAI_FEATURE_ID'        => $feature_id,
  2355.                     'GAI_NO_OF_DEVICE'      => $client_qty,
  2356.                     'GAI_INSTALLED_DATETIME'=> $install_datetime,
  2357.                     'GAI_VALIDITY_DATETIME' => $validity_datetime,
  2358.                     'GAI_STATUS'            => 'A',
  2359.                 );
  2360.                 array_insert_query("gft_addon_feature_install_dtl", $ins_arr);
  2361.             }
  2362.         }
  2363.     }
  2364.     if(mysqli_num_rows($res1) > 0){
  2365.         post_instock_custom_license($lead_code);
  2366.     }
  2367. }
  2368.  
  2369. /**
  2370.  * @param string $lead_code
  2371.  */
  2372. function warehouse_provisioning($lead_code){
  2373.     $corp_id = get_corporate_customer_for_client($lead_code);
  2374.     $que1 = " select GOP_PRODUCT_CODE,GOP_PRODUCT_SKEW from gft_order_hdr ".
  2375.             " join gft_order_product_dtl on (GOP_ORDER_NO=GOD_ORDER_NO) ".
  2376.             " join gft_product_master on (GPM_PRODUCT_CODE=GOP_PRODUCT_CODE and GPM_PRODUCT_SKEW=GOP_PRODUCT_SKEW) ".
  2377.             " where GPM_LICENSE_TYPE!=3 and GOP_PRODUCT_CODE in (200,500) and GPM_PRODUCT_TYPE!=8 and GOD_LEAD_CODE='$corp_id' and GOD_ORDER_STATUS='A' ";
  2378.     $res1 = execute_my_query($que1);
  2379.     if($row1 = mysqli_fetch_array($res1)){
  2380.         $base_pcode = $row1['GOP_PRODUCT_CODE'];
  2381.         $prod_col_name = get_product_column_name_from_code($base_pcode."-".substr($row1['GOP_PRODUCT_SKEW'], 0,4));
  2382.         if($prod_col_name==""){
  2383.             return;
  2384.         }
  2385.         $base_que = " select ba.GPV_VERSION,ba.GPV_WH_BASE_SCHEMA_URL from gft_install_dtl_new ".
  2386.                     " join gft_product_version_master hq on (hq.GPV_PRODUCT_CODE=GID_LIC_PCODE and hq.GPV_VERSION=GID_CURRENT_VERSION) ".
  2387.                     " join gft_product_version_master ba on (ba.GPV_PRODUCT_CODE=$base_pcode and ba.GPV_VERSION=hq.$prod_col_name) ".
  2388.                     " where GID_LEAD_CODE='$lead_code' and GID_STATUS!='U' and GID_LIC_PCODE=300 order by GID_VALIDITY_DATE ";
  2389.         $base_res = execute_my_query($base_que);
  2390.         if($base_row = mysqli_fetch_array($base_res)){
  2391.             $post_data = array(
  2392.                 'user'=>$lead_code,
  2393.                 'product'=>'warehouse',
  2394.                 'base_schema'=>$base_row['GPV_WH_BASE_SCHEMA_URL'],
  2395.                 'product_version'=>$base_row['GPV_VERSION']
  2396.             );
  2397.             $cp_config = get_connectplus_config();
  2398.             $header_arr = array('Content-Type:application/json','X-Api-Key:'.$cp_config['warehouse_api_key']);
  2399.             do_curl_to_connectplus($lead_code, $cp_config['warehouse_url'], json_encode($post_data), $header_arr);
  2400.         }
  2401.     }
  2402. }
  2403.  
  2404. /**
  2405.  * @param string $lic_no
  2406.  * @param string $cust_id
  2407.  * 
  2408.  * @return string[string]
  2409.  */
  2410. function register_peergroup_entry_for_nettrade($lic_no,$cust_id,$ph_no){
  2411.     global $secure_conn;
  2412.     $parsed_data = /*. (string[string]) .*/array();
  2413.     $split_order_no = substr($lic_no,0,5)."-".substr($lic_no,5,5)."-".substr($lic_no,10,5)."-".substr($lic_no,15,4);
  2414.     $cust_res = ("select GLH_CUST_NAME, GLH_CUST_STREETADDR2 from gft_lead_hdr where GLH_LEAD_CODE={customer_id} ");
  2415.     $stmt = $secure_conn->preparedStatement($cust_res);
  2416.     $stmt->setParam("customer_id",$cust_id);
  2417.     $select_res = $stmt->executeQuery();
  2418.     if($select_res->numRows()>0 && $data1=$select_res->fetchArray()) {
  2419.         $cust_name             = $data1['GLH_CUST_NAME'];
  2420.         $cust_location         = $data1['GLH_CUST_STREETADDR2'];
  2421.         $post_str              = "purpose=get_store_url&orderNo=$split_order_no&customerName=$cust_name&customerLocation=$cust_location&customerId=$ph_no&csEnabled=1&entryFor=HQNT";
  2422.         $ch = curl_init(get_samee_const("Peergroup_Portcheck_Url"));
  2423.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  2424.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
  2425.         $response_json = (string)curl_exec($ch);
  2426.         curl_close($ch);
  2427.         $parsed_data = /*. (string[string]) .*/json_decode($response_json,true);
  2428.     }
  2429.     return $parsed_data;
  2430. }
  2431.  
  2432. /**
  2433.  * @param string $lic_no
  2434.  * @param string $id
  2435.  * @param string $name
  2436.  * @param string $location
  2437.  * @param string $uuid
  2438.  * 
  2439.  * @return string
  2440.  */
  2441. function register_peergroup_entry_for_webreporter($lic_no,$id,$name,$location,$uuid){
  2442.     $split_order_no = substr($lic_no,0,5)."-".substr($lic_no,5,5)."-".substr($lic_no,10,5)."-".substr($lic_no,15,4)."-WR";
  2443.     $post_str = "purpose=get_store_url&orderNo=$split_order_no&customerName=$name&customerLocation=$location&customerId=$id&uuid=$uuid";
  2444.     $ch = curl_init(get_samee_const("Peergroup_Portcheck_Url"));
  2445.     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  2446.     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
  2447.     $response_json = (string)curl_exec($ch);
  2448.     curl_close($ch);
  2449.     return $response_json;
  2450. }
  2451. /**
  2452.  * @param int $customerId
  2453.  * @param string $base_product_alias
  2454.  * 
  2455.  * @return string
  2456.  */
  2457. function get_customer_product_identity($customerId, $base_product_alias){
  2458.     $today_date = date('Y-m-d');
  2459.     $customer_identity = "";
  2460.     $ins_que =" select GID_LIC_PCODE,substr(GID_LIC_PSKEW,1,4) as pgroup,GID_VALIDITY_DATE,GID_CURRENT_VERSION,GPM_PRODUCT_ABR,gpg_version, ".
  2461.                                 " GID_ORDER_NO,GID_FULLFILLMENT_NO,GID_LIC_PSKEW ".
  2462.                                   " from gft_install_dtl_new join gft_product_family_master fm on (fm.GPM_PRODUCT_CODE=GID_LIC_PCODE) ".
  2463.                                   " join gft_product_group_master on (gpg_product_family_code=GID_LIC_PCODE and gpg_skew=substr(GID_LIC_PSKEW,1,4)) ".
  2464.                                   " join gft_product_master pm on (pm.GPM_PRODUCT_CODE=GID_LIC_PCODE and pm.GPM_PRODUCT_SKEW=GID_LIC_PSKEW) ".
  2465.                   " where GPM_IS_BASE_PRODUCT='Y' and GID_LEAD_CODE='$customerId' AND GPG_PRODUCT_ALIAS='$base_product_alias' ". 
  2466.                   " and GID_STATUS!='U' and if(GPM_LICENSE_TYPE=3,GID_VALIDITY_DATE>='$today_date',1) order by GID_VALIDITY_DATE desc ";
  2467.     $res_que = execute_my_query($ins_que);
  2468.         while($data1 = mysqli_fetch_array($res_que)){
  2469.                 if(in_array($data1['GID_LIC_PCODE'], array('200','500','300')) ){
  2470.                     $customer_identity = $data1['GID_ORDER_NO'].substr("0000".$data1['GID_FULLFILLMENT_NO'], -4).$data1['GID_LIC_PCODE'].substr(str_replace(".","",$data1['GID_LIC_PSKEW']),0,5);
  2471.                 }
  2472.         }
  2473.     return $customer_identity;
  2474. }
  2475. /**
  2476.  * @param string $customerId
  2477.  * @param string $patch_key
  2478.  * 
  2479.  * @return string
  2480.  */
  2481. function get_customer_idendity($customerId, $patch_key){
  2482.     global $secure_conn;
  2483.         $today_date = date("Y-m-d");
  2484.         $customer_identity = "";
  2485.         $sql1 = " select GID_ORDER_NO, GID_FULLFILLMENT_NO,GID_LIC_PCODE,GID_LIC_PSKEW from gft_auto_patch ".
  2486.                         " JOIN gft_install_dtl_new ON(gid_lead_code=GAP_LEAD_CODE AND GAP_PRODUCT_CODE=GID_PRODUCT_CODE)".
  2487.                         " where GAP_LEAD_CODE={customerId} ".
  2488.                         " and GAP_AUTH_KEY={patch_key} AND GID_VALIDITY_DATE>={today_date} and GID_STATUS!='U'";
  2489.         $stmt = $secure_conn->preparedStatement($sql1);
  2490.         $stmt->setParam("customerId",$customerId);
  2491.         $stmt->setParam("patch_key",$patch_key);
  2492.         $stmt->setParam("today_date",$today_date);
  2493.         $select_res = $stmt->executeQuery();
  2494.         if($select_res->numRows()>0) {
  2495.             $qd=$select_res->fetchAll();
  2496.             foreach ($qd as $data1){
  2497.                 if(in_array($data1['GID_LIC_PCODE'], array('200','500','300')) ){
  2498.                     $customer_identity = $data1['GID_ORDER_NO'].substr("0000".$data1['GID_FULLFILLMENT_NO'], -4).$data1['GID_LIC_PCODE'].substr(str_replace(".","",$data1['GID_LIC_PSKEW']),0,5);
  2499.                 }
  2500.             }
  2501.         }
  2502.        
  2503.         return $customer_identity;
  2504. }
  2505. ?>
File Description
  • php
  • PHP Code
  • 01 Jun-2021
  • 91.98 Kb
You can Share it: