示例#1
0
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('&nbsp;', '', 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;
                }
            }
        }
    }
}
示例#2
0
function dr_trackActivity($Act, $EID, $ReturnValue, $Level = 0)
{
    //return;
    $Table = '';
    if (!empty($EID)) {
        $Setup = getelement($EID);
        $Table = $Setup['Content']['_main_table'];
    }
    //$ReturnValue = $Config['Content']['_ReturnFields'][0];
    $Activity = df_checkActivity($Act);
    $UserID = 0;
    if (!empty($_SESSION['UserBase']['Member']['EmailAddress'])) {
        $UserID = $_SESSION['UserBase']['Member']['EmailAddress'];
    }
    if (mysql_query("INSERT INTO `_adittrack_entries` (\n\t\t\t\t\t\t`ID` ,\n\t\t\t\t\t\t`User` ,\n\t\t\t\t\t\t`Activity` ,\n\t\t\t\t\t\t`Table` ,\n\t\t\t\t\t\t`Entry` ,\n\t\t\t\t\t\t`Element`,\n\t\t\t\t\t\t`Date`\n\t\t\t\t\t\t)\n\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\tNULL , '" . $UserID . "', '" . $Activity . "', '" . $Table . "', '" . $ReturnValue . "', '" . $EID . "', '" . date('Y-m-d H:i:s') . "'\n\t\t\t\t\t\t);")) {
        return true;
    }
    if ($Level == 0) {
        mysql_query("CREATE TABLE IF NOT EXISTS `_adittrack_entries` (\n\t\t\t\t\t  `ID` int(11) NOT NULL auto_increment,\n\t\t\t\t\t  `User` varchar(255) NOT NULL,\n\t\t\t\t\t  `Activity` int(11) NOT NULL,\n\t\t\t\t\t  `Table` varchar(255) NOT NULL,\n\t\t\t\t\t  `Entry` varchar(255) NOT NULL,\n\t\t\t\t\t  `Element` int(11) NOT NULL,\n\t\t\t\t\t  `Date` datetime NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (`ID`)\n\t\t\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8");
        return dr_trackActivity($Act, $EID, $ReturnValue, 1);
    }
    return false;
}
示例#3
0
function df_deleteEntries($EID, $Data)
{
    global $wpdb;
    $Data = df_cleanArray(explode('|||', $Data));
    $El = getelement($EID);
    $Config = $El['Content'];
    if (empty($Config['_Show_Delete']) && empty($Config['_Show_Delete_action'])) {
        return 'Deleting is Disabled';
    }
    if (!empty($RefConfig['Field'])) {
        if (in_array('imageupload', $RefConfig['Field'])) {
            $ImagesToDelete = array_keys($RefConfig['Field'], 'imageupload');
        }
    }
    $Index = 0;
    $Return = '';
    foreach ($Data as $ID) {
        $ID = str_replace($EID . '_', '', $ID);
        //$Pre = $wpdb->escape("SELECT * FROM `" . $Config['_main_table'] . "` WHERE `" . $Config['_ReturnFields'][0] . "` = '" . $ID . "' LIMIT 1;");
        $Pre = "SELECT * FROM `" . $Config['_main_table'] . "` WHERE `" . $Config['_ReturnFields'][0] . "` = '" . $ID . "' LIMIT 1;";
        $OldData = $wpdb->get_row($Pre, ARRAY_A);
        dr_trackActivity('Delete', $EID, $ID);
        if (!empty($ImagesToDelete)) {
            foreach ($ImagesToDelete as $Field) {
                if (file_exists($OldData[$Field])) {
                    unlink($OldData[$Field]);
                }
            }
        }
        // post update processess
        if (!empty($Config['_FormProcessors'])) {
            foreach ($Config['_FormProcessors'] as $processID => $Setup) {
                if (!empty($Setup['_onDelete'])) {
                    if (file_exists(WP_PLUGIN_DIR . '/db-toolkit/data_form/processors/' . $Setup['_process'] . '/functions.php')) {
                        include_once WP_PLUGIN_DIR . '/db-toolkit/data_form/processors/' . $Setup['_process'] . '/functions.php';
                        $func = 'pre_process_' . $Setup['_process'];
                        if (function_exists($func)) {
                            $OldData = $func($OldData, $Setup, $Config);
                        }
                    }
                }
            }
        }
        $deleteQuery = "DELETE FROM `" . $Config['_main_table'] . "` WHERE `" . $Config['_ReturnFields'][0] . "` = '" . $ID . "' LIMIT 1;";
        $Rows = $wpdb->query($deleteQuery);
        // post update processess
        if (!empty($Config['_FormProcessors'])) {
            foreach ($Config['_FormProcessors'] as $processID => $Setup) {
                if (!empty($Setup['_onDelete'])) {
                    if (file_exists(WP_PLUGIN_DIR . '/db-toolkit/data_form/processors/' . $Setup['_process'] . '/functions.php')) {
                        include_once WP_PLUGIN_DIR . '/db-toolkit/data_form/processors/' . $Setup['_process'] . '/functions.php';
                        $func = 'post_process_' . $Setup['_process'];
                        if (function_exists($func)) {
                            $OldData = $func($OldData, $Setup, $Config);
                            if (!is_array($OldData)) {
                                //$Config['_UpdateSuccess'] = $OldData;
                            }
                        }
                    }
                }
            }
        }
        $Index++;
    }
    $Note = 'Item';
    if ($Rows > 1) {
        $Note = 'Items';
    }
    return $Rows . ' ' . $Note . ' Deleted<br />';
}