$result_attach = $db->query('SELECT af.owner,ar.rules FROM ' . $db->prefix . 'attach_2_files AS af, ' . $db->prefix . 'attach_2_rules AS ar, ' . $db->prefix . 'posts AS p, ' . $db->prefix . 'topics AS t WHERE af.id=\'' . $attach_id . '\' AND ar.group_id=\'' . $pun_user['g_id'] . '\' AND ar.forum_id=t.forum_id AND t.id=p.topic_id AND p.id=af.post_id LIMIT 1') or error('Unable to fetch attachment details and forum rules', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result_attach) > 0 || $pun_user['g_id'] == PUN_ADMIN) { list($attach_cur_owner, $attach_rules) = $db->fetch_row($result_attach); $attach_allowed = false; if ($pun_user['g_id'] == PUN_ADMIN) { //admin overrides $attach_allowed = true; } elseif ($attach_cur_owner == $pun_user['id']) { //it's the owner of the file that want to delete it $attach_allowed = attach_rules($attach_rules, ATTACH_OWNER_DELETE); } else { //it's not the owner that wants to delete the attachment... $attach_allowed = attach_rules($attach_rules, ATTACH_DELETE); } if ($attach_allowed) { if (!attach_delete_attachment($attach_id)) { // uncomment if you want to show error if it fails to delete //error('Unable to delete attachment.'); } } else { // the user may not delete it ... uncomment the error if you want to use it ... //error('You\'re not allowed to delete the attachment'); } } else { // the user probably hasn't any rules in this forum any longer... } } } } //Then recieve any potential new files if (isset($_FILES['attached_file']) && $_FILES['attached_file']['size'] != 0 && is_uploaded_file($_FILES['attached_file']['tmp_name'])) {
<?php echo $attach_output; ?> </div> </div> </div> <?php } elseif (isset($_POST['delete_orphans'])) { // search for all orphans, $result_attach = $db->query('SELECT af.id FROM `' . $db->prefix . 'attach_2_files` AS af LEFT JOIN `' . $db->prefix . 'posts` AS p ON p.id=af.post_id WHERE p.id IS NULL') or error('Unable to search for orphans', __FILE__, __LINE__, $db->error()); // if there is any orphans start deleting them one by one... if ($db->num_rows($result_attach) > 0) { // we have orphan(s) $i = 0; while (list($attach_id) = $db->fetch_row($result_attach)) { attach_delete_attachment($attach_id); $i++; } message($i . ' orphan(s) deleted. Shouldn\'t be any orphans left now'); } else { // if there aren't any orphans, tell the user that... message('No orphans found. Yipeee. :)'); } } elseif (isset($_POST['edit_rules']) && isset($_POST['forum'])) { $attach_output = ''; $attach_cur_f_id = intval($_POST['forum']); // first some stuff is things are updated, deleted or created ... after this the normal 'edit_rules' will show ... if (isset($_POST['update_ruleset'])) { // here the update will go ... to update an existing ruleset // calculate the rules $attach_cur_group_rules = 0;