예제 #1
0
function processReportUpload()
{
    // Build filepath
    $uploadfile = getcwd() . '/tmp/' . basename($_FILES['file']['name']);
    // If move from temp PHP directory == success, then true
    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
        // Check to see if this is a duplicate report
        $isDuplicate = getReportData(NULL, gps('report_name'));
        if ($isDuplicate) {
            unlink($uploadfile);
            // Put result in a encoded JSON return
            $out = array("result" => 'duplicate', "report_name" => $isDuplicate['report_name'], "description" => $isDuplicate['short_description'], "report_id" => $out['report_id']);
            return json_encode($out);
        }
        //// Start building query
        // Get the file as binary
        $report_data = file_get_contents($uploadfile);
        // Report Name - Used to check for duplicates
        $report_name = gps('report_name');
        // Report Short Description
        $short_description = gps('short_description');
        // New Report?
        $reportStatus = gps('reportNew');
        // Author ID
        $aud = gps('report_author_id');
        $report_owner_author_id = $aud;
        $report_the_user_id = $aud;
        // Scope of Data
        $report_type_id = gps('report_type_id');
        // Scope of Data
        $report_scope_id = gps('report_scope_id');
        // Publication Number
        $pid = gps('report_number');
        // Filename
        $report_file_name = basename($_FILES['file']['name']);
        // Publication Date. Tenatively date of import.
        $report_publication_date = date("m-d-y");
        // xx-xx-xxxx
        // report filesize
        $report_file_size = filesize($uploadfile);
        // set report ID to null if it is a new report, otherwise, use $stored_report_id
        //$report_id = ($reportStatus == 0) ? NULL : $reportStatus;
        // Build Parameters
        $spParams = array(array(NULL, 1), array(NULL, 1), array($report_owner_author_id, 1), array($report_id, 1), array($report_name, 1), array($short_description, 1), array($pid, 1), array($report_publication_date, 1), array(1, 1), array($report_type_id, 1), array('http://', 1), array(1, 1), array($report_file_size, 1), array($report_file_name, 1), array($report_file_name, 1), array('pdf', 1), array('application/pdf', 1), array(1, 1), array($report_data, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY)), array(1, 1), array($report_scope_id, 1), array($report_the_user_id, 1));
        // call the procedure
        $result = callStoredProcedure(sqlsrvConnect(), 'Report_WyomingTobaccoEdit_SP', $spParams);
        // if JSON result TRUE
        if ($result['success']) {
            unlink($uploadfile);
            // Delete uploaded file as its now in DB
            // prepare JSON data pairs in to array
            $out = array("result" => 'success', "post_ID" => gps('post_ID'), "description" => gps('short_description'), "category" => gps('category'), "scope" => gps('sod'), "publication_number" => gps('pid'), "report_id" => $result['report_id'], "report_name" => $result['report_name']);
            // return array as json
            return json_encode($out);
        } else {
            $error = print_r($result, TRUE);
            // if anything else, return error
            $out = array("result" => "error" . $error);
            return json_encode($out);
        }
    }
}
function wysac_delete_saved_report()
{
    global $wpdb;
    include "processReportUpload.php";
    $conn = sqlsrvConnect();
    // Used only with MYSQL
    $post_id = $_POST['post_id'];
    // Use donly with SQLSRV
    $report_author_id = $_POST['report_author_id'];
    $report_id = $_POST['report_id'];
    /** Begin SQL Srv SP Call **/
    $spParams = array(array(NULL, 1), array(NULL, 1), array($report_id, 1), array($report_author_id, 1));
    $sp = "{ call dbo.ReportDelete_SP(?,?,?,?) }";
    $result = sqlsrv_query($conn, $sp, $spParams);
    /** End SQL Srv SP Call **/
    if ($result) {
        // if SQLSRV return TRUE
        if ($wpdb->delete('wp_wysac_pdf_id', array('post_id' => $post_id), $where_format = null)) {
            // if WPDB return TRUE
            return json_encode(array('deleted' => 'true', 'post_id' => $report_id));
        } else {
            return json_encode(array('deleted' => 'false', 'db' => 'mysql'));
        }
    } else {
        return json_encode(array('deleted' => 'false', 'db' => 'sqlsrv'));
    }
}