planning2.inc.php 16.4 KB
Newer Older
Bate's avatar
Bate committed
1 2 3 4 5 6 7 8 9 10
<?php

class planning2 extends stdentity
{
	var $name;
	var $weekly;
	var $group;
	var $admin_group;
	var $start;
	var $end;
Bate's avatar
Bate committed
11
	var $is_public;
Bate's avatar
Bate committed
12 13 14 15

	function load_by_id( $id )
	{
		$req = new requete( $this->db, "SELECT * from `pl2_planning`
Bate's avatar
Bate committed
16
						WHERE `id_planning` = '".
Bate's avatar
Bate committed
17 18 19 20 21 22 23 24 25 26 27 28 29
						mysql_real_escape_string($id).
						"' LIMIT 1");
		if( $req->lines != 1 )
		{
			$this->id = null;
			return false;
		}
		$this->_load($req->get_row());
		return true;
	}

	function _load( $row )
	{
Bate's avatar
Bate committed
30
		$this->id		= $row['id_planning'];
Bate's avatar
Bate committed
31 32 33 34
		$this->group		= $row['id_group'];
		$this->admin_group	= $row['id_admin_group'];
		$this->name		= $row['name_planning'];
		$this->weekly		= $row['weekly_planning'];
Bate's avatar
Bate committed
35 36
		$this->start		= strtotime($row['start']." UTC");
		$this->end		= strtotime($row['end']." UTC");
Bate's avatar
Bate committed
37
		$this->is_public	= $row['is_public'];
Bate's avatar
Bate committed
38 39
	}

Bate's avatar
Bate committed
40
	function add ( $name, $group, $admin_group, $weekly, $start, $end, $is_public = true )
Bate's avatar
Bate committed
41
	{
42 43 44 45 46 47 48
		$this->name = mysql_real_escape_string($name);
		$this->group = intval($group);
		$this->admin_group = intval($admin_group);
		$this->weekly = intval($weekly);
		$this->start = mysql_real_escape_string($start);
		$this->end = mysql_real_escape_string($end);
		$this->is_public= ((bool)$is_public);
Bate's avatar
Bate committed
49 50 51 52 53 54 55

		$sql = new insert ($this->dbrw,
                       "pl2_planning",
                       array(
                             "name_planning" => $this->name,
			     "id_group" => $this->group,
			     "id_admin_group" => $this->admin_group,
Bate's avatar
Bate committed
56 57
			     "start" => gmdate("Y-m-d H:i:s",$this->start),
			     "end" => gmdate("Y-m-d H:i:s",$this->end),
Bate's avatar
Bate committed
58 59
                             "weekly_planning" => $this->weekly,
                             "is_public" => $this->is_public
Bate's avatar
Bate committed
60 61 62 63 64 65 66 67 68 69 70 71 72
                            )
                      );
		if ( !$sql->is_success() )
		{
			$this->id = null;
			return false;
		}

		$this->id = $sql->get_id();

		return true;
	}

Bate's avatar
Bate committed
73
	function update ( $name, $group, $admin_group, $start, $end , $is_public)
Bate's avatar
Bate committed
74
	{
75 76 77 78 79 80
		$this->name = mysql_real_escape_string($name);
		$this->group = intval($group);
		$this->admin_group = intval($admin_group);
		$this->start = mysql_real_escape_string($start);
		$this->end = mysql_real_escape_string($end);
		$this->is_public = ((bool)$is_public);
Bate's avatar
Bate committed
81 82 83 84 85 86 87

		$sql = new update ($this->dbrw,
                       "pl2_planning",
                       array(
                             "name_planning" => $this->name,
			     "id_group" => $this->group,
			     "id_admin_group" => $this->admin_group,
Bate's avatar
Bate committed
88 89
			     "start" => gmdate("Y-m-d H:i:s",$this->start),
			     "end" => gmdate("Y-m-d H:i:s",$this->end),
Bate's avatar
Bate committed
90 91
                             "weekly_planning" => $this->weekly,
                             "is_public" => $this->is_public
Bate's avatar
Bate committed
92 93 94
                            ),
			array("id_planning" => $this->id)
                      );
Bate's avatar
Bate committed
95
		return $sql->is_success();
Bate's avatar
Bate committed
96 97 98 99 100 101 102 103
	}

	function remove()
	{
		$sql = new requete($this->db, "SELECT `id_gap` FROM `pl2_gap`
						WHERE id_planning = ".$this->id);
		while(list($gap_id) = $sql->get_row())
		{
Bate's avatar
Bate committed
104
			$this->delete_gap( $gap_id );
Bate's avatar
Bate committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
		}
		$sql = new delete($this->dbrw, "pl2_absence",
			array(
                             "id_planning" => $this->id
                            )
                       );
		$sql = new delete($this->dbrw, "pl2_planning",
			array(
                             "id_planning" => $this->id
                            )
                       );
	}

	function add_gap( $start, $end, $gap_name, $max_users )
	{
120 121 122 123 124
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
		$gap_name = mysql_real_escape_string($gap_name);
		$max_users = intval($max_users);

Bate's avatar
Bate committed
125 126 127 128 129 130 131
		$gap_name = trim($gap_name);
		if( $max_users <= 0 )
			return -1;
		if(empty($gap_name))
			return -1;
		if($start >= $end)
			return -1;
Bate's avatar
Bate committed
132
		if(!$this->weekly && $start < $this->start)
Bate's avatar
Bate committed
133
			return -1;
Bate's avatar
Bate committed
134
		if(!$this->weekly && $end > $this->end)
Bate's avatar
Bate committed
135 136 137
			return -1;
		if($this->weekly)
		{
Bate's avatar
Bate committed
138
			if($end >= $this->weekly*24*3600)
Bate's avatar
Bate committed
139 140 141 142 143 144 145
				return -1;
		}
		$sql = new insert ($this->dbrw,
                       "pl2_gap",
                       array(
			     "id_planning" => $this->id,
                             "name_gap" => $gap_name,
Bate's avatar
Bate committed
146 147
			     "start" => gmdate("Y-m-d H:i:s",$start),
                             "end" => gmdate("Y-m-d H:i:s",$end),
Bate's avatar
Bate committed
148 149 150 151 152 153 154 155 156 157 158 159 160
			     "max_users" => $max_users
                            )
                      );
		if ( !$sql->is_success() )
		{
			return -1;
		}

		return $sql->get_id();
	}

	function update_gap( $gap_id, $start, $end, $gap_name, $max_users )
	{
161 162 163 164 165
		$gap_id = intval($gap_id);
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
		$gap_name = mysql_real_escape_string($gap_name);
		$max_users = intval($max_users);
Bate's avatar
Bate committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
		if($gap_id <= 0 )
			return -1;
		if( $max_users <= 0 )
			return -1;
		$gap_name = trim($gap_name);
		if(empty($gap_name))
			return -1;
		if($start >= $end)
			return -1;
		if($start < $this->start)
			return -1;
		if($end > $this->end)
			return -1;
		if($this->weekly)
		{
Bate's avatar
Bate committed
181
			if($end >= $this->weekly*24*3600)
Bate's avatar
Bate committed
182 183 184 185 186 187 188 189
				return -1;
		}
		$sql = new update ($this->dbrw,
                       "pl2_gap",
                       array(
			     "id_planning" => $this->id,
                             "name_gap" => $gap_name,
			     "max_users" => $max_users,
Bate's avatar
Bate committed
190 191
			     "start" => gmdate("Y-m-d H:i:s",$start),
                             "end" => gmdate("Y-m-d H:i:s",$end)
Bate's avatar
Bate committed
192 193 194 195 196 197 198 199 200
                            ),
		       array(
			     "id_gap" => $gap_id
		       )
                      );
	}

	function delete_gap( $gap_id )
	{
201
		$gap_id = intval($gap_id);
Bate's avatar
Bate committed
202 203 204 205 206
		$sql = new delete($this->dbrw, "pl2_user_gap",
			array(
                       		"id_gap" => $gap_id
			)
                );
Bate's avatar
Bate committed
207 208
		if(!$sql->is_success())
			return false;
Bate's avatar
Bate committed
209 210 211 212 213
		$sql = new delete($this->dbrw, "pl2_gap",
			array(
                             "id_gap" => $gap_id
                            )
                       );
Bate's avatar
Bate committed
214
		return $sql->is_success();
Bate's avatar
Bate committed
215 216 217 218
	}

	function get_max_users_for( $gap_id, $start, $end )
	{
219
		$gap_id = intval($gap_id);
Bate's avatar
Bate committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
		$start = mysql_escape_string($start);
		$end = mysql_escape_string($end);
		if(!$this->weekly)
		{
			$sql = new requete($this->db,
				"SELECT count(*) FROM pl2_user_gap
        	                 JOIN pl2_gap ON pl2_gap.id_gap = pl2_user_gap.id_gap
                	         WHERE pl2_gap.id_gap = '$gap_id'");
			if( list($total) = $sql->get_row())
				return $total;
			else
				return -1;
		}
		$max_users = 0;
		$new_start = $start;
		$to_break = false;
		while(true)
		{
			$to_break = false;
			$sql = new requete($this->db,
				"SELECT min(start) FROM pl2_absence
				 JOIN pl2_gap 
				 ON pl2_gap.id_planning = pl2_absence.id_planning
				 JOIN pl2_user_gap
				 ON pl2_gap.id_gap = pl2_user_gap.id_gap
				 AND pl2_user_gap.id_utilisateur = pl2_absence.id_utilisateur
				 WHERE pl2_gap.id_gap = '$gap_id'
Bate's avatar
Bate committed
247 248
				 AND pl2_absence.start < '".gmdate("Y-m-d H:i:s",$end)."'
				 AND pl2_absence.end > '".gmdate("Y-m-d H:i:s",$new_start)."'");
Bate's avatar
Bate committed
249 250 251 252 253 254 255 256 257 258 259 260 261
			if($sql->lines <= 0)
				$to_break = true;
			else
			{
				list( $date_absence ) = $sql->get_row();
				if(is_null($date_absence))
					$to_break = true;
			}

			$sql = new requete($this->db,
				"SELECT min(end) FROM pl2_user_gap
				 JOIN pl2_gap
				 ON pl2_gap.id_gap = pl2_user_gap.id_gap
Bate's avatar
Bate committed
262 263
				 WHERE pl2_user_gap.start <= '".gmdate("Y-m-d H:i:s",$new_start)."' 
				 AND pl2_user_gap.end > '".gmdate("Y-m-d H:i:s",$new_start)."'");
Bate's avatar
Bate committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280

			if($sql->lines <= 0)
				if($to_break)
					break;
			else
			{
				list( $date_min ) = $sql->get_row();
				if(is_null($date_min) && $to_break)
					break;
			}

			$date_min = ($date_min<$date_absence)?$date_min:$date_absence;
			
			$sql = new requete($this->db,
				"SELECT count(*) FROM pl2_user_gap
        	                 JOIN pl2_gap ON pl2_gap.id_gap = pl2_user_gap.id_gap
                	         WHERE pl2_gap.id_gap = '$gap_id'
Bate's avatar
Bate committed
281 282
				 AND pl2_user_gap.start <= '".gmdate("Y-m-d H:i:s",$new_start)."'
				 AND pl2_user_gap.end >= '".gmdate("Y-m-d H:i:s",$date_min)."'");
Bate's avatar
Bate committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296
			if(!$sql->is_success())
			{
				exit();
			}
			list( $my_max ) = $sql->get_row();
			$max_users = max($my_max,$max_users);
			$new_start = $date_min;
		}
		return $max_users;
		
	}
	
	function is_user_addable( $gap_id, $user_id, $start, $end )
	{
297 298 299 300 301
		$gap_id = intval($gap_id);
		$user_id = $intval($user_id);
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);

Bate's avatar
Bate committed
302 303 304
		$sql = new requete($this->db, 
			"SELECT * from pl2_user_gap
			 WHERE id_gap = '$gap_id'
Bate's avatar
Bate committed
305 306 307
			 AND id_utilisateur = '$user_id'
			 AND 
			 (
Bate's avatar
Bate committed
308 309
			 	(	 start <= '".gmdate("Y-m-d H:i:s",$end)."'
					 AND start >= '".gmdate("Y-m-d H:i:s",$start)."'
Bate's avatar
Bate committed
310 311
				)
			  	OR
Bate's avatar
Bate committed
312 313
				(        end >= '".gmdate("Y-m-d H:i:s",$start)."'
					 AND end <= '".gmdate("Y-m-d H:i:s",$end)."'
Bate's avatar
Bate committed
314 315 316 317 318 319 320 321 322
				)
			 )");
		if($sql->lines > 0)
			return false;
		$sql = new requete($this->db, 
			"SELECT * from pl2_user_gap
			 JOIN pl2_gap ON pl2_gap.id_gap = pl2_user_gap.id_gap
			 WHERE id_utilisateur = '$user_id'
			 AND id_planning IN (SELECT id_planning FROM pl2_gap WHERE id_gap = '$gap_id')
Bate's avatar
Bate committed
323 324
			 AND 
			 (
Bate's avatar
Bate committed
325 326
			 	(	 pl2_user_gap.start <= '".gmdate("Y-m-d H:i:s",$end)."'
					 AND pl2_user_gap.start >= '".gmdate("Y-m-d H:i:s",$start)."'
Bate's avatar
Bate committed
327 328
				)
			  	OR
Bate's avatar
Bate committed
329 330
				(        pl2_user_gap.end >= '".gmdate("Y-m-d H:i:s",$start)."'
					 AND pl2_user_gap.end <= '".gmdate("Y-m-d H:i:s",$end)."'
Bate's avatar
Bate committed
331
				)
Bate's avatar
Bate committed
332 333 334 335 336 337 338 339
			  	OR
				(        pl2_user_gap.start <= '".gmdate("Y-m-d H:i:s",$start)."'
					 AND pl2_user_gap.end >= '".gmdate("Y-m-d H:i:s",$end)."'
				)
			  	OR
				(        pl2_user_gap.start >= '".gmdate("Y-m-d H:i:s",$start)."'
					 AND pl2_user_gap.end <= '".gmdate("Y-m-d H:i:s",$end)."'
				)
Bate's avatar
Bate committed
340 341 342 343
			 )
			 AND
			 (
				(
Bate's avatar
Bate committed
344 345
					pl2_gap.start < (SELECT end FROM pl2_gap WHERE id_gap = '$gap_id')
					AND pl2_gap.start > (SELECT start FROM pl2_gap WHERE id_gap = '$gap_id')
Bate's avatar
Bate committed
346 347 348
				)
				OR
				(
Bate's avatar
Bate committed
349 350
					pl2_gap.end > (SELECT start FROM pl2_gap WHERE id_gap = '$gap_id')
                                        AND pl2_gap.end < (SELECT end FROM pl2_gap WHERE id_gap = '$gap_id')
Bate's avatar
Bate committed
351
				)
Bate's avatar
Bate committed
352 353 354 355 356 357 358 359 360 361
				OR
				(
					pl2_gap.start <= (SELECT start FROM pl2_gap WHERE id_gap = '$gap_id')
                                        AND pl2_gap.end >= (SELECT end FROM pl2_gap WHERE id_gap = '$gap_id')
				)
				OR
				(
					pl2_gap.start >= (SELECT start FROM pl2_gap WHERE id_gap = '$gap_id')
                                        AND pl2_gap.end <= (SELECT end FROM pl2_gap WHERE id_gap = '$gap_id')
				)
Bate's avatar
Bate committed
362 363 364
			 )");
		if($sql->lines > 0)
			return false;
Bate's avatar
Bate committed
365
		$users = $this->get_max_users_for($gap_id,$start,$end);
Bate's avatar
Bate committed
366 367 368 369 370 371 372 373 374 375 376
		$sql = new requete($this->db,
			"SELECT max_users FROM pl2_gap
			 WHERE id_gap = $gap_id");
		if($sql->lines != 1)
			return false;
		list( $max_users ) = $sql->get_row();
		return ($users < $max_users);
	}

	function add_user_to_gap( $gap_id, $user_id, $start, $end)
	{
377 378 379 380
		$gap_id = intval($gap_id);
		$user_id = $intval($user_id);
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
Bate's avatar
Bate committed
381
		if(!$this->is_user_addable($gap_id,$user_id,$start,$end))
Bate's avatar
Bate committed
382 383 384 385 386 387
			return -1;
		$sql = new insert ($this->dbrw,
                       "pl2_user_gap",
                       array(
			     "id_gap" => $gap_id,
                             "id_utilisateur" => $user_id,
Bate's avatar
Bate committed
388 389
			     "start" => gmdate("Y-m-d H:i:s",$start),
                             "end" => gmdate("Y-m-d H:i:s",$end)
Bate's avatar
Bate committed
390 391 392 393 394 395 396 397 398 399 400 401
                            )
                      );
		if ( !$sql->is_success() )
		{
			return -1;
		}

		return $sql->get_id();
	}

	function remove_user_from_gap( $user_gap_id )
	{
402
		$user_gap_id = intval($user_gap_id);
Bate's avatar
Bate committed
403 404 405 406 407 408 409 410 411
		$sql = new delete($this->dbrw, "pl2_user_gap",
			array(
                             "id_user_gap" => $user_gap_id
                            )
                       );
	}

	function get_gaps_for_user( $user_id)
	{
412
		$user_id = intval($user_id);
Bate's avatar
Bate committed
413 414 415 416 417
		return new requete($this->db,
			"SELECT id_gap FROM pl2_user_gap
			 WHERE id_utilisateur = $user_id");
	}

Bate's avatar
Bate committed
418
	function get_gaps( $start, $end )
Bate's avatar
Bate committed
419
	{
420 421
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
Bate's avatar
Bate committed
422
		if($this->weekly)
Bate's avatar
Bate committed
423
			return new requete($this->db,
Bate's avatar
Bate committed
424
				"SELECT id_gap, start, end, name_gap, max_users FROM pl2_gap 
Bate's avatar
Bate committed
425 426 427 428
				 WHERE id_planning = $this->id 
				 ORDER BY start ASC");
		else
			return new requete($this->db,
Bate's avatar
Bate committed
429
                                "SELECT id_gap, start, end, name_gap, max_users FROM pl2_gap 
Bate's avatar
Bate committed
430 431 432 433
                                 WHERE id_planning = $this->id ".
				 (is_null($start)?"":("AND end > '".gmdate("Y-m-d H:i:s",$start)."' ")).
				 (is_null($end)?"":("AND start < '".gmdate("Y-m-d H:i:s",$end)."' ")).
                                 "ORDER BY start ASC");
Bate's avatar
Bate committed
434 435 436 437
	}

	function get_gaps_time( $start, $end )
	{
438 439
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
Bate's avatar
Bate committed
440
		if($this->weekly)
Bate's avatar
Bate committed
441 442 443 444 445 446 447 448 449 450
			return new requete($this->db,
				"SELECT start as date FROM pl2_gap 
				 WHERE id_planning = $this->id 
				 UNION DISTINCT SELECT end as date 
				 FROM pl2_gap 
				 WHERE id_planning = $this->id 
				 ORDER BY date ASC");
		else
			return new requete($this->db,
                                "SELECT start as date FROM pl2_gap 
Bate's avatar
Bate committed
451 452 453 454
                                 WHERE id_planning = $this->id ".
				 (is_null($start)?"":("AND end > '".gmdate("Y-m-d H:i:s",$start)."' ")).
				 (is_null($end)?"":("AND start < '".gmdate("Y-m-d H:i:s",$end)."' ")).
                                 "UNION DISTINCT
Bate's avatar
Bate committed
455
				 SELECT end as date FROM pl2_gap 
Bate's avatar
Bate committed
456 457 458 459
                                 WHERE id_planning = $this->id ".
				 (is_null($start)?"":("AND end > '".gmdate("Y-m-d H:i:s",$start)."' ")).
				 (is_null($end)?"":("AND start < '".gmdate("Y-m-d H:i:s",$end)."' ")).
                                 "ORDER BY date ASC");
Bate's avatar
Bate committed
460 461
	}

Bate's avatar
Bate committed
462 463 464
	function get_gaps_names()
	{
		return new requete($this->db,
Bate's avatar
Bate committed
465
			"SELECT DISTINCT name_gap FROM pl2_gap WHERE id_planning = $this->id ORDER BY name_gap");
Bate's avatar
Bate committed
466 467
	}

Bate's avatar
Bate committed
468 469
	function get_gap_info( $gap_id )
	{
470
		$gap_id = intval($gap_id);
Bate's avatar
Bate committed
471 472
		return new requete($this->db,
                        "SELECT id_gap, name_gap, start, end FROM pl2_gap 
Bate's avatar
Bate committed
473
			 WHERE id_gap = $gap_id AND id_planning = $this->id");
Bate's avatar
Bate committed
474 475
	}

Bate's avatar
Bate committed
476 477
	function get_user_gap_info( $user_gap_id )
	{
478
		$user_gap_id = intval($user_gap_id);
Bate's avatar
Bate committed
479 480 481 482 483
		return new requete($this->db,
                        "SELECT id_gap, id_utilisateur, start, end FROM pl2_user_gap
			 WHERE id_user_gap = $user_gap_id");
	}

Bate's avatar
Bate committed
484 485
	function get_gaps_from_names( $name )
	{
486
		$name = mysql_real_escape_string($name);
Bate's avatar
Bate committed
487
		return new requete($this->db,
Bate's avatar
Bate committed
488 489 490 491 492
			"SELECT id_gap FROM pl2_gap WHERE id_planning = $this->id AND gap_name = '$name' ORDER BY start");
	}

	function get_week_start( $date )
	{
493
		$date = mysql_real_escape_string($date);
Bate's avatar
Bate committed
494 495 496
		if($this->weekly)
		{
			$diff = $date - $this->start;
Bate's avatar
Bate committed
497
                        $date = $date - ($diff % ($this->weekly*3600*24));
Bate's avatar
Bate committed
498 499 500 501 502 503
		}
		else
		{
			$req = new requete($this->db,
				"SELECT start FROM pl2_gap 
				 WHERE id_planning = $this->id
Bate's avatar
Bate committed
504
				 AND start > '".gmdate("Y-m-d H:i:s",$date)."'
Bate's avatar
Bate committed
505 506 507 508
				 ORDER BY start ASC LIMIT 1");
			if($req->lines == 1)
			{
				list( $tmp ) = $req->get_row();
Bate's avatar
Bate committed
509
				$date = strtotime( $tmp." UTC" );
Bate's avatar
Bate committed
510 511
			}
		}
Bate's avatar
Bate committed
512
		return strtotime(gmdate("Y-m-d 00:00:00",$date)." UTC");
Bate's avatar
Bate committed
513 514
	}

Bate's avatar
Bate committed
515 516
	function get_users_for_gap( $gap_id, $date )
	{
517 518
		$gap_id = intval($gap_id);
		$date = mysql_real_escape_string($date);
Bate's avatar
Bate committed
519 520 521 522 523 524 525 526 527
		$sql = new requete($this->db,
			"SELECT start,end FROM pl2_gap
			 WHERE id_gap = $gap_id");
		if(!$sql->is_success())
			exit();
		list( $start, $end ) = $sql->get_row();

		if($this->weekly)
		{
Bate's avatar
Bate committed
528 529 530
			/*$date = strtotime(date('o-\\WW',$date));*/
			$diff = $date - $this->start;
			$date = $date - ($diff % ($this->weekly*3600*24));
Bate's avatar
Bate committed
531 532
			$start = strtotime($start." UTC")+$date;
			$end = strtotime($end." UTC")+$date;
Bate's avatar
Bate committed
533 534
			$start =gmdate("Y-m-d H:i:s",$start);
			$end =gmdate("Y-m-d H:i:s",$end);	
Bate's avatar
Bate committed
535 536 537 538 539 540
		}
		return new requete($this->db,
			"SELECT utilisateurs.id_utilisateur as id_utilisateur, 
				IF(utl_etu_utbm.surnom_utbm!='' AND utl_etu_utbm.surnom_utbm IS NOT NULL,
					utl_etu_utbm.surnom_utbm, 
					CONCAT(`utilisateurs`.`prenom_utl`,' ',`utilisateurs`.`nom_utl`)) 
Bate's avatar
Bate committed
541 542
				as `nom_utilisateur`,
				pl2_user_gap.id_user_gap as id_user_gap
Bate's avatar
Bate committed
543
			 FROM pl2_user_gap
Bate's avatar
Bate committed
544
			 JOIN utilisateurs
Bate's avatar
Bate committed
545
			 ON utilisateurs.id_utilisateur = pl2_user_gap.id_utilisateur
Bate's avatar
Bate committed
546
			 LEFT OUTER JOIN utl_etu_utbm
Bate's avatar
Bate committed
547
			 ON utilisateurs.id_utilisateur = utl_etu_utbm.id_utilisateur
Bate's avatar
Bate committed
548 549 550 551 552 553 554 555
			 WHERE id_gap = $gap_id
			 AND utilisateurs.id_utilisateur NOT IN
			 (	SELECT id_utilisateur FROM pl2_absence
				JOIN pl2_gap
				ON pl2_gap.id_planning = pl2_absence.id_planning
				WHERE (pl2_absence.start < '$start' AND pl2_absence.end > '$start')
				OR  (pl2_absence.start < '$end' AND pl2_absence.start > '$start')
			 )
Bate's avatar
Bate committed
556 557
			 AND pl2_user_gap.start <= '$start'
			 AND pl2_user_gap.end >= '$end'");
Bate's avatar
Bate committed
558 559 560 561 562 563
		
	}
	
}

?>