function acf_repeater_population($form) { GFCommon::log_debug("acf_repeater_population() function called for form {$form['id']}"); // filters are applied only to form ID 4. Change to your form ID foreach ($form['fields'] as &$field) { // if the field is not a radio button type or it does not have the CSS Class Name required, continue if ('radio' != $field->type || false === strpos($field->cssClass, 'dates_from_acf')) { continue; } // start with an empty choices array $field->choices = array(); // need the ID of the current post global $post; GFCommon::log_debug("global post =>" . print_r($post, true)); $rows = get_field('coursedates'); if ($rows) { GFCommon::log_debug("get_field() for coursedates: \$rows => " . print_r($rows, 1)); foreach ($rows as $row) { $city = $row['city']; $text = date_i18n('l j. F Y', strtotime($row['startdate'])) . " - " . $city; $field->choices[] = array('text' => $text, 'value' => $row['startdate'] . " - " . $city); } } else { $field->choices[] = array('text' => 'Ingen ledige datoer', 'value' => 'Ingen ledige datoer'); } break; } // always return the form return $form; }
function GFUEA_custom_notification_attachments($notification, $form, $entry) { $log = 'rw_notification_attachments() - '; GFCommon::log_debug($log . 'starting.'); # mail("*****@*****.**","Notification Fire" . date("Y-m-d h:i:s"), print_r($notification, true) . print_r($form,true) . print_r($entry,true)); if (substr($notification["name"], -5) == "GFUEA") { //mail("*****@*****.**","Notification Fire" . date("Y-m-d h:i:s"), print_r($notification, true) . print_r($form,true) . print_r($entry,true)); $fileupload_fields = GFCommon::get_fields_by_type($form, array('fileupload')); if (!is_array($fileupload_fields)) { return $notification; } $attachments = array(); $upload_root = RGFormsModel::get_upload_root(); foreach ($fileupload_fields as $field) { $url = $entry[$field['id']]; if (empty($url)) { continue; } elseif ($field['multipleFiles']) { $uploaded_files = json_decode(stripslashes($url), true); $zip = new ZipArchive(); //$filetext = date("Y-m-d his"); $filename = $upload_root . "/uploaded_files" . $entry['id'] . ".zip"; if ($zip->open($filename, ZipArchive::CREATE) !== TRUE) { foreach ($uploaded_files as $uploaded_file) { $attachment = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $uploaded_file); GFCommon::log_debug($log . 'attaching the file: ' . print_r($attachment, true)); $attachments[] = $attachment; } } else { foreach ($uploaded_files as $uploaded_file) { $attachment = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $uploaded_file); GFCommon::log_debug($log . 'attaching the file: ' . print_r($attachment, true)); $new_filename = substr($attachment, strrpos($attachment, '/') + 1); $zip->addFile($attachment, $new_filename); //$attachments[] = $attachment; } $zip->close(); $attachments[] = $filename; add_filter('gform_confirmation', 'gfuea_clean_zips', 10, 4); } } else { $attachment = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $url); GFCommon::log_debug($log . 'attaching the file: ' . print_r($attachment, true)); $attachments[] = $attachment; } } $notification['attachments'] = $attachments; } //mail("*****@*****.**","Notification Fire" . date("Y-m-d h:i:s"), "Attach IDs:\n" . print_r($attachIds, true) . "\nNotification:\n" . print_r($notification, true) . "\nForm:\n" .print_r($form,true) . "\nEntry:\n" .print_r($entry,true)); GFCommon::log_debug($log . 'stopping.'); return $notification; }
function wpan_send_form_tracking_event($entry, $form) { global $post; $msg = "About to send form tracking event to Google Analytics..."; wpan_log_debug($msg); GFCommon::log_debug($msg); /* Extract the plugin options from the database */ $options = wpan_get_options(); $tracking_uid = isset($options['tracking_uid']) ? $options['tracking_uid'] : ''; $debug = isset($options['debug']) ? $options['debug'] : ''; $form_title = $form['title']; /* I have taken the following four lines of code from https://github.com/theiconic/php-ga-measurement-protocol; thank you! */ $document_path = str_replace(home_url(), '', $entry['source_url']); $document_location = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI']; $document_title = isset($post) && get_the_title($post) ? get_the_title($post) : 'no title'; /* Setup the class */ $ga_options = ['client_create_random_id' => true, 'client_fallback_id' => 555, 'client_id' => null, 'user_id' => null, 'adapter' => ['async' => true, 'ssl' => false]]; /* Connect to tracker */ $gatracking = new \Racecore\GATracking\GATracking($tracking_uid, $ga_options); /* Build GA event */ $event = $gatracking->createTracking('Event'); $event->setAsNonInteractionHit(false); $event->setEventCategory('Contact'); $event->setEventAction($form_title); $event->setEventLabel($document_path); $event->setDocumentPath($document_path); $event->setDocumentLocation($document_location); $event->setDocumentTitle($document_title); /* Send event to GA severs */ $response = $gatracking->sendTracking($event); /* Debug */ if ($debug) { wpan_log_debug("Sent the following event to Google Analytics:"); wpan_log_debug($event); wpan_log_debug("Received the following respons from Google Analytics (ASYNC, so it might be empty): "); wpan_log_debug($response); // wpan_log_debug( "This is the form that triggered the event:" ); // wpan_log_debug( $form ); // wpan_log_debug( "This is the entry of the form in Gravity Forms:" ); // wpan_log_debug( $entry ); } }
/** * Send the file. * * @param $form_id * @param $file */ private static function deliver($form_id, $file) { $path = GFFormsModel::get_upload_path($form_id); $file_path = trailingslashit($path) . $file; GFCommon::log_debug("delivering file: {$file_path}"); if (file_exists($file_path)) { GFCommon::log_debug("file exists - starting delivery"); $content_type = self::get_content_type($file_path); $content_disposition = rgget('dl') ? 'attachment' : 'inline'; nocache_headers(); header('Robots: none'); header('Content-Type: ' . $content_type); header('Content-Description: File Transfer'); header('Content-Disposition: ' . $content_disposition . '; filename="' . basename($file) . '"'); header('Content-Transfer-Encoding: binary'); self::readfile_chunked($file_path); die; } else { GFCommon::log_debug("file does not exist. abort with 404"); self::die_404(); } }
public function handle_page_request() { global $HTTP_RAW_POST_DATA; $route = get_query_var(GFWEBAPI_ROUTE_VAR); if (false == $route) { return; } self::authenticate(); $test_mode = rgget("test"); if ($test_mode) { die("test mode"); } $settings = get_option('gravityformsaddon_gravityformswebapi_settings'); if (empty($settings)) { $this->die_not_authorized(); } $account_id = $settings["impersonate_account"]; wp_set_current_user($account_id); $route_parts = pathinfo($route); $format = rgar($route_parts, 'extension'); if ($format) { $route = str_replace("." . $format, "", $route); } $path_array = explode("/", $route); $collection = strtolower(rgar($path_array, 0)); $id = rgar($path_array, 1); if (strpos($id, ";") !== false) { $id = explode(";", $id); } $collection2 = strtolower(rgar($path_array, 2)); $id2 = rgar($path_array, 3); if (strpos($id2, ";") !== false) { $id2 = explode(";", $id2); } if (empty($format)) { $format = "json"; } $schema = strtolower(rgget("schema")); $offset = isset($_GET["paging"]["offset"]) ? strtolower($_GET["paging"]["offset"]) : 0; $page_size = isset($_GET["paging"]["page_size"]) ? strtolower($_GET["paging"]["page_size"]) : 10; $method = strtoupper($_SERVER['REQUEST_METHOD']); $args = compact("offset", "page_size", "schema"); if (empty($collection2)) { do_action("gform_webapi_" . strtolower($method) . "_" . $collection, $id, $format, $args); } else { do_action("gform_webapi_" . strtolower($method) . "_" . $collection . "_" . $collection2, $id, $id2, $format, $args); } if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents('php://input'); } GFCommon::log_debug("WebAPI: HTTP_RAW_POST_DATA = " . $HTTP_RAW_POST_DATA); $data = json_decode($HTTP_RAW_POST_DATA, true); // todo: tidy up this mess switch ($collection) { case "forms": switch ($collection2) { case "results": switch ($method) { case 'GET': $this->get_results($id); break; case 'DELETE': case 'PUT': case 'POST': default: $this->die_bad_request(); } break; case "properties": switch ($method) { case 'PUT': $this->put_forms_properties($data, $id); break; default: $this->die_bad_request(); } break; case "feeds": if (false == empty($id2)) { $this->die_bad_request(); } switch ($method) { case 'GET': $this->get_feeds(null, $id); break; case 'DELETE': $this->delete_feeds(null, $id); break; case 'PUT': $this->die_not_implemented(); break; case 'POST': $this->post_feeds($data, $id); break; default: $this->die_bad_request(); } break; case "entries": if (false == empty($id2)) { $this->die_bad_request(); } switch ($method) { case 'GET': $this->get_entries(null, $id, $schema); break; case 'POST': $this->post_entries($data, $id); break; case 'PUT': case 'DELETE': case 'POST': $this->die_not_implemented(); break; default: $this->die_bad_request(); } break; case "": switch ($method) { case 'GET': $this->get_forms($id, $schema); break; case 'DELETE': $this->delete_forms($id); break; case 'PUT': $this->put_forms($data, $id, $id2); break; case 'POST': if (false === empty($id)) { $this->die_bad_request(); } $this->post_forms($data, $id); break; default: $this->die_bad_request(); } break; default: $this->die_bad_request(); break; } break; case "entries": // route = /entries/{id} switch ($method) { case 'GET': switch ($collection2) { case "fields": // route = /entries/{id}/fields/{id2} $this->get_entries($id, null, $schema, $id2); break; case "": $this->get_entries($id, null, $schema); break; default: $this->die_bad_request(); } break; case 'DELETE': $this->delete_entries($id); break; case 'PUT': switch ($collection2) { case "properties": // route = /entries/{id}/properties/{id2} $this->put_entry_properties($data, $id); break; case "": $this->put_entries($data, $id); break; } break; case 'POST': if (false === empty($id)) { $this->die_bad_request(); } $this->post_entries($data); break; default: $this->die_bad_request(); } break; case "feeds": switch ($method) { case 'GET': $this->get_feeds($id); break; case 'DELETE': if (empty($id)) { $this->die_bad_request(); } $this->delete_feeds($id); break; case 'PUT': $this->put_feeds($data, $id); break; case 'POST': if (false === empty($id)) { $this->die_bad_request(); } $this->post_feeds($data); break; default: $this->die_bad_request(); } break; default: $this->die_bad_request(); break; } $this->die_bad_request(); }
private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = "", $message_format = "html", $attachments = "") { $to = str_replace(" ", "", $to); $bcc = str_replace(" ", "", $bcc); //invalid to email address or no content. can't send email if (!GFCommon::is_valid_email($to) || empty($subject) && empty($message)) { return; } if (!GFCommon::is_valid_email($from)) { $from = get_bloginfo("admin_email"); } //invalid from address. can't send email if (!GFCommon::is_valid_email($from)) { return; } $content_type = $message_format == "html" ? "text/html" : "text/plain"; $name = empty($from_name) ? $from : $from_name; $headers = "From: \"{$name}\" <{$from}> \r\n"; $headers .= GFCommon::is_valid_email($reply_to) ? "Reply-To: {$reply_to}\r\n" : ""; $headers .= GFCommon::is_valid_email($bcc) ? "Bcc: {$bcc}\r\n" : ""; $headers .= "Content-type: {$content_type}; charset=" . get_option('blog_charset') . "\r\n"; GFCommon::log_debug("Sending email via wp_mail()"); GFCommon::log_debug(print_r(compact("to", "subject", "message", "headers", "attachments"), true)); $result = wp_mail($to, $subject, $message, $headers, $attachments); $result_text = $result ? "success" : "failed"; GFCommon::log_debug("Result from wp_mail(): {$result} ({$result_text})"); }
function add_note_sidebar($lead, $form) { global $current_user; $user_data = get_userdata($current_user->ID); $project_name = $lead['151']; $email_to = $_POST['gentry_email_notes_to_sidebar']; $email_note_info = ''; //emailing notes if configured if (!empty($email_to)) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Preparing to email entry notes.'); $email_to = $_POST['gentry_email_notes_to_sidebar']; $email_from = $current_user->user_email; $email_subject = stripslashes('Response Required Maker Application: ' . $lead['id'] . ' ' . $project_name); $entry_url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=mf_entries&view=mfentry&id=' . $form['id'] . '&lid=' . rgar($lead, 'id'); $body = stripslashes($_POST['new_note_sidebar']) . '<br /><br />Please reply in entry:<a href="' . $entry_url . '">' . $entry_url . '</a>'; $headers = "From: \"{$email_from}\" <{$email_from}> \r\n"; //Enable HTML Email Formatting in the body add_filter('wp_mail_content_type', 'wpse27856_set_content_type'); $result = wp_mail($email_to, $email_subject, $body, $headers); //Remove HTML Email Formatting remove_filter('wp_mail_content_type', 'wpse27856_set_content_type'); $email_note_info = '<br /><br />:SENT TO:[' . implode(",", $email_to) . ']'; } mf_add_note($lead['id'], nl2br(stripslashes($_POST['new_note_sidebar'] . $email_note_info))); }
public static function is_auto_update_disabled() { // Currently WordPress won't ask Gravity Forms to update if background updates are disabled. // Let's double check anyway. // WordPress background updates are disabled if you don't want file changes. if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { return true; } if (defined('WP_INSTALLING')) { return true; } $wp_updates_disabled = defined('AUTOMATIC_UPDATER_DISABLED') && AUTOMATIC_UPDATER_DISABLED; $wp_updates_disabled = apply_filters('automatic_updater_disabled', $wp_updates_disabled); if ($wp_updates_disabled) { GFCommon::log_debug(__METHOD__ . '() - Background updates are disabled in WordPress.'); return true; } // Now check Gravity Forms Background Update Settings $enabled = get_option('gform_enable_background_updates'); GFCommon::log_debug('GFForms::is_auto_update_disabled() - $enabled: ' . var_export($enabled, true)); /** * Filter to disable Gravity Forms Automatic updates * * @param bool $enabled Check if automatic updates are enabled, and then disable it */ $disabled = apply_filters('gform_disable_auto_update', !$enabled); GFCommon::log_debug('GFForms::is_auto_update_disabled() - $disabled: ' . var_export($disabled, true)); if (!$disabled) { $disabled = defined('GFORM_DISABLE_AUTO_UPDATE') && GFORM_DISABLE_AUTO_UPDATE; GFCommon::log_debug('GFForms::is_auto_update_disabled() - GFORM_DISABLE_AUTO_UPDATE: ' . var_export($disabled, true)); } return $disabled; }
/** * Trims values from an array of elements e.g. notifications and confirmations * * @param array $meta_array Form object. * @param array $form Form object. * @param bool $updated Output parameter. * * @return array $meta_array */ public static function trim_conditional_logic_values($meta_array, $form, &$updated = false) { GFCommon::log_debug('GFFormsModel::trim_conditional_logic_values(): Starting.'); if (is_array($meta_array)) { foreach ($meta_array as &$meta) { $meta = self::trim_conditional_logic_values_from_element($meta, $form, $updated); } } if ($updated) { GFCommon::log_debug('GFFormsModel::trim_conditional_logic_values(): Conditional logic values trimmed.'); } return $meta_array; }
private static function upload_files($form, $files) { //Creating temp folder if it does not exist $target_path = RGFormsModel::get_upload_path($form["id"]) . "/tmp/"; wp_mkdir_p($target_path); foreach ($form["fields"] as $field) { $input_name = "input_{$field["id"]}"; //skip fields that are not file upload fields or that don't have a file to be uploaded or that have failed validation $input_type = RGFormsModel::get_input_type($field); if (!in_array($input_type, array("fileupload", "post_image")) || $field["failed_validation"] || empty($_FILES[$input_name]["name"])) { GFCommon::log_debug("upload_files() - skipping field: {$field["label"]}({$field["id"]} - {$field["type"]})"); continue; } $file_info = RGFormsModel::get_temp_filename($form["id"], $input_name); GFCommon::log_debug("upload_files() - temp file info: " . print_r($file_info, true)); if ($file_info && move_uploaded_file($_FILES[$input_name]['tmp_name'], $target_path . $file_info["temp_filename"])) { $files[$input_name] = $file_info["uploaded_filename"]; GFCommon::log_debug("upload_files() - file uploaded successfully: {$file_info["uploaded_filename"]}"); } else { GFCommon::log_error("upload_files() - file could not be uploaded: tmp_name: {$_FILES[$input_name]['tmp_name']} - target location: " . $target_path . $file_info["temp_filename"]); } } return $files; }
public static function start_export($form) { $form_id = $form['id']; $fields = $_POST['export_field']; $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00'); $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59'); $search_criteria['status'] = 'active'; $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form); if (!empty($start_date)) { $search_criteria['start_date'] = $start_date; } if (!empty($end_date)) { $search_criteria['end_date'] = $end_date; } $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info'); GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}"); GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}"); $form = self::add_default_export_fields($form); $entry_count = GFAPI::count_entries($form_id, $search_criteria); $page_size = 100; $offset = 0; //Adding BOM marker for UTF-8 $lines = chr(239) . chr(187) . chr(191); // set the separater $separator = gf_apply_filters('gform_export_separator', $form_id, ',', $form_id); $field_rows = self::get_field_row_count($form, $fields, $entry_count); //writing header $headers = array(); foreach ($fields as $field_id) { $field = RGFormsModel::get_field($form, $field_id); $label = gf_apply_filters('gform_entries_field_header_pre_export', array($form_id, $field_id), GFCommon::get_label($field, $field_id), $form, $field); $value = str_replace('"', '""', $label); GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}"); $headers[$field_id] = $value; $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0; if ($subrow_count == 0) { $lines .= '"' . $value . '"' . $separator; } else { for ($i = 1; $i <= $subrow_count; $i++) { $lines .= '"' . $value . ' ' . $i . '"' . $separator; } } GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}"); } $lines = substr($lines, 0, strlen($lines) - 1) . "\n"; //paging through results for memory issues while ($entry_count > 0) { $paging = array('offset' => $offset, 'page_size' => $page_size); $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging); $leads = gf_apply_filters('gform_leads_before_export', $form_id, $leads, $form, $paging); foreach ($leads as $lead) { foreach ($fields as $field_id) { switch ($field_id) { case 'date_created': $lead_gmt_time = mysql2date('G', $lead['date_created']); $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time); $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true); break; default: $field = RGFormsModel::get_field($form, $field_id); $value = is_object($field) ? $field->get_value_export($lead, $field_id, false, true) : rgar($lead, $field_id); $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead); GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}"); break; } if (isset($field_rows[$field_id])) { $list = empty($value) ? array() : unserialize($value); foreach ($list as $row) { $row_values = array_values($row); $row_str = implode('|', $row_values); $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator; } //filling missing subrow columns (if any) $missing_count = intval($field_rows[$field_id]) - count($list); for ($i = 0; $i < $missing_count; $i++) { $lines .= '""' . $separator; } } else { $value = maybe_unserialize($value); if (is_array($value)) { $value = implode('|', $value); } $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator; } } $lines = substr($lines, 0, strlen($lines) - 1); GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}"); $lines .= "\n"; } $offset += $page_size; $entry_count -= $page_size; if (!seems_utf8($lines)) { $lines = utf8_encode($lines); } $lines = apply_filters('gform_export_lines', $lines); echo $lines; $lines = ''; } /** * Fires after exporting all the entries in form * * @param array $form The Form object to get the entries from * @param string $start_date The start date for when the export of entries should take place * @param string $end_date The end date for when the export of entries should stop * @param array $fields The specified fields where the entries should be exported from */ do_action('gform_post_export_entries', $form, $start_date, $end_date, $fields); }
public static function search_leads($form_id, $search_criteria = array(), $sorting = null, $paging = null) { global $wpdb; $sort_field = isset($sorting["key"]) ? $sorting["key"] : "date_created"; // column, field or entry meta if (is_numeric($sort_field)) { $sql = self::sort_by_field_query($form_id, $search_criteria, $sorting, $paging); } else { $sql = self::sort_by_column_query($form_id, $search_criteria, $sorting, $paging); } //initializing rownum $wpdb->query("select @rownum:=0"); GFCommon::log_debug($sql); //getting results $results = $wpdb->get_results($sql); $leads = GFFormsModel::build_lead_array($results); return $leads; }
/** * Deletes all rows in the lead table that don't have corresponding rows in the details table. * * @since 2.0.0 * @access public * @static * @global $wpdb */ public static function delete_orphaned_entries() { global $wpdb; GFCommon::log_debug(__METHOD__ . '(): Starting to delete orphaned entries'); $lead_table = GFFormsModel::get_lead_table_name(); $lead_details_table = GFFormsModel::get_lead_details_table_name(); $sql = "DELETE FROM {$lead_table} WHERE id NOT IN( SELECT lead_id FROM {$lead_details_table} )"; $result = $wpdb->query($sql); GFCommon::log_debug(__METHOD__ . '(): Delete result: ' . print_r($result, true)); }
public static function is_auto_update_disabled() { // Background updates are disabled if you don't want file changes. if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { return true; } if (defined('WP_INSTALLING')) { return true; } $enabled = get_option('gform_enable_background_updates'); GFCommon::log_debug('GFForms::is_auto_update_disabled() - $enabled: ' . var_export($enabled, true)); $disabled = apply_filters('gform_disable_auto_update', !$enabled); GFCommon::log_debug('GFForms::is_auto_update_disabled() - $disabled: ' . var_export($disabled, true)); if (!$disabled) { $disabled = defined('GFORM_DISABLE_AUTO_UPDATE') && GFORM_DISABLE_AUTO_UPDATE; GFCommon::log_debug('GFForms::is_auto_update_disabled() - GFORM_DISABLE_AUTO_UPDATE: ' . var_export($disabled, true)); } return $disabled; }
/** * Saves form meta. Note the special requirements for the meta string. * * @param $id * @param string $form_json A valid JSON string. The JSON is manipulated before decoding and is designed to work together with jQuery.toJSON() rather than json_encode. Avoid using json_encode as it will convert unicode characters into their respective entities with slashes. These slashes get stripped so unicode characters won't survive intact. * * @return array */ public static function save_form_info($id, $form_json) { global $wpdb; $form_json = stripslashes($form_json); $form_json = nl2br($form_json); GFCommon::log_debug("form meta json:" . $form_json); $form_meta = json_decode($form_json, true); GFCommon::log_debug("form meta:"); GFCommon::log_debug(print_r($form_json, true)); if (!$form_meta) { return array("status" => "invalid_json", "meta" => null); } $form_table_name = $wpdb->prefix . "rg_form"; //Making sure title is not duplicate $forms = RGFormsModel::get_forms(); foreach ($forms as $form) { if (strtolower($form->title) == strtolower($form_meta["title"]) && rgar($form_meta, "id") != $form->id) { return array("status" => "duplicate_title", "meta" => $form_meta); } } if ($id > 0) { $form_meta = GFFormsModel::trim_form_meta_values($form_meta); RGFormsModel::update_form_meta($id, $form_meta); //updating form title $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"])); $form_meta = RGFormsModel::get_form_meta($id); do_action('gform_after_save_form', $form_meta, false); return array("status" => $id, "meta" => $form_meta); } else { //inserting form $id = RGFormsModel::insert_form($form_meta["title"]); //updating object's id property $form_meta["id"] = $id; //creating default notification if (apply_filters('gform_default_notification', true)) { $default_notification = array("id" => uniqid(), "to" => "{admin_email}", "name" => __("Admin Notification", "gravityforms"), "event" => "form_submission", "toType" => "email", "subject" => __("New submission from", "gravityforms") . " {form_title}", "message" => "{all_fields}"); $notifications = array($default_notification["id"] => $default_notification); //updating notifications form meta RGFormsModel::save_form_notifications($id, $notifications); } // add default confirmation when saving a new form $confirmation_id = uniqid(); $confirmations = array(); $confirmations[$confirmation_id] = array('id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', 'message' => __("Thanks for contacting us! We will get in touch with you shortly.", "gravityforms"), 'url' => '', 'pageId' => '', 'queryString' => ''); GFFormsModel::save_form_confirmations($id, $confirmations); //updating form meta RGFormsModel::update_form_meta($id, $form_meta); $form_meta = RGFormsModel::get_form_meta($id); do_action('gform_after_save_form', $form_meta, true); return array("status" => $id * -1, "meta" => $form_meta); } }
public static function save_form_info($id, $form_json) { global $wpdb; $form_json = stripslashes($form_json); $form_json = nl2br($form_json); GFCommon::log_debug("form meta json:" . $form_json); $form_meta = json_decode($form_json, true); GFCommon::log_debug("form meta:"); GFCommon::log_debug(print_r($form_json, true)); if (!$form_meta) { return array("status" => "invalid_json", "meta" => null); } $form_table_name = $wpdb->prefix . "rg_form"; $meta_table_name = $wpdb->prefix . "rg_form_meta"; //Making sure title is not duplicate $forms = RGFormsModel::get_forms(); foreach ($forms as $form) { if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) { return array("status" => "duplicate_title", "meta" => $form_meta); } } if ($id > 0) { RGFormsModel::update_form_meta($id, $form_meta); //updating form title $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"])); $form_meta = RGFormsModel::get_form_meta($id); do_action('gform_after_save_form', $form_meta, false); return array("status" => $id, "meta" => $form_meta); } else { //inserting form $id = RGFormsModel::insert_form($form_meta["title"]); //updating object's id property $form_meta["id"] = $id; //creating default notification if (apply_filters('gform_default_notification', true)) { $form_meta["notification"]["to"] = "{admin_email}"; $form_meta["notification"]["subject"] = __("New submission from", "gravityforms") . " {form_title}"; $form_meta["notification"]["message"] = "{all_fields}"; } //updating form meta RGFormsModel::update_form_meta($id, $form_meta); $form_meta = RGFormsModel::get_form_meta($id); do_action('gform_after_save_form', $form_meta, true); return array("status" => $id * -1, "meta" => $form_meta); } }
public static function get_calculation_value($field_id, $form, $lead) { $filters = array('price', 'value', ''); $value = false; foreach ($filters as $filter) { if (is_numeric($value)) { //value found, exit loop break; } $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead)); } if (!$value || !is_numeric($value)) { GFCommon::log_debug("GFCommon::get_calculation_value(): No value or non-numeric value available for field #{$field_id}. Returning zero instead."); $value = 0; } return $value; }
public static function get_calculation_value($field_id, $form, $lead, $number_format = '') { $filters = array('price', 'value', ''); $value = false; $field = RGFormsModel::get_field($form, $field_id); $is_pricing_field = self::has_currency_value($field); if ($field->numberFormat) { $number_format = $field->numberFormat; } elseif (empty($number_format)) { $number_format = 'decimal_dot'; } foreach ($filters as $filter) { if (is_numeric($value)) { //value found, exit loop break; } $replaced_value = GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead); if ($is_pricing_field) { $value = self::to_number($replaced_value); } else { $value = self::clean_number($replaced_value, $number_format); } } if (!$value || !is_numeric($value)) { GFCommon::log_debug("GFCommon::get_calculation_value(): No value or non-numeric value available for field #{$field_id}. Returning zero instead."); $value = 0; } return $value; }
public static function get_leads($form_id, $sort_field_number = 0, $sort_direction = 'DESC', $search = '', $offset = 0, $page_size = 30, $star = null, $read = null, $is_numeric_sort = false, $start_date = null, $end_date = null, $status = 'active') { global $wpdb; if (empty($sort_field_number)) { $sort_field_number = "date_created"; } if (is_numeric($sort_field_number)) { $sql = self::sort_by_custom_field_query($form_id, $sort_field_number, $sort_direction, $search, $offset, $page_size, $star, $read, $is_numeric_sort, $status); } else { $sql = self::sort_by_default_field_query($form_id, $sort_field_number, $sort_direction, $search, $offset, $page_size, $star, $read, $is_numeric_sort, $start_date, $end_date, $status); } GFCommon::log_debug($sql); //initializing rownum $wpdb->query("select @rownum:=0"); //getting results $results = $wpdb->get_results($sql); $leads = self::build_lead_array($results); return $leads; }
private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = "", $message_format = "html", $attachments = "") { $to = str_replace(" ", "", $to); $bcc = str_replace(" ", "", $bcc); //invalid to email address or no content. can't send email if (!GFCommon::is_valid_email($to) || empty($subject) && empty($message)) { GFCommon::log_debug("Cannot send email because either the TO address is invalid or there is no SUBJECT or MESSAGE."); GFCommon::log_debug(print_r(compact("to", "subject", "message"), true)); return; } if (!GFCommon::is_valid_email($from)) { $from = get_bloginfo("admin_email"); } //invalid from address. can't send email if (!GFCommon::is_valid_email($from)) { GFCommon::log_debug("Cannot send email because the FROM address is invalid."); GFCommon::log_debug(print_r(compact("to", "from", "subject"), true)); return; } $content_type = $message_format == "html" ? "text/html" : "text/plain"; $name = empty($from_name) ? $from : $from_name; $headers = array(); $headers["From"] = "From: \"{$name}\" <{$from}>"; if (GFCommon::is_valid_email($reply_to)) { $headers["Reply-To"] = "Reply-To: {$reply_to}"; } if (GFCommon::is_valid_email($bcc)) { $headers["Bcc"] = "Bcc: {$bcc}"; } $headers["Content-type"] = "Content-type: {$content_type}; charset=" . get_option('blog_charset'); $abort_email = false; extract(apply_filters("gform_pre_send_email", compact("to", "subject", "message", "headers", "attachments", "abort_email"), $message_format)); $is_success = false; if (!$abort_email) { GFCommon::log_debug("Sending email via wp_mail()"); GFCommon::log_debug(print_r(compact("to", "subject", "message", "headers", "attachments", "abort_email"), true)); $is_success = wp_mail($to, $subject, $message, $headers, $attachments); GFCommon::log_debug("Result from wp_mail(): {$is_success}"); } do_action("gform_after_email", $is_success, $to, $subject, $message, $headers, $attachments, $message_format); }
public static function start_export($form) { $form_id = $form['id']; $fields = $_POST['export_field']; $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00'); $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59'); $search_criteria['status'] = 'active'; $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form); if (!empty($start_date)) { $search_criteria['start_date'] = $start_date; } if (!empty($end_date)) { $search_criteria['end_date'] = $end_date; } $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info'); GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}"); GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}"); $form = self::add_default_export_fields($form); $entry_count = GFAPI::count_entries($form_id, $search_criteria); $page_size = 100; $offset = 0; //Adding BOM marker for UTF-8 $lines = chr(239) . chr(187) . chr(191); // set the separater $separator = apply_filters('gform_export_separator_' . $form_id, apply_filters('gform_export_separator', ',', $form_id), $form_id); $field_rows = self::get_field_row_count($form, $fields, $entry_count); //writing header $headers = array(); foreach ($fields as $field_id) { $field = RGFormsModel::get_field($form, $field_id); $value = str_replace('"', '""', GFCommon::get_label($field, $field_id)); GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}"); $headers[$field_id] = $str = preg_replace('/[^a-z\\d ]/i', '', $value); $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0; if ($subrow_count == 0) { $lines .= '"' . $value . '"' . $separator; } else { for ($i = 1; $i <= $subrow_count; $i++) { $lines .= '"' . $value . ' ' . $i . '"' . $separator; } } GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}"); } $lines = substr($lines, 0, strlen($lines) - 1) . "\n"; //paging through results for memory issues while ($entry_count > 0) { $paging = array('offset' => $offset, 'page_size' => $page_size); $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging); $leads = apply_filters("gform_leads_before_export_{$form_id}", apply_filters('gform_leads_before_export', $leads, $form, $paging), $form, $paging); foreach ($leads as $lead) { foreach ($fields as $field_id) { switch ($field_id) { case 'date_created': $lead_gmt_time = mysql2date('G', $lead['date_created']); $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time); $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true); break; default: $long_text = ''; if (strlen(rgar($lead, $field_id)) >= GFORMS_MAX_FIELD_LENGTH - 10) { $long_text = RGFormsModel::get_field_value_long($lead, $field_id, $form); } $value = !empty($long_text) ? $long_text : rgar($lead, $field_id); $field = RGFormsModel::get_field($form, $field_id); $input_type = RGFormsModel::get_input_type($field); if ($input_type == 'checkbox') { //pass in label value that has not had quotes escaped so the is_checkbox_checked function compares the unchanged label value with the lead value $header_label_not_escaped = GFCommon::get_label($field, $field_id); $value = GFFormsModel::is_checkbox_checked($field_id, $header_label_not_escaped, $lead, $form); if ($value === false) { $value = ''; } } else { if ($input_type == 'fileupload' && $field->multipleFiles) { $value = !empty($value) ? implode(' , ', json_decode($value, true)) : ''; } } $value = preg_replace('/[^a-z\\d ]/i', '', $value); $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead); GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}"); break; } if (isset($field_rows[$field_id])) { $list = empty($value) ? array() : unserialize($value); foreach ($list as $row) { $row_values = array_values($row); $row_str = implode('|', $row_values); $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator; } //filling missing subrow columns (if any) $missing_count = intval($field_rows[$field_id]) - count($list); for ($i = 0; $i < $missing_count; $i++) { $lines .= '""' . $separator; } } else { $value = maybe_unserialize($value); if (is_array($value)) { $value = implode('|', $value); } $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator; } } $lines = substr($lines, 0, strlen($lines) - 1); GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}"); $lines .= "\n"; } $offset += $page_size; $entry_count -= $page_size; if (!seems_utf8($lines)) { $lines = utf8_encode($lines); } if (function_exists('mb_convert_encoding')) { // Convert the contents to UTF-16LE which has wider support than UTF-8. // This fixes an issue with special characters in Excel for Mac. $lines = mb_convert_encoding($lines, 'UTF-16LE', 'UTF-8'); } echo $lines; $lines = ''; } }
public static function upload() { GFCommon::log_debug('GFAsyncUpload::upload(): Starting.'); if ($_SERVER['REQUEST_METHOD'] != 'POST') { status_header(404); die; } header('Content-Type: text/html; charset=' . get_option('blog_charset')); send_nosniff_header(); nocache_headers(); status_header(200); // If the file is bigger than the server can accept then the form_id might not arrive. // This might happen if the file is bigger than the max post size ini setting. // Validation in the browser reduces the risk of this happening. if (!isset($_REQUEST['form_id'])) { GFCommon::log_debug('GFAsyncUpload::upload(): File upload aborted because the form_id was not found. The file may have been bigger than the max post size ini setting.'); self::die_error(500, __('Failed to upload file.', 'gravityforms')); } $form_id = absint($_REQUEST['form_id']); $form_unique_id = rgpost('gform_unique_id'); $form = GFAPI::get_form($form_id); if (empty($form) || !$form['is_active']) { die; } if (rgar($form, 'requireLogin')) { if (!is_user_logged_in()) { die; } check_admin_referer('gform_file_upload_' . $form_id, '_gform_file_upload_nonce_' . $form_id); } if (!ctype_alnum($form_unique_id)) { die; } $target_dir = GFFormsModel::get_upload_path($form_id) . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; if (!is_dir($target_dir)) { if (!wp_mkdir_p($target_dir)) { GFCommon::log_debug("GFAsyncUpload::upload(): Couldn't create the tmp folder: " . $target_dir); self::die_error(500, __('Failed to upload file.', 'gravityforms')); } } $time = current_time('mysql'); $y = substr($time, 0, 4); $m = substr($time, 5, 2); //adding index.html files to all subfolders if (!file_exists(GFFormsModel::get_upload_root() . '/index.html')) { GFForms::add_security_files(); } else { if (!file_exists(GFFormsModel::get_upload_path($form_id) . '/index.html')) { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id)); } else { if (!file_exists(GFFormsModel::get_upload_path($form_id) . "/{$y}/index.html")) { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id) . "/{$y}"); } else { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id) . "/{$y}/{$m}"); } } } if (!file_exists($target_dir . '/index.html')) { GFCommon::recursive_add_index_file($target_dir); } $uploaded_filename = $_FILES['file']['name']; $file_name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; $field_id = rgpost('field_id'); $field_id = absint($field_id); $field = GFFormsModel::get_field($form, $field_id); if (empty($field) || GFFormsModel::get_input_type($field) != 'fileupload') { die; } $file_name = sanitize_file_name($file_name); $uploaded_filename = sanitize_file_name($uploaded_filename); $allowed_extensions = !empty($field->allowedExtensions) ? GFCommon::clean_extensions(explode(',', strtolower($field->allowedExtensions))) : array(); $max_upload_size_in_bytes = $field->maxFileSize > 0 ? $field->maxFileSize * 1048576 : wp_max_upload_size(); $max_upload_size_in_mb = $max_upload_size_in_bytes / 1048576; if ($_FILES['file']['size'] > 0 && $_FILES['file']['size'] > $max_upload_size_in_bytes) { self::die_error(104, sprintf(__('File exceeds size limit. Maximum file size: %dMB', 'gravityforms'), $max_upload_size_in_mb)); } if (GFCommon::file_name_has_disallowed_extension($file_name) || GFCommon::file_name_has_disallowed_extension($uploaded_filename)) { GFCommon::log_debug("GFAsyncUpload::upload(): Illegal file extension: {$file_name}"); self::die_error(104, __('The uploaded file type is not allowed.', 'gravityforms')); } if (!empty($allowed_extensions)) { if (!GFCommon::match_file_extension($file_name, $allowed_extensions) || !GFCommon::match_file_extension($uploaded_filename, $allowed_extensions)) { GFCommon::log_debug("GFAsyncUpload::upload(): The uploaded file type is not allowed: {$file_name}"); self::die_error(104, sprintf(__('The uploaded file type is not allowed. Must be one of the following: %s', 'gravityforms'), strtolower($field['allowedExtensions']))); } } $whitelisting_disabled = apply_filters('gform_file_upload_whitelisting_disabled', false); if (empty($allowed_extensions) && !$whitelisting_disabled) { // Whitelist the file type $valid_uploaded_filename = GFCommon::check_type_and_ext($_FILES['file'], $uploaded_filename); if (is_wp_error($valid_uploaded_filename)) { self::die_error($valid_uploaded_filename->get_error_code(), $valid_uploaded_filename->get_error_message()); } $valid_file_name = GFCommon::check_type_and_ext($_FILES['file'], $file_name); if (is_wp_error($valid_uploaded_filename)) { self::die_error($valid_file_name->get_error_code(), $valid_file_name->get_error_message()); } } $tmp_file_name = $form_unique_id . '_input_' . $field_id . '_' . $file_name; $tmp_file_name = sanitize_file_name($tmp_file_name); $file_path = $target_dir . $tmp_file_name; $cleanup_target_dir = true; // Remove old files $max_file_age = 5 * 3600; // Temp file age in seconds // Remove old temp files if ($cleanup_target_dir) { if (is_dir($target_dir) && ($dir = opendir($target_dir))) { while (($file = readdir($dir)) !== false) { $tmp_file_path = $target_dir . $file; // Remove temp file if it is older than the max age and is not the current file if (preg_match('/\\.part$/', $file) && filemtime($tmp_file_path) < time() - $max_file_age && $tmp_file_path != "{$file_path}.part") { GFCommon::log_debug('GFAsyncUpload::upload(): Deleting file: ' . $tmp_file_path); @unlink($tmp_file_path); } } closedir($dir); } else { GFCommon::log_debug('GFAsyncUpload::upload(): Failed to open temp directory: ' . $target_dir); self::die_error(100, __('Failed to open temp directory.', 'gravityforms')); } } if (isset($_SERVER['HTTP_CONTENT_TYPE'])) { $contentType = $_SERVER['HTTP_CONTENT_TYPE']; } if (isset($_SERVER['CONTENT_TYPE'])) { $contentType = $_SERVER['CONTENT_TYPE']; } $chunk = isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0; $chunks = isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0; // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 if (strpos($contentType, 'multipart') !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { // Open temp file $out = @fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if ($out) { // Read binary input stream and append it to temp file $in = @fopen($_FILES['file']['tmp_name'], 'rb'); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { self::die_error(101, __('Failed to open input stream.', 'gravityforms')); } @fclose($in); @fclose($out); @unlink($_FILES['file']['tmp_name']); } else { self::die_error(102, __('Failed to open output stream.', 'gravityforms')); } } else { self::die_error(103, __('Failed to move uploaded file.', 'gravityforms')); } } else { // Open temp file $out = @fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if ($out) { // Read binary input stream and append it to temp file $in = @fopen('php://input', 'rb'); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { self::die_error(101, __('Failed to open input stream.', 'gravityforms')); } @fclose($in); @fclose($out); } else { self::die_error(102, __('Failed to open output stream.', 'gravityforms')); } } // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$file_path}.part", $file_path); } if (file_exists($file_path)) { GFFormsModel::set_permissions($file_path); } else { self::die_error(105, __('Upload unsuccessful', 'gravityforms') . ' ' . $uploaded_filename); } $output = array('status' => 'ok', 'data' => array('temp_filename' => $tmp_file_name, 'uploaded_filename' => str_replace("\\'", "'", urldecode($uploaded_filename)))); $output = json_encode($output); GFCommon::log_debug(sprintf('GFAsyncUpload::upload(): File upload complete. temp_filename: %s uploaded_filename: %s ', $tmp_file_name, $uploaded_filename)); gf_do_action('gform_post_multifile_upload', $form['id'], $form, $field, $uploaded_filename, $tmp_file_name, $file_path); die($output); }
public static function handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax) { $resume_email = isset($_POST['gform_resume_email']) ? $_POST['gform_resume_email'] : null; $confirmation_message = self::replace_save_variables($confirmation_message, $form, $resume_token, $resume_email); $confirmation_message = GFCommon::gform_do_shortcode($confirmation_message); $confirmation_message = "<div class='form_saved_message'><span>" . $confirmation_message . '</span></div>'; $form_id = absint($form['id']); $has_pages = self::has_pages($form); $default_anchor = $has_pages || $ajax ? true : false; $use_anchor = gf_apply_filters(array('gform_confirmation_anchor', $form_id), $default_anchor); if ($use_anchor !== false) { $confirmation_message = "<a id='gf_{$form_id}' class='gform_anchor' ></a>" . $confirmation_message; } $wrapper_css_class = GFCommon::get_browser_class() . ' gform_wrapper'; $confirmation_message = "<div class='{$wrapper_css_class}' id='gform_wrapper_{$form_id}'>" . $confirmation_message . '</div>'; if ($ajax) { $confirmation_message = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $confirmation_message . '</body></html>'; } GFCommon::log_debug('GFFormDisplay::handle_save_confirmation(): Confirmation => ' . print_r($confirmation_message, true)); return $confirmation_message; }
public function get_api_key($third_party_name) { $site_keys = $this->ensure_site_registered(); if (empty($site_keys)) { return false; } switch ($third_party_name) { case 'Dropbox': GFCommon::log_debug(__METHOD__ . '() - retrieving dropbox api key'); $auth = base64_encode($site_keys['site_key'] . ':' . $site_keys['site_secret']); $headers = array('Authorization' => 'GravityAPI ' . $auth); $response = $this->request('credentials/dropbox', array(), 'GET', array('headers' => $headers)); return $this->prepare_response_body($response); default: return new WP_Error('unsupported_service_name', 'The provided third party service name: ' . $third_party_name . ' is not supported. '); } }
/** * Saves form meta. Note the special requirements for the meta string. * * @param $id * @param string $form_json A valid JSON string. The JSON is manipulated before decoding and is designed to work together with jQuery.toJSON() rather than json_encode. Avoid using json_encode as it will convert unicode characters into their respective entities with slashes. These slashes get stripped so unicode characters won't survive intact. * * @return array */ public static function save_form_info($id, $form_json) { global $wpdb; $form_json = stripslashes($form_json); $form_json = nl2br($form_json); GFCommon::log_debug('GFFormDetail::save_form_info(): Form meta json: ' . $form_json); $form_meta = json_decode($form_json, true); $form_meta = GFFormsModel::convert_field_objects($form_meta); GFCommon::log_debug('GFFormDetail::save_form_info(): Form meta => ' . print_r($form_meta, true)); if (!$form_meta) { return array('status' => 'invalid_json', 'meta' => null); } $form_table_name = $wpdb->prefix . 'rg_form'; //Making sure title is not duplicate $forms = RGFormsModel::get_forms(); foreach ($forms as $form) { if (strtolower($form->title) == strtolower($form_meta['title']) && rgar($form_meta, 'id') != $form->id) { return array('status' => 'duplicate_title', 'meta' => $form_meta); } } if ($id > 0) { $form_meta = GFFormsModel::trim_form_meta_values($form_meta); RGFormsModel::update_form_meta($id, $form_meta); //updating form title $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta['title'], $form_meta['id'])); $form_meta = RGFormsModel::get_form_meta($id); do_action('gform_after_save_form', $form_meta, false); return array('status' => $id, 'meta' => $form_meta); } else { //inserting form $id = RGFormsModel::insert_form($form_meta['title']); //updating object's id property $form_meta['id'] = $id; //creating default notification if (apply_filters('gform_default_notification', true)) { $default_notification = array('id' => uniqid(), 'to' => '{admin_email}', 'name' => __('Admin Notification', 'gravityforms'), 'event' => 'form_submission', 'toType' => 'email', 'subject' => __('New submission from', 'gravityforms') . ' {form_title}', 'message' => '{all_fields}'); $notifications = array($default_notification['id'] => $default_notification); //updating notifications form meta RGFormsModel::save_form_notifications($id, $notifications); } // add default confirmation when saving a new form $confirmation_id = uniqid(); $confirmations = array(); $confirmations[$confirmation_id] = array('id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', 'message' => __('Thanks for contacting us! We will get in touch with you shortly.', 'gravityforms'), 'url' => '', 'pageId' => '', 'queryString' => ''); GFFormsModel::save_form_confirmations($id, $confirmations); //updating form meta RGFormsModel::update_form_meta($id, $form_meta); $form_meta = RGFormsModel::get_form_meta($id); do_action('gform_after_save_form', $form_meta, true); return array('status' => $id * -1, 'meta' => $form_meta); } }
/** * Sends all active notifications for a form given an entry object and an event. * * @param $form * @param $entry * @param string $event Default = 'form_submission' * @param array $data Optional. Array of data which can be used in the notifications via the generic {object:property} merge tag. * * @return array */ public static function send_notifications($form, $entry, $event = 'form_submission', $data = array()) { if (rgempty('notifications', $form) || !is_array($form['notifications'])) { return array(); } $entry_id = rgar($entry, 'id'); GFCommon::log_debug("GFAPI::send_notifications(): Gathering notifications for {$event} event for entry #{$entry_id}."); $notifications_to_send = array(); //running through filters that disable form submission notifications foreach ($form['notifications'] as $notification) { if (rgar($notification, 'event') != $event) { continue; } if ($event == 'form_submission') { if (rgar($notification, 'type') == 'user' && gf_apply_filters(array('gform_disable_user_notification', $form['id']), false, $form, $entry)) { GFCommon::log_debug("GFAPI::send_notifications(): Notification is disabled by gform_disable_user_notification hook, not including notification (#{$notification['id']} - {$notification['name']})."); //skip user notification if it has been disabled by a hook continue; } elseif (rgar($notification, 'type') == 'admin' && gf_apply_filters(array('gform_disable_admin_notification', $form['id']), false, $form, $entry)) { GFCommon::log_debug("GFAPI::send_notifications(): Notification is disabled by gform_disable_admin_notification hook, not including notification (#{$notification['id']} - {$notification['name']})."); //skip admin notification if it has been disabled by a hook continue; } } if (gf_apply_filters(array('gform_disable_notification', $form['id']), false, $notification, $form, $entry)) { GFCommon::log_debug("GFAPI::send_notifications(): Notification is disabled by gform_disable_notification hook, not including notification (#{$notification['id']} - {$notification['name']})."); //skip notifications if it has been disabled by a hook continue; } $notifications_to_send[] = $notification['id']; } GFCommon::send_notifications($notifications_to_send, $form, $entry, true, $event, $data); }
public static function lead_detail_page() { global $current_user; if (!GFCommon::ensure_wp_version()) { return; } echo GFCommon::get_remote_message(); $form = RGFormsModel::get_form_meta(absint($_GET['id'])); $form_id = absint($form['id']); $form = apply_filters('gform_admin_pre_render_' . $form_id, apply_filters('gform_admin_pre_render', $form)); $lead_id = absint(rgget('lid')); $filter = rgget('filter'); $status = in_array($filter, array('trash', 'spam')) ? $filter : 'active'; $position = rgget('pos') ? rgget('pos') : 0; $sort_direction = rgget('dir') ? rgget('dir') : 'DESC'; $sort_field = empty($_GET['sort']) ? 0 : $_GET['sort']; $sort_field_meta = RGFormsModel::get_field($form, $sort_field); $is_numeric = $sort_field_meta['type'] == 'number'; $star = $filter == 'star' ? 1 : null; $read = $filter == 'unread' ? 0 : null; $search_criteria['status'] = $status; if ($star) { $search_criteria['field_filters'][] = array('key' => 'is_starred', 'value' => (bool) $star); } if (!is_null($read)) { $search_criteria['field_filters'][] = array('key' => 'is_read', 'value' => (bool) $read); } $search_field_id = rgget('field_id'); if (isset($_GET['field_id']) && $_GET['field_id'] !== '') { $key = $search_field_id; $val = rgget('s'); $strpos_row_key = strpos($search_field_id, '|'); if ($strpos_row_key !== false) { //multi-row likert $key_array = explode('|', $search_field_id); $key = $key_array[0]; $val = $key_array[1] . ':' . $val; } $search_criteria['field_filters'][] = array('key' => $key, 'operator' => rgempty('operator', $_GET) ? 'is' : rgget('operator'), 'value' => $val); $type = rgget('type'); if (empty($type)) { if (rgget('field_id') == '0') { $search_criteria['type'] = 'global'; } } } $paging = array('offset' => $position, 'page_size' => 1); if (!empty($sort_field)) { $sorting = array('key' => $_GET['sort'], 'direction' => $sort_direction, 'is_numeric' => $is_numeric); } else { $sorting = array(); } $total_count = 0; $leads = GFAPI::get_entries($form['id'], $search_criteria, $sorting, $paging, $total_count); $prev_pos = !rgblank($position) && $position > 0 ? $position - 1 : false; $next_pos = !rgblank($position) && $position < $total_count - 1 ? $position + 1 : false; // unread filter requires special handling for pagination since entries are filter out of the query as they are read if ($filter == 'unread') { $next_pos = $position; if ($next_pos + 1 == $total_count) { $next_pos = false; } } if (!$lead_id) { $lead = !empty($leads) ? $leads[0] : false; } else { $lead = GFAPI::get_entry($lead_id); } if (!$lead) { esc_html_e("Oops! We couldn't find your entry. Please try again", 'gravityforms'); return; } RGFormsModel::update_lead_property($lead['id'], 'is_read', 1); switch (RGForms::post('action')) { case 'update': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); //Loading files that have been uploaded to temp folder $files = GFCommon::json_decode(stripslashes(RGForms::post('gform_uploaded_files'))); if (!is_array($files)) { $files = array(); } GFFormsModel::$uploaded_files[$form_id] = $files; GFFormsModel::save_lead($form, $lead); do_action('gform_after_update_entry', $form, $lead['id']); do_action("gform_after_update_entry_{$form['id']}", $form, $lead['id']); $lead = RGFormsModel::get_lead($lead['id']); $lead = GFFormsModel::set_entry_meta($lead, $form); break; case 'add_note': check_admin_referer('gforms_update_note', 'gforms_update_note'); $user_data = get_userdata($current_user->ID); RGFormsModel::add_note($lead['id'], $current_user->ID, $user_data->display_name, stripslashes($_POST['new_note'])); //emailing notes if configured if (rgpost('gentry_email_notes_to')) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Preparing to email entry notes.'); $email_to = $_POST['gentry_email_notes_to']; $email_from = $current_user->user_email; $email_subject = stripslashes($_POST['gentry_email_subject']); $body = stripslashes($_POST['new_note']); $headers = "From: \"{$email_from}\" <{$email_from}> \r\n"; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Emailing notes - TO: {$email_to} SUBJECT: {$email_subject} BODY: {$body} HEADERS: {$headers}"); $is_success = wp_mail($email_to, $email_subject, $body, $headers); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFEntryDetail::lead_detail_page(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } do_action('gform_post_send_entry_note', $result, $email_to, $email_from, $email_subject, $body, $form, $lead); } break; case 'add_quick_note': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); $user_data = get_userdata($current_user->ID); RGFormsModel::add_note($lead['id'], $current_user->ID, $user_data->display_name, stripslashes($_POST['quick_note'])); break; case 'bulk': check_admin_referer('gforms_update_note', 'gforms_update_note'); if ($_POST['bulk_action'] == 'delete') { if (!GFCommon::current_user_can_any('gravityforms_edit_entry_notes')) { die(esc_html__("You don't have adequate permission to delete notes.", 'gravityforms')); } RGFormsModel::delete_notes($_POST['note']); } break; case 'trash': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); RGFormsModel::update_lead_property($lead['id'], 'status', 'trash'); $lead = RGFormsModel::get_lead($lead['id']); break; case 'restore': case 'unspam': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); RGFormsModel::update_lead_property($lead['id'], 'status', 'active'); $lead = RGFormsModel::get_lead($lead['id']); break; case 'spam': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); RGFormsModel::update_lead_property($lead['id'], 'status', 'spam'); $lead = RGFormsModel::get_lead($lead['id']); break; case 'delete': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); if (!GFCommon::current_user_can_any('gravityforms_delete_entries')) { die(esc_html__("You don't have adequate permission to delete entries.", 'gravityforms')); } RGFormsModel::delete_lead($lead['id']); ?> <script type="text/javascript"> document.location.href = '<?php echo 'admin.php?page=gf_entries&view=entries&id=' . absint($form['id']); ?> '; </script> <?php break; } $mode = empty($_POST['screen_mode']) ? 'view' : $_POST['screen_mode']; $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min'; ?> <link rel="stylesheet" href="<?php echo GFCommon::get_base_url(); ?> /css/admin<?php echo $min; ?> .css" /> <script type="text/javascript"> jQuery(document).ready(function () { toggleNotificationOverride(true); jQuery('#gform_update_button').prop('disabled', false); }); function DeleteFile(leadId, fieldId, deleteButton) { if (confirm(<?php echo json_encode(__("Would you like to delete this file? 'Cancel' to stop. 'OK' to delete", 'gravityforms')); ?> )) { var fileIndex = jQuery(deleteButton).parent().index(); var mysack = new sack("<?php echo admin_url('admin-ajax.php'); ?> "); mysack.execute = 1; mysack.method = 'POST'; mysack.setVar("action", "rg_delete_file"); mysack.setVar("rg_delete_file", "<?php echo wp_create_nonce('rg_delete_file'); ?> "); mysack.setVar("lead_id", leadId); mysack.setVar("field_id", fieldId); mysack.setVar("file_index", fileIndex); mysack.onError = function () { alert(<?php echo json_encode(__('Ajax error while deleting field.', 'gravityforms')); ?> ) }; mysack.runAJAX(); return true; } } function EndDeleteFile(fieldId, fileIndex) { var previewFileSelector = "#preview_existing_files_" + fieldId + " .ginput_preview"; var $previewFiles = jQuery(previewFileSelector); var rr = $previewFiles.eq(fileIndex); $previewFiles.eq(fileIndex).remove(); var $visiblePreviewFields = jQuery(previewFileSelector); if ($visiblePreviewFields.length == 0) { jQuery('#preview_' + fieldId).hide(); jQuery('#upload_' + fieldId).show('slow'); } } function ToggleShowEmptyFields() { if (jQuery("#gentry_display_empty_fields").is(":checked")) { createCookie("gf_display_empty_fields", true, 10000); document.location = document.location.href; } else { eraseCookie("gf_display_empty_fields"); document.location = document.location.href; } } function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function eraseCookie(name) { createCookie(name, "", -1); } function ResendNotifications() { var selectedNotifications = new Array(); jQuery(".gform_notifications:checked").each(function () { selectedNotifications.push(jQuery(this).val()); }); var sendTo = jQuery('#notification_override_email').val(); if (selectedNotifications.length <= 0) { displayMessage(<?php echo json_encode(__('You must select at least one type of notification to resend.', 'gravityforms')); ?> , 'error', '#notifications_container'); return; } jQuery('#please_wait_container').fadeIn(); jQuery.post(ajaxurl, { action : "gf_resend_notifications", gf_resend_notifications: '<?php echo wp_create_nonce('gf_resend_notifications'); ?> ', notifications : jQuery.toJSON(selectedNotifications), sendTo : sendTo, leadIds : '<?php echo absint($lead['id']); ?> ', formId : '<?php echo absint($form['id']); ?> ' }, function (response) { if (response) { displayMessage(response, "error", "#notifications_container"); } else { displayMessage(<?php echo json_encode(esc_html__('Notifications were resent successfully.', 'gravityforms')); ?> , "updated", "#notifications_container" ); // reset UI jQuery(".gform_notifications").attr( 'checked', false ); jQuery('#notification_override_email').val(''); toggleNotificationOverride(); } jQuery('#please_wait_container').hide(); setTimeout(function () { jQuery('#notifications_container').find('.message').slideUp(); }, 5000); } ); } function displayMessage( message, messageClass, container ) { jQuery( container ).find( '.message' ).hide().html( message ).attr( 'class', 'message ' + messageClass ).slideDown(); } function toggleNotificationOverride(isInit) { if (isInit) jQuery('#notification_override_email').val(''); if (jQuery(".gform_notifications:checked").length > 0) { jQuery('#notifications_override_settings').slideDown(); } else { jQuery('#notifications_override_settings').slideUp(function () { jQuery('#notification_override_email').val(''); }); } } </script> <form method="post" id="entry_form" enctype='multipart/form-data'> <?php wp_nonce_field('gforms_save_entry', 'gforms_save_entry'); ?> <input type="hidden" name="action" id="action" value="" /> <input type="hidden" name="screen_mode" id="screen_mode" value="<?php echo esc_attr(rgpost('screen_mode')); ?> " /> <div class="wrap gf_entry_wrap"> <h2 class="gf_admin_page_title"> <span><?php echo esc_html__('Entry #', 'gravityforms') . absint($lead['id']); ?> </span><span class="gf_admin_page_subtitle"><span class="gf_admin_page_formid">ID: <?php echo absint($form['id']); ?> </span><span class='gf_admin_page_formname'><?php esc_html_e('Form Name', 'gravityforms'); ?> : <?php echo esc_html($form['title']); $gf_entry_locking = new GFEntryLocking(); $gf_entry_locking->lock_info($lead_id); ?> </span></span></h2> <?php if (isset($_GET['pos'])) { ?> <div class="gf_entry_detail_pagination"> <ul> <li class="gf_entry_count"> <span>entry <strong><?php echo $position + 1; ?> </strong> of <strong><?php echo $total_count; ?> </strong></span> </li> <li class="gf_entry_prev gf_entry_pagination"><?php echo GFEntryDetail::entry_detail_pagination_link($prev_pos, 'Previous Entry', 'gf_entry_prev_link', 'fa fa-arrow-circle-o-left'); ?> </li> <li class="gf_entry_next gf_entry_pagination"><?php echo GFEntryDetail::entry_detail_pagination_link($next_pos, 'Next Entry', 'gf_entry_next_link', 'fa fa-arrow-circle-o-right'); ?> </li> </ul> </div> <?php } ?> <?php RGForms::top_toolbar(); ?> <div id="poststuff" class="metabox-holder has-right-sidebar"> <div id="side-info-column" class="inner-sidebar"> <?php do_action('gform_entry_detail_sidebar_before', $form, $lead); ?> <!-- INFO BOX --> <div id="submitdiv" class="stuffbox"> <h3 class="hndle" style="cursor:default;"> <span><?php esc_html_e('Entry', 'gravityforms'); ?> </span> </h3> <div class="inside"> <div id="submitcomment" class="submitbox"> <div id="minor-publishing" style="padding:10px;"> <?php esc_html_e('Entry Id', 'gravityforms'); ?> : <?php echo absint($lead['id']); ?> <br /><br /> <?php esc_html_e('Submitted on', 'gravityforms'); ?> : <?php echo esc_html(GFCommon::format_date($lead['date_created'], false, 'Y/m/d')); ?> <br /><br /> <?php esc_html_e('User IP', 'gravityforms'); ?> : <?php echo esc_html($lead['ip']); ?> <br /><br /> <?php if (!empty($lead['created_by']) && ($usermeta = get_userdata($lead['created_by']))) { ?> <?php esc_html_e('User', 'gravityforms'); ?> : <a href="user-edit.php?user_id=<?php echo absint($lead['created_by']); ?> " alt="<?php esc_attr_e('View user profile', 'gravityforms'); ?> " title="<?php esc_attr_e('View user profile', 'gravityforms'); ?> "><?php echo esc_html($usermeta->user_login); ?> </a> <br /><br /> <?php } ?> <?php esc_html_e('Embed Url', 'gravityforms'); ?> : <a href="<?php echo esc_url($lead['source_url']); ?> " target="_blank" alt="<?php echo esc_attr($lead['source_url']); ?> " title="<?php echo esc_attr($lead['source_url']); ?> ">.../<?php echo esc_html(GFCommon::truncate_url($lead['source_url'])); ?> </a> <br /><br /> <?php if (!empty($lead['post_id'])) { $post = get_post($lead['post_id']); ?> <?php esc_html_e('Edit Post', 'gravityforms'); ?> : <a href="post.php?action=edit&post=<?php echo absint($post->ID); ?> " alt="<?php esc_attr_e('Click to edit post', 'gravityforms'); ?> " title="<?php esc_attr_e('Click to edit post', 'gravityforms'); ?> "><?php echo esc_html($post->post_title); ?> </a> <br /><br /> <?php } if (do_action('gform_enable_entry_info_payment_details', true, $lead)) { if (!empty($lead['payment_status'])) { echo $lead['transaction_type'] != 2 ? esc_html__('Payment Status', 'gravityforms') : esc_html__('Subscription Status', 'gravityforms'); ?> : <span id="gform_payment_status"><?php echo apply_filters('gform_payment_status', $lead['payment_status'], $form, $lead); ?> </span> <br /><br /> <?php if (!empty($lead['payment_date'])) { echo $lead['transaction_type'] != 2 ? esc_html__('Payment Date', 'gravityforms') : esc_html__('Start Date', 'gravityforms'); ?> : <?php echo GFCommon::format_date($lead['payment_date'], false, 'Y/m/d', $lead['transaction_type'] != 2); ?> <br /><br /> <?php } if (!empty($lead['transaction_id'])) { echo $lead['transaction_type'] != 2 ? esc_html__('Transaction Id', 'gravityforms') : esc_html__('Subscriber Id', 'gravityforms'); ?> : <?php echo esc_html($lead['transaction_id']); ?> <br /><br /> <?php } if (!rgblank($lead['payment_amount'])) { echo $lead['transaction_type'] != 2 ? esc_html__('Payment Amount', 'gravityforms') : esc_html__('Subscription Amount', 'gravityforms'); ?> : <?php echo GFCommon::to_money($lead['payment_amount'], $lead['currency']); ?> <br /><br /> <?php } } } do_action('gform_entry_info', $form['id'], $lead); ?> </div> <div id="major-publishing-actions"> <div id="delete-action"> <?php switch ($lead['status']) { case 'spam': if (GFCommon::spam_enabled($form['id'])) { ?> <a onclick="jQuery('#action').val('unspam'); jQuery('#entry_form').submit()" href="#"><?php esc_html_e('Not Spam', 'gravityforms'); ?> </a> <?php echo GFCommon::current_user_can_any('gravityforms_delete_entries') ? '|' : ''; } if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> <a class="submitdelete deletion" onclick="if ( confirm('<?php echo esc_js(__("You are about to delete this entry. 'Cancel' to stop, 'OK' to delete.", 'gravityforms')); ?> ') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php esc_html_e('Delete Permanently', 'gravityforms'); ?> </a> <?php } break; case 'trash': ?> <a onclick="jQuery('#action').val('restore'); jQuery('#entry_form').submit()" href="#"><?php esc_html_e('Restore', 'gravityforms'); ?> </a> <?php if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> | <a class="submitdelete deletion" onclick="if ( confirm('<?php echo esc_js(__("You are about to delete this entry. 'Cancel' to stop, 'OK' to delete.", 'gravityforms')); ?> ') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php esc_html_e('Delete Permanently', 'gravityforms'); ?> </a> <?php } break; default: if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> <a class="submitdelete deletion" onclick="jQuery('#action').val('trash'); jQuery('#entry_form').submit()" href="#"><?php esc_html_e('Move to Trash', 'gravityforms'); ?> </a> <?php echo GFCommon::spam_enabled($form['id']) ? '|' : ''; } if (GFCommon::spam_enabled($form['id'])) { ?> <a class="submitdelete deletion" onclick="jQuery('#action').val('spam'); jQuery('#entry_form').submit()" href="#"><?php esc_html_e('Mark as Spam', 'gravityforms'); ?> </a> <?php } } ?> </div> <div id="publishing-action"> <?php if (GFCommon::current_user_can_any('gravityforms_edit_entries') && $lead['status'] != 'trash') { $button_text = $mode == 'view' ? __('Edit', 'gravityforms') : __('Update', 'gravityforms'); $disabled = $mode == 'view' ? '' : ' disabled="disabled" '; $update_button_id = $mode == 'view' ? 'gform_edit_button' : 'gform_update_button'; $button_click = $mode == 'view' ? "jQuery('#screen_mode').val('edit');" : "jQuery('#action').val('update'); jQuery('#screen_mode').val('view');"; $update_button = '<input id="' . $update_button_id . '" ' . $disabled . ' class="button button-large button-primary" type="submit" tabindex="4" value="' . esc_attr($button_text) . '" name="save" onclick="' . $button_click . '"/>'; echo apply_filters('gform_entrydetail_update_button', $update_button); if ($mode == 'edit') { echo ' <input class="button button-large" type="submit" tabindex="5" value="' . esc_attr__('Cancel', 'gravityforms') . '" name="cancel" onclick="jQuery(\'#screen_mode\').val(\'view\');"/>'; } } ?> </div> <div class="clear"></div> </div> </div> </div> </div> <?php if (!empty($lead['payment_status']) && !apply_filters('gform_enable_entry_info_payment_details', true, $lead)) { self::payment_details_box($lead, $form); } ?> <?php do_action('gform_entry_detail_sidebar_middle', $form, $lead); ?> <?php if (GFCommon::current_user_can_any('gravityforms_edit_entry_notes')) { ?> <!-- start notifications --> <div class="postbox" id="notifications_container"> <h3 class="hndle" style="cursor:default;"> <span><?php esc_html_e('Notifications', 'gravityforms'); ?> </span> </h3> <div class="inside"> <div class="message" style="display:none;padding:10px;"></div> <div> <?php $notifications = GFCommon::get_notifications('resend_notifications', $form); if (!is_array($notifications) || count($form['notifications']) <= 0) { ?> <p class="description"><?php esc_html_e('You cannot resend notifications for this entry because this form does not currently have any notifications configured.', 'gravityforms'); ?> </p> <a href="<?php echo admin_url("admin.php?page=gf_edit_forms&view=settings&subview=notification&id={$form_id}"); ?> " class="button"><?php esc_html_e('Configure Notifications', 'gravityforms'); ?> </a> <?php } else { foreach ($notifications as $notification) { ?> <input type="checkbox" class="gform_notifications" value="<?php echo esc_attr($notification['id']); ?> " id="notification_<?php echo esc_attr($notification['id']); ?> " onclick="toggleNotificationOverride();" /> <label for="notification_<?php echo esc_attr($notification['id']); ?> "><?php echo esc_html($notification['name']); ?> </label> <br /><br /> <?php } ?> <div id="notifications_override_settings" style="display:none;"> <p class="description" style="padding-top:0; margin-top:0; width:99%;">You may override the default notification settings by entering a comma delimited list of emails to which the selected notifications should be sent.</p> <label for="notification_override_email"><?php esc_html_e('Send To', 'gravityforms'); ?> <?php gform_tooltip('notification_override_email'); ?> </label><br /> <input type="text" name="notification_override_email" id="notification_override_email" style="width:99%;" /> <br /><br /> </div> <input type="button" name="notification_resend" value="<?php esc_attr_e('Resend Notifications', 'gravityforms'); ?> " class="button" style="" onclick="ResendNotifications();" /> <span id="please_wait_container" style="display:none; margin-left: 5px;"> <i class='gficon-gravityforms-spinner-icon gficon-spin'></i> <?php esc_html_e('Resending...', 'gravityforms'); ?> </span> <?php } ?> </div> </div> </div> <!-- / end notifications --> <?php } ?> <!-- begin print button --> <div class="detail-view-print"> <a href="javascript:;" onclick="var notes_qs = jQuery('#gform_print_notes').is(':checked') ? '¬es=1' : ''; var url='<?php echo trailingslashit(site_url()); ?> ?gf_page=print-entry&fid=<?php echo absint($form['id']); ?> &lid=<?php echo absint($lead['id']); ?> ' + notes_qs; window.open (url,'printwindow');" class="button"><?php esc_html_e('Print', 'gravityforms'); ?> </a> <?php if (GFCommon::current_user_can_any('gravityforms_view_entry_notes')) { ?> <input type="checkbox" name="print_notes" value="print_notes" checked="checked" id="gform_print_notes" /> <label for="print_notes"><?php esc_html_e('include notes', 'gravityforms'); ?> </label> <?php } ?> </div> <!-- end print button --> <?php do_action('gform_entry_detail_sidebar_after', $form, $lead); ?> </div> <div id="post-body" class="has-sidebar"> <div id="post-body-content" class="has-sidebar-content"> <?php do_action('gform_entry_detail_content_before', $form, $lead); if ($mode == 'view') { self::lead_detail_grid($form, $lead, true); } else { self::lead_detail_edit($form, $lead); } do_action('gform_entry_detail', $form, $lead); if (GFCommon::current_user_can_any('gravityforms_view_entry_notes')) { ?> <div class="postbox"> <h3> <label for="name"><?php esc_html_e('Notes', 'gravityforms'); ?> </label> </h3> <form method="post"> <?php wp_nonce_field('gforms_update_note', 'gforms_update_note'); ?> <div class="inside"> <?php $notes = RGFormsModel::get_lead_notes($lead['id']); //getting email values $email_fields = GFCommon::get_email_fields($form); $emails = array(); foreach ($email_fields as $email_field) { if (!empty($lead[$email_field->id])) { $emails[] = $lead[$email_field->id]; } } //displaying notes grid $subject = ''; self::notes_grid($notes, true, $emails, $subject); ?> </div> </form> </div> <?php } do_action('gform_entry_detail_content_after', $form, $lead); ?> </div> </div> </div> </div> </form> <?php if (rgpost('action') == 'update') { ?> <div class="updated fade" style="padding:6px;"> <?php esc_html_e('Entry Updated.', 'gravityforms'); ?> </div> <?php } }
public static function setup($force_setup = false) { global $wpdb; $has_version_changed = get_option("rg_form_version") != GFCommon::$version; if ($has_version_changed) { //Making sure version has really changed. Gets around aggressive caching issue on some sites that cause setup to run multiple times. $has_version_changed = self::get_wp_option("rg_form_version") != GFCommon::$version; } if ($has_version_changed || $force_setup) { $blog_id = get_current_blog_id(); GFCommon::log_debug("Blog {$blog_id} - Beginning of setup. From version " . get_option("rg_form_version") . " to version " . GFCommon::$version); //setting up database structure self::setup_database(); //auto-setting and auto-validating license key based on value configured via the GF_LICENSE_KEY constant or the gf_license_key variable //auto-populating reCAPTCHA keys base on constant self::maybe_populate_keys(); //Auto-importing forms based on GF_IMPORT_FILE AND GF_THEME_IMPORT_FILE self::maybe_import_forms(); //The format the version info changed to JSON. Make sure the old format is not cached. if (version_compare(get_option("rg_form_version"), "1.8.0.3", "<")) { delete_transient("gform_update_info"); } update_option("rg_form_version", GFCommon::$version); GFCommon::log_debug("Blog {$blog_id} - End of setup."); } }
function set_permissions($path) { GFCommon::log_debug(__METHOD__ . '(): Setting permissions on: ' . $path); GFFormsModel::set_permissions($path); }
public static function handle_confirmation($form, $lead, $ajax=false){ GFCommon::log_debug("Sending confirmation"); //run the function to populate the legacy confirmation format to be safe $form = self::update_confirmation($form, $lead); if($form["confirmation"]["type"] == "message"){ $default_anchor = self::has_pages($form) ? 1 : 0; $anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)) ? "<a id='gf_{$form["id"]}' name='gf_{$form["id"]}' class='gform_anchor' ></a>" : ""; $nl2br = rgar($form["confirmation"],"disableAutoformat") ? false : true; $cssClass = rgar($form, "cssClass"); $confirmation = empty($form["confirmation"]["message"]) ? "{$anchor} " : "{$anchor}<div id='gform_confirmation_wrapper_{$form["id"]}' class='gform_confirmation_wrapper {$cssClass}'><div id='gform_confirmation_message_{$form["id"]}' class='gform_confirmation_message_{$form["id"]} gform_confirmation_message'>" . GFCommon::replace_variables($form["confirmation"]["message"], $form, $lead, false, true, $nl2br) . "</div></div>"; } else{ if(!empty($form["confirmation"]["pageId"])){ $url = get_permalink($form["confirmation"]["pageId"]); $dynamic_query = GFCommon::replace_variables(trim($form["confirmation"]["queryString"]), $form, $lead, true); if(!empty($dynamic_query)) $url .= "?" . $dynamic_query; } else{ $url = GFCommon::replace_variables(trim($form["confirmation"]["url"]), $form, $lead, false, true); $url_info = parse_url($url); $query_string = rgar($url_info, "query"); $dynamic_query = GFCommon::replace_variables(trim($form["confirmation"]["queryString"]), $form, $lead, true); $query_string .= rgempty("query", $url_info) || empty($dynamic_query) ? $dynamic_query : "&" . $dynamic_query; if(!empty($url_info["fragment"])) $query_string .= "#" . rgar($url_info,"fragment"); $url = $url_info["scheme"] . "://" . rgar($url_info,"host"); if(!empty($url_info["port"])) $url .= ":" . rgar($url_info,"port"); $url .= rgar($url_info,"path"); if(!empty($query_string)){ $url .= "?{$query_string}"; } } if(headers_sent() || $ajax){ //Perform client side redirect for AJAX forms, of if headers have already been sent $confirmation = self::get_js_redirect_confirmation($url, $ajax); } else{ $confirmation = array("redirect" => $url); } } $confirmation = apply_filters("gform_confirmation_{$form["id"]}", apply_filters("gform_confirmation", $confirmation, $form, $lead, $ajax), $form, $lead, $ajax); if(!is_array($confirmation)){ $confirmation = GFCommon::gform_do_shortcode($confirmation); //enabling shortcodes } else if(headers_sent() || $ajax){ //Perform client side redirect for AJAX forms, of if headers have already been sent $confirmation = self::get_js_redirect_confirmation($confirmation["redirect"], $ajax); //redirecting via client side } GFCommon::log_debug("Confirmation: " . print_r($confirmation, true)); return $confirmation; }