public static function duplicate()
 {
     $params = FrmForm::get_admin_params();
     if (!current_user_can('frm_create_entries')) {
         return FrmEntriesController::show($params['id']);
     }
     $message = $errors = '';
     $record = FrmEntry::duplicate($params['id']);
     if ($record) {
         $message = __('Entry was Successfully Duplicated', 'formidable');
     } else {
         $errors = __('There was a problem duplicating that entry', 'formidable');
     }
     if (!empty($errors)) {
         return FrmEntriesController::display_list($message, $errors);
     } else {
         return self::get_edit_vars($record, array(), $message);
     }
 }
Пример #2
0
 /**
  * After an entry is duplicated, also duplicate the sub entries
  * @since 2.0
  */
 public static function duplicate_sub_entries($entry_id, $form_id, $args)
 {
     $form_fields = FrmProFormsHelper::has_field('form', $form_id, false);
     $section_fields = FrmProFormsHelper::has_repeat_field($form_id, false);
     $form_fields = array_merge($section_fields, $form_fields);
     if (empty($form_fields)) {
         // there are no fields for child entries
         return;
     }
     $entry = FrmEntry::getOne($entry_id, true);
     $sub_ids = array();
     foreach ($form_fields as $field) {
         if (!isset($entry->metas[$field->id])) {
             continue;
         }
         $field_ids = array();
         $ids = maybe_unserialize($entry->metas[$field->id]);
         if (!empty($ids)) {
             // duplicate all entries for this field
             foreach ((array) $ids as $sub_id) {
                 $field_ids[] = FrmEntry::duplicate($sub_id);
                 unset($sub_id);
             }
             FrmEntryMeta::update_entry_meta($entry_id, $field->id, null, $field_ids);
             $sub_ids = array_merge($field_ids, $sub_ids);
         }
         unset($field, $field_ids);
     }
     if (!empty($sub_ids)) {
         // update the parent id for new entries
         global $wpdb;
         $where = array('id' => $sub_ids);
         FrmDb::get_where_clause_and_values($where);
         array_unshift($where['values'], $entry_id);
         $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_items SET parent_item_id = %d ' . $where['where'], $where['values']));
     }
 }