function content_56783e294739f2_31837577($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_studlycaps')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.studlycaps.php';
        }
        if (!is_callable('smarty_modifier_lcfirst')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.lcfirst.php';
        }
        ?>
<<?php 
        ?>
?php
/**
 * @package <?php 
        echo $_smarty_tpl->tpl_vars['appname']->value;
        ?>

 *
 * APPLICATION-WIDE CONFIGURATION SETTINGS
 *
 * This file contains application-wide configuration settings.  The settings
 * here will be the same regardless of the machine on which the app is running.
 *
 * This configuration should be added to version control.
 *
 * No settings should be added to this file that would need to be changed
 * on a per-machine basic (ie local, staging or production).  Any
 * machine-specific settings should be added to _machine_config.php
 */

/**
 * APPLICATION ROOT DIRECTORY
 * If the application doesn't detect this correctly then it can be set explicitly
 */
if (!GlobalConfig::$APP_ROOT) GlobalConfig::$APP_ROOT = realpath("./");

/**
 * check is needed to ensure asp_tags is not enabled
 */
if (ini_get('asp_tags')) 
	die('<h3>Server Configuration Problem: asp_tags is enabled, but is not compatible with Savant.</h3>'
	. '<p>You can disable asp_tags in .htaccess, php.ini or generate your app with another template engine such as Smarty.</p>');

/**
 * INCLUDE PATH
 * Adjust the include path as necessary so PHP can locate required libraries
 */
set_include_path(
		GlobalConfig::$APP_ROOT . '/libs/' . PATH_SEPARATOR .
<?php 
        if ($_smarty_tpl->tpl_vars['includePhar']->value == '1') {
            ?>
		'phar://' . GlobalConfig::$APP_ROOT . '/libs/phreeze-3.3.8.phar' . PATH_SEPARATOR .
<?php 
        }
        ?>
		GlobalConfig::$APP_ROOT . '/<?php 
        echo $_smarty_tpl->tpl_vars['includePath']->value;
        ?>
' . PATH_SEPARATOR .
		GlobalConfig::$APP_ROOT . '/vendor/phreeze/phreeze/libs/' . PATH_SEPARATOR .
		get_include_path()
);

/**
 * COMPOSER AUTOLOADER
 * Uncomment if Composer is being used to manage dependencies
 */
// $loader = require 'vendor/autoload.php';
// $loader->setUseIncludePath(true);

/**
 * SESSION CLASSES
 * Any classes that will be stored in the session can be added here
 * and will be pre-loaded on every page
 */
require_once "App/ExampleUser.php";

/**
 * RENDER ENGINE
 * You can use any template system that implements
 * IRenderEngine for the view layer.  Phreeze provides pre-built
 * implementations for Smarty, Savant and plain PHP.
 */
require_once 'verysimple/Phreeze/SavantRenderEngine.php';
GlobalConfig::$TEMPLATE_ENGINE = 'SavantRenderEngine';
GlobalConfig::$TEMPLATE_PATH = GlobalConfig::$APP_ROOT . '/templates/';

/**
 * ROUTE MAP
 * The route map connects URLs to Controller+Method and additionally maps the
 * wildcards to a named parameter so that they are accessible inside the
 * Controller without having to parse the URL for parameters such as IDs
 */
GlobalConfig::$ROUTE_MAP = array(

	// default controller when no route specified
	'GET:' => array('route' => 'Default.Home'),
		
	// example authentication routes
	'GET:loginform' => array('route' => 'SecureExample.LoginForm'),
	'POST:login' => array('route' => 'SecureExample.Login'),
	'GET:secureuser' => array('route' => 'SecureExample.UserPage'),
	'GET:secureadmin' => array('route' => 'SecureExample.AdminPage'),
	'GET:logout' => array('route' => 'SecureExample.Logout'),
<?php 
        $_smarty_tpl->tpl_vars['table'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['table']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['tables']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['table']->key => $_smarty_tpl->tpl_vars['table']->value) {
            $_smarty_tpl->tpl_vars['table']->_loop = true;
            if (isset($_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['table']->value->Name])) {
                ?>
	<?php 
                $_smarty_tpl->tpl_vars['singular'] = new Smarty_variable($_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['table']->value->Name]['singular'], null, 0);
                ?>
	<?php 
                $_smarty_tpl->tpl_vars['plural'] = new Smarty_variable($_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['table']->value->Name]['plural'], null, 0);
                ?>

	// <?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>

	'GET:<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.ListView'),
	'GET:<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
/<?php 
                if ($_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
                    ?>
(:num)<?php 
                } else {
                    ?>
(:any)<?php 
                }
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.SingleView', 'params' => array('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
                ?>
' => 1)),
	'GET:api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.Query'),
	'POST:api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.Create'),
	'GET:api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
/<?php 
                if ($_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
                    ?>
(:num)<?php 
                } else {
                    ?>
(:any)<?php 
                }
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.Read', 'params' => array('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
                ?>
' => 2)),
	'PUT:api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
/<?php 
                if ($_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
                    ?>
(:num)<?php 
                } else {
                    ?>
(:any)<?php 
                }
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.Update', 'params' => array('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
                ?>
' => 2)),
	'DELETE:api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
/<?php 
                if ($_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
                    ?>
(:num)<?php 
                } else {
                    ?>
(:any)<?php 
                }
                ?>
' => array('route' => '<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
.Delete', 'params' => array('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
                ?>
' => 2)),
<?php 
            }
        }
        ?>

	// catch any broken API urls
	'GET:api/(:any)' => array('route' => 'Default.ErrorApi404'),
	'PUT:api/(:any)' => array('route' => 'Default.ErrorApi404'),
	'POST:api/(:any)' => array('route' => 'Default.ErrorApi404'),
	'DELETE:api/(:any)' => array('route' => 'Default.ErrorApi404')
);

/**
 * FETCHING STRATEGY
 * You may uncomment any of the lines below to specify always eager fetching.
 * Alternatively, you can copy/paste to a specific page for one-time eager fetching
 * If you paste into a controller method, replace $G_PHREEZER with $this->Phreezer
 */
<?php 
        $_smarty_tpl->tpl_vars['tbl'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['tbl']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['tables']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['tbl']->key => $_smarty_tpl->tpl_vars['tbl']->value) {
            $_smarty_tpl->tpl_vars['tbl']->_loop = true;
            $_smarty_tpl->tpl_vars['constraint'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['constraint']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['tbl']->value->Constraints;
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['constraint']->key => $_smarty_tpl->tpl_vars['constraint']->value) {
                $_smarty_tpl->tpl_vars['constraint']->_loop = true;
                ?>
// $GlobalConfig->GetInstance()->GetPhreezer()->SetLoadType("<?php 
                echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['tbl']->value->Name);
                ?>
","<?php 
                echo $_smarty_tpl->tpl_vars['constraint']->value->Name;
                ?>
",KM_LOAD_EAGER); // KM_LOAD_INNER | KM_LOAD_EAGER | KM_LOAD_LAZY
<?php 
            }
        }
        ?>
?<?php 
        ?>
><?php 
    }
    function content_56783e28bc7c19_07366781($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_studlycaps')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.studlycaps.php';
        }
        if (!is_callable('smarty_modifier_lcfirst')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.lcfirst.php';
        }
        ?>
/**
 * backbone model definitions for <?php 
        echo $_smarty_tpl->tpl_vars['appname']->value;
        ?>

 */

/**
 * Use emulated HTTP if the server doesn't support PUT/DELETE or application/json requests
 */
Backbone.emulateHTTP = false;
Backbone.emulateJSON = false;

var model = {};

/**
 * long polling duration in miliseconds.  (5000 = recommended, 0 = disabled)
 * warning: setting this to a low number will increase server load
 */
model.longPollDuration = <?php 
        if ($_smarty_tpl->tpl_vars['enableLongPolling']->value != '0') {
            ?>
5000<?php 
        } else {
            ?>
0<?php 
        }
        ?>
;

/**
 * whether to refresh the collection immediately after a model is updated
 */
model.reloadCollectionOnModelUpdate = true;


/**
 * a default sort method for sorting collection items.  this will sort the collection
 * based on the orderBy and orderDesc property that was used on the last fetch call
 * to the server. 
 */
model.AbstractCollection = Backbone.Collection.extend({
	totalResults: 0,
	totalPages: 0,
	currentPage: 0,
	pageSize: 0,
	orderBy: '',
	orderDesc: false,
	lastResponseText: null,
	lastRequestParams: null,
	collectionHasChanged: true,
	
	/**
	 * fetch the collection from the server using the same options and 
	 * parameters as the previous fetch
	 */
	refetch: function() {
		this.fetch({ data: this.lastRequestParams })
	},
	
	/* uncomment to debug fetch event triggers
	fetch: function(options) {
            this.constructor.__super__.fetch.apply(this, arguments);
	},
	// */
	
	/**
	 * client-side sorting baesd on the orderBy and orderDesc parameters that
	 * were used to fetch the data from the server.  Backbone ignores the
	 * order of records coming from the server so we have to sort them ourselves
	 */
	comparator: function(a,b) {
		
		var result = 0;
		var options = this.lastRequestParams;
		
		if (options && options.orderBy) {
			
			// lcase the first letter of the property name
			var propName = options.orderBy.charAt(0).toLowerCase() + options.orderBy.slice(1);
			var aVal = a.get(propName);
			var bVal = b.get(propName);
			
			if (isNaN(aVal) || isNaN(bVal)) {
				// treat comparison as case-insensitive strings
				aVal = aVal ? aVal.toLowerCase() : '';
				bVal = bVal ? bVal.toLowerCase() : '';
			} else {
				// treat comparision as a number
				aVal = Number(aVal);
				bVal = Number(bVal);
			}
			
			if (aVal < bVal) {
				result = options.orderDesc ? 1 : -1;
			} else if (aVal > bVal) {
				result = options.orderDesc ? -1 : 1;
			}
		}
		
		return result;

	},
	/**
	 * override parse to track changes and handle pagination
	 * if the server call has returned page data
	 */
	parse: function(response, options) {

		// the response is already decoded into object form, but it's easier to
		// compary the stringified version.  some earlier versions of backbone did
		// not include the raw response so there is some legacy support here
		var responseText = options && options.xhr ? options.xhr.responseText : JSON.stringify(response);
		this.collectionHasChanged = (this.lastResponseText != responseText);
		this.lastRequestParams = options ? options.data : undefined;
		
		// if the collection has changed then we need to force a re-sort because backbone will
		// only resort the data if a property in the model has changed
		if (this.lastResponseText && this.collectionHasChanged) this.sort({ silent:true });
		
		this.lastResponseText = responseText;
		
		var rows;

		if (response.currentPage) {
			rows = response.rows;
			this.totalResults = response.totalResults;
			this.totalPages = response.totalPages;
			this.currentPage = response.currentPage;
			this.pageSize = response.pageSize;
			this.orderBy = response.orderBy;
			this.orderDesc = response.orderDesc;
		} else {
			rows = response;
			this.totalResults = rows.length;
			this.totalPages = 1;
			this.currentPage = 1;
			this.pageSize = this.totalResults;
			this.orderBy = response.orderBy;
			this.orderDesc = response.orderDesc;
		}

		return rows;
	}
});

<?php 
        $_smarty_tpl->tpl_vars['table'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['table']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['tables']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['table']->key => $_smarty_tpl->tpl_vars['table']->value) {
            $_smarty_tpl->tpl_vars['table']->_loop = true;
            if (isset($_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['table']->value->Name])) {
                $_smarty_tpl->tpl_vars['singular'] = new Smarty_variable($_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['table']->value->Name]['singular'], null, 0);
                $_smarty_tpl->tpl_vars['plural'] = new Smarty_variable($_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['table']->value->Name]['plural'], null, 0);
                ?>
/**
 * <?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
 Backbone Model
 */
model.<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
Model = Backbone.Model.extend({
	urlRoot: 'api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
',
	idAttribute: '<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
                ?>
',
<?php 
                $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars['column']->_loop = false;
                $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                $_smarty_tpl->tpl_vars['column']->total = $_smarty_tpl->_count($_from);
                $_smarty_tpl->tpl_vars['column']->iteration = 0;
                foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
                    $_smarty_tpl->tpl_vars['column']->_loop = true;
                    $_smarty_tpl->tpl_vars['column']->iteration++;
                    $_smarty_tpl->tpl_vars['column']->last = $_smarty_tpl->tpl_vars['column']->iteration === $_smarty_tpl->tpl_vars['column']->total;
                    $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['last'] = $_smarty_tpl->tpl_vars['column']->last;
                    ?>
	<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
: '',
<?php 
                }
                ?>
	defaults: {
<?php 
                $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars['column']->_loop = false;
                $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                $_smarty_tpl->tpl_vars['column']->total = $_smarty_tpl->_count($_from);
                $_smarty_tpl->tpl_vars['column']->iteration = 0;
                foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
                    $_smarty_tpl->tpl_vars['column']->_loop = true;
                    $_smarty_tpl->tpl_vars['column']->iteration++;
                    $_smarty_tpl->tpl_vars['column']->last = $_smarty_tpl->tpl_vars['column']->iteration === $_smarty_tpl->tpl_vars['column']->total;
                    $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['last'] = $_smarty_tpl->tpl_vars['column']->last;
                    ?>
		'<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
': <?php 
                    if ($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix == $_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()) {
                        ?>
null<?php 
                    } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == "date" || $_smarty_tpl->tpl_vars['column']->value->Type == "datetime") {
                        ?>
new Date()<?php 
                    } else {
                        ?>
''<?php 
                    }
                    if (!$_smarty_tpl->getVariable('smarty')->value['foreach']['columnsForEach']['last']) {
                        ?>
,<?php 
                    }
                    ?>

<?php 
                }
                ?>
	}
});

/**
 * <?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
 Backbone Collection
 */
model.<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
Collection = model.AbstractCollection.extend({
	url: 'api/<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
                ?>
',
	model: model.<?php 
                echo $_smarty_tpl->tpl_vars['singular']->value;
                ?>
Model
});

<?php 
            }
        }
    }
    function content_56783e286f3822_99241766($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_studlycaps')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.studlycaps.php';
        }
        if (!is_callable('smarty_modifier_lcfirst')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.lcfirst.php';
        }
        ?>
<<?php 
        ?>
?php
/** @package    <?php 
        echo $_smarty_tpl->tpl_vars['appname']->value;
        ?>
::Controller */

/** import supporting libraries */
require_once("AppBaseController.php");
require_once("Model/<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
.php");

/**
 * <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Controller is the controller class for the <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 object.  The
 * controller is responsible for processing input from the user, reading/updating
 * the model as necessary and displaying the appropriate view.
 *
 * @package <?php 
        echo $_smarty_tpl->tpl_vars['appname']->value;
        ?>
::Controller
 * @author ClassBuilder
 * @version 1.0
 */
class <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Controller extends AppBaseController
{

	/**
	 * Override here for any controller-specific functionality
	 *
	 * @inheritdocs
	 */
	protected function Init()
	{
		parent::Init();

		// TODO: add controller-wide bootstrap code
		
		// TODO: if authentiation is required for this entire controller, for example:
		// $this->RequirePermission(ExampleUser::$PERMISSION_USER,'SecureExample.LoginForm');
	}

	/**
	 * Displays a list view of <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 objects
	 */
	public function ListView()
	{
		$this->Render();
	}

	/**
	 * API Method queries for <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 records and render as JSON
	 */
	public function Query()
	{
		try
		{
			$criteria = new <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Criteria();
			
			// TODO: this will limit results based on all properties included in the filter list 
			$filter = RequestUtil::Get('filter');
			if ($filter) $criteria->AddFilter(
				new CriteriaFilter('<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['column']->total = $_smarty_tpl->_count($_from);
        $_smarty_tpl->tpl_vars['column']->iteration = 0;
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            $_smarty_tpl->tpl_vars['column']->iteration++;
            $_smarty_tpl->tpl_vars['column']->last = $_smarty_tpl->tpl_vars['column']->iteration === $_smarty_tpl->tpl_vars['column']->total;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['filterForEach']['last'] = $_smarty_tpl->tpl_vars['column']->last;
            echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
            if (!$_smarty_tpl->getVariable('smarty')->value['foreach']['filterForEach']['last']) {
                ?>
,<?php 
            }
        }
        ?>
'
				, '%'.$filter.'%')
			);

			// TODO: this is generic query filtering based only on criteria properties
			foreach (array_keys($_REQUEST) as $prop)
			{
				$prop_normal = ucfirst($prop);
				$prop_equals = $prop_normal.'_Equals';

				if (property_exists($criteria, $prop_normal))
				{
					$criteria->$prop_normal = RequestUtil::Get($prop);
				}
				elseif (property_exists($criteria, $prop_equals))
				{
					// this is a convenience so that the _Equals suffix is not needed
					$criteria->$prop_equals = RequestUtil::Get($prop);
				}
			}

			$output = new stdClass();

			// if a sort order was specified then specify in the criteria
 			$output->orderBy = RequestUtil::Get('orderBy');
 			$output->orderDesc = RequestUtil::Get('orderDesc') != '';
 			if ($output->orderBy) $criteria->SetOrder($output->orderBy, $output->orderDesc);

			$page = RequestUtil::Get('page');

			if ($page != '')
			{
				// if page is specified, use this instead (at the expense of one extra count query)
				$pagesize = $this->GetDefaultPageSize();

				$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
 = $this->Phreezer->Query('<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
',$criteria)->GetDataPage($page, $pagesize);
				$output->rows = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
->ToObjectArray(true,$this->SimpleObjectParams());
				$output->totalResults = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
->TotalResults;
				$output->totalPages = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
->TotalPages;
				$output->pageSize = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
->PageSize;
				$output->currentPage = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
->CurrentPage;
			}
			else
			{
				// return all results
				$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
 = $this->Phreezer->Query('<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
',$criteria);
				$output->rows = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
->ToObjectArray(true, $this->SimpleObjectParams());
				$output->totalResults = count($output->rows);
				$output->totalPages = 1;
				$output->pageSize = $output->totalResults;
				$output->currentPage = 1;
			}


			$this->RenderJSON($output, $this->JSONPCallback());
		}
		catch (Exception $ex)
		{
			$this->RenderExceptionJSON($ex);
		}
	}

	/**
	 * API Method retrieves a single <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 record and render as JSON
	 */
	public function Read()
	{
		try
		{
			$pk = $this->GetRouter()->GetUrlParam('<?php 
        echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
        ?>
');
			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
 = $this->Phreezer->Get('<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
',$pk);
			$this->RenderJSON($<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
, $this->JSONPCallback(), true, $this->SimpleObjectParams());
		}
		catch (Exception $ex)
		{
			$this->RenderExceptionJSON($ex);
		}
	}

	/**
	 * API Method inserts a new <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 record and render response as JSON
	 */
	public function Create()
	{
		try
		{
			<?php 
        if ($_smarty_tpl->tpl_vars['table']->value->IsView) {
            ?>
// TODO: views are read-only by default.  uncomment at your own discretion
			throw new Exception('Database views are read-only and cannot be updated');
			<?php 
        }
        ?>
			
			$json = json_decode(RequestUtil::GetBody());

			if (!$json)
			{
				throw new Exception('The request body does not contain valid JSON');
			}

			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
 = new <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
($this->Phreezer);

			// TODO: any fields that should not be inserted by the user should be commented out

<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            if ($_smarty_tpl->tpl_vars['column']->value->Extra == 'auto_increment') {
                ?>
			// this is an auto-increment.  uncomment if updating is allowed
			// $<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
-><?php 
                echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                ?>
 = $this->SafeGetVal($json, '<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
');

<?php 
            } else {
                if ($_smarty_tpl->tpl_vars['column']->value->Type == "date" || $_smarty_tpl->tpl_vars['column']->value->Type == "datetime" || $_smarty_tpl->tpl_vars['column']->value->Type == "timestamp") {
                    ?>
			$<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
 = date('Y-m-d H:i:s',strtotime($this->SafeGetVal($json, '<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
')));
<?php 
                } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == "time") {
                    ?>
			$<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
 = date('H:i:s',strtotime('1970-01-01 ' . $this->SafeGetVal($json, '<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
')));
<?php 
                } else {
                    ?>
			$<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
 = $this->SafeGetVal($json, '<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
');
<?php 
                }
            }
        }
        ?>

			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->Validate();
			$errors = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->GetValidationErrors();

			if (count($errors) > 0)
			{
				$this->RenderErrorJSON('Please check the form for errors',$errors);
			}
			else
			{
<?php 
        if (!$_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
            ?>
				// since the primary key is not auto-increment we must force the insert here
<?php 
        }
        ?>
				$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->Save(<?php 
        if (!$_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
            ?>
true<?php 
        }
        ?>
);
				$this->RenderJSON($<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
, $this->JSONPCallback(), true, $this->SimpleObjectParams());
			}

		}
		catch (Exception $ex)
		{
			$this->RenderExceptionJSON($ex);
		}
	}

	/**
	 * API Method updates an existing <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 record and render response as JSON
	 */
	public function Update()
	{
		try
		{
			<?php 
        if ($_smarty_tpl->tpl_vars['table']->value->IsView) {
            ?>
// TODO: views are read-only by default.  uncomment at your own discretion
			throw new Exception('Database views are read-only and cannot be updated');
			<?php 
        }
        ?>
			
			$json = json_decode(RequestUtil::GetBody());

			if (!$json)
			{
				throw new Exception('The request body does not contain valid JSON');
			}

			$pk = $this->GetRouter()->GetUrlParam('<?php 
        echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
        ?>
');
			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
 = $this->Phreezer->Get('<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
',$pk);

			// TODO: any fields that should not be updated by the user should be commented out

<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            if ($_smarty_tpl->tpl_vars['column']->value->Key == "PRI") {
                ?>
			// this is a primary key.  uncomment if updating is allowed
			// $<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
-><?php 
                echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                ?>
 = $this->SafeGetVal($json, '<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
', $<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
-><?php 
                echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                ?>
);

<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Extra == 'auto_increment') {
                ?>
			// this is an auto-increment.  uncomment if updating is allowed
			// $<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
-><?php 
                echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                ?>
 = $this->SafeGetVal($json, '<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
', $<?php 
                echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                ?>
-><?php 
                echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                ?>
);

<?php 
            } else {
                if ($_smarty_tpl->tpl_vars['column']->value->Type == "date" || $_smarty_tpl->tpl_vars['column']->value->Type == "datetime" || $_smarty_tpl->tpl_vars['column']->value->Type == "timestamp") {
                    ?>
			$<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
 = date('Y-m-d H:i:s',strtotime($this->SafeGetVal($json, '<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
', $<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
)));
<?php 
                } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == "time") {
                    ?>
			$<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
 = date('Y-m-d H:i:s',strtotime('1970-01-01 ' . $this->SafeGetVal($json, '<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
', $<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
)));
<?php 
                } else {
                    ?>
			$<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
 = $this->SafeGetVal($json, '<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
', $<?php 
                    echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
                    ?>
-><?php 
                    echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                    ?>
);
<?php 
                }
            }
        }
        ?>

			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->Validate();
			$errors = $<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->GetValidationErrors();

			if (count($errors) > 0)
			{
				$this->RenderErrorJSON('Please check the form for errors',$errors);
			}
			else
			{
				$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->Save();
				$this->RenderJSON($<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
, $this->JSONPCallback(), true, $this->SimpleObjectParams());
			}


		}
		catch (Exception $ex)
		{

<?php 
        if (!$_smarty_tpl->tpl_vars['table']->value->PrimaryKeyIsAutoIncrement()) {
            ?>
			// this table does not have an auto-increment primary key, so it is semantically correct to
			// issue a REST PUT request, however we have no way to know whether to insert or update.
			// if the record is not found, this exception will indicate that this is an insert request
			if (is_a($ex,'NotFoundException'))
			{
				return $this->Create();
			}
<?php 
        }
        ?>

			$this->RenderExceptionJSON($ex);
		}
	}

	/**
	 * API Method deletes an existing <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 record and render response as JSON
	 */
	public function Delete()
	{
		try
		{
			<?php 
        if ($_smarty_tpl->tpl_vars['table']->value->IsView) {
            ?>
// TODO: views are read-only by default.  uncomment at your own discretion
			throw new Exception('Database views are read-only and cannot be updated');
			<?php 
        }
        ?>
			
			// TODO: if a soft delete is prefered, change this to update the deleted flag instead of hard-deleting

			$pk = $this->GetRouter()->GetUrlParam('<?php 
        echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
        ?>
');
			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
 = $this->Phreezer->Get('<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
',$pk);

			$<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['singular']->value, 'UTF-8');
        ?>
->Delete();

			$output = new stdClass();

			$this->RenderJSON($output, $this->JSONPCallback());

		}
		catch (Exception $ex)
		{
			$this->RenderExceptionJSON($ex);
		}
	}
}

?<?php 
        ?>
>
<?php 
    }
    function content_56783e2934d6b5_81404590($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_lcfirst')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.lcfirst.php';
        }
        if (!is_callable('smarty_modifier_studlycaps')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.studlycaps.php';
        }
        if (!is_callable('smarty_modifier_underscore2space')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.underscore2space.php';
        }
        ?>
<<?php 
        ?>
?php
	$this->assign('title','<?php 
        echo $_smarty_tpl->tpl_vars['appname']->value;
        ?>
 | <?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
');
	$this->assign('nav','<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
');

	$this->display('_Header.tpl.php');
?<?php 
        ?>
>

<script type="text/javascript">
	$LAB.script("scripts/app/<?php 
        echo mb_strtolower($_smarty_tpl->tpl_vars['plural']->value, 'UTF-8');
        ?>
.js").wait(function(){
		$(document).ready(function(){
			page.init();
		});
		
		// hack for IE9 which may respond inconsistently with document.ready
		setTimeout(function(){
			if (!page.isInitialized) page.init();
		},1000);
	});
</script>

<div class="container">

<h1>
	<i class="icon-th-list"></i> <?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>

	<span id=loader class="loader progress progress-striped active"><span class="bar"></span></span>
	<span class='input-append pull-right searchContainer'>
		<input id='filter' type="text" placeholder="Search..." />
		<button class='btn add-on'><i class="icon-search"></i></button>
	</span>
</h1>

	<!-- underscore template for the collection -->
	<script type="text/template" id="<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
CollectionTemplate">
		<table class="collection table table-bordered table-hover">
		<thead>
			<tr>
<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['index'] = -1;
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['index']++;
            if ($_smarty_tpl->getVariable('smarty')->value['foreach']['columnsForEach']['index'] == 5) {
                ?>
<!-- UNCOMMENT TO SHOW ADDITIONAL COLUMNS
<?php 
            }
            ?>
				<th id="header_<?php 
            echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
            ?>
"><?php 
            echo smarty_modifier_underscore2space($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
            ?>
<<?php 
            ?>
% if (page.orderBy == '<?php 
            echo smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
            ?>
') { %<?php 
            ?>
> <i class='icon-arrow-<<?php 
            ?>
%= page.orderDesc ? 'up' : 'down' %<?php 
            ?>
>' /><<?php 
            ?>
% } %<?php 
            ?>
></th>
<?php 
        }
        if ($_smarty_tpl->getVariable('smarty')->value['foreach']['columnsForEach']['index'] >= 5) {
            ?>
-->
<?php 
        }
        ?>
			</tr>
		</thead>
		<tbody>
		<<?php 
        ?>
% items.each(function(item) { %<?php 
        ?>
>
			<tr id="<<?php 
        ?>
%= _.escape(item.get('<?php 
        echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['table']->value->GetPrimaryKeyName()));
        ?>
')) %<?php 
        ?>
>">
<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['index'] = -1;
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['index']++;
            if ($_smarty_tpl->getVariable('smarty')->value['foreach']['columnsForEach']['index'] == 5) {
                ?>
<!-- UNCOMMENT TO SHOW ADDITIONAL COLUMNS
<?php 
            }
            if ($_smarty_tpl->tpl_vars['column']->value->Type == "date") {
                ?>
				<td><<?php 
                ?>
%if (item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
')) { %<?php 
                ?>
><<?php 
                ?>
%= _date(app.parseDate(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
'))).format('MMM D, YYYY') %<?php 
                ?>
><<?php 
                ?>
% } else { %<?php 
                ?>
>NULL<<?php 
                ?>
% } %<?php 
                ?>
></td>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == "datetime" || $_smarty_tpl->tpl_vars['column']->value->Type == "timestamp") {
                ?>
				<td><<?php 
                ?>
%if (item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
')) { %<?php 
                ?>
><<?php 
                ?>
%= _date(app.parseDate(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
'))).format('MMM D, YYYY h:mm A') %<?php 
                ?>
><<?php 
                ?>
% } else { %<?php 
                ?>
>NULL<<?php 
                ?>
% } %<?php 
                ?>
></td>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == "time") {
                ?>
				<td><<?php 
                ?>
%if (item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
')) { %<?php 
                ?>
><<?php 
                ?>
%= _date(app.parseDate(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
'))).format('h:mm A') %<?php 
                ?>
><<?php 
                ?>
% } else { %<?php 
                ?>
>NULL<<?php 
                ?>
% } %<?php 
                ?>
></td>
<?php 
            } else {
                ?>
				<td><<?php 
                ?>
%= _.escape(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
') || '') %<?php 
                ?>
></td>
<?php 
            }
        }
        if ($_smarty_tpl->getVariable('smarty')->value['foreach']['columnsForEach']['index'] >= 5) {
            ?>
-->
<?php 
        }
        ?>
			</tr>
		<<?php 
        ?>
% }); %<?php 
        ?>
>
		</tbody>
		</table>

		<<?php 
        ?>
%=  view.getPaginationHtml(page) %<?php 
        ?>
>
	</script>

	<!-- underscore template for the model -->
	<script type="text/template" id="<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
ModelTemplate">
		<form class="form-horizontal" onsubmit="return false;">
			<fieldset>
<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['index'] = -1;
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['index']++;
            ?>
				<div id="<?php 
            echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
            ?>
InputContainer" class="control-group">
					<label class="control-label" for="<?php 
            echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
            ?>
"><?php 
            echo smarty_modifier_underscore2space($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
            ?>
</label>
					<div class="controls inline-inputs">
<?php 
            if ($_smarty_tpl->tpl_vars['column']->value->Extra == 'auto_increment') {
                ?>
						<span class="input-xlarge uneditable-input" id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
"><<?php 
                ?>
%= _.escape(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
') || '') %<?php 
                ?>
></span>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Key == "MUL" && $_smarty_tpl->tpl_vars['column']->value->Constraints) {
                ?>
						<select id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
" name="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
"></select>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->IsEnum()) {
                ?>
						<select id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
" name="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
">
							<option value=""></option>
<?php 
                $_smarty_tpl->tpl_vars['enumVal'] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars['enumVal']->_loop = false;
                $_from = $_smarty_tpl->tpl_vars['column']->value->GetEnumValues();
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                foreach ($_from as $_smarty_tpl->tpl_vars['enumVal']->key => $_smarty_tpl->tpl_vars['enumVal']->value) {
                    $_smarty_tpl->tpl_vars['enumVal']->_loop = true;
                    ?>
							<option value="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['enumVal']->value, ENT_QUOTES, 'UTF-8', true);
                    ?>
"<<?php 
                    ?>
% if (item.get('<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
')=='<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['enumVal']->value, ENT_QUOTES, 'UTF-8', true);
                    ?>
') { %<?php 
                    ?>
> selected="selected"<<?php 
                    ?>
% } %<?php 
                    ?>
>><?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['enumVal']->value, ENT_QUOTES, 'UTF-8', true);
                    ?>
</option>
<?php 
                }
                ?>
						</select>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == "date" || $_smarty_tpl->tpl_vars['column']->value->Type == "datetime" || $_smarty_tpl->tpl_vars['column']->value->Type == "timestamp") {
                ?>
						<div class="input-append date date-picker" data-date-format="yyyy-mm-dd">
							<input id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
" type="text" value="<<?php 
                ?>
%= _date(app.parseDate(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
'))).format('YYYY-MM-DD') %<?php 
                ?>
>" />
							<span class="add-on"><i class="icon-calendar"></i></span>
						</div>
<?php 
                if ($_smarty_tpl->tpl_vars['column']->value->Type == "datetime" || $_smarty_tpl->tpl_vars['column']->value->Type == "timestamp") {
                    ?>
						<div class="input-append bootstrap-timepicker-component">
							<input id="<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
-time" type="text" class="timepicker-default input-small" value="<<?php 
                    ?>
%= _date(app.parseDate(item.get('<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
'))).format('h:mm A') %<?php 
                    ?>
>" />
							<span class="add-on"><i class="icon-time"></i></span>
						</div>
<?php 
                }
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == 'time') {
                ?>
						<div class="input-append bootstrap-timepicker-component">
							<input id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
" type="text" class="timepicker-default input-small" value="<<?php 
                ?>
%= _date(app.parseDate(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
'))).format('h:mm A') %<?php 
                ?>
>" />
							<span class="add-on"><i class="icon-time"></i></span>
						</div>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == 'text' || $_smarty_tpl->tpl_vars['column']->value->Type == 'tinytext' || $_smarty_tpl->tpl_vars['column']->value->Type == 'mediumtext' || $_smarty_tpl->tpl_vars['column']->value->Type == 'longtext') {
                ?>
						<textarea class="input-xlarge" id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
" rows="3"><<?php 
                ?>
%= _.escape(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
') || '') %<?php 
                ?>
></textarea>
<?php 
            } elseif (false) {
                ?>
						<select id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
"><option>something</option><option>2</option></select>
<?php 
            } else {
                ?>
						<input type="text" class="input-xlarge" id="<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
" placeholder="<?php 
                echo smarty_modifier_underscore2space($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix);
                ?>
" value="<<?php 
                ?>
%= _.escape(item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
') || '') %<?php 
                ?>
>">
<?php 
            }
            ?>
						<span class="help-inline"></span>
					</div>
				</div>
<?php 
        }
        ?>
			</fieldset>
		</form>

		<!-- delete button is is a separate form to prevent enter key from triggering a delete -->
		<form id="delete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
ButtonContainer" class="form-horizontal" onsubmit="return false;">
			<fieldset>
				<div class="control-group">
					<label class="control-label"></label>
					<div class="controls">
						<button id="delete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i> Delete <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
</button>
						<span id="confirmDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Container" class="hide">
							<button id="cancelDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button" class="btn btn-mini">Cancel</button>
							<button id="confirmDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button" class="btn btn-mini btn-danger">Confirm</button>
						</span>
					</div>
				</div>
			</fieldset>
		</form>
	</script>

	<!-- modal edit dialog -->
	<div class="modal hide fade" id="<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
DetailDialog">
		<div class="modal-header">
			<a class="close" data-dismiss="modal">&times;</a>
			<h3>
				<i class="icon-edit"></i> Edit <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>

				<span id="modelLoader" class="loader progress progress-striped active"><span class="bar"></span></span>
			</h3>
		</div>
		<div class="modal-body">
			<div id="modelAlert"></div>
			<div id="<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
ModelContainer"></div>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" >Cancel</button>
			<button id="save<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button" class="btn btn-primary">Save Changes</button>
		</div>
	</div>

	<div id="collectionAlert"></div>
	
	<div id="<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
CollectionContainer" class="collectionContainer">
	</div>

	<p id="newButtonContainer" class="buttonContainer">
		<button id="new<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button" class="btn btn-primary">Add <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
</button>
	</p>

</div> <!-- /container -->

<<?php 
        ?>
?php
	$this->display('_Footer.tpl.php');
?<?php 
        ?>
>
<?php 
    }
    function content_56783e28e4e211_28593655($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_lcfirst')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.lcfirst.php';
        }
        if (!is_callable('smarty_modifier_studlycaps')) {
            include '/var/www/html/phreeze/libs/smarty/plugins/modifier.studlycaps.php';
        }
        ?>
/**
 * View logic for <?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>

 */

/**
 * application logic specific to the <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 listing page
 */
var page = {

	<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['plural']->value);
        ?>
: new model.<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Collection(),
	collectionView: null,
	<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
: null,
	modelView: null,
	isInitialized: false,
	isInitializing: false,

	fetchParams: { filter: '', orderBy: '', orderDesc: '', page: 1 },
	fetchInProgress: false,
	dialogIsOpen: false,

	/**
	 *
	 */
	init: function() {
		// ensure initialization only occurs once
		if (page.isInitialized || page.isInitializing) return;
		page.isInitializing = true;

		if (!$.isReady && console) console.warn('page was initialized before dom is ready.  views may not render properly.');

		// make the new button clickable
		$("#new<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button").click(function(e) {
			e.preventDefault();
			page.showDetailDialog();
		});

		// let the page know when the dialog is open
		$('#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
DetailDialog').on('show',function() {
			page.dialogIsOpen = true;
		});

		// when the model dialog is closed, let page know and reset the model view
		$('#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
DetailDialog').on('hidden',function() {
			$('#modelAlert').html('');
			page.dialogIsOpen = false;
		});

		// save the model when the save button is clicked
		$("#save<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button").click(function(e) {
			e.preventDefault();
			page.updateModel();
		});

		// initialize the collection view
		this.collectionView = new view.CollectionView({
			el: $("#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
CollectionContainer"),
			templateEl: $("#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
CollectionTemplate"),
			collection: page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['plural']->value);
        ?>

		});

		// initialize the search filter
		$('#filter').change(function(obj) {
			page.fetchParams.filter = $('#filter').val();
			page.fetchParams.page = 1;
			page.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
(page.fetchParams);
		});
		
		// make the rows clickable ('rendered' is a custom event, not a standard backbone event)
		this.collectionView.on('rendered',function(){

			// attach click handler to the table rows for editing
			$('table.collection tbody tr').click(function(e) {
				e.preventDefault();
				var m = page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['plural']->value);
        ?>
.get(this.id);
				page.showDetailDialog(m);
			});

			// make the headers clickable for sorting
 			$('table.collection thead tr th').click(function(e) {
 				e.preventDefault();
				var prop = this.id.replace('header_','');

				// toggle the ascending/descending before we change the sort prop
				page.fetchParams.orderDesc = (prop == page.fetchParams.orderBy && !page.fetchParams.orderDesc) ? '1' : '';
				page.fetchParams.orderBy = prop;
				page.fetchParams.page = 1;
 				page.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
(page.fetchParams);
 			});

			// attach click handlers to the pagination controls
			$('.pageButton').click(function(e) {
				e.preventDefault();
				page.fetchParams.page = this.id.substr(5);
				page.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
(page.fetchParams);
			});
			
			page.isInitialized = true;
			page.isInitializing = false;
		});

		// backbone docs recommend bootstrapping data on initial page load, but we live by our own rules!
		this.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
({ page: 1 });

		// initialize the model view
		this.modelView = new view.ModelView({
			el: $("#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
ModelContainer")
		});

		// tell the model view where it's template is located
		this.modelView.templateEl = $("#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
ModelTemplate");

		if (model.longPollDuration > 0)	{
			setInterval(function () {

				if (!page.dialogIsOpen)	{
					page.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
(page.fetchParams,true);
				}

			}, model.longPollDuration);
		}
	},

	/**
	 * Fetch the collection data from the server
	 * @param object params passed through to collection.fetch
	 * @param bool true to hide the loading animation
	 */
	fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
: function(params, hideLoader) {
		// persist the params so that paging/sorting/filtering will play together nicely
		page.fetchParams = params;

		if (page.fetchInProgress) {
			if (console) console.log('supressing fetch because it is already in progress');
		}

		page.fetchInProgress = true;

		if (!hideLoader) app.showProgress('loader');

		page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['plural']->value);
        ?>
.fetch({

			data: params,

			success: function() {

				if (page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['plural']->value);
        ?>
.collectionHasChanged) {
					// TODO: add any logic necessary if the collection has changed
					// the sync event will trigger the view to re-render
				}

				app.hideProgress('loader');
				page.fetchInProgress = false;
			},

			error: function(m, r) {
				app.appendAlert(app.getErrorMessage(r), 'alert-error',0,'collectionAlert');
				app.hideProgress('loader');
				page.fetchInProgress = false;
			}

		});
	},

	/**
	 * show the dialog for editing a model
	 * @param model
	 */
	showDetailDialog: function(m) {

		// show the modal dialog
		$('#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
DetailDialog').modal({ show: true });

		// if a model was specified then that means a user is editing an existing record
		// if not, then the user is creating a new record
		page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
 = m ? m : new model.<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Model();

		page.modelView.model = page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
;

		if (page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
.id == null || page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
.id == '') {
			// this is a new record, there is no need to contact the server
			page.renderModelView(false);
		} else {
			app.showProgress('modelLoader');

			// fetch the model from the server so we are not updating stale data
			page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
.fetch({

				success: function() {
					// data returned from the server.  render the model view
					page.renderModelView(true);
				},

				error: function(m, r) {
					app.appendAlert(app.getErrorMessage(r), 'alert-error',0,'modelAlert');
					app.hideProgress('modelLoader');
				}

			});
		}

	},

	/**
	 * Render the model template in the popup
	 * @param bool show the delete button
	 */
	renderModelView: function(showDeleteButton)	{
		page.modelView.render();

		app.hideProgress('modelLoader');

		// initialize any special controls
		try {
			$('.date-picker')
				.datepicker()
				.on('changeDate', function(ev){
					$('.date-picker').datepicker('hide');
				});
		} catch (error) {
			// this happens if the datepicker input.value isn't a valid date
			if (console) console.log('datepicker error: '+error.message);
		}
		
		$('.timepicker-default').timepicker({ defaultTime: 'value' });

<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['column']->total = $_smarty_tpl->_count($_from);
        $_smarty_tpl->tpl_vars['column']->iteration = 0;
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            $_smarty_tpl->tpl_vars['column']->iteration++;
            $_smarty_tpl->tpl_vars['column']->last = $_smarty_tpl->tpl_vars['column']->iteration === $_smarty_tpl->tpl_vars['column']->total;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['last'] = $_smarty_tpl->tpl_vars['column']->last;
            if ($_smarty_tpl->tpl_vars['column']->value->Key == "MUL" && $_smarty_tpl->tpl_vars['column']->value->Constraints) {
                $_smarty_tpl->tpl_vars['constraint'] = new Smarty_variable($_smarty_tpl->tpl_vars['table']->value->Constraints[$_smarty_tpl->tpl_vars['column']->value->Constraints[0]], null, 0);
                ?>
		// populate the dropdown options for <?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>

		// TODO: load only the selected value, then fetch all options when the drop-down is clicked
		var <?php 
                echo htmlspecialchars(smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix)), ENT_QUOTES, 'UTF-8', true);
                ?>
Values = new model.<?php 
                echo $_smarty_tpl->tpl_vars['tableInfos']->value[$_smarty_tpl->tpl_vars['constraint']->value->ReferenceTableName]['singular'];
                ?>
Collection();
		<?php 
                echo htmlspecialchars(smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix)), ENT_QUOTES, 'UTF-8', true);
                ?>
Values.fetch({
			success: function(c){
				var dd = $('#<?php 
                echo htmlspecialchars(smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix)), ENT_QUOTES, 'UTF-8', true);
                ?>
');
				dd.append('<option value=""></option>');
				c.forEach(function(item,index) {
					dd.append(app.getOptionHtml(
						item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['constraint']->value->ReferenceKeyColumnNoPrefix));
                ?>
'),
						item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['constraint']->value->ReferenceTable->GetDescriptorName()));
                ?>
'), // TODO: change fieldname if the dropdown doesn't show the desired column
						page.<?php 
                echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
                ?>
.get('<?php 
                echo htmlspecialchars(smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix)), ENT_QUOTES, 'UTF-8', true);
                ?>
') == item.get('<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['constraint']->value->ReferenceKeyColumnNoPrefix));
                ?>
')
					));
				});
				
				if (!app.browserSucks()) {
					dd.combobox();
					$('div.combobox-container + span.help-inline').hide(); // TODO: hack because combobox is making the inline help div have a height
				}

			},
			error: function(collection,response,scope) {
				app.appendAlert(app.getErrorMessage(response), 'alert-error',0,'modelAlert');
			}
		});

<?php 
            } elseif ($_smarty_tpl->tpl_vars['column']->value->IsEnum()) {
                ?>
	if (!app.browserSucks()) {
		$('#<?php 
                echo htmlspecialchars(smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix)), ENT_QUOTES, 'UTF-8', true);
                ?>
').combobox();
		$('div.combobox-container + span.help-inline').hide(); // TODO: hack because combobox is making the inline help div have a height
	}

<?php 
            }
        }
        ?>

		if (showDeleteButton) {
			// attach click handlers to the delete buttons

			$('#delete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button').click(function(e) {
				e.preventDefault();
				$('#confirmDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Container').show('fast');
			});

			$('#cancelDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button').click(function(e) {
				e.preventDefault();
				$('#confirmDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Container').hide('fast');
			});

			$('#confirmDelete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
Button').click(function(e) {
				e.preventDefault();
				page.deleteModel();
			});

		} else {
			// no point in initializing the click handlers if we don't show the button
			$('#delete<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
ButtonContainer').hide();
		}
	},

	/**
	 * update the model that is currently displayed in the dialog
	 */
	updateModel: function() {
		// reset any previous errors
		$('#modelAlert').html('');
		$('.control-group').removeClass('error');
		$('.help-inline').html('');

		// if this is new then on success we need to add it to the collection
		var isNew = page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
.isNew();

		app.showProgress('modelLoader');

		page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
.save({
<?php 
        $_smarty_tpl->tpl_vars['column'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['column']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['table']->value->Columns;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['column']->total = $_smarty_tpl->_count($_from);
        $_smarty_tpl->tpl_vars['column']->iteration = 0;
        foreach ($_from as $_smarty_tpl->tpl_vars['column']->key => $_smarty_tpl->tpl_vars['column']->value) {
            $_smarty_tpl->tpl_vars['column']->_loop = true;
            $_smarty_tpl->tpl_vars['column']->iteration++;
            $_smarty_tpl->tpl_vars['column']->last = $_smarty_tpl->tpl_vars['column']->iteration === $_smarty_tpl->tpl_vars['column']->total;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['columnsForEach']['last'] = $_smarty_tpl->tpl_vars['column']->last;
            if ($_smarty_tpl->tpl_vars['column']->value->Extra != 'auto_increment') {
                ?>
			'<?php 
                echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                ?>
': <?php 
                if ($_smarty_tpl->tpl_vars['column']->value->Type == "datetime" || $_smarty_tpl->tpl_vars['column']->value->Type == "timestamp") {
                    ?>
$('input#<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
').val()+' '+$('input#<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
-time').val()<?php 
                } else {
                    ?>
$('<?php 
                    if ($_smarty_tpl->tpl_vars['column']->value->Key == "MUL" && $_smarty_tpl->tpl_vars['column']->value->Constraints || $_smarty_tpl->tpl_vars['column']->value->IsEnum()) {
                        ?>
select<?php 
                    } elseif ($_smarty_tpl->tpl_vars['column']->value->Type == 'text' || $_smarty_tpl->tpl_vars['column']->value->Type == 'tinytext' || $_smarty_tpl->tpl_vars['column']->value->Type == 'mediumtext' || $_smarty_tpl->tpl_vars['column']->value->Type == 'longtext') {
                        ?>
textarea<?php 
                    } else {
                        ?>
input<?php 
                    }
                    ?>
#<?php 
                    echo smarty_modifier_lcfirst(smarty_modifier_studlycaps($_smarty_tpl->tpl_vars['column']->value->NameWithoutPrefix));
                    ?>
').val()<?php 
                }
                if (!$_smarty_tpl->getVariable('smarty')->value['foreach']['columnsForEach']['last']) {
                    ?>
,<?php 
                }
            }
            ?>

<?php 
        }
        ?>
		}, {
			wait: true,
			success: function(){
				$('#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
DetailDialog').modal('hide');
				setTimeout("app.appendAlert('<?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 was sucessfully " + (isNew ? "inserted" : "updated") + "','alert-success',3000,'collectionAlert')",500);
				app.hideProgress('modelLoader');

				// if the collection was initally new then we need to add it to the collection now
				if (isNew) { page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['plural']->value);
        ?>
.add(page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
) }

				if (model.reloadCollectionOnModelUpdate) {
					// re-fetch and render the collection after the model has been updated
					page.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
(page.fetchParams,true);
				}
		},
			error: function(model,response,scope){

				app.hideProgress('modelLoader');

				app.appendAlert(app.getErrorMessage(response), 'alert-error',0,'modelAlert');

				try {
					var json = $.parseJSON(response.responseText);

					if (json.errors) {
						$.each(json.errors, function(key, value) {
							$('#'+key+'InputContainer').addClass('error');
							$('#'+key+'InputContainer span.help-inline').html(value);
							$('#'+key+'InputContainer span.help-inline').show();
						});
					}
				} catch (e2) {
					if (console) console.log('error parsing server response: '+e2.message);
				}
			}
		});
	},

	/**
	 * delete the model that is currently displayed in the dialog
	 */
	deleteModel: function()	{
		// reset any previous errors
		$('#modelAlert').html('');

		app.showProgress('modelLoader');

		page.<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
.destroy({
			wait: true,
			success: function(){
				$('#<?php 
        echo smarty_modifier_lcfirst($_smarty_tpl->tpl_vars['singular']->value);
        ?>
DetailDialog').modal('hide');
				setTimeout("app.appendAlert('The <?php 
        echo $_smarty_tpl->tpl_vars['singular']->value;
        ?>
 record was deleted','alert-success',3000,'collectionAlert')",500);
				app.hideProgress('modelLoader');

				if (model.reloadCollectionOnModelUpdate) {
					// re-fetch and render the collection after the model has been updated
					page.fetch<?php 
        echo $_smarty_tpl->tpl_vars['plural']->value;
        ?>
(page.fetchParams,true);
				}
			},
			error: function(model,response,scope) {
				app.appendAlert(app.getErrorMessage(response), 'alert-error',0,'modelAlert');
				app.hideProgress('modelLoader');
			}
		});
	}
};

<?php 
    }