sparqapi/api/application/controllers/Template_Management_Controller.php
2022-11-09 17:45:24 +05:30

1970 lines
85 KiB
PHP

<?php
/**
* User: velz
* This Controller deals with User Management CRUD Operations
*/
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/REST_Controller.php';
class Template_Management_Controller extends REST_Controller {
function __construct()
{
// Construct the parent class
parent::__construct();
$this->load->model('PD_Model');
$this->load->model('Template_Management_Model');
$this->load->helper('satellite_image');
$this->external_path = $this->config->item('external_data_path');
}
public function listAllTemplates_get()
{
$page = "";$limit = ""; $sort = "asc";
$result = $this->Template_Management_Model->listAllTemplates($page,$limit,$sort);
if(count($result))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Save and Update Template Name ********/
public function saveNewTemplateName_post()
{
$records = $this->post('records');
if($records['template_id'] == null || $records['template_id'] == "")
{
$template_id = $this->Template_Management_Model->saveRecords($records,TEMPLATE);
if($template_id != "" || $template_id != null)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_id;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
else
{
$where_condition_array = array('template_id'=>$records['template_id']);
$modified = $this->Template_Management_Model->updateRecords($records,TEMPLATE,$where_condition_array);
if($modified != "" || $modified != null)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $modified;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
/******** save and Edit Template Lender,Product, and Customer Segments ********/
public function saveTemplateLenderDetails_post()
{
$count = 0;
$template_lender_details = $this->post('records');
//print_r($template_lender_details);die();
foreach($template_lender_details as $template_lender_detail)
{
if($template_lender_detail['template_lender_map_id'] != null || $template_lender_detail['template_lender_map_id'] != "")
{
$where_condition_array = array('template_lender_map_id'=>$template_lender_detail['template_lender_map_id']);
$modified = $this->Template_Management_Model->updateRecords($template_lender_detail,LENDERTEMPLATE,$where_condition_array);
if($modified != "" || $modified != null){ $count++; }
}
else
{
$id = $this->Template_Management_Model->saveRecords($template_lender_detail,LENDERTEMPLATE);
if($id != "" || $id != null){ $count++; }
}
}
if($count == count($template_lender_details))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = true;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Save and Update Template Categories ********/
public function saveTemplateCategoryDetails_post()
{
$count = 0;
$template_category_details = $this->post('records');
//print_r($template_category_details);die();
foreach($template_category_details as $template_category_detail)
{
if($template_category_detail['template_category_weightage_id'] != null || $template_category_detail['template_category_weightage_id'] != "")
{
//$groups = $template_category_detail['groups'];
//unset($template_category_detail['groups']);
$where_condition_array = array('template_category_weightage_id'=>$template_category_detail['template_category_weightage_id']);
$modified = $this->Template_Management_Model->updateRecords($template_category_detail,TEMPLATECATEGORYWEIGHTAGE,$where_condition_array);
if($modified != "" || $modified != null){ $count++; }
//Groups insert/update
// foreach($groups as $group_key => $group)
// {
// if($group['template_group_id'] != null || $group['template_group_id'] != "")
// {
// $where_condition_array = array('template_group_id'=>$group['template_group_id']);
// $modified = $this->Template_Management_Model->updateRecords($group,TEMPLATEGROUP,$where_condition_array);
// }
// else
// {
// $template_group_id = $this->Template_Management_Model->saveRecords($group,TEMPLATEGROUP);
// }
// }
}
//Insert Categories
else
{
// $groups = $template_category_detail['groups'];
// unset($template_category_detail['groups']);
$id = $this->Template_Management_Model->saveRecords($template_category_detail,TEMPLATECATEGORYWEIGHTAGE);
if($id != "" || $id != null){ $count++; }
//Groups insert
// foreach($groups as $group_key => $group)
// {
// $template_group_id = $this->Template_Management_Model->saveRecords($group,TEMPLATEGROUP);
// }
}
}
if($count == count($template_category_details))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = true;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Save/update Template Question and Answers ********/
public function saveTemplateQuestionAnswers_post()
{
$question_count = 0;
$count = 0;
$template_question_answers_details = $this->post('records');
//print_r($template_question_answers_details);
foreach($template_question_answers_details as $key => $template_question_answers_detail)
{
//echo "FOr".$key;
$answers_array = array();
if($template_question_answers_detail['template_question_id'] != null || $template_question_answers_detail['template_question_id'] != "")
{
if(isset($template_question_answers_detail['answers']))
{
$answers_array = $template_question_answers_detail['answers'];
unset($template_question_answers_detail['answers']);
}
$where_condition_array = array('template_question_id' => $template_question_answers_detail['template_question_id']);
unset($template_question_answers_detail['question_id']);
unset($template_question_answers_detail['question']);
$question_modified = $this->Template_Management_Model->updateRecords($template_question_answers_detail,TEMPLATEQUESTION,$where_condition_array);
if($question_modified){$question_count++;}
if(count($answers_array))
{
foreach($answers_array as $key => $answer)
{
if($answer['template_answer_weightage_id'] != "" || $answer['template_answer_weightage_id'] != null)
{
$where_condition_array = array('template_answer_weightage_id' => $answer['template_answer_weightage_id']);
unset($answer['answer']);
$answer_modified = $this->Template_Management_Model->updateRecords($answer,TEMPLATEANSWERWEIGHTAGE,$where_condition_array);
if($answer_modified != "" || $answer_modified != null) {$count++;}
}
else
{
unset($answer['answer']);
$answer_inserted = $this->Template_Management_Model->saveRecords($answer,TEMPLATEANSWERWEIGHTAGE);
//if($answer_inserted != "" || $answer_inserted != null) {$count++;}
}
}
}
}
else
{
if(isset($template_question_answers_detail['answers']))
{
$answers_array = $template_question_answers_detail['answers'];
unset($template_question_answers_detail['answers']);
}
unset($template_question_answers_detail['question_id']);
unset($template_question_answers_detail['question']);
$question_id = $this->Template_Management_Model->saveRecords($template_question_answers_detail,TEMPLATEQUESTION);
if($question_id){$question_count++;}
if(count($answers_array))
{
foreach($answers_array as $key => $answer)
{
$answer['fk_template_question_id'] = $question_id;
unset($answer['answer']);
$answer_inserted = $this->Template_Management_Model->saveRecords($answer,TEMPLATEANSWERWEIGHTAGE);
//if($answer_inserted != "" || $answer_inserted != null) {$count++;}
}
}
}
}
if(($question_count != "" || $question_id != null) )
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = true;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Load Existed Template Master Details for Edit page @param template id ********/
public function getTemplateMaster_post()
{
$template_id = $this->post('template_id');
$template_master = $this->Template_Management_Model->getTemplateMaster($template_id);
if(count($template_master))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_master;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Load Existed Template Lender Mapping for Edit page @param template id ********/
public function getTemplateLenders_post()
{
$template_id = $this->post('template_id');
$template_lenders = $this->Template_Management_Model->getTemplateLenders($template_id);
if(count($template_lenders))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_lenders;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Load Existed Template Categories for Edit page @param template id ********/
public function getTemplateCategories_post()
{
$template_id = $this->post('template_id');
$template_categories = $this->Template_Management_Model->getTemplateCategories($template_id);
if(count($template_categories))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_categories;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/******** Load Existed Template Question and Answers for Edit page @param template id ********/
public function getTemplateQuestionAnswers_post()
{
$template_id = $this->post('template_id');
$template_questionanswers = $this->Template_Management_Model->getTemplateQuestionAnswers($template_id);
if(count($template_questionanswers))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_questionanswers;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
/************** Get List of Categories to Template Add/Edit Page DropDown ***************/
public function getListOfCategories_get()
{
$fields = array('question_category_id','category_name');
$where_condition_array = array('isactive' => 1);
$result_data = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONCATEGORY);
if(count($result_data))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function getQuestionsForTemplateCreation_post()
{
$template_id = "";$category_id = "";
if($this->post('template_id')){ $template_id = $this->post('template_id'); }
if($this->post('category_id')){ $category_id = $this->post('category_id'); }
$questions = $this->Template_Management_Model->getListOfQuestions($template_id,$category_id);
if(count($questions))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $questions;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data,REST_Controller::HTTP_OK);
}
}
//Get Categories and questions group compinations
public function getCategoryGroupCombinations_get()
{
$fields = array('question_category_id','category_name');
$where_condition_array = array('isactive' => 1);
$result_data = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONCATEGORY);
if(count($result_data))
{
foreach($result_data as $key => $result)
{
$groups = $this->Template_Management_Model->getCategoryGroupCombinations($result['question_category_id']);
$result_data[$key]['gropus'] = $groups;
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = "No Categories Found!";
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function saveScoreCardQuestions_post()
{
$records = $this->post('records');
$id = "";
$count = 0;
foreach($records as $rec_key => $record)
{
$answers = $record['answers'];
unset($record['answers']);
unset($record['question_key_mapping_id']);
unset($record['question']);
if($record['score_question_id'] != null || $record['score_question_id'] != "")
{
$where_condition_array = array('score_question_id' => $record['score_question_id']);
$id = $this->Template_Management_Model->updateRecords($record,SCORECARDQUESTIONS,$where_condition_array);
if($id != null || $id != "")
{
$count++;
foreach($answers as $ans_key => $answer)
{
unset($answer['id']);
unset($answer['name']);
if($answer['score_answer_id'] != null || $answer['score_answer_id'] != "")
{
$where_condition_array = array('score_answer_id' => $answer['score_answer_id']);
$ans_id = $this->Template_Management_Model->updateRecords($answer,SCORECARDANSWERS,$where_condition_array);
}
else
{
$answer['fk_score_question_id'] = $record['score_question_id'];
$ans_id = $this->Template_Management_Model->saveRecords($answer,SCORECARDANSWERS);
}
}
}
}
else
{
$id = $this->Template_Management_Model->saveRecords($record,SCORECARDQUESTIONS);
if($id != null || $id != "")
{
$count++;
foreach($answers as $ans_key => $answer)
{
unset($answer['id']);
unset($answer['name']);
$answer['fk_score_question_id'] = $id;
$ans_id = $this->Template_Management_Model->saveRecords($answer,SCORECARDANSWERS);
}
}
}
}
if($count == count($records))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $id;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = "Something Went Wrong!";
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function getFormAndQuestionKeys_post()
{
$records = $this->post('records');
$formid = 0;
$templateid = $records['templateid'];
$formid = $records['formid'];
$categoryid = $records['categoryid'];
//*******************INTERNAL PURPOSE***************************************************
$master_tables_field_names = $this->config->item('master_tables_field_names');
$master_tables_pkid = $this->config->item('master_tables_pkid');
//*******************INTERNAL PURPOSE***************************************************
//get Alreday assigned ques and kys from template
$fields = array('fk_key');
$where_condition_array = array('fk_template_id' =>$templateid,'isactive' => 1,'fk_form_id' =>$formid );
$exits_questions = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,SCORECARDQUESTIONS);
$result_data = array();
//print_r();
if(!count($exits_questions))
{
$fields = array('question_key_mapping_id','fk_form_id','fk_category_id','question','key','ismaster','master_name');
$where_condition_array = array();
if($formid != 0)
{
$where_condition_array = array('isactive' => 1,'fk_form_id' => $formid,'fk_category_id' => $categoryid);
}
else
{
$where_condition_array = array('isactive' => 1);
}
$result_data = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING);
if(count($result_data))
{
foreach($result_data as $res_key => $result)
{
$result_data[$res_key]['score_question_id'] = null;
$result_data[$res_key]['fk_template_id'] = null;
$result_data[$res_key]['fk_key'] = null;
$result_data[$res_key]['weightage'] = null;
$result_data[$res_key]['calc_type'] = null;
if($result['master_name'] != null || $result['master_name'] != "")
{
//echo $result['master_name'];
$fields = array($master_tables_pkid[$result['master_name']].' as id',$master_tables_field_names[$result['master_name']].' as name');
$table = constant($result['master_name']);
$where_condition_array = array('isactive' => 1);
$answers = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,$table);
foreach($answers as $answer_key => $answer)
{
$answers[$answer_key]['answer'] = null;
$answers[$answer_key]['fk_score_question_id'] = null;
$answers[$answer_key]['score'] = null;
$answers[$answer_key]['score_answer_id'] = null;
}
$result_data[$res_key]['answers'] = $answers;
}
}
}
}
else
{
$temp_array = array();
foreach($exits_questions as $res)
{
array_push($temp_array,$res['fk_key']);
}
//print_r($temp_array);
$this->db->SELECT('QUESTIONKEYMAPPING.question_key_mapping_id,QUESTIONKEYMAPPING.fk_form_id,QUESTIONKEYMAPPING.question,QUESTIONKEYMAPPING.key,QUESTIONKEYMAPPING.master_name,SCORECARDQUESTIONS.score_question_id,SCORECARDQUESTIONS.fk_template_id,SCORECARDQUESTIONS.fk_key,SCORECARDQUESTIONS.weightage,SCORECARDQUESTIONS.calc_type');
$this->db->FROM(QUESTIONKEYMAPPING.' as QUESTIONKEYMAPPING');
$this->db->JOIN(SCORECARDQUESTIONS.' as SCORECARDQUESTIONS','QUESTIONKEYMAPPING.fk_form_id = SCORECARDQUESTIONS.fk_form_id AND QUESTIONKEYMAPPING.key = SCORECARDQUESTIONS.fk_key AND SCORECARDQUESTIONS.isactive = 1','LEFT');
if($formid != 0)
{
$this->db->WHERE('QUESTIONKEYMAPPING.fk_form_id',$formid);
$this->db->WHERE('QUESTIONKEYMAPPING.fk_category_id',$categoryid);
}
$this->db->WHERE_NOT_IN('QUESTIONKEYMAPPING.key',$temp_array);
$this->db->WHERE('QUESTIONKEYMAPPING.isactive',1);
//$this->db->WHERE('SCORECARDQUESTIONS.isactive',1);
$result_data = $this->db->GET()->result_array();
if(count($result_data))
{
foreach($result_data as $res_key => $result)
{
if($result['master_name'] != null || $result['master_name'] != "")
{
//echo $result['master_name'];
$fields = array($master_tables_pkid[$result['master_name']].' as id',$master_tables_field_names[$result['master_name']].' as name');
$table = constant($result['master_name']);
$where_condition_array = array('isactive' => 1);
$answers = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,$table);
foreach($answers as $answer_key => $answer)
{
$answers[$answer_key]['answer'] = null;
$answers[$answer_key]['fk_score_question_id'] = null;
$answers[$answer_key]['score'] = null;
$answers[$answer_key]['score_answer_id'] = null;
}
$result_data[$res_key]['answers'] = $answers;
}
}
}
}
if(count($result_data))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = "No Data Found!";
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function getScorecardDetails_post()
{
$templateid = $this->post('templateid');
//*******************INTERNAL PURPOSE***************************************************
$master_tables_field_names = $this->config->item('master_tables_field_names');
$master_tables_pkid = $this->config->item('master_tables_pkid');
//*******************INTERNAL PURPOSE***************************************************
//Get Categories assigned to this template$template_id = $this->post('template_id');
$this->db->SELECT('QUESTIONCATEGORY.category_name,TEMPLATECATEGORYWEIGHTAGE.template_category_weightage_id, TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id, TEMPLATECATEGORYWEIGHTAGE.fk_template_id, TEMPLATECATEGORYWEIGHTAGE.weightage, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.createdon,"%d/%m/%Y") as createdon, TEMPLATECATEGORYWEIGHTAGE.fk_createdby, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.updatedon, "%d/%m/%Y") as updatedon, TEMPLATECATEGORYWEIGHTAGE.isactive, TEMPLATECATEGORYWEIGHTAGE.fk_updatedby');
$this->db->FROM(TEMPLATECATEGORYWEIGHTAGE .' as TEMPLATECATEGORYWEIGHTAGE');
$this->db->JOIN(QUESTIONCATEGORY.' as QUESTIONCATEGORY','TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id = QUESTIONCATEGORY.question_category_id');
$this->db->WHERE('TEMPLATECATEGORYWEIGHTAGE.fk_template_id',$templateid);
$template_categories = $this->db->GET()->result_array();
//print_r($template_categories);die();
foreach($template_categories as $cate_key => $category)
{
$this->db->SELECT('QUESTIONKEYMAPPING.question_key_mapping_id,QUESTIONKEYMAPPING.fk_form_id,QUESTIONKEYMAPPING.question,QUESTIONKEYMAPPING.key,QUESTIONKEYMAPPING.master_name,SCORECARDQUESTIONS.score_question_id,SCORECARDQUESTIONS.fk_template_id,SCORECARDQUESTIONS.fk_form_id,SCORECARDQUESTIONS.fk_key,SCORECARDQUESTIONS.weightage,SCORECARDQUESTIONS.calc_type');
$this->db->FROM(SCORECARDQUESTIONS.' as SCORECARDQUESTIONS');
$this->db->JOIN(QUESTIONKEYMAPPING.' as QUESTIONKEYMAPPING','SCORECARDQUESTIONS.fk_form_id = QUESTIONKEYMAPPING.fk_form_id AND QUESTIONKEYMAPPING.key = SCORECARDQUESTIONS.fk_key AND SCORECARDQUESTIONS.isactive = 1 AND QUESTIONKEYMAPPING.isactive = 1 AND SCORECARDQUESTIONS.fk_template_id ='.$templateid,'LEFT');
$this->db->WHERE('QUESTIONKEYMAPPING.fk_category_id',$category['fk_question_category_id']);
$ques_keys = $this->db->GET()->result_array();
//print_r($ques_keys);
foreach($ques_keys as $res_key => $result)
{
if($result['master_name'] != null || $result['master_name'] != "")
{
//echo $result['master_name'];
$fields = array($master_tables_pkid[$result['master_name']].' as id',$master_tables_field_names[$result['master_name']].' as name');
$table = constant($result['master_name']);
$where_condition_array = array('isactive' => 1);
$answers = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,$table);
//print_r($answers);
foreach($answers as $answer_key => $answer)
{
$this->db->SELECT('SCORECARDANSWERS.score_answer_id, SCORECARDANSWERS.fk_score_question_id, SCORECARDANSWERS.answer, SCORECARDANSWERS.score,SCORECARDANSWERS.isactive');
$this->db->FROM(SCORECARDANSWERS.' as SCORECARDANSWERS');
$this->db->WHERE('SCORECARDANSWERS.fk_score_question_id',$result['score_question_id']);
//$this->db->WHERE('SCORECARDANSWERS.isactive',1);
$this->db->WHERE('SCORECARDANSWERS.answer',$answer['id']);
$exact_answers = $this->db->GET()->result_array();
//print_r($this->db->last_query());
//print_r($exact_answers);
if(count($exact_answers))
{
$answers[$answer_key]['answer'] = $exact_answers[0]['answer'];
$answers[$answer_key]['fk_score_question_id'] = $exact_answers[0]['fk_score_question_id'];
$answers[$answer_key]['score'] = $exact_answers[0]['score'];
$answers[$answer_key]['score_answer_id'] = $exact_answers[0]['score_answer_id'];
$answers[$answer_key]['isactive'] = $exact_answers[0]['isactive'];
}
else
{
$answers[$answer_key]['answer'] = null;
$answers[$answer_key]['fk_score_question_id'] = null;
$answers[$answer_key]['score'] = null;
$answers[$answer_key]['score_answer_id'] = null;
$answers[$answer_key]['isactive'] = 1;
}
}
$ques_keys[$res_key]['answers'] = $answers;
}
}
$template_categories[$cate_key]['questions'] = $ques_keys;
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_categories;
$this->response($data,REST_Controller::HTTP_OK);
}
public function savePDReportTemplate_post()
{
$records = $this->post('records');
$pk_id = 0;
if($records['report_template_id'] != "" || $records['report_template_id'] != null)
{
//echo "update";die();
$where_condition_array = array('report_template_id' => $records['report_template_id']);
$pk_id = $this->Template_Management_Model->updateRecords($records,REPORTTEMPLATES,$where_condition_array);
}
else
{
$pk_id = $this->Template_Management_Model->saveRecords($records,REPORTTEMPLATES);
}
if($pk_id != 0)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $pk_id;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Not enough Data to Calculate Assessed Income';
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function getPDReportTemplate_post()
{
$records = $this->post('records');
$fields = array('report_template_id', 'fk_template_id','content');
$where_condition_array = array('fk_template_id'=>$records['fk_template_id'],'isactive'=>1);
$result_array = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,REPORTTEMPLATES);
if(count($result_array))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_array;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Data Available';
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function getTemplateForms_get()
{
$template_id = $this->get('template_id');
$fields = array('form_id');
$where_condition_array = array('fk_template_id'=>$template_id,'isactive'=>1);
$result_array = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATEFORMS);
//print_r($this->db->last_query());
$temp = array();
foreach($result_array as $r)
{
$formid = $r['form_id'];
$temp = array_merge($temp,array($formid));
}
if(count($result_array))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $temp;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Data Available';
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function saveTemplateForms_post()
{
$records = $this->post("records");
$template_id = $records['template_id'];
$forms = $records['forms'];
//print_r($forms);
$this->db->where('fk_template_id',$template_id);
$this->db->where_not_in('form_id',$forms);
$this->db->SET('isactive',0);
$this->db->UPDATE(TEMPLATEFORMS);
$fields = array('form_id');
$where_condition_array = array('fk_template_id'=>$template_id);
$result_array = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATEFORMS);
//print_r($result_array);
$insert_array = array();
$count = 0;
foreach($forms as $form)
{
$i = 0;
foreach($result_array as $result)
{
if($form == $result['form_id'])
{
$i++;
}
}
if($i == 0) {$insert_array[] = $form; }
}
foreach($insert_array as $newform)
{
$fields = array('isactive' => 1,'form_id' => $newform,'fk_template_id' => $template_id);
$pk_id = $this->Template_Management_Model->saveRecords($fields,TEMPLATEFORMS);
if($pk_id != "" || $pk_id != null) { $count++; }
}
if($count == count($insert_array))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $count;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Something Went Wrong! Try again Later';
$this->response($data,REST_Controller::HTTP_OK);
}
}
//Module : Template V2.0 (Dynamic Form Template).
// API 1 Master Listing
public function getTemplateV2_get(){
$lender_id = $this->get('entity_id');
if(isset($lender_id) && !empty($lender_id)){
$result_array = $this->Template_Management_Model->getTemplateMappingDetailsV2($lender_id);
if(count($result_array)>0)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_array;
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Data Available';
}
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Lender Id Not Found. Try Again!';
}
$this->response($data,REST_Controller::HTTP_OK);
}
// API 2 Get Template with Form Details V2.0 : ps 20/12/2021
public function getTemplateFormsV2_get(){
// echo "i am @927";die();
if(isset($_GET['map_id']))
{
$records['map_id'] = $this->get("map_id");}
if(isset($_GET['entity_id']))
{
$records['entity_id'] = $this->get("entity_id");}
if(isset($_GET['product_id']))
{
$records['product_id'] = $this->get("product_id");}
if(isset($_GET['customer_segment_id']))
{
$records['customer_segment_id'] = $this->get("customer_segment_id");}
$result_array = $this->Template_Management_Model->getTemplateMappingDetailsV2($records);
// print_r($result_array);die();
if(!empty($result_array))
foreach($result_array as $inx => $arr)
{
if($arr['map_id'] != null || $arr['map_id'] != ""){
$forms =$this->Template_Management_Model->getTemplateFormsV2($arr['map_id']);
for($i=0; $i<count($forms); $i++){
if($forms[$i]['form_id']=='19'){$forms[$i]['form_name']="Neighbourhood";}
}
$result_array[$inx]["forms"] = $forms;
}else{
$result_array[$inx]["forms"] = array();
}
$buinessFormAvailable =$this->Template_Management_Model->checkBuinessFormsAvailablity($records);
if($buinessFormAvailable){array_push($result_array[$inx]["forms"],array("form_id"=> "13","form_name"=> "Business Information","json"=> "","is_form_disabled"=> "0","is_business_form"=> "1","is_group_form"=> "1","pd_form_order"=>"5","is_form_status"=>null,"template_id"=>null));}
array_push($result_array[$inx]["forms"],array("form_id"=> "18","form_name"=> "General Information","json"=> "","is_form_disabled"=> "0","is_business_form"=> "0","is_group_form"=> "0","pd_form_order"=>"2","is_form_status"=>null,"template_id"=>null));
array_push($result_array[$inx]["forms"],array("form_id"=> "26","form_name"=> "Photograph","json"=> "","is_form_disabled"=> "0","is_business_form"=> "0","is_group_form"=> "0","pd_form_order"=>"24","is_form_status"=>null,"template_id"=>null));
// $buiness_arr = array("form_id"=> "13","form_name"=> "Business Information","json"=> "","is_form_disabled"=> "0","is_business_form"=> "1","is_group_form"=> "1");
// array_push($result_array[$inx]["forms"],$buiness_arr);
}
if(count($result_array)>0)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_array;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Data Available';
$this->response($data,REST_Controller::HTTP_OK);
}
}
//Save and Update Form Template Details V2.0 : ps 20/12/2021
// "entity_id": "42",
// "product_id": "24",
// "customer_segment_id": "5",
// "json": "{ \"section_id\":\"5\", \"section_name\":\"Address details\", \"onsubmit\":null, \"questions\":[ { \"question\":\"Address at which PD was initiated\", \"question_key\":\"initiated_address\", \"type\":\"7\", \"disable\":false, \"field_width\":\"100\", \"title\":\"Address Details\", \"answers\":true, \"api_properties\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"State\", \"question_key\":\"State_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"STATE\" }, \"fields\":[ \"state_id\", \"name\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"City\", \"question_key\":\"City_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfStatesAndCities\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"state_id\" }, \"fields\":[ \"city_id\", \"city_name\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Pincode\", \"question_key\":\"Pincode_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfStatesAndCities\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"pincode\" }, \"fields\":[ \"pincode\", \"pincode_id\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Is this the address where PD is done ?\", \"question_key\":\"is_pd_done_on_initiated_address\", \"type\":\"2\", \"disable\":false, \"field_width\":\"100\", \"onchange_properties\": [{ \"purpose\":\"FORM_CTRL\", \"form_controls\":[ { \"insert_index\":\"is_pd_done_on_initiated_address\", \"expression\":\"(String('is_pd_done_on_initiated_address') == String('No'))\", \"value_keys\":[ \"is_pd_done_on_initiated_address\" ], \"questions\":[ { \"question\":\"Reason for change in PD visit address\", \"question_key\":\"end_use\", \"type\":\"1\", \"field_width\":\"100\", \"api_properties\":null, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ ] }, { \"question\":\"Pincode\", \"question_key\":\"Pincode_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"COMMENTSONLOCALITY\" }, \"fields\":[ \"comments_on_locality_id\", \"rating\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"City\", \"question_key\":\"City_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"COMMENTSONLOCALITY\" }, \"fields\":[ \"comments_on_locality_id\", \"rating\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"State\", \"question_key\":\"State_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"STATE\" }, \"fields\":[ \"state_id\", \"name\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Enter actual PD address\", \"question_key\":\"actual_pd_address\", \"type\":\"1\", \"field_width\":\"100\", \"api_properties\":null, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ ] } ] } ] }], \"api_properties\":null, \"answers\":[ { \"answer_id\":\"Yes\", \"answer\":\"Yes\" }, { \"answer_id\":\"No\", \"answer\":\"No\" } ], \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Address Type\", \"question_key\":\"Address_Type\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"ADDRESSTYPE\" }, \"fields\":[ \"address_type_id\", \"address_type\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Locality\", \"question_key\":\"Locality\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"LOCALITY\" }, \"fields\":[ \"locality_id\", \"locality_name\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Approach to PD location*\", \"question_key\":\"Approach_to_PD_location\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"PDLOCATIONAPPROACH\" }, \"fields\":[ \"pd_location_approach_id\", \"description\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Comment on Locality\", \"question_key\":\"Comment_on_Locality\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"COMMENTSONLOCALITY\" }, \"fields\":[ \"comments_on_locality_id\", \"rating\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Unit of Measurement\", \"question_key\":\"Unit_of_Measurement\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"UOM\" }, \"fields\":[ \"uom_id\", \"name\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] },{ \"question\":\"Estimate area of the Residence\", \"question_key\":\"Estimate_area_of_the_Residence\", \"type\":\"1\", \"disable\":false, \"field_width\":\"45\", \"api_properties\": null, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] } ] }",
// "form_id": "5"
// public function saveTemplateFormsV2_post(){
// $records = $this->post("records");
// $json = json_encode($records['json'],true);
// $fields = array('id');
// $where_condition_array = array('entity_id'=>$records['entity_id'],'product_id'=>$records['product_id'],'customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1);
// $mapping_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_MAP_V2);
// // print_r($mapping_table);die();
// if(count($mapping_table)>0){
// $map_id = $mapping_table[0]['id'];
// //in-active existing Entries here using Map ID and Form ID means
// $fields = array('id');
// $where_condition_array = array('map_id'=>$map_id,"form_id"=>$records['form_id'],"isactive"=>1);
// $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2);
// if(count($json_table)>0){
// $this->db->where('id',$json_table[0]['id']);
// $this->db->set('isactive',0);
// $this->db->update(TEMPLATE_JSON_V2);
// }
// // insert json here.
// $fields = array('isactive' => 1,'form_id' => $records['form_id'],'json' => $json,'map_id'=>$map_id);
// $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2);
// }
// else{
// // insert map & its json here.
// $fields = array('entity_id'=>$records['entity_id'],'product_id'=>$records['product_id'],'customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1);
// $map_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_MAP_V2);
// if($map_pk_id){
// $fields = array('isactive' => 1,'form_id' => $records['form_id'],'json' => $json,'map_id'=>$map_pk_id);
// $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2);
// }
// }
// if($json_pk_id)
// {
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['records'] = "Sucessfully Inserted";
// $this->response($data,REST_Controller::HTTP_OK);
// }
// else
// {
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
// $data['msg'] = 'Something Went Wrong! Try again Later';
// $this->response($data,REST_Controller::HTTP_OK);
// }
// }
// API 3 : to save and Update the Mapping Details and return the Pkid
public function saveTemplateV2_post(){
// draft,approve,completed
// strtoupper(str_replace(' ', '', $form_status));
$records = $this->post("records");
// print_r($records);die();
if( (!isset($records['entity_id'])) || (!isset($records['product_id'])) || (!isset($records['customer_segment_id'])) )
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Key Missing! Try again Later';
$this->response($data,REST_Controller::HTTP_OK);
}else{
$fields = array('id');
$flag=0;
$where_condition_array = $records;
$where_condition_array['isactive'] = 1;
$map_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_MAP_V2);
// $map_table = array();
if(count($map_table)>0){
// $this->db->where('id',$map_table[0]['id']);
// $this->db->set('isactive',0);
// $this->db->update(TEMPLATE_MAP_V2);
// $map_pk_id = (int)$map_table[0]['id'];
$msg = "Data Already Available For Given Params / MAPID => ".(int)$map_table[0]['id'];
$STScode = REST_Controller::HTTP_ACCEPTED;
$flag++;
}else{
// form Template is declare as gobally in m_pd_forms table @form_template column using CustomerSegmentID.
// $form_template = array();
$regular_form_template = $this->Template_Management_Model->getFormTemplate($records['customer_segment_id']);
$buiness_form_template = $this->getBuinessFormTemplate($records);
$key = array_search('13', array_column($regular_form_template, 'form_id'));
if (!empty($key)) {
unset($regular_form_template[$key]);//here 13th form is buiness unset here.id have both regular and buiness.
$form_template = array_merge($regular_form_template,$buiness_form_template);
}else{
$form_template = $regular_form_template;
}
$map_pk_id = $this->Template_Management_Model->saveTemplateMapping($records,TEMPLATE_MAP_V2);
$c = "JSON ID Are =>"; //concate;
for($i=0; $i<count($form_template); $i++){
$template = $form_template[$i]['form_template'];
if($template != null || $template != ""){
$fields = array('form_id' => $form_template[$i]['form_id'],'json' => $template,'map_id'=>$map_pk_id,'is_form_status'=>"DRAFT");
if($form_template[$i]['form_id'] != 18 ||$form_template[$i]['form_id'] != 26){
// if($form_template[$i]['form_id'] != 18 ||$form_template[$i]['form_id'] != 26 ||$form_template[$i]['form_id'] != 13){
$json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2);
$c = $c." ".$json_pk_id;}
}
}
$msg = "Sucessfully Inserted";
$flag++;
$STScode = REST_Controller::HTTP_OK;
}
if($flag>0)
{
$data['dataStatus'] = true;
$data['status'] = $STScode;
if(isset($map_pk_id)){$data['map_id'] = $map_pk_id;}
if(isset($c)){$data['json_id'] = $c;}
$data['msg'] = $msg;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Something Went Wrong! Try again Later';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
// API 4 : to save and Update the Mapping Details and return the Pkid
public function saveTemplateFormsV2_post(){
$records = $this->post("records");
if(!isset($records['json']) || !isset($records['form_id']) || !isset($records['map_id']))
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Key Missing! Try again Later';
$this->response($data,REST_Controller::HTTP_OK);
}else{
$map_id = $records['map_id'];
$form_id = $records['form_id'];
$fields = array('id');
$status = strtoupper(str_replace(' ', '',$records['form_status']));
$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1);
$json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2);
### Don't Delete Because First Requirement..... multiple draft mode and multiple approve mode but when completed means inactive the draft json and approve json
// foreach ($json_table as $value) $id_array[] = $value['id'];
// if(count($json_table)>0 && $status == "COMPLETED"){
// $this->db->where_in('id',$id_array);
// $this->db->set('isactive',0);
// $this->db->update(TEMPLATE_JSON_V2);
// }else if(count($json_table)>0 && ($status == "DRAFT" || $status == "APPROVED")){
// $this->db->where('is_form_status',"COMPLETED");
// $this->db->where_in('id',$id_array);
// $this->db->set('isactive',0);
// $this->db->update(TEMPLATE_JSON_V2);
// }
// $json = json_encode($records['json'],true);
// $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status);
// $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2);
if($status == "DRAFT"){
if(count($json_table)>0){
if($status == "COMPLETED"){
$this->db->where_in('id',$json_table[0]['id']);
$this->db->set('isactive',0);
$this->db->where('is_form_status',"COMPLETED");
$this->db->update(TEMPLATE_JSON_V2);
}else{
$json_pk_id = $json_table[0]['id'];
$data = array('json' => json_encode($records['json'],true),'is_form_status' => $status);
$this->db->where('isactive',1);
$this->db->where('id',$json_pk_id);
$this->db->update(TEMPLATE_JSON_V2,$data);
$msg = "Sucessfully Updated";
}
}else{
$json = json_encode($records['json'],true);
$fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status);
$json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2);
$msg = "Sucessfully Inserted";}
}else if($status == "APPROVED" || $status == "COMPLETED"){
//approve and completed status means just update the status only.
$json_pk_id = $json_table[0]['id'];
$data = array('json' => json_encode($records['json'],true),'is_form_status' => $status);
$this->db->where('isactive',1);
$this->db->where('id',$json_pk_id);
$this->db->update(TEMPLATE_JSON_V2,$data);
$msg = "Sucessfully Updated";
}
if($json_pk_id)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['json_id'] = $json_pk_id;
$data['msg'] = $msg;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Something Went Wrong! Try again Later';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
//API 5 : to Delete Template Details Using map id and its json's
public function deleteDynamicTemplateV2_get(){
$map_id = $this->get('map_id');
if(isset($map_id) && !empty($map_id)){
$flag = $this->Template_Management_Model->inactiveMappingDetailsandJSONV2($map_id);
if($flag)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'Successfully Deleted';
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Noting to Delete';
}
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Map Id Not Found. Try Again!';
}
$this->response($data,REST_Controller::HTTP_OK);
}
//API 6 :
public function loadFullTemplateV2_get()
{
$pd_id = "";
$client = "";
$random_string = "";
$api = "";
$fi_id = "";
if($this->get('pd_id')) { $pd_id = $this->get('pd_id'); }
if($this->get('client')) { $client = $this->get('client'); }
if($this->get('random_string')) { $random_string = $this->get('random_string'); }
if($this->get('api')) { $api = $this->get('api'); }
if($this->get('fi_id')) {$fi_id = $this->get('fi_id');}
if($pd_id != "" || $pd_id != null)
{
$template_details = $this->PD_Model->getTemplateForPDV2($pd_id,$client,$random_string,$api);
if(count($template_details))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_details;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'There is no Template for Given PD-ID'.$pd_id;
$this->response($data,REST_Controller::HTTP_OK);
}
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_BAD_REQUEST;
$data['msg'] = 'No Param Available';
$this->response($data,REST_Controller::HTTP_OK);
}
}
//API 7
public function formWiseJSONTemplateV2_get(){
if( (!isset($_GET['map_id'])) && (!isset($_GET['form_id'])) )
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Key Missing! Please Check again both map-id and form-id';
$this->response($data,REST_Controller::HTTP_OK);
}else{
$map_id = $_GET['map_id'];
$form_id = $_GET['form_id'];
$template_id = isset($_GET['template_id'])?$_GET['template_id']:null;
$fields = array('id','json');
// if($template_id){$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"is_form_status"=>"COMPLETED","id"=>$template_id);}
// else{$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"is_form_status"=>"COMPLETED","isactive"=>1);$data['note'] = "Existing JSON..";}
if($template_id){$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"id"=>$template_id);}
else{$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1);}
$json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2);
if(count($json_table)>0){
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['json'] = $json_table[0]['json'];
$data['template_id'] = $json_table[0]['id'];
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'JSON Not Available! Try again Later';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
public function disableformV2_post(){
$record = $this->post("records");
if( (!isset($record['map_id'])) || (!isset($record['form_id'])) || (!isset($record['is_form_disabled'])) )
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Key Missing! Please Check again map-id,is_form_disabled and form-id';
$this->response($data,REST_Controller::HTTP_OK);
} else{
$map_id = $record['map_id'];
$form_id = $record['form_id'];
$is_form_disabled = $record['is_form_disabled'];
$fields = array('id');
// $where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1,"is_form_status"=>"COMPLETED");
$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1);
$json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2);
if(count($json_table)>0){
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['json'] = $json_table[0]['json'];
// $this->response($data,REST_Controller::HTTP_OK);
$res = $this->Template_Management_Model->updateRecords(array('is_form_disabled' => $is_form_disabled),TEMPLATE_JSON_V2,$where_condition_array);
if($res){
$fields = array('pd_form_name');
$where_condition_array = array("pd_form_id"=>$form_id);
$form_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,PDFORMS);
if($is_form_disabled == 1) $msg = $form_table[0]['pd_form_name'].' Successfully Disabled' ;
if($is_form_disabled == 0) $msg = $form_table[0]['pd_form_name'].' Successfully Enabled' ;
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = $msg;
$this->response($data,REST_Controller::HTTP_OK);
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'There is No Changes..';
$this->response($data,REST_Controller::HTTP_OK);
}
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Data Found for Given Map-id and Form-id';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
// analysing
public function getBuinessGroupFormsV2_get(){
// echo $_GET['map_id'];die;
// if((!isset($_GET['map_id'])))
// {
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NOT_FOUND;
// $data['msg'] = 'Key Missing! Please Check again both map-id and form-id';
// $this->response($data,REST_Controller::HTTP_OK);
// }
// else{
if(isset($_GET['map_id']))
{
$records['map_id'] = $this->get("map_id");}
if(isset($_GET['entity_id']))
{
$records['entity_id'] = $this->get("entity_id");}
if(isset($_GET['product_id']))
{
$records['product_id'] = $this->get("product_id");}
if(isset($_GET['customer_segment_id']))
{
$records['customer_segment_id'] = $this->get("customer_segment_id");}
$result_array = $this->Template_Management_Model->getTemplateMappingDetailsV2($records);
// echo "no problem";print_r($result_array);die;
if(!empty($result_array))
foreach($result_array as $inx => $arr)
{
if($arr['map_id'] != null || $arr['map_id'] != ""){
$result_array[$inx]["forms"] = $this->Template_Management_Model->getBuinessGroupForms($arr['map_id']);
array_push($result_array[$inx]["forms"],array("form_id"=> "14","form_name"=> "Financial Information","pd_form_level_order"=> "2","json"=> "","is_form_disabled"=> "0","is_business_form"=> "1","is_group_form"=> "0","pd_form_order"=>"8","is_form_status"=>null,"template_id"=>null,"map_id"=>$arr['map_id']));
}else{
$result_array[$inx]["forms"] = array();
}
}
if(count($result_array)>0)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_array;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Data Available';
$this->response($data,REST_Controller::HTTP_OK);
}
}
public function JSONquestionFilterV2_get(){
if( (!isset($_GET['map_id'])) && (!isset($_GET['form_id'])) )
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Key Missing! Please Check again both map-id and form-id';
$this->response($data,REST_Controller::HTTP_OK);
}else{
$map_id = $_GET['map_id'];
$form_id = $_GET['form_id'];
// Using global keyword
// global $global_form_id;
$fields = array('json');
$where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1);
// "is_form_status"=>
$json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2);
if(count($json_table)>0){
$json = json_decode($json_table[0]['json'],true);
if(isset($json['questions'][0]['question_key']) ){
$quest = isset($json['questions'])?$json['questions']:$json['question'];
}else{
$quest = isset($json['questions'][0]['question'])?$json['questions'][0]['question']:$json['question'][0]['question'];
// s$quest = $json['questions'][0]['question'];
}
// re-check (1,2) // done (5,19,14,24,20,22) //ok-but-doubt (13,11)
// print_r($quest);die();
$filter_arr = array();
//try 4
if(!empty($quest)){
$arr1 = $this->call_arr1($quest);
$arr2 = $this->call_arr2($quest);
$filter_arr = $this->merged_arr($arr1,$arr2);
}
if(!empty($filter_arr)){
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
// $data['available_question'] = $filter_arr;
// $data['json'] = $quest;
$this->response($data,REST_Controller::HTTP_OK);
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'There is no JSON template. try again';
$this->response($data,REST_Controller::HTTP_OK);
}
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Data Found Given Map-id and Form-id';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
//Step 1 : Question Filter Only
public function call_arr1($quest){
$return_arr = array();
$i = 0 ;
// print_r($quest);
if((!empty($quest)) && (is_array($quest) || is_object($quest)) )
{
foreach ($quest as $key => $value) {
// $return_arr[$i] = array('question'=> $value['question'],'question_key'=>$value['question_key']);
// $return_arr[$i]['question'] = $value['question'];
// $return_arr[$i]['question_key'] = $value['question_key'];
if(isset($value['question'][0]['question_key'])){
$question = isset($value['question']) ? $value['question'] : array();
for($j = 0 ;$j<count($question);$j++){
$latest_quest = isset($question[$j]['question_key']) ? $question : $question[$j]['question'];
$temp[$i] = $this->call_arr1($latest_quest);
$arr2 = $this->call_arr2($latest_quest);
$return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
$i++;
}
}else if(isset($value['questions'][0]['question_key'])){
$question = isset($value['questions']) ? $value['questions'] : array();
for($j = 0 ;$j<count($question);$j++){
$latest_quest = isset($question[$j]['question_key']) ? $question : $question[$j]['question'];
$temp[$i] = $this->call_arr1($latest_quest);
$arr2 = $this->call_arr2($latest_quest);
$return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
$i++;
}
}
else{
$return_arr[$i] = $value['question'];
$i++;
}
}
}
return $return_arr;
}
//Step 2 : Onchange fns - Question Filter
public function call_arr2($quest){
$return_arr = array();
$i = 0 ;
if(!empty($quest) && is_array($quest) || is_object($quest)){
foreach ($quest as $key => $value) {
if((isset($value['onchange_properties'])) && (!empty($value['onchange_properties'])) && ($value['onchange_properties'] != null)){
for($h=0;$h<count($value['onchange_properties']);$h++){
$onchange_properties = isset($value['onchange_properties'][$h]['form_controls']) ? $value['onchange_properties'][$h]['form_controls'] : array();
$count = isset($onchange_properties) ? count($onchange_properties) : 0 ;
if($count>0 && !empty($onchange_properties)){
foreach ($onchange_properties as $key1 => $value1) {
// echo $value1['expression'];
// if($value1['question_key'] == 'Payment_Terms'){
// echo "I have step 1";
// echo($value['question_key']);
// echo $value1['question_key'];}
// if($value['question_key'] == 'Assets_Type'){
// }
if($value1['insert_index'] == $value['question_key']){
if(count($value1['questions']) > 0){
// echo " 8-i".$i;
for($j = 0 ;$j<count($value1['questions']);$j++){
// if($value['question_key'] == 'Assets_Type'){
// echo "**";
// }
// if($value['question_key'] == 'Payment_Terms'){
// print_r($value1['questions']);
// echo count($value1['questions']);
// print_r($this->call_arr1($value1['questions'],$fid)); run
// print_r($this->call_arr2($value1['questions'][$j]['question']));
// echo " <br> parent ".$value['question_key'];
$latest_quest = isset($value1['questions'][$j]['question_key']) ? $value1['questions'] : $value1['questions'][$j]['question'];
// $latest_quest = $value1['expression'] ? $latest_quest.$value1['expression'] : $latest_quest;
// echo " Key ".$value1['insert_index'];
$temp[$i] = $this->call_arr1($latest_quest);
$arr2 = $this->call_arr2($latest_quest);
$return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
// }
// $temp[$i] = $this->call_arr1($value1['questions'][$j]['question'],$fid);
// $arr2 = $this->call_arr2($value1['questions'][$j]['question'],$fid);
// $return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
}
}
// else{
// if(isset($value1['questions'][0]['question_key'])){
// $temp[$i] = $this->call_arr1($value1['questions'],$fid);
// $arr2 = $this->call_arr2($value1['questions'],$fid);
// // $arr1 = $this->call_arr1($value1['questions']);
// // $arr2[$i]['child'] = $this->call_arr2($temp[$i],$arr2);
// $return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
// }else{
// $temp[$i] = $this->call_arr1($value1['questions'][0]['question'],$fid);
// $arr2 = $this->call_arr2($value1['questions'][0]['question'],$fid);
// $return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
// }
// }
// foreach($value1['question'] as $key2 => $value2){
// $temp2[$i] = $this->call_arr1($value2['question']);
// $arr3 = $this->call_arr2($value2['question']);
// $return_arr[$i] = $this->merged_arr($temp2[$i],$arr3);
// }
}
}
}
}
}
$i++;
}
}
return $return_arr;
}
//Step 3 : Mapping Here for single-array using 2-array(arr1,arr2) ---- Short description is "array associate"
public function merged_arr($arr1,$arr2){
$final_result = array();
foreach($arr1 as $key=>$val){ // Loop though one array
if (array_key_exists($key, $arr2))
{
$val2 = $arr2[$key]; // Get the values from the other array
$final_result[$val] = $val2; // combine here (mapping as key)
// $final_result[$key] = $val + $val2;
// $final_result[$key][$val] = $val2;
}
else{
$final_result[$key] = $val; // combine here (mapping as key)
}
}
return $final_result;
}
//Step 4 : description - to get un-associated array.
// public function arr_formation_for_associate(){
// $return_arr = array();
// $i = 0 ;
// }
// http://localhost/AWSEC2/sparqapi/api/Template_Management_Controller/check
// public function check_get(){
// $form_template = $this->Template_Management_Model->getFormTemplate(4);
// // print_r($form_template);die();
// $this->response($form_template,REST_Controller::HTTP_OK);
// }
public function getBuinessFormTemplate($records){
$fields = array('short_name');
$where_condition_array = array('entity_id'=>$records['entity_id'],"isactive"=>1);
$lender_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,'m_entity');
$lender_short_name = $lender_table[0]['short_name'];
$fields = array(' abbr');
$where_condition_array = array('customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1);
$segment_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,'m_customer_segment');
$str = substr($segment_table[0]['abbr'],-2);
$form_id = array(13,22,1,2,11);
//here 14 removed because finacial form calculation are there.
if(strcmp($str,'AI')) { array_push($form_id,16); }
if(!strcasecmp($lender_short_name, 'CLIX')){ array_push($form_id,21); }
if(!strcasecmp($lender_short_name, 'CLIX') || (!strcasecmp($lender_short_name, 'MWISE'))) { array_push($form_id,23);}
$form_template = $this->Template_Management_Model->getBuinessFormTemplate($form_id);
return $form_template;
}
public function loadFITemplate_get()
{
$pd_id = "";
$client = "";
$random_string = "";
$api = "";
$FI_id = "";
if ($this->get('pd_id')) {
$pd_id = $this->get('pd_id');
}
if ($this->get('client')) {
$client = $this->get('client');
}
if ($this->get('random_string')) {
$random_string = $this->get('random_string');
}
if ($this->get('api')) {
$api = $this->get('api');
}
if ($this->get('fi_id')) {
$FI_id = $this->get('fi_id');
}
if ($pd_id != "" || $pd_id != null) {
$template_details = $this->PD_Model->getFITemplateForPD($pd_id, $client, $random_string, $api,$FI_id);
if (count($template_details)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template_details;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Template Not for PD ID' . $pd_id;
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_BAD_REQUEST;
$data['msg'] = 'No Param Available';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function FIformWiseTemplate_get(){
if((!isset($_GET['form_id'])) )
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Key Missing! Please Check again both form-id';
$this->response($data,REST_Controller::HTTP_OK);
}else{
$form_id = $_GET['form_id'];
$fields = array('pd_form_id','pd_form_name','form_template');
$where_condition_array = array("form_id"=>$form_id,'isactive'=>1);
$json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,PDFORMS);
if(count($json_table)>0){
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['json'] = $json_table;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'FI-PD JSON Not Available for Given Form ID ! ';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
public function saveFIPDPhotograph_post()
{
$records = $this->post('records');
if ($records['pd_document_id'] != null && $records['pd_document_id'] != "") {
$where_condition_array = array('pd_document_id' => $records['pd_document_id']);
$to_update = array("pd_image_alias_name" => $records['pd_image_alias_name']);
$res['count'] = $this->PD_Model->updateRecords($to_update, PDDOCUMENTS, $where_condition_array);
$res['msg'] = "Updated";
$data['uri'] = null;
}else if($records['pd_document_id'] == "") {
if ($records['image_key'] == 'selfie_with_person_met') {
$this->PD_Model->updateRecords(array('start_location' => $records['location']), PDTRIGGER, array('pd_id' => $records['pd_id']));
satellite_image::getSatelliteImage($records['pd_id']);
}
// if ($records['image_key'] == 'video') {
// $res = $this->saveShortsVideo($records,$_FILES);
// }else{
$res = $this->saveBase64Images($records);
// }
}
if (!empty($res)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['uri'] = $res['records'];
$data['msg'] = $res['msg'];
$this->response($data, REST_Controller::HTTP_OK, true);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Something Went Wrong!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function saveBase64Images($data)
{
$pd_id = $data['pd_id'];
$form_id = $data['formid'];
log_message('ERROR', '###FI-PDIMAGE saveBase64Images function called' . $pd_id . ' - ' . $form_id);
$count = 0;
$result = array();
$pks = array();
$uri = null;
$pd_details = $this->PD_Model->getPDMasterDetails($pd_id);
//print_r($data);die();
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id);
$this->location_for_watermark = $data['location'];
$temp_base64_string = $data['image'];
$is_show_report = isset($data['is_show_report']) ? $data['is_show_report'] : null;
$output_file = $this->external_path . "/pd_reports/" . $pd_id . "/temp_base64_image.jpeg";
$this->temp_path_for_watermark = $output_file;
//Generate Random File Name
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 5; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$temp_file_name = $randomString . date('Y-m-d-H-i-s') . '.jpeg';
log_message('ERROR', '###FI-PDIMAGE writing started' . $pd_id . ' - ' . $form_id);
$ifp = fopen($output_file, 'wb');
$temp_data = explode(',', $temp_base64_string);
fwrite($ifp, base64_decode($temp_data[1]));
fclose($ifp);
log_message('ERROR', '###FI-PDIMAGE writing done' . $pd_id . ' - ' . $form_id);
log_message('ERROR', '###FI-PDIMAGE uploading to S3' . $pd_id . ' - ' . $form_id);
$tempdoc = $output_file;
$tempdocname = $temp_file_name;
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_details[0]['fk_lender_id'];
$key = 'pd' . $pd_id . '/' . $tempdocname;
$sourcefile = $tempdoc;
$bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $sourcefile);
//this line make this bucket data values in obj level so can access in helpers and hook files
$this->bucket_data_for_watermark = $bucket_data;
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
log_message('ERROR', '###FI-PDIMAGE stored in S3' . $pd_id . ' - ' . $form_id);
$record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => (isset($data['pd_document_title']) ? $data['pd_document_title'] : null), 'pd_document_name' => $tempdocname, 'fk_form_id' => $form_id, 'is_show_report' => $is_show_report, 'location' => isset($data['location']) ? $data['location'] : null, 'img_type' => (isset($data['img_type']) ? $data['img_type'] : null), 'image_key' => (isset($data['image_key']) ? $data['image_key'] : null), "pd_image_alias_name" => (isset($data['pd_image_alias_name']) ? $data['pd_image_alias_name'] : null));
$id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week');
$this->img_url_for_watermark = $uri;
}
if ($id) {
log_message('ERROR', '###FI-PDIMAGE Saved Sucessfully ID '.$id);
//$logger->info('All Images Saved Sucessfully',array($pd_id,$form_id,$company_id));
$result['status'] = true;
$result['id'] = $id;
$result['records'] = $uri;
$result['msg'] = "Images Saved Successfully";
} else {
//$logger->info('Some Images Not Saved',array($pd_id,$form_id,$company_id));
$result['status'] = true;
$result['msg'] = "Images Not Saved!";
}
return $result;
}
// public function saveShortsVideo($records,$files)
// {
// log_message('ERROR', "saveShortsVideo FNS called");
// $file_folder = "pd_reports";
// $_FILES = $files;
// if (!empty($_FILES['video_file'])) {
// $form_id = $records['form_id'];
// $pd_id = $records['pd_id'];
// $pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
// if(isset($records['filename']) && $records['filename'] !=""){
// $temp_file_name = $records['filename'];
// }else{
// //Generate Random File Name
// $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// $charactersLength = strlen($characters);
// $randomString = '';
// for ($i = 0; $i < 5; $i++) {
// $randomString .= $characters[rand(0, $charactersLength - 1)];
// }
// $temp_file_name = $randomString . date('Y-m-d-H-i-s') . '.mp4';
// }
// log_message('ERROR', "filename = ".$temp_file_name);
// $lender_id = $pd_master_details[0]['fk_lender_id'];
// $bucketname = LENDER_BUCKET_NAME_PREFIX . $lender_id;
// $key = 'pd' . $records['pd_id'] . '/video/' . $temp_file_name;
// log_message('ERROR', "bucket key = ".$bucketname);
// $file_name_wo_extension = explode('.', ($temp_file_name))[0];
// log_message('ERROR', "file_name_extension = ".$file_name_wo_extension);
// $file_type = explode('/', ($_FILES['video_file']['type']))[1];
// log_message('ERROR', "file_type ".$file_type);
// $folder_to_check = XLPATH . '/' . $file_folder . '/' . $records['pd_id'] . '/videos';
// // echo $folder_to_check;//die();
// if (!file_exists($folder_to_check)) {
// mkdir(XLPATH . '/' . $file_folder . '/' . $records['pd_id'], 0777);
// mkdir($folder_to_check, 0777);
// }
// $config = array('upload_path' => $folder_to_check, 'overwrite' => TRUE, 'allowed_types' => '*', 'file_name' => $file_name_wo_extension . '.' . $file_type);
// $this->load->library('upload', $config);
// if ($this->upload->do_upload('video_file')) {
// $sourcefile = $folder_to_check . '/' . $file_name_wo_extension . '.mp4';
// $bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $sourcefile);
// $s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
// if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
// $uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week');
// log_message('ERROR', '###PD SHORTS VIDEO stored in S3 uri = ' . $uri);
// $record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => isset($records['pd_document_title']) ? $records['pd_document_title'] : 'Video', 'pd_document_name' => $temp_file_name, 'fk_form_id' => $form_id, 'is_show_report' => 1, 'rental_count_id' => null, 'location' => null, 'co_applicant_id' => null, 'img_type' => null, 'image_key' => "video", "pd_image_alias_name" => null,"content_type"=>2);
// $record_data['company_id'] = null;
// $id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
// if(file_exists($folder_to_check . '/' . $file_name_wo_extension . '.webm')){unlink($folder_to_check . '/' . $file_name_wo_extension . '.webm');}
// if(file_exists($folder_to_check . '/' . $file_name_wo_extension . '.mp4')){unlink($folder_to_check . '/' . $file_name_wo_extension . '.mp4');}
// if ($id != null || $id != "") {
// log_message('ERROR', '###PD SHORTS VIDEO Saved');
// $result['status'] = true;
// $result['msg'] = 'Video Saved Successfully';
// $result['records'] = array('id'=>$id,'uri'=>$uri);
// }
// else{
// log_message('ERROR', '###PD SHORTS VIDEO Entry Not saved');
// $result['status'] = false;
// $result['msg'] = 'Something Wrong. Try Later!';
// }
// }else{
// log_message('ERROR', '###PD SHORTS VIDEO S3 Uri not saved');
// $result['status'] = false;
// $result['msg'] = 'Something Wrong. Try Later!';
// }
// } else {
// $result['status'] = false;
// $result['msg'] = 'Something Wrong. Try Later!';
// }
// } else {
// log_message('ERROR', '###PD SHORTS No Video Found');
// $result['status'] = false;
// $result['msg'] = 'No Video found to upload';
// }
// return $result;
// }
public function FIPDPhotograph_get(){
$pd_id = $this->get('pd_id');
$form_id = "34"; // FI photograph HardCoded.
if(!empty($pd_id)){
$fields = array('json');
$where_condition_array = array("fk_form_id"=>$form_id,"fk_pd_id"=>$pd_id,'isactive'=>1);
$form_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON);
// print_r($form_table);
// $file = $this->external_path . '/pd_reports/tmp/1.txt'; // testing purpose;
if(count($form_table)>0){
// if(1){
$json = json_decode($form_table[0]['json'],true);
$json = $json['photograph_details'];
// $json = $this->getArr(); // testing purpose;
// print_r($json);die(); // testing purpose;
$pd_master = $this->PD_Model->selectCustomRecords(array('pd_id', 'random_string','fk_lender_id'), array('pd_id' => $pd_id ), PDTRIGGER);
$pd_docs = $this->PD_Model->selectCustomRecords(array('pd_document_id', 'fk_pd_id', 'fk_pd_detail_id', 'fk_form_id', 'co_applicant_id', 'img_type', 'image_key', 'pd_document_title', 'pd_document_name', 'pd_image_alias_name', 'createdon', 'fk_createdby', 'updatedon', 'fk_updatedby', 'company_id', 'is_show_report', 'is_name_editable', 'rental_count_id', 'location', 'isactive', 'retake_flag'), array('fk_pd_id' => $pd_id, 'fk_form_id' =>$form_id, 'pd_document_title != ""' =>null), PDDOCUMENTS);
if(count($pd_docs)>0){
$bucket_name = LENDER_BUCKET_NAME_PREFIX . $pd_master[0]['fk_lender_id'];
// $imgs = array('selfie_with_person_met' => array('is_multiple' => 0,'img_name' => 'Selfie of the person contacted'),'name_board_seen' => array('is_multiple' => 1,'img_name' => 'Business Name Board'),'stock_image' => array('is_multiple' => 1,'img_name' => 'Stock Images'),'workplace_interior_image' => array('is_multiple' => 1,'img_name' => 'Work Place Interior'));
foreach ($pd_docs as $key => $value) {
if($value['image_key'] == 'video'){
$vdopath = 'pd' . $pd_master[0]['pd_id'] . '/video/' . $value['pd_document_name'];
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $vdopath, $time = '+1 week');
}else{
$picspath = 'pd' . $pd_master[0]['pd_id'] . '/' . $value['pd_document_name'];
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $picspath, '+5 minutes');
}
$pd_docs[$key]['doc_url'] = $singed_uri;
}
// print_r($pd_docs);die(); // wroking fine
for($i=0; $i<count($json); $i++){
if(isset($json[$i]['is_multiple']) && $json[$i]['is_multiple'] == 0 && $json[$i]['answer_value'] == "saved"){
for($j=0; $j<count($pd_docs); $j++){
if($pd_docs[$j]['image_key'] == $json[$i]['question_key']){
$json[$i]['answer_value'] = $pd_docs[$j]['doc_url'];
$json[$i]['pd_document_id'] = $pd_docs[$j]['pd_document_id'];
}
}
}
else if(isset($json[$i]['questions_group'])){
$second_arr = $json[$i]['questions_group'];
for($k=0; $k<count($second_arr); $k++){
$thrid_arr = $second_arr[$k]['questions'];
for($l=0; $l<count($thrid_arr); $l++){
if(isset($thrid_arr[$l]['is_multiple']) && $thrid_arr[$l]['is_multiple'] == 0 && $thrid_arr[$l]['answer_value'] == "saved"){
for($j=0; $j<count($pd_docs); $j++){
$question = $thrid_arr[$l]['question'].' '.($k+1);
// echo "\n Tilte=>".$pd_docs[$j]['pd_document_title'];echo "\n Q=>".$question;
if($pd_docs[$j]['image_key'] == $thrid_arr[$l]['question_key'] && strtoupper($pd_docs[$j]['pd_document_title']) == strtoupper($question)){
// $thrid_arr[$l]['answer_value'] = $pd_docs[$j]['doc_url'];
$json[$i]['questions_group'][$k]['questions'][$l]['answer_value'] = $pd_docs[$j]['doc_url'];
$json[$i]['questions_group'][$k]['questions'][$l]['pd_document_id'] = $pd_docs[$j]['pd_document_id'];
}
}
// print_r($thrid_arr[$l]);
}
}
}
// echo "inxx".$i;
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $json;
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'FI-Document Not Available for Given PD ID ! ';
}
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'FI-Photograph JSON Not Available for Given PD ID ! ';
}
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'PD ID Not available ! ';
}
$this->response($data, REST_Controller::HTTP_OK);
}
}