function handle_submit()
{
    global $db_connections, $def_coy, $tb_pref_counter, $db, $comp_subdirs, $path_to_root, $selected_id;
    $error = false;
    if (!check_data()) {
        return false;
    }
    if ($selected_id == -1) {
        $selected_id = count($db_connections);
    }
    $new = !isset($db_connections[$selected_id]);
    if ((bool) $_POST['def'] == true) {
        $def_coy = $selected_id;
    }
    $db_connections[$selected_id]['name'] = $_POST['name'];
    if ($new) {
        $db_connections[$selected_id]['host'] = $_POST['host'];
        $db_connections[$selected_id]['dbuser'] = $_POST['dbuser'];
        $db_connections[$selected_id]['dbpassword'] = $_POST['dbpassword'];
        $db_connections[$selected_id]['dbname'] = $_POST['dbname'];
        if (is_numeric($_POST['tbpref'])) {
            $db_connections[$selected_id]['tbpref'] = $_POST['tbpref'] == 1 ? $tb_pref_counter . "_" : '';
        } else {
            if ($_POST['tbpref'] != "") {
                $db_connections[$selected_id]['tbpref'] = $_POST['tbpref'];
            } else {
                $db_connections[$selected_id]['tbpref'] = "";
            }
        }
        $conn = $db_connections[$selected_id];
        if (($db = db_create_db($conn)) == 0) {
            display_error(_("Error creating Database: ") . $conn['dbname'] . _(", Please create it manually"));
            $error = true;
        } else {
            if (!db_import($path_to_root . '/sql/' . get_post('coa'), $conn, $selected_id)) {
                display_error(_('Cannot create new company due to bugs in sql file.'));
                $error = true;
            } else {
                if (!isset($_POST['admpassword']) || $_POST['admpassword'] == "") {
                    $_POST['admpassword'] = "******";
                }
                update_admin_password($conn, md5($_POST['admpassword']));
            }
        }
        set_global_connection();
        if ($error) {
            remove_connection($selected_id);
            return false;
        }
    }
    $error = write_config_db($new);
    if ($error == -1) {
        display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
    } else {
        if ($error == -2) {
            display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
        } else {
            if ($error == -3) {
                display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation."));
            }
        }
    }
    if ($error != 0) {
        return false;
    }
    if ($new) {
        create_comp_dirs(company_path($selected_id), $comp_subdirs);
    }
    $exts = get_company_extensions();
    write_extensions($exts, $selected_id);
    display_notification($new ? _('New company has been created.') : _('Company has been updated.'));
    return true;
}
Example #2
0
    $comp = get_post('extset');
    $exts = get_company_extensions($comp);
    $result = true;
    foreach ($exts as $i => $ext) {
        if ($ext['package'] && $ext['active'] ^ check_value('Active' . $i)) {
            $activated = activate_hooks($ext['package'], $comp, !$ext['active']);
            // change active state
            if ($activated !== null) {
                $result &= $activated;
            }
            if ($activated || $activated === null) {
                $exts[$i]['active'] = check_value('Active' . $i);
            }
        }
    }
    write_extensions($exts, get_post('extset'));
    if (get_post('extset') == user_company()) {
        $installed_extensions = $exts;
    }
    if (!$result) {
        display_error(_('Status change for some extensions failed.'));
        $Ajax->activate('ext_tbl');
        // refresh settings display
    } else {
        display_notification(_('Current active extensions set has been saved.'));
    }
}
if ($id = find_submit('Update', false)) {
    install_extension($id);
}
if ($id = find_submit('Local', false)) {
Example #3
0
function fix_extensions()
{
    global $path_to_root, $db_connections;
    if (!file_exists($path_to_root . '/modules/installed_modules.php')) {
        return true;
    }
    // already converted
    if (!is_writable($path_to_root . '/modules/installed_modules.php')) {
        display_error(_('Cannot upgrade extensions system: file /modules/installed_modules.php is not writeable'));
        return false;
    }
    $exts = array();
    include $path_to_root . '/installed_extensions.php';
    foreach ($installed_extensions as $ext) {
        $ext['filename'] = $ext['app_file'];
        unset($ext['app_file']);
        $ext['tab'] = $ext['name'];
        $ext['name'] = access_string($ext['title'], true);
        $ext['path'] = $ext['folder'];
        unset($ext['folder']);
        $ext['type'] = 'extension';
        $ext['active'] = '1';
        $exts[] = $ext;
    }
    if (!write_extensions($exts)) {
        return false;
    }
    $cnt = count($db_connections);
    for ($i = 0; $i < $cnt; $i++) {
        write_extensions($exts, $i);
    }
    unlink($path_to_root . '/modules/installed_modules.php');
    return true;
}