[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-admin/ -> form_fields.php (source)

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_list_
   3  {
   4      const screen        = 'mailpress_page_form_fields';
   5      const capability    = 'MailPress_manage_forms';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/add-ons/form/';
   7      const file            = __FILE__;
   8  
   9      const add_form_id    = 'add';
  10      const list_id        = 'the-list';
  11      const tr_prefix_id    = 'field';
  12  
  13  ////  Redirect  ////
  14  
  15  	public static function redirect() 
  16      {
  17          $action = parent::redirect();
  18          if ( !$action ) return;
  19  
  20          $url_parms = self::get_url_parms( array( 's', 'paged', 'id', 'form_id' ) );
  21          $checked    = ( isset( self::$get_['checked'] ) ) ? self::$get_['checked'] : array();
  22  
  23          $count    = str_replace( 'bulk-', '', $action );
  24          $count     .= 'd';
  25          $$count    = 0;
  26  
  27          switch( $action ) 
  28          {
  29              case 'bulk-delete' :
  30                  foreach( $checked as $id )
  31                  {
  32                      if ( MP_Form_field::delete( $id, $url_parms['form_id'] ) )
  33                      {
  34                          $$count++;
  35                      }
  36                  }
  37  
  38                  if ( $$count )
  39                  {
  40                      $url_parms[$count] = $$count;
  41                  }
  42  
  43                  $url_parms['message'] = ( $$count <= 1 ) ? 3 : 4;
  44                  self::mp_redirect( self::url( MailPress_fields, $url_parms ) );
  45              break;
  46  
  47              case 'add':
  48                  $e = MP_Form_field::insert( self::$pst_ );
  49                  $url_parms['message'] = ( $e  ) ? 1 : 91;
  50                  unset( $url_parms['s'] );
  51                  self::mp_redirect( self::url( MailPress_fields, $url_parms ) );
  52              break;
  53              case 'duplicate' :
  54                  MP_Form_field::duplicate( $url_parms['id'], $url_parms['form_id'] );
  55                  self::mp_redirect( self::url( MailPress_fields, $url_parms ) );
  56              break;
  57              case 'edited':
  58                  unset( self::$get_['action'] );
  59                  if ( !isset( self::$pst_['cancel'] ) ) 
  60                  {
  61                      $e = MP_Form_field::insert( self::$pst_ );
  62                      $url_parms['message'] = ( $e ) ? 2 : 92 ;
  63                      $url_parms['action']  = 'edit';
  64                  }
  65                  else
  66                  {
  67                      unset( $url_parms['id'] );
  68                  }
  69  
  70                  self::mp_redirect( self::url( MailPress_fields, $url_parms ) );
  71              break;
  72              case 'delete':
  73                  MP_Form_field::delete( $url_parms['id'], $url_parms['form_id'] );
  74                  unset( $url_parms['id'] );
  75  
  76                  $url_parms['message'] = 3;
  77                  self::mp_redirect( self::url( MailPress_fields, $url_parms ) );
  78              break;
  79          }
  80      }
  81  
  82  ////  Title  ////
  83  
  84  	public static function title() 
  85      { 
  86          new MP_Form_field_types();
  87          if ( isset( self::$get_['form_id'] ) )
  88          {
  89              global $title;
  90              $title = __( 'MailPress Forms Edit Fields', 'MailPress' );
  91          } 
  92      }
  93  
  94  ////  Help  ////
  95  
  96  	public static function add_help_tab() 
  97      {
  98  // snippet as admin page to get contextual help ...
  99          $field_types = MP_Form_field_types::get_all();
 100  
 101          if ( isset( self::$get_['action'] ) && ( 'edit' == self::$get_['action'] ) )
 102          {
 103              $field = MP_Form_field::get( self::$get_['id'] );
 104          }
 105          else
 106          {
 107              $field = new stdClass();
 108              $field->type = 'text';
 109          }
 110  
 111          global $current_screen;
 112  
 113          $content = '';
 114          $content .= '<p><strong>' . __( 'Form fields :', 'MailPress' ) . '</strong></p>'
 115                  . '<p>'
 116                  . __( 'You can insert any field in your form.', 'MailPress' )
 117                  . '<br />'
 118                  . __( 'Text Input, Multi-line Input, Checkbox, Radio Button, Drop-down list, File select and Button are standard form fields.', 'MailPress' )
 119                  . '<br />'
 120                  . __( 'The other fields are composite ones, which means they are made of several fields with specific display and/or controls.', 'MailPress' )
 121                  . '<br />'
 122                  . __( 'To select the help on a specific field type, select this field type in the admin page hereunder.', 'MailPress' )
 123  
 124                  . '</p>';
 125  
 126          $content .= '<div id="form_fields_help">';
 127  
 128          foreach ( $field_types as $key => $field_type )
 129          {
 130              $content .= MP_Form_field_types::settings_help( '', $key, $field );
 131          }
 132  
 133          $content .= '</div>';
 134  
 135          $current_screen->add_help_tab( array(     'id'        => 'overview',
 136                                          'title'     => __( 'Overview' ),
 137                                          'content'    => $content )
 138          );
 139      }
 140  
 141  ////  Styles  ////
 142  
 143  	public static function print_styles( $s ) 
 144      {
 145          $styles = ( is_array( $s ) ) ? $s : array();
 146  
 147  // for specific css
 148          $pathcss        = MP_ABSPATH . 'mp-includes/class/options/form/field_types_' . get_user_option( 'admin_color' ) . '.css';
 149          $css_url        = '/' . MP_PATH . 'mp-includes/class/options/form/field_types_' . get_user_option( 'admin_color' ) . '.css';
 150          $css_url_default     = '/' . MP_PATH . 'mp-includes/class/options/form/field_types_fresh.css';
 151          $css_url        = ( is_file( $pathcss ) ) ? $css_url : $css_url_default;
 152          wp_register_style( 'mp_field_types',     $css_url );
 153  
 154          wp_register_style( self::screen,        '/' . MP_PATH . 'mp-admin/css/form_fields.css', array( 'mp_field_types', 'thickbox' ) );
 155  
 156          $styles[] = self::screen;
 157          parent::print_styles( $styles );
 158      }
 159  
 160  //// Scripts ////
 161  
 162  	public static function print_scripts( $scripts = array() )  
 163      {
 164          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery', 'jquery-ui-tabs' ), false, 1 );
 165          wp_localize_script( 'mp-ajax-response',     'wpAjax', array( 
 166              'noPerm' => __( 'An unidentified error has occurred.' ), 
 167              'broken' => __( 'An unidentified error has occurred.' ), 
 168              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 169           ) );
 170  
 171          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response' ), false, 1 );
 172  
 173          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array( 'thickbox' ), false, 1 );
 174  
 175          wp_register_script( 'mp-taxonomy',         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array( 'mp-lists' ), false, 1 );
 176          wp_localize_script( 'mp-taxonomy',         'MP_AdminPageL10n', array(     
 177              'pending' => __( '%i% pending' ), 
 178              'screen' => self::screen,
 179              'list_id' => self::list_id,
 180              'add_form_id' => self::add_form_id,
 181              'tr_prefix_id' => self::tr_prefix_id,
 182              'l10n_print_after' => 'try{convertEntities( MP_AdminPageL10n );}catch( e ){};' 
 183           ) );
 184  
 185          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/form_fields.js', array( 'mp-taxonomy', 'mp-thickbox' ), false, 1 );
 186  
 187          $scripts[] = self::screen;
 188          parent::print_scripts( $scripts );
 189      }
 190  
 191  //// Columns ////
 192  
 193  	public static function get_columns() 
 194      {
 195          if ( isset( self::$get_['form_id'] ) ) 
 196          {
 197              $form = MP_Form::get( self::$get_['form_id'] );
 198              if ( isset( $form->settings['visitor']['mail'] ) && ( $form->settings['visitor']['mail'] != '0' ) )
 199              {
 200                  add_filter( 'MailPress_form_columns_form_fields', array( __CLASS__, 'add_incopy_column' ), 1, 1 );
 201              }
 202          }
 203  
 204          $columns = array(    'cb'        => '<input type="checkbox" />',
 205                          'name'    => __( 'Label', 'MailPress' ),
 206                          'type'    => __( 'Type', 'MailPress' ),
 207                          'order'    => __( 'Order', 'MailPress' ),
 208                          'required'    => __( 'Required', 'MailPress' ),
 209                          'template'    => __( 'Template', 'MailPress' ) 
 210          );
 211          return apply_filters( 'MailPress_form_columns_form_fields', $columns );
 212      }
 213  
 214  	public static function add_incopy_column( $columns )
 215      {
 216          $template             = array_pop( $columns );
 217          $columns['incopy']    = __( 'In&#160;copy', 'MailPress' );
 218              $columns['template']     = $template;
 219          return $columns;
 220      }
 221  
 222  //// List ////
 223  
 224  	public static function get_list( $args )
 225      {
 226          extract( $args );
 227  
 228          global $wpdb;
 229  
 230          $order = "a.ordre";
 231  
 232          $where = ' AND ( a.form_id = ' . self::$get_['form_id'] . ' ) ';
 233  
 234          if ( isset( $url_parms['s'] ) )
 235          {
 236              $sc = array( 'a.label', 'a.description' );
 237  
 238              $where .= self::get_search_clause( $url_parms['s'], $sc );
 239          }
 240  
 241          $args['query'] = "SELECT DISTINCT SQL_CALC_FOUND_ROWS a.id, a.form_id, a.ordre, a.type, a.template, a.label, a.description, a.settings FROM $wpdb->mp_fields a WHERE 1=1 $where ORDER BY $order";
 242          $args['cache_name'] = 'mp_field';
 243  
 244          return parent::get_list( $args );
 245      }
 246  
 247  ////  Row  ////
 248  
 249  	public static function get_row( $id, $url_parms, $checkbox = true ) 
 250      {
 251          static $row_class = '';
 252  
 253          $field = MP_Form_field::get( $id );
 254  
 255          $field_types = MP_Form_field_types::get_all();
 256  
 257  // url's
 258          $url_parms['action']    = 'edit';
 259          $url_parms['id']    = $field->id;
 260          $url_parms['form_id']    = $field->form_id;
 261  
 262          $edit_url = esc_url( self::url( MailPress_fields, $url_parms ) );
 263          $url_parms['action']     = 'duplicate';
 264          $duplicate_url = esc_url( self::url( MailPress_fields, $url_parms, 'duplicate-field_' . $field->id ) );
 265          $url_parms['action']     = 'delete';
 266          $delete_url = esc_url( self::url( MailPress_fields, $url_parms, 'delete-form_' . $field->id ) );
 267  // actions
 268          $actions = array();
 269          $actions['edit'] = '<a href="' . $edit_url . '">' . __( 'Edit' ) . '</a>';
 270          $actions['duplicate'] = '<a class="dim:' . self::list_id . ':' . self::tr_prefix_id . '-' . $field->id . ':unapproved:e7e7d3:e7e7d3" href="' . $duplicate_url . '">' . __( 'Duplicate', 'MailPress' ) . '</a>';
 271          $actions['delete'] = '<a class="submitdelete" href="' . $delete_url . '">' . __( 'Delete' ) . '</a>';
 272  
 273          $row_class = 'alternate' == $row_class ? '' : 'alternate';
 274  
 275  // protected
 276          $disabled = '';
 277          if ( isset( $field->settings['options']['protected'] ) )
 278          {
 279              unset( $actions['duplicate'], $actions['delete'] );
 280              $disabled = ' disabled="disabled"';
 281          }
 282  
 283          $out = '';
 284          $out .= '<tr id="' . self::tr_prefix_id . '-' . $field->id . '" class="iedit ' . $row_class . '">';
 285  
 286          $columns = self::get_columns();
 287          $hidden  = self::get_hidden_columns();
 288  
 289          foreach ( $columns as $column_name => $column_display_name ) 
 290          {
 291              $attributes = sprintf( 'class="%1$s column-%1$s%2$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '' );
 292  
 293              switch ( $column_name ) 
 294              {
 295                  case 'cb':
 296                      $out .= ( !$disabled ) ? '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $field->id . '" /></th>' : '<th class="check-column"></th>';
 297                  break;
 298                  case 'name':
 299                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $field->label ) ) . '">' . $field->label . '</a></strong><br />';
 300                      $out .= self::get_actions( $actions );
 301                      $out .= '</td>';
 302                  break;
 303                  case 'type':
 304                       $out .= '<td ' . $attributes . '>';
 305                      $out .= '<div class="pl28 field_type_' . $field->type . '">' . $field_types[$field->type]['desc'] . '</div>';
 306                       $out .= '</td>';
 307                   break;
 308                  case 'incopy':
 309                       $out .= '<td ' . $attributes . '>';
 310                      if ( isset( $field->settings['options']['incopy'] ) ) $out .= __( 'yes', 'MailPress' );
 311                       $out .= '</td>';
 312                   break;
 313                  case 'required':
 314                       $out .= '<td ' . $attributes . '>';
 315                      if ( isset( $field->settings['controls']['required'] ) ) $out .= __( 'yes', 'MailPress' );
 316                       $out .= '</td>';
 317                   break;
 318                  case 'order':
 319                       $out .= '<td ' . $attributes . '>';
 320                      $out .= $field->ordre;
 321                       $out .= '</td>';
 322                   break;
 323                  default:
 324                      $out .= '<td ' . $attributes . '>';
 325                      $out .= $field->{$column_name};
 326                      $out .= '</td>';
 327                  break;
 328              }
 329          }
 330          $out .= '</tr>';
 331  
 332          return $out;
 333      }
 334  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1