UM_Admin_DragDrop

The Ultimate Member UM Admin DragDrop class.

Defined (1)

The class is defined in the following location(s).

/admin/core/um-admin-dragdrop.php  
  1. class UM_Admin_DragDrop { 
  2.  
  3. function __construct() { 
  4.  
  5. add_action('admin_footer', array(&$this, 'load_field_order'), 9); 
  6.  
  7. add_action('wp_ajax_nopriv_update_order', array(&$this, 'update_order') ); 
  8. add_action('wp_ajax_update_order', array(&$this, 'update_order') ); 
  9.  
  10.  
  11. /*** 
  12. *** @update order of fields 
  13. ***/ 
  14. function update_order() { 
  15.  
  16. global $ultimatemember; 
  17.  
  18. if ( !is_user_logged_in() || !current_user_can('manage_options') ) die('Please login as administrator'); 
  19.  
  20. extract($_POST); 
  21.  
  22. $fields = $ultimatemember->query->get_attr('custom_fields', $form_id ); 
  23.  
  24. $this->row_data = get_option('um_form_rowdata_'. $form_id ); 
  25.  
  26. if( isset( $fields ) ) { 
  27. foreach( $fields as $key => $array ) { 
  28. if ( $array['type'] == 'row' ) { 
  29. $this->row_data[$key] = $array; 
  30. unset( $fields[$key] ); 
  31.  
  32. foreach( $_POST as $key => $value ) { 
  33.  
  34. // adding rows 
  35. if (0 === strpos($key, '_um_row_')) { 
  36.  
  37. $update_args = null; 
  38.  
  39. $row_id = str_replace( '_um_row_', '', $key ); 
  40.  
  41. $row_array = array( 
  42. 'type' => 'row',  
  43. 'id' => $value,  
  44. 'sub_rows' => $_POST[ '_um_rowsub_'.$row_id .'_rows' ],  
  45. 'cols' => $_POST[ '_um_rowcols_'.$row_id .'_cols' ],  
  46. 'origin' => $_POST[ '_um_roworigin_'.$row_id . '_val' ],  
  47. ); 
  48.  
  49. $row_args = $row_array; 
  50.  
  51. if ( isset( $this->row_data[ $row_array['origin'] ] ) ) { 
  52. foreach( $this->row_data[ $row_array['origin'] ] as $k => $v ) { 
  53. if ( $k != 'position' && $k != 'metakey' ) { 
  54. $update_args[$k] = $v; 
  55. if ( isset( $update_args ) ) { 
  56. $row_args = array_merge( $update_args, $row_array ); 
  57. $this->exist_rows[] = $key; 
  58.  
  59. $fields[$key] = $row_args; 
  60.  
  61.  
  62. // change field position 
  63. if (0 === strpos($key, 'um_position_') ) { 
  64. $field_key = str_replace('um_position_', '', $key); 
  65. if ( isset( $fields[$field_key] ) ) { 
  66. $fields[$field_key]['position'] = $value; 
  67.  
  68. // change field master row 
  69. if (0 === strpos($key, 'um_row_') ) { 
  70. $field_key = str_replace('um_row_', '', $key); 
  71. if ( isset( $fields[$field_key] ) ) { 
  72. $fields[$field_key]['in_row'] = $value; 
  73.  
  74. // change field sub row 
  75. if (0 === strpos($key, 'um_subrow_') ) { 
  76. $field_key = str_replace('um_subrow_', '', $key); 
  77. if ( isset( $fields[$field_key] ) ) { 
  78. $fields[$field_key]['in_sub_row'] = $value; 
  79.  
  80. // change field column 
  81. if (0 === strpos($key, 'um_col_') ) { 
  82. $field_key = str_replace('um_col_', '', $key); 
  83. if ( isset( $fields[$field_key] ) ) { 
  84. $fields[$field_key]['in_column'] = $value; 
  85.  
  86. // add field to group 
  87. if (0 === strpos($key, 'um_group_') ) { 
  88. $field_key = str_replace('um_group_', '', $key); 
  89. if ( isset( $fields[$field_key] ) ) { 
  90. $fields[$field_key]['in_group'] = $value; 
  91.  
  92.  
  93. foreach( $this->row_data as $k => $v ) { 
  94. if ( !in_array( $k, $this->exist_rows ) ) 
  95. unset( $this->row_data[$k] ); 
  96.  
  97. update_option('um_existing_rows_' . $form_id, $this->exist_rows ); 
  98.  
  99. update_option('um_form_rowdata_' . $form_id , $this->row_data ); 
  100.  
  101. $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); 
  102.  
  103.  
  104. /*** 
  105. *** @load form to maintain form order 
  106. ***/ 
  107. function load_field_order() { 
  108.  
  109. global $ultimatemember; 
  110.  
  111. $screen = get_current_screen(); 
  112.  
  113. if ( !isset( $screen->id ) || $screen->id != 'um_form' ) return; 
  114.  
  115. ?> 
  116.  
  117. <div class="um-col-demon-settings" data-in_row="" data-in_sub_row="" data-in_column="" data-in_group="" /> 
  118.  
  119. <div class="um-col-demon-row" style="display:none;"> 
  120.  
  121. <div class="um-admin-drag-row-icons"> 
  122. <a href="#" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php _e('Add Row', 'ultimatemember'); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a> 
  123. <a href="#" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php _e('Edit Row', 'ultimatemember'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo get_the_ID(); ?>"><i class="um-faicon-pencil"></i></a> 
  124. <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span> 
  125. <a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row', 'ultimatemember'); ?>" data-remove_element="um-admin-drag-row"><i class="um-faicon-trash-o"></i></a> 
  126. </div><div class="um-admin-clear"></div> 
  127.  
  128. <div class="um-admin-drag-rowsubs"> 
  129. <div class="um-admin-drag-rowsub"> 
  130.  
  131. <div class="um-admin-drag-ctrls columns"> 
  132. <a href="#" class="active" data-cols="1"></a> 
  133. <a href="#" data-cols="2"></a> 
  134. <a href="#" data-cols="3"></a> 
  135. </div> 
  136.  
  137. <div class="um-admin-drag-rowsub-icons"> 
  138. <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span> 
  139. <a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row', 'ultimatemember'); ?>" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a> 
  140. </div><div class="um-admin-clear"></div> 
  141.  
  142. <div class="um-admin-drag-col"> 
  143. </div> 
  144.  
  145. <div class="um-admin-drag-col-dynamic"></div> 
  146.  
  147. <div class="um-admin-clear"></div> 
  148.  
  149. </div> 
  150. </div> 
  151.  
  152. </div> 
  153.  
  154. <div class="um-col-demon-subrow" style="display:none;"> 
  155.  
  156. <div class="um-admin-drag-ctrls columns"> 
  157. <a href="#" class="active" data-cols="1"></a> 
  158. <a href="#" data-cols="2"></a> 
  159. <a href="#" data-cols="3"></a> 
  160. </div> 
  161.  
  162. <div class="um-admin-drag-rowsub-icons"> 
  163. <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span> 
  164. <a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row', 'ultimatemember'); ?>" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a> 
  165. </div><div class="um-admin-clear"></div> 
  166.  
  167. <div class="um-admin-drag-col"> 
  168. </div> 
  169.  
  170. <div class="um-admin-drag-col-dynamic"></div> 
  171.  
  172. <div class="um-admin-clear"></div> 
  173.  
  174. </div> 
  175.  
  176.  
  177. <form action="" method="post" class="um_update_order"> 
  178.  
  179. <input type="hidden" name="action" id="action" value="update_order" /> 
  180.  
  181. <input type="hidden" name="form_id" id="form_id" value="<?php echo get_the_ID(); ?>" /> 
  182.  
  183. <div class="um_update_order_fields"> 
  184.  
  185. </div> 
  186.  
  187. </form> 
  188.  
  189. <?php 
  190.  
  191.