Are you a regular stikked user? Signup so you can keep track of your pastes!
  1. <?php
  2.  
  3. class Providers extends Controller {
  4.  
  5.         function Providers()
  6.         {
  7.                 parent::Controller();  
  8.         }
  9.        
  10.         function index()
  11.         {
  12.                 $this->load->view('providers');
  13.         }
  14.         function add()
  15.         {
  16.                 $this->load->view('add');
  17.         }
  18.         function addnew()
  19.         {
  20.                 if($_REQUEST['act']=='add')
  21.                 {
  22.                         $this->load->library('form_validation');
  23.                         $this->form_validation->set_error_delimiters('<li>', '</li>');
  24.                         $this->form_validation->set_rules('name', 'Name', 'trim|required');
  25.                         $this->form_validation->set_rules('address', 'Address', 'required');
  26.                         $this->form_validation->set_rules('city', 'City', 'trim|required');
  27.                         $this->form_validation->set_rules('state', 'State', 'required');
  28.                         $this->form_validation->set_rules('zip', 'Zip Code', 'trim');
  29.                         $this->form_validation->set_rules('facility', 'Facility', 'required');
  30.                         $this->form_validation->set_rules('minage', 'Min Age', '');
  31.                         $this->form_validation->set_rules('maxage', 'Max Age', '');
  32.                         $this->form_validation->set_rules('licensed', 'Licensed', '');
  33.                         $this->form_validation->set_rules('licensedcap', 'licensedcap', 'integer|exact_length[3]');
  34.                         $this->form_validation->set_rules('website', 'Website', 'prep_url');
  35.                         $this->form_validation->set_rules('phone', 'Phone', 'exact_length[12]');
  36.                         $this->form_validation->set_rules('weeklyrate', 'Weekly Rate', '');
  37.                         $this->form_validation->set_rules('monthlyrate', 'Monthly Rate', '');
  38.                        
  39.                         if($this->form_validation->run()==FALSE)
  40.                         {
  41.                                 $sarr['qiws']='no';
  42.                         }
  43.                         else
  44.                         {
  45.                                 $sarr['qiws']='yes';
  46.                                 $data=array(
  47.                                                         'name'=>set_value('name'),
  48.                                                         'address'=>set_value('address'),
  49.                                                         'state'=>set_value('state'),
  50.                                                         'city'=>set_value('city'),
  51.                                                         'facility'=>set_value('facility'),
  52.                                                         'weeklyrate'=>set_value('weeklyrate'),
  53.                                                         'monthlyrate'=>set_value('monthlyrate'),
  54.                                                         'minage'=>set_value('minage'),
  55.                                                         'maxage'=>set_value('maxage'),
  56.                                                         'licensed'=>set_value('licensed'),
  57.                                                         'licensedcap'=>set_value('licensedcap'),
  58.                                                         'website'=>set_value('website'),
  59.                                                         'licensed'=>set_value('licensed'),
  60.                                                         'website'=>set_value('website'),
  61.                                                         'zip'=>set_value('zip'),
  62.                                                         'phone'=>set_value('phone'),
  63.                                                         'ip'=>$this->input->ip_address(),
  64.                                                         );
  65.                                 //var_dump($_POST);exit();
  66.                                 //$this->db->_compile_select();
  67.                                 $this->db->insert('providers',$data);
  68.                                 //exit($this->db->last_query());
  69.                                 $sarr['id']=$this->db->insert_id();
  70.                         }
  71.                 }
  72.                 $this->load->view('addnew',$sarr);
  73.         }
  74.         function rate($id)
  75.         {
  76.                 $provider=$this->f->getprovider($id);
  77.                 if($provider==0)
  78.                 {
  79.                         redirect('providers');
  80.                 }
  81.                 $sarr=array();
  82.                 if($_REQUEST['act']== 'rate')
  83.                 {
  84.                         $this->load->library('form_validation');
  85.                         $this->form_validation->set_error_delimiters('<li>', '</li>');
  86.                         $this->form_validation->set_rules('staff', 'Staff', 'required|integer');
  87.                         $this->form_validation->set_rules('facilities', 'Facilities', 'required|integer');
  88.                         $this->form_validation->set_rules('activities', 'Activities', 'required|integer');
  89.                         $this->form_validation->set_rules('personal_attention', 'Personal Attention', 'required|integer');
  90.                         $this->form_validation->set_rules('monetary_value', 'Monetary Value', 'required|integer');
  91.                         $this->form_validation->set_rules('location', 'Location', 'required|integer');
  92.                         $this->form_validation->set_rules('review', 'Review', 'trim|max_length[1000]');
  93.                         if($this->form_validation->run()==FALSE)
  94.                         {
  95.                                 $sarr['qiws']='no';
  96.                         }
  97.                         else
  98.                         {
  99.                                 $sarr['qiws']='yes';
  100.                                 $total=(set_value('staff')+set_value('facilities')+set_value('activities')+set_value('personal_attention')+set_value('monetary_value')+set_value('location'))/6;
  101.                                 $data=array(
  102.                                                         'providerid'=>$id,
  103.                                                         'staff'=>set_value('staff'),
  104.                                                         'facilities'=>set_value('facilities'),
  105.                                                         'activities'=>set_value('activities'),
  106.                                                         'personal_attention'=>set_value('personal_attention'),
  107.                                                         'monetary_value'=>set_value('monetary_value'),
  108.                                                         'location'=>set_value('location'),
  109.                                                         'total'=>$total,
  110.                                                         'review'=>set_value('review'),
  111.                                                         'ipaddress'=>$this->input->ip_address(),
  112.                                                         'userid'=>$this->session->userdata('userid'),
  113.                                                         );
  114.                                 $this->db->insert('rates',$data);
  115.                                 $sql="UPDATE providers, (SELECT avg(`total`) as point, count(`id`) as norating FROM rates WHERE providerid = '$id') as A SET providers.point = A.point, providers.norating = A.norating WHERE id = '$id'";
  116.                                 $this->db->query($sql);
  117.                                 redirect('providers/view/'.$id);
  118.                         }
  119.                 }
  120.                 $this->load->view('rate',$provider+$sarr);
  121.         }
  122.         function view($id)
  123.         {
  124.                 $provider=$this->f->getprovider($id);
  125.                 if($provider==0)
  126.                 {
  127.                         redirect('providers');
  128.                 }
  129.                 $sarr=array();
  130.                 $query=$this->db->get_where('rates',array('providerid'=>$id));
  131.                 if($query->num_rows()>0)
  132.                 {
  133.                         $sarr['ratesArr']=$query->result_array();
  134.                 }
  135.                 else
  136.                 {
  137.                         redirect('providers/rate/'.$id);
  138.                 }
  139.                 $this->load->view('view',$provider+$sarr);
  140.         }
  141.         function viewlist($type,$state)
  142.         {
  143.                 $this->db->start_cache();
  144.                 if($type=='state'&&strlen($state)==2)
  145.                 {
  146.                         $this->db->where('state',$state);
  147.                         $suburl = '/state/'.$state.'/';
  148.                 }
  149.                 $this->db->stop_cache();
  150.                 $this->load->library('pagination');
  151.                 $config['base_url'] = site_url().'providers/viewlist/'.$suburl.'?submit=page';
  152.                 $config['total_rows'] = $this->db->count_all_results('providers');
  153.                 $config['per_page'] = '20';
  154.                 $this->pagination->initialize($config);
  155.                 $query = $this->db->get('providers', 20, $_GET['per_page']);
  156.                 $queryArr=$query->result_array();
  157.                 $sarr=array('state'=>$state,'queryArr'=>$queryArr);
  158.                 $this->db->flush_cache();
  159.                 $this->load->view('list',$sarr);
  160.         }
  161.         function search()
  162.         {
  163.                 $currentUrl = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  164.                 if($_REQUEST['act']=='search')
  165.                 {
  166.                         $this->db->start_cache();
  167.                         extract($_GET);
  168.                         $this->db->where(array('status'=>1));
  169.                         if(!empty($name))
  170.                         {
  171.                                 $this->db->like(array('name'=>$name));
  172.                         }
  173.                         if(!empty($address))
  174.                         {
  175.                                 $this->db->like(array('address'=>$address));
  176.                         }
  177.                         if(!empty($state))
  178.                         {
  179.                                 $this->db->where(array('state'=>$state));
  180.                         }
  181.                         if(!empty($city))
  182.                         {
  183.                                 $this->db->like(array('city'=>$city));
  184.                         }
  185.                         if(is_array($facility))
  186.                         {
  187.                                 if(count($facility)!=4)
  188.                                 {
  189.                                         $sqlx="(";
  190.                                         $i=0;
  191.                                         foreach($facility as $val)
  192.                                         {
  193.                                                 $i++;
  194.                                                 if($i!=1)
  195.                                                 {
  196.                                                         $sqlx.=' OR ';
  197.                                                 }
  198.                                                 $sqlx.="facility = '$val'";
  199.                                         }
  200.                                         $sqlx.=")";
  201.                                         $this->db->where($sqlx);
  202.                                 }
  203.                         }
  204.                         if(is_numeric($minage))
  205.                         {
  206.                                 $this->db->where(array('minage'=>$minage));
  207.                         }
  208.                         if(is_numeric($maxage))
  209.                         {
  210.                                 $this->db->where(array('maxage'=>$maxage));
  211.                         }
  212.                         if(!empty($weeklyrate))
  213.                         {
  214.                                 $this->db->where(array('weeklyrate'=>$weeklyrate));
  215.                         }
  216.                         if(!empty($monthlyrate))
  217.                         {
  218.                                 $this->db->where(array('monthlyrate'=>$monthlyrate));
  219.                         }
  220.                         if(is_array($licensed))
  221.                         {
  222.                                 if(count($facility)!=4)
  223.                                 {
  224.                                         $sqlx="(";
  225.                                         $i=0;
  226.                                         foreach($licensed as $val)
  227.                                         {
  228.                                                 $i++;
  229.                                                 if($i!=1)
  230.                                                 {
  231.                                                         $sqlx.=' OR ';
  232.                                                 }
  233.                                                 $sqlx.="licensed = '$val'";
  234.                                         }
  235.                                         $sqlx.=")";
  236.                                         $this->db->where($sqlx);
  237.                                 }
  238.                         }
  239.                         if(!empty($website))
  240.                         {
  241.                                 $this->db->like(array('website'=>$website));
  242.                         }
  243.                         if(!empty($zip))
  244.                         {
  245.                                 $this->load->library('zipcode');
  246.                                 if(!empty($distance))
  247.                                 {
  248.                                         $zips = $this->zipcode->get_zips_in_range(substr($zip,0,5), $distance, _ZIPS_SORT_BY_DISTANCE_ASC, true);
  249.                                         //var_dump($zips);
  250.                                         if($zips != false)
  251.                                         {
  252.                                                 $sqlx="(";
  253.                                                 foreach($zips as $field=>$value)
  254.                                                 {
  255.                                                         if($sqlx!='(')
  256.                                                         {
  257.                                                                 $sqlx.= " OR ";
  258.                                                         }
  259.                                                         $sqlx.="zip LIKE '%$field%'";
  260.                                                 }
  261.                                                 $sqlx.=")";
  262.                                                 //echo $sqlx;
  263.                                                 $this->db->where($sqlx);
  264.                                         }
  265.                                         else
  266.                                         {
  267.                                                 $this->db->like(array('zip'=>$zip));
  268.                                         }
  269.                                 }
  270.                                 else
  271.                                 {
  272.                                         $this->db->like(array('zip'=>$zip));
  273.                                 }
  274.                         }
  275.                         $this->db->stop_cache();
  276.                         $query = $this->db->get('providers', 20, $_GET['per_page']);
  277.                         $queryArr=$query->result_array();
  278.                         $sarr=array('queryArr'=>$queryArr);
  279.  
  280.                         $this->load->library('pagination');
  281.                         $config['base_url'] = $currentUrl;
  282.                         $config['total_rows'] = $this->db->count_all_results('providers');
  283.                         $config['per_page'] = '20';
  284.                         $this->pagination->initialize($config);
  285.                         $this->db->flush_cache();
  286.                         $this->load->view('listsearch',$sarr);
  287.                 }
  288.                 else
  289.                 {
  290.                         $this->load->view('search');
  291.                 }
  292.         }
  293.         function report($type,$id)
  294.         {
  295.                 if($type=='p')
  296.                 {
  297.                         $query=$this->db->get_where('providers',array('id'=>$id));
  298.                         if($query->num_rows()==0)
  299.                         {
  300.                                 redirect('providers');
  301.                         }
  302.                         $data=$query->result_array();
  303.                         if($_REQUEST['act']=='report')
  304.                         {
  305.                                 if(!empty($_POST['msg']))
  306.                                 {
  307.                                         $this->db->insert('reports',array('type'=>'p','pfid'=>$id,'msg'=>$_POST['msg'],'ip'=>$this->input->ip_address()));
  308.                                         $data[0]['qiws']=1;
  309.                                 }
  310.                                 else
  311.                                 {
  312.                                         $data[0]['qiws']=0;
  313.                                 }
  314.                         }
  315.                         $this->load->view('correct_provider',$data[0]);
  316.                 }
  317.                 elseif($type=='f')
  318.                 {
  319.                         $query=$this->db->get_where('rates',array('id'=>$id));
  320.                         if($query->num_rows()==0)
  321.                         {
  322.                                 redirect('rates');
  323.                         }
  324.                         $data=$query->result_array();
  325.                         if($_REQUEST['act']=='report')
  326.                         {
  327.                                 if(!empty($_POST['msg']))
  328.                                 {
  329.                                         $this->db->insert('reports',array('type'=>'f','pfid'=>$id,'msg'=>$_POST['msg'],'ip'=>$this->input->ip_address()));
  330.                                         $data[0]['qiws']=1;
  331.                                 }
  332.                                 else
  333.                                 {
  334.                                         $data[0]['qiws']=0;
  335.                                 }
  336.                         }
  337.                         $this->load->view('correct_ratings',$data[0]);
  338.                 }
  339.                 else
  340.                 {
  341.                         redirect('providers');
  342.                 }
  343.         }
  344.         function respond($type,$id)
  345.         {
  346.                 if($this->session->userdata('logged_in')!=true)
  347.                 {
  348.                         redirect('login');
  349.                 }
  350.                 if($type=='f')
  351.                 {
  352.                         $query=$this->db->get_where('rates',array('id'=>$id));
  353.                         if($query->num_rows()==0)
  354.                         {
  355.                                 redirect('rates');
  356.                         }
  357.                         $data=$query->result_array();
  358.                         if($_REQUEST['act']=='respond')
  359.                         {
  360.                                 if(!empty($_POST['message']))
  361.                                 {
  362.                                         $this->db->insert('feedbacks',array(
  363.                                                                                                                 'rateid'=>$id,
  364.                                                                                                                 'message'=>$_POST['message'],
  365.                                                                                                                 'ip'=>$this->input->ip_address(),
  366.                                                                                                                 'userid'=>$this->session->userdata('userid'),
  367.                                                                                                                 ));
  368.                                        
  369.                                         $this->db->where('id', $id);
  370.                                         $this->db->update('rates', array('respond'=>1));
  371.                                         $data[0]['qiws']=1;
  372.                                 }
  373.                                 else
  374.                                 {
  375.                                         $data[0]['qiws']=0;
  376.                                 }
  377.                         }
  378.                         $this->load->view('respond',$data[0]);
  379.                 }
  380.                 else
  381.                 {
  382.                         redirect('providers');
  383.                 }
  384.         }
  385. }
  386. ?>

Reply to "Untitled"

Here you can reply to the paste above

Create a snipurl

Make Private

Feeling clever? Set some advanced options.