HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/modules/form/module.form.php
<?php

class iwp_module_form extends iwp_module
{
	public
		$baseTableName  = 'whatever',
		$moduleName     = 'form',
		$hasBlocks      = true,
		$controller     = 'admin',
		$action         = 'index',
		$renderLayout   = true,
		$renderTemplate = true;

	protected $eventListeners = array(
			'iwp_event_admin_navigation_dropdownmenucreated' => array(
					'iwp_module_form',
					'OnDropdownMenuCreated'
				),
			'iwp_event_admin_content_tinymceplugin' => array(
					'iwp_module_form',
					'TinyMCEPluginHook'
				),
			'iwp_event_content_afterdbload' => array(
					'iwp_module_form',
					'ViewContentHook'
				),
			'iwp_event_categories_beforeshowtemplate' => array(
					'iwp_module_form',
					'onCategoriesBeforeShowTemplate'
				),
			'iwp_event_template_outputblockbeforeparsesection' => array(
					'iwp_module_form',
					'onOutputBlockBeforeParseSection'
				),
			'iwp_event_users_beforeprofiledisplay' => array(
					'iwp_module_form', 'onUserProfileDisplay'
				)
		);

	public static $SitePermissionOptions = array();

	/**
	 * Holds the instance to iwp_module_form
	 *
	 * @var Object iwp_module_form $_instance
	 */
	private static $instance;



	/**
	 * Constructor.
	 *
	 * @return Object iwp_module_form
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Returns a list of database tables for this module.
	 *
	 * @param boolean $withoutPrefix A boolean for whether or not to include the prefix for the table.
	 *
	 * @return string
	 */
	public function getTables($withoutPrefix=false) {

		$tables = array(
			iwp_module_form_model_field::BASE_TABLE_NAME,
			iwp_module_form_model_form::BASE_TABLE_NAME,
			iwp_module_form_model_response::BASE_TABLE_NAME,
			iwp_module_form_model_response_value::BASE_TABLE_NAME,
			iwp_module_form_model_widget::BASE_TABLE_NAME,
		);

		// remove the module_ from all the tables, as this is included in the IWP_MODULE_DB_PREFIX constant
		// and we don't want it if we're returning without the prefix
		foreach($tables as $k=>$table ){
			if(substr($table, 0, 7) == 'module_') {
				$tables[$k] = substr($table, 7);
			}
		}

		if($withoutPrefix) {
			return $tables;
		}

		foreach($tables as $k=>$table ){
			$tables[$k] = IWP_MODULE_DB_PREFIX . $table;
		}

		return $tables;
	}

	/**
	 * Returns this module's site-wide permission options
	 *
	 * @return array
	 */
	public static function GetSitePermissionOptions () {
		return self::$SitePermissionOptions;
	}

	/**
	 * Returns this module's content-type-specific permission options
	 *
	 * @return array
	 */
	public static function GetContentPermissionOptions () {
		return self::$ContentPermissionOptions;
	}


	/**
	 * Returns a granularity list for this class to be displayed on the group permissions page
	 *
	 * @param Integer $total Total will be populated with number of rows found in query (by reference)
	 * @param String $filter Filter string, optional
	 * @param Integer $page Page number of records to return, optional
	 * @return Array List of value/text pairs
	 */
	public static function getGranularityList (&$total, &$page, $filter = '') {
		$forms = iwp_module_form_model_form::getForms();
		$total = iwp_module_form_model_form::getNumForms();
		$list  = array();

		if ($forms) {
			foreach ($forms as $form) {
				$form->text  = $form->name;
				$form->value = $form->id;

				array_push($list, (array) $form);
			}
		}

		return (array) $list;
	}

	/**
	 * Listener for the iwp_event_admin_navigation_dropdownmenucreated event
	 *
	 * @param iwp_event_admin_navigation_dropdownmenucreated $data
	 */
	public static function OnDropdownMenuCreated(iwp_event_admin_navigation_dropdownmenucreated $data)
	{
		$auth             = iwp_admin_auth::getInstance();
		$canCreateForms   = $auth->HasPerm('sitemodules', 'form', 'createForms', '*');
		$canEditForms     = $auth->HasPerm('sitemodules', 'form', 'editForms', '*');
		$canDeleteForms   = $auth->HasPerm('sitemodules', 'form', 'deleteForms', '*');
		$canViewResponses = $auth->HasPerm('sitemodules', 'form', 'viewResponses', '*');
		$canViewForms     = $canCreateForms || $canEditForms || $canDeleteForms || $canViewResponses;
		
		if (!$canViewForms) {
			return false;
		}
	
		$module           = iwp_module_form::getInstance();
		$contentMenuIndex = array_search('mnuContent', array_keys($data->menuItems));
		$linkPrefix       = 'index.php?section=module&action=custom&module=form&';
		$menu             = array();
		
		$menu[] = array(
				'text' => $module->lang->Get('menuTitleViewForms'),
				'link' => $linkPrefix,
				'show' => true,
				'help' => $module->lang->Get('menuDetailViewForms'),
				'icon' => '../../modules/form/images/application_form_magnify.png',
			);
		
		if ($canCreateForms) {
			$menu[] = array(
					'text' => $module->lang->Get('menuTitleCreateForm'),
					'link' => $linkPrefix . 'moduleAction=edit.form',
					'show' => true,
					'help' => $module->lang->Get('menuDetailCreateForm'),
					'icon' => '../../modules/form/images/application_form_edit.png',
				);
		}
		
		if ($canViewResponses) {
			$menu[] = array(
					'text' => $module->lang->Get('menuTitleViewResponses'),
					'link' => $linkPrefix . 'moduleAction=view.responses',
					'show' => true,
					'help' => $module->lang->Get('menuDetailViewResponses'),
					'icon' => '../../modules/form/images/report_magnify.png',
				);
				
			$menu[] = array(
					'text' => $module->lang->Get('menuTitleExportResponses'),
					'link' => $linkPrefix . 'moduleAction=export.responses',
					'show' => true,
					'help' => $module->lang->Get('menuDetailExportResponses'),
					'icon' => '../../modules/form/images/page_excel.png',
				);
		}

		//	content menu not found or content menu is at end of tab list, insert at end of tab list
		if ($contentMenuIndex === false || $contentMenuIndex == count($data->menuItems) - 1) {
			$data->menuItems['module_form'] = $menu;
		//	otherwise insert after the content tab
		} else {
			iwp_module_form::ArrayInsert($data->menuItems, $contentMenuIndex + 1, array('module_form' => $menu));
		}

		// figure out if we are in the form section
		if (@$_GET['section'] == 'module' && @$_GET['action'] == 'custom' && @$_GET['module'] == 'form') {
			$data->currentMenu = 'module_form';
		}
	}

	/**
	 * Listens for the tinymce plugin event. It first generates javascript to set the language registry variables and then
	 * dispatches the call to the tinymce plugin.
	 *
	 * @return Void
	 * @param  iwp_event_admin_content_tinymceplugin $data
	 */
	public static function TinyMCEPluginHook(iwp_event_admin_content_tinymceplugin $data)
	{
		$data->code .= "
			;(function($) {
				var 
					// language variables
					lang = " . json_encode(self::getInstance()->lang->GetLangVars()) . ",
				
					// define the iModal buttons
					iModalButtons = ''
						+ '<button id=\"tinymce-module-form-imodal-close\" type=\"button\" style=\"float: left;\">' + lang.tinymceIModalCancel + '</button>'
						+ '<button id=\"tinymce-module-form-imodal-insert\" type=\"button\" style=\"float: right; font-weight: bold;\" disabled=\"disabled\">' + lang.tinymceIModalInsert + '</button>';
				
				// create the plugin
				tinymce.create('tinymce.plugins.moduleForm', {
					
					init : function(editor, url) {
						editor.addCommand('mceInsertFeedbackForm', function() {
							var win = $.fn.window.create({
								title    : lang.tinymceIModalTitle,
								uri      : 'index.php?section=module&action=custom&module=form&moduleController=admin&moduleAction=tinymce.form-list',
								autoOpen : true
							}).buttons(iModalButtons);
							
							win.jQuery().bind('windowAfterOpen', function() {
								// imodal close button
								$('#tinymce-module-form-imodal-close').bind('click', function() {
									$.fn.window.closeAll();
								});
								
								// imodal insert button
								$('#tinymce-module-form-imodal-insert').bind('click', function() {
									_insertAndClose.apply($('#tinymce-module-form-list').find(':radio:checked'));
								});
								
								// when a form is double clicked, insert it
								$('#tinymce-module-form-list tr')
									.bind('click', function() {
										$('#tinymce-module-form-imodal-insert').removeAttr('disabled');
									})
									.bind('dblclick', function() {
										_insertAndClose.apply($(this).closest('tr').find(':radio'));
									});
								
								
								/**
								 * Inserts the selected feedback form and closes the iModal, but only
								 * if a form is actually selected for insertion.
								 */
								function _insertAndClose()
								{
									var radio = $(this);
									var id    = radio.val();
									
									// insert a placeholder for the feedback form, the id query string variable is set so it can be parsed 
									// by the script that will replace the placeholder with the actual form on the front end
									// tinyMCE.activeEditor.selection.setContent('<img id=\"feedback-form-placeholder-' + id + '\" src=\"' + iwp.config.get('adminPath') + '/index.php?section=module&action=custom&module=form&moduleAction=tinymce.placeholder&formId=' + id + '\" />');
									editor.execCommand('mceInsertContent', false, '<img id=\"feedback-form-placeholder-' + id + '\" src=\"' + iwp.config.get('adminPath') + '/index.php?section=module&action=custom&module=form&moduleAction=tinymce.placeholder&formId=' + id + '\" />');
									
									// close the modal
									$.fn.window.closeAll();
								}
							});
						});
						
						editor.addButton('moduleForm', {
							title : lang.tinymceIModalTitle,
							image : '../modules/form/images/tinymce_icon.png',
							cmd   : 'mceInsertFeedbackForm'
						});
					},
					
					getInfo : function() {
						
					}
					
				});
				
				// add the plugin
				tinymce.PluginManager.add('moduleForm', tinymce.plugins.moduleForm);
				
			})(jQuery);
		";
	}

	/**
	 * Modifies the content data parsing any form placeholders that are in the content.
	 *
	 * @return Void
	 * @param  iwp_event_content_afterdbload $data
	 */
	public static function ViewContentHook(iwp_event_content_afterdbload $data)
	{
		$thisClass = self::getInstance();
		$content   = iwp_content::getInstance();

		$content->Set('summary', $thisClass->parseContent($content->Get('summary')));
		$content->Set('content', $thisClass->parseContent($content->Get('content')));
	}
	
	/**
	 * Modifies the template before it is output to allow for content modification.
	 * 
	 * @return Void
	 * @param  iwp_event_categories_beforeshowtemplate $data
	 */
	public static function onCategoriesBeforeShowTemplate(iwp_event_categories_beforeshowtemplate $data)
	{
		$data->template->Assign('categoryDescription', self::getInstance()->parseContent($data->template->Get('categoryDescription')), false);
	}
	
	/**
	 * Modifies custom block output so that forms appear in custom blocks.
	 * 
	 * @return Void
	 * @param  iwp_event_template_outputblockbeforeparsesection $data
	 */
	public static function onOutputBlockBeforeParseSection(iwp_event_template_outputblockbeforeparsesection $data)
	{
		switch (strtolower($data->type)) {
			case 'customcontent':
				$data->template->Assign('blockContent', self::getInstance()->parseContent($data->template->Get('blockContent')), false);	
			break;
		}
	}
	
	/**
	 * Listener for the iwp_event_users_beforeprofiledisplay event which adjusts user biography output to 
	 * make forms appear on front end custom blocks.
	 *
	 * @param iwp_event_users_beforeprofiledisplay $data
	 */
	public static function onUserProfileDisplay (iwp_event_users_beforeprofiledisplay $data) {
		$data->user->Set('biography', self::getInstance()->parseContent($data->user->Get('biography')));
	}

	/**
	 * ArrayInsert
	 * Inserts one array into another at a given position.
	 *
	 * @param array $array The recipient array to be inserted into, passed by reference and will have it's pointer reset
	 * @param mixed $position The index (numeric) position at which to insert
	 * @param mixed $insert_array The array to be inserted
	 */
	private static function ArrayInsert(&$array, $position, $insertArray)
	{
		$firstArray = array_splice($array, 0, $position);
		$array      = array_merge($firstArray, $insertArray, $array);
	}

	/**
	 * Returns the singleton instance of iwp_module_form
	 *
	 * @return Object iwp_module_form
	 */
	public static function getInstance()
	{
		if (!self::$instance instanceof iwp_module_form) {
			self::$instance = new iwp_module_form();
		}

		return self::$instance;
	}

	/**
	 * Returns an array so the framework is happy. Otherwise it throws an error.
	 *
	 * @return Array
	 */
	public static function getURIMatches()
	{
		return array();
	}



	/**
	 * Parses the passed content replacing any form placeholders in the input string.
	 *
	 * @return String        - String of the parsed content.
	 * @param  String $content - The input string to parse.
	 */
	public function parseContent($content)
	{
		// the regex to match the form placeholder
		$matchRregex = '/<img.*id="feedback-form-placeholder-([0-9]+)".*\/>/';

		// find all form ids
		if (!preg_match_all($matchRregex, $content, $matches)) {
			return $content;
		}

		// the form ids are in the first match
		$formIds = $matches[1];

		// iterate through each one and replace each placeholder with the appropriate form html
		foreach ($formIds as $formId) {
			// cast
			$formId = (int) $formId;

			// return the parsed output
			$content = preg_replace('/<img.*id="feedback-form-placeholder-' . $formId . '".*\/>/', $this->getFormContent($formId), $content);
		}

		// return the parsed input
		return $content;
	}

	/**
	 * Returns the content for the specified form that has the passed $formId.
	 *
	 * @return string
	 *
	 * @param int    $formId   The id of the form to get the content for.
	 * $param string $position The position on the layout where the form was placed.
	 */
	public function getFormContent($formId, $position = 'middle')
	{
		// add the required javascript
		$this->template->AddRequiredJS(IWP_BASE_URI . '/javascript/jquery/plugins/jquery.plugin.js');
		$this->template->AddRequiredJS(IWP_BASE_URI . '/javascript/jquery/plugins/jquery.validate.js');

		// don't escape!
		$this->template->DefaultHtmlEscape = false;

		// set the template path so we can render the form templates
		$this->template->SetTemplatePath(realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates'));

		// give the form an action to handle the submission
		$this->template->Assign('action', iwp_config::get('siteURL') . '/form/handle-submit.html?formId=' . $formId);

		// if an id was retrieved
		$formInstance = new iwp_module_form_model_form($formId);

		// We only want to replace feedback forms that exist. If one doesn't exist, then we
		// need to replace the placeholder with nothing and continue replacing other placeholders
		// if they exist.
		if (!$formInstance->GetId()) {
			return '';
		}

		// get widget and form data
		$widgets = $formInstance->getWidgets();
		$form    = $formInstance->GetData();

		// language
		$this->template->Assign('langvars', $this->lang->GetLangVars());

		// and if there are widgets
		if ($widgets) {
			// iterate through each one
			foreach ($widgets as $k => &$widget) {
				// make sure this widget should be visible to users
				if ($widget->is_visible == 1 || $widget->type == 'section.break') {
					$widget->className = Interspire_String::camelCase($widget->type, true);

					$widgetErrors   = iwp_session::Get('module.form.' . $formInstance->GetId() . '.widgetErrors');
					$widgetInstance = new iwp_module_form_model_widget($widget->id);
					$widget->fields = $widgetInstance->getFields(false);

					// if there are errors for this widget, set them
					if ($widgetErrors && count($widgetErrors[$widget->id]) > 0) {
						$widget->errors = $widgetErrors[$widget->id];
					}

					// randomize the fields if told to do so
					if ($widget->is_random == 1) {
						shuffle($widget->fields);
					}

					// tack on an other field if one exists
					if ($otherField = $widgetInstance->getOtherField()) {
						$otherField->value = '__other__';

						$widget->fields[] = $otherField;
					}

					// if it is a file widget, then grab the file types
					if ($widget->type == 'file') {
						$widget->fileTypes    = preg_split('/\s*,\s*/', $widget->allowed_file_types);
						$widget->lastFileType = array_pop($widget->fileTypes);
					}

					// assign the widget information to the view
					$this->template->Assign('widget', $widget);

					// render the widget template
					$widget->template = $this->template->parseTemplate('widget.' . $widget->type, true, 'form');
				} else {
					unset($widgets[$k]);
				}
			}

			// clear the widget errors session variable
			iwp_session::Kill('module.form.' . $formInstance->GetId() . '.widgetErrors');
		}

		// assign the form, widget and widget-field data to the template
		$this->template->Assign('errorMessage', iwp_session::Get('module.form.' . $formInstance->GetId() . '.errorMessage'));
		$this->template->Assign('successMessage', iwp_session::Get('module.form.' . $formInstance->GetId() . '.successMessage'));
		$this->template->Assign('form', $form);
		$this->template->Assign('widgets', $widgets);

		// unset the message that was set, so it doesn't get displayed again
		iwp_session::Kill('module.form.' . $formInstance->GetId() . '.errorMessage');
		iwp_session::Kill('module.form.' . $formInstance->GetId() . '.successMessage');

		return $this->template->parseTemplate('form', true);
	}

	/**
	 * Shows a specific page based on the matched uri.
	 *
	 * @return Void
	 *
	 * @param String $uri - The uri that was matched.
	 */
	public function ShowPageByIniUri($uri)
	{
		// get the matched uri
		$matchedUri = $this->urls->GetCurrentModulePage();

		// instantiate the front end controller
		$controller = new iwp_module_form_controller();

		// route to the appropriate method, __call will handle anything that is undefined
		$controller->$matchedUri();
	}

	/**
	 * Returns an array of layout blocks that will show up in the feedback form module accordion list.
	 *
	 * @return array
	 */
	public function GetLayoutBlocks()
	{
		// get the forms
		$forms = iwp_module_form_model_form::getForms();

		// holds the block information to be returned
		$blocks = array();

		// format the blocks
		if ($forms) {
			foreach ($forms as $form) {
				$blocks[] = array(
						'id'   => 'FeedbackForm' . $form->id,
						'name' => $form->name,
						'icon' => IWP_MODULES_URI . '/' . $this->moduleName . '/images/tab_icon.png'
					);
			}
		}

		return $blocks;
	}

	/**
	 * Parses the form id from the passed $name and returns the content
	 * for the form with that id.
	 *
	 * @return string
	 *
	 * @param string $name
	 * @param string $pos
	 * @param string $id[optional]
	 */
	public function OutputBlock($name, $pos, $id = null)
	{
		$formId = (int) str_replace('FeedbackForm', '', $name);

		return $this->getFormContent($formId, $pos);
	}

	/**
	 * Routes the application to specific parts of the module.
	 *
	 * @return Void
	 */
	public function AdminCustom()
	{
		$ds       = DIRECTORY_SEPARATOR;
		$upDir    = '..' . $ds;
		$tpl      = $this->template;
		$baseDir  = dirname(__FILE__);
		$langvars = $this->lang->GetLangVars();
		
		// set permissions for views
		$tpl->Assign('userCan', array(
				'createForms'   => $this->auth->HasPerm('sitemodules', 'form', 'createForms', '*'),
				'editForms'     => $this->auth->HasPerm('sitemodules', 'form', 'editForms', '*'),
				'deleteForms'   => $this->auth->HasPerm('sitemodules', 'form', 'deleteForms', '*'),
				'viewResponses' => $this->auth->HasPerm('sitemodules', 'form', 'viewResponses', '*')
			));
		
		// assign the template var so that the breadcrumbs link correctly
		$tpl->Assign('module', 'form');

		// language variables for templates
		$tpl->Assign('langvars', $langvars);

		// language variables for javascript
		$tpl->Assign('jsonLangvars', json_encode($langvars));

		// override the default controller if a controller is set
		if (isset($_GET['moduleController'])) {
			$this->controller = $_GET['moduleController'];
		}

		// override the default action if an action is set
		if (isset($_GET['moduleAction'])) {
			$this->action = $_GET['moduleAction'];
		}

		// create names
		$controllerName = 'iwp_module_form_controller_' . Interspire_String::camelCase($this->controller);
		$actionName     = Interspire_String::camelCase($this->action) . 'Action';
		
		// set breadcrumb language variables
		iwp_language::getInstance()->Set('module_breadcrumb', $this->lang->Get('breadcrumb'));
		iwp_language::getInstance()->Set('module_custom_breadcrumb', $this->lang->Get('breadcrumb_' . $actionName));

		$messageText = iwp_session::Get('MessageText');
		$messageType = iwp_session::Get('MessageType');

		// set message info if it exists
		if ($messageText) {
			$tpl->Assign('MessageText', $messageText);
			$tpl->Assign('MessageType', $messageType);

			// remove message info from session
			iwp_session::Kill('MessageText');
			iwp_session::Kill('MessageType');
		}

		// create a new instance of the desired controller
		$controllerInstance = new $controllerName;

		// set the lang variable
		$controllerInstance->lang = $this->lang;

		// just extending iwp_base doesn't give us current template settings
		$controllerInstance->template = $this->template;

		// if the required action doesn't exist, then __call will handle the undefined action
		$controllerInstance->$actionName();

		// header and footer will wrap the content
		$header  = '';
		$message = '';
		$footer  = '';

		// if we are rendering the layout, we need to grab the main header and footer files before
		// we change the template directory for parsing module files
		if ($this->renderLayout) {
			$header  = $tpl->ParseTemplate('header', true);
			$message = $tpl->ParseTemplate('message', true);
			$footer  = $tpl->ParseTemplate('footer', true);
		}

		// set the flash message for the templates
		$tpl->Assign('flashMessage', $message);

		// wrap the content in the layout
		// if renderTemplate is false, then the layout will also be disabled
		if ($this->renderTemplate) {
			echo $header . $tpl->ParseTemplate($this->action, true, 'form') . $footer;
		}
	}

	/**
	 * Creates the database schema required for the form module. It sets the properties required
	 * for the module to install the database schema successfully. It also inserts the predefined
	 * forms if this is the first time installing it.
	 *
	 * @see iwp_tablecreator
	 *
	 * @return NULL
	 */
	public function CreateModuleTable()
	{
		// table names
		$tablePrefix            = GetConfig('tablePrefix');
		$fieldTableName         = $tablePrefix . iwp_module_form_model_field::BASE_TABLE_NAME;
		$formTableName          = $tablePrefix . iwp_module_form_model_form::BASE_TABLE_NAME;
		$responseTableName      = $tablePrefix . iwp_module_form_model_response::BASE_TABLE_NAME;
		$responseValueTableName = $tablePrefix . iwp_module_form_model_response_value::BASE_TABLE_NAME;
		$widgetTableName        = $tablePrefix . iwp_module_form_model_widget::BASE_TABLE_NAME;

		// tables
		$fieldTable         = new iwp_tablecreator($fieldTableName);
		$formTable          = new iwp_tablecreator($formTableName);
		$responseTable      = new iwp_tablecreator($responseTableName);
		$responseValueTable = new iwp_tablecreator($responseValueTableName);
		$widgetTable        = new iwp_tablecreator($widgetTableName);



		// field schema
		$fieldTable
			->AddField('id')
			->SetAsPrimaryKey();
		$fieldTable
			->AddField('module_form_widget_id')
			->SetAsInt();
		$fieldTable
			->AddField('value')
			->SetAsText()
			->SetIsNull();
		$fieldTable
			->AddField('is_selected')
			->SetAsTinyInt();
		$fieldTable
			->AddField('is_other')
			->SetAsTinyInt();
		$fieldTable
			->AddField('other_label_text')
			->SetAsTinyText()
			->SetIsNull();
		$fieldTable
			->AddField('display_order')
			->SetAsInt();

		// field indexes
		$fieldTable->AddIndex('module_form_widget_id', 'module_form_widget_id');



		// form schema
		$formTable
			->AddField('id')
			->SetAsPrimaryKey();
		$formTable
			->AddField('name')
			->SetAsTinyText()
			->SetIsNull();
		$formTable
			->AddField('description')
			->SetAsText()
			->SetIsNull();
		$formTable
			->AddField('created')
			->SetAsDateTime();
		$formTable
			->AddField('updated')
			->SetAsDateTime()
			->SetIsNull();
		$formTable
			->AddField('email')
			->SetAsVarChar();
		$formTable
			->AddField('email_feedback')
			->SetAsTinyInt()
			->Set('default', 0);
		$formTable
			->AddField('after_submit')
			->SetAsEnum(array('show_message', 'show_uri'), 'show_message');
		$formTable
			->AddField('show_message')
			->SetAsText();
		$formTable
			->AddField('show_uri')
			->SetAsText();
		$formTable
			->AddField('error_message')
			->SetAsText();
		$formTable
			->AddField('submit_button_text')
			->SetAsTinyText();



		// response schema
		$responseTable
			->AddField('id')
			->SetAsPrimaryKey();
		$responseTable
			->AddField('module_form_form_id')
			->SetAsInt();
		$responseTable
			->AddField('datetime')
			->SetAsDateTime();

		// response indexes
		$responseTable->AddIndex('module_form_form_id', 'module_form_form_id');



		// response value schema
		$responseValueTable
			->AddField('id')
			->SetAsPrimaryKey();
		$responseValueTable
			->AddField('module_form_response_id')
			->SetAsInt();
		$responseValueTable
			->AddField('module_form_widget_id')
			->SetAsInt();
		$responseValueTable
			->AddField('value')
			->SetAsText()
			->SetIsNull();

		// response value indexes
		$responseValueTable->AddIndex('module_form_response_id', 'module_form_response_id');
		$responseValueTable->AddIndex('module_form_widget_id', 'module_form_widget_id');



		// widget schema
		$widgetTable
			->AddField('id')
			->SetAsPrimaryKey();
		$widgetTable
			->AddField('module_form_form_id')
			->SetAsInt();
		$widgetTable
			->AddField('name')
			->SetAsTinyText()
			->SetIsNull();
		$widgetTable
			->AddField('description')
			->SetAsText()
			->SetIsNull();
		$widgetTable
			->AddField('type')
			->SetAsVarChar();
		$widgetTable
			->AddField('is_required')
			->SetAsTinyInt();
		$widgetTable
			->AddField('is_random')
			->SetAsTinyInt();
		$widgetTable
			->AddField('is_visible')
			->SetAsTinyInt();
		$widgetTable
			->AddField('allowed_file_types')
			->SetAsText()
			->SetIsNull();
		$widgetTable
			->AddField('display_order')
			->SetAsInt();

		// widget indexes
		$widgetTable->AddIndex('module_form_form_id', 'module_form_form_id');



		// define the structure for the module
		$this->table       = array(&$fieldTable, &$formTable, &$responseTable, &$responseValueTable, &$widgetTable);
		$this->tableSchema = array(
				$fieldTableName         => $fieldTable->GetCreateTable(),
				$formTableName          => $formTable->GetCreateTable(),
				$responseTableName      => $responseTable->GetCreateTable(),
				$responseValueTableName => $responseValueTable->GetCreateTable(),
				$widgetTableName        => $widgetTable->GetCreateTable()
			);
	}
	
	/**
	 * Activates the current module.
	 */
	public function ActivateModule()
	{
		$installPreBuiltForms = false;
		$tableToCheck         = GetConfig('tablePrefix') . iwp_module_form_model_form::BASE_TABLE_NAME;
		
		// we only install pre-built forms if this is the first activation
		if (!$this->db->TableExists($tableToCheck)) {
			$installPreBuiltForms = true;
		}
		
		// activate the parent module
		$activated = parent::ActivateModule();
		
		// if we aren't installing the pre-built forms, return
		if (!$installPreBuiltForms) {
			return $activated;
		}
		
		// install the pre-built forms
		foreach (iwp_module_form_prebuiltforms::$forms as $form) {
			$formInstance = new iwp_module_form_model_form($form);
			
			if ($formInstance->Save()) {
				foreach ($form['widgets'] as $widget) {
					$widgetInstance = $formInstance->saveWidget(new iwp_module_form_model_widget($widget));
					
					foreach ($widget['fields'] as $field) {
						$widgetInstance->saveField(new iwp_module_form_model_field($field));
					}
				}
			}
		}
		
		return $activated;
	}
}

iwp_module_form::$SitePermissionOptions = array(
	'full'          => new iwp_permissionoption(true,  false, false),
	'createForms'   => new iwp_permissionoption(false, false, false),
	'editForms'     => new iwp_permissionoption(true,  false, false),
	'deleteForms'   => new iwp_permissionoption(true,  false, false),
	'viewResponses' => new iwp_permissionoption(true,  false, false)
);