function handle_levels_updates()
 {
     global $action, $page;
     wp_reset_vars(array('action', 'page'));
     if (isset($_GET['doaction']) || isset($_GET['doaction2'])) {
         if (addslashes($_GET['action']) == 'delete' || addslashes($_GET['action2']) == 'delete') {
             $action = 'bulk-delete';
         }
         if (addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') {
             $action = 'bulk-toggle';
         }
     }
     switch (addslashes($action)) {
         case 'removeheader':
             $this->dismiss_user_help($page);
             wp_safe_redirect(remove_query_arg('action'));
             break;
         case 'added':
             $id = (int) $_POST['level_id'];
             check_admin_referer('add-' . $id);
             if ($id) {
                 $level = new M_Level($id);
                 if ($level->add()) {
                     // Add in the meta information
                     if (!empty($_POST['level_protectedcontent'])) {
                         $level->update_meta('level_protectedcontent', $_POST['level_protectedcontent']);
                     }
                     // redirect
                     wp_safe_redirect(add_query_arg('msg', 1, 'admin.php?page=' . $page));
                 } else {
                     wp_safe_redirect(add_query_arg('msg', 4, 'admin.php?page=' . $page));
                 }
             } else {
                 wp_safe_redirect(add_query_arg('msg', 4, 'admin.php?page=' . $page));
             }
             break;
         case 'updated':
             $id = (int) $_POST['level_id'];
             check_admin_referer('update-' . $id);
             if ($id) {
                 $level = new M_Level($id);
                 if ($level->update()) {
                     // update the meta information
                     if (!empty($_POST['level_protectedcontent'])) {
                         $level->update_meta('level_protectedcontent', $_POST['level_protectedcontent']);
                     } else {
                         $level->delete_meta('level_protectedcontent');
                     }
                     // redirect
                     wp_safe_redirect(add_query_arg('msg', 3, 'admin.php?page=' . $page));
                 } else {
                     wp_safe_redirect(add_query_arg('msg', 5, 'admin.php?page=' . $page));
                 }
             } else {
                 wp_safe_redirect(add_query_arg('msg', 5, 'admin.php?page=' . $page));
             }
             break;
         case 'delete':
             if (isset($_GET['level_id'])) {
                 $level_id = (int) $_GET['level_id'];
                 check_admin_referer('delete-level_' . $level_id);
                 $level = new M_Level($level_id);
                 if ($level->delete($level_id)) {
                     // delete the meta information
                     $level->delete_meta('level_protectedcontent');
                     // redirect
                     wp_safe_redirect(add_query_arg('msg', 2, wp_get_referer()));
                 } else {
                     wp_safe_redirect(add_query_arg('msg', 6, wp_get_referer()));
                 }
             }
             break;
         case 'toggle':
             if (isset($_GET['level_id'])) {
                 $level_id = (int) $_GET['level_id'];
                 check_admin_referer('toggle-level_' . $level_id);
                 $level = new M_Level($level_id);
                 if ($level->toggleactivation()) {
                     wp_safe_redirect(add_query_arg('msg', 7, wp_get_referer()));
                 } else {
                     wp_safe_redirect(add_query_arg('msg', 8, wp_get_referer()));
                 }
             }
             break;
         case 'bulk-delete':
             check_admin_referer('bulk-levels');
             foreach ($_GET['levelcheck'] as $value) {
                 if (is_numeric($value)) {
                     $level_id = (int) $value;
                     $level = new M_Level($level_id);
                     $level->delete();
                 }
             }
             wp_safe_redirect(add_query_arg('msg', 2, wp_get_referer()));
             break;
         case 'bulk-toggle':
             check_admin_referer('bulk-levels');
             foreach ($_GET['levelcheck'] as $value) {
                 if (is_numeric($value)) {
                     $level_id = (int) $value;
                     $level = new M_Level($level_id);
                     $level->toggleactivation();
                 }
             }
             wp_safe_redirect(add_query_arg('msg', 7, wp_get_referer()));
             break;
     }
 }
Exemplo n.º 2
0
 function handle_levels_updates()
 {
     global $action, $page;
     nxt_reset_vars(array('action', 'page'));
     // check levels
     $this->get_all_levels();
     if (isset($_GET['doaction']) || isset($_GET['doaction2'])) {
         if (addslashes($_GET['action']) == 'delete' || addslashes($_GET['action2']) == 'delete') {
             $action = 'bulk-delete';
         }
         if (addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') {
             $action = 'bulk-toggle';
         }
     }
     switch (addslashes($action)) {
         case 'added':
             $id = (int) $_POST['level_id'];
             check_admin_referer('add-' . $id);
             if ($id) {
                 $level = new M_Level($id);
                 if (!M_can_add_level()) {
                     nxt_safe_redirect(add_query_arg('msg', 4, 'admin.php?page=' . $page));
                 } else {
                     if ($level->add()) {
                         nxt_safe_redirect(add_query_arg('msg', 1, 'admin.php?page=' . $page));
                     } else {
                         nxt_safe_redirect(add_query_arg('msg', 4, 'admin.php?page=' . $page));
                     }
                 }
             } else {
                 nxt_safe_redirect(add_query_arg('msg', 4, 'admin.php?page=' . $page));
             }
             break;
         case 'updated':
             $id = (int) $_POST['level_id'];
             check_admin_referer('update-' . $id);
             if ($id) {
                 $level = new M_Level($id);
                 if ($level->update()) {
                     nxt_safe_redirect(add_query_arg('msg', 3, 'admin.php?page=' . $page));
                 } else {
                     nxt_safe_redirect(add_query_arg('msg', 5, 'admin.php?page=' . $page));
                 }
             } else {
                 nxt_safe_redirect(add_query_arg('msg', 5, 'admin.php?page=' . $page));
             }
             break;
         case 'delete':
             if (isset($_GET['level_id'])) {
                 $level_id = (int) $_GET['level_id'];
                 check_admin_referer('delete-level_' . $level_id);
                 $level = new M_Level($level_id);
                 if ($level->delete($level_id)) {
                     nxt_safe_redirect(add_query_arg('msg', 2, nxt_get_referer()));
                 } else {
                     nxt_safe_redirect(add_query_arg('msg', 6, nxt_get_referer()));
                 }
             }
             break;
         case 'toggle':
             if (isset($_GET['level_id'])) {
                 $level_id = (int) $_GET['level_id'];
                 check_admin_referer('toggle-level_' . $level_id);
                 $level = new M_Level($level_id);
                 if ($level->toggleactivation()) {
                     nxt_safe_redirect(add_query_arg('msg', 7, nxt_get_referer()));
                 } else {
                     nxt_safe_redirect(add_query_arg('msg', 8, nxt_get_referer()));
                 }
             }
             break;
         case 'bulk-delete':
             check_admin_referer('bulk-levels');
             foreach ($_GET['levelcheck'] as $value) {
                 if (is_numeric($value)) {
                     $level_id = (int) $value;
                     $level = new M_Level($level_id);
                     $level->delete();
                 }
             }
             nxt_safe_redirect(add_query_arg('msg', 2, nxt_get_referer()));
             break;
         case 'bulk-toggle':
             check_admin_referer('bulk-levels');
             foreach ($_GET['levelcheck'] as $value) {
                 if (is_numeric($value)) {
                     $level_id = (int) $value;
                     $level = new M_Level($level_id);
                     $level->toggleactivation();
                 }
             }
             nxt_safe_redirect(add_query_arg('msg', 7, nxt_get_referer()));
             break;
     }
 }