/** * Affiche la page des groupes */ public static function display_page() { self::manage_post(); ob_start(); wpshop_display::displayPageHeader(__('Groups', 'wpshop'), '', __('Groups', 'wpshop'), __('Groups', 'wpshop'), true, 'admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '&action=add', ''); $content = ob_get_contents(); ob_end_clean(); $wps_customer_mdl = new wps_customer_mdl(); // Si on re�oit une action if (!empty($_GET['action'])) { $readonly_name_field = ''; switch ($_GET['action']) { case 'delete': if (!empty($_GET['code'])) { $roles = get_option('wp_user_roles', array()); if (isset($roles[$_GET['code']]) && $_GET['code'] != 'customer' && $_GET['code'] != 'wpshop_customer') { unset($roles[$_GET['code']]); $this->unaffectUsersToGroup($_GET['code']); update_option('wp_user_roles', $roles); } } wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); break; case 'edit': $readonly_name_field = 'readonly'; if (!empty($_GET['code'])) { $role = $this->getRole($_GET['code']); if (!empty($role)) { $group_name = $role['name']; $group_description = $role['description']; $group_parent = $role['parent']; $submit_button_value = __('Edit the group', 'wpshop'); $submit_button_name = 'editrole'; // ROLES $roles = get_option('wp_user_roles', array()); $select_parent = '<option value="">--</option>'; foreach ($roles as $code => $role) { if ($code != $_GET['code']) { $selected = $group_parent == $code ? 'selected' : ''; $select_parent .= '<option value="' . $code . '" ' . $selected . '>' . $role['name'] . '</option>'; } } // USERS $users = $wps_customer_mdl->getUserList(); if (!empty($users)) { $select_users = ''; foreach ($users as $user) { if ($user->ID != 1) { $u = new WP_User($user->ID); $selected = isset($u->roles[0]) && $u->roles[0] == $_GET['code'] ? 'selected' : ''; $select_users .= '<option value="' . $user->ID . '" ' . $selected . '>' . $user->user_login . '</option>'; } } } } else { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); exit; } } else { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); exit; } break; case 'add': $group_name = $group_description = ''; $submit_button_value = __('Create the group', 'wpshop'); $submit_button_name = 'addrole'; // ROLES $roles = get_option('wp_user_roles', array()); $select_parent = '<option value="">--</option>'; foreach ($roles as $code => $role) { $select_parent .= '<option value="' . $code . '">' . $role['name'] . '</option>'; } // USERS $users = $wps_customer_mdl->getUserList(); $select_users = ''; if (!empty($users)) { foreach ($users as $user) { if ($user->ID != 1) { $select_users .= '<option value="' . $user->ID . '">' . $user->user_login . '</option>'; } } } break; } $content .= ' <form method="post"> <label>' . __('Name', 'wpshop') . '</label><br /><input type="text" name="group-name" style="width:500px;" value="' . $group_name . '" ' . $readonly_name_field . ' /><br /><br /> <label>' . __('Parent', 'wpshop') . '</label><br /> <select name="group-parent" class="chosen_select" style="width:500px;"> ' . $select_parent . ' </select><br /><br /> <label>' . __('Users', 'wpshop') . '</label><br /> <select name="group-users[]" class="chosen_select" multiple style="width:500px;"> ' . $select_users . ' </select><br /><br /> <label>' . __('Description', 'wpshop') . '</label><br /><textarea name="group-description" style="width:500px;">' . $group_description . '</textarea><br /><br /> <input type="submit" class="button-primary" name="' . $submit_button_name . '" value="' . $submit_button_value . '" /> <a href="admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '">' . __('Cancel', 'wpshop') . '</a> </form> '; } else { $wpshop_list_table = new wpshop_groups_custom_List_table(); //Fetch, prepare, sort, and filter our data... $status = "'valid'"; if (!empty($_REQUEST['attribute_status'])) { switch ($_REQUEST['attribute_status']) { case 'unactive': $status = "'moderated', 'notused'"; if (empty($_REQUEST['orderby']) && empty($_REQUEST['order'])) { $_REQUEST['orderby'] = 'status'; $_REQUEST['order'] = 'asc'; } break; default: $status = "'" . $_REQUEST['attribute_status'] . "'"; break; } } $roles = get_option('wp_user_roles', array()); $i = 0; $attribute_set_list = array(); $group_not_to_display = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); $wpshop_groups_meta = get_option('wpshop_groups_meta', array()); foreach ($roles as $code => $role) { if (!in_array($code, $group_not_to_display)) { $description = !empty($wpshop_groups_meta[$code]['description']) ? $wpshop_groups_meta[$code]['description'] : '--'; $attribute_set_list[$i]['name'] = $role['name']; $attribute_set_list[$i]['description'] = $description; $attribute_set_list[$i]['code'] = $code; $i++; } } $wpshop_list_table->prepare_items($attribute_set_list); ob_start(); $wpshop_list_table->display(); $element_output = ob_get_contents(); ob_end_clean(); $content .= $element_output; } $content .= '</div>'; echo $content; }
/** * Return The complete output page code * * @return string The complete html page output */ public static function display_page() { $pageAddButton = false; $pageMessage = $addButtonLink = $pageFormButton = $pageIcon = $pageIconTitle = $pageIconAlt = $objectType = ''; $outputType = 'listing'; $objectToEdit = isset($_REQUEST['id']) ? wpshop_tools::varSanitizer($_REQUEST['id']) : ''; $pageSlug = isset($_REQUEST['page']) ? wpshop_tools::varSanitizer($_REQUEST['page']) : ''; $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : ''; /* Select the content to add to the page looking for the parameter */ switch ($pageSlug) { case WPSHOP_URL_SLUG_ATTRIBUTE_LISTING: $objectType = new wpshop_attributes(); $current_user_can_edit = current_user_can('wpshop_edit_attributes'); $current_user_can_add = current_user_can('wpshop_add_attributes'); $current_user_can_delete = current_user_can('wpshop_delete_attributes'); if (current_user_can('wpshop_add_attributes')) { $pageAddButton = true; } break; case WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING: $objectType = new wpshop_attributes_set(); $current_user_can_edit = current_user_can('wpshop_edit_attribute_set'); $current_user_can_add = current_user_can('wpshop_add_attribute_set'); $current_user_can_delete = current_user_can('wpshop_delete_attribute_set'); if (current_user_can('wpshop_add_attribute_set')) { $pageAddButton = true; } break; case WPSHOP_URL_SLUG_SHORTCODES: $pageAddButton = false; $current_user_can_edit = false; $objectType = new wps_shortcodes_ctr(); break; case WPSHOP_URL_SLUG_MESSAGES: $pageAddButton = false; $objectType = new wpshop_messages(); $current_user_can_edit = true; if (!empty($_GET['mid'])) { $action = 'edit'; } break; default: $pageTitle = sprintf(__('You have to add this page into %s at line %s', 'wpshop'), __FILE__, __LINE__ - 4); $pageAddButton = false; break; } if ($objectType != '') { if ($action != '' && ($action == 'edit' && $current_user_can_edit || $action == 'add' && $current_user_can_add || $action == 'delete' && $current_user_can_delete)) { $outputType = 'adding'; } $objectType->elementAction(); $pageIcon = self::getPageIconInformation('path', $objectType); $pageIconTitle = self::getPageIconInformation('title', $objectType); $pageIconAlt = self::getPageIconInformation('alt', $objectType); if ($outputType == 'listing') { $pageContent = $objectType->elementList(); } elseif ($outputType == 'adding') { $pageAddButton = false; $pageFormButton = $objectType->getPageFormButton($objectToEdit); $pageContent = $objectType->elementEdition($objectToEdit); } $pageTitle = $objectType->pageTitle(); $pageMessage = $objectType->pageMessage; if (in_array($objectType->getEditionSlug(), array(WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING))) { $addButtonLink = admin_url('admin.php?page=' . $objectType->getEditionSlug() . '&action=add'); } else { $addButtonLink = admin_url('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES . '&page=' . $objectType->getEditionSlug() . '&action=add'); } } /* Page content header */ wpshop_display::displayPageHeader($pageTitle, $pageIcon, $pageIconTitle, $pageIconAlt, $pageAddButton, $addButtonLink, $pageMessage, $pageSlug); /* Page content */ echo $pageContent; /* Page content footer */ wpshop_display::displayPageFooter($pageFormButton); }
<?php /** Tools main page */ ob_start(); echo wpshop_display::displayPageHeader(__('Outils pour WP-Shop', 'wpshop'), '', __('WPShop tools', 'wpshop'), __('WPShop tools', 'wpshop'), false, '', '', 'wpshop-tools'); ?> <div id="wpshop_configurations_container" class="wpshop_cls" > <div id="tools_tabs" class="wpshop_tabs wpshop_full_page_tabs wpshop_tools_tabs" > <ul> <li class="loading_pic_on_select" ><a href="<?php echo admin_url('admin-ajax.php'); ?> ?action=wpshop_tool_db_check" title="wpshop_tools_tab_container" ><?php _e('Database structure check', 'wpshop'); ?> </a></li> <li class="loading_pic_on_select" ><a href="<?php echo admin_url('admin-ajax.php'); ?> ?action=wpshop_tool_default_datas_check" title="wpshop_tools_tab_container" ><?php _e('Default data check', 'wpshop'); ?> </a></li> <li class="loading_pic_on_select" ><a href="<?php echo admin_url('admin-ajax.php'); ?> ?action=wps_mass_action" title="wpshop_tools_tab_container" class="wps_mass_action" ><?php _e('Mass action', 'wpshop'); ?> </a></li> <li class="loading_pic_on_select" ><a href="<?php