Advertisement
terorama

csv / req5.php

Aug 28th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.83 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.    
  5. if ($_SERVER["SERVER_NAME"]=='localhost')
  6.    require 'alinc.php';
  7. else
  8.    require 'baser_i.inc.php';
  9.  
  10.    
  11. if (!isset($_COOKIE["timeget"]))
  12.    setcookie('timeget',date('d.m.Y H:i:s'),time()+60);
  13.    
  14. if  (!isset($_COOKIE["infget"]))
  15.    setcookie('infget',serialize($_GET), time()+60);
  16.  
  17.  
  18. if ($_SERVER["SERVER_NAME"]=='localhost')
  19.    $baser= Baser_i::init('localhost', '', '', '');
  20.    
  21. else if (strpos($_SERVER["SERVER_NAME"],'dmkim1.bget.ru')!=-1)
  22.         $baser= Baser_i::init ('localhost',
  23.         '','','');
  24.    else
  25.       $baser= Baser_i::init('localhost', '', '', '');
  26.      
  27.      
  28.       $baser=Baser_i::getInstance();
  29.  
  30.  
  31.  
  32.  
  33.  
  34. if (!isset($_REQUEST["req"])) {
  35.  
  36. ?>
  37.  
  38. <form method="post" action="<?=$_SERVER["PHP_SELF"]?>" enctype="application/x-www-form-urlencoded">
  39.    <textarea name="sqlin" cols="60" rows="10"></textarea>
  40.    <input type="hidden" name="req" value="cvsout" />
  41.    <input type="submit" name="submit" value="go" />
  42. </form>
  43.  
  44. <?php
  45. exit();
  46. }
  47.  
  48. $req=@$_REQUEST["req"];
  49.  
  50.  
  51. //-------------------------------------------------------------------------
  52. //-------------------------------------------------------------------------
  53. switch ($req) {
  54.    
  55.    case "cvsout":
  56.      
  57.       //header("Content-type:text/plain; charset=windows-1251");
  58.      
  59.       header("Content-type: application/vnd.ms-excel");
  60.       header("Content-disposition:attachment;filename=\"inquery.csv\"");
  61.      
  62.       $fn='../tempinfo.dat';
  63.       $fz=fopen($fn,'wb');
  64.      
  65.       $arr=$baser->getQuery($_REQUEST["sqlin"]);
  66.       foreach ($arr as $el) {
  67.          fputcsv($fz,$el);
  68.       }
  69.       fclose($fz);
  70.       $s=file_get_contents($fn);
  71.       echo $s;
  72.      
  73.       break;
  74.    
  75.    //-------------------------------     
  76.    case "testplain":
  77.      header("Content-type:text-plain");
  78.      header("Content-disposition:attachment;filename=\"testfile.txt\"");
  79.      
  80.      break;
  81.    //-------------------------------
  82.  
  83.    
  84.    //-------------------------------     
  85.    case "showlog":
  86.    
  87.       header('Content-type:text/plain; charset=utf-8');
  88.       ob_implicit_flush();
  89.      
  90.       $fz=fopen($baser->logfile,'rb');
  91.      
  92.       if ($fz) {
  93.          $strs=array();
  94.          fseek($fz,max(-6000,-filesize($baser->logfile)),SEEK_END);
  95.          $i=0;
  96.          $str_i=fgets($fz,4096);
  97.          do {
  98.             $str_i=fgets($fz,4096);
  99.            
  100.             if ($str_i!==false)
  101.                $strs[]=$str_i;
  102.             }  
  103.          while ($str_i!==false);
  104.          
  105.          if (!feof($fz))
  106.             echo "Error reading file \r\n";
  107.            
  108.         fclose($fz);   
  109.            
  110.          $strs_rev=array_reverse($strs);
  111.          
  112.          function output_z($item,$key) {
  113.                echo "$item";
  114.              }
  115.          
  116.          array_walk($strs_rev,"output_z");
  117.            
  118.          
  119.          //echo (fread($fz, filesize($baser->logfile)));
  120.          
  121.       }
  122.      
  123.       break;
  124.   //--------------------------------  
  125.   case "checkstr":
  126.      
  127.       $test_str='apples and oranges';
  128.       echo $test_str;
  129.      
  130.       break;
  131.   //--------------------------------  
  132.   case "instest":
  133.      $baser->insertQuery('insert into regs(%fields%) values(%values%)',
  134.                           array('reg_name'), array('\'testtest\''));
  135.                          
  136.      break;            
  137.                          
  138.   //--------------------------------
  139.   case "instest4":
  140.      $baser->insertQuery('insert into regs(reg_name) values(?)',null,array('test888'));
  141.      break;
  142.      
  143.   //--------------------------------
  144.   case "exectest":
  145.      $baser->execQuery("update regs set reg_name=? where id=116",array('testinfo'));
  146.      break;
  147.      
  148.   case "seltest":
  149.      header('Content-type:text/plain; charset=utf-8');
  150.      echo print_r( $baser->getQuery("select * from regs",2,3));
  151.      echo print_r( $baser->getQuery("select * from regs",2,3,'inf'));
  152.      break;
  153.      
  154.   case "seltest4":
  155.  
  156.      header('Content-type:text/plain; charset=utf-8');
  157.      echo print_r( $baser->getQueryAll("select * from regs where id=?",array(116,117,118)) );
  158.      echo print_r( $baser->getQueryAll("select * from regs where id=?",119) );
  159.      
  160. }
  161.  
  162.  
  163.    
  164. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement