################################################################
## MOD Title: EDIT-TEXT (Reason for Change)
## MOD Author:  killerbees19 < forum@happytec.at > (Christian Schrtter) http://www.happytec.at
## MOD Description: German:
##                  Mit diesem MOD kann man einen Grund fr das Bearbeiten eines beitrages angeben.
##
##                  English:
##                  With this MOD you can save a reason for edit a post.
##
## Italiano Translation: bersetzungen D/I -> http://www.de-it.ch/
## French and Dutch Translation: RC -> http://www.wuyts.org
##
## MOD Version: 1.0.0
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit:   includes/constants.php
##                  includes/functions_post.php
##                  language/lang_english/lang_main.php
##                  language/lang_spanish/lang_main.php
##                  templates/xxx/posting_body.tpl
##                  templates/xxx/viewtopic_body.tpl
##                  modcp.php
##                  posting.php
##                  viewtopic.php
##
## Included Files: N/A
##
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
################################################################
## Author Notes: 
##
################################################################
## MOD History: 
## 
##   2006-12-14 - Version 1.0.0
##      - First release
## 
##   2006-12-07 - Version 0.1.3
##      - French language included
##      - Dutch language included
##      - phpBB.com valid install.txt
##      - substr() updated
## 
##   2006-12-06 - Version 0.1.2
##      - English language included
## 
##   2006-12-06 - Version 0.1.1
##      - Max lenght check with substr()
## 
##   2006-12-06 - Version 0.1.0
##      - First Release for BETA-Testers
## 
##   2006-10-25 - Version 0.0.1
##      - Start programming
##      - Installed on forum.happytec.at
## 
################################################################
##	
##  Support:    http://www.forum.happytec.at
##  Copyright:  2006 Christian Schrtter
##
################################################################
##
## For security purposes, please check: http://www.happytec.at/download/d_02.php
## for the latest version of this MOD. Although MODs are checked 
## before being allowed in the MODs Database there is no guarantee 
## that there are no security problems within the MOD. No support 
## will be given for MODs not found within the MODs Database which 
## can be found at http://www.phpbb.de/moddb/
##
################################################################
##  Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
################################################################
# 
#-----[ DIY INSTRUCTIONS ]------------------------------------------ 
#
Upload, run, then delete if succesful install.php !!!

#
#-----[ OPEN ]-----
#
includes/constants.php

#
#-----[ FIND ]-----
#
// Table names
define('CONFIRM_TABLE', $table_prefix.'confirm');

#
#-----[ AFTER, ADD ]-----
#
// EDIT TEXT - Start
define('edit_text_table', $table_prefix.'edit_text');
// EDIT TEXT - End

#
#-----[ OPEN ]-----
#
includes/functions_post.php

#
#-----[ FIND ]-----
#
    //
		// Flood control
		//
		$where_sql = ($userdata['user_id'] == ANONYMOUS) ? "poster_ip = '$user_ip'" : 'poster_id = ' . $userdata['user_id'];
		$sql = "SELECT MAX(post_time) AS last_post_time
			FROM " . POSTS_TABLE . "
			WHERE $where_sql";
		if ($result = $db->sql_query($sql))
		{
			if ($row = $db->sql_fetchrow($result))
			{
				if (intval($row['last_post_time']) > 0 && ($current_time - intval($row['last_post_time'])) < intval($board_config['flood_interval']))
				{
					message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
				}
			}
		}
	}

#
#-----[ AFTER, ADD ]-----
#
  // START EDIT TEXT
	$edit_text = addslashes(substr(trim($_POST['edit_text']), 0, 250));
	if ($mode == 'editpost')
	{
		if (!isset($_POST['no_edit']))
		{
		  $sqledit = "SELECT * FROM ". edit_text_table ." WHERE postid='".$post_id."'";
		  if (!$db->sql_query($sqledit))
			{
				message_die(GENERAL_ERROR, 'Error in editing', '', __LINE__, __FILE__, $sqledit);
			}
			
      if ( $db->sql_numrows() == FALSE )
      {
        if (!empty($_POST['edit_text']))
        {
          $editsql = "INSERT INTO ". edit_text_table ." (postid, text, user) VALUES ('".$post_id."', '".$edit_text."', '".$userdata['username']."')";
          if (!$db->sql_query($editsql))
          {
            message_die(GENERAL_ERROR, 'Error in editing', '', __LINE__, __FILE__, $editsql);
          }
        }
      }
      else
      {
        $editsql = "UPDATE ". edit_text_table ." SET text='".$edit_text."', user='".$userdata['username']."' WHERE postid='".$post_id."'";
        if (!$db->sql_query($editsql))
        {
          message_die(GENERAL_ERROR, 'Error in editing', '', __LINE__, __FILE__, $editsql);
        }
      }
		}
		remove_search_post($post_id);
	}
	// END EDIT TEXT

#
#-----[ FIND ]-----
#
  if ($mode != 'poll_delete')
	{
		include($phpbb_root_path . 'includes/functions_search.'.$phpEx);

#
#-----[ AFTER, ADD ]-----
#
    $editsql = "DELETE FROM ". edit_text_table ." WHERE postid=".$post_id;
    if( !$db->sql_query($editsql) )
    {
      message_die(GENERAL_ERROR, 'Could not delete edit text', '', __LINE__, __FILE__, $editsql);
    }

#
#-----[ OPEN ]-----
# Only, if you installed english language-file
language/lang_english/lang_main.php

#
#-----[ FIND ]-----
#
?>

#
##
###
###-----[ BEFORE, ADD ]-----
### note: Do this only if you installed "Extended Edit Message MOD" from leuchte.net
###       When this MOD is'nt installed, ignore this part
##
#

// EDIT TEXT
$lang['edit_text'] = '<br /><br />Reason for change of %s: %s';
$lang['edit_text_info'] = 'Reason for change:';

#
#-----[ BEFORE, ADD ]-----
# note: Do this only if you have >>not<< installed "Extended Edit Message MOD" from leuchte.net

// EDIT TEXT
$lang['No_edit_message'] = 'Don\'t save my edit';
$lang['edit_text'] = '<br /><br />Reason for change of %s: %s';
$lang['edit_text_info'] = 'Reason for change:';

#
#-----[ OPEN ]-----
# Solamente, si tienes instalado el archivo de idioma spanish
language/lang_spanish/lang_main.php

#
#-----[ FIND ]-----
#
?>

#
##
###
###-----[ BEFORE, ADD ]-----
### Nota: Hacer esto solamente si tienes instalado el "Extended Edit Message MOD" de leuchte.net
###       Si no esta instalado ese MOD, ignorar esta parte
##
#

// EDIT TEXT
$lang['edit_text'] = '<br /><br />Razn del Cambio por %s: %s';
$lang['edit_text_info'] = 'Razn del Cambio:';

#
#-----[ BEFORE, ADD ]-----
# Nota: Hacer esto solamente si >>NO<< tienes instalado el "Extended Edit Message MOD" de leuchte.net

// EDIT TEXT
$lang['No_edit_message'] = 'No guardar mi edicin';
$lang['edit_text'] = '<br /><br />Razn del Cambio por %s: %s';
$lang['edit_text_info'] = 'Razn del Cambio:';

#
#----[ OPEN ]----
#
posting.php

#
#-----[ FIND ]-----
#
//
// Delete selection
//
if ( $mode == 'editpost' && ( ( $is_auth['auth_delete'] && $post_data['last_post'] && ( !$post_data['has_poll'] || $post_data['edit_poll'] ) ) || $is_auth['auth_mod'] ) )
{
	$template->assign_block_vars('switch_delete_checkbox', array());
}

#
##
###
###-----[ BEFORE, ADD ]-----
### note: Do this only if you installed "Extended Edit Message MOD" from leuchte.net
###       When this MOD is'nt installed, ignore this part
##
#
//
// EDIT TEXT - only show if mode is editpost
//
if ($mode == 'editpost')
{ 
  $template->assign_block_vars('switch_edit_text', array());
}

#
#-----[ BEFORE, ADD ]-----
# note: Do this only if you have >>not<< installed "Extended Edit Message MOD" from leuchte.net
//
// Edit checkbox - only show if user is Admin and mode is editpost
//
if ($userdata['user_level'] == ADMIN)
{
	if ($mode == 'editpost')
	{ 
		$template->assign_block_vars('switch_edit_checkbox', array());
	}
}

//
// EDIT TEXT - only show if mode is editpost
//
if ($mode == 'editpost')
{ 
  $template->assign_block_vars('switch_edit_text', array());
}

# 
#-----[ FIND ]------------------------------------------ 
#
	'L_SPELLCHECK' => $lang['Spellcheck'],

#
##
###
###-----[ AFTER, ADD ]-----
### note: Do this only if you installed "Extended Edit Message MOD" from leuchte.net
###       When this MOD is'nt installed, ignore this part
##
#

  // EDIT TEXT
	'edit_text_info'	 => $lang['edit_text_info'],
	// EDIT TEXT
	
#
#-----[ BEFORE, ADD ]-----
# note: Do this only if you have >>not<< installed "Extended Edit Message MOD" from leuchte.net

  // EDIT TEXT
	'edit_text_info'	 => $lang['edit_text_info'],
	'L_NO_EDIT_MSG' => $lang['No_edit_message'],
	// EDIT TEXT

#
#-----[ OPEN ]-----
#
viewtopic.php

#
#-----[ FIND ]-----
#
    'U_MINI_POST' => $mini_post_url,
    'U_POST_ID' => $postrow[$i]['post_id'])
  );

#
#-----[ AFTER, ADD ]-----
#

// START EDIT TEXT
$sql = "SELECT user, text FROM ". edit_text_table ." WHERE postid='". $postrow[$i]['post_id'] ."'";
if ( !($result = $db->sql_query($sql)) ) 
{ 
  message_die(GENERAL_ERROR, "Could not get edit_text", '', __LINE__, __FILE__, $sql); 
}
$edit_text = array();
while($row = $db->sql_fetchrow($result))
{
  $edit_text[] = $row;
}
    
if($edit_text['0']['text'] != '')
{
  $template->assign_block_vars('postrow.edit_text', array(
    'EDIT_TEXT' => sprintf($lang['edit_text'], htmlentities($edit_text['0']['user']), htmlentities($edit_text['0']['text'])))
  );
}
// END EDIT TEXT

#
#-----[ OPEN ]-----
# note: Do this for every template installed
templates/xxx/posting_body.tpl

#
#-----[ FIND ]-----
#
		  <tr> 
			<td colspan="9"><span class="gen"> 
			  <textarea name="message" rows="15" cols="35" wrap="virtual" style="width:450px" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);">{MESSAGE}</textarea>
			  </span></td>
		  </tr>

#
##
###
###-----[ AFTER, ADD ]-----
### note: Do this only if you installed "Extended Edit Message MOD" from leuchte.net
###       When this MOD is'nt installed, ignore this part
##
#
      <!-- BEGIN switch_edit_text -->
		  <tr> 
			<td colspan="9"><span class="gen"> 
			  {edit_text_info}&nbsp;
        <input type="text" name="edit_text" size="45" maxlength="250" class="post" value="{edit_text}">
			  </span></td>
		  </tr>
		  <!-- END switch_edit_text -->

#
#-----[ AFTER, ADD ]-----
# note: Do this only if you have >>not<< installed "Extended Edit Message MOD" from leuchte.net
      
      <!-- BEGIN switch_edit_text -->
		  <tr> 
			<td colspan="9"><span class="gen"> 
			  {edit_text_info}&nbsp;
        <input type="text" name="edit_text" size="45" maxlength="250" class="post" value="{edit_text}">
			  </span></td>
		  </tr>
		  <!-- END switch_edit_text -->
		  <!-- BEGIN switch_edit_checkbox -->
		  <tr> 
			<td colspan="9"><input type="checkbox" name="no_edit" />&nbsp;<span class="gen">{L_NO_EDIT_MSG}</span></td>
		  </tr>
		  <!-- END switch_edit_checkbox -->
		  
#
#-----[ OPEN ]-----
# note: Do this for every template installed
templates/xxx/viewtopic_body.tpl

#
#-----[ FIND ]-----
#
      </tr>
			<tr> 
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2"><span class="postbody">{postrow.MESSAGE}{postrow.SIGNATURE}</span>


#
#-----[ AFTER, ADD ]-----
# note: Begin a new line after and before this code!!!
        
        <!-- BEGIN edit_text -->
				<span class="gensmall">{postrow.edit_text.EDIT_TEXT}</span>
				<!-- END edit_text -->

# 
#-----[ OPEN ]------------------------------------------ 
#
modcp.php 

# 
#-----[ FIND ]------------------------------------------ 
#
				$post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . intval($row['post_id']);
			}
			$db->sql_freeresult($result);
			

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$editsql = "DELETE FROM ". edit_text_table ." WHERE postid IN ($topic_id_sql)";
			if( !$db->sql_query($editsql) )
			{
				message_die(GENERAL_ERROR, 'Could not delete edit text', '', __LINE__, __FILE__, $editsql);
			}

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM
