<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="modx.prosilver.en.xsl"?>
<!--For security purposes, please check: http://www.phpbb.com/mods/ 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.com/mods/-->
<mod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phpbb.com/mods/xml/modx-1.0.1.xsd">
  <header>
    <license>http://opensource.org/licenses/gpl-license.php GNU General Public License v2</license>
    <title lang="en">Attendance Mod</title>
    <description lang="en">The Attendance Mod adds a new function to postings which provides unlimited clickable options at the top of a thread.
By clicking an option you register for it with your username and the registration date.
Registrations can be customized, confirmed, limited by users, can have an expiry date and different layouts.</description>
    <author-notes lang="en">Thanks to all who helped developing this mod by testing, giving suggestions and reporting bugs.</author-notes>
    <author-group>
      <author>
        <realname>Daniel Geue</realname>
        <email>info@danielgeue.de</email>
        <username>NetizenKane</username>
        <homepage>www.danielgeue.de</homepage>
        <contributions />
      </author>
    </author-group>
    <mod-version stage="alpha">
      <major>0</major>
      <minor>2</minor>
      <revision>4</revision>
    </mod-version>
    <installation>
      <level>intermediate</level>
      <time>2100</time>
      <target-version>
        <target-primary>3.0.1</target-primary>
        <target-major allow="exact">3</target-major>
        <target-minor allow="exact">0</target-minor>
        <target-revision allow="exact">1</target-revision>
      </target-version>
    </installation>
    <history>
	      <entry>
        <date>2008-05-23T00:00:00+01:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>2</minor>
          <revision>4</revision>
        </rev-version>
        <changelog lang="en">
		  <change>Summary of registrations in search view added</change>
          <change>Install script bug fixed (viewforum_body.html)</change>
          <change>Install script typos fixed</change>
          <change>Preview of registration form in posting.php added</change>
          <change>Character set bug at database fixed (utf-8)</change>
        </changelog>
      </entry>
	      <entry>
        <date>2008-05-07T00:00:00+01:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>2</minor>
          <revision>3</revision>
        </rev-version>
        <changelog lang="en">
		  <change>Small install script added</change>
          <change>Layouts recoded</change>
          <change>Summary of registrations in viewforum view added</change>
          <change>Bug with mouseover function fixed</change>
        </changelog>
      </entry>
	      <entry>
        <date>2008-02-11T00:00:00+01:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>2</minor>
          <revision>2</revision>
        </rev-version>
        <changelog lang="en">
          <change>Commata Bug at preset set fixed</change>
        </changelog>
      </entry>
      <entry>
        <date>2008-02-04T00:00:00+01:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>2</minor>
          <revision>1</revision>
        </rev-version>
        <changelog lang="en">
          <change>ACP preset add fixed</change>
          <change>Install script bug fixed</change>
          <change>SQL FULLTEXT INDEX removed</change>
        </changelog>
      </entry>
      <entry>
        <date>2008-01-31T00:00:00+01:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>2</minor>
          <revision>0</revision>
        </rev-version>
        <changelog lang="en">
          <change>Preset functionality implemented</change>
          <change>Fixed bugs with special characters</change>
          <change>Fixed bugs when previewing and editing registration postings</change>
          <change>Fixed undefined variables</change>
        </changelog>
      </entry>
      <entry>
        <date>2007-11-23T00:00:00+01:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>1</minor>
          <revision>2</revision>
        </rev-version>
        <changelog lang="en">
          <change>Fixed bug with previewing a registration</change>
        </changelog>
      </entry>
      <entry>
        <date>2007-10-20T00:00:00+02:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>1</minor>
          <revision>1</revision>
        </rev-version>
        <changelog lang="en">
          <change>Small adaption for phpBB RC7 implemented</change>
        </changelog>
      </entry>
      <entry>
        <date>2007-10-18T00:00:00+02:00</date>
        <rev-version stage="alpha">
          <major>0</major>
          <minor>1</minor>
          <revision>0</revision>
        </rev-version>
        <changelog lang="en">
          <change>Alpha Release</change>
        </changelog>
      </entry>
    </history>
    <meta name="generator" content="Phpbb.ModTeam.Tools (c#)" />
  </header>
  <action-group>
    <sql>
CREATE TABLE phpbb_am_options (
	am_option_id mediumint(8) unsigned NOT NULL auto_increment,
	topic_id mediumint(8) unsigned NOT NULL default '0',
	am_option_text text NOT NULL,
	am_option_max tinyint(5) unsigned NOT NULL default '0',
	am_option_color varchar(6) binary NOT NULL default '000000',
	PRIMARY KEY  (am_option_id),
	KEY am_topic_id (topic_id)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;

CREATE TABLE phpbb_am_registrations (
	am_registration_id mediumint(8) unsigned NOT NULL auto_increment,
	topic_id mediumint(8) unsigned NOT NULL default '0',
	am_option_id mediumint(8) unsigned NOT NULL default '0',
	am_user_id mediumint(8) unsigned NOT NULL default '0',
	am_user_ip varchar(40) binary NOT NULL default '0',
	am_registration_time int(11) NOT NULL default '0',
	am_registration_confirmed int(11) NOT NULL default '0',
	PRIMARY KEY (am_registration_id),
	KEY am_option_id (am_option_id,am_user_id,topic_id)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;

CREATE TABLE phpbb_am_presets (
  am_preset_id mediumint(8) unsigned NOT NULL auto_increment,
  am_preset_name varchar(50) binary NOT NULL default '0',
  am_length int(11) unsigned NOT NULL default '0',
  am_visible tinyint(1) NOT NULL default '0',
  am_confirmable tinyint(1) NOT NULL default '0',
  am_reg_change tinyint(1) NOT NULL default '0',
  am_layout tinyint(2) NOT NULL default '0',
  am_option_text text NOT NULL,
  am_option_max text NOT NULL,
  am_option_color text NOT NULL,
  am_preset_order mediumint(8) unsigned NOT NULL default '0',
  PRIMARY KEY  (am_preset_id)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;

ALTER TABLE phpbb_topics ADD am_start INT( 11 ) DEFAULT '0' NOT NULL;
ALTER TABLE phpbb_topics ADD am_length INT( 11 ) DEFAULT '0' NOT NULL;
ALTER TABLE phpbb_topics ADD am_visible TINYINT( 1 ) DEFAULT '0' NOT NULL;
ALTER TABLE phpbb_topics ADD am_confirmable TINYINT( 1 ) DEFAULT '0' NOT NULL;
ALTER TABLE phpbb_topics ADD am_reg_change TINYINT( 1 ) DEFAULT '0' NOT NULL;
ALTER TABLE phpbb_topics ADD am_layout TINYINT( 2 ) DEFAULT '0' NOT NULL;

INSERT INTO phpbb_acl_options (auth_option_id , auth_option , is_global , is_local , founder_only)
	VALUES (NULL , 'f_xam_register', 0, 1, 0);
INSERT INTO phpbb_acl_options (auth_option_id , auth_option , is_global , is_local , founder_only)
	VALUES (NULL , 'f_xam_create', 0, 1, 0);
INSERT INTO phpbb_acl_options (auth_option_id , auth_option , is_global , is_local , founder_only)
	VALUES (NULL , 'f_xam_preset', 0, 1, 0);
    </sql>

<copy>
    <file from="root/adm/style/acp_am_presets.html" to="adm/style/acp_am_presets.html" />
	<file from="root/includes/acp/info/acp_am_presets.php" to="includes/acp/info/acp_am_presets.php" />
    <file from="root/includes/acp/acp_am_presets.php" to="includes/acp/acp_am_presets.php" />
    <file from="root/includes/functions_am.php" to="includes/functions_am.php" />
    <file from="root/install_am/am_install_functions.php" to="install_am/am_install_functions.php" />
    <file from="root/install_am/index.htm" to="install_am/index.htm" />
    <file from="root/install_am/install.php" to="install_am/install.php" />
    <file from="root/language/en/acp/permissions_am.php" to="language/en/acp/permissions_am.php" />
    <file from="root/language/en/mods/am_posting.php" to="language/en/mods/am_posting.php" />
    <file from="root/language/en/mods/am_viewtopic.php" to="language/en/mods/am_viewtopic.php" />
    <file from="root/language/en/mods/info_am_presets.php" to="language/en/mods/info_am_presets.php" />
    <file from="root/styles/prosilver/template/posting_am_body.html" to="styles/prosilver/template/posting_am_body.html" />
    <file from="root/styles/prosilver/template/posting_preview_am_0.html" to="styles/prosilver/template/posting_preview_am_0.html" />
    <file from="root/styles/prosilver/template/posting_preview_am_1.html" to="styles/prosilver/template/posting_preview_am_1.html" />
    <file from="root/styles/prosilver/template/viewtopic_am_0.html" to="styles/prosilver/template/viewtopic_am_0.html" />
    <file from="root/styles/prosilver/template/viewtopic_am_1.html" to="styles/prosilver/template/viewtopic_am_1.html" />
    <file from="root/styles/prosilver/theme/attendance_mod.css" to="styles/prosilver/theme/attendance_mod.css" />
    <file from="root/styles/prosilver/theme/colour_picker.css" to="styles/prosilver/theme/colour_picker.css" />
</copy>

<open src="adm/style/admin.css">
    <edit>
        <find><![CDATA[.phpinfo td, .phpinfo th, .phpinfo h2, .phpinfo h1 {
	text-align: left;
}]]></find>
        <action type="after-add"><![CDATA[
/* --- Attendance Mod Start ---------------------------------------------------
	Type: Insert */

/* Classes for Attendance Mod
---------------------------------------- */

#dhtmlgoodies_colorPicker {
	position:absolute;
	width:250px;
	padding-bottom:1px;
	background-color:#FFF;
	border:1px solid #317082;

	width: 252px;	/* IE 5.x */
	width/* */:/**/250px;	/* Other browsers */
	width: /**/250px;
}

#dhtmlgoodies_colorPicker .colorPicker_topRow {
	padding-bottom:1px;
	border-bottom:3px double #317082;
	background-color:#E2EBED;
	padding-left:2px;

	width: 250px;	/* IE 5.x */
	width/* */:/**/248px;	/* Other browsers */
	width: /**/248px;

	height: 20px;	/* IE 5.x */
	height/* */:/**/16px;	/* Other browsers */
	height: /**/16px;
}

#dhtmlgoodies_colorPicker .colorPicker_statusBar {
	height:13px;
	padding-bottom:2px;
	width:248px;
	border-top:3px double #317082;
	background-color:#E2EBED;
	padding-left:2px;
	clear:both;

	width: 250px;	/* IE 5.x */
	width/* */:/**/248px;	/* Other browsers */
	width: /**/248px;

	height: 18px;	/* IE 5.x */
	height/* */:/**/13px;	/* Other browsers */
	height: /**/13px;
}

#dhtmlgoodies_colorPicker .colorSquare {
	margin-left:1px;
	margin-bottom:1px;
	float:left;
	border:1px solid #000;
	cursor:pointer;

	width: 12px;	/* IE 5.x */
	width/* */:/**/10px;	/* Other browsers */
	width: /**/10px;

	height: 12px;	/* IE 5.x */
	height/* */:/**/10px;	/* Other browsers */
	height: /**/10px;
}

.colorPickerTab_inactive,.colorPickerTab_active {
	height:17px;
	padding-left:4px;
	cursor:pointer;
}

.colorPickerTab_inactive span {
	background-image:url('images/tab_left_inactive.gif');
}

.colorPickerTab_active span {
	background-image:url('images/tab_left_active.gif');
}

.colorPickerTab_inactive span, .colorPickerTab_active span {
	line-height:16px;
	font-weight:bold;
	font-family:arial;
	font-size:11px;
	padding-top:1px;
	vertical-align:middle;
	background-position:top left;
	background-repeat: no-repeat;
	float:left;
	padding-left:6px;
	-moz-user-select:no;
}

.colorPickerTab_inactive img,.colorPickerTab_active img {
	float:left;
}

.colorPickerCloseButton {
	width:11px;
	height:11px;
	text-align:center;
	line-height:10px;
	border:1px solid #317082;
	position:absolute;
	right:1px;
	font-size:12px;
	font-weight:bold;
	top:1px;
	padding:1px;
	cursor:pointer;

	width: 15px;	/* IE 5.x */
	width/* */:/**/11px;	/* Other browsers */
	width: /**/11px;

	height: 15px;	/* IE 5.x */
	height/* */:/**/11px;	/* Other browsers */
	height: /**/11px;
}

#colorPicker_statusBarTxt {
	font-size:11px;
	font-family:arial;
	vertical-align:top;
	line-height:13px;
}

form {
	padding-left:5px;
}

.form_widget_amount_slider {
	border-top:1px solid #9d9c99;
	border-left:1px solid #9d9c99;
	border-bottom:1px solid #eee;
	border-right:1px solid #eee;
	background-color:#f0ede0;
	position:absolute;
	bottom:0px;

	width: 5px;	/* IE 5.x */
	width/* */:/**/3px;	/* Other browsers */
	width: /**/3px;

	height: 5px;	/* IE 5.x */
	height/* */:/**/3px;	/* Other browsers */
	height: /**/3px;
}

.colorSliderLabel {
	width:15px;
	height:20px;
	float:left;
	font-size:11px;
	font-weight:bold;
}

.colorSlider {
	width:175px;
	height:20px;
	float:left;
}

.colorInput {
	width:45px;
	height:20px;
	float:left;
}

.colorPreviewDiv {
	width:186px;
	margin-right:2px;
	margin-top:1px;
	border:1px solid #CCC;
	height:20px;
	float:left;
	cursor:pointer;

	width: 188px;	/* IE 5.x */
	width/* */:/**/186px;	/* Other browsers */
	width: /**/186px;

	height: 22px;	/* IE 5.x */
	height/* */:/**/20px;	/* Other browsers */
	height: /**/20px;
}

.colorCodeDiv {
	width:50px;
	height:20px;
	float:left;
}

/* --- Attendance Mod End -----------------------------------------------------*/]]></action>
    </edit>
</open>
<open src="includes/constants">
    <edit>
        <find><![CDATA[// Additional tables]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
define('AM_OPTIONS_TABLE',			$table_prefix . 'am_options');
define('AM_REGISTRATIONS_TABLE',	$table_prefix . 'am_registrations');
define('AM_PRESETS_TABLE',			$table_prefix . 'am_presets');
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="includes/functions_admin.php">
    <edit>
        <find><![CDATA[	$table_ary = array(TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE);]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", AM_OPTIONS_TABLE, AM_REGISTRATIONS_TABLE"]]></action>
    </edit>
	<edit>
        <find><![CDATA[	$table_ary = array(TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE);]]></find>
        <inline-edit>
            <inline-find><![CDATA[, POLL_OPTIONS_TABLE]]></inline-find>
            <inline-action type="after-add"><![CDATA[, AM_OPTIONS_TABLE, AM_REGISTRATIONS_TABLE]]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[
	foreach ($table_ary as $table)
	{
		$sql = "DELETE FROM $table
			WHERE " . $db->sql_in_set('topic_id', $topic_ids);]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="includes/functions_posting.php">
    <edit>
        <find><![CDATA[function submit_post(]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", &$am_registration"]]></action>
    </edit>
	<edit>
        <find><![CDATA[function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)]]></find>
        <inline-edit>
            <inline-find><![CDATA[, &$poll]]></inline-find>
            <inline-action type="after-add"><![CDATA[, &$am_registration]]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[{
	global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path;]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[		case 'edit_last_post':
		case 'edit_topic':]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
			$has_option = false;
			if (!empty($am_registration))
			{
				foreach ($am_registration['am_options'] as $am_option_text)
				{
					if (!empty($am_option_text))
					{
						$has_option = true;
						break;
					}
				}
				unset($am_option_text);
			}
// --- Attendance Mod End -----------------------------------------------------	]]></action>
    </edit>
    <edit>
        <find><![CDATA[					'poll_vote_change'	=> $poll['poll_vote_change'])
				);
			}]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
			if (!empty($am_registration))
			{
				$has_option = false;
				foreach ($am_registration['am_options'] as $am_option_text)
				{
					if (!empty($am_option_text))
					{
						$has_option = true;
						break;
					}
				}
				unset($am_option_text);

				if (!empty($has_option))
				{
					$sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
						'am_start'			=> ($am_registration['am_start']) ? $am_registration['am_start'] : $current_time,
						'am_length'			=> ($am_registration['am_length'] * 86400),
						'am_visible'		=> $am_registration['am_visible'],
						'am_confirmable'	=> $am_registration['am_confirmable'],
						'am_reg_change'		=> $am_registration['am_reg_change'],
						'am_layout'			=> $am_registration['am_layout'])
					);
				}
			}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[		case 'edit_topic':
		case 'edit_first_post':]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
			$has_option = false;
			if (!empty($am_registration))
			{
				foreach ($am_registration['am_options'] as $am_option_text)
				{
					if (!empty($am_option_text))
					{
						$has_option = true;
						break;
					}
				}
				unset($am_option_text);
			}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[				'poll_vote_change'			=> (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
				'am_start'					=> ($has_option) ? (($am_registration['am_start']) ? $am_registration['am_start'] : $current_time) : 0,
				'am_length'					=> ($has_option) ? ($am_registration['am_length'] * 86400) : 0,
				'am_visible'				=> (isset($am_registration['am_visible'])) ? $am_registration['am_visible'] : 0,
				'am_confirmable'			=> (isset($am_registration['am_confirmable'])) ? $am_registration['am_confirmable'] : 0,
				'am_reg_change'				=> (isset($am_registration['am_reg_change'])) ? $am_registration['am_reg_change'] : 0,
				'am_layout'					=> (isset($am_registration['am_layout'])) ? $am_registration['am_layout'] : 0,
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[	// Submit Attachments]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	// Update Registration Tables
	$has_option = false;
	if (!empty($am_registration))
	{
		foreach ($am_registration['am_options'] as $am_option_text)
		{
			if (!empty($am_option_text))
			{
				$has_option = true;
				break;
			}
		}
		unset($am_option_text);
	}

	if (!empty($has_option))
	{
		$cur_am_options = array();
		$del_option_array = array();

		if ($am_registration['am_start'] && $mode == 'edit')
		{
			$sql = 'SELECT *
				FROM ' . AM_OPTIONS_TABLE . '
				WHERE topic_id = ' . $data['topic_id'] . '
				ORDER BY am_option_id';
			$result = $db->sql_query($sql);

			while ($row = $db->sql_fetchrow($result))
			{
				$cur_am_options['am_options_id'][]		= $row['am_option_id'];
				$cur_am_options['am_options_text'][]	= $row['am_option_text'];
				$cur_am_options['am_options_max'][]		= $row['am_option_max'];
				$cur_am_options['am_options_color'][]	= $row['am_option_color'];
			}
			$db->sql_freeresult($result);
		}

		if (!empty($cur_am_options['am_options_id']))
		{
			$del_option_ary = array_diff($cur_am_options['am_options_id'], $am_registration['am_options_id']);
		}

		$sql_insert_ary = array();

		$am_preset_option_text = '';
		$am_preset_option_max = '';
		$am_preset_option_color = '';

		for ($i = 0, $size = sizeof($am_registration['am_options_id']); $i < $size; $i++)
		{
			$sql_update = '';
			$changed = false;

			if (!empty($am_registration['am_options_id'][$i]))
			{
				if (in_array($am_registration['am_options_id'][$i], $cur_am_options['am_options_id'], true))
				{
					$am_option_max = (!empty($am_registration['am_options_max'][$i]) ? (int) $am_registration['am_options_max'][$i] : 0);
					$am_option_color = (!empty($am_registration['am_options_color'][$i]) ? (string) str_replace('#', '', $am_registration['am_options_color'][$i]) : '000000');

					if ($am_registration['am_options'][$i] != $cur_am_options['am_options_text'][$i])
					{
						if ($sql_update == '')
						{
							$sql_update .= 'SET am_option_text = "' . $db->sql_escape($am_registration['am_options'][$i]) .'"';
							$changed = true;
						}
						else
						{
							$sql_update .= ', am_option_text = "' . $db->sql_escape($am_registration['am_options'][$i]) . '"';
							$changed = true;
						}
					}

					if ($am_option_max != $cur_am_options['am_options_max'][$i])
					{
						if ($sql_update == '')
						{
							$sql_update .= 'SET am_option_max = ' . $db->sql_escape($am_option_max);
							$changed = true;
						}
						else
						{
							$sql_update .= ', am_option_max = ' . $db->sql_escape($am_option_max);
							$changed = true;
						}
					}

					if ($am_option_color != $cur_am_options['am_options_color'][$i])
					{
						if ($sql_update == '')
						{
							$sql_update .= 'SET am_option_color = "' . $db->sql_escape($am_option_color) . '"';
							$changed = true;
						}
						else
						{
							$sql_update .= ', am_option_color = "' . $db->sql_escape($am_option_color) . '"';
							$changed = true;
						}
					}

					if ($changed)
					{
						$sql = 'UPDATE ' . AM_OPTIONS_TABLE . "
							$sql_update
							WHERE am_option_id = " . $am_registration['am_options_id'][$i] . '
								AND topic_id = ' . $data['topic_id'];

						$db->sql_query($sql);
					}
				}
			}
			else
			{
				if (!empty($am_registration['am_options'][$i]))
				{
					// If we add options we need to put them to the end to be able to preserve votes...
					$sql_insert_ary[] = array(
						'topic_id'			=> (int) $data['topic_id'],
						'am_option_text'	=> (string) $am_registration['am_options'][$i],
						'am_option_max'		=> (!empty($am_registration['am_options_max'][$i]) ? (int) $am_registration['am_options_max'][$i] : 0),
						'am_option_color'	=> (!empty($am_registration['am_options_color'][$i]) ? (string) str_replace('#', '', $am_registration['am_options_color'][$i]) : '000000'),
					);
				}

				if ($am_registration['am_preset_save'] && !empty($am_registration['am_preset_name']))
				{
					$delimiter = (($size - 1 == $i) ? '' : '\n');
					$am_preset_option_text	.= (string) $am_registration['am_options'][$i].$delimiter;
					$am_preset_option_max 	.= (string) $am_registration['am_options_max'][$i].$delimiter;
					$am_preset_option_color .= (string) $am_registration['am_options_color'][$i].$delimiter;
				}
			}
		}

		$db->sql_multi_insert(AM_OPTIONS_TABLE, $sql_insert_ary);

		if ($am_registration['am_preset_save'] && !empty($am_registration['am_preset_name']))
		{
			$sql_ary = array(
				'am_preset_name'	=> (string) $am_registration['am_preset_name'],
				'am_length'			=> (!empty($am_registration['am_length']) ? (int) $am_registration['am_length'] : 0),
				'am_visible'		=> (isset($am_registration['am_visible'])) ? (bool) $am_registration['am_visible'] : 0,
				'am_confirmable'	=> (isset($am_registration['am_confirmable'])) ? (bool) $am_registration['am_confirmable'] : 0,
				'am_reg_change'		=> (isset($am_registration['am_reg_change'])) ? (bool) $am_registration['am_reg_change'] : 0,
				'am_layout'			=> (isset($am_registration['am_layout'])) ? (int) $am_registration['am_layout'] : 0,
				'am_option_text'	=> (!empty($am_preset_option_text) ? (string) $am_preset_option_text : ''),
				'am_option_max'		=> (!empty($am_preset_option_max) ? (string) $am_preset_option_max : ''),
				'am_option_color'	=> (!empty($am_preset_option_color) ? (string) $am_preset_option_color : '')
			);

			$sql = 'SELECT MAX(am_preset_order) as max_order
				FROM ' . AM_PRESETS_TABLE;
			$result = $db->sql_query($sql);
			$max_order = (int) $db->sql_fetchfield('max_order');
			$db->sql_freeresult($result);

			$sql_ary['am_preset_order'] = $max_order + 1;

			$sql = 'INSERT INTO ' . AM_PRESETS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
			$db->sql_query($sql);
		}

		if (!empty($del_option_ary))
		{
			foreach ($del_option_ary as $del_option)
			{
				$sql = 'DELETE FROM ' . AM_OPTIONS_TABLE . '
					WHERE am_option_id = ' . $del_option . '
						AND topic_id = ' . $data['topic_id'];
				$db->sql_query($sql);
			}
		}
	}
// --- Attendance Mod End -----------------------------------------------------
        ]]></action>
    </edit>
</open>
<open src="includes/message_parser.php">
    <edit>
        <find><![CDATA[		$poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']);
	}]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	/**
	* Parse Registration
	*/
	function parse_registration(&$am_registration, &$forum_id)
	{
		global $auth, $user, $config;

		$options_max_smaller_zero = 0;
		$options_max_integer = 0;

		foreach ($am_registration['am_options_max'] as $am_options_max )
		{
			if ($am_options_max < 0)
			{
				$options_max_smaller_zero = 1;
			}
			else if (!is_numeric($am_options_max) && !empty($am_options_max))
			{
				$options_max_integer = 1;
			}
		}

		if (!empty($options_max_smaller_zero))
		{
			$this->warn_msg[] = $user->lang['SLOTS_SMALLER_ZERO'];
		}

		if (!empty($options_max_integer))
		{
			$this->warn_msg[] = $user->lang['SLOTS_NO_INTEGER'];
		}

		if (!is_int($am_registration['am_length']))
		{
			$this->warn_msg[] = $user->lang['LENGTH_NO_INTEGER'];
		}
		else if ($am_registration['am_length'] < 0 )
		{
			$this->warn_msg[] = $user->lang['LENGTH_SMALLER_ZERO'];
		}

		if ($am_registration['am_preset_save'] && empty($am_registration['am_preset_name']))
		{
			$this->warn_msg[] = $user->lang['NO_PRESET_NAME'];
		}
	}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="language/en/acp/common.php">
    <edit>
        <find><![CDATA[	'ACP_WORDS'					=> 'Word censoring',
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	'ACP_AM'			=> 'Attendance Mod',
	'ACP_AM_PRESETS'		=> 'Presets',
// --- Attendance Mod End -----------------------------------------------------
        ]]></action>
    </edit>
    <edit>
        <find><![CDATA[	'LOG_WORD_EDIT'			=> '<strong>Edited word censor</strong><br /> %s',
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	'AM_LOG_PRESET_ADD'		=> '<strong>Added registration preset</strong><br /> Preset name: %s',
	'AM_LOG_PRESET_DELETE'	=> '<strong>Deleted registration preset</strong><br /> Preset name: %s',
	'AM_LOG_PRESET_EDIT'	=> '<strong>Edited registration preset</strong><br /> Preset name: %s',
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/posting_buttons.html">
    <edit>
        <find><![CDATA[	var panels = new Array('options-panel', 'attach-panel', 'poll-panel');]]></find>
        <action type="before-add"><![CDATA[	<!-- Attendance Mod Start -->]]></action>
    </edit>
	<edit>
        <find><![CDATA[	var panels = new Array('options-panel', 'attach-panel', 'poll-panel');]]></find>
        <inline-edit>
            <inline-find><![CDATA[, 'poll-panel']]></inline-find>
            <inline-action type="after-add"><![CDATA[, 'am-panel']]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[	var show_panel = 'options-panel';]]></find>
        <action type="before-add"><![CDATA[	<!-- Attendance Mod End -->]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/posting_editor.html">
    <edit>
        <find><![CDATA[				<!-- IF S_SHOW_POLL_BOX || S_POLL_DELETE --><li id="poll-panel-tab"><a href="#tabs" onclick="subPanels('poll-panel'); return false;"><span>{L_ADD_POLL}</span></a></li><!-- ENDIF -->]]></find>
        <action type="after-add"><![CDATA[				<!-- Attendance Mod Start -->
				<!-- IF S_SHOW_AM_BOX || S_AM_DELETE --><li id="am-panel-tab"><a href="#tabs" onclick="subPanels('am-panel'); return false;"><span>{L_ADD_AM}</span></a></li><!-- ENDIF -->
				<!-- Attendance Mod End -->]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/posting_layout.html">
    <edit>
        <find><![CDATA[<!-- IF S_SHOW_POLL_BOX or S_POLL_DELETE --><!-- INCLUDE posting_poll_body.html --><!-- ENDIF -->
        ]]></find>
        <action type="after-add"><![CDATA[<!-- Attendance Mod Start -->
<!-- IF S_SHOW_AM_BOX or S_AM_DELETE --><!-- INCLUDE posting_am_body.html --><!-- ENDIF -->
<!-- Attendance Mod End -->
        ]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/posting_preview.html">
    <edit>
        <find><![CDATA[	<div class="postbody">
		<h3>{L_PREVIEW}: {PREVIEW_SUBJECT}</h3>]]></find>
        <action type="before-add"><![CDATA[<!-- Attendance Mod Start -->
{S_AM_LAYOUT}
<!-- Attendance Mod End -->]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/search_results.html">
    <edit>
        <find><![CDATA[<!-- IF searchresults.S_TOPIC_REPORTED --><a href="{searchresults.U_MCP_REPORT}">{REPORTED_IMG}</a><!-- ENDIF -->]]></find>
        <action type="after-add"><![CDATA[<!-- Attendance Mod Start --><!-- IF searchresults.S_TOPIC_REGISTRATION -->&nbsp;{searchresults.TOPIC_REGISTRATIONS}<!-- ENDIF --><!-- Attendance Mod End -->]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/viewforum_body.html">
    <edit>
        <find><![CDATA[<dt><!-- IF S_DISPLAY_ACTIVE -->{L_ACTIVE_TOPICS}<!-- ELSEIF topicrow.S_TOPIC_TYPE_SWITCH and topicrow.S_TOPIC_TYPE gt 1 -->{L_ANNOUNCEMENTS}<!-- ELSE -->{L_TOPICS}<!-- ENDIF --></dt>]]></find>
        <action type="after-add"><![CDATA[<!-- Attendance Mod Start --><dd class="registrations">{L_REPLIES}</dd><!-- Attendance Mod End -->]]></action>
    </edit>
    <edit>
        <find><![CDATA[					<!-- IF topicrow.S_TOPIC_REPORTED --><a href="{topicrow.U_MCP_REPORT}">{REPORTED_IMG}</a><!-- ENDIF -->]]></find>
        <action type="after-add"><![CDATA[<!-- Attendance Mod Start --><!-- IF topicrow.S_TOPIC_REGISTRATION -->&nbsp;{topicrow.TOPIC_REGISTRATIONS}<!-- ENDIF --><!-- Attendance Mod End -->]]></action>
    </edit>
</open>
<open src="styles/prosilver/template/viewtopic_body.html">
    <edit>
        <find><![CDATA[
<!-- BEGIN postrow -->]]></find>
        <action type="before-add"><![CDATA[<!-- Attendance Mod Start -->
{S_AM_LAYOUT}
<!-- Attendance Mod End -->]]></action>
    </edit>
</open>
<open src="styles/prosilver/theme/stylesheet.css">
    <edit>
        <find><![CDATA[@import url("colours.css");]]></find>
        <action type="after-add"><![CDATA[/* --- Attendance Mod Start --------------------------------------------------- */
@import url("colour_picker.css");
@import url("attendance_mod.css");
/* --- Attendance Mod End ----------------------------------------------------- */]]></action>
    </edit>
</open>
<open src="styles/prosilver/theme/tweaks.css">
    <edit>
        <find><![CDATA[* html .column1, * html .column2 { width: 45%; }
        ]]></find>
        <action type="after-add"><![CDATA[/* --- Attendance Mod Start --------------------------------------------------- */
/* Inline Insert: , dl.am_registrations:after */]]></action>
    </edit>
	<edit>
        <find><![CDATA[#tabs:after, #minitabs:after, .post:after, .navbar:after, fieldset dl:after, ul.topiclist dl:after, ul.linklist:after, dl.polls:after {]]></find>
        <inline-edit>
            <inline-find><![CDATA[, dl.polls:after]]></inline-find>
            <inline-action type="after-add"><![CDATA[, dl.am_registrations:after]]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[	visibility: hidden;
}*/]]></find>
        <action type="after-add"><![CDATA[/* --- Attendance Mod End ----------------------------------------------------- */

/* --- Attendance Mod Start --------------------------------------------------- */
/* Inline Insert: , dl.am_registrations */]]></action>
    </edit>
	<edit>
        <find><![CDATA[.clearfix, #tabs, #minitabs, fieldset dl, ul.topiclist dl, dl.polls {]]></find>
        <inline-edit>
            <inline-find><![CDATA[, dl.polls]]></inline-find>
            <inline-action type="after-add"><![CDATA[, dl.am_registrations]]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[
/* viewtopic fix */]]></find>
        <action type="before-add"><![CDATA[/* --- Attendance Mod End ----------------------------------------------------- */]]></action>
    </edit>
</open>
<open src="posting.php">
    <edit>
        <find><![CDATA[include($phpbb_root_path . 'includes/message_parser.' . $phpEx);]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
include($phpbb_root_path . 'includes/functions_am.' . $phpEx);
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[	upload_popup($post_data['forum_style']);
	exit_handler();
}
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", 'mods/am_posting'"]]></action>
    </edit>
	<edit>
        <find><![CDATA[$user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);]]></find>
        <inline-edit>
            <inline-find><![CDATA[, 'viewtopic']]></inline-find>
            <inline-action type="after-add"><![CDATA[, 'mods/am_posting']]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[
// Use post_row values in favor of submitted ones...]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[$post_data['poll_options']		= array();]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
$post_data['am_start']			= (!empty($post_data['am_start'])) ? (int) $post_data['am_start'] : 0;
$post_data['am_length']			= (!empty($post_data['am_length'])) ? (int) $post_data['am_length'] / 86400 : 0;
$post_data['am_visible']		= (isset($post_data['am_visible'])) ? (bool) $post_data['am_visible'] : 1;
$post_data['am_confirmable']	= (isset($post_data['am_confirmable'])) ? (bool) $post_data['am_confirmable'] : 0;
$post_data['am_reg_change']		= (isset($post_data['am_reg_change'])) ? (bool) $post_data['am_reg_change'] : 1;
$post_data['am_layout']			= (!empty($post_data['am_layout'])) ? (int) $post_data['am_layout'] : 0;
$post_data['am_preset_save']	= (isset($post_data['am_preset_save'])) ? (bool) $post_data['am_preset_save'] : 1;
$post_data['am_options_id']		= array();
$post_data['am_options']		= array();
$post_data['am_options_max']	= array();
$post_data['am_options_color']	= array();
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[$orig_poll_options_size = sizeof($post_data['poll_options']);]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
// Get Registration Data
if ($post_data['am_start'])
{
	$sql = 'SELECT am_option_id, am_option_text, am_option_max, am_option_color
		FROM ' . AM_OPTIONS_TABLE . "
		WHERE topic_id = $topic_id
		ORDER BY am_option_id";
	$result = $db->sql_query($sql);

	while ($row = $db->sql_fetchrow($result))
	{
		$post_data['am_options_id'][]		= trim($row['am_option_id']);
		$post_data['am_options'][]			= trim($row['am_option_text']);
		$post_data['am_options_max'][]		= trim($row['am_option_max']);
		$post_data['am_options_color'][]	= '#'.trim($row['am_option_color']);
	}
	$db->sql_freeresult($result);
}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[	$poll_delete		= (isset($_POST['poll_delete'])) ? true : false;]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	$am_delete	= (isset($_POST['am_delete'])) ? true : false;
	$am_reset	= (isset($_POST['am_reset'])) ? true : false;
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[		$post_data['poll_vote_change']	= ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
	}
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert

	// Delete Registration
	if ($am_delete && $mode == 'edit' && sizeof($post_data['am_options']) &&
		(($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id)))
	{
		if ($submit)
		{
			$sql = 'DELETE FROM ' . AM_OPTIONS_TABLE . "
				WHERE topic_id = $topic_id";
			$db->sql_query($sql);

			$sql = 'DELETE FROM ' . AM_REGISTRATIONS_TABLE . "
				WHERE topic_id = $topic_id";
			$db->sql_query($sql);

			$topic_sql = array(
				'am_start'			=> 0,
				'am_length'			=> 0,
				'am_visible'		=> 0,
				'am_confirmable'	=> 0,
				'am_reg_change'		=> 0,
				'am_layout'			=> 0
			);

			$sql = 'UPDATE ' . TOPICS_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
				WHERE topic_id = $topic_id";
			$db->sql_query($sql);
		}

		$post_data['am_options'] = array();
		$post_data['am_start'] = $post_data['am_length'] = $post_data['am_visible'] = $post_data['am_confirmable'] = $post_data['am_reg_change'] = $post_data['am_layout'] = 0;
	}
	else
	{
		$post_data['am_length']			= request_var('am_length', 0, true);
		$post_data['am_options']		= utf8_normalize_nfc(request_var('am_option_text', array(''), true));
		$post_data['am_options_max']	= utf8_normalize_nfc(request_var('am_option_max', array(''), true));
		$post_data['am_options_color']	= utf8_normalize_nfc(request_var('am_option_color', array(''), true));
		$post_data['am_options_id']		= request_var('am_option_id', array(''), true);
		$post_data['am_visible']		= (isset($_POST['am_visible'])) ? 1 : 0;
		$post_data['am_confirmable']	= (isset($_POST['am_confirmable'])) ? 1 : 0;
		$post_data['am_reg_change']		= (isset($_POST['am_reg_change'])) ? 1 : 0;
		$post_data['am_layout']			= request_var('am_layout', 0);
		$post_data['am_preset_save']	= (isset($_POST['am_preset_save'])) ? 1 : 0;
		$post_data['am_preset_name']	= utf8_normalize_nfc(request_var('am_preset_name', '', true));
	}

	if ($am_reset && $mode == 'edit' && sizeof($post_data['am_options']) &&
		(($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id)))
	{
		if ($submit)
		{
			$sql = 'DELETE FROM ' . AM_REGISTRATIONS_TABLE . "
				WHERE topic_id = $topic_id";
			$db->sql_query($sql);

			$topic_sql = array(
				'am_start'			=> $post_data['am_start'],
				'am_length'			=> $post_data['am_length'],
				'am_visible'		=> $post_data['am_visible'],
				'am_confirmable'	=> $post_data['am_confirmable'],
				'am_reg_change'		=> $post_data['am_reg_change'],
				'am_layout'			=> $post_data['am_layout']
			);

			$sql = 'UPDATE ' . TOPICS_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
				WHERE topic_id = $topic_id";
			$db->sql_query($sql);
		}
	}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[		$poll = array();
	}]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	if ($post_data['am_options'] &&
		($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
		&& $auth->acl_get('f_xam_create', $forum_id))
	{
		$am_registration = array(
			'am_start'			=> $post_data['am_start'],
			'am_length'			=> $post_data['am_length'],
			'am_options_id'		=> $post_data['am_options_id'],
			'am_options'		=> $post_data['am_options'],
			'am_options_max'	=> $post_data['am_options_max'],
			'am_options_color'	=> $post_data['am_options_color'],
			'am_visible'		=> $post_data['am_visible'],
			'am_confirmable'	=> $post_data['am_confirmable'],
			'am_reg_change'		=> $post_data['am_reg_change'],
			'am_layout'			=> $post_data['am_layout'],
			'am_preset_save'	=> $post_data['am_preset_save'],
			'am_preset_name'	=> $post_data['am_preset_name']
		);

		$message_parser->parse_registration($am_registration, $forum_id);
	}
	else
	{
		$am_registration = array();
	}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[				$data['topic_replies'] = $post_data['topic_replies'];
			}

			unset($message_parser);]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", $am_registration"]]></action>
    </edit>
	<edit>
        <find><![CDATA[$redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);]]></find>
        <inline-edit>
            <inline-find><![CDATA[, $poll]]></inline-find>
            <inline-action type="after-add"><![CDATA[, $am_registration]]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[$post_need_approval = (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? true : false;]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[		unset($preview_poll_options);
	}
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
	// Registration Preview
	if (!$am_delete && ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
	&& $auth->acl_get('f_xam_create', $forum_id))
	{
		$s_am_layout 	= 'posting_preview_am_' . $post_data['am_layout'] . '.html';

		$template->assign_vars(array(
			'S_AM_LAYOUT'		=> am_registration_preview($s_am_layout, $post_data))
		);
	}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[
// Attachment entry]]></find>
        <action type="before-add"><![CDATA[
// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
// Attendance entry
if (($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))	&& $auth->acl_get('f_xam_create', $forum_id))
{
	$preview_am_options 		= $post_data['am_options'];
	$preview_am_options_max		= $post_data['am_options_max'];
	$preview_am_options_color	= $post_data['am_options_color'];
	$preview_am_options_id		= $post_data['am_options_id'];

	$post_data['am_options']		= array();
	$post_data['am_options_max']	= array();
	$post_data['am_options_color']	= array();
	$post_data['am_options_id']		= array();

	$count = 0;

	foreach ($preview_am_options as $key => $option)
	{
		if (!empty($option))
		{
			$post_data['am_options'][$key]			= '"'.$option.'"';
			$post_data['am_options_max'][$key]		= '"'.$preview_am_options_max[$count].'"';
			$post_data['am_options_color'][$key]	= '"'.$preview_am_options_color[$count].'"';
			$post_data['am_options_id'][$key]		= '"'.$preview_am_options_id[$count].'"';
		}
		$count++;
	}
	unset($preview_am_options);
	$s_am_preset_options = '<option value="">' . $user->lang['AM_PRESET'] . '</option><option value="" disabled="disabled">------------------------</option>';

	$am_length_ary 		= array();
	$am_visible_ary 	= array();
	$am_confirmable_ary = array();
	$am_reg_change_ary 	= array();
	$am_layout_ary 		= array();

	$am_options_jscode = '';

	$s_am_presets = array();

	$s_am_presets = am_get_preset_data();

	$count = 0;
	foreach($s_am_presets as $presets)
	{
		$s_am_preset_options	.= '<option value="' . $count . '">' . $presets['am_preset_name'] . '</option>';
		$am_length_ary[]		= $presets['am_length'];
		$am_visible_ary[]		= $presets['am_visible'];
		$am_confirmable_ary[]	= $presets['am_confirmable'];
		$am_reg_change_ary[]	= $presets['am_reg_change'];
		$am_layout_ary[]		= $presets['am_layout'];

		$am_actual_option_text	= htmlspecialchars_decode(str_replace("'", "\'", $presets['am_option_text']));
		$am_actual_option_max	= htmlspecialchars_decode(str_replace("'", "\'", $presets['am_option_max']));
		$am_actual_option_color = htmlspecialchars_decode(str_replace("'", "\'", $presets['am_option_color']));

		$am_options_jscode		.= "construct_options('$am_actual_option_text','$am_actual_option_max','$am_actual_option_color');";
		$count++;
	}

	$s_am_layout_options = '';
	for ($i=0; $i<2; $i++)
	{
		$am_layout_option_name		= 'AM_LAYOUT_'.$i;
		$am_layout_option_lang		= $user->lang[$am_layout_option_name];
		$am_layout_option_checked	= (($post_data['am_layout'] == $i) ? 'selected="selected"' : '');
		$s_am_layout_options		.= '<option value="' . $i . '"' . $am_layout_option_checked . '>' . $am_layout_option_lang . '</option>';
	}

	$template->assign_vars(array(
		'S_SHOW_AM_BOX'				=> true,
		'S_AM_PRESET'				=> (($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))	&& $auth->acl_get('f_xam_preset', $forum_id)),
		'S_AM_DELETE'				=> ($mode == 'edit' && sizeof($post_data['am_options']) && (($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))),
		'S_AM_DELETE_CHECKED'		=> (!empty($am_delete)) ? true : false,
		'S_AM_RESET_CHECKED'		=> (!empty($am_reset)) ? true : false,

		'S_AM_PRESET_OPTIONS'		=> $s_am_preset_options,
		'S_AM_LAYOUT_OPTIONS'		=> $s_am_layout_options,

		'AM_OPTIONS_JSCODE'			=> $am_options_jscode,
		'AM_LENGTH_ARRAY'			=> implode(", ", $am_length_ary),
		'AM_VISIBLE_ARRAY'			=> implode(", ", $am_visible_ary),
		'AM_CONFIRMABLE_ARRAY'		=> implode(", ", $am_confirmable_ary),
		'AM_REG_CHANGE_ARRAY'		=> implode(", ", $am_reg_change_ary),
		'AM_LAYOUT_ARRAY'			=> implode(", ", $am_layout_ary),

		'AM_OPTIONS'				=> (!empty($post_data['am_options'])) ? implode(",", $post_data['am_options']) : '',
		'AM_OPTIONS_MAX'			=> (!empty($post_data['am_options_max'])) ? implode(",", $post_data['am_options_max']) : '',
		'AM_OPTIONS_COLOR'			=> (!empty($post_data['am_options_color'])) ? implode(",", $post_data['am_options_color']) : '',
		'AM_OPTIONS_ID'				=> (!empty($post_data['am_options_id'])) ? implode(",", $post_data['am_options_id']) : '',

		'AM_LAYOUT'					=> (isset($post_data['am_layout'])) ? (int) $post_data['am_layout'] : '',

		'AM_LENGTH'					=> (isset($post_data['am_length'])) ? (int) $post_data['am_length'] : '',
		'AM_ACTIVATE_CHECKED'		=> (!empty($post_data['am_visible'])) ? ' checked="checked"' : '',
		'AM_CONFIRMATION_CHECKED'	=> (!empty($post_data['am_confirmable'])) ? ' checked="checked"' : '',
		'AM_REG_CHANGE_CHECKED'		=> (!empty($post_data['am_reg_change'])) ? ' checked="checked"' : ''
		)
	);
}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="search.php">
    <edit>
        <find><![CDATA[		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
		include($phpbb_root_path . 'includes/functions_am.' . $phpEx);
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[				$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$result_topic_id", true, $user->session_id) : '';
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
				$am_summary	= '';
				if ($row['am_start'] > 0)
				{
					$am_summary		= am_get_summary($row['topic_id']);
					$s_am_has_reg	= true;
				}
				else
				{
					$s_am_has_reg	= false;
				}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[					'TOPIC_TYPE'		=> $topic_type,
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
					'TOPIC_REGISTRATIONS'	=> $am_summary,
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[					'S_UNREAD_TOPIC'		=> $unread_topic,
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
					'S_TOPIC_REGISTRATION'	=> $s_am_has_reg,
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="viewforum.php">
    <edit>
        <find><![CDATA[include($phpbb_root_path . 'includes/functions_display.' . $phpEx);]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
include($phpbb_root_path . 'includes/functions_am.' . $phpEx);
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[		$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
		$am_summary	= '';
		if ($row['am_start'] > 0)
		{
			$am_summary		= am_get_summary($row['topic_id']);
			$s_am_has_reg	= true;
		}
		else
		{
			$s_am_has_reg	= false;
		}
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[			'TOPIC_TYPE'		=> $topic_type,
        ]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
			'TOPIC_REGISTRATIONS'	=> $am_summary,
// --- Attendance Mod End -----------------------------------------------------
        ]]></action>
    </edit>
    <edit>
        <find><![CDATA[			'S_UNREAD_TOPIC'		=> $unread_topic,]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
			'S_TOPIC_REGISTRATION'	=> $s_am_has_reg,
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
</open>
<open src="viewtopic.php">
    <edit>
        <find><![CDATA[include($phpbb_root_path . 'includes/bbcode.' . $phpEx);]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
include($phpbb_root_path . 'includes/functions_am.' . $phpEx);
// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[			// Setup user environment so we can process lang string]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", 'mods/am_viewtopic'"]]></action>
    </edit>
	<edit>
        <find><![CDATA[			// Setup user environment so we can process lang string
			$user->setup('viewtopic');]]></find>
        <inline-edit>
            <inline-find><![CDATA['viewtopic']]></inline-find>
            <inline-action type="after-add"><![CDATA[, 'mods/am_viewtopic']]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[			trigger_error('NO_TOPIC');
		}

		$post_id = $row['post_id'];]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[	else if ($view == 'next' || $view == 'previous')
	{
		$sql_condition = ($view == 'next') ? '>' : '<';
		$sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';

		$sql = 'SELECT forum_id, topic_last_post_time
			FROM ' . TOPICS_TABLE . '
			WHERE topic_id = ' . $topic_id;
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		if (!$row)
		{]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", 'mods/am_viewtopic'"	]]></action>
    </edit>
	<edit>
        <find><![CDATA[			$user->setup('viewtopic');
			// OK, the topic doesn't exist. This error message is not helpful, but technically correct.]]></find>
        <inline-edit>
            <inline-find><![CDATA['viewtopic']]></inline-find>
            <inline-action type="after-add"><![CDATA[, 'mods/am_viewtopic']]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[			// OK, the topic doesn't exist. This error message is not helpful, but technically correct.]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------	]]></action>
    </edit>
    <edit>
        <find><![CDATA[		else
		{
			$sql = 'SELECT topic_id, forum_id
				FROM ' . TOPICS_TABLE . '
				WHERE forum_id = ' . $row['forum_id'] . "
					AND topic_moved_id = 0
					AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
					" . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . "
				ORDER BY topic_last_post_time $sql_ordering";
			$result = $db->sql_query_limit($sql, 1);
			$row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);

			if (!$row)
			{]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Inline Insert ", 'mods/am_viewtopic'"]]></action>
    </edit>
	<edit>
        <find><![CDATA[				$user->setup('viewtopic');
				trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
			}
			else
			{
				$topic_id = $row['topic_id'];]]></find>
        <inline-edit>
            <inline-find><![CDATA['viewtopic']]></inline-find>
            <inline-action type="after-add"><![CDATA[, 'mods/am_viewtopic']]></inline-action>
        </inline-edit>
    </edit>
    <edit>
        <find><![CDATA[				trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
			}
			else
			{
				$topic_id = $row['topic_id'];]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------	]]></action>
    </edit>
    <edit>
        <find><![CDATA[// Setup look and feel]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Replace, old line was "$user->setup('viewtopic', $topic_data['forum_style']);"]]></action>
    </edit>
	<edit>
        <find><![CDATA[$user->setup('viewtopic', $topic_data['forum_style']);]]></find>
        <inline-edit>
            <inline-find><![CDATA[setup(]]></inline-find>
            <inline-action type="after-add"><![CDATA[array(]]></inline-action>
            <inline-find><![CDATA['viewtopic']]></inline-find>
            <inline-action type="after-add"><![CDATA[, 'mods/am_viewtopic')]]></inline-action>
        </inline-edit>
    </edit>
	<edit>
        <find><![CDATA[
if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))]]></find>
        <action type="before-add"><![CDATA[// --- Attendance Mod End -----------------------------------------------------]]></action>
    </edit>
    <edit>
        <find><![CDATA[	unset($poll_end, $poll_info, $voted_id);
}]]></find>
        <action type="after-add"><![CDATA[// --- Attendance Mod Start ---------------------------------------------------
// Type: Insert
// Does this topic contain a registration?
if (!empty($topic_data['am_start']) && !empty($topic_data['am_visible']))
{
	$am_option_info					= array();
	$cur_option_id					= '';
	$am_registration_data			= array();
	$s_am_registration				= array();

	$am_option_info					= am_get_options($topic_id);
	$cur_am_option_id				= am_get_cur_user_registration_data($topic_id);
	$am_registration_data			= am_get_registration_data($topic_id);
	$am_registration_permissions	= am_check_permissions($topic_data, $cur_am_option_id, $forum_id);
	$am_regoption_id				= 0;

	foreach ($am_option_info as $am_option)
	{
		$am_option_id = 'am_register_'.$am_option['am_option_id'];
		if (isset($_POST[$am_option_id]))
		{
			$am_regoption_id = $am_option['am_option_id'];
		}
	}

	if ($am_regoption_id && $am_registration_permissions['register'])
	{
		if ($am_regoption_id == $cur_am_option_id)
		{
			$sql = 'UPDATE ' . AM_REGISTRATIONS_TABLE . '
				SET am_registration_confirmed = ' . time() . '
				WHERE am_option_id = ' . (int) $am_regoption_id . '
					AND topic_id = ' . (int) $topic_id;
			$db->sql_query($sql);
		}
		else if ($user->data['is_registered'])
		{
			$sql_ary = array(
				'topic_id'					=> (int) $topic_id,
				'am_option_id'				=> (int) $am_regoption_id,
				'am_user_id'				=> (int) $user->data['user_id'],
				'am_user_ip'				=> (string) $user->ip,
				'am_registration_time'		=> (int) time(),
				'am_registration_confirmed'	=> (int) 0
			);

			if($cur_am_option_id)
			{
				$sql = 'DELETE FROM ' . AM_REGISTRATIONS_TABLE . '
					WHERE topic_id = ' . (int) $topic_id . '
						AND am_option_id = ' . (int) $cur_am_option_id . '
						AND am_user_id = ' . (int) $user->data['user_id'];
				$db->sql_query($sql);
			}

			$sql = 'INSERT INTO ' . AM_REGISTRATIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
			$db->sql_query($sql);
		}

		$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start");

		meta_refresh(5, $redirect_url);
		trigger_error($user->lang['AM_REGISTRATION_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
	}
	else if (isset($_POST['am_unregister']) && $am_registration_permissions['unregister'])
	{
		$sql = 'DELETE FROM ' . AM_REGISTRATIONS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND am_option_id = ' . (int) $cur_am_option_id . '
				AND am_user_id = ' . (int) $user->data['user_id'];
		$db->sql_query($sql);

		$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start");

		meta_refresh(5, $redirect_url);
		trigger_error($user->lang['AM_REGISTRATION_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
	}

	$s_am_layout = 'viewtopic_am_' . $topic_data['am_layout'] . '.html';

	$template->assign_vars(array(
		'S_AM_LAYOUT'	=> am_registration_display($s_am_layout, $am_option_info, $am_registration_data, $topic_data, $cur_am_option_id, $am_registration_permissions, $viewtopic_url))
	);

	unset($am_end, $am_option_info, $am_registration_data, $cur_am_option_id, $am_regoption_id);
}
// --- Attendance Mod End -----------------------------------------------------
        ]]></action>
    </edit>
</open>

<diy-instructions lang="en">
 Open install_am/install.php in your web browser.
 Delete the install_am folder after execution of install.php.
</diy-instructions>
  </action-group>
</mod>
