FAS UDF tab

This commit is contained in:
Paolo
2017-07-18 12:48:47 +02:00
parent de2c9703de
commit b9c846f18f
6 changed files with 202 additions and 66 deletions
+84 -5
View File
@@ -8,11 +8,15 @@ class UDF extends VileSci_Controller
{
parent::__construct();
// Load session library
$this->load->library('session');
// Loads the widget library
$this->load->library('WidgetLib');
//
$this->load->model('person/Person_model', 'PersonModel');
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
}
/**
@@ -21,19 +25,94 @@ class UDF extends VileSci_Controller
public function index()
{
$person_id = $this->input->get('person_id');
if (isset($this->session->person_id))
{
if (!isset($person_id))
{
$person_id = $this->session->person_id;
}
unset($this->session->person_id);
}
$prestudent_id = $this->input->get('prestudent_id');
if (isset($this->session->prestudent_id))
{
if (!isset($prestudent_id))
{
$prestudent_id = $this->session->prestudent_id;
}
unset($this->session->prestudent_id);
}
$result = null;
if (isset($this->session->result))
{
$result = clone $this->session->result;
$this->session->set_userdata('result', null);
}
$person = $this->PersonModel->load($person_id);
$prestudent = $this->PrestudentModel->load($prestudent_id);
$udfs = $this->PersonModel->getUDFs();
$personUdfs = $this->PersonModel->getUDFs();
$prestudentUdfs = $this->PrestudentModel->getUDFs();
$udfs['person_id'] = 1;
$udfs['prestudent_id'] = 1;
$udfs['caller'] = 'system/UDF?person_id=1';
$personUdfs['person_id'] = $person_id;
$prestudentUdfs['prestudent_id'] = $prestudent_id;
$data = array(
'udfs' => $udfs
'personUdfs' => $personUdfs,
'prestudentUdfs' => $prestudentUdfs,
'result' => $result
);
$this->load->view('system/udf', $data);
}
/**
*
*/
public function saveUDF()
{
$udfs = $this->input->post();
$validation = $this->_validate($udfs);
$userdata = array(
'person_id' => $udfs['person_id'],
'prestudent_id' => $udfs['prestudent_id']
);
if (isSuccess($validation))
{
// Load model UDF_model
$this->load->model('system/UDF_model', 'UDFModel');
$result = $this->UDFModel->saveUDFs($udfs);
$userdata['result'] = $result;
}
else
{
$userdata['result'] = $validation;
}
$this->session->set_userdata($userdata);
redirect('system/UDF');
}
/**
*
*/
private function _validate($udfs)
{
$validation = error('person_id or prestudent_id is missing');
if((isset($udfs['person_id']) && !(is_null($udfs['person_id'])) && ($udfs['person_id'] != ''))
|| (isset($udfs['prestudent_id']) && !(is_null($udfs['prestudent_id'])) && ($udfs['prestudent_id'] != '')))
{
$validation = success(true);
}
return $validation;
}
}
+8 -8
View File
@@ -49,27 +49,27 @@ class UDF_model extends DB_Model
$resultPerson = success('person');
$resultPrestudent = success('prestudent');
$person_id = $udfs['person_id'];
unset($udfs['person_id']);
$prestudent_id = $udfs['prestudent_id'];
unset($udfs['prestudent_id']);
//
if (isset($udfs['person_id']))
if (isset($person_id))
{
// Load model Person_model
$this->load->model('person/Person_model', 'PersonModel');
$person_id = $udfs['person_id'];
unset($udfs['person_id']);
$resultPerson = $this->PersonModel->update($person_id, $udfs);
}
//
if (isset($udfs['prestudent_id']))
if (isset($prestudent_id))
{
// Load model Prestudent_model
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
$prestudent_id = $udfs['prestudent_id'];
unset($udfs['prestudent_id']);
$resultPrestudent = $this->PrestudentModel->update($prestudent_id, $udfs);
}
+101 -20
View File
@@ -1,28 +1,109 @@
<?php $this->load->view("templates/header", array("title" => "UDF")); ?>
<body>
<body style="background-color: #eff0f1;">
<form action="/core/index.ci.php/api/v1/system/UDF/UDF" method="POST">
<?php
if ($result != null)
{
if (isSuccess($result))
{
?>
<div style="color: black;">
Saved!
</div>
<div>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::UDFS_ARG_NAME => $udfs
)
);
?>
</div>
<br>
<?php
}
else
{
?>
<div style="color: red;">
Error while saving!
</div>
<br>
<div style="color: red;">
<?php
$errors = $result->retval;
foreach($errors as $error)
{
foreach($error as $fieldError)
{
echo $fieldError->msg . ' -> ' . $fieldError->retval . '<br>';
}
}
?>
</div>
<br>
<br>
<br>
<?php
}
}
?>
<form action="/core/index.ci.php/system/UDF/saveUDF" method="POST">
<table>
<tr>
<td>
Person
</td>
<td width="30px">
&nbsp;
</td>
<td>
Prestudent
</td>
</tr>
<tr>
<td colspan="3">
&nbsp;
</td>
</tr>
<tr>
<td>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::UDFS_ARG_NAME => $personUdfs
)
);
?>
</td>
<td width="30px">
&nbsp;
</td>
<td>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_prestudent',
UDFWidgetTpl::UDFS_ARG_NAME => $prestudentUdfs
)
);
?>
</td>
</tr>
<tr>
<td colspan="3">
&nbsp;
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="Save">
</td>
</tr>
</table>
<div>
<input type="submit" value="Save">
</div>
<input type="hidden" name="person_id" value="<?php echo $udfs['person_id']; ?>">
<input type="hidden" name="caller" value="<?php echo $udfs['caller']; ?>">
<!-- <input type="hidden" name="prestudent_id" value="<?php echo $udfs['prestudent_id']; ?>"> -->
<input type="hidden" name="person_id" value="<?php echo $personUdfs['person_id']; ?>">
<input type="hidden" name="prestudent_id" value="<?php echo $prestudentUdfs['prestudent_id']; ?>">
</form>
</body>