private static function _delete_entry($entry_id, $form)
 {
     if (!$form) {
         return;
     }
     $form->options = maybe_unserialize($form->options);
     if (isset($form->options['no_save']) && $form->options['no_save']) {
         FrmEntry::destroy($entry_id);
     }
 }
示例#2
0
 /**
  * Delete entries from repeating sections and transfer first row to parent entries
  */
 private static function move_entries_to_parent_form($args)
 {
     global $wpdb;
     // get the ids of the entries saved in child fields
     $items = FrmDb::get_results($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items i ON i.id=m.item_id', array('field_id' => $args['children']), 'item_id,parent_item_id', array('order_by' => 'i.created_at ASC'));
     $updated_ids = array();
     foreach ($items as $item) {
         $child_id = $item->item_id;
         $parent_id = $item->parent_item_id;
         if (!in_array($parent_id, $updated_ids)) {
             // Change the item_id in frm_item_metas to match the parent item ID
             $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_item_metas SET item_id = %d WHERE item_id = %d', $parent_id, $child_id));
             $updated_ids[] = $parent_id;
         }
         // Delete the child entry
         FrmEntry::destroy($child_id);
     }
     // delete all the metas for the repeat section
     $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $args['field_id']));
     // Delete the child form
     FrmForm::destroy($args['form_id']);
 }
示例#3
0
 /**
  * @return int|boolean
  */
 public static function destroy($id)
 {
     global $wpdb;
     $form = self::getOne($id);
     if (!$form) {
         return false;
     }
     // Disconnect the entries from this form
     $entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('form_id' => $id));
     foreach ($entries as $entry_id) {
         FrmEntry::destroy($entry_id);
         unset($entry_id);
     }
     // Disconnect the fields from this form
     $wpdb->query($wpdb->prepare('DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id));
     $query_results = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
     if ($query_results) {
         // Delete all form actions linked to this form
         $action_control = FrmFormActionsController::get_form_actions('email');
         $action_control->destroy($id, 'all');
         // Clear form caching
         self::clear_form_cache();
         do_action('frm_destroy_form', $id);
         do_action('frm_destroy_form_' . $id);
     }
     return $query_results;
 }
 public static function maybe_delete_entry($entry)
 {
     FrmEntry::maybe_get_entry($entry);
     if (!$entry || !FrmProEntriesHelper::user_can_delete($entry)) {
         $message = __('There was an error deleting that entry', 'formidable');
         return $message;
     }
     $result = FrmEntry::destroy($entry->id);
     return $result;
 }
示例#5
0
 public static function destroy_post($entry_id, $entry = false)
 {
     global $wpdb;
     if ($entry) {
         $post_id = $entry->post_id;
     } else {
         $post_id = FrmDb::get_var($wpdb->prefix . 'frm_items', array('id' => $entry_id), 'post_id');
     }
     // delete child entries
     $child_entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('parent_item_id' => $entry_id));
     foreach ($child_entries as $child_entry) {
         FrmEntry::destroy($child_entry);
     }
     // Remove hook to make things consistent
     // Due to a WP bug, this hook won't be used for parent entry when there are child entries
     remove_action('frm_before_destroy_entry', 'FrmProFormActionsController::trigger_delete_actions', 20, 2);
     // Trigger delete actions for parent entry
     FrmProFormActionsController::trigger_delete_actions($entry_id, $entry);
     if ($post_id) {
         wp_delete_post($post_id);
     }
 }
示例#6
0
 public static function save_sub_entries($values, $action = 'create')
 {
     $form_id = isset($values['form_id']) ? (int) $values['form_id'] : 0;
     if (!$form_id || !isset($values['item_meta'])) {
         return $values;
     }
     $form_fields = FrmProFormsHelper::has_field('form', $form_id, false);
     $section_fields = FrmProFormsHelper::has_field('divider', $form_id, false);
     if (!$form_fields && !$section_fields) {
         // only continue if there could be sub entries
         return $values;
     }
     $form_fields = array_merge($section_fields, $form_fields);
     $new_values = $values;
     unset($new_values['item_meta']);
     // allow for multiple embeded forms
     foreach ($form_fields as $field) {
         if (!isset($values['item_meta'][$field->id]) || !isset($field->field_options['form_select']) || !isset($values['item_meta'][$field->id]['form'])) {
             // don't continue if we don't know which form to insert the sub entries into
             unset($values['item_meta'][$field->id]);
             continue;
         }
         if ('divider' == $field->type && !FrmField::is_repeating_field($field)) {
             // only create sub entries for repeatable sections
             continue;
         }
         $field_values = $values['item_meta'][$field->id];
         $sub_form_id = $field->field_options['form_select'];
         unset($field_values['form']);
         if ($action != 'create' && isset($field_values['id'])) {
             $old_ids = FrmEntryMeta::get_entry_meta_by_field($values['id'], $field->id);
             $old_ids = array_filter((array) $old_ids, 'is_numeric');
             unset($field_values['id']);
         } else {
             $old_ids = array();
         }
         $sub_ids = array();
         foreach ($field_values as $k => $v) {
             $entry_values = $new_values;
             $entry_values['form_id'] = $sub_form_id;
             $entry_values['item_meta'] = (array) $v;
             $entry_values['parent_item_id'] = isset($values['id']) ? $values['id'] : 0;
             $entry_values['parent_form_id'] = $form_id;
             // include a nonce just to be sure the parent_form_id is legit
             $entry_values['parent_nonce'] = wp_create_nonce('parent');
             // set values for later user (file upload and tags fields)
             $_POST['item_meta']['key_pointer'] = $k;
             $_POST['item_meta']['parent_field'] = $field->id;
             if (!is_numeric($k) && in_array(str_replace('i', '', $k), $old_ids)) {
                 // update existing sub entries
                 $entry_values['id'] = str_replace('i', '', $k);
                 FrmEntry::update($entry_values['id'], $entry_values);
                 $sub_id = $entry_values['id'];
             } else {
                 // create new sub entries
                 $sub_id = FrmEntry::create($entry_values);
             }
             if ($sub_id) {
                 $sub_ids[] = $sub_id;
             }
             unset($k, $v, $entry_values, $sub_id);
         }
         $values['item_meta'][$field->id] = $sub_ids;
         // array of sub entry ids
         $old_ids = array_diff($old_ids, $sub_ids);
         if (!empty($old_ids)) {
             // delete entries that were removed from section
             foreach ($old_ids as $old_id) {
                 FrmEntry::destroy($old_id);
             }
         }
         unset($field);
     }
     return $values;
 }