/**
 * Function to de-activate all plugins
 **/
function wpau_deactivate_plugins($automated = false)
{
    if (!current_user_can('edit_plugins')) {
        echo 'Oops sorry you are not authorized to do this';
        return false;
    }
    global $theFuncComplete;
    wpauPersistNoLog(false, false, $automated);
    $thePlugs = array();
    require_once 'wpau_plugin.class.php';
    $path = "../";
    if ($automated) {
        $path = "../../";
    }
    $currentPlugs = get_option('active_plugins');
    foreach ($currentPlugs as $plugin) {
        if (wpau_validate_file($path . $plugin)) {
            //another wp guys check
            if (in_array($plugin, $currentPlugs)) {
                array_push($thePlugs, $plugin);
            }
        }
    }
    $wpauPluginsHandler = new wpauPluginHandler($thePlugs);
    if ($wpauPluginsHandler->deActivatePlugins()) {
        $theFuncComplete = true;
        $message = 'All the plugins have been de-activated, except for <strong>Wordpress automatic upgrade</strong> plugin.';
    } else {
        $theFuncComplete = false;
        $message = 'The plugins could not be de-activated. Please click here to manually de-activate the plugin. Please do not de-activate the <strong>Wordpress automatic upgrade</strong> plugin';
    }
    wpauPersist(true, $wpauPluginsHandler->loggedData, $theFuncComplete, $message, true);
    unset($wpauPluginsHandler);
    if ($automated) {
        return $theFuncComplete;
    }
}
 function reActivatePlugin($plugin, $automated)
 {
     if (!current_user_can('edit_plugins')) {
         echo 'Oops sorry you are not authorized to do this';
         return false;
     }
     global $wpdb;
     $current = get_option('active_plugins');
     $pluginfile = $plugin->plugin_name;
     $pluginid = $plugin->id;
     $path = "../";
     if ($automated) {
         $path = "../../";
     }
     if (wpau_validate_file($path . $pluginfile)) {
         if (!file_exists(ABSPATH . PLUGINDIR . '/' . $pluginfile)) {
             $this->logMessage('Plugin ' . $pluginfile . ' file does not exist');
         } else {
             if (!in_array($pluginfile, $current)) {
                 ob_start();
                 echo '<script language="JavaScript" type="text/javascript"> ' . ' window.location = "edit.php?page=' . WPAU_PAGE . '&task=re-plugin&pluginid=' . $plugin->id . '"' . '</script>';
                 if ($file_included = @(include ABSPATH . PLUGINDIR . '/' . $pluginfile)) {
                     $current[] = $pluginfile;
                     sort($current);
                     update_option('active_plugins', $current);
                     do_action('activate_' . $pluginfile);
                     $wpdb->query("Update " . WPAU_PLUGIN_TABLE . " set plugin_status = 1, plugin_reactive_response = 1 where id = {$pluginid}");
                     $this->logMessage('Plugin <strong>' . $pluginfile . '</strong> was activated succesfully<br>');
                 } else {
                     $this->logMessage('<span style="color:red">Plugin <strong>' . $pluginfile . '</strong> could not be activated succesfully. You will need to activate it manually.</span><br>');
                 }
                 ob_end_clean();
             } else {
                 $this->logMessage('Plugin <strong>' . $pluginfile . '</strong> is already activated<br>');
             }
         }
     } else {
         $this->logMessage('Could not validate the plugin <strong>' . $pluginfile . '</strong><br>');
         //TODO LOG REASONS FOR NOT VALIDATING
     }
 }