6,6 → 6,8 |
if(array_key_exists('delete', $_POST)) { |
$id = $_POST['id']; |
$db->begin_transaction(); |
$db->query_params("delete from telbook_entries_export where entry_id" |
. " = (select entry_id from telbook_entries where entry_person=$1)", array($id)); |
$db->query_params("delete from telbook_entries where entry_person=$1", array($id)); |
$db->query_params("delete from telbook_persons where person_id=$1", array($id)); |
$db->commit_transaction(); |
38,7 → 40,12 |
} |
} |
|
$db->query_params("delete from telbook_entries_export where entry_id" |
. " = (select entry_id from telbook_entries where entry_person=$1)", array($id)); |
$db->query_params("delete from telbook_entries where entry_person=$1", array($id)); |
|
# save entries |
$entries_id = array(); |
foreach($_POST as $key => $value) { |
if(substr($key, 0, strlen('entry_title-')) == 'entry_title-') { |
$entry_count = substr($key, strlen('entry_title-')); |
52,10 → 59,35 |
. " (entry_value, entry_title, entry_person, entry_comment)" |
. " values ($1, $2, $3, $4)", |
array($entry_value, $entry_title, $id, $entry_comment)); |
|
$db->query("select currval('telbook_entries_entry_id_seq')"); |
if($line = $db->fetch_row_idx()) { |
$entries_id[$entry_count] = $line[0]; |
} |
} |
} |
} |
|
# save entries export targets |
foreach($_POST as $key => $value) { |
if(substr($key, 0, strlen('entry_export-')) == 'entry_export-') { |
$substr_len = strlen('entry_export-'); |
$pos = strpos($key, '-', $substr_len); |
if($pos) { |
$entry_count = substr($key, $substr_len, $pos - $substr_len); |
$export_id = substr($key, $pos+1); |
$entry_id = $entries_id[$entry_count]; |
|
if($export_id && $entry_id) { |
$db->query_params("insert into telbook_entries_export" |
. " (export_id, entry_id)" |
. " values ($1, $2)", |
array($export_id, $entry_id)); |
} |
} |
} |
} |
|
$db->commit_transaction(); |
|
header("Location: telbook_list.php"); |