Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1392 → Rev 1393

//asterisk-stats/trunk/telbook_categories_update.php
5,29 → 5,58
 
if(array_key_exists('delete', $_POST)) {
$id = $_POST['id'];
$db->begin_transaction();
$db->query_params("update telbook_persons set person_category=NULL"
. " where person_category=$1", array($id));
$db->query_params("delete from telbook_categories_export where category_id=$1", array($id));
$db->query_params("delete from telbook_categories where category_id=$1", array($id));
$db->commit_transaction();
 
header("Location: telbook_categories_list.php");
$g_display->add_text('Information deleted successfully');
}
else if(array_key_exists('update', $_POST)) {
$id = $_POST['id'];
$category_name = $_POST['category_name'];
$category_comment = $_POST['category_comment'];
$category_export_key = ($_POST['category_export_key'] ? $_POST['category_export_key'] : NULL);
elseif(array_key_exists('update', $_POST)) {
$id = $_POST['id'];
$category_name = $_POST['category_name'];
$category_comment = $_POST['category_comment'];
 
$db->begin_transaction();
 
if($id) {
$db->query_params("update telbook_categories set"
. " category_name=$2, category_comment=$3, category_export_key=$4"
. " category_name=$2, category_comment=$3"
. " where category_id=$1",
array($id, $category_name, $category_comment, $category_export_key));
array($id, $category_name, $category_comment));
}
else {
$db->query_params("insert into telbook_categories"
. " (category_name, category_comment, category_export_key) values ($1, $2, $3)",
array($category_name, $category_comment, $category_export_key));
. " (category_name, category_comment) values ($1, $2)",
array($category_name, $category_comment));
 
$db->query("select currval('telbook_categories_category_id_seq')");
if($line = $db->fetch_row_idx()) {
$id = $line[0];
}
}
 
$db->query_params("delete from telbook_categories_export where category_id=$1", array($id));
 
# save entries
foreach($_POST as $key => $value) {
if(substr($key, 0, strlen('export_title-')) == 'export_title-') {
$export_id = substr($key, strlen('export_title-'));
 
if($value) {
$db->query_params("insert into telbook_categories_export"
. " (export_id, category_id, category_export_title)"
. " values ($1, $2, $3)",
array($export_id, $id, $value));
}
}
}
 
$db->commit_transaction();
 
header("Location: telbook_categories_list.php");
$g_display->add_text('Information saved successfully');
}