Location: PHPKode > projects > Opensheet > opensheet/users_tasks.php
<?php



ini_set('display_errors','1');
error_reporting(E_ALL);
session_start();
include ('start.php');
require ('functions/base.functions.php');
#require ('functions/users.inc.php');
include ('classes/global.class.php');


	set_lang($_SESSION['lang']);
	$login_type = new users();
		if ($_SESSION['permissions']['admin'] !== "1"){
		Header("Location: timesheet.php");
					exit();

		}
		
if(isset($_POST['users']) && isset($_POST['tid']) && isset($_POST['pid'])){
$pid = $_POST['pid'];
$tid = $_POST['tid'];
$users = new Users;
$taskHours = new Tasks();
#$uids = $users->getUsersArray('active');
$uids = $users->getProjectUsers($pid);
$uidtemp = $_POST['users'];
$uidToStay = array();

	foreach($uidtemp as $num=>$uid){
		$uidIntask[$uid]=array('status'=>'Y');
	}

	foreach($uids as $num=>$data){
		if(isset($uidIntask[$data['user_id']])){
				$to_base[$data['user_id']]= array('status' => 'Y');
			}else{
				$hours = $taskHours->getTskUsrSummMonth($tid,$data['user_id'],date('Y'),date('m') );
				if(is_null($hours[$tid]['summ']) || $hours[$tid]['summ'] == NULL || $hours[$tid]['summ'] == 0){
					$to_base[$data['user_id']]= array('status' => 'N');
					}	else {	
						$uidToStay[$data['user_id']] = array('have_hours'=>'Y'); 
					}
				}
		}
	
	foreach($to_base as $uid=>$value){
		$users->updateTaskStatus($uid,$tid,$value['status']);
	} 	
	
	$send = serialize($uidToStay);
	Header("Location: users_tasks.php?tid=$tid&data=$send");
	
	exit();
}

if(isset($_POST['task_id']) && isset($_POST['flush_hours_per_user'])){
	$pid = $_POST['project_id'];
	$tid = $_POST['task_id'];
	$year = date('Y');
	$month = date('m');
	$days = date('t');
	$days++;
	$users = $_POST['users'];
	$query = new Timesheet;
	$array = array();
	
	
	foreach($users as $uid=>$action) {
			for($day=1;$day<$days;$day++){
				$array['tasks'][$pid][$tid][$day]= "";
				
			}
		$query->setHours($uid,$array,$year,$month);
	}
	

 	#print_r($array);
 		Header("Location: users_tasks.php?tid=$tid");
					exit();
}




?><!-- Headers -->
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link   rel="stylesheet" type="text/css" href="css/multiselect.common.css"  />
<link   rel="stylesheet" type="text/css" href="css/ui.multiselect.css" />
<link   rel="stylesheet" type="text/css" href="css/jqueryslidemenu.css" />
<link   type="text/css" rel="stylesheet" href="css/south-street/jquery-ui-1.7.1.custom.css" />
<link   rel="stylesheet" type="text/css" href="css/green/style.css"  media="print, projection, screen" />

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="js/jqueryslidemenu.js"></script>
<script type="text/javascript" src="js/ui.multiselect.js"></script>
<script type="text/javascript" src="js/plugins/localisation/jquery.localisation-min.js"></script>
<script type="text/javascript">
$(function(){
		$('.show_error_close').live('click',function(){ 
			 if ( $('.show_error').css('display') == 'block' )  $('.show_error').css({'display':'none'}) 
			 else $('.show_error').css({'display':'block'})
		})
});	
</script>

<!--[if lte IE 7]>
<style type="text/css">
html .jqueryslidemenu{height: 1%;} /*Holly Hack for IE7 and below*/
</style>
<![endif]-->
<script type="text/javascript">
$(function(){
	$.localise('ui-multiselect', {/*language: 'en',*/ path: 'js/locale/'});
	$(".multiselect").multiselect();

});
</script>


<title>Users in Projects</title>


</head>
<body>
<?php
include ('include/menu.settings.inc.html');
#get project id
$tid = $_GET['tid'];
$send =  $_GET['data'];
$send = unserialize(stripslashes($send)); #Get error while we try to remove users with hours in a base

#print_r(unserialize(stripslashes($send)));
#$data = unserialize($send);

#priecho "TEST";nt_r($data);
$tasks =  new Tasks;
$usersListActive = $tasks->getTaskUsers($tid);
asort($usersListActive);


$pid = $tasks->getTaskParent($tid);
$users= new Users;
$usersListAll = $users->getProjectUsers($pid);
#print_r($usersListAll);
?>

<form action="" method="POST">
      <select id="users" class="multiselect" multiple="multiple" name="users[]">
<?php 

		foreach ($usersListActive as $num=>$data){
			echo '<option value="'.$data['user_id'].'" selected="selected">'.$data['real_name'].'</option>';
			$taskUids[$data['user_id']]= array('status'=>'Y');
			}

	foreach ($usersListAll as $uid=>$value){
			if(!isset($taskUids[$value['user_id']])) {	echo '<option value="'.$value['user_id'].'">'.$value['real_name'].'</option>';}
	}




$project = new Projects;
$tasks =  new Tasks;
$project_vars = $project->getProjectVars($pid);
$task_vars = $tasks->getTaskVars($tid);
?>
</select>
      <br/>
       <input type="hidden" value="<?php echo $pid;?>" name="pid"/>
       <input type="hidden" value="<?php echo $tid;?>" name="tid"/>
     <center> <input type="submit" value="<?php echo gettext('GO');?>"/></center>
    </form>


<!-- Project desc -->
<div class="project" style=" width:200px;height: 450px;top: 50px; border: 1px solid black; right:50px;position:absolute; z-index:22;background: #F0F0F6;">
<center><p><?php echo gettext('task');?>:</p></center>

<table style='margin: 10px;'>
<tbody>
<tr><td style='width:30%;'><?php echo gettext('Root_project');?></td></tr>

<tr><td style='width:30%;'><?php echo $project_vars['proj_name'];?></td></tr>
<tr><td style='width:30%;'><br></td></tr>
<tr><td style='width:30%;'><?php echo $task_vars['task_name'];?></td></tr>

<tr><td style='width:30%;'><?php echo gettext('Index');?>:</td></tr>
<tr><td style='width:30%;'><?php echo $task_vars['task_index'];?></td></tr>
<tr><td style='width:30%;'><br></td></tr>

<tr><td style='width:30%;'><?php echo gettext('status');?>:</td></tr>
<tr><td style='width:30%;'><?php echo $task_vars['status'];?></td></tr>
</tbody>
</table>

</div>

<!-- Error Message -->
<?php 
if (isset($send) && $send != NULL){
?>
<div class="show_error" style=" width:30%;height: 450px;top: 70px; border: 1px solid black; right:35%;position:absolute; z-index:122;background: #F0F0F6;display: block;">
<div style="position:absolute; z-index:123;width:22px;height: 22px;top: -10px;right:-10px;"><a href="#"  class="show_error_close"><img style="border:0px;"src="images/button_cancel.png"></a></div>

<center><p><?php echo gettext('show_error_while_removing_user_from_project');?>:</p></center>
<p><?php echo gettext('To keep our base You need to choose:');?>:</p>
<p><?php echo gettext('1: Keep this user in this project,press Cancel button');?>:</p>
<p><?php echo gettext('2: Flush user this months hours');?>:</p>


<form method='POST' action=''>
<table style='margin: 10px;width:100%;'>
<tbody>
<?php foreach($send as $uid=>$trash){ ?>

<tr><td style='width:80%;'><?php echo $users->getRealName($uid);?></td>
<td><input type='checkbox' name='users[<?php echo $uid;?>]' value='Y' checked></input></td>

</tr>
<?php } ?>
</tbody></table>
<input type='hidden' name='project_id' value='<?php echo $pid;?>'>
<input type='hidden' name='task_id' value='<?php echo $tid;?>'>
<center> <input type="submit" name='flush_hours_per_user' value="Flush" ></input></center>
</form>


</div>
<?php }   ?>

</body>
</html>
Return current item: Opensheet