150 lines
3.4 KiB
PHP
150 lines
3.4 KiB
PHP
<?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,
|
|
'ajaxage'=>FALSE,
|
|
'ajaxagemax'=>FALSE,
|
|
'edit'=>TRUE,
|
|
);
|
|
|
|
public function action_add() {
|
|
Block::factory()
|
|
->type('form-horizontal')
|
|
->title('Add/Edit Record')
|
|
->title_icon('fa-wrench')
|
|
->body($this->add_edit());
|
|
}
|
|
|
|
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(TRUE);
|
|
}
|
|
|
|
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()) {
|
|
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);
|
|
}
|
|
|
|
$co->values($this->request->post());
|
|
|
|
if (! $this->save($co))
|
|
$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('
|
|
$(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);
|
|
}
|
|
});
|
|
});
|
|
|
|
$("#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)});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
');
|
|
|
|
return View::factory('child/user/add_edit')
|
|
->set('o',$co)
|
|
->set('so',Company::instance()->so());
|
|
}
|
|
}
|
|
?>
|