<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Ourapplicationprogramminginterface extends CI_Controller {
    
  function __construct(){
    parent::__construct();    
    $this->load->model('m_masters');
        $this->load->helper(array('url','html','form'));
        $this->load->library('session');
    ini_set('max_execution_time', 0);    
    ini_set('memory_limit', '20000M');
    date_default_timezone_set("Asia/Jakarta");

  }
 
 
  public function index()
  {
    //   show_404($page = 'gasdgasdg', $log_error = TRUE);
       echo "hahahahahaha";
  }
  
  public function getwebutilities()
  {
    $fromjsondata = (array)json_decode(file_get_contents('php://input'));
    $this->form_validation->set_data($fromjsondata);
    $this->form_validation->set_rules('web', 'web', 'required|xss_clean');
    $this->form_validation->set_rules('password', 'password', 'required|xss_clean');
    $this->form_validation->set_rules('namabrand', 'namabrand', 'required|xss_clean');
    
    if ($this->form_validation->run() == FALSE)
    {
      // print_r($fromjsondata);
      $response['queryresult'] = validation_errors();
      $this->output
      ->set_status_header(400)
      ->set_content_type('application/json', 'utf-8')
      ->set_output(json_encode($response, JSON_PRETTY_PRINT))
      ->_display();
      exit;
    }
    else
    {
      $querystring = "select * from apipassword where web = '".$fromjsondata['web']. "' and `password` = '".$fromjsondata['password']. "'";
      $authentication = $this->m_masters->querying($querystring)->result();
      if (count($authentication) < 1)
      {
          $response['queryresult'] = "We would like you to leave! You doesnt pass the authentication phase!";
          $this->output
          ->set_status_header(400)
          ->set_content_type('application/json', 'utf-8')
          ->set_output(json_encode($response, JSON_PRETTY_PRINT))
          ->_display();
          exit;
      }
      else
      {
          $namabrand = $fromjsondata['namabrand'];
          $querywebutilities = "select * from tb_amp_seo where nama_brand = '".$namabrand."'";
          $querythis = $this->m_masters->querying($querywebutilities);
          $queryresult = $this->db->affected_rows();
          if($queryresult < 0)
          {
            $response['queryresult'] = "Data Update Error!";
          }
          else
          {
            $response['queryresult'] = $querythis->result();
          }
          $this->output
          ->set_status_header(400)
          ->set_content_type('application/json', 'utf-8')
          ->set_output(json_encode($response, JSON_PRETTY_PRINT))
          ->_display();
          exit;
      }
    }
  }
}