[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/include/inc_act/ -> act_export.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  
  24  session_start();
  25  $phpwcms = array();
  26  require_once ('../../config/phpwcms/conf.inc.php');
  27  require_once  ('../inc_lib/default.inc.php');
  28  require_once  (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  29  
  30  require_once  (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');
  31  checkLogin();
  32  require_once  (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php');
  33  
  34  
  35  $action = isset($_GET['action']) ? $_GET['action'] : '';
  36  
  37  // export form results
  38  if($action == 'exportformresult' && isset($_GET['fid']) && ($fid = intval($_GET['fid']))) {
  39  
  40      $data        = _dbQuery("SELECT *, DATE_FORMAT(formresult_createdate, '%Y-%m-%d %H:%i:%s') AS formresult_date  FROM ".DB_PREPEND.'phpwcms_formresult WHERE formresult_pid='.$fid);
  41      
  42      if(!$data) die('Just a problem!');
  43      
  44      $export        = array();
  45      $row        = 1;
  46      $export[0]    = array('#'=>'','#ID'=>'','#Date'=>'','#IP'=>'');
  47      
  48      // run all data first and combine array elements
  49      foreach($data as $key => $value) {
  50      
  51          // numbering starting at 1
  52          $export[$row]['#']        = $row;
  53          $export[$row]['#ID']    = $value['formresult_id'];
  54          $export[$row]['#Date']    = $value['formresult_createdate'];
  55          $export[$row]['#IP']    = $value['formresult_ip'];
  56          
  57          $val_array                = @unserialize($value['formresult_content']);
  58          if(is_array($val_array) && count($val_array)) {
  59              foreach($val_array as $a_key => $a_value) {
  60                  $export[$row][$a_key]    = $a_value;
  61                  $export[0][$a_key]        = '';
  62              }
  63          }
  64          
  65          $row++;
  66      }
  67      
  68      $elements = array();
  69      
  70      $elements[0]  = '    <tr>'.LF;
  71      foreach($export[0] as $key => $value) {
  72          $elements[0] .= '        <th>';
  73          $elements[0] .= $key;
  74          $elements[0] .= '</th>'.LF;
  75      }
  76      $elements[0] .= '    </tr>';
  77      
  78      
  79      for($x = 1; $x < $row; $x++) {
  80          
  81          $elements[$x]  = '    <tr>'.LF;
  82          foreach($export[0] as $key => $value) {
  83      
  84              $elements[$x] .= '        <td>';
  85              $elements[$x] .= isset($export[$x][$key]) ? html_specialchars($export[$x][$key]) : '';
  86              $elements[$x] .= '</td>'.LF;
  87      
  88          }
  89          $elements[$x] .= '    </tr>';
  90          
  91          unset($export[$x]); // free memory
  92      }
  93      
  94      unset($export); // free memory
  95  
  96      $filename = date('Y-m-d_H-i-s').'_formresultID-'.$fid.'.xls';
  97  
  98      if (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  99          // workaround for IE filename bug with multiple periods / multiple dots in filename
 100          // that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
 101          $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
 102      }
 103      
 104      //header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
 105      //header('Last-Modified: '.gmdate('D, d M Y H:i:s GMT', time()) );
 106      //header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0');
 107      
 108      
 109      //header('Content-type: application/force-download'); 
 110       //header('Content-Disposition: attachment; filename="'.$filename.'"');
 111      //header('Content-Transfer-Encoding: binary'.LF);
 112      
 113      echo '<table border="1" cellspacing="1" cellpadding="2">'.LF;
 114      echo implode(LF, $elements);
 115      echo LF.'</table>';
 116      flush();
 117      exit();
 118      
 119  } elseif($action == 'exportformresultdetail' && isset($_GET['fid']) && ($fid = intval($_GET['fid']))) {
 120  
 121      $data        = _getDatabaseQueryResult("SELECT *, DATE_FORMAT(formresult_createdate, '%Y-%m-%d %H:%i:%S') AS formresult_date FROM ".DB_PREPEND.'phpwcms_formresult WHERE formresult_pid='.$fid);
 122      
 123      if(!$data) die('Just a problem!');
 124      
 125      $export        = array();
 126      $row        = 1;
 127      $export[0]    = array('#ID'=>'','#Date'=>'','#IP'=>'');
 128      
 129      // run all data first and combine array elements
 130      foreach($data as $key => $value) {
 131      
 132          // numbering starting at 1
 133          $export[$row]['#ID']    = $value['formresult_id'];
 134          $export[$row]['#Date']    = $value['formresult_createdate'];
 135          $export[$row]['#IP']    = $value['formresult_ip'];
 136          
 137          $val_array                = @unserialize($value['formresult_content']);
 138          if(is_array($val_array) && count($val_array)) {
 139              foreach($val_array as $a_key => $a_value) {
 140                  $export[$row][$a_key]    = $a_value;
 141                  $export[0][$a_key]        = '';
 142              }
 143          }
 144          
 145          $row++;
 146      }
 147      
 148      
 149      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
 150      header('Last-Modified: '.gmdate('D, d M Y H:i:s GMT', time()) );
 151      header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0');
 152  
 153      $filename = date('Y-m-d_H-i-s').'_formresultdetailID-'.$fid.'.html';    
 154      header('Content-type: text/html'); 
 155       header('Content-Disposition: attachment; filename="'.$filename.'"');
 156      
 157      echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'.LF;
 158      echo '<html>'.LF;
 159      echo '<head>'.LF;
 160      echo '    <title>Formresult Detail Export ID'.$fid.'</title>'.LF;
 161      echo '    <style type="text/css">
 162      <!--
 163          body {font-family:Arial,Helvetica,sans-serif;font-size:10pt;}
 164          hr {margin:0;padding:0;height:1px;border:0;border-bottom:1px solid #666666;page-break-after:always;}
 165          td {font-size: 10pt;}
 166      // -->
 167      </style>'.LF;
 168      echo '</head>'.LF;
 169      echo '<body>'.LF;
 170      
 171      $elements = array();
 172      
 173      
 174      for($x = 1; $x < $row; $x++) {
 175          
 176          echo '<p style="font-weight:bold">page '.$x.' of '.($row-1).'</p>'.LF;
 177          echo '<table border="0" cellspacing="0" cellpadding="0" summary="ID:'.$fid.'">'.LF;
 178  
 179          foreach($export[0] as $key => $value) {
 180      
 181              echo '<tr>'.LF;
 182              echo '    <td valign="top" style="padding:0 5px 0 0;"><strong>'.ucfirst($key).'</strong></td>'.LF;
 183              echo '    <td valign="top" style="padding:0 0 3px 0;">';
 184              if(isset($export[$x][$key])) {
 185                  
 186                  if(strpos($export[$x][$key], '/'.$phpwcms["content_path"].'form/')) {
 187                  
 188                      $ext = which_ext($export[$x][$key]);
 189                      $export[$x][$key] = html_specialchars($export[$x][$key]);
 190                      if($ext == 'jpg' || $ext == 'gif' || $ext == 'png') {
 191                          echo '<img src="'.$export[$x][$key].'" border="0" alt="" />';
 192                      } else {
 193                          echo '<a href="'.$export[$x][$key].'">'.$export[$x][$key].'</a>';
 194                      }                
 195                  
 196                  } else {
 197                      echo html_specialchars($export[$x][$key]);
 198                  }
 199              
 200              } else {
 201              
 202                  echo '&nbsp;';
 203              
 204              }
 205  
 206              echo '</td>'.LF.'</tr>'.LF;
 207      
 208          }
 209          echo '</table>'.LF.'<hr />'.LF;
 210      
 211      }
 212      
 213      echo '</body>'.LF.'</html>';
 214      exit();
 215      
 216      
 217  } elseif($action == 'exportsubscriber') {
 218  
 219      // export list of newsletter subscribers
 220      $_userInfo = array();
 221  
 222      // default settings for listing selected users
 223      $_userInfo['list_active']        = isset($_SESSION['list_active']) ? $_SESSION['list_active'] : 1;
 224      $_userInfo['list_inactive']        = isset($_SESSION['list_inactive']) ? $_SESSION['list_inactive'] : 1;
 225  
 226      $_userInfo['where_query']    = '';
 227  
 228      if($_userInfo['list_active'] != $_userInfo['list_inactive'] && $_userInfo['list_active']) {
 229          $_userInfo['where_query']    = ' WHERE address_verified=1';
 230      } elseif($_userInfo['list_active'] != $_userInfo['list_inactive'] && $_userInfo['list_inactive']) {
 231          $_userInfo['where_query']    = ' WHERE address_verified=0';
 232      }
 233      
 234      if(isset(