indvdum@0: add_lang(array('mcp', 'acp/posting')); indvdum@0: indvdum@0: // Set up general vars indvdum@0: $action = request_var('action', ''); indvdum@0: $submit = (isset($_POST['submit'])) ? true : false; indvdum@0: $reason_id = request_var('id', 0); indvdum@0: indvdum@0: $this->tpl_name = 'acp_reasons'; indvdum@0: $this->page_title = 'ACP_REASONS'; indvdum@0: indvdum@0: $form_name = 'acp_reason'; indvdum@0: add_form_key('acp_reason'); indvdum@0: indvdum@0: $error = array(); indvdum@0: indvdum@0: switch ($action) indvdum@0: { indvdum@0: case 'add': indvdum@0: case 'edit': indvdum@0: indvdum@0: $reason_row = array( indvdum@0: 'reason_title' => utf8_normalize_nfc(request_var('reason_title', '', true)), indvdum@0: 'reason_description' => utf8_normalize_nfc(request_var('reason_description', '', true)), indvdum@0: ); indvdum@0: indvdum@0: if ($submit) indvdum@0: { indvdum@0: if (!check_form_key($form_name)) indvdum@0: { indvdum@0: $error[] = $user->lang['FORM_INVALID']; indvdum@0: } indvdum@0: // Reason specified? indvdum@0: if (!$reason_row['reason_title'] || !$reason_row['reason_description']) indvdum@0: { indvdum@0: $error[] = $user->lang['NO_REASON_INFO']; indvdum@0: } indvdum@0: indvdum@0: $check_double = ($action == 'add') ? true : false; indvdum@0: indvdum@0: if ($action == 'edit') indvdum@0: { indvdum@0: $sql = 'SELECT reason_title indvdum@0: FROM ' . REPORTS_REASONS_TABLE . " indvdum@0: WHERE reason_id = $reason_id"; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $row = $db->sql_fetchrow($result); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (strtolower($row['reason_title']) == 'other' || strtolower($reason_row['reason_title']) == 'other') indvdum@0: { indvdum@0: $reason_row['reason_title'] = 'other'; indvdum@0: } indvdum@0: indvdum@0: if ($row['reason_title'] != $reason_row['reason_title']) indvdum@0: { indvdum@0: $check_double = true; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // Check for same reason if adding it... indvdum@0: if ($check_double) indvdum@0: { indvdum@0: $sql = 'SELECT reason_id indvdum@0: FROM ' . REPORTS_REASONS_TABLE . " indvdum@0: WHERE reason_title = '" . $db->sql_escape($reason_row['reason_title']) . "'"; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $row = $db->sql_fetchrow($result); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if ($row || ($action == 'add' && strtolower($reason_row['reason_title']) == 'other')) indvdum@0: { indvdum@0: $error[] = $user->lang['REASON_ALREADY_EXIST']; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if (!sizeof($error)) indvdum@0: { indvdum@0: // New reason? indvdum@0: if ($action == 'add') indvdum@0: { indvdum@0: // Get new order... indvdum@0: $sql = 'SELECT MAX(reason_order) as max_reason_order indvdum@0: FROM ' . REPORTS_REASONS_TABLE; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $max_order = (int) $db->sql_fetchfield('max_reason_order'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $sql_ary = array( indvdum@0: 'reason_title' => (string) $reason_row['reason_title'], indvdum@0: 'reason_description' => (string) $reason_row['reason_description'], indvdum@0: 'reason_order' => $max_order + 1 indvdum@0: ); indvdum@0: indvdum@0: $db->sql_query('INSERT INTO ' . REPORTS_REASONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); indvdum@0: indvdum@0: $log = 'ADDED'; indvdum@0: } indvdum@0: else if ($reason_id) indvdum@0: { indvdum@0: $sql_ary = array( indvdum@0: 'reason_title' => (string) $reason_row['reason_title'], indvdum@0: 'reason_description' => (string) $reason_row['reason_description'], indvdum@0: ); indvdum@0: indvdum@0: $db->sql_query('UPDATE ' . REPORTS_REASONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' indvdum@0: WHERE reason_id = ' . $reason_id); indvdum@0: indvdum@0: $log = 'UPDATED'; indvdum@0: } indvdum@0: indvdum@0: add_log('admin', 'LOG_REASON_' . $log, $reason_row['reason_title']); indvdum@0: trigger_error($user->lang['REASON_' . $log] . adm_back_link($this->u_action)); indvdum@0: } indvdum@0: } indvdum@0: else if ($reason_id) indvdum@0: { indvdum@0: $sql = 'SELECT * indvdum@0: FROM ' . REPORTS_REASONS_TABLE . ' indvdum@0: WHERE reason_id = ' . $reason_id; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $reason_row = $db->sql_fetchrow($result); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$reason_row) indvdum@0: { indvdum@0: trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $l_title = ($action == 'edit') ? 'EDIT' : 'ADD'; indvdum@0: indvdum@0: $translated = false; indvdum@0: indvdum@0: // If the reason is defined within the language file, we will use the localized version, else just use the database entry... indvdum@0: if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])])) indvdum@0: { indvdum@0: $translated = true; indvdum@0: } indvdum@0: indvdum@0: $template->assign_vars(array( indvdum@0: 'L_TITLE' => $user->lang['REASON_' . $l_title], indvdum@0: 'U_ACTION' => $this->u_action . "&id=$reason_id&action=$action", indvdum@0: 'U_BACK' => $this->u_action, indvdum@0: 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', indvdum@0: indvdum@0: 'REASON_TITLE' => $reason_row['reason_title'], indvdum@0: 'REASON_DESCRIPTION' => $reason_row['reason_description'], indvdum@0: indvdum@0: 'TRANSLATED_TITLE' => ($translated) ? $user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])] : '', indvdum@0: 'TRANSLATED_DESCRIPTION'=> ($translated) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])] : '', indvdum@0: indvdum@0: 'S_AVAILABLE_TITLES' => implode(', ', array_map('htmlspecialchars', array_keys($user->lang['report_reasons']['TITLE']))), indvdum@0: 'S_EDIT_REASON' => true, indvdum@0: 'S_TRANSLATED' => $translated, indvdum@0: 'S_ERROR' => (sizeof($error)) ? true : false, indvdum@0: ) indvdum@0: ); indvdum@0: indvdum@0: return; indvdum@0: break; indvdum@0: indvdum@0: case 'delete': indvdum@0: indvdum@0: $sql = 'SELECT * indvdum@0: FROM ' . REPORTS_REASONS_TABLE . ' indvdum@0: WHERE reason_id = ' . $reason_id; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $reason_row = $db->sql_fetchrow($result); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$reason_row) indvdum@0: { indvdum@0: trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING); indvdum@0: } indvdum@0: indvdum@0: if (strtolower($reason_row['reason_title']) == 'other') indvdum@0: { indvdum@0: trigger_error($user->lang['NO_REMOVE_DEFAULT_REASON'] . adm_back_link($this->u_action), E_USER_WARNING); indvdum@0: } indvdum@0: indvdum@0: // Let the deletion be confirmed... indvdum@0: if (confirm_box(true)) indvdum@0: { indvdum@0: $sql = 'SELECT reason_id indvdum@0: FROM ' . REPORTS_REASONS_TABLE . " indvdum@0: WHERE LOWER(reason_title) = 'other'"; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $other_reason_id = (int) $db->sql_fetchfield('reason_id'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: switch ($db->sql_layer) indvdum@0: { indvdum@0: // The ugly one! indvdum@0: case 'mysqli': indvdum@0: case 'mysql4': indvdum@0: case 'mysql': indvdum@0: // Change the reports using this reason to 'other' indvdum@0: $sql = 'UPDATE ' . REPORTS_TABLE . ' indvdum@0: SET reason_id = ' . $other_reason_id . ", report_text = CONCAT('" . $db->sql_escape($reason_row['reason_description']) . "\n\n', report_text) indvdum@0: WHERE reason_id = $reason_id"; indvdum@0: break; indvdum@0: indvdum@0: // Standard? What's that? indvdum@0: case 'mssql': indvdum@0: case 'mssql_odbc': indvdum@0: case 'mssqlnative': indvdum@0: // Change the reports using this reason to 'other' indvdum@0: $sql = "DECLARE @ptrval binary(16) indvdum@0: indvdum@0: SELECT @ptrval = TEXTPTR(report_text) indvdum@0: FROM " . REPORTS_TABLE . " indvdum@0: WHERE reason_id = " . $reason_id . " indvdum@0: indvdum@0: UPDATETEXT " . REPORTS_TABLE . ".report_text @ptrval 0 0 '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' indvdum@0: indvdum@0: UPDATE " . REPORTS_TABLE . ' indvdum@0: SET reason_id = ' . $other_reason_id . " indvdum@0: WHERE reason_id = $reason_id"; indvdum@0: break; indvdum@0: indvdum@0: // Teh standard indvdum@0: case 'postgres': indvdum@0: case 'oracle': indvdum@0: case 'firebird': indvdum@0: case 'sqlite': indvdum@0: // Change the reports using this reason to 'other' indvdum@0: $sql = 'UPDATE ' . REPORTS_TABLE . ' indvdum@0: SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' || report_text indvdum@0: WHERE reason_id = $reason_id"; indvdum@0: break; indvdum@0: } indvdum@0: $db->sql_query($sql); indvdum@0: indvdum@0: $db->sql_query('DELETE FROM ' . REPORTS_REASONS_TABLE . ' WHERE reason_id = ' . $reason_id); indvdum@0: indvdum@0: add_log('admin', 'LOG_REASON_REMOVED', $reason_row['reason_title']); indvdum@0: trigger_error($user->lang['REASON_REMOVED'] . adm_back_link($this->u_action)); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( indvdum@0: 'i' => $id, indvdum@0: 'mode' => $mode, indvdum@0: 'action' => $action, indvdum@0: 'id' => $reason_id)) indvdum@0: ); indvdum@0: } indvdum@0: indvdum@0: break; indvdum@0: indvdum@0: case 'move_up': indvdum@0: case 'move_down': indvdum@0: indvdum@0: $order = request_var('order', 0); indvdum@0: $order_total = $order * 2 + (($action == 'move_up') ? -1 : 1); indvdum@0: indvdum@0: $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . ' indvdum@0: SET reason_order = ' . $order_total . ' - reason_order indvdum@0: WHERE reason_order IN (' . $order . ', ' . (($action == 'move_up') ? $order - 1 : $order + 1) . ')'; indvdum@0: $db->sql_query($sql); indvdum@0: indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: // By default, check that order is valid and fix it if necessary indvdum@0: $sql = 'SELECT reason_id, reason_order indvdum@0: FROM ' . REPORTS_REASONS_TABLE . ' indvdum@0: ORDER BY reason_order'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: if ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $order = 0; indvdum@0: do indvdum@0: { indvdum@0: ++$order; indvdum@0: indvdum@0: if ($row['reason_order'] != $order) indvdum@0: { indvdum@0: $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . " indvdum@0: SET reason_order = $order indvdum@0: WHERE reason_id = {$row['reason_id']}"; indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: } indvdum@0: while ($row = $db->sql_fetchrow($result)); indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $template->assign_vars(array( indvdum@0: 'U_ACTION' => $this->u_action, indvdum@0: ) indvdum@0: ); indvdum@0: indvdum@0: // Reason count indvdum@0: $sql = 'SELECT reason_id, COUNT(reason_id) AS reason_count indvdum@0: FROM ' . REPORTS_TABLE . ' indvdum@0: GROUP BY reason_id'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: $reason_count = array(); indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $reason_count[$row['reason_id']] = $row['reason_count']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $sql = 'SELECT * indvdum@0: FROM ' . REPORTS_REASONS_TABLE . ' indvdum@0: ORDER BY reason_order ASC'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $translated = false; indvdum@0: $other_reason = ($row['reason_title'] == 'other') ? true : false; indvdum@0: indvdum@0: // If the reason is defined within the language file, we will use the localized version, else just use the database entry... indvdum@0: if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) indvdum@0: { indvdum@0: $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]; indvdum@0: $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]; indvdum@0: indvdum@0: $translated = true; indvdum@0: } indvdum@0: indvdum@0: $template->assign_block_vars('reasons', array( indvdum@0: 'REASON_TITLE' => $row['reason_title'], indvdum@0: 'REASON_DESCRIPTION' => $row['reason_description'], indvdum@0: 'REASON_COUNT' => (isset($reason_count[$row['reason_id']])) ? $reason_count[$row['reason_id']] : 0, indvdum@0: indvdum@0: 'S_TRANSLATED' => $translated, indvdum@0: 'S_OTHER_REASON' => $other_reason, indvdum@0: indvdum@0: 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['reason_id'], indvdum@0: 'U_DELETE' => (!$other_reason) ? $this->u_action . '&action=delete&id=' . $row['reason_id'] : '', indvdum@0: 'U_MOVE_UP' => $this->u_action . '&action=move_up&order=' . $row['reason_order'], indvdum@0: 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&order=' . $row['reason_order']) indvdum@0: ); indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: ?>