[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  
   3  if ( !( function_exists( 'current_user_can' ) && current_user_can( MP_AdminPage::capability ) ) ) die( 'Access denied' );
   4  
   5  $url_parms = MP_AdminPage::get_url_parms( array( 's', 'paged', 'id' ) );
   6  
   7  //
   8  // MANAGING H1
   9  //
  10  
  11  $h1 = __( 'Forms', 'MailPress' );
  12  
  13  //
  14  // MANAGING MESSAGE
  15  //
  16  
  17  $messages[1] = __( 'Form added.', 'MailPress' );
  18  $messages[2] = __( 'Form updated.', 'MailPress' );
  19  $messages[3] = __( 'Form deleted.', 'MailPress' );
  20  $messages[4] = __( 'Forms deleted.', 'MailPress' );
  21  $messages[91] = __( 'Form not added.', 'MailPress' );
  22  $messages[92] = __( 'Form not updated.', 'MailPress' );
  23  
  24  if ( isset( MP_AdminPage::$get_['message'] ) )
  25  {
  26      $message = $messages[MP_AdminPage::$get_['message']];
  27      $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] );
  28  }
  29  
  30  //
  31  // MANAGING BULK ACTIONS
  32  //
  33  
  34  $bulk_actions['']         = __( 'Bulk Actions' );
  35  $bulk_actions['delete']    = __( 'Delete', 'MailPress' );
  36  
  37  //
  38  // MANAGING CONTENT
  39  //
  40  
  41  global $action;
  42  wp_reset_vars( array( 'action' ) );
  43  if ( 'edit' == $action )
  44  {
  45      $action = 'edited';
  46      $cancel = '<input type="submit" class="button" name="cancel" value="' . esc_attr( __( 'Cancel', 'MailPress' ) ) . '" />';
  47  
  48      $id = ( int ) $url_parms['id'];
  49      $form = MP_Form::get( $id );
  50  
  51      $h3 = sprintf( __( 'Edit Form # %1$s', 'MailPress' ), $id );
  52      $hb3= __( 'Update' );
  53      $hbclass = '-primary';
  54  }
  55  else
  56  {
  57      $action = MP_AdminPage::add_form_id;
  58      $cancel = '';
  59  
  60      $form = new stdClass();
  61  
  62      $h3 = $hb3 = __( 'Add Form', 'MailPress' );
  63      $hbclass = '';
  64  }
  65  
  66  // Form settings tab
  67  
  68  $tabs = array( 'attributes' => __( 'Attributes', 'MailPress' ), 'options' => __( 'Options', 'MailPress' ), 'messages' => __( 'Messages', 'MailPress' ), 'visitor' => __( 'Visitor', 'MailPress' ), 'recipient' => __( 'Recipient', 'MailPress' ) );
  69  if ( isset( MP_AdminPage::$get_['action'] ) && ( 'edit' == MP_AdminPage::$get_['action'] ) ) $tabs['html'] = __( 'Html', 'MailPress' ); 
  70  
  71  // Form templates
  72  
  73  $form_templates = new MP_Form_templates();
  74  $xform_template = $form_templates->get_all();
  75  
  76  // Subscribing visitor actions
  77  
  78  $xvisitor_subscriptions['0'] = __( 'no', 'MailPress' );
  79  $xvisitor_subscriptions['1'] = __( 'not active', 'MailPress' );
  80  $xvisitor_subscriptions['2'] = __( 'to be confirmed', 'MailPress' );
  81  $xvisitor_subscriptions['3'] = __( 'active', 'MailPress' );
  82  
  83  $xvisitor_mail['0'] = __( 'no', 'MailPress' );
  84  $xvisitor_mail['1'] = __( 'to be confirmed', 'MailPress' );
  85  $xvisitor_mail['2'] = __( 'yes', 'MailPress' );
  86  
  87  // Mail themes and templates
  88  
  89  $th = new MP_Themes();
  90  $themes = $th->themes; 
  91  
  92  foreach( $themes as $key => $theme )
  93  {
  94      if ( 'plaintext' == $theme['Stylesheet'] ) unset( $themes[$key] );
  95      if ( '_' == $theme['Stylesheet'][0] )     unset( $themes[$key] );
  96  }
  97  
  98  if ( !isset( $form->settings['recipient']['theme'] ) ) $form->settings['recipient']['theme'] = $themes[$th->current_theme]['Stylesheet'];
  99  if ( !isset( $form->settings['visitor'  ]['theme'] ) ) $form->settings['visitor'  ]['theme'] = $themes[$th->current_theme]['Stylesheet'];
 100  
 101  $xtheme = $xtemplates = array();
 102  foreach ( $themes as $theme )
 103  {
 104      if ( 'plaintext' == $theme['Stylesheet'] ) continue;
 105      if ( '_'         == $theme['Stylesheet'][0] ) continue;
 106  
 107      $xtheme[$theme['Stylesheet']] = $theme['Stylesheet'];
 108      if ( !$templates = $th->get_page_templates( $theme['Stylesheet'] ) ) $templates = $th->get_page_templates( $theme['Stylesheet'], true );
 109  
 110      $xtemplates[$theme['Stylesheet']] = array();
 111      foreach ( $templates as $key => $value )
 112      {
 113          if ( strpos( $key, 'form' ) !== 0 ) continue;
 114          $xtemplates[$theme['Stylesheet']][$key] = $key;
 115      }
 116      if ( !empty( $xtemplates[$theme['Stylesheet']] ) ) ksort( $xtemplates[$theme['Stylesheet']] );
 117  
 118      array_unshift( $xtemplates[$theme['Stylesheet']], __( 'none', 'MailPress' ) );
 119  }
 120  
 121  //
 122  // MANAGING LIST
 123  //
 124  
 125  $url_parms['paged'] = isset( $url_parms['paged'] ) ? $url_parms['paged'] : 1;
 126  $_per_page = MP_AdminPage::get_per_page();
 127  
 128  do
 129  {
 130      $start = ( $url_parms['paged'] - 1 ) * $_per_page;
 131      list( $items, $total ) = MP_AdminPage::get_list( array( 'start' => $start, '_per_page' => $_per_page, 'url_parms' => $url_parms ) );
 132      $url_parms['paged']--;
 133  } while ( $total <= $start );
 134  $url_parms['paged']++;
 135  
 136  ?>
 137  <div class="wrap nosubsub">
 138      <h1>
 139          <?php echo esc_html( $h1 ); ?> 
 140  <?php if ( isset( $url_parms['s'] ) ) printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_attr( $url_parms['s'] ) ); ?>
 141      </h1>
 142  <?php if ( isset( $message ) ) MP_AdminPage::message( $message, ( MP_AdminPage::$get_['message'] < 90 ) ); ?>
 143      <form class="search-form topmargin" method="get">
 144  
 145          <input type="hidden" name="page" value="<?php echo MP_AdminPage::screen; ?>" />
 146  
 147          <p class="search-box">
 148              <input type="text" name="s" class="search-input" value="<?php if ( isset( $url_parms['s'] ) ) echo esc_attr( $url_parms['s'] ); ?>" />
 149              <input type="submit" class="button" value="<?php _e( 'Search', 'MailPress' ); ?>" />
 150          </p>
 151  
 152      </form>
 153      <br class="clear" />
 154      <div id="col-container">
 155          <div id="col-right">
 156              <div class="col-wrap">
 157                  <form id="posts-filter" method="get">
 158  
 159                      <input type="hidden" name="page" value="<?php echo MP_AdminPage::screen; ?>" />
 160  
 161                      <div class="tablenav top">
 162  <?php MP_AdminPage::pagination( $total ); ?>
 163                          <div class="alignleft actions bulkactions">
 164  <?php    MP_AdminPage::get_bulk_actions( $bulk_actions ); ?>
 165                          </div>
 166                          <br class="clear" />
 167                      </div>
 168                      <div class="clear"></div>
 169                      <table class="wp-list-table widefat fixed striped zyxw">
 170                          <thead>
 171                              <tr>
 172  <?php MP_AdminPage::columns_list(); ?>
 173                              </tr>
 174                          </thead>
 175                          <tbody id="<?php echo MP_AdminPage::list_id; ?>" class="list:<?php echo MP_AdminPage::tr_prefix_id; ?>">
 176  <?php if ( $items ) : ?>
 177  <?php foreach ( $items as $item ) { echo MP_AdminPage::get_row( $item->id, $url_parms ); } ?>
 178  <?php endif; ?>
 179                          </tbody>
 180                          <tfoot>
 181                              <tr>
 182  <?php MP_AdminPage::columns_list( false ); ?>
 183                              </tr>
 184                          </tfoot>
 185                      </table>
 186                      <div class="tablenav bottom">
 187  <?php MP_AdminPage::pagination( $total, 'bottom' ); ?>
 188                          <div class="alignleft actions bulkactions">
 189  <?php    MP_AdminPage::get_bulk_actions( $bulk_actions, 'action2' ); ?>
 190                          </div>
 191                          <br class="clear" />
 192                      </div>
 193                      <br class="clear" />
 194                  </form>
 195              </div>
 196          </div><!-- /col-right -->
 197          <div id="col-left">
 198              <div class="col-wrap">
 199                  <div class="form-wrap">
 200                      <h3><?php echo esc_html( $h3 ); ?></h3>
 201                      <div id="ajax-response"></div>
 202                      <form name="<?php echo $action; ?>"  id="<?php echo $action; ?>"  method="post" class="<?php echo $action; ?>:<?php echo MP_AdminPage::list_id; ?>: validate">
 203  
 204                          <input type="hidden" name="action" value="<?php echo $action; ?>" />
 205  <?php MP_AdminPage::post_url_parms( $url_parms, array( 's', 'paged', 'id' ) ); ?>
 206                          <?php wp_nonce_field( 'update-' . MP_AdminPage::tr_prefix_id ); ?>
 207  
 208                          <div class="form-field form-required nopm">
 209                              <label for="form_label"><?php _e( 'Label', 'MailPress' ); ?></label>
 210                              <input type="text" name="label" id="form_label" size="40" aria-required="true" value="<?php if ( isset( $form->label ) ) echo esc_attr( $form->label ); ?>" />
 211                              <p>&#160;</p>
 212                          </div>
 213                          <div class="form-field nopm">
 214                              <span class="fr">
 215                                  <span class="description"><small><?php _e( 'template', 'MailPress' ); ?></small></span>
 216                                  <select name="template" id="f_template" class="mr14">
 217  <?php MP_AdminPage::select_option( $xform_template, ( isset( $form->template ) ) ? $form->template : 'default' ); ?>
 218                                  </select>
 219                              </span>
 220                              <label for="form_description" class="di"><?php _e( 'Description', 'MailPress' ); ?></label>
 221                              <input type="text" name="description" id="form_description" size="40" value="<?php if ( isset( $form->description ) ) echo esc_attr( $form->description ); ?>" />
 222                              <p><small><?php _e( 'The description can be use to give further explanations', 'MailPress' ); ?></small></p>
 223                          </div>
 224                          <div id="form_settings" class="form field form_settings mt18">
 225                              <ul>
 226  <?php
 227      foreach( $tabs as $tab_type => $tab )
 228      {
 229          echo '<li><a href="#settings_tab_' . $tab_type . '"><span>' . $tab . '</span></a></li>' . "\n";
 230      }
 231  ?>
 232                              </ul>
 233                              <div class="clear">
 234  <?php
 235      $i = 0;
 236      foreach( $tabs as $tab_type => $tab ) 
 237      {
 238          $i++;
 239          echo '                                <div id="settings_tab_' . $tab_type . '" class="ui-tabs settings_form_tabs settings_' . $tab_type . '" data-tab="' . $i . '">' . "\n";
 240          switch ( $tab_type )
 241          {
 242              case 'attributes' : 
 243  ?>
 244                                      <span class="description"><small>class="</small></span><input type="text" name="settings[attributes][class]" id="form_attribute_class" size="40" class="w80" value="<?php if ( isset( $form->settings['attributes']['class'] ) ) echo esc_attr( $form->settings['attributes']['class'] ); ?>" /><span class="description"><small>"</small></span><br />
 245                                      <span class="description"><small>style="</small></span><input type="text" name="settings[attributes][style]" id="form_attribute_style" size="40" class="w80" value="<?php if ( isset( $form->settings['attributes']['style'] ) ) echo esc_attr( $form->settings['attributes']['style'] ); ?>" /><span class="description"><small>"</small></span><br />
 246                                      <input type="text" name="settings[attributes][misc]" id="form_attribute_misc" size="40" class="w98" value="<?php if ( isset( $form->settings['attributes']['misc'] ) ) echo esc_attr( $form->settings['attributes']['misc'] ); ?>" /><br />
 247                                      <span class="description"><i><?php _e( "other attributes except 'name' & 'action'", 'MailPress' ); ?></i></span>
 248  <?php
 249              break;
 250              case 'options'    : 
 251  ?>
 252                                      <input type="checkbox" value="1" name="settings[options][reset]" id="form_option_reset" class="wa"<?php checked( '1', ( ( isset( $form->settings['options']['reset'] ) ) ? 1 : 0 ) ); ?> />
 253                                      <label for="form_option_reset" class="di"><small><?php _e( 'Reset after submission', 'MailPress' ); ?></small></label>
 254  <?php
 255              break;
 256              case 'messages'    : 
 257  ?>
 258                                      <label for="f_message_ok"><small><?php _e( 'When processing form is successful', 'MailPress' ); ?></small></label>
 259                                      <input type="text" name="settings[message][ok]" id="f_message_ok" size="40" class="w98" value="<?php if ( isset( $form->settings['message']['ok'] ) ) echo esc_attr( $form->settings['message']['ok'] ); ?>" />
 260                                      <label for="f_message_ko"><small><?php _e( 'When processing form has failed', 'MailPress' ); ?></small></label>
 261                                      <input type="text" name="settings[message][ko]" id="f_message_ko" size="40" class="w98" value="<?php if ( isset( $form->settings['message']['ko'] ) ) echo esc_attr( $form->settings['message']['ko'] ); ?>" />
 262  <?php
 263              break;
 264  
 265              case 'recipient'    : 
 266  ?>
 267                                      <div id="div_form_toemail">
 268                                          <label for="form_toemail"><small><?php _e( 'Email', 'MailPress' ); ?></small></label>
 269                                          <input type="text" name="settings[recipient][toemail]" id="form_toemail" size="40" class="wa form-required" aria-required="true" value="<?php if ( isset( $form->settings['recipient']['toemail'] ) ) echo $form->settings['recipient']['toemail']; ?>" />
 270                                      </div>
 271                                      <label for="form_toname"><small><?php _e( 'Name', 'MailPress' ); ?></small></label>
 272                                      <input type="text" id="form_toname" name="settings[recipient][toname]" size="40" class="wa" value="<?php if ( isset( $form->settings['recipient']['toname'] ) ) echo esc_attr( $form->settings['recipient']['toname'] ); ?>" />
 273                                      <label for="recipient_theme"><small><?php _e( 'Mail Theme/Template', 'MailPress' ); ?></small></label>
 274                                      <select name="settings[recipient][theme]" id="recipient_theme">
 275  <?php MP_AdminPage::select_option( $xtheme, $form->settings['recipient']['theme'] ); ?>
 276                                      </select>
 277  <?php 
 278  foreach ( $xtemplates as $key => $xtemplate )
 279  {
 280  $xx = '0';
 281  if ( isset( $form->settings['recipient']['template'] ) && $key == $form->settings['recipient']['theme'] ) $xx = $form->settings['recipient']['template'];
 282  ?>
 283                                      <select name="settings[recipient][th][<?php echo $key; ?>][tm]" id="recipient_<?php echo $key; ?>" class="<?php if ( $key != $form->settings['recipient']['theme'] ) echo 'mask ';?>recipient_template">
 284  <?php MP_AdminPage::select_option( $xtemplate, $xx );?>
 285                                      </select>
 286  <?php
 287  }
 288              break;
 289              case 'visitor'    : 
 290  ?>
 291                                      <label for="visitor_subscription"><small><?php _e( 'Subscription option', 'MailPress' ); ?></small></label>
 292                                      <select name="settings[visitor][subscription]" id="visitor_subscription">
 293  <?php MP_AdminPage::select_option( $xvisitor_subscriptions, ( isset( $form->settings['visitor']['subscription'] ) ) ? $form->settings['visitor']['subscription'] : 0 ); ?>
 294                                      </select>
 295                                      <small><?php _e( 'Becomes a subscriber', 'MailPress' ); ?></small>
 296                                      <div class="<?php echo ( isset( $form->settings['visitor']['subscription'] ) && ( $form->settings['visitor']['subscription'] != '0' ) ) ? '' : 'mask '; ?>visitor_subscription_selected nopmb">
 297  <?php do_action( 'MailPress_form_visitor_subscription', $form ); ?>
 298                                      </div>
 299                                      <label for="visitor_mail"><small><?php _e( 'Mail option', 'MailPress' ); ?></small></label>
 300                                      <select name="settings[visitor][mail]" id="visitor_mail">
 301  <?php MP_AdminPage::select_option( $xvisitor_mail, ( isset( $form->settings['visitor']['mail'] ) ) ? $form->settings['visitor']['mail'] : 0 ); ?>
 302                                      </select>
 303                                      <small><?php _e( 'Receives a copy', 'MailPress' ); ?></small>
 304                                      <div class="<?php echo ( isset( $form->settings['visitor']['mail'] ) && ( $form->settings['visitor']['mail'] != '0' ) ) ? '' : 'mask '; ?>visitor_mail_selected nopmb">
 305                                          <label for="visitor_theme"><small><?php _e( 'Mail Theme/Template', 'MailPress' ); ?></small></label>
 306                                          <select name="settings[visitor][theme]" id="visitor_theme">
 307  <?php MP_AdminPage::select_option( $xtheme, $form->settings['visitor']['theme'] ); ?>
 308                                          </select>
 309  <?php 
 310  foreach ( $xtemplates as $key => $xtemplate )
 311  {
 312  $xx = '0';
 313  if ( isset( $form->settings['visitor']['template'] ) && $key == $form->settings['visitor']['theme'] ) $xx = $form->settings['visitor']['template'];
 314  ?>
 315                                          <select name="settings[visitor][th][<?php echo $key; ?>][tm]" id="visitor_<?php echo $key; ?>" class="<?php if ( $key != $form->settings['visitor']['theme'] ) echo 'mask ';?>visitor_template">
 316  <?php MP_AdminPage::select_option( $xtemplate, $xx );?>
 317                                          </select>
 318  <?php
 319  }
 320  ?>
 321                                      </div>
 322  <?php
 323              break;
 324              case 'html'       : 
 325                  $html = $form_templates->get_form_template( $form->template );
 326                  if ( !$html ) $html = '{{form}}';
 327  
 328                  $search = $replace = array();
 329                  $search[] = '{{label}}';     $replace[] = $form->label;
 330                  $search[] = '{{description}}';     $replace[] = $form->description;
 331                  $search[] = '{{form}}';     $replace[] = sprintf( '%1$s<!-- %2$s --></form>', MP_Form::get_tag( $form ), __( 'form content', 'MailPress' ) );
 332                  $search[] = '{{message}}';     $replace[] = sprintf ( '<!-- %1$s -->', __( 'ok/ko message', 'MailPress' ) );
 333                  $html = str_replace( $search, $replace, $html );
 334  ?>
 335                                      <div class="filter-img bkgndc bd1sc html">
 336                                          <?php echo htmlspecialchars( $html, ENT_QUOTES ); ?>
 337                                      </div>
 338                                      <p><small><?php printf( __( 'Template : %1$s', 'MailPress' ), $form->template ); ?></small></p>
 339  <?php
 340              break;
 341          }
 342          echo "                                </div>\n";
 343      }
 344  ?>                                    
 345                              </div>
 346                          </div>
 347                          <p class="m15-0">
 348                              <input type="submit" name="submit" id="form_submit" class="button<?php echo $hbclass; ?>" value="<?php echo $hb3; ?>" />
 349                              <?php echo $cancel; ?>
 350                          </p>
 351                      </form>
 352                  </div>
 353              </div>
 354          </div><!-- /col-left -->
 355      </div><!-- /col-container -->
 356  </div><!-- /wrap -->


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