Advertisement
plirof2

zx_edit_sna.php v008a

Nov 23rd, 2022 (edited)
1,338
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.50 KB | None | 0 0
  1. <?php
  2. $debug=false; //NEED to be false to enable download
  3. /*
  4. v221125b - Seems to work Teamnames+Player names
  5. v221125a - Added loop for names (but not working) - BUG- File write was for fixed size
  6. v221124b-
  7. v221123 - Initial PHP version
  8.  
  9. use https://hexed.it/
  10.  
  11. ToDo:
  12. - Create second PHP file where it merges changes and SNA file
  13. - Footballer of the year -add HEX for players names
  14. */
  15. $write_enabled=false;
  16. //$filename="fb_year.sna";
  17. $filename="footgr21.sna";
  18.  
  19. //echo str_pad($input, 9);                      // produces "Alien     "
  20.  
  21. //$position=hexdec("00004ฮ‘2ฮ’"); // You have to pre-calculate it once
  22. //$position=hexdec("00010edb"); // You have to pre-calculate it
  23. $interval_size=10;// intervals 37 ok for first 17 ($group_iterations)
  24. $string_size=9; //Size of stored string
  25. $group_iterations=23;
  26. //Second time
  27. $addr_array = array(
  28.     "00004A2B"=>"Category 1",
  29.     //"00004B07"=>"B ethniki",
  30.     "00004B07"=>"Category 2",
  31.     "00004BE3"=>"Category 3",
  32.     "00004CBF"=>"Category 4",
  33.     "00004D9B"=>"Champions league",
  34.     //"00024B07"=>"EEtniki???",
  35.     "00004E77"=>"Nations League",
  36.        
  37. );
  38.  
  39.  
  40.  
  41.  
  42.  
  43. //$position=hexdec($addr);
  44. //if ($debug) echo $position;
  45. //$data="ARISOLE".$addr; // Replacement
  46.  
  47. $data="TEAM";
  48. $data=str_pad($data, 9);
  49. $index_add=0;
  50. /*
  51. if ($f=fopen($filename, "r+")) {
  52.  
  53.     foreach($addr_array as $pos => $pos_team ){
  54.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  55.         $position=hexdec($pos);
  56.         $index_add=0;
  57.         for($i=1;$i<23;$i++){
  58.             fseek($f, $position+$index_add);
  59.             $teamname=fread($f,9);
  60.             fseek($f, $position+$index_add);
  61.             echo "<li>$i ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  62.             if ($write_enabled)fwrite($f, $data);
  63.             $index_add=10*$i;
  64.         } //End of for($i=1;$i,30l$i++){
  65.         echo "<HR>";
  66.     } //foreach($addr_array as $pos => $pos_team ){
  67.     fclose($f);
  68. } else {
  69.     echo "Can't open file";
  70. }
  71. */
  72.  
  73.  
  74. if ($f=fopen($filename, "rb")) {
  75.  
  76. //READ contents of file
  77. $contents = '';
  78. while (!feof($f)) {
  79.     $contents .= fread($f, 8192);
  80. }
  81. //echo "<hr>".$contents;
  82. fclose($f);
  83. }
  84. $content_orig=$contents;
  85. if ($debug) echo '<hr> COMPARE1 '.strcmp($content_orig, $contents);
  86.  
  87.  
  88.  
  89.  
  90.  
  91. if(@$_REQUEST["getfile"]!="true") {
  92. //if we don't have a request
  93.  
  94.  
  95. //echo "<h3>".substr($contents, 18987,220)."</h3>";
  96. echo "<form target='_blank' action='' method=POST >";
  97.  
  98.  
  99.     foreach($addr_array as $pos => $pos_team ){
  100.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  101.         $position=hexdec($pos);
  102.         $index_add=0;
  103.         for($i=1;$i<$group_iterations;$i++){
  104.             //fseek($f, $position+$index_add);
  105.            // $teamname=fread($f,9);
  106.             $teamname=substr($contents, $position+$index_add,$string_size);
  107.  
  108.             //fseek($f, $position+$index_add);
  109.             echo "<li>$i ) $teamname <!--(position+index_add($index_add))-->".dechex($position+$index_add)."/".($position+$index_add);
  110.             echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'"  maxlength="'.$string_size.'" size="'.($string_size+1).'" ><br>';
  111.             if ($write_enabled)fwrite($f, $data);
  112.             $index_add=$interval_size*$i;
  113.         } //End of for($i=1;$i,30l$i++){
  114.         echo "<HR>";
  115.     } //foreach($addr_array as $pos => $pos_team ){
  116.    
  117.    
  118.    
  119.    
  120.     //Footballer of the year Player names
  121.     $interval_size=20;// intervals 37 ok for first 17 ($group_iterations)
  122.     $string_size=19; //Size of stored string
  123.     $group_iterations=15;
  124.     $addr_array = array("00006FD5"=>"Player Names",);
  125.     foreach($addr_array as $pos => $pos_team ){
  126.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  127.         $position=hexdec($pos);
  128.         $index_add=0;
  129.         for($i=1;$i<$group_iterations;$i++){
  130.             //fseek($f, $position+$index_add);
  131.            // $teamname=fread($f,9);
  132.             $teamname=substr($contents, $position+$index_add,$string_size);
  133.  
  134.             //fseek($f, $position+$index_add);
  135.             echo "<li>$i ) $teamname <!--(position+index_add($index_add))-->".dechex($position+$index_add)."/".($position+$index_add);
  136.             echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'" maxlength="'.$string_size.'" size="'.($string_size+4).'" ><br>';
  137.             if ($write_enabled)fwrite($f, $data);
  138.             $index_add=$interval_size*$i;
  139.         } //End of for($i=1;$i,30l$i++){
  140.         echo "<HR>";
  141.     } //foreach($addr_array as $pos => $pos_team ){
  142.    
  143.    
  144.    
  145.    
  146.    
  147.    
  148.    
  149.    
  150.    
  151. echo "<input type=hidden name='getfile' value=true >";
  152. echo "<input type=submit>";
  153. echo "</form>";
  154.  
  155.  
  156.  
  157.  
  158. }else {
  159. // If file download
  160.  
  161.  
  162. //if($debug)echo "<h3>contents line 126</h3>".$contents."<hr>";
  163. foreach($_REQUEST as $pos => $text ){
  164.     if ($debug) echo "<hr> $pos => $text";
  165.     if($pos=="getfile") continue;
  166.     //https://www.php.net/manual/en/function.file-put-contents.php
  167.  
  168. //}
  169.  
  170. //echo "<h3>".substr($contents, 18987,220)."</h3>";
  171. //echo "<form target='_blank' action=zx_recreate_sna_file.php >";
  172.     //oreach($addr_array as $pos => $pos_team ){
  173.         if ($debug) echo "<h3>$pos / ".hexdec($pos)." , $text </h3>";
  174.         $position=hexdec($pos);
  175.         $index_add=0;
  176.         //for($i=1;$i<23;$i++){
  177.             //fseek($f, $position+$index_add);
  178.            // $teamname=fread($f,9);
  179.             //if($debug)echo "<h3>contents line 143</h3>".substr($contents, 0,9)."<hr>";           
  180.             //$contents=substr_replace($contents,$text,$pos,9);
  181.             $text_length=strlen($text);
  182.             $contents=substr_replace($contents,$text,$pos,$text_length);
  183.             //fseek($f, $position+$index_add);
  184.             $teamname=substr($contents, $position+$index_add,$text_length);
  185.             if ($debug) echo "<li> ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  186.             //echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'" maxlength="9" ><br>';
  187.             //if ($write_enabled)fwrite($f, $data);
  188.             //$index_add=10*$i;
  189.         //} //End of for($i=1;$i,30l$i++){
  190.         if ($debug) echo "<HR>";
  191.     } //foreach($addr_array as $pos => $pos_team ){
  192. //echo "<input type=submit>";
  193. //echo "</form>";
  194.  
  195. if ($debug) echo '<hr> COMPARE '.strcmp($content_orig, $contents);
  196. //if($debug)echo "<hr><hr><hr>".$content_orig."<hr><hr>";
  197.  
  198. header('Content-Disposition: attachment; filename="fotygr.sna"');
  199. header('Content-Type: text/plain'); # Don't use application/force-download - it's not a real MIME type, and the Content-Disposition header is sufficient
  200. header('Content-Length: ' . strlen($contents));
  201. header('Connection: close');
  202. echo $contents;
  203. //print_r($_REQUEST);
  204. //echo $str;
  205. }
  206. //end of if($_REQUEST["getfile"]!="true") {
  207. ?>
  208.  
Advertisement
Comments
  • mozmoz1
    1 year (edited)
    Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement