[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_adminpage_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          if     ( !empty($_REQUEST['action'])  && ($_REQUEST['action']  != -1))    $action = $_REQUEST['action'];
  18          elseif ( !empty($_REQUEST['action2']) && ($_REQUEST['action2'] != -1) )    $action = $_REQUEST['action2'];
  19          if (!isset($action)) return;
  20  
  21          $url_parms = self::get_url_parms(array('s', 'paged', 'id'));
  22          $checked    = (isset($_GET['checked'])) ? $_GET['checked'] : array();
  23  
  24          $count    = str_replace('bulk-', '', $action);
  25          $count     .= 'd';
  26          $$count    = 0;
  27  
  28          switch($action) 
  29          {
  30              case 'bulk-delete' :
  31                  foreach($checked as $id) if (MP_Form::delete($id)) $$count++;
  32  
  33                  if ($$count) $url_parms[$count] = $$count;
  34                  $url_parms['message'] = ($$count <= 1) ? 3 : 4;
  35                  self::mp_redirect( self::url(MailPress_forms, $url_parms) );
  36              break;
  37  
  38              case 'add':
  39                  $e = MP_Form::insert($_POST);
  40                  $url_parms['message'] = ( $e ) ? 1 : 91;
  41                  unset($url_parms['s']);
  42                  self::mp_redirect( self::url(MailPress_forms, $url_parms) );
  43              break;
  44              case 'duplicate' :
  45                  MP_Form::duplicate($url_parms['id']);
  46                  self::mp_redirect( self::url(MailPress_forms, $url_parms) );
  47              break;
  48              case 'edited':
  49                  unset($_GET['action']);
  50                  if (!isset($_POST['cancel'])) 
  51                  {
  52                      $e = MP_Form::insert($_POST);
  53                      $url_parms['message'] = ( $e ) ? 2 : 92 ;
  54                      $url_parms['action']  = 'edit';
  55                  }
  56                  else unset($url_parms['id']);
  57  
  58                  self::mp_redirect( self::url(MailPress_forms, $url_parms) );
  59              break;
  60  
  61              case 'delete':
  62                  MP_Form::delete($url_parms['id']);
  63                  unset($url_parms['id']);
  64  
  65                  $url_parms['message'] = 3;
  66                  self::mp_redirect( self::url(MailPress_forms, $url_parms) );
  67              break;
  68          }
  69      }
  70  
  71  ////  Title  ////
  72  
  73  	public static function title() 
  74      { 
  75          new MP_Form_field_types();
  76          if (isset($_GET['id'])) { global $title; $title = __('Edit Form', MP_TXTDOM); } 
  77      }
  78  
  79  ////  Styles  ////
  80  
  81  	public static function print_styles($styles = array()) 
  82      {
  83          wp_register_style ( MailPress_page_forms,    '/' . MP_PATH . 'mp-admin/css/forms.css', array('thickbox') );
  84          $styles[] = MailPress_page_forms;
  85          parent::print_styles($styles);
  86      }
  87  
  88  //// Scripts ////
  89  
  90  	public static function print_scripts($scripts = array())  
  91      {
  92          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array('jquery', 'jquery-ui-tabs'), false, 1);
  93          wp_localize_script( 'mp-ajax-response',     'wpAjax', array(
  94              'noPerm' => __('An unidentified error has occurred.'), 
  95              'broken' => __('An unidentified error has occurred.'), 
  96              'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};' 
  97          ));
  98  
  99          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array('mp-ajax-response'), false, 1);
 100          wp_localize_script( 'mp-lists',         'wpListL10n', array( 
 101              'url' => MP_Action_url
 102          ));
 103  
 104          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array('thickbox'), false, 1);
 105  
 106          wp_register_script( 'mp-taxonomy',         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array('mp-lists'), false, 1);
 107          wp_localize_script( 'mp-taxonomy',         'MP_AdminPageL10n', array(
 108              'pending' => __('%i% pending'), 
 109              'screen' => self::screen,
 110              'list_id' => self::list_id,
 111              'add_form_id' => self::add_form_id,
 112              'tr_prefix_id' => self::tr_prefix_id,
 113              'l10n_print_after' => 'try{convertEntities(MP_AdminPageL10n);}catch(e){};' 
 114          ));
 115  
 116          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/forms.js', array('mp-taxonomy', 'mp-thickbox'), false, 1);
 117  
 118          $scripts[] = self::screen;
 119          parent::print_scripts($scripts);
 120      }
 121  
 122  //// Columns ////
 123  
 124  	public static function get_columns() 
 125      {
 126          $columns = array(    'cb'            => '<input type="checkbox" />',
 127                      'name'        => __('Label', MP_TXTDOM),
 128                      'template'        => __('Template', MP_TXTDOM),
 129                      'recipient'        => __('Recipient', MP_TXTDOM),
 130                      'confirm'         => __('Copy', MP_TXTDOM));
 131          return $columns;
 132      }
 133  
 134  //// List ////
 135  
 136  	public static function get_list($args)
 137      {
 138          extract($args);
 139  
 140          global $wpdb;
 141  
 142          $where = '';
 143  
 144          if (isset($url_parms['s']))
 145          {
 146              $sc = array('a.label', 'a.description' );
 147  
 148              $where .= self::get_search_clause($url_parms['s'], $sc);
 149          }
 150  
 151          $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 ";
 152          $args['cache_name'] = 'mp_form';
 153  
 154          return parent::get_list($args);
 155      }
 156  
 157  ////  Row  ////
 158  
 159  	public static function get_row( $form, $url_parms ) 
 160      {
 161          static $row_class = '';
 162  
 163          $form = MP_Form::get( $form );
 164  
 165  // url's
 166          $url_parms['action']     = 'edit';
 167  
 168          $url_parms['id']     = $form->id;
 169  
 170          $edit_url = esc_url(self::url( MailPress_forms, $url_parms ));
 171          $url_parms['action']     = 'duplicate';
 172          $duplicate_url = esc_url(self::url( MailPress_forms, $url_parms, 'duplicate-form_' . $form->id ));
 173  
 174          $url_parms['action']     = 'edit_fields';
 175          $url_parms['form_id'] = $url_parms['id']; unset($url_parms['id']); 
 176          $edit_fields_url = esc_url(self::url( MailPress_fields, $url_parms ));
 177          $url_parms['id'] = $url_parms['form_id']; unset($url_parms['form_id']); 
 178  
 179          $edit_templates_url = esc_url(self::url( MailPress_templates, array('action' => 'edit', 'template' => $form->template)));
 180  
 181          $args = array();
 182          $args['id']     = $form->id;
 183          $args['action']     = 'ifview';
 184          $args['preview_iframe'] = 1; $args['TB_iframe']= 'true';
 185          $view_url        = esc_url(self::url(MP_Action_url, $args));
 186  
 187          $url_parms['action']     = 'delete';
 188          $delete_url = esc_url(self::url( MailPress_forms, $url_parms, 'delete-form_' . $form->id ));
 189  
 190  // actions
 191          $actions = array();
 192          $actions['edit'] = '<a href="' . $edit_url . '">' . __('Edit') . '</a>';
 193          $actions['edit_templates'] = '<a href="' . $edit_templates_url . '">' . __('Templates', MP_TXTDOM) . '</a>';
 194          $actions['edit_fields'] = '<a href="' . $edit_fields_url . '">' . __('Fields', MP_TXTDOM) . '</a>';
 195          $actions['duplicate'] = "<a class='dim:" . self::list_id . ":" . self::tr_prefix_id . "-" . $form->id . ":unapproved:e7e7d3:e7e7d3' href='$duplicate_url'>" . __('Duplicate', MP_TXTDOM) . "</a>";
 196          $actions['delete'] = "<a class='submitdelete' href='$delete_url'>" . __('Delete') . "</a>";
 197          $actions['view'] = "<a class='thickbox thickbox-preview' href='$view_url' title=\"" . esc_attr(sprintf(__('Form preview #%1$s (%2$s)', MP_TXTDOM), $form->id, $form->label)) . "\" >" . __('Preview', MP_TXTDOM) . "</a>";
 198  
 199          $row_class = ('alternate' == substr($row_class, 0, 9)) ? '' : 'alternate '; $row_class .= 'iedit';
 200  
 201          $out = '';
 202          $out .= "<tr id='" . self::tr_prefix_id . "-$form->id' class='$row_class'>";
 203  
 204          $columns = self::get_columns();
 205          $hidden  = self::get_hidden_columns();
 206  
 207          foreach ( $columns as $column_name => $column_display_name ) 
 208          {
 209              $class = "class='$column_name column-$column_name'";
 210  
 211              $style = '';
 212              if ( in_array($column_name, $hidden) )
 213                  $style = ' style="display:none;"';
 214  
 215              $attributes = "$class$style";
 216              switch ($column_name) 
 217              {
 218                  case 'cb':
 219                      $out .= '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $form->id . '" /></th>';
 220                  break;
 221                  case 'name':
 222                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr(sprintf(__('Edit "%s"'), $form->label)) . '">' . $form->label . '</a></strong><br />';
 223                      $out .= self::get_actions($actions);
 224                      $out .= '</td>';
 225                  break;
 226                   case 'template':
 227                       $out .= "<td $attributes>" . $form->template . "</td>\n";
 228                   break;
 229                   case 'Theme':
 230                       $out .= "<td $attributes>" . $form->settings['recipient']['theme'];
 231                      if (!empty($form->settings['recipient']['template'])) $out .= '<br />(' . $form->settings['recipient']['template'] . ')'; 
 232                      $out .= "</td>\n";
 233                   break;
 234                   case 'recipient':
 235                       $out .= "<td $attributes>" . $form->settings['recipient']['toemail'];
 236                      if (!empty($form->settings['recipient']['toname'])) $out .= '<br />(' . $form->settings['recipient']['toname'] . ')'; 
 237                      $out .= "</td>\n";
 238                   break;
 239                  case 'confirm':
 240                       $out .= "<td $attributes>";
 241                      $mail = (isset($form->settings['visitor']['mail'])) ? $form->settings['visitor']['mail'] : 0;
 242                      switch ($mail)
 243                      {
 244                          case 1 :
 245                              $out .= __('t.b.c.', MP_TXTDOM);
 246                          break;
 247                          case 2 :
 248                              $out .= __('yes', MP_TXTDOM);
 249                          break;
 250                          default :
 251                              $out .= __('no', MP_TXTDOM);
 252                          break;
 253                      }
 254                       $out .= "</td>\n";
 255                   break;
 256              }
 257          }
 258          $out .= "</tr>\n";
 259  
 260          return $out;
 261      }
 262  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1