2014-10-22 11:22:47 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Membership Database Add Children
|
|
|
|
*
|
|
|
|
* @package Membership Database
|
|
|
|
* @category Controllers/User
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2014 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_User_Child extends Controller_Child {
|
|
|
|
protected $auth_required = TRUE;
|
|
|
|
protected $secure_actions = array(
|
|
|
|
'add'=>TRUE,
|
2014-10-22 23:05:32 +00:00
|
|
|
'ajaxage'=>FALSE,
|
|
|
|
'ajaxagemax'=>FALSE,
|
2014-10-22 11:22:47 +00:00
|
|
|
'edit'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
public function action_add() {
|
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title('Add/Edit Record')
|
|
|
|
->title_icon('fa-wrench')
|
|
|
|
->body($this->add_edit());
|
|
|
|
}
|
|
|
|
|
2014-10-22 23:05:32 +00:00
|
|
|
public function action_ajaxage() {
|
|
|
|
$x = ORM::factory('Child');
|
|
|
|
$x->dob = $this->request->query('date');
|
|
|
|
$this->template->content = $x->age();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_ajaxagemax() {
|
|
|
|
$x = ORM::factory('Child');
|
|
|
|
$x->dob = $this->request->query('date');
|
|
|
|
$this->template->content = $x->date_enrol_max();
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:22:47 +00:00
|
|
|
public function action_edit() {
|
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title('Add/Edit Record')
|
|
|
|
->title_icon('fa-wrench')
|
|
|
|
->body($this->add_edit($this->request->param('id')));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function add_edit($id=NULL) {
|
|
|
|
$co = ORM::factory('Child',$id);
|
|
|
|
|
|
|
|
if ($this->request->post()) {
|
|
|
|
$co->values($this->request->post());
|
|
|
|
$co->account_id = (string)$this->ao;
|
|
|
|
|
|
|
|
if ($co->changed() AND (! $this->save($co)))
|
|
|
|
$co->reload()->values($this->request->post());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no room records, we'll create a waitlist one that can be completed.
|
|
|
|
if (! $co->subitems())
|
|
|
|
$co->subitem_add($co->room->values(array('child_id'=>$co->id,'code'=>'W')));
|
|
|
|
|
|
|
|
Style::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/bootstrap/css/bootstrap.datepicker.css');
|
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/bootstrap/js/bootstrap.datepicker.js');
|
|
|
|
|
|
|
|
// Set our maximum date, that children can stay
|
|
|
|
Script::factory()
|
|
|
|
->type('stdin')
|
|
|
|
->data('
|
2014-10-22 23:05:32 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
'.($co->loaded() ? '
|
|
|
|
$("#date_stop").datepicker({
|
|
|
|
endDate: new Date('.($co->date_enrol_max()*1000).')
|
|
|
|
});
|
|
|
|
' : '').'
|
|
|
|
|
|
|
|
$("#dob").datepicker().on("hide",function(e) {
|
|
|
|
var x = $("#dob").datepicker("getDate").getTime()/1000;
|
|
|
|
|
|
|
|
// Send the request and update sub category dropdown
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
data: "date="+x,
|
|
|
|
dataType: "html",
|
|
|
|
cache: false,
|
|
|
|
url: "'.URL::link('user','child/ajaxage',TRUE).'",
|
|
|
|
timeout: 2000,
|
|
|
|
error: function(x) {
|
|
|
|
alert("Failed to submit");
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$("div[id=age]").empty().append(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
data: "date="+x,
|
|
|
|
dataType: "html",
|
|
|
|
cache: false,
|
|
|
|
url: "'.URL::link('user','child/ajaxagemax',TRUE).'",
|
|
|
|
timeout: 2000,
|
|
|
|
error: function(x) {
|
|
|
|
alert("Failed to submit");
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$("#date_stop").datepicker("setEndDate",new Date(data*1000));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-10-22 11:22:47 +00:00
|
|
|
');
|
|
|
|
|
|
|
|
return View::factory('child/user/add_edit')
|
|
|
|
->set('o',$co)
|
|
|
|
->set('so',Company::instance()->so());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|