/** * Stands for MemberMouse MySQL Query - wraps mysql query into one simple access point that's flexible enough to handle * either the mysql or mysqli driver * * @param string $sql The SQL Query to be executed * @param string $use_mysqli_use_result * (optional - only applicable when system is utilizing mysqli driver) when true, * system will use MYSQLI_USE_RESULT result set method, else will use * default of MYSQLI_STORE_RESULT * * @return when MySQL driver is mysql, returns resource link to result set, when driver is mysqli, returns mysqli result set object * */ function _mmmq($sql, $use_mysqli_use_result = false) { global $wpdb; $result = null; switch (_mmmd()) { case MM_MYSQL_DRIVER: $result = @mysql_query($sql, $wpdb->dbh); break; case MM_MYSQLI_DRIVER: $result = @mysqli_query($wpdb->dbh, $sql, $use_mysqli_use_result ? MYSQLI_USE_RESULT : MYSQLI_STORE_RESULT); break; } return $result; }
ini_set('max_execution_time', 0); ini_set('memory_limit', '128M'); //-------------------- Authenticate the user ------------------------------// global $current_user; $userHooks = new MM_UserHooks(); if ($userHooks->checkEmployeeAccess() === false) { redirectToErrorPage(); } //make sure one of the supported pages is making the request if (!isset($_REQUEST['module']) || $_REQUEST['module'] != "MM_ManageTransactionsView") { redirectToErrorPage(); } //-------------------- Setup the direct db access methods ------------------------------// $fetch_object_function = _mmmd() . "_fetch_object"; $free_result_function = _mmmd() . "_free_result"; $error_function = _mmmd() . "_error"; //-------------------- Setup the filename and file type (header generation also) ------------------------------// //TODO: set charset to utf-8 $fileType = "application/csv"; $fileName = "export.csv"; header("Content-type: " . $fileType); header("Content-Disposition: filename=" . $fileName); header("Pragma: no-cache"); //-------------------- Generate Data ------------------------------// if ($_REQUEST['module'] == "MM_ManageTransactionsView") { $view = new MM_ManageTransactionsView(); $dataGrid = new MM_DataGrid($_REQUEST, "transaction_date", "desc"); $csvHeaders = $view->getCSVHeaders(); //headers array is keyed by the db fieldname $handle = fopen("php://output", "w"); fputcsv($handle, $csvHeaders);