// All rights reserved. This script is part of PHPWCMS. The PHPWCMS web content management system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html A copy is found in the textfile GPL.txt and important notices to the license from the author is found in LICENSE.txt distributed with these scripts. This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This copyright notice MUST APPEAR in all copies of the script! *************************************************************************************/ session_start(); $phpwcms = array(); require_once ('../../config/phpwcms/conf.inc.php'); require_once ('../inc_lib/default.inc.php'); require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php'); require_once (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php'); checkLogin(); require_once (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php'); $action = isset($_GET['action']) ? $_GET['action'] : ''; // export form results if($action == 'exportformresult' && isset($_GET['fid']) && ($fid = intval($_GET['fid']))) { $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); if(!$data) die('Just a problem!'); $export = array(); $row = 1; $export[0] = array('#'=>'','#ID'=>'','#Date'=>'','#IP'=>''); // run all data first and combine array elements foreach($data as $key => $value) { // numbering starting at 1 $export[$row]['#'] = $row; $export[$row]['#ID'] = $value['formresult_id']; $export[$row]['#Date'] = $value['formresult_createdate']; $export[$row]['#IP'] = $value['formresult_ip']; $val_array = @unserialize($value['formresult_content']); if(is_array($val_array) && count($val_array)) { foreach($val_array as $a_key => $a_value) { $export[$row][$a_key] = $a_value; $export[0][$a_key] = ''; } } $row++; } $elements = array(); $elements[0] = ' '.LF; foreach($export[0] as $key => $value) { $elements[0] .= ' '; $elements[0] .= $key; $elements[0] .= ''.LF; } $elements[0] .= ' '; for($x = 1; $x < $row; $x++) { $elements[$x] = ' '.LF; foreach($export[0] as $key => $value) { $elements[$x] .= ' '; $elements[$x] .= isset($export[$x][$key]) ? html_specialchars($export[$x][$key]) : ''; $elements[$x] .= ''.LF; } $elements[$x] .= ' '; unset($export[$x]); // free memory } unset($export); // free memory $filename = date('Y-m-d_H-i-s').'_formresultID-'.$fid.'.xls'; if (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { // workaround for IE filename bug with multiple periods / multiple dots in filename // that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1); } //header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); //header('Last-Modified: '.gmdate('D, d M Y H:i:s GMT', time()) ); //header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0'); //header('Content-type: application/force-download'); //header('Content-Disposition: attachment; filename="'.$filename.'"'); //header('Content-Transfer-Encoding: binary'.LF); echo ''.LF; echo implode(LF, $elements); echo LF.'
'; flush(); exit(); } elseif($action == 'exportformresultdetail' && isset($_GET['fid']) && ($fid = intval($_GET['fid']))) { $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); if(!$data) die('Just a problem!'); $export = array(); $row = 1; $export[0] = array('#ID'=>'','#Date'=>'','#IP'=>''); // run all data first and combine array elements foreach($data as $key => $value) { // numbering starting at 1 $export[$row]['#ID'] = $value['formresult_id']; $export[$row]['#Date'] = $value['formresult_createdate']; $export[$row]['#IP'] = $value['formresult_ip']; $val_array = @unserialize($value['formresult_content']); if(is_array($val_array) && count($val_array)) { foreach($val_array as $a_key => $a_value) { $export[$row][$a_key] = $a_value; $export[0][$a_key] = ''; } } $row++; } header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s GMT', time()) ); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0'); $filename = date('Y-m-d_H-i-s').'_formresultdetailID-'.$fid.'.html'; header('Content-type: text/html'); header('Content-Disposition: attachment; filename="'.$filename.'"'); echo ''.LF; echo ''.LF; echo ''.LF; echo ' Formresult Detail Export ID'.$fid.''.LF; echo ' '.LF; echo ''.LF; echo ''.LF; $elements = array(); for($x = 1; $x < $row; $x++) { echo '

page '.$x.' of '.($row-1).'

'.LF; echo ''.LF; foreach($export[0] as $key => $value) { echo ''.LF; echo ' '.LF; echo ' '.LF.''.LF; } echo '
'.ucfirst($key).''; if(isset($export[$x][$key])) { if(strpos($export[$x][$key], '/'.$phpwcms["content_path"].'form/')) { $ext = which_ext($export[$x][$key]); $export[$x][$key] = html_specialchars($export[$x][$key]); if($ext == 'jpg' || $ext == 'gif' || $ext == 'png') { echo ''; } else { echo ''.$export[$x][$key].''; } } else { echo html_specialchars($export[$x][$key]); } } else { echo ' '; } echo '
'.LF.'
'.LF; } echo ''.LF.''; exit(); } elseif($action == 'exportsubscriber') { // export list of newsletter subscribers $_userInfo = array(); // default settings for listing selected users $_userInfo['list_active'] = isset($_SESSION['list_active']) ? $_SESSION['list_active'] : 1; $_userInfo['list_inactive'] = isset($_SESSION['list_inactive']) ? $_SESSION['list_inactive'] : 1; $_userInfo['where_query'] = ''; if($_userInfo['list_active'] != $_userInfo['list_inactive'] && $_userInfo['list_active']) { $_userInfo['where_query'] = ' WHERE address_verified=1'; } elseif($_userInfo['list_active'] != $_userInfo['list_inactive'] && $_userInfo['list_inactive']) { $_userInfo['where_query'] = ' WHERE address_verified=0'; } if(isset($_SESSION['filter_subscriber']) && count($_SESSION['filter_subscriber'])) { $_userInfo['filter_array'] = array(); foreach($_SESSION['filter_subscriber'] as $_userInfo['filter']) { //usr_name, usr_login, usr_email $_userInfo['filter_array'][] = "CONCAT(address_email, address_name) LIKE '%".aporeplace($_userInfo['filter'])."%'"; } if(count($_userInfo['filter_array'])) { $_userInfo['where_query'] .= $_userInfo['where_query'] ? ' AND ' : ' WHERE '; $_userInfo['where_query'] .= '('.implode('OR', $_userInfo['filter_array']).')'; } } // get all subscribers from db $data = _dbQuery("SELECT *, DATE_FORMAT(address_tstamp, '%Y-%m-%d %H:%i:%s') AS addate FROM ".DB_PREPEND."phpwcms_address".$_userInfo['where_query'].' ORDER BY address_tstamp'); if($data) { // send header data $filename = date('Y-m-d_H-i-s').'_newsletterRecipients.xls'; header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s GMT', time()) ); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0'); header('Content-type: application/vnd-ms-excel'); header('Content-Disposition: attachment; filename="'.$filename.'"'); echo ''.LF; // 1st row - column names echo ''.LF; echo ''.LF; echo ''.LF; echo ''.LF; echo ''.LF; echo ''.LF; // now check subscriptions $_userInfo['subscriptions'] = _dbQuery("SELECT * FROM ".DB_PREPEND."phpwcms_subscription ORDER BY subscription_name"); $_userInfo['channel'] = array(); if($_userInfo['subscriptions']) { $x = 0; foreach($_userInfo['subscriptions'] as $value) { // echo channel column name echo ''.LF; $_userInfo['channel'][$x] = $value['subscription_id']; $x++; } } echo ''.LF; $_userInfo['count'] = count($_userInfo['channel']); foreach($data as $value) { // make check if all szubscriptions or special if($value['address_subscription']) { $value['all'] = ''; $value['address_subscription'] = unserialize($value['address_subscription']); if(in_array(0, $value['address_subscription'])) $value['all'] = 'X'; } else { $value['all'] = 'X'; } echo ''.LF; echo ''.LF; echo ''.LF; echo ''.LF; echo ''.LF; echo ''.LF; // custom subscriptions if($_userInfo['count']) { if($value['all'] === '') { for($x=0; $x < $_userInfo['count']; $x++) { echo ''.LF; } } else { echo str_repeat(''.LF, $_userInfo['count']); } } echo ''.LF; } echo '
verifiedemailnamelast changeall'.html_specialchars($value['subscription_name']).'
'.($value['address_verified'] ? 'X' : '').''.html_specialchars($value['address_email']).''.html_specialchars($value['address_name']).''.html_specialchars($value['addate']).''.$value['all'].''; echo in_array($_userInfo['channel'][$x], $value['address_subscription']) ? 'X' : ''; echo '
'; } exit(); } else { die('Just a problem!'); } ?>