/** * Article::saveupdatePeriod * * Save period as new or update existing one * * @access public * @since 2004-12-13 * @author Christian Ehret <*****@*****.**> */ function saveupdatePeriod() { global $gDatabase, $request, $tbl_period, $tbl_bararticle, $errorhandler; $periodid = $request->GetVar('frm_theperiodid', 'post'); $active = false; $auto_commit = false; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); if ($request->GetVar('frm_periodact', 'post') == 'true') { $active = true; $query = sprintf("UPDATE {$tbl_period} SET \n\t\t\t\t\t\t\t active = %s,\n\t\t\t\t\t\t\t updated_date = NOW(), \n\t\t\t\t\t\t\t fk_updated_user_id = %s ", MetabaseGetBooleanFieldValue($gDatabase, false), $request->GetVar('uid', 'session')); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Article::saveupdatePeriod()', $query); } } // update if ($periodid !== '-1') { $query = sprintf("UPDATE {$tbl_period} SET \n\t\t\t period = %s, \n\t\t\t\t\t\t\t active = %s,\n\t\t\t\t\t\t\t updated_date = NOW(), \n\t\t\t\t\t\t\t fk_updated_user_id = %s \n\t\t\t\t\t\t\t WHERE pk_period_id = %s ", MetabaseGetTextFieldValue($gDatabase, $request->GetVar('frm_perioddesc', 'post')), MetabaseGetBooleanFieldValue($gDatabase, $active), $request->GetVar('uid', 'session'), $periodid); } else { // new $name = "zvs_pk_period_id"; $sequence = MetabaseGetSequenceNextValue($gDatabase, $name, &$periodid); $query = sprintf("INSERT INTO {$tbl_period}\n\t\t\t (pk_period_id, period, active, inserted_date, fk_inserted_user_id, updated_date, fk_updated_user_id)\n\t\t\t\t\t\t\t VALUES (%s, %s, %s, NOW(), %s, NULL, NULL )", $periodid, MetabaseGetTextFieldValue($gDatabase, $request->GetVar('frm_perioddesc', 'post')), MetabaseGetBooleanFieldValue($gDatabase, $active), $request->GetVar('uid', 'session')); } $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Article::saveupdatePeriod()', $query); } else { if ($request->GetVar('frm_cpyperiod', 'post') != -1) { $query = "SELECT fk_bararticlecat_id, description, price, hotkey\n\t\t\t\t\t FROM {$tbl_bararticle} \n\t\t\t\t\t WHERE ISNULL(deleted_date) AND\n\t\t\t\t\t fk_period_id = " . $request->GetVar('frm_cpyperiod', 'post'); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Article::saveupdatePeriod()', $query); } for ($row = 0; ($eor = MetabaseEndOfResult($gDatabase, $result)) == 0; ++$row) { $name = "zvs_pk_bararticle_id"; $sequence = MetabaseGetSequenceNextValue($gDatabase, $name, &$bararticleid); $query = sprintf("INSERT INTO {$tbl_bararticle} \n\t\t\t\t\t (pk_bararticle_id, fk_period_id, fk_bararticlecat_id,\n\t\t\t\t\t\t\t description, price, hotkey, inserted_date, \n\t\t\t\t\t\t\t fk_inserted_user_id)\n\t\t\t\t\t\t\t VALUES (%s, %s, %s, %s, %s, %s, NOW(), %s) ", $bararticleid, $periodid, MetabaseFetchResult($gDatabase, $result, $row, 0), MetabaseGetTextFieldValue($gDatabase, MetabaseFetchResult($gDatabase, $result, $row, 1)), MetabaseGetTextFieldValue($gDatabase, MetabaseFetchResult($gDatabase, $result, $row, 2)), MetabaseGetTextFieldValue($gDatabase, MetabaseFetchResult($gDatabase, $result, $row, 3)), $request->GetVar('uid', 'session')); $result2 = MetabaseQuery($gDatabase, $query); if (!$result2) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Article::saveupdatePeriod()', $query); } } } $success = MetabaseCommitTransaction($gDatabase); // end transaction $auto_commit = true; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); } return $periodid; }
/** * Guest::shareaddress() * * share address * * @param string $shareid address id and type of source * @param number $guestid address id * @param string $type type of aim * @access public * @since 2005-08-20 * @author Christian Ehret <*****@*****.**> */ function shareaddress($shareid, $guestid, $type) { global $gDatabase, $tbl_guest_address, $tbl_address, $errorhandler; $sharetype = substr($shareid, 0, 1); $shareid = substr($shareid, 2); $type = ucfirst(substr($type, 0, 1)); $auto_commit = false; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); $query = sprintf("SELECT pk_fk_address_id FROM {$tbl_guest_address}\n\t\t WHERE pk_fk_guest_id = %s\n\t\t\t\t\t\t AND address_type = %s ", $guestid, MetabaseGetTextFieldValue($gDatabase, $type)); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Guest::shareaddress()', $query); } $oldaddressid = MetabaseFetchResult($gDatabase, $result, 0, 0); $query = sprintf("SELECT pk_fk_address_id FROM {$tbl_guest_address}\n\t\t WHERE pk_fk_guest_id = %s\n\t\t\t\t\t\t AND address_type = %s ", $shareid, MetabaseGetTextFieldValue($gDatabase, $sharetype)); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Guest::shareaddress()', $query); } $newaddressid = MetabaseFetchResult($gDatabase, $result, 0, 0); if ($oldaddressid) { $query = sprintf("UPDATE {$tbl_guest_address} ga \n\t\t SET pk_fk_address_id = %s \n\t\t\t\t\t\t WHERE pk_fk_guest_id = %s \n\t\t\t\t\t\t AND address_type = %s", $newaddressid, $guestid, MetabaseGetTextFieldValue($gDatabase, $type)); } else { $query = sprintf("INSERT INTO {$tbl_guest_address} \n\t\t\t\t\t\t (pk_fk_guest_id, pk_fk_address_id, address_type) \n\t\t\t\t\t\t VALUES (%s, %s, %s)", $guestid, $newaddressid, MetabaseGetTextFieldValue($gDatabase, $type)); } $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Guest::shareaddress()', $query); } if ($oldaddressid) { // check if address is used more than this time $query = "SELECT count( * ) FROM {$tbl_guest_address} \n\t\t\t WHERE pk_fk_address_id = {$oldaddressid}"; $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Guest::shareaddress()', $query); } else { $count = MetabaseFetchResult($gDatabase, $result, 0, 0); } if ($count == 0) { $query = sprintf("DELETE FROM {$tbl_address} \n\t\t\t\t\t\t WHERE pk_address_id = %s", $oldaddressid, MetabaseGetTextFieldValue($gDatabase, $type)); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Guest::shareaddress()', $query); } } } $success = MetabaseCommitTransaction($gDatabase); // end transaction $auto_commit = true; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); }
if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'database', $query); } $success = splitSqlFile($queries, $sql); for ($i = 0; $i < count($queries); ++$i) { if (substr($queries[$i], 0, 3) == "USE") { $query = "USE {$schema}"; } else { $query = $queries[$i]; } $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'database', $query); } } $query = "SET FOREIGN_KEY_CHECKS = 0"; $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'database', $query); } $success = MetabaseCommitTransaction($gDatabase); // end transaction $auto_commit = true; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); $smarty->assign('tpl_ready', 'true'); } } $smarty->display('database.tpl');
$data["access_date"] = MetabaseToday(); $data["access_time"] = MetabaseTime(); $data["approved"] = MetabaseNow(); if (!InsertTestValues($database, $prepared_query, $data) || !MetabaseRollbackTransaction($database) || !($result = MetabaseQuery($database, "SELECT * FROM users"))) { $success = 0; } else { if (!MetabaseEndOfResult($database, $result)) { $pass = 0; echo "FAILED!{$eol}"; $failed++; echo "Test {$test}: transaction rollback did not revert the row that was inserted{$eol}"; } MetabaseFreeResult($database, $result); } if ($success && $pass) { if (!InsertTestValues($database, $prepared_query, $data) || !MetabaseCommitTransaction($database) || !($result = MetabaseQuery($database, "SELECT * FROM users"))) { $success = 0; } else { if (MetabaseEndOfResult($database, $result)) { $pass = 0; echo "FAILED!{$eol}"; $failed++; echo "Test {$test}: transaction commit did not make permanent the row that was inserted{$eol}"; } MetabaseFreeResult($database, $result); } } if ($success && $pass) { if (!($result = MetabaseQuery($database, "DELETE FROM users"))) { $success = 0; }
/** * price::save() * * save prices for a season * * @access public * @since 2004-01-01 * @author Christian Ehret <*****@*****.**> */ function save() { global $gDatabase, $request, $tbl_price, $tbl_price2, $errorhandler, $rcat, $bcat; // turn on Transaction Control $auto_commit = false; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); $seasonids = array(); $seasonids = $request->getVar('frm_seasonid', 'post'); $bcats = $bcat->Get(); $rcats = $rcat->get('N'); $rcats2 = $rcat->get('A'); for ($i = 0; $i < count($seasonids); $i++) { // delete all old entries for the season for price normal $query = sprintf("DELETE FROM {$tbl_price} WHERE fk_season_id = %s", $seasonids[$i]); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Price::save()', $query); } // delete all old entries for the season for price advanced $query = sprintf("DELETE FROM {$tbl_price2} WHERE fk_season_id = %s", $seasonids[$i]); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Price::save()', $query); } // insert new values for ($j = 0; $j < count($bcats); $j++) { for ($k = 0; $k < count($rcats); $k++) { $frmperson = "frm_price_adult_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmperson_short = "frm_price_adult_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmchildren = "frm_price_child_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmchildren_short = "frm_price_child_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmchildren2 = "frm_price_child2_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmchildren2_short = "frm_price_child2_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmchildren3 = "frm_price_child3_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmchildren3_short = "frm_price_child3_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmabsolute = "frm_price_pausch_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmabsolute_short = "frm_price_pausch_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $frmtype = "frm_type_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats[$k][catid]; $priceperson = 0.0; $pricepersonshort = 0.0; $pricechildren = 0.0; $pricechildrenshort = 0.0; $pricechildren2 = 0.0; $pricechildren2short = 0.0; $pricechildren3 = 0.0; $pricechildren3short = 0.0; if ($request->GetVar($frmperson, 'post') !== "") { $priceperson = $request->GetVar($frmperson, 'post'); } if ($request->GetVar($frmperson_short, 'post') !== "") { $pricepersonshort = $request->GetVar($frmperson_short, 'post'); } if ($request->GetVar($frmchildren, 'post') !== "") { $pricechildren = $request->GetVar($frmchildren, 'post'); } if ($request->GetVar($frmchildren_short, 'post') !== "") { $pricechildrenshort = $request->GetVar($frmchildren_short, 'post'); } if ($request->GetVar($frmchildren2, 'post') !== "") { $pricechildren2 = $request->GetVar($frmchildren2, 'post'); } if ($request->GetVar($frmchildren2_short, 'post') !== "") { $pricechildren2short = $request->GetVar($frmchildren2_short, 'post'); } if ($request->GetVar($frmchildren3, 'post') !== "") { $pricechildren3 = $request->GetVar($frmchildren3, 'post'); } if ($request->GetVar($frmchildren3_short, 'post') !== "") { $pricechildren3short = $request->GetVar($frmchildren3_short, 'post'); } $name = "zvs_pk_price_id"; $sequence = MetabaseGetSequenceNextValue($gDatabase, $name, &$priceid); $query = sprintf("INSERT INTO {$tbl_price}\n\t\t\t\t\t\t\t\t (pk_price_id, fk_roomcat_id, fk_bookingcat_id,\n\t\t\t\t\t\t\t\t fk_season_id, price_person, price_children, \n\t\t\t\t\t\t\t\t price_type, inserted_date, fk_inserted_user_id, \n\t\t\t\t\t\t\t\t price_person_short, price_children_short,\n\t\t\t\t\t\t\t\t price_children2, price_children2_short, price_children3, price_children3_short) \n\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t (%s, %s, %s, %s, %s, %s, %s, NOW(), %s, %s, %s, %s, %s, %s, %s) ", $priceid, $rcats[$k][catid], $bcats[$j][bcatid], $seasonids[$i], $priceperson, $pricechildren, MetabaseGetTextFieldValue($gDatabase, 'PP'), $request->GetVar('uid', 'session'), $pricepersonshort, $pricechildrenshort, $pricechildren2, $pricechildren2short, $pricechildren3, $pricechildren3short); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Price::save()', $query); } } for ($k = 0; $k < count($rcats2); $k++) { $frmprice = "frm_price_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats2[$k][catid]; $frmprice_short = "frm_price_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats2[$k][catid]; $frmperson = "frm_person_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats2[$k][catid]; $frmadditional = "frm_additional_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats2[$k][catid]; $frmadditional_short = "frm_additional_short_" . $seasonids[$i] . "_" . $bcats[$j][bcatid] . "_" . $rcats2[$k][catid]; $price = 0.0; $priceshort = 0.0; $additional = 0.0; $additionalshort = 0.0; if ($request->GetVar($frmprice, 'post') !== "") { $price = $request->GetVar($frmprice, 'post'); } if ($request->GetVar($frmprice_short, 'post') !== "") { $priceshort = $request->GetVar($frmprice_short, 'post'); } if ($request->GetVar($frmadditional, 'post') !== "") { $additional = $request->GetVar($frmadditional, 'post'); } if ($request->GetVar($frmadditional_short, 'post') !== "") { $additionalshort = $request->GetVar($frmadditional_short, 'post'); } $name = "zvs_pk_price2_id"; $sequence = MetabaseGetSequenceNextValue($gDatabase, $name, &$priceid); $query = sprintf("INSERT INTO {$tbl_price2}\n\t\t\t\t\t\t\t\t (pk_price2_id, fk_roomcat_id, fk_bookingcat_id,\n\t\t\t\t\t\t\t\t fk_season_id, price, price_short, \n\t\t\t\t\t\t\t\t persons_included, price_additional, price_short_additional,\n\t\t\t\t\t\t\t\t inserted_date, fk_inserted_user_id) \n\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t (%s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), %s) ", $priceid, $rcats2[$k][catid], $bcats[$j][bcatid], $seasonids[$i], $price, $priceshort, MetabaseGetTextFieldValue($gDatabase, $request->GetVar($frmperson, 'post')), $additional, $additionalshort, $request->GetVar('uid', 'session')); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Price::save()', $query); } } } } $success = MetabaseCommitTransaction($gDatabase); // end transaction $auto_commit = true; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); }
/** * price::deletedraft() * * delete draft receipt * * @param number $draftreceiptid draft receipt id * @param boolean $transc transaction control * @access public * @since 2004-04-18 * @author Christian Ehret <*****@*****.**> */ function deletedraft($draftreceiptid, $transc) { global $gDatabase, $tbl_draftreceipt, $tbl_draftreceipt_booking, $tbl_draftreceipt_item, $errorhandler, $request; if ($transc) { $auto_commit = false; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); } $query = "DELETE FROM {$tbl_draftreceipt_item} WHERE fk_draftreceipt_id = " . $draftreceiptid; $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Receipt::deletedraft()', $query); } $query = "DELETE FROM {$tbl_draftreceipt_booking} WHERE pk_fk_draftreceipt_id = " . $draftreceiptid; $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Receipt::deletedraft()', $query); } $query = "DELETE FROM {$tbl_draftreceipt} WHERE pk_draftreceipt_id = " . $draftreceiptid; $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Receipt::deletedraft()', $query); } else { if ($transc) { $success = MetabaseCommitTransaction($gDatabase); // end transaction $auto_commit = true; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); } } }
if ($success && $pass) { $passed++; echo "OK.{$eol}"; } } } else { echo "Transactions are not supported.{$eol}"; } } if (isset($tests["nestedtransactions"]) && $success) { if (MetabaseSupport($database, "Transactions")) { $test = "transactions"; echo "Testing nested transactions... "; flush(); $pass = 1; if (!MetabaseAutoCommitTransactions($database, 0) || !MetabaseAutoCommitTransactions($database, 0) || !MetabaseCommitTransaction($database) || !MetabaseAutoCommitTransactions($database, 1) || !MetabaseRollbackTransaction($database) || !MetabaseAutoCommitTransactions($database, 1)) { $success = 0; } if ($success && $pass) { $passed++; echo "OK.{$eol}"; } } else { echo "Transactions are not supported.{$eol}"; } } if (MetabaseSupport($database, "PatternBuild") && isset($tests["patterns"]) && $success) { $test = "patterns"; echo "Testing queries with pattern matching conditions... "; $values = array(1 => "%end", 2 => "begin%end", 3 => "begin%", 4 => "beginend", 5 => "_end", 6 => "begin_end", 7 => "begin_", 8 => "beginend", 9 => " _@%\\ ]['?*"); flush();
/** * Booking::deloldreservation() * * This function marks an old reservation as deleted * * @param number $bookingid booking id * @access public * @since 2004-02-07 * @author Christian Ehret <*****@*****.**> */ function deloldreservation($bookingid) { global $tbl_booking, $tbl_booking_detail, $gDatabase, $request, $errorhandler; // transaction control $auto_commit = false; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); $query = sprintf("UPDATE {$tbl_booking} \n\t\t SET deleted_date = NOW(), \n\t\t\t\t\t\t fk_deleted_user_id = %s \n\t\t\t\t\t\t WHERE pk_booking_id = %s ", 1, MetabaseGetTextFieldValue($gDatabase, $bookingid)); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Booking::deloldreservation()', $query); } else { $query = sprintf("UPDATE {$tbl_booking_detail} \n\t\t\t\t\t\t\t SET deleted_date = NOW(), \n\t\t\t\t\t\t\t fk_deleted_user_id = %s \n\t\t\t\t\t\t\t WHERE fk_booking_id = %s ", 1, MetabaseGetTextFieldValue($gDatabase, $bookingid)); $result = MetabaseQuery($gDatabase, $query); if (!$result) { $success = MetabaseRollbackTransaction($gDatabase); $errorhandler->display('SQL', 'Booking::deloldreservation()', $query); } else { $success = MetabaseCommitTransaction($gDatabase); // end transaction $auto_commit = true; $success = MetabaseAutoCommitTransactions($gDatabase, $auto_commit); } } }