php - How to create a action button that creates users in codeigniter? -
i have 3 users admin,reseller , users. reseller request admin want xyx number of users.
this saved in table called user_request in admin there view can see reseller has requested how many users.
and there button approve or reject. if admin hits approve want code create users reseller. each users mapped his/her reseller field called key unique.
so, when users created must store key of reseller in users table.
now, if approves users request re-seller must deleted. confused should doing here!
the view :
<div class="row"> <div class="col-lg-12"> <div class="panel panel-info"> <div class="panel-heading"> <h4>new user requests</h4> </div> <!-- /.panel-heading --> <div class="panel-body"> <div class="datatable_wrapper"> <table class="table table-striped table-bordered table-hover" id="datatables-example"> <thead> <tr> <th>id</th> <th>users requested</th> <th>unique id</th> <th>date of request</th> <th>approve</th> <th>reject</th> <th>status</th> </tr> </thead> <!-- fetch records--> <tbody> <?php if(count($users)): foreach($users $user): ?> <tr class="odd gradex"> <td><?php echo $user->id; ?></td> <td><?php echo $user->id, $user->user_requested; ?></td> <td><?php echo $user->id, $user->key; ?></td> <td><?php echo $user->id, $user->date_requested; ?></td> <td><a href="reseller/create_user" class="btn btn-primary">yes <i class="glyphicon glyphicon-ok"></i></a></td> <td><a href="reseller/change_status" class="btn btn-danger">no <?php echo'<i class="glyphicon glyphicon-trash"></i>';?></a></td> <td><a href="" class="btn btn-success"><?php echo $user->status; ?></td> </a></td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="3">we not find users.</td> </tr> <?php endif; ?> </tbody> </table> </div> <!-- /.table-responsive --> </div> <!-- /.panel-body --> </div> <!-- /.panel --> </div> <!-- /.col-lg-12 --> </div>
the controller:
public function create_user() { $this->load->model('more_m'); $id = $this->session->userdata('id'); $this->db->set('status', "'approved'",false); $this->db->where('id',$id); $this->db->update('user_request'); redirect('admin/new_user'); }
now, want add code creates users requested reseller.
i have succeeded accomplish :
public function create_user() { $this->load->model('more_m'); $id= $this->session->userdata('id'); $rajan =$this->more_m->get(array('user_requested',$id)); $request=$rajan->user_requested; $this->load->model('reseller_m'); $query=$this->db->select('key'); $query=$this->db->get('reseller'); if($query->num_rows() > 0) { $row = $query->row_array(); $key= $row['key']; } for($i=1; $i<=$request;$i++) { $userdata=array('key'=>$key); $this->db->insert('users',$userdata); } $this->load->model('more_m'); $id = $this->session->userdata('id'); $this->db->set('status', "'approved'",false); $this->db->where('id',$id); $this->db->update('user_request'); redirect('admin/new_user'); }
firstly fetch how many users required key , loop them , insert users along reseller key
Comments
Post a Comment