user and admin

Hi there

my problem is i have an app with admin and partners access group lvl 1 and 2

the problem here when i login as partner i see the items that assigned to me by the admin

but when i press backspace button the page refresh and show up all the items that the admin have too

please can you chk where i made the error and thank you for your help

here is the code
[php]<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Members extends CI_Controller {
public $success, $message, $data;
var $table = “subscribers”;
var $part_tabel = “partners”;
var $serv_tabel = “servers”;
var $user = NULL;

function __construct() {
	parent::__construct();
	$this->success = true;
	$this->data = array();
	$this->message = ""; 
	if (!$this->ion_auth->logged_in())
	{
		if($this->ion_auth->isAjax()){
			$this->success = false;
			$this->to_json(array("login"=>true));
			exit;
		}else{
			redirect('auth/login');
		}
	}
	$this->load->model("tools_model");
	$this->load->model("user_model");		
	$this->user = $this->get_partner_id();
}
function user_info(){
	$lines = array();
	$users = json_decode($this->input->post("users"), true);		
	foreach($users as $user){			
		if($t = $this->tools_model->fetch_user_infos($user))
			$lines = array_merge($lines,$t);
			
	}
	$this->load->view("user_infos", array("lines"=>$lines));
}
function get_record($id){
	$q = $this->db->get_where($this->table, array("id"=>$id));
	return $q->num_rows() > 0 ? $q->row_array() : array();	
}
function update(){
    $data = $this->input->post("data");
	$record = json_decode($data, TRUE);
	unset($record["days_left"]);
	$record["end_date"] = date("Y-m-d G:i:s", (intval($record["duration"]) * 30 * 24 *  60 * 60) + strtotime($record["date"]));
	

	if($this->user_model->update($record)){
		$this->success = true;
		$this->message = "Informations abonné misent à jour avec succès!";
	}else{
		$this->success = false;
		$this->message = "Erreur lors de la mise à jour!";		
	}

	$this->to_json();	
}
private function get_partner_id(){
	$q = $this->db->get_where($this->part_tabel, array("user_id"=>$this->ion_auth->user()->row()->id));
	if($q->num_rows() > 0)
		return $q->row()->id;
	else
		return false;	
}
public function index()
{
	$this->load->view("members");
}

function retrive(){
 
	 $this->db->select("(TO_DAYS(date) + duration) - TO_DAYS(NOW())  as days_left");
	$this->db->select("subscribers.id, subscribers.name,subscribers.amount_left, proxy,subscribers.username,subscribers.date,subscribers.duration,subscribers.end_date,subscribers.amount,subscribers.chat,subscribers.mobile,subscribers.created,subscribers.payment,subscribers.type,subscribers.status,subscribers.server_id,subscribers.namo");
	
	if($this->input->post("fields")){
		$fields = json_decode($this->input->post("fields"),true);			
		foreach($fields as $field){
			$this->db->or_like("subscribers.".$field,$this->input->post("query"));
		}
	}
	
		

	$this->db->join('partners', 'partners.id = subscribers.partner_id',"left");
	if(!empty($this->user))
		$this->db->where("partner_id", $this->user);
	else
		$this->db->where("0", 1, false);
	$q = $this->db->get($this->table);		
	$total = $q->num_rows();
	$q->free_result();
	
		
		$this->db->select("subscribers.id, subscribers.name,amount_left,subscribers.proxy, subscribers.username,subscribers.date,subscribers.duration,subscribers.end_date,subscribers.amount,subscribers.chat,subscribers.mobile,subscribers.created,subscribers.payment,subscribers.type,subscribers.status, subscribers.server_id,subscribers.namo");
		$this->db->select("CONCAT('C: ',servers.url,' ',servers.listen_port,' ',subscribers.username,' ',subscribers.password) as cline", FALSE);
	     $this->db->select("(TO_DAYS(date) + duration) - TO_DAYS(NOW())  as days_left");
		 $this->db->join('servers', 'servers.id = subscribers.server_id',"left");
		
	if(!empty($this->user))
		$this->db->where("partner_id", $this->user);
	else
		$this->db->where("0", 1, false);
	
	if($this->input->post("fields")){
		$fields = json_decode($this->input->post("fields"),true);
				
		foreach($fields as $field){
			$this->db->or_like($field,$this->input->post("query"));
		}
	}		
	
	
	
	if($this->input->post("sort")){
		$this->db->order_by($this->input->post("sort"),$this->input->post("dir"));			
	}else{		
		$this->db->order_by("subscribers.status","ASC");
		$this->db->order_by("subscribers.created","DESC");
	}
		
	if($this->input->post("start"))
		$this->db->limit($this->input->post("limit"), $this->input->post("start"));
	else
		$this->db->limit(100);
	$this->db->where("subscribers.partner_id !=",1);

	$q = $this->db->get($this->table);	 
//	print($this->db->last_query());
	if($q->num_rows() > 0){
		$this->data = $q->result_array();
	}
	$this->to_json(array("total"=>$total));
}
function to_json($params = false){
	$properties = array(
		"success"=>$this->success,
		"message"=>$this->message,
		"data"   =>$this->data
	);
	if(is_array($params)){
		foreach($params as $key=>$val)
		$properties[$key] = $val;
	}
	echo json_encode($properties);
}

function download(){			
	$this->load->library('zip');		
	$users = $this->input->get('users');
	$users = explode(":",$users);
	$this->db->select("subscribers.username");		
	$this->db->select("CONCAT('C: ',servers.url,' ',servers.listen_port,' ',subscribers.username,' ',subscribers.password) as cline", FALSE);
	$this->db->join('servers', 'servers.id = subscribers.server_id',"left");
	$this->db->where_in("subscribers.id", $users);
	$q = $this->db->get($this->table);
	
	if($q->num_rows() > 0){
		foreach($q->result() as $row){
			$name = $row->username."/"	;
			$this->zip->add_data($name, $row->cline);
		}
	}
	
	$this->zip->download("abonnements-".date("d-m-Y").".zip");
}

}

[/php]

At this level you will spend countless hours manually searching for bugs if you don’t have the tools to help you. Do yourself a favor and get xdebug up and running with whatever IDE you use. In debug mode you can step through the execution and will be able to see how it jumps into the “wrong” places immediately.

Good luck :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service