[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_list_
   3  {
   4      const screen         = MailPress_page_forms;
   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     = 'form';
  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' ) );
  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::delete( $id ) )
  33                      {
  34                          $$count++;
  35                      }
  36                  }
  37  
  38                  if ( $$count )
  39                  {
  40                      $url_parms[$count] = $$count;
  41                  }
  42                  $url_parms['message'] = ( $$count <= 1 ) ? 3 : 4;
  43                  self::mp_redirect( self::url( MailPress_forms, $url_parms ) );
  44              break;
  45  
  46              case 'add':
  47                  $e = MP_Form::insert( self::$pst_ );
  48                  $url_parms['message'] = ( $e ) ? 1 : 91;
  49                  unset( $url_parms['s'] );
  50                  self::mp_redirect( self::url( MailPress_forms, $url_parms ) );
  51              break;
  52              case 'duplicate' :
  53                  MP_Form::duplicate( $url_parms['id'] );
  54                  self::mp_redirect( self::url( MailPress_forms, $url_parms ) );
  55              break;
  56              case 'edited':
  57                  unset( self::$get_['action'] );
  58                  if ( !isset( self::$pst_['cancel'] ) ) 
  59                  {
  60                      $e = MP_Form::insert( self::$pst_ );
  61                      $url_parms['message'] = ( $e ) ? 2 : 92 ;
  62                      $url_parms['action']  = 'edit';
  63                  }
  64                  else
  65                  {
  66                      unset( $url_parms['id'] );
  67                  }
  68  
  69                  self::mp_redirect( self::url( MailPress_forms, $url_parms ) );
  70              break;
  71  
  72              case 'delete':
  73                  MP_Form::delete( $url_parms['id'] );
  74                  unset( $url_parms['id'] );
  75  
  76                  $url_parms['message'] = 3;
  77                  self::mp_redirect( self::url( MailPress_forms, $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_['id'] ) )
  88          {
  89              global $title;
  90              $title = __( 'Edit Form', 'MailPress' );
  91          } 
  92      }
  93  
  94  //// Help ////
  95  
  96  	public static function add_help_tab() 
  97      {
  98          global $current_screen;
  99  
 100          $content = '';
 101          $content .= '<p><strong>' . __( 'Forms :', 'MailPress' ) . '</strong></p>'
 102                  . '<p>' . __( 'To create a form, you will need to : ', 'MailPress' ) . '</p>'
 103                  . '<ol><li> '
 104                  . sprintf( __( 'Using this form, create a MailPress form linked to a %s.', 'MailPress' ), sprintf( '<a href="' . MailPress_templates . '" target="_blank">%s</a>', __( 'template', 'MailPress' ) ) )
 105                  . '</li><li> '
 106                  . __( 'Once created, select the option &#8220;Fields&#8221; in the forms list, to create your form fields', 'MailPress' )
 107                  . '</li></ol>';
 108  
 109          $content .= '<div id="mp_help" class="mp_help">'
 110                  .'<ul><li>'
 111                  . '<a href="#mp_help_tab_1">' . __( 'Attributes', 'MailPress' ) . '</a>'
 112                  . '</li><li> '
 113                  . '<a href="#mp_help_tab_2">' . __( 'Options', 'MailPress' ) . '</a>'
 114                  . '</li><li> '
 115                  . '<a href="#mp_help_tab_3">' . __( 'Messages', 'MailPress' ) . '</a>'
 116                  . '</li><li> '
 117                  . '<a href="#mp_help_tab_4">' . __( 'Visitor', 'MailPress' ) . '</a>'
 118                  . '</li><li> '
 119                  . '<a href="#mp_help_tab_5">' . __( 'Recipient', 'MailPress' ) . '</a>'
 120                  . '</li></ul> '
 121          . '<div class="cbh95">'
 122              . '<div id="mp_help_tab_1" class="mp_help_tabs">'
 123                  . '<table>'
 124                  . '<tr><td>'
 125                  . 'class ='
 126                  . '<td><td>'
 127                  . sprintf( __( 'For css purpose, if you need any class to be set in the %s HTML tag', 'MailPress' ), '<code>form</code>' )
 128                  . '</td></tr>'
 129                  . '<tr><td>'
 130                  . 'style ='
 131                  . '<td><td>'
 132                  . sprintf( __( 'For css purpose, if you need any style to be set in the %s HTML tag', 'MailPress' ), '<code>form</code>' )
 133                  . '</td></tr>'
 134                  . '<tr><td>'
 135                  . '<td><td>'
 136                  . __( "other attributes except 'name' & 'action'", 'MailPress' )
 137                  . '</td></tr>'
 138                  . '</table>'
 139              . '</div>'
 140              . '<div id="mp_help_tab_2" class="mp_help_tabs">'
 141                  . '<table>'
 142                  . '<tr><td>'
 143                  . __( 'Reset...', 'MailPress' )
 144                  . '<td><td>'
 145                  . __( 'After submitted, all form fields initialised', 'MailPress' )
 146                  . '</td></tr>'
 147                  . '</table>'
 148              . '</div>'
 149              . '<div id="mp_help_tab_3" class="mp_help_tabs">'
 150                  . '<table>'
 151                  . '<tr><td>'
 152                  . __( 'success', 'MailPress' )
 153                  . '<td><td>'
 154                  . __( 'Your message', 'MailPress' )
 155                  . '</td></tr>'
 156                  . '<tr><td>'
 157                  . __( 'failed', 'MailPress' )
 158                  . '<td><td>'
 159                  . __( 'Your message', 'MailPress' )
 160                  . '</td></tr>'
 161                  . '<tr><td>'
 162                  . '<td><td>'
 163                  . __( 'You can choose the location of your message in your html by editing its template... look for {{message}}', 'MailPress' )
 164                  . '</td></tr>'
 165                  . '</table>'
 166              . '</div>'
 167              . '<div id="mp_help_tab_4" class="mp_help_tabs">'
 168                  . '<table>'
 169                  . '<tr><td>'
 170                  . __( 'Subscriber', 'MailPress' )
 171                  . '<td><td>'
 172                  . __( 'Choose option.', 'MailPress' )
 173                  . '</td></tr>'
 174                  . '<tr><td>'
 175                  . __( 'Copy', 'MailPress' )
 176                  . '<td><td>'
 177                  . __( 'Choose option.', 'MailPress' )
 178                  . ' <i>'
 179                  . __( 'to be confirmed, will automatically add a checkbox in the form fields.', 'MailPress' )
 180                  . '</i></td></tr>'
 181                  . '</table>'
 182              . '</div>'
 183              . '<div id="mp_help_tab_5" class="mp_help_tabs">'
 184                  . '<table>'
 185                  . '<tr><td>'
 186                  . __( 'Email', 'MailPress' )
 187                  . '<td><td>'
 188                  . __( 'Recipient Email', 'MailPress' )
 189                  . '</td></tr>'
 190                  . '<tr><td>'
 191                  . __( 'Name', 'MailPress' )
 192                  . '<td><td>'
 193                  . __( 'Recipient name', 'MailPress' )
 194                  . '</td></tr>'
 195                  . '<tr><td>'
 196                  . '<td><td>'
 197                  . __( 'MailPress theme template must start by "form_", see samples in <code>mailpress/mp-content/themes</code>', 'MailPress' )
 198                  . '</td></tr>'
 199                  . '</table>'
 200              . '</div>'
 201              . '</div>'
 202                  . '</div>';
 203  
 204          $current_screen->add_help_tab( array(     'id'        => 'overview',
 205                                          'title'        => __( 'Overview' ),
 206                                          'content'    => $content )
 207          );
 208      }
 209  
 210  ////  Styles  ////
 211  
 212  	public static function print_styles( $s ) 
 213      {
 214          $styles = ( is_array( $s ) ) ? $s : array();
 215  
 216          wp_register_style( self::screen,    '/' . MP_PATH . 'mp-admin/css/forms.css', array( 'thickbox' ) );
 217  
 218          $styles[] = self::screen;
 219          parent::print_styles( $styles );
 220      }
 221  
 222  //// Scripts ////
 223  
 224  	public static function print_scripts( $scripts = array() )  
 225      {
 226          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery', 'jquery-ui-tabs' ), false, 1 );
 227          wp_localize_script( 'mp-ajax-response',     'wpAjax', array( 
 228              'noPerm' => __( 'An unidentified error has occurred.' ), 
 229              'broken' => __( 'An unidentified error has occurred.' ), 
 230              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 231           ) );
 232  
 233          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response' ), false, 1 );
 234  
 235          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array( 'thickbox' ), false, 1 );
 236  
 237          wp_register_script( 'mp-taxonomy',         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array( 'mp-lists' ), false, 1 );
 238          wp_localize_script( 'mp-taxonomy',         'MP_AdminPageL10n', array( 
 239              'pending' => __( '%i% pending' ), 
 240              'screen' => self::screen,
 241              'list_id' => self::list_id,
 242              'add_form_id' => self::add_form_id,
 243              'tr_prefix_id' => self::tr_prefix_id,
 244              'l10n_print_after' => 'try{convertEntities( MP_AdminPageL10n );}catch( e ){};' 
 245           ) );
 246  
 247          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/forms.js', array( 'mp-taxonomy', 'mp-thickbox' ), false, 1 );
 248  
 249          $scripts[] = self::screen;
 250          parent::print_scripts( $scripts );
 251      }
 252  
 253  //// Columns ////
 254  
 255  	public static function get_columns() 
 256      {
 257          $columns = array(    'cb'            => '<input type="checkbox" />',
 258                          'name'        => __( 'Label', 'MailPress' ),
 259                          'template'        => __( 'Template', 'MailPress' ),
 260                          'recipient'    => __( 'Recipient', 'MailPress' ),
 261                          'confirm'        => __( 'Copy', 'MailPress' ) 
 262          );
 263          return $columns;
 264      }
 265  
 266  //// List ////
 267  
 268  	public static function get_list( $args )
 269      {
 270          extract( $args );
 271  
 272          global $wpdb;
 273  
 274          $where = '';
 275  
 276          if ( isset( $url_parms['s'] ) )
 277          {
 278              $sc = array( 'a.label', 'a.description' );
 279  
 280              $where .= self::get_search_clause( $url_parms['s'], $sc );
 281          }
 282  
 283          $args['query'] = "SELECT DISTINCT SQL_CALC_FOUND_ROWS a.id, a.label, a.description, a.template, a.settings FROM $wpdb->mp_forms a WHERE 1=1 $where ";
 284          $args['cache_name'] = 'mp_form';
 285  
 286          return parent::get_list( $args );
 287      }
 288  
 289  ////  Row  ////
 290  
 291  	public static function get_row( $form, $url_parms ) 
 292      {
 293          static $row_class = '';
 294  
 295          $form = MP_Form::get( $form );
 296  
 297  // url's
 298          $url_parms['action']     = 'edit';
 299  
 300          $url_parms['id']     = $form->id;
 301  
 302          $edit_url = esc_url( self::url( MailPress_forms, $url_parms ) );
 303          $url_parms['action']     = 'duplicate';
 304          $duplicate_url = esc_url( self::url( MailPress_forms, $url_parms, 'duplicate-form_' . $form->id ) );
 305  
 306          $url_parms['action']     = 'edit_fields';
 307          $url_parms['form_id'] = $url_parms['id']; unset( $url_parms['id'] ); 
 308          $edit_fields_url = esc_url( self::url( MailPress_fields, $url_parms ) );
 309          $url_parms['id'] = $url_parms['form_id']; unset( $url_parms['form_id'] ); 
 310  
 311          $edit_templates_url = esc_url( self::url( MailPress_templates, array( 'action' => 'edit', 'template' => $form->template ) ) );
 312  
 313          $args = array();
 314          $args['id']        = $form->id;
 315          $args['action']     = 'mp_ajax';
 316          $args['mp_action']     = 'ifview';
 317          $args['TB_iframe']    = 'true';
 318          $view_url            = esc_url( self::url( admin_url( 'admin-ajax.php' ), $args ) );
 319  
 320          $url_parms['action']     = 'delete';
 321          $delete_url = esc_url( self::url( MailPress_forms, $url_parms, 'delete-form_' . $form->id ) );
 322  
 323  // actions
 324          $actions = array();
 325          $actions['edit'] = '<a href="' . $edit_url . '">' . __( 'Edit' ) . '</a>';
 326          $actions['edit_templates'] = '<a href="' . $edit_templates_url . '">' . __( 'Templates', 'MailPress' ) . '</a>';
 327          $actions['edit_fields'] = '<a href="' . $edit_fields_url . '">' . __( 'Fields', 'MailPress' ) . '</a>';
 328          $actions['duplicate'] = '<a class="dim:' . self::list_id . ':' . self::tr_prefix_id . '-' . $form->id . ':unapproved:e7e7d3:e7e7d3" href="' . $duplicate_url . '">' . __( 'Duplicate', 'MailPress' ) . '</a>';
 329          $actions['delete'] = '<a class="submitdelete" href="' . $delete_url . '">' . __( 'Delete' ) . '</a>';
 330          $actions['view'] = '<a class="thickbox thickbox-preview" href="' . $view_url . '" title="' . esc_attr( sprintf( __( 'Form preview #%1$s (%2$s)', 'MailPress' ), $form->id, $form->label ) ) . '" >' . __( 'Preview', 'MailPress' ) . '</a>';
 331  
 332          $row_class = ( 'alternate' == substr( $row_class, 0, 9 ) ) ? '' : 'alternate '; 
 333          $row_class .= 'iedit';
 334  
 335          $out = '';
 336          $out .= '<tr id="' . self::tr_prefix_id . '-' . $form->id . '" class="' . $row_class . '">';
 337  
 338          $columns = self::get_columns();
 339          $hidden  = self::get_hidden_columns();
 340  
 341          foreach ( $columns as $column_name => $column_display_name ) 
 342          {
 343              $attributes = sprintf( 'class="%1$s column-%1$s%2$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '' );
 344  
 345              switch ( $column_name ) 
 346              {
 347                  case 'cb':
 348                      $out .= '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $form->id . '" /></th>';
 349                  break;
 350                  case 'name':
 351                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $form->label ) ) . '">' . $form->label . '</a></strong><br />';
 352                      $out .= self::get_actions( $actions );
 353                      $out .= '</td>';
 354                  break;
 355                   case 'template':
 356                       $out .= '<td ' . $attributes . '>' . $form->template . '</td>';
 357                   break;
 358                   case 'Theme':
 359                       $out .= '<td ' . $attributes . '>' . $form->settings['recipient']['theme'];
 360                      if ( !empty( $form->settings['recipient']['template'] ) ) $out .= '<br />( ' . $form->settings['recipient']['template'] . ' )'; 
 361                      $out .= '</td>';
 362                   break;
 363                   case 'recipient':
 364                       $out .= '<td ' . $attributes . '>' . $form->settings['recipient']['toemail'];
 365                      if ( !empty( $form->settings['recipient']['toname'] ) ) $out .= '<br />( ' . $form->settings['recipient']['toname'] . ' )'; 
 366                      $out .= '</td>';
 367                   break;
 368                  case 'confirm':
 369                       $out .= '<td ' . $attributes . '>';
 370                      $mail = ( isset( $form->settings['visitor']['mail'] ) ) ? $form->settings['visitor']['mail'] : 0;
 371                      switch ( $mail )
 372                      {
 373                          case 1 :
 374                              $out .= __( 't.b.c.', 'MailPress' );
 375                          break;
 376                          case 2 :
 377                              $out .= __( 'yes', 'MailPress' );
 378                          break;
 379                          default :
 380                              $out .= __( 'no', 'MailPress' );
 381                          break;
 382                      }
 383                       $out .= '</td>';
 384                   break;
 385              }
 386          }
 387          $out .= '</tr>';
 388  
 389          return $out;
 390      }
 391  }


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