Example #1
0
        	<input type="password" name="psw" value="" maxlength="100" autocomplete="off" />
        </td>
        
        <td class="pc_label_td" rowspan="2" style="border-left: 1px solid #DFDFDF;"><?php 
_e("Categories", 'pc_ml');
?>
 <span class="pc_req_field">*</span></td>
        <td class="pc_field_td" rowspan="2">
        	<?php 
$user_categories = get_terms('pg_user_categories', 'orderby=name&hide_empty=0');
if (count($user_categories) == 0) {
    echo '<li><a href="edit-tags.php?taxonomy=pg_user_categories" style="color: red;">' . __('Create at least an user category', 'pc_ml') . '</a></li>';
} else {
    echo '
				<select name="categories[]" multiple="multiple" class="lcweb-chosen pc_menu_select" data-placeholder="' . __('Select categories', 'pc_ml') . ' .." autocomplete="off">';
    foreach (pc_user_cats() as $cat_id => $cat_name) {
        $selected = $print_val && is_array($fdata['categories']) && in_array($cat_id, $fdata['categories']) ? 'selected="selected"' : '';
        echo '<option value="' . $cat_id . '" ' . $selected . '>' . $cat_name . '</option>';
    }
    echo '</select>';
}
?>
        </td>
      </tr>
      <tr>
      	<td class="pc_label_td"><?php 
_e("Repeat password", 'pc_ml');
?>
 <?php 
if (!$upd) {
    ?>
function pc_widget_restriction_fields($t, $return, $instance)
{
    include_once PC_DIR . '/functions.php';
    $field_id = $t->get_field_id('pc_allow');
    $pc_cats = pc_user_cats();
    $instance = wp_parse_args((array) $instance, array('title' => '', 'text' => '', 'pc_allow' => array()));
    if (!isset($instance['pc_allow']) || !is_array($instance['pc_allow'])) {
        $instance['pc_allow'] = array();
    }
    //if(!isset($instance['pc_block'])) {$instance['pc_block'] = array();}
    ?>
    <p class="pc_widget_control_wrap">
        <label  for="<?php 
    echo $field_id;
    ?>
"><?php 
    _e('Which PrivateContent user categories can see the page?', 'pc_ml');
    ?>
:</label>
        <select id="<?php 
    echo $field_id;
    ?>
" name="pc_allow[]" multiple="multiple"  class="lcweb-chosen" data-placeholder="<?php 
    _e('select a category', 'pc_ml');
    ?>
 .." autocomplete="off" style="width: 388px;">
        	<option value="all" <?php 
    if (in_array('all', $instance['pc_allow'])) {
        echo 'selected="selected"';
    }
    ?>
><?php 
    _e('Any logged user', 'pc_ml');
    ?>
</option>
			<option value="unlogged" <?php 
    if (in_array('unlogged', $instance['pc_allow'])) {
        echo 'selected="selected"';
    }
    ?>
><?php 
    _e('Unlogged Users', 'pc_ml');
    ?>
</option>
			<?php 
    foreach ($pc_cats as $cat_id => $name) {
        $sel = in_array($cat_id, $instance['pc_allow']) ? 'selected="selected"' : '';
        echo '<option value="' . $cat_id . '" ' . $sel . '>' . $name . '</option>';
    }
    ?>
        </select>
    </p>
    
    <script type="text/javascript">
    jQuery(document).ready(function(e) {
		// set dropdown width
		jQuery('.pc_widget_control_wrap select').css('width', (jQuery('.sidebars-column-1').width() - 48));
		
		pc_live_chosen();
	}); 
	</script>
    
	<?php 
    $retrun = null;
    return array($t, $return, $instance);
}
 public function validate_form($indexes, $custom_errors = array(), $user_id = false, $specific_checks = true)
 {
     include_once 'simple_form_validator.php';
     global $wpdb;
     $validator = new simple_fv();
     $validator->formHandle((array) $indexes);
     $fdata = $validator->form_val;
     // clean data and save options
     foreach ($fdata as $key => $val) {
         if (is_string($val)) {
             $fdata[$key] = stripslashes($val);
         } elseif (is_array($val)) {
             $fdata[$key] = array();
             foreach ($val as $arr_val) {
                 $fdata[$key][] = stripslashes($arr_val);
             }
         }
     }
     /*** special validation cases ***/
     foreach ($indexes as $field) {
         // password strength
         if ($field['index'] == 'psw') {
             $psw_strength = $this->check_psw_strength($fdata['psw']);
             if ($psw_strength !== true) {
                 $validator->custom_error[__("Password strength", 'pc_ml')] = $psw_strength;
             }
         }
         // username unicity
         if ($specific_checks && $field['index'] == 'username') {
             $already_exists = $user_id ? ' AND id != ' . (int) $user_id : '';
             $wpdb->query($wpdb->prepare("SELECT id FROM " . PC_USERS_TABLE . " WHERE username = %s AND status != 0 " . $already_exists . " LIMIT 1", trim((string) $fdata['username'])));
             if ($wpdb->num_rows) {
                 $validator->custom_error[__("Username", 'pc_ml')] = __("Another user already has this username", 'pc_ml');
             }
         }
         // categories
         if ($specific_checks && $field['index'] == 'categories' && !empty($fdata['categories'])) {
             $cats = !isset($GLOBALS['pc_escape_no_reg_cats']) ? pc_user_cats(false) : pc_user_cats(true);
             foreach ((array) $fdata['categories'] as $f_cat) {
                 if (!isset($cats[$f_cat])) {
                     $name = $this->fields['categories']['label'];
                     $validator->custom_error[$name] = __("One or more chosen categories are wrong", 'pc_ml');
                     break;
                 }
             }
         }
     }
     // wrap up
     $this->form_data = $fdata;
     $errors = $validator->getErrors();
     if (!empty($custom_errors)) {
         if (!empty($errors)) {
             $errors .= '<br/>';
         }
         $errors .= implode('<br/>', $custom_errors);
     }
     // PC-FILTER - add custom errors on form validation - passes errors string and form data
     $this->errors = apply_filters('pc_form_valid_errors', $errors, $fdata);
     return empty($this->errors) ? true : false;
 }
Example #4
0
<?php

include_once PC_DIR . '/classes/paginator.php';
include_once PC_DIR . '/functions.php';
global $pc_users, $pc_wp_user;
// base page URL
$base_page_url = admin_url() . 'admin.php?page=pc_user_manage';
// first/last name flag
$fist_last_name = get_option('pg_use_first_last_name');
// user categories
$user_categories = pc_user_cats();
// WP user sync check
$wp_user_sync = $pc_users->wp_user_sync;
// minimum level to manage users
$au_cap = get_option('pg_min_role_tmu', get_option('pg_min_role', 'upload_files'));
$cuc = current_user_can($au_cap);
// micro helper function to know if GET field exists
function pc_get_param_exists($param_name)
{
    return isset($_GET[$param_name]) && !empty($_GET[$param_name]) ? true : false;
}
// table columns
$table_cols = array('id' => array('name' => 'ID', 'sortable' => true, 'width' => '45px'), 'username' => array('name' => __('Username', 'pc_ml'), 'sortable' => true), 'name' => array('name' => $fist_last_name ? __('First name', 'pc_ml') : __('Name', 'pc_ml'), 'sortable' => true), 'surname' => array('name' => $fist_last_name ? __('Last name', 'pc_ml') : __('Surname', 'pc_ml'), 'sortable' => true), 'email' => array('name' => __('E-mail', 'pc_ml'), 'sortable' => true), 'tel' => array('name' => __('Telephone', 'pc_ml'), 'sortable' => true, 'width' => '120px'), 'categories' => array('name' => __('Categories', 'pc_ml'), 'sortable' => false), 'insert_date' => array('name' => __('Registered on', 'pc_ml'), 'sortable' => true, 'width' => '152px'), 'last_access' => array('name' => __('Last access', 'pc_ml'), 'sortable' => false, 'width' => '110px'));
// PC-FILTER - additional fields for users list - must comply with initial structure
$table_cols = apply_filters('pc_users_list_table_fiels', $table_cols);
// QUERY SETUP AND PAGINATOR
$p = new pc_paginator();
// USER MANAGEMENT ACTIONS (REMOVE - DISABLE - ENABLE)
if (pc_get_param_exists('ucat_action') && pc_get_param_exists('pc_users') && $cuc) {
    if (!isset($_GET['pc_nonce']) || !wp_verify_nonce($_GET['pc_nonce'], __FILE__)) {
        die('<p>Cheating?</p>');