function handle_level_edit_form($level_id = false, $clone = false) { global $page, $M_Rules, $M_SectionRules; if ($level_id && !$clone) { $mlevel = new M_Level($level_id); $level = $mlevel->get(); } else { if ($clone) { $mlevel = new M_Level($level_id); $level = $mlevel->get(); $level->level_title .= __(' clone', 'membership'); } else { $level = new stdclass(); $level->level_title = __('new level', 'membership'); } $level->id = time() * -1; } // Get the relevant parts if (isset($mlevel)) { $positives = $mlevel->get_rules('positive'); $negatives = $mlevel->get_rules('negative'); } // Re-arrange the rules $rules = array(); $p = array(); $n = array(); if (!empty($positives)) { foreach ($positives as $positive) { $rules[$positive->rule_area] = maybe_unserialize($positive->rule_value); $p[$positive->rule_area] = maybe_unserialize($positive->rule_value); } } if (!empty($negatives)) { foreach ($negatives as $negative) { $rules[$negative->rule_area] = maybe_unserialize($negative->rule_value); $n[$negative->rule_area] = maybe_unserialize($negative->rule_value); } } // Check which tab we should open the edit form with if (!empty($p) && !empty($n)) { // We have content in both areas - so start with advanced open $advancedtab = 'activetab'; $negativetab = ''; $positivetab = ''; $advancedcontent = 'activecontent'; $negativecontent = 'activecontent'; $positivecontent = 'activecontent'; } else { if (!empty($n)) { // We have content in the negative area - so start with that $advancedtab = ''; $negativetab = 'activetab'; $positivetab = ''; $advancedcontent = 'inactivecontent'; $negativecontent = 'activecontent'; $positivecontent = 'inactivecontent'; } else { // Default to the positive area $advancedtab = ''; $negativetab = ''; $positivetab = 'activetab'; $advancedcontent = 'inactivecontent'; $negativecontent = 'inactivecontent'; $positivecontent = 'activecontent'; } } ?> <div class='wrap nosubsub'> <div class="icon32" id="icon-link-manager"><br></div> <h2><?php echo __('Edit ', 'membership') . " - " . esc_html($level->level_title); ?> </h2> <?php if (isset($usemsg)) { echo '<div id="message" class="updated fade"><p>' . $messages[$usemsg] . '</p></div>'; $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); } ?> <div class='level-liquid-left'> <div id='level-left'> <form action='?page=<?php echo $page; ?> ' name='leveledit' method='post'> <input type='hidden' name='level_id' id='level_id' value='<?php echo $level->id; ?> ' /> <input type='hidden' name='ontab' id='ontab' value='positive' /> <input type='hidden' name='beingdragged' id='beingdragged' value='' /> <input type='hidden' name='in-positive-rules' id='in-positive-rules' value=',<?php echo implode(',', array_keys($p)); ?> ' /> <input type='hidden' name='in-negative-rules' id='in-negative-rules' value=',<?php echo implode(',', array_keys($n)); ?> ' /> <input type='hidden' name='postive-rules-order' id='postive-rules-order' value='' /> <input type='hidden' name='negative-rules-order' id='negative-rules-order' value='' /> <div id='edit-level' class='level-holder-wrap'> <div class='sidebar-name no-movecursor'> <h3><?php echo esc_html($level->level_title); ?> </h3> </div> <div class='level-holder'> <div class='level-details'> <label for='level_title'><?php _e('Level title', 'membership'); ?> </label><?php //echo $this->_tips->add_tip( __('This is the title used throughout the system to identify this level.','membership') ); ?> <br/> <input class='wide' type='text' name='level_title' id='level_title' value='<?php echo esc_attr($level->level_title); ?> ' /> <br/><br/> <label for='level_shortcode'><?php _e('Level shortcode', 'membership'); ?> </label><?php echo $this->_tips->add_tip(__('The shortcode for this level is based on the title (above). It can be used to wrap content that you only want to be seen by members on this level e.g. [levelshortcode] protected content [/levelshortcode]', 'membership')); ?> <?php if ($level->id > 0) { echo "[" . M_normalize_shortcode($level->level_title) . "]"; } else { _e('Save your level to create the shortcode', 'membership'); } ?> </div> <?php do_action('membership_level_form_before_rules', $level->id); ?> <ul class='leveltabs'> <li class='positivetab <?php echo $positivetab; ?> '><div class='downarrow'></div><a href='#positive'><div><?php _e('Positive Rules', 'membership'); ?> </div></a></li> <li class='negativetab <?php echo $negativetab; ?> '><div class='downarrow'></div><a href='#negative'><div><?php _e('Negative Rules', 'membership'); ?> </div></a></li> <li class='advancedtab <?php echo $advancedtab; ?> '><div class='downarrow'></div><a href='#advanced'><div><?php _e('Advanced (both)', 'membership'); ?> </div></a></li> </ul> <div class='advancedtabwarning <?php echo $advancedcontent; ?> '> <?php _e('<strong>Warning:</strong> using both positive and negative rules on the same level can cause conflicts and unpredictable behaviour.', 'membership'); ?> </div> <div class='positivecontent <?php echo $positivecontent; ?> '> <h3 class='positive positivetitle <?php echo $advancedcontent; ?> '><?php _e('Positive rules', 'membership'); ?> </h3> <p class='description'><?php _e('These are the areas / elements that a member of this level can access.', 'membership'); ?> </p> <div id='positive-rules' class='level-droppable-rules levels-sortable'> <?php _e('Drop here', 'membership'); ?> </div> <div id='positive-rules-holder'> <?php do_action('membership_level_form_before_positive_rules', $level->id); ?> <?php if (!empty($p)) { foreach ($p as $key => $value) { if (isset($M_Rules[$key])) { $rule = new $M_Rules[$key](); $rule->admin_main($value); } } } ?> <?php do_action('membership_level_form_after_positive_rules', $level->id); ?> </div> </div> <div class='negativecontent <?php echo $negativecontent; ?> '> <h3 class='negative negativetitle <?php echo $advancedcontent; ?> '><?php _e('Negative rules', 'membership'); ?> </h3> <p class='description'><?php _e('These are the areas / elements that a member of this level doesn\'t have access to.', 'membership'); ?> </p> <div id='negative-rules' class='level-droppable-rules levels-sortable'> <?php _e('Drop here', 'membership'); ?> </div> <div id='negative-rules-holder'> <?php do_action('membership_level_form_before_negative_rules', $level->id); ?> <?php if (!empty($n)) { foreach ($n as $key => $value) { if (isset($M_Rules[$key])) { $rule = new $M_Rules[$key](); $rule->admin_main($value); } } } ?> <?php do_action('membership_level_form_after_negative_rules', $level->id); ?> </div> </div> <div class='advancedcontent <?php echo $advancedcontent; ?> '> <h3><?php _e('Custom shortcode protected content message', 'membership'); ?> </h3> <p class='description'><?php _e('If you want a protected content message to be displayed for this level then you can enter it here.', 'membership'); ?> </p> <?php $args = array("textarea_name" => "level_protectedcontent", "textarea_rows" => 20); if (!empty($mlevel)) { $level_protectedcontent = $mlevel->get_meta('level_protectedcontent'); } if (empty($level_protectedcontent)) { $level_protectedcontent = ''; } wp_editor(stripslashes($level_protectedcontent), "level_protectedcontent", $args); ?> </div> <div class='advancedcontent <?php echo $advancedcontent; ?> '> <?php do_action('membership_level_form_after_rules', $level->id); ?> </div> <div class='buttons'> <?php if ($level->id > 0) { wp_original_referer_field(true, 'previous'); wp_nonce_field('update-' . $level->id); ?> <a href='?page=<?php echo $page; ?> ' class='cancellink' title='Cancel edit'><?php _e('Cancel', 'membership'); ?> </a> <input type='submit' value='<?php _e('Update', 'membership'); ?> ' class='button-primary' /> <input type='hidden' name='action' value='updated' /> <?php } else { wp_original_referer_field(true, 'previous'); wp_nonce_field('add-' . $level->id); ?> <a href='?page=<?php echo $page; ?> ' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?> </a> <input type='submit' value='<?php _e('Add', 'membership'); ?> ' class='button-primary' /> <input type='hidden' name='action' value='added' /> <?php } ?> </div> </div> </div> </form> </div> <div id='hiden-actions'> <?php $sections = apply_filters('membership_level_sections', array()); foreach ($sections as $key => $section) { if (isset($M_SectionRules[$key])) { foreach ($M_SectionRules[$key] as $mrule => $mclass) { $rule = new $mclass(); if (!array_key_exists($mrule, $rules)) { $rule->admin_main(false); } } } } ?> </div> <!-- hidden-actions --> </div> <!-- level-liquid-left --> <div class='level-liquid-right'> <div class="level-holder-wrap"> <?php do_action('membership_sidebar_top_level'); do_action('membership_sidebar_top', 'level'); $sections = apply_filters('membership_level_sections', array()); foreach ($sections as $key => $section) { ?> <div class="sidebar-name no-movecursor"> <h3><?php echo $section['title']; ?> </h3> </div> <div class="section-holder" id="sidebar-<?php echo $key; ?> " style="min-height: 98px;"> <ul class='levels level-levels-draggable'> <?php if (isset($M_SectionRules[$key])) { foreach ($M_SectionRules[$key] as $mrule => $mclass) { $rule = new $mclass(); if (!array_key_exists($mrule, $rules)) { $rule->admin_sidebar(false); } else { $rule->admin_sidebar(true); } } } ?> </ul> </div> <?php } ?> </div> <!-- level-holder-wrap --> </div> <!-- level-liquid-left --> </div> <!-- wrap --> <?php }
function handle_level_edit_form($level_id = false, $clone = false) { global $page, $M_Rules, $M_SectionRules; if ($level_id && !$clone) { $mlevel = new M_Level($level_id); $level = $mlevel->get(); } else { if ($clone) { $mlevel = new M_Level($level_id); $level = $mlevel->get(); $level->level_title .= __(' clone', 'membership'); } else { $level = new stdclass(); $level->level_title = __('new level', 'membership'); } $level->id = time() * -1; } // Get the relevant parts if (isset($mlevel)) { $positives = $mlevel->get_rules('positive'); $negatives = $mlevel->get_rules('negative'); } // Re-arrange the rules $rules = array(); $p = array(); $n = array(); if (!empty($positives)) { foreach ($positives as $positive) { $rules[$positive->rule_area] = maybe_unserialize($positive->rule_value); $p[$positive->rule_area] = maybe_unserialize($positive->rule_value); } } if (!empty($negatives)) { foreach ($negatives as $negative) { $rules[$negative->rule_area] = maybe_unserialize($negative->rule_value); $n[$negative->rule_area] = maybe_unserialize($negative->rule_value); } } ?> <div class='wrap nosubsub'> <div class="icon32" id="icon-link-manager"><br></div> <h2><?php echo __('Edit ', 'membership') . " - " . esc_html($level->level_title); ?> </h2> <?php if (isset($usemsg)) { echo '<div id="message" class="updated fade"><p>' . $messages[$usemsg] . '</p></div>'; $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); } ?> <div class='level-liquid-left'> <div id='level-left'> <form action='?page=<?php echo $page; ?> ' name='leveledit' method='post'> <input type='hidden' name='level_id' id='level_id' value='<?php echo $level->id; ?> ' /> <input type='hidden' name='beingdragged' id='beingdragged' value='' /> <input type='hidden' name='in-positive-rules' id='in-positive-rules' value=',<?php echo implode(',', array_keys($p)); ?> ' /> <input type='hidden' name='in-negative-rules' id='in-negative-rules' value=',<?php echo implode(',', array_keys($n)); ?> ' /> <input type='hidden' name='postive-rules-order' id='postive-rules-order' value='' /> <input type='hidden' name='negative-rules-order' id='negative-rules-order' value='' /> <div id='edit-level' class='level-holder-wrap'> <div class='sidebar-name no-movecursor'> <h3><?php echo esc_html($level->level_title); ?> </h3> </div> <div class='level-holder'> <div class='level-details'> <label for='level_title'><?php _e('Level title', 'membership'); ?> </label><br/> <input class='wide' type='text' name='level_title' id='level_title' value='<?php echo esc_attr($level->level_title); ?> ' /> </div> <?php do_action('membership_level_form_before_rules', $level->id); ?> <h3 class='positive'><?php _e('Positive rules', 'membership'); ?> </h3> <p class='description'><?php _e('These are the areas / elements that a member of this level can access.', 'membership'); ?> </p> <div id='positive-rules' class='level-droppable-rules levels-sortable'> <?php _e('Drop here', 'membership'); ?> </div> <div id='positive-rules-holder'> <?php do_action('membership_level_form_before_positive_rules', $level->id); ?> <?php if (!empty($p)) { foreach ($p as $key => $value) { if (isset($M_Rules[$key])) { $rule = new $M_Rules[$key](); $rule->admin_main($value); } } } ?> <?php do_action('membership_level_form_after_positive_rules', $level->id); ?> </div> <h3 class='negative'><?php _e('Negative rules', 'membership'); ?> </h3> <p class='description'><?php _e('These are the areas / elements that a member of this level doesn\'t have access to.', 'membership'); ?> </p> <div id='negative-rules' class='level-droppable-rules levels-sortable'> <?php _e('Drop here', 'membership'); ?> </div> <div id='negative-rules-holder'> <?php do_action('membership_level_form_before_negative_rules', $level->id); ?> <?php if (!empty($n)) { foreach ($n as $key => $value) { if (isset($M_Rules[$key])) { $rule = new $M_Rules[$key](); $rule->admin_main($value); } } } ?> <?php do_action('membership_level_form_after_negative_rules', $level->id); ?> </div> <?php do_action('membership_level_form_after_rules', $level->id); ?> <div class='buttons'> <?php if ($level->id > 0) { nxt_original_referer_field(true, 'previous'); nxt_nonce_field('update-' . $level->id); ?> <a href='?page=<?php echo $page; ?> ' class='cancellink' title='Cancel edit'><?php _e('Cancel', 'membership'); ?> </a> <input type='submit' value='<?php _e('Update', 'membership'); ?> ' class='button' /> <input type='hidden' name='action' value='updated' /> <?php } else { nxt_original_referer_field(true, 'previous'); nxt_nonce_field('add-' . $level->id); ?> <a href='?page=<?php echo $page; ?> ' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?> </a> <input type='submit' value='<?php _e('Add', 'membership'); ?> ' class='button' /> <input type='hidden' name='action' value='added' /> <?php } ?> </div> </div> </div> </form> </div> <div id='hiden-actions'> <?php $sections = apply_filters('membership_level_sections', array()); foreach ($sections as $key => $section) { if (isset($M_SectionRules[$key])) { foreach ($M_SectionRules[$key] as $mrule => $mclass) { $rule = new $mclass(); if (!array_key_exists($mrule, $rules)) { $rule->admin_main(false); } } } } ?> </div> <!-- hidden-actions --> </div> <!-- level-liquid-left --> <div class='level-liquid-right'> <div class="level-holder-wrap"> <?php $sections = apply_filters('membership_level_sections', array()); foreach ($sections as $key => $section) { ?> <div class="sidebar-name no-movecursor"> <h3><?php echo $section['title']; ?> </h3> </div> <div class="section-holder" id="sidebar-<?php echo $key; ?> " style="min-height: 98px;"> <ul class='levels level-levels-draggable'> <?php if (isset($M_SectionRules[$key])) { foreach ($M_SectionRules[$key] as $mrule => $mclass) { $rule = new $mclass(); if (!array_key_exists($mrule, $rules)) { $rule->admin_sidebar(false); } else { $rule->admin_sidebar(true); } } } ?> </ul> </div> <?php } ?> </div> <!-- level-holder-wrap --> </div> <!-- level-liquid-left --> </div> <!-- wrap --> <?php }