function cw_file_area_delete_list($type, $id, $field = 'customer_id')
{
    global $tables;
    $list = cw_query_column("select file_id from " . $tables[$type] . " where {$field}='{$id}'");
    if (is_array($list)) {
        foreach ($list as $v) {
            cw_file_area_delete($type, $v);
        }
    }
}
<?php

if ($action == 'delete' && is_array($del)) {
    cw_load('file_area');
    foreach ($del as $file_id => $v) {
        cw_file_area_delete('customers_letters', $file_id);
    }
    cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}");
}
if ($action == 'upload') {
    cw_load('file_area');
    $data = array();
    $data['file_path'] = cw_move_uploaded_file('userfile');
    $data['filename'] = basename($_FILES['userfile']['name']);
    if ($data['file_path']) {
        cw_file_area_save('customers_letters', $user, $data);
    }
    cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}");
}
$search =& cw_session_register('search');
if (isset($_GET['substring'])) {
    $search['letters']['substring'] = $substring;
}
if (isset($_GET['fromdate'])) {
    $search['letters']['fromdate'] = cw_core_strtotime($fromdate);
}
if (isset($_GET['dateto'])) {
    $search['letters']['todate'] = cw_core_strtotime($todate) + 86399;
}
$conditions = '';
$data = $search['letters'];
<?php

if ($action == 'delete' && is_array($del)) {
    cw_load('file_area');
    foreach ($del as $file_id => $v) {
        cw_file_area_delete('customers_generated_docs', $file_id);
    }
    cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}");
}
if ($action == 'upload') {
    cw_load('file_area');
    $data = array();
    $data['file_path'] = cw_move_uploaded_file('userfile');
    $data['filename'] = basename($_FILES['userfile']['name']);
    $data['descr'] = $descr;
    if ($data['file_path']) {
        cw_file_area_save('customers_generated_docs', $user, $data);
    }
    cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}");
}
$search =& cw_session_register('search');
if (isset($_GET['substring'])) {
    $search['generated_docs']['substring'] = $substring;
}
if (isset($_GET['fromdate'])) {
    $search['generated_docs']['fromdate'] = cw_core_strtotime($fromdate);
}
if (isset($_GET['dateto'])) {
    $search['generated_docs']['todate'] = cw_core_strtotime($todate) + 86399;
}
$conditions = '';
        if (count($_FILES)) {
            foreach ($_FILES['enfiles']['name'] as $index => $name) {
                $data = array();
                $data['file_path'] = cw_move_uploaded_file('enfiles', '', $index);
                $data['filename'] = basename($name);
                if ($data['file_path']) {
                    cw_file_area_save('accounting_records_files', $record_id, $data);
                }
            }
        }
        cw_session_unregister('record_saved_data');
        cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}&record_id={$record_id}");
    }
    if ($action == 'delete_enfile' && $file_id) {
        $record_id = cw_query_first_cell("select customer_id from {$tables['accounting_records_files']} where file_id='{$file_id}'");
        cw_file_area_delete('accounting_records_files', $file_id);
        cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}&record_id={$record_id}");
    }
    if ($record_saved_data) {
        $record = array_merge($record, $record_saved_data);
        cw_session_unregister('record_saved_data');
    }
    $smarty->assign('record', $record);
    $smarty->assign('mode', $mode);
    $smarty->assign('main', 'transaction');
} else {
    cw_session_register('search_data', array());
    $data = array();
    $data['customer_id'] = $user;
    if (isset($fromdate)) {
        $data['start'] = $fromdate;