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