/**
  * Do the actual plugin auto install
  *
  * @param   string $plugin      Plugin name
  * @param   array  $inst_params Installation parameters for the plugin
  * @param   bool   $verbose     true: enable verbose logging
  * @return  bool             true on success, false otherwise
  */
 private function autoInstallPlugin($plugin, array $inst_params, $verbose = true)
 {
     global $_CONF, $_TABLES, $_USER, $_DB_dbms, $_DB_table_prefix;
     $fake_uid = false;
     if (!isset($_USER['uid'])) {
         $_USER['uid'] = 1;
         $fake_uid = false;
     }
     $basePath = $_CONF['path'] . 'plugins/' . $plugin . '/';
     if ($verbose) {
         COM_errorLog("Attempting to install the '{$plugin}' plugin", 1);
     }
     // sanity checks for $inst_parms
     if (isset($inst_params['info'])) {
         $pi_name = $inst_params['info']['pi_name'];
         $pi_version = $inst_params['info']['pi_version'];
         $pi_gl_version = $inst_params['info']['pi_gl_version'];
         $pi_homepage = $inst_params['info']['pi_homepage'];
     }
     if (empty($pi_name) || $pi_name !== $plugin || empty($pi_version) || empty($pi_gl_version) || empty($pi_homepage)) {
         COM_errorLog('Incomplete plugin info', 1);
         return false;
     }
     // add plugin tables, if any
     if (!empty($inst_params['tables'])) {
         $tables = $inst_params['tables'];
         foreach ($tables as $table) {
             $_TABLES[$table] = $_DB_table_prefix . $table;
         }
     }
     // Create the plugin's group(s), if any
     $groups = array();
     $adminGroupId = 0;
     if (!empty($inst_params['groups'])) {
         $groups = $inst_params['groups'];
         foreach ($groups as $name => $desc) {
             if ($verbose) {
                 COM_errorLog("Attempting to create '{$name}' group", 1);
             }
             $grp_name = DB_escapeString($name);
             $grp_desc = DB_escapeString($desc);
             DB_query("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('" . DB_escapeString($grp_name) . "', '" . DB_escapeString($grp_desc) . "')", 1);
             if (DB_error()) {
                 COM_errorLog('Error creating plugin group', 1);
                 PLG_uninstall($plugin);
                 return false;
             }
             // keep the new group's ID for use in the mappings section (below)
             $groups[$name] = DB_insertId();
             // assume that the first group is the plugin's Admin group
             if ($adminGroupId == 0) {
                 $adminGroupId = $groups[$name];
             }
         }
     }
     // Create the plugin's table(s)
     $_SQL = array();
     $DEFVALUES = array();
     if (file_exists($basePath . 'sql/' . $_DB_dbms . '_install.php')) {
         require_once $basePath . 'sql/' . $_DB_dbms . '_install.php';
     }
     if (count($_SQL) > 0) {
         $useInnodb = false;
         if ($_DB_dbms === 'mysql' && DB_getItem($_TABLES['vars'], 'value', "name = 'database_engine'") === 'InnoDB') {
             $useInnodb = true;
         }
         $this->env['use_innodb'] = $useInnodb;
         foreach ($_SQL as $sql) {
             $sql = str_replace('#group#', $adminGroupId, $sql);
             DB_query($sql);
             if (DB_error()) {
                 COM_errorLog('Error creating plugin table', 1);
                 PLG_uninstall($plugin);
                 return false;
             }
         }
     }
     // Add the plugin's features
     if ($verbose) {
         COM_errorLog("Attempting to add '{$plugin}' features", 1);
     }
     $mappings = array();
     if (!empty($inst_params['features'])) {
         $features = $inst_params['features'];
         if (!empty($inst_params['mappings'])) {
             $mappings = $inst_params['mappings'];
         }
         foreach ($features as $feature => $desc) {
             $ft_name = DB_escapeString($feature);
             $ft_desc = DB_escapeString($desc);
             DB_query("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " . "VALUES ('{$ft_name}', '{$ft_desc}')", 1);
             if (DB_error()) {
                 COM_errorLog('Error adding plugin feature', 1);
                 PLG_uninstall($plugin);
                 return false;
             }
             $feat_id = DB_insertId();
             if (isset($mappings[$feature])) {
                 foreach ($mappings[$feature] as $group) {
                     if ($verbose) {
                         COM_errorLog("Adding '{$feature}' feature to the '{$group}' group", 1);
                     }
                     DB_query("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ({$feat_id}, {$groups[$group]})");
                     if (DB_error()) {
                         COM_errorLog('Error mapping plugin feature', 1);
                         PLG_uninstall($plugin);
                         return false;
                     }
                 }
             }
         }
     }
     // Add plugin's Admin group to the Root user group
     // (assumes that the Root group's ID is always 1)
     if (count($groups) > 0) {
         if ($verbose) {
             COM_errorLog("Attempting to give all users in the Root group access to the '{$plugin}' Admin group", 1);
         }
         foreach ($groups as $key => $value) {
             DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES " . "({$adminGroupId}, NULL, 1)");
             if (DB_error()) {
                 COM_errorLog('Error adding plugin admin group to Root group', 1);
                 PLG_uninstall($plugin);
                 return false;
             }
         }
     }
     // Pre-populate tables or run any other SQL queries
     if (count($DEFVALUES) > 0) {
         if ($verbose) {
             COM_errorLog('Inserting default data', 1);
         }
         foreach ($DEFVALUES as $sql) {
             $sql = str_replace('#group#', $adminGroupId, $sql);
             DB_query($sql, 1);
             if (DB_error()) {
                 COM_errorLog('Error adding plugin default data', 1);
                 PLG_uninstall($plugin);
                 return false;
             }
         }
     }
     // Load the online configuration records
     $load_config = 'plugin_load_configuration_' . $plugin;
     if (function_exists($load_config)) {
         if (!$load_config($plugin)) {
             COM_errorLog('Error loading plugin configuration', 1);
             PLG_uninstall($plugin);
             return false;
         }
         require_once $_CONF['path'] . 'system/classes/config.class.php';
         $config = config::get_instance();
         $config->initConfig();
         // force re-reading, including new plugin conf
     }
     // Finally, register the plugin with Geeklog
     if ($verbose) {
         COM_errorLog("Registering '{$plugin}' plugin", 1);
     }
     // silently delete an existing entry
     DB_delete($_TABLES['plugins'], 'pi_name', $plugin);
     $plugin = DB_escapeString($plugin);
     $pi_version = DB_escapeString($pi_version);
     $pi_gl_version = DB_escapeString($pi_gl_version);
     $pi_homepage = DB_escapeString($pi_homepage);
     DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) " . "VALUES ('{$plugin}', '{$pi_version}', '{$pi_gl_version}', '{$pi_homepage}', 1)");
     if (DB_error()) {
         COM_errorLog('Failed to register plugin', 1);
         PLG_uninstall($plugin);
         return false;
     }
     // give the plugin a chance to perform any post-install operations
     $postInstall = 'plugin_postinstall_' . $plugin;
     if (function_exists($postInstall)) {
         if (!$postInstall($plugin)) {
             COM_errorLog('Plugin postinstall failed', 1);
             PLG_uninstall($plugin);
             return false;
         }
     }
     if ($verbose) {
         COM_errorLog("Successfully installed the '{$plugin}' plugin!", 1);
     }
     if ($fake_uid) {
         unset($_USER['uid']);
     }
     return true;
 }
Exemple #2
0
/**
* Uninstall a plugin (call its uninstall function).
*
* @param    pi_name   string   name of the plugin to uninstall
* @return             string   HTML for error or success message
*
*/
function PLUGINS_unInstall($pi_name)
{
    global $_CONF, $_DB_table_prefix, $_TABLES, $LANG32, $LANG08, $MESSAGE, $_IMAGE_TYPE;
    $retval = '';
    if (strlen($pi_name) == 0) {
        $retval .= COM_showMessageText($LANG32[12], $LANG32[13], true);
        COM_errorLog($LANG32[12]);
        return $retval;
    }
    // if the plugin is disabled, load the functions.inc now
    if (!function_exists('plugin_uninstall_' . $pi_name)) {
        if (!file_exists($_CONF['path'] . 'plugins/' . $pi_name . '/functions.inc')) {
            COM_errorLog("Unable to locate the plugin directory for " . $pi_name . " - cannot uninstall");
        } else {
            require_once $_CONF['path'] . 'plugins/' . $pi_name . '/functions.inc';
        }
    }
    if (!function_exists('plugin_autouninstall_' . $pi_name) && file_exists($_CONF['path'] . 'plugins/' . $pi_name . '/autoinstall.php')) {
        require_once $_CONF['path'] . 'plugins/' . $pi_name . '/autoinstall.php';
    }
    $msg = '';
    if (PLG_uninstall($pi_name)) {
        $msg = 45;
        $retval .= COM_showMessage(45);
    } else {
        $msg = 95;
        $retval .= COM_showMessage(95);
    }
    CTL_clearCache();
    if ($msg != '') {
        COM_setMessage($msg);
        $refreshURL = $_CONF['site_admin_url'] . '/plugins.php';
    } else {
        $refreshURL = $_CONF['site_admin_url'] . '/plugins.php';
    }
    echo COM_refresh($refreshURL);
    exit;
}
Exemple #3
0
 function INSTALLER_fail($pluginName, $rev)
 {
     $A = array_reverse($rev);
     foreach ($A as $sql) {
         if (empty($sql)) {
             // no step
         } elseif (is_array($sql)) {
             if (array_key_exists('type', $sql)) {
                 $function = 'INSTALLER_fail_' . $type;
                 if (function_exists($function)) {
                     COM_errorlog("AutoInstall: FAIL: calling {$function}");
                     $function($sql);
                 }
             }
         } else {
             COM_errorLog("AutoInstall: FAIL: {$sql}");
             DB_query($sql, 1);
         }
     }
     PLG_uninstall($pluginName);
 }
Exemple #4
0
/**
* Plugin postinstall
*
* We're inserting our default data here since it depends on other stuff that
* has to happen first ...
*
* @return   boolean     true = proceed with install, false = an error occured
*
*/
function plugin_postinstall_nexlist($pi_name)
{
    global $_DB_dbms, $_CONF, $_DB_table_prefix, $_TABLES;
    require_once $_CONF['path'] . 'plugins/nexlist/nexlist.php';
    $DEFVALUES = array();
    $DEFVALUES[] = " INSERT INTO {$_TABLES['nexlist']} (id, plugin, category, name, description, listfields, edit_perms, view_perms, active) VALUES (1, 'all', 'Testing', 'Example List', 'This is an example list definition that has 2 fields. The one field is using a function to provide the dropdown list options. This function could be obtaining the list of options from a list maintained by this plugin - so it can build on itself.', 'User Name', 2, 2, 1);";
    $DEFVALUES[] = "INSERT INTO {$_TABLES['nexlistfields']} (id, lid, fieldname, value_by_function) VALUES (1, 1, 'Username', 'nexlistGetUsers');";
    $DEFVALUES[] = " INSERT INTO {$_TABLES['nexlistfields']} (id, lid, fieldname, value_by_function) VALUES (2, 1, 'Location', '');";
    $DEFVALUES[] = "INSERT INTO {$_TABLES['nexlistitems']} (id, lid, value, active, itemorder) VALUES (1, 1, '1', 1, 10);";
    if ($_DB_dbms != 'mssql') {
        COM_errorLog('Inserting default data', 1);
        foreach ($DEFVALUES as $sql) {
            DB_query($sql, 1);
            if (DB_error()) {
                PLG_uninstall($pi_name);
                return false;
            }
        }
    }
    return true;
}
Exemple #5
0
    echo $display;
    exit;
}
/**
* Main Function
*/
if (SEC_checkToken()) {
    $action = COM_applyFilter($_GET['action']);
    if ($action == 'install') {
        if (plugin_install_evlist()) {
            // Redirects to the plugin editor
            echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=44');
            exit;
        } else {
            echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=72');
            exit;
        }
    } else {
        if ($action == 'uninstall') {
            USES_lib_plugin();
            if (PLG_uninstall('evlist')) {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=45');
                exit;
            } else {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=73');
                exit;
            }
        }
    }
}
echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
Exemple #6
0
/**
*   Puts the datastructures for this plugin into the Geeklog database
*   Note: Corresponding uninstall routine is in functions.inc
*   @return   boolean True if successful False otherwise
*   @ignore
*/
function plugin_install_external()
{
    global $pi_name, $NEWTABLE, $_CONF_EXP, $DEFVALUES, $NEWFEATURE, $_TABLES, $_CONF;
    COM_errorLog("Attempting to install the {$pi_name} Plugin", 1);
    // Create the Plugins Tables
    foreach ($NEWTABLE as $table => $sql) {
        COM_errorLog("Creating {$table} table", 1);
        DB_query($sql, 1);
        if (DB_error()) {
            COM_errorLog("Error Creating {$table} table", 1);
            PLG_uninstall($pi_name);
            return false;
            exit;
        }
        COM_errorLog("Success - Created {$table} table", 1);
    }
    // Insert Default Data
    /*foreach ($DEFVALUES as $table => $sql) {
          COM_errorLog("Inserting default data into $table table",1);
          DB_query($sql,1);
          if (DB_error()) {
              COM_errorLog("Error inserting default data into $table table",1);
              PLG_uninstall($pi_name);
              return false;
              exit;
          }
          COM_errorLog("Success - inserting data into $table table",1);
      }*/
    // Create the plugin admin security group
    COM_errorLog("Attempting to create {$pi_name} admin group", 1);
    DB_query("INSERT INTO {$_TABLES['groups']} (\n            grp_name, \n            grp_descr) \n        VALUES (\n            '{$pi_name} Admin', \n            'Users in this group can administer the {$pi_name} plugin')", 1);
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
        exit;
    }
    COM_errorLog('...success', 1);
    $group_id = DB_insertId();
    // Save the grp id for later uninstall
    COM_errorLog('About to save group_id to vars table for use during uninstall', 1);
    DB_query("INSERT INTO {$_TABLES['vars']} \n            VALUES ('{$pi_name}_gid', {$group_id})", 1);
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
        exit;
    }
    COM_errorLog('...success', 1);
    // Add plugin Features
    foreach ($NEWFEATURE as $feature => $desc) {
        COM_errorLog("Adding {$feature} feature", 1);
        DB_query("INSERT INTO {$_TABLES['features']} \n                (ft_name, ft_descr) \n            VALUES \n                ('{$feature}','{$desc}')", 1);
        if (DB_error()) {
            COM_errorLog("Failure adding {$feature} feature", 1);
            PLG_uninstall($pi_name);
            return false;
            exit;
        }
        $feat_id = DB_insertId();
        COM_errorLog("Success", 1);
        COM_errorLog("Adding {$feature} feature to admin group", 1);
        DB_query("INSERT INTO {$_TABLES['access']} \n                (acc_ft_id, acc_grp_id) \n            VALUES \n                ({$feat_id}, {$group_id})");
        if (DB_error()) {
            COM_errorLog("Failure adding {$feature} feature to admin group", 1);
            PLG_uninstall($pi_name);
            return false;
            exit;
        }
        COM_errorLog("Success", 1);
    }
    // OK, now give Root users access to this plugin now! NOTE: Root group should always be 1
    COM_errorLog("Attempting to give all users in Root group access to {$pi_name} admin group", 1);
    DB_query("INSERT INTO {$_TABLES['group_assignments']} \n            VALUES ({$group_id}, NULL, 1)");
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
        exit;
    }
    // Load the online configuration records
    if (!plugin_initconfig_external($group_id)) {
        PLG_uninstall($pi_name);
        return false;
    }
    // Register the plugin with Geeklog
    COM_errorLog("Registering {$pi_name} plugin with Geeklog", 1);
    DB_delete($_TABLES['plugins'], 'pi_name', 'external');
    DB_query("INSERT INTO {$_TABLES['plugins']} (\n            pi_name, \n            pi_version, \n            pi_gl_version, \n            pi_homepage, \n            pi_enabled) \n        VALUES (\n            '{$_CONF_EXP['pi_name']}', \n            '{$_CONF_EXP['pi_version']}', \n            '{$_CONF_EXP['gl_version']}', \n            '{$_CONF_EXP['pi_url']}', \n            1)");
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
        exit;
    }
    COM_errorLog("Succesfully installed the {$pi_name} Plugin!", 1);
    return true;
}
Exemple #7
0
/**
* Puts the datastructures for this plugin into the Geeklog database
*
*/
function plugin_install_now()
{
    global $_CONF, $_TABLES, $_USER, $_DB_dbms, $GROUPS, $FEATURES, $MAPPINGS, $DEFVALUES, $base_path, $pi_name, $pi_display_name, $pi_version, $gl_version, $pi_url;
    COM_errorLog("Attempting to install the {$pi_display_name} plugin", 1);
    // create the plugin's groups
    $admin_group_id = 0;
    foreach ($GROUPS as $name => $desc) {
        COM_errorLog("Attempting to create {$name} group", 1);
        $grp_name = addslashes($name);
        $grp_desc = addslashes($desc);
        DB_query("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('{$grp_name}', '{$grp_desc}')", 1);
        if (DB_error()) {
            PLG_uninstall($pi_name);
            return false;
        }
        // replace the description with the new group id so we can use it later
        $GROUPS[$name] = DB_insertId();
        // assume that the first group is the plugin's Admin group
        if ($admin_group_id == 0) {
            $admin_group_id = $GROUPS[$name];
        }
    }
    // Create the plugin's table(s)
    $_SQL = array();
    if (file_exists($base_path . 'sql/' . $_DB_dbms . '_install.php')) {
        require_once $base_path . 'sql/' . $_DB_dbms . '_install.php';
    }
    if (count($_SQL) > 0) {
        $use_innodb = false;
        if ($_DB_dbms == 'mysql' && DB_getItem($_TABLES['vars'], 'value', "name = 'database_engine'") == 'InnoDB') {
            $use_innodb = true;
        }
        foreach ($_SQL as $sql) {
            $sql = str_replace('#group#', $admin_group_id, $sql);
            if ($use_innodb) {
                $sql = str_replace('MyISAM', 'InnoDB', $sql);
            }
            DB_query($sql);
            if (DB_error()) {
                COM_errorLog('Error creating table', 1);
                PLG_uninstall($pi_name);
                return false;
            }
        }
    }
    // Add the plugin's features
    COM_errorLog("Attempting to add {$pi_display_name} feature(s)", 1);
    foreach ($FEATURES as $feature => $desc) {
        $ft_name = addslashes($feature);
        $ft_desc = addslashes($desc);
        DB_query("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " . "VALUES ('{$ft_name}', '{$ft_desc}')", 1);
        if (DB_error()) {
            PLG_uninstall($pi_name);
            return false;
        }
        $feat_id = DB_insertId();
        if (isset($MAPPINGS[$feature])) {
            foreach ($MAPPINGS[$feature] as $group) {
                COM_errorLog("Adding {$feature} feature to the {$group} group", 1);
                DB_query("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ({$feat_id}, {$GROUPS[$group]})");
                if (DB_error()) {
                    PLG_uninstall($pi_name);
                    return false;
                }
            }
        }
    }
    // Add plugin's Admin group to the Root user group
    // (assumes that the Root group's ID is always 1)
    COM_errorLog("Attempting to give all users in the Root group access to the {$pi_display_name}'s Admin group", 1);
    DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES " . "({$admin_group_id}, NULL, 1)");
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
    }
    // Pre-populate tables or run any other SQL queries
    COM_errorLog('Inserting default data', 1);
    foreach ($DEFVALUES as $sql) {
        $sql = str_replace('#group#', $admin_group_id, $sql);
        DB_query($sql, 1);
        if (DB_error()) {
            PLG_uninstall($pi_name);
            return false;
        }
    }
    // Load the online configuration records
    if (function_exists('plugin_load_configuration')) {
        if (!plugin_load_configuration()) {
            PLG_uninstall($pi_name);
            return false;
        }
    }
    // Finally, register the plugin with Geeklog
    COM_errorLog("Registering {$pi_display_name} plugin with Geeklog", 1);
    // silently delete an existing entry
    DB_delete($_TABLES['plugins'], 'pi_name', $pi_name);
    DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) VALUES " . "('{$pi_name}', '{$pi_version}', '{$gl_version}', '{$pi_url}', 1)");
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
    }
    // give the plugin a chance to perform any post-install operations
    if (function_exists('plugin_postinstall')) {
        if (!plugin_postinstall()) {
            PLG_uninstall($pi_name);
            return false;
        }
    }
    COM_errorLog("Successfully installed the {$pi_display_name} plugin!", 1);
    return true;
}
Exemple #8
0
*/
$base_path = "{$_CONF['path']}plugins/lglib";
require_once "{$base_path}/autoinstall.php";
require_once "{$base_path}/functions.inc";
USES_lib_install();
/* 
* Main Function
*/
if (SEC_checkToken()) {
    if ($_GET['action'] == 'install') {
        if (plugin_install_lglib()) {
            echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=44');
            exit;
        } else {
            echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=72');
            exit;
        }
    } else {
        if ($_GET['action'] == "uninstall") {
            USES_lib_plugin();
            if (PLG_uninstall('lglib')) {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=45');
                exit;
            } else {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=73');
                exit;
            }
        }
    }
}
echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
Exemple #9
0
/** Import automatic installation function */
require_once $_CONF['path'] . '/plugins/classifieds/autoinstall.php';
USES_lib_install();
/*
* Main Function
*/
if (SEC_checkToken()) {
    $action = isset($_REQUEST['action']) ? trim($_REQUEST['action']) : '';
    switch ($action) {
        case 'install':
            if (plugin_install_classifieds()) {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=44');
                exit;
            } else {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=72');
                exit;
            }
            break;
        case 'uninstall':
            USES_lib_plugin();
            if (PLG_uninstall($_CONF_ADVT['pi_name'])) {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=45');
                exit;
            } else {
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=73');
                exit;
            }
            break;
    }
}
echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
function plugin_postinstall_paypal($pi_name)
{
    global $_TABLES, $_CONF, $_USER;
    /* New Groups */
    $groups['Paypal User'] = '******';
    $groups['Paypal Viewer'] = 'Users in this group can view products';
    // Groups assignment mapping (note: group -> group, not user -> group)
    $grp_assign['Paypal User'] = array(13);
    // 13 is the Logged-in Users group
    $grp_assign['Paypal Viewer'] = array(2);
    // 2 is the All Users group
    // Assign created paypal groups to other (logical) groups
    foreach ($grp_assign as $group => $grparray) {
        foreach ($grparray as $togroup) {
            COM_errorLog("Assigning group {$togroup} to {$group}", 1);
            $result = DB_query("SELECT grp_id, grp_name FROM {$_TABLES['groups']} WHERE grp_name ='{$group}'");
            $A = DB_fetchArray($result);
            DB_query("INSERT INTO {$_TABLES['group_assignments']} " . "VALUES ({$A[0]}, NULL, {$togroup})");
            if (DB_error()) {
                COM_errorLog("Failed assigning group {$togroup} to {$group}", 1);
                PLG_uninstall('paypal');
                return false;
            }
            COM_errorLog('...success', 1);
        }
    }
    /* This code is for statistics ONLY */
    $message = 'Completed paypal plugin install: ' . date('m d Y', time()) . "   AT " . date('H:i', time()) . "\n";
    $message .= 'Site: ' . $_CONF['site_url'] . ' and Sitename: ' . $_CONF['site_name'] . "\n";
    $pi_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = 'paypal'");
    COM_mail("*****@*****.**", "{$pi_name} Version:{$pi_version} Install successfull", $message);
    // Create paypal_downloads.log file
    $paypalDownload = fopen($_CONF['path_log'] . 'paypal_downloads.log', 'w') or die("can't create file paypal_downloads.log file");
    fclose($paypalDownload);
    return true;
}