db->from('custom_fields');
$CI->db->where('belong_to', $belongs_to);
$CI->db->order_by('custom_fields.belong_to', 'asc');
$CI->db->order_by('custom_fields.weight', 'asc');
$query = $CI->db->get();
$result = $query->result_array();
$fields_html = '';
foreach ($result as $result_key => $field) {
$type = $field['type'];
$label = ucfirst($field['name']);
$field_name = 'custom_fields[' . $field['belong_to'] . '][' . $field['id'] . ']';
if ($field['bs_column'] == '' || $field['bs_column'] == 0) {
$field['bs_column'] = 12;
}
$input_class = "";
$value = "";
if ($rel_id !== false) {
$return_value = get_custom_field_value($rel_id, $field['id'], $belongs_to);
if (!empty($return_value)) {
$value = $return_value->field_value;
}
}
$fields_html .= '
';
if ($field['type'] == 'input' || $field['type'] == 'number') {
$type = $field['type'] == 'input' ? 'text' : 'number';
$fields_html .= render_input_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'textarea') {
$fields_html .= render_textarea_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'select') {
$options = optionSplit($field['field_values']);
$fields_html .= render_select_field($field_name, $options, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'multiselect') {
$options = optionSplit($field['field_values']);
$fields_html .= render_multiselect_field($field_name, $options, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'checkbox') {
$options = optionSplit($field['field_values']);
$fields_html .= render_checkbox_field($field_name, $options, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'date_picker') {
$type = $field['type'];
$fields_html .= render_date_picker_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'date_picker_time') {
$type = $field['type'];
$fields_html .= render_date_picker_time_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'colorpicker') {
$type = $field['type'];
$fields_html .= render_colorpicker_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'link') {
$type = $field['type'];
$fields_html .= render_link_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
}
$fields_html .= '
';
}
return $fields_html;
}
function display_admission_custom_fields($belongs_to, $rel_id = false, $where = array())
{
$CI = &get_instance();
$CI->db->from('custom_fields');
$CI->db->where('belong_to', $belongs_to);
$CI->db->order_by('custom_fields.belong_to', 'asc');
$CI->db->order_by('custom_fields.weight', 'asc');
$query = $CI->db->get();
$result = $query->result_array();
$fields_html = '';
foreach ($result as $result_key => $field) {
$type = $field['type'];
$label = ucfirst($field['name']);
if($CI->customlib->getfieldstatus($field['name']))
{
$field_name = 'custom_fields[' . $field['belong_to'] . '][' . $field['id'] . ']';
if ($field['bs_column'] == '' || $field['bs_column'] == 0) {
$field['bs_column'] = 12;
}
$input_class = "";
$value = "";
if ($rel_id !== false) {
$return_value = get_custom_field_value($rel_id, $field['id'], $belongs_to);
if (!empty($return_value)) {
$value = $return_value->field_value;
}
}
$fields_html .= '';
if ($field['type'] == 'input' || $field['type'] == 'number') {
$type = $field['type'] == 'input' ? 'text' : 'number';
$fields_html .= render_input_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'textarea') {
$fields_html .= render_textarea_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'select') {
$options = optionSplit($field['field_values']);
$fields_html .= render_select_field($field_name, $options, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'multiselect') {
$options = optionSplit($field['field_values']);
$fields_html .= render_multiselect_field($field_name, $options, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'checkbox') {
$options = optionSplit($field['field_values']);
$fields_html .= render_checkbox_field($field_name, $options, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'date_picker') {
$type = $field['type'];
$fields_html .= render_date_picker_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'date_picker_time') {
$type = $field['type'];
$fields_html .= render_date_picker_time_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'colorpicker') {
$type = $field['type'];
$fields_html .= render_colorpicker_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
} elseif ($field['type'] == 'link') {
$type = $field['type'];
$fields_html .= render_link_field($field_name, $field['belong_to'], $field['id'], $field['validation'], $label, $value, $type, $input_class);
}
$fields_html .= '
';
}
}
return $fields_html;
}
function render_input_field($name, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (isset($_POST['custom_fields'][$belong_to][$field_id])) {
$value = $_POST['custom_fields'][$belong_to][$field_id];
}
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_textarea_field($name, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (isset($_POST['custom_fields'][$belong_to][$field_id])) {
$value = $_POST['custom_fields'][$belong_to][$field_id];
}
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_select_field($name, $options, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_multiselect_field($name, $options, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_checkbox_field($name, $options, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
return $input;
}
function render_date_picker_field($name, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (isset($_POST['custom_fields'][$belong_to][$field_id])) {
$value = $_POST['custom_fields'][$belong_to][$field_id];
}
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_date_picker_time_field($name, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (isset($_POST['custom_fields'][$belong_to][$field_id])) {
$value = $_POST['custom_fields'][$belong_to][$field_id];
}
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_colorpicker_field($name, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (isset($_POST['custom_fields'][$belong_to][$field_id])) {
$value = $_POST['custom_fields'][$belong_to][$field_id];
}
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function render_link_field($name, $belong_to, $field_id, $validation, $label = '', $value = '', $type = 'text', $input_class = '')
{
$input = '';
$_form_group_attr = '';
$_input_attrs = '';
if (isset($_POST['custom_fields'][$belong_to][$field_id])) {
$value = $_POST['custom_fields'][$belong_to][$field_id];
}
if (!empty($input_class)) {
$input_class = ' ' . $input_class;
}
$input .= '';
if ($label != '') {
$input .= '';
}
if ($validation) {
$input .= " *";
}
$input .= '';
$input .= '' . form_error($name) . '';
$input .= '
';
return $input;
}
function get_custom_field_value($rel_id, $field_id, $belongs_to)
{
$CI = &get_instance();
$sql = 'SELECT * FROM `custom_fields` INNER JOIN custom_field_values on custom_field_values.belong_table_id=' . $CI->db->escape($rel_id) . ' and custom_field_values.custom_field_id=custom_fields.id WHERE belong_to =' . $CI->db->escape($belongs_to) . ' and custom_field_values.custom_field_id=' . $CI->db->escape($field_id);
$query = $CI->db->query($sql);
return $query->row();
}
function optionSplit($values)
{
return explode(',', $values);
}
function removeBreak($option_value)
{
return preg_replace('/
\\s*$/', '', $option_value);
}
function get_custom_table_values($table_id, $belongs_to)
{
$CI = &get_instance();
$sql = 'SELECT custom_field_values.*,custom_fields.name,custom_fields.type,custom_fields.belong_to FROM `custom_field_values` RIGHT JOIN custom_fields on custom_fields.id=custom_field_values.custom_field_id and belong_table_id=' . $CI->db->escape($table_id) . ' WHERE custom_fields.belong_to=' . $CI->db->escape($belongs_to) . ' ORDER by custom_fields.weight asc';
$query = $CI->db->query($sql);
return $query->result();
}
function get_custom_print_table_values($table_id, $belongs_to)
{
$CI = &get_instance();
$sql = 'SELECT custom_field_values.*,custom_fields.name,custom_fields.type,custom_fields.belong_to FROM `custom_field_values` RIGHT JOIN custom_fields on custom_fields.id=custom_field_values.custom_field_id and belong_table_id=' . $CI->db->escape($table_id) . ' WHERE custom_fields.belong_to=' . $CI->db->escape($belongs_to) . ' AND custom_fields.visible_on_table=1 ORDER by custom_fields.weight asc';
$query = $CI->db->query($sql);
return $query->result();
}
function get_custom_fields($belongs_to)
{
$CI = &get_instance();
$sql = 'SELECT custom_fields.* FROM `custom_fields` WHERE custom_fields.belong_to=' . $CI->db->escape($belongs_to) . ' ORDER by custom_fields.id asc';
$query = $CI->db->query($sql);
return $query->result();
}
function get_student_editable_fields()
{
$fields = array(
'firstname' => lang('first_name'),
'admission_date' => lang('admission_date'),
'middlename' => lang('middle_name'),
'lastname' => lang('last_name'),
'rte' => lang('rte'),
'student_photo' => lang('student')." ".lang('photo'),
'mobile_no' => lang('mobile_no'),
'student_email' => lang('email'),
'religion' => lang('religion'),
'cast' => lang('cast'),
'dob' => lang('date_of_birth'),
'is_blood_group' => lang('blood_group'),
'if_guardian_is' => lang('if_guardian_is'),
'gender' => lang('gender'),
'current_address' => lang('current_address'),
'permanent_address' => lang('permanent_address'),
'category' => lang('category'),
'bank_account_no' => lang('bank_account_no'),
'bank_name' => lang('bank_name'),
'ifsc_code' => lang('ifsc_code'),
'father_name' => lang('father_name'),
'father_phone' => lang('father_phone'),
'father_occupation' => lang('father_occupation'),
'mother_name' => lang('mother_name'),
'mother_phone' => lang('mother_phone'),
'is_student_house' => lang('house'),
'mother_occupation' => lang('mother_occupation'),
'guardian_name' => lang('guardian_name'),
'guardian_relation' => lang('guardian_relation'),
'guardian_phone' => lang('guardian_phone'),
'guardian_occupation' => lang('guardian_occupation'),
'guardian_address' => lang('guardian_address'),
'guardian_email' => lang('guardian_email'),
'national_identification_no' => lang('national_identification_no'),
'local_identification_no' => lang('local_identification_no'),
'father_pic' => lang('father') . " " . lang('photo'),
'mother_pic' => lang('mother') . " " . lang('photo'),
'guardian_pic' => lang('guardian') . " " . lang('photo'),
'student_height' => lang('height'),
'student_weight' => lang('weight'),
'previous_school_details' => lang('previous_school_details')
);
return $fields;
}
function get_captcha_editable_fields()
{
$fields = array(
'userlogin' => lang('user')." ".lang('login'),
'login' => lang('admin')." ".lang('login'),
'admission' => lang('online')." ".lang('admission'),
'complain' => lang('complain'),
'contact_us' => lang('contact_us'),
);
return $fields;
}
function get_onlineadmission_editable_fields()
{
$fields = array(
'middlename' => lang('middle_name'),
'lastname' => lang('last_name'),
'category' => lang('category'),
'religion' => lang('religion'),
'cast' => lang('cast'),
'mobile_no' => lang('mobile_no'),
'student_email' => lang('email'),
'student_photo' => lang('student')." ".lang('photo'),
'is_student_house' => lang('house'),
'is_blood_group' => lang('blood_group'),
'student_height' => lang('height'),
'student_weight' => lang('weight'),
'measurement_date' => lang('measurement_date'),
'father_name' => lang('father_name'),
'father_phone' => lang('father_phone'),
'father_occupation' => lang('father_occupation'),
'father_pic' => lang('father') . " " . lang('photo'),
'mother_name' => lang('mother_name'),
'mother_phone' => lang('mother_phone'),
'mother_occupation' => lang('mother_occupation'),
'mother_pic' => lang('mother') . " " . lang('photo'),
'if_guardian_is' => lang('if_guardian_is'),
'guardian_name' => lang('guardian_name'),
'guardian_relation' => lang('guardian_relation'),
'guardian_phone' => lang('guardian_phone'),
'guardian_email' => lang('guardian_email'),
'guardian_occupation' => lang('guardian_occupation'),
'guardian_photo' => lang('guardian')." ".lang('photo'),
'guardian_address' => lang('guardian_address'),
'current_address' => lang('if_guardian_address_is_current_address'),
'permanent_address' => lang('if_permanent_address_is_current_address'),
'bank_account_no' => lang('bank_account_no'),
'bank_name' => lang('bank_name'),
'ifsc_code' => lang('ifsc_code'),
'national_identification_no' => lang('national_identification_no'),
'local_identification_no' => lang('local_identification_no'),
'rte' => lang('rte'),
'previous_school_details' => lang('previous_school_details'),
'student_note' => lang('note')
);
return $fields;
}
}