<?php
##
##
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
require PUN_ROOT.'include/attach/attach_incl.php'; //Attachment Mod row, loads variables, functions and lang file
//
// If we have any input
//
if(isset($_POST['read_documentation'])){ // the user wants to read the documentation, so let him/her do so...
generate_admin_menu($plugin); // Display the admin navigation menu
?>
<?php
}elseif(isset($_POST['list_attachments'])){
if(isset($_POST['start']))
$attach_limit_start = intval($_POST['start']);
else
$attach_limit_start = 0;
if(isset($_POST['number']))
$attach_limit_number = intval($_POST['number']);
else
$attach_limit_number = 50;
if(isset($_POST['auto_increase']))
$attach_auto_increase = (intval($_POST['auto_increase'])==1)?$attach_limit_start+$attach_limit_number:$attach_limit_start;
else
$attach_auto_increase = $attach_limit_start;
if(isset($_POST['direction']))
$attach_result_direction = (intval($_POST['direction'])==1)?'ASC':'DESC';
else
$attach_result_direction = 'ASC';
if(isset($_POST['order']))
switch (intval($_POST['order'])){
case 0:
$attach_result_order = 'id';
break;
case 1:
$attach_result_order = 'downloads';
break;
case 2:
$attach_result_order = 'size';
break;
case 3:
$attach_result_order = 'downloads*size';
break;
default:
$attach_result_order = 'id';
break;
}
else
$attach_result_order = 'id';
$attach_output = '';
//search for all attachments ...
$result = $db->query('SELECT id, owner, post_id, filename, extension, mime, location, size, downloads FROM `'.$db->prefix.'attach_2_files` ORDER BY '.$attach_result_order.' '.$attach_result_direction.' LIMIT '.$attach_limit_start.','.$attach_limit_number.'')or error('Unable to fetch attachments',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)>0){
while(list($attach_id,$attach_owner,$attach_post_id,$attach_filename,$attach_extension,$attach_mime,$attach_location,$attach_size,$attach_downloads)=$db->fetch_row($result)){
$attach_output .= ' <div class="inform">
<fieldset>
<legend>Attachment: ('.$attach_id.') '.$attach_filename.'</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Filename</th>
<td>
<span>'.attach_icon($attach_extension).'"<a href="attachment.php?item='.$attach_id.'">'.$attach_filename.'</a>" Click to view/download.</span>
</td>
</tr>
<tr>
<th scope="row">Filesize</th>
<td>
<span>'.number_format($attach_size).' bytes</span>
</td>
</tr>
<tr>
<th scope="row">Downloads</th>
<td>
<span>'.number_format($attach_downloads).' downloads</span>
</td>
</tr>
<tr>
<th scope="row">Total transfer</th>
<td>
<span>'.number_format($attach_downloads*$attach_size).' bytes</span>
</td>
</tr>
<tr>
<th scope="row">Actions</th>
<td>
<span>
<form name="alter_attachment_id_'.$attach_id.'" method="post" action="'.$_SERVER['REQUEST_URI'].'">
<input class="button" type="Submit" name="delete_attachment" value="Delete attachment" /><input type="hidden" name="attachment_id" value="'.$attach_id.'" />
</form>
</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>';
}
}else
message('No attachments found.');
generate_admin_menu($plugin); // Display the admin navigation menu
?>
<div class="block">
<h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - List attachments</span></h2>
<div class="box">
<div class="inbox">
<div class="inform">
<form name="list_attachments_form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<fieldset>
<legend>Search options</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Start at</th>
<td>
<span><input class="textbox" type="text" name="start" size="3" value="<?php echo $attach_auto_increase; ?>" tabindex="1" /> (Auto increase? <input type="radio" name="auto_increase" value="1" tabindex="2" <?php echo ($attach_auto_increase != $attach_limit_start)?'checked="checked" ':''; ?>/><strong>Yes</strong> <input type="radio" name="auto_increase" value="0" tabindex="3" <?php echo ($attach_auto_increase != $attach_limit_start)?'':'checked="checked" '; ?>/><strong>No</strong>)</span>
</td>
</tr>
<tr>
<th scope="row">Number to show</th>
<td>
<span><input class="textbox" type="text" name="number" size="3" value="<?php echo $attach_limit_number; ?>" tabindex="4" /></span>
</td>
</tr>
<tr>
<th scope="row">Order</th>
<td>
<span><input type="radio" name="order" value="0" tabindex="5" <?php echo ($attach_result_order == 'id')?'checked="checked" ':''; ?>/>ID <input type="radio" name="order" value="1" tabindex="6" <?php echo ($attach_result_order == 'downloads')?'checked="checked" ':''; ?>/>Downloads <input type="radio" name="order" value="2" tabindex="7" <?php echo ($attach_result_order == 'size')?'checked="checked" ':''; ?>/>Size <input type="radio" name="order" value="3" tabindex="8" <?php echo ($attach_result_order == 'downloads*size')?'checked="checked" ':''; ?>/>Total transfer</span>
</td>
</tr>
<tr>
<th scope="row">Direction</th>
<td>
<span><input type="radio" name="direction" value="1" tabindex="9" <?php echo ($attach_result_direction == 'ASC')?'checked="checked" ':''; ?>/>Increasing <input type="radio" name="direction" value="0" tabindex="10" <?php echo ($attach_result_direction == 'DESC')?'checked="checked" ':''; ?>/>Decreasing</span>
</td>
</tr>
</table>
<input class="button" type="submit" name="list_attachments" value="List Attachments" tabindex="11" />
</div>
</fieldset>
</form>
</div>
<?php echo $attach_output; ?>
</div>
</div>
</div>
<?php
}elseif(isset($_POST['delete_orphan'])){
//ok, delte this attachment
if(attach_delete_attachment(intval($_POST['attachment_id'])))
message('Orpahn attachment deleted.');
else
message('Error when deleting orphan. Orphan attachment not deleted.');
}elseif(isset($_POST['delete_attachment'])){
//ok, delete this attachment
if(attach_delete_attachment(intval($_POST['attachment_id'])))
message('Attachment deleted.');
else
message('Error when deleting attachment. Attachment not deleted.');
}elseif(isset($_POST['list_orphans'])){
$attach_output='';
//search if we have any orphans
$result_attach = $db->query('SELECT af.id, af.owner, af.post_id, af.filename, af.extension, af.mime, af.location, af.size, af.downloads 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($db->num_rows($result_attach)>0){// if we have any orphans, output some info
while(list($attach_id,$attach_owner,$attach_post_id,$attach_filename,$attach_extension,$attach_mime,$attach_location,$attach_size,$attach_downloads)=$db->fetch_row($result_attach)){
$attach_output .= '
<div class="inform">
<fieldset>
<legend>Attachment: ('.$attach_id.') '.$attach_filename.'</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Filename</th>
<td>
<span>'.attach_icon($attach_extension).'"<a href="attachment.php?item='.$attach_id.'">'.$attach_filename.'</a>" Click to view/download. (Location on disk: "'.$attach_location.'")</span>
</td>
</tr>
<tr>
<th scope="row">Filesize</th>
<td>
<span>'.number_format($attach_size).' bytes</span>
</td>
</tr>
<tr>
<th scope="row">Downloads</th>
<td>
<span>'.number_format($attach_downloads).' downloads</span>
</td>
</tr>
<tr>
<th scope="row">Total transfer</th>
<td>
<span>'.number_format($attach_downloads*$attach_size).' bytes</span>
</td>
</tr>
<tr>
<th scope="row">Actions</th>
<td>
<span>
<form name="alter_attachment_id_'.$attach_id.'" method="post" action="'.$_SERVER['REQUEST_URI'].'">
<input class="button" type="Submit" name="delete_orphan" value="Delete attachment" /><input type="hidden" name="attachment_id" value="'.$attach_id.'" />
</form>
</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>';
}
}else // if we haven't any orphans, show such a message
message('No orphans found. Yipeee. :)');
generate_admin_menu($plugin); // Display the admin navigation menu
?>
<div class="block">
<h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - List all orphan attachments</span></h2>
<div class="box">
<div class="inbox">
<?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;
$attach_cur_group_rules += (isset($_POST['download']))?ATTACH_DOWNLOAD:0;
$attach_cur_group_rules += (isset($_POST['upload']))?ATTACH_UPLOAD:0;
$attach_cur_group_rules += (isset($_POST['owner_delete']))?ATTACH_OWNER_DELETE:0;
$attach_cur_group_rules += (isset($_POST['delete']))?ATTACH_DELETE:0;
$attach_cur_group_id = intval($_POST['edit_ruleset']);
$attach_cur_group_size = ($pun_config['attach_max_size']>intval($_POST['size']))?intval($_POST['size']):$pun_config['attach_max_size'];
$attach_cur_group_per_post = intval($_POST['per_post']);
$attach_cur_group_file_ext = $db->escape($_POST['file_ext']);
if($attach_cur_group_rules != 0)
$result = $db->query('UPDATE '.$db->prefix.'attach_2_rules SET rules=\''.$attach_cur_group_rules.'\', size=\''.$attach_cur_group_size.'\', per_post=\''.$attach_cur_group_per_post.'\', file_ext=\''.$attach_cur_group_file_ext.'\' WHERE group_id=\''.$attach_cur_group_id.'\' AND forum_id=\''.$attach_cur_f_id.'\' LIMIT 1')or error('Unable to update ruleset for group',__FILE__,__LINE__,$db->error());
else
$result = $db->query('DELETE FROM '.$db->prefix.'attach_2_rules WHERE group_id=\''.$attach_cur_group_id.'\' AND forum_id=\''.$attach_cur_f_id.'\' LIMIT 1')or error('Unable to update/delete ruleset for group',__FILE__,__LINE__,$db->error());
}elseif(isset($_POST['delete_ruleset'])){
// here the deletes will go ... to delete an existing ruleset
$attach_cur_group_id = intval($_POST['edit_ruleset']);
$result = $db->query('DELETE FROM '.$db->prefix.'attach_2_rules WHERE group_id=\''.$attach_cur_group_id.'\' AND forum_id=\''.$attach_cur_f_id.'\' LIMIT 1')or error('Unable to delete ruleset for group',__FILE__,__LINE__,$db->error());
}elseif(isset($_POST['create_ruleset'])){
// here the creates will go ... to create a new ruleset
$attach_cur_group_rules = 0;
$attach_cur_group_rules += (isset($_POST['download']))?ATTACH_DOWNLOAD:0;
$attach_cur_group_rules += (isset($_POST['upload']))?ATTACH_UPLOAD:0;
$attach_cur_group_rules += (isset($_POST['owner_delete']))?ATTACH_OWNER_DELETE:0;
$attach_cur_group_rules += (isset($_POST['delete']))?ATTACH_DELETE:0;
$attach_cur_group_id = intval($_POST['newgroup']);
$attach_cur_group_size = intval($_POST['size']);
$attach_cur_group_per_post = intval($_POST['per_post']);
$attach_cur_group_file_ext = $db->escape($_POST['file_ext']);
if($attach_cur_group_rules != 0)
$result = $db->query('INSERT INTO '.$db->prefix.'attach_2_rules (group_id, forum_id, rules, size, per_post, file_ext) VALUES (\''.$attach_cur_group_id.'\', \''.$attach_cur_f_id.'\', \''.$attach_cur_group_rules.'\', \''.$attach_cur_group_size.'\', \''.$attach_cur_group_per_post.'\', \''.$attach_cur_group_file_ext.'\')')or error('Unable to create ruleset',__FILE__,__LINE__,$db->error());
else
message('You need to allow the group to do anything to add them to the rules for the forum! No new ruleset created.');
}
// and now back to the normal 'edit rules'
$attach_output ='';
$attach_cur_f_id=intval($_POST['forum']);
// generate an array with groupid => groupname (used for matching existing rules, but also for creating new ones...)
$attach_grouparray = array();
$result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE 1 ORDER BY g_id ASC')or error('Unable to fetch usergroups',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
while(list($key,$value) = $db->fetch_row($result)){
$attach_grouparray[$key]=$value;
}
}
// fetch all the info of this forum
$result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$attach_cur_f_id.' LIMIT 1')or error('Unable to fetch forum',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)==0)
error('No such forum found');
list($attach_cur_f_name) = $db->fetch_row($result);
// fetch all existing rules
$attach_rightsarray = array();
$attach_sizearray = array();
$attach_per_postarray = array();
$attach_file_extarray = array();
$result_two = $db->query('SELECT group_id, rules, size, per_post, file_ext FROM '.$db->prefix.'attach_2_rules WHERE forum_id='.$attach_cur_f_id.' ORDER BY group_id')or error('Unable to fetch rights for users in forum',__FILE__,__LINE__,$db->error());
if($db->num_rows($result_two)!=0){
while(list($attach_cur_group_id,$attach_cur_group_rules,$attach_cur_group_size,$attach_cur_group_per_post,$attach_cur_group_file_ext) = $db->fetch_row($result_two)){
$attach_rightsarray[$attach_cur_group_id] = $attach_cur_group_rules;
$attach_sizearray[$attach_cur_group_id] = $attach_cur_group_size;
$attach_per_postarray[$attach_cur_group_id] = $attach_cur_group_per_post;
$attach_file_extarray[$attach_cur_group_id] = $attach_cur_group_file_ext;
}
}
// create output for the existing ones
if(count($attach_rightsarray)!=0){
$attach_output .= '
<h2 class="block2"><span>Existing rules for forum: '.$attach_cur_f_name.'</span></h2>
<div class="box">
<div>
<div class="inform">
';
foreach ($attach_rightsarray as $key => $value){
$attach_cur_group_rules ='<input type="checkbox" name="download" value="1" ';
$attach_cur_group_rules .= (attach_rules($value,ATTACH_DOWNLOAD))?'checked="checked" ':'';
$attach_cur_group_rules .='/>Download <input type="checkbox" name="upload" value="1" ';
$attach_cur_group_rules .= (attach_rules($value,ATTACH_UPLOAD))?'checked="checked" ':'';
$attach_cur_group_rules .='/>Upload <input type="checkbox" name="owner_delete" value="1" ';
$attach_cur_group_rules .= (attach_rules($value,ATTACH_OWNER_DELETE))?'checked="checked" ':'';
$attach_cur_group_rules .='/>Owner Delete <input type="checkbox" name="delete" value="1" ';
$attach_cur_group_rules .= (attach_rules($value,ATTACH_DELETE))?'checked="checked" ':'';
$attach_cur_group_rules .='/>Delete';
$attach_output .= '
<form id="example'.$key.'" name="example'.$key.'" method="post" action="'.$_SERVER['REQUEST_URI'].'">
<fieldset>
<legend>Group: ';
$attach_output .= (array_key_exists($key,$attach_grouparray))? $attach_grouparray[$key]:'(<strong>'.$key.'</strong> Best is to delete this ruleset, no group has it!!!!)';
$attach_output .= '</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Allow</th>
<td>
<span>'.$attach_cur_group_rules.'</span>
</td>
</tr>
<tr>
<th scope="row">Max Upload</th>
<td>
<span><input class="textbox" type="text" name="size" value="'.$attach_sizearray[$key].'" />bytes</span>
</td>
</tr>
<tr>
<th scope="row">Attachments per post</th>
<td>
<input class="textbox" type="text" name="per_post" value="'.$attach_per_postarray[$key].'" />
<span>Here you can increase the allowed number of attachments per post. (To add more attachments to a post the user needs to edit the message.)</span>
</td>
</tr>
<tr>
<th scope="row">Allowed files</th>
<td>
<input class="textbox" type="text" name="file_ext" value="'.$attach_file_extarray[$key].'" size="80" />
<span>If empty, allow all files except those to always deny.</span>
</td>
</tr>
</table>
<input type="hidden" name="forum" value="'.$attach_cur_f_id.'" />
<input type="hidden" name="edit_rules" value="'.$attach_cur_f_id.'" />
<input type="hidden" name="edit_ruleset" value="'.$key.'" />
<input class="button" type="submit" name="update_ruleset" value="Edit this ruleset" /> or
<input class="button" type="submit" name="delete_ruleset" value="Delete this ruleset" />
</div>
</fieldset>
</form>
';
}
$attach_output .= '
</div>
</div>
</div>';
}
// create output for creating a new one
if(count($attach_grouparray)>0){
// generate the select statement
$attach_group_select = '
<select class="textbox" id="newgroup" name="newgroup">
';
foreach($attach_grouparray as $key => $value){
if($key!=1)$attach_group_select .= ' <option value="'.$key.'">'.$value.'</OPTION>
';
}
$attach_group_select .= '
</select>
';
// generate the whole baddabang ...
$attach_output .= '
<h2 class="block2"><span>Create new ruleset for forum: '.$attach_cur_f_name.'</span></h2>
<div class="box">
<div>
<div class="inform">
<form id="createnew" name="createnew" method="post" action="'.$_SERVER['REQUEST_URI'].'">
<fieldset>
<legend>Create new ruleset</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Group</th>
<td>'.$attach_group_select.'</td>
</tr>
<tr>
<th scope="row">Allow</th>
<td>
<span><input type="checkbox" name="download" value="1" />Download
<input type="checkbox" name="upload" value="1" />Upload
<input type="checkbox" name="owner_delete" value="1" />Owner Delete
<input type="checkbox" name="delete" value="1" />Delete</span>
</td>
</tr>
<tr>
<th scope="row">Max Upload</th>
<td>
<span><input class="textbox" type="text" name="size" value="100000" />bytes</span>
</td>
</tr>
<tr>
<th scope="row">Attachments per post</th>
<td>
<input class="textbox" type="text" name="per_post" value="1" />
<span>Here you can increase the allowed number of attachments per post. (To add more attachments to a post the user needs to edit the message.)</span>
</td>
</tr>
<tr>
<th scope="row">Allowed files</th>
<td>
<input class="textbox" type="text" name="file_ext" value="" size="80" />
<span>If empty, allow all files except those to always deny.</span>
</td>
</tr>
</table>
<input type="hidden" name="forum" value="'.$attach_cur_f_id.'" />
<input type="hidden" name="edit_rules" value="'.$attach_cur_f_id.'" />
<input class="button" type="submit" name="create_ruleset" value="Create new ruleset" />
</div>
</fieldset>
</form>
</div>
</div>
</div>
';
}
// output the shit
generate_admin_menu($plugin); // Display the admin navigation menu
?>
<div id="exampleplugin" class="blockform">
<h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - Edit rules</span></h2>
<div class="box">
<div class="inbox">
<p>You alter the rules per group basis, for each forum. Download, means that people in that group are allowed to download all attachments in that forum. Upload, means that the group is allowed to attach files to their posts. Owner delete, means that the owner of the file is allowed to delete the file from the post. Delete, means that the group will be allowed to delete all files (usefull for Moderators, but noone else)</p>
<p>You can also set a max size per group, and a list of allowed filextensions. The max size cannot be set larger than the hard limit set in the settings (if it is, it'll get that value instead). The allowed file extensions is where you can limit what people is allowed to upload, if it's left empty the Attachment Mod will allow all files except those specified in the Mod Settings to always deny.</p>
</div>
</div>
<?php echo $attach_output; ?>
</div>
<?php
}elseif(isset($_POST['list_rules'])){
$attach_output ='';
// generate an array with groupid => groupname, used when figuring out what the group is called ...
$attach_grouparray = array();
$attach_rightsarray = array();
$result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE 1 ORDER BY g_id ASC')or error('Unable to fetch usergroups',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
while(list($key,$value) = $db->fetch_row($result)){
$attach_grouparray[$key]=$value;
}
}
// select all the categorys and forums ...
$result = $db->query('SELECT c.cat_name, f.id, f.forum_name FROM '.$db->prefix.'categories AS c, '.$db->prefix.'forums AS f WHERE c.id=f.cat_id ORDER BY c.disp_position, f.disp_position')or error('Unable to fetch categorys and forums',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
$attach_prev_cat_name = '';
while(list($attach_cur_cat_name,$attach_cur_f_id,$attach_cur_f_name) = $db->fetch_row($result)){
// if the category name has changed, and the last one isn't '' end the category and start a new, othervise just start one
if($attach_cur_cat_name!=$attach_prev_cat_name){
if($attach_prev_cat_name!=''){ // close the last one ...
$attach_output .= '
</div>
</div>
</div>
';
}
//start new category
$attach_output .= '
<h2 class="block2"><span>Category: '.$attach_cur_cat_name.'</span></h2>
<div class="box">
<div>
<div class="inform">';
}
$attach_prev_cat_name = $attach_cur_cat_name;
// empty the strings ...
$attach_cur_forum_download = '';
$attach_cur_forum_upload = '';
$attach_cur_forum_delete = '';
$attach_cur_forum_ownerdelete = '';
unset($attach_rightsarray);
$attach_rightsarray = array();
// select all the groups that has rights set in this forum...
$result_two = $db->query('SELECT group_id, rules FROM '.$db->prefix.'attach_2_rules WHERE forum_id='.$attach_cur_f_id.' ORDER BY group_id')or error('Unable to fetch rights for users in forum',__FILE__,__LINE__,$db->error());
if($db->num_rows($result_two)!=0){
// clean up the array ... so we have an empty array to start with
while(list($attach_cur_group_id,$attach_cur_group_rules) = $db->fetch_row($result_two)){
$attach_rightsarray[$attach_cur_group_id] = $attach_cur_group_rules;
}
// check what they may access ...
foreach ($attach_rightsarray as $key => $value){
if(attach_rules($value,ATTACH_DOWNLOAD)){
if(array_key_exists($key,$attach_grouparray))
$attach_cur_forum_download .= ', '.$attach_grouparray[$key];
else
$attach_cur_forum_download .= ', (<strong>'.$key.'</strong>)';
}
if(attach_rules($value,ATTACH_UPLOAD)){
if(array_key_exists($key,$attach_grouparray))
$attach_cur_forum_upload .= ', '.$attach_grouparray[$key];
else
$attach_cur_forum_upload .= ', (<strong>'.$key.'</strong>)';
}
if(attach_rules($value,ATTACH_DELETE)){
if(array_key_exists($key,$attach_grouparray))
$attach_cur_forum_delete .= ', '.$attach_grouparray[$key];
else
$attach_cur_forum_delete .= ', (<strong>'.$key.'</strong>)';
}
if(attach_rules($value,ATTACH_OWNER_DELETE)){
if(array_key_exists($key,$attach_grouparray))
$attach_cur_forum_ownerdelete .= ', '.$attach_grouparray[$key];
else
$attach_cur_forum_ownerdelete .= ', (<strong>'.$key.'</strong>)';
}
}
}
// output the forum stuff...
$attach_output .= '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'">
<fieldset>
<legend>Forum: '.$attach_cur_f_name.'</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Download</th>
<td>
<span>'.ltrim($attach_cur_forum_download,', ').'</span>
</td>
</tr>
<tr>
<th scope="row">Upload</th>
<td>
<span>'.ltrim($attach_cur_forum_upload,', ').'</span>
</td>
</tr>
<tr>
<th scope="row">Owner delete</th>
<td>
<span>'.ltrim($attach_cur_forum_ownerdelete,', ').'</span>
</td>
</tr>
<tr>
<th scope="row">Delete</th>
<td>
<span>'.ltrim($attach_cur_forum_delete,', ').'</span>
</td>
</tr>
</table>
<input type="hidden" name="forum" value="'.$attach_cur_f_id.'" /><input class="button" type="submit" name="edit_rules" value="Edit rules for this forum" />
</div>
</fieldset>
</form>
';
}
// close the last category
$attach_output .= '
</div>
</div>
</div>
</div>
';
}
// well ... generate the page :D
generate_admin_menu($plugin); // Display the admin navigation menu
?>
<div id="exampleplugin" class="blockform">
<h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - Administration Rules</span></h2>
<div class="box">
<div class="inbox">
<p>This is where you select what rules should be applied on different groups on different forums.</p>
<p>If a group isn't listed, they aren't allowed to do stuff.(Except Administrators that always may post)</p>
</div>
</div>
<?php
echo $attach_output;
}elseif(isset($_POST['optimize_tables'])){
$result = $db->query('OPTIMIZE TABLE `'.$db->prefix.'attach_2_files`')or error('Unable to optimize table: attach_2_files',__FILE__,__LINE__,$db->error());
$result = $db->query('OPTIMIZE TABLE `'.$db->prefix.'attach_2_rules`')or error('Unable to optimize table: attach_2_rules',__FILE__,__LINE__,$db->error());
redirect($_SERVER['REQUEST_URI'], 'Attachment Mod '.$pun_config['attach_cur_version'].', Tables Optimized …');
}elseif(isset($_POST['update_settings'])){
// rewrite stuff from POST variables
$form['use_icon'] = intval($_POST['use_icon']);
$form['icon_folder'] = $_POST['icon_folder']; //later strip out all < > | ? * " from the string, to try to up the safety
$form['icon_extension'] = $_POST['icon_extension']; //later strip out all \ / < > | ? * from the string, to try to up the safety
$form['icon_name'] = $_POST['icon_name']; //later strip out all \ / < > | ? * from the string, to try to up the safety
$form['create_orphans'] = intval($_POST['create_orphans']);
$form['always_deny'] = $_POST['always_deny']; //later strip out all \ / < > | ? * from the string, to try to up the safety
$form['max_size'] = intval($_POST['max_size']);
$form['basefolder'] = $_POST['basefolder']; //later strip out all < > | ? * " from the string, to try to up the safety
//insert it into the database
//taken most from admin_options.php, small changes to cope with the attachment mod instead of forum options...
while (list($key, $input) = @each($form))
{
// Only update values that have changed
if ($pun_config['attach_'.$key] != $input)
{
if ($input != '' || is_int($input))
$value = '\''.$db->escape($input).'\'';
else
$value = 'NULL';
$db->query('UPDATE '.$db->prefix.'config SET conf_value='.$value.' WHERE conf_name=\'attach_'.$key.'\'') or error('Unable to update attachment mod config', __FILE__, __LINE__, $db->error());
}
}
// Regenerate the config cache
require_once PUN_ROOT.'include/cache.php';
generate_config_cache();
// end of stuff taken from admin_options
redirect($_SERVER['REQUEST_URI'], 'Attachment Mod '.$pun_config['attach_cur_version'].' settings updated. Redirecting …');
}elseif(isset($_POST['generate_subfolder'])||isset($_POST['change_subfolder'])){
// if the latter, we should use that instead for new folder
if(isset($_POST['change_subfolder'])) // we want to use the entered subfolder
$newname = $_POST['subfolder']; // fiddle with security later... i.e. only allow 0-9 + a-z
else
$newname = attach_generate_pathname($pun_config['attach_basefolder']); // ok, we doesn't need to use a folder that has been created beforehand ...
if(!attach_create_subfolder($newname))
error('Unable to create new subfolder with name '.$newname,__FILE__,__LINE__);
else
redirect($_SERVER['REQUEST_URI'], 'Attachment Mod '.$pun_config['attach_cur_version'].' new subfolder created. Redirecting …');
}elseif(isset($_POST['alter_settings'])||isset($_GET['alter_settings'])){
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div id="exampleplugin" class="blockform">
<h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - Alter Settings</span></h2>
<div class="box">
<div class="inbox">
<p>From this page you can more or less alter everything how the mod will behave. Please consult the documentation before changing the values here, as some changes might get undesired results.</p>
</div>
</div>
<h2 class="block2"><span>Settings</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<p class="submittop"><input class="button" type="submit" name="update_settings" value="Update settings" tabindex="1" /></p>
<div class="inform">
<fieldset>
<legend>Attachment Icons</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Use icons</th>
<td>
<strong><input type="radio" name="use_icon" value="1" <?php if($pun_config['attach_use_icon']==1)echo 'checked="checked" '; ?>tabindex="2" />Yes <input type="radio" name="use_icon" value="0" <?php if($pun_config['attach_use_icon']==0)echo 'checked="checked" '; ?>tabindex="3" />No</strong>
<span>If you want to globally disable the use of icons for the attachments. If it's set to No, noone will see icons, even if the users have selected to show images. Icons are not showed to people that has selected not to use images in posts.</span>
</td>
</tr>
<tr>
<th scope="row">Icon folder<div></div></th>
<td>
<input class="textbox" type="text" name="icon_folder" value="<?php echo $pun_config['attach_icon_folder']; ?>" tabindex="4" />
<span>Set this to where the attachment mod stores the icons. The pathname should end with a slash.</span>
</td>
</tr>
<tr>
<th scope="row">Icons used<div></div></th>
<td>
<input class="textbox" type="text" name="icon_extension" value="<?php echo htmlspecialchars($pun_config['attach_icon_extension']); ?>" tabindex="5" size="50" />File extension<br />
<input class="textbox" type="text" name="icon_name" value="<?php echo htmlspecialchars($pun_config['attach_icon_name']); ?>" tabindex="6" size="50" />Icon name
<span>This is the arrays that holds what fileextension get what icon, the items are separated with double quotation marks (").</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<div class="inform">
<fieldset>
<legend>Attachment Limitations and Storage</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Create orphans</th>
<td>
<strong><input type="radio" name="create_orphans" value="1" <?php if($pun_config['attach_create_orphans']=='1')echo 'checked="checked" '; ?>tabindex="7" />Yes <input type="radio" name="create_orphans" value="0" <?php if($pun_config['attach_create_orphans']=='0')echo 'checked="checked" '; ?>tabindex="8" />No</strong>
<span>If you select to create orphans, then when a thread is deleted no attachments will get deleted. They will instead become orphans, with a possibility to transfer the attachments to new posts. This is done like this as if a person decides to delete his post, it might be ok to loose a couple of attachments, but if a whole thread gets deleted this would mean that people could have important attachments dissapear. I recommend this to be left on Yes (and then it will be faster to delete threads aswell)</span>
</td>
</tr>
<tr>
<th scope="row">Always deny<div></div></th>
<td>
<input class="textbox" type="text" name="always_deny" value="<?php echo htmlspecialchars($pun_config['attach_always_deny']); ?>" tabindex="9" size="50" />
<span>Files with these extensions will always be denied when people try to upload them, except for Administrators, who can override it. Separate items with double quotation marks (")</span>
</td>
</tr>
<tr>
<th scope="row">Max filesize<div></div></th>
<td>
<input class="textbox" type="text" name="max_size" value="<?php echo htmlspecialchars($pun_config['attach_max_size']); ?>" tabindex="10" size="10" />bytes
<span>This is the 'hard' limit for the maximum allowed uploadsize, not even Administrators can override this. Read documentation to know how big you can allow this to be.</span>
</td>
</tr>
<tr>
<th scope="row">Attachments basefolder<div></div></th>
<td>
<input class="textbox" type="text" name="basefolder" value="<?php echo htmlspecialchars($pun_config['attach_basefolder']); ?>" tabindex="11" />
<span>This is where the Mod will save the files, make sure PHP is allowed to create directories here, as the mod won't work if it isn't allowed to write to this folder. It's extremely important that users cannot browse this folder, as they could get hold of secure items if that would be the case.</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input class="button" type="submit" name="update_settings" value="Update settings" tabindex="12" /></p>
</form>
</div>
<h2 class="block2"><span>Subfolders</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Subfolders</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Current subfolder<div></div></th>
<td>
<input class="textbox" type="text" name="subfolder" value="<?php echo htmlspecialchars($pun_config['attach_subfolder']); ?>" tabindex="13" size="40" maxlength="32" />
<span>In this subfolder the Attachment Mod will save the files. Make sure you <strong>read the documentation <u>before</u></strong> changing this. <em>I suggest you use the generate button to generate new unique names</em> instead of writing your own. (This is simply because humans usually don't make that difficult names, humans are quite predictable)</span>
<span><input class="button" type="submit" name="generate_subfolder" value="Generate new subfolder" tabindex="14" /> or <input class="button" type="submit" name="change_subfolder" value="Change subfolder" tabindex="15" /></span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
</form>
</div>
</div>
<?php
}else{ // Nothing has been asked for, design the 'main page'
// calculate some statistics
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'attach_2_files WHERE 1')or error('Unable to count number of attachment files',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
list($attach_number_of_rows) = $db->fetch_row($result);
if($attach_number_of_rows!=0){
$attach_output = "Number of attachments: $attach_number_of_rows<br />\n ";
// figure out the disk usage, taken from the mysql tables ...
$result = $db->query('SELECT SUM(size),SUM(downloads),SUM(downloads*size) FROM `'.$db->prefix.'attach_2_files` WHERE 1')or error('Unable to summarize disk usage',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
list($attach_size,$attach_downloads,$attach_total_transfer) = $db->fetch_row($result);
$attach_output .= 'Used diskspace: '.number_format($attach_size)." bytes<br />\n ";
$attach_output .= 'Total downloads: '.number_format($attach_downloads)." downloads<br />\n ";
$attach_output .= 'Total transfer: '.number_format($attach_total_transfer)." bytes transferred<br />\n ";
}
// select the most downloaded file
$result = $db->query('SELECT id, owner, filename, size, downloads FROM '.$db->prefix.'attach_2_files WHERE 1 ORDER BY downloads DESC LIMIT 1')or error('Unable to fetch most downloaded attachment',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
list($attach_most_id,$attach_most_owner_id,$attach_most_filename,$attach_most_size,$attach_most_downloads) = $db->fetch_row($result);
$result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id = '.$attach_most_owner_id.' LIMIT 1')or error('Unable to fetch name on user with most downloaded attachment',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)==1)
list($attach_most_owner) = $db->fetch_row($result);
else
$attach_most_owner = 'Now a guest';
$attach_output .= 'Most downloaded: '.number_format($attach_most_downloads).' downloads ("<a href="attachment.php?item='.$attach_most_id.'">'.$attach_most_filename.'</a>" ('.number_format($attach_most_size).' bytes) posted by <a href="profile.php?section=admin&id='.$attach_most_owner_id.'">'.$attach_most_owner.'</a>)';
}else
$attach_output .= 'Most downloaded: none';
// select the attachment with largest total size (size*downloads)
$result = $db->query('SELECT id, owner, filename, size, downloads FROM '.$db->prefix.'attach_2_files WHERE 1 ORDER BY downloads*size DESC LIMIT 1')or error('Unable to fetch downloaded attachment with most transfersize',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)!=0){
list($attach_most_id,$attach_most_owner_id,$attach_most_filename,$attach_most_size,$attach_most_downloads) = $db->fetch_row($result);
$result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id = '.$attach_most_owner_id.' LIMIT 1')or error('Unable to fetch name on user with largest total downloaded attachment',__FILE__,__LINE__,$db->error());
if($db->num_rows($result)==1)
list($attach_most_owner) = $db->fetch_row($result);
else
$attach_most_owner = 'Now a guest';
$attach_output .= "<br />\n".'Largest total download: '.number_format(($attach_most_downloads*$attach_most_size)).' bytes. ("<a href="attachment.php?item='.$attach_most_id.'">'.$attach_most_filename.'</a>" ('.number_format($attach_most_size).' bytes, '.number_format($attach_most_downloads).' downloads) posted by <a href="profile.php?section=admin&id='.$attach_most_owner_id.'">'.$attach_most_owner.'</a>)';
}else
$attach_output .= "<br />\n".'Largest total download: none';
}else
$attach_output = 'No attachments<br /> <br /> '; // Ugly hack due to pageformatting goes funny without those extra rows...
}
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div id="exampleplugin" class="blockform">
<h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - Administration Menu</span></h2>
<div class="box">
<div class="inbox">
<p>From here you can set the settings for the attachment mod. But also perform maintenence tasks (note that some are recommended to be done in Maintenence mode!)</p>
<p>Choose from the menu below what you want to do.</p>
</div>
</div>
<h2 class="block2"><span>Menu</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Basic functions (no need for maintenence mode)</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row"><div><input class="button" type="submit" name="read_documentation" value="Read Documentation" tabindex="2" /></div></th>
<td>
<span>Read the documentation of this mod, how it works, what makes it work, security tips, usage guidelines etc.</span>
</td>
</tr>
<tr>
<th scope="row"><div><input class="button" type="submit" name="list_attachments" value="List Attachments" tabindex="3" /></div></th>
<td>
<span>Here you can see information for all attachments, and remove unwanted without going to the post.</span>
</td>
</tr>
<tr>
<th scope="row"><div><input class="button" type="submit" name="list_orphans" value="List Orphans" tabindex="4" /></div></th>
<td>
<span>When a complete thread gets deleted, the attachments won't be deleted, instead they turn up as orphans (has no parents, i.e. no post is the owner of this attachment). The reason why this is made is because loosing 1-10 attachments might not be that bad, but loosing hundreds might be.</span>
</td>
</tr>
<tr>
<th scope="row"><div><input class="button" type="submit" name="delete_orphans" value="Delete Orphans" tabindex="5" /></div></th>
<td>
<span>This will delete <strong>all</strong> orphan attachments.</span>
</td>
</tr>
<tr>
<th scope="row"><div><input class="button" type="submit" name="list_rules" value="List Rules" tabindex="6" /></div></th>
<td>
<span>In here you can see what permissions you have set for different groups, and you can assign groups access to attach files to their posts or change already existing rules. All settings are per group and per forum basis. No rules = no permissions.</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<div class="inform">
<fieldset>
<legend>Advanced functions (You should probably be in maintenence mode)</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row"><div><input class="button" type="submit" name="optimize_tables" value="Optimize Attachments" tabindex="7" /></div></th>
<td>
<span>If alot of files has been removed, or lots of rules been removed, there are probably alot of overhead in the database, optimize removed unused space in the database tables.</span>
</td>
</tr>
<tr>
<th scope="row"><div><input class="button" type="submit" name="alter_settings" value="Alter Settings" tabindex="8" /></div></th>
<td>
<span>Here you can change almost all settings how the mod behaves, from adding new icons, to creating a new directory to store new attachments in.</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
</form>
</div>
<h2 class="block2"><span>Statistics</span></h2>
<div id="adstats" class="box">
<div class="inbox">
<dl>
<dt>Mod Version</dt>
<dd>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?><br />
© Copyright 2003, 2004, 2005 Frank Hagström
</dd>
<dt>Attachments<br />(According to files currently in database)</dt>
<dd>
<?php echo $attach_output;?>
</dd>
</dl>
</div>
</div>
</div>
<?php
}
// Note that the script just ends here. The footer will be included by admin_loader.php.