$id_report))) !== false; } /** * Deletes a report. * * @param int Report id to be deleted. * * @return bool True if deleted, false otherwise. */ function delete_report ($id_report) { $id_report = safe_int ($id_report); if (empty ($id_report)) return false; $report = get_report ($id_report); if ($report === false) return false; $res1 = @process_sql_delete ('treport_content', array ('id_report' => $id_report)); $res2 = @process_sql_delete ('treport', array ('id_report' => $id_report)); return $res1 && $res2; } /** * Deletes a content from a report. * * @param int Report content id to be deleted. * * @return bool True if deleted, false otherwise. */ function get_report_content ($id_report_content, $filter = false, $fields = false) { $id_report_content = safe_int ($id_report_content); if (empty ($id_report_content)) return false; if (! is_array ($filter)) $filter = array (); if (is_array ($fields)) $fields[] = 'id_report'; $filter['id_rc'] = $id_report_content; $content = @get_db_row_filter ('treport_content', $filter, $fields); if ($content === false) return false; $report = get_report ($content['id_report']); if ($report === false) return false; return $content; } /** * Get all the contents of a report. * * @param int Report id to get contents. * @param array Extra filters for the contents. * @param array Fields to be fetched. All fields by default * * @return array All the contents of a report. */ function create_report_content ($id_report, $values) { $id_report = safe_int ($id_report); if (empty ($id_report)) return false; $report = get_report ($id_report); if ($report === false) return false; if (! is_array ($values)) return false; $values['id_report'] = $id_report; unset ($values['`order`']); $order = (int) get_db_value ('MAX(`order`)', 'treport_content', 'id_report', $id_report); $values['`order`'] = $order + 1; return @process_sql_insert ('treport_content', $values); } /** * Get all the contents of a report. * * @param int Report id to get contents. * @param array Extra filters for the contents. * @param array Fields to be fetched. All fields by default * * @return array All the contents of a report. */ function get_report_contents ($id_report, $filter = false, $fields = false) { $id_report = safe_int ($id_report); if (empty ($id_report)) return array (); $report = get_report ($id_report); if ($report === false) return array (); if (! is_array ($filter)) $filter = array (); $filter['id_report'] = $id_report; $filter['order'] = '`order`'; $contents = get_db_all_rows_filter ('treport_content', $filter, $fields); if ($contents === false) return array (); return $contents; } /** * Moves a content from a report up. * * @param int Report content id to be moved. * * @return bool True if moved, false otherwise. */ function move_report_content_up ($id_report_content) { if (empty ($id_report_content)) return false; $content = get_report_content ($id_report_content); if ($content === false) return false; $order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content); /* Set the previous element order to the current of the content we want to change */ process_sql_update ('treport_content', array ('`order` = `order` + 1'), array ('id_report' => $content['id_report'], '`order` = '.($order - 1))); return (@process_sql_update ('treport_content', array ('`order` = `order` - 1'), array ('id_rc' => $id_report_content))) !== false; } /** * Moves a content from a report up. * * @param int Report content id to be moved. * * @return bool True if moved, false otherwise. */ function move_report_content_down ($id_report_content) { if (empty ($id_report_content)) return false; $content = get_report_content ($id_report_content); if ($content === false) return false; $order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content); /* Set the previous element order to the current of the content we want to change */ process_sql_update ('treport_content', array ('`order` = `order` - 1'), array ('id_report' => (int) $content['id_report'], '`order` = '.($order + 1))); return (@process_sql_update ('treport_content', array ('`order` = `order` + 1'), array ('id_rc' => $id_report_content))) !== false; } /** * Deletes a content from a report. * * @param int Report content id to be deleted. * * @return bool True if deleted, false otherwise. */ function delete_report_content ($id_report_content) { if (empty ($id_report_content)) return false; $content = get_report_content ($id_report_content); if ($content === false) return false; $order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content); process_sql_update ('treport_content', array ('`order` = `order` - 1'), array ('id_report' => (int) $content['id_report'], '`order` > '.$order)); return (@process_sql_delete ('treport_content', array ('id_rc' => $id_report_content))) !== false; } ?>