<?php

$Responses = new PerchForms_Responses($API);
$HTML = $API->get('HTML');
$message = false;
if (isset($_GET['id']) && $_GET['id'] != '') {
    $Response = $Responses->find($_GET['id']);
} else {
    PerchUtil::redirect($API->app_path());
}
if (isset($_GET['file']) && $_GET['file'] != '') {
    $files = $Response->files();
    $file = $files->{$_GET}['file'];
    if (file_exists($file->path)) {
        header('Content-Type: ' . $file->mime);
        header('Content-Length: ' . filesize($file->path));
        header('Content-Disposition: attachment;filename="' . $file->name . '"');
        $fp = fopen($file->path, 'r');
        fpassthru($fp);
        fclose($fp);
        exit;
    }
}
$Form = $API->get('Form');
if ($Form->submitted()) {
    if ($Response->responseSpam()) {
        $Response->mark_not_spam();
        $message = $HTML->success_message('Successfully marked as not being spam.');
    } else {
        $Response->mark_as_spam();
        $message = $HTML->success_message('Successfully marked as spam.');
<?php

$Forms = new PerchForms_Forms($API);
$Responses = new PerchForms_Responses($API);
$HTML = $API->get('HTML');
$Paging = $API->get('Paging');
$Paging->set_per_page(10);
$filter = 'all';
if (isset($_GET['id']) && $_GET['id'] != '') {
    $Form = $Forms->find($_GET['id']);
    $spam = false;
    if (isset($_GET['spam']) && ($_GET['spam'] = 1)) {
        $spam = true;
        $filter = 'spam';
    }
    $responses = $Responses->get_for_from($_GET['id'], $Paging, $spam);
} else {
    PerchUtil::redirect($API->app_path());
}
 public function process_response($SubmittedForm)
 {
     $opts = $this->_load_options();
     $data = array();
     $data['fields'] = array();
     $data['files'] = array();
     $data['page'] = $SubmittedForm->page;
     if (class_exists('PerchContent_Pages')) {
         $Pages = new PerchContent_Pages();
         $Page = $Pages->find_by_path($SubmittedForm->page);
         if ($Page) {
             $data['page'] = array('id' => $Page->pageID(), 'title' => $Page->pageTitle(), 'path' => $Page->pagePath(), 'navtext' => $Page->pageNavText());
         }
     }
     // Anti-spam
     $spam = false;
     $antispam = $SubmittedForm->get_antispam_values();
     $environment = $_SERVER;
     $akismetAPIKey = false;
     if (isset($opts->akismet) && $opts->akismet) {
         if (isset($opts->akismetAPIKey) && $opts->akismetAPIKey != '') {
             $akismetAPIKey = $opts->akismetAPIKey;
         }
     }
     $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey);
     // Files
     if (!$spam && PerchUtil::count($SubmittedForm->files)) {
         if (isset($opts->fileLocation) && $opts->fileLocation != '') {
             foreach ($SubmittedForm->files as $key => &$details) {
                 if ($details['error'] == '0' && $details['size'] > 0) {
                     // no error, upload worked
                     $attrs = $SubmittedForm->get_template_attributes($key);
                     if (is_uploaded_file($details['tmp_name'])) {
                         $filename = $details['name'];
                         $dest = rtrim($opts->fileLocation, '\\/') . DIRECTORY_SEPARATOR;
                         if (file_exists($dest . $filename)) {
                             $filename = time() . $filename;
                         }
                         if (file_exists($dest . $filename)) {
                             $filename = time() . mt_rand() . $filename;
                         }
                         if (PerchUtil::move_uploaded_file($details['tmp_name'], $dest . $filename)) {
                             $details['new_path'] = $dest . $filename;
                             $details['new_filename'] = $filename;
                             $file = new stdClass();
                             $file->name = $filename;
                             $file->path = $dest . $filename;
                             $file->size = $details['size'];
                             $file->mime = '';
                             if (isset($SubmittedForm->mimetypes[$key])) {
                                 $file->mime = $SubmittedForm->mimetypes[$key];
                             }
                             $file->attributes = $attrs->get_attributes();
                             $data['files'][$key] = $file;
                         }
                     }
                 }
             }
         } else {
             PerchUtil::debug('Form ' . $SubmittedForm->id . ': File save location not set, files discarded.', 'error');
         }
     }
     // Fields
     if (PerchUtil::count($SubmittedForm->data)) {
         foreach ($SubmittedForm->data as $key => $value) {
             $attrs = $SubmittedForm->get_template_attributes($key);
             if ($attrs) {
                 $field = new stdClass();
                 $field->attributes = $attrs->get_attributes();
                 // skip submit fields
                 if (isset($field->attributes['type']) && $field->attributes['type'] == 'submit') {
                     // skip it.
                 } else {
                     // skip honeypot field
                     if (isset($field->attributes['antispam']) && $field->attributes['antispam'] == 'honeypot') {
                         // skip it
                     } else {
                         $field->value = $value;
                         $data['fields'][$attrs->id()] = $field;
                     }
                 }
             }
         }
     }
     if (!$spam && isset($opts->email) && $opts->email) {
         $this->_send_email($opts, $data);
     }
     if (isset($opts->store) && $opts->store) {
         $json = PerchUtil::json_safe_encode($data);
         $record = array();
         $record['responseJSON'] = $json;
         $record['formID'] = $this->id();
         $record['responseIP'] = $_SERVER['REMOTE_ADDR'];
         if ($spam) {
             $record['responseSpam'] = '1';
         }
         $spam_data = array();
         $spam_data['fields'] = $antispam;
         $spam_data['environment'] = $environment;
         $record['responseSpamData'] = PerchUtil::json_safe_encode($spam_data);
         $Responses = new PerchForms_Responses($this->api);
         $Response = $Responses->create($record);
     }
     if ($spam || !isset($opts->store) || !$opts->store) {
         // not storing, so drop files
         if (PerchUtil::count($data['files'])) {
             foreach ($data['files'] as $file) {
                 if (file_exists($file->path)) {
                     @unlink($file->path);
                 }
             }
         }
     }
     // Redirect?
     if (isset($opts->successURL) && $opts->successURL) {
         PerchUtil::redirect(trim($opts->successURL));
     }
 }