function render_title($incDate) {
global $wk;
$partie_incDate = explode("/", $incDate); //pour partager jj mm yyyy
$incDateU=mktime(0,0,0, $partie_incDate[0],$partie_incDate[1],$partie_incDate[2]);
?>
}
/*******************************************************************************/
/*******************************************************************************/
function request_detail_events(){
//''' request form inputs from this form
$event_id = $_REQUEST["event_id"] ;
$dt_end = $_REQUEST["dt_end"];
$CodeAdmin = $_REQUEST["CodeAdmin"];
$dt_start = $_REQUEST["dt_start"];
$id = $_REQUEST["id"];
$b_personal = $_REQUEST["b_personal"];
$description = $_REQUEST["description"];
$tm_start = $_REQUEST["tm_start"];
$tm_end = $_REQUEST["tm_end"];
// '********
$location = $_REQUEST["location"];
// '********
$event_name = $_REQUEST["event_name"];
$Cat = $_REQUEST["Cat"];
$NomU = $_REQUEST["NomU"];
}
/**********************************************************************************/
/**********************************************************************************/
function validate_detail_events() {
//''' request and validate data entered from this form
$event_id = trim($_REQUEST["event_id"]);
$dt_end = trim($_REQUEST["dt_end"]);
$CodeAdmin = trim($_REQUEST["CodeAdmin"]);
$dt_start = trim($_REQUEST["dt_start"]);
$id = trim($_REQUEST["id"]);
$b_personal = trim($_REQUEST["b_personal"]);
$description = trim($_REQUEST["description"]);
$tm_start = trim($_REQUEST["tm_start"]);
$tm_end = trim($_REQUEST["tm_end"]);
//'********
$location = trim($_REQUEST["location"]);
//'********
$event_name = trim($_REQUEST["event_name"]);
$Cat = trim($_REQUEST["Cat"]);
$NomU = trim($_REQUEST["NomU"]);
}
/*************************************************************************************/
/*************************************************************************************/
function db_select_detail_Events(){
global $incDate;
$incDate1 = str_replace("'", "''", $incDate);
$partie_incDate = explode("/", $incDate1);
/****************Ajouté pour eviter redondance**********/
$incday= $partie_incDate[1];
$incmonth= $partie_incDate[0]; // mon ajout
$incyear= $partie_incDate[2];
if ($incday<10) $incday="0".$incday;
$incDate1= $incyear."-".$incmonth."-".$incday." 00:00:00";
$codeadmin=to_sql($_SESSION["CodeAdmin"],"number");
$detail_Events_sql = "SELECT events.dt_end, events.CodeAdmin,events.dt_start, eventsoccur.id,TIME(eventsoccur.tm_start) tm_start1, TIME(eventsoccur.tm_end) tm_end1, eventsoccur.location, events.event_id, admin.NomU, eventsoccur.event_name, eventsoccur.description, events.b_personal
FROM events,eventsoccur,admin WHERE ((events.CodeAdmin = admin.CodeAdmin) AND (events.event_id = eventsoccur.event_id) AND ((b_personal = 0)OR (b_personal = 2) OR (b_personal is null)) AND (events.CodeAdmin = '".$codeadmin."') AND (eventsoccur.dt_occur = '".$incDate1."')) ORDER BY UNIX_TIMESTAMP(eventsoccur.tm_start)" ;
return($detail_Events_sql);
}
/*************************************************************************************/
function db_E_select_detail_Events(){
global $incDate;
$incDate1 = str_replace("'", "''", $incDate);
$partie_incDate = explode("/", $incDate1);
/****************Ajouté pour eviter redondance**********/
$incday= $partie_incDate[1];
$incmonth= $partie_incDate[0]; // mon ajout
$incyear= $partie_incDate[2];
if ($incday<10) $incday="0".$incday;
$incDate1= $incyear."-".$incmonth."-".$incday." 00:00:00";
$codeadmin=to_sql($_SESSION["CodeAdmin"],"number");
$detail_Events_sql = "SELECT eventsequipement.dt_end, eventsequipement.CodeAdmin,eventsequipement.dt_start, eventsequipementoccur.id,TIME(eventsequipementoccur.tm_start) tm_start1, TIME(eventsequipementoccur.tm_end) tm_end1, eventsequipementoccur.location, eventsequipement.event_id, admin.NomU, eventsequipementoccur.event_name, eventsequipementoccur.description, eventsequipement.b_personal
FROM eventsequipement,eventsequipementoccur,admin WHERE ((eventsequipement.CodeAdmin = admin.CodeAdmin) AND (eventsequipement.event_id = eventsequipementoccur.event_id) AND ((b_personal = 0)OR (b_personal = 2) OR (b_personal is null)) AND (eventsequipement.CodeAdmin = '".$codeadmin."') AND (eventsequipementoccur.dt_occur = '".$incDate1."')) ORDER BY UNIX_TIMESTAMP(eventsequipementoccur.tm_start)" ;
return($detail_Events_sql);
}
/**************************************************************************************/
function db_delete_detail_Events(){ //procedure
$sql = "DELETE FROM eventsoccur WHERE id =".$id."";
mysql_query($sql);
if (mysql_errno()) {
$message = 'Requête invalide : ' . mysql_error() . "\n";
die($message);
}
}
/**************************************************************************************/
/**************************************************************************************/
Function GetDateName($monthNumber){ // Voir ou mettre cette fonction pour l'appeler plus tard
Switch($monthNumber){
Case "1":
$GetDateName = "Janvier";
break;
Case "2":
$GetDateName = "Février";
break;
Case "3":
$GetDateName = "Mars";
break;
Case "4":
$GetDateName = "Avril";
break;
Case "5":
$GetDateName = "Mai";
break;
Case "6":
$GetDateName = "Juin";
break;
Case "7";
$GetDateName = "Juillet";
break;
Case "8":
$GetDateName = "Août";
break;
Case "9":
$GetDateName = "Septembre";
break;
Case "10":
$GetDateName = "Octobre";
break;
Case "11":
$GetDateName = "Novembre";
break;
Case "12":
$GetDateName = "Décembre";
break;
default :
$GetDateName="";
}
return($GetDateName);
}
/*******************************************************************************/
/*******************************************************************************/
function DaysInAnyMonth($iMonth, $iYear) {
$dTemp = DateAdd("d", -1, mktime(0,0,0,$iMonth + 1,1,$iYear));
// voir equivalent de cette fonction en php
$DaysInAnyMonth= Date("j",$dTemp); //idem
return($DaysInAnyMonth);
}
function WeekdayNameOfFirstOfMonth($iMonth, $iYear) {
$dTemp=date("w",mktime(01, $iMonth,$iYear)); //à verifier
//$dTemp = WeekdayName(Weekday($iMonth."/01/".$iYear,VBSunday)); // voir aussi ces fonctions et le VBSunday
$FirstWeekdayOfMonth = $dTemp;
return($dTemp);
//'response.write "
1st day of " & iMonth & "/" & iYear & " is a: " & dTemp & "
"
}
/***********************************************************************************/
/***********************************************************************************/
function DateFirstWeekdayFallsOn($iMonth, $iYear, $iWeekdayNumber) {
$dTemp = $iWeekdayNumber - date("w",mktime($iMonth,01,$iYear)); //verifier ces fonctions numero du jour dans la semaine c'est w+
if ($dTemp < 0) $dTemp = 0;
$dTemp = DateAdd("d",$dTemp,$iMonth."/01/".$iYear); // cette fonction est dans i_utils.php
$DateFirstWeekdayFallsOn = $dTemp;
//'response.write "
The 1st " & WeekdayName(iWeekdayNumber) & " of " & iMonth & "/" & iYear & " is on: " & dTemp & "
"
}
/************************************************************************************/
/*****************************upd_events functions*****************************************/
/* Fonctions de upd_events.php */
/******************************************************************************************/
function db_select_edit_Events() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $time_start, $id, $rs,$dt_occur, $rep_num_weeks, $rep_type, $rep_opt, $rep_day;
$sql = "SELECT ";
$sql.="events.event_id,";
$sql.="tm_end, ";
$sql.="id, ";
$sql.="recurring_end, ";
$sql.="CodeAdmin, ";
$sql.="event_name, ";
$sql.="location, ";
$sql.="Organisme, ";
$sql.="NomC, ";
$sql.="PrenomC, ";
$sql.="TelC, ";
$sql.="EmailC, ";
$sql.="Cout, ";
$sql.="Tax, ";
$sql.="description,";
$sql.="dt_start, ";
$sql.="tm_start, ";
$sql.="b_personal, ";
$sql.="b_register, ";
$sql.="entry_type, ";
$sql.="rep_type, ";
$sql.="rep_opt, ";
$sql.="rep_num_weeks, ";
$sql.="dt_end, ";
$sql.="dt_occur FROM (events RIGHT JOIN eventsoccur ON events.event_id = eventsoccur.event_id) WHERE ";
$sql.="eventsoccur.id = ".to_sql($id,"number")."";
$rs = mysql_query($sql);
if (!$rs) {
echo "Could not successfully run query ($sql) from DB: " .mysql_error();
$b_error = true;
$error_list["select_data_edit_Events"]="The data selection failed. ".mysql_error();
exit;
}elseif (mysql_num_fields($rs)==0) {
$b_results = false;
$msg_list["select_data_edit_Events"]= "Supprimer.";
}
elseif ($row = mysql_fetch_assoc($rs)) {
$tm_end = $row["tm_end"];
$id = $row["id"];
$recurring_end = $row["recurring_end"];
$event_id = $row["event_id"];
$CodeAdmin = $row["CodeAdmin"];
$event_name = $row["event_name"];
$location = $row["location"];
$Organisme = $row["Organisme"];
$NomC = $row["NomC"];
$PrenomC = $row["PrenomC"];
$TelC = $row["TelC"];
$EmailC = $row["EmailC"];
$Cout = $row["Cout"];
$Tax = $row["Tax"];
$b_register = $row["b_register"];
$description = $row["description"];
$dt_start = $row["dt_start"];
$tm_start = $row["tm_start"];
$b_personal = $row["b_personal"];
$entry_type = $row["entry_type"];
$rep_type = $row["rep_type"];
$rep_opt = $row["rep_opt"];
$rep_num_weeks = $row["rep_num_weeks"];
$dt_occur = $row["dt_occur"];
$dt_end= $row["dt_end"];
if ((isset($recurring_end))&&(!empty($recurring_end))) $dt_end=$recurring_end;
if (($rep_type == 2) || ($rep_type == 6))
for ($i = 0; $i < 7; $i++)
$rep_day[$i]=substr($rep_opt, $i-7, 1);
}
mysql_free_result($rs);
// on error goto 0
}
/******************************************************************************/
function validate_time() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $b_error, $rep_num_weeks, $rep_type, $rep_day;
// '*******validation des entree**************
if ($b_error==true)
If ((is_nan((float)$Cout)) AND (Cout <> "")){
$error_list["startendtime"]="Entrer un numero dans le Coût";
$b_error = true;
}
//'********valide heures**********************
if ((empty($tm_start)) || (empty($tm_end))) {
$error_list["startendtime"]= "Les heures de location et la date sont obligatoires";
$b_error = true;
}
if ((empty($_REQUEST["moisd"])) || (empty($_REQUEST["jourd"])) || (empty($_REQUEST["anneed"]))) {
$error_list["starttime"]="Entrer la date de location .";
$b_error = true;
}
//':: requests and validates event start and end time
if (strlen($tm_start) > 0) $tm_start = $tm_start.":".$_REQUEST["minute_start"];
if (strlen($tm_end) > 0) $tm_end = $tm_end.":".$_REQUEST["minute_end"];
if (strlen($tm_end) > 0) {
$debut = "07:00"; // 07 AM
if ((TimeValue($tm_start) < TimeValue($debut)) or (TimeValue($tm_end) < TimeValue($debut)) or (TimeValue($tm_start) > TimeValue($tm_end))) {
$error_list["startendtime"]= "l'heure de réservation doit être entre 7h et 23h.";
$b_error = true;
}
if ((isset($dt_end))AND (strtotime($dt_start)==strtotime($dt_end)) AND (TimeValue($tm_start) > TimeValue($tm_end))) {
$error_list["startendtime"]= "Heure de fin (".$tm_end.") n'est pas aprés l'heure de début (".$tm_start.")";
$b_error = true;
}
}
$tm_start="1899-12-30 ".$tm_start.":00"; //tm_start et tm_end doivent etre tjs au
$tm_end="1899-12-30 ".$tm_end.":00"; //format "1899-12-30 yyyy-mm-jj"
}
/**************************************************************************************/
function validate_reservation() {
global $dt_start, $dt_end, $recurring_end, $entry_type,$location,$tm_start,$tm_end,$event_id,$dTmp, $b_error, $msg_list, $rep_num_weeks, $rep_type, $rep_day;
$blnReservation = false;
$b_error = false;
$dTmp=$dt_start;
$exit=false;
if (strtotime($dTmp) > strtotime($recurring_end)) {
$b_error = true;
$msg_list["startendtime"]="La date debut devrait être avant la date fin";
} else
for ($j = 1; $j < 300; $j++) {
if (strtotime($dTmp) <= strtotime($recurring_end)) {
$blnReservation=verification($location,$tm_start,$tm_end,$dTmp); // avoir
if ($blnReservation) {
$msg_list["startendtime"]="Le local n'est pas disponible de ".substr(TimePart($tm_start),0, 5)." à ".substr(TimePart($tm_end),0,5).".";
$b_error = true;
} else $b_error = false;
} else break;
//*****************************A revoir ici pour entry_type******************************
if ($entry_type == 0) $dTmp = dateadd("d",1,$dTmp);
elseif ($entry_type < 30) $dTmp = dateadd("d",$entry_type,$dTmp);
elseif ($entry_type == 30) $dTmp = dateadd("m",1,$dTmp);
else $dTmp = dateadd("yyyy",$entry_type,$dTmp);
}
}
/***************************************************************************************/
function validate_Update() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $b_error;
//'********************************
$blnReservation = false;
$exit=false;
$dTmp = datevalue($dt_start);
for ($j = 1; $j<300; $j++) {
if ((strtotime($dTmp) - strtotime($recurring_end))<=0) { //comparer deux dates
/*********************************Autre probleme ici*******************************/
$blnReservation=verificationUpdate($location,$tm_start,$tm_end,$dTmp,$event_id);
/**************************************************************************************/
if ($blnReservation == true) {
$error_list["startendtime"]="Le local n'est pas disponible. (".$tm_start."),(".$tm_end.")";
$b_error = true;
}
}else{
$exit=true;
}
if($exit) break;
if ($entry_type == 0)
$dTmp = dateadd("d",1,$dTmp);
elseif ($entry_type < 30) $dTmp = dateadd("d",$entry_type,$dTmp);
elseif ($entry_type == 30) $dTmp = dateadd("m",1,$dTmp);
else $dTmp = dateadd("Y",1,$dTmp);
}
}
function request_edit_events() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $b_error;
//''' request form inputs from this form
if (isset($_REQUEST["tm_end"])) $tm_end = $_REQUEST["tm_end"];
// else $tm_end= "";
if (isset($_REQUEST["id"])) $id = $_REQUEST["id"];
//else $id= "";
//'recurring_end = request("recurring_end")
if (($_POST["moisend"]<> "") && ($_POST["jourend"] <> "") && ($_POST["anneeend"]<> ""))
$recurring_end = $_REQUEST["moisend"]."/".$_REQUEST["jourend"]."/".$_REQUEST["anneeend"];
$event_id = $_REQUEST["event_id"];
$CodeAdmin = $_REQUEST["CodeAdmin"];
$event_name = $_REQUEST["event_name"];
$location = $_REQUEST["location"];
$Organisme = $_REQUEST["Organisme"];
$NomC = $_REQUEST["NomC"];
$PrenomC = $_REQUEST["PrenomC"];
$TelC = $_REQUEST["TelC"];
$EmailC = $_REQUEST["EmailC"];
$Cout = $_REQUEST["Cout"];
$Tax = $_REQUEST["Tax"];
$b_register = NULL;
$description = $_REQUEST["description"];
//'dt_start = $_REQUEST["dt_start")
if (($_POST["moisd"] <> "") && ($_POST["jourd"] <> "") && ($_POST["anneed"]<> ""))
$dt_start = $_REQUEST["anneed"]."-".$_REQUEST["moisd"]."-".$_REQUEST["jourd"];
$tm_start = $_REQUEST["tm_start"];
$b_personal = $_REQUEST["b_personal"];
//$entry_type = $_REQUEST["entry_type"]; // Mes modifs
$rep_type = $_REQUEST["rep_type"]; // Mes modifs
$dt_occur = $_REQUEST["dt_occur"];
$recurring_update = $_REQUEST["recurring_update"];
}
/****************************************************************************************/
function validate_edit_events() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end,
$event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC,
$EmailC, $Cout, $Tax, $b_register, $b_personal, $b_error, $rep_num_weeks, $rep_type, $rep_day, $recurring_update;
//''' request and validate data entered from this form
/*$b_error=false; */
$id= trim($_REQUEST["id"]);
if (($_POST["moisend"]<> "") && ($_POST["jourend"] <> "") && ($_POST["anneeend"]<> ""))
$recurring_end = trim($_REQUEST["anneeend"]."-".$_REQUEST["moisend"]."-".$_REQUEST["jourend"]);
$event_id= trim($_REQUEST["event_id"]);
if (isset($_REQUEST["CodeAdmin"]))
$CodeAdmin= trim($_REQUEST["CodeAdmin"]);
if ($CodeAdmin == "") {
$error_list["661037"]="Le code est obligatoire.";
$b_error = true;
}
$event_name= trim($_REQUEST["event_name"]);
if ($event_name == "") {
$error_list["661038"]="Le titre est obligatoire.";
$b_error = true;
}
if (isset($_REQUEST["location"]))
$location = trim($_REQUEST["location"]);
if (isset($_REQUEST["event_name"]))
$event_name = trim($_REQUEST["event_name"]);
if (isset($_REQUEST["Organisme"]))
$Organisme = trim($_REQUEST["Organisme"]);
else $Organisme="";
if (isset($_REQUEST["NomC"]))
$NomC = trim($_REQUEST["NomC"]);
else $NomC="";
if (isset($_REQUEST["PrenomC"]))
$PrenomC = trim($_REQUEST["PrenomC"]);
else $PrenomC="";
if (isset($_REQUEST["EmailC"]))
$EmailC = trim($_REQUEST["EmailC"]);
else $EmailC="";
if (isset($_REQUEST["TelC"]))
$TelC = trim($_REQUEST["TelC"]);
else $TelC="";
if (isset($_REQUEST["Tax"]))
$Tax = trim($_REQUEST["Tax"]);
else $Tax="";
if (isset($_REQUEST["Cout"]))
$Cout = trim($_REQUEST["Cout"]);
else $Cout="";
if (isset($_REQUEST["description"]))
$description = trim($_REQUEST["description"]);
else $description="";
if (isset($_REQUEST["b_register"])) /*********stop********/
$b_register = trim($_REQUEST["b_register"]);
else $b_register="";
if (($_POST["moisd"]<> "") && ($_POST["jourd"] <> "") && ($_POST["anneed"]<> ""))
$dt_start = trim($_REQUEST["anneed"]."-".$_REQUEST["moisd"]."-".$_REQUEST["jourd"]);
if ($dt_start == "") {
$error_list["661040"]="La date de début est obligatoire..";
$b_error = true;
}
$b_personal = trim($_REQUEST["b_personal"]);
$dt_occur = trim($_REQUEST["dt_occur"]);
if (isset($_REQUEST["recurring_update"])) {
$recurring_update = trim($_REQUEST["recurring_update"]);
}
else $recurring_update="";
}
/********************************************************************************************/
function get_defaults_edit_events() {
//''' set default values for this form
if (isset($_REQUEST["incDate"]))
$dt_start = "".$_REQUEST["incDate"]."";
else $dt_start = "";
$b_personal = 0;
$recurring_update = "0";
}
/*******************************************************************************************/
/***********************************************************************************/
function db_insert_edit_Events_equipement() {
global $dt_start, $dt_end,$event_id, $recurring_end, $entry_type,$rep_type,$CodeAdmin,$b_personal,$location, $msg_list, $rep_num_weeks, $rep_type, $rep_day, $rep_opt;
if ((isset($recurring_end))&&(!empty($recurring_end))) $dt_end=$recurring_end;
$rep_opt ="";
if (($rep_type == 2) || ($rep_type == 6))
for ($i = 0; $i < 7; $i++) $rep_opt .= empty($rep_day[$i]) ? "0" : "1";
if (!isset($dt_end)) {
$sql = "INSERT INTO eventsequipement (";
$sql.="CodeAdmin,";
$sql.="dt_start,";
$sql.="b_personal,";
$sql.="entry_type,";
$sql.="recurring_end";
$sql.=") VALUES (".$CodeAdmin.",";
$sql.="'".$dt_start."',";
$sql.="'".$b_personal."',";
$sql.="'".$entry_type."',";
$sql.="'".$recurring_end."')";
}
else {
$sql = "INSERT INTO eventsequipement (";
$sql.="CodeAdmin,";
$sql.="dt_start,";
$sql.="dt_end,";
$sql.="b_personal,";
$sql.="entry_type,";
$sql.="recurring_end,";
$sql.="rep_type,";
$sql.="rep_opt,";
$sql.="rep_num_weeks";
$sql.=") VALUES (".$CodeAdmin.",";
$sql.="'".$dt_start."',";
$sql.="'".$dt_end."',";
$sql.="'".$b_personal."',";
$sql.="'".$entry_type."',";
$sql.="'".$recurring_end."',";
$sql.="'".$rep_type."',";
$sql.="'".$rep_opt."',";
$sql.="'".$rep_num_weeks."')";
}
//'response.write sql
//on error resume next
mysql_query($sql)
or DIE ("Could not perform INSERT to table ".mysql_errno().": ".mysql_error());
if (mysql_errno()) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
else {
$rs = mysql_query("SELECT @@IDENTITY");
if ($row = mysql_fetch_row($rs)){
$event_id = $row[0];
}
mysql_free_result($rs);
$msg_list["db_insert_edit_Events"]="Réservation ajoutée.";
}
}
/***********************************************************************************/
function db_insert_edit_Events() {
global $dt_start, $dt_end,$event_id, $recurring_end, $entry_type,$rep_type,$CodeAdmin,$b_personal,$location, $msg_list, $rep_num_weeks, $rep_type, $rep_day, $rep_opt;
if ((isset($recurring_end))&&(!empty($recurring_end))) $dt_end=$recurring_end;
$rep_opt ="";
if (($rep_type == 2) || ($rep_type == 6))
for ($i = 0; $i < 7; $i++) $rep_opt .= empty($rep_day[$i]) ? "0" : "1";
if (!isset($dt_end)) {
$sql = "INSERT INTO events (";
$sql.="CodeAdmin,";
$sql.="dt_start,";
$sql.="b_personal,";
$sql.="entry_type,";
$sql.="recurring_end";
$sql.=") VALUES (".$CodeAdmin.",";
$sql.="'".$dt_start."',";
$sql.="'".$b_personal."',";
$sql.="'".$entry_type."',";
$sql.="'".$recurring_end."')";
}
else {
$sql = "INSERT INTO events (";
$sql.="CodeAdmin,";
$sql.="dt_start,";
$sql.="dt_end,";
$sql.="b_personal,";
$sql.="entry_type,";
$sql.="recurring_end,";
$sql.="rep_type,";
$sql.="rep_opt,";
$sql.="rep_num_weeks";
$sql.=") VALUES (".$CodeAdmin.",";
$sql.="'".$dt_start."',";
$sql.="'".$dt_end."',";
$sql.="'".$b_personal."',";
$sql.="'".$entry_type."',";
$sql.="'".$recurring_end."',";
$sql.="'".$rep_type."',";
$sql.="'".$rep_opt."',";
$sql.="'".$rep_num_weeks."')";
}
//'response.write sql
//on error resume next
mysql_query($sql)
or DIE ("Could not perform INSERT to table ".mysql_errno().": ".mysql_error());
if (mysql_errno()) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
else {
$rs = mysql_query("SELECT @@IDENTITY");
if ($row = mysql_fetch_row($rs)){
$event_id = $row[0];
}
mysql_free_result($rs);
$msg_list["db_insert_edit_Events"]="Réservation ajoutée.";
}
}
/*******************************************************************************/
function db_update_edit_Events() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $rep_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $b_error, $rep_opt, $rep_num_weeks, $rep_day;
$b_personal=0;
$dt_start=datevalue($dt_start)." 00:00:00";
if ((isset($recurring_end)) && (!empty($recurring_end))) $dt_end=$recurring_end;
$rep_opt ="";
if (($rep_type == 2) || ($rep_type == 6))
for ($i = 0; $i < 7; $i++) $rep_opt .= empty($rep_day[$i]) ? "0" : "1";
$sql ="UPDATE events SET ";
$sql.="CodeAdmin = ".$CodeAdmin.", ";
$sql.="dt_start ='".$dt_start."', ";
$sql.="dt_end = '".$dt_end."', ";
$sql.="entry_type = '".$entry_type."', ";
$sql.="recurring_end = '".$recurring_end."', ";
$sql.="rep_type = '".$rep_type."', ";
$sql.="rep_opt = '".$rep_opt."', ";
$sql.="rep_num_weeks = '".$rep_num_weeks."', ";
$sql.="b_personal = ".$b_personal." WHERE ";
$sql.="event_id = ".$event_id."";
mysql_query($sql) or DIE ("Could not perform UPDATE to table ".mysql_errno().": ".mysql_error());
}
/*******************************************************************************/
function db_delete_edit_Events() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $b_error, $id, $msg_list;
$sql = "DELETE FROM eventsoccur";
$sql.=" WHERE ";
$sql.="id = ".$id."";
//'response.write sql
//on error resume next
mysql_query($sql)
or DIE ("Could not perform DELETE to table ".mysql_errno().": ".mysql_error());
if (mysql_errno()) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
else
$msg_list["db_delete_edit_Events"]="Le champ a été supprimé.";
}
/****************************fonctions verification.php**********************************/
function verification($salleid,$hhdebut,$hhfin,$dTmp) {
$blnReserve=false;
$blnLoop=false;
if ($hhdebut <> "") {
$H_debut = strtotime(TimePart($hhdebut));
}
if ($hhfin <> "")
$H_fin = strtotime(TimePart($hhfin));
$partie_dTmp = explode("-", $dTmp);
$dTmp=$dTmp." 00:00:00";
$jour= $partie_dTmp[2];
$mois= $partie_dTmp[1]; // mon ajout
$annee= $partie_dTmp[0];
$strSQL = "SELECT * FROM eventsoccur WHERE ((UNIX_TIMESTAMP(dt_occur)=".strtotime($dTmp).") AND (location = ".(int)$salleid."))";
$rs = mysql_query($strSQL);
if (!$rs) {
echo "Could not successfully run query ($strSQL) from DB: ".mysql_error();
exit;
}
$blnLoop=false;
while ($row = mysql_fetch_assoc($rs)) {
If ((($H_debut >= strtotime(TimePart($row["tm_start"]))) AND ($H_fin <= strtotime(TimePart($row["tm_end"])))) OR (( $H_debut >= strtotime(TimePart($row["tm_start"]))) AND ($H_debut < strtotime(TimePart($row["tm_end"])))) OR (( $H_debut < strtotime(TimePart($row["tm_start"]))) AND ($H_fin >strtotime(TimePart($row["tm_start"]))))) {
$blnReserve=true;
$blnLoop=true;
}
if ($blnLoop) break;
}
mysql_free_result($rs);
$verification=$blnReserve;
return($verification);
}
//********************************************************************************/
function verificationUpdate($salleid,$hhdebut,$hhfin,$dTmp,$event_id) {
$blnReserve=false;
$blnLoop=false;
$hhdebut=$hhdebut.":00";
$hhfin=$hhfin.":00";
$H_debut = strtotime($hhdebut);
$H_fin = strtotime($hhfin);
$strSQL = "SELECT * FROM eventsoccur WHERE ((LEFT(dt_occur,10) = '".$dTmp."') AND (event_id <> ".$event_id.") AND (location=".(int)$salleid."))";
$rs = mysql_query($strSQL);
if (!$rs) {
echo "Could not successfully run query ($strSQL) from DB: " .mysql_error();
exit;
}
$blnLoop=false;
while ($row = mysql_fetch_assoc($rs)) {
If (($H_debut >= strtotime(TimePart($row["tm_start"]))) AND ($H_fin <= strtotime(TimePart($row["tm_end"]))) OR ( $H_debut >= strtotime(TimePart($row["tm_start"]))) AND ($H_debut < strtotime(TimePart($row["tm_end"]))) OR ( $H_debut < strtotime(TimePart($row["tm_start"]))) AND ($H_fin > strtotime(TimePart($row["tm_start"])))) {
$blnReserve=true;
$blnLoop=true;
}
if ($blnLoop) exit;
}
mysql_free_result($rs);
$verificationUpdate=$blnReserve;
return($verificationUpdate);
}
/**************************************************************************************/
/**************************************************************************************/
function add_eventoccurs() {
global $dTmp,$dt_start, $recurring_end, $entry_type, $CodeAdmin, $description, $dt_end, $event_id,$tm_start, $tm_end, $event_name, $location, $Organisme, $NomC, $PrenomC, $TelC, $EmailC, $Cout, $Tax, $b_register, $b_personal, $rep_num_weeks, $rep_type, $rep_day, $rep_opt;
// '*******************************
$exit=false;
$dTmp = $dt_start; //supposé etre datevalue($dt_start)
$dTmpU=tomktime($dTmp);
$recurring_endU=tomktime($recurring_end);
//Ajout GRR
/*$sec = date("s", $dTmpU);
$min = date("i", $dTmpU);
$hour = date("G", $dTmpU); */
$day = date("d", $dTmpU);
$month = date("m", $dTmpU);
$year = date("Y", $dTmpU);
/*********************************************************************************/
$entrys = ""; //ajout grr
/* for ($i = 1; $i<300; $i++) { */
for($i = 0; $i < 300; $i++){
$dTmpU = mktime(0, 0, 0, $month, $day, $year);
//etre equivalent tomktime()
if ( $dTmpU > $recurring_endU)
break;
$entrys[$i] = $dTmpU; //ajout grr
/* if ($entry_type == 0)
$dTmpU = dateadd("d",1,$dTmpU);
elseif ($entry_type < 30)
$dTmpU = dateadd("d",$entry_type,$dTmpU);
elseif ($entry_type == 30)
$dTmpU = dateadd("m",1,$dTmpU);
else $dTmpU = dateadd("Y",1,$dTmpU); */
/* $dTmpU = dateadd("d",1,$dTmpU); */
/*if ($dTmpU <= $recurring_endU){ */
$b_register=0;
$alert=0;
$dTmp=date("Y-n-j",$dTmpU);
$dTmp=$dTmp." 00:00:00";
$sql="INSERT INTO eventsoccur ";
$sql.="VALUES (";
$sql.="NULL,"; //pour generer un ID autoincrement
$sql.="$event_id,";
$sql.="'".$dTmp."', ";
$sql.="'".$tm_start."', ";
$sql.="'".$tm_end."', ";
$sql.="'".$event_name."', ";
$sql.="'".$description."', ";
$sql.="".$location.", ";
$sql.="".$Organisme.", ";
$sql.="'".$NomC."', ";
$sql.="'".$PrenomC."', ";
$sql.="'".$TelC."', ";
$sql.="'".$EmailC."', ";
$sql.="'".$Cout."', ";
$sql.="$Tax, ";
$sql.="$b_register,";
$sql.="$alert)";
mysql_query($sql)
or DIE ("Could not perform Insert to table ".mysql_errno().": ".mysql_error());
/* }else
$exit=true;
if ($exit) break; */
if ($entry_type != 0) {
switch($rep_type)
{
// Daily repeat
case 1:
/*$dTmpU = dateadd("d",$entry_type,$dTmpU); */
$day += 1;
break;
//weekly repeat
case 2:
//$dTmpU = dateadd("d",$entry_type,$dTmpU);
$j = $cur_day = date("w", $entrys[$i]);
// Skip over days of the week which are not enabled:
while ((($j = ($j + 1) % 7) != $cur_day ) && (!$rep_opt[$j]))
$day += 1;
$day += 1;
break;
// Monthly repeat
case 3:
$month += 1;
break;
// Yearly repeat
case 4:
$year += 1;
break;
// Monthly repeat on same week number and day of week
case 5:
$day += same_day_next_month($dTmpU);
break;
// n Weekly repeat
case 6:
$j = $cur_day = date("w", $entrys[$i]);
// Skip over days of the week which are not enabled:
while ((($j = ($j + 1) % (7*$rep_num_weeks)) != $cur_day && $j<7 &&!$rep_opt[$j]) or ($j>=7))
{
$day += 1;
}
$day += 1;
break;
default:
break;
}
} else
$day += 1;
}
}
/**************************************************************************************/
/************************************fonctions bdd grr*****************************************/
/** mrbsGetRepeatEntryList
*
* Returns a list of the repeating entrys
*
* $time - The start time
* $enddate - When the repeat ends
* $rep_type - What type of repeat is it
* $rep_opt - The repeat entrys
* $max_ittr - After going through this many entrys assume an error has occured
*
* Returns:
* empty - The entry does not repeat
* an array - This is a list of start times of each of the repeat entrys
*/
function mrbsGetRepeatEntryList($time, $enddate, $rep_type, $rep_opt, $max_ittr, $rep_num_weeks)
{
$sec = date("s", $time);
$min = date("i", $time);
$hour = date("G", $time);
$day = date("d", $time);
$month = date("m", $time);
$year = date("Y", $time);
$entrys = "";
for($i = 0; $i < $max_ittr; $i++)
{
$time = mktime($hour, $min, $sec, $month, $day, $year);
if ($time > $enddate)
break;
$entrys[$i] = $time;
switch($rep_type)
{
// Daily repeat
case 1:
$day += 1;
break;
// Weekly repeat
case 2:
$j = $cur_day = date("w", $entrys[$i]);
// Skip over days of the week which are not enabled:
while (($j = ($j + 1) % 7) != $cur_day && !$rep_opt[$j])
$day += 1;
$day += 1;
break;
// Monthly repeat
case 3:
$month += 1;
break;
// Yearly repeat
case 4:
$year += 1;
break;
// Monthly repeat on same week number and day of week
case 5:
$day += same_day_next_month($time);
break;
// n Weekly repeat
case 6:
$j = $cur_day = date("w", $entrys[$i]);
// Skip over days of the week which are not enabled:
while ((($j = ($j + 1) % (7*$rep_num_weeks)) != $cur_day && $j<7 &&!$rep_opt[$j]) or ($j>=7))
{
$day += 1;
}
$day += 1;
break;
// Unknown repeat option
default:
return;
}
}
return $entrys;
}
/** mrbsCreateRepeatingEntrys()
*
* Creates a repeat entry in the data base + all the repeating entrys
*
* $starttime - Start time of entry
* $endtime - End time of entry
* $rep_type - The repeat type
* $rep_enddate - When the repeating ends
* $rep_opt - Any options associated with the entry
* $room_id - Room ID
* $owner - Owner
* $name - Name
* $type - Type (Internal/External)
* $description - Description
*
* Returns:
* 0 - An error occured while inserting the entry
* non-zero - The entry's ID
*/
function mrbsCreateRepeatingEntrys($starttime, $endtime, $rep_type, $rep_enddate, $rep_opt,
$room_id, $owner, $name, $type, $description, $rep_num_weeks)
{
global $max_rep_entrys;
$reps = mrbsGetRepeatEntryList($starttime, $rep_enddate, $rep_type, $rep_opt, $max_rep_entrys, $rep_num_weeks);
if(count($reps) > $max_rep_entrys)
return 0;
if(empty($reps))
{
mrbsCreateSingleEntry($starttime, $endtime, 0, 0, $room_id, $owner, $name, $type, $description, '-');
return;
}
$ent = mrbsCreateRepeatEntry($starttime, $endtime, $rep_type, $rep_enddate, $rep_opt, $room_id, $owner, $name, $type, $description, $rep_num_weeks);
if($ent)
{
$diff = $endtime - $starttime;
for($i = 0; $i < count($reps); $i++)
mrbsCreateSingleEntry($reps[$i], $reps[$i] + $diff, 1, $ent,
$room_id, $owner, $name, $type, $description, '-');
}
return $ent;
}
/***********************************Pagination**********************************************/
// Pagination générique d'un listing
function pagine(
&$sql // Elément commun de requête : "FROM..." auquel sera ajouté le "LIMIT..."
,$mpp // Nombre max de lignes par page
,$query // Elément de querystring indiquant le n° de page
,$url // URL de la page
,$long=5 // Nombre max de pages avant et après la page courante
) {
// Pour construire les liens, regarde si $url contient déjà un ?
$t = (strpos($url,"?"))?"&":"?";
// Nombre total d'enregistrements retournés
$res = mysql_query("SELECT count(*) ".$sql);
$nbres = mysql_result($res,0,0);
// Calcul du nombre de pages
$nbpage = ceil($nbres/$mpp);
// La page courante est
$p=@$_GET[$query]; if(!$p) $p=1;
if($p>$nbpage) $p = $nbpage;
// Longueur de la liste de pages
$deb = max(1,$p-$long);
$fin = min($nbpage,$p+$long);
// Construction de la liste de pages
$pagine = "";
if($nbpage>1) {
for($i=$deb;$i<=$fin;$i++) {
// Page courante ?
if($i==$p) $pagine.=" ".$i." ";
// Page 1 > lien sans query
elseif($i==1) $pagine.=" ".$i." ";
// Autre page -> lien avec query
else $pagine.=" ".$i." ";
}
if($pagine) $pagine = " Page".$pagine;
// Premier, précédent
if($pagine&&($p>1)) {
if($p==2) $pagine ="".$pagine;
else $pagine ="".$pagine;
if($p>2) $pagine ="".$pagine;
}
// Suivant, dernier
if($pagine&&($p<$nbpage)) {
$pagine.="";
if($p<$nbpage-1) $pagine.="";
}
// Modification de la requête
$sql .= " LIMIT ".(($p-1)*$mpp).",".$mpp;
}
return $pagine;
}
?>