planning2.inc.php 16.6 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
		$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;
Bate's avatar
Bate committed
236 237
		$date_absence = null;
		$date_min = null;
Bate's avatar
Bate committed
238 239 240 241
		while(true)
		{
			$to_break = false;
			$sql = new requete($this->db,
Bate's avatar
Bate committed
242
				"SELECT min(pl2_absence.start) FROM pl2_absence
Bate's avatar
Bate committed
243 244 245 246 247 248
				 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
249 250
				 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
251 252 253 254 255 256 257 258 259 260
			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,
Bate's avatar
Bate committed
261
				"SELECT min(pl2_user_gap.end) FROM pl2_user_gap
Bate's avatar
Bate committed
262 263
				 JOIN pl2_gap
				 ON pl2_gap.id_gap = pl2_user_gap.id_gap
Bate's avatar
Bate committed
264 265
				 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
266 267 268 269 270 271 272 273 274 275

			if($sql->lines <= 0)
				if($to_break)
					break;
			else
			{
				list( $date_min ) = $sql->get_row();
				if(is_null($date_min) && $to_break)
					break;
			}
Bate's avatar
Bate committed
276 277 278 279
			if(is_null($date_min))
			{
				$date_min = $date_absence;
			}
Bate's avatar
Bate committed
280 281 282 283 284 285
			$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
286 287
				 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
288 289 290 291 292 293 294 295 296 297 298 299 300 301
			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 )
	{
302
		$gap_id = intval($gap_id);
Bate's avatar
Typo  
Bate committed
303
		$user_id = intval($user_id);
304 305 306
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);

Bate's avatar
Bate committed
307 308 309
		$sql = new requete($this->db, 
			"SELECT * from pl2_user_gap
			 WHERE id_gap = '$gap_id'
Bate's avatar
Bate committed
310 311 312
			 AND id_utilisateur = '$user_id'
			 AND 
			 (
Bate's avatar
Bate committed
313 314
			 	(	 start <= '".gmdate("Y-m-d H:i:s",$end)."'
					 AND start >= '".gmdate("Y-m-d H:i:s",$start)."'
Bate's avatar
Bate committed
315 316
				)
			  	OR
Bate's avatar
Bate committed
317 318
				(        end >= '".gmdate("Y-m-d H:i:s",$start)."'
					 AND end <= '".gmdate("Y-m-d H:i:s",$end)."'
Bate's avatar
Bate committed
319 320 321 322 323 324 325 326 327
				)
			 )");
		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
328 329
			 AND 
			 (
Bate's avatar
Bate committed
330 331
			 	(	 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
332 333
				)
			  	OR
Bate's avatar
Bate committed
334 335
				(        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
336
				)
Bate's avatar
Bate committed
337 338 339 340 341 342 343 344
			  	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
345 346 347 348
			 )
			 AND
			 (
				(
Bate's avatar
Bate committed
349 350
					pl2_gap.start < (SELECT tmp.end FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
					AND pl2_gap.start > (SELECT tmp.start FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
Bate's avatar
Bate committed
351 352 353
				)
				OR
				(
Bate's avatar
Bate committed
354 355
					pl2_gap.end > (SELECT tmp.start FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
                                        AND pl2_gap.end < (SELECT tmp.end FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
Bate's avatar
Bate committed
356
				)
Bate's avatar
Bate committed
357 358
				OR
				(
Bate's avatar
Bate committed
359 360
					pl2_gap.start <= (SELECT tmp.start FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
                                        AND pl2_gap.end >= (SELECT tmp.end FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
Bate's avatar
Bate committed
361 362 363
				)
				OR
				(
Bate's avatar
Bate committed
364 365
					pl2_gap.start >= (SELECT tmp.start FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
                                        AND pl2_gap.end <= (SELECT tmp.end FROM pl2_gap AS tmp WHERE tmp.id_gap = '$gap_id')
Bate's avatar
Bate committed
366
				)
Bate's avatar
Bate committed
367 368 369
			 )");
		if($sql->lines > 0)
			return false;
Bate's avatar
Bate committed
370
		$users = $this->get_max_users_for($gap_id,$start,$end);
Bate's avatar
Bate committed
371 372 373 374 375 376 377 378 379 380 381
		$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)
	{
382
		$gap_id = intval($gap_id);
Bate's avatar
Typo  
Bate committed
383
		$user_id = intval($user_id);
384 385
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
Bate's avatar
Bate committed
386
		if(!$this->is_user_addable($gap_id,$user_id,$start,$end))
Bate's avatar
Bate committed
387 388 389 390 391 392
			return -1;
		$sql = new insert ($this->dbrw,
                       "pl2_user_gap",
                       array(
			     "id_gap" => $gap_id,
                             "id_utilisateur" => $user_id,
Bate's avatar
Bate committed
393 394
			     "start" => gmdate("Y-m-d H:i:s",$start),
                             "end" => gmdate("Y-m-d H:i:s",$end)
Bate's avatar
Bate committed
395 396 397 398 399 400 401 402 403 404 405 406
                            )
                      );
		if ( !$sql->is_success() )
		{
			return -1;
		}

		return $sql->get_id();
	}

	function remove_user_from_gap( $user_gap_id )
	{
407
		$user_gap_id = intval($user_gap_id);
Bate's avatar
Bate committed
408 409 410 411 412 413 414 415 416
		$sql = new delete($this->dbrw, "pl2_user_gap",
			array(
                             "id_user_gap" => $user_gap_id
                            )
                       );
	}

	function get_gaps_for_user( $user_id)
	{
417
		$user_id = intval($user_id);
Bate's avatar
Bate committed
418 419 420 421 422
		return new requete($this->db,
			"SELECT id_gap FROM pl2_user_gap
			 WHERE id_utilisateur = $user_id");
	}

Bate's avatar
Bate committed
423
	function get_gaps( $start, $end )
Bate's avatar
Bate committed
424
	{
425 426
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
Bate's avatar
Bate committed
427
		if($this->weekly)
Bate's avatar
Bate committed
428
			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 
				 ORDER BY start ASC");
		else
			return new requete($this->db,
Bate's avatar
Bate committed
434
                                "SELECT id_gap, start, end, name_gap, max_users FROM pl2_gap 
Bate's avatar
Bate committed
435 436 437 438
                                 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
439 440 441 442
	}

	function get_gaps_time( $start, $end )
	{
443 444
		$start = mysql_real_escape_string($start);
		$end = mysql_real_escape_string($end);
Bate's avatar
Bate committed
445
		if($this->weekly)
Bate's avatar
Bate committed
446 447 448 449 450 451 452 453 454 455
			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
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)."' ")).
                                 "UNION DISTINCT
Bate's avatar
Bate committed
460
				 SELECT end as date FROM pl2_gap 
Bate's avatar
Bate committed
461 462 463 464
                                 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
465 466
	}

Bate's avatar
Bate committed
467 468 469
	function get_gaps_names()
	{
		return new requete($this->db,
Bate's avatar
Bate committed
470
			"SELECT DISTINCT name_gap FROM pl2_gap WHERE id_planning = $this->id ORDER BY name_gap");
Bate's avatar
Bate committed
471 472
	}

Bate's avatar
Bate committed
473 474
	function get_gap_info( $gap_id )
	{
475
		$gap_id = intval($gap_id);
Bate's avatar
Bate committed
476 477
		return new requete($this->db,
                        "SELECT id_gap, name_gap, start, end FROM pl2_gap 
Bate's avatar
Bate committed
478
			 WHERE id_gap = $gap_id AND id_planning = $this->id");
Bate's avatar
Bate committed
479 480
	}

Bate's avatar
Bate committed
481 482
	function get_user_gap_info( $user_gap_id )
	{
483
		$user_gap_id = intval($user_gap_id);
Bate's avatar
Bate committed
484 485 486 487 488
		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
489 490
	function get_gaps_from_names( $name )
	{
491
		$name = mysql_real_escape_string($name);
Bate's avatar
Bate committed
492
		return new requete($this->db,
Bate's avatar
Bate committed
493 494 495 496 497
			"SELECT id_gap FROM pl2_gap WHERE id_planning = $this->id AND gap_name = '$name' ORDER BY start");
	}

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

Bate's avatar
Bate committed
520 521
	function get_users_for_gap( $gap_id, $date )
	{
522 523
		$gap_id = intval($gap_id);
		$date = mysql_real_escape_string($date);
Bate's avatar
Bate committed
524 525 526 527 528 529 530 531 532
		$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
533 534 535
			/*$date = strtotime(date('o-\\WW',$date));*/
			$diff = $date - $this->start;
			$date = $date - ($diff % ($this->weekly*3600*24));
Bate's avatar
Bate committed
536 537
			$start = strtotime($start." UTC")+$date;
			$end = strtotime($end." UTC")+$date;
Bate's avatar
Bate committed
538 539
			$start =gmdate("Y-m-d H:i:s",$start);
			$end =gmdate("Y-m-d H:i:s",$end);	
Bate's avatar
Bate committed
540 541 542 543 544 545
		}
		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
546 547
				as `nom_utilisateur`,
				pl2_user_gap.id_user_gap as id_user_gap
Bate's avatar
Bate committed
548
			 FROM pl2_user_gap
Bate's avatar
Bate committed
549
			 JOIN utilisateurs
Bate's avatar
Bate committed
550
			 ON utilisateurs.id_utilisateur = pl2_user_gap.id_utilisateur
Bate's avatar
Bate committed
551
			 LEFT OUTER JOIN utl_etu_utbm
Bate's avatar
Bate committed
552
			 ON utilisateurs.id_utilisateur = utl_etu_utbm.id_utilisateur
Bate's avatar
Bate committed
553 554 555 556 557 558 559 560
			 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
561 562
			 AND pl2_user_gap.start <= '$start'
			 AND pl2_user_gap.end >= '$end'");
Bate's avatar
Bate committed
563 564 565 566 567 568
		
	}
	
}

?>