From Violet Gorilla, 3 Years ago, written in PHP.
This paste is a reply to test1 from test1
- view diff
Embed
  1. <?php
  2.  
  3. // ##############################################################################
  4. // ASTPP - Open Source VoIP Billing Solution
  5. //
  6. // Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
  7. // Samir Doshi <samir.doshi@inextrix.com>
  8. // ASTPP Version 3.0 and above
  9. // License https://www.gnu.org/licenses/agpl-3.0.html
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU Affero General Public License as
  13. // published by the Free Software Foundation, either version 3 of the
  14. // License, or (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU Affero General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU Affero General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. // ##############################################################################
  24. class Frauddetection extends CI_Controller
  25. {
  26.  
  27.     function __construct()
  28.     {
  29.         parent::__construct();
  30.         $this->load->helper('template_inheritance');
  31.         $this->load->library('session');
  32.         $this->load->library("frauddetection_form");
  33.         // $this->load->library('astpp/form');
  34.         $this->load->library('astpp/form',"frauddetection_form");
  35.         $this->load->model('frauddetection_model');
  36.         $this->load->library('csvreader');
  37.         $this->load->library('ASTPP_Sms');
  38.         if ($this->session->userdata('user_login') == FALSE)
  39.             redirect(base_url() . '/astpp/login');
  40.     }
  41.  
  42.     function frauddetection_list()
  43.     {
  44.             $data['page_title'] = gettext('Fraud Detection');
  45.             $data['search_flag'] = true;
  46.             $this->session->set_userdata('advance_search', 0);
  47.             $data['grid_fields'] = $this->frauddetection_form->build_frauddetection_list_for_admin();
  48.             $data["grid_buttons"] = $this->frauddetection_form->build_grid_buttons();
  49.             $data['form_search'] = $this->form->build_serach_form($this->frauddetection_form->get_search_frauddetection_form());
  50.             $this->load->view('view_frauddetection_list', $data);
  51.         }
  52.  
  53.     function frauddetection_list_json()
  54.     {
  55.         $json_data = array();
  56.         $count_all = $this->frauddetection_model->get_frauddetection_list(false);
  57.         $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
  58.         $json_data = $paging_data["json_paging"];
  59.         $query = $this->frauddetection_model->get_frauddetection_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
  60.         //print_r($this->db->last_query()); die;
  61.         $grid_fields = json_decode($this->frauddetection_form->build_frauddetection_list_for_admin());
  62.         $json_data['rows'] = $this->form->build_grid($query, $grid_fields);
  63.         echo json_encode($json_data);
  64.     }
  65.  
  66.     function frauddetection_add($type = "")
  67.     {
  68.         $data['username'] = $this->session->userdata('user_name');
  69.         $data['flag'] = 'create';
  70.         $data['page_title'] = gettext('Create Fraud Detection');
  71.         $data['form'] = $this->form->build_form($this->frauddetection_form->get_frauddetection_form_fields(), '');
  72.         $country_array              = array();
  73.                 $this->db->select('id,country,countrycode');
  74.                 $country_array=$this->db->get('countrycode')->result_array();
  75.                 $data['CountryListArr']  = $country_array;
  76.         $this->load->view('view_frauddetection_add_edit', $data);
  77.     }
  78.  
  79.     function frauddetection_edit($edit_id = '')
  80.     {
  81.         $accountinfo = $this->session->userdata('accountinfo');
  82.         if ($accountinfo['type'] == - 1 || $accountinfo['type'] == 2) {
  83.             $data['page_title'] = gettext('Edit Fraud Detection');
  84.             $where = array(
  85.                 'id' => $edit_id
  86.             );
  87.             $account = $this->db_model->getSelect("*", "fraud_conf", $where);
  88.             $edit_data = $account->row_array();
  89.             $data['form'] = $this->form->build_form($this->frauddetection_form->get_frauddetection_form_fields($edit_id), $edit_data);
  90.             $data['filter'] = $edit_data['filter'];
  91.             $this->load->view('view_frauddetection_add_edit', $data);
  92.         } else {
  93.             $this->session->set_flashdata('astpp_notification', gettext('Permission Denied!'));
  94.             redirect(base_url() . 'frauddetection/frauddetection_list/');
  95.             exit();
  96.         }
  97.     }
  98.  
  99.      function frauddetection_save()
  100.     {
  101.         $add_array = $this->input->post();
  102.         $data['form'] = $this->form->build_form($this->frauddetection_form->get_frauddetection_form_fields($add_array['id']), $add_array);
  103.         if ($add_array['id'] != '') {
  104.             $data['page_title'] = gettext('Edit Frauddetection');
  105.                 if ($this->form_validation->run() == FALSE) {
  106.                 $data['validation_errors'] = validation_errors();
  107.                 echo $data['validation_errors'];
  108.                 exit();
  109.                 } else {
  110.                 $filter='';
  111.                 if($add_array['filter_by'] == 'PER_COUNTRY' || $add_array['filter_by'] == 'GRP_BY_COUNTRY'){
  112.                                  foreach ($add_array['filter'] as $key => $value) {
  113.                                         $filter .= $value . ',';
  114.                                 }
  115.                         }else{
  116.                                 foreach ($add_array['filter'] as $key => $value) {
  117.                                         $filter .= '^'. $value . '.*,';
  118.                                 }
  119.                         }
  120.                 $filter=rtrim($filter,',');
  121.                 $add_array['filter']=$filter;
  122.                 $this->frauddetection_model->edit_frauddetection($add_array, $add_array['id']);
  123.                 echo json_encode(array(
  124.                 "SUCCESS" => $add_array["access_number"] . gettext("Frauddetection Updated Successfully!")
  125.                 ));
  126.                 exit();
  127.                 }
  128.         } else {
  129.                 $data['page_title'] = gettext('frauddetection Details');
  130.                 if ($this->form_validation->run() == FALSE) {
  131.                     $data['validation_errors'] = validation_errors();
  132.                     echo $data['validation_errors'];
  133.                     exit();
  134.                 } else {
  135.                     $filter='';
  136.                     if($add_array['filter_by'] == 'PER_COUNTRY' || $add_array['filter_by'] == 'GRP_BY_COUNTRY'){
  137.                                  foreach ($add_array['filter'] as $key => $value) {
  138.                                         $filter .= $value . ',';
  139.                                 }
  140.                         }else{
  141.                                 foreach ($add_array['filter'] as $key => $value) {
  142.                                         $filter .= '^'. $value . '.*,';
  143.                                 }
  144.                         }
  145.                     $filter=rtrim($filter,',');
  146.                     $add_array['filter']=$filter;
  147.                     $this->frauddetection_model->add_frauddetection($add_array);
  148.                     echo json_encode(array(
  149.                         "SUCCESS" => $add_array["access_number"] . gettext("Frauddetection Added Successfully!")
  150.                     ));
  151.                     exit();
  152.                 }
  153.             }
  154.     }
  155.  
  156.     function frauddetection_list_search()
  157.     {
  158.         $ajax_search = $this->input->post('ajax_search', 0);
  159.         // echo 123122;exit;
  160.         if ($this->input->post('advance_search', TRUE) == 1) {
  161.             $this->session->set_userdata('advance_search', $this->input->post('advance_search'));
  162.             $action = $this->input->post();
  163.             // print_r($action['name']);exit;
  164.             unset($action['action']);
  165.             unset($action['advance_search']);
  166.             $this->session->set_userdata('frauddetection_list_search', $action);
  167.         }
  168.         if (@$ajax_search != 1) {
  169.             redirect(base_url() . 'frauddetection/frauddetection_list/');
  170.         }
  171.     }
  172.  
  173.     function frauddetection_list_clearsearchfilter()
  174.     {
  175.         $this->session->set_userdata('advance_search', 0);
  176.         $this->session->set_userdata('frauddetection_list_search', "");
  177.     }
  178.  
  179.     function frauddetection_remove($id)
  180.     {
  181.         $this->frauddetection_model->remove_frauddetection($id);
  182.         $this->session->set_flashdata('astpp_notification', gettext('Frauddetection Removed Successfully!'));
  183.         redirect(base_url() . 'frauddetection/frauddetection_list/');
  184.     }
  185.    
  186.     function frauddetection_multiple_delete()
  187.     {
  188.         $ids = $this->input->post("selected_ids", true);
  189.         $where = "id IN (" . $ids . ")";
  190.         $this->db->where($where);
  191.         echo $this->db->delete("fraud_conf");
  192.     }
  193.  
  194.     /*function frauddetection_filter_by()
  195.     {
  196.         $filter_value = $_POST['filter'];
  197.         $filter_array = explode(',',$filter_value);
  198.         $filter_by = $_POST['filter_by'];
  199.         $filter = array();
  200.         if(!empty($filter_array)){
  201.                     foreach($filter_array as $key => $value) {
  202.                             $filter[$key] = ltrim(rtrim($value,'.*'),'^');
  203.                             }
  204.                     }
  205.                 if($filter_by != '' ) {
  206.                 if($filter_by == "PER_DST_PREFIX" || $filter_by == "GRP_BY_PREFIX" ) {
  207.                       $this->db->where('status',0);
  208.                       $this->db->where('id',1);
  209.                       $this->db->select('pattern');
  210.                       $this->db->group_by('pattern');
  211.                       $accounts_arrays=$this->db->get('routes')->result_array();
  212.                       foreach($accounts_arrays as $key => $accounts_array) {
  213.                             $accounts[ltrim(rtrim($accounts_array['pattern'],'.*'),'^')] = ltrim(rtrim($accounts_array['pattern'],'.*'),'^');
  214.                       }
  215.                       $did_info = array("name" => "filter[]", "id" => "filter_value_new", "class" => "form-control");
  216.                       echo form_dropdown_multiselect($did_info, $accounts, $filter);
  217.                       exit;
  218.                 } else {
  219.                     $this->db->select('id,country');
  220.                     $this->db->group_by('countrycode');
  221.                     $accounts_arrays=$this->db->get('countrycode')->result_array();
  222.                     $accounts = array();
  223.                     foreach($accounts_arrays as $key => $accounts_array) {
  224.                            $accounts[$accounts_array['id']] = $accounts_array['country'];
  225.                     }
  226.                     $did_info = array("name" => "filter[]", "id" => "filter_value_new", "class" => "form-control");
  227.                     echo form_dropdown_multiselect($did_info, $accounts, $filter);
  228.                     exit;
  229.             }
  230.                                 return false;
  231.             }
  232.      }*/
  233.  
  234.      function frauddetection_filter_by()
  235.     {
  236.         $filter_value = $_POST['filter'];
  237.         $filter_array = explode(',',$filter_value);
  238.         $filter_by = $_POST['filter_by'];
  239.         $filter = array();
  240.         if(!empty($filter_array)){
  241.                     foreach($filter_array as $key => $value) {
  242.                             $filter[$key] = ltrim(rtrim($value,'.*'),'^');
  243.                             }
  244.                     }
  245.                 if($filter_by != '' ) {
  246.                         if($filter_by == "PER_DST_PREFIX" || $filter_by == "GRP_BY_PREFIX" ) {
  247.                         $where = array("status"=>0, "pricelist_id"=>1);
  248.                       $this->db->where($where);
  249.                       $this->db->select("pattern");
  250.                       $this->db->group_by('pattern');
  251.                       $accounts_arrays=$this->db->get('routes')->result_array();
  252.                       //echo "<pre>"; print_r($accounts_arrays); exit;
  253.                       //echo $this->db->last_query(); exit;
  254.                           /*foreach($accounts_arrays as $key => $accounts_array) {
  255.                             $accounts[ltrim(rtrim($accounts_array['pattern'],'.*'),'^')] = ltrim(rtrim($accounts_array['pattern'],'.*'),'^');
  256.                       }*/
  257.                           $did_info = array("name" => "filter[]", "id" => "filter_value_new", "class" => "form-control");
  258.                           echo $this->build_dropdown_pattern($did_info, $accounts_arrays, $filter);
  259.                           exit;
  260.                 } else {
  261.                     $this->db->select('id,country');
  262.                     //$this->db->group_by('countrycode');
  263.                     $accounts_arrays=$this->db->get('countrycode')->result_array();
  264.                     $accounts = array();
  265.                     foreach($accounts_arrays as $key => $accounts_array) {
  266.                            $accounts[$accounts_array['id']] = $accounts_array['country'];
  267.                     }
  268.                     //echo "<pre>"; print_r($accounts); exit;
  269.                     $did_info = array("name" => "filter[]", "id" => "filter_value_new", "class" => "form-control");
  270.                     echo $this->build_dropdown_pattern($did_info, $accounts, $filter,"","country");
  271.                     exit;
  272.             }
  273.                                 return false;
  274.             }
  275.         }
  276.  
  277.          function build_dropdown_pattern($name = '', $options = array(), $selected = array(), $extra = '', $flag='')
  278.     {
  279.         if ( ! is_array($selected))
  280.         {
  281.             $selected = array($selected);
  282.         }
  283. //echo "<pre>"; print_r($selected); exit;
  284.         if ($extra != '') {
  285.             $extra = ' '.$extra;
  286.         }
  287.  
  288.         $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
  289.         $form = '<select name="filter[]"'." id='filter_value_new' multiple='multiple' class='orm-control selectpicker select field multiselectable col-md-12 form-control form-control-lg' data-hide-disabled='true' data-actions-box='true'>\n";
  290.  
  291.         foreach ($options as $key => $val)
  292.         {
  293.             //echo "<pre>"; print_r($val); exit;
  294.             if(isset($val['pattern']) && $val['pattern'] != ""){
  295.                 $key = (string)$val['pattern'];
  296.                 $final_val=ltrim(rtrim($val['pattern'],'.*'),'^');
  297.                 $sel = (in_array($final_val, $selected)) ? ' selected="selected"' : '';
  298.                 //$final_val=ltrim(rtrim($val['pattern'],'.*'),'^');
  299.                 $form .= "<option value='".$final_val."'".$sel.">".$final_val."</option>\n";
  300.             }else{
  301.                 if($flag != ''){
  302.                         $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
  303.                         $form .= "<option value='".$val."'".$sel.">".$val."</option>\n";
  304.                 }else{
  305.                         $key = $val;        
  306.                         $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
  307.                         $form .= "<option value='".$val."'".$sel.">".$val."</option>\n";
  308.                 }
  309.             }
  310. /*
  311.             $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
  312.            
  313.             $final_val=ltrim(rtrim($val['pattern'],'.*'),'^');
  314.             $form .= "<option value='".$final_val."'".$sel.">".$final_val."</option>\n";
  315.  */          
  316.         }
  317.  
  318.         $form .= '</select>';
  319.  
  320.         return $form;
  321.     }
  322.  
  323. }
  324. ?>