Work on enrolment for Kinder

This commit is contained in:
Deon George 2016-08-31 02:13:05 +10:00
parent 571c6a9e3e
commit c82b8b127d
15 changed files with 324 additions and 15 deletions

View File

@ -2,7 +2,7 @@
RewriteEngine On RewriteEngine On
# Installation directory # Installation directory
RewriteBase /memberdb RewriteBase /
# Protect hidden files from being viewed # Protect hidden files from being viewed
<Files .*> <Files .*>

View File

@ -1,9 +1,6 @@
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
// -- Environment setup -------------------------------------------------------- // -- Environment setup --------------------------------------------------------
$SERVER_NAMES = array(
'dev.leenooks.vpn',
);
// Load the core Kohana class // Load the core Kohana class
require SYSPATH.'classes/Kohana/Core'.EXT; require SYSPATH.'classes/Kohana/Core'.EXT;
@ -59,6 +56,13 @@ spl_autoload_register(array('Kohana', 'auto_load'));
*/ */
ini_set('unserialize_callback_func', 'spl_autoload_call'); ini_set('unserialize_callback_func', 'spl_autoload_call');
/**
* Set the mb_substitute_character to "none"
*
* @link http://www.php.net/manual/function.mb-substitute-character.php
*/
mb_substitute_character('none');
// -- Configuration and initialization ----------------------------------------- // -- Configuration and initialization -----------------------------------------
/** /**
@ -66,6 +70,12 @@ ini_set('unserialize_callback_func', 'spl_autoload_call');
*/ */
I18n::lang('en-us'); I18n::lang('en-us');
if (isset($_SERVER['SERVER_PROTOCOL']))
{
// Replace the default protocol.
HTTP::$protocol = $_SERVER['SERVER_PROTOCOL'];
}
/** /**
* Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied. * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
* *
@ -76,7 +86,7 @@ I18n::lang('en-us');
/** /**
* Set the environment status by the domain. * Set the environment status by the domain.
*/ */
Kohana::$environment = (! isset($_SERVER['SERVER_NAME']) OR in_array($_SERVER['SERVER_NAME'],$SERVER_NAMES)) ? Kohana::PRODUCTION : Kohana::DEVELOPMENT; Kohana::$environment = Kohana::PRODUCTION;
if (isset($_SERVER['KOHANA_ENV'])) if (isset($_SERVER['KOHANA_ENV']))
{ {
@ -99,7 +109,7 @@ if (isset($_SERVER['KOHANA_ENV']))
* - boolean expose set the X-Powered-By header FALSE * - boolean expose set the X-Powered-By header FALSE
*/ */
Kohana::init(array( Kohana::init(array(
'base_url' => Kohana::$environment === Kohana::PRODUCTION ? '/memberdb' : '/memberdb', 'base_url' => '/',
'caching' => Kohana::$environment === Kohana::PRODUCTION, 'caching' => Kohana::$environment === Kohana::PRODUCTION,
'profile' => Kohana::$environment !== Kohana::PRODUCTION, 'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'index_file' => FALSE, 'index_file' => FALSE,
@ -133,12 +143,21 @@ Kohana::modules(array(
'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework 'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework
// 'minion' => SMDPATH.'minion', // CLI Tasks // 'minion' => SMDPATH.'minion', // CLI Tasks
'orm' => SMDPATH.'orm', // Object Relationship Mapping 'orm' => SMDPATH.'orm', // Object Relationship Mapping
// 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework
// 'unittest' => SMDPATH.'unittest', // Unit testing // 'unittest' => SMDPATH.'unittest', // Unit testing
// 'userguide' => SMDPATH.'userguide', // User guide and API documentation // 'userguide' => SMDPATH.'userguide', // User guide and API documentation
// 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework // 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework
)); ));
/**
* Cookie Salt
* @see http://kohanaframework.org/3.3/guide/kohana/cookies
*
* If you have not defined a cookie salt in your Cookie class then
* uncomment the line below and define a preferrably long salt.
*/
// Cookie::$salt = NULL;
/** /**
* Load our modules defined in the DB * Load our modules defined in the DB
*/ */
@ -168,7 +187,7 @@ Route::set('default/media', 'media(/<file>)', array('file' => '.+'))
*/ */
Route::set('default', '(<controller>(/<action>(/<id>)))', array('id'=>'[a-zA-Z0-9_.:-]+')) Route::set('default', '(<controller>(/<action>(/<id>)))', array('id'=>'[a-zA-Z0-9_.:-]+'))
->defaults(array( ->defaults(array(
'controller' => 'welcome', 'controller' => 'login',
'action' => 'index', 'action' => 'index',
)); ));

View File

@ -0,0 +1,77 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides MODULE management
*
* @package lnAuth
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Site_Date extends Controller_TemplateDefault {
protected $auth_required = TRUE;
protected $secure_actions = array(
'add'=>TRUE,
'edit'=>TRUE,
'list'=>TRUE,
);
protected $icon = 'fa fa-calendar';
/**
* Add a new site dates
*/
public function action_add() {
Block::factory()
->type('form-horizontal')
->title('New Site Date')
->title_icon($this->icon)
->body($this->add_edit());
}
private function add_edit($id=NULL,$output='') {
$o = ORM::factory('Site_Dates',$id);
if ($this->request->post() AND $o->values($this->request->post())->changed()) {
// Some validation
if ($o->code == 'S') {
$o->date_stop = NULL;
$o->date_start = strtotime(date('Y',$o->date_start).'-01-01');
$o->date_stop = strtotime(date('Y',$o->date_start).'-12-31');
}
if (! $this->save($o))
$o->reload();
}
$this->meta->title = $o->loaded() ? sprintf('Site Date: %s',$o->id) : 'New Site Date';
return View::factory('site/date/admin/add_edit')
->set('o',$o);
}
/**
* Edit a Module Configuration
*/
public function action_edit() {
Block::factory()
->type('form-horizontal')
->title('Update Site Date')
->title_icon($this->icon)
->body($this->add_edit($this->request->param('id')));
}
/**
* List site dates
*/
public function action_list() {
$this->meta->title = 'A|List Site Dates';
Block::factory()
->title('Site Dates')
->title_icon($this->icon)
->body(View::factory('site/date/list')->set('o',ORM::factory('Site_Dates')->find_all()));
}
}
?>

View File

@ -0,0 +1,63 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Membership Database Register
*
* @package Membership Database
* @category Controllers/User
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Enrol extends Controller_TemplateDefault{
protected $auth_required = FALSE;
public function action_index() {
$sdo = $this->request->post('year') ? ORM::factory('Site_Dates',$this->request->post('year')) : ORM::factory('Site_Dates')->where_year($this->request->param('id'));
if (! $sdo->loaded()) {
Block::factory()
->type('form-horizontal')
->title('Choose year of enrolment')
->title_icon('fa fa-calendar')
->body(View::factory('enrol/selectyear'));
return;
}
$ao = ORM::factory('Account');
$co = ORM::factory('Child');
$this->meta->title = 'Enrol';
if ($this->request->post('account') AND $this->request->post('child') AND $this->request->post('room.id')) {
$ao->values($this->request->post('account'));
$co->values($this->request->post('child'));
$ro = ORM::factory('Rooms',$this->request->post('room.id'));
// First we need to make an account
try {
if ($ao->save() AND $co->save()) {
$co->account_id = $ao;
$co->status = 'PEND';
$co->save();
$co->add('rooms',$ro);
}
} catch (ORM_Validation_Exception $e) {
SystemMessage::factory()
->title('Record NOT created')
->type('danger')
->body(join('<br/>',array_values($e->errors('register'))));
}
}
Block::factory()
->type('form-horizontal')
->title('Register enrolment for: '.$sdo->year())
->title_icon('fa fa-university')
->body(View::factory('enrol/child')->set('ao',$ao)->set('co',$co)->set('room_id',$this->request->post('room.id'))->set('year',$sdo->id));
}
}
?>

View File

@ -16,7 +16,7 @@ class Model_Child extends ORM {
protected $_max_return = '12-31'; // Date to leave the center when max date reached, eg: Jan 1 protected $_max_return = '12-31'; // Date to leave the center when max date reached, eg: Jan 1
protected $_has_many = array( protected $_has_many = array(
'room'=>array('model'=>'Room_Children','foreign_key'=>'child_id','far_key'=>'id'), 'rooms'=>array('through'=>'room_children'),
); );
public function filters() { public function filters() {
@ -38,7 +38,7 @@ class Model_Child extends ORM {
); );
protected $_sub_items_load = array( protected $_sub_items_load = array(
'room'=>array('date_start','date_stop'), 'rooms'=>array('date_start','date_stop'),
); );
private function _dob() { private function _dob() {

View File

@ -132,5 +132,14 @@ class Model_Rooms extends ORM {
return $result; return $result;
} }
/**
* Rooms marked with the internal flag are the actual rooms that children are assigned in
* but cannot have an enrolment application for (there may be multiple rooms for the program).
* Thus a non "internal" room should be used for enrolments for the program.
*/
public function where_external() {
return $this->where_open()->where('internal','is',NULL)->or_where('internal','=',0)->where_close();
}
} }
?> ?>

View File

@ -8,12 +8,72 @@
* @author Deon George * @author Deon George
* @copyright (c) 2014 Deon George * @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*
*/ */
class Model_Site_Dates extends ORM { class Model_Site_Dates extends ORM {
// @todo: Code O (open) start/end dates cannot overlap with existing records - put in validation that it cannot be saved. protected $_created_column = NULL;
protected $_updated_column = NULL;
protected $_display_filters = array(
'date_start'=>array(
array('Site::date',array(':value')),
),
'date_stop'=>array(
array('Site::date',array(':value')),
),
);
/**
* List our codes
* CODE:
* + O (open) - site is open for business (start/end cannot overlap)
* + S (school year) - this is a year for school terms @see mdb_term_dates (only year is used from start)
* @todo: Code O (open) start/end dates cannot overlap with existing records - put in validation that it cannot be saved.
*/
public function codes() {
return [
'O'=>'Open',
'S'=>'School Year',
];
}
/**
* Return if this day is open
*/
public function open($day) { public function open($day) {
return $this->{'d_'.$day}; return $this->{'d_'.$day};
} }
public function where_year($year) {
$id = 0;
foreach ($this->list_years() as $k => $v)
if ($v == $year) {
$id = $k;
break;
}
// If we get hear, we didnt find the years
return ORM::factory('Site_Dates',$id ? $id : NULL);
}
/**
* Return the year this record peratins to
* @note: Only valid for School Years (code S)
*/
public function year() {
if ($this->code != 'S')
throw HTTP_Exception::factory(501,'Invalid call to :method, code [:code] is incorrect',[':method'=>__METHOD__,':code'=>$this->code]);
return $this->date_start ? date('Y',$this->date_start) : NULL;
}
public function list_years() {
$result = array();
foreach (ORM::factory('Site_Dates')->where('code','=','S')->where('date_stop','>',time())->find_all()->as_array() as $sdo)
$result[$sdo->id] = $sdo->year();
return $result;
}
} }
?> ?>

View File

@ -35,7 +35,7 @@ class URL extends lnApp_URL {
case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'fa-user'); case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'fa-user');
break; break;
default: $result[$k] = array('name'=>$k,'icon'=>'fa-question-sign'); default: $result[$k] = array('name'=>$k,'icon'=>'fa-question');
} }
return $result; return $result;

View File

@ -0,0 +1,44 @@
<div class="col-md-12">
<?php
echo View::factory('field/select')->set('data',['field'=>'room[id]','value'=>ORM::factory('Rooms')->where_external()->list_select(),'default'=>$room_id,'text'=>'Program','class'=>'col-md-4']);
?>
<fieldset>
<legend>Child Details</legend>
<?php
echo View::factory('field/text')->set('data',['field'=>'child[first_name]','value'=>$co->first_name,'text'=>'First Name','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'child[family_name]','value'=>$co->family_name,'text'=>'Last Name','class'=>'col-md-5']);
echo View::factory('field/date')->set('data',['field'=>'child[dob]','value'=>$co->dob ? $co->dob : time(),'text'=>'Date of Birth','enddate'=>'new Date()']);
?>
</fieldset>
<fieldset>
<legend>Parent Details</legend>
<?php
echo View::factory('field/text')->set('data',['field'=>'account[first_name]','value'=>$ao->first_name,'text'=>'First Name','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'account[last_name]','value'=>$ao->last_name,'text'=>'Last Name','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'account[email]','value'=>$ao->email,'text'=>'Email','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'account[address1]','value'=>$ao->address1,'text'=>'Address','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'account[address2]','value'=>$ao->address2,'text'=>'Address','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'account[city]','value'=>$ao->city,'text'=>'City','class'=>'col-md-5']);
echo View::factory('field/text')->set('data',['field'=>'account[state]','value'=>$ao->state ? $ao->state : 'Vic','text'=>'State','class'=>'col-md-1']);
echo View::factory('field/text')->set('data',['field'=>'account[zip]','value'=>$ao->zip,'text'=>'Post Code','class'=>'col-md-1']);
?>
<input type="hidden" name="account[language_id]" value="1">
<input type="hidden" name="account[country_id]" value="61">
<input type="hidden" name="year" value="<?php echo $year; ?>">
<input type="hidden" name="child[date_reg]" value="<?php echo time(); ?>">
</fieldset>
<?php #@todo This should be in a database ?>
<hr>
<p>Thank you for your enrolment. An enrolment application of $10 will be invoiced to the email address you have included above.<p>
<p>This fee must be paid within 2 days for your application to be accepted. Paying this fee via the method in the email will also confirm that your email address is correct.<p>
<p>We send all correspondence via email, so if you change your email, or dont recieve the enrolment application invoice via email, please contact us.<p>
<p>This application will be automatically deleted in 2 days if your payment has not been received.
<?php echo View::factory('field/submit'); ?>
</div>

View File

@ -0,0 +1,8 @@
<div class="col-md-12">
<?php
echo View::factory('field/select')->set('data',['field'=>'year','value'=>ORM::factory('Site_Dates')->list_years(),'default'=>date('Y',time()),'text'=>'Year','class'=>'col-md-4']);
?>
<?php echo View::factory('field/submit'); ?>
</div>

View File

@ -0,0 +1,15 @@
<div class="col-md-12">
<fieldset>
<legend>Configure New Date Parameters</legend>
<?php
echo View::factory('field/select')->set('data',['field'=>'code','value'=>Arr::Merge([''=>''],$o->codes()),'text'=>'Code','default'=>$o->code,'class'=>'col-md-4']);
echo View::factory('field/date')->set('data',['field'=>'date_start','value'=>$o->date_start ? $o->date_start : time(),'text'=>'Date Start']);
echo View::factory('field/date')->set('data',['field'=>'date_stop','value'=>$o->date_stop ? $o->date_stop : time(),'text'=>'Date Stop']);
?>
</fieldset>
<?php echo View::factory('field/submit'); ?>
</div>

View File

@ -0,0 +1,14 @@
<!-- o = Array of Model_Site_Date -->
<?php echo Table::factory()
->page_items(50)
->data($o)
->columns(array(
'id'=>'ID',
'code'=>'Code',
'date_start'=>'Date Start',
'date_stop'=>'Date End',
))
->prepend(array(
'id'=>array('url'=>URL::link('admin','site_date/edit/')),
));
?>

@ -1 +1 @@
Subproject commit e04ac7d0978213f406f2a8a8e5f389af1a9620b9 Subproject commit 898371c849356932afe44d00f29f881430792c46

@ -1 +1 @@
Subproject commit 69c8052b53a2686e2a6893611a68cdcdde6c8659 Subproject commit f5bc5dfa296a1517ebdb29b2dd0f81b09f136b6a

@ -1 +1 @@
Subproject commit 932252b620b5dc4f7f714ae6974d228417830f8a Subproject commit ceb8159826a20dc11e4df61e036dfa9a2d2e3d73