예제 #1
0
 function install($pref, $force)
 {
     global $db, $systypes_array;
     if (!$this->preconf) {
         return false;
     }
     // Until 2.2 sanitizing text input with db_escape was not
     // consequent enough. To avoid comparision problems we have to
     // fix this now.
     sanitize_database($pref);
     if ($this->beta) {
         // nothing more to be done on upgrade from 2.2beta
         return true;
     }
     // set item category dflt accounts to values from company GL setup
     $prefs = get_company_prefs();
     $sql = "UPDATE {$pref}stock_category SET " . "dflt_sales_act = '" . $prefs['default_inv_sales_act'] . "'," . "dflt_cogs_act = '" . $prefs['default_cogs_act'] . "'," . "dflt_inventory_act = '" . $prefs['default_inventory_act'] . "'," . "dflt_adjustment_act = '" . $prefs['default_adj_act'] . "'," . "dflt_assembly_act = '" . $prefs['default_assembly_act'] . "'";
     if (db_query($sql) == false) {
         display_error("Cannot update category default GL accounts" . ':<br>' . db_error_msg($db));
         return false;
     }
     // add all references to refs table for easy searching via journal interface
     foreach ($systypes_array as $typeno => $typename) {
         $info = get_systype_db_info($typeno);
         if ($info == null || $info[3] == null) {
             continue;
         }
         $tbl = str_replace(TB_PREF, $pref, $info[0]);
         $sql = "SELECT DISTINCT {$info[2]} as id,{$info[3]} as ref FROM {$tbl}";
         if ($info[1]) {
             $sql .= " WHERE {$info[1]}={$typeno}";
         }
         $result = db_query($sql);
         if (db_num_rows($result)) {
             while ($row = db_fetch($result)) {
                 $res2 = db_query("INSERT INTO {$pref}refs VALUES(" . $row['id'] . "," . $typeno . ",'" . $row['ref'] . "')");
                 if (!$res2) {
                     display_error(_("Cannot copy references from {$tbl}") . ':<br>' . db_error_msg($db));
                     return false;
                 }
             }
         }
     }
     if (!($ret = db_query("SELECT MAX(`order_no`) FROM `{$pref}sales_orders`")) || !db_num_rows($ret)) {
         display_error(_('Cannot query max sales order number.'));
         return false;
     }
     $row = db_fetch($ret);
     $max_order = $row[0];
     $next_ref = $max_order + 1;
     $sql = "UPDATE `{$pref}sys_types` \n\t\t\tSET `type_no`='{$max_order}',`next_reference`='{$next_ref}'\n\t\t\tWHERE `type_id`=30";
     if (!db_query($sql)) {
         display_error(_('Cannot store next sales order reference.'));
         return false;
     }
     return convert_roles($pref);
 }
예제 #2
0
 function install($pref, $force)
 {
     global $db_version, $dflt_lang;
     $this->preconf = $this->fix_extensions();
     if (!$this->preconf) {
         return false;
     }
     if (!$this->beta) {
         // all specials below are already done on 2.3beta
         $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master";
         $result = db_query($sql);
         if (!$result) {
             display_error("Cannot read customers" . ':<br>' . db_error_msg($db));
             return false;
         }
         // update all sales orders and transactions with customer std payment terms
         while ($cust = db_fetch($result)) {
             $sql = "UPDATE {$pref}debtor_trans SET " . "payment_terms = '" . $cust['payment_terms'] . "' WHERE debtor_no='" . $cust['debtor_no'] . "'";
             if (db_query($sql) == false) {
                 display_error("Cannot update cust trans payment" . ':<br>' . db_error_msg($db));
                 return false;
             }
             $sql = "UPDATE {$pref}sales_orders SET " . "payment_terms = '" . $cust['payment_terms'] . "' WHERE debtor_no='" . $cust['debtor_no'] . "'";
             if (db_query($sql) == false) {
                 display_error("Cannot update sales order payment" . ':<br>' . db_error_msg($db));
                 return false;
             }
         }
         if (!$this->update_totals($pref)) {
             display_error("Cannot update order totals");
             return false;
         }
         if (!$this->update_line_relations($pref)) {
             display_error("Cannot update sales document links");
             return false;
         }
         //remove obsolete and temporary columns.
         // this have to be done here as db_import rearranges alter query order
         $dropcol = array('crm_persons' => array('tmp_id', 'tmp_class'), 'debtors_master' => array('email'), 'cust_branch' => array('phone', 'phone2', 'fax', 'email'), 'suppliers' => array('phone', 'phone2', 'fax', 'email'), 'debtor_trans' => array('trans_link'));
         foreach ($dropcol as $table => $columns) {
             foreach ($columns as $col) {
                 if (db_query("ALTER TABLE `{$pref}{$table}` DROP `{$col}`") == false) {
                     display_error("Cannot drop {$table}.{$col} column:<br>" . db_error_msg($db));
                     return false;
                 }
             }
         }
         // remove old preferences table after upgrade script has been executed
         $sql = "DROP TABLE IF EXISTS `{$pref}company`";
         if (!db_query($sql)) {
             return false;
         }
     }
     $this->update_lang_cfg();
     return update_company_prefs(array('version_id' => $db_version), $pref);
 }
예제 #3
0
/**
 * send both the error number and error message and query (optional) as paramaters for a triggered error
 * @todo Use/Behaviour of this function should be reviewed before 1.2.0 final
 */
function db_error($p_query = null)
{
    if (null !== $p_query) {
        error_parameters(db_error_num(), db_error_msg(), $p_query);
    } else {
        error_parameters(db_error_num(), db_error_msg());
    }
}
            echo " - ERROR: ";
        } else {
            echo " - WARNING: ";
        }
        if ('' != $p_message) {
            echo $p_message;
        }
    }
    if (GOOD == $p_result) {
        echo " - GOOD";
    }
    echo "\n";
}
$result = @db_connect(config_get_global('dsn', false), config_get_global('hostname'), config_get_global('db_username'), config_get_global('db_password'), config_get_global('database_name'));
if (false == $result) {
    echo "Opening connection to database " . config_get_global('database_name') . " on host " . config_get_global('hostname') . " with username " . config_get_global('db_username') . " failed: " . db_error_msg() . "\n";
    exit(1);
}
# check to see if the new installer was used
if (-1 == config_get('database_version', -1)) {
    echo "Upgrade from the current installed MantisBT version is no longer supported.  If you are using MantisBT version older than 1.0.0, then upgrade to v1.0.0 first.";
    exit(1);
}
# read control variables with defaults
$f_hostname = gpc_get('hostname', config_get('hostname', 'localhost'));
$f_db_type = gpc_get('db_type', config_get('db_type', ''));
$f_database_name = gpc_get('database_name', config_get('database_name', 'bugtrack'));
$f_db_username = gpc_get('db_username', config_get('db_username', ''));
$f_db_password = gpc_get('db_password', config_get('db_password', ''));
$f_db_exists = gpc_get_bool('db_exists', false);
# install the tables
예제 #5
0
    } else {
        print_test_result(BAD, true, 'Database user does not have UPDATE access to the database ( ' . db_error_msg() . ' )');
    }
    ?>
</tr>
<tr>
	<td bgcolor="#ffffff">
		checking ability to DELETE records
	</td>
	<?php 
    $t_query = 'DELETE FROM ' . db_get_table('config') . ' WHERE config_id=\'database_test\'';
    $t_result = @$g_db->Execute($t_query);
    if ($t_result != false) {
        print_test_result(GOOD);
    } else {
        print_test_result(BAD, true, 'Database user does not have DELETE access to the database ( ' . db_error_msg() . ' )');
    }
    ?>
</tr>
</table>
<?php 
    if (false == $g_failed) {
        $t_install_state++;
    }
}
# end install_state == 6
if (7 == $t_install_state) {
    # cleanup and launch upgrade
    ?>
<table width="100%" bgcolor="#222222" cellpadding="10" cellspacing="1">
<tr>
예제 #6
0
 function install($pref, $force)
 {
     global $db;
     /*
     Statement below is allowed only for MySQL >=4.0.4:
     UPDATE `0_bank_trans`, `0_bank_accounts` 
     	SET 0_bank_trans.bank_act=0_bank_accounts.id 
     	WHERE 0_bank_trans.bank_act=0_bank_accounts.account_code;
     */
     $sql = "SELECT id, account_code FROM " . $pref . "bank_accounts";
     if (!($res = db_query($sql))) {
         display_error(_("Cannot retrieve bank accounts codes") . ':<br>' . db_error_msg($db));
         return false;
     }
     while ($acc = db_fetch($res)) {
         $sql = "UPDATE " . $pref . "bank_trans SET bank_act='" . $acc['id'] . "' WHERE bank_act=" . $acc['account_code'];
         if (db_query($sql) == false) {
             display_error(_("Cannot update bank transactions") . ':<br>' . db_error_msg($db));
             return false;
         }
     }
     // copy all item codes from stock_master into item_codes
     $sql = "SELECT `stock_id`,`description`,`category_id` FROM " . $pref . "stock_master";
     $result = db_query($sql);
     if (!$result) {
         display_error(_("Cannot select stock identificators") . ':<br>' . db_error_msg($db));
         return false;
     } else {
         while ($row = db_fetch_assoc($result)) {
             $sql = "INSERT IGNORE " . $pref . "item_codes (`item_code`,`stock_id`,`description`,`category_id`)\n\t\t\t\t\tVALUES('" . $row['stock_id'] . "','" . $row['stock_id'] . "','" . $row['description'] . "','" . $row['category_id'] . "')";
             $res2 = db_query($sql);
             if (!$res2) {
                 display_error(_("Cannot insert stock id into item_codes") . ':<br>' . db_error_msg($db));
                 return false;
             }
         }
     }
     // remove obsolete bank_trans_types table
     // (DROP queries are skipped during non-forced upgrade)
     $sql = "DROP TABLE IF EXISTS `0_bank_trans_types`";
     db_query($sql);
     //
     //	Move all debtor and supplier trans tax details to new table
     // (INSERT INTO t  SELECT ... FROM t ... available after 4.0.14)
     // No easy way to restore net amount for 0% tax rate for moved
     // FA 2.0 transactions, but who cares?
     //
     $move_sql = array("debtor_trans_tax_details" => "SELECT tr.tran_date, tr.type, tr.trans_no, dt.tax_type_id, \n\t\t\tdt.rate, dt.included_in_price, dt.amount, tr.reference as ref,\n\t\t\ttr.rate as ex_rate\n\t\tFROM " . $pref . "debtor_trans_tax_details dt\t\n\t\t\tLEFT JOIN " . $pref . "trans_tax_details tt\n\t\t\t\tON dt.debtor_trans_no=tt.trans_no \n\t\t\t\tAND dt.debtor_trans_type=tt.trans_type,\n\t\t\t" . $pref . "debtor_trans tr\n\t\tWHERE tt.trans_type is NULL\n\t\t\tAND dt.debtor_trans_no = tr.trans_no \n\t\t\tAND dt.debtor_trans_type = tr.type", "supp_invoice_tax_items" => "SELECT tr.tran_date, tr.type, tr.trans_no, st.tax_type_id, \n\t\t\tst.rate, st.included_in_price, st.amount, tr.supp_reference as ref,\n\t\t\ttr.rate as ex_rate\n\t\t\tFROM " . $pref . "supp_invoice_tax_items st\t\n\t\t\t\tLEFT JOIN " . $pref . "trans_tax_details tt\n\t\t\t\t\tON st.supp_trans_no=tt.trans_no \n\t\t\t\t\tAND st.supp_trans_type=tt.trans_type,\n\t\t\t\t\t" . $pref . "supp_trans tr\n\t\t\t\tWHERE tt.trans_type is NULL\n\t\t\t\t\tAND st.supp_trans_no = tr.trans_no \n\t\t\t\t\tAND st.supp_trans_type = tr.type");
     foreach ($move_sql as $tbl => $sql) {
         if (!check_table($pref, $tbl)) {
             $res = db_query($sql, "Cannot retrieve trans tax details from {$tbl}");
             while ($row = db_fetch($res)) {
                 $net_amount = $row['rate'] == 0 ? 0 : ($row['included_in_price'] ? $row['amount'] / $row['rate'] * (100 - $row['rate']) : $row['amount'] / $row['rate'] * 100);
                 $sql2 = "INSERT INTO " . $pref . "trans_tax_details \n\t\t\t\t(trans_type,trans_no,tran_date,tax_type_id,rate,ex_rate,\n\t\t\t\t\tincluded_in_price, net_amount, amount, memo)\n\t\t\t\tVALUES ('" . $row['type'] . "','" . $row['trans_no'] . "','" . $row['tran_date'] . "','" . $row['tax_type_id'] . "','" . $row['rate'] . "','" . $row['ex_rate'] . "','" . $row['included_in_price'] . "','" . $net_amount . "','" . $row['amount'] . "','" . $row['ref'] . "')";
                 db_query($sql2, "Cannot move trans tax details from {$tbl}");
             }
             db_query("DROP TABLE " . $pref . $tbl, "cannot remove {$tbl}");
         }
     }
     return true;
 }
예제 #7
0
	if( GOOD == $p_result ) {
		echo " - GOOD";
	}
	echo "\n";
}

$result = @db_connect( config_get_global( 'dsn', false ), config_get_global( 'hostname' ),
	config_get_global( 'db_username' ), config_get_global( 'db_password' ),
	config_get_global( 'database_name' ) );

if( false == $result ) {
	echo "Opening connection to database " .
		config_get_global( 'database_name' ) .
		" on host " . config_get_global( 'hostname' ) .
		" with username " . config_get_global( 'db_username' ) .
		" failed: " . db_error_msg() . "\n";
	exit( 1 );
}

# TODO: Enhance this check to support the mode where this script is called on an empty database.
# check to see if the new installer was used
if ( -1 == config_get( 'database_version', -1 ) ) {
        echo "Upgrade from the current installed MantisBT version is no longer supported.  If you are using MantisBT version older than 1.0.0, then upgrade to v1.0.0 first.";
        exit( 1 );
}

# read control variables with defaults
$f_hostname = gpc_get( 'hostname', config_get( 'hostname', 'localhost' ) );
$f_db_type = gpc_get( 'db_type', config_get( 'db_type', '' ) );
$f_database_name = gpc_get( 'database_name', config_get( 'database_name', 'bugtrack' ) );
$f_db_username = gpc_get( 'db_username', config_get( 'db_username', '' ) );
예제 #8
0
 function execute()
 {
     if (!function_exists($this->function_name)) {
         $this->error = "Function {$this->function_name} does not exist";
         return false;
     }
     $result = call_user_func($this->function_name);
     if ($result) {
         $this->set_applied();
     } else {
         $this->error = "Function {$this->function_name}() returned false<br />";
         $t_db_error = db_error_msg();
         if (!is_blank($t_db_error)) {
             $this->error .= "Last database error (may not be applicable) was: " . $t_db_error;
         }
     }
     return $result;
 }
예제 #9
0
	if( GOOD == $p_result ) {
		echo ' - GOOD';
	}
	echo "\n";
}

$t_result = @db_connect( config_get_global( 'dsn', false ), config_get_global( 'hostname' ),
	config_get_global( 'db_username' ), config_get_global( 'db_password' ),
	config_get_global( 'database_name' ) );

if( false == $t_result ) {
	echo 'Opening connection to database ' .
		config_get_global( 'database_name' ) .
		' on host ' . config_get_global( 'hostname' ) .
		' with username ' . config_get_global( 'db_username' ) .
		' failed: ' . db_error_msg() . "\n";
	exit( 1 );
}

# TODO: Enhance this check to support the mode where this script is called on an empty database.
# check to see if the new installer was used
if( -1 == config_get( 'database_version', -1 ) ) {
		echo 'Upgrade from the current installed MantisBT version is no longer supported.  If you are using MantisBT version older than 1.0.0, then upgrade to v1.0.0 first.';
		exit( 1 );
}

# read control variables with defaults
$t_db_type = config_get_global( 'db_type' );

# install the tables
if( !preg_match( '/^[a-zA-Z0-9_]+$/', $t_db_type ) ||
예제 #10
0
function db_error()
{
    return "<p>" . db_error_num() . ": " . db_error_msg() . "<p>";
}
예제 #11
0
            echo '- ERROR: ';
        } else {
            echo '- WARNING: ';
        }
        if ('' != $p_message) {
            echo $p_message;
        }
    }
    if (GOOD == $p_result) {
        echo '- GOOD';
    }
    echo "\n";
}
$t_result = @db_connect(config_get_global('dsn', false), config_get_global('hostname'), config_get_global('db_username'), config_get_global('db_password'), config_get_global('database_name'));
if (false == $t_result) {
    echo 'Opening connection to database ' . config_get_global('database_name') . ' on host ' . config_get_global('hostname') . ' with username ' . config_get_global('db_username') . ' failed: ' . db_error_msg() . "\n";
    exit(1);
}
# TODO: Enhance this check to support the mode where this script is called on an empty database.
# check to see if the new installer was used
if (-1 == config_get('database_version', -1)) {
    echo 'Upgrade from the current installed MantisBT version is no longer supported.  If you are using MantisBT version older than 1.0.0, then upgrade to v1.0.0 first.';
    exit(1);
}
# read control variables with defaults
$t_db_type = config_get_global('db_type');
# install the tables
if (!preg_match('/^[a-zA-Z0-9_]+$/', $t_db_type) || !file_exists(dirname(dirname(__FILE__)) . '/library/adodb/drivers/adodb-' . $t_db_type . '.inc.php')) {
    echo 'Invalid db type ' . htmlspecialchars($t_db_type) . '.';
    exit;
}
예제 #12
0
			Upgrade Installation
		</td>
	</tr>
</table>
<br /><br />
<p>Opening connection to database [<?php 
    echo config_get_global('database_name');
    ?>
] on host [<?php 
    echo config_get_global('hostname');
    ?>
] with username [<?php 
    echo config_get_global('db_username');
    ?>
] failed ( <?php 
    echo db_error_msg();
    ?>
 ).</p>
</body>
<?php 
    exit;
}
# check to see if the new installer was used
if (-1 != config_get('database_version', -1)) {
    if (OFF == $g_use_iis) {
        header('Status: 302');
    }
    header('Content-Type: text/html');
    if (ON == $g_use_iis) {
        header("Refresh: 0;url=install.php");
    } else {