I have a site where admin can add/assign users to projects. I have tried a lot of different stuff and the latest is that it works to some extent.. but not as needed:
On ProjectDetails page there is a dropdown-list which is used to add users to specific Project. BUT this drowdown-list shows only users who are not registered in any other projects at all.But Users must be able to be registered/added in multiple projects at same time. What I need is to show this dropdown list in View (ProjectDetails) only with users who are not already registered in this specific project
View:
<? if ( $level == "9" ) { ?>
<?php
$tVAR555 = count($allUsers_NotInProject);
//print_r($testVAR555)."<br><br>";
if ($tVAR555 < 1) {
echo "";
}
else {
echo '
<div class="dropdown button editPP_J">
<i class="add user icon"></i>
<span class="text">Add user</span>
<div class="menu">
<div class="header">
Add user to project
</div>
';
foreach ($allUsers_NotInProject as $rows) {
echo '<div class="item"> <p> Username: <strong>'.$rows->username.'</strong> </p> ';
echo form_open('Project/addParticipant', 'class="form" id="addPP"');
echo form_hidden('user_id', $rows->user_id);
echo form_hidden('Project_ID', $this->uri->segment(3));
echo '
<button type="submit" class="uBfB" id="addPP_SB"> Add
</button>
';
echo form_close();
echo '</div><hr> ';
}
echo '</div></div>';
}
}
?>
Controller:
public function projectDetails($Project_ID) {
$this->is_logged_in();
$loggedInUserID = $this->auth_user_id;
$Project_ID = $this->uri->segment(3);
$data['loggedInUserID'] = $this->auth_user_id;
/* Tested different approaches for fetching data from DB */
$data['projectParticipants'] =
$this->projectModel->getAllProjects_Participants($Project_ID);
/* Tested different approaches for fetching data from DB */
$data['projectUsers2'] =
$this->projectModel->get_projParts($Project_ID);
/* Tested different approaches for fetching data from DB */
$data['allUsers_NotInProject'] =
$this->projectModel->getAllUsers_NotInProject();
$res = $this->projectModel->getProjectDetails($Project_ID);
foreach ($res->result_array() as $projectDetail) {
$data['rProjectID'] = $projectDetail['Project_ID'];
$data['rProjectName'] = $projectDetail['Name'];
$data['rProjectCreatedAt'] = $projectDetail['created_at'];
}
if( $this->verify_role('admin,manager') ) {
if( $this->is_role('manager') ) {
$data['level'] = "6";
}
if( $this->is_role('admin') ) {
$data['level'] = "9";
}
$html = $this->load->view('header', $data, TRUE);
$html .= $this->load->view('projectDetails', $data, TRUE);
$html .= $this->load->view('footer', $data, TRUE);
echo $html;
}
}
Model:
public function getAllProjects_Participants($Project_ID){
$query = $this->db->query("
SELECT * FROM Participants, users WHERE
Participants.user_id = users.user_id AND
Participants.Project_ID = $Project_ID
");
return $query->result_array();
}
public function get_projParts($Project_ID) {
$this->db->select('*');
$this->db->from('Participants');
$this->db->join('Users', 'Participants.user_id = Users.user_id');
$this->db->where('Project_ID', $Project_ID);
$query = $this->db->get();
return $query->result();
}
public function getAllUsers_NotInProject() {
$query = $this->db->query
("
SELECT * FROM users
WHERE user_id NOT IN (
SELECT DISTINCT(user_id) from Participants
)
");
return $query->result();
}
public function getProjectDetails($Project_ID) {
$query2 = $this->db->query
("
SELECT * FROM Projects
WHERE Projects.Project_ID = $Project_ID
");
$res = $query2;
return $res;
}
</div>