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');
|
2014-12-01 03:01:02 +00:00
|
|
|
$this->template->content = $x->date_enrol_max(TRUE);
|
2014-10-22 23:05:32 +00:00
|
|
|
}
|
|
|
|
|
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()) {
|
2014-12-01 03:01:02 +00:00
|
|
|
foreach ($this->request->post('room') as $index=>$room) {
|
|
|
|
$new = FALSE;
|
|
|
|
|
|
|
|
if (! $room['id'] OR ! $rco=$co->subitem_get('id',$room['id'])) {
|
|
|
|
$new = TRUE;
|
|
|
|
$rco = $co->room;
|
|
|
|
$rco->child_id = $co->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rco->values($room);
|
|
|
|
|
|
|
|
if ($new)
|
|
|
|
$co->subitem_add($rco);
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:22:47 +00:00
|
|
|
$co->values($this->request->post());
|
|
|
|
|
2014-12-01 03:01:02 +00:00
|
|
|
if (! $this->save($co))
|
2014-10-22 11:22:47 +00:00
|
|
|
$co->reload()->values($this->request->post());
|
|
|
|
}
|
|
|
|
|
|
|
|
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-12-01 03:01:02 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
var x = '.count($co->subitems()).';
|
|
|
|
|
|
|
|
$("button[name=add]").click(function() {
|
|
|
|
// Send the request and get a new room row
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
data: "cid='.$co->id.'&type="+$(this).val()+"&id="+x++,
|
|
|
|
dataType: "html",
|
|
|
|
cache: false,
|
|
|
|
url: "'.URL::link('director','child/ajaxroomrow',TRUE).'",
|
|
|
|
timeout: 2000,
|
|
|
|
error: function(x) {
|
|
|
|
alert("Failed to submit");
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$("table[name=room] tr:last").after(data);
|
|
|
|
}
|
2014-10-22 23:05:32 +00:00
|
|
|
});
|
2014-12-01 03:01:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#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 input:not(#dob)").each(function(){$(this).datepicker("setEndDate",data)});
|
|
|
|
}
|
2014-10-22 23:05:32 +00:00
|
|
|
});
|
|
|
|
});
|
2014-12-01 03:01:02 +00:00
|
|
|
});
|
2014-10-22 11:22:47 +00:00
|
|
|
');
|
|
|
|
|
|
|
|
return View::factory('child/user/add_edit')
|
|
|
|
->set('o',$co)
|
|
|
|
->set('so',Company::instance()->so());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|