[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_adminpage_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          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', 'form_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_field::delete($id, $url_parms['form_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_fields, $url_parms) );
  36              break;
  37  
  38              case 'add':
  39                  $e = MP_Form_field::insert($_POST);
  40                  $url_parms['message'] = ( $e  ) ? 1 : 91;
  41                  unset($url_parms['s']);
  42                  self::mp_redirect( self::url(MailPress_fields, $url_parms) );
  43              break;
  44              case 'duplicate' :
  45                  MP_Form_field::duplicate($url_parms['id'], $url_parms['form_id']);
  46                  self::mp_redirect( self::url(MailPress_fields, $url_parms) );
  47              break;
  48              case 'edited':
  49                  unset($_GET['action']);
  50                  if (!isset($_POST['cancel'])) 
  51                  {
  52                      $e = MP_Form_field::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_fields, $url_parms) );
  59              break;
  60              case 'delete':
  61                  MP_Form_field::delete($url_parms['id'], $url_parms['form_id']);
  62                  unset($url_parms['id']);
  63  
  64                  $url_parms['message'] = 3;
  65                  self::mp_redirect( self::url(MailPress_fields, $url_parms) );
  66              break;
  67          }
  68      }
  69  
  70  ////  Title  ////
  71  
  72  	public static function title() 
  73      { 
  74          new MP_Form_field_types();
  75          if (isset($_GET['form_id'])) { global $title; $title = __('MailPress Forms Edit Fields', MP_TXTDOM); } 
  76      }
  77  
  78  ////  Styles  ////
  79  
  80  	public static function print_styles($styles = array()) 
  81      {
  82  // for specific css
  83          $pathcss        = MP_ABSPATH . 'mp-includes/class/options/form/field_types_' . get_user_option('admin_color') . '.css';
  84          $css_url        = '/' . MP_PATH . 'mp-includes/class/options/form/field_types_' . get_user_option('admin_color') . '.css';
  85          $css_url_default     = '/' . MP_PATH . 'mp-includes/class/options/form/field_types_fresh.css';
  86          $css_url        = (is_file($pathcss)) ? $css_url : $css_url_default;
  87          wp_register_style ( 'mp_field_types',     $css_url);
  88  
  89          wp_register_style ( self::screen,        '/' . MP_PATH . 'mp-admin/css/form_fields.css', array('mp_field_types', 'thickbox') );
  90          $styles[] = self::screen;
  91          parent::print_styles($styles);
  92      }
  93  
  94  //// Scripts ////
  95  
  96  	public static function print_scripts($scripts = array())  
  97      {
  98          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array('jquery', 'jquery-ui-tabs'), false, 1);
  99          wp_localize_script( 'mp-ajax-response',     'wpAjax', array(
 100              'noPerm' => __('An unidentified error has occurred.'), 
 101              'broken' => __('An unidentified error has occurred.'), 
 102              'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};' 
 103          ));
 104  
 105          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array('mp-ajax-response'), false, 1);
 106          wp_localize_script( 'mp-lists',         'wpListL10n', array( 
 107              'url' => MP_Action_url
 108          ));
 109  
 110          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array('thickbox'), false, 1);
 111  
 112          wp_register_script( 'mp-taxonomy',         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array('mp-lists'), false, 1);
 113          wp_localize_script( 'mp-taxonomy',         'MP_AdminPageL10n', array(    
 114              'pending' => __('%i% pending'), 
 115              'screen' => self::screen,
 116              'list_id' => self::list_id,
 117              'add_form_id' => self::add_form_id,
 118              'tr_prefix_id' => self::tr_prefix_id,
 119              'l10n_print_after' => 'try{convertEntities(MP_AdminPageL10n);}catch(e){};' 
 120          ));
 121  
 122          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/form_fields.js', array('mp-taxonomy', 'mp-thickbox'), false, 1);
 123  
 124          $scripts[] = self::screen;
 125          parent::print_scripts($scripts);
 126      }
 127  
 128  //// Columns ////
 129  
 130  	public static function get_columns() 
 131      {
 132          if (isset($_GET['form_id'])) 
 133          {
 134              $form = MP_Form::get($_GET['form_id']);
 135              if (isset($form->settings['visitor']['mail']) && ($form->settings['visitor']['mail'] != '0'))
 136                  add_filter('MailPress_form_columns_form_fields', array(__CLASS__, 'add_incopy_column'), 1, 1);
 137          }
 138  
 139          $columns = array(    'cb'        => '<input type="checkbox" />',
 140                      'name'     => __('Label', MP_TXTDOM),
 141                      'type'     => __('Type', MP_TXTDOM),
 142                      'order'     => __('Order', MP_TXTDOM),
 143                      'required'     => __('Required', MP_TXTDOM),
 144                      'template'     => __('Template', MP_TXTDOM) 
 145                  );
 146          return apply_filters('MailPress_form_columns_form_fields', $columns);
 147      }
 148  
 149  	public static function add_incopy_column($columns)
 150      {
 151          $template             = array_pop($columns);
 152          $columns['incopy']    = __('In&#160;copy', MP_TXTDOM);
 153              $columns['template']     = $template;
 154          return $columns;
 155      }
 156  
 157  //// List ////
 158  
 159  	public static function get_list($args)
 160      {
 161          extract($args);
 162  
 163          global $wpdb;
 164  
 165          $order = "a.ordre";
 166  
 167          $where = ' AND (a.form_id = ' . $_GET['form_id'] . ') ';
 168  
 169          if (isset($url_parms['s']))
 170          {
 171              $sc = array('a.label', 'a.description' );
 172  
 173              $where .= self::get_search_clause($url_parms['s'], $sc);
 174          }
 175  
 176          $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";
 177          $args['cache_name'] = 'mp_field';
 178  
 179          return parent::get_list($args);
 180      }
 181  
 182  ////  Row  ////
 183  
 184  	public static function get_row( $id, $url_parms, $checkbox = true ) 
 185      {
 186          static $row_class = '';
 187  
 188          $field = MP_Form_field::get( $id );
 189  
 190          $field_types = MP_Form_field_types::get_all();
 191  
 192  // url's
 193          $url_parms['action']     = 'edit';
 194          $url_parms['id']         = $field->id;
 195          $url_parms['form_id']     = $field->form_id;
 196  
 197          $edit_url = esc_url(self::url( MailPress_fields, $url_parms ));
 198          $url_parms['action']     = 'duplicate';
 199          $duplicate_url = esc_url(self::url( MailPress_fields, $url_parms, 'duplicate-field_' . $field->id ));
 200          $url_parms['action']     = 'delete';
 201          $delete_url = esc_url(self::url( MailPress_fields, $url_parms, 'delete-form_' . $field->id ));
 202  // actions
 203          $actions = array();
 204          $actions['edit'] = '<a href="' . $edit_url . '">' . __('Edit') . '</a>';
 205          $actions['duplicate'] = "<a class='dim:" . self::list_id . ":" . self::tr_prefix_id . "-" . $field->id . ":unapproved:e7e7d3:e7e7d3' href='$duplicate_url'>" . __('Duplicate', MP_TXTDOM) . "</a>";
 206          $actions['delete'] = "<a class='submitdelete' href='$delete_url'>" . __('Delete') . "</a>";
 207  
 208          $row_class = 'alternate' == $row_class ? '' : 'alternate';
 209  
 210  // protected
 211          $disabled = '';
 212          if (isset($field->settings['options']['protected']))
 213          {
 214              unset($actions['duplicate'], $actions['delete']);
 215              $disabled = " disabled='disabled'";
 216          }
 217  
 218          $out = '';
 219          $out .= "<tr id='" . self::tr_prefix_id . "-$field->id' class='iedit $row_class'>";
 220  
 221          $columns = self::get_columns();
 222          $hidden  = self::get_hidden_columns();
 223          foreach ( $columns as $column_name => $column_display_name ) 
 224          {
 225              $class = "class='$column_name column-$column_name'";
 226  
 227              $style = '';
 228              if ( in_array($column_name, $hidden) )
 229                  $style = ' style="display:none;"';
 230  
 231              $attributes = "$class$style";
 232  
 233              switch ($column_name) 
 234              {
 235                  case 'cb':
 236                      $out .= (!$disabled) ? '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $field->id . '" /></th>' : '<th class="check-column"></th>';
 237                  break;
 238                  case 'name':
 239                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr(sprintf(__('Edit "%s"'), $field->label)) . '">' . $field->label . '</a></strong><br />';
 240                      $out .= self::get_actions($actions);
 241                      $out .= '</td>';
 242                  break;
 243                  case 'type':
 244                       $out .= "<td $attributes>";
 245                      $out .= "<div class='field_type_" . $field->type . "'  style='padding-left:28px;'>" . $field_types[$field->type]['desc'] . "</div>";
 246                       $out .= "</td>\n";
 247                   break;
 248                  case 'incopy':
 249                       $out .= "<td $attributes>";
 250                      if (isset($field->settings['options']['incopy'])) $out .= __('yes', MP_TXTDOM);
 251                       $out .= "</td>\n";
 252                   break;
 253                  case 'required':
 254                       $out .= "<td $attributes>";
 255                      if (isset($field->settings['controls']['required'])) $out .= __('yes', MP_TXTDOM);
 256                       $out .= "</td>\n";
 257                   break;
 258                  case 'order':
 259                       $out .= "<td $attributes>";
 260                      $out .= $field->ordre;
 261                       $out .= "</td>\n";
 262                   break;
 263                  default:
 264                      $out .= '<td ' . $attributes . '>';
 265                      $out .= $field->{$column_name};
 266                      $out .= '</td>';
 267                  break;
 268              }
 269          }
 270          $out .= "</tr>\n";
 271  
 272          return $out;
 273      }
 274  }


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