function fn_sales_report_update_table($table_data, $table_id = 0, $lang_code = DESCR_SL) { if ($table_data['type'] == 'P') { $table_data['interval_id'] = '1'; } if (empty($table_id)) { $table_id = db_query("INSERT INTO ?:sales_reports_tables ?e", $table_data); fn_create_description('sales_reports_table_descriptions', "table_id", $table_id, $table_data); // Create parameters $_data = $table_data['elements']; $_data['table_id'] = $table_id; $_data['report_id'] = $table_data['report_id']; $_data['element_hash'] = fn_generate_element_hash($table_id, $_data['element_id'], ''); db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data); } else { db_query('UPDATE ?:sales_reports_tables SET ?u WHERE table_id = ?i', $table_data, $table_id); db_query('UPDATE ?:sales_reports_table_descriptions SET ?u WHERE table_id = ?i AND lang_code = ?s', $table_data, $table_id, $lang_code); // Update parameters foreach ($table_data['elements'] as $k => $v) { if ($v['element_id'] == '4' && $table_data['interval_id'] != '1') { db_query("UPDATE ?:sales_reports_tables SET interval_id = 1 WHERE table_id = ?i", $table_id); fn_set_notification('W', __('warning'), __('text_status_is_float')); } db_query('UPDATE ?:sales_reports_table_elements SET ?u WHERE table_id = ?i AND element_hash = ?s', $v, $table_id, $k); if ($table_data['type'] != 'T' && $v['limit_auto'] > 25) { db_query("UPDATE ?:sales_reports_table_elements SET limit_auto = 25 WHERE table_id = ?i AND element_hash = ?s", $table_id, $k); fn_set_notification('W', __('warning'), __('text_max_limit_of_parameters')); } } } foreach ($table_data['conditions'] as $section => $ids) { db_query("DELETE FROM ?:sales_reports_table_conditions WHERE table_id = ?i AND code = ?s", $table_id, $section); $object_ids = is_array($ids) ? $ids : (empty($ids) ? array() : explode(',', $ids)); foreach ($object_ids as $o_id) { $data = array('sub_element_id' => $o_id, 'table_id' => $table_id, 'code' => $section); db_query('REPLACE INTO ?:sales_reports_table_conditions ?e', $data); } } return $table_id; }
function fn_report_table_clone($report_id, $table_id) { //tables for report $table_data = db_get_row("SELECT a.*, b.description FROM ?:sales_reports_tables as a LEFT JOIN ?:sales_reports_table_descriptions as b ON a.table_id = b.table_id AND lang_code = ?s WHERE a.table_id = ?i", CART_LANGUAGE, $table_id); $data['report_id'] = $table_data['report_id']; $data['type'] = $table_data['type']; $table_id_new = db_query("INSERT INTO ?:sales_reports_tables ?e", $data); fn_create_description('sales_reports_table_descriptions', "table_id", $table_id_new, array("description" => $table_data["description"] . '[CLONE]')); //Orders element for table $_elements = db_get_array("SELECT a.* FROM ?:sales_reports_table_elements as a WHERE a.report_id = ?i AND a.table_id = ?i AND a.time_interval = 'N' ORDER BY a.position", $report_id, $table_id); foreach ($_elements as $k => $element) { $data = $element; $data['table_id'] = $table_id_new; $data['condition'] = db_get_fields("SELECT ids FROM ?:sales_reports_table_element_conditions WHERE table_id = ?i AND element_hash = ?s", $table_id, $element['element_hash']); $data['element_hash'] = fn_generate_element_hash($table_id_new, $data['element_id'], $data['condition']); $_data = fn_check_table_fields($data, 'sales_reports_table_elements'); db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data); $_cond['table_id'] = $table_id_new; $_cond['element_hash'] = $data['element_hash']; foreach ($data['condition'] as $kk => $value) { $_cond['ids'] = $value; db_query("INSERT INTO ?:sales_reports_table_element_conditions ?e", $_cond); } } //Intervals for table $_intervals = db_get_array("SELECT a.*, b.description FROM ?:sales_reports_table_elements as a WHERE a.report_id = ?i AND a.table_id = ?i AND a.time_interval = 'Y'", $report_id, $table_id); foreach ($_intervals as $k => $interval) { $data = $interval; $data['table_id'] = $table_id_new; $_data = fn_check_table_fields($data, 'sales_reports_table_elements'); db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data); } return $table_id; }
// Add table $table = $_REQUEST['table']; if (empty($table['description'])) { return array(CONTROLLER_STATUS_REDIRECT, "sales_reports.table.add?report_id={$_REQUEST['report_id']}"); } if ($table['type'] == 'P' || $table['type'] == 'C') { $table['interval_id'] = '1'; } $table['report_id'] = $_REQUEST['report_id']; $table_id = db_query("REPLACE INTO ?:sales_reports_tables ?e", $table); fn_create_description('sales_reports_table_descriptions', "table_id", $table_id, array('description' => $table['description'])); // Create parameters $_data = fn_check_table_fields($_REQUEST['update_element'], 'sales_reports_table_elements'); $_data['table_id'] = $table_id; $_data['report_id'] = $_REQUEST['report_id']; $_data['element_hash'] = fn_generate_element_hash($table_id, $_data['element_id'], ''); db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data); foreach ($_REQUEST['conditions'] as $section => $ids) { db_query("DELETE FROM ?:sales_reports_table_conditions WHERE table_id = ?i AND code = ?s", $table_id, $section); $object_ids = is_array($ids) ? $ids : (empty($ids) ? array() : explode(',', $ids)); foreach ($object_ids as $o_id) { $data = array('sub_element_id' => $o_id, 'table_id' => $table_id, 'code' => $section); db_query('REPLACE INTO ?:sales_reports_table_conditions ?e', $data); } } $suffix = ".table.edit?report_id={$_REQUEST['report_id']}&table_id={$table_id}"; } if ($action == 'update') { db_query('UPDATE ?:sales_reports_tables SET ?u WHERE table_id = ?i', $_REQUEST['table'], $_REQUEST['table_id']); db_query('UPDATE ?:sales_reports_table_descriptions SET ?u WHERE table_id = ?i AND lang_code = ?s', $_REQUEST['table'], $_REQUEST['table_id'], DESCR_SL); if ($_REQUEST['table']['type'] == 'P' || $_REQUEST['table']['type'] == 'C') {