function dt_process() { if (!empty($_POST['func']) && !empty($_POST['action'])) { if ($_POST['action'] == 'wp_dt_ajaxCall') { dt_ajaxCall(); exit; } } if (!empty($_POST['processKey'])) { $_POST = stripslashes_deep($_POST); if ($_POST['processKey'] == $_SESSION['processKey']) { include_once DB_TOOLKIT . 'daiselements.class.php'; include_once DB_TOOLKIT . 'data_form/class.php'; include_once DB_TOOLKIT . 'data_report/class.php'; unset($_SESSION['processKey']); $_SESSION['DF_Post'] = array(); if (!empty($_POST['dr_update'])) { $EID = $_POST['dataForm']['EID']; $Setup = getelement($EID); unset($_POST['dataForm']['dr_update']); unset($_POST['dataForm']['EID']); $Return = df_processUpdate($_POST['dataForm'], $EID); if (!empty($Return['_fail_'])) { $_SESSION['failedProcess'][$EID]['Data'] = $Data; $_SESSION['failedProcess'][$EID]['Fields'] = $Return['_fail_']; $_SESSION['DF_Notification'] = $Return['_error_']; $_SESSION['DF_NotificationTypes'][] = 'error'; header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } if (!empty($Return['Value'])) { dr_trackActivity('Update', $EID, $Return['Value']); $_SESSION['DF_Post_returnID'] = $Return['Value']; $_SESSION['DF_Post_EID'] = $EID; } if (empty($Setup['Content']['_NotificationsOff'])) { if (!empty($Setup['Content']['_inlineNotifications'])) { $_SESSION['DF_Notification'][] = $Return['Message']; $_SESSION['DF_NotificationTypes'][] = $Return['noticeType']; } else { $_SESSION['DF_Post'][] = $Return['Message']; } } } else { foreach ($_POST['dataForm'] as $EID => $Data) { $Return = df_processInsert($EID, $Data); if (!empty($Return['_fail_'])) { $_SESSION['failedProcess'][$EID]['Data'] = $Data; $_SESSION['failedProcess'][$EID]['Fields'] = $Return['_fail_']; $_SESSION['DF_NotificationTypes'][] = 'error'; header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } // Track Activity if (!empty($Return['Value'])) { dr_trackActivity('Insert', $EID, $Return['Value']); } $Setup = getelement($EID); if (empty($Setup['Content']['_NotificationsOff'])) { if (!empty($Setup['Content']['_inlineNotifications'])) { $_SESSION['DF_Notification'][] = $Return['Message']; $_SESSION['DF_NotificationTypes'][] = $Return['noticeType']; } else { $_SESSION['DF_Post'][] = $Return['Message']; } } } } $Redirect = $_SERVER['HTTP_REFERER']; if (!empty($Return['Value'])) { $ReturnValue = $Return['Value']; } if (is_admin()) { if (!empty($Setup['Content']['_ItemViewInterface'])) { $Location = 'admin.php'; } else { $Location = $_SERVER['HTTP_REFERER']; } } else { if (!empty($Setup['Content']['_ItemViewPage'])) { $Location = get_permalink($Setup['Content']['_ItemViewPage']); } else { $Location = $_SERVER['HTTP_REFERER']; } } //echo $Location; //exit; if (!empty($ReturnValue)) { $url = parse_url($_SERVER['HTTP_REFERER']); $returntoken = '?'; if (!empty($url['query'])) { if (empty($Setup['Content']['_ItemViewPage'])) { $Location = str_replace('?' . $url['query'], '', $_SERVER['HTTP_REFERER']); } parse_str($url['query'], $gets); parse_str($ReturnValue, $returngets); if (!empty($Setup['Content']['_ItemViewInterface'])) { $RedirInterface = get_option($Setup['Content']['_ItemViewInterface']); if (!empty($RedirInterface['_ItemGroup'])) { $app = get_option('_' . $RedirInterface['_Application'] . '_app'); if (!empty($app['docked'])) { $gets['page'] = $Setup['Content']['_ItemViewInterface']; } else { $gets['page'] = 'dbt_builder'; $gets['renderinterface'] = $Setup['Content']['_ItemViewInterface']; } } else { $gets['page'] = 'dbt_builder'; $gets['renderinterface'] = $Setup['Content']['_ItemViewInterface']; } } $ReturnValue = htmlspecialchars_decode(@http_build_query(array_merge($gets, $returngets))); } else { if (!empty($Setup['Content']['_ItemViewInterface'])) { $RedirInterface = get_option($Setup['Content']['_ItemViewInterface']); if (!empty($RedirInterface['_ItemGroup'])) { $app = get_option('_' . $RedirInterface['_Application'] . '_app'); if (!empty($app['docked'])) { $gets['page'] = $Setup['Content']['_ItemViewInterface']; } else { $gets['page'] = 'dbt_builder'; $gets['renderinterface'] = $Setup['Content']['_ItemViewInterface']; } } else { $gets['page'] = 'dbt_builder'; $gets['renderinterface'] = $Setup['Content']['_ItemViewInterface']; } $ReturnValue = htmlspecialchars_decode(@http_build_query($gets, $returngets)); } } $Redirect = $Location . $returntoken . $ReturnValue; } //echo $Redirect; //exit; header('Location: ' . $Redirect); exit; } } //vardump($_POST); if (!empty($_POST['importKey'])) { $_POST = stripslashes_deep($_POST); if (empty($_FILES['fileImport']['size'])) { $_SESSION['dataform']['OutScripts'] .= "\n df_buildImportForm('" . $_POST['importInterface'] . "');\n "; $Redirect = $_SERVER['HTTP_REFERER']; header('Location: ' . $Redirect); exit; } $path = wp_upload_dir(); // set filename and paths $Ext = pathinfo($_FILES['fileImport']['name']); $newFileName = $_POST['importInterface'] . '.' . $Ext['extension']; $newLoc = $path['path'] . '/' . $newFileName; $_SESSION['import_' . $_POST['importInterface']]['import'] = wp_upload_bits($newFileName, null, file_get_contents($_FILES['fileImport']['tmp_name'])); $_SESSION['dataform']['OutScripts'] .= "\n df_buildImportManager('" . $_POST['importInterface'] . "');\n "; $Redirect = $_SERVER['HTTP_REFERER']; header('Location: ' . $Redirect); exit; } if (!empty($_POST['importPrepairKey'])) { $Element = getelement($_POST['importInterface']); $_SESSION['import_' . $_POST['importInterface']]['import']['table'] = $Element['Content']['_main_table']; $_SESSION['import_' . $_POST['importInterface']]['import']['delimiter'] = $_POST['importDelimeter']; if (!empty($_POST['importSkipFirst'])) { $_SESSION['import_' . $_POST['importInterface']]['import']['importSkipFirst'] = $_POST['importSkipFirst']; } $_SESSION['import_' . $_POST['importInterface']]['import']['map'] = $_POST['importMap']; $_SESSION['dataform']['OutScripts'] .= "\n df_processImport('" . $_POST['importInterface'] . "');\n "; $Redirect = $_SERVER['HTTP_REFERER']; header('Location: ' . $Redirect); exit; } // API Call //vardump($_SERVER); $pattern = API_getInterfaceRegex(); if (!empty($pattern)) { if (preg_match('/' . $pattern['regex'] . '/s', $_SERVER['REQUEST_URI'], $matches)) { include_once DB_TOOLKIT . 'libs/api_engine.php'; exit; } } /// EXPORT foreach ($_GET as $PDFExport => $Val) { if (!is_array($Val)) { if (strstr($PDFExport, 'format_')) { $export = explode('_dt_', $PDFExport); $exportFormat = $Val; $Media['ID'] = 'dt_' . $export[1]; $Element = getElement($Media['ID']); $Config = $Element['Content']; } } } //error_reporting(E_ALL); //ini_set('display_errors','On'); //esds if (!empty($exportFormat)) { if ($exportFormat == 'pdf') { include_once DB_TOOLKIT . 'daiselements.class.php'; include_once DB_TOOLKIT . 'data_form/class.php'; include_once DB_TOOLKIT . 'data_report/class.php'; include_once DB_TOOLKIT . 'data_itemview/class.php'; include_once DB_TOOLKIT . 'libs/fpdf.php'; include_once DB_TOOLKIT . 'libs/pdfexport.php'; $input_params["return"] = isset($input_params["return"]) ? $input_params["return"] : false; if (empty($Config['_orientation'])) { $Config['_orientation'] = 'P'; } $report = new PDFReport($Config['_orientation'], $Config['_ReportTitle']); //you should use loadlib here //dump($_SESSION['reportFilters'][$Media['ID']]); if (!empty($Config['_FilterMode'])) { $Res = mysql_query("SELECT ID, Content FROM `dais_elements` WHERE `Element` = 'data_report' AND `ParentDocument` = " . $Element['ParentDocument'] . " AND `ID` != '" . $Media['ID'] . "';"); while ($element = mysql_fetch_assoc($Res)) { //dump($element); $eConfig = unserialize($element['Content']); $preReport['ID'] = $element['ID']; $preReport['Config'] = $eConfig; $reportExports[] = $preReport; } } else { $preReport['ID'] = $Media['ID']; $preReport['Config'] = $Config; $reportExports[] = $preReport; } $input_params["return"] = isset($input_params["return"]) ? $input_params["return"] : false; foreach ($reportExports as $key => $reportExport) { //dump($_SESSION); $Continue = true; $Media['ID'] = $reportExport['ID']; $Config = $reportExport['Config']; foreach ($reportExport['Config']['_Field'] as $Key => $Value) { if ($Value == 'viewitem_filter') { if (empty($_SESSION['viewSelector_' . $Media['ID']])) { $Continue = false; } } } if (!empty($Continue)) { $limit = 'full'; if (!empty($_GET['limit'])) { $limit = $_GET['limit']; } $OutData = dr_BuildReportGrid($Media['ID'], false, $_SESSION['report_' . $Media['ID']]['SortField'], $_SESSION['report_' . $Media['ID']]['SortDir'], 'pdf', $limit); //vardump($OutData); $CountStat = array(); if (is_array($OutData)) { if ($key > 0) { $report->addPage(); } // outdata - Headings $report->cf_report_headersMain($OutData, $Config); if (!empty($OutData['Totals'])) { foreach ($OutData['Totals'] as $Field => $Value) { sort($fieldset); $totalData[$Field] = $Value; } $report->cf_report_datagrid($totalData, 7); unset($OutData['Totals']); } } $report->cf_report_spacer(); $Headers = array(); if (!empty($OutData[0])) { foreach ($OutData[0] as $Header => $v) { if (strpos($Config['_IndexType'][$Header], 'hide') === false) { if (!empty($Config['_FieldTitle'][$Header])) { $Headers[] = $Config['_FieldTitle'][$Header]; } else { $Headers[] = $Header; } } } $Total = count($OutData) - 1; $Body = array(); $Counter = 1; for ($i = 0; $i <= $Total; $i++) { if (is_array($OutData[$i])) { foreach ($OutData[$i] as $Field => $v) { if (strpos($Config['_IndexType'][$Field], 'hide') === false) { $Body[$i][] = str_replace(' ', '', html_entity_decode($v)); } } } } } $options["width"] = "100%"; $report->cf_report_data_col_grid($Headers, $Body, $OutData, $Config); $report->cf_report_spacer(); //break; } } $report->cf_report_generate_output(); mysql_close(); exit; } if ($exportFormat == 'csv') { $CSVout = fopen('php://output', 'w'); $prequery = explode('LIMIT', $_SESSION['queries'][$Media['ID']]); $sql_query = $prequery[0]; $filename = uniqid(date('mdHis')) . '.csv'; $out = ''; // Gets the data from the database $result = mysql_query($sql_query); $fields_cnt = mysql_num_fields($result); //dump($Config['_Field']); //dump($Config); //exit; $VisibleFields = array(); $FieldHeaders = array(); foreach ($Config['_Field'] as $Field => $Value) { if ($Config['_IndexType'][$Field] == 'index_show' || $Config['_IndexType'][$Field] == 'noindex_show') { $VisibleFields[] = $Field; $FieldHeaders[] = $Config['_FieldTitle'][$Field]; } } ob_start(); fputcsv($CSVout, $FieldHeaders, ',') . "\r\n"; $out .= ob_get_clean(); while ($exportData = mysql_fetch_assoc($result)) { // run each field type on the result $Row = array(); foreach ($Config['_Field'] as $Field => $Value) { $FieldType = explode('_', $Value); if (in_array($Field, $VisibleFields)) { if (count($FieldType) == 2) { // include fieldtype if (file_exists(DB_TOOLKIT . '/data_form/fieldtypes/' . $FieldType[0] . '/functions.php')) { include_once DB_TOOLKIT . '/data_form/fieldtypes/' . $FieldType[0] . '/functions.php'; } // [type_processValue($Value, $Type, $Field, $Config, $EID, $Data) $Func = $FieldType[0] . '_processvalue'; //$FieldValue = $outRow = $exportData[$Field]; if (function_exists($Func)) { // echo 'yes there is '.$Func.'<br>'; $Row[] = trim(strip_tags(str_replace('<br />', "\r\n", $Func($outRow, $FieldType[1], $Field, $Config, $Media['ID'], $exportData)))); } else { $Row[] = $outRow; } //dump($FieldType); } else { $Row[] = $exportData[$Field]; } } } //combine row ob_start(); fputcsv($CSVout, $Row, ',') . "\r\n"; $out .= ob_get_clean(); } //while($export) // Format the data header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Content-Length: " . strlen($out)); // Output to browser with appropriate mime type, you choose ;) //header("Content-type: text/x-csv"); //header("Content-type: text/csv"); header("Content-type: application/csv charset=UTF-8"); header("Content-Disposition: attachment; filename={$filename}"); //echo '<pre>'; echo $out; //echo '</pre>'; fclose($CSVout); mysql_close(); exit; } if ($exportFormat == 'template') { echo dt_renderInterface($Media['ID']); exit; } if ($exportFormat != 'pdf') { $Element = getelement($Media['ID']); $Config = $Element['Content']; if (!empty($Config['_Show_Plugins'])) { // to do : configure adding plugins to the tool bar if (file_exists(DB_TOOLKIT . 'data_report/plugins/' . $exportFormat . '/functions.php')) { include_once DB_TOOLKIT . 'data_report/plugins/' . $exportFormat . '/functions.php'; mysql_close(); exit; } } } } }