public static function Delete($id) { global $db_connection; global $link_to_report_images; global $link_to_report_files; global $link_to_logo; $ob = Report::FetchBy(['select_list' => 'id, author_id', 'eq_conds' => ['id' => $id], 'is_unique' => true]); if (Error::IsError($ob)) { return $ob; } if (!$db_connection->query("DELETE FROM `" . self::$table . "` WHERE `id` = " . $id)) { echo $db_connection->error; return 0; } else { removeDirectory($link_to_report_images . $id); removeDirectory($link_to_report_files . $id); $sended = User::FetchBy(['select_list' => 'sended_reports', 'eq_conds' => ['id' => $ob->GetAuthorID()], 'is_unique' => true]); $new_sended = []; foreach ($sended->GetSendedReports() as $key => $repid) { if ($repid != $id) { array_push($new_sended, $repid); } } $rc = $db_connection->query('UPDATE ' . User::$table . ' SET sended_reports = "' . $db_connection->real_escape_string(json_encode($new_sended)) . '" WHERE id = ' . $ob->GetAuthorID()); if (!$rc) { return new Error($db_connection->error, Error::db_error); } $received = User::FetchBy(['select_list' => 'received_reports, id', 'where_addition' => '(received_reports LIKE ("%\\"' . $id . '\\"%"))']); if (Error::IsError($received)) { return $received; } foreach ($received as $key => $user) { $new_received = []; foreach ($user->GetReceivedReports() as $key => $repid) { if ($repid != $id) { array_push($new_received, $repid); } } $rc = $db_connection->query('UPDATE ' . User::$table . ' SET received_reports = "' . $db_connection->real_escape_string(json_encode($new_received)) . '" WHERE id = ' . $user->GetID()); if (!$rc) { return new Error($db_connection->error, Error::db_error); } } return 0; } }
$content .= 'allowedContent: true, });'; $content .= 'CKEDITOR.config.height = 400;'; $content .= '</script>'; $content .= '<div class="row">'; $content .= DialogInputsYesNo('edit', $_POST['type'], $ob_id, Language::Word('save'), Language::Word('cancel')); $content .= '</div>'; $content .= '</form>'; $title = Language::Word('report editing'); $header = $title; } } else { if (!isset($_REQUEST['id'])) { echo 'user id is unset'; exit; } $ob = Report::FetchBy(['eq_conds' => ['id' => $_REQUEST['id']], 'is_unique' => true]); $user_id = GetUserID(); $user = User::FetchBy(['eq_conds' => ['id' => $user_id], 'is_unique' => true, 'select_list' => 'received_reports']); if ($user_id !== $ob->GetAuthorID() && !in_array($ob->GetID(), $user->GetReceivedReports()) && GetUserPrivileges() !== admin_user_id) { $content = AlertMessage('alert-danger', Language::Word('access denied')); } else { $title = ''; $header = ''; $content = ''; $title = Language::Word('report'); $header = htmlspecialchars($ob->GetName()); $content = $ob->ToHTMLAutoFull(GetUserPrivileges()); } } } include_once $link_to_admin_template;
if ($content_type === 'sended_reps') { $target = $sended; } } $limit = $to - $from + 1; if ($content_type != 'all_reps') { $ids = ''; for ($i = 0, $cnt = count($target); $i < $cnt; ++$i) { $ids .= '(id = ' . $target[$i] . ')'; if ($i < $cnt - 1) { $ids .= ' OR'; } } $reports = Report::FetchBy(['where_addition' => $ids, 'limit' => $limit, 'offset' => $from, 'order_by' => 'id DESC']); } else { $reports = Report::FetchBy(['limit' => $limit, 'offset' => $from, 'order_by' => 'id DESC']); } for ($i = 0; $i < $limit; ++$i) { $content .= $reports[$i]->ToHTMLAutoShortForTable(GetUserPrivileges()); } $content .= '</tbody>'; $content .= '</table>'; $content .= '</div>'; $content .= '</div>'; require $link_to_pagination_show_template; $content .= $pagination; } else { $content .= ToPageHeader(Language::Word('absense'), "h3", "black"); } default: break;