HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/barbeatleanalyti/public_html/mbaris.beatleanalytics.com/application/controllers/ApiV2.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class ApiV2 extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */

	public function stationlogin()
	{

		$this->load->model('Api_model');
		$staId = $this->input->post('stationLoginId');
		$this->db->select('baris_station.*,baris_division.DivisionName');
		$this->db->from('baris_station');
		$this->db->join('baris_division', 'baris_station.DivisionId = baris_division.DivisionId','left');
		$this->db->where('baris_station.db_stLoginId', $staId); 
		$query = $this->db->get();
		$result = $query->result();
		if($result){
			if($result[0]->DivisionName == null)$result[0]->DivisionName="";

			$response["status"] = "success";
			$response["message"] = "station found successfully";
			$response["data"] = $result[0];
			echo json_encode($response);
		}else{
			$response["status"] = "error";
			$response["message"] = "station not found";
			echo json_encode($response);
		}
		// return $this->Api_model->loginSurvey($staId); 
	}

	public function userLogin()
	{
		$this->load->model('Api_model');
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		$orgid 	= $this->input->post('orgid');
		// return $this->Api_model->endUserLogin($username,$password,$orgid); 
		$pass = md5($password);

		$SQL = "SELECT * FROM baris_userlogin WHERE db_userLoginName = '".$username."' AND db_password = '".$pass."' AND db_usertype = 'auditor' AND OrgID = ".$orgid;
		$query = $this->db->query($SQL);
		$result = $query->result();			
			

		if($result){
			$response["status"] = "success";
			$response["message"] = "auditor found successfully";
			$response["data"] = $result[0];
			echo json_encode($response);
		}else{
			$response["status"] = "error";
			$response["message"] = "auditor not found";
			echo json_encode($response);
		}
	}

	public function getquestion()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$staId = $this->input->post('stationId'); 
		$query = $this->db->get_where("baris_station" , array("stationId"=>$staId));
		$result = $query->result();
		if($result){
			$SQL = "SELECT * FROM baris_question WHERE queId in (".$result[0]->db_questionsId.") ";
			$query = $this->db->query($SQL);
			$data = $query->result();
			//return $data;
			$response["status"] = "success";
			$response["message"] = "data found successfully";
			$response["data"] = $data;
			echo json_encode($response);
		}else{
			$response["status"] = "error";
			$response["message"] = "data not found";
			echo json_encode($response);
		}
	}

	public function getsubquestionlist()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$questionId = $this->input->post('questionId'); //$_POST['stationId'];
		if(empty($questionId))
			$query = $this->db->get('baris_question');
		else
			$query = $this->db->get_where("baris_question",array("queId"=>$questionId));
		
		$question = $query->result();

		if($question){

			$subqueData = array();
			$subQuesionId = explode(',', $question[0]->subqueId);
			foreach ($subQuesionId as $value) {
				$SQL = "SELECT * FROM baris_subquestion WHERE subqueId = ".$value;
				$query = $this->db->query($SQL);
				$result = $query->result();	
				$param = array();
				$param['subqueId'] = $result[0]->subqueId;
				$param['subqueName'] = $result[0]->subqueName;
				$param['db_paramId'] = $result[0]->db_paramId;
				$param['subqueType'] = $result[0]->subqueType;
				array_push($subqueData, $param);
			}
				
			if($question){
				$response["status"] = "success";
				$response["message"] = "data found successfully";
				$response["data"] = $subqueData;
				echo json_encode($response);
			}else{
				$response["status"] = "error";
				$response["message"] = "data not found";
				echo json_encode($response);
			}
		}
	}

	public function getparamlistForSubque()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$subqueId = $this->input->post('questionId');
		$SQL = "SELECT * FROM baris_subquestion WHERE subqueId = ".$subqueId;
		$query = $this->db->query($SQL);
		$result = $query->result();	
		
		$SQL = "SELECT * FROM baris_param where paramId in (".$result[0]->db_paramId.")";
				
		$query = $this->db->query($SQL);
		$paramdata = $query->result();

		if($paramdata){
			$response["status"] = "success";
			$response["message"] = "data found successfully";
			$response["data"] = $paramdata;
			echo json_encode($response);
		}else{
			$response["status"] = "error";
			$response["message"] = "data not found";
			echo json_encode($response);
		}
	}

	public function getpageslistForSubque()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$paramId = $this->input->post('paramId');
		$pageIds = $this->input->post('pageIds');
		$orgId = $this->input->post('orgId');
		$questionId = $this->input->post('questionId');
		$subquestionId = $this->input->post('subquestionId');
		$subquetype = $this->input->post('subquetype');

		$SQL = "SELECT * FROM baris_page where pageId in (".$pageIds.") ORDER BY FIND_IN_SET(pageId,'".$pageIds."')";
		$query = $this->db->query($SQL);
		$pagedata = $query->result();

		$targetdata = "";
		if($subquetype == "manpower_log"){

			$SQL = "SELECT * FROM baris_target WHERE OrgID = ".$orgId." AND queId = ".$questionId." AND subqueId = ".$subquestionId." AND pageId = ".$paramId;
			$query = $this->db->query($SQL);
			$targetdata = $query->result();
		}

		// $SQL = "SELECT
		// baris_page.*,
		// baris_target.value
		// FROM
		// baris_page
		// LEFT JOIN baris_target ON baris_page.pageId = baris_target.pageId
		// WHERE baris_page.pageId in (".$pageIds.")
		// AND baris_target.OrgID = ".$orgId." 
		// AND baris_target.queId = ".$questionId." 
		// AND baris_target.subqueId = ".$subquestionId." 
		// ORDER BY FIND_IN_SET(baris_page.pageId,'".$pageIds."')";

		// $query = $this->db->query($SQL);
		// $pagedata = $query->result();
		if($pagedata){
			$response["status"] = "success";
			$response["message"] = "data found successfully";
			if($targetdata)
			$response["target"] = $targetdata[0]->value;
			else
			$response["target"] = "";

			$response["data"] = $pagedata;
			echo json_encode($response);
		}else{
			$response["status"] = "error";
			$response["message"] = "data not found";
			echo json_encode($response);
		}
	}

	public function getpageslist()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$questionId = $this->input->post('questionId'); //$_POST['stationId'];

		if(empty($questionId))
			$query = $this->db->get('baris_question');
		else
			$query = $this->db->get_where("baris_question",array("queId"=>$questionId));
			
		$question = $query->result();

		if($question){
			$pages	= $this->Api_model->getPagesDetails($question[0]->db_pagesId);
			if($pages){
				$response["status"] = "success";
				$response["message"] = "data found successfully";
				$response["data"] = $pages;
				echo json_encode($response);
			}else{
				$response["status"] = "error";
				$response["message"] = "data not found";
				echo json_encode($response);
			}
		}else{
			$response["status"] = "error";
			$response["message"] = "data not found";
			echo json_encode($response);
		}

	}

	public function insertUserFeedback()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$stationId 			= $this->input->post('stationId'); 
		$userId 			= $this->input->post('userId'); 
		$questionId 		= $this->input->post('questionId'); 
		$subquestionId 		= 6; 
		$coachNo 			= $this->input->post('coachNo'); 
		$coachName 			= $this->input->post('coachName'); 
		//$pageid 			= $this->input->post('questionId'); 
		$avavalue 			= $this->input->post('avavalue'); 
		$OrgID 				= $this->input->post('OrgID'); 
		$DivisionId 		= $this->input->post('DivisionId'); 
		$trainno 			= $this->input->post('trainno'); 
		$departtime 		= $this->input->post('departtime'); 
		$totalCoachCount	= $this->input->post('totalCoachCount'); 
		$tokenid			= $this->input->post('tokenid'); 
		$arrivaltime		= $this->input->post('arrivaltime'); 
		$workstarttime		= $this->input->post('workstarttime'); 
		$workcompletetime	= $this->input->post('workcompletetime'); 
		//$alldata['question'] = $this->Api_model->insertUserFeedback($stationId,$userId,$questionId,$coachName,$avavalue);

		/*for ($i=0; $i <= count($avavalue)-1; $i++){ 
    			$myArray = explode('@!#!@', $avavalue[$i]);
    			$value = mysql_real_escape_string($myArray[1]);
    			$this->Api_model->insertUserFeedback($stationId,$userId,$questionId,$coachName,$myArray[0],$value);
    		}*/

    	foreach ($avavalue as $val) {
    		$myArray = explode('@!#!@', $val);
    		$value = mysql_real_escape_string($myArray[1]);
    		$this->Api_model->insertUserFeedback($stationId,$userId,$questionId,$subquestionId,$coachNo,$coachName,$OrgID,$DivisionId,$trainno,$departtime,$totalCoachCount,$tokenid,$arrivaltime,$workstarttime,$workcompletetime,$myArray[0],$value);
    	}

		$response["status"] = "success";
		$response["message"] = "feedback inserted";
		echo json_encode($response);
		
	}

	public function insertUserFeedback_demo()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$stationId 			= $this->input->post('stationId'); 
		$userId 			= $this->input->post('userId'); 
		$questionId 		= $this->input->post('questionId'); 
		$subquestionId 		= $this->input->post('subquestionId'); 
		$coachNo 			= $this->input->post('coachNo'); 
		$coachName 			= $this->input->post('coachName'); 
		//$pageid 			= $this->input->post('questionId'); 
		$avavalue 			= $this->input->post('avavalue'); 
		$OrgID 				= $this->input->post('OrgID'); 
		$DivisionId 		= $this->input->post('DivisionId'); 
		$trainno 			= $this->input->post('trainno'); 
		$departtime 		= $this->input->post('departtime'); 
		$totalCoachCount	= $this->input->post('totalCoachCount'); 
		$tokenid			= $this->input->post('tokenid'); 
		$arrivaltime		= $this->input->post('arrivaltime'); 
		$workstarttime		= $this->input->post('workstarttime'); 
		$workcompletetime	= $this->input->post('workcompletetime'); 
		//$alldata['question'] = $this->Api_model->insertUserFeedback($stationId,$userId,$questionId,$coachName,$avavalue);

		/*for ($i=0; $i <= count($avavalue)-1; $i++){ 
    			$myArray = explode('@!#!@', $avavalue[$i]);
    			$value = mysql_real_escape_string($myArray[1]);
    			$this->Api_model->insertUserFeedback($stationId,$userId,$questionId,$coachName,$myArray[0],$value);
    		}*/

    	foreach ($avavalue as $val) {
    		$myArray = explode('@!#!@', $val);
    		$value = mysql_real_escape_string($myArray[1]);
    		$this->Api_model->insertUserFeedback_demo($stationId,$userId,$questionId,$subquestionId,$coachNo,$coachName,$OrgID,$DivisionId,$trainno,$departtime,$totalCoachCount,$tokenid,$arrivaltime,$workstarttime,$workcompletetime,$myArray[0],$value);
    	}

		$response["status"] = "success";
		$response["message"] = "feedback inserted";
		echo json_encode($response);
		
	}

	public function insertSubUserFeedback()
	{

		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$stationId 			= $this->input->post('stationId'); 
		$userId 			= $this->input->post('userId'); 
		$questionId 		= $this->input->post('questionId'); 
		$subquestionId 		= $this->input->post('subquestionId'); 
		$paramid 			= $this->input->post('paramid'); 
		//$pageid 			= $this->input->post('questionId'); 
		$avavalue 			= $this->input->post('avavalue'); 
		$OrgID 				= $this->input->post('OrgID'); 
		$DivisionId 		= $this->input->post('DivisionId'); 
		$tokenid			= $this->input->post('tokenid'); 
		$auditorname		= $this->input->post('auditorname'); 
		$extra_manpower		= $this->input->post('extra_manpower'); 


    	foreach ($avavalue as $val) {
    		$myArray = explode('@!#!@', $val);
    		$value = mysql_real_escape_string($myArray[1]);
    		$this->Api_model->insertSubUserFeedback($stationId,$userId,$questionId,$subquestionId,$paramid,$OrgID,$DivisionId,$tokenid,$auditorname,$extra_manpower,$myArray[0],$value);
    	}

		$response["status"] = "success";
		$response["message"] = "feedback inserted";
		echo json_encode($response);
		
	}

	public function deleteOngoingReport()
	{
		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$tokenid = $this->input->post('tokenid'); //$_POST['stationId'];
		$alldata['question'] = $this->Api_model->deleteOngoingReport($tokenid);
		return $alldata['question'];
	}

	public function getOngoingReportforshift()
	{
		$this->load->model('Api_model');
		//$this->load->model('Admin_model');
		$stationId 		= $this->input->post('stationId');
		$userId 		= $this->input->post('userId');
		$questionId 	= $this->input->post('questionId');
		$subqueId 		= $this->input->post('subqueId');
		
		$alldata['question'] = $this->Api_model->getOngoingReportforshift($stationId,$userId,$questionId,$subqueId);
		return $alldata['question'];
	}

	public function uploadImageReport()
	{
		$this->load->model('Api_model');
		$stationId 		= $this->input->post('stationId');
		$userId 		= $this->input->post('userId');
		$processtype 		= $this->input->post('processtype');
		$orgID 		= $this->input->post('orgID');
		$divisionId 		= $this->input->post('DivisionId');
		$remarks 		= $this->input->post('remarks');

		return $this->Api_model->uploadImageReport($stationId,$userId,$processtype,$orgID,$divisionId,$remarks);
		 
	}

	public function getTarget()
	{
		$this->load->model('Api_model');
		$orgID 			= $this->input->post('orgID');
		$questionId 	= $this->input->post('questionId');
		$subqueId 		= $this->input->post('subqueId');
		$paramid 		= $this->input->post('paramid');
		
		return $this->Api_model->getTarget($orgID,$questionId,$subqueId,$paramid);
	}

}