Compare commits

...

5 Commits

Author SHA1 Message Date
Damiano Chintala
30c0174628 extended person attributes to employees 2021-07-26 00:23:32 +02:00
Damiano Chintala
ee4715f4da extended person attributes to suppliers 2021-07-26 00:23:32 +02:00
Damiano Chintala
0ac338d5c8 added person attributes on customers 2021-07-26 00:23:32 +02:00
Damiano Chintala
8c080930c9 added person attributes MVC structure 2021-07-26 00:23:32 +02:00
Damiano Chintala
4e51a13eb7 created person attributes migration 2021-07-26 00:23:32 +02:00
19 changed files with 1956 additions and 46 deletions

1
.gitignore vendored
View File

@@ -38,3 +38,4 @@ auth.json
/docker/data/database/db/*
/docker/data/certbot/conf/*
/docker/data/ospos/app/*
.DS_Store

View File

@@ -159,5 +159,6 @@ $autoload['model'] = array(
'Tax',
'Tax_category',
'Tax_code',
'Tax_jurisdiction'
'Tax_jurisdiction',
'Person_attribute'
);

View File

@@ -223,6 +223,55 @@ class Customers extends Persons
$this->load->view("customers/form", $data);
}
/*
Adds Person_attributes to customer controller
*/
public function person_attributes($customer_id = -1)
{
$data['person_id'] = $customer_id;
$definition_ids = json_decode($this->input->post('definition_ids'), TRUE);
$data['definition_values'] = $this->Person_attribute->get_person_attributes_by_person($customer_id) + $this->Person_attribute->get_values_by_definitions($definition_ids);
$data['definition_names'] = $this->Person_attribute->get_definition_names();
foreach($data['definition_values'] as $definition_id => $definition_value)
{
$person_attribute_value = $this->Person_attribute->get_person_attribute_value($customer_id, $definition_id);
$person_attribute_id = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_id)) ? NULL : $person_attribute_value->person_attribute_id;
$values = &$data['definition_values'][$definition_id];
$values['person_attribute_id'] = $person_attribute_id;
$values['person_attribute_value'] = $person_attribute_value;
$values['selected_value'] = '';
if ($definition_value['definition_type'] == DROPDOWN)
{
$values['values'] = $this->Person_attribute->get_definition_values($definition_id);
$link_value = $this->Person_attribute->get_link_value($customer_id, $definition_id);
$values['selected_value'] = (empty($link_value)) ? '' : $link_value->person_attribute_id;
}
if (!empty($definition_ids[$definition_id]))
{
$values['selected_value'] = $definition_ids[$definition_id];
}
unset($data['definition_names'][$definition_id]);
}
$this->load->view('person_attributes/person', $data);
}
/*
Inserts/updates a customer
*/
@@ -275,12 +324,47 @@ class Customers extends Persons
// New customer
if($customer_id == -1)
{
// Save person attributes for new customer
$customer_id = $person_data['person_id'];
$person_attribute_links = $this->input->post('person_attribute_links') != NULL ? $this->input->post('person_attribute_links') : array();
$person_attribute_ids = $this->input->post('person_attribute_ids');
$this->Person_attribute->delete_link($customer_id);
foreach($person_attribute_links as $definition_id => $person_attribute_id)
{
$definition_type = $this->Person_attribute->get_info($definition_id)->definition_type;
if($definition_type != DROPDOWN)
{
$person_attribute_id = $this->Person_attribute->save_value($person_attribute_id, $definition_id, $customer_id, $person_attribute_ids[$definition_id], $definition_type);
}
$this->Person_attribute->save_link($customer_id, $definition_id, $person_attribute_id);
}
echo json_encode(array('success' => TRUE,
'message' => $this->lang->line('customers_successful_adding') . ' ' . $first_name . ' ' . $last_name,
'id' => $this->xss_clean($customer_data['person_id'])));
}
else // Existing customer
{
// Update Person_attributes for existing Customer
$person_attribute_links = $this->input->post('person_attribute_links') != NULL ? $this->input->post('person_attribute_links') : array();
$person_attribute_ids = $this->input->post('person_attribute_ids');
$this->Person_attribute->delete_link($customer_id);
foreach($person_attribute_links as $definition_id => $person_attribute_id)
{
$definition_type = $this->Person_attribute->get_info($definition_id)->definition_type;
if($definition_type != DROPDOWN)
{
$person_attribute_id = $this->Person_attribute->save_value($person_attribute_id, $definition_id, $customer_id, $person_attribute_ids[$definition_id], $definition_type);
}
$this->Person_attribute->save_link($customer_id, $definition_id, $person_attribute_id);
}
echo json_encode(array('success' => TRUE,
'message' => $this->lang->line('customers_successful_updating') . ' ' . $first_name . ' ' . $last_name,
'id' => $customer_id));
@@ -352,8 +436,9 @@ class Customers extends Persons
public function csv()
{
$name = 'import_customers.csv';
$data = file_get_contents('../' . $name);
force_download($name, $data);
$allowed_person_attributes = $this->Person_attribute->get_definition_names(FALSE);
$data = generate_import_customers_csv($allowed_person_attributes);
force_download($name, $data, TRUE);
}
public function csv_import()
@@ -361,7 +446,7 @@ class Customers extends Persons
$this->load->view('customers/form_csv_import', NULL);
}
public function do_csv_import()
public function do_csv_file()
{
if($_FILES['file_path']['error'] != UPLOAD_ERR_OK)
{
@@ -369,49 +454,51 @@ class Customers extends Persons
}
else
{
if(($handle = fopen($_FILES['file_path']['tmp_name'], 'r')) !== FALSE)
if(file_exists($_FILES['file_path']['tmp_name']))
{
// Skip the first row as it's the table description
fgetcsv($handle);
$i = 1;
$line_array = get_csv_file($_FILES['file_path']['tmp_name']);
$failCodes = array();
$keys = $line_array[0];
$failCodes = array();
while(($data = fgetcsv($handle)) !== FALSE)
$this->db->trans_begin();
for($i = 1; $i < count($line_array); $i++)
{
// XSS file data sanity check
$data = $this->xss_clean($data);
$invalidated = FALSE;
$consent = $data[3] == '' ? 0 : 1;
$line = array_combine($keys,$this->xss_clean($line_array[$i])); //Build a XSS-cleaned associative array with the row to use to assign values
if(sizeof($data) >= 16 && $consent)
//check for consent in file upload, y == yes , empty field == no
$consent = $line['Consent'] == '' ? 0 : 1;
if($consent)
{
$email = strtolower($data[4]);
$email = strtolower($line['Email']);
$person_data = array(
'first_name' => $data[0],
'last_name' => $data[1],
'gender' => $data[2],
'first_name' => $line['First Name'],
'last_name' => $line['Last Name'],
'gender' => $line['Gender'],
'email' => $email,
'phone_number' => $data[5],
'address_1' => $data[6],
'address_2' => $data[7],
'city' => $data[8],
'state' => $data[9],
'zip' => $data[10],
'country' => $data[11],
'comments' => $data[12]
'phone_number' => $line['Phone Number'],
'address_1' => $line['Address 1'],
'address_2' => $line['Address2'],
'city' => $line['City'],
'state' => $line['State'],
'zip' => $line['Zip'],
'country' => $line['Country'],
'comments' => $line['Comments']
);
$customer_data = array(
'consent' => $consent,
'company_name' => $data[13],
'discount' => $data[15],
'discount_type' => $data[16],
'taxable' => $data[17] == '' ? 0 : 1,
'company_name' => $line['Company'],
'discount' => $line['Discount'],
'discount_type' => $line['Discount_Type'],
'taxable' => $line['Taxable'] == '' ? 0 : 1,
'date' => date('Y-m-d H:i:s'),
'employee_id' => $this->Employee->get_logged_in_employee_info()->person_id
);
$account_number = $data[14];
$account_number = $line['Account Number'];
// don't duplicate people with same email
$invalidated = $this->Customer->check_email_exists($email);
@@ -422,36 +509,37 @@ class Customers extends Persons
$invalidated &= $this->Customer->check_account_number_exists($account_number);
}
}
else
if(!$invalidated)
{
$invalidated = TRUE;
$invalidated = $this->data_error_check($line, $person_data);
}
if($invalidated)
{
$failCodes[] = $i;
}
elseif($this->Customer->save_customer($person_data, $customer_data))
//Save to database
if(!$invalidated && $this->Customer->save_customer($person_data, $customer_data))
{
// save person_attributes to customer
$this->save_person_attribute_data($line, $customer_data);
// save customer to Mailchimp selected list
$this->mailchimp_lib->addOrUpdateMember($this->_list_id, $person_data['email'], $person_data['first_name'], '', $person_data['last_name']);
}
//Insert or update customer failure
else
{
$failCodes[] = $i;
$failed_row = $i+1;
$failCodes[] = $failed_row;
log_message("ERROR","CSV Item import failed on line ". $failed_row .". This customer was not imported.");
}
++$i;
}
if(count($failCodes) > 0)
{
$message = $this->lang->line('customers_csv_import_partially_failed') . ' (' . count($failCodes) . '): ' . implode(', ', $failCodes);
$this->db->trans_rollback();
echo json_encode(array('success' => FALSE, 'message' => $message));
}
else
{
$this->db->trans_commit();
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('customers_csv_import_success')));
}
}
@@ -461,5 +549,141 @@ class Customers extends Persons
}
}
}
/**
* Checks the entire line of data in an import file for errors
*
* @param array $line
* @param array $person_data
*
* @return bool Returns FALSE if all data checks out and TRUE when there is an error in the data
*/
private function data_error_check($line, $person_data)
{
//Check for empty required fields
$check_for_empty = array(
$person_data['first_name'],
$person_data['last_name']
);
foreach($check_for_empty as $key => $val)
{
if (empty($val))
{
log_message("ERROR","Empty required value");
return TRUE; //Return fail on empty required fields
}
}
//Build array of fields to check for numerics
$check_for_numeric_values = array(
$person_data['gender'],
$customer_data['discount'],
$customer_data['discount_type']
);
//Check for non-numeric values which require numeric
foreach($check_for_numeric_values as $value)
{
if(!is_numeric($value) && $value != '')
{
log_message("ERROR","non-numeric: '$value' when numeric is required");
return TRUE;
}
}
//Check Person attribute Data
$definition_names = $this->Person_attribute->get_definition_names();
unset($definition_names[-1]);
foreach($definition_names as $definition_name)
{
if(!empty($line['person_attribute_' . $definition_name]))
{
$person_attribute_data = $this->Person_attribute->get_definition_by_name($definition_name)[0];
$person_attribute_type = $person_attribute_data['definition_type'];
$person_attribute_value = $line['person_attribute_' . $definition_name];
if($person_attribute_type == 'DROPDOWN')
{
$dropdown_values = $this->Person_attribute->get_definition_values($person_attribute_data['definition_id']);
$dropdown_values[] = '';
if(in_array($person_attribute_value, $dropdown_values) === FALSE && !empty($person_attribute_value))
{
log_message("ERROR","Value: '$person_attribute_value' is not an acceptable DROPDOWN value");
return TRUE;
}
}
else if($person_attribute_type == 'DECIMAL')
{
if(!is_numeric($person_attribute_value) && !empty($person_attribute_value))
{
log_message("ERROR","'$person_attribute_value' is not an acceptable DECIMAL value");
return TRUE;
}
}
else if($person_attribute_type == 'DATETIME')
{
if(strtotime($person_attribute_value) === FALSE && !empty($person_attribute_value))
{
log_message("ERROR","'$person_attribute_value' is not an acceptable DATETIME value.");
return TRUE;
}
}
}
}
return FALSE;
}
/**
* Saves person_attribute data found in the CSV import.
*
* @param line
* @param failCodes
* @param person_attribute_data
*/
private function save_person_attribute_data($line, $customer_data )
{
$definition_names = $this->Person_attribute->get_definition_names();
unset($definition_names[-1]);
foreach($definition_names as $definition_name)
{
//Create person_attribute value
if(!empty($line['person_attribute_' . $definition_name]) || $line['person_attribute_' . $definition_name] == '0')
{
$person_attribute_data = $this->Person_attribute->get_definition_by_name($definition_name)[0];
//CHECKBOX Person_attribute types (zero value creates person_attribute and marks it as unchecked)
if($person_attribute_data['definition_type'] == 'CHECKBOX')
{
//FALSE and '0' value creates checkbox and marks it as unchecked.
if(strcasecmp($line['person_attribute_' . $definition_name],'FALSE') == 0 || $line['person_attribute_' . $definition_name] == '0')
{
$line['person_attribute_' . $definition_name] = '0';
}
else
{
$line['person_attribute_' . $definition_name] = '1';
}
$status = $this->Person_attribute->save_value($line['person_attribute_' . $definition_name], $person_attribute_data['definition_id'], $customer_data['person_id'], FALSE, $person_attribute_data['definition_type']);
}
//All other Person_attribute types (0 value means person_attribute not created)
elseif(!empty($line['person_attribute_' . $definition_name]))
{
$status = $this->Person_attribute->save_value($line['person_attribute_' . $definition_name], $person_attribute_data['definition_id'], $customer_data['person_id'], FALSE, $person_attribute_data['definition_type']);
}
if($status === FALSE)
{
return FALSE;
}
}
}
}
}
?>

View File

@@ -86,6 +86,54 @@ class Employees extends Persons
$this->load->view('employees/form', $data);
}
/*
Adds Person_attributes to employee controller
*/
public function person_attributes($employee_id = -1)
{
$data['person_id'] = $employee_id;
$definition_ids = json_decode($this->input->post('definition_ids'), TRUE);
$data['definition_values'] = $this->Person_attribute->get_person_attributes_by_person($employee_id) + $this->Person_attribute->get_values_by_definitions($definition_ids);
$data['definition_names'] = $this->Person_attribute->get_definition_names();
foreach($data['definition_values'] as $definition_id => $definition_value)
{
$person_attribute_value = $this->Person_attribute->get_person_attribute_value($employee_id, $definition_id);
$person_attribute_id = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_id)) ? NULL : $person_attribute_value->person_attribute_id;
$values = &$data['definition_values'][$definition_id];
$values['person_attribute_id'] = $person_attribute_id;
$values['person_attribute_value'] = $person_attribute_value;
$values['selected_value'] = '';
if ($definition_value['definition_type'] == DROPDOWN)
{
$values['values'] = $this->Person_attribute->get_definition_values($definition_id);
$link_value = $this->Person_attribute->get_link_value($employee_id, $definition_id);
$values['selected_value'] = (empty($link_value)) ? '' : $link_value->person_attribute_id;
}
if (!empty($definition_ids[$definition_id]))
{
$values['selected_value'] = $definition_ids[$definition_id];
}
unset($data['definition_names'][$definition_id]);
}
$this->load->view('person_attributes/person', $data);
}
/*
Inserts/updates an employee
*/
@@ -154,12 +202,46 @@ class Employees extends Persons
// New employee
if($employee_id == -1)
{
// Save person_attributes for new employee
$employee_id = $person_data['person_id'];
$person_attribute_links = $this->input->post('person_attribute_links') != NULL ? $this->input->post('person_attribute_links') : array();
$person_attribute_ids = $this->input->post('person_attribute_ids');
$this->Person_attribute->delete_link($employee_id);
foreach($person_attribute_links as $definition_id => $person_attribute_id)
{
$definition_type = $this->Person_attribute->get_info($definition_id)->definition_type;
if($definition_type != DROPDOWN)
{
$person_attribute_id = $this->Person_attribute->save_value($person_attribute_id, $definition_id, $employee_id, $person_attribute_ids[$definition_id], $definition_type);
}
$this->Person_attribute->save_link($employee_id, $definition_id, $person_attribute_id);
}
echo json_encode(array('success' => TRUE,
'message' => $this->lang->line('employees_successful_adding') . ' ' . $first_name . ' ' . $last_name,
'id' => $this->xss_clean($employee_data['person_id'])));
}
else // Existing employee
{
// Update person attributes for existing employee
$person_attribute_links = $this->input->post('person_attribute_links') != NULL ? $this->input->post('person_attribute_links') : array();
$person_attribute_ids = $this->input->post('person_attribute_ids');
$this->Person_attribute->delete_link($employee_id);
foreach($person_attribute_links as $definition_id => $person_attribute_id)
{
$definition_type = $this->Person_attribute->get_info($definition_id)->definition_type;
if($definition_type != DROPDOWN)
{
$person_attribute_id = $this->Person_attribute->save_value($person_attribute_id, $definition_id, $employee_id, $person_attribute_ids[$definition_id], $definition_type);
}
$this->Person_attribute->save_link($employee_id, $definition_id, $person_attribute_id);
}
echo json_encode(array('success' => TRUE,
'message' => $this->lang->line('employees_successful_updating') . ' ' . $first_name . ' ' . $last_name,
'id' => $employee_id));

View File

@@ -0,0 +1,184 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class Person_attributes extends Secure_Controller
{
public function __construct()
{
parent::__construct('person_attributes');
}
public function index()
{
$data['table_headers'] = $this->xss_clean(get_person_attribute_definition_manage_table_headers());
$this->load->view('person_attributes/manage', $data);
}
/**
* Returns person table data rows. This will be called with AJAX.
*/
public function search()
{
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$person_attributes = $this->Person_attribute->search($search, $limit, $offset, $sort, $order);
$total_rows = $this->Person_attribute->get_found_rows($search);
$data_rows = array();
foreach($person_attributes->result() as $person_attribute)
{
$person_attribute->definition_flags = $this->_get_person_attributes($person_attribute->definition_flags);
$data_rows[] = get_person_attribute_definition_data_row($person_attribute, $this);
}
$data_rows = $this->xss_clean($data_rows);
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
public function save_person_attribute_value($person_attribute_value)
{
$success = $this->Person_attribute->save_value(urldecode($person_attribute_value), $this->input->post('definition_id'), $this->input->post('person_id'), $this->input->post('person_attribute_id'));
echo json_encode(array('success' => $success != 0));
}
public function delete_person_attribute_value($person_attribute_value)
{
$success = $this->Person_attribute->delete_value($person_attribute_value, $this->input->post('definition_id'));
echo json_encode(array('success' => $success));
}
public function save_definition($definition_id = NO_DEFINITION_ID)
{
$definition_flags = 0;
$flags = (empty($this->input->post('definition_flags'))) ? array() : $this->input->post('definition_flags');
foreach($flags as $flag)
{
$definition_flags |= $flag;
}
//Save definition data
$definition_data = array(
'definition_name' => $this->input->post('definition_name'),
'definition_unit' => $this->input->post('definition_unit') != '' ? $this->input->post('definition_unit') : NULL,
'definition_flags' => $definition_flags,
'definition_fk' => $this->input->post('definition_group') != '' ? $this->input->post('definition_group') : NULL
);
if ($this->input->post('definition_type') != null)
{
$definition_data['definition_type'] = DEFINITION_TYPES[$this->input->post('definition_type')];
}
$definition_name = $this->xss_clean($definition_data['definition_name']);
if($this->Person_attribute->save_definition($definition_data, $definition_id))
{
//New definition
if($definition_id == 0)
{
$definition_values = json_decode($this->input->post('definition_values'));
foreach($definition_values as $definition_value)
{
$this->Person_attribute->save_value($definition_value, $definition_data['definition_id']);
}
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('person_attributes_definition_successful_adding').' '.
$definition_name, 'id' => $definition_data['definition_id']));
}
//Existing definition
else
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('person_attributes_definition_successful_updating').' '.
$definition_name, 'id' => $definition_id));
}
}
//Failure
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('person_attributes_definition_error_adding_updating', $definition_name), 'id' => -1));
}
}
public function suggest_person_attribute($definition_id)
{
$suggestions = $this->xss_clean($this->Person_attribute->get_suggestions($definition_id, $this->input->get('term')));
echo json_encode($suggestions);
}
public function get_row($row_id)
{
$person_attribute_definition_info = $this->Person_attribute->get_info($row_id);
$person_attribute_definition_info->definition_flags = $this->_get_person_attributes($person_attribute_definition_info->definition_flags);
$data_row = $this->xss_clean(get_person_attribute_definition_data_row($person_attribute_definition_info));
echo json_encode($data_row);
}
private function _get_person_attributes($definition_flags = 0)
{
$definition_flag_names = array();
foreach (Person_attribute::get_definition_flags() as $id => $term)
{
if ($id & $definition_flags)
{
$definition_flag_names[$id] = $this->lang->line('person_attributes_' . strtolower($term) . '_visibility');
}
}
return $definition_flag_names;
}
public function view($definition_id = NO_DEFINITION_ID)
{
$info = $this->Person_attribute->get_info($definition_id);
foreach(get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['definition_id'] = $definition_id;
$data['definition_values'] = $this->Person_attribute->get_definition_values($definition_id);
$data['definition_group'] = $this->Person_attribute->get_definitions_by_type(GROUP, $definition_id);
$data['definition_group'][''] = $this->lang->line('common_none_selected_text');
$data['definition_info'] = $info;
$show_all = Person_attribute::SHOW_IN_CUSTOMERS | Person_attribute::SHOW_IN_EMPLOYEES | Person_attribute::SHOW_IN_SUPPLIERS;
$data['definition_flags'] = $this->_get_person_attributes($show_all);
$selected_flags = $info->definition_flags === '' ? $show_all : $info->definition_flags;
$data['selected_definition_flags'] = $this->_get_person_attributes($selected_flags);
$this->load->view("person_attributes/form", $data);
}
public function delete_value($person_attribute_id)
{
return $this->Person_attribute->delete_value($person_attribute_id);
}
public function delete()
{
$person_attributes_to_delete = $this->input->post('ids');
if($this->Person_attribute->delete_definition_list($person_attributes_to_delete))
{
$message = $this->lang->line('person_attributes_definition_successful_deleted') . ' ' . count($person_attributes_to_delete) . ' ' . $this->lang->line('person_attributes_definition_one_or_multiple');
echo json_encode(array('success' => TRUE, 'message' => $message));
}
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('person_attributes_definition_cannot_be_deleted')));
}
}
}

View File

@@ -84,6 +84,55 @@ class Suppliers extends Persons
$this->load->view("suppliers/form", $data);
}
/*
Adds Person_attributes to supplier controller
*/
public function person_attributes($supplier_id = -1)
{
$data['person_id'] = $supplier_id;
$definition_ids = json_decode($this->input->post('definition_ids'), TRUE);
$data['definition_values'] = $this->Person_attribute->get_person_attributes_by_person($supplier_id) + $this->Person_attribute->get_values_by_definitions($definition_ids);
$data['definition_names'] = $this->Person_attribute->get_definition_names();
foreach($data['definition_values'] as $definition_id => $definition_value)
{
$person_attribute_value = $this->Person_attribute->get_person_attribute_value($supplier_id, $definition_id);
$person_attribute_id = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_id)) ? NULL : $person_attribute_value->person_attribute_id;
$values = &$data['definition_values'][$definition_id];
$values['person_attribute_id'] = $person_attribute_id;
$values['person_attribute_value'] = $person_attribute_value;
$values['selected_value'] = '';
if ($definition_value['definition_type'] == DROPDOWN)
{
$values['values'] = $this->Person_attribute->get_definition_values($definition_id);
$link_value = $this->Person_attribute->get_link_value($supplier_id, $definition_id);
$values['selected_value'] = (empty($link_value)) ? '' : $link_value->person_attribute_id;
}
if (!empty($definition_ids[$definition_id]))
{
$values['selected_value'] = $definition_ids[$definition_id];
}
unset($data['definition_names'][$definition_id]);
}
$this->load->view('person_attributes/person', $data);
}
/*
Inserts/updates a supplier
@@ -128,12 +177,46 @@ class Suppliers extends Persons
//New supplier
if($supplier_id == -1)
{
// Save person attributes for new supplier
$supplier_id = $person_data['person_id'];
$person_attribute_links = $this->input->post('person_attribute_links') != NULL ? $this->input->post('person_attribute_links') : array();
$person_attribute_ids = $this->input->post('person_attribute_ids');
$this->Person_attribute->delete_link($supplier_id);
foreach($person_attribute_links as $definition_id => $person_attribute_id)
{
$definition_type = $this->Person_attribute->get_info($definition_id)->definition_type;
if($definition_type != DROPDOWN)
{
$person_attribute_id = $this->Person_attribute->save_value($person_attribute_id, $definition_id, $supplier_id, $person_attribute_ids[$definition_id], $definition_type);
}
$this->Person_attribute->save_link($supplier_id, $definition_id, $person_attribute_id);
}
echo json_encode(array('success' => TRUE,
'message' => $this->lang->line('suppliers_successful_adding') . ' ' . $supplier_data['company_name'],
'id' => $supplier_data['person_id']));
}
else //Existing supplier
{
// Update person attributes for existing supplier
$person_attribute_links = $this->input->post('person_attribute_links') != NULL ? $this->input->post('person_attribute_links') : array();
$person_attribute_ids = $this->input->post('person_attribute_ids');
$this->Person_attribute->delete_link($supplier_id);
foreach($person_attribute_links as $definition_id => $person_attribute_id)
{
$definition_type = $this->Person_attribute->get_info($definition_id)->definition_type;
if($definition_type != DROPDOWN)
{
$person_attribute_id = $this->Person_attribute->save_value($person_attribute_id, $definition_id, $supplier_id, $person_attribute_ids[$definition_id], $definition_type);
}
$this->Person_attribute->save_link($supplier_id, $definition_id, $person_attribute_id);
}
echo json_encode(array('success' => TRUE,
'message' => $this->lang->line('suppliers_successful_updating') . ' ' . $supplier_data['company_name'],
'id' => $supplier_id));

View File

@@ -50,6 +50,38 @@ function generate_attribute_headers($attribute_names)
return $attribute_headers;
}
/**
* Generates the header content for the import_customers.csv file
*
* @return string Comma separated headers for the CSV file
*/
function generate_import_customers_csv($person_attributes)
{
$csv_headers = pack("CCC",0xef,0xbb,0xbf); //Encode the Byte-Order Mark (BOM) so that UTF-8 File headers display properly in Microsoft Excel
$csv_headers .= '"First Name","Last Name",Gender,Consent,Email,"Phone Number","Address 1",Address2,City,State,Zip,Country,Comments,Company,"Account Number",Discount,Discount_Type,Taxable';
$csv_headers .= generate_person_attribute_headers($person_attributes);
return $csv_headers;
}
/**
* Generates a list of person attribute names as a string
*
* @return string Comma-separated list of person_attribute names
*/
function generate_person_attribute_headers($person_attribute_names)
{
$person_attribute_headers = "";
unset($person_attribute_names[-1]);
foreach($person_attribute_names as $person_attribute_name)
{
$person_attribute_headers .= ',"person_attribute_' . $person_attribute_name . '"';
}
return $person_attribute_headers;
}
/**
* Read the contents of a given CSV formatted file into a two-dimensional array
*

View File

@@ -174,6 +174,8 @@ function get_people_manage_table_headers()
{
$CI =& get_instance();
$definition_names = $CI->Person_attribute->get_definitions_by_flags(Person_attribute::SHOW_IN_EMPLOYEES);
$headers = array(
array('people.person_id' => $CI->lang->line('common_id')),
array('last_name' => $CI->lang->line('common_last_name')),
@@ -187,6 +189,11 @@ function get_people_manage_table_headers()
$headers[] = array('messages' => '', 'sortable' => FALSE);
}
foreach($definition_names as $definition_id => $definition_name)
{
$headers[] = array($definition_id => $definition_name, 'sortable' => TRUE);
}
return transform_headers($headers);
}
@@ -197,8 +204,9 @@ function get_person_data_row($person)
{
$CI =& get_instance();
$controller_name = strtolower(get_class($CI));
$definition_names = $CI->Person_attribute->get_definitions_by_flags(Person_attribute::SHOW_IN_EMPLOYEES);
return array (
$columns = array (
'people.person_id' => $person->person_id,
'last_name' => $person->last_name,
'first_name' => $person->first_name,
@@ -210,6 +218,8 @@ function get_person_data_row($person)
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update'))
)
);
return $columns + expand_person_attribute_values($definition_names, (array) $person);
}
@@ -220,6 +230,8 @@ function get_customer_manage_table_headers()
{
$CI =& get_instance();
$definition_names = $CI->Person_attribute->get_definitions_by_flags(Person_attribute::SHOW_IN_CUSTOMERS);
$headers = array(
array('people.person_id' => $CI->lang->line('common_id')),
array('last_name' => $CI->lang->line('common_last_name')),
@@ -234,6 +246,11 @@ function get_customer_manage_table_headers()
$headers[] = array('messages' => '', 'sortable' => FALSE);
}
foreach($definition_names as $definition_id => $definition_name)
{
$headers[] = array($definition_id => $definition_name, 'sortable' => TRUE);
}
return transform_headers($headers);
}
@@ -246,7 +263,9 @@ function get_customer_data_row($person, $stats)
$controller_name = strtolower(get_class($CI));
return array (
$definition_names = $CI->Person_attribute->get_definitions_by_flags(Person_attribute::SHOW_IN_CUSTOMERS);
$columns = array (
'people.person_id' => $person->person_id,
'last_name' => $person->last_name,
'first_name' => $person->first_name,
@@ -258,6 +277,8 @@ function get_customer_data_row($person, $stats)
'edit' => anchor($controller_name."/view/$person->person_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update'))
));
return $columns + expand_person_attribute_values($definition_names, (array) $person);
}
@@ -268,6 +289,8 @@ function get_suppliers_manage_table_headers()
{
$CI =& get_instance();
$definition_names = $CI->Person_attribute->get_definitions_by_flags(Person_attribute::SHOW_IN_SUPPLIERS);
$headers = array(
array('people.person_id' => $CI->lang->line('common_id')),
array('company_name' => $CI->lang->line('suppliers_company_name')),
@@ -284,6 +307,11 @@ function get_suppliers_manage_table_headers()
$headers[] = array('messages' => '');
}
foreach($definition_names as $definition_id => $definition_name)
{
$headers[] = array($definition_id => $definition_name, 'sortable' => TRUE);
}
return transform_headers($headers);
}
@@ -296,7 +324,9 @@ function get_supplier_data_row($supplier)
$controller_name = strtolower(get_class($CI));
return array (
$definition_names = $CI->Person_attribute->get_definitions_by_flags(Person_attribute::SHOW_IN_SUPPLIERS);
$columns = array (
'people.person_id' => $supplier->person_id,
'company_name' => $supplier->company_name,
'agency_name' => $supplier->agency_name,
@@ -310,6 +340,8 @@ function get_supplier_data_row($supplier)
'edit' => anchor($controller_name."/view/$supplier->person_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>"modal-dlg", 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update')))
);
return $columns + expand_person_attribute_values($definition_names, (array) $supplier);
}
@@ -613,6 +645,95 @@ function get_attribute_definition_data_row($attribute)
);
}
/*
Get html data row for person_attributes
*/
function parse_person_attribute_values($columns, $row) {
$person_attribute_values = array();
foreach($columns as $column) {
if (array_key_exists($column, $row))
{
$person_attribute_value = explode('|', $row[$column]);
$person_attribute_values = array_merge($person_attribute_values, $person_attribute_value);
}
}
return $person_attribute_values;
}
function expand_person_attribute_values($definition_names, $row)
{
$values = parse_person_attribute_values(array('person_attribute_values', 'person_attribute_dtvalues', 'person_attribute_dvalues'), $row);
$indexed_values = array();
foreach($values as $person_attribute_value)
{
$exploded_value = explode('_', $person_attribute_value);
if(sizeof($exploded_value) > 1)
{
$indexed_values[$exploded_value[0]] = $exploded_value[1];
}
}
$person_attribute_values = array();
foreach($definition_names as $definition_id => $definition_name)
{
if(isset($indexed_values[$definition_id]))
{
$person_attribute_value = $indexed_values[$definition_id];
$person_attribute_values["$definition_id"] = $person_attribute_value;
}
}
return $person_attribute_values;
}
function get_person_attribute_definition_manage_table_headers()
{
$CI =& get_instance();
$headers = array(
array('definition_id' => $CI->lang->line('person_attributes_definition_id')),
array('definition_name' => $CI->lang->line('person_attributes_definition_name')),
array('definition_type' => $CI->lang->line('person_attributes_definition_type')),
array('definition_flags' => $CI->lang->line('person_attributes_definition_flags')),
array('definition_group' => $CI->lang->line('person_attributes_definition_group')),
);
return transform_headers($headers);
}
function get_person_attribute_definition_data_row($person_attribute)
{
$CI =& get_instance();
$controller_name = strtolower(get_class($CI));
if(count($person_attribute->definition_flags) == 0)
{
$definition_flags = $CI->lang->line('common_none_selected_text');
}
else if($person_attribute->definition_type == GROUP)
{
$definition_flags = "-";
}
else
{
$definition_flags = implode(', ', $person_attribute->definition_flags);
}
return array (
'definition_id' => $person_attribute->definition_id,
'definition_name' => $person_attribute->definition_name,
'definition_type' => $person_attribute->definition_type,
'definition_group' => $person_attribute->definition_group,
'definition_flags' => $definition_flags,
'edit' => anchor("$controller_name/view/$person_attribute->definition_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update'))
)
);
}
/*
Get the header for the expense categories tabular view
*/

View File

@@ -39,3 +39,5 @@ $lang["module_suppliers"] = "Suppliers";
$lang["module_suppliers_desc"] = "Add, Update, Delete, and Search Suppliers.";
$lang["module_taxes"] = "Taxes";
$lang["module_taxes_desc"] = "Configure Sales Taxes.";
$lang["module_person_attributes"] = "Person Attributes";
$lang["module_person_attributes_desc"] = "Add, Update, Delete, and Search Person Attributes.";

View File

@@ -0,0 +1,30 @@
<?php
$lang["person_attributes_person_attribute_value_invalid_chars"] = "Person Attribute value cannot contain '_' or '|'";
$lang["person_attributes_confirm_delete"] = "Are you sure you want to delete the selected person_attribute(s)?";
$lang["person_attributes_confirm_restore"] = "Are you sure you want to restore the selected person attribute(s)?";
$lang["person_attributes_definition_cannot_be_deleted"] = "Could not delete selected person attribute(s)";
$lang["person_attributes_definition_error_adding_updating"] = "Person Attribute %1 could not be added or updated. Please check the error log.";
$lang["person_attributes_definition_flags"] = "Person Attribute Visibility";
$lang["person_attributes_definition_group"] = "Group";
$lang["person_attributes_definition_id"] = "Id";
$lang["person_attributes_definition_name"] = "Add Person Attribute";
$lang["person_attributes_definition_name_required"] = "Person Attribute name is a required field";
$lang["person_attributes_definition_one_or_multiple"] = "person_attribute(s)";
$lang["person_attributes_definition_successful_adding"] = "You have successfully added item";
$lang["person_attributes_definition_successful_deleted"] = "You have successfully deleted";
$lang["person_attributes_definition_successful_updating"] = "You have successfully updated person attribute";
$lang["person_attributes_definition_type"] = "Person Attribute Type";
$lang["person_attributes_definition_type_required"] = "Person Attribute type is a required field";
$lang["person_attributes_definition_unit"] = "Measurement Unit";
$lang["person_attributes_definition_values"] = "Person Attribute Values";
$lang["person_attributes_new"] = "New Person Attribute";
$lang["person_attributes_no_person_attributes_to_display"] = "No Items to display";
$lang["person_attributes_receipt_visibility"] = "Receipt";
$lang["person_attributes_show_in_customers"] = "Show in customers";
$lang["person_attributes_show_in_customers_visibility"] = "Customers";
$lang["person_attributes_show_in_employees"] = "Show in employees";
$lang["person_attributes_show_in_employees_visibility"] = "Employees";
$lang["person_attributes_show_in_suppliers"] = "Show in suppliers";
$lang["person_attributes_show_in_suppliers_visibility"] = "Suppliers";
$lang["person_attributes_update"] = "Update Person Attribute";

View File

@@ -0,0 +1,20 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Migration_Person_Attributes extends CI_Migration
{
public function __construct()
{
parent::__construct();
}
public function up()
{
execute_script(APPPATH . 'migrations/sqlscripts/3.3.4_person_attributes.sql');
}
public function down()
{
}
}
?>

View File

@@ -0,0 +1,50 @@
CREATE TABLE IF NOT EXISTS `ospos_person_attribute_definitions` (
`definition_id` INT(10) NOT NULL AUTO_INCREMENT,
`definition_name` VARCHAR(255) NOT NULL,
`definition_type` VARCHAR(45) NOT NULL,
`definition_unit` VARCHAR(16) NULL,
`definition_flags` TINYINT(4) NOT NULL,
`definition_fk` INT(10) NULL,
`deleted` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`definition_id`),
KEY `definition_fk` (`definition_fk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `ospos_person_attribute_values` (
`person_attribute_id` INT NOT NULL AUTO_INCREMENT,
`person_attribute_value` VARCHAR(255) UNIQUE NULL,
`person_attribute_date` DATETIME NULL,
`person_attribute_decimal` DECIMAL(7,3) NULL,
PRIMARY KEY (`person_attribute_id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `ospos_person_attribute_links` (
`person_attribute_id` INT NULL,
`definition_id` INT NOT NULL,
`person_id` INT NULL,
KEY `person_attribute_id` (`person_attribute_id`),
KEY `definition_id` (`definition_id`),
KEY `person_id` (`person_id`),
UNIQUE `person_attribute_links_uq1` (`person_attribute_id`, `definition_id`, `person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
ALTER TABLE `ospos_person_attribute_definitions`
ADD CONSTRAINT `fk_ospos_person_attribute_definitions_ibfk_1` FOREIGN KEY (`definition_fk`) REFERENCES `ospos_person_attribute_definitions` (`definition_id`);
ALTER TABLE `ospos_person_attribute_links`
ADD CONSTRAINT `ospos_person_attribute_links_ibfk_1` FOREIGN KEY (`definition_id`) REFERENCES `ospos_person_attribute_definitions` (`definition_id`) ON DELETE CASCADE,
ADD CONSTRAINT `ospos_person_attribute_links_ibfk_2` FOREIGN KEY (`person_attribute_id`) REFERENCES `ospos_person_attribute_values` (`person_attribute_id`) ON DELETE CASCADE,
ADD CONSTRAINT `ospos_person_attribute_links_ibfk_3` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
INSERT INTO `ospos_modules` (`name_lang_key`, `desc_lang_key`, `sort`, `module_id`) VALUES
('module_person_attributes', 'module_person_attributes_desc', 108, 'person_attributes');
INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES
('person_attributes', 'person_attributes');
INSERT INTO `ospos_grants` (`permission_id`, `person_id`, `menu_group`) VALUES
('person_attributes', 1, 'office');

View File

@@ -0,0 +1,665 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Person_attribute class
*/
class Person_attribute extends CI_Model
{
const SHOW_IN_CUSTOMERS = 1;
const SHOW_IN_EMPLOYEES = 2;
const SHOW_IN_SUPPLIERS = 4;
public static function get_definition_flags()
{
$class = new ReflectionClass(__CLASS__);
return array_flip($class->getConstants());
}
/*
Determines if a given definition_id is an person_attribute
*/
public function exists($definition_id, $deleted = FALSE)
{
$this->db->from('person_attribute_definitions');
$this->db->where('definition_id', $definition_id);
$this->db->where('deleted', $deleted);
return ($this->db->get()->num_rows() == 1);
}
public function link_exists($person_id, $definition_id = FALSE)
{
$this->db->from('person_attribute_links');
if(empty($definition_id))
{
$this->db->where('definition_id <>');
$this->db->where('person_attribute_id');
}
else
{
$this->db->where('definition_id', $definition_id);
}
$this->db->where('person_id', $person_id);
return ($this->db->get()->num_rows() > 0);
}
/*
Determines if a given person_attribute_value exists in the person_attribute_values table and returns the person_attribute_id if it does
*/
public function value_exists($person_attribute_value)
{
$this->db->distinct('person_attribute_id');
$this->db->from('person_attribute_values');
$this->db->where('person_attribute_value', $person_attribute_value);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
return $query->row()->person_attribute_id;
}
return FALSE;
}
/*
Gets information about a particular person_attribute definition
*/
public function get_info($definition_id)
{
$this->db->select('parent_definition.definition_name AS definition_group, definition.*');
$this->db->from('person_attribute_definitions AS definition');
$this->db->join('person_attribute_definitions AS parent_definition', 'parent_definition.definition_id = definition.definition_fk', 'left');
$this->db->where('definition.definition_id', $definition_id);
$query = $this->db->get();
if($query->num_rows() == 1)
{
return $query->row();
}
else
{
//Get empty base parent object, as $person_id is NOT a customer
$item_obj = new stdClass();
//Get all the fields from customers table
foreach($this->db->list_fields('person_attribute_definitions') as $field)
{
$item_obj->$field = '';
}
return $item_obj;
}
}
/*
Performs a search on person_attribute definitions
*/
public function search($search, $rows = 0, $limit_from = 0, $sort = 'definition.definition_name', $order = 'asc')
{
$this->db->select('parent_definition.definition_name AS definition_group, definition.*');
$this->db->from('person_attribute_definitions AS definition');
$this->db->join('person_attribute_definitions AS parent_definition', 'parent_definition.definition_id = definition.definition_fk', 'left');
$this->db->group_start();
$this->db->like('definition.definition_name', $search);
$this->db->or_like('definition.definition_type', $search);
$this->db->group_end();
$this->db->where('definition.deleted', 0);
$this->db->order_by($sort, $order);
if($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
public function get_person_attributes_by_person($person_id)
{
$this->db->from('person_attribute_definitions');
$this->db->join('person_attribute_links', 'person_attribute_links.definition_id = person_attribute_definitions.definition_id');
$this->db->where('person_id', $person_id);
$this->db->where('deleted', 0);
$this->db->order_by('definition_name','ASC');
$results = $this->db->get()->result_array();
return $this->_to_array($results, 'definition_id');
}
public function get_values_by_definitions($definition_ids)
{
if(count($definition_ids ? : []))
{
$this->db->from('person_attribute_definitions');
$this->db->group_start();
$this->db->where_in('definition_fk', array_keys($definition_ids));
$this->db->or_where_in('definition_id', array_keys($definition_ids));
$this->db->where('definition_type !=', GROUP);
$this->db->group_end();
$this->db->where('deleted', 0);
$results = $this->db->get()->result_array();
return $this->_to_array($results, 'definition_id');
}
return array();
}
public function get_definitions_by_type($person_attribute_type, $definition_id = NO_DEFINITION_ID)
{
$this->db->from('person_attribute_definitions');
$this->db->where('definition_type', $person_attribute_type);
$this->db->where('deleted', 0);
if($definition_id != CATEGORY_DEFINITION_ID)
{
$this->db->where('definition_id != ', $definition_id);
}
$this->db->where('definition_fk');
$results = $this->db->get()->result_array();
return $this->_to_array($results, 'definition_id', 'definition_name');
}
public function get_definitions_by_flags($definition_flags)
{
$this->db->from('person_attribute_definitions');
$this->db->where('definition_flags &', $definition_flags);
$this->db->where('deleted', 0);
$this->db->where('definition_type <>', GROUP);
$this->db->order_by('definition_id');
$results = $this->db->get()->result_array();
return $this->_to_array($results, 'definition_id', 'definition_name');
}
/**
* Returns an array of person_attribute definition names and IDs
*
* @param boolean $groups If FALSE does not return GROUP type person_attributes in the array
* @return array Array containing definition IDs, person_attribute names and -1 index with the local language '[SELECT]' line.
*/
public function get_definition_names($groups = TRUE)
{
$this->db->from('person_attribute_definitions');
$this->db->where('deleted', 0);
$this->db->order_by('definition_name','ASC');
if($groups === FALSE)
{
$this->db->where_not_in('definition_type',GROUP);
}
$results = $this->db->get()->result_array();
$definition_name = array(-1 => $this->lang->line('common_none_selected_text'));
return $definition_name + $this->_to_array($results, 'definition_id', 'definition_name');
}
public function get_definition_values($definition_id)
{
$person_attribute_values = [];
if($definition_id > 0 || $definition_id == CATEGORY_DEFINITION_ID)
{
$this->db->from('person_attribute_links');
$this->db->join('person_attribute_values', 'person_attribute_values.person_attribute_id = person_attribute_links.person_attribute_id');
$this->db->where('definition_id', $definition_id);
$this->db->where('person_id');
$this->db->order_by('person_attribute_value','ASC');
$results = $this->db->get()->result_array();
return $this->_to_array($results, 'person_attribute_id', 'person_attribute_value');
}
return $person_attribute_values;
}
private function _to_array($results, $key, $value = '')
{
return array_column(array_map(function($result) use ($key, $value) {
return [$result[$key], empty($value) ? $result : $result[$value]];
}, $results), 1, 0);
}
/*
Gets total of rows
*/
public function get_total_rows()
{
$this->db->from('person_attribute_definitions');
$this->db->where('deleted', 0);
return $this->db->count_all_results();
}
/*
Get number of rows
*/
public function get_found_rows($search)
{
return $this->search($search)->num_rows();
}
private function check_data_validity($definition, $from, $to)
{
$success = FALSE;
if($from === TEXT)
{
$this->db->select('person_id,person_attribute_value');
$this->db->from('person_attribute_values');
$this->db->join('person_attribute_links', 'person_attribute_values.person_attribute_id = person_attribute_links.person_attribute_id');
$this->db->where('definition_id',$definition);
$success = TRUE;
if($to === DATE)
{
foreach($this->db->get()->result_array() as $row)
{
if(valid_date($row['person_attribute_value']) === FALSE)
{
log_message('ERROR', 'person_id: ' . $row['person_id'] . ' with person_attribute_value: ' . $row['person_attribute_value'] . ' cannot be converted to datetime');
$success = FALSE;
}
}
}
else if($to === DECIMAL)
{
foreach($this->db->get()->result_array() as $row)
{
if(valid_decimal($row['person_attribute_value']) === FALSE)
{
log_message('ERROR', 'person_id: ' . $row['person_id'] . ' with person_attribute_value: ' . $row['person_attribute_value'] . ' cannot be converted to decimal');
$success = FALSE;
}
}
}
}
return $success;
}
private function convert_definition_type($definition_id, $from_type, $to_type)
{
$success = FALSE;
//From TEXT
if($from_type === TEXT)
{
//To DATETIME or DECIMAL
if(in_array($to_type, [DATE, DECIMAL], TRUE))
{
$field = ($to_type === DATE ? 'person_attribute_date' : 'person_attribute_decimal');
if($this->check_data_validity($definition_id, $from_type, $to_type))
{
$this->db->trans_start();
$query = 'UPDATE ospos_person_attribute_values ';
$query .= 'INNER JOIN ospos_person_attribute_links ';
$query .= 'ON ospos_person_attribute_values.person_attribute_id = ospos_person_attribute_links.person_attribute_id ';
$query .= 'SET '. $field .'= person_attribute_value, ';
$query .= 'person_attribute_value = NULL ';
$query .= 'WHERE definition_id = ' . $this->db->escape($definition_id);
$success = $this->db->query($query);
$this->db->trans_complete();
}
}
//To DROPDOWN or CHECKBOX
else if($to_type === DROPDOWN)
{
$success = TRUE;
}
else if($to_type === CHECKBOX)
{
$checkbox_person_attribute_values = $this->checkbox_person_attribute_values($definition_id);
$this->db->trans_start();
$query = 'UPDATE ospos_person_attribute_values values ';
$query .= 'INNER JOIN ospos_person_attribute_links links ';
$query .= 'ON values.person_attribute_id = links.person_attribute_id ';
$query .= "SET links.person_attribute_id = IF((values.person_attribute_value IN('FALSE','0','') OR (values.person_attribute_value IS NULL)), $checkbox_person_attribute_values[0], $checkbox_person_attribute_values[1]) ";
$query .= 'WHERE definition_id = ' . $this->db->escape($definition_id);
$success = $this->db->query($query);
$this->db->trans_complete();
}
}
//From DROPDOWN
else if($from_type === DROPDOWN)
{
//To TEXT
if(in_array($to_type, [TEXT, CHECKBOX], TRUE))
{
$this->db->trans_start();
$this->db->from('ospos_person_attribute_links');
$this->db->where('definition_id',$definition_id);
$this->db->where('person_id', NULL);
$success = $this->db->delete();
$this->db->trans_complete();
//To CHECKBOX
if($to_type === CHECKBOX)
{
$checkbox_person_attribute_values = $this->checkbox_person_attribute_values($definition_id);
$this->db->trans_start();
$query = 'UPDATE ospos_person_attribute_values vals ';
$query .= 'INNER JOIN ospos_person_attribute_links links ';
$query .= 'ON vals.person_attribute_id = links.person_attribute_id ';
$query .= "SET links.person_attribute_id = IF((vals.person_attribute_value IN('FALSE','0','') OR (vals.person_attribute_value IS NULL)), $checkbox_person_attribute_values[0], $checkbox_person_attribute_values[1]) ";
$query .= 'WHERE links.definition_id = ' . $this->db->escape($definition_id);
$success = $this->db->query($query);
$this->db->trans_complete();
}
}
}
//From any other type
else
{
$success = TRUE;
}
return $success;
}
private function checkbox_person_attribute_values($definition_id)
{
$zero_person_attribute_id = $this->value_exists('0');
$one_person_attribute_id = $this->value_exists('1');
if($zero_person_attribute_id === FALSE)
{
$zero_person_attribute_id = $this->save_value('0', $definition_id, FALSE, FALSE, CHECKBOX);
}
if($one_person_attribute_id === FALSE)
{
$one_person_attribute_id = $this->save_value('1', $definition_id, FALSE, FALSE, CHECKBOX);
}
return array($zero_person_attribute_id, $one_person_attribute_id);
}
/*
Inserts or updates a definition
*/
public function save_definition(&$definition_data, $definition_id = NO_DEFINITION_ID)
{
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
//Definition doesn't exist
if($definition_id === NO_DEFINITION_ID || !$this->exists($definition_id))
{
if($this->exists($definition_id,TRUE))
{
$success = $this->undelete($definition_id);
}
else
{
$success = $this->db->insert('person_attribute_definitions', $definition_data);
$definition_data['definition_id'] = $this->db->insert_id();
}
}
//Definition already exists
else
{
$this->db->select('definition_type, definition_name');
$this->db->from('person_attribute_definitions');
$this->db->where('definition_id', $definition_id);
$row = $this->db->get()->row();
$from_definition_type = $row->definition_type;
$from_definition_name = $row->definition_name;
$to_definition_type = $definition_data['definition_type'];
if($from_definition_type !== $to_definition_type)
{
if(!$this->convert_definition_type($definition_id,$from_definition_type,$to_definition_type))
{
return FALSE;
}
}
$this->db->where('definition_id', $definition_id);
$success = $this->db->update('person_attribute_definitions', $definition_data);
$definition_data['definition_id'] = $definition_id;
}
$this->db->trans_complete();
$success &= $this->db->trans_status();
return $success;
}
public function get_definition_by_name($definition_name, $definition_type = FALSE)
{
$this->db->from('person_attribute_definitions');
$this->db->where('definition_name', $definition_name);
if($definition_type != FALSE)
{
$this->db->where('definition_type', $definition_type);
}
return $this->db->get()->result_array();
}
public function save_link($person_id, $definition_id, $person_attribute_id)
{
$this->db->trans_start();
if($this->link_exists($person_id, $definition_id))
{
$this->db->where('definition_id', $definition_id);
$this->db->where('person_id', $person_id);
$this->db->update('person_attribute_links', array('person_attribute_id' => $person_attribute_id));
}
else
{
$this->db->insert('person_attribute_links', array('person_attribute_id' => $person_attribute_id, 'person_id' => $person_id, 'definition_id' => $definition_id));
}
$this->db->trans_complete();
return $this->db->trans_status();
}
public function delete_link($person_id)
{
return $this->db->delete('person_attribute_links', array('person_id' => $person_id));
}
public function get_link_value($person_id, $definition_id)
{
$this->db->where('person_id', $person_id);
$this->db->where('definition_id', $definition_id);
return $this->db->get('person_attribute_links')->row_object();
}
public function get_link_values($person_id, $definition_flags)
{
$format = $this->db->escape(dateformat_mysql());
$this->db->select("GROUP_CONCAT(person_attribute_value SEPARATOR ', ') AS person_attribute_values");
$this->db->select("GROUP_CONCAT(DATE_FORMAT(person_attribute_date, $format) SEPARATOR ', ') AS person_attribute_dtvalues");
$this->db->from('person_attribute_links');
$this->db->join('person_attribute_values', 'person_attribute_values.person_attribute_id = person_attribute_links.person_attribute_id');
$this->db->join('person_attribute_definitions', 'person_attribute_definitions.definition_id = person_attribute_links.definition_id');
$this->db->where('definition_type <>', GROUP);
$this->db->where('deleted', 0);
// if(!empty($id))
// {
// $this->db->where($sale_receiving_fk, $id);
// }
// else
// {
// $this->db->where('sale_id');
// $this->db->where('receiving_id');
// }
$this->db->where('person_id', (int) $person_id);
$this->db->where('definition_flags & ', $definition_flags);
return $this->db->get();
}
public function get_person_attribute_value($person_id, $definition_id)
{
$this->db->from('person_attribute_values');
$this->db->join('person_attribute_links', 'person_attribute_links.person_attribute_id = person_attribute_values.person_attribute_id');
$this->db->where('definition_id', $definition_id);
$this->db->where('person_id', (int) $person_id);
return $this->db->get()->row_object();
}
public function copy_person_attribute_links($person_id, $id)
{
$this->db->query(
'INSERT INTO ospos_person_attribute_links (person_id, definition_id, person_attribute_id)
SELECT ' . $this->db->escape($person_id) . ', definition_id, person_attribute_id, ' . $this->db->escape($id) . '
FROM ' . $this->db->dbprefix('person_attribute_links') . '
WHERE person_id = ' . $this->db->escape($person_id)
);
}
public function get_suggestions($definition_id, $term)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('person_attribute_value, person_attribute_values.person_attribute_id');
$this->db->from('person_attribute_definitions AS definition');
$this->db->join('person_attribute_links', 'person_attribute_links.definition_id = definition.definition_id');
$this->db->join('person_attribute_values', 'person_attribute_values.person_attribute_id = person_attribute_links.person_attribute_id');
$this->db->like('person_attribute_value', $term);
$this->db->where('deleted', 0);
$this->db->where('definition.definition_id', $definition_id);
$this->db->order_by('person_attribute_value','ASC');
foreach($this->db->get()->result() as $row)
{
$row_array = (array) $row;
$suggestions[] = array('value' => $row_array['person_attribute_id'], 'label' => $row_array['person_attribute_value']);
}
return $suggestions;
}
public function save_value($person_attribute_value, $definition_id, $person_id = FALSE, $person_attribute_id = FALSE, $definition_type = DROPDOWN)
{
$this->db->trans_start();
//New Person_attribute
if(empty($person_attribute_id) || empty($person_id))
{
if(in_array($definition_type, [TEXT, DROPDOWN, CHECKBOX], TRUE))
{
$person_attribute_id = $this->value_exists($person_attribute_value);
if(empty($person_attribute_id))
{
$this->db->insert('person_attribute_values', array('person_attribute_value' => $person_attribute_value));
}
}
else if($definition_type == DECIMAL)
{
$this->db->insert('person_attribute_values', array('person_attribute_decimal' => $person_attribute_value));
}
else
{
$this->db->insert('person_attribute_values', array('person_attribute_date' => date('Y-m-d', strtotime($person_attribute_value))));
}
$person_attribute_id = $person_attribute_id ? $person_attribute_id : $this->db->insert_id();
$this->db->insert('person_attribute_links', array(
'person_attribute_id' => empty($person_attribute_id) ? NULL : $person_attribute_id,
'person_id' => empty($person_id) ? NULL : $person_id,
'definition_id' => $definition_id));
}
//Existing Person_attribute
else
{
$this->db->where('person_attribute_id', $person_attribute_id);
if(in_array($definition_type, [TEXT, DROPDOWN], TRUE))
{
$this->db->update('person_attribute_values', array('person_attribute_value' => $person_attribute_value));
}
else if($definition_type == DECIMAL)
{
$this->db->update('person_attribute_values', array('person_attribute_decimal' => $person_attribute_value));
}
else
{
$this->db->update('person_attribute_values', array('person_attribute_date' => date('Y-m-d', strtotime($person_attribute_value))));
}
}
$this->db->trans_complete();
return $person_attribute_id;
}
public function delete_value($person_attribute_value, $definition_id)
{
return $this->db->query("DELETE atrv, atrl FROM " . $this->db->dbprefix('person_attribute_values') . " atrv, " . $this->db->dbprefix('person_attribute_links') . " atrl " .
"WHERE atrl.person_attribute_id = atrv.person_attribute_id AND atrv.person_attribute_value = " . $this->db->escape($person_attribute_value) . " AND atrl.definition_id = " . $this->db->escape($definition_id));
}
/**
* Deletes an Person_attribute definition from the database and associated column in the customer_import.csv
*
* @param unknown $definition_id Person_attribute definition ID to remove.
* @return boolean TRUE if successful and FALSE if there is a failure
*/
public function delete_definition($definition_id)
{
$this->db->where('definition_id', $definition_id);
return $this->db->update('person_attribute_definitions', array('deleted' => 1));
}
public function delete_definition_list($definition_ids)
{
$this->db->where_in('definition_id', $definition_ids);
return $this->db->update('person_attribute_definitions', array('deleted' => 1));
}
/*
Undeletes one person_attribute definition
*/
public function undelete($definition_id)
{
$this->db->where('definition_id', $definition_id);
return $this->db->update('person_attribute_definitions', array('deleted'=>0));
}
}

View File

@@ -1,6 +1,6 @@
<ul id="error_message_box" class="error_message_box"></ul>
<?php echo form_open_multipart('customers/do_csv_import/', array('id'=>'csv_form', 'class'=>'form-horizontal')); ?>
<?php echo form_open_multipart('customers/do_csv_file/', array('id'=>'csv_form', 'class'=>'form-horizontal')); ?>
<fieldset id="item_basic_info">
<div class="form-group form-group-sm">
<div class="col-xs-12">

View File

@@ -149,6 +149,12 @@
</div>
</div>
<div id="person_attributes">
<script type="text/javascript">
$('#person_attributes').load('<?php echo site_url($controller_name . "/person_attributes/$person_info->person_id");?>');
</script>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('common_comments'), 'comments', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-8'>

View File

@@ -0,0 +1,243 @@
<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box" class="error_message_box"></ul>
<?php echo form_open('person_attributes/save_definition/'.$definition_id, array('id'=>'person_attribute_form', 'class'=>'form-horizontal')); ?>
<fieldset id="person_attribute_basic_info">
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('person_attributes_definition_name'), 'definition_name', array('class'=>'required control-label col-xs-3')); ?>
<div class='col-xs-8'>
<?php echo form_input(array(
'name'=>'definition_name',
'id' => 'definition_name',
'class'=>'form-control input-sm',
'value'=>$definition_info->definition_name)
);?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('person_attributes_definition_type'), 'definition_type', array('class'=>'required control-label col-xs-3')); ?>
<div class='col-xs-8'>
<?php echo form_dropdown('definition_type', DEFINITION_TYPES, array_search($definition_info->definition_type, DEFINITION_TYPES), 'id="definition_type" class="form-control"');?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('person_attributes_definition_group'), 'definition_group', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<?php echo form_dropdown('definition_group', $definition_group, $definition_info->definition_fk, 'id="definition_group" class="form-control" ' . (empty($definition_group) ? 'disabled="disabled"' : ''));?>
</div>
</div>
<div class="form-group form-group-sm hidden">
<?php echo form_label($this->lang->line('person_attributes_definition_flags'), 'definition_flags', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<div class="input-group">
<?php echo form_multiselect('definition_flags[]', $definition_flags, array_keys($selected_definition_flags), array('id'=>'definition_flags', 'class'=>'selectpicker show-menu-arrow', 'data-none-selected-text'=>$this->lang->line('common_none_selected_text'), 'data-selected-text-format'=>'count > 1', 'data-style'=>'btn-default btn-sm', 'data-width'=>'fit')); ?>
</div>
</div>
</div>
<div class="form-group form-group-sm hidden">
<?php echo form_label($this->lang->line('person_attributes_definition_unit'), 'definition_units', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<div class="input-group">
<?php echo form_input(array('name'=>'definition_unit', 'value'=>$definition_info->definition_unit,'class'=>'form-control input-sm', 'id' => 'definition_unit'));?>
</div>
</div>
</div>
<div class="form-group form-group-sm hidden">
<?php echo form_label($this->lang->line('person_attributes_definition_values'), 'definition_value', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<div class="input-group">
<?php echo form_input(array('name'=>'definition_value', 'class'=>'form-control input-sm', 'id' => 'definition_value'));?>
<span id="add_person_attribute_value" class="input-group-addon input-sm btn btn-default">
<span class="glyphicon glyphicon-plus-sign"></span>
</span>
</div>
</div>
</div>
<div class="form-group form-group-sm hidden">
<?php echo form_label('&nbsp', 'definition_list_group', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<ul id="definition_list_group" class="list-group"></ul>
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<script type="text/javascript">
//validation and submit handling
$(document).ready(function()
{
var values = [];
var definition_id = <?php echo $definition_id; ?>;
var is_new = definition_id == 0;
var disable_definition_types = function()
{
var definition_type = $("#definition_type option:selected").text();
if(definition_type == "DATE" || (definition_type == "GROUP" && !is_new) || definition_type == "DECIMAL")
{
$('#definition_type').prop("disabled",true);
}
else if(definition_type == "DROPDOWN" || definition_type == "CHECKBOX")
{
$("#definition_type option:contains('GROUP')").hide();
$("#definition_type option:contains('DATE')").hide();
$("#definition_type option:contains('DECIMAL')").hide();
}
else
{
$("#definition_type option:contains('GROUP')").hide();
}
}
disable_definition_types();
var disable_category_dropdown = function()
{
if(definition_id == -1)
{
$('#definition_name').prop("disabled",true);
$('#definition_type').prop("disabled",true);
$('#definition_group').parents('.form-group').toggleClass("hidden", true);
$('#definition_flags').parents('.form-group').toggleClass('hidden', true);
}
}
disable_category_dropdown();
var show_hide_fields = function(event)
{
var is_dropdown = $('#definition_type').val() !== '1';
var is_decimal = $('#definition_type').val() !== '2';
var is_no_group = $('#definition_type').val() !== '0';
var is_category_dropdown = definition_id == -1;
$('#definition_value, #definition_list_group').parents('.form-group').toggleClass('hidden', is_dropdown);
$('#definition_unit').parents('.form-group').toggleClass('hidden', is_decimal);
//Appropriately show definition flags if not category_dropdown
if(definition_id != -1)
{
$('#definition_flags').parents('.form-group').toggleClass('hidden', !is_no_group);
}
};
$('#definition_type').change(show_hide_fields);
show_hide_fields();
$('.selectpicker').each(function () {
var $selectpicker = $(this);
$.fn.selectpicker.call($selectpicker, $selectpicker.data());
});
var remove_person_attribute_value = function()
{
var value = $(this).parents("li").text();
if (is_new)
{
values.splice($.inArray(value, values), 1);
}
else
{
$.post('<?php echo site_url($controller_name . "/delete_person_attribute_value/");?>' + escape(value), {definition_id: definition_id});
}
$(this).parents("li").remove();
};
var add_person_attribute_value = function(value)
{
var is_event = typeof(value) !== 'string';
if ($("#definition_value").val().match(/(\||_)/g) != null)
{
return;
}
if (is_event)
{
value = $('#definition_value').val();
if (!value)
{
return;
}
if (is_new)
{
values.push(value);
}
else
{
$.post('<?php echo site_url("person_attributes/save_person_attribute_value/");?>' + escape(value), {definition_id: definition_id});
}
}
$('#definition_list_group').append("<li class='list-group-item'>" + value + "<a href='javascript:void(0);'><span class='glyphicon glyphicon-trash pull-right'></span></a></li>")
.find(':last-child a').click(remove_person_attribute_value);
$('#definition_value').val('');
};
$('#add_person_attribute_value').click(add_person_attribute_value);
$('#definition_value').keypress(function (e) {
if (e.which == 13) {
add_person_attribute_value();
return false;
}
});
var definition_values = <?php echo json_encode(array_values($definition_values)) ?>;
$.each(definition_values, function(index, element) {
add_person_attribute_value(element);
});
$.validator.addMethod('valid_chars', function(value, element) {
return value.match(/(\||_)/g) == null;
}, "<?php echo $this->lang->line('person_attributes_person_attribute_value_invalid_chars'); ?>");
$('form').bind('submit', function () {
$(this).find(':input').prop('disabled', false);
});
$('#person_attribute_form').validate($.extend({
submitHandler: function(form)
{
$(form).ajaxSubmit({
beforeSerialize: function($form, options) {
is_new && $('<input>').attr({
id: 'definition_values',
type: 'hidden',
name: 'definition_values',
value: JSON.stringify(values)
}).appendTo($form);
},
success: function(response)
{
dialog_support.hide();
table_support.handle_submit('<?php echo site_url($controller_name); ?>', response);
},
dataType: 'json'
});
},
rules:
{
definition_name: 'required',
definition_value: 'valid_chars',
definition_type: 'required'
},
messages:
{
definition_name: "<?php echo $this->lang->line('person_attributes_definition_name_required'); ?>",
definition_type: "<?php echo $this->lang->line('person_attributes_definition_type_required'); ?>"
}
}, form_support.error));
});
</script>

View File

@@ -0,0 +1,37 @@
<?php $this->load->view("partial/header"); ?>
<script type="text/javascript">
$(document).ready(function()
{
<?php $this->load->view('partial/bootstrap_tables_locale'); ?>
table_support.init({
resource: '<?php echo site_url($controller_name);?>',
headers: <?php echo $table_headers; ?>,
pageSize: <?php echo $this->config->item('lines_per_page'); ?>,
uniqueId: 'definition_id'
});
});
</script>
<div id="title_bar" class="btn-toolbar print_hide">
<button class='btn btn-info btn-sm pull-right modal-dlg' data-btn-submit='<?php echo $this->lang->line('common_submit') ?>' data-href='<?php echo site_url($controller_name."/view"); ?>'
title='<?php echo $this->lang->line($controller_name . '_new'); ?>'>
<span class="glyphicon glyphicon-star">&nbsp</span><?php echo $this->lang->line($controller_name. '_new'); ?>
</button>
</div>
<div id="toolbar">
<div class="pull-left form-inline" role="toolbar">
<button id="delete" class="btn btn-default btn-sm print_hide">
<span class="glyphicon glyphicon-trash">&nbsp</span><?php echo $this->lang->line("common_delete"); ?>
</button>
</div>
</div>
<div id="table_holder">
<table id="table"></table>
</div>
<?php $this->load->view("partial/footer"); ?>

View File

@@ -0,0 +1,129 @@
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line("person_attributes_definition_name"), "definition_name_label", array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<?php echo form_dropdown('definition_name', $definition_names, -1, array('id' => 'definition_name', 'class' => 'form-control')); ?>
</div>
</div>
<?php
foreach($definition_values as $definition_id => $definition_value)
{
?>
<div class="form-group form-group-sm">
<?php echo form_label($definition_value['definition_name'], $definition_value['definition_name'], array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<div class="input-group">
<?php
echo form_hidden("person_attribute_ids[$definition_id]", $definition_value['person_attribute_id']);
$person_attribute_value = $definition_value['person_attribute_value'];
if ($definition_value['definition_type'] == DATE)
{
$value = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_date)) ? NOW : strtotime($person_attribute_value->person_attribute_date);
echo form_input(array(
'name' => "person_attribute_links[$definition_id]",
'value' => to_date($value),
'class' => 'form-control input-sm datetime',
'data-definition-id' => $definition_id,
'readonly' => 'true'));
}
else if ($definition_value['definition_type'] == DROPDOWN)
{
$selected_value = $definition_value['selected_value'];
echo form_dropdown("person_attribute_links[$definition_id]", $definition_value['values'], $selected_value, "class='form-control' data-definition-id='$definition_id'");
}
else if ($definition_value['definition_type'] == TEXT)
{
$value = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_value)) ? $definition_value['selected_value'] : $person_attribute_value->person_attribute_value;
echo form_input("person_attribute_links[$definition_id]", $value, "class='form-control valid_chars' data-definition-id='$definition_id'");
}
else if ($definition_value['definition_type'] == DECIMAL)
{
$value = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_decimal)) ? $definition_value['selected_value'] : $person_attribute_value->person_attribute_decimal;
echo form_input("person_attribute_links[$definition_id]", $value, "class='form-control valid_chars' data-definition-id='$definition_id'");
}
else if ($definition_value['definition_type'] == CHECKBOX)
{
$value = (empty($person_attribute_value) || empty($person_attribute_value->person_attribute_value)) ? $definition_value['selected_value'] : $person_attribute_value->person_attribute_value;
//Sends 0 if the box is unchecked instead of not sending anything.
echo form_input(array(
'type' => 'hidden',
'name' => "person_attribute_links[$definition_id]",
'id' => "person_attribute_links[$definition_id]",
'value' => 0,
'data-definition-id' => $definition_id
));
echo form_checkbox(array(
'name' => "person_attribute_links[$definition_id]",
'id' => "person_attribute_links[$definition_id]",
'value' => 1,
'checked' => ($value ? 1 : 0),
'class' => 'checkbox-inline',
'data-definition-id' => $definition_id
));
}
?>
<span class="input-group-addon input-sm btn btn-default remove_person_attribute_btn"><span class="glyphicon glyphicon-trash"></span></span>
</div>
</div>
</div>
<?php
}
?>
<script type="text/javascript">
(function() {
<?php $this->load->view('partial/datepicker_locale', array('config' => '{ minView: 2, format: "'.dateformat_bootstrap($this->config->item('dateformat') . '"}'))); ?>
var enable_delete = function() {
$('.remove_person_attribute_btn').click(function() {
$(this).parents('.form-group').remove();
});
};
enable_delete();
$("input[name*='person_attribute_links']").change(function() {
var definition_id = $(this).data('definition-id');
$("input[name='person_attribute_ids[" + definition_id + "]']").val('');
}).autocomplete({
source: function(request, response) {
$.get('<?php echo site_url('person_attributes/suggest_person_attribute/');?>' + this.element.data('definition-id') + '?term=' + request.term, function(data) {
return response(data);
}, 'json');
},
appendTo: '.modal-content',
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
},
delay: 10
});
var definition_values = function() {
var result = {};
$("[name*='person_attribute_links'").each(function() {
var definition_id = $(this).data('definition-id');
result[definition_id] = $(this).val();
});
return result;
};
var refresh = function() {
var definition_id = $("#definition_name option:selected").val();
var person_attribute_values = definition_values();
person_attribute_values[definition_id] = '';
$('#person_attributes').load('<?php echo site_url($controller_name . "/person_attributes/$person_id");?>', {
'definition_ids': JSON.stringify(person_attribute_values)
}, enable_delete);
};
$('#definition_name').change(function() {
refresh();
});
})();
</script>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB