diff -crbB attachmod237/admin/admin_attachments.php attachmod238/admin/admin_attachments.php
*** attachmod237/admin/admin_attachments.php	Thu Jun 19 19:08:40 2003
--- attachmod238/admin/admin_attachments.php	Thu Jun 19 19:08:41 2003
***************
*** 6,12 ****
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: admin_attachments.php,v 1.43 2003/03/07 17:48:23 acydburn Exp $
   *
   ***************************************************************************/
  
--- 6,12 ----
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: admin_attachments.php,v 1.46 2003/06/19 16:55:21 acydburn Exp $
   *
   ***************************************************************************/
  
***************
*** 41,46 ****
--- 41,47 ----
  
  @include_once($phpbb_root_path . 'attach_mod/includes/constants.'.$phpEx);
  include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
+ @include_once($phpbb_root_path . 'attach_mod/includes/functions_attach.'.$phpEx);
  
  if (!intval($attach_config['allow_ftp_upload']))
  {
***************
*** 1095,1101 ****
  	$info = '';
  	@set_time_limit(0);
  
! 	print_r('Sync Topics');
  	
  	$sql = "SELECT topic_id	FROM " . TOPICS_TABLE;
  	if ( !($result = $db->sql_query($sql)) )
--- 1096,1102 ----
  	$info = '';
  	@set_time_limit(0);
  
! 	echo 'Sync Topics';
  	
  	$sql = "SELECT topic_id	FROM " . TOPICS_TABLE;
  	if ( !($result = $db->sql_query($sql)) )
***************
*** 1103,1118 ****
  		message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
  	}
  
! 	print_r('<br />');
  
  	while( $row = $db->sql_fetchrow($result) )
  	{
! 		print_r('.');
  		attachment_sync_topic($row['topic_id']);
  	}
  
! 	print_r('<br /><br />');
! 	print_r('Sync Posts');
  	
  	// Reassign Attachments to the Poster ID
  	$sql = "SELECT a.attach_id, a.post_id, a.user_id_1, p.poster_id FROM " . ATTACHMENTS_TABLE . " a, " . POSTS_TABLE . " p 
--- 1104,1127 ----
  		message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
  	}
  
! 	echo '<br />';
  
+ 	$i = 0;
  	while( $row = $db->sql_fetchrow($result) )
  	{
! 		@flush();
! 		echo '.';
! 		if ($i % 50 == 0)
! 		{
! 			echo '<br />';
! 		}
  		attachment_sync_topic($row['topic_id']);
+ 		$i++;
  	}
+ 	$db->sql_freeresult($result);
  
! 	echo '<br /><br />';
! 	echo 'Sync Posts';
  	
  	// Reassign Attachments to the Poster ID
  	$sql = "SELECT a.attach_id, a.post_id, a.user_id_1, p.poster_id FROM " . ATTACHMENTS_TABLE . " a, " . POSTS_TABLE . " p 
***************
*** 1123,1129 ****
  		message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  	}
  
! 	print_r('<br />');
  
  	$rows = $db->sql_fetchrowset($result);
  	$num_rows = $db->sql_numrows($result);
--- 1132,1138 ----
  		message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  	}
  
! 	echo '<br />';
  
  	$rows = $db->sql_fetchrowset($result);
  	$num_rows = $db->sql_numrows($result);
***************
*** 1134,1144 ****
  
  		$db->sql_query($sql);
  
! 		print_r('.');
  	}
  
! 	print_r('<br /><br />');
! 	print_r('Sync Thumbnails');
  	
  	// Sync Thumbnails (if a thumbnail is no longer there, delete it)
  	// Get all Posts/PM's with the Thumbnail Flag set
--- 1143,1158 ----
  
  		$db->sql_query($sql);
  
! 		@flush();
! 		echo '.';
! 		if ($i % 50 == 0)
! 		{
! 			echo '<br />';
! 		}
  	}
  
! 	echo '<br /><br />';
! 	echo 'Sync Thumbnails';
  	
  	// Sync Thumbnails (if a thumbnail is no longer there, delete it)
  	// Get all Posts/PM's with the Thumbnail Flag set
***************
*** 1150,1160 ****
  		message_die(GENERAL_ERROR, 'Could not get thumbnail informations', '', __LINE__, __FILE__, $sql);
  	}
  	
! 	print_r('<br />');
  
  	while ($row = $db->sql_fetchrow($result))
  	{
! 		print_r('.');
  
  		if (!thumbnail_exists($row['physical_filename']))
  		{
--- 1164,1180 ----
  		message_die(GENERAL_ERROR, 'Could not get thumbnail informations', '', __LINE__, __FILE__, $sql);
  	}
  	
! 	echo '<br />';
  
+ 	$i = 0;
  	while ($row = $db->sql_fetchrow($result))
  	{
! 		@flush();
! 		echo '.';
! 		if ($i % 50 == 0)
! 		{
! 			echo '<br />';
! 		}
  
  		if (!thumbnail_exists($row['physical_filename']))
  		{
***************
*** 1166,1176 ****
  				die('Could not update thumbnail informations -> ' . $error['message'] . ' -> ' . $sql);
  			}
  		}
  	}
  	
  	die('<br /><br /><br />' . $lang['Attach_sync_finished'] . '<br /><br />' . $info);
  
! 	exit();
  }
  
  // Quota Limit Settings
--- 1186,1230 ----
  				die('Could not update thumbnail informations -> ' . $error['message'] . ' -> ' . $sql);
  			}
  		}
+ 		$i++;
+ 	}
+ 	$db->sql_freeresult($result);
+ 
+ 	// Sync Thumbnails (make sure all non-existent thumbnails are deleted) - the other way around
+ 	// Get all Posts/PM's with the Thumbnail Flag NOT set
+ 	// Go through all of them and make sure the Thumbnail does NOT exist. If it does exist, delete it
+ 	$sql = "SELECT attach_id, physical_filename, thumbnail FROM " . ATTACHMENTS_DESC_TABLE . " WHERE thumbnail = 0";
+ 
+ 	if ( !($result = $db->sql_query($sql)) )
+ 	{
+ 		message_die(GENERAL_ERROR, 'Could not get thumbnail informations', '', __LINE__, __FILE__, $sql);
+ 	}
+ 	
+ 	echo '<br />';
+ 
+ 	$i = 0;
+ 	while ($row = $db->sql_fetchrow($result))
+ 	{
+ 		@flush();
+ 		echo '.';
+ 		if ($i % 50 == 0)
+ 		{
+ 			echo '<br />';
+ 		}
+ 
+ 		if (thumbnail_exists($row['physical_filename']))
+ 		{
+ 			$info .= sprintf($lang['Sync_thumbnail_resetted'], $row['physical_filename']) . '<br />';
+ 			unlink_attach($row['physical_filename'], MODE_THUMBNAIL);
+ 		}
+ 		$i++;
  	}
+ 	$db->sql_freeresult($result);
  
+ 	@flush();
  	die('<br /><br /><br />' . $lang['Attach_sync_finished'] . '<br /><br />' . $info);
  
! 	exit;
  }
  
  // Quota Limit Settings
diff -crbB attachmod237/attach_mod/includes/constants.php attachmod238/attach_mod/includes/constants.php
*** attachmod237/attach_mod/includes/constants.php	Thu Jun 19 19:08:40 2003
--- attachmod238/attach_mod/includes/constants.php	Thu Jun 19 19:08:41 2003
***************
*** 6,12 ****
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: constants.php,v 1.22 2003/03/05 18:01:10 acydburn Exp $
   *
   *
   ***************************************************************************/
--- 6,12 ----
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: constants.php,v 1.23 2003/06/18 19:48:45 acydburn Exp $
   *
   *
   ***************************************************************************/
***************
*** 72,77 ****
  define('QUOTA_UPLOAD_LIMIT', 1);
  define('QUOTA_PM_LIMIT', 2);
  
! define('ATTACH_VERSION', '2.3.7');
  
  ?>
\ No newline at end of file
--- 72,77 ----
  define('QUOTA_UPLOAD_LIMIT', 1);
  define('QUOTA_PM_LIMIT', 2);
  
! define('ATTACH_VERSION', '2.3.8');
  
  ?>
\ No newline at end of file
diff -crbB attachmod237/attach_mod/includes/functions_includes.php attachmod238/attach_mod/includes/functions_includes.php
*** attachmod237/attach_mod/includes/functions_includes.php	Thu Jun 19 19:08:40 2003
--- attachmod238/attach_mod/includes/functions_includes.php	Thu Jun 19 19:08:41 2003
***************
*** 6,12 ****
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: functions_includes.php,v 1.28 2003/03/09 21:56:53 acydburn Exp $
   *
   *
   ***************************************************************************/
--- 6,12 ----
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: functions_includes.php,v 1.30 2003/06/19 16:39:41 acydburn Exp $
   *
   *
   ***************************************************************************/
***************
*** 234,240 ****
  //	$s_auth_can .= ( ( $is_auth['auth_attachments'] ) ? $rules_link . ' ' . $lang['Rules_attach_can'] : $lang['Rules_attach_cannot'] ) . '<br />';
  	$s_auth_can .= ( ( $is_auth['auth_attachments'] && $is_auth['auth_post'] ) ? $lang['Rules_attach_can'] : $lang['Rules_attach_cannot'] ) . '<br />';
  
! 	$s_auth_can .= ( ( $is_auth['auth_download'] && $is_auth['auth_read'] ) ? $lang['Rules_download_can'] : $lang['Rules_download_cannot'] ) . '<br />';
  }
  
  //
--- 234,240 ----
  //	$s_auth_can .= ( ( $is_auth['auth_attachments'] ) ? $rules_link . ' ' . $lang['Rules_attach_can'] : $lang['Rules_attach_cannot'] ) . '<br />';
  	$s_auth_can .= ( ( $is_auth['auth_attachments'] && $is_auth['auth_post'] ) ? $lang['Rules_attach_can'] : $lang['Rules_attach_cannot'] ) . '<br />';
  
! 	$s_auth_can .= (($is_auth['auth_download']) ? $lang['Rules_download_can'] : $lang['Rules_download_cannot'] ) . '<br />';
  }
  
  //
diff -crbB attachmod237/attach_mod/includes/functions_thumbs.php attachmod238/attach_mod/includes/functions_thumbs.php
*** attachmod237/attach_mod/includes/functions_thumbs.php	Thu Jun 19 19:08:40 2003
--- attachmod238/attach_mod/includes/functions_thumbs.php	Thu Jun 19 19:08:41 2003
***************
*** 6,12 ****
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: functions_thumbs.php,v 1.22 2003/02/23 11:36:25 acydburn Exp $
   *
   *
   ***************************************************************************/
--- 6,12 ----
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: functions_thumbs.php,v 1.23 2003/06/18 17:53:01 acydburn Exp $
   *
   *
   ***************************************************************************/
***************
*** 176,182 ****
  	{
  		if (is_array($size) && count($size) > 0) 
  		{
! 			@exec($imagick . ' -quality 75 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' ' . $source . ' ' . $new_file);
  			if (@file_exists(@amod_realpath($new_file)))
  			{
  				$used_imagick = TRUE;
--- 176,182 ----
  	{
  		if (is_array($size) && count($size) > 0) 
  		{
! 			@exec($imagick . ' -quality 75 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' ' . $source . ' +profile "*" ' . $new_file);
  			if (@file_exists(@amod_realpath($new_file)))
  			{
  				$used_imagick = TRUE;
diff -crbB attachmod237/attach_mod/posting_attachments.php attachmod238/attach_mod/posting_attachments.php
*** attachmod237/attach_mod/posting_attachments.php	Thu Jun 19 19:08:40 2003
--- attachmod238/attach_mod/posting_attachments.php	Thu Jun 19 19:08:41 2003
***************
*** 6,12 ****
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: posting_attachments.php,v 1.56 2003/02/27 14:04:02 acydburn Exp $
   *
   *
   ***************************************************************************/
--- 6,12 ----
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: posting_attachments.php,v 1.57 2003/06/19 16:34:50 acydburn Exp $
   *
   *
   ***************************************************************************/
***************
*** 265,277 ****
  			if ( $userdata['user_level'] == ADMIN )
  			{
  				$is_auth['auth_attachments'] = '1';
- 				$is_auth['auth_read'] = TRUE;
  				$max_attachments = ADMIN_MAX_ATTACHMENTS;
  			}
  			else
  			{
  				$is_auth['auth_attachments'] = intval($attach_config['allow_pm_attach']);
- 				$is_auth['auth_read'] = TRUE;
  				$max_attachments = intval($attach_config['max_attachments_pm']);
  			}
  		}
--- 265,275 ----
***************
*** 290,296 ****
  		//
  		// nothing, if the user is not authorized or attachment mod disabled
  		//
! 		if ( (intval($attach_config['disable_mod'])) || (!( ($is_auth['auth_attachments']) && ($is_auth['auth_read']))) )
  		{
  			return (FALSE);
  		}
--- 288,294 ----
  		//
  		// nothing, if the user is not authorized or attachment mod disabled
  		//
! 		if ( intval($attach_config['disable_mod']) || !$is_auth['auth_attachments'])
  		{
  			return (FALSE);
  		}
***************
*** 1532,1538 ****
  	{
  		global $attach_config, $is_auth, $userdata;
  
! 		if ( (intval($attach_config['disable_mod'])) || (!( ($is_auth['auth_attachments']) && ($is_auth['auth_read']))) )
  		{
  			return (FALSE);
  		}
--- 1530,1536 ----
  	{
  		global $attach_config, $is_auth, $userdata;
  
! 		if (intval($attach_config['disable_mod']) || !$is_auth['auth_attachments'])
  		{
  			return (FALSE);
  		}
***************
*** 1550,1556 ****
  		//
  		// Insert Attachment ?
  		//
! 		if ((!empty($post_id)) && ( $mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost' ) && ($is_auth['auth_attachments']) && ($is_auth['auth_read']))
  		{
  			$this->do_insert_attachment('attach_list', 'post', $post_id);
  			$this->do_insert_attachment('last_attachment', 'post', $post_id);
--- 1548,1554 ----
  		//
  		// Insert Attachment ?
  		//
! 		if ((!empty($post_id)) && ( $mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost' ) && ($is_auth['auth_attachments']))
  		{
  			$this->do_insert_attachment('attach_list', 'post', $post_id);
  			$this->do_insert_attachment('last_attachment', 'post', $post_id);
diff -crbB attachmod237/download.php attachmod238/download.php
*** attachmod237/download.php	Thu Jun 19 19:08:41 2003
--- attachmod238/download.php	Thu Jun 19 19:08:41 2003
***************
*** 6,12 ****
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: download.php,v 1.33 2003/03/05 18:01:11 acydburn Exp $
   *
   *
   ***************************************************************************/
--- 6,12 ----
   *   copyright            : (C) 2002 Meik Sievertsen
   *   email                : acyd.burn@gmx.de
   *
!  *   $Id: download.php,v 1.35 2003/06/19 16:34:50 acydburn Exp $
   *
   *
   ***************************************************************************/
***************
*** 118,138 ****
  	$thumbnail = FALSE;
  }
  
! //
! // Begin Functions
! //
! function send_file_to_browser($real_filename, $mimetype, $physical_filename, $upload_dir, $attach_id)
  {
  	global $_SERVER, $HTTP_USER_AGENT, $HTTP_SERVER_VARS, $lang, $db, $attach_config;
  
! 	if ($upload_dir == '')
! 	{
! 		$filename = $physical_filename;
! 	}
! 	else
! 	{
! 		$filename = $upload_dir . '/' . $physical_filename;
! 	}
  
  	$gotit = FALSE;
  
--- 118,129 ----
  	$thumbnail = FALSE;
  }
  
! // Send file to browser
! function send_file_to_browser($attachment, $upload_dir)
  {
  	global $_SERVER, $HTTP_USER_AGENT, $HTTP_SERVER_VARS, $lang, $db, $attach_config;
  
! 	$filename = ($upload_dir == '') ? $attachment['physical_filename'] : $upload_dir . '/' . $attachment['physical_filename'];
  
  	$gotit = FALSE;
  
***************
*** 201,239 ****
  		$browser_agent = 'other';
  	}
  
! 	//
! 	// Correct the Mime Type, if it's an octetstream
! 	//
! 	if ( ($mimetype == 'application/octet-stream') || ($mimetype == 'application/octetstream') )
  	{
! 		if ( ($browser_agent == 'ie') || ($browser_agent == 'opera') )
! 		{
! 			$mimetype = 'application/octetstream';
! 		}
! 		else
! 		{
! 			$mimetype = 'application/octet-stream';
! 		}
  	}
  
  	@ob_end_clean();
  	@ini_set('zlib.output_compression', 'Off');
  	header('Pragma: public');
  	header('Content-Transfer-Encoding: none');
  
- 	//
  	// Send out the Headers
! 	//
! 	if ($browser_agent == 'ie')
! 	{
! 		header('Content-Type: ' . $mimetype);
! 		header('Content-Disposition: inline; filename="' . $real_filename . '"');
! 	} 
! 	else
! 	{
! 		header('Content-Type: ' . $mimetype . '; name="' . $real_filename . '"');
! 		header('Content-Disposition: attachment; filename=' . $real_filename);
! 	}
  
  	//
  	// Now send the File Contents to the Browser
--- 192,213 ----
  		$browser_agent = 'other';
  	}
  
! 	// Correct the mime type - we force application/octetstream for all files, except images
! 	// Please do not change this, it is a security precaution
! 	if (!strstr($attachment['mimetype'], 'image'))
  	{
! 		$attachment['mimetype'] = ($browser_agent == 'ie' || $browser_agent == 'opera') ? 'application/octetstream' : 'application/octet-stream';
  	}
  
+ 	// Now the tricky part... let's dance
  	@ob_end_clean();
  	@ini_set('zlib.output_compression', 'Off');
  	header('Pragma: public');
  	header('Content-Transfer-Encoding: none');
  
  	// Send out the Headers
! 	header('Content-Type: ' . $attachment['mimetype'] . '; name="' . $attachment['real_filename'] . '"');
! 	header('Content-Disposition: inline; filename="' . $attachment['real_filename'] . '"');
  
  	//
  	// Now send the File Contents to the Browser
***************
*** 247,253 ****
  		}
  		readfile($filename);
  	}
! 	else if ((!$gotit) && (intval($attach_config['allow_ftp_upload'])))
  	{
  		$conn_id = attach_init_ftp();
  
--- 221,227 ----
  		}
  		readfile($filename);
  	}
! 	else if (!$gotit && intval($attach_config['allow_ftp_upload']))
  	{
  		$conn_id = attach_init_ftp();
  
***************
*** 259,265 ****
  		@unlink($tmp_filename);
  
  		$mode = FTP_BINARY;
! 		if ( (preg_match("/text/i", $mimetype)) || (preg_match("/html/i", $mimetype)) )
  		{
  			$mode = FTP_ASCII;
  		}
--- 233,239 ----
  		@unlink($tmp_filename);
  
  		$mode = FTP_BINARY;
! 		if ( (preg_match("/text/i", $attachment['mimetype'])) || (preg_match("/html/i", $attachment['mimetype'])) )
  		{
  			$mode = FTP_ASCII;
  		}
***************
*** 361,367 ****
  		$is_auth = array();
  		$is_auth = auth(AUTH_ALL, $forum_id, $userdata); 
  
! 		if ( $is_auth['auth_download'] && $is_auth['auth_read'] )
  		{
  			$authorised = TRUE;
  		}
--- 335,341 ----
  		$is_auth = array();
  		$is_auth = auth(AUTH_ALL, $forum_id, $userdata); 
  
! 		if ($is_auth['auth_download'])
  		{
  			$authorised = TRUE;
  		}
***************
*** 482,494 ****
  	if (intval($attach_config['allow_ftp_upload']))
  	{
  		// We do not need a download path, we are not downloading physically
! 		send_file_to_browser($attachment['real_filename'], $attachment['mimetype'], $attachment['physical_filename'] , '', $attachment['attach_id']);
! 		exit();
  	}
  	else
  	{
! 		send_file_to_browser($attachment['real_filename'], $attachment['mimetype'], $attachment['physical_filename'], $upload_dir, $attachment['attach_id']);
! 		exit();
  	}
  }
  
--- 456,468 ----
  	if (intval($attach_config['allow_ftp_upload']))
  	{
  		// We do not need a download path, we are not downloading physically
! 		send_file_to_browser($attachment, '');
! 		exit;
  	}
  	else
  	{
! 		send_file_to_browser($attachment, $upload_dir);
! 		exit;
  	}
  }
  
