Advertisement
Guest User

Codeigniter

a guest
Jan 5th, 2013
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.58 KB | None | 0 0
  1. <?php
  2. class Testimonials extends CI_Controller
  3. {
  4.  
  5. public $data = array();
  6. /*============*/
  7. // constructor
  8. /*============*/
  9. function __construct()
  10. {
  11.     parent::__construct();
  12.     $this->load->library('pagination');
  13.  
  14.     $this->load->model('admin/admin_model');
  15.     $this->load->model('admin/testimonials_model');
  16.     $this->load->model('admin/testimonials_config_model');
  17.  
  18.    
  19.     if(!$this->admin_model->validate_session())
  20.         {
  21.             die('you do not have permission');
  22.         }
  23.     else {
  24.        
  25.         //load required models
  26.    
  27.         //initialize variables
  28.         $this->data['change_settings'] = FALSE;
  29.         $this->data['atleast_one_required_field'] = TRUE;
  30.         $this->data['testimonials_p_p_error'] = FALSE;
  31.     }
  32.  
  33.  
  34.  
  35. }
  36.  
  37. /*=============*/
  38. // index
  39. /*=============*/
  40. public function index()
  41. {
  42.    
  43.     $this->load->view('admin/testimonials_view',$this->data);
  44. }
  45.  
  46. /*================*/
  47. // change_settings
  48. /*================*/
  49. public function change_settings()
  50. {
  51.  
  52.     $testimonial_required_fields_setting = 0;
  53.     $testimonial_required_fields_setting = $this->input->post('tc_require_phone') === 'true' ? $testimonial_required_fields_setting+1 : $testimonial_required_fields_setting;
  54.     $testimonial_required_fields_setting = $this->input->post('tc_require_email') === 'true' ? $testimonial_required_fields_setting+1 : $testimonial_required_fields_setting;
  55.     $testimonial_required_fields_setting = $this->input->post('tc_require_website') === 'true' ? $testimonial_required_fields_setting+1 : $testimonial_required_fields_setting;
  56.  
  57.     if($testimonial_required_fields_setting > 0)
  58.         {
  59.             $this->testimonials_config_model->update_required_fields();
  60.             $this->data['atleast_one_required_field'] = TRUE;
  61.             $this->data['change_settings'] = TRUE; }
  62.         else {
  63.                 $this->data['atleast_one_required_field'] = FALSE;
  64.                 $this->data['change_settings'] = FALSE; }
  65.                
  66. //check testimonials per page setting      
  67. if( ($this->input->post('tc_testimonials_per_page') > 15) || ($this->input->post('tc_testimonials_per_page') <= 4))
  68. {
  69.     $this->data['testimonials_p_p_error'] = TRUE;
  70. }else{
  71.     $this->testimonials_config_model->set_config_value_plain('displayed_per_page',$this->input->post('tc_testimonials_per_page'));
  72. }
  73.     $this->index();
  74. }
  75.  
  76. /*==========*/
  77. // approve
  78. /*==========*/
  79. public function approve($option = null, $id = null) {
  80.  
  81. $this->data['approved']= false;
  82. $this->data['deleted']=false;
  83.  
  84. if(strcasecmp($option, 'yes')==0)
  85.     {
  86.         $approve = array('testimonial_approved'=>1);
  87.         $this->db->where('id',$id);
  88.         $this->db->update('nv_cms_testimonials',$approve);
  89.         $this->data['approved']=true;
  90.     }
  91. elseif(strcasecmp($option, 'no') == 0)
  92.     {
  93.         $this->db->delete('nv_cms_testimonials',array('id'=>$id));
  94.         $this->data['deleted']=true;
  95.        
  96.     }
  97. $this->data['new_testimonials'] = $this->testimonials_model->get_new_testimonials();
  98. $this->load->view('admin/testimonials_approve_view.php',$this->data);
  99. }
  100.  
  101. /*=========*/
  102. // manage  
  103. /*=========*/
  104. public function manage($action = null, $id = null) {
  105.  
  106.  
  107.     $this->load->model('admin/testimonials_model');
  108.  
  109.  
  110. $this->data['deleted'] = false;
  111.  
  112. if(strcasecmp($action, 'delete') == 0 )
  113. {
  114.     $this->db->delete('nv_cms_testimonials',array('id'=>$id));
  115.     $this->data['deleted']=true;
  116.    
  117.     $this->data['testimonials'] = $this->testimonials_model->get_all_testimonials_with_pagination('5',$this->uri->segment(4));
  118.    
  119.     //pagination
  120.     $config['base_url'] = base_url().'admin/testimonials/manage';
  121.     $config['total_rows'] = $this->testimonials_model->get_all_testimonials();
  122.     $config['per_page'] = 5;
  123.     $config['uri_segment'] = 4;
  124.     $this->pagination->initialize($config);
  125.    
  126.     $this->data['pagination_links'] = $this->pagination->create_links();
  127.     $this->load->view('admin/testimonials_manage_view',$this->data);
  128.  
  129. }
  130. elseif(strcasecmp($action, 'edit')==0)
  131. {
  132.    
  133.    
  134.     $this->data['testimonial'] = $this->testimonials_model->get_testimonial_by_id($id);
  135.     $this->load->view('admin/testimonials_edit_view',$this->data);
  136. }
  137. elseif(strcasecmp($action, 'update')==0)
  138. {
  139.     $this->testimonials_model->update_testimonial($id);
  140.    
  141. }else{
  142.  
  143.  
  144.          $CI =& get_instance();
  145.    
  146.    
  147.     $this->data['testimonials'] = $CI->testimonials_model->get_all_testimonials_with_pagination('5',$this->uri->segment(4));
  148.    
  149.     //pagination
  150.     $config['base_url'] = base_url().'admin/testimonials/manage';
  151.     $config['total_rows'] = $this->testimonials_model->get_all_testimonials();
  152.     $config['per_page'] = 5;
  153.     $config['uri_segment'] = 4;
  154.     $this->pagination->initialize($config);
  155.    
  156.     $this->data['pagination_links'] = $this->pagination->create_links();
  157.     $this->load->view('admin/testimonials_manage_view',$this->data);
  158.     }
  159.    
  160. }//manage
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement